1 23 24 package org.infoglue.deliver.applications.actions; 25 26 import java.io.IOException ; 27 import java.io.PrintWriter ; 28 import java.lang.reflect.Method ; 29 import java.lang.reflect.Modifier ; 30 import java.security.Principal ; 31 import java.util.ArrayList ; 32 import java.util.HashMap ; 33 import java.util.List ; 34 import java.util.Map ; 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 54 55 public class ViewApplicationSettingsAction extends ViewPageAction { 57 private final static Logger logger = Logger.getLogger(ViewApplicationSettingsAction.class.getName()); 58 59 private List templateMethods = new ArrayList (); 61 62 private String navigationTitle = null; 64 private String sourceId = null; 65 private String className = null; 66 67 private static final String ENCODING = "UTF-8"; 68 69 72 73 public ViewApplicationSettingsAction() 74 { 75 } 76 77 81 82 public String doExecute() throws Exception  83 { 84 return NONE; 85 } 86 87 protected String out(String string) throws IOException  88 { 89 getResponse().setContentType("text/xml; charset=" + ENCODING); 90 PrintWriter out = getResponse().getWriter(); 91 out.println(string); 92 return null; 93 } 94 95 private String q(String s) 96 { 97 return "\"" + s + "\""; 98 } 99 100 private String createMethodElement(Method m) 101 { 102 String args = ""; 103 Class [] 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 doGetClassMethods() throws Exception  114 { 115 StringBuffer document = new StringBuffer (); 116 try 117 { 118 Class 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 m[] = cls.getDeclaredMethods(); 130 for (int i = 0; i < m.length; i++) 131 { 132 Method 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 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 155 156 public String doGetTemplateLogicMethods() throws Exception  157 { 158 try 159 { 160 Method m[] = BasicTemplateController.class.getDeclaredMethods(); 161 for (int i = 0; i < m.length; i++) 162 { 163 Method method = m[i]; 164 if(!method.getName().startsWith("set")) 165 { 166 StringBuffer sb = new StringBuffer (); 167 sb.append(method.getName()); 168 sb.append("("); 169 Class [] 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 methodString = sb.toString(); 180 int position = 0; 181 while(position < this.templateMethods.size()) 182 { 183 String currentString = (String )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 e) 197 { 198 System.err.println(e); 199 } 200 return "templateMethods"; 201 } 202 203 206 207 public String doGetPageNavigationTitle() throws Exception  208 { 209 DatabaseWrapper dbWrapper = new DatabaseWrapper(CastorDatabaseService.getDatabase()); 210 212 beginTransaction(dbWrapper.getDatabase()); 213 214 try 215 { 216 Principal principal = (Principal )this.getHttpSession().getAttribute("infogluePrincipal"); 217 if(principal == null) 218 { 219 try 220 { 221 Map arguments = new HashMap (); 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 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 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 getTemplateMethods() 251 { 252 return templateMethods; 253 } 254 255 public String getNavigationTitle() 256 { 257 return navigationTitle; 258 } 259 260 public String getSourceId() 261 { 262 return this.sourceId; 263 } 264 265 public void setSourceId(String sourceId) 266 { 267 this.sourceId = sourceId; 268 } 269 270 public String getClassName() 271 { 272 return className; 273 } 274 public void setClassName(String className) 275 { 276 this.className = className; 277 } 278 } 279 | Popular Tags |