Author: julien(a)jboss.com
Date: 2008-02-06 19:07:31 -0500 (Wed, 06 Feb 2008)
New Revision: 9819
Removed:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/ControllerServlet.java
Log:
removed what idea should have removed
Deleted:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/ControllerServlet.java
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/ControllerServlet.java 2008-02-06
23:49:49 UTC (rev 9818)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/ControllerServlet.java 2008-02-07
00:07:31 UTC (rev 9819)
@@ -1,221 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2008, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portal.portlet.test.jsp;
-
-import org.jboss.portal.portlet.test.jsp.response.Chunk;
-import org.jboss.portal.portlet.test.jsp.response.BytesChunk;
-import org.jboss.portal.portlet.test.jsp.response.CharsChunk;
-import org.jboss.portal.portlet.test.jsp.response.PortletChunk;
-import org.jboss.portal.portlet.PortletInvoker;
-import org.jboss.portal.portlet.PortletInvokerException;
-import org.jboss.portal.portlet.invocation.response.PortletInvocationResponse;
-import org.jboss.portal.portlet.invocation.response.FragmentResponse;
-import org.jboss.portal.portlet.controller.PortletController;
-import org.jboss.portal.portlet.controller.response.ControllerResponse;
-import org.jboss.portal.portlet.controller.response.PageUpdateResponse;
-import org.jboss.portal.portlet.controller.response.ResourceResponse;
-import org.jboss.portal.portlet.controller.state.PageNavigationalState;
-import org.jboss.portal.common.io.IOTools;
-
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import javax.servlet.ServletException;
-import javax.servlet.ServletOutputStream;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.io.Writer;
-import java.util.Map;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 630 $
- */
-public class ControllerServlet extends HttpServlet
-{
-
- protected void service(HttpServletRequest req, HttpServletResponse resp) throws
ServletException, IOException
- {
- try
- {
- _service(req, resp);
- }
- catch (ClassNotFoundException e)
- {
- throw new ServletException(e);
- }
- }
-
- protected void _service(HttpServletRequest req, HttpServletResponse resp) throws
ServletException, IOException, ClassNotFoundException
- {
- PortletInvoker invoker =
(PortletInvoker)getServletContext().getAttribute("ConsumerPortletInvoker");
-
- //
- PagePortletControllerContext context = new PagePortletControllerContext(req, resp,
getServletContext(), invoker);
-
- //
- PageNavigationalState pageState = null;
- if (context.getRequest() != null)
- {
- ControllerResponse controllerResponse;
- try
- {
- controllerResponse = new PortletController().process(context.getRequest());
- }
- catch (PortletInvokerException e)
- {
- throw new ServletException(e);
- }
-
- //
- if (controllerResponse instanceof PageUpdateResponse)
- {
- PageUpdateResponse pageUpdate = (PageUpdateResponse)controllerResponse;
- pageState = pageUpdate.getPageState();
- }
- else if (controllerResponse instanceof ResourceResponse)
- {
- ResourceResponse resourceResponse = (ResourceResponse)controllerResponse;
- PortletInvocationResponse pir = resourceResponse.response;
-
- //
- if (pir instanceof FragmentResponse)
- {
- FragmentResponse fragment = (FragmentResponse)pir;
-
- //
- if (fragment.getType() == FragmentResponse.TYPE_EMPTY)
- {
- resp.setStatus(HttpServletResponse.SC_NO_CONTENT);
- }
- else
- {
- String contentType = fragment.getContentType();
- if (contentType != null)
- {
- resp.setContentType(contentType);
- }
-
- //
- if (fragment.getType() == FragmentResponse.TYPE_BYTES)
- {
- ServletOutputStream out = null;
- try
- {
- out = resp.getOutputStream();
- out.write(fragment.getBytes().toByteArray());
- }
- finally
- {
- IOTools.safeClose(out);
- }
- }
- else
- {
- Writer writer = null;
- try
- {
- writer = resp.getWriter();
- writer.write(fragment.getChars().toString());
- }
- finally
- {
- writer.close();
- }
- }
- }
- }
- else
- {
- // todo
- }
- }
- else
- {
- // todo
- }
- }
-
- //
- Page page = context.getPage();
-
- //
- Map<String, PortletInvocationResponse> responses = page.render(context,
pageState);
-
- //
- resp.setContentType("text/html");
- PrintWriter writer = resp.getWriter();
- int count = 0;
- for (Chunk chunk : page.getChunks())
- {
- if (chunk instanceof BytesChunk)
- {
- BytesChunk bytesChunk = (BytesChunk)chunk;
- writer.write(new String(bytesChunk.getBytes()));
- }
- else if (chunk instanceof CharsChunk)
- {
- CharsChunk bytesChunk = (CharsChunk)chunk;
- writer.write(bytesChunk.getChars());
- }
- else if (chunk instanceof PortletChunk)
- {
- PortletChunk portletChunk = (PortletChunk)chunk;
- String windowId = "" + count++;
-
- PortletInvocationResponse response = responses.get(windowId);
- if (response != null)
- {
- if (response instanceof FragmentResponse)
- {
- FragmentResponse fragment = (FragmentResponse)response;
- if (fragment.getType() != FragmentResponse.TYPE_EMPTY)
- {
- String frag;
- if (fragment.getType() == FragmentResponse.TYPE_BYTES)
- {
- frag = fragment.getBytes().toString();
- }
- else
- {
- frag = fragment.getChars().toString();
- }
-
- //
- writer.write(frag);
- }
- }
- else
- {
- writer.write(response.getClass().getSimpleName() + "[" +
portletChunk.getPortletName() + "," + portletChunk.getApplicationName() +
"]");
- }
- }
- else
- {
- writer.write("Empty[" + portletChunk.getPortletName() +
"," + portletChunk.getApplicationName() + "]");
- }
- }
- }
- writer.close();
- }
-}