org.apache.solr.util
Class SystemIdResolver

java.lang.Object
  extended by org.apache.solr.util.SystemIdResolver
All Implemented Interfaces:
EntityResolver, EntityResolver2

public final class SystemIdResolver
extends Object
implements EntityResolver, EntityResolver2

This is a helper class to support resolving of XIncludes or other hrefs inside XML files on top of a ResourceLoader. Just plug this class on top of a ResourceLoader and pass it as EntityResolver to SAX parsers or via wrapper methods as URIResolver to XSL transformers or XMLResolver to STAX parsers. The resolver handles special SystemIds with an URI scheme of solrres: that point to resources. To produce such systemIds when you initially call the parser, use createSystemIdFromResourceName(java.lang.String) which produces a SystemId that can be included along the InputStream coming from ResourceLoader.openResource(java.lang.String).

In general create the InputSource to be passed to the parser like:

  InputSource is = new InputSource(loader.openSchema(name));
  is.setSystemId(SystemIdResolver.createSystemIdFromResourceName(name));
  final DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
  db.setEntityResolver(new SystemIdResolver(loader));
  Document doc = db.parse(is);
 


Field Summary
static String RESOURCE_LOADER_AUTHORITY_ABSOLUTE
           
static String RESOURCE_LOADER_URI_SCHEME
           
 
Constructor Summary
SystemIdResolver(ResourceLoader loader)
           
 
Method Summary
 EntityResolver asEntityResolver()
           
 URIResolver asURIResolver()
           
 XMLResolver asXMLResolver()
           
static String createSystemIdFromResourceName(String name)
           
 InputSource getExternalSubset(String name, String baseURI)
           
 InputSource resolveEntity(String publicId, String systemId)
           
 InputSource resolveEntity(String name, String publicId, String baseURI, String systemId)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RESOURCE_LOADER_URI_SCHEME

public static final String RESOURCE_LOADER_URI_SCHEME
See Also:
Constant Field Values

RESOURCE_LOADER_AUTHORITY_ABSOLUTE

public static final String RESOURCE_LOADER_AUTHORITY_ABSOLUTE
See Also:
Constant Field Values
Constructor Detail

SystemIdResolver

public SystemIdResolver(ResourceLoader loader)
Method Detail

asEntityResolver

public EntityResolver asEntityResolver()

asURIResolver

public URIResolver asURIResolver()

asXMLResolver

public XMLResolver asXMLResolver()

getExternalSubset

public InputSource getExternalSubset(String name,
                                     String baseURI)
Specified by:
getExternalSubset in interface EntityResolver2

resolveEntity

public InputSource resolveEntity(String name,
                                 String publicId,
                                 String baseURI,
                                 String systemId)
                          throws IOException
Specified by:
resolveEntity in interface EntityResolver2
Throws:
IOException

resolveEntity

public InputSource resolveEntity(String publicId,
                                 String systemId)
                          throws IOException
Specified by:
resolveEntity in interface EntityResolver
Throws:
IOException

createSystemIdFromResourceName

public static String createSystemIdFromResourceName(String name)


Copyright © 2000-2013 Apache Software Foundation. All Rights Reserved.