You are viewing a plain text version of this content. The canonical link for it is here.
Posted to portalapps-dev@portals.apache.org by vk...@apache.org on 2009/04/16 14:35:00 UTC

svn commit: r765609 - in /portals/applications/gems/trunk: ./ src/main/java/org/apache/portals/applications/ src/main/java/org/apache/portals/applications/gems/ src/main/java/org/apache/portals/applications/gems/browser/

Author: vkumar
Date: Thu Apr 16 12:35:00 2009
New Revision: 765609

URL: http://svn.apache.org/viewvc?rev=765609&view=rev
Log:
https://issues.apache.org/jira/browse/APA-1
Updating gems version and removing old dependencies

Added:
    portals/applications/gems/trunk/src/main/java/org/apache/portals/applications/
    portals/applications/gems/trunk/src/main/java/org/apache/portals/applications/gems/
    portals/applications/gems/trunk/src/main/java/org/apache/portals/applications/gems/browser/
    portals/applications/gems/trunk/src/main/java/org/apache/portals/applications/gems/browser/Browser.java   (with props)
    portals/applications/gems/trunk/src/main/java/org/apache/portals/applications/gems/browser/BrowserIterator.java   (with props)
    portals/applications/gems/trunk/src/main/java/org/apache/portals/applications/gems/browser/BrowserPortlet.java   (with props)
    portals/applications/gems/trunk/src/main/java/org/apache/portals/applications/gems/browser/DatabaseBrowserIterator.java   (with props)
    portals/applications/gems/trunk/src/main/java/org/apache/portals/applications/gems/browser/StatusMessage.java   (with props)
Modified:
    portals/applications/gems/trunk/pom.xml

Modified: portals/applications/gems/trunk/pom.xml
URL: http://svn.apache.org/viewvc/portals/applications/gems/trunk/pom.xml?rev=765609&r1=765608&r2=765609&view=diff
==============================================================================
--- portals/applications/gems/trunk/pom.xml (original)
+++ portals/applications/gems/trunk/pom.xml Thu Apr 16 12:35:00 2009
@@ -1,19 +1,18 @@
 <?xml version="1.0" encoding="UTF-8"?>
-  <!--
-    Licensed to the Apache Software Foundation (ASF) under one or more
-    contributor license agreements. See the NOTICE file distributed with
-    this work for additional information regarding copyright ownership.
-    The ASF licenses this file to You under the Apache License, Version
-    2.0 (the "License"); you may not use this file except in compliance
-    with the License. You may obtain a copy of the License at
-
-    http://www.apache.org/licenses/LICENSE-2.0 Unless required by
-    applicable law or agreed to in writing, software distributed under
-    the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
-    OR CONDITIONS OF ANY KIND, either express or implied. See the
-    License for the specific language governing permissions and
-    limitations under the License. $Id$
-  -->
+<!--
+  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. $Id$
+-->
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
 
@@ -27,24 +26,21 @@
   <parent>
     <groupId>org.apache.portals</groupId>
     <artifactId>applications-pom</artifactId>
-    <version>1.0-SNAPSHOT</version>
+    <version>1.0</version>
   </parent>
-  
+
   <groupId>org.apache.portals.applications</groupId>
   <artifactId>apa-gems</artifactId>
-  <version>2.2-SNAPSHOT</version>
+  <version>1.0-SNAPSHOT</version>
 
   <packaging>jar</packaging>
   <name>Apache Portals Gems</name>
-  <description>
-    Reusable Portlets (Gems) for your Portlet Applications.
-  </description>
+  <description>Reusable Portlets (Gems) for your Portlet Applications.</description>
 
   <properties>
     <portlet-api.version>2.0</portlet-api.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>
     <commons-dbcp.version>1.2.2</commons-dbcp.version>
     <commons-httpclient.version>3.0.1</commons-httpclient.version>
     <commons-lang.version>2.1</commons-lang.version>
@@ -61,7 +57,7 @@
       <groupId>javax.portlet</groupId>
       <artifactId>portlet-api</artifactId>
       <version>${portlet-api.version}</version>
-    <scope>provided</scope>
+      <scope>provided</scope>
     </dependency>
     <dependency>
       <groupId>velocity</groupId>
@@ -74,11 +70,6 @@
       <version>${org.apache.portals.bridges.velocity.version}</version>
     </dependency>
     <dependency>
-      <groupId>commons-dbcp</groupId>
-      <artifactId>commons-dbcp</artifactId>
-      <version>${commons-dbcp.version}</version>
-    </dependency>
-    <dependency>
       <groupId>commons-lang</groupId>
       <artifactId>commons-lang</artifactId>
       <version>${commons-lang.version}</version>
@@ -103,17 +94,12 @@
       <artifactId>spring-webmvc-portlet</artifactId>
       <version>${spring.version}</version>
     </dependency>
-    <dependency>
-      <groupId>org.apache.poi</groupId>
-      <artifactId>poi</artifactId>
-      <version>${poi.version}</version>
-    </dependency>
   </dependencies>
 
   <scm>
-    <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>
+    <connection>scm:svn:http://svn.apache.org/repos/asf/portals/applications/gems/trunk/</connection>
+    <developerConnection>scm:svn:https://svn.apache.org/repos/asf/portals/applications/gems/trunk/</developerConnection>
+    <url>http://svn.apache.org/viewcvs.cgi/portals/applications/gems/trunk/</url>
   </scm>
 
 </project>
\ No newline at end of file

Added: portals/applications/gems/trunk/src/main/java/org/apache/portals/applications/gems/browser/Browser.java
URL: http://svn.apache.org/viewvc/portals/applications/gems/trunk/src/main/java/org/apache/portals/applications/gems/browser/Browser.java?rev=765609&view=auto
==============================================================================
--- portals/applications/gems/trunk/src/main/java/org/apache/portals/applications/gems/browser/Browser.java (added)
+++ portals/applications/gems/trunk/src/main/java/org/apache/portals/applications/gems/browser/Browser.java Thu Apr 16 12:35:00 2009
@@ -0,0 +1,39 @@
+/*
+ * 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.applications.gems.browser;
+
+import java.util.List;
+
+import javax.portlet.RenderRequest;
+
+
+/**
+ * GemsBrowser - defines the inteface for Gems Browsers
+ * 
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor </a>
+ * @version $Id: Browser.java 516448 2007-03-09 16:25:47Z ate $
+ */
+public interface Browser
+{
+    void getRows(RenderRequest request, String sql, int windowSize)
+    throws Exception;
+    
+    boolean filter(List row, RenderRequest request);    
+    
+    public void populate(int rowIndex, int columnIndex, List row);    
+    
+}
\ No newline at end of file

Propchange: portals/applications/gems/trunk/src/main/java/org/apache/portals/applications/gems/browser/Browser.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: portals/applications/gems/trunk/src/main/java/org/apache/portals/applications/gems/browser/BrowserIterator.java
URL: http://svn.apache.org/viewvc/portals/applications/gems/trunk/src/main/java/org/apache/portals/applications/gems/browser/BrowserIterator.java?rev=765609&view=auto
==============================================================================
--- portals/applications/gems/trunk/src/main/java/org/apache/portals/applications/gems/browser/BrowserIterator.java (added)
+++ portals/applications/gems/trunk/src/main/java/org/apache/portals/applications/gems/browser/BrowserIterator.java Thu Apr 16 12:35:00 2009
@@ -0,0 +1,99 @@
+/*
+ * 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.applications.gems.browser;
+
+import java.io.Serializable;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * DatabaseBrowserPortlet
+ * 
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor </a>
+ * @version $Id: BrowserIterator.java 516448 2007-03-09 16:25:47Z ate $
+ */
+public interface BrowserIterator extends Iterator, Comparator, Serializable
+{
+
+    /**
+     * This method returns the index of the row to which the cursor is pointing
+     * at.
+     *  
+     */
+    public int getTop();
+
+    /**
+     * This method returns the window size.
+     *  
+     */
+    public int getWindowSize();
+
+    /**
+     * This method returns the last index of the row in the window displayed.
+     *  
+     */
+    public int getBottom();
+
+    /**
+     * This method points the cursor to the index provided.
+     * 
+     * @param start
+     *            Index to which cursor should point to
+     */
+    public void setTop(int start);
+
+    /**
+     * This method returns the result set vector.
+     *  
+     */
+    public List getResultSet();
+
+    /**
+     * This method returns the number of rows in the result set.
+     *  
+     */
+    public int getResultSetSize();
+
+    /**
+     * This method returns the List containg the column labels of the result
+     * set.
+     *  
+     */
+    public List getResultSetTitleList();
+
+    /**
+     * This method returns the List containg the Types of the columns the result
+     * set.
+     * 
+     * @see java.sql.Types
+     */
+    public List getResultSetTypesList();
+
+    /**
+     * This method sorts the result set according to the value of the column as
+     * specified by the parameter column name. Changes the order of the result
+     * set vector. If it is called on the same columnName more than once it
+     * toggles the ordering ie first it will be ascending, then it will be
+     * descending, then ascending and so on.
+     * 
+     * @param String
+     *            sortColumnName
+     */
+    public void sort(String sortColumnName);
+
+}

Propchange: portals/applications/gems/trunk/src/main/java/org/apache/portals/applications/gems/browser/BrowserIterator.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: portals/applications/gems/trunk/src/main/java/org/apache/portals/applications/gems/browser/BrowserPortlet.java
URL: http://svn.apache.org/viewvc/portals/applications/gems/trunk/src/main/java/org/apache/portals/applications/gems/browser/BrowserPortlet.java?rev=765609&view=auto
==============================================================================
--- portals/applications/gems/trunk/src/main/java/org/apache/portals/applications/gems/browser/BrowserPortlet.java (added)
+++ portals/applications/gems/trunk/src/main/java/org/apache/portals/applications/gems/browser/BrowserPortlet.java Thu Apr 16 12:35:00 2009
@@ -0,0 +1,507 @@
+/*
+ * 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.applications.gems.browser;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Vector;
+
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletContext;
+import javax.portlet.PortletException;
+import javax.portlet.PortletMode;
+import javax.portlet.PortletPreferences;
+import javax.portlet.PortletRequest;
+import javax.portlet.PortletSession;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.portals.bridges.velocity.GenericVelocityPortlet;
+import org.apache.portals.messaging.PortletMessaging;
+import org.apache.velocity.context.Context;
+
+/**
+ * AbstractBrowserPortlet
+ * 
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor </a>
+ * @version $Id: BrowserPortlet.java 752495 2009-03-11 16:14:21Z vkumar $
+ */
+public class BrowserPortlet extends GenericVelocityPortlet implements Browser
+{
+    protected static final String SQL = "sql";
+    public static final String TABLE_NAME = "tableName";
+    public static final String CONDITIONS = "conditions";
+    public static final String Order_BY_COLUMNS = "orderByColumns";
+    public static final String COLUMNS = "columnNames";
+    protected static final String POOLNAME = "poolname";
+    protected static final String START = "start";
+    protected static final String FIND = "find";
+    protected static final String SEARCH_STRING = "searchString";
+    protected static final String SEARCH_COLUMN = "searchColumn";
+    protected static final String FILTERED = "filtered";
+    protected static final String FILTER = "filter";
+    protected static final String CUSTOMIZE_TEMPLATE = "customizeTemplate";
+    protected static final String WINDOW_SIZE = "WindowSize";
+    protected static final String USER_OBJECT_NAMES = "user-object-names";
+    protected static final String USER_OBJECT_TYPES = "user-object-types";
+    protected static final String USER_OBJECTS = "user-objects";
+    protected static final String SQL_PARAM_PREFIX = "sqlparam";
+    protected static final String LINKS_READ = "linksRead";
+    protected static final String ROW_LINK = "rowLinks";
+    
+    protected static final String TABLE_LINK = "tableLinks";
+    protected static final String ROW_LINK_IDS = "row-link-ids";
+    protected static final String ROW_LINK_TYPES = "row-link-types";
+    protected static final String ROW_LINK_TARGETS = "row-link-targets";
+    protected static final String TABLE_LINK_IDS = "table-link-ids";
+    protected static final String TABLE_LINK_TYPES = "table-link-types";
+    protected static final String TABLE_LINK_TARGETS = "table-link-targets";
+    protected static final String BROWSER_TABLE_SIZE = "tableSize";
+    protected static final String BROWSER_ACTION_KEY = "browser_action_key";
+    protected static final String BROWSER_ITERATOR = "table";
+    protected static final String BROWSER_TITLE_ITERATOR = "title";
+    protected static final String NEXT = "next";
+    protected static final String PREVIOUS = "prev";
+    protected static final String FIRST = "first";
+    protected static final String LAST = "last";
+    protected static final String VELOCITY_NULL_ENTRY = "-";
+    // portlet entry Id
+    protected static final String PEID = "js_peid";
+    protected static final String SORT_COLUMN_NAME = "js_dbcolumn";
+    protected static final String SORT_ORDER = "sortOrder";
+    protected List sqlParameters = new Vector();
+    /*
+     * SSO link
+     */
+    protected PortletContext context;
+    
+    /**
+     * Static initialization of the logger for this class
+     */
+    protected Log log = LogFactory.getLog(BrowserPortlet.class);
+
+    public void init(PortletConfig config) throws PortletException
+    {
+        super.init(config);
+        context = getPortletContext();
+    }
+
+    public void getRows(RenderRequest request, String sql, int windowSize) throws Exception
+    {
+    }
+
+    public void getRows(RenderRequest request, String sql, int windowSize, String filter) throws Exception
+    {
+    }
+
+    public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException
+    {
+        
+        int resultSetSize, next, prev, windowSize;
+        response.setContentType("text/html");
+        BrowserIterator iterator = getBrowserIterator(request);
+        Context context = this.getContext(request);
+        String sortColName = request.getParameter(SORT_COLUMN_NAME);
+        String sortorder = request.getParameter(SORT_ORDER);
+        int start = getStartVariable(request, START, sortColName, iterator);
+        PortletPreferences prefs = request.getPreferences();
+        windowSize = Integer.parseInt(prefs.getValue(WINDOW_SIZE, "10"));
+        StatusMessage message = (StatusMessage) PortletMessaging.consume(request, "DatabaseBrowserPortlet", "action");
+        if (sortorder==null)
+        {
+            sortorder = "DESC";
+        }
+        if (message != null)
+        {
+            this.getContext(request).put("statusMsg", message);
+        }
+        try
+        {
+            if (iterator == null)
+            {
+                String sql = getQueryString(request, context);
+                // System.out.println("buildNormalContext SQL: "+sql);
+                readUserParameters(request, context);
+                String filter = request.getParameter(FILTER);
+                if (filter != null)
+                    getRows(request, sql, windowSize, filter);
+                else
+                    getRows(request, sql, windowSize);
+                iterator = getBrowserIterator(request);
+                start = 0;
+            }
+            else
+            {
+                if (sortColName != null)
+                {
+                    iterator.sort(sortColName);
+                }
+            }
+            resultSetSize = iterator.getResultSetSize();
+            if (start >= resultSetSize)
+            {
+                if ((start - windowSize) > 0)
+                    start = resultSetSize - windowSize;
+                else
+                    start = 0;
+            }
+            next = start + windowSize;
+            prev = start - windowSize;
+            if (prev < 0 && start > 0)
+                prev = 0;
+            iterator.setTop(start);
+            readLinkParameters(request, context);
+            if (iterator != null)
+            {
+                resultSetSize = iterator.getResultSetSize();
+                if (next < resultSetSize)
+                {
+                    context.put(NEXT, String.valueOf(next));
+                }
+                if (prev <= resultSetSize && prev >= 0)
+                {
+                    context.put(PREVIOUS, String.valueOf(prev));
+                }
+                       
+                context.put(BROWSER_ITERATOR, iterator);
+                context.put(BROWSER_TITLE_ITERATOR, iterator.getResultSetTitleList());
+                context.put(BROWSER_TABLE_SIZE, new Integer(resultSetSize));
+                context.put(WINDOW_SIZE, new Integer(windowSize));
+                context.put(START, new Integer(start));
+                if(sortorder.equals("ASC")){
+                    context.put(SORT_ORDER, "DESC");    
+                }else{
+                    context.put(SORT_ORDER, "ASC");    
+                }
+                
+                /*
+                 * System.out.println("buildNormalContext Sort column name= "+sortColName); System.out.println("buildNormalContext Iterator:
+                 * "+iterator); System.out.println("buildNormalContext Titles= "+iterator.getResultSetTitleList()); System.out.println("buildNormalContext
+                 * windowSize="+windowSize+" prev="+prev+ " next="+next+" start="+start+" resultSetSize="+resultSetSize);
+                 */
+            }
+        }
+        catch (Exception e)
+        {
+            String msg = e.toString();
+            Throwable cause = e.getCause();
+            if (cause != null)
+            {
+                msg = msg + ", " + cause.getMessage();
+            }
+            context.put("statusMsg", new StatusMessage(msg, StatusMessage.ERROR));
+            // log the error msg
+            log.error("Exception", e);
+        }
+        super.doView(request, response);
+    }
+
+    public void doEdit(RenderRequest request, RenderResponse response) throws PortletException, IOException
+    {
+        response.setContentType("text/html");
+        doPreferencesEdit(request, response);
+    }
+
+    public void processAction(ActionRequest request, ActionResponse response) throws PortletException, IOException
+    {
+        if (request.getPortletMode() == PortletMode.EDIT)
+        {
+            processPreferencesAction(request, response);
+            clearBrowserIterator(request);
+        }
+        else
+        {
+            String browserAction = request.getParameter("db.browser.action");
+            if (browserAction != null)
+            {
+                if (browserAction.equals("refresh"))
+                {
+                    clearBrowserIterator(request);
+                }
+                String start = request.getParameter(START);
+                if (start != null)
+                {
+                    response.setRenderParameter(START, start);
+                }
+                String searchString = request.getParameter(SEARCH_STRING);
+                if (searchString != null)
+                {
+                    String searchColumn = request.getParameter(SEARCH_COLUMN);
+                    String filtered = request.getParameter(FILTERED);
+                    if (filtered != null)
+                    {
+                        clearBrowserIterator(request);
+                        response.setRenderParameter(FILTER, searchString);
+                    }
+                    else
+                    {
+                        int index = find(this.getBrowserIterator(request), searchString, searchColumn);
+                        if (index == -1)
+                        {
+                            try
+                            {
+                                StatusMessage sm = new StatusMessage("Could not find match for: " + searchString, StatusMessage.ALERT);
+                                PortletMessaging.publish(request, "DatabaseBrowserPortlet", "action", sm);
+                            }
+                            catch (Exception e)
+                            {
+                            }
+                        }
+                        else
+                        {
+                            response.setRenderParameter(START, Integer.toString(index));
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    /**
+     * Centralizes the calls to session - to retrieve the BrowserIterator.
+     * 
+     * @param data
+     *            The turbine rundata context for this request.
+     */
+    protected BrowserIterator getBrowserIterator(PortletRequest request)
+    {
+        BrowserIterator iterator = (BrowserIterator) request.getPortletSession().getAttribute(BROWSER_ACTION_KEY, PortletSession.PORTLET_SCOPE);
+        return iterator;
+    }
+
+    /**
+     * Centralizes the calls to session - to set the BrowserIterator.
+     * 
+     * @param data
+     *            The turbine rundata context for this request.
+     * @param iterator
+     *            .
+     */
+    protected void setBrowserIterator(RenderRequest request, BrowserIterator iterator)
+    {
+        request.getPortletSession().setAttribute(BROWSER_ACTION_KEY, iterator);
+    }
+
+    /**
+     * Centralizes the calls to session - to clear the BrowserIterator from the temp storage.
+     * 
+     * @param data
+     *            The turbine rundata context for this request.
+     */
+    protected void clearBrowserIterator(PortletRequest request)
+    {
+        request.getPortletSession().removeAttribute(BROWSER_ACTION_KEY);
+    }
+
+    protected int getStartVariable(RenderRequest request, String attrName, String sortColName, BrowserIterator iterator)
+    {
+        int start = -1;
+        // if users want to overwrite how the sorting affects the cursor for
+        // the window
+        if (sortColName != null)
+            start = getStartIndex();
+        if (start < 0)
+        {
+            // fallback routine for start
+            String startStr = request.getParameter(attrName);
+            if (startStr != null && startStr.length() > 0)
+            {
+                try
+                {
+                    start = Integer.parseInt(startStr);
+                }
+                catch (Exception e)
+                {
+                    if (iterator != null)
+                        start = iterator.getTop();
+                    else
+                        start = 0;
+                }
+            }
+            else if (start == -1 && iterator != null)
+            {
+                start = iterator.getTop();
+            }
+            if (start < 0)
+                start = 0;
+        }
+        return start;
+    }
+
+    /**
+     * to be used if sorting behavior to be overwritten
+     */
+    protected int getStartIndex()
+    {
+        return 0;
+    }
+
+    /**
+     * This method returns the sql from the getQuery method which can be overwritten according to the needs of the application. If the getQuery() returns null,
+     * then it gets the value from the psml file. If the psml value is null then it returns the value from the xreg file.
+     */
+    protected String getQueryString(RenderRequest request, Context context)
+    {
+        String sql = getQueryString(request);
+        if (null == sql)
+        {
+            sql = getPreference(request, SQL, null);
+        }
+        return sql;
+    }
+
+    public String getQueryString(PortletRequest request)
+    {
+        return null;
+    }
+
+    protected String getPreference(PortletRequest request, String attrName, String attrDefValue)
+    {
+        return request.getPreferences().getValue(attrName, attrDefValue);
+    }
+
+    protected void readUserParameters(RenderRequest request, Context context)
+    {
+        Object userObjRead = request.getPortletSession().getAttribute(USER_OBJECTS, PortletSession.PORTLET_SCOPE);
+        if (userObjRead != null)
+        {
+            context.put(USER_OBJECTS, userObjRead);
+            // System.out.println("userObjectListSize: "+
+            // ((List)userObjRead).size());
+        }
+        else
+        {
+            /*
+             * TODO: implement user parameters String userObjTypes= getParameterFromRegistry(portlet,USER_OBJECT_TYPES,null); String userObjNames=
+             * getParameterFromRegistry(portlet,USER_OBJECT_NAMES,null); if( userObjTypes != null && userObjTypes.length() > 0 ) { userObjectList = new
+             * ArrayList(); int userObjectIndex = 0; StringTokenizer tokenizer1 = new StringTokenizer(userObjNames, ","); StringTokenizer tokenizer3 = new
+             * StringTokenizer(userObjTypes, ","); while(tokenizer1.hasMoreTokens() && tokenizer3.hasMoreTokens()) { userObjectList.add(userObjectIndex, new
+             * ActionParameter(tokenizer1.nextToken(), null, tokenizer3.nextToken())); userObjectIndex++; } context.put(USER_OBJECTS, userObjectList);
+             * setParameterToTemp(portlet, rundata, USER_OBJECTS, userObjectList); //System.out.println("readLink: userObjectTypesListSize:
+             * "+userObjectList.size()); }
+             */
+        }
+    }
+
+    protected void readSqlParameters(PortletRequest request)
+    {
+        List sqlParamList = null;
+        int i = 1;
+        while (true)
+        {
+            String param = getPreference(request, SQL_PARAM_PREFIX + i, null);
+            if (param == null)
+            {
+                break;
+            }
+            else
+            {
+                if (sqlParamList == null)
+                {
+                    sqlParamList = new ArrayList();
+                }
+                sqlParamList.add(param);
+            }
+            i++;
+        }
+        if (sqlParamList != null)
+        {
+            setSQLParameters(sqlParamList);
+        }
+    }
+
+    public void setSQLParameters(List parameters)
+    {
+        this.sqlParameters = parameters;
+    }
+
+    protected void readLinkParameters(RenderRequest request, Context context)
+    {
+        // TODO: implement me
+    }
+
+    /**
+     * This method should be overwritten every time the user object needs to be populated with some user specific constraints. As an example if the user wanted
+     * to track the parent of an object based on some calculation per row, it could be done here.
+     */
+    public void populate(int rowIndex, int columnIndex, List row)
+    {
+    }
+
+    public boolean filter(List row, RenderRequest request)
+    {
+        return false;
+    }
+
+    public void publishStatusMessage(PortletRequest request, String portlet, String topic, Throwable e, String message)
+    {
+        String msg = message + ": " + e.toString();
+        Throwable cause = e.getCause();
+        if (cause != null)
+        {
+            msg = msg + ", " + cause.getMessage();
+        }
+        StatusMessage sm = new StatusMessage(msg, StatusMessage.ERROR);
+        try
+        {
+            // TODO: fixme, bug in Pluto on portlet session
+            PortletMessaging.publish(request, portlet, topic, sm);
+        }
+        catch (Exception ee)
+        {
+            System.err.println("Failed to publish message: " + e);
+        }
+    }
+
+    public int find(BrowserIterator iterator, String searchString, String searchColumn)
+    {
+        int index = 0;
+        int column = 1;
+        if (searchColumn != null)
+            column = Integer.parseInt(searchColumn);
+        Iterator it = iterator.getResultSet().iterator();
+        while (it.hasNext())
+        {
+            Object row = it.next();
+            String item = "";
+            if (row instanceof String)
+                item = (String) row;
+            else if (row instanceof List)
+            {
+                // TODO: this only works on String columns
+                item = (String) ((List) row).get(column);
+            }
+            if (item.startsWith(searchString))
+            {
+                return index;
+            }
+            index++;
+        }
+        return -1;
+    }
+
+    public List getTitleList(PortletRequest request)
+    {
+        return null;
+    } 
+}
\ No newline at end of file

Propchange: portals/applications/gems/trunk/src/main/java/org/apache/portals/applications/gems/browser/BrowserPortlet.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: portals/applications/gems/trunk/src/main/java/org/apache/portals/applications/gems/browser/DatabaseBrowserIterator.java
URL: http://svn.apache.org/viewvc/portals/applications/gems/trunk/src/main/java/org/apache/portals/applications/gems/browser/DatabaseBrowserIterator.java?rev=765609&view=auto
==============================================================================
--- portals/applications/gems/trunk/src/main/java/org/apache/portals/applications/gems/browser/DatabaseBrowserIterator.java (added)
+++ portals/applications/gems/trunk/src/main/java/org/apache/portals/applications/gems/browser/DatabaseBrowserIterator.java Thu Apr 16 12:35:00 2009
@@ -0,0 +1,363 @@
+/*
+ * 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.applications.gems.browser;
+
+import java.sql.Types;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * A class for iterating over the window. The window constitutes the selection
+ * of rows being displayed to the user from the List storing all the ResultSet.
+ * 
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor </a>
+ * @version $Id: DatabaseBrowserIterator.java 517121 2007-03-12 07:45:49Z ate $
+ */
+public class DatabaseBrowserIterator implements BrowserIterator
+{
+    private static final long serialVersionUID = 1;    
+
+    /**
+     * Static initialization of the logger for this class
+     */
+    transient protected Log log = LogFactory.getLog(DatabaseBrowserIterator.class);
+
+    private static final String VELOCITY_NULL_ENTRY = "-";
+
+    int top = 0;
+
+    int index = 0;
+
+    int bottom = -1;
+
+    int windowSize = -1;
+
+    int rsListSize = -1;
+
+    boolean ascendingOrder = true;
+
+    String sortColumnName = null;
+
+    List rsList;
+
+    List rsTitleList;
+
+    List rsTypeList;
+
+    /**
+     * Constructor for the database browser iterator
+     * 
+     * @param result
+     *            The List containg all the rows from the resultSet.
+     * @param columnTitles
+     *            The List containg all the columnLabels from a resultSet.
+     * @param pageSize
+     *            The number of rows to be displayed in a window configured by
+     *            the user.
+     */
+    public DatabaseBrowserIterator(List result, List columnTitles,
+            List columnTypes, int pageSize)
+    {
+        this.rsList = result;
+        this.rsTitleList = columnTitles;
+        this.rsTypeList = columnTypes;
+        this.windowSize = pageSize;
+        this.rsListSize = result.size();
+        setBottom();
+    }
+
+    /**
+     * This method returns the result set.
+     *  
+     */
+    public List getResultSet()
+    {
+        return rsList;
+    }
+
+    /**
+     * This method returns the number of rows in the result set.
+     *  
+     */
+    public int getResultSetSize()
+    {
+        return rsListSize;
+    }
+
+    /**
+     * This method returns the List containg the column labels of the result
+     * set.
+     *  
+     */
+    public List getResultSetTitleList()
+    {
+        return rsTitleList;
+    }
+
+    /**
+     * This method returns the List containg the column type names of the result
+     * set.
+     * 
+     * @see java.sql.Types
+     */
+    public List getResultSetTypesList()
+    {
+        return rsTypeList;
+    }
+
+    /**
+     * This method returns the index of the row to which the cursor is pointing
+     * at.
+     *  
+     */
+    public int getTop()
+    {
+        return top;
+    }
+
+    /**
+     * This method points the cursor to the index provided.
+     * 
+     * @param start
+     *            Index to which cursor should point to
+     */
+    public void setTop(int start)
+    {
+        top = start;
+        index = top;
+        setBottom();
+    }
+
+    /**
+     * This method returns the last index of the row in the window displayed.
+     *  
+     */
+    public int getBottom()
+    {
+        return bottom;
+    }
+
+    /**
+     * This method returns the window size.
+     *  
+     */
+    public int getWindowSize()
+    {
+        return windowSize;
+    }
+
+    /**
+     * This method sets the bottom based on which index the cursor points to and
+     * the size of the result set.
+     *  
+     */
+    private void setBottom()
+    {
+        bottom = top + windowSize;
+        if (bottom > rsListSize)
+        {
+            bottom = rsListSize;
+        }
+    }
+
+    /**
+     * Returns true if the iteration has more elements
+     */
+    public boolean hasNext()
+    {
+        if (index <= rsListSize && index < bottom) { return true; }
+        return false;
+    }
+
+    /**
+     * Returns the next element in the iteration
+     */
+    public Object next()
+    {
+        index = index + 1;
+        return rsList.get(index - 1);
+    }
+
+    /**
+     * Logs as info - since remove operation is not supported by this Iterator.
+     */
+    public void remove()
+    {
+        log.info("The remove operation is not supported.");
+    }
+
+    /**
+     * This method sorts the result set according to the value of the column as
+     * specified by the parameter column name. Changes the order of the result
+     * set vector.
+     * 
+     * @param String
+     *            sortColumnName
+     */
+    public void sort(String columnName)
+    {
+        //System.out.println("current columnName="+columnName);
+        //System.out.println("old columnName="+sortColumnName);
+        if (columnName != null)
+        {
+            if (sortColumnName != null && sortColumnName.equals(columnName))
+            {
+                ascendingOrder = !ascendingOrder;
+            } else
+            {
+                ascendingOrder = true;
+                sortColumnName = columnName;
+            }
+            Collections.sort(rsList, this);
+        }
+    }
+
+    /*
+     * Compares its two arguments for order.
+     *  
+     */
+    public int compare(Object obj1, Object obj2)
+    {
+        int idx = rsTitleList.indexOf(sortColumnName);
+        int order = 0;
+
+        if (idx != -1)
+        {
+            Object col1 = null;
+            Object col2 = null;
+            
+            if (obj1 instanceof String)
+            {
+                col1 = obj1;
+                col2 = obj2;                
+            }
+            else if (obj1 instanceof List)
+            {
+                col1 = ((List) obj1).get(idx);
+                col2 = ((List) obj2).get(idx);
+            }
+
+            if ((col1).equals(VELOCITY_NULL_ENTRY))
+            {
+                if ((col2).equals(VELOCITY_NULL_ENTRY))
+                {
+                    order = 0;
+                } else
+                {
+                    order = -1;
+                }
+            } else if ((col2).equals(VELOCITY_NULL_ENTRY))
+            {
+                order = 1;
+            } else
+            {
+                int type = Integer.parseInt((String) rsTypeList.get(idx));
+                switch (type)
+                {
+
+                case Types.NUMERIC:
+                    order = (((java.math.BigDecimal) col1)
+                            .compareTo((java.math.BigDecimal) col2));
+                    break;
+
+                case Types.DECIMAL:
+                    order = (((java.math.BigDecimal) col1)
+                            .compareTo((java.math.BigDecimal) col2));
+                    break;
+
+                case Types.TINYINT:
+                    order = (((Byte) col1).compareTo((Byte) col2));
+                    break;
+
+                case Types.SMALLINT:
+                    order = (((Short) col1).compareTo((Short) col2));
+                    break;
+
+                case Types.INTEGER:
+                    order = (((Integer) col1).compareTo((Integer) col2));
+                    break;
+
+                case Types.BIGINT:
+                    order = (((Long) col1).compareTo((Long) col2));
+                    break;
+
+                case Types.REAL:
+                    order = (((Float) col1).compareTo((Float) col2));
+                    break;
+
+                case Types.FLOAT:
+                    order = (((Double) col1).compareTo((Double) col2));
+                    break;
+
+                case Types.DOUBLE:
+                    order = (((Double) col1).compareTo((Double) col2));
+                    break;
+
+                case Types.DATE:
+                    order = (((java.sql.Date) col1)
+                            .compareTo((java.sql.Date) col2));
+                    break;
+
+                case Types.TIME:
+                    order = (((java.sql.Time) col1)
+                            .compareTo((java.sql.Time) col2));
+                    break;
+
+                case Types.TIMESTAMP:
+                    order = (((java.sql.Timestamp) col1)
+                            .compareTo((java.sql.Timestamp) col2));
+                    break;
+
+                case Types.CHAR:
+                    order = (((String) col1).compareTo((String) col2));
+                    break;
+
+                case Types.VARCHAR:
+                    order = (((String) col1).compareTo((String) col2));
+                    break;
+
+                case Types.LONGVARCHAR:
+                    order = (((String) col1).compareTo((String) col2));
+                    break;
+
+                default:
+                    log
+                            .info("DatabaseBrowserIterator.compare DataType mapping not found"
+                                    + " in DatabaseBrowserIterator. "
+                                    + "Hence cannot sort based on provided column.");
+                    break;
+                }
+            }
+        }
+        //System.out.println("index of type= "+idx +", order= "+order+",
+        // ascending= "+ascendingOrder);
+        if (!ascendingOrder)
+        {
+            order = 0 - order;
+        }
+        return order;
+    }
+    
+    public boolean getAscendingOrder()
+    {
+        return ascendingOrder;
+    }
+
+}

Propchange: portals/applications/gems/trunk/src/main/java/org/apache/portals/applications/gems/browser/DatabaseBrowserIterator.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: portals/applications/gems/trunk/src/main/java/org/apache/portals/applications/gems/browser/StatusMessage.java
URL: http://svn.apache.org/viewvc/portals/applications/gems/trunk/src/main/java/org/apache/portals/applications/gems/browser/StatusMessage.java?rev=765609&view=auto
==============================================================================
--- portals/applications/gems/trunk/src/main/java/org/apache/portals/applications/gems/browser/StatusMessage.java (added)
+++ portals/applications/gems/trunk/src/main/java/org/apache/portals/applications/gems/browser/StatusMessage.java Thu Apr 16 12:35:00 2009
@@ -0,0 +1,80 @@
+/*
+ * 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.applications.gems.browser;
+
+import java.io.Serializable;
+
+/**
+ * StatusMessage
+ * 
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor </a>
+ * @version $Id: StatusMessage.java 516448 2007-03-09 16:25:47Z ate $
+ */
+public class StatusMessage implements Serializable
+{    
+    private static final long serialVersionUID = 1;    
+    private String text;
+    private String type;
+        
+    public static final String INFO  = "portlet-msg-info";
+    public static final String ERROR = "portlet-msg-error";
+    public static final String ALERT = "portlet-msg-alert";
+    public static final String SUCCESS = "portlet-msg-success";
+    
+    public StatusMessage(String text, String type)
+    {
+        this.text = new String(text);
+        this.type = type;
+    }
+
+    public StatusMessage(String text)
+    {
+        this.text = new String(text);
+        this.type = INFO;
+    }
+    
+    
+    
+    /**
+     * @return Returns the text.
+     */
+    public String getText()
+    {
+        return text;
+    }
+    /**
+     * @param text The text to set.
+     */
+    public void setText(String text)
+    {
+        this.text = text;
+    }
+    /**
+     * @return Returns the type.
+     */
+    public String getType()
+    {
+        return type;
+    }
+    /**
+     * @param type The type to set.
+     */
+    public void setType(String type)
+    {
+        this.type = type;
+    }
+}
\ No newline at end of file

Propchange: portals/applications/gems/trunk/src/main/java/org/apache/portals/applications/gems/browser/StatusMessage.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain