/* * * Copyright (c) 1998 The Java Apache Project. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. Every modification must be notified to the Java Apache Project * and redistribution of the modified code without prior notification * is not permitted in any form. * * 4. All advertising materials mentioning features or use of this * software must display the following acknowledgment: * "This product includes software developed by the Java Apache Project * (http://java.apache.org/)." * * 5. The names "JetSpeed", "Apache JetSpeed" and "Apache JetSpeed * Project" must not be used to endorse or promote products * derived from this software without prior written permission. * * 6. Redistributions of any form whatsoever must retain the following * acknowledgment: * "This product includes software developed by the Java Apache Project * (http://java.apache.org/)." * * THIS SOFTWARE IS PROVIDED BY THE JAVA APACHE PROJECT "AS IS" AND ANY * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE JAVA APACHE PROJECT OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. * * License version 1.0 * */ package org.apache.jetspeed.turbine.screens.portlets; //jetspeed stuff. import org.apache.jetspeed.*; import org.apache.jetspeed.util.*; import org.apache.jetspeed.portal.*; import org.apache.jetspeed.portal.factory.*; import org.apache.jetspeed.portal.portlets.*; import org.apache.jetspeed.portal.portletmarkup.*; import org.apache.ecs.*; //servlet import javax.servlet.*; import javax.servlet.http.*; //standard java stuff import java.io.*; import java.net.*; import java.util.*; //ecs support import org.apache.ecs.*; import org.apache.ecs.html.*; //Turbine support import org.apache.turbine.modules.*; import org.apache.turbine.util.*; /** Servlet which renders a portlet @author Kevin Burton @version $Id$ */ public class PortletViewerScreen extends Screen { /* The following are excepted as HTTP parameters and are acted on: url: The URL to be passed to the portlet config. classname: The Class name of the portlet to be rendered */ public ConcreteElement build( RunData rundata ) { HttpServletRequest request = rundata.getRequest(); HttpServletResponse response = rundata.getResponse(); ElementContainer root = new ElementContainer(); String classname = request.getParameter("classname"); if (classname == null) { root.addElement( this.getClassName() ); return null; } String url = request.getParameter("url"); try { Portlet portlet = PortletFactory.getInstance( rundata ).getPortlet( classname, url, rundata ); PortletControl control = PortletControlFactory.getInstance( portlet ); control.setWidth( "100%" ); PortletController pc = PortletControllerFactory.getInstance( control ); root.addElement( pc.getContent() ); } catch (PortletException e) { System.err.println("ERROR: Tried to render portlet: " + classname ); System.err.println("ERROR: With the URL of: " + url ); e.printStackTrace(); return null; } return root; } /** @author Kevin Burton @version $Id$ */ public static String getURL( String classname, String url, RunData rundata ) { Entry entry = new Entry(); entry.setClassname( classname ); entry.setUrl( url ); return getURL( entry, rundata ); } /** Determine how to fetch a single portlet based on classname and url. Everytime you want to view an individual Portlet you should call this method @author Kevin Burton @version $Id$ */ public static String getURL( Entry entry, RunData rundata ) { DynamicURI uri = new DynamicURI( rundata, "portlets.PortletViewerScreen" ); if (entry.getClassname() != null) { uri.addQueryData( "classname", entry.getClassname() ); } if (entry.getUrl() != null) { uri.addQueryData( "url", entry.getUrl() ); } Parameter[] param = entry.getParameter(); for (int i = 0; i < param.length; ++i ) { String name = param[i].getName(); String value = param[i].getValue(); if (value != null) { uri.addQueryData( name, value ); } } return uri.toString(); } /** @author Kevin Burton @version $Id$ */ //FIX ME: This should use ECS private ConcreteElement getUrlPrompt() { return new P("The URL you specified is invalid. Please specifiy another.") .addElement( new Form() ) .addElement( new Input().setType("text").setName("url")) .addElement( new BR() ) .addElement( new Input().setType("submit")); } private ConcreteElement getClassName() { return new P("The ClassName you specified is invalid. Please specifiy another.") .addElement( new Form() ) .addElement( new Input().setType("text").setName("classname")) .addElement( new BR() ) .addElement( new Input().setType("submit")); } }