protected boolean isNamespaceDeclaration(QName qName) { String prefix = qName.getPrefix(); String localPart = qName.getLocalPart(); return (XMLConstants.XMLNS_ATTRIBUTE.equals(localPart) && prefix.isEmpty()) || (XMLConstants.XMLNS_ATTRIBUTE.equals(prefix) && !localPart.isEmpty()); }
@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)); } } }
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 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; } }
@Test public void testCascadeDeleteWorkspaceSpecific() throws Exception { Catalog catalog = getCatalog(); WorkspaceInfo ws = catalog.getWorkspaceByName(MockData.ROAD_SEGMENTS.getPrefix()); StyleInfo style = catalog.getStyleByName(MockData.ROAD_SEGMENTS.getLocalPart()); style.setWorkspace(ws); catalog.save(style);
@Test public void testGenericStyle() throws Exception { Catalog cat = getCatalog(); CatalogBuilder cb = new CatalogBuilder(cat); cb.setStore(cat.getDataStoreByName(MockData.GENERICENTITY.getPrefix())); FeatureTypeInfo fti = cb.buildFeatureType(toName(MockData.GENERICENTITY)); LayerInfo li = cb.buildLayer(fti); // check we assigned the generic style assertEquals("generic", li.getDefaultStyle().getName()); }
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 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)); } } }
@Test public void testGML32() throws Exception { Document dom = getAsDOM( "wfs?request=getfeature&version=2.0.0&outputFormat=gml32&typename=" + MockData.BASIC_POLYGONS.getPrefix() + ":" + MockData.BASIC_POLYGONS.getLocalPart()); assertEquals(WFS.NAMESPACE, dom.getDocumentElement().getNamespaceURI()); assertEquals("FeatureCollection", dom.getDocumentElement().getLocalName()); }
@Test public void testGetBoundsFromCRS() throws Exception { Catalog cat = getCatalog(); CatalogBuilder cb = new CatalogBuilder(cat); cb.setStore(cat.getDataStoreByName(MockData.LINES.getPrefix())); FeatureTypeInfo fti = cb.buildFeatureType(toName(MockData.LINES)); CoordinateReferenceSystem resourceCRS = fti.getCRS(); assertNotNull(resourceCRS); // make sure the srs is as expected, otherwise the rest of the tests don't make sense assertEquals("EPSG:32615", fti.getSRS()); ReferencedEnvelope crsBounds = cb.getBoundsFromCRS(fti); assertNotNull(crsBounds); CoordinateReferenceSystem exptectedCRS = CRS.decode("EPSG:32615"); assertEquals(new ReferencedEnvelope(CRS.getEnvelope(exptectedCRS)), crsBounds); // if we change the srs when there's no reproject policy, should still be the same bounding // box fti.setSRS("EPSG:4326"); fti.setProjectionPolicy(ProjectionPolicy.NONE); crsBounds = cb.getBoundsFromCRS(fti); assertEquals(new ReferencedEnvelope(CRS.getEnvelope(exptectedCRS)), crsBounds); // if we use reproject policy, bounds should now be different fti.setProjectionPolicy(ProjectionPolicy.FORCE_DECLARED); crsBounds = cb.getBoundsFromCRS(fti); assertNotEquals(new ReferencedEnvelope(CRS.getEnvelope(exptectedCRS)), crsBounds); // should now be 4326 bounds CoordinateReferenceSystem crs4326 = CRS.decode("EPSG:4326"); assertEquals(new ReferencedEnvelope(CRS.getEnvelope(crs4326)), crsBounds); fti.setProjectionPolicy(ProjectionPolicy.REPROJECT_TO_DECLARED); assertEquals(new ReferencedEnvelope(CRS.getEnvelope(crs4326)), crsBounds); }
/** 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>(); }
@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)); } } }
/** * 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 public void declareNamespace(QName v, XMLSerializer w) { w.getNamespaceContext().declareNamespace(v.getNamespaceURI(),v.getPrefix(),false); } });
for (Iterator i = event.getAttributes(); i.hasNext();) { Attribute staxAttr = (Attribute)i.next(); String uri = fixNull(name.getNamespaceURI()); String localName = name.getLocalPart(); String prefix = name.getPrefix(); String qName; if (prefix == null || prefix.length() == 0)
@Test public void testGML3CoordinatesFormatting() throws Exception { enableCoordinatesFormatting(); Document dom = getAsDOM( "wfs?request=getfeature&version=1.0.0&outputFormat=gml3&typename=" + MockData.BASIC_POLYGONS.getPrefix() + ":" + MockData.BASIC_POLYGONS.getLocalPart()); assertEquals( "-1.0000 0.0000 0.0000 1.0000 1.0000 0.0000 0.0000 -1.0000 -1.0000 0.0000", dom.getElementsByTagName("gml:posList").item(0).getTextContent()); }
@Test public void testFeatureType() throws Exception { // build a feature type (it's already in the catalog, but we just want to // check it's built as expected // LINES is a feature type with a native SRS, so we want the bounds to be there Catalog cat = getCatalog(); CatalogBuilder cb = new CatalogBuilder(cat); cb.setStore(cat.getDataStoreByName(MockData.LINES.getPrefix())); FeatureTypeInfo fti = cb.buildFeatureType(toName(MockData.LINES)); // perform basic checks assertEquals("EPSG:32615", fti.getSRS()); assertEquals(CRS.decode("EPSG:32615", true), fti.getCRS()); assertNull(fti.getNativeBoundingBox()); assertNull(fti.getLatLonBoundingBox()); // force bounds computation cb.setupBounds(fti); assertNotNull(fti.getNativeBoundingBox()); assertNotNull(fti.getNativeBoundingBox().getCoordinateReferenceSystem()); assertNotNull(fti.getLatLonBoundingBox()); }
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; }
public void startNode(String name) { try { QName qname = qnameMap.getQName(encodeNode(name)); String prefix = qname.getPrefix(); String uri = qname.getNamespaceURI(); out.writeStartElement(prefix, qname.getLocalPart(), uri); if (hasPrefix) { out.setPrefix(prefix, uri);
protected boolean isNamespaceDeclaration(QName qName) { String prefix = qName.getPrefix(); String localPart = qName.getLocalPart(); return (XMLConstants.XMLNS_ATTRIBUTE.equals(localPart) && prefix.isEmpty()) || (XMLConstants.XMLNS_ATTRIBUTE.equals(prefix) && !localPart.isEmpty()); }