01: /*
02: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
03: * Distributed under the terms of either:
04: * - the common development and distribution license (CDDL), v1.0; or
05: * - the GNU Lesser General Public License, v2.1 or later
06: * $Id: XmlUriResolver.java 3634 2007-01-08 21:42:24Z gbevin $
07: */
08: package com.uwyn.rife.xml;
09:
10: import com.uwyn.rife.resources.ResourceFinder;
11: import java.net.URL;
12: import javax.xml.transform.Source;
13: import javax.xml.transform.TransformerException;
14: import javax.xml.transform.URIResolver;
15: import javax.xml.transform.sax.SAXSource;
16:
17: public class XmlUriResolver implements URIResolver {
18: private ResourceFinder mResourceFinder = null;
19:
20: public XmlUriResolver(ResourceFinder resourcefinder) {
21: mResourceFinder = resourcefinder;
22: }
23:
24: public Source resolve(String href, String base)
25: throws TransformerException {
26: URL resource = mResourceFinder.getResource(href);
27: if (null == resource) {
28: return null;
29: }
30:
31: return new SAXSource(new XmlInputSource(resource));
32: }
33: }
|