cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r429435 - /cocoon/trunk/blocks/cocoon-portal/cocoon-portal-portlet-newimpl/src/main/java/org/apache/cocoon/portal/pluto/
Date Mon, 07 Aug 2006 19:11:09 GMT
Author: cziegeler
Date: Mon Aug  7 12:11:08 2006
New Revision: 429435

URL: http://svn.apache.org/viewvc?rev=429435&view=rev
Log:
Continue implementation

Added:
    cocoon/trunk/blocks/cocoon-portal/cocoon-portal-portlet-newimpl/src/main/java/org/apache/cocoon/portal/pluto/PortalCallbackServiceImpl.java
  (with props)
    cocoon/trunk/blocks/cocoon-portal/cocoon-portal-portlet-newimpl/src/main/java/org/apache/cocoon/portal/pluto/PortletAdapter.java
  (with props)
    cocoon/trunk/blocks/cocoon-portal/cocoon-portal-portlet-newimpl/src/main/java/org/apache/cocoon/portal/pluto/PortletURLConverter.java
  (with props)
    cocoon/trunk/blocks/cocoon-portal/cocoon-portal-portlet-newimpl/src/main/java/org/apache/cocoon/portal/pluto/PortletURLProviderImpl.java
  (with props)
Modified:
    cocoon/trunk/blocks/cocoon-portal/cocoon-portal-portlet-newimpl/src/main/java/org/apache/cocoon/portal/pluto/ContainerServicesImpl.java

Modified: cocoon/trunk/blocks/cocoon-portal/cocoon-portal-portlet-newimpl/src/main/java/org/apache/cocoon/portal/pluto/ContainerServicesImpl.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-portal/cocoon-portal-portlet-newimpl/src/main/java/org/apache/cocoon/portal/pluto/ContainerServicesImpl.java?rev=429435&r1=429434&r2=429435&view=diff
==============================================================================
--- cocoon/trunk/blocks/cocoon-portal/cocoon-portal-portlet-newimpl/src/main/java/org/apache/cocoon/portal/pluto/ContainerServicesImpl.java
(original)
+++ cocoon/trunk/blocks/cocoon-portal/cocoon-portal-portlet-newimpl/src/main/java/org/apache/cocoon/portal/pluto/ContainerServicesImpl.java
Mon Aug  7 12:11:08 2006
@@ -37,12 +37,13 @@
 
     protected PortalContext portalContext = new PortalContextImpl();
 
+    protected PortalCallbackServiceImpl portalCallbackService = new PortalCallbackServiceImpl();
+
     /**
      * @see org.apache.pluto.RequiredContainerServices#getPortalCallbackService()
      */
     public PortalCallbackService getPortalCallbackService() {
-        // TODO Auto-generated method stub
-        return null;
+        return this.portalCallbackService;
     }
 
     /**

Added: cocoon/trunk/blocks/cocoon-portal/cocoon-portal-portlet-newimpl/src/main/java/org/apache/cocoon/portal/pluto/PortalCallbackServiceImpl.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-portal/cocoon-portal-portlet-newimpl/src/main/java/org/apache/cocoon/portal/pluto/PortalCallbackServiceImpl.java?rev=429435&view=auto
==============================================================================
--- cocoon/trunk/blocks/cocoon-portal/cocoon-portal-portlet-newimpl/src/main/java/org/apache/cocoon/portal/pluto/PortalCallbackServiceImpl.java
(added)
+++ cocoon/trunk/blocks/cocoon-portal/cocoon-portal-portlet-newimpl/src/main/java/org/apache/cocoon/portal/pluto/PortalCallbackServiceImpl.java
Mon Aug  7 12:11:08 2006
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2006 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.cocoon.portal.pluto;
+
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.pluto.PortletWindow;
+import org.apache.pluto.spi.PortalCallbackService;
+import org.apache.pluto.spi.PortletURLProvider;
+import org.apache.pluto.spi.ResourceURLProvider;
+
+/**
+ * @version $Id$
+ */
+public class PortalCallbackServiceImpl implements PortalCallbackService {
+
+    /**
+     * @see org.apache.pluto.spi.PortalCallbackService#addResponseProperty(javax.servlet.http.HttpServletRequest,
org.apache.pluto.PortletWindow, java.lang.String, java.lang.String)
+     */
+    public void addResponseProperty(HttpServletRequest request, PortletWindow window, String
name, String value) {
+        // TODO Auto-generated method stub        
+    }
+
+    /**
+     * @see org.apache.pluto.spi.PortalCallbackService#getPortletURLProvider(javax.servlet.http.HttpServletRequest,
org.apache.pluto.PortletWindow)
+     */
+    public PortletURLProvider getPortletURLProvider(HttpServletRequest request, PortletWindow
window) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    /**
+     * @see org.apache.pluto.spi.PortalCallbackService#getRequestProperties(javax.servlet.http.HttpServletRequest,
org.apache.pluto.PortletWindow)
+     */
+    public Map getRequestProperties(HttpServletRequest request, PortletWindow window) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    /**
+     * @see org.apache.pluto.spi.PortalCallbackService#getResourceURLProvider(javax.servlet.http.HttpServletRequest,
org.apache.pluto.PortletWindow)
+     */
+    public ResourceURLProvider getResourceURLProvider(HttpServletRequest request, PortletWindow
window) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    /**
+     * @see org.apache.pluto.spi.PortalCallbackService#setResponseProperty(javax.servlet.http.HttpServletRequest,
org.apache.pluto.PortletWindow, java.lang.String, java.lang.String)
+     */
+    public void setResponseProperty(HttpServletRequest request, PortletWindow window, String
name, String value) {
+        // TODO Auto-generated method stub
+        
+    }
+
+    /**
+     * @see org.apache.pluto.spi.PortalCallbackService#setTitle(javax.servlet.http.HttpServletRequest,
org.apache.pluto.PortletWindow, java.lang.String)
+     */
+    public void setTitle(HttpServletRequest request, PortletWindow window, String title)
{
+        // TODO Auto-generated method stub
+        
+    }
+}

Propchange: cocoon/trunk/blocks/cocoon-portal/cocoon-portal-portlet-newimpl/src/main/java/org/apache/cocoon/portal/pluto/PortalCallbackServiceImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/blocks/cocoon-portal/cocoon-portal-portlet-newimpl/src/main/java/org/apache/cocoon/portal/pluto/PortalCallbackServiceImpl.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/trunk/blocks/cocoon-portal/cocoon-portal-portlet-newimpl/src/main/java/org/apache/cocoon/portal/pluto/PortletAdapter.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-portal/cocoon-portal-portlet-newimpl/src/main/java/org/apache/cocoon/portal/pluto/PortletAdapter.java?rev=429435&view=auto
==============================================================================
--- cocoon/trunk/blocks/cocoon-portal/cocoon-portal-portlet-newimpl/src/main/java/org/apache/cocoon/portal/pluto/PortletAdapter.java
(added)
+++ cocoon/trunk/blocks/cocoon-portal/cocoon-portal-portlet-newimpl/src/main/java/org/apache/cocoon/portal/pluto/PortletAdapter.java
Mon Aug  7 12:11:08 2006
@@ -0,0 +1,218 @@
+/*
+ * Copyright 2004-2005 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.cocoon.portal.pluto;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import javax.portlet.WindowState;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.avalon.framework.parameters.ParameterException;
+import org.apache.avalon.framework.parameters.Parameterizable;
+import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.cocoon.ProcessingException;
+import org.apache.cocoon.portal.PortalManagerAspect;
+import org.apache.cocoon.portal.PortalManagerAspectPrepareContext;
+import org.apache.cocoon.portal.PortalManagerAspectRenderContext;
+import org.apache.cocoon.portal.PortalService;
+import org.apache.cocoon.portal.coplet.CopletDefinitionFeatures;
+import org.apache.cocoon.portal.coplet.CopletInstance;
+import org.apache.cocoon.portal.coplet.adapter.CopletDecorationProvider;
+import org.apache.cocoon.portal.coplet.adapter.impl.AbstractCopletAdapter;
+import org.apache.cocoon.portal.event.Receiver;
+import org.apache.cocoon.portal.event.coplet.CopletInstanceSizingEvent;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+
+
+/**
+ * This is the adapter to use JSR-168 portlets as coplets.
+ *
+ * @version $Id$
+ */
+public class PortletAdapter 
+    extends AbstractCopletAdapter
+    implements PortalManagerAspect, CopletDecorationProvider, Receiver, Parameterizable {
+
+    /** Name of the temporary coplet instance attribute holding the portlet window. */
+    public static final String PORTLET_WINDOW_ATTRIBUTE_NAME = PortletAdapter.class.getName()
+ "/window";
+
+    /** Name of the temporary coplet instance attribute holding the dynamic title (if any).
*/
+    public static final String DYNAMIC_TITLE_ATTRIBUTE_NAME = PortletAdapter.class.getName()
+ "/dynamic-title";
+
+    /** Name of the temporary coplet instance attribute holding the window state. */
+    public static final String WINDOW_STATE_ATTRIBUTE_NAME = PortletAdapter.class.getName()
+ "/window-state";
+
+    /** Name of the temporary coplet instance attribute holding the portlet mode. */
+    public static final String PORTLET_MODE_ATTRIBUTE_NAME = PortletAdapter.class.getName()
+ "/portlet-mode";
+
+    /** Name of the portlet mode for full screen (if supported). */
+    public static final String FULL_SCREEN_WINDOW_STATE_ATTRIBUTE_NAME = "full-screen-mode";
+
+    /** Name of attribute in the coplet definition storing the portlet identifier. */
+    public static final String PORTLET_ATTRIBUTE_NAME = "portlet";
+
+    /** The configuration. */
+    protected Parameters parameters;
+
+    /** Is full-screen enabled? */
+    protected boolean enableFullScreen;
+
+    /** Is maximized enabled? */
+    protected boolean enableMaximized;
+
+    /**
+     * @see org.apache.avalon.framework.parameters.Parameterizable#parameterize(org.apache.avalon.framework.parameters.Parameters)
+     */
+    public void parameterize(Parameters params) throws ParameterException {
+        this.parameters = params;
+    }
+
+    /**
+     * @see org.apache.cocoon.portal.coplet.adapter.CopletAdapter#login(org.apache.cocoon.portal.coplet.CopletInstance)
+     */
+    public void login(CopletInstance coplet) {
+        super.login(coplet);
+    }
+
+    /**
+     * @see org.apache.cocoon.portal.coplet.adapter.impl.AbstractCopletAdapter#streamContent(org.apache.cocoon.portal.coplet.CopletInstance,
org.xml.sax.ContentHandler)
+     */
+    public void streamContent(CopletInstance coplet,
+                              ContentHandler contentHandler)
+    throws SAXException {
+    }
+
+    /**
+     * @see org.apache.cocoon.portal.coplet.adapter.CopletAdapter#logout(org.apache.cocoon.portal.coplet.CopletInstance)
+     */
+    public void logout(CopletInstance coplet) {
+        super.logout(coplet);
+    }
+
+    /**
+     * @see org.apache.avalon.framework.activity.Disposable#dispose()
+     */
+    public void dispose() {
+        super.dispose();
+    }
+
+    /**
+     * @see org.apache.avalon.framework.activity.Initializable#initialize()
+     */
+    public void initialize() throws Exception {
+        super.initialize();
+        this.enableFullScreen = this.portalService.getConfigurationAsBoolean(PortalService.CONFIGURATION_FULL_SCREEN_ENABLED,
true);
+        this.enableMaximized = this.portalService.getConfigurationAsBoolean(PortalService.CONFIGURATION_MAXIMIZED_ENABLED,
true);
+        this.initContainer();
+    }
+
+    /**
+     * Initialize the container
+     */
+    public void initContainer() throws Exception {
+    }
+
+    /**
+     * This method is invoked each time an event for a portlet is received (user clicking/activating
+     * something in the portlet).
+     * @see Receiver
+     */
+    public void inform(PortletURLProviderImpl event, PortalService service) {
+    }
+
+    /**
+     * This method is invoked each time a coplet instance is resized.
+     * @see Receiver
+     */
+    public void inform(CopletInstanceSizingEvent event, PortalService service) {
+        WindowState ws = WindowState.NORMAL;
+        if ( event.getSize() == CopletInstance.SIZE_NORMAL ) {
+            ws = WindowState.NORMAL;
+        } else if ( event.getSize() == CopletInstance.SIZE_MAXIMIZED ) {
+            ws = WindowState.MAXIMIZED;
+        } else if ( event.getSize() == CopletInstance.SIZE_MINIMIZED ) {
+            ws = WindowState.MINIMIZED;
+        } else if ( event.getSize() == CopletInstance.SIZE_FULLSCREEN ) {
+            ws = new WindowState((String)CopletDefinitionFeatures.getAttributeValue(event.getTarget().getCopletDefinition(),
FULL_SCREEN_WINDOW_STATE_ATTRIBUTE_NAME, null));
+        }
+        final String wsString = (String)event.getTarget().getTemporaryAttribute(WINDOW_STATE_ATTRIBUTE_NAME);
+        if ( !wsString.equals(ws.toString()) ) {
+            event.getTarget().setTemporaryAttribute(WINDOW_STATE_ATTRIBUTE_NAME, ws.toString());
+        }
+    }
+
+    /**
+     * @see org.apache.cocoon.portal.PortalManagerAspect#prepare(org.apache.cocoon.portal.PortalManagerAspectPrepareContext,
org.apache.cocoon.portal.PortalService)
+     */
+    public void prepare(PortalManagerAspectPrepareContext aspectContext,
+                        PortalService service)
+    throws ProcessingException {
+        // process the events
+        aspectContext.invokeNext();
+
+    }
+
+    /**
+     * @see org.apache.cocoon.portal.PortalManagerAspect#render(org.apache.cocoon.portal.PortalManagerAspectRenderContext,
org.apache.cocoon.portal.PortalService, org.xml.sax.ContentHandler, java.util.Properties)
+     */
+    public void render(PortalManagerAspectRenderContext aspectContext,
+                       PortalService service,
+                       ContentHandler ch,
+                       Properties properties)
+    throws SAXException {
+        final Map objectModel = aspectContext.getObjectModel();
+
+        // don't generate a response, if we issued a redirect
+        if (objectModel.remove("portlet-event") == null) {
+            aspectContext.invokeNext(ch, properties);
+        }
+    }
+
+    protected String getResponse(CopletInstance instance, HttpServletResponse response) {
+        return response.toString();
+    }
+
+    /**
+     * @see org.apache.cocoon.portal.coplet.adapter.CopletDecorationProvider#getPossibleCopletModes(CopletInstance)
+     */
+    public List getPossibleCopletModes(CopletInstance copletInstanceData) {
+        final List modes = new ArrayList();
+        return modes;
+    }
+
+    /**
+     * @see org.apache.cocoon.portal.coplet.adapter.CopletDecorationProvider#getPossibleWindowStates(CopletInstance)
+     */
+    public List getPossibleWindowStates(CopletInstance copletInstanceData) {
+        final List states = new ArrayList();
+        return states;
+    }
+
+    /**
+     * @see org.apache.cocoon.portal.coplet.adapter.CopletDecorationProvider#getTitle(org.apache.cocoon.portal.coplet.CopletInstance)
+     */
+    public String getTitle(CopletInstance copletInstanceData) {
+        String title = null;
+        if ( title == null ) {
+            title = copletInstanceData.getTitle();
+        }
+        return title;
+    }
+}

Propchange: cocoon/trunk/blocks/cocoon-portal/cocoon-portal-portlet-newimpl/src/main/java/org/apache/cocoon/portal/pluto/PortletAdapter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/blocks/cocoon-portal/cocoon-portal-portlet-newimpl/src/main/java/org/apache/cocoon/portal/pluto/PortletAdapter.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/trunk/blocks/cocoon-portal/cocoon-portal-portlet-newimpl/src/main/java/org/apache/cocoon/portal/pluto/PortletURLConverter.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-portal/cocoon-portal-portlet-newimpl/src/main/java/org/apache/cocoon/portal/pluto/PortletURLConverter.java?rev=429435&view=auto
==============================================================================
--- cocoon/trunk/blocks/cocoon-portal/cocoon-portal-portlet-newimpl/src/main/java/org/apache/cocoon/portal/pluto/PortletURLConverter.java
(added)
+++ cocoon/trunk/blocks/cocoon-portal/cocoon-portal-portlet-newimpl/src/main/java/org/apache/cocoon/portal/pluto/PortletURLConverter.java
Mon Aug  7 12:11:08 2006
@@ -0,0 +1,290 @@
+/*
+ * Copyright 2003-2005 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.cocoon.portal.pluto;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.StringTokenizer;
+
+import javax.portlet.PortletMode;
+import javax.portlet.WindowState;
+
+import org.apache.pluto.util.StringUtils;
+
+/**
+ * Create the URL for a portlet.
+ *
+ * @version $Id$
+ */
+public class PortletURLConverter {
+
+    public static final String ACTION = "ac";
+    public static final String MODE = "md";
+    public static final String PORTLET_ID = "pid";
+    public static final String PREFIX = "_";
+    public static final String PARAM = "pm";
+    public static final String STATE = "st";
+
+    private final Map urlData = new HashMap();
+    private final Map parameters = new HashMap();
+    private String copletId;
+
+    /**
+     * Constructor used when the URL will be marshalled.
+     * @param cid The coplet id.
+     */
+    public PortletURLConverter() {
+        // default constructor
+    }
+
+    /**
+     * Constructor used when the URL will be unmarshalled.
+     * @param eventData The url data.
+     */
+    public PortletURLConverter(String eventData) {
+        StringTokenizer tokenizer = new StringTokenizer(eventData, "/");
+        while (tokenizer.hasMoreTokens()) {
+            String token = tokenizer.nextToken();
+            if (isParameter(token)) {
+                String name = decodeParameterName(token);
+                String key = encodeParameterName(name);
+                this.parameters.put(key, token.substring(key.length()));
+            } else {
+                StringTokenizer tokens = new StringTokenizer(token, PREFIX);
+
+                if (tokens.countTokens() > 1) {
+                    String key = tokens.nextToken();
+                    if (key.equals(PORTLET_ID)) {
+                        this.copletId = tokens.nextToken();
+                    } else {
+                        String value = tokens.nextToken();
+                        urlData.put(key, value);
+                    }
+                }
+            }
+        }
+    }
+
+    /**
+     * Return the PortletMode
+     * @return The PortletMode
+     */
+    public PortletMode getMode() {
+        String mode = (String)urlData.get(getModeKey());
+        if (mode != null) {
+            return new PortletMode(mode);
+        }
+        return PortletMode.VIEW;
+    }
+
+    /**
+     * Return the WindowState
+     * @return The WindowState
+     */
+    public WindowState getState() {
+        String state = (String) urlData.get(getStateKey());
+        if (state != null) {
+            return new WindowState(state);
+        }
+        return WindowState.NORMAL;
+    }
+
+    /**
+     * Return the indicator if this is an action.
+     * @return true if this is an action URL, false if a render URL.
+     */
+    public boolean isAction() {
+        return (urlData.get(getActionKey()) != null);
+    }
+
+    /**
+     * Indicates that the URL is an action.
+     */
+    public void setAction() {
+        urlData.put(getActionKey(),ACTION.toUpperCase());
+    }
+
+    /**
+     * Sets the PortletMode.
+     * @param mode The PortletMode
+     */
+    public void setMode(PortletMode mode) {
+        urlData.put(getModeKey(), mode.toString());
+    }
+
+    /**
+     * Sets the WindowState
+     * @param state The WindowState
+     */
+    public void setState(WindowState state) {
+        urlData.put(getStateKey(), state.toString());
+    }
+
+    /**
+     * Returns the portlet id.
+     * @return The portlet id.
+     */
+    public String getCopletId() {
+        return this.copletId;
+    }
+
+    public void setCopletId(String value) {
+        this.copletId = value;
+    }
+
+    /**
+     * Returns the request parameters for this portlet URL.
+     * @return A Map containing the parameters for this URL.
+     */
+    public Map getParameters() {
+        Map map = new HashMap();
+        Iterator iter = this.parameters.entrySet().iterator();
+        while (iter.hasNext()) {
+            Map.Entry entry = (Map.Entry)iter.next();
+            String key = decodeParameterName((String) entry.getKey());
+            String[] values = decodeParameterValues((String)entry.getValue());
+            map.put(key, values);
+        }
+        return map;
+    }
+
+    /**
+     * Adds the parameter, replacing a parameter with the same name.
+     * @param name The parameter name
+     * @param values An array of Strings.
+     */
+    public void setParam(String name, String[] values) {
+        this.parameters.put(encodeParameterName(name), encodeParameterValues(values));
+    }
+
+    /**
+     * Returns the marshalled URL.
+     * @return A String containing the marshalled URL.
+     */
+    public String toString() {
+        StringBuffer buffer = new StringBuffer();
+        buffer.append(PORTLET_ID).append(PREFIX).append(copletId);
+        Iterator iter = urlData.entrySet().iterator();
+        while (iter.hasNext()) {
+            buffer.append("/");
+            Map.Entry entry = (Map.Entry)iter.next();
+            buffer.append(entry.getKey()).append(PREFIX).append(entry.getValue());
+        }
+        iter = this.parameters.entrySet().iterator();
+        while (iter.hasNext()) {
+            buffer.append("/");
+            Map.Entry entry = (Map.Entry) iter.next();
+            buffer.append(entry.getKey()).append(PREFIX).append(entry.getValue());
+        }
+        return buffer.toString();
+    }
+
+    private String getActionKey() {
+        return ACTION;
+    }
+
+    private String getModeKey() {
+        return MODE;
+    }
+
+    private String getStateKey() {
+        return STATE;
+    }
+
+    private String getParamKey() {
+        return PARAM + PREFIX;
+    }
+
+    private boolean isParameter(String key) {
+        return key.startsWith(getParamKey());
+    }
+
+    private String decodeParameterName(String encodedParamName) {
+        StringTokenizer tokenizer = new StringTokenizer(encodedParamName, PREFIX);
+        if (!tokenizer.hasMoreTokens()) {
+            return null;
+        }
+        // Skip the key
+        tokenizer.nextToken();
+        if (!tokenizer.hasMoreTokens()) {
+            return null;
+        }
+        String name = tokenizer.nextToken();
+        return decodeValue(name);
+    }
+
+    private String[] decodeParameterValues(String encodedParamValues) {
+        StringTokenizer tokenizer = new StringTokenizer(encodedParamValues, PREFIX);
+        if (!tokenizer.hasMoreTokens()) {
+            return null;
+        }
+        String _count = tokenizer.nextToken();
+        int count = Integer.valueOf(_count).intValue();
+        String[] values = new String[count];
+        for (int i = 0; i < count; i++) {
+            if (!tokenizer.hasMoreTokens()) {
+                return null;
+            }
+            values[i] = decodeValue(tokenizer.nextToken());
+        }
+        return values;
+    }
+
+    private String decodeValue(String value) {
+        String result = value;
+        result = StringUtils.replace(result, "0x1", "_");
+        result = StringUtils.replace(result, "0x2", ".");
+        result = StringUtils.replace(result, "0x3", "/");
+        result = StringUtils.replace(result, "0x4", "\r");
+        result = StringUtils.replace(result, "0x5", "\n");
+        result = StringUtils.replace(result, "0x6", "<");
+        result = StringUtils.replace(result, "0x7", ">");
+        result = StringUtils.replace(result, "0x8", " ");
+        result = StringUtils.replace(result, "0x0", "0x");
+        return result;
+    }
+
+    private String encodeParameterName(String paramName) {
+        StringBuffer returnvalue = new StringBuffer(50);
+        returnvalue.append(getParamKey()).append(encodeValue(paramName));
+        return returnvalue.toString();
+    }
+
+    private String encodeParameterValues(String[] paramValues) {
+        StringBuffer returnvalue = new StringBuffer(100);
+        returnvalue.append(paramValues.length);
+        for (int i = 0; i < paramValues.length; i++) {
+            returnvalue.append("_");
+            returnvalue.append(encodeValue(paramValues[i]));
+        }
+        return returnvalue.toString();
+    }
+
+    private String encodeValue(String value) {
+        String result = value;
+        result = StringUtils.replace(result, "0x", "0x0");
+        result = StringUtils.replace(result, "_", "0x1");
+        result = StringUtils.replace(result, ".", "0x2");
+        result = StringUtils.replace(result, "/", "0x3");
+        result = StringUtils.replace(result, "\r", "0x4");
+        result = StringUtils.replace(result, "\n", "0x5");
+        result = StringUtils.replace(result, "<", "0x6");
+        result = StringUtils.replace(result, ">", "0x7");
+        result = StringUtils.replace(result, " ", "0x8");
+        return result;
+    }
+}
\ No newline at end of file

Propchange: cocoon/trunk/blocks/cocoon-portal/cocoon-portal-portlet-newimpl/src/main/java/org/apache/cocoon/portal/pluto/PortletURLConverter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/blocks/cocoon-portal/cocoon-portal-portlet-newimpl/src/main/java/org/apache/cocoon/portal/pluto/PortletURLConverter.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/trunk/blocks/cocoon-portal/cocoon-portal-portlet-newimpl/src/main/java/org/apache/cocoon/portal/pluto/PortletURLProviderImpl.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-portal/cocoon-portal-portlet-newimpl/src/main/java/org/apache/cocoon/portal/pluto/PortletURLProviderImpl.java?rev=429435&view=auto
==============================================================================
--- cocoon/trunk/blocks/cocoon-portal/cocoon-portal-portlet-newimpl/src/main/java/org/apache/cocoon/portal/pluto/PortletURLProviderImpl.java
(added)
+++ cocoon/trunk/blocks/cocoon-portal/cocoon-portal-portlet-newimpl/src/main/java/org/apache/cocoon/portal/pluto/PortletURLProviderImpl.java
Mon Aug  7 12:11:08 2006
@@ -0,0 +1,211 @@
+/*
+ * Copyright 2004-2005 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.cocoon.portal.pluto;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.portlet.PortletMode;
+import javax.portlet.WindowState;
+
+import org.apache.cocoon.portal.LinkService;
+import org.apache.cocoon.portal.PortalService;
+import org.apache.cocoon.portal.coplet.CopletInstance;
+import org.apache.cocoon.portal.event.ConvertableEvent;
+import org.apache.cocoon.portal.event.CopletInstanceEvent;
+import org.apache.pluto.PortletWindow;
+import org.apache.pluto.spi.PortletURLProvider;
+
+/**
+ * Create the URL for a portlet.
+ *
+ * @version $Id$
+ */
+public class PortletURLProviderImpl 
+       implements PortletURLProvider, CopletInstanceEvent, ConvertableEvent {
+    
+    /** The new portlet mode */
+    protected PortletMode mode;
+    
+    /** The new window state */
+    protected WindowState state;
+    
+    /** Is this an action */
+    protected boolean action;
+    
+    /** Secure link? */
+    protected Boolean secure;
+    
+    /** Clear parameters */
+    protected boolean clearParameters;
+    
+    /** Parameters */
+    protected Map parameters;
+    
+    /** The generated url */
+    protected String generatedURL;
+    private final LinkService linkService;
+
+    /** Tbe coplet instance id. */
+    protected final String copletId;
+
+    /**
+     * Constructor
+     */
+    public PortletURLProviderImpl(PortletWindow portletWindow,
+                                  PortalService service,
+                                  String        copletInstanceId) {
+        this.linkService = service.getLinkService();
+        this.copletId = copletInstanceId;
+    }
+
+    /**
+     * Constructor for factory
+     * @param service
+     * @param eventData
+     */
+    public PortletURLProviderImpl(PortalService service,
+                                  String        eventData) {
+        this.linkService = service.getLinkService();
+        final PortletURLConverter urlConverter = new PortletURLConverter(eventData);
+        this.copletId = urlConverter.getCopletId();
+        this.mode = urlConverter.getMode();
+        this.state = urlConverter.getState();
+        this.action = urlConverter.isAction();
+        this.parameters = urlConverter.getParameters();
+        this.clearParameters = false;
+        this.secure = null;
+    }
+
+    /**
+     * Copy constructor
+     */
+    private PortletURLProviderImpl(PortletURLProviderImpl original) {
+        this.linkService = original.linkService;
+        this.copletId = original.copletId;
+        this.mode = original.mode;
+        this.state = original.state;
+        this.action = original.action;
+        this.secure = original.secure;
+        this.clearParameters = original.clearParameters;
+        this.generatedURL = original.generatedURL;
+        if (original.parameters != null) {
+            this.parameters = new HashMap(original.parameters.size());
+            this.parameters.putAll(original.parameters);
+        }
+    }
+
+    /**
+     * @see org.apache.pluto.spi.PortletURLProvider#setPortletMode(javax.portlet.PortletMode)
+     */
+    public void setPortletMode(PortletMode mode) {
+        this.mode = mode;
+    }
+
+    /**
+     * @see org.apache.pluto.spi.PortletURLProvider#setWindowState(javax.portlet.WindowState)
+     */
+    public void setWindowState(WindowState state) {
+        this.state = state;
+    }
+
+    /**
+     * @see org.apache.pluto.spi.PortletURLProvider#setSecure()
+     */
+    public void setSecure() {
+        this.secure =  Boolean.TRUE;
+    }
+
+    /**
+     * @see org.apache.pluto.spi.PortletURLProvider#clearParameters()
+     */
+    public void clearParameters() {
+        this.clearParameters = true;
+    }
+
+    /**
+     * @see org.apache.pluto.spi.PortletURLProvider#setParameters(java.util.Map)
+     */
+    public void setParameters(Map parameters) {
+        this.parameters = parameters;
+    }
+    
+    /**
+     * @see java.lang.Object#toString()
+     */
+    public String toString() {
+        return new PortletURLProviderImpl(this).getURL();
+    }
+
+    /**
+     * @return
+     */
+    private String getURL() {
+        if ( this.generatedURL == null ) {
+            this.generatedURL = this.linkService.getLinkURI(this, this.secure);
+        }
+        return linkService.encodeURL(this.generatedURL);
+    }
+
+    /**
+     * @see org.apache.cocoon.portal.event.CopletInstanceEvent#getTarget()
+     */
+    public CopletInstance getTarget() {        
+        return null;//((PortletEntityImpl)this.portletWindow.getPortletEntity()).getCopletInstanceData();
+    }
+
+    /**
+     * Return the URL as a String.
+     * @see org.apache.cocoon.portal.event.ConvertableEvent#asString()
+     */
+    public String asString() {
+        PortletURLConverter urlConverter = new PortletURLConverter();
+        urlConverter.setCopletId(this.copletId);
+        if (this.mode != null) {
+            urlConverter.setMode(this.mode);
+        }
+
+        if (this.state != null) {
+            urlConverter.setState(this.state);
+        }
+
+        if (this.action) {
+            urlConverter.setAction();
+        }
+
+        if (this.parameters != null) {
+            Iterator entries = this.parameters.entrySet().iterator();
+            while (entries.hasNext()) {
+                Map.Entry entry = (Map.Entry)entries.next();
+                String name = (String) entry.getKey();
+                Object value = entry.getValue();
+                String[] values = value instanceof String ?
+                    new String[]{(String) value} : (String[]) value;
+                urlConverter.setParam(name, values);
+            }
+        }
+
+        return urlConverter.toString();
+    }
+
+    /**
+     * @see org.apache.pluto.spi.PortletURLProvider#setAction(boolean)
+     */
+    public void setAction(boolean flag) {
+        this.action = flag;
+    }
+}

Propchange: cocoon/trunk/blocks/cocoon-portal/cocoon-portal-portlet-newimpl/src/main/java/org/apache/cocoon/portal/pluto/PortletURLProviderImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/blocks/cocoon-portal/cocoon-portal-portlet-newimpl/src/main/java/org/apache/cocoon/portal/pluto/PortletURLProviderImpl.java
------------------------------------------------------------------------------
    svn:keywords = Id



Mime
View raw message