Search in sources :

Example 71 with CMNode

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

the class XMLHyperlinkDetector method isLinkableAttr.

/**
 * Checks to see if the given attribute is openable. Attribute is openable
 * if it is a namespace declaration attribute or if the attribute value is
 * of type URI.
 *
 * @param attr
 *            cannot be null
 * @param cmElement
 *            CMElementDeclaration associated with the attribute (can be
 *            null)
 * @return true if this attribute is "openOn-able" false otherwise
 */
private boolean isLinkableAttr(Attr attr, CMElementDeclaration cmElement) {
    String attrName = attr.getName();
    String prefix = DOMNamespaceHelper.getPrefix(attrName);
    String unprefixedName = DOMNamespaceHelper.getUnprefixedName(attrName);
    // determine if attribute is namespace declaration
    if ((XMLNS.equals(prefix)) || (XMLNS.equals(unprefixedName))) {
        return true;
    }
    // determine if attribute contains schema location
    if ((XSI_NAMESPACE_URI.equals(DOMNamespaceHelper.getNamespaceURI(attr))) && ((SCHEMA_LOCATION.equals(unprefixedName)) || (NO_NAMESPACE_SCHEMA_LOCATION.equals(unprefixedName)))) {
        return true;
    }
    // determine if attribute value is of type URI
    if (cmElement != null) {
        CMNamedNodeMap attrDecls = cmElement.getAttributes();
        CMNamedNodeMapImpl allAttributes = new CMNamedNodeMapImpl(attrDecls);
        List nodes = ModelQueryUtil.getModelQuery(attr.getOwnerDocument()).getAvailableContent(attr.getOwnerElement(), cmElement, ModelQuery.INCLUDE_ATTRIBUTES);
        for (int k = 0; k < nodes.size(); k++) {
            CMNode cmnode = (CMNode) nodes.get(k);
            if (cmnode.getNodeType() == CMNode.ATTRIBUTE_DECLARATION) {
                allAttributes.put(cmnode);
            }
        }
        attrDecls = allAttributes;
        CMAttributeDeclaration attrDecl = (CMAttributeDeclaration) attrDecls.getNamedItem(attrName);
        if ((attrDecl != null) && (attrDecl.getAttrType() != null) && (CMDataType.URI.equals(attrDecl.getAttrType().getDataTypeName()))) {
            return true;
        }
    }
    return false;
}
Also used : CMNamedNodeMapImpl(org.eclipse.wst.xml.core.internal.contentmodel.basic.CMNamedNodeMapImpl) ArrayList(java.util.ArrayList) List(java.util.List) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) CMAttributeDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)

Example 72 with CMNode

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

the class XMLPropertySource method resetPropertyValue.

/**
 * Resets the specified property's value to its default value.
 */
public void resetPropertyValue(Object propertyObject) {
    String property = propertyObject.toString();
    CMNamedNodeMap attrDecls = null;
    CMElementDeclaration ed = getDeclaration();
    if (ed != null) {
        attrDecls = ed.getAttributes();
        CMNamedNodeMapImpl allAttributes = new CMNamedNodeMapImpl(attrDecls);
        List nodes = ModelQueryUtil.getModelQuery(fNode.getOwnerDocument()).getAvailableContent((Element) fNode, ed, ModelQuery.INCLUDE_ATTRIBUTES);
        for (int k = 0; k < nodes.size(); k++) {
            CMNode cmnode = (CMNode) nodes.get(k);
            if (cmnode.getNodeType() == CMNode.ATTRIBUTE_DECLARATION) {
                allAttributes.put(cmnode);
            }
        }
        attrDecls = allAttributes;
    }
    NamedNodeMap attrMap = fNode.getAttributes();
    if (attrDecls != null) {
        CMAttributeDeclaration attrDecl = (CMAttributeDeclaration) attrDecls.getNamedItem(property);
        String defValue = null;
        if (attrDecl != null) {
            if (attrDecl.getAttrType() != null) {
                CMDataType helper = attrDecl.getAttrType();
                if ((helper.getImpliedValueKind() != CMDataType.IMPLIED_VALUE_NONE) && (helper.getImpliedValue() != null)) {
                    defValue = helper.getImpliedValue();
                }
            }
        }
        if ((defValue != null) && (defValue.length() > 0)) {
            // implied values will be in the DOM, but not the source
            attrMap.removeNamedItem(property);
        } else {
            // $NON-NLS-1$
            ((Attr) attrMap.getNamedItem(property)).setValue("");
        }
    } else {
        // remember, this method is for reset, not remove
        // $NON-NLS-1$
        ((Attr) attrMap.getNamedItem(property)).setValue("");
    }
}
Also used : CMNamedNodeMapImpl(org.eclipse.wst.xml.core.internal.contentmodel.basic.CMNamedNodeMapImpl) NamedNodeMap(org.w3c.dom.NamedNodeMap) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) CMDataType(org.eclipse.wst.xml.core.internal.contentmodel.CMDataType) ArrayList(java.util.ArrayList) List(java.util.List) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) CMAttributeDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap) Attr(org.w3c.dom.Attr)

Example 73 with CMNode

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

the class BugFixesTest method testForBug176420.

public void testForBug176420() {
    // Obtain the model from /testresources/samples/testSchemaForBug176420.xsd
    Bundle bundle = Platform.getBundle("org.eclipse.wst.xsd.core.tests");
    URL url = bundle.getEntry("/testresources/samples/testSchemaForBug176420.xsd");
    CMDocument document = XSDImpl.buildCMDocument(url.toExternalForm());
    assertNotNull("Content model loaded Null", document);
    // Obtain the enumerated values of the root element
    CMNode cmNode = document.getElements().item(0);
    String[] enumeratedValues = ((CMElementDeclaration) cmNode).getDataType().getEnumeratedValues();
    // Verify that all 12 enumerated values are included
    assertEquals(12, enumeratedValues.length);
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) Bundle(org.osgi.framework.Bundle) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) URL(java.net.URL)

Example 74 with CMNode

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

the class BugFixesTest method testXSIType.

// Add tests here
@SuppressWarnings("unchecked")
public void testXSIType() {
    String soapSchemaURI = locateFileUsingCatalog("http://schemas.xmlsoap.org/wsdl/soap/");
    CMDocumentFactoryXSD factory = new CMDocumentFactoryXSD();
    assertNotNull("Assert factory is not null", factory);
    CMDocument cmDocument = factory.createCMDocument(soapSchemaURI);
    assertNotNull("Assert CMDocument is not null", cmDocument);
    CMNamedNodeMap elements = cmDocument.getElements();
    boolean foundDesiredElement = false;
    for (Iterator<CMElementDeclaration> i = elements.iterator(); i.hasNext(); ) {
        CMElementDeclaration element = i.next();
        if ("binding".equals(element.getElementName())) {
            foundDesiredElement = true;
            CMNamedNodeMap attributes = element.getAttributes();
            // Three attributes: required, transport and style
            assertNotNull(attributes);
            // If the xsi:type was present, it would be 4 attributes
            assertTrue(attributes.getLength() == 3);
            CMNode attrNode = null;
            attrNode = attributes.getNamedItem("required");
            assertNotNull(attrNode);
            attrNode = attributes.getNamedItem("transport");
            assertNotNull(attrNode);
            attrNode = attributes.getNamedItem("style");
            assertNotNull(attrNode);
            // Should be null!
            attrNode = attributes.getNamedItem("type");
            assertNull(attrNode);
            break;
        }
    }
    // if we didn't even find the binding element, then something terrible went wrong
    assertTrue(foundDesiredElement);
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap) CMDocumentFactoryXSD(org.eclipse.wst.xsd.contentmodel.internal.CMDocumentFactoryXSD)

Example 75 with CMNode

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

the class AbstractContentAssistProcessor method getValidChildElementDeclarations.

// returns a list of CMNodes that can be validly inserted at this
// childPosition
// Given the grammar shown below and a snippet of XML code (where the '|'
// indicated the cursor position)
// the list would return only the element declarations can be inserted
// while maintaing validity of the content.
// 
// grammar : Foo -> (A, B, C)
// snippet : <Foo><A>|
// result : {B}
// 
protected List getValidChildElementDeclarations(Element parent, int childPosition, int kindOfAction) {
    List modelQueryActions = getAvailableChildrenAtIndex(parent, childPosition, ModelQuery.VALIDITY_STRICT);
    Iterator iterator = modelQueryActions.iterator();
    List cmnodes = new Vector();
    while (iterator.hasNext()) {
        ModelQueryAction action = (ModelQueryAction) iterator.next();
        if ((childPosition < 0) || (((action.getStartIndex() <= childPosition) && (childPosition <= action.getEndIndex())) && (action.getKind() == kindOfAction))) {
            CMNode actionCMNode = action.getCMNode();
            if ((actionCMNode != null) && !cmnodes.contains(actionCMNode)) {
                cmnodes.add(actionCMNode);
            }
        }
    }
    return cmnodes;
}
Also used : ModelQueryAction(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQueryAction) Iterator(java.util.Iterator) CMNodeList(org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList) List(java.util.List) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) Vector(java.util.Vector)

Aggregations

CMNode (org.eclipse.wst.xml.core.internal.contentmodel.CMNode)133 CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)37 List (java.util.List)36 CMNamedNodeMap (org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)35 ArrayList (java.util.ArrayList)28 Iterator (java.util.Iterator)23 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)20 CMNodeList (org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList)19 CMAttributeDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration)17 CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)17 Element (org.w3c.dom.Element)16 NodeList (org.w3c.dom.NodeList)15 CMNamedNodeMapImpl (org.eclipse.wst.xml.core.internal.contentmodel.basic.CMNamedNodeMapImpl)14 ModelQuery (org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)13 Node (org.w3c.dom.Node)13 NamedNodeMap (org.w3c.dom.NamedNodeMap)10 ModelQueryAction (org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQueryAction)9 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)9 Image (org.eclipse.swt.graphics.Image)8 CustomCompletionProposal (org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal)8