Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
StyleUriResolver |
|
| 3.0;3 |
1 | /** | |
2 | * Copyright 2005-2011 The Kuali Foundation | |
3 | * | |
4 | * Licensed under the Educational Community License, Version 2.0 (the "License"); | |
5 | * you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at | |
7 | * | |
8 | * http://www.opensource.org/licenses/ecl2.php | |
9 | * | |
10 | * Unless required by applicable law or agreed to in writing, software | |
11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | * See the License for the specific language governing permissions and | |
14 | * limitations under the License. | |
15 | */ | |
16 | package org.kuali.rice.core.impl.style; | |
17 | ||
18 | import java.io.StringReader; | |
19 | ||
20 | import javax.xml.transform.Source; | |
21 | import javax.xml.transform.URIResolver; | |
22 | import javax.xml.transform.stream.StreamSource; | |
23 | ||
24 | import org.apache.log4j.Logger; | |
25 | import org.kuali.rice.core.api.style.Style; | |
26 | import org.kuali.rice.core.api.style.StyleService; | |
27 | ||
28 | ||
29 | /** | |
30 | * A URIResolver that knows how to resolve href's based on style names. | |
31 | * | |
32 | * @author Kuali Rice Team (rice.collab@kuali.org) | |
33 | * | |
34 | */ | |
35 | class StyleUriResolver implements URIResolver { | |
36 | ||
37 | 0 | private static final Logger LOG = Logger.getLogger(StyleUriResolver.class); |
38 | ||
39 | private final StyleService styleService; | |
40 | ||
41 | 0 | StyleUriResolver(StyleService styleService) { |
42 | 0 | if (styleService == null) { |
43 | 0 | throw new IllegalArgumentException("styleService cannot be null"); |
44 | } | |
45 | 0 | this.styleService = styleService; |
46 | 0 | } |
47 | ||
48 | public Source resolve(String href, String base) { | |
49 | ||
50 | try { | |
51 | 0 | Style style = styleService.getStyle(href); |
52 | 0 | return new StreamSource(new StringReader(style.getXmlContent())); |
53 | ||
54 | 0 | } catch (Exception e) { |
55 | 0 | LOG.error("Error ocurred getting style " + href, e); |
56 | } | |
57 | 0 | return null; |
58 | } | |
59 | ||
60 | } |