• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java XmlUtil类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.intellij.xml.util.XmlUtil的典型用法代码示例。如果您正苦于以下问题:Java XmlUtil类的具体用法?Java XmlUtil怎么用?Java XmlUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



XmlUtil类属于com.intellij.xml.util包,在下文中一共展示了XmlUtil类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: insertSchemaLocationLookup

import com.intellij.xml.util.XmlUtil; //导入依赖的package包/类
public static void insertSchemaLocationLookup(XmlFile xmlFile, String namespace, String locationLookup) {
    final XmlTag rootTag = xmlFile.getRootTag();
    if (rootTag == null)
        return;
    final XmlAttribute attribute = rootTag.getAttribute("xsi:schemaLocation", HTTP_WWW_W3_ORG_2001_XMLSCHEMA);
    if (attribute != null) {
        final String value = attribute.getValue();
        attribute.setValue(value + "\n\t\t\t" + namespace + " " + locationLookup);
    } else {
        final XmlElementFactory elementFactory = XmlElementFactory.getInstance(xmlFile.getProject());
        final XmlAttribute schemaLocation = elementFactory.createXmlAttribute("xsi:schemaLocation", XmlUtil.XML_SCHEMA_INSTANCE_URI);
        schemaLocation.setValue(namespace + " " + locationLookup);
        rootTag.add(schemaLocation);
    }

}
 
开发者ID:machaval,项目名称:mule-intellij-plugins,代码行数:17,代码来源:MuleSchemaUtils.java


示例2: getChildrenByName

import com.intellij.xml.util.XmlUtil; //导入依赖的package包/类
public List<DomStub> getChildrenByName(final CharSequence name, @Nullable final String nsKey) {
  final List<DomStub> stubs = getChildrenStubs();
  if (stubs.isEmpty()) {
    return Collections.emptyList();
  }

  final String s = nsKey == null ? "" : nsKey;
  final List<DomStub> result = new SmartList<DomStub>();
  //noinspection ForLoopReplaceableByForEach
  for (int i = 0, size = stubs.size(); i < size; i++) {
    final DomStub stub = stubs.get(i);
    if (XmlUtil.getLocalName(stub.getName()).equals(name) &&
        Comparing.equal(s, stub.getNamespaceKey())) {
      result.add(stub);
    }
  }
  return result;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:DomStub.java


示例3: getElementsToSurround

import com.intellij.xml.util.XmlUtil; //导入依赖的package包/类
@Override
@NotNull public PsiElement[] getElementsToSurround(PsiFile file, int startOffset, int endOffset) {
  final Pair<XmlTagChild, XmlTagChild> childrenInRange = XmlUtil.findTagChildrenInRange(file, startOffset, endOffset);
  if (childrenInRange == null) {
    final PsiElement elementAt = file.findElementAt(startOffset);
    if (elementAt instanceof XmlToken &&
        ((XmlToken)elementAt).getTokenType() == XmlTokenType.XML_DATA_CHARACTERS) {
      return new PsiElement[] {elementAt};
    }
    return PsiElement.EMPTY_ARRAY;
  }
  List<PsiElement> result = new ArrayList<PsiElement>();
  PsiElement first = childrenInRange.getFirst();
  PsiElement last = childrenInRange.getSecond();
  while(true) {
    result.add(first);
    if (first == last) break;
    first = first.getNextSibling();
  }

  return PsiUtilCore.toPsiElementArray(result);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:XmlSurroundDescriptor.java


示例4: calcXmlFileHeader

import com.intellij.xml.util.XmlUtil; //导入依赖的package包/类
@NotNull
private static XmlFileHeader calcXmlFileHeader(final XmlFile file) {

  if (file instanceof PsiFileEx && ((PsiFileEx)file).isContentsLoaded() && file.getNode().isParsed()) {
    return computeHeaderByPsi(file);
  }

  if (!XmlUtil.isStubBuilding() && file.getFileType() == XmlFileType.INSTANCE) {
    VirtualFile virtualFile = file.getVirtualFile();
    if (virtualFile instanceof VirtualFileWithId) {
      ObjectStubTree tree = StubTreeLoader.getInstance().readFromVFile(file.getProject(), virtualFile);
      if (tree != null) {
        Stub root = tree.getRoot();
        if (root instanceof FileStub) {
          return ((FileStub)root).getHeader();
        }
      }
    }
  }

  if (!file.isValid()) return XmlFileHeader.EMPTY;

  return NanoXmlUtil.parseHeader(file);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:DomServiceImpl.java


示例5: isSchemaEnumerated

import com.intellij.xml.util.XmlUtil; //导入依赖的package包/类
public static boolean isSchemaEnumerated(final PsiElement element) {
  if (element instanceof XmlTag) {
    final XmlTag simpleContent = XmlUtil.getSchemaSimpleContent((XmlTag)element);
    if (simpleContent != null && XmlUtil.collectEnumerationValues(simpleContent, new HashSet<String>())) {
      return true;
    }                  
  }
  if (element instanceof XmlAttributeValue) {
    final PsiElement parent = element.getParent();
    if (parent instanceof XmlAttribute) {
      final XmlAttributeDescriptor descriptor = ((XmlAttribute)parent).getDescriptor();
      if (descriptor != null && descriptor.isEnumerated()) {
        return true;
      }

      String[] enumeratedValues = XmlAttributeValueGetter.getEnumeratedValues((XmlAttribute)parent);
      if (enumeratedValues != null && enumeratedValues.length > 0) {
        String value = descriptor == null ? null : descriptor.getDefaultValue();
        if (value == null || enumeratedValues.length != 1 || !value.equals(enumeratedValues[0])) {
          return true;
        }
      }
    }
  }
  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:DomCompletionContributor.java


示例6: getElementDescriptor

import com.intellij.xml.util.XmlUtil; //导入依赖的package包/类
@Override
public XmlElementDescriptor getElementDescriptor(@NotNull XmlTag tag) {
  XmlElementDescriptor elementDescriptor = super.getElementDescriptor(tag);

  if (LOG.isDebugEnabled()) {
    LOG.debug("Descriptor from rng for tag " +
              tag.getName() +
              " is " +
              (elementDescriptor != null ? elementDescriptor.getClass().getCanonicalName() : "NULL"));
  }

  String namespace;
  if (elementDescriptor == null &&
      !((namespace = tag.getNamespace()).equals(XmlUtil.XHTML_URI))) {
    return new AnyXmlElementDescriptor(
      null,
      XmlUtil.HTML_URI.equals(namespace) ? this : tag.getNSDescriptor(tag.getNamespace(), true)
    );
  }

  return elementDescriptor;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:RelaxedHtmlFromRngNSDescriptor.java


示例7: get

import com.intellij.xml.util.XmlUtil; //导入依赖的package包/类
@Override
public Object[] get(final PsiElement context, CompletionContext completionContext) {
  final List<String> results = new LinkedList<String>();

  final PsiElementProcessor processor = new PsiElementProcessor() {
    @Override
    public boolean execute(@NotNull final PsiElement element) {
      if (element instanceof XmlEntityDecl) {
        final XmlEntityDecl xmlEntityDecl = (XmlEntityDecl)element;
        if (xmlEntityDecl.isInternalReference()) {
          results.add(xmlEntityDecl.getName());
        }
      }
      return true;
    }
  };

  XmlUtil.processXmlElements((XmlFile)context.getContainingFile().getOriginalFile(), processor, true);
  return ArrayUtil.toObjectArray(results);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:DtdCompletionData.java


示例8: getCommentBeforeEatComment

import com.intellij.xml.util.XmlUtil; //导入依赖的package包/类
@Nullable
private static String getCommentBeforeEatComment(XmlTag tag) {
  PsiElement comment = XmlDocumentationProvider.findPreviousComment(tag);
  for (int i = 0; i < 5; ++i) {
    if (comment == null) {
      break;
    }
    String value = StringUtil.trim(XmlUtil.getCommentText((XmlComment)comment));

    //  This check is there to ignore "formatting" comments like the first and third lines in
    //  <!-- ============== -->
    //  <!-- Generic styles -->
    //  <!-- ============== -->
    if (!StringUtil.isEmpty(value) && value.charAt(0) != '*' && value.charAt(0) != '=') {
      return value;
    }
    comment = XmlDocumentationProvider.findPreviousComment(comment.getPrevSibling());
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:AttributeDefinitionsImpl.java


示例9: getType

import com.intellij.xml.util.XmlUtil; //导入依赖的package包/类
@Nullable
public TypeDescriptor getType(XmlElement context) {
  final XmlNSDescriptor nsDescriptor = getNSDescriptor(context);
  if (!(nsDescriptor instanceof XmlNSTypeDescriptorProvider)) return null;

  TypeDescriptor type = ((XmlNSTypeDescriptorProvider) nsDescriptor).getTypeDescriptor(myDescriptorTag);
  if (type == null) {
    String substAttr = myDescriptorTag.getAttributeValue("substitutionGroup");
    if (substAttr != null) {
      final String namespacePrefix = XmlUtil.findPrefixByQualifiedName(substAttr);
      final String namespace = namespacePrefix.isEmpty() ?
                               getDefaultNamespace() :
                               myDescriptorTag.getNamespaceByPrefix(namespacePrefix);
      final String local = XmlUtil.findLocalNameByQualifiedName(substAttr);
      final XmlElementDescriptorImpl originalElement = (XmlElementDescriptorImpl)((XmlNSDescriptorImpl)getNSDescriptor()).getElementDescriptor(local, namespace);
      if (originalElement != null && originalElement != this) {
        type = originalElement.getType(context);
      }
    }
  }
  return type;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:XmlElementDescriptorImpl.java


示例10: getElementDescriptor

import com.intellij.xml.util.XmlUtil; //导入依赖的package包/类
@Override
public XmlElementDescriptor getElementDescriptor(XmlTag element, XmlTag contextTag){
  final XmlElement context = (XmlElement)element.getParent();

  XmlElementDescriptor elementDescriptor = getElementDescriptor(
    element.getLocalName(),
    element.getNamespace(), context,
    element.getName()
  );

  if(elementDescriptor == null || element.getAttributeValue("xsi:type") != null){
    final XmlElementDescriptor xmlDescriptorByType = XmlUtil.findXmlDescriptorByType(element);

    if (xmlDescriptorByType != null) elementDescriptor = xmlDescriptorByType;
    else if (context instanceof XmlTag && ((XmlTag)context).getAttributeValue("xsi:type") != null && askParentDescriptorViaXsi()) {
      final XmlElementDescriptor parentXmlDescriptorByType = XmlUtil.findXmlDescriptorByType(((XmlTag)context));
      if (parentXmlDescriptorByType != null) {
        elementDescriptor = parentXmlDescriptorByType.getElementDescriptor(element, contextTag);
      }
    }
  }
  return elementDescriptor;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:XmlElementDescriptorImpl.java


示例11: findSpecialTag

import com.intellij.xml.util.XmlUtil; //导入依赖的package包/类
private static @Nullable XmlTag findSpecialTag(@NonNls String name, @NonNls String specialName, XmlTag rootTag, XmlNSDescriptorImpl descriptor,
                                     HashSet<XmlTag> visited) {
  XmlNSDescriptorImpl nsDescriptor = getNSDescriptorToSearchIn(rootTag, name, descriptor);

  if (nsDescriptor != descriptor) {
    final XmlDocument document = nsDescriptor.getDescriptorFile() != null ? nsDescriptor.getDescriptorFile().getDocument():null;
    if (document == null) return null;

    return findSpecialTag(
      XmlUtil.findLocalNameByQualifiedName(name),
      specialName,
      document.getRootTag(),
      nsDescriptor,
      visited
    );
  }

  if (visited == null) visited = new HashSet<XmlTag>(1);
  else if (visited.contains(rootTag)) return null;
  visited.add(rootTag);

  XmlTag[] tags = rootTag.getSubTags();

  return findSpecialTagIn(tags, specialName, name, rootTag, descriptor, visited);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:XmlNSDescriptorImpl.java


示例12: getRedefinedElementDescriptorFile

import com.intellij.xml.util.XmlUtil; //导入依赖的package包/类
public static XmlFile getRedefinedElementDescriptorFile(final XmlTag parentTag) {
  final String schemaL = parentTag.getAttributeValue(XmlUtil.SCHEMA_LOCATION_ATT);

  if (schemaL != null) {
    final PsiReference[] references = parentTag.getAttribute(XmlUtil.SCHEMA_LOCATION_ATT, null).getValueElement().getReferences();

    if (references.length > 0) {
      final PsiElement psiElement = references[references.length - 1].resolve();

      if (psiElement instanceof XmlFile) {
        return ((XmlFile)psiElement);
      }
    }
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:XmlNSDescriptorImpl.java


示例13: isLanguageRelevant

import com.intellij.xml.util.XmlUtil; //导入依赖的package包/类
private static boolean isLanguageRelevant(final PsiElement element,
                                          final PsiFile file,
                                          final Ref<Boolean> isRelevantLanguage,
                                          final Ref<Boolean> isAnt) {
  Boolean isAntFile = isAnt.get();
  if (isAntFile == null) {
    isAntFile = XmlUtil.isAntFile(file);
    isAnt.set(isAntFile);
  }
  Boolean result = isRelevantLanguage.get();
  if (result == null) {
    Language language = element.getLanguage();
    PsiElement parent = element.getParent();
    if (element instanceof PsiWhiteSpace && parent != null) {
      language = parent.getLanguage();
    }
    result = language instanceof XMLLanguage || HtmlUtil.supportsXmlTypedHandlers(file) || isAntFile.booleanValue();
    isRelevantLanguage.set(result);
  }
  return result.booleanValue();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:XmlAutoPopupHandler.java


示例14: createAndPutTypesCachedValue

import com.intellij.xml.util.XmlUtil; //导入依赖的package包/类
private CachedValue<TypeDescriptor> createAndPutTypesCachedValue(final XmlTag tag, final Pair<QNameKey, XmlTag> pair) {
  final CachedValue<TypeDescriptor> value = CachedValuesManager.getManager(tag.getProject()).createCachedValue(
    new CachedValueProvider<TypeDescriptor>() {
      @Override
      public CachedValueProvider.Result<TypeDescriptor> compute() {
        final String name = tag.getAttributeValue("name");

        if (name != null &&
            pair.first != null &&
            pair.first.first != null &&
            !name.equals(XmlUtil.findLocalNameByQualifiedName(pair.first.first))
          ) {
          myTypesMap.remove(pair);
          return new Result<TypeDescriptor>(null, PsiModificationTracker.MODIFICATION_COUNT);
        }
        final ComplexTypeDescriptor complexTypeDescriptor = new ComplexTypeDescriptor(XmlNSDescriptorImpl.this, tag);
        return new Result<TypeDescriptor>(complexTypeDescriptor, tag);
      }
    }, false);
  myTypesMap.put(pair, value);
  return value;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:XmlNSDescriptorImpl.java


示例15: processEnumeration

import com.intellij.xml.util.XmlUtil; //导入依赖的package包/类
private boolean processEnumeration(XmlElement context, PairProcessor<PsiElement, String> processor, boolean forCompletion) {
  XmlTag contextTag = context != null ? PsiTreeUtil.getContextOfType(context, XmlTag.class, false) : null;
  final XmlElementDescriptorImpl elementDescriptor = (XmlElementDescriptorImpl)XmlUtil.findXmlDescriptorByType(getDeclaration(), contextTag);

  if (elementDescriptor!=null && elementDescriptor.getType() instanceof ComplexTypeDescriptor) {
    return processEnumerationImpl(((ComplexTypeDescriptor)elementDescriptor.getType()).getDeclaration(), processor, forCompletion);
  }

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

  if (type != null) {
    return processEnumerationImpl(type, processor, forCompletion);
  }

  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:XsdEnumerationDescriptor.java


示例16: getNamespace

import com.intellij.xml.util.XmlUtil; //导入依赖的package包/类
private static String getNamespace(final XmlTag tag, final String text) {
  final String namespacePrefix = XmlUtil.findPrefixByQualifiedName(text);
  final String namespaceByPrefix = tag.getNamespaceByPrefix(namespacePrefix);
  if (!namespaceByPrefix.isEmpty()) return namespaceByPrefix;
  final XmlTag rootTag = ((XmlFile)tag.getContainingFile()).getRootTag();

  if (rootTag != null &&
      "schema".equals(rootTag.getLocalName()) &&
      XmlUtil.ourSchemaUrisList.indexOf(rootTag.getNamespace()) != -1 ) {
    final String targetNS = rootTag.getAttributeValue(TARGET_NAMESPACE);

    if (targetNS != null) {
      final String targetNsPrefix = rootTag.getPrefixByNamespace(targetNS);

      if (namespacePrefix.equals(targetNsPrefix) ||
          (namespaceByPrefix.isEmpty() && targetNsPrefix == null)) {
        return targetNS;
      }
    }
  }
  return namespaceByPrefix;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:TypeOrElementOrAttributeReference.java


示例17: findRedefinedDescriptor

import com.intellij.xml.util.XmlUtil; //导入依赖的package包/类
@Nullable
public static XmlNSDescriptorImpl findRedefinedDescriptor(XmlTag tag, String text) {
  final String localName = XmlUtil.findLocalNameByQualifiedName(text);
  for(XmlTag parentTag = tag.getParentTag(); parentTag != null; parentTag = parentTag.getParentTag()) {

    if (localName.equals(parentTag.getAttributeValue("name"))) {
      final XmlTag grandParent = parentTag.getParentTag();

      if (grandParent != null && "redefine".equals(grandParent.getLocalName())) {
        return XmlNSDescriptorImpl.getRedefinedElementDescriptor(grandParent);
      }
    }
  }

  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:SchemaReferencesProvider.java


示例18: resolveURI

import com.intellij.xml.util.XmlUtil; //导入依赖的package包/类
public static String resolveURI(PsiFile descriptorFile, String s) {
    final PsiFile file = XmlUtil.findXmlFile(descriptorFile, s);

    if (file != null) {
      final VirtualFile virtualFile = file.getVirtualFile();
      if (virtualFile != null) {
        final PsiDocumentManager dm = PsiDocumentManager.getInstance(file.getProject());
        final Document d = dm.getCachedDocument(file);
        if (d != null) {
          // TODO: fix. write action + saving -> deadlock
//          dm.commitDocument(d);
//          FileDocumentManager.getInstance().saveDocument(d);
        }
        s = reallyFixIDEAUrl(virtualFile.getUrl());
      }
    }
    return s;
  }
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:RngParser.java


示例19: getValueElement

import com.intellij.xml.util.XmlUtil; //导入依赖的package包/类
@Nullable
private PsiElement getValueElement(PsiFile baseFile) {
  final XmlAttributeValue attributeValue = getValueElement();
  if (isInternalReference()) return attributeValue;

  if (attributeValue != null) {
    final String value = attributeValue.getValue();
    if (value != null) {
      XmlFile xmlFile = XmlUtil.findNamespaceByLocation(baseFile, value);
      if (xmlFile != null) {
        return xmlFile;
      }

      final int i = XmlUtil.getPrefixLength(value);
      if (i > 0) {
        return XmlUtil.findNamespaceByLocation(baseFile, value.substring(i));
      }
    }
  }

  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:XmlEntityDeclImpl.java


示例20: isElementWithEmbeddedType

import com.intellij.xml.util.XmlUtil; //导入依赖的package包/类
public static boolean isElementWithEmbeddedType(XmlTagImpl xml, final String typeName, final String typeNsPrefix) {
  final String localName = xml.getLocalName();
  if (! (XmlUtil.XML_SCHEMA_URI.equals(xml.getNamespace()) && "element".equals(localName))) {
    return false;
  }
  final XmlAttribute nameAttr = getNameAttr(xml);
  if (nameAttr == null || nameAttr.getValue() == null) return false;
  final String localTypeName = XmlUtil.findLocalNameByQualifiedName(nameAttr.getValue());
  final String prefix = XmlUtil.findPrefixByQualifiedName(nameAttr.getValue());
  if (! typeName.equals(localTypeName) || ! typeNsPrefix.equals(prefix)) {
    return false;
  }
  final XmlTag[] tags = xml.getSubTags();
  for (XmlTag tag : tags) {
    if (isTypeElement((XmlTagImpl)tag)) {
      return true;
    }
  }
  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:SchemaDefinitionsSearch.java



注:本文中的com.intellij.xml.util.XmlUtil类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java BaseFullChunk类代码示例发布时间:2022-05-21
下一篇:
Java MappedConfiguration类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap