⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 typeseditorform.java

📁 电子地图服务器,搭建自己的地图服务
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* Copyright (c) 2001 - 2007 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.vfny.geoserver.form.data;

import com.vividsolutions.jts.geom.Envelope;
import org.apache.struts.Globals;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.util.MessageResources;
import org.geotools.data.DataStore;
import org.geotools.feature.FeatureType;
import org.geotools.feature.GeometryAttributeType;
import org.geotools.referencing.CRS;
import org.opengis.referencing.FactoryException;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.vfny.geoserver.action.HTMLEncoder;
import org.vfny.geoserver.config.AttributeTypeInfoConfig;
import org.vfny.geoserver.config.ConfigRequests;
import org.vfny.geoserver.config.DataConfig;
import org.vfny.geoserver.config.DataStoreConfig;
import org.vfny.geoserver.config.FeatureTypeConfig;
import org.vfny.geoserver.config.StyleConfig;
import org.vfny.geoserver.global.FeatureTypeInfo;
import org.vfny.geoserver.global.MetaDataLink;
import org.vfny.geoserver.global.UserContainer;
import org.vfny.geoserver.global.dto.AttributeTypeInfoDTO;
import org.vfny.geoserver.global.dto.DataTransferObjectFactory;
import org.vfny.geoserver.util.Requests;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.SortedSet;
import java.util.TreeSet;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;


/**
 * Form used to work with FeatureType information.
 *
 * @author jgarnett, Refractions Research, Inc.
 * @author $Author: cholmesny $ (last modification)
 * @version $Id: TypesEditorForm.java 7693 2007-11-01 09:31:11Z aaime $
 */
public class TypesEditorForm extends ActionForm {
    static final List schemaBases;
    static final List allMetadataURLTypes;

    static {
        List bases = new ArrayList();
        bases.add("--");
        bases.addAll(DataTransferObjectFactory.schemaBaseMap.keySet());
        schemaBases = Collections.unmodifiableList(bases);
        allMetadataURLTypes = Arrays.asList(new String[] { "FGDC", "TC211" });
    }

    /** Identiy DataStore responsible for this FeatureType */
    private String dataStoreId;

    /** Identify Style used to render this feature type */
    private String styleId;

    /** Sorted Set of available styles */
    private SortedSet panelStyleIds;
    private SortedSet typeStyles;
    private String[] otherSelectedStyles;

    /**
     * Name of featureType.
     *
     * <p>
     * An exact match for typeName provided by a DataStore.
     * </p>
     */
    private String typeName;

    /**
         *
         */
    private String wmsPath;

    /**
     * Representation of the Spatial Reference System.
     *
     * <p>
     * Empty represents unknown, usually assumed to be Cartisian Coordinates.
     * </p>
    */
    private String SRS;

    /**
     *  WKT representation of the SRS
     *  This is read-only since it gets generated from the SRS id.
     *  Everytime SRS is updates (#setSRS()), this will also be re-set.
     *  If there's a problem with the SRS, this will try to give some info about the error.
     */
    private String SRSWKT;
    
    /**
     * WKT representation of the native SRS
     */
    private String nativeSRSWKT;
    
    private List allSrsHandling;
    private int srsHandling = FeatureTypeInfo.FORCE;

    /** Title of this FeatureType */
    private String title;

    /** Representation of bounds info as parseable by Double */
    private String minX;

    /** Representation of bounds info as parseable by Double */
    private String minY;

    /** Representation of bounds info as parseable by Double */
    private String maxX;

    /** Representation of bounds info as parseable by Double */
    private String maxY;

    /** List of keywords, often grouped with brackets */
    private String keywords;

    /** Metadata URL
     *  This is a quick hack, the user interface and configuration code is really too broken
     *  to waste time on it...
     **/
    private MetaDataLink[] metadataLinks;

    /** Metadata URL types **/
    private String[] metadataURLTypes;

    /** FeatureType abstract */
    private String description;

    /** The amount of time to use for the CacheControl: max-age parameter in maps generated from this featuretype **/
    private String cacheMaxAge;

    /** Should we add the CacheControl: max-age header to maps generated from this featureType? **/
    private boolean cachingEnabled;
    private boolean cachingEnabledChecked = false;

    /**
     * One of a select list - simplest is AbstractBaseClass.
     *
     * <p>
     * The value "--" will be used to indicate default schema completly
     * generated from FeatureType information at runtime.
     * </p>
     *
     * <p>
     * When generated the schema will make use a schemaBase of
     * "AbstractFeatureType".
     * </p>
     */
    private String schemaBase;

    /**
     * The name of the complex element of type schemaBase.
     *
     * <p>
     * We only need this for non generated schemaBase.
     * </p>
     */
    private String schemaName;

    /** List of AttributeDisplay and AttributeForm */
    private List attributes;

    /** List of attributes available for addition */
    private List addList;

    /** Action requested by user */
    private String action;

    /** Sorted Set of available styles */
    private SortedSet styles;

    /** A hidden field to enable autogeneration of extents (for SRS and BoundingBox values) **/
    private String autoGenerateExtent;

    /** Stores the name of the new attribute they wish to create */
    private String newAttribute;

    /** these store the bounding box of DATASET - in it coordinate system.
         *  normally, you'll have these set to "" or null.
         *  They're only for information purposes (presentation), they are never persisted or used in any calculations.
         */
    private String dataMinX;
    private String dataMinY;
    private String dataMaxX;
    private String dataMaxY;
    private CoordinateReferenceSystem declaredCRS;
    private CoordinateReferenceSystem nativeCRS;

    /**
     * Set up FeatureTypeEditor from from Web Container.
     *
     * <p>
     * The key DataConfig.SELECTED_FEATURE_TYPE is used to look up the selected
     * from the web container.
     * </p>
     *
     * @param mapping
     * @param request
     */
    public void reset(ActionMapping mapping, HttpServletRequest request) {
        super.reset(mapping, request);

        action = "";

        ServletContext servletContext = getServlet().getServletContext();
        ServletContext context = servletContext;

        DataConfig config = ConfigRequests.getDataConfig(request);
        UserContainer user = Requests.getUserContainer(request);

        FeatureTypeConfig type = user.getFeatureTypeConfig();

        if (type == null) {
            System.out.println("Type is not there");

            // Not sure what to do, user must have bookmarked?
            return; // Action should redirect to Select screen?
        }

        this.dataStoreId = type.getDataStoreId();
        this.styleId = type.getDefaultStyle();

        description = type.getAbstract();

        this.cacheMaxAge = type.getCacheMaxAge();
        this.cachingEnabled = type.isCachingEnabled();
        cachingEnabledChecked = false;

        Envelope bounds = type.getLatLongBBox();

        if ((bounds == null) || bounds.isNull()) {
            minX = "";
            minY = "";
            maxY = "";
            maxX = "";
        } else {
            minX = Double.toString(bounds.getMinX());
            minY = Double.toString(bounds.getMinY());
            maxX = Double.toString(bounds.getMaxX());
            maxY = Double.toString(bounds.getMaxY());
        }

        Envelope nativeBounds = type.getNativeBBox();

        if ((nativeBounds == null) || nativeBounds.isNull()) {
            dataMinX = "";
            dataMinY = "";
            dataMaxX = "";
            dataMaxY = "";
        } else {
            dataMinX = Double.toString(nativeBounds.getMinX());
            dataMinY = Double.toString(nativeBounds.getMinY());
            dataMaxX = Double.toString(nativeBounds.getMaxX());
            dataMaxY = Double.toString(nativeBounds.getMaxY());
        }

        typeName = type.getName();
        setSRS(Integer.toString(type.getSRS())); // doing it this way also sets SRSWKT
        srsHandling = type.getSRSHandling();
        
        nativeSRSWKT = "-";
        DataStore dataStore = null;
        try {
            DataConfig dataConfig =  (DataConfig) servletContext.getAttribute(DataConfig.CONFIG_KEY);
            DataStoreConfig dsConfig = dataConfig.getDataStore(type.getDataStoreId());
            dataStore = dsConfig.findDataStore(servletContext);
            FeatureType featureType = dataStore.getSchema(type.getName());
            GeometryAttributeType dg = featureType.getDefaultGeometry();
            if(dg != null && dg.getCoordinateSystem() != null) {
                nativeCRS = dg.getCoordinateSystem();
                nativeSRSWKT = dg.getCoordinateSystem().toString();
            }
        } catch(Exception e) {
            // never mind
        } finally {
            if(dataStore != null) dataStore.dispose();
        }
        
        // load localized
        MessageResources resources = ((MessageResources) request.getAttribute(Globals.MESSAGES_KEY));
        if(nativeSRSWKT == "-")
            allSrsHandling =  Arrays.asList(new String[] {resources.getMessage("label.type.forceSRS")});
        else
            allSrsHandling =  Arrays.asList(new String[] {resources.getMessage("label.type.forceSRS"),
                resources.getMessage("label.type.reprojectSRS"), resources.getMessage("label.type.leaveSRS")});
        

        title = type.getTitle();
        wmsPath = type.getWmsPath();

        System.out.println("rest based on schemaBase: " + type.getSchemaBase());

        // Generate ReadOnly list of Attributes
        //
        DataStoreConfig dataStoreConfig = config.getDataStore(dataStoreId);
        FeatureType featureType = null;

        try {
            dataStore = dataStoreConfig.findDataStore(servletContext);
            featureType = dataStore.getSchema(typeName);
        } catch (IOException e) {
            // DataStore unavailable!
        } finally {
            if(dataStore != null) dataStore.dispose();
        }

        if (((type.getSchemaBase() == null) || "--".equals(type.getSchemaBase()))
                || (type.getSchemaAttributes() == null)) {
            //We are using the generated attributes
            this.schemaBase = "--";
            this.schemaName = typeName + "_Type";
            this.attributes = new LinkedList();

            // Generate ReadOnly list of Attributes
            //
            List generated = DataTransferObjectFactory.generateAttributes(featureType);
            this.attributes = attributesDisplayList(generated);
            addList = Collections.EMPTY_LIST;
        } else {
            this.schemaBase = type.getSchemaBase();
            this.schemaName = type.getSchemaName();
            this.attributes = new LinkedList();

            //
            // Need to add read only AttributeDisplay for each required attribute
            // defined by schemaBase
            //
            List schemaAttributes = DataTransferObjectFactory.generateRequiredAttributes(schemaBase);
            attributes.addAll(attributesDisplayList(schemaAttributes));
            attributes.addAll(attributesFormList(type.getSchemaAttributes(), featureType));
            addList = new ArrayList(featureType.getAttributeCount());

            for (int i = 0; i < featureType.getAttributeCount(); i++) {
                String attributeName = featureType.getAttributeType(i).getName();

                if (lookUpAttribute(attributeName) == null) {
                    addList.add(attributeName);
                }
            }
        }

        StringBuffer buf = new StringBuffer();

        for (Iterator i = type.getKeywords().iterator(); i.hasNext();) {
            String keyword = (String) i.next();
            buf.append(keyword);

            if (i.hasNext()) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -