org.jdom2.Namespace.getNamespace()方法的使用及代码示例

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

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

Namespace.getNamespace介绍

[英]This will retrieve (if in existence) or create (if not) a Namespace for the supplied URI, and make it usable as a default namespace, as no prefix is supplied. This method is thread-safe.
[中]这将为提供的URI检索(如果存在)或创建(如果不存在)一个Namespace,并使其可用作默认命名空间,因为没有提供前缀。此方法是线程安全的。

代码示例

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

public void registerNamespacesInto(Element element) {
  for (PluginNamespace namespace : xsdsFor.values()) {
    element.addNamespaceDeclaration(Namespace.getNamespace(namespace.prefix, namespace.uri));
  }
}

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

public Namespace getPluginNamespace() {
  return Namespace.getNamespace(getPluginNamespacePrefix(), getPluginNamespaceUri());
}

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

private static Namespace namespaceFor(ConfigTag annotation) {
  return Namespace.getNamespace(annotation.namespacePrefix(), annotation.namespaceURI());
}

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

private static Namespace namespaceFor(AttributeAwareConfigTag annotation) {
  return Namespace.getNamespace(annotation.namespacePrefix(), annotation.namespaceURI());
}

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

private Element child(Element e, ConfigTag tag) {
  return e.getChild(tag.value(), Namespace.getNamespace(tag.namespacePrefix(), tag.namespaceURI()));
}

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

private Document createEmptyCruiseConfigDocument() {
  Element root = new Element("cruise");
  Namespace xsiNamespace = Namespace.getNamespace("xsi", XML_NS);
  root.addNamespaceDeclaration(xsiNamespace);
  registry.registerNamespacesInto(root);
  root.setAttribute("noNamespaceSchemaLocation", "cruise-config.xsd", xsiNamespace);
  String xsds = registry.xsds();
  if (!xsds.isEmpty()) {
    root.setAttribute("schemaLocation", xsds, xsiNamespace);
  }
  root.setAttribute("schemaVersion", Integer.toString(GoConstants.CONFIG_SCHEMA_VERSION));
  return new Document(root);
}

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

@Test
public void shouldAddPluginNamespaceToPassedInElement() throws MalformedURLException {
  ConfigElementImplementationRegistry registry = new ConfigElementImplementationRegistry(pluginExtns);
  registry.xsdFor(PluginTestUtil.bundleCtxWithHeaders(m(PluginNamespace.XSD_NAMESPACE_PREFIX, "something", PluginNamespace.XSD_NAMESPACE_URI, "uri")), new File("file:///tmp/foo").toURI().toURL());
  registry.xsdFor(PluginTestUtil.bundleCtxWithHeaders(m(PluginNamespace.XSD_NAMESPACE_PREFIX, "second", PluginNamespace.XSD_NAMESPACE_URI, "uri-1")), new File("file:///tmp/foo1").toURI().toURL());
  Element foo = new Element("foo");
  registry.registerNamespacesInto(foo);
  assertThat(foo.getNamespace("something"), is(Namespace.getNamespace("something", "uri")));
  assertThat(foo.getNamespace("second"), is(Namespace.getNamespace("second", "uri-1")));
}

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

@Test
public void registerAllConfigTagImplementationsProvidedByPlugins() throws MalformedURLException {
  BundleContext execCtx = PluginTestUtil.bundleCtxWithHeaders(DataStructureUtils.m(PluginNamespace.XSD_NAMESPACE_PREFIX, "exec", PluginNamespace.XSD_NAMESPACE_URI, "uri-exec"));
  PluggableViewModelFactory<PluginExec> factory = mock(PluggableViewModelFactory.class);
  ConfigTypeExtension exec = new TestTaskConfigTypeExtension<>(PluginExec.class, factory);
  ConfigurationExtension execTag = new ConfigurationExtension<>(
      new PluginNamespace(execCtx, new URL("file:///exec")), exec);
  BundleContext antCtx = PluginTestUtil.bundleCtxWithHeaders(DataStructureUtils.m(PluginNamespace.XSD_NAMESPACE_PREFIX, "ant", PluginNamespace.XSD_NAMESPACE_URI, "uri-ant"));
  ConfigTypeExtension ant = new TestTaskConfigTypeExtension<>(PluginAnt.class, mock(PluggableViewModelFactory.class));
  ConfigurationExtension antTag = new ConfigurationExtension<>(
      new PluginNamespace(antCtx, new URL("file:///ant")), ant);
  when(pluginExtns.configTagImplementations()).thenReturn(Arrays.asList(execTag, antTag));
  ConfigElementImplementationRegistry registry = new ConfigElementImplementationRegistry(pluginExtns);
  assertThat(registry.xsds(), containsString("uri-exec file:/exec"));
  assertThat(registry.xsds(), containsString("uri-ant file:/ant"));
  List<Class<? extends Task>> implementationTypes = registry.implementersOf(Task.class);
  assertThat(implementationTypes.contains(PluginExec.class), is(true));
  assertThat(implementationTypes.contains(PluginAnt.class), is(true));
  Element mock = mock(Element.class);
  registry.registerNamespacesInto(mock);
  verify(mock).addNamespaceDeclaration(Namespace.getNamespace("exec", "uri-exec"));
  verify(mock).addNamespaceDeclaration(Namespace.getNamespace("ant", "uri-ant"));
}

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

/**
 * This will retrieve (if in existence) or create (if not) a 
 * <code>Namespace</code> for the supplied URI, and make it usable 
 * as a default namespace, as no prefix is supplied.
 * This method is thread-safe.
 *
 * @param uri <code>String</code> URI of new <code>Namespace</code>.
 * @return <code>Namespace</code> - ready to use namespace.
 */
public static Namespace getNamespace(final String uri) {
  return getNamespace(NS_PREFIX_DEFAULT, uri);
}

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

/**
 * Creates a new element with the supplied (local) name and a namespace
 * given by a URI. The element will be put into the unprefixed (default)
 * namespace.
 *
 * @param  name                 name of the element
 * @param  uri                  namespace URI for the element
 * @throws IllegalNameException if the given name is illegal as an element
 *                              name or the given URI is illegal as a
 *                              namespace URI
 */
public Element(final String name, final String uri) {
  this(name, Namespace.getNamespace(NS_PREFIX_DEFAULT, uri));
}

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

private Object readResolve() {
  return Namespace.getNamespace(pprefix, puri);
}

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

/**
 * Creates a new element with the supplied (local) name and a namespace
 * given by the supplied prefix and URI combination.
 *
 * @param  name                 local name of the element
 * @param  prefix               namespace prefix
 * @param  uri                  namespace URI for the element
 * @throws IllegalNameException if the given name is illegal as an element
 *                              name, the given prefix is illegal as a
 *                              namespace prefix, or the given URI is
 *                              illegal as a namespace URI
 */
public Element(final String name, final String prefix, final String uri) {
  this(name, Namespace.getNamespace(prefix, uri));
}

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

/**
 * This will add the prefix mapping to the JDOM <code>Document</code>
 * object.
 * 
 * @param prefix
 *        <code>String</code> namespace prefix.
 * @param uri
 *        <code>String</code> namespace URI.
 */
@Override
public void startPrefixMapping(final String prefix, final String uri)
    throws SAXException {
  if (suppress)
    return;
  final Namespace ns = Namespace.getNamespace(prefix, uri);
  declaredNamespaces.add(ns);
}

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

@Override
public Element element(final int line, final int col, final String name, String uri) {
  return element(name, Namespace.getNamespace("", uri));
}

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

@Override
public Element element(final int line, final int col, final String name, String prefix, String uri) {
  return element(name, Namespace.getNamespace(prefix, uri));
}

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

/**
 * Adds a namespace definition (prefix and URI) to the list of
 * namespaces known of this XPath expression.
 * <p>
 * <strong>Note</strong>: In XPath, there is no such thing as a
 * 'default namespace'.  The empty prefix <b>always</b> resolves
 * to the empty namespace URI.</p>
 *
 * @param  prefix   the namespace prefix.
 * @param  uri      the namespace URI.
 *
 * @throws IllegalNameException   if the prefix or uri are null or
 *                                empty strings or if they contain
 *                                illegal characters.
 */
public void addNamespace(String prefix, String uri) {
  addNamespace(Namespace.getNamespace(prefix, uri));
}

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

/**
 * Define a Namespace to be available for the XPath expression. If a
 * Namespace with the same prefix was previously defined then the prefix
 * will be re-defined.
 * 
 * @param prefix
 *        The namespace prefix to define.
 * @param uri
 *        The namespace URI to define.
 * @return true if the Namespace prefix was newly defined, false if the
 *         prefix was previously defined and has now been redefined.
 */
public boolean setNamespace(String prefix, String uri) {
  if (prefix == null) {
    throw new NullPointerException("Null prefix");
  }
  if (uri == null) {
    throw new NullPointerException("Null URI");
  }
  return setNamespace(Namespace.getNamespace(prefix, uri));
}

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

private static final Element processElement(final JDOMFactory factory, 
    final XMLStreamReader reader) {
  final Element element = factory.element(reader.getLocalName(),
      Namespace.getNamespace(reader.getPrefix(), 
          reader.getNamespaceURI()));
  // Handle attributes
  for (int i=0, len=reader.getAttributeCount(); i<len; i++) {
    factory.setAttribute(element, factory.attribute(
        reader.getAttributeLocalName(i),
        reader.getAttributeValue(i), 
        AttributeType.getAttributeType(reader.getAttributeType(i)),
        Namespace.getNamespace(reader.getAttributePrefix(i),
            reader.getAttributeNamespace(i))));
  }
  // Handle Namespaces
  for (int i = 0, len = reader.getNamespaceCount(); i < len; i++) {
    element.addNamespaceDeclaration(Namespace.getNamespace(
        reader.getNamespacePrefix(i), reader.getNamespaceURI(i)));
  }
  return element;
}

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

private static final Element processElement(final JDOMFactory factory,
    final StartElement event) {
  final QName qname = event.getName();
  final Element element = factory.element(qname.getLocalPart(),
      Namespace.getNamespace(qname.getPrefix(), qname.getNamespaceURI()));
  // Handle attributes
  for (final Iterator<?> it = event.getAttributes();
      it.hasNext(); ) {
    final javax.xml.stream.events.Attribute att =
        (javax.xml.stream.events.Attribute)it.next();
    final QName aqname = att.getName();
    final Namespace attNs = Namespace.getNamespace(aqname.getPrefix(),
        aqname.getNamespaceURI());
    factory.setAttribute(element, factory.attribute(
        aqname.getLocalPart(), att.getValue(),
        AttributeType.getAttributeType(att.getDTDType()), attNs));
  }
  for (final Iterator<?> it = event.getNamespaces(); it.hasNext();) {
    final javax.xml.stream.events.Namespace ns =
        (javax.xml.stream.events.Namespace)it.next();
    element.addNamespaceDeclaration(Namespace.getNamespace(
        ns.getPrefix(), ns.getNamespaceURI()));
  }
  return element;
}

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

@Override
public Object getVariableValue(String namespaceURI, String prefix,
    String localName) throws UnresolvableException {
  if (namespaceURI == null) {
    namespaceURI = "";
  }
  if (prefix == null) {
    prefix = "";
  }
  try {
    if ("".equals(namespaceURI)) {
      namespaceURI = getNamespace(prefix).getURI();
    }
    return getVariable(localName, Namespace.getNamespace(namespaceURI));
  } catch (IllegalArgumentException e) {
    throw new UnresolvableException("Unable to resolve variable " + 
        localName + " in namespace '" + namespaceURI + 
        "' to a vaulue.");
  }
}

相关文章