001: /* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
002: * This code is licensed under the GPL 2.0 license, availible at the root
003: * application directory.
004: */
005: package org.vfny.geoserver.action.data;
006:
007: import org.apache.struts.action.ActionForm;
008: import org.apache.struts.action.ActionForward;
009: import org.apache.struts.action.ActionMapping;
010: import org.geotools.coverage.grid.GridCoverage2D;
011: import org.geotools.coverage.grid.io.AbstractGridCoverage2DReader;
012: import org.geotools.coverage.grid.io.AbstractGridFormat;
013: import org.geotools.parameter.DefaultParameterDescriptor;
014: import org.opengis.coverage.grid.Format;
015: import org.opengis.coverage.grid.GridCoverage;
016: import org.opengis.coverage.grid.GridCoverageReader;
017: import org.opengis.parameter.GeneralParameterValue;
018: import org.opengis.parameter.InvalidParameterValueException;
019: import org.opengis.parameter.ParameterDescriptor;
020: import org.opengis.parameter.ParameterNotFoundException;
021: import org.opengis.parameter.ParameterValue;
022: import org.opengis.parameter.ParameterValueGroup;
023: import org.vfny.geoserver.action.ConfigAction;
024: import org.vfny.geoserver.config.CoverageConfig;
025: import org.vfny.geoserver.config.DataConfig;
026: import org.vfny.geoserver.form.data.DataCoveragesNewForm;
027: import org.vfny.geoserver.global.ConfigurationException;
028: import org.vfny.geoserver.global.CoverageStoreInfo;
029: import org.vfny.geoserver.global.Data;
030: import org.vfny.geoserver.global.GeoserverDataDirectory;
031: import org.vfny.geoserver.global.UserContainer;
032: import org.vfny.geoserver.util.CoverageUtils;
033: import java.io.IOException;
034: import java.net.MalformedURLException;
035: import java.util.ArrayList;
036: import java.util.HashMap;
037: import java.util.Iterator;
038: import java.util.List;
039: import javax.servlet.http.HttpServletRequest;
040: import javax.servlet.http.HttpServletResponse;
041:
042: /**
043: * DataCoveragesNewAction purpose.
044: *
045: * <p>
046: * Description of DataCoveragesNewAction ...
047: * </p>
048: *
049: * <p>
050: * Capabilities:
051: * </p>
052: *
053: * <ul>
054: * <li> Coverage: description </li>
055: * </ul>
056: *
057: * <p>
058: * Example Use:
059: * </p>
060: *
061: * <pre><code>
062: * DataCoveragesNewAction x = new DataCoveragesNewAction(...);
063: * </code></pre>
064: *
065: * @author rgould, Refractions Research, Inc.
066: * @author cholmesny
067: * @author $Author: Alessio Fabiani (alessio.fabiani@gmail.com) $ (last
068: * modification)
069: * @author $Author: Simone Giannecchini (simboss1@gmail.com) $ (last
070: * modification)
071: * @version $Id: DataCoveragesNewAction.java,v 1.15 2004/09/17 16:34:47
072: * cholmesny Exp $
073: */
074: public class DataCoveragesNewAction extends ConfigAction {
075: public final static String NEW_COVERAGE_KEY = "newCoverage";
076:
077: public ActionForward execute(ActionMapping mapping,
078: ActionForm incomingForm, UserContainer user,
079: HttpServletRequest request, HttpServletResponse response)
080: throws ConfigurationException {
081: final DataCoveragesNewForm form = (DataCoveragesNewForm) incomingForm;
082: final String formatID = form.getSelectedNewCoverage();
083: final Data catalog = getData();
084: CoverageStoreInfo cvStoreInfo = catalog.getFormatInfo(formatID);
085:
086: if (cvStoreInfo == null) {
087: cvStoreInfo = new CoverageStoreInfo(getDataConfig()
088: .getDataFormat(formatID).toDTO(), catalog);
089: }
090:
091: CoverageConfig coverageConfig = newCoverageConfig(cvStoreInfo,
092: formatID, request);
093:
094: user.setCoverageConfig(coverageConfig);
095:
096: return mapping.findForward("config.data.coverage.editor");
097: }
098:
099: /**
100: * Static method so that the CoverageStore editor can do the same thing that the new one
101: * does.*/
102: public static CoverageConfig newCoverageConfig(
103: CoverageStoreInfo cvStoreInfo, String formatID,
104: HttpServletRequest request) throws ConfigurationException {
105: //GridCoverage gc = null;
106: final Format format = cvStoreInfo.getFormat();
107: AbstractGridCoverage2DReader reader = (AbstractGridCoverage2DReader) cvStoreInfo
108: .getReader();
109:
110: if (reader == null) {
111: reader = (AbstractGridCoverage2DReader) ((AbstractGridFormat) format)
112: .getReader(GeoserverDataDirectory
113: .findDataFile(cvStoreInfo.getUrl()));
114: }
115:
116: if (reader == null) {
117: throw new ConfigurationException(
118: "Could not obtain a reader for the CoverageDataSet. Please check the CoverageDataSet configuration!");
119: }
120:
121: CoverageConfig coverageConfig = new CoverageConfig(formatID,
122: format, reader, request);
123:
124: request.setAttribute(NEW_COVERAGE_KEY, "true");
125: request.getSession().setAttribute(DataConfig.SELECTED_COVERAGE,
126: coverageConfig);
127:
128: return coverageConfig;
129: }
130: }
|