@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; } }
@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 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();
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 void applyBatchUpdates( QName remoteTypeName, WFSDiff diff, TransactionRequest transactionRequest) { List<BatchUpdate> batchUpdates = diff.getBatchUpdates(); for (BatchUpdate batch : batchUpdates) { List<QName> propertyNames = new ArrayList<QName>(batch.properties.length); for (Name attName : batch.properties) { propertyNames.add( new QName(remoteTypeName.getNamespaceURI(), attName.getLocalPart())); } List<Object> newValues = Arrays.asList(batch.values); Filter updateFilter = batch.filter; Update update = transactionRequest.createUpdate( remoteTypeName, propertyNames, newValues, updateFilter); transactionRequest.add(update); } }
@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; }
@Override public void childElement(UnmarshallingContext.State state, TagName arg) throws SAXException { ChildLoader child = childUnmarshallers.get(arg.uri,arg.local); if(child == null) { Boolean backupWithParentNamespace = ((JAXBContextImpl) state.getContext().getJAXBContext()).backupWithParentNamespace; backupWithParentNamespace = backupWithParentNamespace != null ? backupWithParentNamespace : Boolean.parseBoolean(Util.getSystemProperty(JAXBRIContext.BACKUP_WITH_PARENT_NAMESPACE)); if ((beanInfo != null) && (beanInfo.getTypeNames() != null) && backupWithParentNamespace) { Iterator<?> typeNamesIt = beanInfo.getTypeNames().iterator(); QName parentQName = null; if ((typeNamesIt != null) && (typeNamesIt.hasNext()) && (catchAll == null)) { parentQName = (QName) typeNamesIt.next(); String parentUri = parentQName.getNamespaceURI(); child = childUnmarshallers.get(parentUri, arg.local); } } if (child == null) { child = catchAll; if(child==null) { super.childElement(state,arg); return; } } } state.setLoader(child.loader); state.setReceiver(child.receiver); }
@Override protected void write(OutputStream out) throws IOException { XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS); xmlOptions.setSaveSyntheticDocumentElement( new QName(CTChartsheet.type.getName().getNamespaceURI(), "chartsheet")); chartsheet.save(out, xmlOptions); }
public void attWildcardAsURIs(Map<QName,String> attributes, String fieldName) { if(attributes==null) return; for( Map.Entry<QName,String> e : attributes.entrySet() ) { QName n = e.getKey(); String nsUri = n.getNamespaceURI(); if(nsUri.length()>0) { String p = n.getPrefix(); if(p.length()==0) p=null; nsContext.declareNsUri(nsUri, p, true); } } }
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)); } } }
/** Keys for overriding default layer properties */ public static class StyleProperty<T> { T get(Map<StyleProperty, Object> map, T def) { return map != null && map.containsKey(this) ? (T) map.get(this) : def; } public static StyleProperty<String> FORMAT = new StyleProperty<String>(); public static StyleProperty<Version> FORMAT_VERSION = new StyleProperty<Version>(); public static StyleProperty<LegendInfo> LEGEND_INFO = new StyleProperty<LegendInfo>(); }
private void applySingleUpdate( QName remoteTypeName, SimpleFeature feature, TransactionRequest transactionRequest) throws IOException { // so bad, this is going to update a lot of unnecessary properties. We'd need to make // DiffContentFeatureWriter's live and current attributes protected and extend write so that // it records the truly modified attributes instead Collection<Property> properties = feature.getProperties(); List<QName> propertyNames = new ArrayList<QName>(); List<Object> newValues = new ArrayList<Object>(); for (Property p : properties) { QName attName = new QName(remoteTypeName.getNamespaceURI(), p.getName().getLocalPart()); Object attValue = p.getValue(); propertyNames.add(attName); newValues.add(attValue); } Filter updateFilter = dataStore.getFilterFactory().id(Collections.singleton(feature.getIdentifier())); Update update = transactionRequest.createUpdate( remoteTypeName, propertyNames, newValues, updateFilter); transactionRequest.add(update); }
@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; }
/** * Computes the type name of the array from that of the item type. */ public static QName calcArrayTypeName(QName n) { String uri; if(n.getNamespaceURI().equals(WellKnownNamespace.XML_SCHEMA)) { TODO.checkSpec("this URI"); uri = "http://jaxb.dev.java.net/array"; } else uri = n.getNamespaceURI(); return new QName(uri,n.getLocalPart()+"Array"); } }
@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)); } } }
@Override protected void commit() throws IOException { if (ctSettings == null) { throw new IllegalStateException("Unable to write out settings that were never read in!"); } XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS); xmlOptions.setSaveSyntheticDocumentElement(new QName(CTSettings.type.getName().getNamespaceURI(), "settings")); PackagePart part = getPackagePart(); OutputStream out = part.getOutputStream(); ctSettings.save(out, xmlOptions); out.close(); }
public static String _printQName(QName val, NamespaceContext nsc) { // Double-check String qname; String prefix = nsc.getPrefix(val.getNamespaceURI()); String localPart = val.getLocalPart(); if (prefix == null || prefix.length() == 0) { // be defensive qname = localPart; } else { qname = prefix + ':' + localPart; } return qname; }
@Override public void declareNamespace(QName v, XMLSerializer w) { w.getNamespaceContext().declareNamespace(v.getNamespaceURI(),v.getPrefix(),false); } });
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)); } } }