下面列出了org.xml.sax.EntityResolver#resolveEntity ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public InputSource getInputSource(EntityResolver r)
throws IOException, SAXException {
InputSource retval;
retval = r.resolveEntity(publicId, systemId);
// SAX sez if null is returned, use the URI directly
if (retval == null)
retval = Resolver.createInputSource(new URL(systemId), false);
return retval;
}
private static InputSource makeInputSource(XMLReader xr, String systemId) throws IOException, SAXException {
EntityResolver er = xr.getEntityResolver();
if (er != null) {
InputSource inputSource = er.resolveEntity(null, systemId);
if (inputSource != null)
return inputSource;
}
return new InputSource(systemId);
}
public InputSource getInputSource(EntityResolver r)
throws IOException, SAXException {
InputSource retval;
retval = r.resolveEntity(publicId, systemId);
// SAX sez if null is returned, use the URI directly
if (retval == null)
retval = Resolver.createInputSource(new URL(systemId), false);
return retval;
}
private static InputSource makeInputSource(XMLReader xr, String systemId) throws IOException, SAXException {
EntityResolver er = xr.getEntityResolver();
if (er != null) {
InputSource inputSource = er.resolveEntity(null, systemId);
if (inputSource != null)
return inputSource;
}
return new InputSource(systemId);
}
/**
* @see org.xml.sax.EntityResolver#resolveEntity(java.lang.String, java.lang.String)
*/
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
LOG.debug("resolveEntity: " + publicId + " " + systemId);
for (EntityResolver resolver: resolvers) {
LOG.debug("Invoking entity resolver: " + resolver);
InputSource source = resolver.resolveEntity(publicId, systemId);
if (source != null) {
LOG.debug("source != null: " + source);
return source;
}
}
return null;
}
private static InputSource makeInputSource(XMLReader xr, String systemId) throws IOException, SAXException {
EntityResolver er = xr.getEntityResolver();
if (er != null) {
InputSource inputSource = er.resolveEntity(null, systemId);
if (inputSource != null)
return inputSource;
}
return new InputSource(systemId);
}
public ModelSource getModelSource(URI locationURI,
ModelSource modelSourceOfSourceDocument) throws CatalogModelException {
InputStream inputStream = null;
try {
UserCatalog cat = UserCatalog.getDefault();
// mainly for unit tests
if (cat == null) {
return null;
}
EntityResolver resolver = cat.getEntityResolver();
InputSource src = resolver.resolveEntity(null, locationURI.toString());
if(src != null) {
inputStream = new URL(src.getSystemId()).openStream();
} else {
javax.xml.transform.Source isrc = ((javax.xml.transform.URIResolver)resolver).
resolve(locationURI.toString(), null);
if(isrc != null)
inputStream = new URL(isrc.getSystemId()).openStream();
}
if(inputStream != null)
return createModelSource(inputStream);
} catch (Exception ex) {
throw new CatalogModelException(ex);
}
return null;
}
public InputSource getInputSource(EntityResolver r)
throws IOException, SAXException {
InputSource retval;
retval = r.resolveEntity(publicId, systemId);
// SAX sez if null is returned, use the URI directly
if (retval == null)
retval = Resolver.createInputSource(new URL(systemId), false);
return retval;
}
private static InputSource makeInputSource(XMLReader xr, String systemId) throws IOException, SAXException {
EntityResolver er = xr.getEntityResolver();
if (er != null) {
InputSource inputSource = er.resolveEntity(null, systemId);
if (inputSource != null)
return inputSource;
}
return new InputSource(systemId);
}
public InputSource getInputSource(EntityResolver r)
throws IOException, SAXException {
InputSource retval;
retval = r.resolveEntity(publicId, systemId);
// SAX sez if null is returned, use the URI directly
if (retval == null)
retval = Resolver.createInputSource(new URL(systemId), false);
return retval;
}
private static InputSource makeInputSource(XMLReader xr, String systemId) throws IOException, SAXException {
EntityResolver er = xr.getEntityResolver();
if (er != null) {
InputSource inputSource = er.resolveEntity(null, systemId);
if (inputSource != null)
return inputSource;
}
return new InputSource(systemId);
}
public InputSource getInputSource(EntityResolver r)
throws IOException, SAXException {
InputSource retval;
retval = r.resolveEntity(publicId, systemId);
// SAX sez if null is returned, use the URI directly
if (retval == null)
retval = Resolver.createInputSource(new URL(systemId), false);
return retval;
}
private static InputSource makeInputSource(XMLReader xr, String systemId) throws IOException, SAXException {
EntityResolver er = xr.getEntityResolver();
if (er != null) {
InputSource inputSource = er.resolveEntity(null, systemId);
if (inputSource != null)
return inputSource;
}
return new InputSource(systemId);
}
public InputSource getInputSource(EntityResolver r)
throws IOException, SAXException {
InputSource retval;
retval = r.resolveEntity(publicId, systemId);
// SAX sez if null is returned, use the URI directly
if (retval == null)
retval = Resolver.createInputSource(new URL(systemId), false);
return retval;
}
private static InputSource makeInputSource(XMLReader xr, String systemId) throws IOException, SAXException {
EntityResolver er = xr.getEntityResolver();
if (er != null) {
InputSource inputSource = er.resolveEntity(null, systemId);
if (inputSource != null)
return inputSource;
}
return new InputSource(systemId);
}
public InputSource getInputSource(EntityResolver r)
throws IOException, SAXException {
InputSource retval;
retval = r.resolveEntity(publicId, systemId);
// SAX sez if null is returned, use the URI directly
if (retval == null)
retval = Resolver.createInputSource(new URL(systemId), false);
return retval;
}
private static InputSource makeInputSource(XMLReader xr, String systemId) throws IOException, SAXException {
EntityResolver er = xr.getEntityResolver();
if (er != null) {
InputSource inputSource = er.resolveEntity(null, systemId);
if (inputSource != null)
return inputSource;
}
return new InputSource(systemId);
}
/**
* Resolves relative URI found in the document.
*
* @param namespaceURI
* passed to the entity resolver.
* @param relativeUri
* value of the schemaLocation attribute. Can be null.
*
* @return
* non-null if {@link EntityResolver} returned an {@link InputSource},
* or if the relativeUri parameter seems to be pointing to something.
* Otherwise it returns null, in which case import/include should be abandoned.
*/
private InputSource resolveRelativeURL( String namespaceURI, String relativeUri ) throws SAXException {
try {
String baseUri = getLocator().getSystemId();
if(baseUri==null)
// if the base URI is not available, the document system ID is
// better than nothing.
baseUri=documentSystemId;
String systemId = null;
if(relativeUri!=null)
systemId = Uri.resolve(baseUri,relativeUri);
EntityResolver er = parser.getEntityResolver();
if(er!=null) {
InputSource is = er.resolveEntity(namespaceURI,systemId);
if(is!=null)
return is;
}
if(systemId!=null)
return new InputSource(systemId);
else
return null;
} catch (IOException e) {
SAXParseException se = new SAXParseException(e.getMessage(),getLocator(),e);
parser.errorHandler.error(se);
return null;
}
}
@Nullable
public InputSource resolveEntity (final String sPublicId, final String sSystemId) throws IOException, SAXException
{
_updatePosition ("resolveEntity");
final EntityResolver aER = m_aEntityResolver;
if (aER != null)
return aER.resolveEntity (sPublicId, sSystemId);
// If using XHTML this should be replaced by using the LocalEntityResolver
// instead
if (sPublicId == null)
{
if (LOGGER.isInfoEnabled ())
LOGGER.info ("Need to resolve entity with system ID '" + sSystemId + "'");
}
else
if (sSystemId == null)
{
if (LOGGER.isInfoEnabled ())
LOGGER.info ("Need to resolve entity with public ID '" + sPublicId + "'");
}
else
{
if (LOGGER.isInfoEnabled ())
LOGGER.info ("Need to resolve entity with public ID '" + sPublicId + "' and system ID '" + sSystemId + "'");
}
return null;
}
@Nullable
public InputSource resolveEntity (@Nullable final String sName,
@Nullable final String sPublicId,
@Nullable final String sBaseURI,
@Nonnull final String sSystemId) throws SAXException, IOException
{
_updatePosition ("resolveEntity2");
final EntityResolver2 aER2 = m_aEntityResolver2;
if (aER2 != null)
return aER2.resolveEntity (sName, sPublicId, sBaseURI, sSystemId);
final EntityResolver aER = m_aEntityResolver;
if (aER != null)
return aER.resolveEntity (sPublicId, sSystemId);
if (LOGGER.isInfoEnabled ())
LOGGER.info ("Need to resolve entity with name '" +
sName +
"', public ID '" +
sPublicId +
"' base URI '" +
sBaseURI +
"' and system ID '" +
sSystemId +
"'");
return null;
}