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

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


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

    IDOMModel structuredModel = node.getModel();
    IStructuredDocument structuredDocument = structuredModel.getStructuredDocument();
    replaceSource(structuredModel, structuredDocument, startTagStartOffset, 0, startTag);
    newNode = (IDOMNode) structuredModel.getIndexedRegion(startTagStartOffset); // save
    // new
    // node

    return newNode;
  }
View Full Code Here


        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();
              replaceSource(structuredModel, structuredDocument, attrValueStartOffset, attrValueLength, newAttrValue);
              newNode = (IDOMNode) structuredModel.getIndexedRegion(startTagStartOffset); // save
              // new
              // node
            }
          }
        }
View Full Code Here

        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

            offset = startTagStructuredDocumentRegion.getStart() + lastRegion.getStart();
            structuredDocument.replaceText(structuredDocument, offset, 0, "/"); //$NON-NLS-1$
            newNode = (IDOMNode) structuredModel.getIndexedRegion(startTagStartOffset); // save
          }
        }
      }
    }
View Full Code Here

  /**
   */
  protected boolean isCDATAContainer() {
    // use BlockMaker instead of CMElementDeclaration
    // because <style> and <script> in XHTML is not CDATA content type
    IDOMModel model = getModel();
    if (model == null)
      return false; // error
    IStructuredDocument structuredDocument = model.getStructuredDocument();
    if (structuredDocument == null || fTagName == null)
      return false; // eror
    RegionParser parser = structuredDocument.getParser();
    if (parser == null || !(parser instanceof XMLSourceParser))
      return false;
View Full Code Here

    return null;
  }

  private IProject getProject(Element element) {
    if (element instanceof IDOMElement) {
      IDOMModel model = ((IDOMElement) element).getModel();
      IFile file = StructuredModelUtil.getFileFor(model);
      if (file != null) {
        return file.getProject();
      }
    }
View Full Code Here

    return null;//default - all!
  }

  private IFile getFile(Element element) {
    if (element instanceof IDOMElement) {
      IDOMModel model = ((IDOMElement) element).getModel();
      IFile file = StructuredModelUtil.getFileFor(model);
      return file;
    }
    return null;
  }
View Full Code Here

  public String getURIfromTLD(File tldFile) {

    if (tldFile == null) {
      return null;
    }
    IDOMModel tldModel = null;

    InputStream in = null;
    try {
      in = new FileInputStream(tldFile);
    } catch (FileNotFoundException e) {
      _log.error("RenderingTraverser.Error.FileNotFound", e); //$NON-NLS-1$
      return null;
    }
//    IDOMModel xmlModel = null;

    try {
      tldModel = (IDOMModel) StructuredModelManager.getModelManager().getModelForRead(
          tldFile.getAbsolutePath(), in, null);
      NodeList uriList = tldModel.getDocument().getElementsByTagName(
          TLD_TAG_URI);
      for (int i = 0, n = uriList.getLength(); i < n; i++) {
        Node uri = uriList.item(i);
        return uri.getChildNodes().item(0).getNodeValue();
      }
    } catch (UnsupportedEncodingException e1) {
      _log.error("RenderingTraverser.Error.UnsupportedEncoding", e1); //$NON-NLS-1$
    } catch (IOException e1) {
      _log.error("RenderingTraverser.Error.IO", e1); //$NON-NLS-1$
    } finally {
      ResourceUtils.ensureClosed(in);
     
      if (tldModel != null)
      {
          tldModel.releaseFromRead();
      }
    }

    return null;
  }
View Full Code Here

   */
  public String getURIfromTLD(IFile tldFile) {
    if (tldFile == null) {
      return null;
    }
    IDOMModel tldModel;

    try {
      tldModel = (IDOMModel) getModelManager().getModelForRead(tldFile);
      NodeList uriList = tldModel.getDocument().getElementsByTagName(
          TLD_TAG_URI);
      for (int i = 0, n = uriList.getLength(); i < n; i++) {
        Node uri = uriList.item(i);
        return uri.getChildNodes().item(0).getNodeValue();
      }
View Full Code Here

      }
      if (uri.startsWith(URI_PREFIX_HTTP)) {
        IFile webxml = WebrootUtil.getWebContentContainer(_project)
            .getFolder(new Path(IFileFolderConstants.FOLDER_WEBINF)).getFile(
                IFileFolderConstants.FILE_WEB_XML);
        IDOMModel xmlModel;

        if (webxml.exists()) {
          try {
            xmlModel = (IDOMModel) getModelManager()
                .getModelForRead(webxml);

            NodeList taglibNodeList = xmlModel
                .getDocument()
                .getElementsByTagName(ICSSPropertyID.TAG_TAGLIB);

            for (int i = 0, size = taglibNodeList.getLength(); i < size; i++) {
              Node taglibNode = taglibNodeList.item(i);

              NodeList childList = taglibNode.getChildNodes();
              String taguri = ""; //$NON-NLS-1$
              String taglocation = ""; //$NON-NLS-1$
              for (int j = 0, childSize = childList.getLength(); j < childSize; j++) {
                Node childTaglibNode = childList.item(j);
                if (ICSSPropertyID.ATTR_TAGLIB_URI
                    .equalsIgnoreCase(childTaglibNode
                        .getNodeName())) {
                  taguri = childTaglibNode.getChildNodes()
                      .item(0).getNodeValue();
                }
                if (ICSSPropertyID.ATTR_TAGLIB_LOCATION
                    .equalsIgnoreCase(childTaglibNode
                        .getNodeName())) {
                  taglocation = childTaglibNode
                      .getChildNodes().item(0)
                      .getNodeValue();
                }

              }
              if (uri.equalsIgnoreCase(taguri))
                uri = _project.getProject().getLocation()
                    .toString()
                    + IFileFolderConstants.PATH_SEPARATOR
                    + WebrootUtil
                        .getWebContentFolderName(_project)
                    + taglocation;
            }
            xmlModel.releaseFromRead();
          } catch (IOException e) {

            // Error in taglib locating.
            _log.error(
                "Error.ProjectResolver.GetlocationByURI.0", e); //$NON-NLS-1$
View Full Code Here

    IResource adapter = null;
    if (adapterType.equals(IResource.class)) {
      if (adaptableObject instanceof NodeEditPart) {
        final IDOMNode node = ((NodeEditPart)adaptableObject).getIDOMNode();
        if (node != null) {
          final IDOMModel model = node.getModel();
          if (model != null) {
            adapter = StructuredModelUtil.getFileFor(model);
          }
        }
      }
View Full Code Here

TOP

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

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.