KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > deliver > applications > actions > ViewApplicationSettingsAction


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

23
24 package org.infoglue.deliver.applications.actions;
25
26 import java.io.IOException JavaDoc;
27 import java.io.PrintWriter JavaDoc;
28 import java.lang.reflect.Method JavaDoc;
29 import java.lang.reflect.Modifier JavaDoc;
30 import java.security.Principal JavaDoc;
31 import java.util.ArrayList JavaDoc;
32 import java.util.HashMap JavaDoc;
33 import java.util.List JavaDoc;
34 import java.util.Map JavaDoc;
35
36 import org.apache.log4j.Logger;
37 import org.infoglue.cms.controllers.kernel.impl.simple.CastorDatabaseService;
38 import org.infoglue.cms.exception.SystemException;
39 import org.infoglue.cms.security.InfoGluePrincipal;
40 import org.infoglue.cms.util.CmsPropertyHandler;
41 import org.infoglue.deliver.applications.databeans.DatabaseWrapper;
42 import org.infoglue.deliver.controllers.kernel.impl.simple.BasicTemplateController;
43 import org.infoglue.deliver.controllers.kernel.impl.simple.ComponentLogic;
44 import org.infoglue.deliver.controllers.kernel.impl.simple.ExtranetController;
45 import org.infoglue.deliver.controllers.kernel.impl.simple.IntegrationDeliveryController;
46 import org.infoglue.deliver.controllers.kernel.impl.simple.NodeDeliveryController;
47 import org.infoglue.deliver.controllers.kernel.impl.simple.TemplateController;
48
49 /**
50  * This is the action that can supply a caller with a lot of information about the delivery-engine.
51  *
52  * @author Mattias Bogeblad
53  */

54
55 public class ViewApplicationSettingsAction extends ViewPageAction //WebworkAbstractAction
56
{
57     private final static Logger logger = Logger.getLogger(ViewApplicationSettingsAction.class.getName());
58
59     //Used to get a list of all available mthods
60
private List JavaDoc templateMethods = new ArrayList JavaDoc();
61
62     //Used to get the navigation title of a page
63
private String JavaDoc navigationTitle = null;
64     private String JavaDoc sourceId = null;
65     private String JavaDoc className = null;
66
67     private static final String JavaDoc ENCODING = "UTF-8";
68
69     /**
70      * The constructor for this action - contains nothing right now.
71      */

72     
73     public ViewApplicationSettingsAction()
74     {
75     }
76     
77     /**
78      * This method is the application entry-point. The parameters has been set through the setters
79      * and now we just have to render the appropriate output.
80      */

81          
82     public String JavaDoc doExecute() throws Exception JavaDoc
83     {
84         return NONE;
85     }
86
87     protected String JavaDoc out(String JavaDoc string) throws IOException JavaDoc
88     {
89         getResponse().setContentType("text/xml; charset=" + ENCODING);
90         PrintWriter JavaDoc out = getResponse().getWriter();
91         out.println(string);
92         return null;
93     }
94     
95     private String JavaDoc q(String JavaDoc s)
96     {
97         return "\"" + s + "\"";
98     }
99     
100     private String JavaDoc createMethodElement(Method JavaDoc m)
101     {
102         String JavaDoc args = "";
103         Class JavaDoc[] params = m.getParameterTypes();
104         for(int i=0; i<params.length; i++)
105         {
106             if(i!=0) args+=", ";
107             args += params[i].getName();
108         }
109         
110         return "<method name=" + q(m.getName()) + " returnType=" + q(m.getReturnType().getName()) + " args=" + q(args) + "/>";
111     }
112     
113     public String JavaDoc doGetClassMethods() throws Exception JavaDoc
114     {
115         StringBuffer JavaDoc document = new StringBuffer JavaDoc();
116         try
117         {
118             Class JavaDoc cls = null;
119             if(className==null || className.equals("$templateLogic"))
120                 cls = BasicTemplateController.class;
121             else if(className.equals("$componentLogic"))
122                 cls = ComponentLogic.class;
123             else
124                 cls = Class.forName(className);
125             
126             if(cls==null) return out("<methods class=\"null\" package=\"null\"/>");
127             
128             document.append("<methods class=" + q(cls.getName()) + " package=" + q(cls.getPackage().getName()) + ">");
129             Method JavaDoc m[] = cls.getDeclaredMethods();
130             for (int i = 0; i < m.length; i++)
131             {
132                 Method JavaDoc method = m[i];
133                 if(Modifier.isPublic(method.getModifiers()))
134                 {
135                     document.append(createMethodElement(method));
136                 }
137             }
138             document.append("</methods>");
139         }
140         catch (Throwable JavaDoc e)
141         {
142             System.err.println(e);
143             return out("<methods class=\"null\" package=\"null\"/>");
144         }
145
146         return out(document.toString());
147     }
148     
149     
150     /**
151      * This command is used to get a list of all available methods on the templateController.
152      * This service is mostly used by the template-editor so it can keep up with changes easily.
153      * @deprecated
154      */

155     
156     public String JavaDoc doGetTemplateLogicMethods() throws Exception JavaDoc
157     {
158         try
159         {
160             Method JavaDoc m[] = BasicTemplateController.class.getDeclaredMethods();
161             for (int i = 0; i < m.length; i++)
162             {
163                 Method JavaDoc method = m[i];
164                 if(!method.getName().startsWith("set"))
165                 {
166                     StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
167                     sb.append(method.getName());
168                     sb.append("(");
169                     Class JavaDoc[] parameters = method.getParameterTypes();
170                     for (int j = 0; j < parameters.length; j++)
171                     {
172                         if(j != 0)
173                             sb.append(", ");
174                             
175                         sb.append(parameters[j].getName());
176                     }
177                     sb.append(")");
178                     
179                     String JavaDoc methodString = sb.toString();
180                     int position = 0;
181                     while(position < this.templateMethods.size())
182                     {
183                         String JavaDoc currentString = (String JavaDoc)this.templateMethods.get(position);
184                         if(currentString.compareToIgnoreCase(methodString) > 0)
185                         {
186                             break;
187                         }
188                         position++;
189                     }
190                     
191                     this.templateMethods.add(position, methodString);
192             
193                 }
194             }
195         }
196         catch (Throwable JavaDoc e)
197         {
198             System.err.println(e);
199         }
200         return "templateMethods";
201     }
202     
203     /**
204      * This command is used to get the navigationtitle for a sitenode in a certain language.
205      */

206     
207     public String JavaDoc doGetPageNavigationTitle() throws Exception JavaDoc
208     {
209         DatabaseWrapper dbWrapper = new DatabaseWrapper(CastorDatabaseService.getDatabase());
210         //Database db = CastorDatabaseService.getDatabase();
211

212         beginTransaction(dbWrapper.getDatabase());
213
214         try
215         {
216             Principal JavaDoc principal = (Principal JavaDoc)this.getHttpSession().getAttribute("infogluePrincipal");
217             if(principal == null)
218             {
219                 try
220                 {
221                     Map JavaDoc arguments = new HashMap JavaDoc();
222                     arguments.put("j_username", CmsPropertyHandler.getAnonymousUser());
223                     arguments.put("j_password", CmsPropertyHandler.getAnonymousPassword());
224                     
225                     principal = ExtranetController.getController().getAuthenticatedPrincipal(arguments);
226                 }
227                 catch(Exception JavaDoc e)
228                 {
229                     throw new SystemException("There was no anonymous user found in the system. There must be - add the user anonymous/anonymous and try again.", e);
230                 }
231             }
232             
233             this.nodeDeliveryController = NodeDeliveryController.getNodeDeliveryController(getSiteNodeId(), getLanguageId(), getContentId());
234             this.integrationDeliveryController = IntegrationDeliveryController.getIntegrationDeliveryController(getSiteNodeId(), getLanguageId(), getContentId());
235             TemplateController templateController = getTemplateController(dbWrapper, getSiteNodeId(), getLanguageId(), getContentId(), getRequest(), (InfoGluePrincipal)principal, false);
236             this.navigationTitle = templateController.getPageNavTitle(this.getSiteNodeId());
237
238             closeTransaction(dbWrapper.getDatabase());
239         }
240         catch(Exception JavaDoc e)
241         {
242             logger.error("An error occurred so we should not complete the transaction:" + e, e);
243             rollbackTransaction(dbWrapper.getDatabase());
244             throw new SystemException(e.getMessage());
245         }
246
247         return "navigationTitle";
248     }
249         
250     public List JavaDoc getTemplateMethods()
251     {
252         return templateMethods;
253     }
254
255     public String JavaDoc getNavigationTitle()
256     {
257         return navigationTitle;
258     }
259
260     public String JavaDoc getSourceId()
261     {
262         return this.sourceId;
263     }
264
265     public void setSourceId(String JavaDoc sourceId)
266     {
267         this.sourceId = sourceId;
268     }
269
270     public String JavaDoc getClassName()
271     {
272         return className;
273     }
274     public void setClassName(String JavaDoc className)
275     {
276         this.className = className;
277     }
278 }
279
Popular Tags