/** * Returns a single-line string containing the xml representation of the given filter, as * appropriate for the {@code FILTER} parameter in a GetFeature request. */ protected String encodeGetFeatureGetFilter(final Filter filter) throws IOException { Configuration filterConfig = getFilterConfiguration(); Encoder encoder = new Encoder(filterConfig); // do not write the xml declaration encoder.setOmitXMLDeclaration(true); encoder.setEncoding(Charset.forName("UTF-8")); OutputStream out = new ByteArrayOutputStream(); encoder.encode(filter, OGC.Filter, out); String encoded = out.toString(); encoded = encoded.replaceAll("\n", ""); return encoded; }
@Override protected void configureEncoder( Encoder encoder, String elementName, Class<?> xmlConfiguration) { encoder.setNamespaceAware(true); encoder.getNamespaces().declarePrefix("ows", OWS.NAMESPACE); encoder.getNamespaces().declarePrefix("ogc", OGC.NAMESPACE); encoder.getNamespaces().declarePrefix("gml", "http://www.opengis.net/gml"); encoder.getNamespaces().declarePrefix("gmd", "http://www.isotc211.org/2005/gmd"); encoder.getNamespaces().declarePrefix("xlink", XLINK.NAMESPACE); } }
protected void encode(FeatureCollectionResponse hits, OutputStream output, WFSInfo wfs) throws IOException { Encoder encoder = new Encoder(configuration, configuration.schema()); encoder.setEncoding(Charset.forName(wfs.getGeoServer().getSettings().getCharset())); encoder.setSchemaLocation( org.geoserver.wfs.xml.v1_1_0.WFS.NAMESPACE, ResponseUtils.appendPath(wfs.getSchemaBaseURL(), "wfs/1.1.0/wfs.xsd")); encoder.encode( hits.getAdaptee(), org.geoserver.wfs.xml.v1_1_0.WFS.FEATURECOLLECTION, output); } }
private void encodeGmlRssGeometry(Geometry g) { try { // get the proper element name QName elementName = null; if (g instanceof Polygon) { elementName = org.geotools.gml2.GML.Polygon; } else if (g instanceof MultiPoint) { elementName = org.geotools.gml2.GML.MultiPoint; } else { elementName = org.geotools.gml2.GML._Geometry; } // encode in GML3 Encoder encoder = new Encoder(GML_CONFIGURATION); encoder.setInline(true); encoder.setIndenting(true); encoder.encode(g, elementName, contentHandler); } catch (Exception e) { throw new RuntimeException("Cannot transform the specified geometry in GML", e); } }
new NameImpl(name.getNamespaceURI(), name.getLocalPart()); ResourceInfo meta = catalog.getResourceByName(featureTypeName, ResourceInfo.class); Encoder encoder = createEncoder(configuration, ns2metas, gft); encoder.setEncoding(Charset.forName(geoServer.getSettings().getCharset())); Request dispatcherRequest = Dispatcher.REQUEST.get(); if (dispatcherRequest != null) { encoder.setOmitXMLDeclaration(dispatcherRequest.isSOAP()); encoder.setSchemaLocation(getWfsNamespace(), getCanonicalWfsSchemaLocation()); } else { encoder.setSchemaLocation( getWfsNamespace(), buildSchemaURL(request.getBaseURL(), getRelativeWfsSchemaLocation())); Map<String, String> schemaURIs = (Map<String, String>) userSchemaLocation; for (String namespace : schemaURIs.keySet()) { encoder.setSchemaLocation(namespace, schemaURIs.get(namespace)); encoder.getNamespaces() .declarePrefix(ri.getStore().getWorkspace().getName(), namespaceURI); + ". Using a built schema location by default: " + schemaLocation); encoder.setSchemaLocation(namespaceURI, schemaLocation);
Charset charset = getConfig().getDefaultEncoding(); if (null == charset) { charset = Charset.forName("UTF-8"); Encoder encoder = new Encoder(configuration); encoder.setEncoding(charset); encoder.setIndentSize(1); for (QName typeName : typeNames) { String prefix = typeName.getPrefix(); String namespaceURI = typeName.getNamespaceURI(); encoder.getNamespaces().declarePrefix(prefix, namespaceURI);
void write1_1(LockFeatureResponseType lockResponse, OutputStream output, Operation operation) throws IOException { Encoder encoder = new Encoder(configuration, configuration.schema()); encoder.setEncoding(Charset.forName(getInfo().getGeoServer().getSettings().getCharset())); LockFeatureType req = (LockFeatureType) operation.getParameters()[0]; encoder.setSchemaLocation( org.geoserver.wfs.xml.v1_1_0.WFS.NAMESPACE, buildSchemaURL(req.getBaseUrl(), "schemas/wfs/1.1.0/wfs.xsd")); encoder.encode(lockResponse, org.geoserver.wfs.xml.v1_1_0.WFS.LOCKFEATURERESPONSE, output); output.flush(); } }
/** * Returns a single-line string containing the xml representation of the given filter, as * appropriate for the {@code FILTER} parameter in a GetFeature request. */ protected String encodeGetFeatureGetFilter(final Filter filter) throws IOException { final Configuration filterConfig = getFilterConfiguration(); final QName encName; if (filterConfig instanceof org.geotools.filter.v1_0.OGCConfiguration || filterConfig instanceof org.geotools.filter.v1_1.OGCConfiguration) { encName = org.geotools.filter.v1_0.OGC.Filter; } else { encName = org.geotools.filter.v2_0.FES.Filter; } Encoder encoder = new Encoder(filterConfig); // do not write the xml declaration encoder.setOmitXMLDeclaration(true); encoder.setEncoding(Charset.forName("UTF-8")); String encoded = encoder.encodeAsString(filter, encName); encoded = encoded.replaceAll("\n", ""); return encoded; }
serializer.endPrefixMapping(pre); namespaces.declarePrefix((pre != null) ? pre : "", ns); if (namespaces.getURI("") == null) { namespaces.declarePrefix("", schema.getTargetNamespace()); root.setName(name.getLocalPart()); root.setTargetNamespace(name.getNamespaceURI()); root.setTypeDefinition(type); end(entry.encoding); encoded.pop(); Binding binding = bindingLoader.loadBinding(new QName( e.getTargetNamespace(), e.getName()), context); entry.encoding = (Element) encode(entry.object, entry.element); Attr attr = (Attr) encode(executor.getChildObject(), attribute); start(entry.encoding); && (COMMENT.getNamespaceURI().equals(child.getTargetNamespace())) && COMMENT.getLocalPart().equals(child.getName())) { comment(child.getElement());
@Override public void write(Object value, OutputStream output, Operation operation) throws IOException, ServiceException { Encoder encoder = new Encoder(new WFSConfiguration()); encoder.setEncoding(Charset.forName(getInfo().getGeoServer().getSettings().getCharset())); encoder.setOmitXMLDeclaration(Dispatcher.REQUEST.get().isSOAP()); String baseURL = (String) EMFUtils.get((EObject) operation.getParameters()[0], "baseUrl"); encoder.setSchemaLocation(WFS.NAMESPACE, buildSchemaURL(baseURL, "wfs/2.0/wfs.xsd")); encode(encoder, value, output, operation); }
@Override protected void encode(FeatureCollectionResponse hits, OutputStream output, WFSInfo wfs) throws IOException { hits.setNumberOfFeatures(BigInteger.ZERO); // instantiate the XML encoder Encoder encoder = new Encoder(new WFSConfiguration()); encoder.setEncoding(Charset.forName(wfs.getGeoServer().getSettings().getCharset())); encoder.setSchemaLocation( WFS.NAMESPACE, ResponseUtils.appendPath(wfs.getSchemaBaseURL(), "wfs/2.0/wfs.xsd")); Document document; try { // encode the HITS result using FeatureCollection as the root XML element document = encoder.encodeAsDOM(hits.getAdaptee(), WFS.FeatureCollection); } catch (Exception exception) { throw new RuntimeException("Error encoding INDEX result.", exception); } // add the resultSetID attribute to the result addResultSetIdElement(document, resultSetId); // write the XML document to response output stream writeDocument(document, output); }
Name featureTypeName = new NameImpl(typeName.getNamespaceURI(), typeName.getLocalPart()); FeatureTypeInfo ftInfo = catalog.getFeatureTypeByName(featureTypeName); if (ftInfo != null) { NamespaceInfo ns = catalog.getNamespaceByURI(typeName.getNamespaceURI()); encoder.getNamespaces().declarePrefix(ns.getPrefix(), ns.getURI()); } else { if (encoder.getNamespaces().getURI(nameSpaceinfo.getPrefix()) == null) { encoder.getNamespaces() .declarePrefix(nameSpaceinfo.getPrefix(), nameSpaceinfo.getURI()); encoder.encode(value, WFS.ValueCollection, output);
serializer.endPrefixMapping(pre); namespaces.declarePrefix( pre != null ? pre : "" , ns ); if ( namespaces.getURI( "" ) == null ) { namespaces.declarePrefix( "", schema.getTargetNamespace() ); end(entry.encoding); encoded.pop(); new QName( e.getTargetNamespace(), e.getName() ), context ); if ( binding == null ) { new QName( type.getTargetNamespace(), type.getName() ), context ); entry.encoding = (Element) encode(entry.object,entry.element); Attr attr = (Attr) encode(executor.getChildObject(),attribute); if (attr != null) { entry.encoding.setAttributeNodeNS(attr); start(entry.encoding);
.append(qName.getPrefix()) .append(":") .append(qName.getLocalPart()) .append(","); Encoder e = new Encoder(new FESConfiguration()); e.setOmitXMLDeclaration(true); filter.append(e.encodeAsString(q.getFilter(), FES.Filter)); } catch (Exception e) { throw new RuntimeException("Unable to encode filter " + f, e);
encoder = new org.geotools.xml.Encoder(configuration ); encoder.setNamespaceAware(true); encoder.setSchemaLocation("http://www.opengis.net/gml", "http://schemas.opengis.net/gml/3.1.1/base/feature.xsd"); ((org.geotools.gml3.ApplicationSchemaConfiguration)configuration).getDependency(org.geotools.gml3.GMLConfiguration.class).setSrsSyntax(srsSyntax); encoder = new org.geotools.xml.Encoder(configuration ); encoder.setNamespaceAware(true); encoder.setSchemaLocation("http://www.opengis.net/gml http://schemas.opengis.net/gml/3.1.1/base/feature.xsd", namespace + " " + schemaLocation); QName ns = new QName("http://www.opengis.net/gml","FeatureCollection","wfs"); try{ encoder.encode(correctFeatureCollection, ns, os); }catch(IOException e){ LOGGER.error("Exception while trying to encode FeatureCollection.", e);
@Override protected void encode(Encoder encoder, Object value, OutputStream output, Operation op) throws IOException, ServiceException { // check the returned types, they are qnames and we need to declare their prefixes ListStoredQueriesResponseType response = (ListStoredQueriesResponseType) value; for (StoredQueryListItemType sq : response.getStoredQuery()) { if (sq.getReturnFeatureType() != null) { for (QName qName : sq.getReturnFeatureType()) { if (qName.getNamespaceURI() != null && qName.getPrefix() != null) { encoder.getNamespaces() .declarePrefix(qName.getPrefix(), qName.getNamespaceURI()); } } } } encoder.encode(value, WFS.ListStoredQueriesResponse, output); } }
final QName typeName = new QName(schema.getNamespace().getAuthority(), schema.getTypeName()); final Set deletedIds = new HashSet(); final PropertyType property = WfsFactory.eINSTANCE.createPropertyType(); String name = (String) it.next(); property.setName(new QName(name)); property.setValue(f.getAttribute(name)); properties.add(property); Encoder encoder = new Encoder(configuration, configuration.schema()); encoder.setSchemaLocation(org.geoserver.wfs.xml.v1_1_0.WFS.NAMESPACE, ResponseUtils.appendPath(wfs.getSchemaBaseURL(), "wfs/1.1.0/wfs.xsd")); encoder.setOutputFormat(format); encoder.setSchemaLocation(namespaceURI, ResponseUtils.appendQueryString(wfs.getOnlineResource().toString(), "service=WFS&version=1.1.0&request=DescribeFeatureType&typeName=" + typeNames.toString())); encoder.encode(transaction, org.geoserver.wfs.xml.v1_1_0.WFS.TRANSACTION, output); } catch (SAXException e) {
GetFeatureType serverRequest = reqParts.getServerRequest(); Encoder encoder = new Encoder(strategy.getWfsConfiguration()); String prefix = fullName.getPrefix(); String namespace = fullName.getNamespaceURI(); if (!XMLConstants.DEFAULT_NS_PREFIX.equals(prefix)) { encoder.getNamespaces().declarePrefix(prefix, namespace);
@Override public void encode(Object object, ContentHandler handler) throws Exception { FeatureCollection features = (FeatureCollection) object; SimpleFeatureType featureType = (SimpleFeatureType) features.getSchema(); FeatureCollectionType fc = WfsFactory.eINSTANCE.createFeatureCollectionType(); fc.getFeature().add(features); Encoder e = new Encoder(configuration); e.getNamespaces().declarePrefix("feature", featureType.getName().getNamespaceURI()); e.encode(fc, getElement(), handler); }