You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by ta...@apache.org on 2004/06/26 03:23:40 UTC
cvs commit: jakarta-jetspeed/fusion/src/java/org/apache/jetspeed/fusion/portal/portlets/streaming FusionServletOutputStream.java FusionResponseWrapper.java
taylor 2004/06/25 18:23:40
Added: fusion/src/java/org/apache/jetspeed/fusion/modules/actions/portlets
CustomizeJSR168Action.java FusionEndCustomize.java
fusion/src/java/org/apache/jetspeed/fusion/services/fusion
FusionServiceImpl.java FusionService.java
fusion/src/java/org/apache/jetspeed/fusion/portal/portlets
JetspeedFusionPortlet.java
fusion/src/java/org/apache/jetspeed/fusion/tools/pamanager
FusionCatalinaPAM.java FusionPAM.java
fusion/src/java/org/apache/jetspeed/fusion/modules/actions
FusionAccessController.java
fusion/src/java/org/apache/jetspeed/fusion/services/resources
FusionResources.java
fusion/src/java/org/apache/jetspeed/fusion/portal/portlets/streaming
FusionServletOutputStream.java
FusionResponseWrapper.java
Log:
Fusion Implementation -- Java code (JSR-168 support in J1)
CVS: ----------------------------------------------------------------------
CVS: PR:
CVS: If this change addresses a PR in the problem report tracking
CVS: database, then enter the PR number(s) here.
CVS: Obtained from:
CVS: If this change has been taken from another system, such as NCSA,
CVS: then name the system in this line, otherwise delete it.
CVS: Submitted by:
CVS: If this code has been contributed to Apache by someone else; i.e.,
CVS: they sent us a patch or a new module, then include their name/email
CVS: address here. If this is your work then delete this line.
CVS: Reviewed by:
CVS: If we are doing pre-commit code reviews and someone else has
CVS: reviewed your changes, include their name(s) here.
CVS: If you have not had it reviewed then delete this line.
Revision Changes Path
1.1 jakarta-jetspeed/fusion/src/java/org/apache/jetspeed/fusion/modules/actions/portlets/CustomizeJSR168Action.java
Index: CustomizeJSR168Action.java
===================================================================
package org.apache.jetspeed.fusion.modules.actions.portlets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.prefs.BackingStoreException;
import java.util.prefs.Preferences;
import org.apache.jetspeed.Jetspeed;
import org.apache.jetspeed.components.persistence.store.PersistenceStore;
import org.apache.jetspeed.components.portletregistry.PortletRegistryComponent;
import org.apache.jetspeed.fusion.services.resources.FusionResources;
import org.apache.jetspeed.modules.actions.portlets.CustomizeSetAction;
import org.apache.jetspeed.modules.actions.portlets.VelocityPortletAction;
import org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite;
import org.apache.jetspeed.om.common.preference.PreferenceComposite;
import org.apache.jetspeed.om.registry.Parameter;
import org.apache.jetspeed.om.registry.PortletEntry;
import org.apache.jetspeed.portal.Portlet;
import org.apache.jetspeed.portal.PortletInstance;
import org.apache.jetspeed.portal.portlets.VelocityPortlet;
import org.apache.jetspeed.prefs.PropertyManager;
import org.apache.jetspeed.services.Registry;
import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
import org.apache.jetspeed.services.logging.JetspeedLogger;
import org.apache.jetspeed.services.persistence.PersistenceManager;
import org.apache.jetspeed.services.rundata.JetspeedRunData;
import org.apache.jetspeed.userinfo.UserInfoManager;
import org.apache.jetspeed.util.PortletConfigState;
import org.apache.pluto.om.common.PreferenceSet;
import org.apache.turbine.util.RunData;
import org.apache.velocity.context.Context;
/**
* @author Jeremy
*
*
*/
public class CustomizeJSR168Action extends VelocityPortletAction
{
/**
* Static initialization of the logger for this class
*/
private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(CustomizeJSR168Action.class.getName());
private static final String PORTLET_APPLICATION_NAME = FusionResources.getString(FusionResources.PORTLET_APPLICATION_PARAMETER);
private static final String PORTLET_DEFINITION_NAME = FusionResources.getString(FusionResources.PORTLET_DEFINITION_PARAMETER);
/**
* Subclasses must override this method to provide default behavior
* for the portlet action
*
* <table>
* <tr><th>Context </th><th> Description</th></tr>
* <!-- --------- ------------------------- -->
* <tr><td>action </td><td> Action to use</td></tr>
* <tr><td>current_skin </td><td> Current skin for this portlet INSTANCE</td></tr>
* <tr><td>params </td><td> List of configurable parameters from the REGISTRY entry.</td></tr>
* <tr><td>portlet </td><td> Portlet, not the Portlet Instance!</td></tr>
* <tr><td>skins </td><td> List of skins</td></tr>
* <tr><td>security </td><td> List of security ref</td></tr>
* <tr><td>security_ref </td><td> Current securityRef for this portlet INSTANCE</td></tr>
* </table>
*/
protected void buildNormalContext( VelocityPortlet portlet,
Context context,
RunData rundata )
{
// generic context stuff
context.put("skins", CustomizeSetAction.buildList(rundata, Registry.SKIN));
context.put("securitys", CustomizeSetAction.buildList(rundata, Registry.SECURITY));
// we should first retrieve the portlet to customize
Portlet p = ((JetspeedRunData)rundata).getCustomized();
PortletInstance instance = PersistenceManager.getInstance(p, rundata);
context.put("portlet_instance", PersistenceManager.getInstance(p, rundata));
if (p==null) return;
// retrieve the portlet parameters
PortletEntry entry = (PortletEntry)Registry.getEntry(Registry.PORTLET,p.getName());
if(entry != null)
{
Parameter portletAppParam = entry.getParameter(PORTLET_APPLICATION_NAME);
Parameter portletDefParam = entry.getParameter(PORTLET_DEFINITION_NAME);
if(portletAppParam != null && portletDefParam != null)
{
String portletApp = portletAppParam.getValue();
String portletDef = portletDefParam.getValue();
//String portletApp = PortletConfigState.getConfigParameter(p, PORTLET_APPLICATION_NAME, null);
//String portletDef = PortletConfigState.getConfigParameter(p, PORTLET_DEFINITION_NAME, null);
String uniqueId = portletApp + "::" + portletDef;
logger.debug("Pref UniqueID: " + uniqueId);
System.out.println("Pref UniqueID: " + uniqueId);
HashMap allPrefs = new HashMap();
logger.info("MY ACTION FIRED!!!!");
System.out.println("MY ACTION FIRED!!!!");
String entityId = "5"; //Preference Portlet
String userPrefsNode = "/user/" + rundata.getUser().getUserName() + "/portletprefs/" + entityId;
String entityPrefsNode = "/System/Jetspeed/entities/" + entityId;
System.out.println("UserPrefNode: " + userPrefsNode);
System.out.println("EntityPrefNode: " + entityPrefsNode);
//TODO: get prefs from user and entity, add to hash
PortletRegistryComponent registry = (PortletRegistryComponent) Jetspeed.getComponentManager().getComponent(PortletRegistryComponent.class);
//PersistenceStore store = registry.getPersistenceStore();
//store.getTransaction().begin();
PortletDefinitionComposite pdef = registry.getPortletDefinitionByUniqueName(uniqueId);
PreferenceSet prefSet = pdef.getPreferenceSet();
Iterator prefIter = prefSet.iterator();
while (prefIter.hasNext())
{
PreferenceComposite pref = (PreferenceComposite) prefIter.next();
String prefName = pref.getName();
String prefType = pref.getType();
if(!allPrefs.containsKey(prefName))
{
String[] values = pref.getValueArray();
logger.debug("Found default pref " + prefName + " with type " + prefType + " with values " + values);
System.out.println("Found default pref " + prefName + " with type " + prefType + " with values " + values);
List valueList = arrayToList(values);
if(valueList != null)
{
allPrefs.put(prefName, valueList);
}
}
}
//store.getTransaction().commit();
context.put("preferences", allPrefs);
}
}
/*
PropertyManager pm = (PropertyManager) Jetspeed.getEngine().getComponentManager().getComponent(PropertyManager.class);
String node = "/user/" + rundata.getUser().getUserName();
Preferences userPrefs = Preferences.userRoot().node(node);
try
{
String[] children = userPrefs.childrenNames();
if(children != null)
{
for(int i=0; i<children.length; i++)
{
String child = children[i];
Preferences childPref = userPrefs.node(child);
}
}
} catch (BackingStoreException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
*/
context.put("action", "portlets.CustomizeJSR168Action");
}
/**
* This is untested!!!!
*
* @param preferences
* @param userNode
*/
private void getUserPreferences(Map preferences, String userNode)
{
boolean nodeExists = false;
try
{
nodeExists = Preferences.userRoot().nodeExists(userNode);
}
catch (BackingStoreException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
if(nodeExists)
{
Preferences userPrefs = Preferences.userRoot().node(userNode);
String[] childNames = null;
try
{
//will keys work just as well
childNames = userPrefs.childrenNames();
} catch (BackingStoreException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
if(childNames != null)
{
for(int i=0; i<childNames.length; i++)
{
String childName = childNames[i];
String value = userPrefs.get(childName, null);
ArrayList values = new ArrayList(1);
values.add(value);
preferences.put(childName, values);
}
}
}
}
private List arrayToList(String[] array)
{
ArrayList list = null;
if(array != null)
{
list = new ArrayList(array.length);
for(int i=0; i<array.length; i++)
{
list.add(array[i]);
}
}
return list;
}
}
1.1 jakarta-jetspeed/fusion/src/java/org/apache/jetspeed/fusion/modules/actions/portlets/FusionEndCustomize.java
Index: FusionEndCustomize.java
===================================================================
/*
* Copyright 2000-2001,2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.jetspeed.fusion.modules.actions.portlets;
import java.util.Iterator;
import org.apache.jetspeed.Jetspeed;
import org.apache.jetspeed.components.portletentity.PortletEntityAccessComponent;
import org.apache.jetspeed.components.portletregistry.PortletRegistryComponent;
import org.apache.jetspeed.fusion.services.resources.FusionResources;
import org.apache.jetspeed.modules.actions.controls.EndCustomize;
import org.apache.jetspeed.om.profile.Entry;
import org.apache.jetspeed.om.profile.Parameter;
import org.apache.jetspeed.om.profile.Portlets;
import org.apache.jetspeed.om.profile.Profile;
import org.apache.jetspeed.om.profile.psml.PsmlParameter;
import org.apache.jetspeed.om.registry.PortletEntry;
import org.apache.jetspeed.portal.Portlet;
import org.apache.jetspeed.services.PortletFactory;
import org.apache.jetspeed.services.Registry;
import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
import org.apache.jetspeed.services.logging.JetspeedLogger;
import org.apache.jetspeed.services.rundata.JetspeedRunData;
import org.apache.pluto.om.entity.PortletEntity;
import org.apache.pluto.om.portlet.PortletDefinition;
import org.apache.turbine.util.RunData;
/**
* This action must be invoked to clean up the customization
* state and redirect the user to his portal hompage
*
* @author <a href="mailto:taylorl@apache.org">David Sean Taylor</a>
*/
public class FusionEndCustomize extends EndCustomize
{
private static final JetspeedLogger log = JetspeedLogFactoryService.getLogger(FusionEndCustomize.class.getName());
private static final String PORTLET_APPLICATION_NAME = FusionResources.getString(FusionResources.PORTLET_APPLICATION_PARAMETER);
private static final String PORTLET_DEFINITION_NAME = FusionResources.getString(FusionResources.PORTLET_DEFINITION_PARAMETER);
private static final String JSR_PORTLET = FusionResources.getString(FusionResources.JSR168_PORTLET);
private static final String J2_ENTITY = FusionResources.getString(FusionResources.J2_ENTITY);
public void doPerform(RunData data) throws Exception
{
Profile profile = ((JetspeedRunData) data).getCustomizedProfile();
Portlets portlets = profile.getDocument().getPortlets();
if (portlets == null)
{
return;
}
int count = 0;
count = traverse(portlets, count);
if (count > 0)
{
JetspeedRunData jrun = (JetspeedRunData)data;
jrun.getCustomizedProfile().store();
System.out.println("Stored profile");
}
super.doPerform(data);
}
private int traverse(Portlets portlets, int count)
{
// First let's add all the Entries in the current level
Iterator eItr = portlets.getEntriesIterator();
while(eItr.hasNext())
{
Entry entry = (Entry)eItr.next();
Portlet portlet = null;
try
{
portlet = PortletFactory.getPortlet(entry);
}
catch (Exception e)
{
log.error("Could not create portlet for entry " + entry.getId(), e);
continue;
}
if (portlet == null)
{
log.error("Could not create portlet for entry " + entry.getId());
continue;
}
if (isFusionPortlet(portlet))
{
String pa = portlet.getPortletConfig().getInitParameter(PORTLET_APPLICATION_NAME, null);
String pd = portlet.getPortletConfig().getInitParameter(PORTLET_DEFINITION_NAME, null);
String registryKey = pa + "::" + pd;
Parameter param = entry.getParameter(J2_ENTITY);
if (param == null)
{
PortletRegistryComponent registryAccess =
(PortletRegistryComponent)Jetspeed.getComponentManager().getComponent(PortletRegistryComponent.class);
PortletEntityAccessComponent entityAccess =
(PortletEntityAccessComponent)Jetspeed.getComponentManager().getComponent(PortletEntityAccessComponent.class);
PortletDefinition portletDef = registryAccess.getPortletDefinitionByUniqueName(registryKey);
if (null == portletDef)
{
log.error("Could not find portlet definition in registry for " + registryKey);
continue;
}
PortletEntity entity = entityAccess.newPortletEntityInstance(portletDef);
try
{
entityAccess.storePortletEntity(entity);
param = new PsmlParameter();
param.setName(J2_ENTITY);
param.setValue(entity.getId().toString());
entry.addParameter(param);
count++;
}
catch (Exception e)
{
log.error("Failed to store portlet entity: " + registryKey, e);
continue;
}
}
}
// entries.add(new JetspeedPortletInstance(portlet, profile));
}
//Now if there are child levels, drill down recursively
if(portlets.getPortletsCount() > 0)
{
Iterator pItr = portlets.getPortletsIterator();
while(pItr.hasNext())
{
Portlets childPortlets = (Portlets)pItr.next();
count += traverse(childPortlets, count);
}
}
return count;
}
private boolean isFusionPortlet(Portlet entry)
{
// instanceof would sure be nice here, too bad about the wrappers
PortletEntry pe = (PortletEntry)
Registry.getEntry(Registry.PORTLET, entry.getName());
if (pe == null)
{
return false;
}
String parent = pe.getParent();
while (parent != null)
{
if (parent.equals(JSR_PORTLET))
{
return true;
}
pe = (PortletEntry)Registry.getEntry(Registry.PORTLET, parent);
if (pe == null)
{
break;
}
parent = pe.getParent();
}
return false;
}
}
1.1 jakarta-jetspeed/fusion/src/java/org/apache/jetspeed/fusion/services/fusion/FusionServiceImpl.java
Index: FusionServiceImpl.java
===================================================================
/*
* Copyright 2000-2001,2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.jetspeed.fusion.services.fusion;
import javax.servlet.ServletConfig;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.jetspeed.components.ComponentManager;
import org.apache.jetspeed.components.portletregistry.PortletRegistryComponent;
import org.apache.jetspeed.cps.CPSInitializationException;
import org.apache.jetspeed.cps.CommonPortletServices;
import org.apache.jetspeed.om.common.portlet.MutablePortletApplication;
import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
import org.apache.jetspeed.services.logging.JetspeedLogger;
import org.apache.pluto.om.portlet.PortletDefinition;
import org.apache.turbine.services.InitializationException;
import org.apache.turbine.services.TurbineBaseService;
import org.apache.turbine.services.TurbineServices;
import org.apache.turbine.services.resources.ResourceService;
// Fusion
import org.apache.jetspeed.Jetspeed;
import org.apache.jetspeed.engine.Engine;
import org.apache.jetspeed.exception.JetspeedException;
/**
* Fusion Service, this service fuses J2 into J1
*
* @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
* @version $Id: FusionServiceImpl.java,v 1.1 2004/06/26 01:23:40 taylor Exp $
*/
public class FusionServiceImpl extends TurbineBaseService
implements
FusionService
{
private static final JetspeedLogger log = JetspeedLogFactoryService.getLogger(FusionServiceImpl.class.getName());
private final static String CONFIG_PROPERTIES_FILE = "properties.file";
private final static String CONFIG_DEBUG = "debug";
private boolean debug = false;
private String propertiesFile = "/WEB-INF/conf/fusion.properties";
protected CommonPortletServices cps = null;
// Jetspeed engine
private Engine jetspeed = null;
/**
* This is the early initialization method called by the
* Turbine <code>Service</code> framework
* @param conf The <code>ServletConfig</code>
* @exception throws a <code>InitializationException</code> if the service
* fails to initialize
*/
public synchronized void init(ServletConfig conf)
throws InitializationException
{
// already initialized
if (getInit()) return;
System.out.println("Starting Up Fusion Service");
// get configuration parameters from Jetspeed Resources
ResourceService serviceConf = ((TurbineServices)TurbineServices.getInstance())
.getResources(FusionService.SERVICE_NAME);
propertiesFile = serviceConf.getString( CONFIG_PROPERTIES_FILE, propertiesFile );
debug = serviceConf.getBoolean(CONFIG_DEBUG, debug);
Configuration properties;
String applicationRoot;
try
{
applicationRoot = conf.getServletContext().getRealPath("/");
String realPath = conf.getServletContext().getRealPath(propertiesFile);
properties = (Configuration) new PropertiesConfiguration(realPath);
properties.setProperty(CommonPortletServices.APPLICATION_ROOT_KEY, applicationRoot);
System.out.println("APP ROOT = " + applicationRoot);
System.out.println("PROP FILE = " + realPath);
startFusion(properties, applicationRoot, conf);
}
catch (Throwable t)
{
t.printStackTrace();
log.error(t);
throw new InitializationException("Configure CPS Exception", t);
}
/*
try
{
// Start the CPS Manager
cps = CommonPortletServices.getInstance();
cps.init(properties, applicationRoot);
}
catch (CPSInitializationException e)
{
e.printStackTrace();
log.error(e);
throw new InitializationException("Initialize CPS Exception", e);
}
*/
System.out.println("Fusion Service: Initialization Done");
// initialization done
setInit(true);
}
public void shutdown()
{
System.out.println("Shutting down CPS Bridge");
Engine engine =Jetspeed.getEngine();
try
{
engine.shutdown();
}
catch (JetspeedException e)
{
System.out.println("ERROR: Shutting down CPS Bridge " + e);
}
System.out.println("D0NE: Shutting down CPS Bridge");
}
/**
* Fuse in J2
*
* @param configuration The properties file for J2
* @param applicationRoot The application root
* @param servletConfig
* @throws InitializationException
*/
public void startFusion(Configuration configuration, String applicationRoot, ServletConfig servletConfig)
throws InitializationException
{
try
{
// Start Jetspeed
Engine engine = Jetspeed.createEngine(configuration, applicationRoot, servletConfig);
engine.initContainer(servletConfig);
}
catch (Exception e)
{
throw new InitializationException("Failed to initialize Fusione engine", e);
}
}
private void testRegistryConnection()
throws InitializationException
{
try
{
ComponentManager cm = Jetspeed.getComponentManager();
PortletRegistryComponent registry = (PortletRegistryComponent)cm.getComponent(PortletRegistryComponent.class);
if (registry == null)
{
System.err.println("Failed to get registry component!");
return;
}
MutablePortletApplication pac = registry.getPortletApplication("jetspeed");
if (pac != null)
{
PortletDefinition portlet = pac.getPortletDefinitionByName("VelocityTwoColumns");
if (portlet != null)
{
System.out.println("REGISTRY TEST [READ PORTLET] ENTRY. Name[jetspeed] sucessful!");
}
else
{
throw new InitializationException(
"Registry Test: Load Portlet failed!, Portlet doesn't exist");
}
}
else
{
throw new InitializationException(
"Registry Test: Load Portlet Application failed!, Application doesn't exist");
}
}
catch(Throwable e)
{
System.out.println("REGISTRY TEST [READ PORTLET] ENTRY. Name[jetspeed] failed. Error[" + e + "]");
e.printStackTrace();
throw new InitializationException("JetspeedPortletRegistry.getPortletApplication failed" +
"Trace[" + e + "]", e);
}
}
}
1.1 jakarta-jetspeed/fusion/src/java/org/apache/jetspeed/fusion/services/fusion/FusionService.java
Index: FusionService.java
===================================================================
/*
* Copyright 2000-2001,2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.jetspeed.fusion.services.fusion;
import org.apache.turbine.services.Service;
/**
* Fusion Service
*
* @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
* @version $Id: FusionService.java,v 1.1 2004/06/26 01:23:40 taylor Exp $
*/
public interface FusionService extends Service
{
/** The name of this service */
public String SERVICE_NAME = "fusion";
}
1.1 jakarta-jetspeed/fusion/src/java/org/apache/jetspeed/fusion/portal/portlets/JetspeedFusionPortlet.java
Index: JetspeedFusionPortlet.java
===================================================================
/*
* Copyright 2000-2001,2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.jetspeed.fusion.portal.portlets;
import javax.portlet.PortletMode;
import javax.portlet.WindowState;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.ecs.ConcreteElement;
import org.apache.jetspeed.Jetspeed;
import org.apache.jetspeed.PortalReservedParameters;
import org.apache.jetspeed.components.portletentity.PortletEntityAccessComponent;
import org.apache.jetspeed.components.portletregistry.PortletRegistryComponent;
import org.apache.jetspeed.container.session.NavigationalState;
import org.apache.jetspeed.container.session.NavigationalStateComponent;
import org.apache.jetspeed.container.window.PortletWindowAccessor;
import org.apache.jetspeed.engine.Engine;
import org.apache.jetspeed.fusion.services.resources.FusionResources;
import org.apache.jetspeed.portal.PortletException;
import org.apache.jetspeed.portal.PortletInstance;
import org.apache.jetspeed.portal.portlets.AbstractInstancePortlet;
import org.apache.jetspeed.request.RequestContext;
import org.apache.jetspeed.request.RequestContextComponent;
import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
import org.apache.jetspeed.services.logging.JetspeedLogger;
import org.apache.jetspeed.services.rundata.JetspeedRunData;
import org.apache.jetspeed.util.JetspeedClearElement;
import org.apache.pluto.om.entity.PortletEntity;
import org.apache.pluto.om.portlet.PortletDefinition;
import org.apache.pluto.om.window.PortletWindow;
import org.apache.turbine.util.RunData;
/**
* JetspeedFusionPortlet
*
* @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
* @version $Id: JetspeedFusionPortlet.java,v 1.1 2004/06/26 01:23:40 taylor Exp $
*/
public class JetspeedFusionPortlet extends AbstractInstancePortlet
{
private static final JetspeedLogger log = JetspeedLogFactoryService.getLogger(JetspeedFusionPortlet.class.getName());
private static final String PORTLET_APPLICATION_NAME = FusionResources.getString(FusionResources.PORTLET_APPLICATION_PARAMETER);
private static final String PORTLET_DEFINITION_NAME = FusionResources.getString(FusionResources.PORTLET_DEFINITION_PARAMETER);
private static final String J2_ENTITY = FusionResources.getString(FusionResources.J2_ENTITY);
private NavigationalStateComponent navState;
private PortletWindowAccessor windowAccessor;
private PortletEntityAccessComponent entityAccess;
private PortletRegistryComponent registryAccess;
// TODO: get this from NavStateComponent
private static final String NAVSTATE_SESSION_KEY = "org.apache.jetspeed.navstate";
public void init()
throws PortletException
{
navState = (NavigationalStateComponent)
Jetspeed.getComponentManager().getComponent(NavigationalStateComponent.class);
windowAccessor = (PortletWindowAccessor)
Jetspeed.getComponentManager().getComponent(PortletWindowAccessor.class);
entityAccess = (PortletEntityAccessComponent)
Jetspeed.getComponentManager().getComponent(PortletEntityAccessComponent.class);
registryAccess = (PortletRegistryComponent)
Jetspeed.getComponentManager().getComponent(PortletRegistryComponent.class);
}
public ConcreteElement getContent(RunData data)
{
JetspeedRunData jrun = (JetspeedRunData)data;
HttpServletResponse response = data.getResponse();
String entityId = null;
try
{
PortletInstance instance = this.getInstance(jrun);
entityId = instance.getAttribute(J2_ENTITY, "");
String pa = getPortletConfig().getInitParameter(PORTLET_APPLICATION_NAME, null);
String pd = getPortletConfig().getInitParameter(PORTLET_DEFINITION_NAME, null);
String registryKey = pa + "::" + pd;
PortletWindow window = getPortletWindow(entityId, registryKey);
if (window == null)
{
String msg = "Could not find portlet definition in registry for " + registryKey + " and entity " + entityId;
log.error(msg);
return new JetspeedClearElement("JSR 168 Portlet is not configured correctly, no content available. Registry Key [" + registryKey + "], entity [" + entityId + "]");
}
int mode = jrun.getMode();
syncNavigationalState(window, jrun, mode);
switch (mode)
{
case JetspeedRunData.NORMAL:
response.getWriter().print("JF:MODE:normal: ");
break;
case JetspeedRunData.MAXIMIZE:
response.getWriter().print("JF:MODE:maximize");
break;
case JetspeedRunData.CUSTOMIZE:
response.getWriter().print("JF:MODE:customize");
break;
}
}
catch (Exception e)
{
e.printStackTrace();
}
return service(data, entityId);
// return dispatch(data, entityId);
}
protected PortletWindow getPortletWindow(String id, String registryKey)
{
PortletWindow window = windowAccessor.getPortletWindow(id);
if (window == null)
{
PortletEntity entity = entityAccess.getPortletEntity(id);
if (entity == null)
{
PortletDefinition portletDef = registryAccess.getPortletDefinitionByUniqueName(registryKey);
if (null == portletDef)
{
// can't get the portlet either, give up
return null;
}
entity = entityAccess.newPortletEntityInstance(portletDef);
window = windowAccessor.createPortletWindow(entity, id);
try
{
entityAccess.storePortletEntity(entity);
}
catch (Exception e)
{
log.error("Failed to store portlet entity: " + registryKey, e);
return null;
}
}
else
{
window = windowAccessor.createPortletWindow(entity, id);
}
}
return window;
}
/*
public boolean providesCustomization()
{
return true;
}
*/
/*
public HttpServletResponse getResponseForWindow(HttpServletRequest req, HttpServletResponse resp)
{
PortletContent myContent = new PortletContent();
synchronized (contents)
{
contents.put(window.getId(), myContent);
}
return new HttpBufferedResponse(request.getResponse(),myContent.getWriter());
}
*/
public ConcreteElement service(RunData data, String entityId)
{
String result = "";
RequestContextComponent contextComponent = null;
RequestContext context = null;
try
{
HttpServletRequest request = data.getRequest();
HttpServletResponse response = // TODO: test new FusionResponseWrapper(data.getResponse());
data.getResponse();
ServletConfig config = data.getServletConfig();
Engine engine = Jetspeed.getEngine();
contextComponent = (RequestContextComponent)Jetspeed.getComponentManager().getComponent(RequestContextComponent.class);
context = contextComponent.create(request, response, config);
context.setAttribute(PortalReservedParameters.PORTLET_ENTITY, entityId);
engine.service(context);
// TODO: test result = response.toString();
}
catch (Throwable t)
{
t.printStackTrace();
return new JetspeedClearElement(t.getMessage());
}
finally
{
if (contextComponent != null && context != null)
{
contextComponent.release(context);
}
}
return new JetspeedClearElement(result);
}
/**
* dispatch to fusion portlet
*
* @param data
*/
public ConcreteElement dispatch(RunData data, String entityId)
{
String result = "";
try
{
HttpServletRequest request = data.getRequest();
String dispatchURL = "/fusion/portal?pipeline=portlet-pipeline&entity=" + entityId;
ServletContext fusion = data.getServletConfig().getServletContext().getContext("/fusion");
if (fusion == null)
{
String message = "Dispatching ERROR: Failed to get Fusion webapp context";
return new JetspeedClearElement(message);
}
RequestDispatcher jsDispatcher = fusion.getRequestDispatcher(dispatchURL);
if (jsDispatcher == null)
{
String message = "Dispatching ERROR: Failed to get a request dispatcher for /jetspeed";
return new JetspeedClearElement(message);
}
// TODO: need to create a response wrapper and buffer the content
HttpServletResponse response = data.getResponse(); // TODO: TEST new FusionResponseWrapper(data.getResponse());
jsDispatcher.include(data.getRequest(), response);
// response.getWriter().print("Hello JSR 168 out the print writer");
// Note this is still under construction
// result = "Portlet Content goes here";
}
catch (Throwable t)
{
t.printStackTrace();
return new JetspeedClearElement(t.getMessage());
}
return new JetspeedClearElement(result);
}
private void syncNavigationalState(PortletWindow window,
JetspeedRunData data,
int mode)
{
NavigationalState nav =
(NavigationalState)data.getSession().getAttribute(NAVSTATE_SESSION_KEY);
if (null == nav)
{
return;
}
PortletMode mode2 = PortletMode.VIEW;
WindowState state = WindowState.NORMAL;
mode2 = nav.getMode(window);
state = nav.getState(window);
if (isMinimized(data))
{
nav.setState(window, WindowState.MINIMIZED);
return;
}
switch (mode)
{
case JetspeedRunData.NORMAL:
if (!mode2.equals(PortletMode.VIEW))
{
nav.setMode(window, PortletMode.VIEW);
}
if (!state.equals(WindowState.NORMAL))
{
nav.setState(window, WindowState.NORMAL);
}
break;
case JetspeedRunData.MAXIMIZE:
if (!state.equals(WindowState.MAXIMIZED))
{
nav.setState(window, WindowState.MAXIMIZED);
}
break;
case JetspeedRunData.CUSTOMIZE:
if (!mode2.equals(PortletMode.EDIT))
{
nav.setMode(window, PortletMode.EDIT);
}
break;
}
}
public boolean providesCustomization()
{
return true;
}
public void setMinimized(boolean flag, RunData rundata)
{
super.setMinimized(flag, rundata);
System.out.println("MINIMIZING...");
JetspeedRunData jrun = (JetspeedRunData)rundata;
String entityId = null;
PortletInstance instance = this.getInstance(jrun);
entityId = instance.getAttribute(J2_ENTITY, "3");
PortletWindow window = windowAccessor.getPortletWindow(entityId);
if (window == null)
{
window = windowAccessor.createPortletWindow(entityId);
}
int mode = jrun.getMode();
syncNavigationalState(window, jrun, mode);
System.out.println("MINIMIZED...done: " + window.getId());
}
public boolean getAllowEdit( RunData rundata )
{
// TODO: look 'allow' up in J2 portlet
return super.getAllowEdit(rundata);
}
public boolean getAllowView( RunData rundata )
{
// TODO: look 'allow' up in J2 portlet
return super.getAllowView(rundata);
}
public boolean getAllowMaximize( RunData rundata )
{
// TODO: look 'allow' up in J2 portlet
return super.getAllowEdit(rundata);
}
}
1.1 jakarta-jetspeed/fusion/src/java/org/apache/jetspeed/fusion/tools/pamanager/FusionCatalinaPAM.java
Index: FusionCatalinaPAM.java
===================================================================
/*
* Copyright 2000-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.jetspeed.fusion.tools.pamanager;
import java.util.Map;
import java.util.Locale;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.jetspeed.tools.pamanager.PortletApplicationException;
import org.apache.jetspeed.tools.pamanager.PortletApplicationManagement;
import org.apache.jetspeed.tools.pamanager.servletcontainer.TomcatManager;
import org.apache.jetspeed.components.portletregistry.PortletRegistryComponent;
/**
* FusionCatalinaPAM
*
* @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
* @version $Id: FusionCatalinaPAM.java,v 1.1 2004/06/26 01:23:40 taylor Exp $
*/
public class FusionCatalinaPAM extends FusionPAM implements
PortletApplicationManagement
{
// Implementaion of deplyment interface
public final static String PAM_PROPERTY_SERVER = "server";
public final static String PAM_PROPERTY_PORT = "port";
public final static String PAM_PROPERTY_USER = "user";
public final static String PAM_PROPERTY_PASSWORD = "password";
private TomcatManager tomcatManager = null;
protected static final Log log = LogFactory.getLog("deployment");
public FusionCatalinaPAM(PortletRegistryComponent registry, Locale defaultLocale)
{
super(registry, defaultLocale);
}
public void connect(Map params)
throws PortletApplicationException
{
try
{
int port = 8080;
String server = (String)params.get(PAM_PROPERTY_SERVER);
Integer portNumber = (Integer)params.get(PAM_PROPERTY_PORT);
if (null != portNumber)
{
port = portNumber.intValue();
}
String username = (String)params.get(PAM_PROPERTY_USER);
String password = (String)params.get(PAM_PROPERTY_PASSWORD);
tomcatManager = new TomcatManager(server, port, username, password);
}
catch (Exception e)
{
throw new PortletApplicationException(e);
}
}
// Interface not supported by this implementation
public void deploy(String webAppsDir, String warFile, String paName)
throws PortletApplicationException
{
try
{
super.deploy(webAppsDir, warFile, paName);
checkResponse(tomcatManager.install(webAppsDir + "/" + paName, paName));
}
catch (PortletApplicationException pe)
{
throw pe;
}
catch (Exception e)
{
throw new PortletApplicationException(e);
}
}
/**
* Deploys the specified war file to the webapps directory on the Application Server.
* The appServer parameter specifies a specific Application Server.
*
*
* @param warFile The warFile containing the Portlet Application
* @param paName The Portlet Application name
* @throws PortletApplicationException
*/
public void deploy(String warFile, String paName) throws PortletApplicationException
{
super.deploy(null, warFile, paName, 0);
try
{
checkResponse(tomcatManager.install(warFile, paName));
}
catch (PortletApplicationException pe)
{
throw pe;
}
catch (Exception e)
{
throw new PortletApplicationException(e);
}
}
/**
* Prepares the specified war file for deployment.
*
* @param paName The Portlet Application name
* @throws PortletApplicationException
*/
public void undeploy(String paName) throws PortletApplicationException
{
try
{
checkResponse(tomcatManager.remove(paName));
Thread.sleep(2000);
super.undeploy(paName);
}
catch (UnsupportedOperationException usoe)
{
// ignore FS PAM not suporting this
}
catch (Exception e)
{
throw new PortletApplicationException(e);
}
}
/** Undeploys application.
*
* @param webAppsDir The webapps directory inside the Application Server
* @param paName The Portlet Application name
* @throws PortletApplicationException
*/
public void undeploy(String webAppsDir, String paName) throws PortletApplicationException
{
try
{
checkResponse(tomcatManager.remove(paName));
Thread.sleep(2000);
super.undeploy(webAppsDir, paName);
}
catch (PortletApplicationException pe)
{
throw pe;
}
catch (Exception e)
{
throw new PortletApplicationException(e);
}
}
// Implementaion of Lifecycle interface
/**
* Starts the specified Portlet Application on the Application Server
*
* @param paName The Portlet Application name
* @throws PortletApplicationException
*/
public void start(String paName) throws PortletApplicationException
{
try
{
checkResponse(tomcatManager.start(paName));
}
catch (PortletApplicationException pe)
{
throw pe;
}
catch (Exception e)
{
throw new PortletApplicationException(e);
}
}
/**
* Stops a portlet application from running on the Application Server
*
* @param paName The Portlet Application name
* @throws PortletApplicationException
*/
public void stop(String paName) throws PortletApplicationException
{
try
{
checkResponse(tomcatManager.stop(paName));
}
catch (PortletApplicationException pe)
{
throw pe;
}
catch (Exception e)
{
throw new PortletApplicationException(e);
}
}
/**
* Reloads a portlet application.
*
* @param paName The Portlet Application name
* @throws PortletApplicationException
*/
public void reload(String paName) throws PortletApplicationException
{
try
{
checkResponse(tomcatManager.reload(paName));
}
catch (PortletApplicationException pe)
{
throw pe;
}
catch (Exception e)
{
throw new PortletApplicationException(e);
}
}
/**
*
* @param response
* @throws PortletApplicationException
*/
private void checkResponse(String response) throws PortletApplicationException
{
if (response == null || (!response.startsWith("OK") && response.indexOf("Application already exists at path") == -1) )
{
if (response == null)
{
response = "null response";
}
throw new PortletApplicationException("Catalina container action failed, \"" + response + "\"");
}
else
{
log.info("Catalina deployment response: " + response);
}
}
/**
* @see org.apache.jetspeed.tools.pamanager.Deployment#deploy(java.lang.String, java.lang.String, java.lang.String, java.lang.String, int)
*/
public void deploy(String webAppsDir, String warFile, String paName, String deploymentDbAlias, int startState)
throws PortletApplicationException
{
super.deploy(webAppsDir, warFile, paName, startState);
try
{
checkResponse(tomcatManager.install(warFile, paName));
}
catch (PortletApplicationException pe)
{
throw pe;
}
catch (Exception e)
{
throw new PortletApplicationException(e);
}
}
}
1.1 jakarta-jetspeed/fusion/src/java/org/apache/jetspeed/fusion/tools/pamanager/FusionPAM.java
Index: FusionPAM.java
===================================================================
/*
* Copyright 2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.jetspeed.fusion.tools.pamanager;
import java.util.Collection;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Locale;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.jetspeed.Jetspeed;
import org.apache.jetspeed.components.persistence.store.PersistenceStore;
import org.apache.jetspeed.components.portletregistry.PortletRegistryComponent;
import org.apache.jetspeed.fusion.services.resources.FusionResources;
import org.apache.jetspeed.om.common.portlet.MutablePortletApplication;
import org.apache.jetspeed.om.profile.Entry;
import org.apache.jetspeed.om.profile.PSMLDocument;
import org.apache.jetspeed.om.profile.Profile;
import org.apache.jetspeed.om.profile.QueryLocator;
import org.apache.jetspeed.om.registry.Category;
import org.apache.jetspeed.om.registry.MediaTypeEntry;
import org.apache.jetspeed.om.registry.MediaTypeRegistry;
import org.apache.jetspeed.om.registry.PortletEntry;
import org.apache.jetspeed.om.registry.base.BaseCachedParameter;
import org.apache.jetspeed.services.PsmlManager;
import org.apache.jetspeed.services.Registry;
import org.apache.jetspeed.tools.pamanager.Deployment;
import org.apache.jetspeed.tools.pamanager.FileSystemPAM;
import org.apache.jetspeed.tools.pamanager.PortletApplicationException;
import org.apache.jetspeed.tools.pamanager.Registration;
import org.apache.pluto.om.common.Description;
import org.apache.pluto.om.common.DisplayName;
import org.apache.pluto.om.common.Language;
import org.apache.pluto.om.portlet.ContentType;
import org.apache.pluto.om.portlet.PortletDefinition;
import org.apache.turbine.util.TurbineConfig;
//import org.apache.regexp.RE;
//import org.apache.regexp.RECompiler;
/**
* FusionPAM
*
* @author <a href="mailto:jford@apache.org">Jeremy Ford</a>
* @version $Id: FusionPAM.java,v 1.1 2004/06/26 01:23:40 taylor Exp $
*/
public class FusionPAM
extends
FileSystemPAM
implements
Deployment,
Registration
{
private static final Log log = LogFactory.getLog("deployment");
private static String JSR168_PORTLET;
private static String PORTLET_DEFINITION_NAME;
private static String PORTLET_APPLICATION_NAME;
private static final String JS1_REFERENCE_TYPE = "ref";
public FusionPAM(PortletRegistryComponent registry, Locale defaultLocale)
{
super(registry, defaultLocale);
initJetspeedOne(null);
}
public static void main(String args[])
{
System.out.println("*** Fusion PAM ***");
initJetspeedOne(args);
System.out.println("*** Exiting FUSION PAM ***");
}
protected static void initJetspeedOne(String args[])
{
//
// initialize and bootstrap services
//
try
{
if (args != null)
{
//String root = "./stage/webapp"; // FOR TESTING only
String root = System.getProperty("pam.deploy.dir") + "/fusion";
log.info("Using PAM root: " + root);
String properties = "/WEB-INF/conf/FusionPAM.properties";
//String properties = "/WEB-INF/conf/TurbineResources.properties";
//System.out.println("Using PAM root: " + root);
TurbineConfig config = new TurbineConfig( root, properties);
config.initialize();
System.out.println("TURBINE CONFIG DONE Using PAM root: " + root);
}
JSR168_PORTLET = FusionResources.getString(FusionResources.JSR168_PORTLET, "JSR168Portlet");
PORTLET_DEFINITION_NAME = FusionResources.getString(FusionResources.PORTLET_DEFINITION_PARAMETER, "portlet_definition");
PORTLET_APPLICATION_NAME = FusionResources.getString(FusionResources.PORTLET_APPLICATION_PARAMETER, "portlet_application");
log.info("Using PDEF NAME " + PORTLET_DEFINITION_NAME);
log.info("Using PAPP NAME " + PORTLET_APPLICATION_NAME);
}
catch (Exception e)
{
System.out.println("EXCEPTION IN TURBINE CONFIG");
String msg = "Fusion PAM: error initializing Turbine configuration";
log.error(msg, e);
System.out.println(msg);
e.printStackTrace();
System.exit(0);
}
/*
try
{
Enumeration entries = Registry.getNames();
while (entries.hasMoreElements())
{
String name = (String)entries.nextElement();
System.out.println("name = " + name);
}
}
catch (org.apache.turbine.services.InstantiationException e)
{
String msg = "Fusion PAM: error loading Psml Exporter Service";
log.error(msg, e);
System.out.println(msg);
e.printStackTrace();
System.exit(0);
}
*/
}
public void deploy(String webAppsDir,
String warFile,
String paName)
throws PortletApplicationException
{
System.out.println("***** Deploying now...." + warFile);
super.deploy(webAppsDir, warFile, paName);
//FIXME: This could be a protected member from FileSystemPAM
PortletRegistryComponent registry = (PortletRegistryComponent) Jetspeed.getComponentManager().getComponent(PortletRegistryComponent.class);
//create xreg
PersistenceStore store = registry.getPersistenceStore();
try
{
// remove entries from the registry
// registry.processPortletApplicationTree(app, "remove");
store.getTransaction().begin();
log.info("Saving the portlet.xml in the J1 registry...");
MutablePortletApplication app = registry.getPortletApplication(paName);
Collection pds = app.getPortletDefinitions();
Iterator pdsIter = pds.iterator();
while (pdsIter.hasNext())
{
PortletDefinition pdef = (PortletDefinition) pdsIter.next();
PortletEntry entry = createPortletEntry(paName, pdef);
Registry.saveEntry(Registry.PORTLET, entry);
System.out.println("Writing registry: " + entry.getName());
}
store.getTransaction().commit();
}
catch (Exception e1)
{
e1.printStackTrace();
// store.getTransaction().rollback();
log.error("Error processing rollback. Attempting to rollback registry transaction.", e1);
}
//TurbineServices.getInstance().shutdownServices();
}
public static PortletEntry createPortletEntry(String paName, PortletDefinition portletDefinition)
{
//TODO: do the lookup once, minor speed improvment
// validate parent entry exists
PortletEntry parentEntry = (PortletEntry)Registry.getEntry(Registry.PORTLET, JSR168_PORTLET);
//TODO: speed improvement 2, only get categories once
Iterator categoryIterator = parentEntry.listCategories();
PortletEntry entry = (PortletEntry) Registry.createEntry(Registry.PORTLET);
entry.setParent(JSR168_PORTLET);
entry.setType(JS1_REFERENCE_TYPE);
Description desc = portletDefinition.getDescription(Jetspeed.getDefaultLocale());
if(desc != null)
{
entry.setDescription(desc.getDescription());
}
DisplayName title = portletDefinition.getDisplayName(Jetspeed.getDefaultLocale());
if (title != null)
{
entry.setTitle(title.getDisplayName());
}
else
{
Language lang = portletDefinition.getLanguageSet().get(Jetspeed.getDefaultLocale());
if (lang != null)
{
String tit = lang.getShortTitle();
if (tit == null)
{
tit = lang.getTitle();
if (tit != null)
{
entry.setTitle(tit);
}
}
else
{
entry.setTitle(tit);
if (desc == null)
{
String descTitle = lang.getTitle();
if (descTitle != null)
{
entry.setDescription(descTitle);
}
}
}
}
}
entry.setName(portletDefinition.getName());
Iterator iter = portletDefinition.getContentTypeSet().iterator();
while (iter.hasNext())
{
ContentType contentType = (ContentType) iter.next();
String type = contentType.getContentType();
log.info("Attempting to find media entry with mimetype " + type);
//example: content type text/html => media type html
MediaTypeRegistry mediaRegistry = (MediaTypeRegistry) Registry.get(Registry.MEDIA_TYPE);
Enumeration en = mediaRegistry.getEntries();
while(en.hasMoreElements())
{
MediaTypeEntry mte = (MediaTypeEntry)en.nextElement();
//TODO: the type can have wildcards, will REGEXP handle this?
/*
RE r = null;
RECompiler rc = null;
try
{
rc = new RECompiler();
r = new RE();
r.setProgram(rc.compile(type));
}
catch (org.apache.regexp.RESyntaxException rex)
{
log.warn("FusionPAM: error processing regular expression [" + type + "]: " +
rex.toString());
}
*/
if(type.indexOf('*') != -1)
{
log.info("Found mime type with wildcard.");
}
else if (type.equals(mte.getMimeType()))// || r.match(mte.getMimeType()))
{
log.info("Found media entry " + mte.getName() + " that matches mimetype " + type);
entry.addMediaType(mte.getName());
break;
}
}
}
//TODO: figure out security
//entry.setSecurityRef()
//TODO: what parameters are needed for the JSR168 portlet?
//NOTE: we should not need to copy preferences to the parameters
BaseCachedParameter pdefParam = new BaseCachedParameter();
pdefParam.setName(PORTLET_DEFINITION_NAME);
pdefParam.setValue(portletDefinition.getName());
pdefParam.setHidden(true);
entry.addParameter(pdefParam);
BaseCachedParameter pappParam = new BaseCachedParameter();
pappParam.setName(PORTLET_APPLICATION_NAME);
pappParam.setValue(paName);
pappParam.setHidden(true);
entry.addParameter(pappParam);
//copy categories
while (categoryIterator.hasNext())
{
Category category = (Category) categoryIterator.next();
//this will only add the category if it doesn't already exist
//which, it shouldn't
entry.addCategory(category.getName(), category.getGroup());
}
return entry;
}
public void undeploy( String webAppsDir, String paName ) throws PortletApplicationException
{
System.out.println("***** UN Deploying now...." + paName);
PortletRegistryComponent registry = (PortletRegistryComponent) Jetspeed.getComponentManager().getComponent(PortletRegistryComponent.class);
try
{
// remove entries from the registry
MutablePortletApplication app = registry.getPortletApplication(paName);
Collection pds = app.getPortletDefinitions();
Iterator pdsIter = pds.iterator();
while (pdsIter.hasNext())
{
PortletDefinition pdef = (PortletDefinition) pdsIter.next();
String name = pdef.getName();
Registry.removeEntry(Registry.PORTLET, name);
System.out.println("registry entry removed: " + name);
// remove PSML refs
removePSML(name);
}
}
catch (Exception e1)
{
e1.printStackTrace();
// store.getTransaction().rollback();
log.error("Error processing rollback. Attempting to rollback registry transaction.", e1);
}
//TurbineServices.getInstance().shutdownServices();
super.undeploy(webAppsDir, paName);
}
/**
* Removes all PSML entries in the entire portal for the given name
*
* @param name of the portlet in the registry
*/
private void removePSML(String name)
{
System.out.println("Trying to remove all PSML instances for: " + name);
QueryLocator locator = new QueryLocator(QueryLocator.QUERY_USER); // ALL
Iterator profiles = null;
int count = 0;
try
{
profiles = PsmlManager.query(locator);
while (profiles.hasNext() )
{
Profile profile = (Profile)profiles.next();
PSMLDocument doc = profile.getDocument();
System.out.println("Scanning: " + doc.getName());
Entry entry = doc.getEntry(name);
if (entry != null)
{
System.out.println("***** REMOVING ENTRY : " + entry.getName());
doc.removeEntryById(entry.getId());
PsmlManager.store(profile);
}
}
}
catch(Exception e)
{
e.printStackTrace();
log.error("Remove PSML: Failed to remove profiles for portlet: " + name, e );
}
}
}
1.1 jakarta-jetspeed/fusion/src/java/org/apache/jetspeed/fusion/modules/actions/FusionAccessController.java
Index: FusionAccessController.java
===================================================================
/*
* Copyright 2001,2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.jetspeed.fusion.modules.actions;
import javax.servlet.ServletConfig;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.jetspeed.Jetspeed;
import org.apache.jetspeed.PortalReservedParameters;
import org.apache.jetspeed.container.session.NavigationalStateComponent;
import org.apache.jetspeed.engine.Engine;
import org.apache.jetspeed.modules.actions.JetspeedAccessController;
import org.apache.jetspeed.request.RequestContext;
import org.apache.jetspeed.request.RequestContextComponent;
import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
import org.apache.jetspeed.services.logging.JetspeedLogger;
import org.apache.jetspeed.services.resources.JetspeedResources;
import org.apache.turbine.TurbineConstants;
import org.apache.turbine.util.RunData;
/**
* <p>FusionAccessController serves two purposes:
* <ul>
* <li>Process the JSR 168 action phase. A portlet's action is executed here.</li>
* <li>Delegate to standard Jetpeed-1 access controller processing.</li>
* </ul>
*
* @author <a href="mailto:david@bluesunrise.com">David Sean Taylor</a>
* @version $Id: FusionAccessController.java,v 1.1 2004/06/26 01:23:40 taylor Exp $
*/
public class FusionAccessController extends JetspeedAccessController
{
private static final JetspeedLogger log = JetspeedLogFactoryService.getLogger(FusionAccessController.class.getName());
/**
* Execute the action.
*
* @param data Turbine information.
* @exception Exception, a generic exception.
*/
public void doPerform( RunData data ) throws Exception
{
try
{
super.doPerform(data);
}
catch (Throwable other)
{
data.setScreenTemplate(JetspeedResources.getString(TurbineConstants.TEMPLATE_ERROR));
String message = other.getMessage() != null ? other.getMessage() : other.toString();
data.setMessage(message);
data.setStackTrace(org.apache.turbine.util.StringUtils.stackTrace(other), other);
return;
}
RequestContextComponent contextComponent = null;
RequestContext context = null;
try
{
HttpServletRequest request = data.getRequest();
HttpServletResponse response = data.getResponse();
NavigationalStateComponent nav = (NavigationalStateComponent)Jetspeed.getComponentManager().getComponent(NavigationalStateComponent.class);
if (nav.hasPortalParameter(request, NavigationalStateComponent.ACTION))
{
// System.out.println("*** ACTION PARAM FOUND!!!!!!!!!!! ****");
ServletConfig config = data.getServletConfig();
Engine engine = Jetspeed.getEngine();
contextComponent = (RequestContextComponent)Jetspeed.getComponentManager().getComponent(RequestContextComponent.class);
context = contextComponent.create(request, response, config);
context.setAttribute(PortalReservedParameters.PIPELINE, PortalReservedParameters.ACTION_PIPELINE);
// context.setAttribute(PortalReservedParameters.PORTLET_ENTITY, entityId);
engine.service(context);
}
}
catch (Throwable t)
{
t.printStackTrace();
log.error("error in fusion access controller", t);
}
finally
{
if (contextComponent != null && context != null)
{
contextComponent.release(context);
}
}
}
}
1.1 jakarta-jetspeed/fusion/src/java/org/apache/jetspeed/fusion/services/resources/FusionResources.java
Index: FusionResources.java
===================================================================
/*
* Copyright 2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.jetspeed.fusion.services.resources;
import org.apache.jetspeed.services.resources.JetspeedResources;
/**
* Extends the JetspeedResources to add Fusion specific keys
*
* @author <a href="mailto:jford@apache.org">Jeremy Ford</a>
* @version $Id: FusionResources.java,v 1.1 2004/06/26 01:23:40 taylor Exp $
*/
public class FusionResources extends JetspeedResources
{
public static final String JSR168_PORTLET = "fusion.jsr168.parent";
public static final String PORTLET_DEFINITION_PARAMETER = "fusion.jsr168.portlet_definition";
public static final String PORTLET_APPLICATION_PARAMETER = "fusion.jsr168.portlet_application";
public static final String J2_ENTITY = "fusion.jsr168.j2.entity";
}
1.1 jakarta-jetspeed/fusion/src/java/org/apache/jetspeed/fusion/portal/portlets/streaming/FusionServletOutputStream.java
Index: FusionServletOutputStream.java
===================================================================
/*
* Copyright 2000-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.jetspeed.fusion.portal.portlets.streaming;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import javax.servlet.ServletOutputStream;
/**
* FusionServletOutputStream
*
* @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
* @author <a href="mailto:serge.huber@jahia.org">Serge Huber</a>
* @version $Id: FusionServletOutputStream.java,v 1.1 2004/06/26 01:23:40 taylor Exp $
*/
public class FusionServletOutputStream extends ServletOutputStream
{
private ByteArrayOutputStream byteArray = new ByteArrayOutputStream ();
private OutputStreamWriter streamWriter;
private ServletOutputStream existingStream;
private OutputStreamWriter existingStreamWriter;
private String encoding;
public FusionServletOutputStream(String encoding) throws UnsupportedEncodingException
{
super();
this.encoding = encoding;
streamWriter = new OutputStreamWriter (byteArray, encoding);
}
public FusionServletOutputStream (ServletOutputStream existingStream, String encoding)
throws UnsupportedEncodingException
{
super();
this.existingStream = existingStream;
this.encoding = encoding;
streamWriter = new OutputStreamWriter (byteArray, encoding);
existingStreamWriter = new OutputStreamWriter (existingStream, encoding);
}
public void write(char[] cbuf) throws IOException
{
streamWriter.write(cbuf, 0, cbuf.length);
if (existingStream != null)
{
existingStreamWriter.write(cbuf, 0, cbuf.length);
}
}
public void write(char[] cbuf, int off, int len) throws IOException
{
streamWriter.write(cbuf, off, len);
if (existingStream != null)
{
existingStreamWriter.write(cbuf, off, len);
}
}
public void write(int c) throws IOException
{
byteArray.write(c);
if (existingStream != null)
{
existingStream.write(c);
}
}
public void write(String s) throws IOException
{
streamWriter.write(s);
if (existingStream != null)
{
existingStreamWriter.write(s);
}
}
public void write(String str, int off, int len) throws IOException
{
streamWriter.write(str, off, len);
if (existingStream != null)
{
existingStreamWriter.write(str, off, len);
}
}
public String getBuffer() throws UnsupportedEncodingException
{
return byteArray.toString(encoding);
}
public void flush() throws IOException
{
if (existingStream != null)
{
existingStreamWriter.flush();
existingStream.flush();
}
}
public void close()
{
}
}
1.1 jakarta-jetspeed/fusion/src/java/org/apache/jetspeed/fusion/portal/portlets/streaming/FusionResponseWrapper.java
Index: FusionResponseWrapper.java
===================================================================
/*
* Copyright 2000-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.jetspeed.fusion.portal.portlets.streaming;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;
/**
* FusionResponseWrapper
*
* @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
* @author <a href="mailto:serge.huber@jahia.org">Serge Huber</a>
* @version $Id: FusionResponseWrapper.java,v 1.1 2004/06/26 01:23:40 taylor Exp $
*/
public class FusionResponseWrapper extends HttpServletResponseWrapper
{
private FusionServletOutputStream outputStream = null;
private PrintWriter printWriter = null;
private boolean isPassThrough = false;
private String encoding = "ISO-8859-1";
private String forceEncoding = null;
private boolean outputStreamCalled = false;
public FusionResponseWrapper(HttpServletResponse httpServletResponse,
boolean isPassThrough,
String forceEncoding)
{
super (httpServletResponse);
}
public FusionResponseWrapper(HttpServletResponse httpServletResponse)
{
super (httpServletResponse);
}
public PrintWriter getWriter()
{
checkStreams();
return printWriter;
}
public ServletOutputStream getOutputStream() throws IOException
{
checkStreams();
this.outputStreamCalled = true;
return outputStream;
}
private void checkStreams()
{
if ((outputStream == null) && (printWriter == null))
{
try
{
// printWriter = new StringPrintWriter(new StringWriter(),
// outputStringBuffer);
if (isPassThrough)
{
outputStream = new FusionServletOutputStream(super
.getResponse().getOutputStream(), encoding);
} else
{
outputStream = new FusionServletOutputStream(encoding);
}
OutputStreamWriter streamWriter;
if (encoding != null)
{
streamWriter = new OutputStreamWriter(outputStream,
encoding);
} else
{
streamWriter = new OutputStreamWriter(outputStream);
}
printWriter = new PrintWriter(streamWriter, true);
} catch (Exception e)
{
// logger.debug("Error creating StringPrintWriter object !", e);
}
}
}
public String getStringBuffer(boolean checkWriterError) throws IOException
{
try
{
if (outputStreamCalled)
{
// logger.debug("buffer=[" + strOutputStream.getBuffer(encoding)
// + "]");
return outputStream.getBuffer();
}
else
{
if (outputStream == null)
{
return null;
} else
{
if (checkWriterError && printWriter.checkError())
{
throw new IOException(
"An error has occured while writing to output");
}
return outputStream.getBuffer();
}
}
}
catch (Exception e)
{
return "";
}
}
public String toString()
{
try
{
return getStringBuffer(true);
}
catch (Exception e)
{
return "Error getting portlet content.";
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org