Search in sources :

Example 36 with XSOMParser

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

the class FileService method writeXML.

private void writeXML(File file, Value value, boolean append, String schemaFilename, String doctypeSystem, String encoding, boolean indent) throws IOException {
    if (value.children().isEmpty()) {
        // TODO: perhaps we should erase the content of the file before returning.
        return;
    }
    String rootName = value.children().keySet().iterator().next();
    Value root = value.children().get(rootName).get(0);
    String rootNameSpace = "";
    if (root.hasChildren(NAMESPACE_ATTRIBUTE_NAME)) {
        rootNameSpace = root.getFirstChild(NAMESPACE_ATTRIBUTE_NAME).strValue();
    }
    try {
        // XSType type = null;
        if (schemaFilename != null) {
            try {
                XSOMParser parser = new XSOMParser();
                parser.parse(schemaFilename);
                XSSchemaSet schemaSet = parser.getResult();
                // } else
                if (schemaSet == null || schemaSet.getElementDecl(rootNameSpace, rootName) == null) {
                    throw new IOException("Root element " + rootName + " with namespace " + rootNameSpace + " not found in the schema " + schemaFilename);
                // System.out.println( "Root element " + rootName + " with namespace " + rootNameSpace
                // + " not found in the schema " + schemaFilename );
                }
            } catch (SAXException e) {
                throw new IOException(e);
            }
        }
        Document doc = documentBuilderFactory.newDocumentBuilder().newDocument();
        Transformer transformer = transformerFactory.newTransformer();
        jolie.xml.XmlUtils.configTransformer(transformer, encoding, doctypeSystem, indent);
        jolie.xml.XmlUtils.valueToDocument(value, doc, schemaFilename);
        try (Writer writer = new FileWriter(file, append)) {
            StreamResult result = new StreamResult(writer);
            transformer.transform(new DOMSource(doc), result);
        }
    } catch (ParserConfigurationException | TransformerException e) {
        throw new IOException(e);
    }
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) XSOMParser(com.sun.xml.xsom.parser.XSOMParser) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) XSSchemaSet(com.sun.xml.xsom.XSSchemaSet) FileWriter(java.io.FileWriter) IOException(java.io.IOException) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException) Value(jolie.runtime.Value) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) FileWriter(java.io.FileWriter) TransformerException(javax.xml.transform.TransformerException)

Example 37 with XSOMParser

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

the class SoapProtocol method getSchemaSet.

private XSSchemaSet getSchemaSet() throws IOException, SAXException {
    if (schemaSet == null) {
        XSOMParser schemaParser = new XSOMParser();
        ValueVector vec = getParameterVector("schema");
        if (vec.size() > 0) {
            for (Value v : vec) {
                schemaParser.parse(new File(v.strValue()));
            }
        }
        parseWSDLTypes(schemaParser);
        schemaSet = schemaParser.getResult();
        String nsPrefix = "jolie";
        int i = 1;
        for (XSSchema schema : schemaSet.getSchemas()) {
            if (!schema.getTargetNamespace().equals(XMLConstants.W3C_XML_SCHEMA_NS_URI)) {
                namespacePrefixMap.put(schema.getTargetNamespace(), nsPrefix + i++);
            }
        }
    }
    return schemaSet;
}
Also used : ValueVector(jolie.runtime.ValueVector) XSOMParser(com.sun.xml.xsom.parser.XSOMParser) Value(jolie.runtime.Value) File(java.io.File) XSSchema(com.sun.xml.xsom.XSSchema)

Example 38 with XSOMParser

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

the class SchemaParserUtil method parseXSDSchema.

public static XSSchemaSet parseXSDSchema(File file) {
    XSOMParser parser = new XSOMParser();
    try {
        parser.setAnnotationParser(new XSDAnnotationFactory());
        parser.parse(file);
        return parser.getResult();
    } catch (SAXException e) {
        String eMessage = "Failed to parse XSD-schema from file: " + file.getAbsolutePath();
        log.error(e, eMessage);
        throw new ConnectorIOException(eMessage, e);
    } catch (IOException e) {
        String eMessage = "Failed to read from file: " + file.getAbsolutePath();
        log.error(e, eMessage);
        throw new ConnectorIOException(eMessage, e);
    }
}
Also used : ConnectorIOException(org.identityconnectors.framework.common.exceptions.ConnectorIOException) XSDAnnotationFactory(org.forgerock.openicf.connectors.xml.xsdparser.XSDAnnotationFactory) XSOMParser(com.sun.xml.xsom.parser.XSOMParser) IOException(java.io.IOException) ConnectorIOException(org.identityconnectors.framework.common.exceptions.ConnectorIOException) 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