Exemple #1
0
  public XMLNode getPreviousSiblingTag(String allowed) {
    if (parent == null || parent.getType().equals("/") || allowed == null) return null;
    Position[] pos = null;
    try {
      pos = document.getPositions(XMLDocumentPartitioner.CONTENT_TYPES_CATEGORY);
    } catch (BadPositionCategoryException e) {
      e.printStackTrace();
      return null;
    }
    Arrays.sort(pos, COMPARATOR);
    int index = 0;
    while (pos[index] != this) index++;
    if (index > 0) {
      XMLNode result = null;
      for (int i = index - 1; i >= 0; i--) {
        result = (XMLNode) pos[i];
        if (result == parent) return null;
        String type = result.getType();
        if (result.getParent() != parent
            || (type.equals(ITypeConstants.TEXT)
                || type.equals(ITypeConstants.COMMENT)
                || type.equals(ITypeConstants.DECL))) {
          continue;
        }

        String name = result.getName();
        if (name == null) continue;
        if (type.equals(ITypeConstants.ENDTAG)) {
          XMLNode corresponding = result.getCorrespondingNode();
          if (allowed.indexOf(corresponding.getName().toLowerCase()) >= 0) return corresponding;
        } else if (allowed.indexOf(name) >= 0) {
          return result;
        }
      }
    }

    return null;
  }
Exemple #2
0
  /*
   * (non-Javadoc)
   *
   * @see org.eclipse.ui.model.IWorkbenchAdapter#getChildren(java.lang.Object)
   */
  public Object[] getChildren(Object obj) {
    if (obj instanceof XMLNode) {
      List result = new ArrayList();

      XMLNode artifact = (XMLNode) obj;
      for (Iterator it = artifact.getChildren().iterator(); it.hasNext(); ) {
        XMLNode child = (XMLNode) it.next();
        String childType = child.getType();
        if (childType == ITypeConstants.ENDTAG
            || (childType == ITypeConstants.TEXT && child.containsOnlyWhitespaces())) continue;
        result.add(child);
      }

      String type = artifact.getType();
      if (type == ITypeConstants.TAG || type == ITypeConstants.EMPTYTAG) {
        result.addAll(0, artifact.getAttributes());
      } else if (type == ITypeConstants.DECL) {
      }

      return result.toArray(new XMLNode[0]);
    }

    return null;
  }
Exemple #3
0
  /** @deprecated not needed anymore? */
  public XMLNode getPreviousSibling() {
    if (parent == null) throw new IllegalStateException("create tree first");

    String myType = getType();
    if (parent.getType().equals("/")) return null;
    if (myType.equals(ITypeConstants.ENDTAG)) {
      if (correspondingNode != null) {
        return correspondingNode.getPreviousSibling();
      } else {
        return null;
      }
    }

    XMLNode candidate = getPreviousArtifact();
    if (candidate == null) return null;
    if (candidate.parent == parent) return candidate;
    return null;
  }