Package org.geoserver.ows

Examples of org.geoserver.ows.KvpParser


        //strip out parsers which do not match current service/request/version
        String service = (String) kvp.get( "service" );
        String version = (String) kvp.get( "version" );
        String request = (String) kvp.get( "request" );
        for (Iterator p = parsers.iterator(); p.hasNext(); ) {
            KvpParser parser = (KvpParser) p.next();
           
            if ( parser.getService() != null && !parser.getService().equalsIgnoreCase(service) ) {
                p.remove();
                continue;
            }
           
            if ( parser.getVersion() != null && !parser.getVersion().toString().equals(version) ) {
                p.remove();
                continue;
            }
           
            if ( parser.getRequest() != null && !parser.getRequest().equalsIgnoreCase(request) ) {
                p.remove();
            }
        }
       
        //parser the kvp's
        ArrayList<Throwable> errors = new ArrayList<Throwable>();
        for (Iterator itr = kvp.entrySet().iterator(); itr.hasNext();) {
            Map.Entry entry = (Map.Entry) itr.next();
            String key = (String) entry.getKey();
            String value = (String) entry.getValue();
           
            //find the parser for this key value pair
            Object parsed = null;

            for (Iterator pitr = parsers.iterator(); pitr.hasNext() && parsed == null;) {
                KvpParser parser = (KvpParser) pitr.next();

                if (key.equalsIgnoreCase(parser.getKey())) {
                    try {
                        parsed = parser.parse(value);
                    } catch (Throwable t) {
                        //dont throw any exceptions yet, befor the service is
                        // known
                        errors.add( t );
                    }
View Full Code Here


            }

            Object parsed = null;

            for (Iterator p = parsers.iterator(); p.hasNext();) {
                KvpParser parser = (KvpParser) p.next();
                if ( key.equalsIgnoreCase( parser.getKey() ) ) {
                    parsed = parser.parse( raw );
                    if ( parsed != null ) {

                        break;
                    }
                }
View Full Code Here

    }

    public Object parse(String value) throws Exception {
      List ret = new ArrayList();
        List parsers = GeoServerExtensions.extensions(KvpParser.class, applicationContext);
        KvpParser formatOptionsParser = null;
        for (Object o : parsers) {
            KvpParser parser = (KvpParser) o;
            if ( parser.getKey().equalsIgnoreCase("format_options") ) {
              formatOptionsParser = parser;
              break;
            }
        }
        if (formatOptionsParser == null) {
View Full Code Here

    @Test
    public void testParserForVersion() throws Exception {
        // look up parser objects
        List<KvpParser> parsers = GeoServerExtensions.extensions(KvpParser.class);
        KvpParser parser = KvpUtils.findParser("interpolation", "WCS", null, "2.0.0", parsers);
        assertNotNull(parser);
        // Ensure the correct parser is taken
        assertEquals(parser.getClass(), InterpolationKvpParser.class);
        // Version 2.0.1
        parser = KvpUtils.findParser("interpolation", "WCS", null, "2.0.1", parsers);
        assertNotNull(parser);
        // Ensure the correct parser is taken
        assertEquals(parser.getClass(), InterpolationKvpParser.class);
    }
View Full Code Here

        for (Iterator<Map.Entry<Object, Object>> itr = kvp.entrySet().iterator(); itr.hasNext();) {
            Map.Entry<Object, Object> entry = itr.next();
            String key = (String) entry.getKey();

            // find the parser for this key value pair
            KvpParser parser = findParser(key, service, request, version, parsers);

            // parse the value
            Object parsed = null;
            if (parser != null) {
                try {
                    if (entry.getValue() instanceof String) {
                        String value = (String) entry.getValue();
                        parsed = parser.parse(value);
                    } else {
                        String[] values = (String[]) entry.getValue();
                        List<Object> result = new ArrayList<Object>();
                        for (String v : values) {
                            result.add(parser.parse(v));
                        }
                        parsed = result;
                    }
                } catch (Throwable t) {
                    // dont throw any exceptions yet, befor the service is
View Full Code Here

     * @param request the request parameter from the kvp (can be null)
     */
    public static void purgeParsers(List<KvpParser> parsers, final String service,
            final String version, final String request) {
        for (Iterator<KvpParser> p = parsers.iterator(); p.hasNext();) {
            KvpParser parser = p.next();

            if (parser.getService() != null && !parser.getService().equalsIgnoreCase(service)) {
                p.remove();
            } else if (parser.getVersion() != null
                    && !parser.getVersion().toString().equals(version)) {
                p.remove();
            } else if (parser.getRequest() != null
                    && !parser.getRequest().equalsIgnoreCase(request)) {
                p.remove();
            }
        }
    }
View Full Code Here

     * @throws IllegalStateException if more than one candidate parser is found
     */
    public static KvpParser findParser(final String key, final String service,
            final String request, final String version, Collection<KvpParser> parsers) {
        // find the parser for this key value pair
        KvpParser parser = null;
        final Iterator<KvpParser> pitr = parsers.iterator();
        while (pitr.hasNext()) {
            KvpParser candidate = pitr.next();
            if (key.equalsIgnoreCase(candidate.getKey())) {
                if (parser == null) {
                    parser = candidate;
                } else {
                    // if target service matches, it is a closer match
                    String trgService = candidate.getService();
                    if (trgService != null && trgService.equalsIgnoreCase(service)) {
                        // determine if this parser more closely matches the request
                        String curService = parser.getService();
                        if (curService == null) {
                            parser = candidate;
                        } else {
                            // both match, filter by version
                            Version curVersion = parser.getVersion();
                            Version trgVersion = candidate.getVersion();
                            if (trgVersion != null) {
                                if (curVersion == null && trgVersion.toString().equals(version)) {
                                    parser = candidate;
                                }
                            } else {
View Full Code Here

     * @throws IllegalStateException if more than one candidate parser is found
     */
    public static Object parseKey(final String key, final String value, final String service,
            final String request, final String version, List<KvpParser> parsers) throws Exception {
        // find the parser for this key value pair
        KvpParser parser = findParser(key, service, request, version, parsers);
        if (parser == null) {
            return null;
        }
        return parser.parse(value);
    }
View Full Code Here

    @Test
    public void testParserForVersion() {
        // look up parser objects
        List<KvpParser> parsers = GeoServerExtensions.extensions(KvpParser.class);
        KvpParser parser = KvpUtils.findParser("interpolation", "WCS", null, "1.0.0", parsers);
        assertNotNull(parser);
        // Ensure the correct parser is taken
        assertEquals(parser.getClass(), InterpolationMethodKvpParser.class);
    }
View Full Code Here

            String raw = kv.size() == 1 ? "true" : KvpUtils.unescape(kv.get(1));
              
            Object parsed = null;

            for (Iterator p = parsers.iterator(); p.hasNext();) {
                KvpParser parser = (KvpParser) p.next();
                if ( key.equalsIgnoreCase( parser.getKey() ) ) {
                    parsed = parser.parse( raw );
                    if ( parsed != null ) {

                        break;
                    }
                }
View Full Code Here

TOP

Related Classes of org.geoserver.ows.KvpParser

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.