/** * Convert a {@code QName} to a qualified name, as used by DOM and SAX. * The returned string has a format of {@code prefix:localName} if the * prefix is set, or just {@code localName} if not. * @param qName the {@code QName} * @return the qualified name */ protected String toQualifiedName(QName qName) { String prefix = qName.getPrefix(); if (!StringUtils.hasLength(prefix)) { return qName.getLocalPart(); } else { return prefix + ":" + qName.getLocalPart(); } }
@Override protected void startElementInternal(QName name, Attributes attributes, Map<String, String> namespaceMapping) throws XMLStreamException { this.streamWriter.writeStartElement(name.getPrefix(), name.getLocalPart(), name.getNamespaceURI()); for (Map.Entry<String, String> entry : namespaceMapping.entrySet()) { String prefix = entry.getKey(); String namespaceUri = entry.getValue(); this.streamWriter.writeNamespace(prefix, namespaceUri); if (XMLConstants.DEFAULT_NS_PREFIX.equals(prefix)) { this.streamWriter.setDefaultNamespace(namespaceUri); } else { this.streamWriter.setPrefix(prefix, namespaceUri); } } for (int i = 0; i < attributes.getLength(); i++) { QName attrName = toQName(attributes.getURI(i), attributes.getQName(i)); if (!isNamespaceDeclaration(attrName)) { this.streamWriter.writeAttribute(attrName.getPrefix(), attrName.getNamespaceURI(), attrName.getLocalPart(), attributes.getValue(i)); } } }
static Element of(QName qName) { QName name; if (qName.getNamespaceURI().equals("")) { name = new QName(NAMESPACE_1_0, qName.getLocalPart()); } else { name = qName; } final Element element = elements.get(name); return element == null ? UNKNOWN : element; } }
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 = ""; 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 StartElement withNamespace(StartElement startElement) { // otherwise, wrap the start element event to provide a default namespace mapping final List<Namespace> namespaces = new ArrayList<Namespace>(); namespaces.add( xmlEventFactory.createNamespace( "", namespaceUri ) ); Iterator<?> originalNamespaces = startElement.getNamespaces(); while ( originalNamespaces.hasNext() ) { namespaces.add( (Namespace) originalNamespaces.next() ); } return xmlEventFactory.createStartElement( new QName( namespaceUri, startElement.getName().getLocalPart() ), startElement.getAttributes(), namespaces.iterator() ); }
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; } }
@Override public Collection<GeometryOperand> getGeometryOperands() { List<GeometryOperand> geometryOperands = new ArrayList<GeometryOperand>(); if (getGeometryOperands2() != null) { for (GeometryOperandType go : getGeometryOperands2().getGeometryOperand()) { geometryOperands.add(GeometryOperand.get(go.getName().getNamespaceURI(), go.getName().getLocalPart())); } } return geometryOperands; }
private Coordinate[] parseLineStringInternal(int dimension, CoordinateReferenceSystem crs) throws XmlPullParserException, IOException { final QName lineElementName = new QName(parser.getNamespace(), parser.getName()); final QName coordsName = new QName(parser.getNamespace(), parser.getName()); String tagName = parser.getName(); if (GML.pos.equals(coordsName)) { do { point = parseCoordList(dimension, crs); coords.add(point[0]); parser.nextTag(); tagName = parser.getName(); eventType = parser.getEventType(); } while (eventType == START_TAG && GML.pos.getLocalPart().equals(tagName)); do { point = parseCoord(); coords.add(point); parser.nextTag(); tagName = parser.getName(); eventType = parser.getEventType(); } while (eventType == START_TAG && GML.coord.getLocalPart().equals(tagName)); "Expected posList or pos inside LinearRing: " + tagName); parser.require(END_TAG, lineElementName.getNamespaceURI(), lineElementName.getLocalPart()); return lineCoords;
Catalog catalog) throws IOException { String prefix = qName.getPrefix(); String name = qName.getLocalPart(); String uri = qName.getNamespaceURI(); featureType.getKeywords().add(new Keyword(name)); featureType.setEnabled(true); featureType.setProjectionPolicy(
@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("{ NAME=> '"); sb.append(name); sb.append('\''); for (Map.Entry<QName,Object> e: attrs.entrySet()) { sb.append(", "); sb.append(e.getKey().getLocalPart()); sb.append(" => '"); sb.append(e.getValue().toString()); sb.append('\''); } sb.append(", COLUMNS => [ "); Iterator<ColumnSchemaModel> i = columns.iterator(); while (i.hasNext()) { ColumnSchemaModel family = i.next(); sb.append(family.toString()); if (i.hasNext()) { sb.append(','); } sb.append(' '); } sb.append("] }"); return sb.toString(); }
void setFieldInSObject( SObject sobjPass, XmlObject element ) { Iterator<XmlObject> children = element.getChildren(); String name = element.getName().getLocalPart(); if ( !children.hasNext() ) { sobjPass.setSObjectField( name, element.getValue() ); } else { SObject child = new SObject(); child.setName( new QName( name ) ); while ( children.hasNext() ) { setFieldInSObject( child, children.next() ); } sobjPass.setSObjectField( name, child ); } }
public TypeReference(QName tagName, Type type, Annotation... annotations) { if(tagName==null || type==null || annotations==null) { String nullArgs = ""; if(tagName == null) nullArgs = "tagName"; if(type == null) nullArgs += (nullArgs.length() > 0 ? ", type" : "type"); if(annotations == null) nullArgs += (nullArgs.length() > 0 ? ", annotations" : "annotations"); Messages.ARGUMENT_CANT_BE_NULL.format(nullArgs); throw new IllegalArgumentException(Messages.ARGUMENT_CANT_BE_NULL.format(nullArgs)); } this.tagName = new QName(tagName.getNamespaceURI().intern(), tagName.getLocalPart().intern(), tagName.getPrefix()); this.type = type; this.annotations = annotations; }
private StartElement transform(StartElement startElement) { String elementName = startElement.getName().getLocalPart(); // use the start element to determine whether we have a persistence.xml or orm.xml if ( START_ELEMENT_TO_NAMESPACE_URI.containsKey( elementName ) ) { currentDocumentNamespaceUri = START_ELEMENT_TO_NAMESPACE_URI.get( elementName ); } List<Attribute> newElementAttributeList = updateElementAttributes( startElement ); List<Namespace> newNamespaceList = updateElementNamespaces( startElement ); // create the new element return xmlEventFactory.createStartElement( new QName( currentDocumentNamespaceUri, startElement.getName().getLocalPart() ), newElementAttributeList.iterator(), newNamespaceList.iterator() ); }
@Override @Nullable public String getAttributeValue(@Nullable String namespaceURI, String localName) { for (int i = 0; i < getAttributeCount(); i++) { QName name = getAttributeName(i); if (name.getLocalPart().equals(localName) && (namespaceURI == null || name.getNamespaceURI().equals(namespaceURI))) { return getAttributeValue(i); } } return null; }
private void handleEndElement(EndElement endElement) throws SAXException { if (getContentHandler() != null) { QName qName = endElement.getName(); if (hasNamespacesFeature()) { getContentHandler().endElement(qName.getNamespaceURI(), qName.getLocalPart(), toQualifiedName(qName)); for (Iterator i = endElement.getNamespaces(); i.hasNext();) { Namespace namespace = (Namespace) i.next(); endPrefixMapping(namespace.getPrefix()); } } else { getContentHandler().endElement("", "", toQualifiedName(qName)); } } }
final List<Namespace> targetNamespaces = new ArrayList<Namespace>(); if ( "".equals( startElement.getName().getNamespaceURI() ) ) { targetNamespaces.add( xmlEventFactory.createNamespace( MappingXsdSupport.INSTANCE.hbmXsd().getNamespaceUri() ) ); while ( originalNamespaces.hasNext() ) { Namespace namespace = originalNamespaces.next(); if ( NAMESPACE_URIS_TO_MAP.contains( namespace.getNamespaceURI() ) ) { targetNamespaces.add( namespace ); new QName( MappingXsdSupport.INSTANCE.hbmXsd().getNamespaceUri(), startElement.getName().getLocalPart() ), startElement.getAttributes(), targetNamespaces.iterator() );
@Override public Collection<GeometryOperand> getGeometryOperands() { List<GeometryOperand> geometryOperands = new ArrayList<GeometryOperand>(); if (getGeometryOperands2() != null) { for (GeometryOperandType go : getGeometryOperands2().getGeometryOperand()) { geometryOperands.add(GeometryOperand.get(go.getName().getNamespaceURI(), go.getName().getLocalPart())); } } return geometryOperands; }
private Coordinate[] parseLineStringInternal(int dimension, CoordinateReferenceSystem crs) throws XmlPullParserException, IOException { final QName lineElementName = new QName(parser.getNamespace(), parser.getName()); final QName coordsName = new QName(parser.getNamespace(), parser.getName()); String tagName = parser.getName(); if (GML.pos.equals(coordsName)) { do { point = parseCoordList(dimension); coords.add(point[0]); parser.nextTag(); tagName = parser.getName(); eventType = parser.getEventType(); } while (eventType == START_TAG && tagName == GML.pos.getLocalPart()); do { point = parseCoord(); coords.add(point); parser.nextTag(); tagName = parser.getName(); eventType = parser.getEventType(); } while (eventType == START_TAG && GML.coord.getLocalPart().equals(tagName)); "Expected posList or pos inside LinearRing: " + tagName); parser.require(END_TAG, lineElementName.getNamespaceURI(), lineElementName.getLocalPart()); return lineCoords;
if (filter.includeElement(depth, qn.getLocalPart(), Namespace.getNamespace(qn.getPrefix(), qn.getNamespaceURI()))) { ret.add(processPrunableElement(factory, stream, depth, filter)); } else { final int back = depth; ret.add(DTDParser.parse(stream.getText(), factory)); ret.add(factory.cdata(text));
for ( Iterator<WsdlOperation> itr = listeOperations.iterator(); itr.hasNext(); ) { WsdlOperation op = itr.next(); wOperation.add( op.getOperationQName().getLocalPart() ); if ( op.getOperationQName().getLocalPart().equals( text ) ) { wOperation.setText( text );