Search in sources :

Example 51 with CMNamedNodeMap

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

the class BugFixesTest method testGlobalAtrributeDocumentation.

public void testGlobalAtrributeDocumentation() {
    // See bug 157254
    Bundle bundle = Platform.getBundle("org.eclipse.wst.xsd.core.tests");
    URL url = bundle.getEntry("/testresources/samples/documentation/TestAttributeRefs.xsd");
    CMDocument document = XSDImpl.buildCMDocument(url.toExternalForm());
    assertNotNull("Content model loaded Null", document);
    CMNamedNodeMap elements = document.getElements();
    CMElementDeclaration node = (CMElementDeclaration) elements.getNamedItem("object");
    assertNotNull("Missing object element", node);
    CMNamedNodeMap attributes = node.getAttributes();
    testGlobalAttr1Documentation(attributes);
    testGlobalAttr2Documentation(attributes);
    testGlobalAttr3Documentation(attributes);
    testGlobalAttr4Documentation(attributes);
    testLocalAttrDocumentation(attributes);
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) Bundle(org.osgi.framework.Bundle) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap) URL(java.net.URL)

Example 52 with CMNamedNodeMap

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

the class BugFixesTest method testBase64BinaryDefaultValue.

/**
 * See https://bugs.eclipse.org/bugs/show_bug.cgi?id=322841
 */
public void testBase64BinaryDefaultValue() {
    Bundle bundle = Platform.getBundle(XSDCoreTestsPlugin.PLUGIN_ID);
    // $NON-NLS-1$
    URL url = bundle.getEntry("/testresources/samples/base64Binary/Test.xsd");
    CMDocument cmDocument = XSDImpl.buildCMDocument(url.toExternalForm());
    assertNotNull(cmDocument);
    CMNamedNodeMap elements = cmDocument.getElements();
    // $NON-NLS-1$
    CMElementDeclaration cmElementDeclaration = (CMElementDeclaration) elements.getNamedItem("Test");
    assertNotNull(cmElementDeclaration);
    CMDataType dataType = cmElementDeclaration.getDataType();
    assertNotNull(dataType);
    String impliedValue = dataType.generateInstanceValue();
    // $NON-NLS-1$
    assertEquals("MA==", impliedValue);
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) CMDataType(org.eclipse.wst.xml.core.internal.contentmodel.CMDataType) Bundle(org.osgi.framework.Bundle) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap) URL(java.net.URL)

Example 53 with CMNamedNodeMap

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

the class CMElementDeclarationImpl method toString.

public String toString() {
    StringBuffer buffer = new StringBuffer();
    // $NON-NLS-1$
    buffer.append("\n\t " + super.toString());
    // $NON-NLS-1$
    buffer.append("\n\t name:" + StringUtils.escape(getNodeName()));
    // $NON-NLS-1$
    buffer.append("\n\t tag class:" + StringUtils.escape(getTagclass()));
    // $NON-NLS-1$
    buffer.append("\n\t tei class:" + StringUtils.escape(getTeiclass()));
    // $NON-NLS-1$
    buffer.append("\n\t body content:" + StringUtils.escape(getBodycontent()));
    // $NON-NLS-1$
    buffer.append("\n\t description (info):" + StringUtils.escape(getDescription()));
    // $NON-NLS-1$
    buffer.append("\n\t attributes:");
    CMNamedNodeMap attributes = getAttributes();
    for (int i = 0; i < attributes.getLength(); i++) {
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        buffer.append("\n\t\t" + StringUtils.replace(attributes.item(i).toString(), "\n", "\n\t\t"));
    }
    // $NON-NLS-1$
    buffer.append("\n\t variables:");
    for (int i = 0; i < getVariables().size(); i++) {
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        buffer.append("\n\t\t" + StringUtils.replace(getVariables().get(i).toString(), "\n", "\n\t\t"));
    }
    return buffer.toString();
}
Also used : CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)

Example 54 with CMNamedNodeMap

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

the class CommentElementHandlerForSSI method createElement.

public Element createElement(Document document, String data, boolean isJSPTag) {
    ModelQuery modelQuery = ModelQueryUtil.getModelQuery(document);
    if (modelQuery == null) {
        return null;
    }
    CMDocument cm = modelQuery.getCorrespondingCMDocument(document);
    if (cm == null) {
        return null;
    }
    CMNamedNodeMap map = cm.getElements();
    if (map == null) {
        return null;
    }
    TagScanner scanner = new TagScanner(data, 1);
    String name = scanner.nextName();
    if (name == null) {
        return null;
    }
    StringBuffer buffer = new StringBuffer(name.length() + 4);
    buffer.append(SSI_PREFIX);
    buffer.append(':');
    buffer.append(name);
    String tagName = buffer.toString();
    // check if valid (defined) SSI tag or not
    if (map.getNamedItem(tagName) == null) {
        return null;
    }
    CommentElementFactory factory = new CommentElementFactory(document, isJSPTag, this);
    Element element = factory.create(tagName, CommentElementFactory.IS_START);
    // set attributes
    String attrName = scanner.nextName();
    while (attrName != null) {
        String attrValue = scanner.nextValue();
        Attr attr = document.createAttribute(attrName);
        if (attr != null) {
            if (attrValue != null)
                attr.setValue(attrValue);
            element.setAttributeNode(attr);
        }
        attrName = scanner.nextName();
    }
    return element;
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) CommentElementFactory(org.eclipse.wst.xml.core.internal.commentelement.util.CommentElementFactory) Element(org.w3c.dom.Element) IDOMElement(org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery) TagScanner(org.eclipse.wst.xml.core.internal.commentelement.util.TagScanner) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap) Attr(org.w3c.dom.Attr)

Example 55 with CMNamedNodeMap

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

the class LibraryTagsCompletionProposalComputer method forciblyGetTagLibAndJSPElements.

/**
 * <p><b>NOTE: </b>This should be removed as soon as Bug 311961 is fixed</p>
 * <p>This is bad because it does not use the ModelQuery framework, it
 * access the TLDCMDocumentManager directly</p>
 * <p>This is essentially a combination of the {@link TaglibModelQueryExtension} and
 * the {@link JSPModelQueryExtension} but it means any other extensions get left
 * out when creating content assist suggestion at the document root level</p>
 *
 * @param elementDecls
 * @param node
 * @param childIndex
 * @return
 */
private List forciblyGetTagLibAndJSPElements(List elementDecls, Node node, int childIndex) {
    if (node instanceof IDOMNode) {
        /*
			 * find the location of the intended insertion as it will give us
			 * the correct offset for checking position dependent CMDocuments
			 */
        int textInsertionOffset = 0;
        NodeList children = node.getChildNodes();
        if (children.getLength() >= childIndex && childIndex >= 0) {
            Node nodeAlreadyAtIndex = children.item(childIndex);
            if (nodeAlreadyAtIndex instanceof IDOMNode)
                textInsertionOffset = ((IDOMNode) nodeAlreadyAtIndex).getEndOffset();
        } else {
            textInsertionOffset = ((IDOMNode) node).getStartOffset();
        }
        TLDCMDocumentManager mgr = TaglibController.getTLDCMDocumentManager(((IDOMNode) node).getStructuredDocument());
        if (mgr != null) {
            List moreCMDocuments = mgr.getCMDocumentTrackers(textInsertionOffset);
            if (moreCMDocuments != null) {
                for (int i = 0; i < moreCMDocuments.size(); i++) {
                    CMDocument doc = (CMDocument) moreCMDocuments.get(i);
                    CMNamedNodeMap elements = doc.getElements();
                    if (elements != null) {
                        for (int j = 0; j < elements.getLength(); j++) {
                            CMElementDeclaration ed = (CMElementDeclaration) elements.item(j);
                            elementDecls.add(ed);
                        }
                    }
                }
            }
        }
        // get position dependent CMDocuments and insert their tags as
        // proposals
        ModelQueryAdapter mqAdapter = null;
        if (node.getNodeType() == Node.DOCUMENT_NODE)
            mqAdapter = (ModelQueryAdapter) ((IDOMNode) node).getAdapterFor(ModelQueryAdapter.class);
        else
            mqAdapter = (ModelQueryAdapter) ((IDOMNode) node.getOwnerDocument()).getAdapterFor(ModelQueryAdapter.class);
        if (mqAdapter != null) {
            CMDocument doc = mqAdapter.getModelQuery().getCorrespondingCMDocument(node);
            if (doc != null) {
                CMDocument jcmdoc = getDefaultJSPCMDocument((IDOMNode) node);
                CMNamedNodeMap jspelements = jcmdoc.getElements();
                /*
					 * For a built-in JSP action the content model is properly
					 * set up, so don't just blindly add the rest--unless this
					 * will be a direct child of the document
					 */
                if (jspelements != null && (!(doc instanceof JSPCMDocument) || node.getNodeType() == Node.DOCUMENT_NODE)) {
                    List rejectElements = new ArrayList();
                    // determine if the document is in XML form
                    Document domDoc = null;
                    if (node.getNodeType() == Node.DOCUMENT_NODE)
                        domDoc = (Document) node;
                    else
                        domDoc = node.getOwnerDocument();
                    // Show XML tag forms of JSP markers if jsp:root is
                    // the document element OR it's HTML but
                    // isn't really in the text.
                    // If the document isn't strictly XML, pull out the
                    // XML tag forms it is xml format
                    rejectElements.add(JSP12Namespace.ElementName.SCRIPTLET);
                    rejectElements.add(JSP12Namespace.ElementName.EXPRESSION);
                    rejectElements.add(JSP12Namespace.ElementName.DECLARATION);
                    rejectElements.add(JSP12Namespace.ElementName.DIRECTIVE_INCLUDE);
                    rejectElements.add(JSP12Namespace.ElementName.DIRECTIVE_PAGE);
                    rejectElements.add(JSP12Namespace.ElementName.TEXT);
                    rejectElements.add(JSP12Namespace.ElementName.DIRECTIVE_TAGLIB);
                    rejectElements.add(JSP20Namespace.ElementName.DIRECTIVE_TAG);
                    rejectElements.add(JSP20Namespace.ElementName.DIRECTIVE_ATTRIBUTE);
                    rejectElements.add(JSP20Namespace.ElementName.DIRECTIVE_VARIABLE);
                    if (isXMLFormat(domDoc)) {
                        // jsp actions
                        rejectElements.add(JSP12Namespace.ElementName.FALLBACK);
                        rejectElements.add(JSP12Namespace.ElementName.USEBEAN);
                        rejectElements.add(JSP12Namespace.ElementName.GETPROPERTY);
                        rejectElements.add(JSP12Namespace.ElementName.SETPROPERTY);
                        rejectElements.add(JSP12Namespace.ElementName.INCLUDE);
                        rejectElements.add(JSP12Namespace.ElementName.FORWARD);
                        rejectElements.add(JSP12Namespace.ElementName.PLUGIN);
                        rejectElements.add(JSP12Namespace.ElementName.FALLBACK);
                        rejectElements.add(JSP12Namespace.ElementName.PARAM);
                        rejectElements.add(JSP12Namespace.ElementName.PARAMS);
                    }
                    // don't show jsp:root if a document element already
                    // exists
                    Element docElement = domDoc.getDocumentElement();
                    if (// $NON-NLS-1$
                    docElement != null && ((docElement.getNodeName().equals("jsp:root")) || ((((IDOMNode) docElement).getStartStructuredDocumentRegion() != null || ((IDOMNode) docElement).getEndStructuredDocumentRegion() != null))))
                        rejectElements.add(JSP12Namespace.ElementName.ROOT);
                    for (int j = 0; j < jspelements.getLength(); j++) {
                        CMElementDeclaration ed = (CMElementDeclaration) jspelements.item(j);
                        if (rejectElements.contains(ed.getNodeName()))
                            continue;
                        elementDecls.add(ed);
                    }
                }
            } else // No cm document (such as for the Document (a non-Element) node itself)
            {
                CMNamedNodeMap jspElements = getDefaultJSPCMDocument((IDOMNode) node).getElements();
                int length = jspElements.getLength();
                for (int i = 0; i < length; i++) {
                    elementDecls.add(jspElements.item(i));
                }
            }
        }
    }
    return elementDecls;
}
Also used : JSPCMDocument(org.eclipse.wst.html.core.internal.contentmodel.JSPCMDocument) CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) TLDCMDocumentManager(org.eclipse.jst.jsp.core.internal.contentmodel.tld.TLDCMDocumentManager) ModelQueryAdapter(org.eclipse.wst.xml.core.internal.ssemodelquery.ModelQueryAdapter) NodeList(org.w3c.dom.NodeList) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) Document(org.w3c.dom.Document) JSPCMDocument(org.eclipse.wst.html.core.internal.contentmodel.JSPCMDocument) CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) JSPCMDocument(org.eclipse.wst.html.core.internal.contentmodel.JSPCMDocument) List(java.util.List) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)

Aggregations

CMNamedNodeMap (org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)68 CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)39 CMNode (org.eclipse.wst.xml.core.internal.contentmodel.CMNode)36 CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)26 CMAttributeDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration)23 List (java.util.List)21 ArrayList (java.util.ArrayList)18 ModelQuery (org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)16 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)14 Element (org.w3c.dom.Element)14 CMNamedNodeMapImpl (org.eclipse.wst.xml.core.internal.contentmodel.basic.CMNamedNodeMapImpl)13 NamedNodeMap (org.w3c.dom.NamedNodeMap)10 CMDataType (org.eclipse.wst.xml.core.internal.contentmodel.CMDataType)9 NodeList (org.w3c.dom.NodeList)9 Iterator (java.util.Iterator)8 Attr (org.w3c.dom.Attr)8 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)7 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)6 CMNodeList (org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList)6 IDOMElement (org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement)6