protected IRegion getRegion(IDocument document, final int offset) {
    StructuredModelWrapper smw = new StructuredModelWrapper();
    smw.init(document);
    try {
      Document xmlDocument = smw.getDocument();
      if (xmlDocument == null) return null;

      Node n = Utils.findNodeForOffset(xmlDocument, offset);

      if (n == null || !(n instanceof IDOMElement)) return null;

      IDOMElement elem = (IDOMElement) n;
      String tagName = elem.getTagName();
      int start = Utils.getValueStart(elem);
      final int nameStart =
          start + (elem.isEndTag() ? "</" : "<").length(); // $NON-NLS-1$ //$NON-NLS-2$
      final int nameEnd = nameStart + tagName.length();

      if (nameStart > offset || nameEnd <= offset) return null;

      return new Region(nameStart, nameEnd - nameStart);
    } finally {
      smw.dispose();
    }
  }
 public Element createElement(Document document, String data, boolean isJSPTag) {
   IDOMElement element = (IDOMElement) getHandler().createElement(document, data, isJSPTag);
   if (element != null) {
     CommentElementAdapter adapter =
         (CommentElementAdapter) element.getAdapterFor(CommentElementAdapter.class);
     if (adapter != null) {
       adapter.setConfiguration(this);
     }
   }
   return element;
 }
 public void getChildrenFromXml(List<Activity> list, IDOMElement input, Activity parent) {
   if (input.getLocalName().equals(IntSyslogSchemaConstants.ELEM_INBOUND_CHANNEL_ADAPTER)) {
     InboundChannelAdapterModelElement adapter =
         new InboundChannelAdapterModelElement(input, parent.getDiagram());
     list.add(adapter);
   }
 }
Ejemplo n.º 4
0
  public static PortletLayoutElement createFromElement(
      IDOMElement portletLayoutElement, ILayoutTplDiagramFactory factory) {
    if (portletLayoutElement == null) {
      return null;
    }

    PortletLayoutElement newPortletLayout = factory.newPortletLayout();

    String existingClassName = portletLayoutElement.getAttribute("class"); // $NON-NLS-1$

    if ((!CoreUtil.isNullOrEmpty(existingClassName))
        && existingClassName.contains("portlet-layout")) // $NON-NLS-1$
    {
      newPortletLayout.setClassName(existingClassName);
    } else {
      newPortletLayout.setClassName("portlet-layout"); // $NON-NLS-1$
    }

    IDOMElement[] portletColumnElements =
        LayoutTplUtil.findChildElementsByClassName(
            portletLayoutElement, "div", "portlet-column"); // $NON-NLS-1$ //$NON-NLS-2$

    for (IDOMElement portletColumnElement : portletColumnElements) {
      PortletColumnElement newPortletColumn =
          factory.newPortletColumnFromElement(portletColumnElement);
      newPortletLayout.addColumn(newPortletColumn);
    }

    return newPortletLayout;
  }
 public String generateTagName(Element element) {
   if (element == null) return null;
   IDOMElement xe = (IDOMElement) element;
   String tagName = element.getTagName();
   if (tagName == null) return null;
   if (xe.isJSPTag()) {
     if (tagName.equals(JSPTag.JSP_EXPRESSION)) return JSPTag.EXPRESSION_TOKEN;
     if (tagName.equals(JSPTag.JSP_DECLARATION)) return JSPTag.DECLARATION_TOKEN;
     if (tagName.equals(JSPTag.JSP_DIRECTIVE)) return JSPTag.DIRECTIVE_TOKEN;
     if (tagName.startsWith(JSPTag.JSP_DIRECTIVE)) {
       int offset = JSPTag.JSP_DIRECTIVE.length() + 1; // after '.'
       return (JSPTag.DIRECTIVE_TOKEN + tagName.substring(offset));
     }
     return (xe.isCommentTag()) ? tagName : null;
   } else if (tagName.startsWith(JSPTag.TAG_OPEN)) {
     if (!tagName.endsWith(JSPTag.TAG_CLOSE)) {
       // close JSP
       return (tagName + JSPTag.TAG_CLOSE);
     }
   } else if (xe.isCommentTag()) {
     String prefix = element.getPrefix();
     if (prefix.equals(SSI_PREFIX)) {
       return (SSI_TOKEN + element.getLocalName());
     }
   } else {
     if (!xe.isJSPTag()
         && xe.isGlobalTag()
         && // global tag
         CMNodeUtil.getElementDeclaration(xe) != null) {
       String newName = tagName;
       switch (getTagNameCase(xe)) {
         case DocumentTypeAdapter.UPPER_CASE:
           newName = tagName.toUpperCase(Locale.ENGLISH);
           break;
         case DocumentTypeAdapter.LOWER_CASE:
           newName = tagName.toLowerCase(Locale.ENGLISH);
           break;
       }
       if (newName != tagName) {
         tagName = newName;
         setTagName(element, tagName);
       }
     }
   }
   return tagName;
 }
 public static IRegion getElementRegion(IDOMElement element) {
   int endOffset;
   if (element.hasEndTag() && element.isClosed()) endOffset = element.getStartEndOffset();
   else endOffset = element.getEndOffset();
   return new Region(element.getStartOffset(), endOffset - element.getStartOffset());
 }
 void setupCommentElement(IDOMElement element) {
   element.setCommentTag(true);
   CommentElementAdapter adapter = new CommentElementAdapter(false, fHandler);
   adapter.setConfiguration(this);
   element.addAdapter(adapter);
 }