org.dom4j.Namespace类的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(12.0k)|赞(0)|评价(0)|浏览(255)

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

Namespace介绍

[英]Namespace is a Flyweight Namespace that can be shared amongst nodes.
[中]Namespace是一个可以在节点之间共享的Flyweight命名空间。

代码示例

代码示例来源:origin: igniterealtime/Openfire

try {
  Element element = xmlReader.read(new StringReader(stanza)).getRootElement();
  for (Element child : (List<Element>)element.elements()) {
    Namespace ns = child.getNamespace();
    if (ns == null || ns.getURI().equals("jabber:client") || ns.getURI().equals("jabber:server")) {
      continue;
    Element added = message.addChildElement(child.getName(), child.getNamespaceURI());
    if (!child.getText().isEmpty()) {
      added.setText(child.getText());

代码示例来源:origin: igniterealtime/Openfire

public static Element getSASLMechanismsElement( ClientSession session )
{
  final Element result = DocumentHelper.createElement( new QName( "mechanisms", new Namespace( "", SASL_NAMESPACE ) ) );
  for (String mech : getSupportedMechanisms()) {
    if (mech.equals("EXTERNAL")) {
      boolean trustedCert = false;
      if (session.isSecure()) {
        final Connection connection   = ( (LocalClientSession) session ).getConnection();
        final TrustStore trustStore   = connection.getConfiguration().getTrustStore();
        trustedCert = trustStore.isTrusted( connection.getPeerCertificates() );
      }
      if ( !trustedCert ) {
        continue; // Do not offer EXTERNAL.
      }
    }
    final Element mechanism = result.addElement("mechanism");
    mechanism.setText(mech);
  }
  return result;
}

代码示例来源:origin: pentaho/pentaho-kettle

public void prepareNSMap( Element l ) {
 @SuppressWarnings( "unchecked" )
 List<Namespace> namespacesList = l.declaredNamespaces();
 for ( Namespace ns : namespacesList ) {
  if ( ns.getPrefix().trim().length() == 0 ) {
   data.NAMESPACE.put( "pre" + data.NSPath.size(), ns.getURI() );
   String path = "";
   Element element = l;
   while ( element != null ) {
    if ( element.getNamespacePrefix() != null && element.getNamespacePrefix().length() > 0 ) {
     path = GetXMLDataMeta.N0DE_SEPARATOR + element.getNamespacePrefix() + ":" + element.getName() + path;
    } else {
     path = GetXMLDataMeta.N0DE_SEPARATOR + element.getName() + path;
    }
    element = element.getParent();
   }
   data.NSPath.add( path );
  } else {
   data.NAMESPACE.put( ns.getPrefix(), ns.getURI() );
  }
 }
 @SuppressWarnings( "unchecked" )
 List<Element> elementsList = l.elements();
 for ( Element e : elementsList ) {
  prepareNSMap( e );
 }
}

代码示例来源:origin: igniterealtime/Openfire

protected void writeNamespace(Namespace namespace) throws IOException {
  if ( namespace != null ) {
    writeNamespace(namespace.getPrefix(), namespace.getURI());
  }
}

代码示例来源:origin: jaxen/jaxen

List nsList = new ArrayList();
HashSet prefixes = new HashSet();
for ( Element context = element; context != null; context = context.getParent() ) {
  List declaredNS = new ArrayList(context.declaredNamespaces());
  declaredNS.add(context.getNamespace());
  for ( Iterator iter = context.attributes().iterator(); iter.hasNext(); )
    if (namespace != Namespace.NO_NAMESPACE)
      String prefix = namespace.getPrefix();
      if ( ! prefixes.contains( prefix ) ) {
        prefixes.add( prefix );
        nsList.add( namespace.asXPathResult( element ) );
nsList.add( Namespace.XML_NAMESPACE.asXPathResult( element ) );
return nsList.iterator();

代码示例来源:origin: webx/citrus

if (isConfigurationPointNamespace(ns.getURI())) {
  nsToBeRemoved.add(ns);
  if (!configurationPointNamespaces.containsKey(ns.getURI())) {
    if (isEmpty(ns.getPrefix())) {
      String prefix = getNamespacePrefix(
          schemas.getConfigurationPoints().getConfigurationPointByNamespaceUri(ns.getURI()).getPreferredNsPrefix(), ns.getURI());
      ns = Namespace.get(prefix, ns.getURI());
      modified = true;
    configurationPointNamespaces.put(ns.getURI(), ns);
    allSchemaNamespaces.put(ns.getURI(), ns);
} else if (schemas.getNamespaceMappings().containsKey(ns.getURI())) {
  if (!allSchemaNamespaces.containsKey(ns.getURI())) {
    allSchemaNamespaces.put(ns.getURI(), ns);
   || isContributionElement(namespaceURI, element.getName())) {
  setNamespacePrefix(element, ns.getPrefix());
  visitSubElements(element);
} finally {
  if ("http://www.w3.org/2001/XMLSchema-instance".equals(ns.getURI())) {
    xsi = ns;
  } else if (!allSchemaNamespaces.containsKey(ns.getURI())) {
    otherNamespaces.put(ns.getURI(), ns);

代码示例来源:origin: webx/citrus

public org.dom4j.Element filter(org.dom4j.Element e) throws Exception {
    // 删除schemaLocation
    org.dom4j.Attribute attr = e.attribute(new QName("schemaLocation", new Namespace("xsi",
                                             "http://www.w3.org/2001/XMLSchema-instance")));
    if (attr != null) {
      e.remove(attr);
    }
    // 导入beans:import,并删除element
    if ("http://www.springframework.org/schema/beans".equals(e.getNamespaceURI())
      && "import".equals(e.getName())) {
      String importedResourceName = trimToNull(e.attributeValue("resource"));
      if (importedResourceName != null) {
        Resource importedResource;
        if (importedResourceName.contains(":")) {
          importedResource = loader.getResource(importedResourceName);
        } else {
          importedResource = namedResource.resource.createRelative(importedResourceName);
        }
        ConfigurationFile importedConfigurationFile = parseConfigurationFile(new NamedResource(
            importedResourceName, importedResource), parsedNames);
        if (importedConfigurationFile != null) {
          importedConfigurationFiles.add(importedConfigurationFile);
        }
      }
      return null;
    }
    return e;
  }
});

代码示例来源:origin: igniterealtime/Openfire

private void initiateSession(Element stanza) {
  
  String host = stanza.attributeValue("to");
  StreamError streamError = null;
  Locale language = Locale.forLanguageTag(stanza.attributeValue(QName.get("lang", XMLConstants.XML_NS_URI), "en"));
  if (STREAM_FOOTER.equals(stanza.getName())) {
    // an error occurred while setting up the session
    Log.warn("Client closed stream before session was established");
  } else if (!STREAM_HEADER.equals(stanza.getName())) {
    streamError = new StreamError(StreamError.Condition.unsupported_stanza_type);
    Log.warn("Closing session due to incorrect stream header. Tag: " + stanza.getName());
  } else if (!FRAMING_NAMESPACE.equals(stanza.getNamespace().getURI())) {
    // Validate the stream namespace (https://tools.ietf.org/html/rfc7395#section-3.3.2)
    streamError = new StreamError(StreamError.Condition.invalid_namespace);
    Log.warn("Closing session due to invalid namespace in stream header. Namespace: " + stanza.getNamespace().getURI());
  } else if (!validateHost(host)) {
    streamError = new StreamError(StreamError.Condition.host_unknown);
    Log.warn("Closing session due to incorrect hostname in stream header. Host: " + host);
  } else {
    // valid stream; initiate session
    xmppSession = SessionManager.getInstance().createClientSession(wsConnection, language);
    xmppSession.setSessionData("ws", Boolean.TRUE);
  }
  if (xmppSession == null) {
    closeStream(streamError);
  } else {
    openStream(language.toLanguageTag(), stanza.attributeValue("from"));
    configureStream();
  }
}

代码示例来源:origin: igniterealtime/Openfire

parent.addComment(pp.getText());
String text = pp.getText();
if (parent != null) {
  parent.addCDATA(text);
String text = pp.getText();
if (parent != null) {
  parent.addText(text);
if (pp.getPrefix() == null && IGNORED_NAMESPACE_ON_STANZA.contains(qname.getNamespaceURI())) {
  for (Element el = parent; el != null; el = el.getParent()) {
    final String defaultNS = el.getNamespaceForPrefix("").getURI();
    if (defaultNS.equals("")) {
    if (!defaultNS.equals(qname.getNamespaceURI())) {
  } else if ( parent == null && IGNORED_NAMESPACE_ON_STANZA.contains( namespaceUri ) ) {
  } else if ( !(dropNamespace && namespaceUri.equals( qname.getNamespaceURI() ) ) ) {
    newElement.addNamespace( "", namespaceUri );

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

private void wrapElementInSpringBeanContainer(Element rootElement, org.w3c.dom.Element dependentElement) throws ParserConfigurationException
{
  String namespaceUri = dependentElement.getNamespaceURI();
  Namespace namespace = new Namespace(dependentElement.getPrefix(), namespaceUri);
  Element beans = rootElement.element(new QName(BEANS_ELEMENT, namespace));
  if (beans == null)
  {
    beans = rootElement.addElement(BEANS_ELEMENT, namespaceUri);
  }
  beans.add(convert(dependentElement));
}

代码示例来源:origin: se.kb/oai4j

private void addTypesAndMetadata(AggregateBase aggregate, List<Node> nodes) {
  for (Node node : nodes) {
    Element element = (Element) node;
    if (element.getNamespace().equals(DC_NS)) {
      aggregate.addMetadata((new Metadata(Namespace.DC, element.getName(), element.getText())));
    }
    else if (element.getNamespace().equals(DCTERMS_NS)) {
      aggregate.addMetadata((new Metadata(Namespace.DCTERMS, element.getName(), element.getText())));
    }
    else if (element.getNamespace().equals(RDF_NS) && element.getName().equals("type")) {
      aggregate.addType(new Type(element.getText()));
    }
  }
}

代码示例来源:origin: igniterealtime/Openfire

Iterator<?> it = message.getElement().elementIterator();
    if (Namespace.NO_NAMESPACE.equals(el.getNamespace())) {
      continue;
    if (!el.getNamespaceURI().equals("http://jabber.org/protocol/chatstates")
        && !(el.getQName().equals(QName.get("rtt", "urn:xmpp:rtt:0")))
        ) {
      return true;

代码示例来源:origin: com.haulmont.cuba/cuba-core

private Document createEmptyDocument() {
  Document doc = DocumentHelper.createDocument();
  Element rootEl = doc.addElement("entity-mappings", XMLNS);
  Namespace xsi = new Namespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
  rootEl.add(xsi);
  rootEl.addAttribute(new QName("schemaLocation", xsi), SCHEMA_LOCATION);
  rootEl.addAttribute("version", PERSISTENCE_VER);
  return doc;
}

代码示例来源:origin: org.opencms/opencms-solr

/**
 * Adds an xml element to the given parent and sets the appropriate namespace and 
 * prefix.<p>
 * 
 * @param parent the parent node to add the element
 * @param name the name of the new element
 * 
 * @return the created element with the given name which was added to the given parent
 */
public static Element addElement(Element parent, String name) {
  return parent.addElement(new QName(name, Namespace.get("D", DEFAULT_NAMESPACE)));
}

代码示例来源:origin: igniterealtime/Openfire

/**
 * Returns the stream features which are available for this session.
 *
 * @return the stream features which are available for this session.
 */
public Collection<Element> getAvailableStreamFeaturesElements() {
  List<Element> elements = new ArrayList<>();
  if (getAuthToken() == null) {
    Element sasl = SASLAuthentication.getSASLMechanismsElement(this);
    if (sasl != null) {
      elements.add(sasl);
    }
  }
  if (XMPPServer.getInstance().getIQRegisterHandler().isInbandRegEnabled()) {
    elements.add(DocumentHelper.createElement(new QName("register",
        new Namespace("", "http://jabber.org/features/iq-register"))));
  }
  Element bind = DocumentHelper.createElement(new QName("bind",
      new Namespace("", "urn:ietf:params:xml:ns:xmpp-bind")));
  elements.add(bind);
  Element session = DocumentHelper.createElement(new QName("session",
      new Namespace("", "urn:ietf:params:xml:ns:xmpp-session")));
  session.addElement("optional");
  elements.add(session);
  return elements;
}

代码示例来源:origin: igniterealtime/Openfire

for ( int i = 0, size = element.attributeCount(); i < size; i++ ) {
  Attribute attribute = element.attribute(i);
  Namespace ns = attribute.getNamespace();
  if (ns != null && ns != Namespace.NO_NAMESPACE && ns != Namespace.XML_NAMESPACE) {
    String prefix = ns.getPrefix();
    String uri = namespaceStack.getURI(prefix);
    if (!ns.getURI().equals(uri)) { // output a new namespace declaration
      writeNamespace(ns);
      namespaceStack.push(ns);

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

public String getPath(Element context) {
  StringBuffer path = new StringBuffer(10);
  Element parent = getParent();
  if ((parent != null) && (parent != context)) {
    path.append(parent.getPath(context));
    path.append('/');
  }
  path.append(getXPathNameStep());
  return path.toString();
}

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

public String getUniquePath(Element context) {
  StringBuffer path = new StringBuffer(10);
  Element parent = getParent();
  if ((parent != null) && (parent != context)) {
    path.append(parent.getUniquePath(context));
    path.append('/');
  }
  path.append(getXPathNameStep());
  return path.toString();
}

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

public static QName get(String name, String prefix, String uri) {
  if (((prefix == null) || (prefix.length() == 0)) && (uri == null)) {
    return QName.get(name);
  } else if ((prefix == null) || (prefix.length() == 0)) {
    return getCache().get(name, Namespace.get(uri));
  } else if (uri == null) {
    return QName.get(name);
  } else {
    return getCache().get(name, Namespace.get(prefix, uri));
  }
}

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

qName = new QName(localName, Namespace.get(namespaceURI));
} else {
  qName = new QName(localName);

相关文章