Package org.eclipse.wst.xml.core.internal.provisional.document

Examples of org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr


        }
        else if (ATTRIBUTE_VALUE.equals(selectionStrategy)) {
          // underline the attribute's value
          if (node.getNodeType() == Node.ELEMENT_NODE) {
            IDOMElement element = (IDOMElement) node;
            IDOMAttr attributeNode = (IDOMAttr) (element.getAttributeNode(nameOrValue));
            if (attributeNode != null) {
              startEndPositions[0] = attributeNode.getValueRegionStartOffset();
              String valueRegionText = attributeNode.getValueRegionText();
              int valueRegionLength = valueRegionText == null ? 0 : valueRegionText.length();
              startEndPositions[1] = startEndPositions[0] + valueRegionLength;
            }
          }
        }
        else if (ALL_ATTRIBUTES.equals(selectionStrategy)) {
          // underline all attributes
          if (node.getNodeType() == Node.ELEMENT_NODE) {
            IDOMElement element = (IDOMElement) node;
            NamedNodeMap attributes = element.getAttributes();
            if (attributes != null) {
              IDOMNode first = (IDOMNode) attributes.item(0);
              IDOMNode last = (IDOMNode) attributes.item(attributes.getLength() - 1);
              if ((first != null) && (last != null)) {
                startEndPositions[0] = first.getStartOffset();
                startEndPositions[1] = last.getEndOffset();
              }
            }
          }
        }
        else if (TEXT.equals(selectionStrategy)) {
          // underline the text between the tags
          if (node.getNodeType() == Node.TEXT_NODE) {
            IDOMText textNode = (IDOMText) node;
            int start = textNode.getStartOffset();
            String value = textNode.getNodeValue();
            int index = 0;
            char curChar = value.charAt(index);
            // here we are finding start offset by skipping over
            // whitespace:
            while ((curChar == '\n') || (curChar == '\t') || (curChar == '\r') || (curChar == ' ')) {
              curChar = value.charAt(index);
              index++;
            }
            if (index > 0) {
              index--;

            }
            start = start + index;
            startEndPositions[0] = start;
            startEndPositions[1] = start + value.trim().length();
          }
          else if (node.getNodeType() == Node.ELEMENT_NODE) {
            IDOMElement element = (IDOMElement) node;
            Node child = element.getFirstChild();
            if (child instanceof IDOMNode) {
              IDOMNode xmlChild = ((IDOMNode) child);
              startEndPositions[0] = xmlChild.getStartOffset();
              startEndPositions[1] = xmlChild.getEndOffset();
            }
          }
        }
        else if (FIRST_NON_WHITESPACE_TEXT.equals(selectionStrategy)) {
          // search through all child nodes and return range of
          // first non-whitespace
          // text node
          if (node.getNodeType() == Node.ELEMENT_NODE) {
            NodeList nodes = node.getChildNodes();
            for (int i = 0; i < nodes.getLength(); i++) {
              Node currentNode = nodes.item(i);
              if (currentNode.getNodeType() == Node.TEXT_NODE) {
                // TODO (Trung) I don't think we should call
                // getNodeValue(), trim(), length()
                // repeatedly.
                // This is inefficient, to improve use local
                // variables to store values.
                IDOMText textNode = (IDOMText) currentNode;
                if (textNode.getNodeValue().trim().length() > 0) {
                  String value = textNode.getNodeValue();
                  int index = 0;
                  int start = textNode.getStartOffset();
                  char curChar = value.charAt(index);
                  // here we are finding start offset by
                  // skipping over whitespace:
                  while ((curChar == '\n') || (curChar == '\t') || (curChar == '\r') || (curChar == ' ')) {
                    curChar = value.charAt(index);
                    index++;
                  }
                  if (index > 0) {
                    index--;

                  }
                  start = start + index;
                  startEndPositions[0] = start;
                  startEndPositions[1] = start + value.trim().length();
                  break;
                }
              }

            }
          }
        }

        else if (TEXT_ENTITY_REFERENCE.equals(selectionStrategy)) {
          if (node.getNodeType() == Node.ENTITY_REFERENCE_NODE) {
            startEndPositions[0] = region.getStartOffset();
            startEndPositions[1] = region.getEndOffset();
          }
          else if (node.getNodeType() == Node.ELEMENT_NODE) {
            /*
             * In this case the undeclared entity might be in one
             * of the attribute values. Search through the
             * attributes to find the range of the undeclared
             * entity.
             */
            String entity = "&" + nameOrValue + ";"; //$NON-NLS-1$ //$NON-NLS-2$
            NamedNodeMap attributes = node.getAttributes();
            for (int i = 0; i < attributes.getLength(); i++) {
              IDOMAttr attr = (IDOMAttr) attributes.item(i);
              String nodeValue = attr.getNodeValue();
              int index = nodeValue.indexOf(entity);
              if (index != -1) {
                startEndPositions[0] = attr.getValueRegionStartOffset() + index + 1;
                startEndPositions[1] = startEndPositions[0] + entity.length();
              }
            }
          }

        }
        else if (VALUE_OF_ATTRIBUTE_WITH_GIVEN_VALUE.equals(selectionStrategy)) {
          // TODO (Trung) do we really need this strategy ?
          // If we know the name of the name of the attribute, we
          // can retrieve its value.
          // Hence, we can incoperate this strategy with
          // ATTRIBUTE_VALUE ?
          if (node.getNodeType() == Node.ELEMENT_NODE) {
            // here we will search through all attributes for the
            // one with the
            // with the value we want:
            // TODO (Trung) I see a potential problem here.
            // What happens when there is another attribute having
            // the same value
            // with this attribute's buggy value ?
            // Need to solve when time permits.
            NamedNodeMap attributes = node.getAttributes();
            for (int i = 0; i < attributes.getLength(); i++) {
              IDOMAttr attr = (IDOMAttr) attributes.item(i);
              String nodeValue = attr.getNodeValue().trim();
              if (nodeValue.equals(nameOrValue)) {
                startEndPositions[0] = attr.getValueRegionStartOffset() + 1;
                startEndPositions[1] = startEndPositions[0] + nodeValue.length();
                break;
              }
            }
          }
View Full Code Here


      // whether
      // an attr has prefix or not by calling XMLAttr#isGlobalAttr().
      // When a attr has prefix (not global), it returns false.
      boolean isXMLAttr = a instanceof IDOMAttr;
      if (isXMLAttr) {
        IDOMAttr xmlattr = (IDOMAttr) a;
        if (!xmlattr.isGlobalAttr())
          continue; // skip futher validation and begin next loop.
      }

      String attrName = a.getName().toLowerCase(Locale.US);
      if (attrName.startsWith(ATTR_NAME_DATA) && attrName.length() > ATTR_NAME_DATA.length())
View Full Code Here

      // whether
      // an attr has prefix or not by calling XMLAttr#isGlobalAttr().
      // When a attr has prefix (not global), it returns false.
      boolean isXMLAttr = a instanceof IDOMAttr;
      if (isXMLAttr) {
        IDOMAttr xmlattr = (IDOMAttr) a;
        if (!xmlattr.isGlobalAttr())
          continue; // skip futher validation and begin next loop.
      }

      CMAttributeDeclaration adec = (CMAttributeDeclaration) declarations.getNamedItem(a.getName());
      final String attrName = a.getName().toLowerCase(Locale.US);
View Full Code Here

    NamedNodeMap attrs = target.getAttributes();
    for (int i = 0; i < attrs.getLength(); i++) {
      Node n = attrs.item(i);
      if (!(n instanceof IDOMAttr))
        continue;
      IDOMAttr a = (IDOMAttr) n;
      String prefix = a.getPrefix();
      if ((prefix != null) && isUnknownAttr(a, target)) {
        // The attr has unknown prefix.  So, check it.
        if (!isValidPrefix(prefix, target)) {
          // report unknown attr error.
          ITextRegion r = a.getNameRegion();
          if (r == null)
            continue;
          int a_offset = a.getNameRegionStartOffset();
          int a_length = a.getNameRegion().getLength();
          reporter.report(new ErrorInfoImpl(UNDEFINED_NAME_ERROR, new Segment(a_offset, a_length), a));
        }
      }
    }
  }
View Full Code Here

        IDOMNode docNode = (IDOMNode) node;
        hyperRegion = new Region(docNode.getStartOffset(), docNode.getEndOffset() - docNode.getStartOffset());
      }
      else if (nodeType == Node.ATTRIBUTE_NODE) {
        // handle attribute nodes
        IDOMAttr att = (IDOMAttr) node;
        // do not include quotes in attribute value region
        int regOffset = att.getValueRegionStartOffset();
        ITextRegion valueRegion = att.getValueRegion();
        if (valueRegion != null) {
          int regLength = valueRegion.getTextLength();
          String attValue = att.getValueRegionText();
          if (StringUtils.isQuoted(attValue)) {
            ++regOffset;
            regLength = regLength - 2;
          }
          hyperRegion = new Region(regOffset, regLength);
View Full Code Here

      ISourceGenerator generator = node.getModel().getGenerator();

      for (int i = 0; i < attributesLength; i++) {
        attributes = newNode.getAttributes();
        attributesLength = attributes.getLength();
        IDOMAttr eachAttr = (IDOMAttr) attributes.item(i);
        // ITextRegion oldAttrValueRegion = eachAttr.getValueRegion();
        String oldAttrValue = eachAttr.getValueRegionText();
        if (oldAttrValue == null) {
          IDOMModel structuredModel = node.getModel();
          if (isXMLType(structuredModel)) {
            // TODO: Kit, please check. Is there any way to not
            // rely on getting regions from attributes?
            String newAttrValue = "=\"" + eachAttr.getNameRegionText() + "\""; //$NON-NLS-1$ //$NON-NLS-2$

            IStructuredDocument structuredDocument = structuredModel.getStructuredDocument();
            replaceSource(structuredModel, structuredDocument, eachAttr.getNameRegionEndOffset(), 0, newAttrValue);
            newNode = (IDOMNode) structuredModel.getIndexedRegion(node.getStartOffset()); // save
            // new
            // node
          }
        }
        else {

          char quote = StringUtils.isQuoted(oldAttrValue) ? oldAttrValue.charAt(0) : DOUBLE_QUOTE;
          String newAttrValue = generator.generateAttrValue(eachAttr, quote);

          // There is a problem in
          // StructuredDocumentRegionUtil.getAttrValue(ITextRegion)
          // when the region is instanceof ContextRegion.
          // Workaround for now...
          if (oldAttrValue.length() == 1) {
            char firstChar = oldAttrValue.charAt(0);
            if (firstChar == SINGLE_QUOTE)
              newAttrValue = SINGLE_QUOTES;
            else if (firstChar == DOUBLE_QUOTE)
              newAttrValue = DOUBLE_QUOTES;
          }

          if (newAttrValue != null) {
            if (newAttrValue.compareTo(oldAttrValue) != 0) {
              int attrValueStartOffset = eachAttr.getValueRegionStartOffset();
              int attrValueLength = oldAttrValue.length();
              int startTagStartOffset = node.getStartOffset();

              IDOMModel structuredModel = node.getModel();
              IStructuredDocument structuredDocument = structuredModel.getStructuredDocument();
View Full Code Here

      }
      else {
        if (fSeverityUnexpectedRuntimeExpression != ValidationMessage.IGNORE && adec instanceof TLDAttributeDeclaration) {
          // The attribute cannot have a runtime evaluation of an expression
          if (!isTrue(((TLDAttributeDeclaration) adec).getRtexprvalue())) {
            IDOMAttr attr = (IDOMAttr) a;
            if(checkRuntimeValue(attr) && !fIsELIgnored) {
              String msg = NLS.bind(JSPCoreMessages.JSPActionValidator_1, a.getName());
              LocalizedMessage message = new LocalizedMessage(fSeverityUnexpectedRuntimeExpression, msg, file);
              ITextRegion region = attr.getValueRegion();
              int start = attr.getValueRegionStartOffset();
              int length = region != null ? region.getTextLength() : 0;
              int lineNo = document.getLineOfOffset(start);
              message.setLineNo(lineNo);
              message.setOffset(start);
              message.setLength(length);
View Full Code Here

        ISourceGenerator generator = node.getModel().getGenerator();

        for (int i = 0; i < attributesLength; i++) {
          attributes = newNode.getAttributes();
          attributesLength = attributes.getLength();
          IDOMAttr eachAttr = (IDOMAttr) attributes.item(i);
          //ITextRegion oldAttrValueRegion =
          // eachAttr.getValueRegion();
          String oldAttrValue = eachAttr.getValueRegionText();
          if (oldAttrValue == null) {
            IDOMModel structuredModel = node.getModel();
            if (isXMLType(structuredModel)) {
              String newAttrValue = "\"" + eachAttr.getNameRegionText() + "\""; //$NON-NLS-1$ //$NON-NLS-2$

              IStructuredDocument structuredDocument = structuredModel.getStructuredDocument();
              if (eachAttr.getEqualRegion() != null)
                // equal region exists
                structuredDocument.replaceText(structuredDocument, eachAttr.getEndOffset(), 0, newAttrValue);
              else
                // no equal region
                structuredDocument.replaceText(structuredDocument, eachAttr.getNameRegionTextEndOffset(), 0, "=".concat(newAttrValue)); //$NON-NLS-1$
              newNode = (IDOMNode) structuredModel.getIndexedRegion(node.getStartOffset()); // save
              // new
              // node
            }
          } else {
            //String oldAttrValue = oldAttrValueRegion.getText();
            char quote = StringUtils.isQuoted(oldAttrValue) ? oldAttrValue.charAt(0) : DOUBLE_QUOTE;
            String newAttrValue = generator.generateAttrValue(eachAttr, quote);

            // There is a problem in
            // StructuredDocumentRegionUtil.getAttrValue(ITextRegion)
            // when the region is instanceof ContextRegion.
            // Workaround for now...
            if (oldAttrValue.length() == 1) {
              char firstChar = oldAttrValue.charAt(0);
              if (firstChar == SINGLE_QUOTE)
                newAttrValue = SINGLE_QUOTES;
              else if (firstChar == DOUBLE_QUOTE)
                newAttrValue = DOUBLE_QUOTES;
            }

            if (newAttrValue != null) {
              if (newAttrValue.compareTo(oldAttrValue) != 0) {
                int attrValueStartOffset = eachAttr.getValueRegionStartOffset();
                int attrValueLength = oldAttrValue.length();
                int startTagStartOffset = node.getStartOffset();

                IDOMModel structuredModel = node.getModel();
                IStructuredDocument structuredDocument = structuredModel.getStructuredDocument();
View Full Code Here

      ISourceGenerator generator = node.getModel().getGenerator();

      for (int i = 0; i < attributesLength; i++) {
        attributes = newNode.getAttributes();
        attributesLength = attributes.getLength();
        IDOMAttr eachAttr = (IDOMAttr) attributes.item(i);
        // ITextRegion oldAttrValueRegion = eachAttr.getValueRegion();
        String oldAttrValue = eachAttr.getValueRegionText();
        if (oldAttrValue == null) {
          IDOMModel structuredModel = node.getModel();
          if (isXMLType(structuredModel)) {
            // TODO: Kit, please check. Is there any way to not
            // rely on getting regions from attributes?
            String newAttrValue = "=\"" + eachAttr.getNameRegionText() + "\""; //$NON-NLS-1$ //$NON-NLS-2$

            IStructuredDocument structuredDocument = structuredModel.getStructuredDocument();
            replaceSource(structuredModel, structuredDocument, eachAttr.getNameRegionEndOffset(), 0, newAttrValue);
            newNode = (IDOMNode) structuredModel.getIndexedRegion(node.getStartOffset()); // save
            // new
            // node
          }
        }
        else {

          char quote = StringUtils.isQuoted(oldAttrValue) ? oldAttrValue.charAt(0) : DOUBLE_QUOTE;
          String newAttrValue = generator.generateAttrValue(eachAttr, quote);

          // There is a problem in
          // StructuredDocumentRegionUtil.getAttrValue(ITextRegion)
          // when the region is instanceof ContextRegion.
          // Workaround for now...
          if (oldAttrValue.length() == 1) {
            char firstChar = oldAttrValue.charAt(0);
            if (firstChar == SINGLE_QUOTE)
              newAttrValue = SINGLE_QUOTES;
            else if (firstChar == DOUBLE_QUOTE)
              newAttrValue = DOUBLE_QUOTES;
          }

          if (newAttrValue != null) {
            if (newAttrValue.compareTo(oldAttrValue) != 0) {
              int attrValueStartOffset = eachAttr.getValueRegionStartOffset();
              int attrValueLength = oldAttrValue.length();
              int startTagStartOffset = node.getStartOffset();

              IDOMModel structuredModel = node.getModel();
              IStructuredDocument structuredDocument = structuredModel.getStructuredDocument();
View Full Code Here

      IDOMContextResolver resolver = IStructuredDocumentContextResolverFactory.INSTANCE.getDOMContextResolver(getStructuredDocumentContext());
      if (resolver != null){
        Node aNode = resolver.getNode();
        if (aNode instanceof IDOMAttr) {
          Node tagNode = ((IDOMAttr)aNode).getOwnerElement();
          IDOMAttr typeNode = (IDOMAttr) tagNode.getAttributes().getNamedItem("type"); //$NON-NLS-1$
          if (typeNode != null)
            return typeNode.getValue();
        }       
      }
    }
    return ""; //$NON-NLS-1$
  }
View Full Code Here

TOP

Related Classes of org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr

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.