private static boolean compareAttributeAwareConfigTag(Element e, AttributeAwareConfigTag attributeAwareConfigTag) { return attributeAwareConfigTag.value().equals(e.getName()) && attributeAwareConfigTag.attributeValue().equals(e.getAttributeValue(attributeAwareConfigTag.attribute())) && e.getNamespace().getURI().equals(attributeAwareConfigTag.namespaceURI()); }
public static boolean compare(Element e, Class<?> implementation, ConfigCache configCache) { final AttributeAwareConfigTag attributeAwareConfigTag = annotationFor(implementation, AttributeAwareConfigTag.class); if (attributeAwareConfigTag != null) { return compareAttributeAwareConfigTag(e, attributeAwareConfigTag); } ConfigTag configTag = configTag(implementation, configCache); return configTag.value().equals(e.getName()) && e.getNamespace().getURI().equals(configTag.namespaceURI()); }
/** * This returns the URI mapped to this <code>Attribute</code>'s * prefix. If no mapping is found, an empty <code>String</code> is * returned. * * @return <code>String</code> - namespace URI for this <code>Attribute</code>. */ public String getNamespaceURI() { return namespace.getURI(); }
/** * Returns the namespace URI mapped to this element's prefix (or the * in-scope default namespace URI if no prefix). If no mapping is found, an * empty string is returned. * * @return the namespace URI for this element */ public String getNamespaceURI() { return namespace.getURI(); }
@Override public final Object getVariable(final String name, Namespace uri) { final Map<String, Object> vmap = xvariables.get(uri == null ? "" : uri.getURI()); if (vmap == null) { throw new IllegalArgumentException("Variable with name '" + name + "' in namespace '" + uri.getURI() + "' has not been declared."); } final Object ret = vmap.get(name); if (ret == null) { if (!vmap.containsKey(name)) { throw new IllegalArgumentException("Variable with name '" + name + "' in namespace '" + uri.getURI() + "' has not been declared."); } // leave translating null variable values to the implementation. return null; } return ret; }
@Override public Object setVariable(String name, Namespace uri, Object value) { final Object ret = getVariable(name, uri); // if that succeeded then we have it easy.... xvariables.get(uri.getURI()).put(name, value); return ret; }
@Override public String toString() { return ns.getPrefix() + "=" + ns.getURI(); } }
@Override public String translateNamespacePrefixToUri(String prefix) { return getNamespace(prefix).getURI(); }
@Override public final String getNamespaceStringValue(Object namespace) { return ((NamespaceContainer)namespace).getNamespace().getURI(); }
void includeNamespace(Namespace namespace) { nsFromUser.put(namespace.getPrefix(), namespace.getURI()); }
/** * 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); }
/** * 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; }
@Override public javax.xml.stream.events.Namespace next() { Namespace ns = source.next(); return fac.createNamespace(ns.getPrefix(), ns.getURI()); }
/** * 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()); }
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()); } } }
/** * Return index of the <code>Attribute</code> with the given <i>name</i> and * the same Namespace URI as <i>namespace</i>. * * @param name * name of <code>Attribute</code> to retrieve * @param namespace * indicate what <code>Namespace</code> URI to consider * @return the index of the attribute that matches the conditions, or * <code>-1</code> if there is none. */ int indexOf(final String name, final Namespace namespace) { if (attributeData != null) { if (namespace == null) { return indexOf(name, Namespace.NO_NAMESPACE); } final String uri = namespace.getURI(); for (int i = 0; i < size; i++) { final Attribute att = attributeData[i]; if (uri.equals(att.getNamespaceURI()) && name.equals(att.getName())) { return i; } } } return -1; }
@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."); } }
@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()); }
/** * 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()); } }
/** * This will handle printing of any needed <code>{@link Namespace}</code> * declarations. * * @param out * <code>Writer</code> to use. * @param fstack * The current FormatStack * @param ns * <code>Namespace</code> to print definition of * @throws IOException * if the output fails */ protected void printNamespace(final Writer out, final FormatStack fstack, final Namespace ns) throws IOException { final String prefix = ns.getPrefix(); final String uri = ns.getURI(); write(out, " xmlns"); if (!prefix.equals("")) { write(out, ":"); write(out, prefix); } write(out, "=\""); attributeEscapedEntitiesFilter(out, fstack, uri); write(out, "\""); }