org.gatein.pc.samples.remotecontroller.RemoteControllerPortlet Maven / Gradle / Ivy
/*
* JBoss, a division of Red Hat
* Copyright 2010, 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.gatein.pc.samples.remotecontroller;
import javax.portlet.GenericPortlet;
import javax.portlet.PortletException;
import javax.portlet.PortletURL;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import javax.portlet.ResourceRequest;
import javax.portlet.ResourceResponse;
import javax.portlet.ResourceURL;
import javax.portlet.WindowState;
import java.io.IOException;
import java.io.PrintWriter;
/**
* @author Chris Laprun
* @version $Revision: 9979 $
*/
public class RemoteControllerPortlet extends GenericPortlet
{
private static final String ZIPCODE = "zipcode";
@Override
protected void doView(RenderRequest renderRequest, RenderResponse renderResponse) throws PortletException, IOException
{
renderResponse.setContentType("text/html");
PrintWriter printWriter = renderResponse.getWriter();
String namespace = "n_" + renderResponse.getNamespace();
printWriter.print("");
}
@Override
protected void doHeaders(RenderRequest renderRequest, RenderResponse renderResponse)
{
PrintWriter printWriter = null;
try
{
printWriter = renderResponse.getWriter();
String namespace = "n_" + renderResponse.getNamespace();
String remoteWindowName = namespace + "_remote";
printWriter.print("");
}
catch (IOException e)
{
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
}
@Override
public void serveResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws PortletException, IOException
{
String id = resourceRequest.getResourceID();
if (id == null)
{
resourceResponse.setContentType("text/html");
PrintWriter writer = resourceResponse.getWriter();
String namespace = "n_" + resourceResponse.getNamespace();
writer.print("\n");
PortletURL url = resourceResponse.createRenderURL();
url.setWindowState(WindowState.MINIMIZED);
writer.print("- minimize parent portlet
");
url.setWindowState(WindowState.MAXIMIZED);
writer.print("- maximize parent portlet
");
url.setWindowState(WindowState.NORMAL);
writer.print("- make parent portlet normal
");
writer.print("
- ");
url = resourceResponse.createRenderURL();
writer.print("Set value of 'zipcode' public render parameter to:
");
url.setParameter(ZIPCODE, "80201");
writer.print("- Denver, CO");
url.setParameter(ZIPCODE, "94102");
writer.print("
- San Francisco, CA");
url.setParameter(ZIPCODE, "20001");
writer.print("
- Washington, DC");
writer.print("
");
}
else
{
throw new IllegalArgumentException("Don't know how to handle resource: " + id);
}
}
private String createParentURL(PortletURL url)
{
return "openLinkInParent('" + url + "')";
}
}