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

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


        tagNameCase = getCleanupPreferences().getTagNameCase();
    }

    String oldTagName = node.getNodeName();
    String newTagName = oldTagName;
    IDOMNode newNode = node;

    /*
     * 254961 - all HTML tag names and attribute names should be in
     * English even for HTML files in other languages like Japanese or
     * Turkish. English locale should be used to convert between uppercase
View Full Code Here


      if (!converter.hasSpaces())
        return; // empty
      boolean removeSpaces = false;
      if (parent.getNodeType() == Node.ELEMENT_NODE) {
        // check if tags are omitted
        IDOMNode element = (IDOMNode) parent;
        if (node.getPreviousSibling() == null && element.getStartStructuredDocumentRegion() == null) {
          removeSpaces = true;
        }
        else if (node.getNextSibling() == null && element.getEndStructuredDocumentRegion() == null) {
          removeSpaces = true;
        }
      }
      if (removeSpaces) {
        converter.replaceSpaces(null);
View Full Code Here

  protected IDOMNode insertEndTag(IDOMNode node) {
    IDOMElement element = (IDOMElement) node;

    int startTagStartOffset = node.getStartOffset();
    IDOMModel structuredModel = node.getModel();
    IDOMNode newNode = null;

    if (element.isCommentTag()) {
      // do nothing
    }
    else if (isEmptyElement(element)) {
      IStructuredDocument structuredDocument = structuredModel.getStructuredDocument();
      IStructuredDocumentRegion startStructuredDocumentRegion = node.getStartStructuredDocumentRegion();
      ITextRegionList regions = startStructuredDocumentRegion.getRegions();
      ITextRegion lastRegion = regions.get(regions.size() - 1);
      replaceSource(structuredModel, structuredDocument, startStructuredDocumentRegion.getStartOffset(lastRegion), lastRegion.getLength(), EMPTY_TAG_CLOSE);

      if (regions.size() > 1) {
        ITextRegion regionBeforeTagClose = regions.get(regions.size() - 1 - 1);

        // insert a space separator before tag close if the previous
        // region does not have extra spaces
        if (regionBeforeTagClose.getTextLength() == regionBeforeTagClose.getLength())
          replaceSource(structuredModel, structuredDocument, startStructuredDocumentRegion.getStartOffset(lastRegion), 0, " "); //$NON-NLS-1$
      }
    }
    else {
      String tagName = node.getNodeName();
      String endTag = END_TAG_OPEN.concat(tagName).concat(TAG_CLOSE);

      IDOMNode lastChild = (IDOMNode) node.getLastChild();
      int endTagStartOffset = 0;
      if (lastChild != null)
        // if this node has children, insert the end tag after the
        // last child
        endTagStartOffset = lastChild.getEndOffset();
      else
        // if this node does not has children, insert the end tag
        // after the start tag
        endTagStartOffset = node.getEndOffset();
View Full Code Here

    return newNode;
  }

  protected IDOMNode insertMissingTags(IDOMNode node) {
    boolean insertMissingTags = getCleanupPreferences().getInsertMissingTags();
    IDOMNode newNode = node;

    if (insertMissingTags) {
      IStructuredDocumentRegion startTagStructuredDocumentRegion = node.getStartStructuredDocumentRegion();
      if (startTagStructuredDocumentRegion == null) {
        // implicit start tag; generate tag for it
        newNode = insertStartTag(node);
        startTagStructuredDocumentRegion = newNode.getStartStructuredDocumentRegion();
      }

      IStructuredDocumentRegion endTagStructuredDocumentRegion = newNode.getEndStructuredDocumentRegion();

      ITextRegionList regionList = startTagStructuredDocumentRegion.getRegions();
      if (startTagStructuredDocumentRegion != null && regionList != null && regionList.get(regionList.size() - 1).getType() == DOMRegionContext.XML_EMPTY_TAG_CLOSE) {

      }
View Full Code Here

  protected IDOMNode insertStartTag(IDOMNode node) {
    IDOMElement element = (IDOMElement) node;
    if (element.isCommentTag())
      return node; // do nothing

    IDOMNode newNode = null;

    String tagName = node.getNodeName();
    String startTag = START_TAG_OPEN.concat(tagName).concat(TAG_CLOSE);
    int startTagStartOffset = node.getStartOffset();
View Full Code Here

    IDOMElement element = (IDOMElement) node;
    if (element.isCommentTag())
      return node; // do nothing

    boolean quoteAttrValues = getCleanupPreferences().getQuoteAttrValues();
    IDOMNode newNode = node;

    if (quoteAttrValues) {
      NamedNodeMap attributes = newNode.getAttributes();
      int attributesLength = attributes.getLength();
      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) {
View Full Code Here

    return newNode;
  }

  private IDOMNode insertRequiredAttrs(IDOMNode node) {
    boolean insertRequiredAttrs = getCleanupPreferences().getInsertRequiredAttrs();
    IDOMNode newNode = node;

    if (insertRequiredAttrs) {
      List requiredAttrs = getRequiredAttrs(newNode);
      if (requiredAttrs.size() > 0) {
        NamedNodeMap currentAttrs = node.getAttributes();
        List insertAttrs = new ArrayList();
        if (currentAttrs.getLength() == 0)
          insertAttrs.addAll(requiredAttrs);
        else {
          for (int i = 0; i < requiredAttrs.size(); i++) {
            String requiredAttrName = ((CMAttributeDeclaration) requiredAttrs.get(i)).getAttrName();
            boolean found = false;
            for (int j = 0; j < currentAttrs.getLength(); j++) {
              String currentAttrName = currentAttrs.item(j).getNodeName();
              if (requiredAttrName.compareToIgnoreCase(currentAttrName) == 0) {
                found = true;
                break;
              }
            }
            if (!found)
              insertAttrs.add(requiredAttrs.get(i));
          }
        }
        if (insertAttrs.size() > 0) {
          IStructuredDocumentRegion startStructuredDocumentRegion = newNode.getStartStructuredDocumentRegion();
          int index = startStructuredDocumentRegion.getEndOffset();
          ITextRegion lastRegion = startStructuredDocumentRegion.getLastRegion();
          if (lastRegion.getType() == DOMRegionContext.XML_TAG_CLOSE) {
            index--;
            lastRegion = startStructuredDocumentRegion.getRegionAtCharacterOffset(index - 1);
          }
          else if (lastRegion.getType() == DOMRegionContext.XML_EMPTY_TAG_CLOSE) {
            index = index - 2;
            lastRegion = startStructuredDocumentRegion.getRegionAtCharacterOffset(index - 1);
          }
          MultiTextEdit multiTextEdit = new MultiTextEdit();
          try {
            for (int i = insertAttrs.size() - 1; i >= 0; i--) {
              CMAttributeDeclaration attrDecl = (CMAttributeDeclaration) insertAttrs.get(i);
              String requiredAttributeName = attrDecl.getAttrName();
              String defaultValue = attrDecl.getDefaultValue();
              if (defaultValue == null)
                defaultValue = ""; //$NON-NLS-1$
              String nameAndDefaultValue = " "; //$NON-NLS-1$
              if (i == 0 && lastRegion.getLength() > lastRegion.getTextLength())
                nameAndDefaultValue = ""; //$NON-NLS-1$
              nameAndDefaultValue += requiredAttributeName + "=\"" + defaultValue + "\""; //$NON-NLS-1$ //$NON-NLS-2$
              multiTextEdit.addChild(new InsertEdit(index, nameAndDefaultValue));
              // BUG3381: MultiTextEdit applies all child
              // TextEdit's basing on offsets
              // in the document before the first TextEdit, not
              // after each
              // child TextEdit. Therefore, do not need to
              // advance the index.
              // index += nameAndDefaultValue.length();
            }
            multiTextEdit.apply(newNode.getStructuredDocument());
          }
          catch (BadLocationException e) {
            // log or now, unless we find reason not to
            Logger.log(Logger.INFO, e.getMessage());
          }
View Full Code Here

   * @param node the {@link IDOMNode} to possible compress
   * @return the compressed node if the given node should be compressed, else the node as it was given
   */
  private IDOMNode compressEmptyElementTag(IDOMNode node) {
    boolean compressEmptyElementTags = getCleanupPreferences().getCompressEmptyElementTags();
    IDOMNode newNode = node;

    IStructuredDocumentRegion startTagStructuredDocumentRegion = newNode.getFirstStructuredDocumentRegion();
    IStructuredDocumentRegion endTagStructuredDocumentRegion = newNode.getLastStructuredDocumentRegion();

    //only compress tags if they are empty
    if ((compressEmptyElementTags && startTagStructuredDocumentRegion != endTagStructuredDocumentRegion &&
        startTagStructuredDocumentRegion != null)) {

      //only compress end tags if its XHTML or not a container
      if(isXMLTag((IDOMElement)newNode) || !newNode.isContainer()) {
        ITextRegionList regions = startTagStructuredDocumentRegion.getRegions();
        ITextRegion lastRegion = regions.get(regions.size() - 1);
        // format children and end tag if not empty element tag
        if (lastRegion.getType() != DOMRegionContext.XML_EMPTY_TAG_CLOSE) {
          NodeList childNodes = newNode.getChildNodes();
          if (childNodes == null || childNodes.getLength() == 0 || (childNodes.getLength() == 1 && (childNodes.item(0)).getNodeType() == Node.TEXT_NODE && ((childNodes.item(0)).getNodeValue().trim().length() == 0))) {
            IDOMModel structuredModel = newNode.getModel();
            IStructuredDocument structuredDocument = structuredModel.getStructuredDocument();

            int startTagStartOffset = newNode.getStartOffset();
            int offset = endTagStructuredDocumentRegion.getStart();
            int length = endTagStructuredDocumentRegion.getLength();
            structuredDocument.replaceText(structuredDocument, offset, length, ""); //$NON-NLS-1$
            newNode = (IDOMNode) structuredModel.getIndexedRegion(startTagStartOffset); // save

View Full Code Here

      if ("-".equals(command.text) && isPreferenceEnabled(JSPUIPreferenceNames.TYPING_COMPLETE_COMMENTS)) { //$NON-NLS-1$
        if (prefixedWith(document, command.offset, "<%-")) { //$NON-NLS-1$
         
          model = StructuredModelManager.getModelManager().getExistingModelForRead(document);
          if (model != null) {
            IDOMNode node = (IDOMNode) model.getIndexedRegion(command.offset);
            IDOMNode parent = (node != null) ? (IDOMNode) node.getParentNode() : null;
            // Parent is the scriptlet tag
            if (parent != null && JSP11Namespace.ElementName.SCRIPTLET.equals(parent.getNodeName()) && !parent.getSource().endsWith("--%>")) { //$NON-NLS-1$
              IStructuredDocumentRegion end = parent.getEndStructuredDocumentRegion();
              if (end != null) {
                try {
                  document.replace(end.getStartOffset(), 0, "--"); //$NON-NLS-1$
                } catch (BadLocationException e) {
                  Logger.logException(e);
View Full Code Here

   * add proposals for tags in attribute values
   */
  protected void addAttributeValueProposals(ContentAssistRequest contentAssistRequest) {
    addTemplates(contentAssistRequest, TemplateContextTypeIdsJSP.ATTRIBUTE_VALUE);

    IDOMNode node = (IDOMNode) contentAssistRequest.getNode();

    // add JSP extra proposals from JSPBeanInfoContentAssistProcessor
    // JSPPropertyContentAssistProcessor

    // 2.1
    // get results from JSPUseBean and JSPProperty here
    // (look up processor in a map based on node name)
    JSPDummyContentAssistProcessor extraProcessor = (JSPDummyContentAssistProcessor) fNameToProcessorMap.get(node.getNodeName());
    if (extraProcessor != null && contentAssistRequest != null) {
      extraProcessor.addAttributeValueProposals(contentAssistRequest);
    }

    ModelQuery mq = ModelQueryUtil.getModelQuery(node.getOwnerDocument());
    if (mq != null) {
      CMDocument doc = mq.getCorrespondingCMDocument(node);
      // this shouldn't have to have the prefix coded in
      if (doc instanceof JSPCMDocument || doc instanceof CMNodeWrapper || node.getNodeName().startsWith("jsp:")) //$NON-NLS-1$
        return;
    }

    // Find the attribute name for which this position should have a value
    IStructuredDocumentRegion open = node.getFirstStructuredDocumentRegion();
    ITextRegionList openRegions = open.getRegions();
    int i = openRegions.indexOf(contentAssistRequest.getRegion());
    if (i < 0)
      return;
    ITextRegion nameRegion = null;
    while (i >= 0) {
      nameRegion = openRegions.get(i--);
      if (nameRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME)
        break;
    }
   
    // on an empty value, add all the JSP and taglib tags
    CMElementDeclaration elementDecl = getCMElementDeclaration(node);
    if (nameRegion != null && elementDecl != null) {
      String attributeName = open.getText(nameRegion);
      if (attributeName != null) {
        String currentValue = node.getAttributes().getNamedItem(attributeName).getNodeValue();
       
        if(currentValue == null || currentValue.length() == 0) { //$NON-NLS-1$
          List additionalElements = ModelQueryUtil.getModelQuery(node.getOwnerDocument()).getAvailableContent((Element) node, elementDecl, ModelQuery.INCLUDE_ATTRIBUTES);
          for (i = 0; i < additionalElements.size(); i++) {
            Object additionalElement = additionalElements.get(i);
            if(additionalElement instanceof CMElementDeclaration) {
              CMElementDeclaration ed = (CMElementDeclaration) additionalElement;
 
              String tagname = getContentGenerator().getRequiredName(node, ed);
              StringBuffer contents = new StringBuffer("\""); //$NON-NLS-1$
              getContentGenerator().generateTag(node, ed, contents);
              contents.append('"'); //$NON-NLS-1$
              CustomCompletionProposal proposal = new CustomCompletionProposal(contents.toString(), contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), contents.length(), JSPEditorPluginImageHelper.getInstance().getImage(JSPEditorPluginImages.IMG_OBJ_TAG_GENERIC), tagname, null, null, XMLRelevanceConstants.R_JSP_ATTRIBUTE_VALUE);
              contentAssistRequest.addProposal(proposal);
            }
          }
       
        }
      }
    }
    else if (contentAssistRequest.getRegion().getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) {
      try {
        // Create a new model for Content Assist to operate on. This
        // will simulate
        // a full Document and then adjust the offset numbers in the
        // list of results.
        IStructuredModel internalModel = null;
        IModelManager mmanager = StructuredModelManager.getModelManager();
        internalModel = mmanager.createUnManagedStructuredModelFor(ContentTypeIdForJSP.ContentTypeID_JSP);
        IDOMNode xmlNode = null;
        IDOMModel xmlOuterModel = null;
        if (contentAssistRequest.getNode() instanceof IDOMNode) {
          xmlNode = (IDOMNode) contentAssistRequest.getNode();
          xmlOuterModel = xmlNode.getModel();
          internalModel.setResolver(xmlOuterModel.getResolver());
          internalModel.setBaseLocation(xmlOuterModel.getBaseLocation());
        }
        String contents = StringUtils.strip(contentAssistRequest.getText());
        if (xmlNode != null && contents != null) {
          int additionalShifts = 0;
          // Be sure that custom tags from taglibs also show up
          // by
          // adding taglib declarations to the internal model.
          TLDCMDocumentManager mgr = TaglibController.getTLDCMDocumentManager(xmlOuterModel.getStructuredDocument());
          if (mgr != null) {
            List trackers = mgr.getCMDocumentTrackers(contentAssistRequest.getReplacementBeginPosition());
            if (trackers != null) {
              for (i = 0; i < trackers.size(); i++) {
                CMDocumentTracker tracker = (CMDocumentTracker) trackers.get(i);
                String declaration = tracker.getStructuredDocumentRegion().getText();
                if (declaration != null) {
                  contents = declaration + contents;
                  additionalShifts += declaration.length();
                }
              }
            }
          }
          // Also copy any jsp:useBean tags so that
          // jsp:[gs]etProperty will function
          Document doc = null;
          if (contentAssistRequest.getNode().getNodeType() == Node.DOCUMENT_NODE)
            doc = (Document) node;
          else
            doc = node.getOwnerDocument();
          NodeList useBeans = doc.getElementsByTagName(JSP12Namespace.ElementName.USEBEAN);
          for (int k = 0; k < useBeans.getLength(); k++) {
            IDOMNode useBean = (IDOMNode) useBeans.item(k);
            if (useBean.getStartOffset() < contentAssistRequest.getReplacementBeginPosition()) {
              StringBuffer useBeanText = new StringBuffer("<jsp:useBean"); //$NON-NLS-1$
              for (int j = 0; j < useBean.getAttributes().getLength(); j++) {
                Attr attr = (Attr) useBean.getAttributes().item(j);
                useBeanText.append(' ');
                useBeanText.append(attr.getName());
                useBeanText.append("=\""); //$NON-NLS-1$
                useBeanText.append(attr.getValue());
                useBeanText.append('"');
View Full Code Here

TOP

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

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.