KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > cms > controllers > kernel > impl > simple > ShortcutController


1 /* ===============================================================================
2 /* ===============================================================================
3 *
4 * Part of the InfoGlue Content Management Platform (www.infoglue.org)
5 *
6 * ===============================================================================
7 *
8 * Copyright (C)
9 *
10 * This program is free software; you can redistribute it and/or modify it under
11 * the terms of the GNU General Public License version 2, as published by the
12 * Free Software Foundation. See the file LICENSE.html for more information.
13 *
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along with
19 * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
20 * Place, Suite 330 / Boston, MA 02111-1307 / USA.
21 *
22 * ===============================================================================
23 */

24
25 package org.infoglue.cms.controllers.kernel.impl.simple;
26
27 import java.util.ArrayList JavaDoc;
28 import java.util.HashMap JavaDoc;
29 import java.util.Iterator JavaDoc;
30 import java.util.List JavaDoc;
31 import java.util.Map JavaDoc;
32
33 import org.apache.log4j.Logger;
34 import org.dom4j.Document;
35 import org.dom4j.Node;
36 import org.infoglue.cms.entities.kernel.BaseEntityVO;
37 import org.infoglue.cms.entities.mydesktop.ShortcutVO;
38 import org.infoglue.cms.exception.SystemException;
39 import org.infoglue.cms.security.InfoGluePrincipal;
40 import org.infoglue.cms.util.dom.DOMBuilder;
41
42 import com.opensymphony.module.propertyset.PropertySet;
43 import com.opensymphony.module.propertyset.PropertySetManager;
44
45 /**
46  * This controller fetches all shortcuts available. They can exist on personal, role or global level.
47  *
48  * @author Mattias Bogeblad
49  */

50
51 public class ShortcutController extends BaseController
52 {
53     private final static Logger logger = Logger.getLogger(ShortcutController.class.getName());
54
55     private static final ShortcutController controller = new ShortcutController();
56
57     /**
58      * Returns the WorkflowController singleton
59      * @return a reference to a WorkflowController
60      */

61     public static ShortcutController getController()
62     {
63         return controller;
64     }
65
66     private ShortcutController() {}
67
68     /**
69      * Returns a list of all available shortcuts defined in the system including personal
70      * @param userPrincipal a user principal
71      * @return a list ShortcutVOs representing available shortcuts
72      */

73     public List JavaDoc getAvailableShortcutVOList(InfoGluePrincipal userPrincipal) throws SystemException
74     {
75         List JavaDoc availableShortcutVOList = new ArrayList JavaDoc();
76          
77         try
78         {
79             Map JavaDoc args = new HashMap JavaDoc();
80             args.put("globalKey", "infoglue");
81             PropertySet propertySet = PropertySetManager.getInstance("jdbc", args);
82     
83             String JavaDoc xml = getDataPropertyValue(propertySet, "serverNode_-1_shortcuts");
84             logger.info("xml:" + xml);
85             
86             if(xml != null)
87             {
88                 DOMBuilder domBuilder = new DOMBuilder();
89                 
90                 Document document = domBuilder.getDocument(xml);
91                 
92                 List JavaDoc nodes = document.getRootElement().selectNodes("shortcut");
93                 logger.info("nodes:" + nodes.size());
94                 
95                 Iterator JavaDoc nodesIterator = nodes.iterator();
96                 while(nodesIterator.hasNext())
97                 {
98                     Node node = (Node)nodesIterator.next();
99                     logger.info("Node:" + node.asXML());
100                     
101                     Node nameNode = node.selectSingleNode("name");
102                     Node urlNode = node.selectSingleNode("url");
103                     Node popupNode = node.selectSingleNode("popup");
104
105                     String JavaDoc name = nameNode.getStringValue();
106                     String JavaDoc url = urlNode.getStringValue();
107                     String JavaDoc popup = popupNode.getStringValue();
108                     
109                     ShortcutVO shortcut = new ShortcutVO(name, url, Boolean.valueOf(popup).booleanValue());
110                     
111                     availableShortcutVOList.add(shortcut);}
112             }
113             
114         }
115         catch(Exception JavaDoc e)
116         {
117             logger.error("An error occurred when reading shortcuts:" + e.getMessage(), e);
118         }
119         
120         return availableShortcutVOList;
121     }
122
123     public String JavaDoc getDataPropertyValue(PropertySet propertySet, String JavaDoc key) throws Exception JavaDoc
124     {
125         byte[] valueBytes = propertySet.getData(key);
126         if(valueBytes != null)
127             return new String JavaDoc(valueBytes, "utf-8");
128         else
129             return null;
130     }
131
132     /**
133      * Returns a new WorkflowActionVO. This method is apparently unused, but is required by BaseController. We don't
134      * use it internally because it requires a cast; it is simpler to just use <code>new</code> to create an instance.
135      * @return a new WorkflowActionVO.
136      */

137     public BaseEntityVO getNewVO()
138     {
139         return null;
140     }
141 }
142
Popular Tags