Package org.eclipse.wst.xml.core.internal.contentmodel

Examples of org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap


    // Names of the descriptors in the above List
    List descriptorNames = new ArrayList();

    // Update any descriptors derived from the metainfo
    CMElementDeclaration ed = getDeclaration();
    CMNamedNodeMap attrMap = null;
    if (ed != null) {
      attrMap = ed.getAttributes();
      CMNamedNodeMapImpl allAttributes = new CMNamedNodeMapImpl(attrMap);
      ModelQuery modelQuery = ModelQueryUtil.getModelQuery(fNode.getOwnerDocument());
      if(modelQuery != null) {
      List nodes = modelQuery.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);
          }
        }
      }
      attrMap = allAttributes;
    }
    // Update exiting descriptors; not added to the final list here
    if (attrMap != null) {
      // Update existing descriptor types based on metainfo
      CMAttributeDeclaration attrDecl = null;
      for (int i = 0; i < attrMap.getLength(); i++) {
        attrDecl = (CMAttributeDeclaration) attrMap.item(i);
        String attrName = DOMNamespaceHelper.computeName(attrDecl, fNode, null);
        if (!declaredNames.contains(attrName)) {
          declaredNames.add(attrName);
        }
        for (int j = 0; j < fDescriptors.length; j++) {
          boolean sameName = (fCaseSensitive && fDescriptors[j].getId().equals(attrDecl.getNodeName())) || (!fCaseSensitive && attrDecl.getNodeName().equals(fDescriptors[j].getId().toString()));
          if (sameName) {
            String[] validValues = getValidValues(attrDecl);
            // Update the descriptor for this
            // CMAttributeDeclaration (only enumerated values get
            // updated for now)
            if (fDescriptors[j] instanceof EnumeratedStringPropertyDescriptor) {
              ((EnumeratedStringPropertyDescriptor) fDescriptors[j]).updateValues(validValues);
            }
            // Replace with better descriptor
            else if ((validValues != null) && (validValues.length > 0)) {
              fDescriptors[j] = createPropertyDescriptor(attrDecl, null);
            }
          }
        }
      }
    }
    else {
      // Update existing descriptors based on not having any metainfo
      for (int j = 0; j < fDescriptors.length; j++) {
        // Replace with basic descriptor
        if (!(fDescriptors[j] instanceof TextPropertyDescriptor)) {
          fDescriptors[j] = createDefaultPropertyDescriptor((String) fDescriptors[j].getId());
        }
      }
    }

    NamedNodeMap attributes = fNode.getAttributes();

    // Remove descriptors for attributes that aren't present AND aren't
    // known through metainfo,
    // do this by only reusing existing descriptors for attributes that
    // are present or declared
    for (int i = 0; i < fDescriptors.length; i++) {
      if (fDescriptors[i] != null) {
        String descriptorName = fDescriptors[i].getId().toString();
        if ((declaredNames.contains(descriptorName) || (attributes.getNamedItem(descriptorName) != null)) && !descriptorNames.contains(descriptorName)) {
          descriptorNames.add(descriptorName);
          descriptors.add(fDescriptors[i]);
        }
      }
    }

    // Add descriptors for declared attributes that don't already have one
    if (attrMap != null) {
      // Update existing descriptor types based on metainfo
      CMAttributeDeclaration attrDecl = null;
      for (int i = 0; i < attrMap.getLength(); i++) {
        attrDecl = (CMAttributeDeclaration) attrMap.item(i);
        String attrName = DOMNamespaceHelper.computeName(attrDecl, fNode, null);
        if (fCaseSensitive) {
          if (!descriptorNames.contains(attrName)) {
            IPropertyDescriptor descriptor = createPropertyDescriptor(attrDecl, null);
            if (descriptor != null) {
View Full Code Here


      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;
View Full Code Here

    //System.out.println("current tapestry component :" + name);
    CMNode node = this.getNamedItem(name);
    List result = new ArrayList();
    if(node instanceof ElemDecl){
      ElemDecl element = (ElemDecl) node;
      CMNamedNodeMap attributes = element.getAttributes();
      Iterator ite = attributes.iterator();
      while(ite.hasNext()){
        CMNode attr = (CMNode) ite.next();
        Template template = new Template(attr.getNodeName(), buildAttributeDescription(attr, element), contextTypeId, buildAttributeInsertCode(attr), true);
        result.add(template);
      }
View Full Code Here

   * @param cmdoc
   */
  private void loadFromCMDocument(final TaglibPaletteDrawer category,
      final CMDocument cmdoc) {

    final CMNamedNodeMap nodeMap = cmdoc.getElements();
    for (int i = 0, size = nodeMap.getLength(); i < size; i++) {
      final CMElementDeclaration eledecl = (CMElementDeclaration) nodeMap
          .item(i);
      final String tagName = eledecl.getElementName();
      TagToolPaletteEntry item;
      if (tagName.equalsIgnoreCase(IHTMLConstants.TAG_INPUT)) {// TODO:
                                    // fix
View Full Code Here

   */
  protected CMAttributeDeclaration getCMAttributeDeclaration(IDOMNode node, CMElementDeclaration elementDecl, String attName) {
    CMAttributeDeclaration attrDecl = null;

    if (elementDecl != null) {
      CMNamedNodeMap attributes = elementDecl.getAttributes();
     
      CMNamedNodeMapImpl allAttributes = new CMNamedNodeMapImpl(attributes);
      List nodes = ModelQueryUtil.getModelQuery(node.getOwnerDocument()).getAvailableContent((Element) node, elementDecl, 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);
        }
      }
      attributes = allAttributes;

      String noprefixName = DOMNamespaceHelper.getUnprefixedName(attName);
      if (attributes != null) {
        attrDecl = (CMAttributeDeclaration) attributes.getNamedItem(noprefixName);
        if (attrDecl == null) {
          attrDecl = (CMAttributeDeclaration) attributes.getNamedItem(attName);
        }
      }
    }
    return attrDecl;
  }
View Full Code Here

  {
  }

  public void visitCMDocument(CMDocument document)
  {
    CMNamedNodeMap map = document.getElements();
    int size = map.getLength();
    for (int i = 0; i < size; i++)
    {
      visitCMNode(map.item(i));
    }
  }
View Full Code Here

    }
  }

  public void visitCMElementDeclaration(CMElementDeclaration ed)
  {
    CMNamedNodeMap nodeMap = ed.getAttributes();
    int size = nodeMap.getLength();
    for (int i = 0; i < size; i++)
    {
      visitCMNode(nodeMap.item(i));
    }

    visitCMNode(ed.getContent());

    visitCMDataType(ed.getDataType());
View Full Code Here

        boolean oldAttachNodesToParent = attachNodesToParent;
        attachNodesToParent = true;

        // instead of calling super.visitCMElementDeclaration()
        // we duplicate the code with some minor modifications
        CMNamedNodeMap nodeMap = ed.getAttributes();
        int size = nodeMap.getLength();
        for (int j = 0; j < size; j++) {
          visitCMNode(nodeMap.item(j));
        }

        CMContent content = ed.getContent();
        if (content != null) {
          visitCMNode(content);
View Full Code Here

  }

  public static void testPopulateDocumentFromGrammarFile(Document document, String grammarFileName, String rootElementName, boolean hack) {
    try {
      CMDocument cmDocument = ContentModelManager.getInstance().createCMDocument(grammarFileName, null);
      CMNamedNodeMap elementMap = cmDocument.getElements();
      CMElementDeclaration element = (CMElementDeclaration) elementMap.getNamedItem(rootElementName);

      DOMContentBuilderImpl contentBuilder = new DOMContentBuilderImpl(document);
      contentBuilder.supressCreationOfDoctypeAndXMLDeclaration = hack;
      contentBuilder.createDefaultRootContent(cmDocument, element);
View Full Code Here

    Assert.isNotNull(cmDocument);
    Assert.isNotNull(getRootElementName());

    // create the xml model
    CMNamedNodeMap nameNodeMap = cmDocument.getElements();
    CMElementDeclaration cmElementDeclaration = (CMElementDeclaration) nameNodeMap.getNamedItem(getRootElementName());

    Document xmlDocument = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
    DOMContentBuilderImpl contentBuilder = new DOMContentBuilderImpl(xmlDocument);

    // this 'uglyTempHack' flag is required in order to supress the
View Full Code Here

TOP

Related Classes of org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.