Package org.geotools.xml

Examples of org.geotools.xml.Parser


     * @return
     * @throws IOException
     */
    SimpleFeature fromGML3(String gml3) throws IOException {
        try {
            Parser parser = new Parser(configuration);
            parser.setStrict(false);
            return (SimpleFeature) parser.parse(new StringReader(gml3));
        } catch (ParserConfigurationException e) {
            throw (IOException) new IOException("Failure parsing the feature").initCause(e);
        } catch (SAXException e) {
            throw (IOException) new IOException("Failure parsing the feature").initCause(e);
        }
View Full Code Here


     * @throws Exception
     */
    protected void validate(MockHttpServletResponse response) throws Exception {
        GSSConfiguration configuration = (GSSConfiguration) applicationContext
                .getBean("gssXmlConfiguration");
        Parser parser = new Parser(configuration);
        parser.validate(new StringReader(response.getOutputStreamContent()));
        if (parser.getValidationErrors().size() > 0) {
            for (Iterator it = parser.getValidationErrors().iterator(); it.hasNext();) {
                SAXParseException se = (SAXParseException) it.next();
                System.out.println(se);
            }
            // print(dom(response));
            fail("Document is not valid, see standard output for a document dump and validation exceptions");
View Full Code Here

            this.configuration = configuration;
            this.geoServer = gs;
    }
   
    public Object read(Object request, Reader reader, Map kvp) throws Exception {
        Parser parser = new Parser(configuration);
        parser.setValidating(true);
       
        //"inject" namespace mappings
        Catalog catalog = geoServer.getCatalog();
        List<NamespaceInfo> namespaces = catalog.getNamespaces();
        for ( NamespaceInfo ns : namespaces ) {
            if ( ns.equals( catalog.getDefaultNamespace() ) ) 
                continue;
           
            parser.getNamespaces().declarePrefix(
                ns.getPrefix(), ns.getURI());
        }
      
        //set the input source with the correct encoding
        InputSource source = new InputSource(reader);
        source.setEncoding(geoServer.getGlobal().getCharset());

        Object parsed = parser.parse(source);

        // unfortunately insert elements in transactions cannot be validated...
        if(!(parsed instanceof PostDiffType) && !(parsed instanceof GetDiffResponseType)) {
            if (!parser.getValidationErrors().isEmpty()) {
                WFSException exception = new WFSException("Invalid request", "InvalidParameterValue");
   
                for (Iterator e = parser.getValidationErrors().iterator(); e.hasNext();) {
                    Exception error = (Exception) e.next();
                    exception.getExceptionText().add(error.getLocalizedMessage());
                }
   
                throw exception;
View Full Code Here

        this.configuration = configuration;
    }

    public Object read(Object request, Reader reader, Map kvp) throws Exception {
        //create the parser instance
        Parser parser = new Parser(configuration);
        parser.setValidating(true);
        parser.setFailOnValidationError(true);
        parser.setStrict(true);
       
        // parse
        Object parsed;
        try {
            parsed = parser.parse(reader);
        } catch(Exception e) {
            throw new WcsException("Parsing failed, the xml request is most probably not compliant to the wcs schema", e);
        }
       
        return parsed;
View Full Code Here

        this.configuration = configuration;
    }

    public Object read(Object request, Reader reader, Map kvp) throws Exception {
        // create the parser instance
        Parser parser = new Parser(configuration);
        parser.setValidating(true);
        parser.setFailOnValidationError(true);
        parser.setStrict(true);

        // parse
        Object parsed;
        try {
            parsed = parser.parse(reader);
        } catch (Exception e) {
            throw new WcsException(
                    "Parsing failed, the xml request is most probably not compliant to the wcs schema",
                    e);
        }
View Full Code Here

        String xml = rs.getString(names[0]);
        if (xml == null) {
            return null;
        }

        Parser parser = new Parser(ogc);
        try {
            Filter filter = (Filter) parser.parse(new StringReader(xml));
            return filter;
        } catch (Exception e) {
            String msg = "Could not decode filter: " + xml;
            throw new HibernateException(msg, e);
        }
View Full Code Here

            if (statusCode != HttpStatus.SC_OK) {
                throw new IOException("HTTP client returned with code " + statusCode);
            }

            // parse the response
            Parser parser = new Parser(configuration);
            parser.setStrict(true);
            parser.setFailOnValidationError(true);
            InputStream is;
            if(LOGGER.isLoggable(Level.FINE)) {
                String responseString = method.getResponseBodyAsString();
                LOGGER.log(Level.FINE, "Response from Unit:\n" + responseString);
                is = new ByteArrayInputStream(responseString.getBytes());
            } else {
                is = method.getResponseBodyAsStream();
            }
            response = parser.parse(is);
        } catch (Exception e) {
            throw (IOException) new IOException("Error occurred while executing "
                    + "a call to the Unit").initCause(e);
        } finally {
            method.releaseConnection();
View Full Code Here

            new FeatureTypeSchemaBuilder.GML3(getGeoServer());
        return new WFSConfiguration(getGeoServer(),sb,new WFS(sb));
    }

    public void testValid() throws Exception {
        Parser parser = new Parser(configuration());
        parser.parse(getClass().getResourceAsStream("GetFeature.xml"));

        assertEquals(0, parser.getValidationErrors().size());
    }
View Full Code Here

        assertEquals(0, parser.getValidationErrors().size());
    }

    public void testInvalid() throws Exception {
        Parser parser = new Parser(configuration());
        parser.setValidating(true);
        parser.parse(getClass().getResourceAsStream("GetFeature-invalid.xml"));

        assertTrue(parser.getValidationErrors().size() > 0);
    }
View Full Code Here

                + "      <ows:Identifier>result</ows:Identifier>\n"
                + "    </wps:RawDataOutput>\n" + "  </wps:ResponseForm>\n" + "</wps:Execute>";

        MockHttpServletResponse response = postAsServletResponse(root(), xml);

        Parser p = new Parser(new WFSConfiguration());
        FeatureCollectionType fct = (FeatureCollectionType) p.parse(new ByteArrayInputStream(
                response.getOutputStreamContent().getBytes()));
        FeatureCollection fc = (FeatureCollection) fct.getFeature().get(0);

        assertEquals(36, fc.size());
       
View Full Code Here

TOP

Related Classes of org.geotools.xml.Parser

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.