01: /**********************************************************************************
02: * $URL: https://source.sakaiproject.org/svn/sam/trunk/component/src/java/org/sakaiproject/tool/assessment/qti/util/URIResolver.java $
03: * $Id: URIResolver.java 9274 2006-05-10 22:50:48Z daisyf@stanford.edu $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2005, 2006 The Sakai Foundation.
07: *
08: * Licensed under the Educational Community License, Version 1.0 (the"License");
09: * you may not use this file except in compliance with the License.
10: * You may obtain a copy of the License at
11: *
12: * http://www.opensource.org/licenses/ecl1.php
13: *
14: * Unless required by applicable law or agreed to in writing, software
15: * distributed under the License is distributed on an "AS IS" BASIS,
16: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: * See the License for the specific language governing permissions and
18: * limitations under the License.
19: *
20: **********************************************************************************/package org.sakaiproject.tool.assessment.qti.util;
21:
22: import java.net.URI;
23: import java.net.URISyntaxException;
24: import javax.xml.transform.Source;
25: import javax.xml.transform.TransformerException;
26: import javax.xml.transform.stream.StreamSource;
27:
28: import org.apache.commons.logging.Log;
29: import org.apache.commons.logging.LogFactory;
30:
31: /**
32: * <p>Copyright: Copyright (c) 2005</p>
33: * <p>Organization: Sakai Project</p>
34: * @author palcasi
35: * @version $Id: URIResolver.java 9274 2006-05-10 22:50:48Z daisyf@stanford.edu $
36: */
37: public class URIResolver implements javax.xml.transform.URIResolver {
38: private static Log log = LogFactory.getLog(URIResolver.class);
39:
40: public URIResolver() {
41: }
42:
43: /* (non-Javadoc)
44: * @see javax.xml.transform.URIResolver#resolve(java.lang.String, java.lang.String)
45: */
46: public Source resolve(String href, String base)
47: throws TransformerException {
48: Source source = null;
49: String path = null;
50: try {
51: URI uri = new URI(base);
52: path = uri.resolve(href).toString();
53: source = new StreamSource(path);
54: } catch (URISyntaxException e) {
55: log.error(e);
56: throw new RuntimeException(e);
57: }
58:
59: return source;
60: }
61:
62: }
|