use of org.eclipse.wst.xml.core.internal.contentmodel.internal.util.CMValidator in project webtools.sourceediting by eclipse.
the class CMValidatorTest method main.
public static void main(String[] arg) {
if (arg.length > 1) {
try {
// CMDocumentFactoryRegistry.getInstance().registerCMDocumentBuilderWithClassName("org.eclipse.wst.xml.core.internal.contentmodel.mofimpl.CMDocumentBuilderImpl");
String grammarFileName = arg[0];
String elementName = arg[1];
CMDocument cmDocument = ContentModelManager.getInstance().createCMDocument(grammarFileName, null);
CMNamedNodeMap elementMap = cmDocument.getElements();
CMElementDeclaration element = (CMElementDeclaration) elementMap.getNamedItem(elementName);
if (element != null) {
/*
println("found element [" + elementName + "] contentType = " + element.getContentType());
GraphNode graphNode = createGraph(element);
printGraph(graphNode);
*/
// $NON-NLS-1$
println("-------------- begin validate ---------------");
StringElementContentComparator comparator = new StringElementContentComparator();
CMValidator validator = new CMValidator();
ElementPathRecordingResult result = new ElementPathRecordingResult();
validator.getOriginArray(element, CMValidator.createStringList(arg, 2), comparator, result);
if (result.isValid) {
CMNode[] nodeMapping = result.getOriginArray();
// $NON-NLS-1$
println("Validation Success!");
// $NON-NLS-1$
print(" ");
for (int i = 0; i < nodeMapping.length; i++) {
// $NON-NLS-1$
String name = nodeMapping[i] != null ? nodeMapping[i].getNodeName() : "null";
// $NON-NLS-1$ //$NON-NLS-2$
print("[" + name + "]");
}
// $NON-NLS-1$
println("");
} else {
// $NON-NLS-1$
println("Validation Failed! ");
if (result.errorMessage != null) {
// $NON-NLS-1$
println(" " + result.errorMessage);
}
}
// $NON-NLS-1$
println("-------------- end validate ---------------");
} else {
// $NON-NLS-1$ //$NON-NLS-2$
println("element [" + elementName + "] can not be found");
}
} catch (Exception e) {
// $NON-NLS-1$
println("CMValidator error");
e.printStackTrace();
}
} else {
// $NON-NLS-1$ //$NON-NLS-2$
println("2 args required... only " + arg.length + " provided");
// $NON-NLS-1$
println("usage java org.eclipse.wst.newxml.util.XMLUtil grammarFileName rootElementName pattern");
}
}
Aggregations