XercesSchemaValidationUtils() { DOMXSImplementationSourceImpl source = new org.apache.xerces.dom.DOMXSImplementationSourceImpl(); impl = (XSImplementation)source.getDOMImplementation("XS-Loader"); }
(new DOMXSImplementationSourceImpl()).getDOMImplementation(XMLConstants.XSD_LOADER_NAME);
/** * A method to request a DOM implementation. * @param features A string that specifies which features are required. * This is a space separated list in which each feature is specified * by its name optionally followed by a space and a version number. * This is something like: "XML 1.0 Traversal Events 2.0" * @return An implementation that has the desired features, or * <code>null</code> if this source has none. */ public DOMImplementation getDOMImplementation(String features) { DOMImplementation impl = super.getDOMImplementation(features); if (impl != null){ return impl; } // if not try the PSVIDOMImplementation impl = PSVIDOMImplementationImpl.getDOMImplementation(); if (testImpl(impl, features)) { return impl; } // if not try the XSImplementation impl = XSImplementationImpl.getDOMImplementation(); if (testImpl(impl, features)) { return impl; } return null; }
/** * registers bunch of schemas located in the schemaUri folder * * @param modelsUri String; the folder containing schemas to register * @throws BagriException in case of any error */ //@Override public void registerModels(String modelsUri) throws BagriException { XSImplementation impl = (XSImplementation) new DOMXSImplementationSourceImpl().getDOMImplementation("XS-Loader LS"); XSLoader schemaLoader = impl.createXSLoader(null); java.nio.file.Path catalog = Paths.get(modelsUri); List<String> files = new ArrayList<>(); processCatalog(catalog, files); if (files.size() > 0) { StringList schemas = impl.createStringList(files.toArray(new String[files.size()])); XSModel schema = schemaLoader.loadURIList(schemas); processModel(schema); } }
private byte[] flushDom(Document dom) { // if it is one of our DOM files we may flush all collected namespaces // to the root element if (dom instanceof OdfFileDom) { OdfFileDom odfDom = (OdfFileDom) dom; Map<String, String> nsByUri = odfDom.getMapNamespacePrefixByUri(); OdfElement root = odfDom.getRootElement(); if (root != null) { for (Entry<String, String> entry : nsByUri.entrySet()) { root.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:" + entry.getValue(), entry.getKey()); } } } ByteArrayOutputStream baos = new ByteArrayOutputStream(); DOMXSImplementationSourceImpl dis = new org.apache.xerces.dom.DOMXSImplementationSourceImpl(); DOMImplementationLS impl = (DOMImplementationLS) dis.getDOMImplementation("LS"); LSSerializer writer = impl.createLSSerializer(); LSOutput output = impl.createLSOutput(); output.setByteStream(baos); writer.write(dom, output); return baos.toByteArray(); }
private byte[] flushDom(Document dom) { // if it is one of our DOM files we may flush all collected namespaces to the root element if (dom instanceof OdfFileDom) { OdfFileDom odfDom = (OdfFileDom) dom; Map<String, String> nsByUri = odfDom.getMapNamespacePrefixByUri(); OdfElement root = odfDom.getRootElement(); if (root != null) { for (Entry<String, String> entry : nsByUri.entrySet()) { root.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:" + entry.getValue(), entry.getKey()); } } } ByteArrayOutputStream baos = new ByteArrayOutputStream(); DOMXSImplementationSourceImpl dis = new org.apache.xerces.dom.DOMXSImplementationSourceImpl(); DOMImplementationLS impl = (DOMImplementationLS) dis.getDOMImplementation("LS"); LSSerializer writer = impl.createLSSerializer(); LSOutput output = impl.createLSOutput(); output.setByteStream(baos); writer.write(dom, output); return baos.toByteArray(); }
private byte[] flushDom(Document dom) { // if it is one of our DOM files we may flush all collected namespaces // to the root element if (dom instanceof OdfFileDom) { OdfFileDom odfDom = (OdfFileDom) dom; Map<String, String> nsByUri = odfDom.getMapNamespacePrefixByUri(); OdfElement root = odfDom.getRootElement(); if (root != null) { for (Entry<String, String> entry : nsByUri.entrySet()) { root.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:" + entry.getValue(), entry.getKey()); } } } ByteArrayOutputStream baos = new ByteArrayOutputStream(); DOMXSImplementationSourceImpl dis = new org.apache.xerces.dom.DOMXSImplementationSourceImpl(); DOMImplementationLS impl = (DOMImplementationLS) dis.getDOMImplementation("LS"); LSSerializer writer = impl.createLSSerializer(); LSOutput output = impl.createLSOutput(); output.setByteStream(baos); writer.write(dom, output); return baos.toByteArray(); }
/** * registers bunch of node path's specified in the XML schema (XSD) * * @param model String; schema in plain text * @throws BagriException in case of any error */ @Override public void registerModel(String model) throws BagriException { XSImplementation impl = (XSImplementation) new DOMXSImplementationSourceImpl().getDOMImplementation("XS-Loader LS"); XSLoader schemaLoader = impl.createXSLoader(null); LSInput lsi = ((DOMImplementationLS) impl).createLSInput(); lsi.setStringData(model); XSModel schema = schemaLoader.load(lsi); processModel(schema); }