org.apache.axiom.om.OMElement.getAllDeclaredNamespaces()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(10.3k)|赞(0)|评价(0)|浏览(124)

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

OMElement.getAllDeclaredNamespaces介绍

[英]Returns an iterator for all of the namespaces declared on this element. Note that this is not the same as the set of namespace declarations in scope. Since building a namespace context and resolving namespace prefixes has some subtleties associated with it (such as masked namespace declarations and prefix undeclaring), it is generally recommended to use one of the following specialized methods for this purpose:

  • #getNamespacesInScope() or #getNamespaceContext(boolean) to calculate the namespace context for the element.
  • #findNamespace(String,String) and #findNamespaceURI(String) to resolve a namespace prefix or to find a namespace prefix for a given URI.
  • #resolveQName(String) to resolve a QName literal.
  • AXIOMXPath#AXIOMXPath(OMElement,String) or AXIOMXPath#AXIOMXPath(OMAttribute) to create an XPath expression using the namespace context of a given element.

It is expected that applications only rarely use #getAllDeclaredNamespaces()directly.

The iterator returned by this method supports Iterator#remove() and that method can be used to remove a namespace declaration from this element.
[中]返回此元素上声明的所有名称空间的迭代器。请注意,这与作用域中的一组名称空间声明不同。由于构建名称空间上下文和解析名称空间前缀有一些微妙之处(例如屏蔽名称空间声明和前缀取消声明),因此通常建议为此使用以下专门方法之一:
*#GetNamespacesScope()或#getNamespaceContext(布尔值)来计算元素的命名空间上下文。
*#findNamespace(String,String)和#findNamespace URI(String)解析名称空间前缀或查找给定URI的名称空间前缀。
*#resolveQName(字符串)解析QName文字。
*AXIOMIXPATH#AXIOMIXPATH(OMElement,String)或AXIOMIXPATH#AXIOMIXPATH(OMAttribute)使用给定元素的命名空间上下文创建XPath表达式。
预计应用程序很少直接使用#getAllDeclaredNamespaces()。
此方法返回的迭代器支持迭代器#remove(),该方法可用于从此元素中删除命名空间声明。

代码示例

代码示例来源:origin: wso2/wso2-synapse

public void setNamespaces(OMElement elem){
  Iterator namespaces = elem.getAllDeclaredNamespaces();
  while (namespaces.hasNext()){
    OMNamespace ns = (OMNamespace) namespaces.next();
    namespaceList.add(ns);
  }
}

代码示例来源:origin: stackoverflow.com

OMDocument document = ...
for (Iterator it = document.getDescendants(false); it.hasNext(); ) {
  OMNode node = (OMNode)it.next();
  if (node instanceof OMElement) {
    OMElement element = (OMElement)node;
    element.setNamespace(null, false);  // <-- this actually changes the namespace of the element
    for (Iterator it2 = element.getAllDeclaredNamespaces(); it2.hasNext(); ) {
      it2.next();
      it2.remove();
    }
  }
}

代码示例来源:origin: org.apache.axis2/axis2-saaj

public boolean removeNamespaceDeclaration(String prefix) {
  for (Iterator<OMNamespace> it = omTarget.getAllDeclaredNamespaces(); it.hasNext(); ) {
    if (it.next().getPrefix().equals(prefix)) {
      it.remove();
      return true;
    }
  }
  return false;
}

代码示例来源:origin: org.wso2.carbon/org.wso2.carbon.bam.core

protected static java.util.Map getOMElementNamespaces(OMElement element) {
  java.util.Map returnMap = new java.util.HashMap();
  java.util.Iterator namespaceIterator = element.getAllDeclaredNamespaces();
  while (namespaceIterator.hasNext()) {
    org.apache.axiom.om.OMNamespace ns = (org.apache.axiom.om.OMNamespace) namespaceIterator.next();
    returnMap.put(ns.getPrefix(), ns.getNamespaceURI());
  }
  return returnMap;
}

代码示例来源:origin: org.apache.ws.commons.axiom/axiom-truth

@Override
public Map<String, String> getNamespaces() {
  Map<String,String> namespaces = null;
  for (Iterator it = ((OMElement)node).getAllDeclaredNamespaces(); it.hasNext(); ) {
    OMNamespace ns = (OMNamespace)it.next();
    if (namespaces == null) {
      namespaces = new HashMap<String,String>();
    }
    namespaces.put(ns.getPrefix(), ns.getNamespaceURI());
  }
  return namespaces;
}

代码示例来源:origin: org.apache.axis2/axis2-saaj

public Iterator getNamespacePrefixes() {
  //Get all declared namespace, make a list of their prefixes and return an iterator over that list
  ArrayList prefixList = new ArrayList();
  Iterator nsIter = omTarget.getAllDeclaredNamespaces();
  while (nsIter.hasNext()) {
    Object o = nsIter.next();
    if (o instanceof org.apache.axiom.om.OMNamespace) {
      org.apache.axiom.om.OMNamespace ns = (org.apache.axiom.om.OMNamespace)o;
      prefixList.add(ns.getPrefix());
    }
  }
  return prefixList.iterator();
}

代码示例来源:origin: apache/axis2-java

public boolean removeNamespaceDeclaration(String prefix) {
  for (Iterator<OMNamespace> it = omTarget.getAllDeclaredNamespaces(); it.hasNext(); ) {
    if (it.next().getPrefix().equals(prefix)) {
      it.remove();
      return true;
    }
  }
  return false;
}

代码示例来源:origin: apache/axis2-java

public Iterator getNamespacePrefixes() {
  //Get all declared namespace, make a list of their prefixes and return an iterator over that list
  ArrayList prefixList = new ArrayList();
  Iterator nsIter = omTarget.getAllDeclaredNamespaces();
  while (nsIter.hasNext()) {
    Object o = nsIter.next();
    if (o instanceof org.apache.axiom.om.OMNamespace) {
      org.apache.axiom.om.OMNamespace ns = (org.apache.axiom.om.OMNamespace)o;
      prefixList.add(ns.getPrefix());
    }
  }
  return prefixList.iterator();
}

代码示例来源:origin: org.apache.rampart/rampart-core

private static void findPrefixNamespaces(OMElement e, Set<OMNamespace> results) {
  Iterator iterator = e.getAllDeclaredNamespaces();
  if (iterator != null) {
    while (iterator.hasNext())
      results.add((OMNamespace)iterator.next());
  }
  Iterator children = e.getChildElements();
  while (children.hasNext()) {
    findPrefixNamespaces((OMElement) children.next(), results);
  }
}

代码示例来源:origin: org.apache.ws.commons.axiom/axiom-api

/**
 * serializeNamespaces
 *
 * @param element
 * @param writer
 * @throws XMLStreamException
 * @deprecated Use serializeStartpart instead
 */
public static void serializeNamespaces
    (OMElement
        element,
     XMLStreamWriter writer) throws XMLStreamException {
  Iterator namespaces = element.getAllDeclaredNamespaces();
  if (namespaces != null) {
    while (namespaces.hasNext()) {
      serializeNamespace((OMNamespace) namespaces.next(), writer);
    }
  }
}

代码示例来源:origin: org.apache.abdera/abdera-parser

public Map<String, String> getNamespaces() {
  Map<String, String> namespaces = new HashMap<String, String>();
  OMElement current = this;
  while (current != null) {
    Iterator i = current.getAllDeclaredNamespaces();
    while (i.hasNext()) {
      OMNamespace ns = (OMNamespace)i.next();
      String prefix = ns.getPrefix();
      String uri = ns.getNamespaceURI();
      if (!namespaces.containsKey(prefix))
        namespaces.put(prefix, uri);
    }
    OMContainer parent = current.getParent();
    current = (OMElement)((parent != null && parent instanceof OMElement) ? parent : null);
  }
  return Collections.unmodifiableMap(namespaces);
}

代码示例来源:origin: org.apache.ws.commons.axiom/axiom-truth

public void hasNoNamespaceDeclarations() {
  if (getSubject().getAllDeclaredNamespaces().hasNext()) {
    fail("has no namespace declarations");
  }
}

代码示例来源:origin: org.apache.ws.commons.axiom/axiom-truth

public void hasNamespaceDeclaration(OMNamespace ns) {
    for (Iterator it = getSubject().getAllDeclaredNamespaces(); it.hasNext(); ) {
      if (it.next().equals(ns)) {
        return;
      }
    }
    fail("has namespace declaration for namespace URI \"" + ns.getNamespaceURI()
        + "\" and prefix \"" + ns.getPrefix() + "\"");
  }
}

代码示例来源:origin: org.wso2.carbon.governance/org.wso2.carbon.governance.registry.extensions

public static List evaluateXpath(OMElement contentElement, String xpathString) {
  List ret = new ArrayList();
  try {
    AXIOMXPath xpath = new AXIOMXPath(xpathString);
    Iterator nsIterator = contentElement.getAllDeclaredNamespaces();
    while (nsIterator.hasNext()) {
      OMNamespace next = (OMNamespace) nsIterator.next();
      xpath.addNamespace("x", next.getNamespaceURI());
      ret.addAll(xpath.selectNodes(contentElement));
    }
    return ret;
  } catch (Exception e) {
    log.error(e);
  }
  return null;
}

代码示例来源:origin: org.ow2.petals/petals-bc-soap

/**
 * Copy the tag data (attributes and namespaces) from the source element to
 * the target element.
 * 
 * @param sourceElement
 * @param targetElement
 */
public static void copyTagData(OMElement sourceElement,
    OMElement targetElement) {
  for (Iterator<?> i = sourceElement.getAllDeclaredNamespaces(); i
      .hasNext();) {
    OMNamespace ns = (OMNamespace) i.next();
    targetElement.declareNamespace(ns);
  }
  for (Iterator<?> i = sourceElement.getAllAttributes(); i.hasNext();) {
    OMAttribute attr = (OMAttribute) i.next();
    targetElement.addAttribute(attr);
  }
}

代码示例来源:origin: org.bluestemsoftware.open.eoa.ext/open-eoa-aspect-axiom

/**
 * @param i
 * @return Returns String.
 * @see javax.xml.stream.XMLStreamReader#getNamespaceURI
 */
public String getNamespaceURI(int i) {
  String returnString = null;
  if (parser != null) {
    returnString = parser.getNamespaceURI(i);
  } else {
    if (isStartElement() || isEndElement()
        || (currentEvent == NAMESPACE)) {
      OMNamespace ns = (OMNamespace) getItemFromIterator(
          ((OMElement) lastNode).getAllDeclaredNamespaces(), i);
      returnString = (ns == null) ? null : ns.getNamespaceURI();
    }
  }
  return returnString;
}

代码示例来源:origin: org.wso2.bpel/ode-bpel-epr

@SuppressWarnings("unchecked")
private static void buildNScontext(NSContext nscontext, OMElement element) {
  if (element == null)
    return;
  if (element.getParent() instanceof OMElement)
    buildNScontext(nscontext, (OMElement) element.getParent());
  if (element.getAllDeclaredNamespaces() != null)
    for (Iterator<OMNamespace> i=element.getAllDeclaredNamespaces(); i.hasNext(); ){
      OMNamespace omn = i.next();
      nscontext.register(omn.getPrefix(), omn.getNamespaceURI());
    }
  if (element.getDefaultNamespace() != null)
    nscontext.register("", element.getDefaultNamespace().getNamespaceURI());
}

代码示例来源:origin: org.bluestemsoftware.open.eoa.ext/open-eoa-aspect-axiom

/**
 * @return Returns int.
 * @see javax.xml.stream.XMLStreamReader#getNamespaceCount()
 */
public int getNamespaceCount() {
  int returnCount = 0;
  if (parser != null) {
    returnCount = parser.getNamespaceCount();
  } else {
    if (isStartElement() || isEndElement()
        || (currentEvent == NAMESPACE)) {
      returnCount = getCount(((OMElement) lastNode)
          .getAllDeclaredNamespaces());
    }
  }
  return returnCount;
}

代码示例来源:origin: deegree/deegree3

@SuppressWarnings("unchecked")
private void augmentNamespaceContext( OMElement element, NamespaceBindings nsContext ) {
  Iterator<OMNamespace> iterator = element.getAllDeclaredNamespaces();
  while ( iterator.hasNext() ) {
    OMNamespace namespace = iterator.next();
    if ( nsContext.translateNamespacePrefixToUri( namespace.getPrefix() ) == null ) {
      nsContext.addNamespace( namespace.getPrefix(), namespace.getNamespaceURI() );
    }
  }
  OMContainer parent = element.getParent();
  if ( parent != null && parent instanceof OMElement ) {
    augmentNamespaceContext( (OMElement) parent, nsContext );
  }
}

代码示例来源:origin: org.bluestemsoftware.open.eoa.ext/open-eoa-aspect-axiom

/**
 * @param i
 * @return Returns String.
 * @see javax.xml.stream.XMLStreamReader#getNamespacePrefix
 */
public String getNamespacePrefix(int i) {
  String returnString = null;
  if (parser != null) {
    returnString = parser.getNamespacePrefix(i);
  } else {
    if (isStartElement() || isEndElement()
        || (currentEvent == NAMESPACE)) {
      OMNamespace ns = (OMNamespace) getItemFromIterator(
          ((OMElement) lastNode).getAllDeclaredNamespaces(), i);
      returnString = (ns == null) ? null : ns.getPrefix();
    }
  }
  return returnString;
}

相关文章

微信公众号

最新文章

更多