All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.vfny.geoserver.action.DemoAction Maven / Gradle / Ivy

There is a newer version: 1.7.0
Show newest version
/* 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.action;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.vfny.geoserver.form.DemoForm;
import org.vfny.geoserver.util.Requests;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * This Action handles all the buttons for the Demo.jsp page.
 *
 * 

* This one is more complicated then usual since not all the actions require * the form bean to be validated! I am going to have to hack a little bit to * make that happen, I may end up making the form bean validation differ * depending on the selected action. *

* *

* Buttons that make this action go: * *

    *
  • * Submit: submit the request specified by url and post fields (Should be done * using Javascript locally) *
  • *
  • * Change: select between the precanned demos *
  • *
* * As usual we will have to uninternationlize the action name provided to us. *

* * @author Richard Gould * @author Jody Garnett * @author $Author: Alessio Fabiani ([email protected]) $ (last modification) * @author $Author: Simone Giannecchini ([email protected]) $ (last modification) */ public class DemoAction extends GeoServerAction { public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { DemoForm demoForm = (DemoForm) form; File dir = demoForm.getDir(); String demo = demoForm.getDemo(); String baseUrl = Requests.getBaseUrl(request, getGeoServer()); if (demo.equals("")) { demoForm.setUrl(baseUrl); demoForm.setBody(""); } String service = demo.substring(0, demo.indexOf('_')).toLowerCase(); String url = Requests.getBaseUrl(request, getGeoServer()) + service; File file = new File(dir, demo); BufferedReader reader = new BufferedReader(new FileReader(file)); StringBuffer buf = new StringBuffer(); for (String line = reader.readLine(); line != null; line = reader.readLine()) { buf.append(line); buf.append("\n"); } if (demo.endsWith(".url")) { demoForm.setUrl(baseUrl + buf.toString()); demoForm.setBody(""); } else { //demo.endsWith(.xml), but not yet for backwards compatibility. demoForm.setUrl(url); demoForm.setBody(buf.toString()); } // return back to the admin demo // return mapping.findForward("welcome.demo"); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy