org.jdom2.Element.getAdditionalNamespaces()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(11.4k)|赞(0)|评价(0)|浏览(99)

本文整理了Java中org.jdom2.Element.getAdditionalNamespaces()方法的一些代码示例,展示了Element.getAdditionalNamespaces()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Element.getAdditionalNamespaces()方法的具体详情如下:
包路径:org.jdom2.Element
类名称:Element
方法名:getAdditionalNamespaces

Element.getAdditionalNamespaces介绍

[英]Returns a list of the additional namespace declarations on this element. This includes only additional namespace, not the namespace of the element itself, which can be obtained through #getNamespace(). If there are no additional declarations, this returns an empty list. Note, the returned list is unmodifiable.
[中]返回此元素上附加命名空间声明的列表。这只包括额外的名称空间,而不是元素本身的名称空间,可以通过#getNamespace()获得。如果没有其他声明,则返回空列表。注意,返回的列表是不可修改的。

代码示例

代码示例来源:origin: org.jdom/jdom

namespaces.put(getNamespacePrefix(), getNamespace());
if (additionalNamespaces != null) {
  for (Namespace ns : getAdditionalNamespaces()) {
    if (!namespaces.containsKey(ns.getPrefix())) {
      namespaces.put(ns.getPrefix(), ns);

代码示例来源:origin: org.jdom/jdom

getAdditionalNamespaces());
if (reason != null) {
  throw new IllegalAddException(this, namespace, reason);

代码示例来源:origin: org.codehaus.plexus/plexus-component-metadata

/**
 * @return list of Namespaces.
 */
public List getAdditionalNamespaces()
{
  return element.getAdditionalNamespaces();
}

代码示例来源:origin: org.jdom/jdom

element.getAdditionalNamespaces());
if (reason != null) {
  return reason;

代码示例来源:origin: org.jdom/jdom

for (final Namespace ns : element.getAdditionalNamespaces()) {
  if (ns == mns) {
    continue;

代码示例来源:origin: org.mule.modules/mule-module-rss

@Override
public WireFeed parse(final Document document, final boolean validate, final Locale locale) throws IllegalArgumentException, FeedException
{
  final Element rssRoot = document.getRootElement();
  namespaces = new ArrayList<>(rssRoot.getAdditionalNamespaces());
  namespaces.add(NO_NAMESPACE);
  return parseChannel(rssRoot, locale);
}

代码示例来源:origin: org.mycore/oaipmh-dataprovider

private Map<String, Namespace> getNamespaceMap(Element element) {
  Map<String, Namespace> map = new HashMap<>();
  map.put(element.getNamespace().getPrefix(), element.getNamespace());
  element.getAdditionalNamespaces().forEach(ns -> map.put(ns.getPrefix(), ns));
  return map;
}

代码示例来源:origin: org.apache.marmotta/sesame-tools-rio-rss

/**
 * Purging unused declarations is less optimal, performance-wise, than never adding them in the first place.  So, we
 * should still ask the ROME guys to fix their code (not adding dozens of unnecessary module declarations). Having
 * said that: purging them here, before XML generation, is more efficient than parsing and re-molding the XML after
 * ROME generates it.
 * <p/>
 * Note that the calling app could still add declarations/modules to the Feed tree after this.  Which is fine.  But
 * those modules are then responsible for crawling to the root of the tree, at generate() time, to make sure their
 * namespace declarations are present.
 */
protected static void purgeUnusedNamespaceDeclarations(Element root) {
  java.util.Set usedPrefixes = new java.util.HashSet();
  collectUsedPrefixes(root, usedPrefixes);
  List list = root.getAdditionalNamespaces();
  List additionalNamespaces = new java.util.ArrayList();
  additionalNamespaces.addAll(list); // the duplication will prevent a ConcurrentModificationException below
  for (int i = 0; i < additionalNamespaces.size(); i++) {
    Namespace ns = (Namespace) additionalNamespaces.get(i);
    String prefix = ns.getPrefix();
    if (prefix != null && prefix.length() > 0 && !usedPrefixes.contains(prefix)) {
      root.removeNamespaceDeclaration(ns);
    }
  }
}

代码示例来源:origin: rometools/rome

/**
 * Purging unused declarations is less optimal, performance-wise, than never adding them in the
 * first place. So, we should still ask the ROME guys to fix their code (not adding dozens of
 * unnecessary module declarations). Having said that: purging them here, before XML generation,
 * is more efficient than parsing and re-molding the XML after ROME generates it.
 * <p/>
 * Note that the calling app could still add declarations/modules to the Feed tree after this.
 * Which is fine. But those modules are then responsible for crawling to the root of the tree,
 * at generate() time, to make sure their namespace declarations are present.
 */
protected static void purgeUnusedNamespaceDeclarations(final Element root) {
  final Set<String> usedPrefixes = new HashSet<String>();
  collectUsedPrefixes(root, usedPrefixes);
  final List<Namespace> list = root.getAdditionalNamespaces();
  final List<Namespace> additionalNamespaces = new ArrayList<Namespace>();
  additionalNamespaces.addAll(list); // the duplication will prevent a
  // ConcurrentModificationException
  // below
  for (final Namespace ns : additionalNamespaces) {
    final String prefix = ns.getPrefix();
    if (prefix != null && prefix.length() > 0 && !usedPrefixes.contains(prefix)) {
      root.removeNamespaceDeclaration(ns);
    }
  }
}

代码示例来源:origin: apache/marmotta

/**
 * Purging unused declarations is less optimal, performance-wise, than never adding them in the first place.  So, we
 * should still ask the ROME guys to fix their code (not adding dozens of unnecessary module declarations). Having
 * said that: purging them here, before XML generation, is more efficient than parsing and re-molding the XML after
 * ROME generates it.
 * <p/>
 * Note that the calling app could still add declarations/modules to the Feed tree after this.  Which is fine.  But
 * those modules are then responsible for crawling to the root of the tree, at generate() time, to make sure their
 * namespace declarations are present.
 */
protected static void purgeUnusedNamespaceDeclarations(Element root) {
  java.util.Set usedPrefixes = new java.util.HashSet();
  collectUsedPrefixes(root, usedPrefixes);
  List list = root.getAdditionalNamespaces();
  List additionalNamespaces = new java.util.ArrayList();
  additionalNamespaces.addAll(list); // the duplication will prevent a ConcurrentModificationException below
  for (Object additionalNamespace : additionalNamespaces) {
    Namespace ns = (Namespace) additionalNamespace;
    String prefix = ns.getPrefix();
    if (prefix != null && prefix.length() > 0 && !usedPrefixes.contains(prefix)) {
      root.removeNamespaceDeclaration(ns);
    }
  }
}

代码示例来源:origin: org.opencadc/cadc-vosi

private void transformCapabilities(Document doc, HttpServletRequest request)
    throws IOException, JDOMException {
  URL rurl = new URL(request.getRequestURL().toString());
  String hostname = rurl.getHost();
  Element root = doc.getRootElement();
  List<Namespace> nsList = new ArrayList<Namespace>();
  nsList.addAll(root.getAdditionalNamespaces());
  nsList.add(root.getNamespace());
  String xpath = "/vosi:capabilities/capability/interface/accessURL";
  XPathFactory xf = XPathFactory.instance();
  XPathExpression<Element> xp = xf.compile(xpath, Filters.element(),
      null, nsList);
  List<Element> accessURLs = xp.evaluate(doc);
  log.debug("xpath[" + xpath + "] found: " + accessURLs.size());
  for (Element e : accessURLs) {
    String surl = e.getTextTrim();
    log.debug("accessURL: " + surl);
    URL url = new URL(surl);
    URL nurl = new URL(url.getProtocol(), hostname, url.getPath());
    log.debug("accessURL: " + surl + " -> " + nurl);
    e.setText(nurl.toExternalForm());
  }
}

代码示例来源:origin: com.theoryinpractise/halbuilder-xml

private void readNamespaces(Representation resource, Element element) {
  List<Namespace> namespaces = element.getAdditionalNamespaces();
  for (Namespace ns : namespaces) {
    if (!"xsi".equals(ns.getPrefix())) {
      resource.withNamespace(ns.getPrefix(), ns.getURI());
    }
  }
}

代码示例来源:origin: org.apache.marmotta/sesame-tools-rio-rss

public boolean isMyType(Document document) {
  boolean ok = false;
  Element rssRoot = document.getRootElement();
  Namespace defaultNS = rssRoot.getNamespace();
  List additionalNSs = rssRoot.getAdditionalNamespaces();
  ok = defaultNS!=null && defaultNS.equals(getRDFNamespace());
  if (ok) {
    if (additionalNSs==null) {
      ok = false;
    }
    else {
      ok = false;
      for (int i=0;!ok && i<additionalNSs.size();i++) {
        ok = getRSSNamespace().equals(additionalNSs.get(i));
      }
    }
  }
  return ok;
}

代码示例来源:origin: apache/marmotta

public boolean isMyType(Document document) {
  boolean ok = false;
  Element rssRoot = document.getRootElement();
  Namespace defaultNS = rssRoot.getNamespace();
  List additionalNSs = rssRoot.getAdditionalNamespaces();
  ok = defaultNS!=null && defaultNS.equals(getRDFNamespace());
  if (ok) {
    if (additionalNSs==null) {
      ok = false;
    }
    else {
      ok = false;
      for (int i=0;!ok && i<additionalNSs.size();i++) {
        ok = getRSSNamespace().equals(additionalNSs.get(i));
      }
    }
  }
  return ok;
}

代码示例来源:origin: org.apache.marmotta/sesame-tools-rio-rss

/**
 * Indicates if a JDom document is an RSS instance that can be parsed with the parser.
 * <p/>
 * It checks for RDF ("http://www.w3.org/1999/02/22-rdf-syntax-ns#") and
 * RSS ("http://purl.org/rss/1.0/") namespaces being defined in the root element.
 *
 * @param document document to check if it can be parsed with this parser implementation.
 * @return <b>true</b> if the document is RSS1., <b>false</b> otherwise.
 */
public boolean isMyType(Document document) {
  boolean ok = false;
  Element rssRoot = document.getRootElement();
  Namespace defaultNS = rssRoot.getNamespace();
  List additionalNSs = rssRoot.getAdditionalNamespaces();
  ok = (defaultNS != null) && defaultNS.equals(getRSSNamespace());
  return ok;
}

代码示例来源:origin: apache/marmotta

/**
 * Indicates if a JDom document is an RSS instance that can be parsed with the parser.
 * <p/>
 * It checks for RDF ("http://www.w3.org/1999/02/22-rdf-syntax-ns#") and
 * RSS ("http://purl.org/rss/1.0/") namespaces being defined in the root element.
 *
 * @param document document to check if it can be parsed with this parser implementation.
 * @return <b>true</b> if the document is RSS1., <b>false</b> otherwise.
 */
public boolean isMyType(Document document) {
  boolean ok = false;
  Element rssRoot = document.getRootElement();
  Namespace defaultNS = rssRoot.getNamespace();
  List additionalNSs = rssRoot.getAdditionalNamespaces();
  ok = (defaultNS != null) && defaultNS.equals(getRSSNamespace());
  return ok;
}

代码示例来源:origin: org.mycore/mycore-xeditor

private void addNamespacesFrom(Element element) {
  MCRConstants.registerNamespace(element.getNamespace());
  for (Namespace ns : element.getAdditionalNamespaces()) {
    MCRConstants.registerNamespace(ns);
  }
  for (Element child : element.getChildren()) {
    addNamespacesFrom(child);
  }
}

代码示例来源:origin: apache/marmotta

/**
 * Indicates if a JDom document is an RSS instance that can be parsed with the parser.
 * <p/>
 * It checks for RDF ("http://www.w3.org/1999/02/22-rdf-syntax-ns#") and
 * RSS ("http://purl.org/rss/1.0/") namespaces being defined in the root element.
 *
 * @param document document to check if it can be parsed with this parser implementation.
 * @return <b>true</b> if the document is RSS1., <b>false</b> otherwise.
 */
public boolean isMyType(Document document) {
  boolean ok = false;
  Element rssRoot = document.getRootElement();
  Namespace defaultNS = rssRoot.getNamespace();
  List additionalNSs = rssRoot.getAdditionalNamespaces();
  ok = defaultNS!=null && defaultNS.equals(getRDFNamespace());
  if (ok) {
    if (additionalNSs==null) {
      ok = false;
    }
    else {
      ok = false;
      for (int i=0;!ok && i<additionalNSs.size();i++) {
        ok = getRSSNamespace().equals(additionalNSs.get(i));
      }
    }
  }
  return ok;
}

代码示例来源:origin: rometools/rome

@Override
public boolean isMyType(final Document document) {
  final Element rssRoot = document.getRootElement();
  final Namespace defaultNS = rssRoot.getNamespace();
  final List<Namespace> additionalNSs = rssRoot.getAdditionalNamespaces();
  boolean myType = false;
  if (defaultNS != null && defaultNS.equals(getRDFNamespace()) && additionalNSs != null) {
    for (final Namespace namespace : additionalNSs) {
      if (getRSSNamespace().equals(namespace)) {
        myType = true;
        break;
      }
    }
  }
  return myType;
}

代码示例来源:origin: com.rometools/rome

@Override
public boolean isMyType(final Document document) {
  final Element rssRoot = document.getRootElement();
  final Namespace defaultNS = rssRoot.getNamespace();
  final List<Namespace> additionalNSs = rssRoot.getAdditionalNamespaces();
  boolean myType = false;
  if (defaultNS != null && defaultNS.equals(getRDFNamespace()) && additionalNSs != null) {
    for (final Namespace namespace : additionalNSs) {
      if (getRSSNamespace().equals(namespace)) {
        myType = true;
        break;
      }
    }
  }
  return myType;
}

相关文章

微信公众号

最新文章

更多