incubator-graffito-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tay...@apache.org
Subject svn commit: r161231 - in incubator/graffito/trunk/applications/graffito-portlets/src/java/org/apache/portals/graffito/portlets: AbstractGraffitoPortlet.java SearchPortlet.java TreePortlet.java tree/CMSTreeLoader.java
Date Wed, 13 Apr 2005 22:56:18 GMT
Author: taylor
Date: Wed Apr 13 15:56:17 2005
New Revision: 161231

URL: http://svn.apache.org/viewcvs?view=rev&rev=161231
Log:
abstracted common stuff in tree and search portlets

Added:
    incubator/graffito/trunk/applications/graffito-portlets/src/java/org/apache/portals/graffito/portlets/AbstractGraffitoPortlet.java
Modified:
    incubator/graffito/trunk/applications/graffito-portlets/src/java/org/apache/portals/graffito/portlets/SearchPortlet.java
    incubator/graffito/trunk/applications/graffito-portlets/src/java/org/apache/portals/graffito/portlets/TreePortlet.java
    incubator/graffito/trunk/applications/graffito-portlets/src/java/org/apache/portals/graffito/portlets/tree/CMSTreeLoader.java

Added: incubator/graffito/trunk/applications/graffito-portlets/src/java/org/apache/portals/graffito/portlets/AbstractGraffitoPortlet.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/applications/graffito-portlets/src/java/org/apache/portals/graffito/portlets/AbstractGraffitoPortlet.java?view=auto&rev=161231
==============================================================================
--- incubator/graffito/trunk/applications/graffito-portlets/src/java/org/apache/portals/graffito/portlets/AbstractGraffitoPortlet.java
(added)
+++ incubator/graffito/trunk/applications/graffito-portlets/src/java/org/apache/portals/graffito/portlets/AbstractGraffitoPortlet.java
Wed Apr 13 15:56:17 2005
@@ -0,0 +1,160 @@
+/*
+ * 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.portals.graffito.portlets;
+
+import java.util.HashMap;
+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.portals.graffito.ContentModelService;
+import org.apache.portals.graffito.ContentSearchService;
+import org.apache.portals.graffito.portlets.tree.CMSTreeLoader;
+import org.apache.portals.graffito.portlets.util.ServiceAccessor;
+
+
+/**
+ * AbstractGraffitoPortlet
+ * 
+ * @author <a href="mailto:dtaylor@itgroundwork.com">David Sean Taylor</a>
+ * @version $Id: $
+ */
+
+public class AbstractGraffitoPortlet extends GenericServletPortlet
+{
+    protected ContentSearchService search = null;
+    protected ContentModelService cms = null;
+    protected CMSTreeLoader loader ;
+    protected String anchorImage;
+    protected Map imageMap = new HashMap();
+    protected String folderImage;
+    protected String documentImage;
+    
+    public void init(PortletConfig config) throws PortletException
+    {
+        super.init(config);
+        
+        search = (ContentSearchService)ServiceAccessor.getSearchService();
+        if (search == null)
+        {
+            throw new PortletException("Failed to load CMS Search service");
+        }
+        cms = ServiceAccessor.getModelService();
+        if (cms == null)
+        {
+            throw new PortletException("Failed to load CMS service");
+        }
+        
+        loader = new CMSTreeLoader(cms, this);
+        
+        String extensions = config.getInitParameter("extensions");
+        String images = config.getInitParameter("images");
+        anchorImage = config.getInitParameter("anchorImage");
+        folderImage = config.getInitParameter("folderImage");
+        documentImage = config.getInitParameter("documentImage");
+
+        if (extensions == null)
+        {
+            extensions = "html,txt,pdf";
+        }
+        if (images == null)
+        {
+            images = "document.gif, text.gif, pdficon.gif";
+        }
+        if (anchorImage == null)
+        {
+            anchorImage = "anchorLink.gif";
+        }
+        if (folderImage == null)
+        {
+            folderImage = "folder.gif";
+        }
+        if (documentImage == null)
+        {
+            documentImage = "document.gif";
+        }
+        
+        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 anchorImage.
+     */
+    public String getAnchorImage()
+    {
+        return anchorImage;
+    }
+    /**
+     * @return Returns the folderImage.
+     */
+    public String getFolderImage()
+    {
+        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;
+    }
+}

Modified: incubator/graffito/trunk/applications/graffito-portlets/src/java/org/apache/portals/graffito/portlets/SearchPortlet.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/applications/graffito-portlets/src/java/org/apache/portals/graffito/portlets/SearchPortlet.java?view=diff&r1=161230&r2=161231
==============================================================================
--- incubator/graffito/trunk/applications/graffito-portlets/src/java/org/apache/portals/graffito/portlets/SearchPortlet.java
(original)
+++ incubator/graffito/trunk/applications/graffito-portlets/src/java/org/apache/portals/graffito/portlets/SearchPortlet.java
Wed Apr 13 15:56:17 2005
@@ -27,7 +27,6 @@
 import javax.portlet.RenderRequest;
 import javax.portlet.RenderResponse;
 
-import org.apache.portals.bridges.common.GenericServletPortlet;
 import org.apache.portals.graffito.ContentModelService;
 import org.apache.portals.graffito.ContentSearchService;
 import org.apache.portals.graffito.exception.ContentManagementException;
@@ -48,7 +47,7 @@
  * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
  * @version $Id: CMSSearchPortlet.java,v 1.4 2005/02/22 02:00:51 david Exp $
  */
-public class SearchPortlet extends GenericServletPortlet
+public class SearchPortlet extends AbstractGraffitoPortlet
 {
     public final static String PORTLET_URL = "portlet_url";
     
@@ -60,10 +59,6 @@
     private static final String SEARCH_STRING = "search_string";
     //TODO: localize this message    
     private static final String NOT_FOUND = "No matching documents found for search criteria.";
-
-    private ContentSearchService search = null;
-    private ContentModelService cms = null;
-    private CMSTreeLoader loader ;
         
     //TODO: config via portlet.xml
     private int perPage = 10;
@@ -337,20 +332,7 @@
     
     public void init(PortletConfig config) throws PortletException
     {
-        super.init(config);
-        
-        search = (ContentSearchService)ServiceAccessor.getSearchService();
-        if (search == null)
-        {
-            throw new PortletException("Failed to load CMS Search service");
-        }
-        cms = ServiceAccessor.getModelService();
-        if (cms == null)
-        {
-            throw new PortletException("Failed to load CMS service");
-        }
-        
-        loader = new CMSTreeLoader(cms);
+        super.init(config);        
     }
     
 }

Modified: incubator/graffito/trunk/applications/graffito-portlets/src/java/org/apache/portals/graffito/portlets/TreePortlet.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/applications/graffito-portlets/src/java/org/apache/portals/graffito/portlets/TreePortlet.java?view=diff&r1=161230&r2=161231
==============================================================================
--- incubator/graffito/trunk/applications/graffito-portlets/src/java/org/apache/portals/graffito/portlets/TreePortlet.java
(original)
+++ incubator/graffito/trunk/applications/graffito-portlets/src/java/org/apache/portals/graffito/portlets/TreePortlet.java
Wed Apr 13 15:56:17 2005
@@ -30,8 +30,6 @@
 import javax.portlet.RenderRequest;
 import javax.portlet.RenderResponse;
 
-import org.apache.portals.bridges.common.GenericServletPortlet;
-import org.apache.portals.graffito.ContentModelService;
 import org.apache.portals.graffito.exception.ContentManagementException;
 import org.apache.portals.graffito.model.Document;
 import org.apache.portals.graffito.model.Folder;
@@ -40,7 +38,6 @@
 import org.apache.webapp.admin.TreeControlNode;
 
 import org.apache.portals.graffito.portlets.tree.CMSTreeLoader;
-import org.apache.portals.graffito.portlets.util.ServiceAccessor;
 
 
 
@@ -50,7 +47,7 @@
  * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
  * @version $Id: CMSTreePortlet.java,v 1.2 2005/02/18 01:10:56 david Exp $
  */
-public class TreePortlet extends GenericServletPortlet
+public class TreePortlet extends AbstractGraffitoPortlet
 {
     public final static String PORTLET_ACTION = "portlet_action";
     public final static String PORTLET_URL = "portlet_url";
@@ -64,10 +61,7 @@
     protected final static String TARGET = "_parent";
     
     protected String xmlIndex;
-    
-    protected CMSTreeLoader loader;
-    protected ContentModelService cms;
-    
+        
     public void doView(RenderRequest request, RenderResponse response) throws PortletException,
IOException
     {
         response.setContentType("text/html");
@@ -238,14 +232,6 @@
     public void init(PortletConfig config) throws PortletException
     {
         super.init(config);
-                
-        cms = ServiceAccessor.getModelService();
-        if (cms == null)
-        {
-            throw new PortletException("Failed to load CMS service");
-        }
-        loader = new CMSTreeLoader(cms);
-
     }
 
                  

Modified: incubator/graffito/trunk/applications/graffito-portlets/src/java/org/apache/portals/graffito/portlets/tree/CMSTreeLoader.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/applications/graffito-portlets/src/java/org/apache/portals/graffito/portlets/tree/CMSTreeLoader.java?view=diff&r1=161230&r2=161231
==============================================================================
--- incubator/graffito/trunk/applications/graffito-portlets/src/java/org/apache/portals/graffito/portlets/tree/CMSTreeLoader.java
(original)
+++ incubator/graffito/trunk/applications/graffito-portlets/src/java/org/apache/portals/graffito/portlets/tree/CMSTreeLoader.java
Wed Apr 13 15:56:17 2005
@@ -27,8 +27,8 @@
 import org.apache.portals.graffito.model.Document;
 import org.apache.portals.graffito.model.Folder;
 import org.apache.portals.graffito.model.Link;
+import org.apache.portals.graffito.portlets.AbstractGraffitoPortlet;
 import org.apache.webapp.admin.TreeControlNode;
-import org.apache.portals.graffito.portlets.util.ServiceAccessor;
 
 public class CMSTreeLoader 
 {
@@ -36,10 +36,12 @@
 	public final static String PORTLET_URL = "portlet_url";
 		
 	private ContentModelService cms; 
+    private AbstractGraffitoPortlet portlet;
         
-    public CMSTreeLoader(ContentModelService cms)
+    public CMSTreeLoader(ContentModelService cms, AbstractGraffitoPortlet portlet)
     {
         this.cms = cms;
+        this.portlet = portlet;
     }
     
     public TreeControlNode createFolderNode(Folder folder) throws ContentManagementException
@@ -47,7 +49,7 @@
         TreeControlNode node = 
             new TreeControlNode(
                     folder.getUri(), 
-                    "folder.gif", 
+                    portlet.getFolderImage(),  
                     folder.getName(), 
                     null, 
                     null, 
@@ -72,7 +74,7 @@
     	TreeControlNode issueNode = 
             new TreeControlNode(
                     document.getUri(),
-                    "document.gif", 
+                    portlet.getImageForContentType(document.getContentType()),
                     title, 
                     PORTLET_URL, 
                     null, 
@@ -94,7 +96,7 @@
     	TreeControlNode linkNode = 
             new TreeControlNode(
                     link.getProperty("reference") + link.getProperty("anchor"),
-                    "anchorlink.gif", 
+                    portlet.getAnchorImage(), 
                     link.getProperty("displayTitle"), 
                     PORTLET_URL, 
                     null, 
@@ -114,7 +116,7 @@
     public TreeControlNode createRootNode(String label, String rootDomain)
     {
     	TreeControlNode root = new TreeControlNode("ROOT-NODE", 
-                "folder.gif", 
+                portlet.getFolderImage(), 
                 label, // label 
                 null,       // action
                 null,       // target



Mime
View raw message