private static boolean isCollection(XmlElementDescriptor each) {
   XmlTag declaration = (XmlTag) each.getDeclaration();
   if (declaration != null) {
     XmlTag complexType = declaration.findFirstSubTag("xs:complexType");
     if (complexType != null) {
       if (complexType.findFirstSubTag("xs:sequence") != null) return true;
     }
   }
   return false;
 }
  public String[] getEnumeratedValues(XmlElement context) {
    final XmlElementDescriptorImpl elementDescriptor =
        (XmlElementDescriptorImpl)
            XmlUtil.findXmlDescriptorByType(
                myTag,
                context != null ? PsiTreeUtil.getContextOfType(context, XmlTag.class, true) : null);

    if (elementDescriptor != null && elementDescriptor.getType() instanceof ComplexTypeDescriptor) {
      final EnumerationData data =
          getEnumeratedValuesImpl(
              ((ComplexTypeDescriptor) elementDescriptor.getType()).getDeclaration());
      final String s = getDefaultValue();

      if (s != null && s.length() > 0 && data == null) {
        return new String[] {s};
      }
      return data != null ? data.enumeratedValues : ArrayUtil.EMPTY_STRING_ARRAY;
    }

    final String namespacePrefix = myTag.getNamespacePrefix();
    XmlTag type =
        myTag.findFirstSubTag(
            ((namespacePrefix.length() > 0) ? namespacePrefix + ":" : "") + "simpleType");

    if (type != null) {
      final EnumerationData data = getEnumeratedValuesImpl(type);
      return data != null ? data.enumeratedValues : ArrayUtil.EMPTY_STRING_ARRAY;
    }

    return ArrayUtil.EMPTY_STRING_ARRAY;
  }
Пример #3
0
  /**
   * @param xmlFile
   * @param tagName
   * @param tagValue
   * @param path hierarchy path, this will be the parent of the new tag, ex: root/node1/node2
   * @return
   */
  public static XmlTag createTagInFile(
      final XmlFile xmlFile,
      String tagName,
      String tagValue,
      String path,
      Map<String, String> attributes) {
    XmlTag root = xmlFile.getRootTag();

    String[] pathElements = path.split("/");

    if (pathElements.length > 0 && pathElements[0].equals(root.getName())) {
      XmlTag lastExistentParent = root;
      String curPath = pathElements[0];
      pathElements =
          (String[])
              ArrayUtils.remove(
                  pathElements, 0); // ArrayUtils.removeElement(pathElements, pathElements[0]);
      for (String curTagName : pathElements) {
        lastExistentParent = lastExistentParent.findFirstSubTag(curTagName);
        if (lastExistentParent == null) {
          lastExistentParent = createTagInFile(xmlFile, curTagName, "", curPath);
          if (lastExistentParent == null) {
            return null;
          }
        }
        curPath += "/" + curTagName;
      }
      final XmlTag newTag = lastExistentParent.createChildTag(tagName, "", tagValue, false);

      if (attributes != null) {
        for (Map.Entry<String, String> entry : attributes.entrySet()) {
          newTag.setAttribute(entry.getKey(), entry.getValue());
        }
      }

      final XmlTag parent = lastExistentParent;
      Runnable runnable =
          new Runnable() {
            @Override
            public void run() {
              new WriteCommandAction.Simple(
                  xmlFile.getProject(), "Create Xml Tag in File", xmlFile) {
                @Override
                protected void run() {

                  //                           newTag = (XmlTag)parent.add(newTag);
                  parent.addAfter(newTag, null);
                }
              }.execute();
            }
          };
      runnable.run();
      // PsiDocumentManager.getInstance(xmlFile.getProject()).commitDocument(document);
      return findSubTag(xmlFile, path + "/" + newTag.getName());

    } else {
      return null;
    }
  }
Пример #4
0
  /**
   * @param rootTag
   * @param path relative to root
   * @return
   */
  public static XmlTag findSubTag(@NotNull XmlTag rootTag, String path) {
    String[] pathElements = path.split("/");

    XmlTag curTag = rootTag;
    for (String curTagName : pathElements) {
      curTag = curTag.findFirstSubTag(curTagName);
      if (curTag == null) break;
    }
    return curTag;
  }
  private PsiElement tryResolveToActivationSection() {
    XmlTag xmlTag = PsiTreeUtil.getParentOfType(getElement(), XmlTag.class);
    while (xmlTag != null) {
      if (xmlTag.getName().equals("profile")) {
        XmlTag activation = xmlTag.findFirstSubTag("activation");
        if (activation != null) {
          for (XmlTag propertyTag : activation.findSubTags("property")) {
            XmlTag nameTag = propertyTag.findFirstSubTag("name");
            if (nameTag != null) {
              if (nameTag.getValue().getTrimmedText().equals(myText)) {
                return nameTag;
              }
            }
          }
        }
        break;
      }

      xmlTag = xmlTag.getParentTag();
    }

    return null;
  }
Пример #6
0
  @Nullable
  public static XmlTag findTag(@NotNull DomElement domElement, @NotNull String path) {
    List<String> elements = StringUtil.split(path, ".");
    if (elements.isEmpty()) return null;

    Pair<String, Integer> nameAndIndex = translateTagName(elements.get(0));
    String name = nameAndIndex.first;
    Integer index = nameAndIndex.second;

    XmlTag result = domElement.getXmlTag();
    if (result == null || !name.equals(result.getName())) return null;
    result = getIndexedTag(result, index);

    for (String each : elements.subList(1, elements.size())) {
      nameAndIndex = translateTagName(each);
      name = nameAndIndex.first;
      index = nameAndIndex.second;

      result = result.findFirstSubTag(name);
      if (result == null) return null;
      result = getIndexedTag(result, index);
    }
    return result;
  }