org.apache.xerces.xni.XMLResourceIdentifier Java Examples

The following examples show how to use org.apache.xerces.xni.XMLResourceIdentifier. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ClassLoaderXmlEntityResolverTest.java    From iaf with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #2
Source File: ClassLoaderXmlEntityResolverTest.java    From iaf with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #3
Source File: XSLURIResolverExtension.java    From lemminx with Eclipse Public License 2.0 5 votes vote down vote up
@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;
}
 
Example #4
Source File: ClassLoaderXmlEntityResolverTest.java    From iaf with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #5
Source File: ClassLoaderXmlEntityResolverTest.java    From iaf with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #6
Source File: ClassLoaderXmlEntityResolverTest.java    From iaf with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #7
Source File: ClassLoaderXmlEntityResolverTest.java    From iaf with Apache License 2.0 5 votes vote down vote up
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;
	}
 
Example #8
Source File: ClassLoaderXmlEntityResolver.java    From iaf with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #9
Source File: SchemaBuilder.java    From xml-avro with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #10
Source File: NekoHtmlDocumentHandler.java    From gate-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void startGeneralEntity(String arg0, XMLResourceIdentifier arg1,
        String arg2, Augmentations arg3) throws XNIException {
  if(DEBUG_UNUSED) {
    Out.println("startGeneralEntity");
  }
}
 
Example #11
Source File: XSDResolver.java    From RISE-V2G with MIT License 5 votes vote down vote up
@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;
}
 
Example #12
Source File: HTMLTagBalancer.java    From cc-dbp with Apache License 2.0 5 votes vote down vote up
/** 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);
    }

}
 
Example #13
Source File: URIResolverExtensionManager.java    From lemminx with Eclipse Public License 2.0 5 votes vote down vote up
@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);
}
 
Example #14
Source File: XMLCatalogResolverExtension.java    From lemminx with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public XMLInputSource resolveEntity(XMLResourceIdentifier resourceIdentifier) throws XNIException, IOException {
	if (catalogResolver != null) {
		return catalogResolver.resolveEntity(resourceIdentifier);
	}
	return null;
}
 
Example #15
Source File: XMLCacheResolverExtension.java    From lemminx with Eclipse Public License 2.0 5 votes vote down vote up
@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;
}
 
Example #16
Source File: XSDURIResolverExtension.java    From lemminx with Eclipse Public License 2.0 5 votes vote down vote up
@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;
}
 
Example #17
Source File: CMDTDDocument.java    From lemminx with Eclipse Public License 2.0 5 votes vote down vote up
@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);
	}
}
 
Example #18
Source File: CMDTDDocument.java    From lemminx with Eclipse Public License 2.0 5 votes vote down vote up
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);
}
 
Example #19
Source File: XMLCatalogURIResolverExtension.java    From lemminx with Eclipse Public License 2.0 5 votes vote down vote up
@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;
}
 
Example #20
Source File: XMLModelHandler.java    From lemminx with Eclipse Public License 2.0 5 votes vote down vote up
@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);
	}
}
 
Example #21
Source File: XMLCacheResolverExtension.java    From lemminx with Eclipse Public License 2.0 4 votes vote down vote up
public XMLFileInputSource(XMLResourceIdentifier resourceIdentifier, Path file) {
	super(resourceIdentifier);
	this.file = file;
}
 
Example #22
Source File: CMDTDDocument.java    From lemminx with Eclipse Public License 2.0 4 votes vote down vote up
public ScannedDTDEntityDecl(String name, XMLResourceIdentifier identifier, ScannedEntity scannedEntity) {
	this(name, null, identifier, scannedEntity);
}
 
Example #23
Source File: URIResolverExtension.java    From lemminx with Eclipse Public License 2.0 4 votes vote down vote up
@Override
default XMLInputSource resolveEntity(XMLResourceIdentifier resourceIdentifier) throws XNIException, IOException {
	return null;
}