Package org.geotools.xml

Examples of org.geotools.xml.Encoder


        response.setContentType("application/xml");

        //response.setCharacterEncoding( "UTF-8" );
        OWSConfiguration configuration = new OWSConfiguration();

        Encoder encoder = new Encoder(configuration, configuration.schema());
        encoder.setIndenting(true);
        encoder.setIndentSize(2);
        encoder.setLineWidth(60);

        String schemaLocation = buildSchemaURL(baseURL(request.getHttpRequest()), "ows/1.1.0/owsAll.xsd");
        encoder.setSchemaLocation(OWS.NAMESPACE, schemaLocation);

        try {
            encoder.encode(report, OWS.ExceptionReport,
                response.getOutputStream());
        } catch (Exception ex) {
            //throw new RuntimeException(ex);
            // Hmm, not much we can do here.  I guess log the fact that we couldn't write out the exception and be done with it...
            LOGGER.log(Level.INFO, "Problem writing exception information back to calling client:", ex);
View Full Code Here


    }

    public void write(Object value, OutputStream output, Operation operation)
            throws IOException, ServiceException {
   
        Encoder encoder = new Encoder( new GMLConfiguration() );
        encoder.setEncoding(Charset.forName( wfs.getGeoServer().getGlobal().getCharset() ));
       
        if ( value instanceof Point ) {
            encoder.encode( value, GML.Point, output );
        }
        else if ( value instanceof MultiPoint ) {
            encoder.encode( value, GML.MultiPoint, output );
        }
        else if ( value instanceof LineString ) {
            encoder.encode( value, GML.LineString, output );
        }
        else if ( value instanceof MultiLineString ) {
            encoder.encode( value, GML.MultiLineString, output );
        }
        else if ( value instanceof Polygon ) {
            encoder.encode( value, GML.Polygon, output );
        }
        else if ( value instanceof MultiPolygon ) {
            encoder.encode( value, GML.MultiPolygon, output );
        }
        else {
            throw new WFSException( "Cannot encode geometry of type: " + value.getClass() );
        }
     }
View Full Code Here

    @Override
    public void write(Object value, OutputStream output, Operation operation)
            throws IOException, ServiceException {
        try {
            Configuration c = (Configuration) xmlConfiguration.newInstance();
            Encoder e = new Encoder( c );
            e.encode( value, new QName( c.getXSD().getNamespaceURI(), elementName ), output );
        }
        catch (Exception e) {
            throw (IOException) new IOException().initCause( e );
        }
    }
View Full Code Here

        writer.flush();
    }

    void write1_1(LockFeatureResponseType lockResponse, OutputStream output, Operation operation)
        throws IOException {
        Encoder encoder = new Encoder(configuration, configuration.schema());
        encoder.setEncoding(Charset.forName( wfs.getGeoServer().getGlobal().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();
    }
View Full Code Here

        final TransactionType transaction = converter.convert(diffReaders, TransactionType.class);

        //declare wfs schema location
        BaseRequestType gft = (BaseRequestType) operation.getParameters()[0];

        Encoder encoder = new Encoder(configuration, configuration.schema());
        encodeWfsSchemaLocation(encoder, gft.getBaseUrl());

        encoder.setIndenting(true);
        encoder.setEncoding(Charset.forName( global.getCharset() ));

        // set up schema locations
        // round up the info objects for each feature collection
        HashMap /* <String,Set> */ ns2metas = new HashMap();

        for (int i = 0; i < diffReaders.length; i++) {
            final FeatureDiffReader diffReader = diffReaders[i];
            final SimpleFeatureType featureType = diffReader.getSchema();

            // load the metadata for the feature type
            String namespaceURI = featureType.getName().getNamespaceURI();
            FeatureTypeInfo meta = catalog.getFeatureTypeByName( namespaceURI, featureType.getName().getLocalPart() );

            // add it to the map
            Set metas = (Set) ns2metas.get(namespaceURI);

            if (metas == null) {
                metas = new HashSet();
                ns2metas.put(namespaceURI, metas);
            }

            metas.add(meta);
        }

        // declare application schema namespaces
        for (Iterator i = ns2metas.entrySet().iterator(); i.hasNext();) {
            Map.Entry entry = (Map.Entry) i.next();

            String namespaceURI = (String) entry.getKey();
            Set metas = (Set) entry.getValue();

            StringBuffer typeNames = new StringBuffer();

            for (Iterator m = metas.iterator(); m.hasNext();) {
                FeatureTypeInfo meta = (FeatureTypeInfo) m.next();
                typeNames.append(meta.getName());

                if (m.hasNext()) {
                    typeNames.append(",");
                }
            }

            // set the schema location
            encodeTypeSchemaLocation(encoder, gft.getBaseUrl(), namespaceURI, typeNames);
        }

        try {
            encoder.encode(transaction, element, output);
        } finally {
          for (int i = 0; i < diffReaders.length; i++) {
        diffReaders[i].close();
      }
        }
View Full Code Here

        }
        else {
            configuration.getProperties().add( GMLConfiguration.NO_FEATURE_BOUNDS);
        }
       
        Encoder encoder = new Encoder(configuration, configuration.schema());
        encoder.setEncoding(Charset.forName( global.getCharset() ));

        //declare wfs schema location
        BaseRequestType gft = (BaseRequestType)getFeature.getParameters()[0];
       
        if (wfs.isCanonicalSchemaLocation()) {
            encoder.setSchemaLocation(org.geoserver.wfs.xml.v1_1_0.WFS.NAMESPACE,
                    WFS.CANONICAL_SCHEMA_LOCATION);
        } else {
            encoder.setSchemaLocation(org.geoserver.wfs.xml.v1_1_0.WFS.NAMESPACE,
                    buildSchemaURL(gft.getBaseUrl(), "wfs/1.1.0/wfs.xsd"));
        }

        //declare application schema namespaces
        Map<String, String> params = params("service", "WFS", "version", "1.1.0", "request", "DescribeFeatureType");
        for (Iterator i = ns2metas.entrySet().iterator(); i.hasNext();) {
            Map.Entry entry = (Map.Entry) i.next();

            String namespaceURI = (String) entry.getKey();
            Set metas = (Set) entry.getValue();

            StringBuffer typeNames = new StringBuffer();

            String userSchemaLocation = null;
            for (Iterator m = metas.iterator(); m.hasNext();) {
                FeatureTypeInfo meta = (FeatureTypeInfo) m.next();
                if (userSchemaLocation == null) {
                    FeatureType featureType = meta.getFeatureType();
                    Object schemaUri = featureType.getUserData().get("schemaURI");
                    if (schemaUri != null) {
                        userSchemaLocation = schemaUri.toString();
                    }
                }
                typeNames.append(meta.getPrefixedName());
               
                if (m.hasNext()) {
                    typeNames.append(",");
                }
            }
            params.put("typeName", typeNames.toString());

            //set the schema location if the user provides it, otherwise give a default one
            if (userSchemaLocation != null) {
                encoder.setSchemaLocation(namespaceURI, userSchemaLocation);
            } else {
                String schemaLocation = buildURL(gft.getBaseUrl(), "wfs", params, URLType.SERVICE);
                LOGGER.finer("Unable to find user-defined schema location for: " + namespaceURI
                        + ". Using a built schema location by default: " + schemaLocation);
                encoder.setSchemaLocation(namespaceURI, schemaLocation);
            }
        }

        encoder.encode(results, org.geoserver.wfs.xml.v1_1_0.WFS.FEATURECOLLECTION, output);
    }
View Full Code Here

       
        //grab the metadata
        FeatureTypeInfo meta = catalog.getFeatureTypeByName(featureType.getName());
       
        //create teh encoder
        Encoder encoder = new Encoder( configuration );
        encoder.setEncoding(Charset.forName( wfs.getGeoServer().getGlobal().getCharset() ) );
        encoder.encode( feature,
            new QName( meta.getNamespace().getURI(), meta.getName()), output );
    }
View Full Code Here

            ActionType action = (ActionType) response.getTransactionResults().getAction().iterator()
                                                     .next();
            throw new WFSException(action.getMessage(), action.getCode(), action.getLocator());
        }

        Encoder encoder = new Encoder(configuration, configuration.schema());
        encoder.setEncoding(Charset.forName( wfs.getGeoServer().getGlobal().getCharset()) );

        TransactionType req = (TransactionType)operation.getParameters()[0];
       
        encoder.setSchemaLocation(org.geoserver.wfs.xml.v1_1_0.WFS.NAMESPACE,
                buildSchemaURL(req.getBaseUrl(), "wfs/1.1.0/wfs.xsd"));
        encoder.encode(response, org.geoserver.wfs.xml.v1_1_0.WFS.TRANSACTIONRESPONSE, output);
      
    }
View Full Code Here

                fos = zos;
            } else {
                fos = new FileOutputStream(kmlFile);
            }
   
            Encoder encoder = new Encoder(new KMLConfiguration());
            encoder.setIndenting(true);
   
            encoder.encode(newCollection, KML.kml, fos);
           
        } finally {
            if (fos != null) {
                fos.close();
                fos = null;
View Full Code Here

    @Test
    public void testGML2() throws Exception {
        final Geometry geometry = GeomFormat.WKT.parse("Polygon((482200.0 63000.0,835700.0 63000.0,835700.0 301000.0,482200.0 301000.0," +
                                                       "482200.0 63000.0))");
        final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        final Encoder encoder = new Encoder(GeomFormat.gml2Config);
        encoder.setIndenting(false);
        encoder.setOmitXMLDeclaration(true);
        encoder.setNamespaceAware(true);

        encoder.encode(geometry, org.geotools.gml2.GML.geometryMember, outputStream);
        String gmlString = outputStream.toString();

        assertNotNull(GeomFormat.GML2.parse(gmlString));
        assertNotNull(GeomFormat.GML2.parse(URLEncoder.encode(gmlString, "UTF-8")));
    }
View Full Code Here

TOP

Related Classes of org.geotools.xml.Encoder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.