use of javax.xml.stream.events.Attribute in project spring-framework by spring-projects.
the class StaxEventXMLReader method handleStartElement.
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));
}
}
}
use of javax.xml.stream.events.Attribute in project spring-framework by spring-projects.
the class StaxEventXMLReader method getAttributes.
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()) {
namespace = "";
}
String type = attribute.getDTDType();
if (type == null) {
type = "CDATA";
}
attributes.addAttribute(namespace, qName.getLocalPart(), toQualifiedName(qName), type, attribute.getValue());
}
if (hasNamespacePrefixesFeature()) {
for (Iterator i = event.getNamespaces(); i.hasNext(); ) {
Namespace namespace = (Namespace) i.next();
String prefix = namespace.getPrefix();
String namespaceUri = namespace.getNamespaceURI();
String qName;
if (StringUtils.hasLength(prefix)) {
qName = "xmlns:" + prefix;
} else {
qName = "xmlns";
}
attributes.addAttribute("", "", qName, "CDATA", namespaceUri);
}
}
return attributes;
}
use of javax.xml.stream.events.Attribute in project kernel by exoplatform.
the class InitialContextBinder method readBindings.
/**
* Import references from xml-file.
*
* @return map with bind name - references
*
* @throws XMLStreamException
* if errors occurs during import
* @throws FileNotFoundException
* if can't open input stream from file
*/
protected Map<String, Reference> readBindings() throws FileNotFoundException, XMLStreamException {
Stack<RefEntity> stack = new Stack<RefEntity>();
Map<String, Reference> importedRefs = new HashMap<String, Reference>();
XMLInputFactory factory = XMLInputFactory.newInstance();
XMLEventReader reader = factory.createXMLEventReader(PrivilegedFileHelper.fileInputStream(bindingsStorePath), "UTF-8");
while (reader.hasNext()) {
XMLEvent event = reader.nextEvent();
switch(event.getEventType()) {
case XMLStreamConstants.START_ELEMENT:
StartElement startElement = event.asStartElement();
Map<String, String> attr = new HashMap<String, String>();
Iterator attributes = startElement.getAttributes();
while (attributes.hasNext()) {
Attribute attribute = (Attribute) attributes.next();
attr.put(attribute.getName().getLocalPart(), attribute.getValue());
}
String localName = startElement.getName().getLocalPart();
if (localName.equals(REFERENCE_ELEMENT)) {
String bindName = attr.get(BIND_NAME_ATTR);
String className = attr.get(CLASS_NAME_ATTR);
String factoryName = attr.get(FACTORY_ATTR);
String factoryLocation = attr.get(FACTORY_LOCATION_ATTR);
Reference reference = new Reference(className, factoryName, factoryLocation);
stack.push(new RefEntity(bindName, reference));
} else if (localName.equals(PROPERTY_ELEMENT)) {
RefEntity refEntity = stack.pop();
Reference reference = refEntity.getValue();
for (Entry<String, String> entry : attr.entrySet()) {
reference.add(new StringRefAddr(entry.getKey(), entry.getValue()));
}
refEntity.setValue(reference);
stack.push(refEntity);
}
break;
case XMLStreamConstants.END_ELEMENT:
EndElement endElement = event.asEndElement();
localName = endElement.getName().getLocalPart();
if (localName.equals(REFERENCE_ELEMENT)) {
RefEntity refEntity = stack.pop();
importedRefs.put(refEntity.getKey(), refEntity.getValue());
}
break;
default:
break;
}
}
return importedRefs;
}
use of javax.xml.stream.events.Attribute in project Payara by payara.
the class DomainXmlTransformer method getReplaceAttributeInStartEvent.
/**
* Create a new start element based on the original but that replaces attribute value
*/
private StartElement getReplaceAttributeInStartEvent(XMLEvent event, String attr_name, String attr_value) {
Set attributes = new HashSet();
for (java.util.Iterator i = event.asStartElement().getAttributes(); i.hasNext(); ) {
Attribute a = (Attribute) i.next();
if (!a.getName().getLocalPart().equals(attr_name)) {
attributes.add(a);
}
}
Attribute newAttribute = xmlEventFactory.createAttribute(attr_name, attr_value);
attributes.add(newAttribute);
StartElement oldStartEvent = event.asStartElement();
return xmlEventFactory.createStartElement(oldStartEvent.getName(), attributes.iterator(), oldStartEvent.getNamespaces());
}
use of javax.xml.stream.events.Attribute in project Payara by payara.
the class DomainXmlTransformer method getSkippedElementStartEvent.
/**
* Create a new start element based on the original but that does not include
* the specified attribute.
*/
private StartElement getSkippedElementStartEvent(XMLEvent event) {
Set attributes = new HashSet();
for (java.util.Iterator i = event.asStartElement().getAttributes(); i.hasNext(); ) {
Attribute a = (Attribute) i.next();
if (!DISABLE_SUB_ELEMENTS.contains(a.getName().getLocalPart())) {
attributes.add(a);
}
}
StartElement oldStartEvent = event.asStartElement();
return xmlEventFactory.createStartElement(oldStartEvent.getName(), attributes.iterator(), oldStartEvent.getNamespaces());
}
Aggregations