Package org.geoserver.catalog.rest

Source Code of org.geoserver.catalog.rest.FeatureTypeFinder

/* Copyright (c) 2001 - 2009 TOPP - www.openplans.org.  All rights reserved.
* This code is licensed under the GPL 2.0 license, availible at the root
* application directory.
*/
package org.geoserver.catalog.rest;

import org.geoserver.catalog.Catalog;
import org.geoserver.catalog.NamespaceInfo;
import org.geoserver.rest.RestletException;
import org.restlet.data.Form;
import org.restlet.data.Method;
import org.restlet.data.Request;
import org.restlet.data.Response;
import org.restlet.data.Status;
import org.restlet.resource.Resource;

public class FeatureTypeFinder extends AbstractCatalogFinder {

    protected FeatureTypeFinder(Catalog catalog) {
        super(catalog);
    }
   
    @Override
    public Resource findTarget(Request request, Response response) {
        String ws = (String) request.getAttributes().get( "workspace" );
        String ds = (String) request.getAttributes().get( "datastore" );
        String ft = (String) request.getAttributes().get( "featuretype");
       
        //ensure referenced resources exist
        if ( ws != null && catalog.getWorkspaceByName( ws ) == null ) {
            throw new RestletException( "No such workspace: " + ws, Status.CLIENT_ERROR_NOT_FOUND );
        }
        if ( ds != null && catalog.getDataStoreByName(ws, ds) == null ) {
            throw new RestletException( "No such datastore: " + ws + "," + ds, Status.CLIENT_ERROR_NOT_FOUND );
        }
       
        if ( ft != null ) {
            if ( ds != null &&
                    catalog.getFeatureTypeByDataStore(catalog.getDataStoreByName(ws, ds), ft) == null) {
                throw new RestletException( "No such feature type: "+ws+","+ds+","+ft, Status.CLIENT_ERROR_NOT_FOUND );
            }
            else {
                //look up by workspace/namespace
                NamespaceInfo ns = catalog.getNamespaceByPrefix( ws );
                if ( ns == null || catalog.getFeatureTypeByName( ns, ft ) == null ) {
                    throw new RestletException( "No such feature type: "+ws+","+ft, Status.CLIENT_ERROR_NOT_FOUND );
                }
            }
        }
        else {
            //check the list flag, if == 'available', just return the list
            // of feature types available
            Form form = request.getResourceRef().getQueryAsForm();
            if ( "available".equalsIgnoreCase( form.getFirstValue( "list" ) ) ) {
                return new AvailableFeatureTypeResource(null,request,response,catalog);
            }
           
            if (request.getMethod() == Method.GET ) {
                return new FeatureTypeListResource(getContext(),request,response,catalog);
            }
        }
       
        return new FeatureTypeResource(null,request,response,catalog);
    }

}
TOP

Related Classes of org.geoserver.catalog.rest.FeatureTypeFinder

TOP
Copyright © 2018 www.massapi.com. 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.