Java源码示例:org.apache.xerces.xni.XMLResourceIdentifier

示例1
@Test
public void bytesClassPath() throws SAXException, IOException, ConfigurationException {
	ClassLoader localClassLoader = Thread.currentThread().getContextClassLoader();

	URL file = this.getClass().getResource(JAR_FILE);
	assertNotNull("jar url not found", file);
	JarFile jarFile = new JarFile(file.getFile());
	assertNotNull("jar file not found",jarFile);

	JarFileClassLoader cl = new JarFileClassLoader(localClassLoader);
	cl.setJar(file.getFile());
	cl.configure(null, "");

	ClassLoaderXmlEntityResolver resolver = new ClassLoaderXmlEntityResolver(cl);

	XMLResourceIdentifier resourceIdentifier = getXMLResourceIdentifier("ClassLoader/Xslt/names.xsl");

	XMLInputSource inputSource = resolver.resolveEntity(resourceIdentifier);
	assertNotNull(inputSource);
}
 
示例2
@Test
public void bytesClassPathAbsolute() throws SAXException, IOException, ConfigurationException  {
	ClassLoader localClassLoader = Thread.currentThread().getContextClassLoader();

	URL file = this.getClass().getResource(JAR_FILE);
	assertNotNull("jar url not found", file);
	JarFile jarFile = new JarFile(file.getFile());
	assertNotNull("jar file not found",jarFile);

	JarFileClassLoader cl = new JarFileClassLoader(localClassLoader);
	cl.setJar(file.getFile());
	cl.configure(null, "");

	ClassLoaderXmlEntityResolver resolver = new ClassLoaderXmlEntityResolver(cl);

	XMLResourceIdentifier resourceIdentifier = getXMLResourceIdentifier("/ClassLoader/Xslt/names.xsl");

	XMLInputSource inputSource = resolver.resolveEntity(resourceIdentifier);
	assertNotNull(inputSource);
}
 
示例3
@Override
public XMLInputSource resolveEntity(XMLResourceIdentifier resourceIdentifier) throws XNIException, IOException {
	XMLInputSource is = null;
	for (URIResolverExtension resolver : resolvers) {
		is = resolver.resolveEntity(resourceIdentifier);
		if (is != null) {
			return is;
		}
	}
	return defaultURIResolverExtension.resolveEntity(resourceIdentifier);
}
 
示例4
@Override
public void startGeneralEntity(String name, XMLResourceIdentifier identifier, String encoding, Augmentations augs)
		throws XNIException {
	if (xmlModelValidators != null) {
		for (XMLModelValidator validator : xmlModelValidators) {
			validator.startGeneralEntity(name, identifier, encoding, augs);
		}
	}

	if (documentHandler != null) {
		documentHandler.startGeneralEntity(name, identifier, encoding, augs);
	}
}
 
示例5
@Override
public XMLInputSource resolveEntity(XMLResourceIdentifier resourceIdentifier) throws XNIException, IOException {
	if (hasDTDorXMLSchema(resourceIdentifier.getBaseSystemId())) {
		return null;
	}
	String publicId = resourceIdentifier.getNamespace();
	if (CATALOG_NAMESPACE_URI.equals(publicId)) {
		return new XMLInputSource(publicId, CATALOG_SYSTEM, CATALOG_SYSTEM);
	}
	return null;
}
 
示例6
private ScannedDTDEntityDecl(String entityName, String value, XMLResourceIdentifier identifier,
		ScannedEntity scannedEntity) {
	super(-1, -1);
	this.entityName = entityName;
	this.value = value;
	this.publicId = identifier != null ? identifier.getPublicId() : null;
	this.systemId = identifier != null ? identifier.getLiteralSystemId() : null;
	this.nameParameter = createNameParameter(entityName, scannedEntity);
}
 
示例7
@Override
public void externalEntityDecl(String name, XMLResourceIdentifier identifier, Augmentations augs)
		throws XNIException {
	super.externalEntityDecl(name, identifier, augs);
	try {
		entities.add(new ScannedDTDEntityDecl(name, identifier, fEntityManager.getCurrentEntity()));
	} catch (Exception e) {
		LOGGER.log(Level.SEVERE, "Error while extracting information for the external entity '" + name + "'", e);
	}
}
 
示例8
@Override
public XMLInputSource resolveEntity(XMLResourceIdentifier resourceIdentifier) throws XNIException, IOException {
	String publicId = resourceIdentifier.getNamespace();
	if (SCHEMA_FOR_SCHEMA_URI_2001.equals(publicId) || SCHEMA_FOR_NAMESPACE_URI_1998.equals(publicId)) {
		String baseLocation = resourceIdentifier.getBaseSystemId();
		String xslFilePath = resolve(baseLocation, publicId, null);
		if (xslFilePath != null) {
			return new XMLInputSource(publicId, xslFilePath, xslFilePath);
		}
	}
	return null;
}
 
示例9
@Override
public XMLInputSource resolveEntity(XMLResourceIdentifier resourceIdentifier) throws XNIException, IOException {
	String url = resourceIdentifier.getExpandedSystemId();
	// Try to get the downloaded resource. In the case where the resource is
	// downloading but takes too long, a CacheResourceDownloadingException is
	// thrown.
	Path file = getCachedResource(url);
	if (file != null) {
		// The resource was downloaded locally, use it.
		return new XMLFileInputSource(resourceIdentifier, file);
	}
	return null;
}
 
示例10
@Override
public XMLInputSource resolveEntity(XMLResourceIdentifier resourceIdentifier) throws XNIException, IOException {
	if (catalogResolver != null) {
		return catalogResolver.resolveEntity(resourceIdentifier);
	}
	return null;
}
 
示例11
@Override
public XMLInputSource resolveEntity(XMLResourceIdentifier resourceIdentifier) throws XNIException, IOException {
	String publicId = resourceIdentifier.getNamespace();
	if (XSL_NAMESPACE_URI.equals(publicId)) {
		String baseLocation = resourceIdentifier.getBaseSystemId();
		String xslFilePath = resolve(baseLocation, publicId, null);
		if (xslFilePath != null) {
			return new XMLInputSource(publicId, xslFilePath, xslFilePath);
		}
	}
	return null;
}
 
示例12
/** Start entity. */
public void startGeneralEntity(String name, 
                               XMLResourceIdentifier id,
                               String encoding,
                               Augmentations augs) throws XNIException {
    fSeenAnything = true;

    // check for end of document
    if (fSeenRootElementEnd) {
        return;
    }

    // insert body, if needed
    if (!fDocumentFragment) {
        boolean insertBody = !fSeenRootElement;
        if (!insertBody) {
            Info info = fElementStack.peek();
            if (info.element.code == HTMLElements.HEAD ||
                info.element.code == HTMLElements.HTML) {
                String hname = modifyName("head", fNamesElems);
                String bname = modifyName("body", fNamesElems);
                if (fReportErrors) {
                    fErrorReporter.reportWarning("HTML2009", new Object[]{hname,bname});
                }
                fQName.setValues(null, hname, hname, null);
                endElement(fQName, synthesizedAugs());
                insertBody = true;
            }
        }
        if (insertBody) {
            forceStartBody();
        }
    }
    
    // call handler
    if (fDocumentHandler != null) {
        fDocumentHandler.startGeneralEntity(name, id, encoding, augs);
    }

}
 
示例13
@Override
public XMLInputSource resolveEntity(XMLResourceIdentifier resourceIdentifier) 
		throws XNIException, IOException {
	String literalSystemId = resourceIdentifier.getLiteralSystemId(); 
	
	if (xmlInputSourceEntities != null && xmlInputSourceEntities.containsKey(literalSystemId)) {
		return xmlInputSourceEntities.get(literalSystemId);
	}

	return null;
}
 
示例14
@Override
public void startGeneralEntity(String arg0, XMLResourceIdentifier arg1,
        String arg2, Augmentations arg3) throws XNIException {
  if(DEBUG_UNUSED) {
    Out.println("startGeneralEntity");
  }
}
 
示例15
@Override
public XMLInputSource resolveEntity(XMLResourceIdentifier id) throws XNIException, IOException {
    String systemId = id.getLiteralSystemId();
    debug("Resolving " + systemId);

    XMLInputSource source = new XMLInputSource(id);
    source.setByteStream(resolver.getStream(systemId));
    return source;
}
 
示例16
@Override
public XMLInputSource resolveEntity(XMLResourceIdentifier resourceIdentifier) throws XNIException, IOException {
	if (log.isDebugEnabled()) log.debug("resolveEntity publicId ["+resourceIdentifier.getPublicId()+"] baseSystemId ["+resourceIdentifier.getBaseSystemId()+"] expandedSystemId ["+resourceIdentifier.getExpandedSystemId()+"] literalSystemId ["+resourceIdentifier.getLiteralSystemId()+"] namespace ["+resourceIdentifier.getNamespace()+"]");
	if (resourceIdentifier.getBaseSystemId() == null
			&& resourceIdentifier.getExpandedSystemId() == null
			&& resourceIdentifier.getLiteralSystemId() == null
			&& resourceIdentifier.getNamespace() == null
			&& resourceIdentifier.getPublicId() == null) {
		// This seems to happen sometimes. For example with import of
		// sub01a.xsd and sub05.xsd without namespace in
		// /XmlValidator/import_include/root.xsd of Ibis4TestIAF. The
		// default resolve entity implementation seems to ignore it, hence
		// return null.
		return null;
	}
	
	String base = resourceIdentifier.getBaseSystemId();
	String href = resourceIdentifier.getLiteralSystemId();
	if (href == null) {
		// Ignore import with namespace but without schemaLocation
		return null;
	}

	Resource resource;
	try {
		resource = resolveToResource(href, base);
	} catch (TransformerException e) {
		throw new XNIException(e);
	}

	
	InputStream inputStream = resource.getURL().openStream();
	return new XMLInputSource(null, resource.getSystemId(), null, inputStream, null);
}
 
示例17
private XMLResourceIdentifier getXMLResourceIdentifier(String href) {
		XMLResourceIdentifier resourceIdentifier = new ResourceIdentifier(); 
		resourceIdentifier.setPublicId(publicId);
		
//		resourceIdentifier.setExpandedSystemId(href); // this file is known to be in the root of the classpath
		resourceIdentifier.setLiteralSystemId(href); // this file is known to be in the root of the classpath
		return resourceIdentifier;
	}
 
示例18
@Test
public void localClassPathFileOnRootOfClasspath() throws SAXException, IOException {
	ClassLoader localClassLoader = Thread.currentThread().getContextClassLoader();
	ClassLoaderXmlEntityResolver resolver = new ClassLoaderXmlEntityResolver(localClassLoader);
	
	XMLResourceIdentifier resourceIdentifier = getXMLResourceIdentifier("AppConstants.properties");
	
	XMLInputSource inputSource = resolver.resolveEntity(resourceIdentifier);
	assertNotNull(inputSource);
}
 
示例19
@Test
public void localClassPathFileOnRootOfClasspathAbsolute() throws SAXException, IOException {
	ClassLoader localClassLoader = Thread.currentThread().getContextClassLoader();
	ClassLoaderXmlEntityResolver resolver = new ClassLoaderXmlEntityResolver(localClassLoader);

	XMLResourceIdentifier resourceIdentifier = getXMLResourceIdentifier("/AppConstants.properties");

	XMLInputSource inputSource = resolver.resolveEntity(resourceIdentifier);
	assertNotNull(inputSource);
}
 
示例20
@Test
public void localClassPathAbsolute() throws SAXException, IOException {
	ClassLoader localClassLoader = Thread.currentThread().getContextClassLoader();
	ClassLoaderXmlEntityResolver resolver = new ClassLoaderXmlEntityResolver(localClassLoader);

	XMLResourceIdentifier resourceIdentifier = getXMLResourceIdentifier("/Xslt/importDocument/lookup.xml");
	
	XMLInputSource inputSource = resolver.resolveEntity(resourceIdentifier);
	assertNotNull(inputSource);
}
 
示例21
@Override
default XMLInputSource resolveEntity(XMLResourceIdentifier resourceIdentifier) throws XNIException, IOException {
	return null;
}
 
示例22
public ScannedDTDEntityDecl(String name, XMLResourceIdentifier identifier, ScannedEntity scannedEntity) {
	this(name, null, identifier, scannedEntity);
}
 
示例23
public XMLFileInputSource(XMLResourceIdentifier resourceIdentifier, Path file) {
	super(resourceIdentifier);
	this.file = file;
}