View Javadoc

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  	private static final Logger LOG = Logger.getLogger(StyleUriResolver.class);
38  	
39  	private final StyleService styleService;
40  	
41  	StyleUriResolver(StyleService styleService) {
42  		if (styleService == null) {
43  			throw new IllegalArgumentException("styleService cannot be null");
44  		}
45  		this.styleService = styleService;
46  	}
47  
48  	public Source resolve(String href, String base) {
49  
50  		try {
51  			Style style = styleService.getStyle(href);
52  			return new StreamSource(new StringReader(style.getXmlContent()));
53  
54  		} catch (Exception e) {
55  			LOG.error("Error ocurred getting style " + href, e);
56  		}
57  		return null;
58  	}
59  
60  }