org.geotools.xml.Encoder类的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(14.0k)|赞(0)|评价(0)|浏览(176)

本文整理了Java中org.geotools.xml.Encoder类的一些代码示例,展示了Encoder类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Encoder类的具体详情如下:
包路径:org.geotools.xml.Encoder
类名称:Encoder

Encoder介绍

[英]Encodes objects as xml based on a schema.

The function of the encoder is to traverse a tree of objects seializing them out as xml as it goes. Navigation and serialization of the tree is performed by instances of org.geotools.xml.Binding which are bound to types in the schema.

To execute the encoder, one must have 3 bits of information:

  1. The root object in the tree to be encoded
  2. The schema / configuration of the intsance document being encoded.
  3. A name of the element defined in the schema which corresponds to the root object in the tree.

As an exmaple, consider the encoding of a org.opengis.filter.Filterinstance.

//instantiate hte configuration for the filter schmea 
Configuration configuration = new OGCConfiguration(); 
//create the encoder 
Encoder encoder = new Encoder( configuration ); 
//get a filter 
Filter filter = ...; 
//get the name of the 'filter' element in the schema 
QName name = new QName( "http://www.opengis.net/ogc", "Filter" ); 
//encode 
encoder.encode( filter, name );

[中]基于模式将对象编码为xml。
编码器的功能是遍历一棵对象树,并将它们作为xml进行序列化。树的导航和序列化由org的实例执行。地理工具。xml。绑定到架构中的类型的绑定。
要执行编码器,必须有3位信息:
1.树中要编码的根对象
1.正在编码的intsance文档的架构/配置。
1.模式中定义的元素的名称,对应于树中的根对象。
作为一个Excel,考虑一个ORG的编码。opengis。滤器过滤状态。

//instantiate hte configuration for the filter schmea 
Configuration configuration = new OGCConfiguration(); 
//create the encoder 
Encoder encoder = new Encoder( configuration ); 
//get a filter 
Filter filter = ...; 
//get the name of the 'filter' element in the schema 
QName name = new QName( "http://www.opengis.net/ogc", "Filter" ); 
//encode 
encoder.encode( filter, name );

代码示例

代码示例来源:origin: org.geotools/gt-wfs

/**
 * 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;
}

代码示例来源:origin: org.geoserver.csw/gs-csw-core

@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);
  }
}

代码示例来源:origin: org.geoserver/gs-wfs

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);
  }
}

代码示例来源:origin: org.geoserver.extension/wps-core

@Override
public void encode(Object obj, ContentHandler handler) throws Exception {
  Encoder e = new Encoder( xml );
  e.encode( obj, element, handler );
}

代码示例来源:origin: org.geoserver.community/gs-oseo-core

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);
  }
}

代码示例来源:origin: org.geoserver/gs-wfs

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);

代码示例来源:origin: org.geotools/gt-wfs-ng

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);

代码示例来源:origin: org.geoserver/gs-wfs

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();
  }
}

代码示例来源:origin: org.geotools/gt-wfs-ng

/**
 * 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;
}

代码示例来源:origin: org.geotools.xsd/gt-core

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());

代码示例来源:origin: org.geoserver/gs-wfs

@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);
}

代码示例来源:origin: org.geoserver.community/gs-nsg-wfs-profile

@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);
}

代码示例来源:origin: org.geoserver/gs-wfs

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);

代码示例来源:origin: org.geotools/gt2-xml-xsd

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);

代码示例来源:origin: org.geoserver/gs-wfs

.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);

代码示例来源:origin: org.n52.wps/52n-wps-io-geotools

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);

代码示例来源:origin: org.geoserver/gs-wfs

@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);
  }
}

代码示例来源:origin: org.geoserver/wfsv

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) {

代码示例来源:origin: org.geotools/gt-wfs

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);

代码示例来源:origin: org.geoserver.extension/gs-wps-core

@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);
}

相关文章