Author: cmailleux
Date: Wed Aug 16 11:27:10 2006
New Revision: 14905

URL: https://svndev.jahia.net/websvn/listing.php?sc=1&rev=14905&repname=jahia
Log:
Change pluto version
Change action url building
Avoid double rendering (but this must not be a problem, this is a workaround.
Override PortletEntityImpl to allow per user preferences in portlets and not 
only per instance. (This class must be copied into tomcat/shared/classes)

Added:
    trunk/core/src/java/org/apache/jetspeed/
    trunk/core/src/java/org/apache/jetspeed/components/
    trunk/core/src/java/org/apache/jetspeed/components/portletentity/
    
trunk/core/src/java/org/apache/jetspeed/components/portletentity/PortletEntityImpl.java
Modified:
    trunk/core/project.xml
    trunk/core/src/java/org/jahia/operations/PageGeneratorQueue.java
    trunk/core/src/java/org/jahia/operations/valves/J2ProcessActionValve.java
    
trunk/core/src/java/org/jahia/services/applications/JahiaJ2SessionPortalURL.java
    
trunk/core/src/java/org/jahia/services/applications/JetspeedDispatchingProvider.java
    
trunk/core/src/java/org/jahia/services/applications/ServletIncludeResponseWrapper.java
    trunk/core/src/java/org/jahia/services/fields/ContentApplicationField.java

Modified: trunk/core/project.xml
URL: 
https://svndev.jahia.net/websvn/diff.php?path=/trunk/core/project.xml&rev=14905&repname=jahia
==============================================================================
--- trunk/core/project.xml (original)
+++ trunk/core/project.xml Wed Aug 16 11:27:10 2006
@@ -1100,7 +1100,7 @@
     <dependency>
       <id>pluto</id>
       <groupId>org.apache.pluto</groupId>
-      <version>1.0.1</version>
+      <version>1.0.1-JAHIA-SNAPSHOT</version>
       <properties>
         <war.bundle>false</war.bundle>
         <war.shared.lib>true</war.shared.lib>

Added: 
trunk/core/src/java/org/apache/jetspeed/components/portletentity/PortletEntityImpl.java
URL: 
https://svndev.jahia.net/websvn/filedetails.php?path=/trunk/core/src/java/org/apache/jetspeed/components/portletentity/PortletEntityImpl.java&rev=14905&repname=jahia
==============================================================================
--- 
trunk/core/src/java/org/apache/jetspeed/components/portletentity/PortletEntityImpl.java
 (added)
+++ 
trunk/core/src/java/org/apache/jetspeed/components/portletentity/PortletEntityImpl.java
 Wed Aug 16 11:27:10 2006
@@ -0,0 +1,527 @@
+package org.apache.jetspeed.components.portletentity;
+
+import org.apache.jetspeed.om.common.portlet.MutablePortletEntity;
+import org.apache.jetspeed.om.common.portlet.PrincipalAware;
+import org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite;
+import org.apache.jetspeed.om.common.portlet.MutablePortletApplication;
+import org.apache.jetspeed.om.common.preference.PreferenceSetComposite;
+import org.apache.jetspeed.om.page.Fragment;
+import org.apache.jetspeed.om.window.impl.PortletWindowListImpl;
+import org.apache.jetspeed.om.preference.impl.PrefsPreferenceSetImpl;
+import org.apache.jetspeed.om.preference.impl.PrefsPreference;
+import org.apache.jetspeed.om.portlet.impl.FragmentPortletDefinition;
+import org.apache.jetspeed.components.persistence.store.RemovalAware;
+import org.apache.jetspeed.components.persistence.store.PersistenceStore;
+import 
org.apache.jetspeed.components.persistence.store.PersistenceStoreRuntimeExcpetion;
+import org.apache.jetspeed.components.portletregistry.PortletRegistry;
+import org.apache.jetspeed.util.JetspeedObjectID;
+import org.apache.pluto.om.entity.PortletApplicationEntity;
+import org.apache.pluto.om.entity.PortletEntity;
+import org.apache.pluto.om.window.PortletWindowList;
+import org.apache.pluto.om.common.ObjectID;
+import org.apache.pluto.om.common.PreferenceSet;
+import org.apache.pluto.om.common.Description;
+import org.apache.pluto.om.portlet.PortletDefinition;
+import org.apache.pluto.util.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jahia.bin.Jahia;
+
+import java.util.*;
+import java.util.prefs.Preferences;
+import java.util.prefs.BackingStoreException;
+import java.security.Principal;
+import java.io.IOException;
+
+/**
+ * Portlet Entity default implementation.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">David Sean Taylor </a>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Scott T. Weaver </a>
+ * @version $Id: PortletEntityImpl.java,v 1.9 2005/04/29 13:59:08 weaver Exp $
+ */
+public class PortletEntityImpl implements MutablePortletEntity, 
PrincipalAware, RemovalAware
+{
+
+    private long oid;
+
+    private long portletId;
+
+    private JetspeedObjectID id;
+
+    protected static PortletEntityAccessComponent pac;
+
+    protected static PortletRegistry registry;
+
+    private static final Log log = LogFactory.getLog(PortletEntityImpl.class);
+
+    protected List originalPreferences;
+
+    // protected PrefsPreferenceSetImpl preferenceSet;
+    // protected ThreadLocal preferenceSetRef = new ThreadLocal();
+    protected Map perPrincipalPrefs = new HashMap();
+
+    protected Map originalValues;
+
+    private PortletApplicationEntity applicationEntity = null;
+
+    private PortletWindowList portletWindows = new PortletWindowListImpl();
+
+    private PortletEntity modifiedObject = null;
+
+    private PortletDefinitionComposite portletDefinition = null;
+
+    protected String portletName;
+
+    protected String appName;
+
+    private boolean dirty = false;
+
+    private Fragment fragment;
+
+    public PortletEntityImpl(Fragment fragment)
+    {
+        setFragment(fragment);
+    }
+
+    public PortletEntityImpl()
+    {
+        super();
+    }
+
+    // protected Principal principal;
+    protected ThreadLocal principalRef = new ThreadLocal();
+
+    public static final String NO_PRINCIPAL = "no-principal";
+    public static final String ENTITY_DEFAULT_PRINCIPAL = "entity-default";
+
+    public ObjectID getId()
+    {
+        return id;
+    }
+
+    public long getOid()
+    {
+        return oid;
+    }
+
+    public void setId( String id )
+    {
+        this.id = JetspeedObjectID.createFromString(id);
+    }
+
+    /**
+     *
+     * <p>
+     * getPreferenceSet
+     * </p>
+     *
+     * @see org.apache.pluto.om.entity.PortletEntity#getPreferenceSet()
+     * @return
+     */
+    public PreferenceSet getPreferenceSet()
+    {
+        Principal currentUser = getPrincipal();
+        return getPreferenceSet(currentUser);
+    }
+
+    public PreferenceSet getPreferenceSet(Principal principal)
+    {
+        PrefsPreferenceSetImpl preferenceSet = (PrefsPreferenceSetImpl) 
perPrincipalPrefs.get(principal);
+        try
+        {
+            if (preferenceSet == null || !dirty)
+            {
+                //TODO: need to be setting this from 
PortletEntityAccessComponent until then it will always be null.
+                String prefNodePath = MutablePortletEntity.PORTLET_ENTITY_ROOT 
+ "/" + getId() +"/"+ principal.getName() +"/"
+                                      + 
PrefsPreference.PORTLET_PREFERENCES_ROOT;
+                Preferences prefNode = 
Preferences.userRoot().node(prefNodePath);
+
+                // NO_PRINCIPAL is actually the defa
+                if(principal.getName().equals(ENTITY_DEFAULT_PRINCIPAL))
+                {
+                    preferenceSet = new PrefsPreferenceSetImpl(prefNode);
+                }
+                else
+                {
+                    preferenceSet = new PrefsPreferenceSetImpl(prefNode, 
(PreferenceSetComposite) getPreferenceSet(new 
PortletEntityUserPrincipal(ENTITY_DEFAULT_PRINCIPAL)) );
+                }
+                perPrincipalPrefs.put(principal, preferenceSet);
+                backupValues(preferenceSet);
+                dirty = true;
+            }
+        }
+        catch (BackingStoreException e)
+        {
+            String msg = "Preference backing store failed: " + e.toString();
+            IllegalStateException ise = new IllegalStateException(msg);
+            ise.initCause(e);
+            throw ise;
+        }
+        return preferenceSet;
+    }
+
+    /**
+     * <p>
+     * backupValues
+     * </p>
+     *
+     *
+     */
+    protected void backupValues( PreferenceSet preferenceSet )
+    {
+        originalValues = new HashMap();
+        Iterator itr = preferenceSet.iterator();
+        while (itr.hasNext())
+        {
+            PrefsPreference pref = (PrefsPreference) itr.next();
+
+            String[] currentValues = pref.getValueArray();
+            String[] backUp = new String[currentValues.length];
+            System.arraycopy(currentValues, 0, backUp, 0, 
currentValues.length);
+            originalValues.put(pref.getName(), backUp);
+
+        }
+    }
+
+    public PortletDefinition getPortletDefinition()
+    {
+        // there are cases when jetspeed gets initialized before
+        // all of the portlet web apps have.  In this event, premature
+        // access to the portal would cause portlet entities to be cached
+        // with their associated window without there corresponding 
PortletDefinition
+        // (becuase the PortletApplication has yet to be registered).
+        if(this.portletDefinition == null)
+        {
+            
setPortletDefinition(registry.getPortletDefinitionByIdentifier(getPortletUniqueName()));
+        }
+
+        // Wrap the portlet defintion every request
+        return new FragmentPortletDefinition(this.portletDefinition, fragment);
+    }
+
+    public PortletApplicationEntity getPortletApplicationEntity()
+    {
+        return applicationEntity;
+    }
+
+    public PortletWindowList getPortletWindowList()
+    {
+        return portletWindows;
+    }
+
+    /**
+     *
+     * <p>
+     * store
+     * </p>
+     *
+     */
+    public void store() throws IOException
+    {
+        store(getPrincipal());
+    }
+
+    public void store(Principal principal) throws IOException
+    {
+        if (pac == null)
+        {
+            throw new IllegalStateException("You must call 
PortletEntityImpl.setPorteltEntityDao() before "
+                                            + "invoking 
PortletEntityImpl.store().");
+        }
+
+        PreferenceSet preferenceSet = 
(PreferenceSet)perPrincipalPrefs.get(principal);
+        pac.storePreferenceSet(preferenceSet, this);
+        dirty = false;
+        if (preferenceSet != null)
+        {
+            backupValues(preferenceSet);
+        }
+    }
+
+    /**
+     *
+     * <p>
+     * reset
+     * </p>
+     *
+     */
+
+    public void reset() throws IOException
+    {
+        PrefsPreferenceSetImpl preferenceSet = (PrefsPreferenceSetImpl) 
perPrincipalPrefs.get(getPrincipal());
+        try
+        {
+            if (originalValues != null && preferenceSet != null)
+            {
+                Iterator prefs = preferenceSet.iterator();
+
+                while (prefs.hasNext())
+                {
+                    PrefsPreference pref = (PrefsPreference) prefs.next();
+                    if (originalValues.containsKey(pref.getName()))
+                    {
+                        pref.setValues((String[]) 
originalValues.get(pref.getName()));
+                    }
+                    else
+                    {
+                        preferenceSet.remove(pref);
+                    }
+                    preferenceSet.flush();
+                }
+
+                Iterator keys = originalValues.keySet().iterator();
+                while (keys.hasNext())
+                {
+                    String key = (String) keys.next();
+                    if (preferenceSet.get(key) == null)
+                    {
+                        preferenceSet.add(key, Arrays.asList((String[]) 
originalValues.get(key)));
+                    }
+                }
+            }
+            dirty = false;
+            backupValues(preferenceSet);
+        }
+        catch (BackingStoreException e)
+        {
+            String msg = "Preference backing store failed: " + e.toString();
+            IOException ioe = new IOException(msg);
+            ioe.initCause(e);
+            throw ioe;
+        }
+
+    }
+
+    // internal methods used for debugging purposes only
+
+    public String toString()
+    {
+        return toString(0);
+    }
+
+    public String toString( int indent )
+    {
+        StringBuffer buffer = new StringBuffer(1000);
+        StringUtils.newLine(buffer, indent);
+        buffer.append(getClass().toString());
+        buffer.append(":");
+        StringUtils.newLine(buffer, indent);
+        buffer.append("{");
+        StringUtils.newLine(buffer, indent);
+        buffer.append("id='");
+        buffer.append(oid);
+        buffer.append("'");
+        StringUtils.newLine(buffer, indent);
+        buffer.append("definition-id='");
+        if(portletDefinition != null)
+        {
+            buffer.append(portletDefinition.getId().toString());
+        }
+        else
+        {
+            buffer.append("null");
+        }
+        buffer.append("'");
+
+        StringUtils.newLine(buffer, indent);
+        //buffer.append(((PreferenceSetImpl)preferences).toString(indent));
+
+        StringUtils.newLine(buffer, indent);
+        buffer.append("}");
+        return buffer.toString();
+    }
+
+    /**
+     * @see 
org.apache.pluto.om.entity.PortletEntity#getDescription(java.util.Locale)
+     */
+    public Description getDescription( Locale arg0 )
+    {
+        return portletDefinition.getDescription(arg0);
+    }
+
+    /**
+     * <p>
+     * setPortletDefinition
+     * </p>
+     *
+     * @param composite
+     *
+     */
+    public void setPortletDefinition( PortletDefinition composite )
+    {
+        if(composite != null)
+        {
+            portletDefinition = (PortletDefinitionComposite) composite;
+            this.appName = 
((MutablePortletApplication)portletDefinition.getPortletApplicationDefinition()).getName();
+            this.portletName = portletDefinition.getName();
+        }
+        else
+        {
+            throw new IllegalArgumentException("Cannot pass a null 
PortletDefinition to a PortletEntity.");
+        }
+    }
+
+    /**
+     * @return Returns the principal.
+     */
+    public Principal getPrincipal()
+    {
+        Principal principal = Jahia.getThreadParamBean().getUser();
+        if (principal == null)
+        {
+            principal = new PortletEntityUserPrincipal(NO_PRINCIPAL);
+        }
+
+        return principal;
+    }
+
+    /**
+     * @param principal
+     *            The principal to set.
+     */
+    protected void setPrincipal( Principal principal )
+    {
+        principalRef.set(principal);
+    }
+
+    class PortletEntityUserPrincipal implements Principal
+    {
+        String name;
+
+        protected PortletEntityUserPrincipal( String name )
+        {
+            this.name = name;
+        }
+
+        /**
+         * <p>
+         * getName
+         * </p>
+         *
+         * @see java.security.Principal#getName()
+         * @return
+         */
+        public String getName()
+        {
+            return name;
+        }
+
+        /**
+         * <p>
+         * equals
+         * </p>
+         *
+         * @see Object#equals(Object)
+         * @param obj
+         * @return
+         */
+        public boolean equals( Object obj )
+        {
+            if (obj != null && obj instanceof Principal)
+            {
+                Principal p = (Principal) obj;
+                return name != null && p.getName() != null && 
name.equals(p.getName());
+            }
+            else
+            {
+                return false;
+            }
+        }
+
+        /**
+         * <p>
+         * hashCode
+         * </p>
+         *
+         * @see Object#hashCode()
+         * @return
+         */
+        public int hashCode()
+        {
+            if (name != null)
+            {
+                return (getClass().getName()+ ":" + name).hashCode();
+            }
+            else
+            {
+                return -1;
+            }
+        }
+
+        /**
+         * <p>
+         * toString
+         * </p>
+         *
+         * @see Object#toString()
+         * @return
+         */
+        public String toString()
+        {
+            return name;
+        }
+    }
+    /**
+     * <p>
+     * postRemoval
+     * </p>
+     *
+     * @see 
org.apache.jetspeed.components.persistence.store.RemovalAware#postRemoval(org.apache.jetspeed.components.persistence.store.PersistenceStore)
+     * @param store
+     * @throws [EMAIL PROTECTED] 
org.apache.jetspeed.persistence.store.PersistenceStoreRuntimeExcpetion}
+     * if the removal of the [EMAIL PROTECTED] java.util.prefs.Preference} 
related to this entity fails
+     */
+    public void postRemoval( PersistenceStore store )
+    {
+
+
+    }
+    /**
+     * <p>
+     * preRemoval
+     * </p>
+     * not implemented.
+     *
+     * @see 
org.apache.jetspeed.components.persistence.store.RemovalAware#preRemoval(org.apache.jetspeed.components.persistence.store.PersistenceStore)
+     * @param store
+     */
+    public void preRemoval( PersistenceStore store )
+    {
+        String rootForEntity = MutablePortletEntity.PORTLET_ENTITY_ROOT + "/" 
+ getId();
+        try
+        {
+            if(Preferences.userRoot().nodeExists(rootForEntity))
+            {
+                Preferences.userRoot().node(rootForEntity).removeNode();
+            }
+        }
+        catch (BackingStoreException e)
+        {
+            throw new PersistenceStoreRuntimeExcpetion(e.toString(), e);
+        }
+
+    }
+    public String getPortletUniqueName()
+    {
+        if(this.appName != null && this.portletName != null)
+        {
+            return this.appName+"::"+this.portletName;
+        }
+        else if(fragment != null)
+        {
+            return fragment.getName();
+        }
+        else
+        {
+            return null;
+        }
+    }
+
+    public void setFragment(Fragment fragment)
+    {
+        this.fragment = fragment;
+    }
+
+
+}

Modified: trunk/core/src/java/org/jahia/operations/PageGeneratorQueue.java
URL: 
https://svndev.jahia.net/websvn/diff.php?path=/trunk/core/src/java/org/jahia/operations/PageGeneratorQueue.java&rev=14905&repname=jahia
==============================================================================
--- trunk/core/src/java/org/jahia/operations/PageGeneratorQueue.java (original)
+++ trunk/core/src/java/org/jahia/operations/PageGeneratorQueue.java Wed Aug 16 
11:27:10 2006
@@ -33,7 +33,7 @@
     private Map generatedPage = new FastHashMap(2503);
     private Map notCacheablePage = new FastHashMap(2503);
     private Map generatingPage = new HashMap(10);
-    private int maxPagesToGenerateInParallel = 10;
+    private int maxPagesToGenerateInParallel = 25;
 
     public PageGeneratorQueue() {
     }

Modified: 
trunk/core/src/java/org/jahia/operations/valves/J2ProcessActionValve.java
URL: 
https://svndev.jahia.net/websvn/diff.php?path=/trunk/core/src/java/org/jahia/operations/valves/J2ProcessActionValve.java&rev=14905&repname=jahia
==============================================================================
--- trunk/core/src/java/org/jahia/operations/valves/J2ProcessActionValve.java 
(original)
+++ trunk/core/src/java/org/jahia/operations/valves/J2ProcessActionValve.java 
Wed Aug 16 11:27:10 2006
@@ -77,6 +77,8 @@
             }
             if (hasActionParam) {
                 logger.debug("Action parameter found.");
+                System.out.println("Action parameter found. pathInfo = " + 
pathInfo);
+                jParams.getSession().setAttribute("actionProcess","1");
                 ServletConfig config = Jahia.getStaticServletConfig();
                 org.apache.jetspeed.engine.Engine engine = 
Jetspeed.getEngine();
                 contextComponent = (RequestContextComponent) Jetspeed.

Modified: 
trunk/core/src/java/org/jahia/services/applications/JahiaJ2SessionPortalURL.java
URL: 
https://svndev.jahia.net/websvn/diff.php?path=/trunk/core/src/java/org/jahia/services/applications/JahiaJ2SessionPortalURL.java&rev=14905&repname=jahia
==============================================================================
--- 
trunk/core/src/java/org/jahia/services/applications/JahiaJ2SessionPortalURL.java
 (original)
+++ 
trunk/core/src/java/org/jahia/services/applications/JahiaJ2SessionPortalURL.java
 Wed Aug 16 11:27:10 2006
@@ -19,11 +19,14 @@
 import org.apache.jetspeed.PortalContext;
 import org.apache.jetspeed.container.state.NavigationalState;
 import org.apache.jetspeed.container.url.impl.QueryStringEncodingPortalURL;
+import org.apache.pluto.om.window.PortletWindow;
 import org.jahia.bin.Jahia;
 import org.jahia.exceptions.JahiaException;
 import org.jahia.params.ProcessingContext;
 
 import javax.servlet.http.HttpServletRequest;
+import javax.portlet.PortletMode;
+import javax.portlet.WindowState;
 import java.util.Map;
 
 /**
@@ -46,6 +49,7 @@
     static public final String PARAMBEAN_REQUEST_ATTRIBUTEKEY = 
"org.jahia.services.applications.ProcessingContext";
     static public final String APPUNIQUEID_REQUEST_ATTRIBUTEKEY = 
"org.jahia.services.applications.AppID";
     private Map parameters = null;
+    private ThreadLocal actionTL = new ThreadLocal();
     public JahiaJ2SessionPortalURL(HttpServletRequest request, String 
characterEncoding, NavigationalState navState, PortalContext portalContext) {
         super(request, characterEncoding, navState,portalContext);
         parameters = request.getParameterMap();
@@ -55,6 +59,16 @@
         super(navState,portalContext);
     }
 
+    public String createPortletURL(PortletWindow window, Map parameters, 
PortletMode mode, WindowState state, boolean action, boolean secure) {
+        actionTL.set(Boolean.valueOf(action));
+        return super.createPortletURL(window, parameters, mode, state, action, 
secure);    //To change body of overridden methods use File | Settings | File 
Templates.
+    }
+
+    public String createPortletURL(PortletWindow window, PortletMode mode, 
WindowState state, boolean secure) {
+        actionTL.set(Boolean.FALSE);
+        return super.createPortletURL(window, mode, state, secure);    //To 
change body of overridden methods use File | Settings | File Templates.
+    }
+
     protected void decodePathAndNavigationalState(HttpServletRequest request) {
         String path = null;
         String encodedNavigationalState = null;
@@ -63,7 +77,10 @@
                 int navParamPos = request.getPathInfo().indexOf("/" + 
getNavigationalStateParameterName() + "/");
                 int navParamLength = ("/" + 
getNavigationalStateParameterName() + "/").length();
                 int navParamEnd = request.getPathInfo().indexOf("/", 
navParamPos + navParamLength);
+                if(navParamEnd>0)
                 encodedNavigationalState = 
request.getPathInfo().substring(navParamPos + navParamLength, navParamEnd);
+                else
+                encodedNavigationalState = 
request.getPathInfo().substring(navParamPos + navParamLength);
             }
 
             path = request.getPathInfo();
@@ -104,6 +121,7 @@
                 paramPart.append(getNavigationalStateParameterName());
                 paramPart.append("/");
                 paramPart.append(encodedNavState);
+                if(((Boolean)actionTL.get()).booleanValue())
                 paramPart.append("/j2action/true/");
                 resultURL = 
processingContext.composePageUrl(processingContext.getPageID()) + 
paramPart.toString();
                 // resultURL = 
processingContext.composeEngineUrl(JetspeedProcessActionEngine.ENGINE_NAME, new 
Properties(), paramPart.toString());

Modified: 
trunk/core/src/java/org/jahia/services/applications/JetspeedDispatchingProvider.java
URL: 
https://svndev.jahia.net/websvn/diff.php?path=/trunk/core/src/java/org/jahia/services/applications/JetspeedDispatchingProvider.java&rev=14905&repname=jahia
==============================================================================
--- 
trunk/core/src/java/org/jahia/services/applications/JetspeedDispatchingProvider.java
 (original)
+++ 
trunk/core/src/java/org/jahia/services/applications/JetspeedDispatchingProvider.java
 Wed Aug 16 11:27:10 2006
@@ -186,7 +186,10 @@
         throws JahiaException {
         StringBuffer result = new StringBuffer();
         try {
-
+            if(jParams.getSession().getAttribute("actionProcess")!=null) {
+                jParams.getSession().removeAttribute("actionProcess");
+                return "";
+            }
             String entryPointDefName = entryPointInstance.getDefName();
             int separatorPos = entryPointDefName.indexOf("###");
             String portletDefName = entryPointDefName.substring(0, 
separatorPos);

Modified: 
trunk/core/src/java/org/jahia/services/applications/ServletIncludeResponseWrapper.java
URL: 
https://svndev.jahia.net/websvn/diff.php?path=/trunk/core/src/java/org/jahia/services/applications/ServletIncludeResponseWrapper.java&rev=14905&repname=jahia
==============================================================================
--- 
trunk/core/src/java/org/jahia/services/applications/ServletIncludeResponseWrapper.java
 (original)
+++ 
trunk/core/src/java/org/jahia/services/applications/ServletIncludeResponseWrapper.java
 Wed Aug 16 11:27:10 2006
@@ -1,20 +1,15 @@
-/*
- * Copyright 2002-2006 Jahia Ltd
- *
- * Licensed under the JAHIA COMMON DEVELOPMENT AND DISTRIBUTION LICENSE 
(JCDDL), 
- * Version 1.0 (the "License"), or (at your option) any later version; you may 
- * not use this file except in compliance with the License. You should have 
- * received a copy of the License along with this program; if not, you may 
obtain 
- * a copy of the License at 
- *
- *  http://www.jahia.org/license/
- *
- * 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.
- */
+//
+//                                   ____.
+//                       __/\ ______|    |__/\.     _______
+//            __   .____|    |       \   |    +----+       \
+//    _______|  /--|    |    |    -   \  _    |    :    -   \_________
+//   \\______: :---|    :    :           |    :    |         \________>
+//           |__\---\_____________:______:    :____|____:_____\
+//                                      /_____|
+//
+//                 . . . i n   j a h i a   w e   t r u s t . . .
+//
+
 package org.jahia.services.applications;
 
 import org.apache.regexp.RE;
@@ -239,6 +234,7 @@
 
         if ((jahiaParams != null) && (appUniqueIDStr != null)) {
 
+            boolean encodeInJahia = true;
             if (URL.toLowerCase ().indexOf (".jsp") == -1) {
                 try {
                     // Check if we should add Jahia extra URL encoding or not.
@@ -287,7 +283,22 @@
                             return super.encodeURL (URL);
                         }
                         if(dispatchedContext.getRequestDispatcher(path)!=null 
&& "portlet".equals(appBean.getType())) {
-                            return super.encodeURL(URL);
+                            logger.info("Path = "+path+ " URL = "+URL+ " 
Context = "+appBean.getContext());
+                            if(!URL.startsWith("/jahia")) {
+                                if(URL.indexOf(appBean.getContext())<0){
+                                    URL=appBean.getContext()+URL;
+                                    encodeInJahia = false;
+                                } else {
+                                    URL = super.encodeURL(URL);
+                                    logger.info("return encoded url "+URL);
+                                    return URL;
+                                }
+//                                if(!URL.startsWith("http")) {
+//                                    URL = jahiaParams.getScheme() + "://" + 
jahiaParams.getServerName() + (jahiaParams.getServerPort() == 80 ? "" : ":" + 
jahiaParams.getServerPort()) + URL;
+//                                }
+                            } else {
+                                return super.encodeURL(URL);
+                            }
                         }
                     } catch (Throwable t) {
                     }
@@ -373,63 +384,52 @@
             ServletIncludeURL = super.encodeURL (resolvedURL.toString ()); // 
let's add Java servlet
             // logger.debug( "encodeURL.ServletIncludeURL=[" +
             //                     ServletIncludeURL + "]");
-            try {
-                ServletIncludeURL = java.net.URLEncoder.encode 
(ServletIncludeURL,encoding);
-            } catch (UnsupportedEncodingException e) {
-                logger.debug ("Error in encoding [" + encoding + " ], 
returning empty buffer", e);
-            }
-
-            try {
+            if(encodeInJahia) {
+                try {
+                    ServletIncludeURL = 
java.net.URLEncoder.encode(ServletIncludeURL, encoding);
+                } catch (UnsupportedEncodingException e) {
+                    logger.debug("Error in encoding [" + encoding + " ], 
returning empty buffer", e);
+                }
+                try {
 
-                // Hollis : append app anchor
+                    // Hollis : append app anchor
 
-                String anchorID = ServletIncludeResponseWrapper.getFieldIDPart 
(appUniqueIDStr);
-                if (anchorID != null) {
-                    jahiaParams.setAnchor ("field_" + anchorID);
-                    // logger.debug( "set anchor to " + 
jahiaParams.getAnchor() );
-                }
-                // let's deactivate the cache in these requests since we must
-                // never cache application requests.
-                String savedCacheStatus = jahiaParams.getCacheStatus ();
-                jahiaParams.setCacheStatus (ProcessingContext.CACHE_BYPASS);
-                String fullScreenStr = "";
-                String fullScreenIDStr = jahiaParams.getParameter 
("fullscreen");
-                if (fullScreenIDStr == null) {
-                    fullScreenIDStr = jahiaParams.getParameter ("maximize");
-                }
-                if (fullScreenIDStr != null) {
-                    fullScreenStr = "&fullscreen=" + fullScreenIDStr;
-                }
+                    String anchorID = 
ServletIncludeResponseWrapper.getFieldIDPart(appUniqueIDStr);
+                    if (anchorID != null) {
+                        jahiaParams.setAnchor("field_" + anchorID);
+                        // logger.debug( "set anchor to " + 
jahiaParams.getAnchor() );
+                    }
+                    // let's deactivate the cache in these requests since we 
must
+                    // never cache application requests.
+                    String savedCacheStatus = jahiaParams.getCacheStatus();
+                    jahiaParams.setCacheStatus(ProcessingContext.CACHE_BYPASS);
+                    String fullScreenStr = "";
+                    String fullScreenIDStr = 
jahiaParams.getParameter("fullscreen");
+                    if (fullScreenIDStr == null) {
+                        fullScreenIDStr = jahiaParams.getParameter("maximize");
+                    }
+                    if (fullScreenIDStr != null) {
+                        fullScreenStr = "&fullscreen=" + fullScreenIDStr;
+                    }
 
-                if (fullScreenEngineOn) {
+                    if (fullScreenEngineOn) {
 
-                    // we are using the full screen engine instead of the
-                    // regular core engine.
-                    Properties extraParams = new Properties ();
-                    extraParams.setProperty 
(ProcessingContext.PAGE_ID_PARAMETER,
-                                             Integer.toString 
(jahiaParams.getPageID ()));
-                    ServletIncludeURL =
-                            jahiaParams.composeEngineUrl (
-                                    FullScreenDispatcherEngine.ENGINE_NAME,
-                                    extraParams,
-                                    "?appid=" +
-                                    appUniqueIDStr +
-                                    "&appparams=" +
-                                    ServletIncludeURL +
-                                    "&resetAppSession=true"
-                            );
-                } else {
-                    ServletIncludeURL = jahiaParams.composeUrl ("?appid=" +
-                                                                appUniqueIDStr 
+
-                                                                fullScreenStr +
-                                                                "&appparams=" +
-                                                                
ServletIncludeURL +
-                                                                
"&resetAppSession=true"
-                    );
+                        // we are using the full screen engine instead of the
+                        // regular core engine.
+                        Properties extraParams = new Properties();
+                        
extraParams.setProperty(ProcessingContext.PAGE_ID_PARAMETER, 
Integer.toString(jahiaParams.getPageID()));
+                        ServletIncludeURL = jahiaParams.composeEngineUrl( 
FullScreenDispatcherEngine.ENGINE_NAME,
+                                extraParams, "?appid=" + appUniqueIDStr + 
"&appparams=" + ServletIncludeURL +
+                                "&resetAppSession=true");
+                    } else {
+                        ServletIncludeURL = jahiaParams.composeUrl("?appid=" + 
appUniqueIDStr + fullScreenStr +
+                                "&appparams=" + ServletIncludeURL + 
"&resetAppSession=true");
+                    }
+                    jahiaParams.setCacheStatus(savedCacheStatus);
+                    ServletIncludeURL = super.encodeURL(ServletIncludeURL);
+                } catch (JahiaException je) {
+                    ServletIncludeURL = null;
                 }
-                jahiaParams.setCacheStatus (savedCacheStatus);
-            } catch (JahiaException je) {
-                ServletIncludeURL = null;
             }
 
         } else {
@@ -439,9 +439,13 @@
                 ServletIncludeURL = URL;
             } else {
                 ServletIncludeURL = super.encodeURL (URL); // let's add Java 
servlet
+                logger.debug ("Not in webapp context "+URL+" 
"+ServletIncludeURL);
             }
         }
-
+        if(!ServletIncludeURL.startsWith("http")) {
+            ServletIncludeURL = super.encodeURL(ServletIncludeURL);
+        }
+        logger.debug("encodeURL return "+ServletIncludeURL);
         return ServletIncludeURL;
     }
 

Modified: 
trunk/core/src/java/org/jahia/services/fields/ContentApplicationField.java
URL: 
https://svndev.jahia.net/websvn/diff.php?path=/trunk/core/src/java/org/jahia/services/fields/ContentApplicationField.java&rev=14905&repname=jahia
==============================================================================
--- trunk/core/src/java/org/jahia/services/fields/ContentApplicationField.java 
(original)
+++ trunk/core/src/java/org/jahia/services/fields/ContentApplicationField.java 
Wed Aug 16 11:27:10 2006
@@ -91,11 +91,9 @@
     public String getValue (ProcessingContext jParams, ContentObjectEntryState 
entryState)
             throws JahiaException {
 
-        ServicesRegistry tmpServicesRegistry = ServicesRegistry.getInstance ();
-
         String appID = getDBValue (entryState);
         if (appID.equals ("<empty>")) {
-            return new String ();
+            return "";
         }
 
         logger.debug ("Dispatching to application for appID=" + appID + "...");
@@ -119,18 +117,18 @@
                 tmpValue = (new RE ("</?html>", RE.MATCH_CASEINDEPENDENT)).
                         subst (tmpValue, "");
             } catch (RESyntaxException e) {
-                logger.debug (".getValue, exeption : " + e.toString ());
+                logger.debug (".getValue, exception : " + e.toString ());
             }
 
-            try {
-                tmpValue = new StringBuffer ().append ("<html>").
-                        append (tmpValue).append ("</html>").toString ();
-            } catch (Throwable t) {
-                t.printStackTrace ();
-            }
+//            try {
+//                tmpValue = new StringBuffer ().append ("<html>").
+//                        append (tmpValue).append ("</html>").toString ();
+//            } catch (Throwable t) {
+//                t.printStackTrace ();
+//            }
             //tmpValue = FormDataManager.formDecode(tmpValue);
         } else {
-            tmpValue = new String ();
+            tmpValue = "";
         }
         return tmpValue;
     }
@@ -152,7 +150,7 @@
      * This method should call preSet.
      */
     public void setAppID (int value, EntrySaveRequest saveRequest) throws 
JahiaException {
-        ContentObjectEntryState verInfo = preSet (String.valueOf (value), 
saveRequest);
+        preSet (String.valueOf (value), saveRequest);
         logger.debug ("Saving application field...");
         postSet(saveRequest);
 
@@ -251,11 +249,8 @@
         if (entryValue == null) {
             return false;
         }
-        if (!entryValue.equals("") &&
-            !entryValue.equals("<empty>")) {
-            return true;
-        }
-        return false;
+        return !entryValue.equals("") &&
+               !entryValue.equals("<empty>");
     }
 
 

Reply via email to