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.vfny.geoserver.action.ConfigAction;
011: import org.vfny.geoserver.config.CoverageConfig;
012: import org.vfny.geoserver.config.CoverageStoreConfig;
013: import org.vfny.geoserver.config.DataConfig;
014: import org.vfny.geoserver.form.data.CoverageStoresEditorForm;
015: import org.vfny.geoserver.global.ConfigurationException;
016: import org.vfny.geoserver.global.CoverageStoreInfo;
017: import org.vfny.geoserver.global.UserContainer;
018: import java.io.IOException;
019: import java.util.Iterator;
020: import java.util.Map;
021: import javax.servlet.ServletException;
022: import javax.servlet.http.HttpServletRequest;
023: import javax.servlet.http.HttpServletResponse;
024:
025: /**
026: * DOCUMENT ME!
027: *
028: * @author $Author: Alessio Fabiani (alessio.fabiani@gmail.com) $ (last
029: * modification)
030: * @author $Author: Simone Giannecchini (simboss1@gmail.com) $ (last
031: * modification)
032: */
033: public final class CoverageStoresEditorAction extends ConfigAction {
034: public ActionForward execute(ActionMapping mapping,
035: ActionForm form, UserContainer user,
036: HttpServletRequest request, HttpServletResponse response)
037: throws ConfigurationException, IOException,
038: ServletException {
039: CoverageStoresEditorForm dataFormatsForm = (CoverageStoresEditorForm) form;
040: String dataFormatID = dataFormatsForm.getDataFormatId();
041: String namespace = dataFormatsForm.getNamespaceId();
042: String type = dataFormatsForm.getType();
043: String url = dataFormatsForm.getUrl();
044: String description = dataFormatsForm.getDescription();
045:
046: DataConfig dataConfig = (DataConfig) getDataConfig();
047: CoverageStoreConfig config = null;
048:
049: config = (CoverageStoreConfig) dataConfig
050: .getDataFormat(dataFormatID);
051:
052: boolean newCoverageFlag = false;
053:
054: if (config == null) {
055: // we are creating a new one.
056: dataConfig.addDataFormat(getUserContainer(request)
057: .getDataFormatConfig());
058: config = (CoverageStoreConfig) dataConfig
059: .getDataFormat(dataFormatID);
060: newCoverageFlag = true;
061: }
062:
063: // /////////////////////////////////////////////////////////////////
064: //
065: // If we got here everything was fine then we can save the
066: // configuration.
067: //
068: // ///////////////////////////////////////////////////////////////
069: boolean enabled = dataFormatsForm.isEnabled();
070:
071: if (dataFormatsForm.isEnabledChecked() == false) {
072: enabled = false;
073: }
074:
075: config.setEnabled(enabled);
076: config.setNameSpaceId(namespace);
077: config.setType(type);
078: config.setUrl(url);
079: config.setAbstract(description);
080: dataConfig.addDataFormat(config);
081: getUserContainer(request).setDataFormatConfig(null);
082: getApplicationState().notifyConfigChanged();
083:
084: CoverageStoreInfo cvStoreInfo = new CoverageStoreInfo(config
085: .toDTO(), getData());
086:
087: if (newCoverageFlag) {
088: //if we're making a new coverage store, then go ahead and create the new coverage and
089: //forward to the editor
090: CoverageConfig coverageConfig = DataCoveragesNewAction
091: .newCoverageConfig(cvStoreInfo, dataFormatID,
092: request);
093: user.setCoverageConfig(coverageConfig);
094:
095: return mapping.findForward("config.data.coverage.editor");
096: } else {
097: // For now we're only not forwarding to the coverage editor if this is a coverage store edit
098: //(instead of a new one. In the future with nD coverage support we'll also want to check
099: //that the coverage store only has one potential coverage, since if not then we don't want
100: //to force people to edit the first one.
101: return mapping.findForward("config.data.format");
102: }
103: }
104:
105: /** Used to debug connection parameters */
106: public void dump(String msg, Map params) {
107: if (msg != null) {
108: System.out.print(msg + " ");
109: }
110:
111: System.out.print(": { ");
112:
113: for (Iterator i = params.entrySet().iterator(); i.hasNext();) {
114: Map.Entry entry = (Map.Entry) i.next();
115: System.out.print(entry.getKey());
116: System.out.print("=");
117: dump(entry.getValue());
118:
119: if (i.hasNext()) {
120: System.out.print(", ");
121: }
122: }
123:
124: System.out.println("}");
125: }
126:
127: public void dump(Object obj) {
128: if (obj == null) {
129: System.out.print("null");
130: } else if (obj instanceof String) {
131: System.out.print("\"");
132: System.out.print(obj);
133: System.out.print("\"");
134: } else {
135: System.out.print(obj);
136: }
137: }
138:
139: public void dump(String msg, Object[] array) {
140: if (msg != null) {
141: System.out.print(msg + " ");
142: }
143:
144: System.out.print(": ");
145:
146: if (array == null) {
147: System.out.print("null");
148:
149: return;
150: }
151:
152: System.out.print("(");
153:
154: for (int i = 0; i < array.length; i++) {
155: dump(array[i]);
156:
157: if (i < (array.length - 1)) {
158: System.out.print(", ");
159: }
160: }
161:
162: System.out.println(")");
163: }
164: }
|