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

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


                //  }
                //}
                //cmAttributes = allAttributes;

                // Check implied values from the DTD way.
                CMAttributeDeclaration attributeDeclaration = (CMAttributeDeclaration) cmAttributes.getNamedItem(XML_SPACE);
                if (attributeDeclaration != null) {
                  // CMAttributeDeclaration found, check
                  // it
                  // out.

                  //BUG214516/196544 - Fixed NPE that was caused by an attr having
                  // a null attr type
                  String defaultValue = null;
                  CMDataType attrType = attributeDeclaration.getAttrType();
                  if (attrType != null) {
                    if ((attrType.getImpliedValueKind() != CMDataType.IMPLIED_VALUE_NONE) && attrType.getImpliedValue() != null)
                      defaultValue = attrType.getImpliedValue();
                    else if ((attrType.getEnumeratedValues() != null) && (attrType.getEnumeratedValues().length > 0)) {
                      defaultValue = attrType.getEnumeratedValues()[0];
View Full Code Here


          }
        }
        attrMap = allAttributes;
       
        Iterator it = attrMap.iterator();
        CMAttributeDeclaration attr = null;
        while (it.hasNext()) {
          attr = (CMAttributeDeclaration) it.next();
          if (attr.getUsage() == CMAttributeDeclaration.REQUIRED) {
            result.add(attr);
          }
        }
      }
    }
View Full Code Here

  /**
   */
  private boolean isBooleanAttr(Attr attr) {
    if (attr == null)
      return false;
    CMAttributeDeclaration decl = CMNodeUtil.getAttributeDeclaration(attr);
    if (decl == null)
      return false;
    CMDataType type = decl.getAttrType();
    if (type == null)
      return false;
    String values[] = type.getEnumeratedValues();
    if (values == null)
      return false;
    return (values.length == 1 && values[0].equals(decl.getAttrName()));
  }
View Full Code Here

      }

      // only add proposals for the attributes whose names begin with the matchstring
      if (attributes != null) {
        for (int i = 0; i < attributes.getLength(); i++) {
          CMAttributeDeclaration attrDecl = (CMAttributeDeclaration) attributes.item(i);

          if(validModelQueryNode(attrDecl)) {
            int isRequired = 0;
            if (attrDecl.getUsage() == CMAttributeDeclaration.REQUIRED) {
              isRequired = XMLRelevanceConstants.R_REQUIRED;
            }
 
            boolean showAttribute = true;
            showAttribute = showAttribute && beginsWith(getRequiredName(node, attrDecl), matchString.trim());
            AttrImpl attr = (AttrImpl) node.getAttributes().getNamedItem(getRequiredName(node, attrDecl));
            ITextRegion nameRegion = attr != null ? attr.getNameRegion() : null;
            // nameRegion.getEndOffset() + 1 is required to allow for
            // matches against the full name of an existing Attr
            showAttribute = showAttribute && ((attr == null) || nameRegion == null ||
                ((nameRegion != null) &&
                    (sdRegion.getStartOffset(nameRegion) <
                      contentAssistRequest.getReplacementBeginPosition()) &&
                    (sdRegion.getStartOffset(nameRegion) + nameRegion.getLength() >=
                      (contentAssistRequest.getReplacementBeginPosition() +
                      contentAssistRequest.getReplacementLength()) )));
            if (showAttribute) {
              //get the proposal image
              Image attrImage = CMImageUtil.getImage(attrDecl);
              if (attrImage == null) {
                if (isRequired > 0) {
                  attrImage = this.getRequiredAttributeImage();
                } else {
                  attrImage = this.getNotRequiredAttributeImage();
                }
              }
 
              String proposedText = null;
              String proposedInfo = getAdditionalInfo(elementDecl, attrDecl);
              CustomCompletionProposal proposal = null;
              // attribute is at this location and already exists
              if (attrAtLocationHasValue) {
                // only propose the name
                proposedText = getRequiredName(node, attrDecl);
                proposal = new MarkupCompletionProposal(
                    proposedText, contentAssistRequest.getReplacementBeginPosition(),
                    contentAssistRequest.getReplacementLength(), proposedText.length(),
                    attrImage, proposedText, null, proposedInfo,
                    XMLRelevanceConstants.R_XML_ATTRIBUTE_NAME + isRequired, true);
              }
              // no attribute exists or is elsewhere, generate
              // minimally
              else {
                Attr existingAttrNode = (Attr) node.getAttributes().getNamedItem(getRequiredName(node, attrDecl));
                String value = null;
                if (existingAttrNode != null && existingAttrNode.getSpecified()) {
                  value = existingAttrNode.getNodeValue();
                }
                int cursorPosition = 0;
                if ((value != null) && (value.length() > 0)) {
                  proposedText = getRequiredName(node, attrDecl);
                  cursorPosition = proposedText.length() + 2;
                }
                else {
                  proposedText = getRequiredText(node, attrDecl);
                  // skip the cursor past a fixed value
                  if (attrDecl.getAttrType() != null && attrDecl.getAttrType().getImpliedValueKind() == CMDataType.IMPLIED_VALUE_FIXED)
                    cursorPosition = proposedText.length();
                  else
                    cursorPosition = getRequiredName(node, attrDecl).length() + 2;
                }
                if (proposalNeedsSpace)
View Full Code Here

      CMElementDeclaration elementDecl = getCMElementDeclaration(node);

      // String attributeName = nameRegion.getText();
      String attributeName = open.getText(nameRegion);

      CMAttributeDeclaration attrDecl = null;

      // No CMElementDeclaration means no attribute metadata, but retrieve the
      // declaration for the attribute otherwise
      if (elementDecl != null) {
        CMNamedNodeMapImpl allAttributes = new CMNamedNodeMapImpl(elementDecl.getAttributes()) {
          private Map caseInsensitive;
         
          private Map getCaseInsensitiveMap() {
            if(caseInsensitive == null)
              caseInsensitive = new HashMap();
            return caseInsensitive;
          }

          public CMNode getNamedItem(String name) {
            CMNode node = super.getNamedItem(name);
            if (node == null) {
              node = (CMNode) getCaseInsensitiveMap().get(name.toLowerCase(Locale.US));
            }
            return node;
          }

          public void put(CMNode cmNode) {
            super.put(cmNode);
            getCaseInsensitiveMap().put(cmNode.getNodeName().toLowerCase(Locale.US), cmNode);
          }
        };
        this.addModelQueryAttributeDeclarations(node, elementDecl, allAttributes);

        String noprefixName = DOMNamespaceHelper.getUnprefixedName(attributeName);
        if (allAttributes != null) {
          attrDecl = (CMAttributeDeclaration) allAttributes.getNamedItem(attributeName);
          if (attrDecl == null) {
            attrDecl = (CMAttributeDeclaration) allAttributes.getNamedItem(noprefixName);
          }
        }
        if (attrDecl == null) {
          setErrorMessage(XMLUIMessages.No_known_attribute__UI_ + attributeName);
        }
      }

      String currentValue = node.getAttributes().getNamedItem(attributeName).getNodeValue();
      String proposedInfo = null;
      //get proposal image
      Image image = CMImageUtil.getImage(attrDecl);
      if (image == null) {
        if ((attrDecl != null) && (attrDecl.getUsage() == CMAttributeDeclaration.REQUIRED)) {
          image = this.getRequiredAttributeImage();
        } else {
          image = this.getNotRequiredAttributeImage();
        }
      }

      if ((attrDecl != null) && (attrDecl.getAttrType() != null)) {
        // attribute is known, prompt with values from the declaration
        proposedInfo = getAdditionalInfo(elementDecl, attrDecl);
        List possibleValues = getPossibleDataTypeValues(node, attrDecl);
        String defaultValue = attrDecl.getAttrType().getImpliedValue();
        String qualifiedDelimiter = (String) attrDecl.getProperty("qualified-delimiter"); //$NON-NLS-1$
        if (possibleValues.size() > 0 || defaultValue != null) {
          // ENUMERATED VALUES
          String matchString = contentAssistRequest.getMatchString();
          if (matchString == null) {
            matchString = ""; //$NON-NLS-1$
          }
          if ((matchString.length() > 0) && (matchString.startsWith("\"") || matchString.startsWith("'"))) { //$NON-NLS-1$ //$NON-NLS-2$
            matchString = matchString.substring(1);
          }
          boolean currentValid = false;

          //create suggestions for enumerated values
          int rOffset = contentAssistRequest.getReplacementBeginPosition();
          int rLength = contentAssistRequest.getReplacementLength();
          for (Iterator j = possibleValues.iterator(); j.hasNext();) {
            String possibleValue = (String) j.next();
            String alternateMatch = null;
            if (qualifiedDelimiter != null) {
              int delimiter = possibleValue.lastIndexOf(qualifiedDelimiter);
              if (delimiter >= 0 && delimiter < possibleValue.length() - 1) {
                alternateMatch = possibleValue.substring(delimiter + 1);
              }
            }
            if(!possibleValue.equals(defaultValue)) {
              currentValid = currentValid || possibleValue.equals(currentValue);
              if ((matchString.length() == 0) || possibleValue.startsWith(matchString)) {
                String rString = "\"" + possibleValue + "\""; //$NON-NLS-1$ //$NON-NLS-2$
                alternateMatch = "\"" + alternateMatch; //$NON-NLS-1$
                CustomCompletionProposal proposal = new MarkupCompletionProposal(
                    rString, rOffset, rLength, possibleValue.length() + 1,
                    XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ENUM),
                    rString, alternateMatch, null, proposedInfo, XMLRelevanceConstants.R_XML_ATTRIBUTE_VALUE, true);
                contentAssistRequest.addProposal(proposal);
              }
            }
          }
          if(defaultValue != null && ((matchString.length() == 0) || defaultValue.startsWith(matchString))) {
            String rString = "\"" + defaultValue + "\""; //$NON-NLS-1$ //$NON-NLS-2$
            CustomCompletionProposal proposal = new MarkupCompletionProposal(
                rString, rOffset, rLength, defaultValue.length() + 1,
                XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_DEFAULT),
                rString, null, proposedInfo, XMLRelevanceConstants.R_XML_ATTRIBUTE_VALUE);
            contentAssistRequest.addProposal(proposal);
          }
        }
        else if (((attrDecl.getUsage() == CMAttributeDeclaration.FIXED) ||
            (attrDecl.getAttrType().getImpliedValueKind() == CMDataType.IMPLIED_VALUE_FIXED)) &&
            (attrDecl.getAttrType().getImpliedValue() != null)) {
         
          // FIXED values
          String value = attrDecl.getAttrType().getImpliedValue();
          if ((value != null) && (value.length() > 0)) {
            String rValue = "\"" + value + "\"";//$NON-NLS-2$//$NON-NLS-1$
            CustomCompletionProposal proposal = new MarkupCompletionProposal(
                rValue, contentAssistRequest.getReplacementBeginPosition(),
                contentAssistRequest.getReplacementLength(), rValue.length() + 1,
View Full Code Here

        if (ed != null)
        {
            for (final Iterator it = ed.getAttributes().iterator(); it.hasNext();)
            {
                final CMAttributeDeclaration attr = (CMAttributeDeclaration) it
                        .next();
                if (attr.getUsage() == CMAttributeDeclaration.REQUIRED
                        && element.getAttribute(attr.getAttrName()) == null)
                {
                    element.setAttribute(attr.getAttrName(), attr
                            .getDefaultValue());
                }
            }
        }
    }
View Full Code Here

      String attrName = a.getName().toLowerCase(Locale.US);
      if (attrName.startsWith(ATTR_NAME_DATA) && attrName.length() > ATTR_NAME_DATA.length())
        continue;

      CMAttributeDeclaration adec = (CMAttributeDeclaration) declarations.getNamedItem(a.getName());
     
      /* Check the modelquery if nothing is declared by the element declaration */
      if (adec == null) {
        if (modelQueryNodes == null)
          modelQueryNodes = ModelQueryUtil.getModelQuery(target.getOwnerDocument()).getAvailableContent((Element) node, edec, ModelQuery.INCLUDE_ATTRIBUTES);
       
       
        for (int k = 0; k < modelQueryNodes.size(); k++) {
          CMNode cmnode = (CMNode) modelQueryNodes.get(k);
          if (cmnode.getNodeType() == CMNode.ATTRIBUTE_DECLARATION && cmnode.getNodeName().toLowerCase(Locale.US).equals(attrName)) {
            adec = (CMAttributeDeclaration) cmnode;
            break;
          }
        }
      }
     
      if (adec == null) {
        // No attr declaration was found. That is, the attr name is
        // undefined.
        // but not regard it as undefined name if it includes nested
        // region
        if (!hasNestedRegion(((IDOMNode) a).getNameRegion())) {
          rgnType = REGION_NAME;
          state = ErrorState.UNDEFINED_NAME_ERROR;
        }
      } else {
        // The attr declaration was found.
        // At 1st, the name should be checked.
        if (CMUtil.isObsolete(adec)){
          state = ErrorState.OBSOLETE_ATTR_NAME_ERROR;
        }
        if (CMUtil.isHTML(edec) && (!CMUtil.isXHTML(edec))) {
          // If the target element is pure HTML (not XHTML), some
          // attributes
          // might be written in boolean format. It should be check
          // specifically.
          if (CMUtil.isBooleanAttr(adec) && ((IDOMAttr) a).hasNameOnly())
            continue; // OK, keep going. No more check is needed
          // against this attr.
        } else {
          // If the target is other than pure HTML (JSP or XHTML),
          // the name
          // must be checked exactly (ie in case sensitive way).
          String actual = a.getName();
          String desired = adec.getAttrName();
          if (!actual.equals(desired)) { // case mismatch
            rgnType = REGION_NAME;
            state = ErrorState.MISMATCHED_ERROR;
          }
        }
        // Then, the value must be checked.
        if (state == ErrorState.NONE_ERROR) { // Need more check.
          // Now, the value should be checked, if the type is ENUM.
          CMDataType attrType = adec.getAttrType();
          String actualValue = a.getValue();
          if (attrType.getImpliedValueKind() == CMDataType.IMPLIED_VALUE_FIXED) {
            // Check FIXED value.
            String validValue = attrType.getImpliedValue();
            if (!actualValue.equals(validValue)) {
View Full Code Here

   * (non-Javadoc)
   *
   * @see org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery#getCMAttributeDeclaration(org.w3c.dom.Attr)
   */
  public CMAttributeDeclaration getCMAttributeDeclaration(Attr attr) {
    CMAttributeDeclaration result = super.getCMAttributeDeclaration(attr);
    if (result == null) {
      ModelQuery query = getEmbeddedModelQuery(attr);
      if (query != null) {
        result = query.getCMAttributeDeclaration(attr);
      }
View Full Code Here

      this.buddyAttrs = buddyAttrs;
      makeBuddySystem(attrs);
    }

    protected String getKeyName(CMNode original) {
      CMAttributeDeclaration adecl = getDecl(original);
      if (adecl == null)
        return null;
      return adecl.getAttrName();
    }
View Full Code Here

        return null;
      return adecl.getAttrName();
    }

    protected CMNode createBuddySystem(CMNode original) {
      CMAttributeDeclaration adecl = getDecl(original);
      if (adecl == null)
        return null;
      CMAttributeDeclaration buddy = null;
      if (buddyAttrs != null) {
        buddy = (CMAttributeDeclaration) buddyAttrs.getNamedItem(adecl.getAttrName());
      }
      return new CMAttributeDeclarationBuddySystem(adecl, buddy, isXHTML());
    }
View Full Code Here

TOP

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

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.