use of javax.xml.stream.events.Namespace in project hibernate-orm by hibernate.
the class JpaNamespaceTransformingEventReader method updateElementNamespaces.
private List<Namespace> updateElementNamespaces(StartElement startElement) {
List<Namespace> newNamespaceList = new ArrayList<Namespace>();
Iterator<?> existingNamespaceIterator = startElement.getNamespaces();
while (existingNamespaceIterator.hasNext()) {
Namespace namespace = (Namespace) existingNamespaceIterator.next();
if (NAMESPACE_MAPPING.containsKey(namespace.getNamespaceURI())) {
newNamespaceList.add(xmlEventFactory.createNamespace(EMPTY_PREFIX, currentDocumentNamespaceUri));
} else {
newNamespaceList.add(namespace);
}
}
// if there is no namespace at all we add the main one. All elements need the namespace
if (newNamespaceList.isEmpty()) {
newNamespaceList.add(xmlEventFactory.createNamespace(EMPTY_PREFIX, currentDocumentNamespaceUri));
}
return newNamespaceList;
}
use of javax.xml.stream.events.Namespace 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.Namespace 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.Namespace in project spring-framework by spring-projects.
the class XMLEventStreamReader method getNamespace.
@SuppressWarnings("rawtypes")
private Namespace getNamespace(int index) {
Iterator namespaces;
if (this.event.isStartElement()) {
namespaces = this.event.asStartElement().getNamespaces();
} else if (this.event.isEndElement()) {
namespaces = this.event.asEndElement().getNamespaces();
} else {
throw new IllegalStateException();
}
int count = 0;
while (namespaces.hasNext()) {
Namespace namespace = (Namespace) namespaces.next();
if (count == index) {
return namespace;
} else {
count++;
}
}
throw new IllegalArgumentException();
}
use of javax.xml.stream.events.Namespace in project spring-framework by spring-projects.
the class XMLEventStreamWriter method doWriteNamespace.
@SuppressWarnings("rawtypes")
private void doWriteNamespace(Namespace namespace) throws XMLStreamException {
int last = this.endElements.size() - 1;
EndElement oldEndElement = this.endElements.get(last);
Iterator oldNamespaces = oldEndElement.getNamespaces();
List<Namespace> newNamespaces = new ArrayList<>();
while (oldNamespaces.hasNext()) {
Namespace oldNamespace = (Namespace) oldNamespaces.next();
newNamespaces.add(oldNamespace);
}
newNamespaces.add(namespace);
EndElement newEndElement = this.eventFactory.createEndElement(oldEndElement.getName(), newNamespaces.iterator());
this.eventWriter.add(namespace);
this.endElements.set(last, newEndElement);
}
Aggregations