/** * Returns the qualified name of the attribute * * @param a * an attribute event * @param enabledNamespaces * indicates if namespaces should be added or not * @return the qualified name of the attribute */ private String getAttributeName( Attribute a, boolean enabledNamespaces ) { if ( !enabledNamespaces ) { return a.getName().getLocalPart(); } else { return getName( a.getName().getPrefix(), a.getName().getLocalPart() ); } }
private List<Attribute> updateElementAttributes(StartElement startElement) { // adjust the version attribute List<Attribute> newElementAttributeList = new ArrayList<Attribute>(); Iterator<?> existingAttributesIterator = startElement.getAttributes(); while ( existingAttributesIterator.hasNext() ) { Attribute attribute = (Attribute) existingAttributesIterator.next(); if ( VERSION_ATTRIBUTE_NAME.equals( attribute.getName().getLocalPart() ) ) { if ( !DEFAULT_VERSION.equals( attribute.getName().getPrefix() ) ) { newElementAttributeList.add( xmlEventFactory.createAttribute( attribute.getName(), DEFAULT_VERSION ) ); } } else { newElementAttributeList.add( attribute ); } } return newElementAttributeList; } }
private Attribute mapAttribute(StartElement startElement, Attribute originalAttribute) { // Here we look to see if this attribute is the JPA version attribute, and if so do 2 things: // 1) validate its version attribute is valid // 2) update its version attribute to the default version if not already // // NOTE : atm this is a very simple check using just the attribute's local name // rather than checking its qualified name. It is possibly (though unlikely) // that this could match on "other" version attributes in the same element if ( ROOT_ELEMENT_NAME.equals( startElement.getName().getLocalPart() ) ) { if ( VERSION_ATTRIBUTE_NAME.equals( originalAttribute.getName().getLocalPart() ) ) { final String specifiedVersion = originalAttribute.getValue(); if ( !LocalXsdResolver.isValidJpaVersion( specifiedVersion ) ) { throw new BadVersionException( specifiedVersion ); } return xmlEventFactory.createAttribute( VERSION_ATTRIBUTE_NAME, LocalXsdResolver.latestJpaVerison() ); } } return originalAttribute; }
if (attrs == null || !attrs.hasNext()) { attrMap = null; } else { attrMap = new LinkedHashMap(); do { Attribute attr = (Attribute) attrs.next(); attrMap.put(attr.getName(), attr); } while (attrs.hasNext()); if (ns != null && ns.hasNext()) { ArrayList l = new ArrayList(); do { l.add((Namespace) ns.next()); // cast to catch type problems early } while (ns.hasNext()); myCtxt = MergedNsContext.construct(nsCtxt, l);
@Override public String next() { Attribute a = it.next(); return a.getName().getLocalPart(); } };
private Element copyAttributes(StartElement source, Element destination) { for (Attribute attribute : forwardOnly(Unchecked.<Iterator<Attribute>>cast(source.getAttributes()))) { destination.setAttribute(attribute.getName().getLocalPart(), attribute.getValue()); } return destination; }
private Attributes getAttributes(StartElement event) { AttributesImpl attributes = new AttributesImpl(); for (Iterator i = event.getAttributes(); i.hasNext();) { Attribute attribute = (Attribute) i.next(); QName qName = attribute.getName(); String namespace = qName.getNamespaceURI(); if (namespace == null || !hasNamespacesFeature()) { type = "CDATA"; attributes.addAttribute(namespace, qName.getLocalPart(), toQualifiedName(qName), type, attribute.getValue()); for (Iterator i = event.getNamespaces(); i.hasNext();) { Namespace namespace = (Namespace) i.next(); String prefix = namespace.getPrefix(); String namespaceUri = namespace.getNamespaceURI();
private void writeAttribute(Attribute a) throws XMLStreamException { writer.writeAttribute(a.getName().getNamespaceURI(), a.getName().getLocalPart(), a.getValue()); } public void addAttribute(Attribute a)
private void updateContext(XMLEvent event) { if (event == null) return; if (event.isEndElement()) { stack.pop(); stackString = ""; for (String s : stack) { stackString += "/" + s; } } else if (event.isStartElement()) { stack.push(event.asStartElement().getName().getLocalPart()); stackString += "/" + event.asStartElement().getName().getLocalPart(); } else if (event.isAttribute()) { Attribute attribute = (Attribute)event; stackString = ""; for (String s : stack) { stackString += "/" + s; } stackString += "/@" + attribute.getName().getLocalPart(); } }
private void handleStartElement(StartElement startElement) throws SAXException { if (getContentHandler() != null) { QName qName = startElement.getName(); if (hasNamespacesFeature()) { for (Iterator i = startElement.getNamespaces(); i.hasNext();) { Namespace namespace = (Namespace) i.next(); startPrefixMapping(namespace.getPrefix(), namespace.getNamespaceURI()); } for (Iterator i = startElement.getAttributes(); i.hasNext();){ Attribute attribute = (Attribute) i.next(); QName attributeName = attribute.getName(); startPrefixMapping(attributeName.getPrefix(), attributeName.getNamespaceURI()); } getContentHandler().startElement(qName.getNamespaceURI(), qName.getLocalPart(), toQualifiedName(qName), getAttributes(startElement)); } else { getContentHandler().startElement("", "", toQualifiedName(qName), getAttributes(startElement)); } } }
private static void printAttribute(Attribute a) { printName(a.getName().getPrefix(),a.getName().getNamespaceURI(), a.getName().getLocalPart()); System.out.print("='"+a.getValue()+"'"); }
Attribute getAttributeByName(String name) { if(attributes == null) return null; for(Attribute attr: attributes) { if(name.equals(attr.getName().getLocalPart())) return attr; } return null; }
for (Iterator i = event.getAttributes(); i.hasNext();) { Attribute staxAttr = (Attribute)i.next(); QName name = staxAttr.getName(); String uri = fixNull(name.getNamespaceURI()); String localName = name.getLocalPart(); String prefix = name.getPrefix(); String qName; qName = prefix + ':' + localName; String type = staxAttr.getDTDType(); String value = staxAttr.getValue();
private static void printAttribute(Attribute a) { System.out.println("PREFIX: " + a.getName().getPrefix()); System.out.println("NAMESP: " + a.getName().getNamespaceURI()); System.out.println("NAME: " + a.getName().getLocalPart()); System.out.println("VALUE: " + a.getValue()); System.out.println("TYPE: " + a.getDTDType()); }
private void updateContext(XMLEvent event) { if (event == null) return; if (event.isEndElement()) { stack.pop(); stackString = ""; for (String s : stack) { stackString += "/" + s; } } else if (event.isStartElement()) { stack.push(event.asStartElement().getName().getLocalPart()); stackString += "/" + event.asStartElement().getName().getLocalPart(); } else if (event.isAttribute()) { Attribute attribute = (Attribute)event; stackString = ""; for (String s : stack) { stackString += "/" + s; } stackString += "/@" + attribute.getName().getLocalPart(); } }
private Attributes getAttributes(StartElement event) { AttributesImpl attributes = new AttributesImpl(); for (Iterator i = event.getAttributes(); i.hasNext();) { Attribute attribute = (Attribute) i.next(); QName qName = attribute.getName(); String namespace = qName.getNamespaceURI(); if (namespace == null || !hasNamespacesFeature()) { type = "CDATA"; attributes.addAttribute(namespace, qName.getLocalPart(), toQualifiedName(qName), type, attribute.getValue()); for (Iterator i = event.getNamespaces(); i.hasNext();) { Namespace namespace = (Namespace) i.next(); String prefix = namespace.getPrefix(); String namespaceUri = namespace.getNamespaceURI();
public String getAttributeValue(String namespaceURI, String localName) { for (Attribute attribute : getAttributes()) { if (attribute.getName().getNamespaceURI().equals(namespaceURI) && attribute.getName().getLocalPart().equals(localName)) { return attribute.getValue(); } } return null; }
public String getAttributeLocalName(int arg0) { String ret = null; List<Attribute> currentAttributes = eventProducer.getAttributes(); if (currentAttributes != null) { Attribute a = currentAttributes.get(arg0); if (a != null) { ret = a.getName().getLocalPart(); } } return ret; }
private void handleStartElement(StartElement startElement) throws SAXException { if (getContentHandler() != null) { QName qName = startElement.getName(); if (hasNamespacesFeature()) { for (Iterator i = startElement.getNamespaces(); i.hasNext();) { Namespace namespace = (Namespace) i.next(); startPrefixMapping(namespace.getPrefix(), namespace.getNamespaceURI()); } for (Iterator i = startElement.getAttributes(); i.hasNext();){ Attribute attribute = (Attribute) i.next(); QName attributeName = attribute.getName(); startPrefixMapping(attributeName.getPrefix(), attributeName.getNamespaceURI()); } getContentHandler().startElement(qName.getNamespaceURI(), qName.getLocalPart(), toQualifiedName(qName), getAttributes(startElement)); } else { getContentHandler().startElement("", "", toQualifiedName(qName), getAttributes(startElement)); } } }