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