View Javadoc

1   /**
2    * Copyright 2005-2012 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.coreservice.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.coreservice.api.style.Style;
26  import org.kuali.rice.coreservice.api.style.StyleService;
27  
28  /**
29   * A URIResolver that knows how to resolve href's based on style names.
30   * 
31   * @author Kuali Rice Team (rice.collab@kuali.org)
32   * 
33   */
34  class StyleUriResolver implements URIResolver {
35  
36  	private static final Logger LOG = Logger.getLogger(StyleUriResolver.class);
37  	
38  	private final StyleService styleService;
39  	
40  	StyleUriResolver(StyleService styleService) {
41  		if (styleService == null) {
42  			throw new IllegalArgumentException("styleService cannot be null");
43  		}
44  		this.styleService = styleService;
45  	}
46  
47  	public Source resolve(String href, String base) {
48  
49  		try {
50  			Style style = styleService.getStyle(href);
51  			return new StreamSource(new StringReader(style.getXmlContent()));
52  
53  		} catch (Exception e) {
54  			LOG.error("Error ocurred getting style " + href, e);
55  		}
56  		return null;
57  	}
58  
59  }