@SuppressWarnings( "unchecked" ) private void appendElement( Element source, Element target ) { for ( Iterator<Attribute> itr = source.getAttributes().iterator(); itr.hasNext(); ) { Attribute a = itr.next(); itr.remove(); Attribute mergedAtt = target.getAttribute( a.getName(), a.getNamespace() ); if ( mergedAtt == null ) { target.setAttribute( a ); } } for ( Iterator<Element> itr = source.getChildren().iterator(); itr.hasNext(); ) { Content n = itr.next(); itr.remove(); target.addContent( n ); } }
for (final Attribute a : attributes) { if (prefix.equals(a.getNamespacePrefix())) { return a.getNamespace();
if (att.getNamespace() == Namespace.NO_NAMESPACE) { buffer.append("@").append(att.getName()); } else {
@Override public List<Namespace> getNamespacesIntroduced() { if (getParent() == null) { return Collections.singletonList(getNamespace()); } return Collections.emptyList(); }
/** * Check if a <code>{@link Namespace}</code> collides with a * <code>{@link Attribute}</code>'s namespace. * * @param namespace <code>Namespace</code> to check. * @param attribute <code>Attribute</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 Attribute attribute) { String reason = null; if (!attribute.getNamespace().equals(Namespace.NO_NAMESPACE)) { reason = checkNamespaceCollision(namespace, attribute.getNamespace()); if (reason != null) { reason += " with an attribute namespace prefix on the element"; } } return reason; }
/** * Create a new in-scope level for the Stack based on an Attribute. * * @param att The attribute to contribute to the namespace scope. */ public void push(Attribute att) { final List<Namespace> toadd = new ArrayList<Namespace>(1); final Namespace mns = att.getNamespace(); // check to see whether the Namespace is new-to-scope. Namespace[] newscope = checkNamespace(toadd, mns, scope[depth]); pushStack(mns, newscope, toadd); }
/** * Return index of attribute with same name and Namespace, or -1 if one * doesn't exist */ private int indexOfDuplicate(final Attribute attribute) { return indexOf(attribute.getName(), attribute.getNamespace()); }
/** * 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); }
/** * Check to see if the Content matches a predefined set of rules. * * @param content The Content to verify. * @return <code>true</code> if the objected matched a predfined * set of rules. */ @Override public Attribute filter(Object content) { if (content instanceof Attribute) { Attribute att = (Attribute) content; if (name == null) { if (namespace == null) { return att; } return namespace.equals(att.getNamespace()) ? att : null; } if (!name.equals(att.getName())) { return null; } if (namespace == null) { return att; } return namespace.equals(att.getNamespace()) ? att : null; } return null; }
if (getParent() == null) { ArrayList<Namespace> ret = new ArrayList<Namespace>(3); ret.add(getNamespace()); ret.add(Namespace.XML_NAMESPACE); return Collections.unmodifiableList(ret); return orderFirst(getNamespace(), getParent().getNamespacesInScope());
@Override public List<Namespace> getNamespacesInherited() { if (getParent() == null) { return Collections.singletonList(Namespace.XML_NAMESPACE); } return orderFirst(getNamespace(), getParent().getNamespacesInScope()); }
Namespace ns = att.getNamespace(); if (!namespaces.containsKey(ns.getPrefix())) { namespaces.put(ns.getPrefix(), ns);
@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()); } }
final Namespace ns = a.getNamespace(); if (ns == Namespace.NO_NAMESPACE) {
/** * Filters an element's attributes. * * @param element An element whose attributes will be filtered * @return The input element whose attributes have been filtered */ private Element filterAttributes(Element element) { Element result = (Element) element.clone(); List<Attribute> attributes = result.getAttributes(); Iterator<Attribute> it = attributes.iterator(); while (it.hasNext()) { Attribute attr = it.next(); if (attr.getNamespace().equals(m_namespace)) { it.remove(); } } return result; }
public void undo(MCRChangeData data) { Attribute attribute = data.getAttribute(); data.getContext().removeAttribute(attribute.getName(), attribute.getNamespace()); } }
/** * Copies those attributes from the other's element into this' element that do not exist in this' element. */ protected void mergeAttributes(MCRMerger other) { for (Attribute attribute : other.element.getAttributes()) { if (this.element.getAttribute(attribute.getName(), attribute.getNamespace()) == null) { this.element.setAttribute(attribute.clone()); } } }
public void undo(MCRChangeData data) { Attribute attribute = data.getAttribute(); data.getContext().removeAttribute(attribute.getName(), attribute.getNamespace()); data.getContext().setAttribute(attribute); } }
private IConstructor convertElement(Element e, boolean trim) { IListWriter kids = vf.listWriter(Factory.Node); for (Object o: e.getAttributes()) { Attribute attr = (Attribute)o; IString key = vf.string(attr.getName()); IString val = vf.string(attr.getValue()); kids.insert(vf.constructor(Factory.Node_attribute, convertNamespace(attr.getNamespace()), key, val)); } int len = e.getContentSize(); for (int i = 0; i < len; i++) { try { kids.append(convertContent(e.getContent(i), trim)); } catch (Skip c) { // Ugh, terrible, but I'm in hurry continue; } } IString name = vf.string(e.getName()); return vf.constructor(Factory.Node_element, convertNamespace(e.getNamespace()), name, kids.done()); }