Search in sources :

Example 31 with CMDocument

use of org.eclipse.wst.xml.core.internal.contentmodel.CMDocument in project webtools.sourceediting by eclipse.

the class NewXMLGenerator method createCMDocument.

public static CMDocument createCMDocument(String uri, String[] errorInfo) {
    String title = null;
    String message = null;
    List errorList = new Vector();
    CMDocument cmDocument = null;
    if (URIHelper.isReadableURI(uri, true)) {
        // (cs) assume the uri has been provided in a normalized form
        cmDocument = ContentModelManager.getInstance().createCMDocument(uri, null);
        if (uri.endsWith(".dtd")) {
            // $NON-NLS-1$
            if (errorList.size() > 0) {
                title = XMLWizardsMessages._UI_INVALID_GRAMMAR_ERROR;
                message = XMLWizardsMessages._UI_LABEL_ERROR_DTD_INVALID_INFO;
            }
        } else // ".xsd"
        {
            // To be consistent with the schema editor validation
            XMLSchemaValidationChecker validator = new XMLSchemaValidationChecker();
            if (!validator.isValid(uri)) {
                title = XMLWizardsMessages._UI_INVALID_GRAMMAR_ERROR;
                message = XMLWizardsMessages._UI_LABEL_ERROR_SCHEMA_INVALID_INFO;
            } else if (cmDocument != null) {
                int globalElementCount = cmDocument.getElements().getLength();
                if (globalElementCount == 0) {
                    title = XMLWizardsMessages._UI_WARNING_TITLE_NO_ROOT_ELEMENTS;
                    message = XMLWizardsMessages._UI_WARNING_MSG_NO_ROOT_ELEMENTS;
                }
            }
        }
    } else {
        title = XMLWizardsMessages._UI_WARNING_TITLE_NO_ROOT_ELEMENTS;
        // $NON-NLS-1$
        message = XMLWizardsMessages._UI_WARNING_URI_NOT_FOUND_COLON + " " + uri;
    }
    errorInfo[0] = title;
    errorInfo[1] = message;
    return cmDocument;
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) List(java.util.List) Vector(java.util.Vector)

Example 32 with CMDocument

use of org.eclipse.wst.xml.core.internal.contentmodel.CMDocument in project webtools.sourceediting by eclipse.

the class GlobalCMDocumentCacheTest method testGlobalCMDocumentCacheEnabled.

/*
	 * Test description:
	 *  - Enable global cache.
	 *  - Schema GlobalCMDocumentCacheTestSchema.xsd is contributed to the system catalog.
	 *  - Load documents "GlobalCMDocumentCacheTest1.xml" and "GlobalCMDocumentCacheTest1.xml".
	 *  - Verify that the associated CMDocuments are the same (cached).
	 *  - Load documents "document1.xml" and "document2.xml" (local schema, not in catalog).  
	 *  - Verify that the associated CMDocuments are different (not cached, as the schema is not in system catalog).
	 */
public void testGlobalCMDocumentCacheEnabled() {
    // Ensure the global cache is disabled.
    setGlobalCacheEnabled(true);
    // Load "web1.xml" and "web2.xml"
    // $NON-NLS-1$
    CMDocument globalCMDocumentCacheTest_1 = getCMDocumentFromXMLFile(PROJECT_NAME + "/GlobalCMDocumentCacheTest1.xml");
    // $NON-NLS-1$
    CMDocument globalCMDocumentCacheTest_2 = getCMDocumentFromXMLFile(PROJECT_NAME + "/GlobalCMDocumentCacheTest2.xml");
    // Ensure CMDocuments are different.
    assertEquals(globalCMDocumentCacheTest_1, globalCMDocumentCacheTest_2);
    // Load "document1.xml" and "document2.xml"
    // $NON-NLS-1$
    CMDocument localCMDocument_1 = getCMDocumentFromXMLFile(PROJECT_NAME + "/document1.xml");
    // $NON-NLS-1$
    CMDocument localCMDocument_2 = getCMDocumentFromXMLFile(PROJECT_NAME + "/document2.xml");
    // Ensure CMDocuments are different.
    assertNotSame(localCMDocument_1, localCMDocument_2);
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)

Example 33 with CMDocument

use of org.eclipse.wst.xml.core.internal.contentmodel.CMDocument in project webtools.sourceediting by eclipse.

the class CMPrinter method getProperties.

public List getProperties(CMNode cmnode) {
    List properties = new Vector();
    if (cmnode != null) {
        // $NON-NLS-1$
        properties.add("CMDocument");
        // $NON-NLS-1$
        properties.add("documentation");
        // $NON-NLS-1$
        properties.add("http://org.eclipse.wst/cm/properties/usesLocalElementDeclarations");
        // $NON-NLS-1$
        properties.add("http://org.eclipse.wst/cm/properties/isNameSpaceAware");
        // $NON-NLS-1$
        properties.add("http://org.eclipse.wst/cm/properties/nsPrefixQualification");
        // $NON-NLS-1$
        properties.add("http://org.eclipse.wst/cm/properties/nillable");
        // $NON-NLS-1$
        properties.add("http://org.eclipse.wst/cm/properties/mofNotifier");
        // $NON-NLS-1$
        properties.add("spec");
        if (cmnode instanceof CMElementDeclaration) {
            // $NON-NLS-1$
            properties.add("http://org.eclipse.wst/cm/properties/definitionInfo");
            // $NON-NLS-1$
            properties.add("http://org.eclipse.wst/cm/properties/definition");
            // $NON-NLS-1$
            properties.add("XSITypes");
            // $NON-NLS-1$
            properties.add("DerivedElementDeclaration");
            // properties.add("SubstitutionGroup"); Currrently broken for nexted xsd files
            // $NON-NLS-1$
            properties.add("Abstract");
        }
        if (cmnode instanceof CMDocument) {
            // $NON-NLS-1$
            properties.add("http://org.eclipse.wst/cm/properties/targetNamespaceURI");
            // $NON-NLS-1$
            properties.add("http://org.eclipse.wst/cm/properties/importedNamespaceInfo");
            // $NON-NLS-1$
            properties.add("http://org.eclipse.wst/cm/properties/namespaceInfo");
            // $NON-NLS-1$
            properties.add("http://org.eclipse.wst/cm/properties/elementFormDefault");
            // $NON-NLS-1$
            properties.add("annotationMap");
        }
    }
    return properties;
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) List(java.util.List) CMNodeList(org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList) Vector(java.util.Vector)

Example 34 with CMDocument

use of org.eclipse.wst.xml.core.internal.contentmodel.CMDocument 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)

Example 35 with CMDocument

use of org.eclipse.wst.xml.core.internal.contentmodel.CMDocument in project webtools.sourceediting by eclipse.

the class AbstractXMLModelQueryCompletionProposalComputer method computeEntityReferenceProposals.

/**
 * return all possible EntityReferenceProposals (according to current
 * position in doc)
 */
private ICompletionProposal[] computeEntityReferenceProposals(ITextRegion completionRegion, IDOMNode treeNode, CompletionProposalInvocationContext context) {
    // only handle XML content for now
    int documentPosition = context.getInvocationOffset();
    // ICompletionProposals
    Vector proposals = new Vector();
    IStructuredDocumentRegion sdRegion = ContentAssistUtils.getStructuredDocumentRegion(context.getViewer(), context.getInvocationOffset());
    if ((completionRegion != null) && (completionRegion.getType() == DOMRegionContext.XML_CONTENT)) {
        int nodeOffset = documentPosition - sdRegion.getStartOffset(completionRegion);
        String regionText = sdRegion.getFullText(completionRegion);
        // the previous region...there might be a better way to do this
        if ((regionText != null) && regionText.trim().equals("") && (documentPosition > 0)) {
            // $NON-NLS-1$
            IStructuredDocumentRegion prev = treeNode.getStructuredDocument().getRegionAtCharacterOffset(documentPosition - 1);
            if ((prev != null) && prev.getText().equals("&")) {
                // $NON-NLS-1$
                // https://bugs.eclipse.org/bugs/show_bug.cgi?id=206680
                // examine previous region
                sdRegion = prev;
                completionRegion = prev.getLastRegion();
                regionText = prev.getFullText();
                nodeOffset = 1;
            }
        }
        // string must start w/ &
        if ((regionText != null) && regionText.startsWith("&")) {
            // $NON-NLS-1$
            // $NON-NLS-1$
            String key = (nodeOffset > 0) ? regionText.substring(1, nodeOffset) : "";
            // get entity proposals, passing in the appropriate start
            // string
            ModelQuery mq = ModelQueryUtil.getModelQuery(((Node) treeNode).getOwnerDocument());
            if (mq != null) {
                CMDocument xmlDoc = mq.getCorrespondingCMDocument(treeNode);
                CMNamedNodeMap cmmap = null;
                Properties entities = null;
                if (xmlDoc != null) {
                    cmmap = xmlDoc.getEntities();
                }
                if (cmmap != null) {
                    entities = mapToProperties(cmmap);
                } else // 224787 in absence of content model, just use
                // minimal 5 entities
                {
                    entities = new Properties();
                    // $NON-NLS-1$ //$NON-NLS-2$
                    entities.put("quot", "\"");
                    // $NON-NLS-1$ //$NON-NLS-2$
                    entities.put("apos", "'");
                    // $NON-NLS-1$ //$NON-NLS-2$
                    entities.put("amp", "&");
                    // $NON-NLS-1$ //$NON-NLS-2$
                    entities.put("lt", "<");
                    // $NON-NLS-1$ //$NON-NLS-2$
                    entities.put("gt", ">");
                    // $NON-NLS-1$ //$NON-NLS-2$
                    entities.put("nbsp", " ");
                }
                addEntityProposals(proposals, entities, key, nodeOffset, sdRegion, completionRegion, context);
            }
        }
    }
    return (ICompletionProposal[]) ((proposals.size() > 0) ? proposals.toArray(new ICompletionProposal[proposals.size()]) : null);
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap) Properties(java.util.Properties) Vector(java.util.Vector)

Aggregations

CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)83 CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)33 CMNamedNodeMap (org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)26 CMNode (org.eclipse.wst.xml.core.internal.contentmodel.CMNode)20 List (java.util.List)15 ModelQuery (org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)14 Document (org.w3c.dom.Document)12 Element (org.w3c.dom.Element)11 ArrayList (java.util.ArrayList)10 Path (org.eclipse.core.runtime.Path)8 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)8 JSPCMDocument (org.eclipse.wst.html.core.internal.contentmodel.JSPCMDocument)7 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)7 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)7 URL (java.net.URL)6 TLDCMDocumentManager (org.eclipse.jst.jsp.core.internal.contentmodel.tld.TLDCMDocumentManager)6 Node (org.w3c.dom.Node)6 NodeList (org.w3c.dom.NodeList)6 Iterator (java.util.Iterator)5 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)5