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

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

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

Namespace.getPrefix介绍

[英]This returns the prefix mapped to this Namespace.
[中]

代码示例

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

/**
 * Returns the namespace prefix of the element or an empty string if none
 * exists.
 *
 * @return                     the namespace prefix
 */
public String getNamespacePrefix() {
  return namespace.getPrefix();
}

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

/**
 * This will retrieve the namespace prefix of the
 * <code>Attribute</code>. For any XML attribute
 * which appears as
 * <code>[namespacePrefix]:[attributeName]</code>,
 * the namespace prefix of the attribute would be
 * <code>[namespacePrefix]</code>. When the attribute
 * has no namespace, an empty <code>String</code> is returned.
 *
 * @return <code>String</code> - namespace prefix of this
 *                               attribute.
 */
public String getNamespacePrefix() {
  return namespace.getPrefix();
}

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

@Override
  public int compare(Namespace ns1, Namespace ns2) {
    return ns1.getPrefix().compareTo(ns2.getPrefix());
  }
}

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

@Override
  public int compare(Namespace ns1, Namespace ns2) {
    return ns1.getPrefix().compareTo(ns2.getPrefix());
  }
};

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

/**
 * This will handle adding any <code>{@link Namespace}</code> attributes to
 * the DOM tree.
 * 
 * @param ns
 *        <code>Namespace</code> to add definition of
 */
private static String getXmlnsTagFor(Namespace ns) {
  String attrName = "xmlns";
  if (!ns.getPrefix().equals("")) {
    attrName += ":";
    attrName += ns.getPrefix();
  }
  return attrName;
}

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

@Override
  public String toString() {
    return ns.getPrefix() + "=" + ns.getURI();
  }
}

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

@Override
public final String getNamespacePrefix(Object namespace) {
  return ((NamespaceContainer)namespace).getNamespace().getPrefix();
}

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

void includeNamespace(Namespace namespace) {
  nsFromUser.put(namespace.getPrefix(), namespace.getURI());
}

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

/**
 * Define a Namespace to be available for the XPath expression.
 * 
 * @param namespace
 *        The namespace to define.
 * @return true if this Namespace prefix was newly defined, false if the
 *         prefix was previously defined and has now been redefined.
 * @throws NullPointerException
 *         if the namespace is null.
 */
public boolean setNamespace(Namespace namespace) {
  if (namespace == null) {
    throw new NullPointerException("Null Namespace");
  }
  if ("".equals(namespace.getPrefix())) {
    if (Namespace.NO_NAMESPACE != namespace) {
      throw new IllegalArgumentException(
          "Cannot set a Namespace URI in XPath for the \"\" prefix.");
    }
    // NO_NAMESPACE is always defined...
    return false;
  }
  if (namespaces == null) {
    namespaces = new HashMap<String, Namespace>();
  }
  return namespaces.put(namespace.getPrefix(), namespace) == null;
}

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

private static final List<Namespace> orderFirst(final Namespace nsa, 
    final List<Namespace> nsl) {
  if (nsl.get(0) == nsa) {
    return nsl;
  }
  // OK, we have our namespace list, but our's is not the first.
  // we need the Attribute's Namespace to be up front.
  TreeMap<String,Namespace> tm = new TreeMap<String, Namespace>();
  for (Namespace ns : nsl) {
    if (ns != nsa) {
      tm.put(ns.getPrefix(), ns);
    }
  }
  ArrayList<Namespace> ret = new ArrayList<Namespace>(tm.size() + 1);
  ret.add(nsa);
  ret.addAll(tm.values());
  return Collections.unmodifiableList(ret);
}

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

/**
 * Returns the full name of the element, in the form
 * [namespacePrefix]:[localName]. If the element does not have a namespace
 * prefix, then the local name is returned.
 *
 * @return                     qualified name of the element (including
 *                             namespace prefix)
 */
public String getQualifiedName() {
  // Note: Any changes here should be reflected in
  // XMLOutputter.printQualifiedName()
  if ("".equals(namespace.getPrefix())) {
    return getName();
  }
  return new StringBuilder(namespace.getPrefix())
  .append(':')
  .append(name)
  .toString();
}

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

/**
 * This will handle printing of any needed <code>{@link Namespace}</code>
 * declarations.
 * 
 * @param out
 *        <code>XMLStreamWriter</code> to use.
 * @param fstack
 *        The current FormatStack
 * @param ns
 *        <code>Namespace</code> to print definition of
 * @throws XMLStreamException
 *         if the output fails
 */
protected void printNamespace(final XMLStreamWriter out, final FormatStack fstack, 
    final Namespace ns)  throws XMLStreamException {
  final String prefix = ns.getPrefix();
  final String uri = ns.getURI();
  
  out.writeNamespace(prefix, uri);
}

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

/**
 * Check if two namespaces collide.
 *
 * @param namespace <code>Namespace</code> to check.
 * @param other <code>Namespace</code> to check against.
 * @return <code>String</code> reason for collision, or
 *         <code>null</code> if no collision.
 */
public static String checkNamespaceCollision(final Namespace namespace,
    final Namespace other) {
  String p1,p2,u1,u2,reason;
  reason = null;
  p1 = namespace.getPrefix();
  u1 = namespace.getURI();
  p2 = other.getPrefix();
  u2 = other.getURI();
  if (p1.equals(p2) && !u1.equals(u2)) {
    reason = "The namespace prefix \"" + p1 + "\" collides";
  }
  return reason;
}

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

@Override
public javax.xml.stream.events.Namespace next() {
  Namespace ns = source.next();
  return fac.createNamespace(ns.getPrefix(), ns.getURI());
}

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

/**
 * This will create an <code>Exception</code> indicating
 * that the addition of the <code>{@link Namespace}</code>
 * to the <code>{@link Element}</code> is illegal.
 *
 * @param base <code>Element</code> that the <code>Namespace</code>
 *             couldn't be added to
 * @param added <code>Namespace</code> that could not be added
 * @param reason cause of the problem
 */
IllegalAddException(Element base, Namespace added, String reason) {
  super(new StringBuilder()
  .append("The namespace xmlns")
  .append(added.getPrefix().equals("") ? "=" 
      : ":" + added.getPrefix() + "=")
      .append("\"")
      .append(added.getURI())
      .append("\" could not be added as a namespace to \"")
      .append(base.getQualifiedName())
      .append("\": ")
      .append(reason)
      .toString());
}

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

/**
 * Check if <code>{@link Attribute}</code>'s namespace collides with a 
 * <code>{@link Element}</code>'s namespace.
 *
 * @param attribute <code>Attribute</code> to check.
 * @param element <code>Element</code> to check against.
 * @return <code>String</code> reason for collision, or
 *         <code>null</code> if no collision.
 */
public static String checkNamespaceCollision(final Attribute attribute,
    final Element element) {
  final Namespace namespace = attribute.getNamespace();
  final String prefix = namespace.getPrefix();
  if ("".equals(prefix)) {
    return null;
  }
  return checkNamespaceCollision(namespace, element);
}

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

void setContext(Object node) {
  nsFromContext.clear();
  List<Namespace> nsl = null;
  if (node instanceof NamespaceAware) {
    nsl = ((NamespaceAware)node).getNamespacesInScope();
  } else if (node instanceof NamespaceContainer) {
    nsl = ((NamespaceContainer)node).getParentElement().getNamespacesInScope();
  }
  if (nsl != null) {
    for (Namespace ns : nsl) {
      nsFromContext.put(ns.getPrefix(), ns.getURI());
    }
  }
}

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

@Override
public final String getElementQName(Object element) {
  Element e = (Element)element;
  if (e.getNamespace().getPrefix().length() == 0) {
    return e.getName();
  }
  return e.getNamespacePrefix() + ":" + e.getName();
}

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

@Override
public javax.xml.stream.events.Attribute next() {
  final Attribute att = source.next();
  final Namespace ns = att.getNamespace();
  if (ns == Namespace.NO_NAMESPACE) {
    return fac.createAttribute(att.getName(), att.getValue());
  }
  return fac.createAttribute(ns.getPrefix(), ns.getURI(), 
      att.getName(), att.getValue());
}

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

/**
 * This will handle printing of an <code>{@link Attribute}</code>.
 * 
 * @param out
 *        <code>XMLStreamWriter</code> to use.
 * @param fstack
 *        The current FormatStack
 * @param attribute
 *        <code>Attribute</code> to output
 * @throws XMLStreamException
 *         if the output fails
 */
protected void printAttribute(final XMLStreamWriter out, final FormatStack fstack,
    final Attribute attribute) throws XMLStreamException {
  if (!attribute.isSpecified() && fstack.isSpecifiedAttributesOnly()) {
    return;
  }
  
  final Namespace ns = attribute.getNamespace();
  if (ns == Namespace.NO_NAMESPACE) {
    out.writeAttribute(attribute.getName(), attribute.getValue());
  } else {
    out.writeAttribute(ns.getPrefix(), ns.getURI(), 
        attribute.getName(), attribute.getValue());
  }
}

相关文章

微信公众号

最新文章

更多