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

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


   */
  private void smartRemoveEndTag(DocumentCommand command, IDocument document, IStructuredModel model) {
    try {
      // An opening tag is now a self-terminated end-tag
      if ("/".equals(command.text) && ">".equals(document.get(command.offset, 1)) && command.length == 0 && HTMLUIPlugin.getDefault().getPreferenceStore().getBoolean(HTMLUIPreferenceNames.TYPING_REMOVE_END_TAGS)) { //$NON-NLS-1$ //$NON-NLS-2$
        IDOMNode node = (IDOMNode) model.getIndexedRegion(command.offset);
        if (node != null && !node.hasChildNodes()) {
          IStructuredDocumentRegion region = node.getFirstStructuredDocumentRegion();
          if(region.getFirstRegion().getType() == DOMRegionContext.XML_TAG_OPEN && command.offset <= region.getEnd()) {
           
            /* if the region before the command offset is a an attribute value region
             * check to see if it has both and opening and closing quote
             */
            ITextRegion prevTextRegion = region.getRegionAtCharacterOffset(command.offset-1);
            boolean inUnclosedAttValueRegion = false;
            if(prevTextRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) {
              //get the text of the attribute value region
              String prevText = region.getText(prevTextRegion);
              inUnclosedAttValueRegion = (prevText.startsWith("'") && ((prevText.length() == 1) || !prevText.endsWith("'"))) ||
                (prevText.startsWith("\"") && ((prevText.length() == 1) || !prevText.endsWith("\"")));
            }
         
            //if command offset is in an unclosed attribute value region then done remove the end tag
            if(!inUnclosedAttValueRegion) {
              region = node.getEndStructuredDocumentRegion();
              if (region != null && region.isEnded()) {
                document.replace(region.getStartOffset(), region.getLength(), ""); //$NON-NLS-1$
              }
            }
          }
View Full Code Here


      ContentAssistRequest contentAssistRequest,
      CompletionProposalInvocationContext context) {
   
    IPath basePath = getBasePath(contentAssistRequest);
    if (basePath != null) {
      IDOMNode node = (IDOMNode) contentAssistRequest.getNode();
 
      //only add attribute value proposals for specific elements
      if(node.getNodeName().equals(JSP11Namespace.ElementName.DIRECTIVE_TAGLIB)) {
        // 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;
        }
   
        String attributeName = null;
        if (nameRegion != null)
          attributeName = open.getText(nameRegion);
   
        String currentValue = null;
        if (contentAssistRequest.getRegion().getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE)
          currentValue = contentAssistRequest.getText();
        else
          currentValue = ""; //$NON-NLS-1$
        String matchString = null;
        // fixups
        int start = contentAssistRequest.getReplacementBeginPosition();
        int length = contentAssistRequest.getReplacementLength();
        if (currentValue.length() > StringUtils.strip(currentValue).length() &&
            (currentValue.startsWith("\"") || currentValue.startsWith("'")) && //$NON-NLS-1$ //$NON-NLS-2$
            contentAssistRequest.getMatchString().length() > 0) {
         
          matchString = currentValue.substring(1, contentAssistRequest.getMatchString().length());
        }
        else {
          matchString = currentValue.substring(0, contentAssistRequest.getMatchString().length());
        }
        boolean existingComplicatedValue = contentAssistRequest.getRegion() != null &&
            contentAssistRequest.getRegion() instanceof ITextRegionContainer;
        if (existingComplicatedValue) {
          contentAssistRequest.getProposals().clear();
          contentAssistRequest.getMacros().clear();
        }
        else {
          String lowerCaseMatch = matchString.toLowerCase(Locale.US);
          if (attributeName.equals(JSP11Namespace.ATTR_NAME_URI)) {
            ITaglibRecord[] availableTaglibRecords = TaglibIndex.getAvailableTaglibRecords(basePath);
            /*
             * a simple enough way to remove duplicates (resolution at
             * runtime would be nondeterministic anyway)
             */
            Map uriToRecords = new HashMap();
            for (int taglibRecordNumber = 0; taglibRecordNumber < availableTaglibRecords.length; taglibRecordNumber++) {
              ITaglibRecord taglibRecord = availableTaglibRecords[taglibRecordNumber];
              ITaglibDescriptor descriptor = taglibRecord.getDescriptor();
              String uri = null;
              switch (taglibRecord.getRecordType()) {
                case ITaglibRecord.URL :
                  uri = descriptor.getURI();
                  uriToRecords.put(uri, taglibRecord);
                  break;
                case ITaglibRecord.JAR : {
                  IPath location = ((IJarRecord) taglibRecord).getLocation();
                  IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(location);
                  IPath localContextRoot = FacetModuleCoreSupport.computeWebContentRootPath(basePath);
                  for (int fileNumber = 0; fileNumber < files.length; fileNumber++) {
                    if (localContextRoot.isPrefixOf(files[fileNumber].getFullPath())) {
                      uri = IPath.SEPARATOR +
                          files[fileNumber].getFullPath().removeFirstSegments(localContextRoot.segmentCount()).toString();
                      uriToRecords.put(uri, taglibRecord);
                    }
                    else {
                      uri = FacetModuleCoreSupport.getRuntimePath(files[fileNumber].getFullPath()).toString();
                      uriToRecords.put(uri, taglibRecord);
                    }
                  }
                  break;
                }
                case ITaglibRecord.TLD : {
                  uri = descriptor.getURI();
                  if (uri == null || uri.trim().length() == 0) {
                    IPath path = ((ITLDRecord) taglibRecord).getPath();
                    IPath localContextRoot = FacetModuleCoreSupport.computeWebContentRootPath(basePath);
                    if (localContextRoot.isPrefixOf(path)) {
                      uri = IPath.SEPARATOR + path.removeFirstSegments(localContextRoot.segmentCount()).toString();
                    }
                    else {
                      uri = FacetModuleCoreSupport.getRuntimePath(path).toString();
                    }
                  }
                  uriToRecords.put(uri, taglibRecord);
                  break;
                }
              }
            }
            /*
             * use the records and their descriptors to construct
             * proposals
             */
            Object[] uris = uriToRecords.keySet().toArray();
            for (int uriNumber = 0; uriNumber < uris.length; uriNumber++) {
              String uri = uris[uriNumber].toString();
              ITaglibRecord taglibRecord = (ITaglibRecord) uriToRecords.get(uri);
              ITaglibDescriptor descriptor = (taglibRecord).getDescriptor();
              if (uri != null && uri.length() > 0 && (matchString.length() == 0 ||
                  uri.toLowerCase(Locale.US).startsWith(lowerCaseMatch))) {
               
                String url = getSmallImageURL(taglibRecord);
                ImageDescriptor imageDescriptor = JSPUIPlugin.getInstance().getImageRegistry().getDescriptor(url);
                if (imageDescriptor == null && url != null) {
                  URL imageURL;
                  try {
                    imageURL = new URL(url);
                    imageDescriptor = ImageDescriptor.createFromURL(imageURL);
                    JSPUIPlugin.getInstance().getImageRegistry().put(url, imageDescriptor);
                  }
                  catch (MalformedURLException e) {
                    Logger.logException(e);
                  }
                }
                String additionalInfo = descriptor.getDisplayName() + "<br/>" + //$NON-NLS-1$
                    descriptor.getDescription() + "<br/>" + descriptor.getTlibVersion(); //$NON-NLS-1$
                Image image = null;
                try {
                  image = JSPUIPlugin.getInstance().getImageRegistry().get(url);
                }
                catch (Exception e) {
                  Logger.logException(e);
                }
                if (image == null) {
                  image = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ATTRIBUTE);
                }
                CustomCompletionProposal proposal = new CustomCompletionProposal(
                    "\"" + uri + "\"", start, length, uri.length() + 2, //$NON-NLS-1$ //$NON-NLS-2$
                    image, uri, null, additionalInfo, IRelevanceConstants.R_NONE);
                contentAssistRequest.addProposal(proposal);
              }
            }
          }
          else if (attributeName.equals(JSP20Namespace.ATTR_NAME_TAGDIR)) {
            ITaglibRecord[] availableTaglibRecords = TaglibIndex.getAvailableTaglibRecords(basePath);
            /*
             * a simple enough way to remove duplicates (resolution at
             * runtime would be nondeterministic anyway)
             */
            Map uriToRecords = new HashMap();
            IPath localContextRoot = FacetModuleCoreSupport.computeWebContentRootPath(basePath);
            for (int taglibRecordNumber = 0; taglibRecordNumber < availableTaglibRecords.length; taglibRecordNumber++) {
              ITaglibRecord taglibRecord = availableTaglibRecords[taglibRecordNumber];
              String uri = null;
              if (taglibRecord.getRecordType() == ITaglibRecord.TAGDIR) {
                IPath path = ((ITagDirRecord) taglibRecord).getPath();
                if (localContextRoot.isPrefixOf(path)) {
                  uri = IPath.SEPARATOR + path.removeFirstSegments(localContextRoot.segmentCount()).toString();
                  uriToRecords.put(uri, taglibRecord);
                }
              }
            }
            /*
             * use the records and their descriptors to construct
             * proposals
             */
            Object[] uris = uriToRecords.keySet().toArray();
            for (int uriNumber = 0; uriNumber < uris.length; uriNumber++) {
              String uri = uris[uriNumber].toString();
              ITaglibRecord taglibRecord = (ITaglibRecord) uriToRecords.get(uri);
              ITaglibDescriptor descriptor = (taglibRecord).getDescriptor();
              if (uri != null && uri.length() > 0 && (matchString.length() == 0 ||
                  uri.toLowerCase(Locale.US).startsWith(lowerCaseMatch))) {
               
                String url = getSmallImageURL(taglibRecord);
                ImageDescriptor imageDescriptor = null;
                if (url != null) {
                  imageDescriptor = JSPUIPlugin.getInstance().getImageRegistry().getDescriptor(url);
                }
                if (imageDescriptor == null && url != null) {
                  URL imageURL;
                  try {
                    imageURL = new URL(url);
                    imageDescriptor = ImageDescriptor.createFromURL(imageURL);
                    JSPUIPlugin.getInstance().getImageRegistry().put(url, imageDescriptor);
                  }
                  catch (MalformedURLException e) {
                    Logger.logException(e);
                  }
                }
                String additionalInfo = descriptor.getDescription() + "<br/>" + descriptor.getTlibVersion(); //$NON-NLS-1$
                Image image = null;
                try {
                  image = JSPUIPlugin.getInstance().getImageRegistry().get(url);
                }
                catch (Exception e) {
                  Logger.logException(e);
                }
                if (image == null) {
                  image = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ATTRIBUTE);
                }
                CustomCompletionProposal proposal = new CustomCompletionProposal(
                    "\"" + uri + "\"", start, length, uri.length() + 2, image, uri, //$NON-NLS-1$ //$NON-NLS-2$
                    null, additionalInfo, IRelevanceConstants.R_NONE);
                contentAssistRequest.addProposal(proposal);
              }
            }
          }
          else if (attributeName.equals(JSP11Namespace.ATTR_NAME_PREFIX)) {
            Node uriAttr = node.getAttributes().getNamedItem(JSP11Namespace.ATTR_NAME_URI);
            String uri = null;
            if (uriAttr != null) {
              uri = uriAttr.getNodeValue();
              ITaglibRecord[] availableTaglibRecords = TaglibIndex.getAvailableTaglibRecords(basePath);
              Map prefixMap = new HashMap();
              for (int taglibrecordNumber = 0; taglibrecordNumber < availableTaglibRecords.length; taglibrecordNumber++) {
                ITaglibDescriptor descriptor = availableTaglibRecords[taglibrecordNumber].getDescriptor();
                if (descriptor != null && descriptor.getURI() != null &&
                    descriptor.getURI().toLowerCase(Locale.US).equals(uri.toLowerCase(Locale.US))) {
                  String shortName = descriptor.getShortName().trim();
                  if (shortName.length() > 0) {
                    boolean valid = true;
                    for (int character = 0; character < shortName.length(); character++) {
                      valid = valid && !Character.isWhitespace(shortName.charAt(character));
                    }
                    if (valid) {
                      prefixMap.put(shortName, descriptor);
                    }
                  }
                }
              }
              Object prefixes[] = prefixMap.keySet().toArray();
              for (int j = 0; j < prefixes.length; j++) {
                String prefix = (String) prefixes[j];
                ITaglibDescriptor descriptor = (ITaglibDescriptor) prefixMap.get(prefix);
                Image image = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ATTRIBUTE);
                CustomCompletionProposal proposal = new CustomCompletionProposal(
                    "\"" + prefix + "\"", start, length, prefix.length() + 2, image, //$NON-NLS-1$ //$NON-NLS-2$
                    prefix, null, descriptor.getDescription(), IRelevanceConstants.R_NONE);
                contentAssistRequest.addProposal(proposal);
              }
            }
            else {
              Node dirAttr = node.getAttributes().getNamedItem(JSP20Namespace.ATTR_NAME_TAGDIR);
              if (dirAttr != null) {
                String dir = dirAttr.getNodeValue();
                if (dir != null) {
                  ITaglibRecord record = TaglibIndex.resolve(basePath.toString(), dir, false);
                  if (record != null) {
View Full Code Here

  protected void addAttributeValueProposals(
      ContentAssistRequest contentAssistRequest,
      CompletionProposalInvocationContext context) {

    if(!this.isXHTML) {
      IDOMNode node = (IDOMNode) contentAssistRequest.getNode();
 
      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 =
        AbstractXMLModelQueryCompletionProposalComputer.getCMElementDeclaration(node);
      if (nameRegion != null && elementDecl != null) {
        String attributeName = open.getText(nameRegion);
        if (attributeName != null) {
          Node parent = contentAssistRequest.getParent();
         
          //ignore start quote in match string
          String matchString = contentAssistRequest.getMatchString().trim();
          if(matchString.startsWith("'") || matchString.startsWith("\"")) { //$NON-NLS-1$ //$NON-NLS-2$
            matchString = matchString.substring(1);
          }
         
          //get all the proposals
          List additionalElements = ModelQueryUtil.getModelQuery(node.getOwnerDocument()).getAvailableContent(
              (Element) node, elementDecl, ModelQuery.INCLUDE_ALL);
          Iterator nodeIterator = additionalElements.iterator();
         
          //check each suggestion
          while (nodeIterator.hasNext()) {
View Full Code Here

  protected INodeAdapter createAdapter(INodeNotifier target) {
    if (Debug.displayInfo)
      System.out.println("-----------------------ModelQueryAdapterFactoryForJSP.createAdapter" + target); //$NON-NLS-1$
    if (modelQueryAdapterImpl == null) {
      if (target instanceof IDOMNode) {
        IDOMNode xmlNode = (IDOMNode) target;
        IStructuredModel model = stateNotifier = xmlNode.getModel();
        if (model.getBaseLocation() != null) {
          stateNotifier.addModelStateListener(this);
        }

        org.eclipse.wst.sse.core.internal.util.URIResolver resolver = model.getResolver();
View Full Code Here

    // get old content length
    Node child = element.getFirstChild();
    if (child == null || child.getNodeType() != Node.TEXT_NODE)
      return;
    IDOMNode content = (IDOMNode) child;
    int oldLength = content.getEndOffset() - content.getStartOffset();

    // get new content length
    int newLength = 0;
    IStructuredDocumentRegionList flatNodes = structuredDocument.getRegionList();
    if (flatNodes != null) {
View Full Code Here

      String prefix = node.getPrefix();

      if (result == null && prefix != null && prefix.length() > 0 && node instanceof IDOMNode) {
        // check position dependent
        IDOMNode xmlNode = (IDOMNode) node;
        TLDCMDocumentManager tldmgr = TaglibController.getTLDCMDocumentManager(xmlNode.getStructuredDocument());
        if (tldmgr != null) {
          List documents = tldmgr.getCMDocumentTrackers(node.getPrefix(), xmlNode.getStartOffset());
          // there shouldn't be more than one cmdocument returned
          if (documents != null && !documents.isEmpty())
            result = (CMDocument) documents.get(0);
        }
      }
View Full Code Here

  /**
   * Apply changes from CSS sub-model to HTML model
   */
  private void replaceData(int offset, int length, String data) {
    IDOMNode element = (IDOMNode) getElement();
    if (element == null)
      return;
    IDOMModel ownerModel = element.getModel();
    if (ownerModel == null)
      return;
    IStructuredDocument structuredDocument = ownerModel.getStructuredDocument();
    if (structuredDocument == null)
      return;
    IStructuredDocumentRegion flatNode = element.getStartStructuredDocumentRegion();
    if (flatNode == null)
      return;

    int contentOffset = flatNode.getEndOffset();
    if (data == null)
View Full Code Here

  protected static final String DOUBLE_QUOTES = "\"\""; //$NON-NLS-1$
  protected static final char SINGLE_QUOTE = '\''; //$NON-NLS-1$
  protected static final char DOUBLE_QUOTE = '\"'; //$NON-NLS-1$

  public Node cleanup(Node node) {
    IDOMNode renamedNode = (IDOMNode) cleanupChildren(node);

    // call quoteAttrValue() first so it will close any unclosed attr
    // quoteAttrValue() will return the new start tag if there is a
    // structure change
    renamedNode = quoteAttrValue(renamedNode);

    // insert tag close if missing
    // if node is not comment tag
    // and not implicit tag
    if (!((IDOMElement) renamedNode).isCommentTag() && (renamedNode.getStartStructuredDocumentRegion() != null)) {
      IDOMModel structuredModel = renamedNode.getModel();

      // save start offset before insertTagClose()
      // or else renamedNode.getStartOffset() will be zero if
      // renamedNode replaced by insertTagClose()
      int startTagStartOffset = renamedNode.getStartOffset();

      // for start tag
      IStructuredDocumentRegion startTagStructuredDocumentRegion = renamedNode.getStartStructuredDocumentRegion();
      insertTagClose(structuredModel, startTagStructuredDocumentRegion);

      // update renamedNode and startTagStructuredDocumentRegion after
      // insertTagClose()
      renamedNode = (IDOMNode) structuredModel.getIndexedRegion(startTagStartOffset);
      startTagStructuredDocumentRegion = renamedNode.getStartStructuredDocumentRegion();

      // for end tag
      IStructuredDocumentRegion endTagStructuredDocumentRegion = renamedNode.getEndStructuredDocumentRegion();
      if (endTagStructuredDocumentRegion != startTagStructuredDocumentRegion)
        insertTagClose(structuredModel, endTagStructuredDocumentRegion);
    }

    // call insertMissingTags() next, it will generate implicit tags if
View Full Code Here

    super();
    notifierAtCreation = target;
    // we need to remember our instance of model,
    // in case we need to "signal" a re-init needed.
    if (target instanceof IDOMNode) {
      IDOMNode node = (IDOMNode) target;
      model = node.getModel();
    }

  }
View Full Code Here

    NamedNodeMap attributes = node.getAttributes();
    int attributesLength = attributes.getLength();

    for (int i = 0; i < attributesLength; i++) {
      IDOMNode eachAttr = (IDOMNode) attributes.item(i);
      if (hasNestedRegion(eachAttr.getNameRegion()))
        continue;
      String oldAttrName = eachAttr.getNodeName();
      String newAttrName = oldAttrName;
      /*
       * 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 and lowercase (otherwise "link" would be converted to
       * Turkish "I Overdot Capital").
       */
      if (attrNameCase == HTMLCorePreferenceNames.LOWER)
        newAttrName = oldAttrName.toLowerCase(Locale.US);
      else if (attrNameCase == HTMLCorePreferenceNames.UPPER)
        newAttrName = oldAttrName.toUpperCase(Locale.US);

      if (newAttrName.compareTo(oldAttrName) != 0) {
        int attrNameStartOffset = eachAttr.getStartOffset();
        int attrNameLength = oldAttrName.length();

        IDOMModel structuredModel = node.getModel();
        IStructuredDocument structuredDocument = structuredModel.getStructuredDocument();
        replaceSource(structuredModel, structuredDocument, attrNameStartOffset, attrNameLength, newAttrName);
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.