Search in sources :

Example 26 with XSOMParser

use of com.sun.xml.xsom.parser.XSOMParser in project schema2proto by entur.

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)

Example 27 with XSOMParser

use of com.sun.xml.xsom.parser.XSOMParser in project schema2proto by entur.

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 28 with XSOMParser

use of com.sun.xml.xsom.parser.XSOMParser in project schema2proto by entur.

the class XSOMParserTest method setUp.

protected void setUp() throws Exception {
    if (docURL == null) {
        docURL = new URL(docURLStr);
        instance = new XSOMParser();
    }
}
Also used : XSOMParser(com.sun.xml.xsom.parser.XSOMParser) URL(java.net.URL)

Example 29 with XSOMParser

use of com.sun.xml.xsom.parser.XSOMParser in project schema2proto by entur.

the class SchemaParser method parse.

public Map<String, ProtoFile> parse() throws SAXException, IOException {
    // Needs fix inside XSOM package
    @SuppressWarnings("java:S2755") SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
    saxParserFactory.setNamespaceAware(true);
    XSOMParser parser = new XSOMParser(saxParserFactory);
    parser.setErrorHandler(this);
    parser.setAnnotationParser(new DomAnnotationParserFactory());
    parser.parse(configuration.xsdFile);
    processSchemaSet(parser.getResult());
    return packageToProtoFileMap;
}
Also used : XSOMParser(com.sun.xml.xsom.parser.XSOMParser) DomAnnotationParserFactory(com.sun.xml.xsom.util.DomAnnotationParserFactory) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Example 30 with XSOMParser

use of com.sun.xml.xsom.parser.XSOMParser in project jolie by jolie.

the class XmlUtils method valueToDocument.

public static void valueToDocument(Value value, Document document, String schemaFilename) throws IOException {
    String rootName = value.children().keySet().iterator().next();
    Value root = value.children().get(rootName).get(0);
    String rootNameSpace = "";
    if (root.hasChildren(jolie.xml.XmlUtils.NAMESPACE_ATTRIBUTE_NAME)) {
        rootNameSpace = root.getFirstChild(jolie.xml.XmlUtils.NAMESPACE_ATTRIBUTE_NAME).strValue();
    }
    XSType type = null;
    if (schemaFilename != null) {
        try {
            XSOMParser parser = new XSOMParser();
            parser.parse(schemaFilename);
            XSSchemaSet schemaSet = parser.getResult();
            if (schemaSet != null && schemaSet.getElementDecl(rootNameSpace, rootName) != null) {
                type = schemaSet.getElementDecl(rootNameSpace, rootName).getType();
            } else if (schemaSet != null && schemaSet.getElementDecl(rootNameSpace, rootName) == null) {
                Interpreter.getInstance().logWarning("Root element " + rootName + " with namespace " + rootNameSpace + " not found in the schema " + schemaFilename);
            }
        } catch (SAXException e) {
            throw new IOException(e);
        }
    }
    if (type == null) {
        valueToDocument(value.getFirstChild(rootName), rootName, document);
    } else {
        valueToDocument(value.getFirstChild(rootName), rootName, document, type);
    }
}
Also used : XSType(com.sun.xml.xsom.XSType) XSOMParser(com.sun.xml.xsom.parser.XSOMParser) XSSchemaSet(com.sun.xml.xsom.XSSchemaSet) Value(jolie.runtime.Value) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException)

Aggregations

XSOMParser (com.sun.xml.xsom.parser.XSOMParser)38 XSSchemaSet (com.sun.xml.xsom.XSSchemaSet)15 SAXException (org.xml.sax.SAXException)14 DomAnnotationParserFactory (com.sun.xml.xsom.util.DomAnnotationParserFactory)10 File (java.io.File)9 InputSource (org.xml.sax.InputSource)7 IOException (java.io.IOException)5 XSSchema (com.sun.xml.xsom.XSSchema)4 OutputStreamWriter (java.io.OutputStreamWriter)4 URL (java.net.URL)4 SAXParserFactory (javax.xml.parsers.SAXParserFactory)4 Transformer (javax.xml.transform.Transformer)4 Document (org.w3c.dom.Document)4 SchemaTreeTraverser (com.sun.xml.xsom.impl.util.SchemaTreeTraverser)3 SchemaWriter (com.sun.xml.xsom.impl.util.SchemaWriter)3 ComponentNameFunction (com.sun.xml.xsom.util.ComponentNameFunction)3 TreeModel (javax.swing.tree.TreeModel)3 DOMSource (javax.xml.transform.dom.DOMSource)3 StreamResult (javax.xml.transform.stream.StreamResult)3 Value (jolie.runtime.Value)3