portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wea...@apache.org
Subject svn commit: r190427 - in /portals/jetspeed-2/trunk/applications/pam/src: java/org/apache/jetspeed/portlets/entityeditor/ webapp/WEB-INF/view/pemp/ webapp/javascript/
Date Mon, 13 Jun 2005 16:49:52 GMT
Author: weaver
Date: Mon Jun 13 09:49:51 2005
New Revision: 190427

URL: http://svn.apache.org/viewcvs?rev=190427&view=rev
Log:
JS2-283:  A portlet entity preference editor written using Ajax approach.  
It's not the next killer app, but it gives a good example of how to use 
Ajax services in J2.

Added:
    portals/jetspeed-2/trunk/applications/pam/src/java/org/apache/jetspeed/portlets/entityeditor/PortletEntityBrowserPortlet.java
    portals/jetspeed-2/trunk/applications/pam/src/java/org/apache/jetspeed/portlets/entityeditor/PortletEntityEditorPortlet.java
    portals/jetspeed-2/trunk/applications/pam/src/webapp/WEB-INF/view/pemp/browser_view.vm
    portals/jetspeed-2/trunk/applications/pam/src/webapp/WEB-INF/view/pemp/editor_view.vm
    portals/jetspeed-2/trunk/applications/pam/src/webapp/javascript/ajax.js

Added: portals/jetspeed-2/trunk/applications/pam/src/java/org/apache/jetspeed/portlets/entityeditor/PortletEntityBrowserPortlet.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/applications/pam/src/java/org/apache/jetspeed/portlets/entityeditor/PortletEntityBrowserPortlet.java?rev=190427&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/applications/pam/src/java/org/apache/jetspeed/portlets/entityeditor/PortletEntityBrowserPortlet.java
(added)
+++ portals/jetspeed-2/trunk/applications/pam/src/java/org/apache/jetspeed/portlets/entityeditor/PortletEntityBrowserPortlet.java
Mon Jun 13 09:49:51 2005
@@ -0,0 +1,113 @@
+package org.apache.jetspeed.portlets.entityeditor;
+
+import java.io.IOException;
+import java.util.Collection;
+
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletContext;
+import javax.portlet.PortletException;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+
+import org.apache.jetspeed.CommonPortletServices;
+import org.apache.jetspeed.components.portletentity.PortletEntityAccessComponent;
+import org.apache.jetspeed.components.portletentity.PortletEntityNotStoredException;
+import org.apache.jetspeed.components.portletregistry.PortletRegistry;
+import org.apache.pluto.om.entity.PortletEntity;
+import org.apache.pluto.om.portlet.PortletDefinition;
+import org.apache.portals.bridges.velocity.GenericVelocityPortlet;
+import org.apache.velocity.context.Context;
+
+public class PortletEntityBrowserPortlet extends GenericVelocityPortlet
+{
+
+    private PortletEntityAccessComponent entityAccess;
+    private PortletRegistry registry;
+    
+
+     /* (non-Javadoc)
+     * @see org.apache.portals.bridges.velocity.GenericVelocityPortlet#init(javax.portlet.PortletConfig)
+     */
+    public void init(PortletConfig config) throws PortletException
+    {
+        super.init(config);
+        PortletContext context = getPortletContext();
+        entityAccess = (PortletEntityAccessComponent)context.getAttribute(CommonPortletServices.CPS_ENTITY_ACCESS_COMPONENT);
+        registry = (PortletRegistry)context.getAttribute(CommonPortletServices.CPS_REGISTRY_COMPONENT);
+    }
+
+    public void doView(RenderRequest request, RenderResponse response) throws PortletException,
IOException
+    {
+        Collection portletApps = registry.getPortletApplications();
+        Context context = getContext(request);
+        context.put("portletApps", portletApps);
+        context.put("entityAccess", entityAccess);
+        context.put("portletContext", getPortletContext());
+        super.doView(request, response);
+    }
+    
+    protected final void doCreate(ActionRequest request, ActionResponse response) throws
PortletException
+    {
+        try
+        {
+            PortletDefinition pd = getPortletDefintion(request);
+            String newId = request.getParameter("newEntityId");
+            PortletEntity entity = null;
+            
+            if(newId != null)
+            {
+                entity = entityAccess.newPortletEntityInstance(pd, newId);
+            }
+            else
+            {
+                entity = entityAccess.newPortletEntityInstance(pd);
+            }
+            
+            entityAccess.storePortletEntity(entity);
+        }
+        catch (PortletEntityNotStoredException e)
+        {
+            throw new PortletException(e.getMessage(), e);
+        }
+        catch (PortletException e)
+        {
+            throw new PortletException(e.getMessage(), e);
+        }
+    }
+    
+    protected final PortletDefinition getPortletDefintion(ActionRequest request) throws PortletException
+    {
+        String portletUniqueName = request.getParameter("selectedPortlet");
+        if(portletUniqueName == null)
+        {
+            throw new PortletException("There was no 'portletUniqueName' parameter specified
in the request.");
+        }
+        else
+        {
+           return registry.getPortletDefinitionByUniqueName(portletUniqueName);         
  
+        }
+    }
+    
+    public void processAction(ActionRequest request, ActionResponse actionResponse) throws
PortletException, IOException
+    {
+        String action = request.getParameter("action");
+        
+        if(action == null)
+        {
+            throw new PortletException("Requires that action either be 'edit' or 'create'");
+        }
+        else if(action.equals("create"))
+        {
+            doCreate(request, actionResponse);
+        }
+        else
+        {
+            throw new PortletException("Requires that action to be 'create'");
+        }
+    }
+    
+    
+
+}

Added: portals/jetspeed-2/trunk/applications/pam/src/java/org/apache/jetspeed/portlets/entityeditor/PortletEntityEditorPortlet.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/applications/pam/src/java/org/apache/jetspeed/portlets/entityeditor/PortletEntityEditorPortlet.java?rev=190427&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/applications/pam/src/java/org/apache/jetspeed/portlets/entityeditor/PortletEntityEditorPortlet.java
(added)
+++ portals/jetspeed-2/trunk/applications/pam/src/java/org/apache/jetspeed/portlets/entityeditor/PortletEntityEditorPortlet.java
Mon Jun 13 09:49:51 2005
@@ -0,0 +1,162 @@
+package org.apache.jetspeed.portlets.entityeditor;
+
+import java.io.IOException;
+import java.util.Arrays;
+
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletContext;
+import javax.portlet.PortletException;
+
+import org.apache.jetspeed.CommonPortletServices;
+import org.apache.jetspeed.components.portletentity.PortletEntityAccessComponent;
+import org.apache.jetspeed.components.portletentity.PortletEntityNotStoredException;
+import org.apache.jetspeed.components.portletregistry.PortletRegistry;
+import org.apache.jetspeed.om.common.preference.PreferenceComposite;
+import org.apache.jetspeed.om.common.preference.PreferenceSetComposite;
+import org.apache.pluto.om.entity.PortletEntity;
+import org.apache.portals.bridges.velocity.GenericVelocityPortlet;
+
+public class PortletEntityEditorPortlet extends GenericVelocityPortlet
+{
+    
+    private PortletEntityAccessComponent entityAccess;
+    private PortletRegistry registry;
+
+    /* (non-Javadoc)
+     * @see org.apache.portals.bridges.velocity.GenericVelocityPortlet#init(javax.portlet.PortletConfig)
+     */
+    public void init(PortletConfig config) throws PortletException
+    {
+        super.init(config);
+        PortletContext context = getPortletContext();
+        entityAccess = (PortletEntityAccessComponent)context.getAttribute(CommonPortletServices.CPS_ENTITY_ACCESS_COMPONENT);
+        registry = (PortletRegistry)context.getAttribute(CommonPortletServices.CPS_REGISTRY_COMPONENT);
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.portals.bridges.velocity.GenericVelocityPortlet#processAction(javax.portlet.ActionRequest,
javax.portlet.ActionResponse)
+     */
+    public void processAction(ActionRequest request, ActionResponse response) throws PortletException,
IOException
+    {
+        String action = request.getParameter("action");
+        
+        if(action == null)
+        {
+            throw new PortletException("This editor requires an action parameter");
+        }
+        else if(action.equals("updateValue"))
+        {
+            doUpdateValue(request, response);
+        }
+        else if(action.equals("addValue"))
+        {
+            doAddValue(request, response);
+        }
+        else if(action.equals("removeValue"))
+        {
+            doRemoveValue(request, response);
+        }
+        else if(action.equals("addPref"))
+        {
+            doAddPref(request, response);
+        }
+        else if(action.equals("removePref"))
+        {
+            doRemovePref(request, response);
+        }
+        else
+        {
+            throw new PortletException("'"+action+"' is not a valid editor action.");
+        }
+    }
+    
+    protected final void doAddPref(ActionRequest request, ActionResponse response) throws
PortletException
+    {
+        PortletEntity entity = getPortletEntity(request);
+        String newName = request.getParameter("newPreferenceName");
+        if(newName == null || newName.length() < 1)
+        {
+            throw new PortletException("You must specify a name for a new preference.");
+        }
+        
+        String[] newValues = request.getParameterValues("newPreferenceValue");
+        if(newValues == null || newValues.length == 0)
+        {
+            throw new PortletException("You must specfiy a value for the new preference "+newName);
+        }
+        
+        PreferenceSetComposite prefSet = (PreferenceSetComposite) entity.getPreferenceSet();
+        prefSet.add(newName, Arrays.asList(newValues));
+        try
+        {
+            entityAccess.storePortletEntity(entity);
+        }
+        catch (PortletEntityNotStoredException e)
+        {
+            throw new PortletException(e.getMessage(), e);
+        }
+    }
+    
+    protected final void doAddValue(ActionRequest request, ActionResponse response) throws
PortletException
+    {
+        PortletEntity entity = getPortletEntity(request);
+        String prefString= request.getParameter("selectedPref");
+        String newValue = request.getParameter("newPrefValue");
+        String prefName = prefString.split("::")[1];
+        PreferenceComposite pref = (PreferenceComposite) entity.getPreferenceSet().get(prefName);
+        pref.addValue(newValue);
+    }
+    
+    protected final void doRemovePref(ActionRequest request, ActionResponse response) throws
PortletException
+    {
+        PortletEntity entity = getPortletEntity(request);
+        String prefString= request.getParameter("selectedPref");
+        String prefName = prefString.split("::")[1];
+        ((PreferenceSetComposite)entity.getPreferenceSet()).remove(prefName);
+        
+    }
+    
+    protected final void doUpdateValue(ActionRequest request, ActionResponse response) throws
PortletException
+    {
+        PortletEntity entity = getPortletEntity(request);
+        String prefString= request.getParameter("selectedPref");
+        String updatedValue = request.getParameter("selectedPrefValue");
+        if(updatedValue.trim().length() == 0)
+        {
+            throw new PortletException("Preference values cannot be empty.");
+        }
+        String[] info = prefString.split("::");
+        String prefName = info[1];
+        int valueIndex = Integer.parseInt(info[2]);
+        PreferenceComposite pref = (PreferenceComposite) entity.getPreferenceSet().get(prefName);
+        pref.setValueAt(valueIndex, updatedValue);
+    }
+    
+    protected final void doRemoveValue(ActionRequest request, ActionResponse response) throws
PortletException
+    {
+        PortletEntity entity = getPortletEntity(request);
+        String prefString= request.getParameter("selectedPref");
+        String updatedValue = request.getParameter("selectedPrefValue");
+        String[] info = prefString.split("::");
+        String prefName = info[1];
+        int valueIndex = Integer.parseInt(info[2]);
+        PreferenceComposite pref = (PreferenceComposite) entity.getPreferenceSet().get(prefName);
+        pref.removeValueAt(valueIndex);
+    }
+
+    
+    protected final PortletEntity getPortletEntity(ActionRequest request) throws PortletException
+    {
+        String entityId = request.getParameter("portletEntityId");
+        if(entityId == null)
+        {
+            throw new PortletException("There was no 'entityId' parameter specified in the
request.");
+        }
+        else
+        {
+           return entityAccess.getPortletEntity(entityId);            
+        }
+    }
+}

Added: portals/jetspeed-2/trunk/applications/pam/src/webapp/WEB-INF/view/pemp/browser_view.vm
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/applications/pam/src/webapp/WEB-INF/view/pemp/browser_view.vm?rev=190427&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/applications/pam/src/webapp/WEB-INF/view/pemp/browser_view.vm
(added)
+++ portals/jetspeed-2/trunk/applications/pam/src/webapp/WEB-INF/view/pemp/browser_view.vm
Mon Jun 13 09:49:51 2005
@@ -0,0 +1,106 @@
+#set($locale = $request.locale)
+
+<script language="javascript" src="${request.contextPath}/javascript/ajax.js"></script>
+
+<script language="javascript">
+
+var currentApp;
+
+
+function Portlet(portletId, title)
+{
+  this.portletId = portletId;
+  this.title = title;
+  this.asOption = new Option("("+this.portletId+") "+this.title , this.portletId);
+  this.portletEntites = new Array();
+}
+
+function onAppSelected(app)
+{
+  hide("PortletEntityEditor");
+  currentApp = app;
+  var sList = document.getElementById("selectedPortlet");
+
+  //Clear out all old options
+  var optsLen = sList.options.length;
+
+  for(i=0; i<optsLen; i++)
+  {
+     sList.remove(0);
+  }
+  
+  //add in new options
+  new PortletDefinitionLoader("selectedPortlet").load(app);
+  
+  hide("selectEntityBlock,createEntityButton");
+  show("selectPortletBlock");
+}
+
+function onPortletSelected(portlet)
+{
+  hide("PortletEntityEditor");
+  var sList = document.getElementById("selectedEntity"); 
+
+  //Clear out all old options
+  var optsLen = sList.options.length;
+
+  for(i=0; i<optsLen; i++)
+  {
+     sList.remove(0);
+  }
+  
+  //add in new options
+  PortletEntityLoader
+  entityLoader = new PortletEntityLoader("selectedEntity", "selectEntityBlock");
+  entityLoader.load(portlet);
+  
+  show("createEntityButton");
+}
+
+function onEntitySelected(entity)
+{
+  var editButton = document.getElementById("editEntityButton");
+  var entityAccess = new InitEntityEditor("portletEntityId", "selectedPref", "entityIdLabel");
+  entityAccess.load(entity);  
+  show("PortletEntityEditor");
+}
+
+
+</script>
+
+
+#set($createUrl = $renderResponse.createActionURL())
+$!createUrl.setParameter("action", "create")
+
+<form name="appSelection" method="post" action="${createUrl}">
+
+<h2 class="portlet-section-header">Portlet Entity Browser</h2>
+
+<h3 class="portlet-section-subheader">Choose a Portlet Application...</h3>
+
+<select id="portletApp" name="portletApp" style="width:350px;" size="6" onChange="onAppSelected(this.options[this.selectedIndex].value);">
+
+</select>
+
+<div id="selectPortletBlock" style="display:none">
+  <h3 class="portlet-section-subheader">Choose a Portlet...</h3>
+
+  <select class="portlet-form-field-label" id="selectedPortlet" name="selectedPortlet"
style="width:350px;" size="6"  onChange="onPortletSelected(this.options[this.selectedIndex].value)">
+  </select>
+  <br />
+  <input type="submit" class="portlet-form-button" id="createEntityButton" name="createEntityButton"
style="display:none" value="Create New Portlet Enitity"/>
+</div>
+
+<div id="selectEntityBlock" style="display:none">	
+  <h3 class="portlet-section-subheader">Choose a Portlet Entity to Edit...</h3>
+  <select class="portlet-form-field-label" id="selectedEntity" name="selectedEntity" style="width:350px;"
size="6" onChange="onEntitySelected(this.options[this.selectedIndex].value)"></select>
+  <br />
+  <input type="button" class="portlet-form-button" id="editEntityButton" name="editEntityButton"
style="display:none" value="Edit Portlet Enitity"/>
+</div>
+
+</form>
+
+<script>
+new PortletAppLoader("portletApp");
+
+</script>
\ No newline at end of file

Added: portals/jetspeed-2/trunk/applications/pam/src/webapp/WEB-INF/view/pemp/editor_view.vm
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/applications/pam/src/webapp/WEB-INF/view/pemp/editor_view.vm?rev=190427&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/applications/pam/src/webapp/WEB-INF/view/pemp/editor_view.vm
(added)
+++ portals/jetspeed-2/trunk/applications/pam/src/webapp/WEB-INF/view/pemp/editor_view.vm
Mon Jun 13 09:49:51 2005
@@ -0,0 +1,77 @@
+<script language="javascript">
+
+function onPrefEntrySelected(selectedOption)
+{
+   var sVal = selectedOption.value.split("::");
+   if(sVal[0] == "prefvalue")
+   {
+     document.getElementById("addPrefValueBlock").style.display="none";
+     document.getElementById("editPrefValueBlock").style.display="inline";
+	 document.getElementById("selectedPrefValue").value=sVal[3];
+   }
+   else if(sVal[0] == "pref")
+   {     
+	 document.getElementById("addPrefValueBlock").style.display="inline";
+	 document.getElementById("editPrefValueBlock").style.display="none"
+   }
+   else
+   {
+     document.getElementById("editPrefValueBlock").style.display="none"
+	 document.getElementById("addPrefValueBlock").style.display="none";
+   }
+
+}
+
+function onRemovePref()
+{
+   if(confirm("Are you sure you want to delete this preference?"))
+   {
+     getElement('EditFormAction').value='removePref';
+	 return true;
+   }
+   else
+   {
+     return false;
+   }
+}
+
+</script>
+
+#set($url = $renderResponse.createActionURL())
+
+<div id="PortletEntityEditor" style="display:none">
+   <p>
+	 <span style="font-weight: bold">You are Editing Entity: </span><span id="entityIdLabel"></span>
    
+   </p>
+   <form name="EditForm" method="POST" action="${url}">
+	  <input type="hidden" id="EditFormAction" name="action" />
+	  <input type="hidden" id="portletEntityId" name="portletEntityId" />
+      <h2 class="portlet-section-subheader">Add New Preference</h2>
+      Name: <input class="portlet-form-field-label" type="text" id="newPreferenceName"
name="newPreferenceName" onKeyUp="enableIfComplete('newPreferenceName,newPreferenceValue',
'addPrefButton');" />
+      <br/>
+      Value: <input class="portlet-form-field-label" type="text" id="newPreferenceValue"
name="newPreferenceValue" onKeyUp="enableIfComplete('newPreferenceName,newPreferenceValue',
'addPrefButton');" />
+      <br/>
+      <input type="Submit" value="Done" class="portlet-form-button" id="addPrefButton"
style="display:none;" onClick="this.form.elements['action'].value='addPref'"/>
+	  
+	  <h2 class="portlet-section-subheader">Update Existing Prefences</h2>
+	  <select size="4" class="portlet-form-field-label" name="selectedPref" id="selectedPref"
style="width:350px;" onChange="onPrefEntrySelected(this.options[this.selectedIndex]);"></select>

+  	
+   
+     <div id="editPrefValueBlock" style="display:none">
+	  <p>
+	    <input type="text" class="portlet-form-field-label" name="selectedPrefValue" id="selectedPrefValue"
onKeyUp="enableIfComplete('selectedPrefValue', 'updatePrefValueButton');"/> 
+	    <input type="submit" id="updatePrefValueButton" value="Update Value" class="portlet-form-button"
onClick="this.form.elements['action'].value='updateValue'" />
+	    <input type="submit" value="Remove Value" class="portlet-form-button" onClick="this.form.elements['action'].value='removeValue'"
/>
+	  </p>
+     </div>
+	 
+	 <div id="addPrefValueBlock" style="display:none">
+	  <p>
+	    <span style="font-weight: bold">New Value:</span>
+		<input type="text" class="portlet-form-field-label" name="newPrefValue" id="newPrefValue"
onKeyUp="enableIfComplete('newPrefValue', 'addValueButton');"/> 
+	    <input type="submit" class="portlet-form-button" id="addValueButton" value="Add Value"
style="display:none;" onClick="this.form.elements['action'].value='addValue'"  />
+		<input type="submit" class="portlet-form-button" id="removePrefButton" value="Remove
Preference "  onClick="return onRemovePref();"  />
+	  </p>
+     </div>
+   </form>
+</div>
\ No newline at end of file

Added: portals/jetspeed-2/trunk/applications/pam/src/webapp/javascript/ajax.js
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/applications/pam/src/webapp/javascript/ajax.js?rev=190427&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/applications/pam/src/webapp/javascript/ajax.js (added)
+++ portals/jetspeed-2/trunk/applications/pam/src/webapp/javascript/ajax.js Mon Jun 13 09:49:51
2005
@@ -0,0 +1,341 @@
+/**
+ * Browser independent XMLHttpRequestLoader
+ */
+function XMLHttpRequestCaller(url, caller)
+{    
+  this.url = url;
+  this.caller = caller;
+
+	this.serviceRequest = function()
+	{
+	  // branch for native XMLHttpRequest object
+	  var _caller = this.caller;
+	  var _url = this.url;
+	  
+      xmlRequest = getHTTPObject();
+      xmlRequest.onreadystatechange = function()
+      {
+         if (xmlRequest.readyState == 4)
+         {
+          // only if "OK"
+          if (xmlRequest.status == 200)
+          {
+             _caller.invoke(xmlRequest);
+          }
+          else
+          {
+            alert("There was a problem retrieving the XML data:\n" + xmlRequest.statusText
+ 
+            " for url: \n" + _url);
+          }
+        }
+	  };
+	      
+      xmlRequest.open("GET", _url, true);
+	  xmlRequest.send(null);	
+	}
+}
+
+
+function PortletAppLoader(elementId)
+{
+
+  
+  this.invoke = function(xmlRequest)
+  {
+   
+     response  = xmlRequest.responseXML.documentElement;
+     portletApps = response.getElementsByTagName('portletApp');
+     list = document.getElementById(elementId);
+     for(i=0; i<portletApps.length; i++)
+     {         
+        name  = new EZDom(portletApps[i]).getChildValue('name');
+        list.options[i] = new Option(name, name);
+     }
+  }
+  
+  var requestCaller = new XMLHttpRequestCaller("/jetspeed/ajax/portlet_apps.ajax?ajax_service=portletRegistry.getPortletApplications"
,this); 
+  requestCaller.serviceRequest();
+}
+
+function PortletDefinitionLoader(elementId)
+{ 
+
+  this.appName;
+   
+  this.invoke = function(xmlRequest)
+  {
+   
+     response  = xmlRequest.responseXML.documentElement;
+     portletDefs = response.getElementsByTagName('portletDefinition');
+     list = document.getElementById(elementId);
+     for(i=0; i<portletDefs.length; i++)
+     {         
+        name  = new EZDom(portletDefs[i]).getChildValue('name');
+        list.options[i] = new Option(name, this.appName+"::"+name);
+     }
+  }
+  
+  this.load = function(appName)
+  {
+     this.appName = appName;
+     var requestCaller = new XMLHttpRequestCaller("/jetspeed/ajax/portlet_definitions.ajax?ajax_service=portletRegistry.getPortletApplication&ajax_param_0_str="+appName
,this); 
+     requestCaller.serviceRequest();
+  }
+}
+
+function PortletEntityLoader(elementId, blockId)
+{
+   
+  this.invoke = function(xmlRequest)
+  {   
+     response  = xmlRequest.responseXML.documentElement;
+     portletEntities = response.getElementsByTagName('portletEntity');
+     list = document.getElementById(elementId);
+     hasEntities=false;
+     for(i=0; i<portletEntities.length; i++)
+     {         
+        id  = new EZDom(portletEntities[i]).getChildValue('id');
+        list.options[i] = new Option(id, id);
+        hasEntities = true;
+     }
+     
+      if(hasEntities && blockId)
+      {
+        show(blockId);
+      }
+      else if( blockId )
+      {
+        hide(blockId);
+      }
+  }
+  
+  this.load = function(portletName)
+  {
+      var requestCaller = new XMLHttpRequestCaller("/jetspeed/ajax/portlet_entities.ajax?ajax_service=entityAccess.getPortletEntities&ajax_param_0_str="+portletName
,this); 
+      requestCaller.serviceRequest();
+  }
+}
+
+function InitEntityEditor(nameId, prefListId, labelId)
+{
+   this.nameId = nameId;
+   this.prefListId = prefListId;
+   this.labelId = labelId;
+   
+  this.invoke = function(xmlRequest)
+  {   
+     var portletEntity  = new PortletEntity(xmlRequest.responseXML.documentElement);
+     var nameElem = getElement(this.nameId);
+     nameElem.value = portletEntity.getId();
+     var list = getElement(this.prefListId);
+     var prefs = portletEntity.getPreferences();
+     var indent = String.fromCharCode(160, 160, 160, 160);
+     var cIndex = 0;
+     clearList(list);
+     for(var i=0; i<prefs.length; i++)
+     {
+        var pref = prefs[i];        
+        
+        list.options[cIndex] = new Option(pref.getName(), "pref::"+pref.getName());
+        
+        cIndex++;
+        list.options[cIndex] = new Option(indent+" ------------------------- Values for "+pref.getName()+"
-------------------------");
+        
+        var values = pref.getValues();
+        for(j=0; j<values.length; j++)
+        {
+          ++cIndex;
+          list.options[cIndex] = new Option(indent+values[j], "prefvalue::"+pref.getName()+"::"+j+"::"+values[j]);
+        }
+        
+        ++cIndex;
+        
+     }     
+     
+     setHTML(this.labelId, portletEntity.getId());     
+  }
+  
+  this.load = function(entityName)
+  {
+      var requestCaller = new XMLHttpRequestCaller("/jetspeed/ajax/portlet_entity.ajax?ajax_service=entityAccess.getPortletEntity&ajax_param_0_str="+entityName,this);

+      requestCaller.serviceRequest();
+  }
+
+
+}
+
+function EZDom(anElement)
+{
+  this.anElement = anElement;
+  
+  this.getChildValue = function(name)
+  {
+    return this.anElement.getElementsByTagName(name)[0].firstChild.data;
+  }
+}
+
+function PortletEntity(element)
+{
+  this.parentClass = EZDom;
+  this.parentClass(element);
+  this.prefs = new Array();
+  
+  var prefElements = element.getElementsByTagName('preference');
+  for(i=0; i<prefElements.length; i++)
+  {
+     this.prefs[i] = new Preference(prefElements[i]);
+  }  
+  
+  this.getId = function()
+  {
+     return this.getChildValue('id');
+  }
+  
+  this.getPreferences = function()
+  {
+     return this.prefs;
+  }
+}
+
+function Preference(element)
+{
+  this.parentClass = EZDom;
+  this.parentClass(element);
+  
+  this.getName = function()
+  {
+    return this.getChildValue('name');
+  }
+  
+  this.getValues = function()
+  {
+     var valueElements = this.anElement.getElementsByTagName('value');
+     var values = new Array(valueElements.length);
+     for(i=0; i<valueElements.length; i++)
+     {
+       values[i] = valueElements[i].firstChild.data;
+     }
+     return values;
+  }    
+}
+
+  
+  
+function clearList(selectList)
+{
+   for(i=0; i<selectList.length; i++)
+   {
+     selectList.options[i] = null;     
+   }
+}
+
+function hide(elementIds)
+{
+   var elementArrayId = elementIds.split(",");
+   for(i=0; i<elementArrayId.length; i++)
+   {
+       getElement(elementArrayId[i]).style.display="none";
+   }
+}
+
+function show(elementIds)
+{
+   var elementArrayId = elementIds.split(",");
+   for(i=0; i<elementArrayId.length; i++)
+   {
+       getElement(elementArrayId[i]).style.display="inline";
+   }
+}
+
+function getElement(eid)
+{
+   return document.getElementById(eid);
+}
+
+function setHTML(eid, htmlValue)
+{
+  getElement(eid).innerHTML = htmlValue;
+}
+
+function enableIfComplete(valuesToCheck, elementsToShow)
+{
+  var checkArray = valuesToCheck.split(",");
+  var ok = false;
+  for(i=0; i<checkArray.length; i++)
+  {
+     var checkValue = getElement(checkArray[i]).value;
+     if(checkValue.length > 0  && isNotWhiteSpace(checkValue))
+     {
+        ok = true;
+     }
+     else
+     {
+        ok = false;
+        break;
+     }
+     
+  }
+  
+  var enableArray = elementsToShow.split(",");
+  for(i=0; i<enableArray.length; i++)
+  {
+     if(ok)
+     {
+     	getElement(enableArray[i]).style.display="inline";
+     }
+     else
+     {
+        getElement(enableArray[i]).style.display="none";
+     }
+  }
+}
+
+function isNotWhiteSpace(value)
+{
+   var regex = /^\s*$/i;
+   return !regex.test(value);
+}
+
+function trim(value)
+{
+  return value.replace(/^(\s+)?(.*\S)(\s+)?$/, '$2')
+}
+
+
+/** Cross browser XMLHttpObject creator */
+function getHTTPObject() 
+{
+  var xmlhttp;
+  /*@cc_on
+  @if (@_jscript_version >= 5)
+    try 
+    {
+      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
+    } catch (e) 
+    {
+      try 
+      {
+        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
+      } 
+      catch (E) 
+      {
+        xmlhttp = false;
+      }
+    }
+  @else
+  xmlhttp = false;
+  @end @*/
+  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
+    try 
+    {
+      xmlhttp = new XMLHttpRequest();
+    } 
+    catch (e) 
+    {
+      xmlhttp = false;
+    }
+  }
+  return xmlhttp;
+}
+
+



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message