List of usage examples for org.w3c.dom.ls LSInput setPublicId
public void setPublicId(String publicId);
From source file:de.betterform.xml.xforms.model.Model.java
private XSLoader getSchemaLoader() throws IllegalAccessException, InstantiationException, ClassNotFoundException { // System.setProperty(DOMImplementationRegistry.PROPERTY, // "org.apache.xerces.dom.DOMXSImplementationSourceImpl"); DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); XSImplementation implementation = (XSImplementation) registry.getDOMImplementation("XS-Loader"); XSLoader loader = implementation.createXSLoader(null); DOMConfiguration cfg = loader.getConfig(); cfg.setParameter("resource-resolver", new LSResourceResolver() { public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) { LSInput input = new LSInput() { String systemId;/*from ww w .j a v a2 s . com*/ public void setSystemId(String systemId) { this.systemId = systemId; } public void setStringData(String s) { } String publicId; public void setPublicId(String publicId) { this.publicId = publicId; } public void setEncoding(String s) { } public void setCharacterStream(Reader reader) { } public void setCertifiedText(boolean flag) { } public void setByteStream(InputStream inputstream) { } String baseURI; public void setBaseURI(String baseURI) { if (baseURI == null || "".equals(baseURI)) { baseURI = getContainer().getProcessor().getBaseURI(); } this.baseURI = baseURI; } public String getSystemId() { return this.systemId; } public String getStringData() { return null; } public String getPublicId() { return this.publicId; } public String getEncoding() { return null; } public Reader getCharacterStream() { return null; } public boolean getCertifiedText() { return false; } public InputStream getByteStream() { if (LOGGER.isTraceEnabled()) { LOGGER.trace("Schema resource\n\t\t publicId '" + publicId + "'\n\t\t systemId '" + systemId + "' requested"); } try { String pathToSchema = null; if ("http://www.w3.org/MarkUp/SCHEMA/xml-events-attribs-1.xsd".equals(systemId)) { pathToSchema = "schema/xml-events-attribs-1.xsd"; } else if ("http://www.w3.org/2001/XMLSchema.xsd".equals(systemId)) { pathToSchema = "schema/XMLSchema.xsd"; } else if ("-//W3C//DTD XMLSCHEMA 200102//EN".equals(publicId)) { pathToSchema = "schema/XMLSchema.dtd"; } else if ("datatypes".equals(publicId)) { pathToSchema = "schema/datatypes.dtd"; } else if ("http://www.w3.org/2001/xml.xsd".equals(systemId)) { pathToSchema = "schema/xml.xsd"; } // LOAD WELL KNOWN SCHEMA if (pathToSchema != null) { if (LOGGER.isTraceEnabled()) { LOGGER.trace("loading Schema '" + pathToSchema + "'\n\n"); } return Thread.currentThread().getContextClassLoader() .getResourceAsStream(pathToSchema); } // LOAD SCHEMA THAT IS NOT(!) YET KNWON TO THE XFORMS PROCESSOR else if (systemId != null && !"".equals(systemId)) { URI schemaURI = new URI(baseURI); schemaURI = schemaURI.resolve(systemId); // ConnectorFactory.getFactory() if (LOGGER.isDebugEnabled()) { LOGGER.debug("loading schema resource '" + schemaURI.toString() + "'\n\n"); } return ConnectorFactory.getFactory().getHTTPResourceAsStream(schemaURI); } else { LOGGER.error("resource not known '" + systemId + "'\n\n"); return null; } } catch (XFormsException e) { e.printStackTrace(); } catch (URISyntaxException e) { e.printStackTrace(); } return null; } public String getBaseURI() { return this.baseURI; } }; input.setSystemId(systemId); input.setBaseURI(baseURI); input.setPublicId(publicId); return input; } }); // END: Patch return loader; }