Search in sources :

Example 1 with StringElementContentComparator

use of org.eclipse.wst.xml.core.internal.contentmodel.internal.util.CMValidator.StringElementContentComparator 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");
    }
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) StringElementContentComparator(org.eclipse.wst.xml.core.internal.contentmodel.internal.util.CMValidator.StringElementContentComparator) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) CMValidator(org.eclipse.wst.xml.core.internal.contentmodel.internal.util.CMValidator) ElementPathRecordingResult(org.eclipse.wst.xml.core.internal.contentmodel.internal.util.CMValidator.ElementPathRecordingResult) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)

Aggregations

CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)1 CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)1 CMNamedNodeMap (org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)1 CMNode (org.eclipse.wst.xml.core.internal.contentmodel.CMNode)1 CMValidator (org.eclipse.wst.xml.core.internal.contentmodel.internal.util.CMValidator)1 ElementPathRecordingResult (org.eclipse.wst.xml.core.internal.contentmodel.internal.util.CMValidator.ElementPathRecordingResult)1 StringElementContentComparator (org.eclipse.wst.xml.core.internal.contentmodel.internal.util.CMValidator.StringElementContentComparator)1