You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pluto-scm@portals.apache.org by es...@apache.org on 2007/03/01 00:13:26 UTC
svn commit: r513051 - in /portals/pluto/trunk:
pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/config/impl/
pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/impl/resource/
pluto-portal-driver-impl/src/test/java/org...
Author: esm
Date: Wed Feb 28 15:13:25 2007
New Revision: 513051
URL: http://svn.apache.org/viewvc?view=rev&rev=513051
Log:
[PLUTO-318]: SupportedWindowStateService provides:
* SupportedWindowStateService interface and implementation wired up in pluto-portal-driver-config.xml
* SupportedWindowStateService Unit tests
* Updated DriverConfiguration interface and impl with isWindowStateSupported methods
Added:
portals/pluto/trunk/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/impl/resource/SupportedWindowStateServiceImpl.java (with props)
portals/pluto/trunk/pluto-portal-driver-impl/src/test/java/org/apache/pluto/driver/services/impl/resource/
portals/pluto/trunk/pluto-portal-driver-impl/src/test/java/org/apache/pluto/driver/services/impl/resource/MockPortletRegistryService.java (with props)
portals/pluto/trunk/pluto-portal-driver-impl/src/test/java/org/apache/pluto/driver/services/impl/resource/MockPropertyConfigService.java (with props)
portals/pluto/trunk/pluto-portal-driver-impl/src/test/java/org/apache/pluto/driver/services/impl/resource/SupportedWindowStateServiceTest.java (with props)
portals/pluto/trunk/pluto-portal-driver-impl/src/test/resources/
portals/pluto/trunk/pluto-portal-driver-impl/src/test/resources/log4j.properties (with props)
portals/pluto/trunk/pluto-portal-driver-impl/src/test/resources/pluto-portal-driver-config.xml (with props)
portals/pluto/trunk/pluto-portal-driver-impl/src/test/resources/portlet.xml (with props)
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/portal/SupportedWindowStateService.java (with props)
Modified:
portals/pluto/trunk/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/config/impl/DriverConfigurationImpl.java
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/config/DriverConfiguration.java
Modified: portals/pluto/trunk/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/config/impl/DriverConfigurationImpl.java
URL: http://svn.apache.org/viewvc/portals/pluto/trunk/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/config/impl/DriverConfigurationImpl.java?view=diff&rev=513051&r1=513050&r2=513051
==============================================================================
--- portals/pluto/trunk/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/config/impl/DriverConfigurationImpl.java (original)
+++ portals/pluto/trunk/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/config/impl/DriverConfigurationImpl.java Wed Feb 28 15:13:25 2007
@@ -22,10 +22,10 @@
import org.apache.pluto.driver.config.DriverConfiguration;
import org.apache.pluto.driver.services.portal.PageConfig;
-import org.apache.pluto.driver.services.portal.PortletWindowConfig;
import org.apache.pluto.driver.services.portal.PropertyConfigService;
import org.apache.pluto.driver.services.portal.RenderConfigService;
import org.apache.pluto.driver.services.portal.SupportedModesService;
+import org.apache.pluto.driver.services.portal.SupportedWindowStateService;
import org.apache.pluto.driver.url.PortalURLParser;
import org.apache.pluto.spi.PortalCallbackService;
import org.apache.pluto.spi.optional.PortletPreferencesService;
@@ -44,6 +44,7 @@
private PropertyConfigService propertyService;
private RenderConfigService renderService;
private SupportedModesService supportedModesService;
+ private SupportedWindowStateService supportedWindowStateService;
// Container Services
private PortalCallbackService portalCallbackService;
@@ -51,14 +52,17 @@
public DriverConfigurationImpl(PortalURLParser portalUrlParser,
PropertyConfigService propertyService,
- RenderConfigService renderService,
- PortalCallbackService portalCallback,
- SupportedModesService supportedModesService) {
+ RenderConfigService renderService,
+ SupportedModesService supportedModesService,
+ SupportedWindowStateService supportedWindowStateService,
+ PortalCallbackService portalCallback) {
+
this.portalUrlParser = portalUrlParser;
this.propertyService = propertyService;
this.renderService = renderService;
this.portalCallbackService = portalCallback;
this.supportedModesService = supportedModesService;
+ this.supportedWindowStateService = supportedWindowStateService;
}
/**
@@ -129,6 +133,7 @@
this.propertyService.init(context);
this.renderService.init(context);
this.supportedModesService.init(context);
+ this.supportedWindowStateService.init(context);
}
public void destroy() {
@@ -140,6 +145,9 @@
if (supportedModesService != null)
supportedModesService.destroy();
+
+ if (supportedWindowStateService != null)
+ supportedWindowStateService.destroy();
}
//
@@ -171,6 +179,21 @@
public void setPortletPreferencesService(PortletPreferencesService portletPreferencesService) {
this.portletPreferencesService = portletPreferencesService;
+ }
+
+ public boolean isWindowStateSupported(String portletId, String windowState)
+ {
+ return supportedWindowStateService.isWindowStateSupported(portletId, windowState);
+ }
+
+ public boolean isWindowStateSupportedByPortal(String windowState)
+ {
+ return supportedWindowStateService.isWindowStateSupportedByPortal(windowState);
+ }
+
+ public boolean isWindowStateSupportedByPortlet(String portletId, String windowState)
+ {
+ return supportedWindowStateService.isWindowStateSupportedByPortlet(portletId, windowState);
}
}
Added: portals/pluto/trunk/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/impl/resource/SupportedWindowStateServiceImpl.java
URL: http://svn.apache.org/viewvc/portals/pluto/trunk/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/impl/resource/SupportedWindowStateServiceImpl.java?view=auto&rev=513051
==============================================================================
--- portals/pluto/trunk/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/impl/resource/SupportedWindowStateServiceImpl.java (added)
+++ portals/pluto/trunk/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/impl/resource/SupportedWindowStateServiceImpl.java Wed Feb 28 15:13:25 2007
@@ -0,0 +1,252 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.pluto.driver.services.impl.resource;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import javax.portlet.WindowState;
+import javax.servlet.ServletContext;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.pluto.PortletContainer;
+import org.apache.pluto.PortletContainerException;
+import org.apache.pluto.descriptors.portlet.CustomWindowStateDD;
+import org.apache.pluto.descriptors.portlet.PortletAppDD;
+import org.apache.pluto.driver.AttributeKeys;
+import org.apache.pluto.driver.config.DriverConfigurationException;
+import org.apache.pluto.driver.services.portal.PortletWindowConfig;
+import org.apache.pluto.driver.services.portal.PropertyConfigService;
+import org.apache.pluto.driver.services.portal.SupportedWindowStateService;
+import org.apache.pluto.spi.optional.PortletRegistryService;
+
+public class SupportedWindowStateServiceImpl implements
+ SupportedWindowStateService
+{
+
+ /** Logger **/
+ private static final Log LOG = LogFactory.getLog(SupportedWindowStateServiceImpl.class);
+
+ /**
+ * Servlet context used to get a handle on the portlet container
+ */
+ private ServletContext servletContext = null;
+
+ /**
+ * PropertyConfigService is injected by Spring. We
+ * use it to obtain the window states that the portal
+ * supports. It is protected only so that the unit
+ * tests have access to the field.
+ */
+ protected PropertyConfigService propertyService = null;
+
+ /**
+ * PortletRegistry is obtained from the PortletContainer on
+ * this service's initialization. It is protected only
+ * so that the unit tests have access to the field.
+ *
+ * Note that it is an optional container service, but
+ * this implmentation requires it.
+ */
+ protected PortletRegistryService portletRegistry = null;
+
+ /**
+ * Contains String objects of window states supported
+ * by the portal (obtained from PropertyConfigService).
+ * It is protected only so that the unit tests have
+ * access to the field.
+ */
+ protected Set portalSupportedWindowStates = new HashSet(3);
+
+ /**
+ * Window States that are specified in PLT.9
+ */
+ protected static final Set JSR168_WINDOW_STATES;
+ static
+ {
+ JSR168_WINDOW_STATES = new HashSet(3);
+ JSR168_WINDOW_STATES.add(WindowState.MAXIMIZED);
+ JSR168_WINDOW_STATES.add(WindowState.MINIMIZED);
+ JSR168_WINDOW_STATES.add(WindowState.NORMAL);
+ }
+
+ private SupportedWindowStateServiceImpl()
+ {
+ // this impl requires a PropertyConfigService on construction.
+ }
+
+ public SupportedWindowStateServiceImpl( PropertyConfigService propertyService )
+ {
+ this.propertyService = propertyService;
+ }
+
+ public boolean isWindowStateSupported(String portletId, String state)
+ {
+ // If the supplied window state is a JSR 168 window state,
+ // we can return immediately
+ if ( JSR168_WINDOW_STATES.contains(state) )
+ {
+ return true;
+ }
+
+ // Otherwise we need to check for custom window states
+
+ return isWindowStateSupportedByPortal(state) &&
+ isWindowStateSupportedByPortlet(portletId, state);
+ }
+
+ public boolean isWindowStateSupportedByPortal(String state)
+ {
+ return portalSupportedWindowStates.contains(state);
+ }
+
+ public boolean isWindowStateSupportedByPortlet(String portletId, String state)
+ {
+ if ( portletId == null ||
+ state == null ||
+ portletId.trim().equals("") ||
+ state.trim().equals(""))
+ {
+ StringBuffer errMsg = new StringBuffer( "Cannot determine supported window " +
+ "states for portletId [" + portletId + "] and window state [" + state + "]. " );
+ String msg = errMsg.append( "One or both of the arguments is empty or null." ).toString();
+ LOG.error(msg);
+ throw new IllegalArgumentException(msg);
+ }
+
+ // We can short-circut the registry lookup if the window state is
+ // one from PLT.9
+ if ( JSR168_WINDOW_STATES.contains(new WindowState(state)) )
+ {
+ return true;
+ }
+
+ // If the supplied window state isn't a JSR 168 window state,
+ // we look to see if it is a custom window state.
+
+ String appId = PortletWindowConfig.parseContextPath(portletId);
+ PortletAppDD portletAppDD = null;
+
+ if (portletRegistry == null)
+ {
+ portletRegistry = getPortletRegistryService();
+ if ( portletRegistry == null )
+ {
+ return false;
+ }
+ }
+
+ try
+ {
+ portletAppDD = portletRegistry.getPortletApplicationDescriptor(appId);
+ }
+ catch ( PortletContainerException e )
+ {
+ StringBuffer errMsg = new StringBuffer( "Cannot determine supported window " +
+ "states for portletId [" + portletId + "] and window state [" + state + "]. " );
+ String msg = errMsg.append( "Unable to access the Portlet Registry Service." ).toString();
+ LOG.error( msg, e );
+ }
+
+ List customWindowStates = portletAppDD.getCustomWindowStates();
+ if ( customWindowStates != null )
+ {
+ for ( Iterator i = customWindowStates.iterator(); i.hasNext(); )
+ {
+ CustomWindowStateDD customState = (CustomWindowStateDD)i.next();
+ if ( customState.getWindowState().equals(state))
+ {
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+
+ public void destroy() throws DriverConfigurationException
+ {
+ LOG.debug( "Destroying SupportedWindowStateService... " );
+ portletRegistry = null;
+ propertyService = null;
+ portalSupportedWindowStates = null;
+ LOG.debug( "SupportedWindowStateService destroyed." );
+ }
+
+ public void init(ServletContext ctx) throws DriverConfigurationException
+ {
+ LOG.debug( "Initializing SupportedWindowStateService... " );
+
+ servletContext = ctx;
+
+ portalSupportedWindowStates = propertyService.getSupportedWindowStates();
+ if ( LOG.isDebugEnabled() )
+ {
+ StringBuffer msg = new StringBuffer();
+
+ if ( portalSupportedWindowStates != null )
+ {
+ msg.append( "Portal supports [" + portalSupportedWindowStates.size() + "] window states. ");
+ for ( Iterator i = portalSupportedWindowStates.iterator(); i.hasNext(); )
+ {
+ msg.append( "[" + i.next() + "]" );
+ if ( i.hasNext() )
+ {
+ msg.append(", ");
+ }
+ }
+ LOG.debug(msg.toString());
+ }
+ }
+
+ if ( portalSupportedWindowStates == null )
+ {
+ final String msg = "Portal supported window states is null!";
+ LOG.error( msg );
+ throw new DriverConfigurationException( msg );
+ }
+ LOG.debug( "SupportedWindowStateService initialized." );
+ }
+
+ private PortletRegistryService getPortletRegistryService()
+ {
+ PortletContainer container = ((PortletContainer)servletContext
+ .getAttribute(AttributeKeys.PORTLET_CONTAINER));
+
+ if ( container == null )
+ {
+ // should never happen
+ final String msg = "Unable to obtain an instance of the container.";
+ LOG.fatal( msg );
+ throw new NullPointerException( msg );
+ }
+
+ if ( container.getOptionalContainerServices() == null ||
+ container.getOptionalContainerServices().getPortletRegistryService() == null )
+ {
+ final String msg = "Unable to obtain the portlet registry. The supported window state " +
+ "service cannot support custom window states.";
+ LOG.info( msg );
+ return null;
+ }
+
+ return container.getOptionalContainerServices().getPortletRegistryService();
+ }
+}
Propchange: portals/pluto/trunk/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/impl/resource/SupportedWindowStateServiceImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: portals/pluto/trunk/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/impl/resource/SupportedWindowStateServiceImpl.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: portals/pluto/trunk/pluto-portal-driver-impl/src/test/java/org/apache/pluto/driver/services/impl/resource/MockPortletRegistryService.java
URL: http://svn.apache.org/viewvc/portals/pluto/trunk/pluto-portal-driver-impl/src/test/java/org/apache/pluto/driver/services/impl/resource/MockPortletRegistryService.java?view=auto&rev=513051
==============================================================================
--- portals/pluto/trunk/pluto-portal-driver-impl/src/test/java/org/apache/pluto/driver/services/impl/resource/MockPortletRegistryService.java (added)
+++ portals/pluto/trunk/pluto-portal-driver-impl/src/test/java/org/apache/pluto/driver/services/impl/resource/MockPortletRegistryService.java Wed Feb 28 15:13:25 2007
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.pluto.driver.services.impl.resource;
+
+import java.io.InputStream;
+import java.util.Iterator;
+
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletContext;
+
+import org.apache.pluto.PortletContainerException;
+import org.apache.pluto.descriptors.portlet.PortletAppDD;
+import org.apache.pluto.descriptors.portlet.PortletDD;
+import org.apache.pluto.descriptors.services.castor.PortletAppDescriptorServiceImpl;
+import org.apache.pluto.spi.optional.PortletRegistryListener;
+import org.apache.pluto.spi.optional.PortletRegistryService;
+
+/**
+ * A mock PortletRegistryService. Supply an InputStream
+ * to a portlet.xml file on construction.
+ *
+ * All methods are no-ops except for getPortletApplicationDescriptor(String).
+ *
+ *
+ * @author Elliot Metsger (emetsger@jhu.edu)
+ * @since Feb 28, 2007
+ * @version $Id$
+ */
+public class MockPortletRegistryService implements PortletRegistryService
+{
+ PortletAppDD portletApp = null;
+
+ public MockPortletRegistryService(InputStream portletXml)
+ {
+ PortletAppDescriptorServiceImpl svc = new PortletAppDescriptorServiceImpl();
+ try
+ {
+ portletApp = svc.read(portletXml);
+ }
+ catch ( Exception e )
+ {
+ throw new RuntimeException( "Could not parse portlet xml.", e );
+ }
+ }
+
+ public void addPortletRegistryListener(PortletRegistryListener listener)
+ {
+
+ }
+
+ public PortletAppDD getPortletApplicationDescriptor(String name)
+ throws PortletContainerException
+ {
+ return portletApp;
+ }
+
+ public PortletConfig getPortletConfig(String applicationId,
+ String portletName) throws PortletContainerException
+ {
+ return null;
+ }
+
+ public PortletContext getPortletContext(String applicationId)
+ throws PortletContainerException
+ {
+ return null;
+ }
+
+ public PortletDD getPortletDescriptor(String applicationId,
+ String portletName) throws PortletContainerException
+ {
+ return null;
+ }
+
+ public Iterator getRegisteredPortletApplicationIds()
+ {
+ return null;
+ }
+
+ public Iterator getRegisteredPortletApplications()
+ {
+ return null;
+ }
+
+ public void removePortletRegistryListener(PortletRegistryListener listener)
+ {
+
+ }
+
+}
Propchange: portals/pluto/trunk/pluto-portal-driver-impl/src/test/java/org/apache/pluto/driver/services/impl/resource/MockPortletRegistryService.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: portals/pluto/trunk/pluto-portal-driver-impl/src/test/java/org/apache/pluto/driver/services/impl/resource/MockPortletRegistryService.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: portals/pluto/trunk/pluto-portal-driver-impl/src/test/java/org/apache/pluto/driver/services/impl/resource/MockPropertyConfigService.java
URL: http://svn.apache.org/viewvc/portals/pluto/trunk/pluto-portal-driver-impl/src/test/java/org/apache/pluto/driver/services/impl/resource/MockPropertyConfigService.java?view=auto&rev=513051
==============================================================================
--- portals/pluto/trunk/pluto-portal-driver-impl/src/test/java/org/apache/pluto/driver/services/impl/resource/MockPropertyConfigService.java (added)
+++ portals/pluto/trunk/pluto-portal-driver-impl/src/test/java/org/apache/pluto/driver/services/impl/resource/MockPropertyConfigService.java Wed Feb 28 15:13:25 2007
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.pluto.driver.services.impl.resource;
+
+import java.util.Set;
+
+import javax.servlet.ServletContext;
+
+import org.apache.pluto.driver.config.DriverConfigurationException;
+import org.apache.pluto.driver.services.impl.resource.ResourceConfig;
+import org.apache.pluto.driver.services.impl.resource.ResourceConfigReader;
+import org.apache.pluto.driver.services.portal.PropertyConfigService;
+
+/**
+ * A mock PropertyConfigService.
+ *
+ * The init() and destroy() methods are no-ops.
+ *
+ * @author Elliot Metsger (emetsger@jhu.edu)
+ * @since Feb 28, 2007
+ * @version $Id$
+ */
+class MockPropertyConfigService implements PropertyConfigService
+{
+
+ private ResourceConfig config = null;
+ private static final String configFile = "/pluto-portal-driver-config.xml";
+
+ public MockPropertyConfigService()
+ {
+ this(configFile);
+ }
+
+ public MockPropertyConfigService(String configFile)
+ {
+ ResourceConfigReader r = ResourceConfigReader.getFactory();
+ try
+ {
+ config = r.parse(this.getClass().getResourceAsStream(configFile));
+ }
+ catch ( Exception e )
+ {
+ throw new RuntimeException( "Unable to create ResourceConfig.", e );
+ }
+ }
+
+ public String getContainerName()
+ {
+ return config.getContainerName();
+ }
+
+ public String getPortalName()
+ {
+ return config.getPortalName();
+ }
+
+ public String getPortalVersion()
+ {
+ return config.getPortalVersion();
+ }
+
+ public Set getSupportedPortletModes()
+ {
+ return config.getSupportedPortletModes();
+ }
+
+ public Set getSupportedWindowStates()
+ {
+ return config.getSupportedWindowStates();
+ }
+
+ public void destroy() throws DriverConfigurationException
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void init(ServletContext ctx) throws DriverConfigurationException
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+}
Propchange: portals/pluto/trunk/pluto-portal-driver-impl/src/test/java/org/apache/pluto/driver/services/impl/resource/MockPropertyConfigService.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: portals/pluto/trunk/pluto-portal-driver-impl/src/test/java/org/apache/pluto/driver/services/impl/resource/MockPropertyConfigService.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: portals/pluto/trunk/pluto-portal-driver-impl/src/test/java/org/apache/pluto/driver/services/impl/resource/SupportedWindowStateServiceTest.java
URL: http://svn.apache.org/viewvc/portals/pluto/trunk/pluto-portal-driver-impl/src/test/java/org/apache/pluto/driver/services/impl/resource/SupportedWindowStateServiceTest.java?view=auto&rev=513051
==============================================================================
--- portals/pluto/trunk/pluto-portal-driver-impl/src/test/java/org/apache/pluto/driver/services/impl/resource/SupportedWindowStateServiceTest.java (added)
+++ portals/pluto/trunk/pluto-portal-driver-impl/src/test/java/org/apache/pluto/driver/services/impl/resource/SupportedWindowStateServiceTest.java Wed Feb 28 15:13:25 2007
@@ -0,0 +1,170 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.pluto.driver.services.impl.resource;
+
+import javax.portlet.WindowState;
+import javax.servlet.ServletContext;
+
+import junit.framework.TestCase;
+
+import org.apache.pluto.driver.config.DriverConfigurationException;
+import org.apache.pluto.driver.services.impl.resource.SupportedWindowStateServiceImpl;
+import org.apache.pluto.driver.services.portal.PropertyConfigService;
+import org.apache.pluto.driver.services.portal.SupportedWindowStateService;
+
+public class SupportedWindowStateServiceTest extends TestCase
+{
+
+ SupportedWindowStateService underTest = null;
+
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ underTest = new SupportedWindowStateServiceUnitTestImpl(
+ new MockPropertyConfigService());
+ underTest.init(null);
+ }
+
+ protected void tearDown() throws Exception
+ {
+ super.tearDown();
+ underTest = null;
+ }
+
+ /**
+ * Ensure JSR-168 window states are supported by both the portal and the portlet.
+ */
+ public void testIsWindowStateSupported()
+ {
+ // We should support all JSR 168 window states
+ assertTrue(underTest.isWindowStateSupported("some.id", "maximized"));
+ assertTrue(underTest.isWindowStateSupported("some.id", "minimized"));
+ assertTrue(underTest.isWindowStateSupported("some.id", "normal"));
+ assertTrue(underTest.isWindowStateSupported("some.id", WindowState.MAXIMIZED.toString()));
+ assertTrue(underTest.isWindowStateSupported("some.id", WindowState.MINIMIZED.toString()));
+ assertTrue(underTest.isWindowStateSupported("some.id", WindowState.NORMAL.toString()));
+ }
+
+ /**
+ * Ensure a custom window state is supported by both the portal and portlet.
+ */
+ public void testIsCustomWindowStateSupported()
+ {
+ assertTrue(underTest.isWindowStateSupported("some.id", "a-custom-state"));
+ assertTrue(underTest.isWindowStateSupported("some.id", new WindowState("a-custom-state").toString()));
+ }
+
+ /**
+ * Ensure a non-existant window state is not supported by either the portal
+ * or the portlet.
+ */
+ public void testIsNonExistantWindowStateSupported()
+ {
+ assertFalse(underTest.isWindowStateSupported("some.id", "a-nonexistant-state"));
+ assertFalse(underTest.isWindowStateSupported("some.id", new WindowState("a-nonexistant-state").toString()));
+ }
+
+ /**
+ * Ensure the portal supports all JSR-168 mandated window states.
+ */
+ public void testIsWindowStateSupportedByPortal()
+ {
+ // We should support all JSR 168 window states
+ assertTrue(underTest.isWindowStateSupportedByPortal("maximized"));
+ assertTrue(underTest.isWindowStateSupportedByPortal("minimized"));
+ assertTrue(underTest.isWindowStateSupportedByPortal("normal"));
+ assertTrue(underTest.isWindowStateSupportedByPortal(WindowState.MAXIMIZED.toString()));
+ assertTrue(underTest.isWindowStateSupportedByPortal(WindowState.MINIMIZED.toString()));
+ assertTrue(underTest.isWindowStateSupportedByPortal(WindowState.NORMAL.toString()));
+ }
+
+ /**
+ * Ensure custom window states are supported by the portal.
+ */
+ public void testIsCustomWindowStateSupportedByPortal()
+ {
+ assertTrue(underTest.isWindowStateSupportedByPortal("a-custom-state"));
+ assertTrue(underTest.isWindowStateSupportedByPortal(new WindowState("a-custom-state").toString()));
+ }
+
+ /**
+ * Ensure non-existant window states are not supported by the portal.
+ */
+ public void testNonExistantWindowStateSupportedByPortal()
+ {
+ assertFalse(underTest.isWindowStateSupportedByPortal("a-nonexistant-state"));
+ assertFalse(underTest.isWindowStateSupportedByPortal(new WindowState("a-nonexistant-state").toString()));
+ }
+
+ /**
+ * Ensure the portlet supports all JSR-168 window states.
+ */
+ public void testIsWindowStateSupportedByPortlet()
+ {
+ // We should support all JSR 168 window states
+ assertTrue(underTest.isWindowStateSupportedByPortlet("some.id", "maximized"));
+ assertTrue(underTest.isWindowStateSupportedByPortlet("some.id", "minimized"));
+ assertTrue(underTest.isWindowStateSupportedByPortlet("some.id", "normal"));
+ assertTrue(underTest.isWindowStateSupportedByPortlet("some.id", WindowState.MAXIMIZED.toString()));
+ assertTrue(underTest.isWindowStateSupportedByPortlet("some.id", WindowState.MINIMIZED.toString()));
+ assertTrue(underTest.isWindowStateSupportedByPortlet("some.id", WindowState.NORMAL.toString()));
+ }
+
+ /**
+ * Ensure custom window states are supported in the portlet.
+ */
+ public void testIsCustomWindowStateSupportedByPortlet()
+ {
+ assertTrue(underTest.isWindowStateSupportedByPortlet("some.id", "a-custom-state"));
+ assertTrue(underTest.isWindowStateSupportedByPortlet("some.id", new WindowState("a-custom-state").toString()));
+ }
+
+ /**
+ * Ensure non-existant window states are not supported by the portlet.
+ */
+ public void testIsNonExistantWindowStateSupportedByPortlet()
+ {
+ assertFalse(underTest.isWindowStateSupportedByPortlet("some.id", "a-nonexistant-state"));
+ assertFalse(underTest.isWindowStateSupportedByPortlet("some.id", new WindowState("a-nonexistant-state").toString()));
+ }
+
+ /**
+ * This class wraps the actual SupportedWindowStateServiceImpl class in
+ * order to override the init() method and supply mock service objects.
+ *
+ * @author Elliot Metsger (emetsger@jhu.edu)
+ * @since Feb 28, 2007
+ * @version $Id$
+ */
+ private class SupportedWindowStateServiceUnitTestImpl
+ extends SupportedWindowStateServiceImpl
+ {
+ SupportedWindowStateServiceUnitTestImpl(PropertyConfigService svc)
+ {
+ super(svc);
+ }
+
+ public void init(ServletContext ctx) throws DriverConfigurationException
+ {
+ this.portletRegistry = new MockPortletRegistryService(
+ this.getClass().getResourceAsStream("/portlet.xml"));
+ this.portalSupportedWindowStates = propertyService.getSupportedWindowStates();
+ }
+ }
+
+
+}
Propchange: portals/pluto/trunk/pluto-portal-driver-impl/src/test/java/org/apache/pluto/driver/services/impl/resource/SupportedWindowStateServiceTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: portals/pluto/trunk/pluto-portal-driver-impl/src/test/java/org/apache/pluto/driver/services/impl/resource/SupportedWindowStateServiceTest.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: portals/pluto/trunk/pluto-portal-driver-impl/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/portals/pluto/trunk/pluto-portal-driver-impl/src/test/resources/log4j.properties?view=auto&rev=513051
==============================================================================
--- portals/pluto/trunk/pluto-portal-driver-impl/src/test/resources/log4j.properties (added)
+++ portals/pluto/trunk/pluto-portal-driver-impl/src/test/resources/log4j.properties Wed Feb 28 15:13:25 2007
@@ -0,0 +1,22 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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.
+#
+log4j.rootLogger=INFO, STDOUT
+
+log4j.appender.STDOUT=org.apache.log4j.ConsoleAppender
+log4j.appender.STDOUT.layout=org.apache.log4j.PatternLayout
Propchange: portals/pluto/trunk/pluto-portal-driver-impl/src/test/resources/log4j.properties
------------------------------------------------------------------------------
svn:eol-style = native
Added: portals/pluto/trunk/pluto-portal-driver-impl/src/test/resources/pluto-portal-driver-config.xml
URL: http://svn.apache.org/viewvc/portals/pluto/trunk/pluto-portal-driver-impl/src/test/resources/pluto-portal-driver-config.xml?view=auto&rev=513051
==============================================================================
--- portals/pluto/trunk/pluto-portal-driver-impl/src/test/resources/pluto-portal-driver-config.xml (added)
+++ portals/pluto/trunk/pluto-portal-driver-impl/src/test/resources/pluto-portal-driver-config.xml Wed Feb 28 15:13:25 2007
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements. See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You 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.
+-->
+
+<pluto-portal-driver
+ xmlns="http://portals.apache.org/pluto/xsd/pluto-portal-driver-config.xsd"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://portals.apache.org/pluto/xsd/pluto-portal-driver-config.xsd
+ http://portals.apache.org/pluto/xsd/pluto-portal-driver-config.xsd"
+ version="1.1">
+
+ <portal-name>pluto-portal-driver</portal-name>
+ <portal-version>${pom.version}</portal-version>
+ <container-name>Pluto Portal Driver</container-name>
+
+ <supports>
+ <portlet-mode>view</portlet-mode>
+ <portlet-mode>edit</portlet-mode>
+ <portlet-mode>help</portlet-mode>
+ <portlet-mode>config</portlet-mode>
+
+ <window-state>normal</window-state>
+ <window-state>maximized</window-state>
+ <window-state>minimized</window-state>
+ <window-state>a-custom-state</window-state>
+ </supports>
+
+
+ <!-- Render configuration which defines the portal pages. -->
+ <render-config default="Test Page">
+ <page name="Test Page" uri="/WEB-INF/themes/pluto-default-theme.jsp">
+ <portlet context="/testsuite" name="TestPortlet1"/>
+ <portlet context="/testsuite" name="TestPortlet2"/>
+ </page>
+ <page name="Secondary Page" uri="/WEB-INF/themes/pluto-default-theme.jsp">
+ <portlet context="/testsuite" name="TestPortlet1"/>
+ <portlet context="/testsuite" name="TestPortlet2"/>
+ </page>
+ <page name="About Pluto" uri="/WEB-INF/themes/pluto-default-theme.jsp">
+ <portlet context="/pluto" name="AboutPortlet"/>
+ </page>
+ <page name="Pluto Admin" uri="/WEB-INF/themes/pluto-default-theme.jsp">
+ <portlet context="/pluto" name="PlutoPageAdmin"/>
+ <portlet context="/pluto" name="AboutPortlet"/>
+ </page>
+ </render-config>
+
+</pluto-portal-driver>
+
+
Propchange: portals/pluto/trunk/pluto-portal-driver-impl/src/test/resources/pluto-portal-driver-config.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added: portals/pluto/trunk/pluto-portal-driver-impl/src/test/resources/portlet.xml
URL: http://svn.apache.org/viewvc/portals/pluto/trunk/pluto-portal-driver-impl/src/test/resources/portlet.xml?view=auto&rev=513051
==============================================================================
--- portals/pluto/trunk/pluto-portal-driver-impl/src/test/resources/portlet.xml (added)
+++ portals/pluto/trunk/pluto-portal-driver-impl/src/test/resources/portlet.xml Wed Feb 28 15:13:25 2007
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements. See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You 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.
+-->
+
+<portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd"
+ version="1.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd
+ http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd">
+
+ <!-- See also PLT.21.9 for full descriptor -->
+ <portlet>
+ <description>A test portlet.xml</description>
+ <portlet-name>TestPortlet</portlet-name>
+ <portlet-class>some.class</portlet-class>
+ <supports>
+ <mime-type>text/html</mime-type>
+ <portlet-mode>edit</portlet-mode>
+ <portlet-mode>help</portlet-mode>
+ </supports>
+ </portlet>
+ <custom-window-state>
+ <description>A test custom window state</description>
+ <window-state>a-custom-state</window-state>
+ </custom-window-state>
+
+</portlet-app>
Propchange: portals/pluto/trunk/pluto-portal-driver-impl/src/test/resources/portlet.xml
------------------------------------------------------------------------------
svn:eol-style = native
Modified: portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/config/DriverConfiguration.java
URL: http://svn.apache.org/viewvc/portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/config/DriverConfiguration.java?view=diff&rev=513051&r1=513050&r2=513051
==============================================================================
--- portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/config/DriverConfiguration.java (original)
+++ portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/config/DriverConfiguration.java Wed Feb 28 15:13:25 2007
@@ -97,6 +97,12 @@
boolean isPortletModeSupportedByPortlet(String portletId, String mode);
boolean isPortletModeSupported(String portletId, String mode);
+
+ boolean isWindowStateSupportedByPortal(String windowState);
+
+ boolean isWindowStateSupportedByPortlet(String portletId, String windowState);
+
+ boolean isWindowStateSupported(String portletId, String windowState);
//
// Utility methods for the container
Added: portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/portal/SupportedWindowStateService.java
URL: http://svn.apache.org/viewvc/portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/portal/SupportedWindowStateService.java?view=auto&rev=513051
==============================================================================
--- portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/portal/SupportedWindowStateService.java (added)
+++ portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/portal/SupportedWindowStateService.java Wed Feb 28 15:13:25 2007
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.pluto.driver.services.portal;
+
+/**
+ * Allows clients to see if a particular WindowState is supported by
+ * the portal, a particular portlet, or both.
+ *
+ * @author Elliot Metsger (emetsger@jhu.edu)
+ * @since Feb 27, 2007
+ * @version $Id$
+ * @see javax.portlet.WindowState
+ */
+public interface SupportedWindowStateService extends DriverConfigurationService {
+
+ /**
+ * Returns true if the portlet and the portal support the supplied
+ * window state.
+ * @param portletId the id uniquely identifying the portlet
+ * @param state the portlet window state
+ * @return true if the portlet and portal both support the supplied window state
+ */
+ public boolean isWindowStateSupported( String portletId, String state );
+
+ /**
+ * Returns true if the portal supports the supplied window state.
+ * @param state the portlet window state
+ * @return true if the portal supports the supplied window state
+ */
+ public boolean isWindowStateSupportedByPortal( String state );
+
+ /**
+ * Returns true if the portlet supports the supplied window state.
+ * @param portletId the id uniquely identifying the portlet
+ * @param state the window state
+ * @return true if the portlet support the supplied state
+ */
+ public boolean isWindowStateSupportedByPortlet( String portletId, String state );
+
+}
Propchange: portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/portal/SupportedWindowStateService.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/portal/SupportedWindowStateService.java
------------------------------------------------------------------------------
svn:keywords = Id