Package org.geotools.xml

Examples of org.geotools.xml.Parser


        StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory();
     // try SLD 1.1 first
        SLDConfiguration config = new SLDConfiguration();
        Reader reader = null;
        try {
            Parser parser = new Parser( config );
            reader = new FileReader(file);
            Object object = parser.parse( reader );
            if( object instanceof StyledLayerDescriptor){
                StyledLayerDescriptor sld = (StyledLayerDescriptor) object;
                return sld;
            }
            else if ( object instanceof NamedStyle ){
                NamedStyle style = (NamedStyle) object;
                StyledLayerDescriptor sld = createDefaultSLD( style );
                return sld;
            }
        }
        catch(Exception ignore){
            // we are ignoring this error and will try the more forgiving option below
            UiPlugin.trace(SLDs.class,"SLD 1.1 configuration failed to parse "+file, ignore);
        }
        finally {
            if( reader != null){
                reader.close();
            }
        }
        // parse it up
        SLDParser parser = new SLDParser(styleFactory);
        try {
            parser.setInput(file);
            StyledLayerDescriptor sld = parser.parseSLD();
            return sld;
        } catch (FileNotFoundException e) {
            return null; // well that is unexpected since f.exists()
        }
    }
View Full Code Here


    public static Style parseStyle(URL url) throws IOException {
        // try SLD 1.1 first
        SLDConfiguration config = new SLDConfiguration();
        InputStream input = null;
        try {
            Parser parser = new Parser( config );
            input = url.openStream();
            Object object = parser.parse( input );
            if( object instanceof StyledLayerDescriptor){
                StyledLayerDescriptor sld = (StyledLayerDescriptor) object;
                Style[] array = SLDs.styles( sld );
                if( array != null && array.length > 0 ){
                    return array[0];
View Full Code Here

        StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory();
        // try SLD 1.1 first
        SLDConfiguration config = new SLDConfiguration();
        Reader reader = null;
        try {
            Parser parser = new Parser( config );
            reader = new FileReader(file);
            Object object = parser.parse( reader );
            if( object instanceof StyledLayerDescriptor){
                StyledLayerDescriptor sld = (StyledLayerDescriptor) object;
                Style[] array = SLDs.styles( sld );
                if( array != null && array.length > 0 ){
                    return array[0];
                }
            }
            else if ( object instanceof NamedStyle ){
                NamedStyle style = (NamedStyle) object;
                return style;
            }
        }
        catch(Exception ignore){
            // we are ignoring this error and will try the more forgiving option below
            UiPlugin.trace(SLDs.class,"SLD 1.1 configuration failed to parse "+file, ignore);
        }
        finally {
            if( reader != null){
                reader.close();
            }
        }
       
        // parse it up
        SLDParser parser = new SLDParser(styleFactory);
        try {
            parser.setInput(file);
            Style[] array = parser.readXML();
            if( array != null && array.length > 0 ){
                return array[0];
            }
        } catch (FileNotFoundException e) {
            return null; // well that is unexpected since f.exists()
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

        if ( strict == null ) {
            strict = Boolean.FALSE;
        }
       
        //create the parser instance
        Parser parser = new Parser(configuration);
       
        //"inject" namespace mappings
        List<NamespaceInfo> namespaces = catalog.getNamespaces();
        for ( NamespaceInfo ns : namespaces ) {
            //if ( namespaces[i].isDefault() )
            //    continue;
           
            parser.getNamespaces().declarePrefix(
                ns.getPrefix(), ns.getURI());
        }
        //set validation based on strict or not
        parser.setValidating(strict.booleanValue());
       
        //parse
        Object parsed = parser.parse(reader);
       
        //if strict was set, check for validation errors and throw an exception
        if (strict.booleanValue() && !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

                InputStream input = new ByteArrayInputStream(rawContent);
   
                try {
                    //create the parser
                    Configuration configuration = new OGCConfiguration();
                    Parser parser_1_0_0 = new Parser(configuration);
                    filter = (Filter) parser_1_0_0.parse(input);
                } catch (Exception e) {
                    //parsing failed, try with a Filter 1.1.0 parser
                    try{
                        input = new ByteArrayInputStream(rawContent);
                        Configuration configuration = new org.geotools.filter.v1_1.OGCConfiguration();
                        Parser parser_1_1_0 = new Parser(configuration);
                        filter = (Filter) parser_1_1_0.parse(input);
                       
                        filters.add(filter);
                    }catch(Exception e2){
                        //parsing failed, fall back to old parser
                        String msg = "Unable to parse filter: " + string;
View Full Code Here

     * Validates a document against the
     * @param dom
     * @param configuration
     */
    protected void checkValidationErrors(Document dom, Configuration configuration) throws Exception {
        Parser p = new Parser(configuration);
        p.setValidating( true );
        p.parse( new DOMSource( dom ) );
   
        if ( !p.getValidationErrors().isEmpty() ) {
            for ( Iterator e = p.getValidationErrors().iterator(); e.hasNext(); ) {
                SAXParseException ex = (SAXParseException) e.next();
                System.out.println( ex.getLineNumber() + "," + ex.getColumnNumber() + " -" + ex.toString()  );
            }
            fail( "Document did not validate.");
        }
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

        }

        public boolean pass(SyndEntry entry){
            try{
                String xmlBlob = ((SyndContent)entry.getContents().get(0)).getValue();
                Parser parser = new Parser(xmlConfiguration);
                TransactionType tx = (TransactionType) parser.parse(new StringReader(xmlBlob));

                Set qnames = new TreeSet();

                Iterator it = tx.getInsert().iterator();
                while (it.hasNext()){
View Full Code Here

        this.configuration = configuration;
    }

    @SuppressWarnings("unchecked")
    public Object read(Object request, Reader reader, Map kvp) throws Exception {
        Parser parser = new Parser(configuration);
        parser.setValidating(true);

        Object parsed;
        try {
            parsed = parser.parse(reader);
        } catch(Exception e) {
            throw new WPSException("Could not parse XML request.", e);
        }

        if (!parser.getValidationErrors().isEmpty()) {
            WPSException exception = new WPSException("Invalid request", "InvalidParameterValue");

            for(Exception error : (List<Exception>)parser.getValidationErrors()) {
                LOGGER.warning( error.getLocalizedMessage() );
                exception.getExceptionText().add(error.getLocalizedMessage());
            }
        }
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.