Author: vkumar
Date: Thu Feb 26 15:50:12 2009
New Revision: 748187

URL: http://svn.apache.org/viewvc?rev=748187&view=rev
Log:
Fixing small issues of databaseBrowser portlet and removing SSO dependency from 
browser portlet

Modified:
    portals/applications/demo/src/main/webapp/WEB-INF/view/database-edit.vm
    portals/applications/demo/src/main/webapp/WEB-INF/view/database-edit1.vm
    portals/applications/demo/src/main/webapp/WEB-INF/view/database-view.vm
    
portals/applications/gems/src/main/java/org/apache/portals/gems/browser/BrowserPortlet.java
    
portals/applications/gems/src/main/java/org/apache/portals/gems/browser/DatabaseBrowserPortlet.java

Modified: 
portals/applications/demo/src/main/webapp/WEB-INF/view/database-edit.vm
URL: 
http://svn.apache.org/viewvc/portals/applications/demo/src/main/webapp/WEB-INF/view/database-edit.vm?rev=748187&r1=748186&r2=748187&view=diff
==============================================================================
--- portals/applications/demo/src/main/webapp/WEB-INF/view/database-edit.vm 
(original)
+++ portals/applications/demo/src/main/webapp/WEB-INF/view/database-edit.vm Thu 
Feb 26 15:50:12 2009
@@ -27,13 +27,15 @@
 #set ($disableSSO = "")
 #end
 
+#set($name=$renderResponse.Namespace)
+
 #if ($statusMsg)
 #parse ('/WEB-INF/view/status-include.vm')
 #end
 
 <h3 class="portlet-section-header">$MESSAGES.getString('label.prefs')</h3>
 
-<form name='J2DBEdit' action="$renderResponse.createActionURL()" method="post">
+<form name='J2DBEdit$name' action="$renderResponse.createActionURL()" 
method="post">
 <table border="0" cellspacing="2" cellpadding="3">
   <tr>
     <th class="portlet-section-alternate"><font 
class="portlet-form-field-label">$MESSAGES.getString('label.datasource.type')</font></th>
@@ -44,10 +46,6 @@
       <div>
         <input type="radio" name="DatasourceType" value='dbcp' #if ($dst == 
'dbcp') checked #end onClick="javascript:chooseDBCP();"/> <font 
class="portlet-form-field-label">$MESSAGES.getString("label.datasource.dbcp")</font>
       </div>
-      <div>
-        <input type="radio" name="DatasourceType" value='sso' #if ($dst == 
'sso') checked #end onClick="javascript:chooseSSO();"/> <font 
class="portlet-form-field-label">$MESSAGES.getString("label.datasource.sso")</font>
-      </div>
-      <p class="portlet-form-field">$MESSAGES.getString('label.select.ds')</p>
     </td>
   </tr>
 </table>
@@ -92,30 +90,6 @@
   </tr>  
 </table>
 
-<h4 
class="portlet-section-header">$MESSAGES.getString('label.sso.settings')</h4>
-
-<table border="0" cellspacing="2" cellpadding="3">
-<tr>
-    <th class="portlet-section-alternate"><font 
class="portlet-form-field-label">$MESSAGES.getString("label.jdbc.driver")</font></th>
-    <td>
-      <input type="input" name="SSOJdbcDriver" $!disableSSO  
value="$!prefsMap.get('SSOJdbcDriver')" size="60" maxlength="100" 
class="portlet-form-field-label"/> 
-    </td>
-  </tr>
-  <tr>
-    <th class="portlet-section-alternate"><font 
class="portlet-form-field-label">$MESSAGES.getString("label.jdbc.connection")</font></th>
-    <td>
-      <input type="input" name="SSOJdbcConnection" $!disableSSO 
value="$!prefsMap.get('SSOJdbcConnection')" size="60" maxlength="100" 
class="portlet-form-field-label"/> 
-    </td>
-  </tr>
-  <tr>
-    <th class="portlet-section-alternate"><font 
class="portlet-form-field-label">SSO Site</font></th>
-    <td>
-      <input type="input" name="SSOSite" $!disableSSO 
value="$!prefsMap.get('SSOSite')" size="60" maxlength="100" 
class="portlet-form-field-label"/> 
-    </td>
-  </tr>
-  </tr>  
-</table>
-
 <h4 
class="portlet-section-header">$MESSAGES.getString('label.general.settings')</h4>
 <table border="0" cellspacing="2" cellpadding="3">
   <tr>
@@ -129,7 +103,7 @@
     <th class="portlet-section-alternate"><font 
class="portlet-form-field-label">TABLE</font></th>
     <td>
        #if($tableLists)
-               <select name="tables" id="tables">
+               <select name="tables${name}" id="tables${name}">
                #foreach ($table in $tableLists )
                        <option value='$table'
                        #if($table == $tabelPref)    
@@ -155,64 +129,48 @@
   function nextPage()
   {
        #if($tableLists)
-       var tables = document.getElementById('tables');
-       document.J2DBEdit.tableName.value = 
tables.options[tables.selectedIndex].value;
+       var tables = document.getElementById('tables${name}');
+       document.J2DBEdit${name}.tableName.value = 
tables.options[tables.selectedIndex].value;
        #else
-       var tables = document.getElementById('tables');
-       document.J2DBEdit.tableName.value = tables.value;
+       var tables = document.getElementById('tables${name}');
+       document.J2DBEdit${name}.tableName.value = tables.value;
        #end
-       document.J2DBEdit.configPage.value = 'configPage1';
-       document.J2DBEdit.submit();
+       document.J2DBEdit${name}.configPage.value = 'configPage1';
+       document.J2DBEdit${name}.submit();
   }
   function chooseDS() 
   {
     disableDS(false);
     disableDBCP(true);
-    disableSSO(true);
   }
 
   function chooseDBCP() 
   {
     disableDS(true);
     disableDBCP(false);
-    disableSSO(true);
-  }
-
-  function chooseSSO() 
-  {
-    disableDS(true);
-    disableDBCP(true);
-    disableSSO(false);
   }
 
   function disableDS(flag) 
   {
-    document.forms['J2DBEdit'].JndiDatasource.disabled = flag;            
+    document.forms['J2DBEdit$name'].JndiDatasource.disabled = flag;            
   }
 
   function disableDBCP(flag) 
   {
-    document.forms['J2DBEdit'].JdbcDriver.disabled = flag;            
-    document.forms['J2DBEdit'].JdbcConnection.disabled = flag;            
-    document.forms['J2DBEdit'].JdbcUsername.disabled = flag;            
-    document.forms['J2DBEdit'].JdbcPassword.disabled = flag;            
-  }
-
-  function disableSSO(flag) 
-  {
-    document.forms['J2DBEdit'].SSOSite.disabled = flag;            
-    document.forms['J2DBEdit'].SSOJdbcDriver.disabled = flag;            
-    document.forms['J2DBEdit'].SSOJdbcConnection.disabled = flag;              
     
+    document.forms['J2DBEdit$name'].JdbcDriver.disabled = flag;            
+    document.forms['J2DBEdit$name'].JdbcConnection.disabled = flag;            
+    document.forms['J2DBEdit$name'].JdbcUsername.disabled = flag;            
+    document.forms['J2DBEdit$name'].JdbcPassword.disabled = flag;            
   }
 
   function presave()
   {
     #if($tableLists)
        var tables = document.getElementById('tables');
-       document.J2DBEdit.tableName.value = 
tables.options[tables.selectedIndex].value;
+       document.J2DBEdit${name}.tableName.value = 
tables.options[tables.selectedIndex].value;
        #else
        var tables = document.getElementById('tables');
-       document.J2DBEdit.tableName.value = tables.value;
+       document.J2DBEdit${name}.tableName.value = tables.value;
        #end
     disableDS(false);
     disableDBCP(false);

Modified: 
portals/applications/demo/src/main/webapp/WEB-INF/view/database-edit1.vm
URL: 
http://svn.apache.org/viewvc/portals/applications/demo/src/main/webapp/WEB-INF/view/database-edit1.vm?rev=748187&r1=748186&r2=748187&view=diff
==============================================================================
--- portals/applications/demo/src/main/webapp/WEB-INF/view/database-edit1.vm 
(original)
+++ portals/applications/demo/src/main/webapp/WEB-INF/view/database-edit1.vm 
Thu Feb 26 15:50:12 2009
@@ -27,13 +27,15 @@
 #set ($disableSSO = "")
 #end
 
+#set($name=$renderResponse.Namespace)
+
 #if ($statusMsg)
 #parse ('/WEB-INF/view/status-include.vm')
 #end
 
 <h3 class="portlet-section-header">Fields</h3>
 
-<form name='J2DBEdit' action="" method="post">
+<form name='J2DBEdit$name' action="" method="post">
 <table border="0" cellspacing="2" cellpadding="3">
   <tr>
     <td class="portlet-section-alternate"><font 
class="portlet-form-field-label">Field Name</font></td>
@@ -124,6 +126,7 @@
        }
        function arrangeColumns()
        {
+               document.getElementById('conditions').value  = 
document.getElementById('conditions').value.replace('where ' ,'');
                var columns = document.getElementById('avilableCols');
                var selectedCols = document.getElementById('selectedCols');     
                for(var j=0; j<ColName.length; j++)
@@ -221,6 +224,13 @@
                                tempValue = tempValue + "," + 
colValue.split(':')[0] + " " + colValue.split(':')[1];
                        }
                }
+       
+               var whereCond = document.getElementById('conditions').value;
+               if(whereCond.length>0)
+               {
+                 whereCond = 'where ' + whereCond;
+                  document.getElementById('conditions').value = whereCond;     
+               }
                document.getElementById('orderByColumns').value = 
tempValue.substring(1);
        }
 
@@ -229,8 +239,8 @@
                listToString();         
                #set ($xmlLink = $renderResponse.createActionURL())
                $xmlLink.setParameter("configPage","configPage")
-               document.J2DBEdit.action = '$xmlLink';
-               document.J2DBEdit.submit();
+               document.J2DBEdit${name}.action = '$xmlLink';
+               document.J2DBEdit${name}.submit();
        }
        function saveAdvanceData()
        {
@@ -238,8 +248,8 @@
                orderBylist();
                #set ($xmlLink = $renderResponse.createActionURL())
                $xmlLink.setParameter("configPage","save")
-               document.J2DBEdit.action = '$xmlLink';
-               document.J2DBEdit.submit();
+               document.J2DBEdit${name}.action = '$xmlLink';
+               document.J2DBEdit${name}.submit();
        }
        
        function moveoutid(source,destination)

Modified: 
portals/applications/demo/src/main/webapp/WEB-INF/view/database-view.vm
URL: 
http://svn.apache.org/viewvc/portals/applications/demo/src/main/webapp/WEB-INF/view/database-view.vm?rev=748187&r1=748186&r2=748187&view=diff
==============================================================================
--- portals/applications/demo/src/main/webapp/WEB-INF/view/database-view.vm 
(original)
+++ portals/applications/demo/src/main/webapp/WEB-INF/view/database-view.vm Thu 
Feb 26 15:50:12 2009
@@ -142,7 +142,8 @@
       <td valign="middle" height="30">
         <div align="center">
                <input type='hidden' name='db.browser.action' value='change'/>  
                  
-               <input type="input" name='start' size='5' value="$start">
+               #set($index = $start + 1)
+               <input type="input" name='start' size='5' value="$index">
         </div>
       </td>  
       <td valign="middle" height="30">
@@ -193,4 +194,4 @@
       </td>
     #end
   </tr>
-</table>
+</table>
\ No newline at end of file

Modified: 
portals/applications/gems/src/main/java/org/apache/portals/gems/browser/BrowserPortlet.java
URL: 
http://svn.apache.org/viewvc/portals/applications/gems/src/main/java/org/apache/portals/gems/browser/BrowserPortlet.java?rev=748187&r1=748186&r2=748187&view=diff
==============================================================================
--- 
portals/applications/gems/src/main/java/org/apache/portals/gems/browser/BrowserPortlet.java
 (original)
+++ 
portals/applications/gems/src/main/java/org/apache/portals/gems/browser/BrowserPortlet.java
 Thu Feb 26 15:50:12 2009
@@ -36,10 +36,6 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.jetspeed.CommonPortletServices;
-import org.apache.jetspeed.security.UserManager;
-import org.apache.jetspeed.services.JetspeedPortletServices;
-import org.apache.jetspeed.sso.SSOManager;
 import org.apache.portals.bridges.velocity.GenericVelocityPortlet;
 import org.apache.portals.gems.util.StatusMessage;
 import org.apache.portals.messaging.PortletMessaging;
@@ -98,8 +94,6 @@
      * SSO link
      */
     protected PortletContext context;
-    protected SSOManager sso;
-    protected UserManager userManager;
     
     /**
      * Static initialization of the logger for this class
@@ -110,17 +104,6 @@
     {
         super.init(config);
         context = getPortletContext();
-        sso = (SSOManager) 
context.getAttribute(CommonPortletServices.CPS_SSO_COMPONENT);
-        if (null == sso)
-        {
-            log.info("Warning: SSO Manager not found.");
-            // throw new PortletException("Failed to find SSO Provider on 
portlet initialization");
-        }
-        userManager = (UserManager) 
context.getAttribute(CommonPortletServices.CPS_USER_MANAGER_COMPONENT); 
-        if (null == userManager)
-        {
-            log.info("Warning: User Manager not found.");
-        }
     }
 
     public void getRows(RenderRequest request, String sql, int windowSize) 
throws Exception
@@ -186,7 +169,7 @@
             if (iterator != null)
             {
                 resultSetSize = iterator.getResultSetSize();
-                if (next <= resultSetSize)
+                if (next < resultSetSize)
                 {
                     context.put(NEXT, String.valueOf(next));
                 }

Modified: 
portals/applications/gems/src/main/java/org/apache/portals/gems/browser/DatabaseBrowserPortlet.java
URL: 
http://svn.apache.org/viewvc/portals/applications/gems/src/main/java/org/apache/portals/gems/browser/DatabaseBrowserPortlet.java?rev=748187&r1=748186&r2=748187&view=diff
==============================================================================
--- 
portals/applications/gems/src/main/java/org/apache/portals/gems/browser/DatabaseBrowserPortlet.java
 (original)
+++ 
portals/applications/gems/src/main/java/org/apache/portals/gems/browser/DatabaseBrowserPortlet.java
 Thu Feb 26 15:50:12 2009
@@ -32,7 +32,6 @@
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.Collection;
 import java.util.Date;
 import java.util.Iterator;
 import java.util.List;
@@ -56,11 +55,6 @@
 import org.apache.jetspeed.PortalReservedParameters;
 import org.apache.jetspeed.request.RequestContext;
 import org.apache.jetspeed.security.JSSubject;
-import org.apache.jetspeed.security.JetspeedPrincipal;
-import org.apache.jetspeed.security.PasswordCredential;
-import org.apache.jetspeed.sso.SSOException;
-import org.apache.jetspeed.sso.SSOSite;
-import org.apache.jetspeed.sso.SSOUser;
 import org.apache.poi.hssf.usermodel.HSSFCell;
 import org.apache.poi.hssf.usermodel.HSSFRow;
 import org.apache.poi.hssf.usermodel.HSSFSheet;
@@ -86,7 +80,7 @@
     String pageRoot = System.getProperty("java.io.tmpdir");
     private String[] colNames;
     private SimpleDateFormat date_output;
-    private static final String DATE_OUTPUT_PATTERN = "M/d/yyyy";
+    private static final String DATE_OUTPUT_PATTERN = "M/d/yyyy HH:mm:ss z";
     BrowserIterator dataBaseIterator;
     private String BLANK_STRING_ARRAY[] = new String[0]; 
     public BrowserIterator getLocalIterators(PortletRequest request, String 
sql, int windowSize) throws Exception
@@ -407,38 +401,6 @@
                 // ds.setUrl("jdbc:mysql://j2-server/j2");
                 con = ds.getConnection();
             }
-            else if (dsType.equals("sso"))
-            {
-                /*
-                 * For SSO the user has to define the JDBCdriver and 
JdbcConnection (URL) but the credentials for the db come from the SSO storage
-                 */
-                BasicDataSource ds = new BasicDataSource();
-                ds.setDriverClassName(prefs.getValue("SSOJdbcDriver", ""));
-                ds.setUrl(prefs.getValue("SSOJdbcConnection", ""));
-                String ssoURL = prefs.getValue("SSOSite", "");
-                
-                if (sso == null)
-                    throw new SSOException("SSO Not supported.");
-                
-                SSOSite site = sso.getSiteByUrl(ssoURL);
-                if (site != null){
-                    // SSO API lookup
-                    PasswordCredential credentials = null;
-                    JetspeedPrincipal principal = 
userManager.getUser(request.getUserPrincipal().getName());
-                       Collection<SSOUser> remoteUsers = 
sso.getRemoteUsers(site,principal);
-                       if (remoteUsers.size() == 1){
-                               credentials = 
sso.getCredentials(remoteUsers.iterator().next());        
-                       } else {
-                               throw new Exception("SSO credential lookup 
failed.");   
-                       }
-                        
-                    String ssoUserName = credentials.getUserName();
-                    String ssoPWD = credentials.getPassword();
-                    ds.setUsername(ssoUserName);
-                    ds.setPassword(ssoPWD);
-                    con = ds.getConnection();
-                }
-            }
             else
             {
                 throw new SQLException("No DataSource provided");
@@ -780,7 +742,7 @@
         return replacePlaceHolder(query.toString(),request);
     }
     private String replacePlaceHolder(String buffer, PortletRequest request){
-        String userName  = 
((RenderRequest)request).getUserPrincipal().getName();
+        String userName  = request.getUserPrincipal().getName();
         buffer = buffer.replace("$USER", "'" + userName + "'");
         return buffer;
     }


Reply via email to