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