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:
006: /*
007: * Created on Jan 6, 2004
008: *
009: * To change the template for this generated file go to
010: * Window>Preferences>Java>Code Generation>Code and Comments
011: */
012: package org.vfny.geoserver.action;
013:
014: import java.io.IOException;
015: import java.util.HashMap;
016: import java.util.Map;
017:
018: import javax.servlet.ServletException;
019: import javax.servlet.http.HttpServletRequest;
020: import javax.servlet.http.HttpServletResponse;
021:
022: import org.apache.struts.action.ActionForm;
023: import org.apache.struts.action.ActionForward;
024: import org.apache.struts.action.ActionMapping;
025: import org.vfny.geoserver.global.ConfigurationException;
026: import org.vfny.geoserver.global.UserContainer;
027: import org.vfny.geoserver.global.dto.DataDTO;
028: import org.vfny.geoserver.global.dto.GeoServerDTO;
029: import org.vfny.geoserver.global.dto.WCSDTO;
030: import org.vfny.geoserver.global.dto.WFSDTO;
031: import org.vfny.geoserver.global.dto.WMSDTO;
032:
033: /**
034: * Update GeoServer with the current configuration.
035: *
036: * <p>
037: * This is a real ConfigAction - you need to be logged in to use it.
038: * </p>
039: *
040: * @author User To change the template for this generated type comment go to
041: * Window>Preferences>Java>Code Generation>Code and Comments
042: */
043: public class UpdateGSAction extends ConfigAction {
044: public ActionForward execute(ActionMapping mapping,
045: ActionForm form, UserContainer user,
046: HttpServletRequest request, HttpServletResponse response)
047: throws IOException, ServletException {
048:
049: updateGeoserver(mapping, form, request, response);
050: updateValidation(mapping, form, request, response);
051:
052: getApplicationState().fireChange();
053: return mapping.findForward("config");
054: }
055:
056: public ActionForward updateGeoserver(ActionMapping mapping,
057: ActionForm form,
058: // UserContainer user,
059: HttpServletRequest request, HttpServletResponse response)
060: throws IOException, ServletException {
061:
062: try {
063: WCSDTO wcsDTO = getWCSConfig().toDTO();
064: WMSDTO wmsDTO = getWMSConfig().toDTO();
065: WFSDTO wfsDTO = getWFSConfig().toDTO();
066: GeoServerDTO geoserverDTO = getGlobalConfig().toDTO();
067: DataDTO dataDTO = getDataConfig().toDTO();
068:
069: //we're updating...increment the updateSequence
070: final int gsUs = geoserverDTO.getUpdateSequence();
071: geoserverDTO.setUpdateSequence(gsUs + 1);
072:
073: //load each service global bean from the modified config DTO
074: getWCS(request).load(wcsDTO);
075: getWFS(request).load(wfsDTO);
076: getWMS(request).load(wmsDTO);
077:
078: //also, don't forget to update the main global config with the changes to the updatesequence
079: getGlobalConfig().update(geoserverDTO);
080:
081: //load the main geoserver bean from the modified config DTO
082: getWCS(request).getGeoServer().load(geoserverDTO);
083: //load the data bean from the modified config DTO
084: getWFS(request).getData().load(dataDTO);
085:
086: } catch (ConfigurationException e) {
087: e.printStackTrace();
088: throw new ServletException(e);
089: }
090:
091: // We need to stay on the same page!
092: getApplicationState(request).notifyToGeoServer();
093:
094: return mapping.findForward("config");
095: }
096:
097: public ActionForward updateValidation(ActionMapping mapping,
098: ActionForm form,
099: // UserContainer user,
100: HttpServletRequest request, HttpServletResponse response)
101: throws IOException, ServletException {
102:
103: try {
104: Map plugins = new HashMap();
105: Map testSuites = new HashMap();
106:
107: if (getValidationConfig().toDTO(plugins, testSuites)) {
108: //sorry, no time to really test this, but I got a null pointer
109: //exception with the demo build target. ch
110: if (getWFS(request).getValidation() != null) {
111: getWFS(request).getValidation().load(testSuites,
112: plugins);
113: }
114: } else {
115: throw new ConfigurationException(
116: "ValidationConfig experienced an error exporting Data Transpher Objects.");
117: }
118: } catch (ConfigurationException e) {
119: e.printStackTrace();
120: throw new ServletException(e);
121: }
122:
123: // We need to stay on the same page!
124: getApplicationState(request).notifyToGeoServer();
125:
126: return mapping.findForward("config.validation");
127: }
128: }
|