List of usage examples for org.w3c.dom.bootstrap DOMImplementationRegistry PROPERTY
String PROPERTY
To view the source code for org.w3c.dom.bootstrap DOMImplementationRegistry PROPERTY.
Click Source Link
From source file:org.alfresco.web.forms.xforms.SchemaUtil.java
public static XSModel parseSchema(final Document schemaDocument, final boolean failOnError) throws FormBuilderException { try {/*from w ww . ja va 2 s . c o m*/ // Get DOM Implementation using DOM Registry System.setProperty(DOMImplementationRegistry.PROPERTY, "org.apache.xerces.dom.DOMXSImplementationSourceImpl"); final DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); final DOMImplementationLS lsImpl = (DOMImplementationLS) registry .getDOMImplementation("XML 1.0 LS 3.0"); if (lsImpl == null) { throw new FormBuilderException("unable to create DOMImplementationLS using " + registry); } final LSInput in = lsImpl.createLSInput(); in.setStringData(XMLUtil.toString(schemaDocument)); final XSImplementation xsImpl = (XSImplementation) registry.getDOMImplementation("XS-Loader"); final XSLoader schemaLoader = xsImpl.createXSLoader(null); final DOMConfiguration config = (DOMConfiguration) schemaLoader.getConfig(); final LinkedList<DOMError> errors = new LinkedList<DOMError>(); config.setParameter("error-handler", new DOMErrorHandler() { public boolean handleError(final DOMError domError) { errors.add(domError); return true; } }); final XSModel result = schemaLoader.load(in); if (failOnError && errors.size() != 0) { final HashSet<String> messages = new HashSet<String>(); StringBuilder message = null; for (DOMError e : errors) { message = new StringBuilder(); final DOMLocator dl = e.getLocation(); if (dl != null) { message.append("at line ").append(dl.getLineNumber()).append(" column ") .append(dl.getColumnNumber()); if (dl.getRelatedNode() != null) { message.append(" node ").append(dl.getRelatedNode().getNodeName()); } message.append(": ").append(e.getMessage()); } messages.add(message.toString()); } message = new StringBuilder(); message.append(messages.size() > 1 ? "errors" : "error").append(" parsing schema: \n"); for (final String s : messages) { message.append(s).append("\n"); } throw new FormBuilderException(message.toString()); } if (result == null) { throw new FormBuilderException("invalid schema"); } return result; } catch (ClassNotFoundException x) { throw new FormBuilderException(x); } catch (InstantiationException x) { throw new FormBuilderException(x); } catch (IllegalAccessException x) { throw new FormBuilderException(x); } }
From source file:org.chiba.tools.schemabuilder.AbstractSchemaFormBuilder.java
private void loadSchema(String inputURI) throws java.lang.ClassNotFoundException, java.lang.InstantiationException, java.lang.IllegalAccessException { // Get DOM Implementation using DOM Registry System.setProperty(DOMImplementationRegistry.PROPERTY, "org.apache.xerces.dom.DOMXSImplementationSourceImpl"); DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); Object o = registry.getDOMImplementation("XS-Loader"); if (o instanceof XSImplementation) { XSImplementation impl = (XSImplementation) o; XSLoader schemaLoader = impl.createXSLoader(null); schema = schemaLoader.loadURI(inputURI); } else if (o != null) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("DOMImplementation is not a XSImplementation: " + o.getClass().getName()); }/*from w w w. java 2 s. c o m*/ System.exit(1); } }
From source file:org.chiba.xml.xforms.core.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); return loader; }
From source file:org.deegree.tools.feature.gml.SchemaAnalyzer.java
/** * @param args//w w w. j a v a2s. com * @throws IllegalAccessException * @throws InstantiationException * @throws ClassNotFoundException * @throws ClassCastException * @throws IOException */ public static void main(String[] args) throws ClassCastException, ClassNotFoundException, InstantiationException, IllegalAccessException, IOException { Options options = initOptions(); // for the moment, using the CLI API there is no way to respond to a help argument; see https://issues.apache.org/jira/browse/CLI-179 if (args.length == 0 || (args.length > 0 && (args[0].contains("help") || args[0].contains("?")))) { printHelp(options); } try { new PosixParser().parse(options, args); String inputFileName = options.getOption(OPT_INPUT_FILE).getValue(); String namespace = options.getOption(OPT_NAMESPACE).getValue(); System.setProperty(DOMImplementationRegistry.PROPERTY, "org.apache.xerces.dom.DOMXSImplementationSourceImpl"); DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); XSImplementation impl = (XSImplementation) registry.getDOMImplementation("XS-Loader"); XSLoader schemaLoader = impl.createXSLoader(null); File inputFile = new File(inputFileName); System.out.println("Loading input schema: '" + inputFileName + "'"); XSModel schema = schemaLoader.loadURI(inputFile.toURI().toURL().toString()); SchemaAnalyzer analyzer = new SchemaAnalyzer(schema); // analyzer.printElementDeclarationSummary( "http://www.opengis.net/gml" ); String s = analyzer.getElementDeclarationSummary(namespace); System.out.println(s); } catch (ParseException exp) { System.err.println("ERROR: Invalid command line: " + exp.getMessage()); } }
From source file:org.sonar.plugins.xml.schemas.SchemaResolver.java
private static LSInput createLSInput(InputStream inputStream) { if (inputStream != null) { System.setProperty(DOMImplementationRegistry.PROPERTY, "org.apache.xerces.dom.DOMImplementationSourceImpl"); try {//w w w . ja v a 2 s. co m DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); DOMImplementation impl = registry.getDOMImplementation("XML 1.0 LS 3.0"); DOMImplementationLS implls = (DOMImplementationLS) impl; LSInput lsInput = implls.createLSInput(); lsInput.setByteStream(inputStream); return lsInput; } catch (ClassNotFoundException e) { throw new SonarException(e); } catch (InstantiationException e) { throw new SonarException(e); } catch (IllegalAccessException e) { throw new SonarException(e); } } return null; }