Search in sources :

Example 1 with DomAnnotationParserFactory

use of com.sun.xml.xsom.util.DomAnnotationParserFactory in project atlasmap by atlasmap.

the class AtlasXmlSchemaSetParser method createXSOMParser.

private XSOMParser createXSOMParser() {
    XSOMParser parser = new XSOMParser(this.saxParserFactory);
    parser.setEntityResolver(new XSOMClasspathEntityResolver(this.classLoader));
    parser.setAnnotationParser(new DomAnnotationParserFactory());
    parser.setErrorHandler(new XSOMErrorHandler());
    return parser;
}
Also used : XSOMParser(com.sun.xml.xsom.parser.XSOMParser) DomAnnotationParserFactory(com.sun.xml.xsom.util.DomAnnotationParserFactory)

Example 2 with DomAnnotationParserFactory

use of com.sun.xml.xsom.util.DomAnnotationParserFactory in project atlasmap by atlasmap.

the class TreeDumper method main.

public static void main(String[] args) throws Exception {
    if (args.length != 1) {
        System.out.println("Please provide a single (root) schema location");
        System.exit(0);
    }
    XSOMParser reader = new XSOMParser();
    // set an error handler so that you can receive error messages
    reader.setErrorHandler(new ErrorReporter(System.out));
    // DomAnnotationParserFactory is a convenient default to use
    reader.setAnnotationParser(new DomAnnotationParserFactory());
    try {
        reader.parse(new File(args[0]));
        XSSchemaSet xss = reader.getResult();
        if (xss == null) {
            System.out.println("error");
        } else {
            SchemaTreeTraverser stt = new SchemaTreeTraverser();
            stt.visit(xss);
            TreeModel model = stt.getModel();
            JTree tree = new JTree(model);
            tree.setCellRenderer(new SchemaTreeTraverser.SchemaTreeCellRenderer());
            TreeDumper dumper = new TreeDumper(args[0], tree);
            Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize();
            // dumper.setPreferredSize(screenDim);
            dumper.setSize(screenDim);
            dumper.setVisible(true);
        }
    } catch (SAXException e) {
        if (e.getException() != null) {
            e.getException().printStackTrace();
        } else {
            e.printStackTrace();
        }
        throw e;
    }
}
Also used : SchemaTreeTraverser(com.sun.xml.xsom.impl.util.SchemaTreeTraverser) TreeModel(javax.swing.tree.TreeModel) XSOMParser(com.sun.xml.xsom.parser.XSOMParser) XSSchemaSet(com.sun.xml.xsom.XSSchemaSet) DomAnnotationParserFactory(com.sun.xml.xsom.util.DomAnnotationParserFactory) File(java.io.File) SAXException(org.xml.sax.SAXException)

Example 3 with DomAnnotationParserFactory

use of com.sun.xml.xsom.util.DomAnnotationParserFactory in project midpoint by Evolveum.

the class DomToSchemaProcessor method createSchemaParser.

private XSOMParser createSchemaParser() {
    XSOMParser parser = new XSOMParser();
    if (entityResolver == null) {
        entityResolver = prismContext.getEntityResolver();
        if (entityResolver == null) {
            throw new IllegalStateException("Entity resolver is not set (even tried to pull it from prism context)");
        }
    }
    SchemaHandler errorHandler = new SchemaHandler(entityResolver);
    parser.setErrorHandler(errorHandler);
    parser.setAnnotationParser(new DomAnnotationParserFactory());
    parser.setEntityResolver(errorHandler);
    return parser;
}
Also used : XSOMParser(com.sun.xml.xsom.parser.XSOMParser) DomAnnotationParserFactory(com.sun.xml.xsom.util.DomAnnotationParserFactory)

Example 4 with DomAnnotationParserFactory

use of com.sun.xml.xsom.util.DomAnnotationParserFactory in project atlasmap by atlasmap.

the class SchemaInspector method doInspect.

private void doInspect(InputStream is) throws Exception {
    xmlDocument = AtlasXmlModelFactory.createXmlDocument();
    Fields fields = new Fields();
    xmlDocument.setFields(fields);
    namespaceContext = new AtlasXmlNamespaceContext();
    rootNamespace = null;
    XSOMParser parser = new XSOMParser(SAXParserFactory.newInstance());
    parser.setAnnotationParser(new DomAnnotationParserFactory());
    parser.setErrorHandler(new XSOMErrorHandler());
    Transformer transformer = TransformerFactory.newInstance().newTransformer();
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);
    Document doc = dbf.newDocumentBuilder().parse(is);
    Element root = doc.getDocumentElement();
    if (root == null) {
        throw new XmlInspectionException("XML schema document is empty");
    } else if ("SchemaSet".equals(root.getLocalName())) {
        XPath xpath = XPathFactory.newInstance().newXPath();
        xpath.setNamespaceContext(namespaceContext);
        NodeList subSchemas = (NodeList) xpath.evaluate(String.format("/%s:SchemaSet/%s:AdditionalSchemas/%s:schema", NS_PREFIX_SCHEMASET, NS_PREFIX_SCHEMASET, NS_PREFIX_XMLSCHEMA), doc, XPathConstants.NODESET);
        for (int i = 0; i < subSchemas.getLength(); i++) {
            Element e = (Element) subSchemas.item(i);
            inheritNamespaces(e, false);
            parser.parse(toInputStream(transformer, e));
        }
        Element rootSchema = (Element) xpath.evaluate(String.format("/%s:SchemaSet/%s:schema", NS_PREFIX_SCHEMASET, NS_PREFIX_XMLSCHEMA), doc, XPathConstants.NODE);
        if (rootSchema == null) {
            throw new XmlInspectionException("The root schema '/SchemaSet/schema' must be specified once and only once");
        }
        rootNamespace = getTargetNamespace(rootSchema);
        if (rootNamespace != null && !rootNamespace.isEmpty()) {
            namespaceContext.add("tns", rootNamespace);
        }
        inheritNamespaces(rootSchema, true);
        parser.parse(toInputStream(transformer, rootSchema));
    } else if ("schema".equals(root.getLocalName())) {
        parser.parse(toInputStream(transformer, root));
        rootNamespace = getTargetNamespace(root);
        if (rootNamespace != null && !rootNamespace.isEmpty()) {
            namespaceContext.add("tns", rootNamespace);
        }
    } else {
        throw new XmlInspectionException(String.format("Unsupported document element '%s': root element must be 'schema' or 'SchemaSet'", root.getLocalName()));
    }
    XSSchemaSet schemaSet = parser.getResult();
    printSchemaSet(schemaSet);
    populateNamespaces();
}
Also used : XPath(javax.xml.xpath.XPath) XSOMParser(com.sun.xml.xsom.parser.XSOMParser) Transformer(javax.xml.transform.Transformer) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) XSSchemaSet(com.sun.xml.xsom.XSSchemaSet) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Document(org.w3c.dom.Document) XmlDocument(io.atlasmap.xml.v2.XmlDocument) XmlFields(io.atlasmap.xml.v2.XmlFields) Fields(io.atlasmap.v2.Fields) DomAnnotationParserFactory(com.sun.xml.xsom.util.DomAnnotationParserFactory)

Example 5 with DomAnnotationParserFactory

use of com.sun.xml.xsom.util.DomAnnotationParserFactory in project atlasmap by atlasmap.

the class Dumper method main.

public static void main(String[] args) throws Exception {
    XSOMParser reader = new XSOMParser();
    // set an error handler so that you can receive error messages
    reader.setErrorHandler(new ErrorReporter(System.out));
    // DomAnnotationParserFactory is a convenient default to use
    reader.setAnnotationParser(new DomAnnotationParserFactory());
    try {
        // the parse method can by called many times
        for (int i = 0; i < args.length; i++) reader.parse(new File(args[i]));
        XSSchemaSet xss = reader.getResult();
        if (xss == null)
            System.out.println("error");
        else
            new SchemaWriter(new OutputStreamWriter(System.out)).visit(xss);
        dump(reader.getDocuments());
    } catch (SAXException e) {
        if (e.getException() != null)
            e.getException().printStackTrace();
        else
            e.printStackTrace();
        throw e;
    }
}
Also used : XSOMParser(com.sun.xml.xsom.parser.XSOMParser) XSSchemaSet(com.sun.xml.xsom.XSSchemaSet) DomAnnotationParserFactory(com.sun.xml.xsom.util.DomAnnotationParserFactory) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) SchemaWriter(com.sun.xml.xsom.impl.util.SchemaWriter) SAXException(org.xml.sax.SAXException)

Aggregations

XSOMParser (com.sun.xml.xsom.parser.XSOMParser)5 DomAnnotationParserFactory (com.sun.xml.xsom.util.DomAnnotationParserFactory)5 XSSchemaSet (com.sun.xml.xsom.XSSchemaSet)3 File (java.io.File)2 SAXException (org.xml.sax.SAXException)2 SchemaTreeTraverser (com.sun.xml.xsom.impl.util.SchemaTreeTraverser)1 SchemaWriter (com.sun.xml.xsom.impl.util.SchemaWriter)1 Fields (io.atlasmap.v2.Fields)1 XmlDocument (io.atlasmap.xml.v2.XmlDocument)1 XmlFields (io.atlasmap.xml.v2.XmlFields)1 OutputStreamWriter (java.io.OutputStreamWriter)1 TreeModel (javax.swing.tree.TreeModel)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 Transformer (javax.xml.transform.Transformer)1 XPath (javax.xml.xpath.XPath)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1 NodeList (org.w3c.dom.NodeList)1