portals-portalapps-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From woon...@apache.org
Subject svn commit: r763984 - in /portals/applications/gems: ./ src/main/java/org/apache/portals/gems/browser/ src/main/java/org/apache/portals/gems/browser/resources/ src/main/java/org/apache/portals/gems/dojo/ src/main/java/org/apache/portals/gems/flash/ src...
Date Fri, 10 Apr 2009 17:35:21 GMT
Author: woonsan
Date: Fri Apr 10 17:35:20 2009
New Revision: 763984

URL: http://svn.apache.org/viewvc?rev=763984&view=rev
Log:
JS2-961: Migrates the existing dojo support portlets to use portlet 2.0 head contribution
API.
Also, removes db browser stuffs because they were moved to its own app project today.
Removes Jetspeed dependencies as well.

Added:
    portals/applications/gems/src/main/java/org/apache/portals/gems/dojo/DojoPortletHelper.java
  (with props)
    portals/applications/gems/src/main/java/org/apache/portals/gems/util/JSONUtils.java  
(with props)
    portals/applications/gems/src/main/resources/
    portals/applications/gems/src/main/resources/org/
    portals/applications/gems/src/main/resources/org/apache/
    portals/applications/gems/src/main/resources/org/apache/portals/
    portals/applications/gems/src/main/resources/org/apache/portals/gems/
    portals/applications/gems/src/main/resources/org/apache/portals/gems/flash/
    portals/applications/gems/src/main/resources/org/apache/portals/gems/flash/templates/
    portals/applications/gems/src/main/resources/org/apache/portals/gems/flash/templates/edit-prefs.vm
      - copied unchanged from r763977, portals/applications/gems/src/main/java/org/apache/portals/gems/flash/templates/edit-prefs.vm
    portals/applications/gems/src/main/resources/org/apache/portals/gems/flash/templates/flash-demo.vm
      - copied unchanged from r763977, portals/applications/gems/src/main/java/org/apache/portals/gems/flash/templates/flash-demo.vm
Removed:
    portals/applications/gems/src/main/java/org/apache/portals/gems/browser/ActionParameter.java
    portals/applications/gems/src/main/java/org/apache/portals/gems/browser/Browser.java
    portals/applications/gems/src/main/java/org/apache/portals/gems/browser/BrowserIterator.java
    portals/applications/gems/src/main/java/org/apache/portals/gems/browser/BrowserPortlet.java
    portals/applications/gems/src/main/java/org/apache/portals/gems/browser/BrowserQuery.java
    portals/applications/gems/src/main/java/org/apache/portals/gems/browser/DatabaseBrowserIterator.java
    portals/applications/gems/src/main/java/org/apache/portals/gems/browser/DatabaseBrowserPortlet.java
    portals/applications/gems/src/main/java/org/apache/portals/gems/browser/resources/
    portals/applications/gems/src/main/java/org/apache/portals/gems/flash/templates/
Modified:
    portals/applications/gems/   (props changed)
    portals/applications/gems/pom.xml
    portals/applications/gems/src/main/java/org/apache/portals/gems/dojo/AbstractDojoVelocityPortlet.java
    portals/applications/gems/src/main/java/org/apache/portals/gems/dojo/DojoSpringMVCPortlet.java
    portals/applications/gems/src/main/java/org/apache/portals/gems/flash/FlashPortlet.java
    portals/applications/gems/src/main/java/org/apache/portals/gems/googlemaps/GoogleMapsPortlet.java

Propchange: portals/applications/gems/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Fri Apr 10 17:35:20 2009
@@ -1,4 +1,3 @@
-maven.log
 target
-jcoverage.ser
 .settings
+.classpath

Modified: portals/applications/gems/pom.xml
URL: http://svn.apache.org/viewvc/portals/applications/gems/pom.xml?rev=763984&r1=763983&r2=763984&view=diff
==============================================================================
--- portals/applications/gems/pom.xml (original)
+++ portals/applications/gems/pom.xml Fri Apr 10 17:35:20 2009
@@ -42,7 +42,6 @@
 
   <properties>
     <portlet-api.version>2.0</portlet-api.version>
-    <jetspeed.version>2.2-SNAPSHOT</jetspeed.version>
     <velocity.version>1.5</velocity.version>
     <org.apache.portals.bridges.velocity.version>1.0.4</org.apache.portals.bridges.velocity.version>
     <poi.version>3.0-FINAL</poi.version>
@@ -65,18 +64,6 @@
     <scope>provided</scope>
     </dependency>
     <dependency>
-      <groupId>org.apache.portals.jetspeed-2</groupId>
-      <artifactId>jetspeed-api</artifactId>
-      <version>${jetspeed.version}</version>
-      <scope>provided</scope>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.portals.jetspeed-2</groupId>
-      <artifactId>jetspeed-commons</artifactId>
-      <version>${jetspeed.version}</version>
-      <scope>provided</scope>
-    </dependency>
-    <dependency>
       <groupId>velocity</groupId>
       <artifactId>velocity</artifactId>
       <version>${velocity.version}</version>
@@ -124,9 +111,9 @@
   </dependencies>
 
   <scm>
-    <connection>scm:svn:http://svn.apache.org/repos/asf/portals/jetspeed-2/trunk/applications/gems</connection>
-    <developerConnection>scm:svn:https://svn.apache.org/repos/asf/portals/jetspeed-2/trunk/applications/gems</developerConnection>
-    <url>http://svn.apache.org/viewcvs.cgi/portals/jetspeed-2/trunk/applications/gems/</url>
+    <connection>scm:svn:http://svn.apache.org/repos/asf/portals/applications/gems</connection>
+    <developerConnection>scm:svn:https://svn.apache.org/repos/asf/portals/applications/gems</developerConnection>
+    <url>http://svn.apache.org/viewcvs.cgi/portals/applications/gems/</url>
   </scm>
 
 </project>
\ No newline at end of file

Modified: portals/applications/gems/src/main/java/org/apache/portals/gems/dojo/AbstractDojoVelocityPortlet.java
URL: http://svn.apache.org/viewvc/portals/applications/gems/src/main/java/org/apache/portals/gems/dojo/AbstractDojoVelocityPortlet.java?rev=763984&r1=763983&r2=763984&view=diff
==============================================================================
--- portals/applications/gems/src/main/java/org/apache/portals/gems/dojo/AbstractDojoVelocityPortlet.java
(original)
+++ portals/applications/gems/src/main/java/org/apache/portals/gems/dojo/AbstractDojoVelocityPortlet.java
Fri Apr 10 17:35:20 2009
@@ -16,13 +16,13 @@
  */
 package org.apache.portals.gems.dojo;
 
+import java.io.IOException;
+
 import javax.portlet.PortletConfig;
 import javax.portlet.PortletException;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
 
-import org.apache.jetspeed.headerresource.HeaderResource;
-import org.apache.jetspeed.portlet.PortletHeaderRequest;
-import org.apache.jetspeed.portlet.PortletHeaderResponse;
-import org.apache.jetspeed.portlet.SupportsHeaderPhase;
 import org.apache.portals.bridges.velocity.GenericVelocityPortlet;
 
 /**
@@ -31,10 +31,17 @@
  * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
  * @version $Id: $
  */
-public abstract class AbstractDojoVelocityPortlet extends GenericVelocityPortlet implements
SupportsHeaderPhase 
-{    
+public abstract class AbstractDojoVelocityPortlet extends GenericVelocityPortlet
+{
+    
+    protected static final String DOJO_REQUIRES_CORE_INIT_PARAM = "dojo.requires.core";
+    protected static final String DOJO_REQUIRES_MODULES_INIT_PARAM = "dojo.requires.modules";
+    
+    private String dojoRequiresCoreList;
+    private String dojoRequiresAddOnList;
+    
     protected String headerPage;
-
+    
     /*
      * Portlet constructor.
      */
@@ -46,44 +53,39 @@
     public void init(PortletConfig config) throws PortletException
     {
         super.init(config);
+        this.dojoRequiresCoreList = this.getInitParameter( DOJO_REQUIRES_CORE_INIT_PARAM
);
+        this.dojoRequiresAddOnList = this.getInitParameter( DOJO_REQUIRES_MODULES_INIT_PARAM
);
         this.headerPage = this.getInitParameter("HeaderPage");
     }
     
-    /*
-     * Include Dojo and Turbo header content using header resource component.
-     *
-     * @param request render request
-     * @param response render response
-     */    
-    public void doHeader( PortletHeaderRequest request, PortletHeaderResponse response )
-    throws PortletException
+    @Override
+    protected void doHeaders(RenderRequest request, RenderResponse response)
     {
-        // use header resource component to ensure header logic is included only once
-        HeaderResource headerResource = response.getHeaderResource();
+        if (this.headerPage != null)
+        {
+            try
+            {
+                this.getPortletContext().getRequestDispatcher(this.headerPage).include(request,
response);
+            }
+            catch (PortletException e)
+            {
+                throw new RuntimeException("Failed to include header page.", e);
+            }
+            catch (IOException e)
+            {
+                throw new RuntimeException("Failed to include header page.", e);
+            }
+        }
 
-        headerResource.dojoEnable();
-        includeHeaderContent( headerResource );
+        if (this.dojoRequiresCoreList != null)
+        {
+            DojoPortletHelper.contributeDojoRequires(response, this.dojoRequiresCoreList);
+        }
         
-        if ( this.headerPage != null )
+        if (this.dojoRequiresAddOnList != null)
         {
-            include( request, response, this.headerPage );
+            DojoPortletHelper.contributeDojoRequires(response, this.dojoRequiresAddOnList);
         }
     }
     
-    protected void includeHeaderContent( HeaderResource headerResource )
-    {
-        // do nothing - intended for derived classes
-    }
-    
-    protected void include(PortletHeaderRequest request, PortletHeaderResponse response,
String headerPagePath, StringBuffer headerText) throws PortletException
-    {
-        response.include(request, response, headerPagePath);
-        headerText.append(response.getContent());
-    }
-    
-    protected void include(PortletHeaderRequest request, PortletHeaderResponse response,
String headerPagePath) throws PortletException
-    {
-        response.include(request, response, headerPagePath);
-        response.getHeaderResource().addHeaderInfo(response.getContent());
-    }
 }

Added: portals/applications/gems/src/main/java/org/apache/portals/gems/dojo/DojoPortletHelper.java
URL: http://svn.apache.org/viewvc/portals/applications/gems/src/main/java/org/apache/portals/gems/dojo/DojoPortletHelper.java?rev=763984&view=auto
==============================================================================
--- portals/applications/gems/src/main/java/org/apache/portals/gems/dojo/DojoPortletHelper.java
(added)
+++ portals/applications/gems/src/main/java/org/apache/portals/gems/dojo/DojoPortletHelper.java
Fri Apr 10 17:35:20 2009
@@ -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.portals.gems.dojo;
+
+import javax.portlet.MimeResponse;
+import javax.portlet.RenderResponse;
+
+import org.apache.commons.lang.StringUtils;
+import org.w3c.dom.Element;
+
+/**
+ * Help class for portlets which want to use DOJO AJAX technologies.
+ * 
+ * @version $Id$
+ */
+public class DojoPortletHelper
+{
+ 
+    /**
+     * An attribute name of head element contributed to the portal page aggregation by a
portlet.
+     * The value of this attribute can be used by portal to merge contents of each contributed
head element
+     * into centralized element(s).
+     * <BR/>
+     * For example, if a contributed head element has an attribute value, 'dojo.require',
with text content, 'dojo.lang.*'
+     * and another contributed element has the same attribute value, 'dojo.require', with
text content, 'dojo.event.*', then
+     * a portal can merge those contents into a single script element for optimization.
+     */
+    public static final String HEAD_ELEMENT_CONTRIBUTION_MERGE_HINT_ATTRIBUTE = "org.apache.portals.portal.page.head.element.contribution.merge.hint";
+
+    /**
+     * An attribute value for key hint which can be used in head elements merging by portal.
 
+     */
+    public static final String HEAD_ELEMENT_CONTRIBUTION_MERGE_HINT_KEY_DOJO_REQUIRE = "dojo.require";
+
+    
+    private DojoPortletHelper()
+    {
+    }
+    
+    public static void contributeScript(RenderResponse response, String language, String
type, String src, String textContent)
+    {
+        Element headElem = response.createElement("script");
+        
+        if (language != null)
+        {
+            headElem.setAttribute("language", language);
+        }
+        
+        if (src != null)
+        {
+            headElem.setAttribute("src", src);
+        }
+        
+        if (type != null)
+        {
+            headElem.setAttribute("type", type);
+        }
+        
+        if (textContent != null)
+        {
+            headElem.appendChild(headElem.getOwnerDocument().createTextNode(textContent));
+        }
+        
+        response.addProperty(MimeResponse.MARKUP_HEAD_ELEMENT, headElem);
+    }
+    
+    public static void contributeDojoRequire(RenderResponse response, String dojoRequire)
+    {
+        Element headElem = response.createElement("script");
+        headElem.setAttribute("language", "JavaScript");
+        headElem.setAttribute("type", "text/javascript");
+        headElem.setAttribute(HEAD_ELEMENT_CONTRIBUTION_MERGE_HINT_ATTRIBUTE, HEAD_ELEMENT_CONTRIBUTION_MERGE_HINT_KEY_DOJO_REQUIRE);
+        headElem.appendChild(headElem.getOwnerDocument().createTextNode("dojo.require(\""
+ dojoRequire + "\");"));
+        response.addProperty(MimeResponse.MARKUP_HEAD_ELEMENT, headElem);
+    }
+
+    public static void contributeDojoRequires(RenderResponse response, String dojoRequires)
+    {
+        String [] dojoRequireArray = StringUtils.split(dojoRequires, ';');
+        
+        if (dojoRequireArray != null)
+        {
+            for (String dojoRequire : dojoRequireArray)
+            {
+                contributeDojoRequire(response, dojoRequire);
+            }
+        }
+    }
+    
+}

Propchange: portals/applications/gems/src/main/java/org/apache/portals/gems/dojo/DojoPortletHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/applications/gems/src/main/java/org/apache/portals/gems/dojo/DojoPortletHelper.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: portals/applications/gems/src/main/java/org/apache/portals/gems/dojo/DojoPortletHelper.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: portals/applications/gems/src/main/java/org/apache/portals/gems/dojo/DojoSpringMVCPortlet.java
URL: http://svn.apache.org/viewvc/portals/applications/gems/src/main/java/org/apache/portals/gems/dojo/DojoSpringMVCPortlet.java?rev=763984&r1=763983&r2=763984&view=diff
==============================================================================
--- portals/applications/gems/src/main/java/org/apache/portals/gems/dojo/DojoSpringMVCPortlet.java
(original)
+++ portals/applications/gems/src/main/java/org/apache/portals/gems/dojo/DojoSpringMVCPortlet.java
Fri Apr 10 17:35:20 2009
@@ -16,21 +16,18 @@
  */
 package org.apache.portals.gems.dojo;
 
+import java.io.IOException;
 import java.util.Enumeration;
-import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
 
 import javax.portlet.PortletException;
 import javax.portlet.RenderRequest;
 import javax.portlet.RenderResponse;
+
 import org.apache.commons.lang.ObjectUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.jetspeed.headerresource.HeaderResource;
-import org.apache.jetspeed.portlet.PortletHeaderRequest;
-import org.apache.jetspeed.portlet.PortletHeaderResponse;
-import org.apache.jetspeed.portlet.SupportsHeaderPhase;
 import org.springframework.beans.BeansException;
 import org.springframework.web.portlet.DispatcherPortlet;
 
@@ -40,10 +37,15 @@
  * 
  * @author <a href="mailto:smilek@apache.org">Steve Milek</a>
  * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a> 
- * @version $Id: $
+ * @version $Id$
  */
-public class DojoSpringMVCPortlet extends DispatcherPortlet implements SupportsHeaderPhase
+public class DojoSpringMVCPortlet extends DispatcherPortlet
 {
+    /*
+     * Class specific logger.
+     */
+    private final static Log log = LogFactory.getLog(DojoSpringMVCPortlet.class);
+
 	protected static final String CRLF = "\r\n";
     
     protected static final String DOJO_REQUIRES_CORE_INIT_PARAM = "dojo.requires.core";
@@ -52,11 +54,6 @@
     private String dojoRequiresCoreList = null;
     private String dojoRequiresAddOnList = null;
     
-    /*
-     * Class specific logger.
-     */
-    private final static Log log = LogFactory.getLog(DojoSpringMVCPortlet.class);
-
     protected String headerPage;
     
     /*
@@ -67,37 +64,6 @@
         super();
     }
     
-    protected boolean addJavascriptBlock(HeaderResource headerResource, StringBuffer javascriptText)
-    {
-    	return addJavascriptElement( headerResource, null, javascriptText );
-    }
-    protected boolean addJavascriptInclude(HeaderResource headerResource, String src)
-    {
-    	return addJavascriptElement( headerResource, src, null );
-    }
-    protected boolean addJavascriptElement(HeaderResource headerResource, String src, StringBuffer
javascriptText)
-    {
-    	if ( ( javascriptText != null && javascriptText.length() > 0 ) || ( src !=
null && src.length() > 0 ) )
-    	{
-    		Map headerInfoMap = new HashMap(8);
-    		headerInfoMap.put("language", "JavaScript");
-    		headerInfoMap.put("type", "text/javascript");
-    		if ( src != null && src.length() > 0 )
-    		{
-    			headerInfoMap.put("src", src);
-    			headerResource.addHeaderInfo("script", headerInfoMap, "");
-    		}
-    		else
-    		{
-    			headerResource.addHeaderInfo("script", headerInfoMap, CRLF + javascriptText.toString());
-    		}
-    		return true ;
-    	}
-    	return false ;
-    }
-    
-    
-
     /*
      * Portlet lifecycle method.
      */
@@ -123,58 +89,92 @@
         super.doRenderService(request, response);
     }
 
-    /*
-     * Include Dojo header content using header resource component.
-     *
-     * @param request render request
-     * @param response render response
-     */    
-    public void doHeader(PortletHeaderRequest request, PortletHeaderResponse response)  
 
-    throws PortletException
+    @Override
+    protected void doHeaders(RenderRequest request, RenderResponse response)
     {
-        // use header resource component to ensure header logic is included only once
-        HeaderResource headerResource = response.getHeaderResource();
-        
-        headerResource.dojoEnable();
-        includeHeaderContent( headerResource );
-        
-        if ( this.headerPage != null )
+        if (this.headerPage != null)
         {
-            include( request, response, this.headerPage );
+            try
+            {
+                this.getPortletContext().getRequestDispatcher(this.headerPage).include(request,
response);
+            }
+            catch (PortletException e)
+            {
+                throw new RuntimeException("Failed to include header page.", e);
+            }
+            catch (IOException e)
+            {
+                throw new RuntimeException("Failed to include header page.", e);
+            }
         }
-    }
-    
-    protected void includeHeaderContent( HeaderResource headerResource )
-    {
-        if ( this.dojoRequiresCoreList != null )
+        
+        if (this.dojoRequiresCoreList != null)
         {
-            headerResource.dojoAddCoreLibraryRequires( this.dojoRequiresCoreList );
+            DojoPortletHelper.contributeDojoRequires(response, this.dojoRequiresCoreList);
         }
-        if ( this.dojoRequiresAddOnList != null )
+        
+        if (this.dojoRequiresAddOnList != null)
         {
-            headerResource.dojoAddModuleLibraryRequires( this.dojoRequiresAddOnList );
+            DojoPortletHelper.contributeDojoRequires(response, this.dojoRequiresAddOnList);
         }
-    }    
-    
-    public void include(PortletHeaderRequest request, PortletHeaderResponse response, String
headerPagePath, StringBuffer headerText) throws PortletException
+    }
+
+    /**
+     * Utility method to allow javascript head element contribution.
+     * Be sure that this method can be invoked only in the {@link #doHeaders(RenderRequest,
RenderResponse)} method
+     * that you may override.
+     * 
+     * @param response
+     * @param textContent
+     * @return
+     */
+    protected boolean addJavascriptBlock(RenderResponse response, String textContent)
+    {
+        return addJavascriptElement(response, null, textContent);
+    }
+
+    /**
+     * Utility method to allow javascript head element contribution.
+     * Be sure that this method can be invoked only in the {@link #doHeaders(RenderRequest,
RenderResponse)} method
+     * that you may override.
+     *
+     * @param response
+     * @param src
+     * @return
+     */
+    protected boolean addJavascriptInclude(RenderResponse response, String src)
     {
-        response.include(request, response, headerPagePath);
-        headerText.append(response.getContent());
+        return addJavascriptElement(response, src, null);
     }
     
-    public void include(PortletHeaderRequest request, PortletHeaderResponse response, String
headerPagePath) throws PortletException
+    /**
+     * Utility method to allow javascript head element contribution.
+     * Be sure that this method can be invoked only in the {@link #doHeaders(RenderRequest,
RenderResponse)} method
+     * that you may override.
+     * 
+     * @param response
+     * @param src
+     * @param textContent
+     * @return
+     */
+    protected boolean addJavascriptElement(RenderResponse response, String src, String textContent)
     {
-        response.include(request, response, headerPagePath);
-        response.getHeaderResource().addHeaderInfo(response.getContent());
+        if ((textContent != null && textContent.length() > 0) || (src != null
&& src.length() > 0))
+        {
+            DojoPortletHelper.contributeScript(response, "JavaScript", "text/javascript",
src, textContent);
+            return true ;
+        }
+        
+        return false ;
     }
-
-
+    
 	// debugging
 
 	protected void dumpAttributes(RenderRequest request)
 	{
 		Enumeration attrIter = request.getAttributeNames();
 		log.info( "request-attributes:");
+		
 		while ( attrIter.hasMoreElements() )
 		{
 			Object attrNm = attrIter.nextElement();
@@ -183,10 +183,12 @@
 			log.info( "   key=" + ObjectUtils.toString(attrNm,"null") + " value=" + attrValDesc);
 		}
 	}
+	
 	protected void dumpSession(RenderRequest request)
 	{
 		Enumeration attrIter = request.getPortletSession().getAttributeNames();
 		log.info( "session-attributes:");
+		
 		while ( attrIter.hasMoreElements() )
 		{
 			Object attrNm = attrIter.nextElement();
@@ -195,6 +197,7 @@
 			log.info( "   key=" + ObjectUtils.toString(attrNm,"null") + " value=" + attrValDesc);
 		}
 	}
+	
 	protected void dumpNameValue( Map m  )
 	{
 		if ( m == null )
@@ -202,12 +205,15 @@
 			log.info( "   <null>" );
 			return;
 		}
+		
 		if ( m.size() == 0 )
 		{
 			log.info( "   <empty>" );
 			return;
 		}
+		
 		Iterator entryIter = m.entrySet().iterator();
+		
 		while ( entryIter.hasNext() )
 		{
 			Map.Entry e = (Map.Entry)entryIter.next();
@@ -218,4 +224,5 @@
 			log.info( "   key=" + eKeyDesc + " value=" + eValDesc);
 		}
 	}
+	
 }

Modified: portals/applications/gems/src/main/java/org/apache/portals/gems/flash/FlashPortlet.java
URL: http://svn.apache.org/viewvc/portals/applications/gems/src/main/java/org/apache/portals/gems/flash/FlashPortlet.java?rev=763984&r1=763983&r2=763984&view=diff
==============================================================================
--- portals/applications/gems/src/main/java/org/apache/portals/gems/flash/FlashPortlet.java
(original)
+++ portals/applications/gems/src/main/java/org/apache/portals/gems/flash/FlashPortlet.java
Fri Apr 10 17:35:20 2009
@@ -18,37 +18,30 @@
 
 import java.io.IOException;
 import java.io.StringWriter;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
-import java.util.StringTokenizer;
-import java.util.Collections;
 import java.util.Properties;
+import java.util.StringTokenizer;
 
 import javax.portlet.ActionRequest;
 import javax.portlet.ActionResponse;
+import javax.portlet.PortletConfig;
 import javax.portlet.PortletException;
 import javax.portlet.PortletPreferences;
-import javax.portlet.PortletRequest;
 import javax.portlet.RenderRequest;
 import javax.portlet.RenderResponse;
 import javax.portlet.WindowState;
-import javax.portlet.PortletConfig;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.portals.bridges.velocity.GenericVelocityPortlet;
-
-import org.apache.velocity.context.Context;
-import org.apache.velocity.app.VelocityEngine;
+import org.apache.portals.gems.util.JSONUtils;
 import org.apache.velocity.Template;
+import org.apache.velocity.app.VelocityEngine;
+import org.apache.velocity.context.Context;
 import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import org.apache.jetspeed.PortalReservedParameters;
-import org.apache.jetspeed.desktop.JetspeedDesktop;
-import org.apache.jetspeed.headerresource.HeaderResourceLib;
-import org.apache.jetspeed.request.RequestContext;
-
 public class FlashPortlet extends GenericVelocityPortlet
 {
     public static final String HEIGHT_PREF = "HEIGHT";
@@ -91,6 +84,9 @@
     public static final String SWF_VERSION = "SWF_VERSION";
     public static final String SWF_VERSION_DEFAULT = "9.0.0";
     
+    public static final String PARAM_SWFOBJECTS_LIB_URL = "SwfObjectsLibUrl";
+    public static final String PARAM_EXPRESS_INSTALL_URL = "ExpressInstallUrl";
+    
     public static final String SWFOBJECTS_LIB_URL = "SWFOBJECTS_URL";
     public static final String EXPRESS_INSTALL_URL = "EXPRESS_INSTALL_URL";
     
@@ -100,28 +96,44 @@
     
     protected String viewPage = null;
     protected String editPage = null;
-
+    
+    protected String defaultSwfObjectsLibUrl = "/javascript/swfobject/swfobject.js";
+    protected String defaultSwfExpressInstallUrl = "/javascript/swfobject/expressInstall.swf";
+    
     private Map object_parameters = null;
     private Map object_attributes = null;    
     private Map flash_vars = null;
 
     private VelocityEngine engine;
 
-
 	public void init( PortletConfig config ) throws PortletException
     { 
         super.init(config);
+        
+        String param = config.getInitParameter(PARAM_SWFOBJECTS_LIB_URL);
+        if (param != null && !"".equals(param))
+        {
+            defaultSwfObjectsLibUrl = param;
+        }
+        
+        param = config.getInitParameter(EXPRESS_INSTALL_URL);
+        if (param != null && !"".equals(param))
+        {
+            defaultSwfExpressInstallUrl = param;
+        }
 
-        String viewPage = config.getInitParameter( PARAM_VIEW_PAGE );
-        if ( viewPage == null || viewPage.length() == 0 )
-            viewPage = null;
-        this.viewPage = viewPage;
-
-        String editPage = config.getInitParameter( PARAM_EDIT_PAGE );
-        if ( editPage == null || editPage.length() == 0 )
-            editPage = null;
-        this.editPage = editPage;
-                
+        param = config.getInitParameter(PARAM_VIEW_PAGE);
+        if (param != null && !"".equals(param))
+        {
+            viewPage = param;
+        }
+
+        param = config.getInitParameter(PARAM_EDIT_PAGE);
+        if (param != null && !"".equals(param))
+        {
+            editPage = param;
+        }
+        
         Map objParams = parseSemicolonEqualsDelimitedProps( config.getInitParameter( OBJECT_PARAMS_INITPARAM
) );
         Map objAttrs = parseSemicolonEqualsDelimitedProps( config.getInitParameter( OBJECT_ATTRIBUTES_INITPARAM
) );
         Map flashVars = parseSemicolonEqualsDelimitedProps( config.getInitParameter( FLASHVARS_INITPARAM
) );
@@ -150,14 +162,17 @@
 	{
 		return this.object_parameters;
 	}
+	
 	protected final Map getDefaultObjectAttributes()
 	{
 		return this.object_attributes;
 	}
+	
 	protected final Map getDefaultFlashVars()
 	{
 		return this.flash_vars;
 	}
+	
 	protected String getDefaultSwfVersion()
 	{
 		return SWF_VERSION_DEFAULT;
@@ -167,10 +182,12 @@
 	{
 		return this.object_parameters;
 	}
+	
 	protected Map getObjectAttributes( RenderRequest request, RenderResponse response, SWFContext
swfContext )
 	{
 		return this.object_attributes;
 	}
+	
 	protected Map getFlashVars( RenderRequest request, RenderResponse response, SWFContext swfContext
)
 	{
 		return this.flash_vars;
@@ -189,15 +206,12 @@
 		String namespace = response.getNamespace();
 		context.put( NAMESPACE, namespace );
 		context.put( REPLACECONTENT_NODEID, namespace + "_flash_replace" );
-		
-		RequestContext requestContext = (RequestContext)request.getAttribute( PortalReservedParameters.REQUEST_CONTEXT_ATTRIBUTE
);
 
-        String portalBaseUrl = HeaderResourceLib.getPortalBaseUrl( requestContext );
-		context.put( SWFOBJECTS_LIB_URL, portalBaseUrl + "/javascript/swfobject/swfobject.js" );
-		context.put( EXPRESS_INSTALL_URL, portalBaseUrl + "/javascript/swfobject/expressInstall.swf"
);
-		
-        Boolean desktopEnabled = (Boolean)requestContext.getAttribute( JetspeedDesktop.DESKTOP_ENABLED_REQUEST_ATTRIBUTE
);
-		context.put( IS_DESKTOP, ( (desktopEnabled == null) ? Boolean.FALSE : desktopEnabled )
);
+        String swfObjectsLibUrl = request.getPreferences().getValue(PARAM_SWFOBJECTS_LIB_URL,
this.defaultSwfObjectsLibUrl);
+        String swfExpressInstallUrl = request.getPreferences().getValue(PARAM_EXPRESS_INSTALL_URL,
this.defaultSwfExpressInstallUrl);
+        
+		context.put( SWFOBJECTS_LIB_URL, swfObjectsLibUrl );
+		context.put( EXPRESS_INSTALL_URL, swfExpressInstallUrl );
 		
 		int swfVersion = ( swfContext.getHeader() != null ? swfContext.getHeader().getVersion()
: -1 );
 		if ( swfVersion > 0 )
@@ -213,14 +227,14 @@
 	
 	protected void setParameterContextVars( RenderRequest request, RenderResponse response,
Context context, SWFContext swfContext )
 	{
-		context.put( OBJECT_PARAMS, HeaderResourceLib.makeJSONObject( getObjectParameters( request,
response, swfContext ), true ).toString() );
+		context.put( OBJECT_PARAMS, JSONUtils.makeJSONObject( getObjectParameters( request, response,
swfContext ), true ).toString() );
 		
 		Map objNodeIdMap = new HashMap();
 		objNodeIdMap.put( "id", response.getNamespace() + "_objnode" );
 		Map[] attrMaps = new Map[] { getObjectAttributes( request, response, swfContext ), objNodeIdMap
};
-		context.put( OBJECT_ATTRIBUTES, HeaderResourceLib.makeJSONObject( attrMaps, true ).toString()
);
+		context.put( OBJECT_ATTRIBUTES, JSONUtils.makeJSONObject( attrMaps, true ).toString() );
 		
-		context.put( FLASHVARS, HeaderResourceLib.makeJSONObject( getFlashVars( request, response,
swfContext ), true ).toString() );
+		context.put( FLASHVARS, JSONUtils.makeJSONObject( getFlashVars( request, response, swfContext
), true ).toString() );
 	}
 	
 	protected void readSwfFileInfo( RenderRequest request, RenderResponse response, Context
context, SWFContext swfContext )
@@ -285,7 +299,7 @@
         if ( heightPercent != null )
         	extraSizeVars.put( HEIGHT_PERCENT, heightPercent );
         
-        context.put( EXTRA_SIZE_INFO, HeaderResourceLib.makeJSONObject( extraSizeVars, true
).toString() );
+        context.put( EXTRA_SIZE_INFO, JSONUtils.makeJSONObject( extraSizeVars, true ).toString()
);
 	}
        
     public void doView(RenderRequest request, RenderResponse response)

Modified: portals/applications/gems/src/main/java/org/apache/portals/gems/googlemaps/GoogleMapsPortlet.java
URL: http://svn.apache.org/viewvc/portals/applications/gems/src/main/java/org/apache/portals/gems/googlemaps/GoogleMapsPortlet.java?rev=763984&r1=763983&r2=763984&view=diff
==============================================================================
--- portals/applications/gems/src/main/java/org/apache/portals/gems/googlemaps/GoogleMapsPortlet.java
(original)
+++ portals/applications/gems/src/main/java/org/apache/portals/gems/googlemaps/GoogleMapsPortlet.java
Fri Apr 10 17:35:20 2009
@@ -18,20 +18,16 @@
 
 
 import java.io.IOException;
-import java.util.Map;
-import java.util.HashMap;
 
-import javax.portlet.PortletException;
 import javax.portlet.ActionRequest;
-import javax.portlet.RenderRequest;
 import javax.portlet.ActionResponse;
-import javax.portlet.MimeResponse;
-import javax.portlet.RenderResponse;
+import javax.portlet.PortletException;
 import javax.portlet.PortletPreferences;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
 
 import org.apache.portals.bridges.velocity.GenericVelocityPortlet;
-
-import org.w3c.dom.Element;
+import org.apache.portals.gems.dojo.DojoPortletHelper;
 
 /**
  * This is a simple class used to override processAction
@@ -41,10 +37,6 @@
  */
 public class GoogleMapsPortlet extends GenericVelocityPortlet
 {
-    
-    private static final String HEAD_ELEMENT_CONTRIBUTION_MERGE_HINT_ATTRIBUTE = "org.apache.portals.portal.page.head.element.contribution.merge.hint";
-
-    private static final String HEAD_ELEMENT_CONTRIBUTION_MERGE_HINT_KEY_DOJO_REQUIRE = "dojo.require";
 
     /**
      * no change
@@ -90,60 +82,12 @@
     protected void doHeaders(RenderRequest request, RenderResponse response)
     {
         String apiKey = request.getPreferences().getValue("APIKey", "");
-        contributeScript(response, "JavaScript", "text/javascript", "http://maps.google.com/maps?file=api&v=2&key="
+ apiKey, null);
-        contributeDojoRequire(response, "dojo.lang.*");
-        contributeDojoRequire(response, "dojo.event.*");
-        contributeDojoRequire(response, "dojo.io.*");
-        contributeDojoRequire(response, "dojo.widget.*");
-        contributeDojoRequire(response, "dojo.widget.Button");
-    }
-    
-    private static void contributeScript(RenderResponse response, String language, String
type, String src, String textContent)
-    {
-        Element headElem = response.createElement("script");
-        
-        if (language != null)
-        {
-            headElem.setAttribute("language", language);
-        }
-        
-        if (src != null)
-        {
-            headElem.setAttribute("src", src);
-        }
-        
-        if (type != null)
-        {
-            headElem.setAttribute("type", type);
-        }
-        
-        if (textContent != null)
-        {
-            headElem.appendChild(headElem.getOwnerDocument().createTextNode(textContent));
-        }
-        
-        response.addProperty(MimeResponse.MARKUP_HEAD_ELEMENT, headElem);
-    }
-    
-    private static void contributeDojoRequire(RenderResponse response, String dojoRequire)
-    {
-        Element headElem = response.createElement("script");
-        headElem.setAttribute("language", "JavaScript");
-        headElem.setAttribute("type", "text/javascript");
-        headElem.setAttribute(HEAD_ELEMENT_CONTRIBUTION_MERGE_HINT_ATTRIBUTE, HEAD_ELEMENT_CONTRIBUTION_MERGE_HINT_KEY_DOJO_REQUIRE);
-        headElem.appendChild(headElem.getOwnerDocument().createTextNode("dojo.require(\""
+ dojoRequire + "\");"));
-        response.addProperty(MimeResponse.MARKUP_HEAD_ELEMENT, headElem);
+        DojoPortletHelper.contributeScript(response, "JavaScript", "text/javascript", "http://maps.google.com/maps?file=api&v=2&key="
+ apiKey, null);
+        DojoPortletHelper.contributeDojoRequire(response, "dojo.lang.*");
+        DojoPortletHelper.contributeDojoRequire(response, "dojo.event.*");
+        DojoPortletHelper.contributeDojoRequire(response, "dojo.io.*");
+        DojoPortletHelper.contributeDojoRequire(response, "dojo.widget.*");
+        DojoPortletHelper.contributeDojoRequire(response, "dojo.widget.Button");
     }
     
 }
-
-
-
-
-
-
-
-
-
-
-

Added: portals/applications/gems/src/main/java/org/apache/portals/gems/util/JSONUtils.java
URL: http://svn.apache.org/viewvc/portals/applications/gems/src/main/java/org/apache/portals/gems/util/JSONUtils.java?rev=763984&view=auto
==============================================================================
--- portals/applications/gems/src/main/java/org/apache/portals/gems/util/JSONUtils.java (added)
+++ portals/applications/gems/src/main/java/org/apache/portals/gems/util/JSONUtils.java Fri
Apr 10 17:35:20 2009
@@ -0,0 +1,172 @@
+/*
+ * 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.portals.gems.util;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * JSON utility
+ * 
+ * @author <a href="mailto:smilek@apache.org">Steve Milek</a>
+ * @version $Id$
+ */
+public class JSONUtils
+{
+    public static StringBuffer makeJSONObject(Map objectMap, boolean whenEmptyReturnNewObject)
+    {
+        return makeJSONObject(null, new Map[] { objectMap }, whenEmptyReturnNewObject);
+    }
+
+    public static StringBuffer makeJSONObject(Map[] objectMaps, boolean whenEmptyReturnNewObject)
+    {
+        return makeJSONObject(null, objectMaps, whenEmptyReturnNewObject);
+    }
+
+    public static StringBuffer makeJSONObject(StringBuffer jsonBuffer, Map objectMap, boolean
whenEmptyReturnNewObject)
+    {
+        return makeJSONObject(jsonBuffer, new Map[] { objectMap }, whenEmptyReturnNewObject);
+    }
+
+    public static StringBuffer makeJSONObject(StringBuffer jsonBuffer, Map[] objectMaps,
boolean whenEmptyReturnNewObject)
+    {
+        if (jsonBuffer == null)
+            jsonBuffer = new StringBuffer();
+        int added = 0;
+        int objMapsLen = (objectMaps == null ? 0 : objectMaps.length);
+        if (objMapsLen > 0)
+        {
+            for (int i = 0; i < objMapsLen; i++)
+            {
+                Map objectMap = objectMaps[i];
+                if (objectMap != null && objectMap.size() > 0)
+                {
+                    if (added == 0)
+                        jsonBuffer.append("{");
+                    Map.Entry objEntry;
+                    Object objKey, objVal;
+                    Iterator objMapIter = objectMap.entrySet().iterator();
+                    while (objMapIter.hasNext())
+                    {
+                        objEntry = (Map.Entry) objMapIter.next();
+                        objKey = objEntry.getKey();
+                        if (objKey != null)
+                        {
+                            if (added > 0)
+                                jsonBuffer.append(", ");
+                            jsonBuffer.append("\"").append(objKey.toString()).append("\":");
+                            objVal = objEntry.getValue();
+                            if (objVal == null)
+                                objVal = "";
+                            jsonBuffer.append("\"").append(objVal.toString()).append("\"");
+                            added++;
+                        }
+                    }
+                }
+            }
+        }
+        if (added > 0)
+        {
+            jsonBuffer.append("}");
+        }
+        else if (whenEmptyReturnNewObject)
+        {
+            jsonBuffer.append("{}");
+        }
+        else
+        {
+            return null;
+        }
+        return jsonBuffer;
+    }
+
+    public static String makeJSONStringArray(Collection stringList)
+    {
+        return makeJSONStringArray(stringList, null);
+    }
+
+    public static String makeJSONStringArray(Collection stringList, List compiledUniqueValues)
+    {
+        if (stringList != null && stringList.size() > 0)
+        {
+            StringBuffer stringListContent = new StringBuffer();
+            Iterator stringListIter = stringList.iterator();
+            while (stringListIter.hasNext())
+            {
+                String value = (String) stringListIter.next();
+                if (value != null && value.length() > 0)
+                {
+                    if (stringListContent.length() > 0)
+                    {
+                        stringListContent.append(", ");
+                    }
+                    else
+                    {
+                        stringListContent.append("[ ");
+                    }
+                    stringListContent.append("\"").append(value).append("\"");
+                    if (compiledUniqueValues != null)
+                    {
+                        if (!compiledUniqueValues.contains(value))
+                        {
+                            compiledUniqueValues.add(value);
+                        }
+                    }
+                }
+            }
+            if (stringListContent.length() > 0)
+            {
+                stringListContent.append(" ]");
+                return stringListContent.toString();
+            }
+        }
+        return null;
+    }
+
+    public static String makeJSONInteger(Object source, boolean quote)
+    {
+        String sourceStr = ((source == null) ? (String) null : source.toString());
+        if (sourceStr != null)
+        {
+            try
+            {
+                Integer.parseInt(sourceStr);
+                if (quote)
+                {
+                    sourceStr = "\"" + sourceStr + "\"";
+                }
+            }
+            catch (NumberFormatException nex)
+            {
+                sourceStr = null;
+            }
+        }
+        return sourceStr;
+    }
+
+    public static String makeJSONBoolean(Object source)
+    {
+        String boolStr = ((source == null) ? (String) null : source.toString());
+        if (boolStr != null && (!boolStr.equals("false")) && (!boolStr.equals("true")))
+        {
+            boolStr = null;
+        }
+        return boolStr;
+    }
+}

Propchange: portals/applications/gems/src/main/java/org/apache/portals/gems/util/JSONUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/applications/gems/src/main/java/org/apache/portals/gems/util/JSONUtils.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: portals/applications/gems/src/main/java/org/apache/portals/gems/util/JSONUtils.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message