001: /******************************************************************************
002: * JBoss, a division of Red Hat *
003: * Copyright 2006, Red Hat Middleware, LLC, and individual *
004: * contributors as indicated by the @authors tag. See the *
005: * copyright.txt in the distribution for a full listing of *
006: * individual contributors. *
007: * *
008: * This is free software; you can redistribute it and/or modify it *
009: * under the terms of the GNU Lesser General Public License as *
010: * published by the Free Software Foundation; either version 2.1 of *
011: * the License, or (at your option) any later version. *
012: * *
013: * This software is distributed in the hope that it will be useful, *
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
016: * Lesser General Public License for more details. *
017: * *
018: * You should have received a copy of the GNU Lesser General Public *
019: * License along with this software; if not, write to the Free *
020: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
021: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
022: ******************************************************************************/package org.jboss.portal.theme.servlet;
023:
024: import org.jboss.logging.Logger;
025:
026: import javax.servlet.ServletException;
027: import javax.servlet.http.HttpServlet;
028: import javax.servlet.http.HttpServletRequest;
029: import javax.servlet.http.HttpServletResponse;
030: import java.io.IOException;
031: import java.util.Date;
032: import java.util.Enumeration;
033:
034: /**
035: * @author <a href="mailto:tomasz.szymanski@jboss.com">Tomasz Szymanski</a>
036: * @author <a href="mailto:roy@jboss.org">Roy Russo</a>
037: */
038:
039: public class DynaAjaxServlet extends HttpServlet {
040: private final static Logger log = Logger
041: .getLogger(DynaAjaxServlet.class);
042:
043: public void doGet(HttpServletRequest req, HttpServletResponse resp)
044: throws ServletException, IOException {
045: doPost(req, resp);
046: }
047:
048: public void doPost(HttpServletRequest req, HttpServletResponse resp)
049: throws ServletException, IOException {
050: Enumeration paramNames = req.getParameterNames();
051: String response = "";
052: while (paramNames.hasMoreElements()) {
053: String name = (String) paramNames.nextElement();
054: // action: windowremove|windowmove
055: if ("action".equalsIgnoreCase(name)) {
056: response = req.getParameter(name);
057: }
058: System.out.println("Parameter: " + name + " = "
059: + req.getParameter(name));
060: }
061:
062: sendResp(resp, response);
063:
064: /*
065: if(req.getParameter("action") != null)
066: {
067: if(req.getParameter("action").equals(PERSIST))
068: {
069: if(req.getParameter("positionNo") == null
070: || req.getParameter("windowId") == null
071: || req.getParameter("oldRegionId") == null
072: || req.getParameter("newRegionId") == null)
073: {
074: resp.sendError(400, "Not enought parameters");
075: return;
076: }
077:
078: if(!testMode)
079: {
080: persistance.persistPosition(req.getParameter("positionNo"),
081: req.getParameter("windowId"), req
082: .getParameter("oldRegionId"), req
083: .getParameter("newRegionId"));
084: }
085:
086: sendResp(resp, "Position persisted");
087: }
088: else if(req.getParameter("action").equals(TEST_MODE))
089: {
090: if(req.getParameter("mode") != null)
091: {
092: try
093: {
094: testMode = Boolean.valueOf(req.getParameter("mode"))
095: .booleanValue();
096: }
097: catch(RuntimeException e)
098: {
099: resp.sendError(400, "Bad arguments");
100: return;
101: }
102:
103: sendResp(resp, ((testMode) ? "Test mode ON" : "Test mode OFF"));
104:
105: }
106: else
107: {
108: resp.sendError(400, "Not enought parameters");
109: return;
110: }
111: }
112: else
113: {
114: resp.sendError(400, "Unknown ajax call");
115: return;
116: }
117: }
118: */
119: }
120:
121: private void sendResp(HttpServletResponse resp, String respData)
122: throws IOException {
123: resp.setHeader("Expires", "Mon, 26 Jul 1997 05:00:00 GMT");
124: resp.setDateHeader("Last-Modified", new Date().getTime());
125: resp.setHeader("Cache-Control",
126: "no-store, no-cache, must-revalidate");
127: resp.addHeader("Cache-Control", "post-check=0, pre-check=0");
128: resp.setContentType("text/html");
129:
130: resp.getWriter().write(respData);
131: }
132:
133: }
|