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);
}
}
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;
}
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);
}
}
Aggregations