portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tay...@apache.org
Subject svn commit: r215966 - in /portals/jetspeed-2/branches/MENUS_BRANCH/applications/pam/src/java/org/apache/jetspeed/portlets/site: AbstractPSMLTreePortlet.java PSMLTreeLoader.java SiteBrowserPortlet.java
Date Tue, 12 Jul 2005 15:44:13 GMT
Author: taylor
Date: Tue Jul 12 08:44:11 2005
New Revision: 215966

URL: http://svn.apache.org/viewcvs?rev=215966&view=rev
Log:
cleaned up and enhanced the Admin Site Manager, work still in progress

Added:
    portals/jetspeed-2/branches/MENUS_BRANCH/applications/pam/src/java/org/apache/jetspeed/portlets/site/AbstractPSMLTreePortlet.java
    portals/jetspeed-2/branches/MENUS_BRANCH/applications/pam/src/java/org/apache/jetspeed/portlets/site/PSMLTreeLoader.java
Modified:
    portals/jetspeed-2/branches/MENUS_BRANCH/applications/pam/src/java/org/apache/jetspeed/portlets/site/SiteBrowserPortlet.java

Added: portals/jetspeed-2/branches/MENUS_BRANCH/applications/pam/src/java/org/apache/jetspeed/portlets/site/AbstractPSMLTreePortlet.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/branches/MENUS_BRANCH/applications/pam/src/java/org/apache/jetspeed/portlets/site/AbstractPSMLTreePortlet.java?rev=215966&view=auto
==============================================================================
--- portals/jetspeed-2/branches/MENUS_BRANCH/applications/pam/src/java/org/apache/jetspeed/portlets/site/AbstractPSMLTreePortlet.java
(added)
+++ portals/jetspeed-2/branches/MENUS_BRANCH/applications/pam/src/java/org/apache/jetspeed/portlets/site/AbstractPSMLTreePortlet.java
Tue Jul 12 08:44:11 2005
@@ -0,0 +1,223 @@
+/*
+ * Copyright 2000-2004 The Apache Software Foundation.
+ * 
+ * Licensed 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.jetspeed.portlets.site;
+
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+import java.util.StringTokenizer;
+
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletException;
+
+import org.apache.portals.bridges.common.GenericServletPortlet;
+import org.apache.jetspeed.CommonPortletServices;
+import org.apache.jetspeed.om.folder.Folder;
+import org.apache.jetspeed.om.page.Page;
+import org.apache.jetspeed.page.PageManager;
+
+
+/**
+ * Abstract Tree Portlet
+ * 
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id: $
+ */
+
+public class AbstractPSMLTreePortlet extends GenericServletPortlet
+{    
+    protected PageManager pageManager;
+    protected PSMLTreeLoader loader;
+    /** the PSML Root, i.e "/" or "/_users/joe" **/
+    protected String psmlRoot;
+
+    /** image map for content type **/
+    protected Map imageMap = new HashMap();
+    
+    protected String linkImage;
+    protected String folderImage;
+    protected String documentImage;
+    protected String rootImage;
+    protected String rootLabel;
+    
+    
+    public void init(PortletConfig config) throws PortletException
+    {
+        super.init(config);
+        
+        pageManager = (PageManager) getPortletContext().getAttribute(CommonPortletServices.CPS_PAGE_MANAGER_COMPONENT);
+        if (null == pageManager) { throw new PortletException(
+                "Failed to find the Page Manager on portlet initialization"); }
+        
+        loader = new PSMLTreeLoader(pageManager, this);
+        psmlRoot = config.getInitParameter("psmlRoot");
+        if (psmlRoot == null)
+        {
+            psmlRoot = "/";
+        }
+        
+        // Images        
+        String extensions = config.getInitParameter("extensions");
+        String images = config.getInitParameter("images");
+        linkImage = config.getInitParameter("linkImage");
+        folderImage = config.getInitParameter("folderImage");
+        documentImage = config.getInitParameter("documentImage");
+        rootImage = config.getInitParameter("rootImage");
+        rootLabel = config.getInitParameter("rootLabel");
+
+        if (extensions == null)
+        {
+            extensions = "text/html,text/plain,application/pdf";
+        }
+        if (images == null)
+        {
+            images = "html-document.gif, text-document.gif, pdficon.jpg";
+        }
+        if (linkImage == null)
+        {
+            linkImage = "link.gif";
+        }
+        if (folderImage == null)
+        {
+            folderImage = "folder.gif";
+        }
+        if (documentImage == null)
+        {
+            documentImage = "document.gif";
+        }
+        if (rootImage == null)
+        {
+            rootImage = "root.gif";
+        }
+        if (rootLabel == null)
+        {
+            rootLabel = "Bookshelf";
+        }
+        
+        String[]ext = stringToArray(extensions, ", ");
+        String[]img = stringToArray(images, ", ");
+        int max = (ext.length > img.length) ? img.length : ext.length;
+        for (int ix = 0; ix < max; ix++) 
+        {
+            imageMap.put(ext[ix], img[ix]);
+        }
+    }
+
+    public static final String[] stringToArray(String str, String separators)
+    {
+        StringTokenizer tokenizer;
+        String[] array = null;
+        int count = 0;
+
+        if (str == null)
+            return array;
+
+        if (separators == null)
+            separators = ", ";
+
+        tokenizer = new StringTokenizer(str, separators);
+        if ((count = tokenizer.countTokens()) <= 0) {
+            return array;
+        }
+        
+        array = new String[count];
+        
+        int ix = 0;
+        while (tokenizer.hasMoreTokens()) 
+        {
+            array[ix] = tokenizer.nextToken();
+            ix++;
+        }
+
+        return array;
+    }
+    
+    /**
+     * @return Returns the linkImage.
+     */
+    public String getLinkImage()
+    {
+        return linkImage;
+    }
+    /**
+     * @return Returns the folderImage.
+     */
+    public String getFolderImage(Folder folder)
+    {
+        if (folder.isReserved())
+        {
+            if (folder.getReservedType() == Folder.RESERVED_FOLDER_USERS)
+                return "users.gif";
+            else if (folder.getReservedType() == Folder.RESERVED_FOLDER_ROLES)
+                return "roles.gif";
+            else if (folder.getReservedType() == Folder.RESERVED_FOLDER_GROUPS)
+                return "groups.gif";
+            else if (folder.getReservedType() == Folder.RESERVED_FOLDER_SUBSITES)
+                return "subsites.gif";
+            else
+                return "other.gif";
+        }
+        return folderImage;
+    }
+    
+    public String getImageForContentType(String contentType)
+    {
+        String ct = (String)imageMap.get(contentType);
+        if (ct == null)
+            return documentImage;
+        return ct;
+    }
+    /**
+     * @return Returns the documentImage.
+     */
+    public String getDocumentImage()
+    {
+        return documentImage;
+    }
+    /**
+     * @return Returns the rootImage.
+     */
+    public String getRootImage()
+    {
+        return rootImage;
+    }
+    /**
+     * @return Returns the rootLabel.
+     */
+    public String getRootLabel()
+    {
+        return rootLabel;
+    }
+    
+    public String getFolderTitle(Folder folder, Locale locale)
+    {
+        String title = folder.getTitle(locale);
+        if (title == null)
+            title = folder.getName();
+        return title;
+    }
+    
+    public String getPageTitle(Page page, Locale locale)
+    {
+        String title = page.getTitle(locale);
+        if (title == null)
+        {
+            title = page.getName();
+        }                
+        return title;
+    }
+    
+}

Added: portals/jetspeed-2/branches/MENUS_BRANCH/applications/pam/src/java/org/apache/jetspeed/portlets/site/PSMLTreeLoader.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/branches/MENUS_BRANCH/applications/pam/src/java/org/apache/jetspeed/portlets/site/PSMLTreeLoader.java?rev=215966&view=auto
==============================================================================
--- portals/jetspeed-2/branches/MENUS_BRANCH/applications/pam/src/java/org/apache/jetspeed/portlets/site/PSMLTreeLoader.java
(added)
+++ portals/jetspeed-2/branches/MENUS_BRANCH/applications/pam/src/java/org/apache/jetspeed/portlets/site/PSMLTreeLoader.java
Tue Jul 12 08:44:11 2005
@@ -0,0 +1,205 @@
+/*
+ * Copyright 2000-2004 The Apache Software Foundation.
+ * 
+ * Licensed 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.jetspeed.portlets.site;
+
+
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Locale;
+
+import org.apache.jetspeed.exception.JetspeedException;
+import org.apache.jetspeed.om.folder.Folder;
+import org.apache.jetspeed.om.page.Link;
+import org.apache.jetspeed.om.page.Page;
+import org.apache.jetspeed.page.PageManager;
+import org.apache.jetspeed.page.document.Node;
+import org.apache.jetspeed.page.document.NodeSet;
+import org.apache.jetspeed.portlets.pam.PortletApplicationResources;
+import org.apache.webapp.admin.TreeControlNode;
+
+/**
+ * PSML Tree Loader
+ * Encapsulates the handling of PSML content into a tree view
+ * 
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id: $
+ */
+public class PSMLTreeLoader 
+{
+    public static final String ROOT_DOMAIN = "ROOT_DOMAIN";
+    public static final String FOLDER_DOMAIN = "FOLDER_DOMAIN";
+    public static final String PAGE_DOMAIN = "PAGE_DOMAIN";
+	
+	public final static String PORTLET_URL = "portlet_url";
+		
+    private AbstractPSMLTreePortlet portlet;
+    private PageManager pm;
+        
+    public PSMLTreeLoader(PageManager pm, AbstractPSMLTreePortlet portlet)
+    {
+        this.pm = pm;
+        this.portlet = portlet;
+    }
+    
+    public TreeControlNode createRootNode(Folder folder, Locale locale)
+    {        
+        TreeControlNode root = 
+            new TreeControlNode(folder.getPath(), // unique id 
+                                portlet.getRootImage(), // image                 
+                                folder.getTitle(locale), // label
+                                PortletApplicationResources.PORTLET_URL, // action 
+                                null, // target 
+                                true, // expanded 
+                                "0"); // domain
+                
+        return root;
+    }    
+    
+    public TreeControlNode createFolderNode(Folder folder, Locale locale, String domain)
throws JetspeedException
+    {        
+        TreeControlNode node = 
+            new TreeControlNode(
+                    folder.getPath(), // unique id
+                    portlet.getFolderImage(folder),  // image
+                    portlet.getFolderTitle(folder, locale), // label
+                    PortletApplicationResources.PORTLET_URL, // action 
+                    null, // target
+                    false, // expanded
+                    domain, // domain
+                    "Folder", // CSS
+                    true); // lazy load
+        
+        node.setExpandWhenClicked(true);
+        node.setTitle(folder.getName());
+        node.setLeaf(folder.getAll().isEmpty());
+        
+        return node;
+    }
+    	
+	public TreeControlNode createPageNode(Page page, Locale locale, String domain) 
+    {
+        String title = portlet.getPageTitle(page, locale);
+        
+    	TreeControlNode issueNode = 
+            new TreeControlNode(
+                    page.getPath(), // unique id
+                    portlet.getImageForContentType("text/html"), // image
+                    title,  // label
+                    PortletApplicationResources.PORTLET_URL, // action 
+                    null, // target
+                    false, // expanded
+                    domain, // domain
+					"Document", // css
+					true); // lazy load
+    	
+        issueNode.setTitle(title);        
+    	issueNode.setLeaf(true);
+    	
+    	return issueNode;
+    }
+    
+    public TreeControlNode createLinkNode(Link link, Locale locale, String domain) 
+    {
+    	TreeControlNode linkNode = 
+            new TreeControlNode(
+                    link.getPath(), // unique id
+                    portlet.getLinkImage(), // image 
+                    link.getTitle(locale), // label
+                    PortletApplicationResources.PORTLET_URL, // action
+                    null, // target
+                    false, // expanded
+                    domain, // domain
+					null, // css
+                    true); // lazy load
+        
+        linkNode.setTitle(link.getTitle());        
+        linkNode.setLeaf(true);
+    	
+    	return linkNode;
+    }
+        
+    public void loadChildren(Folder folder, TreeControlNode parent, Locale locale)
+    {
+        NodeSet childFolders = null;
+        NodeSet childPages = null;
+        NodeSet childLinks = null;
+        try
+        {
+            int ilevel = ((new Integer(parent.getDomain()).intValue()) + 1);        
+            String level = Integer.toString(ilevel);
+            
+            childFolders = folder.getFolders();
+            childPages = folder.getPages();
+            childLinks = folder.getLinks();
+
+            if (childFolders != null)
+            {
+                Iterator folderIter = childFolders.iterator();
+                while (folderIter.hasNext())
+                {
+                    Folder childFolder = (Folder) folderIter.next();                
+                    TreeControlNode childNode = createFolderNode(childFolder, locale, level);
+                    parent.addChild(childNode);
+                }
+            }
+            if (childPages != null)
+            {
+                Iterator pagesIter = childPages.iterator();
+                while (pagesIter.hasNext())
+                {
+                    Page childPage = (Page) pagesIter.next();                
+                    TreeControlNode childNode = createPageNode(childPage, locale, level);
+                    parent.addChild(childNode);
+                }
+            }
+            if (childLinks != null)
+            {
+                Iterator linksIter = childLinks.iterator();
+                while (linksIter.hasNext())
+                {
+                    Link childLink = (Link) linksIter.next();                
+                    TreeControlNode childNode = createLinkNode(childLink, locale, level);
+                    parent.addChild(childNode);
+                }
+            }
+            parent.setLoaded(true);
+        }
+        catch (JetspeedException e)
+        {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+            
+    }
+       	
+	public static Comparator psmlComparator = new PSMLObjectComparator();
+	
+	public static Comparator getComparator() 
+    {
+		return psmlComparator;
+	}
+    
+    private static class PSMLObjectComparator implements Comparator
+    {
+        public int compare(Object o1, Object o2)
+        {
+            Node lhs = (Node)o1;
+            Node rhs = (Node)o2;
+            
+            return rhs.getName().compareTo(lhs.getName());
+        }
+    }
+}

Modified: portals/jetspeed-2/branches/MENUS_BRANCH/applications/pam/src/java/org/apache/jetspeed/portlets/site/SiteBrowserPortlet.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/branches/MENUS_BRANCH/applications/pam/src/java/org/apache/jetspeed/portlets/site/SiteBrowserPortlet.java?rev=215966&r1=215965&r2=215966&view=diff
==============================================================================
--- portals/jetspeed-2/branches/MENUS_BRANCH/applications/pam/src/java/org/apache/jetspeed/portlets/site/SiteBrowserPortlet.java
(original)
+++ portals/jetspeed-2/branches/MENUS_BRANCH/applications/pam/src/java/org/apache/jetspeed/portlets/site/SiteBrowserPortlet.java
Tue Jul 12 08:44:11 2005
@@ -16,7 +16,6 @@
 package org.apache.jetspeed.portlets.site;
 
 import java.io.IOException;
-import java.util.Iterator;
 import java.util.Locale;
 
 import javax.portlet.ActionRequest;
@@ -27,17 +26,12 @@
 import javax.portlet.RenderRequest;
 import javax.portlet.RenderResponse;
 
-import org.apache.jetspeed.CommonPortletServices;
+import org.apache.jetspeed.exception.JetspeedException;
 import org.apache.jetspeed.om.folder.Folder;
 import org.apache.jetspeed.om.folder.FolderNotFoundException;
 import org.apache.jetspeed.om.folder.InvalidFolderException;
-import org.apache.jetspeed.om.page.Page;
-import org.apache.jetspeed.page.PageManager;
-import org.apache.jetspeed.page.document.DocumentException;
 import org.apache.jetspeed.page.document.NodeException;
-import org.apache.jetspeed.page.document.NodeSet;
 import org.apache.jetspeed.portlets.pam.PortletApplicationResources;
-import org.apache.portals.bridges.common.GenericServletPortlet;
 import org.apache.portals.messaging.PortletMessaging;
 import org.apache.webapp.admin.TreeControl;
 import org.apache.webapp.admin.TreeControlNode;
@@ -47,35 +41,40 @@
  * pages and folders.
  * 
  * @author <a href="mailto:jford@apache.com">Jeremy Ford </a>
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
  * @version $Id$
  */
-public class SiteBrowserPortlet extends GenericServletPortlet
+public class SiteBrowserPortlet extends AbstractPSMLTreePortlet
 {
-
     private PortletContext context;
-
-    private PageManager pageManager;
+    private static final String SITE_TREE_ATTRIBUTE = "site-tree";
 
     public void init(PortletConfig config) throws PortletException
     {
         super.init(config);
         context = getPortletContext();
-        pageManager = (PageManager) context.getAttribute(CommonPortletServices.CPS_PAGE_MANAGER_COMPONENT);
-        if (null == pageManager) { throw new PortletException(
-                "Failed to find the Page Manager on portlet initialization"); }
     }
 
     public void doView(RenderRequest request, RenderResponse response) throws PortletException,
IOException
     {
         response.setContentType("text/html");
 
-        TreeControl control = (TreeControl) request.getPortletSession().getAttribute("j2_tree");
+        TreeControl control = prepareSiteTree(request);
+        request.setAttribute(SITE_TREE_ATTRIBUTE, control);
+
+        super.doView(request, response);
+
+    }
+
+    private TreeControl prepareSiteTree(RenderRequest request)
+    {
+        TreeControl control = (TreeControl) request.getPortletSession().getAttribute(SITE_TREE_ATTRIBUTE);
         if (control == null)
         {
             Folder root = null;
             try
             {
-                root = pageManager.getFolder("/");
+                root = pageManager.getFolder(psmlRoot);
             }
             catch (FolderNotFoundException e)
             {
@@ -96,19 +95,16 @@
             if (root != null)
             {
                 control = buildTree(root, request.getLocale());
-                request.getPortletSession().setAttribute("j2_tree", control);
+                request.getPortletSession().setAttribute(SITE_TREE_ATTRIBUTE, control);
             }
         }
-        request.setAttribute("j2_tree", control);
-
-        super.doView(request, response);
-
+        return control;
     }
-
+    
     public void processAction(ActionRequest actionRequest, ActionResponse actionResponse)
throws PortletException,
             IOException
     {
-        TreeControl control = (TreeControl) actionRequest.getPortletSession().getAttribute("j2_tree");
+        TreeControl control = (TreeControl) actionRequest.getPortletSession().getAttribute(SITE_TREE_ATTRIBUTE);
         //assert control != null
         if (control != null)
         {
@@ -116,10 +112,39 @@
             if (node != null)
             {
                 TreeControlNode controlNode = control.findNode(node);
-                if (controlNode != null)
+                if (controlNode != null && controlNode.isLazy() && !controlNode.isLoaded())

+                {
+                    //loader.loadChildren(actionRequest, controlNode, refToURIMap);
+                    String domain = controlNode.getDomain();
+                    //if (domain.equals(PSMLTreeLoader.FOLDER_DOMAIN))
+                    {
+                        try
+                        {
+                            Folder folder = pageManager.getFolder(controlNode.getName());
+                            loader.loadChildren(folder, controlNode, actionRequest.getLocale());
+                        }
+                        catch (JetspeedException e)
+                        {
+                            e.printStackTrace();
+                        }
+                    }
+                }
+                controlNode.setExpanded(!controlNode.isExpanded());
+                //actionRequest.getPortletSession().setAttribute("tree_anchor", node);
+                
+                if(controlNode.isExpanded() && controlNode != control.getRoot())
                 {
-                    controlNode.setExpanded(!controlNode.isExpanded());
+                    TreeControlNode[] siblings = controlNode.getParent().findChildren();
+                    for(int i=0; i<siblings.length; i++)
+                    {
+                        TreeControlNode sibling = siblings[i];
+                        if(sibling != controlNode)
+                        {
+                            sibling.setExpanded(false);
+                        }
+                    }
                 }
+                
             }
 
             String selectedNode = actionRequest.getParameter(PortletApplicationResources.REQUEST_SELECT_NODE);
@@ -172,74 +197,13 @@
     private TreeControl buildTree(Folder folder, Locale locale)
     {
 
-        TreeControlNode root = new TreeControlNode(folder.getName(), null, folder.getTitle(locale),
-                PortletApplicationResources.PORTLET_URL, null, true, "FOLDER_DOMAIN");
-
+        TreeControlNode root = loader.createRootNode(folder, locale);
+        
         TreeControl control = new TreeControl(root);
-
-        buildFolderNodes(folder, root, locale);
+        loader.loadChildren(folder, root, locale);
 
         return control;
     }
 
-    private void buildFolderNodes(Folder folder, TreeControlNode parent, Locale locale)
-    {
-        NodeSet childFolders = null;
-        try
-        {
-            childFolders = folder.getFolders();
-        }
-        catch (FolderNotFoundException e)
-        {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-        }
-        catch (DocumentException e)
-        {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-        }
-
-        if (childFolders != null)
-        {
-            Iterator folderIter = childFolders.iterator();
-            while (folderIter.hasNext())
-            {
-                Folder childFolder = (Folder) folderIter.next();                
-                TreeControlNode childNode = new TreeControlNode(childFolder.getPath(), null,
childFolder
-                        .getTitle(locale), PortletApplicationResources.PORTLET_URL, null,
false, "FOLDER_DOMAIN");
-                parent.addChild(childNode);
-                buildFolderNodes(childFolder, childNode, locale);
-            }
-
-            buildPageNodes(folder, parent, locale);
-        }
-    }
 
-    private void buildPageNodes(Folder folder, TreeControlNode node, Locale locale)
-    {
-        NodeSet pages = null;
-        try
-        {
-            pages = folder.getPages();
-        }
-        catch (NodeException e)
-        {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-        }
-
-        if (pages != null)
-        {
-            Iterator pageIter = pages.iterator();
-
-            while (pageIter.hasNext())
-            {
-                Page page = (Page) pageIter.next();
-                TreeControlNode child = new TreeControlNode(page.getPath(), null, page.getTitle(locale),
-                        PortletApplicationResources.PORTLET_URL, null, false, "PAGE_DOMAIN");
-                node.addChild(child);
-            }
-        }
-    }
 }



---------------------------------------------------------------------
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