use of org.w3c.dom.ls.LSInput in project qi4j-sdk by Qi4j.
the class QuikitResolver method resolveResource.
public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) {
String resourceName = local.getProperty(systemId);
if (resourceName == null) {
System.out.println("type: " + type);
System.out.println("namespaceURI: " + namespaceURI);
System.out.println("publicId: " + publicId);
System.out.println("systemId: " + systemId);
System.out.println("baseURI: " + baseURI);
return null;
}
InputStream resource = getClass().getClassLoader().getResourceAsStream(resourceName);
LSInput input;
try {
input = getLSInput();
} catch (Exception e) {
throw new UnsupportedOperationException("Internal problem. Please report to qi4j-dev forum at Google Groups.", e);
}
input.setBaseURI(baseURI);
input.setByteStream(resource);
input.setPublicId(publicId);
input.setSystemId(systemId);
return input;
}
use of org.w3c.dom.ls.LSInput in project languagetool by languagetool-org.
the class PatternRuleXmlCreator method getDocument.
private Document getDocument(InputStream is) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS");
LSParser parser = impl.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, null);
// we need to ignore whitespace here so the nodeToString() method will be able to indent it properly:
parser.setFilter(new IgnoreWhitespaceFilter());
LSInput domInput = impl.createLSInput();
domInput.setByteStream(is);
return parser.parse(domInput);
}
use of org.w3c.dom.ls.LSInput in project aries by apache.
the class SimpleNamespaceHandlerSet method getSchema.
public Schema getSchema() throws SAXException, IOException {
if (schema == null) {
final List<StreamSource> schemaSources = new ArrayList<StreamSource>();
final List<InputStream> streams = new ArrayList<InputStream>();
try {
InputStream is = getClass().getResourceAsStream("/org/apache/aries/blueprint/blueprint.xsd");
streams.add(is);
schemaSources.add(new StreamSource(is));
for (URI uri : namespaces.keySet()) {
is = namespaces.get(uri).openStream();
streams.add(is);
schemaSources.add(new StreamSource(is));
}
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
schemaFactory.setResourceResolver(new LSResourceResolver() {
public LSInput resolveResource(String type, String namespace, String publicId, String systemId, String baseURI) {
try {
URL namespaceURL = namespaces.get(URI.create(namespace));
if (systemId != null && namespaceURL != null) {
URI systemIdUri = namespaceURL.toURI();
if (!URI.create(systemId).isAbsolute()) {
systemIdUri = systemIdUri.resolve(systemId);
}
if (!systemIdUri.isAbsolute() && "jar".equals(namespaceURL.getProtocol())) {
String urlString = namespaceURL.toString();
int jarFragmentIndex = urlString.lastIndexOf('!');
if (jarFragmentIndex > 0 && jarFragmentIndex < urlString.length() - 1) {
String jarUrlOnly = urlString.substring(0, jarFragmentIndex);
String oldFragment = urlString.substring(jarFragmentIndex + 1);
String newFragment = URI.create(oldFragment).resolve(systemId).toString();
String newJarUri = jarUrlOnly + '!' + newFragment;
systemIdUri = URI.create(newJarUri);
}
}
InputStream resourceStream = systemIdUri.toURL().openStream();
return new LSInputImpl(publicId, systemId, resourceStream);
}
} catch (Exception ex) {
// ignore
}
return null;
}
});
schema = schemaFactory.newSchema(schemaSources.toArray(new Source[schemaSources.size()]));
} finally {
for (InputStream is : streams) {
is.close();
}
}
}
return schema;
}
use of org.w3c.dom.ls.LSInput in project midpoint by Evolveum.
the class XmlEntityResolverImpl method resolveResource.
/* (non-Javadoc)
* @see org.w3c.dom.ls.LSResourceResolver#resolveResource(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
*/
@Override
public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) {
LOGGER.trace("--- Resolving resource of type {}, namespaceURI: {}, publicID: {}, systemID: {}, base URI: {}", type, namespaceURI, publicId, systemId, baseURI);
InputSource inputSource = resolveResourceFromRegisteredSchemas(publicId, systemId);
if (inputSource == null) {
inputSource = resolveResourceUsingBuiltinResolver(type, namespaceURI, publicId, systemId, baseURI);
}
if (inputSource == null) {
LOGGER.error("Unable to resolve resource of type {}, namespaceURI: {}, publicID: {}, systemID: {}, baseURI: {}", new Object[] { type, namespaceURI, publicId, systemId, baseURI });
return null;
}
LOGGER.trace("==> Resolved resource of type {}, namespaceURI: {}, publicID: {}, systemID: {}, baseURI: {} : {}", new Object[] { type, namespaceURI, publicId, systemId, baseURI, inputSource });
return new Input(publicId, systemId, inputSource.getByteStream());
}
Aggregations