1 9 package org.openuss.presentation.enhydra.framework; 10 11 import com.lutris.appserver.server.*; 12 import com.lutris.appserver.server.httpPresentation.*; 13 import com.lutris.appserver.server.user.User; 14 15 import com.lutris.logging.*; 16 17 import com.lutris.util.KeywordValueException; 18 19 22 import java.lang.Throwable ; 23 import java.lang.reflect.*; 24 25 import java.util.*; 26 27 import org.w3c.dom.*; 28 import org.w3c.dom.html.HTMLElement; 29 30 31 37 abstract public class BasePO { 38 41 private static String EVENT = "event"; 42 43 47 private static String STANDARD_METHOD_PREFIX = "handle"; 48 49 52 protected HttpPresentationComms myComms = null; 53 54 64 abstract public String handleDefault() throws HttpPresentationException; 65 66 71 abstract protected boolean loggedInUserRequired(); 72 73 79 abstract protected boolean isForPublicAccess() throws BasePOException; 80 81 88 abstract protected void checkForAccessList() 89 throws ClientPageRedirectException, 90 BasePOException; 91 92 96 public HttpPresentationComms getComms() { 97 return this.myComms; 98 } 99 100 103 public void handleEvent(HttpPresentationComms comms) 104 throws Exception { 105 String event = comms.request.getParameter(EVENT); 106 String returnHTML = null; 107 108 if ((event == null) || (event.length() == 0)) { 109 returnHTML = handleDefault(); 110 } else { 111 returnHTML = getPageContentForEvent(event); 112 } 113 114 comms.response.writeHTML(returnHTML); 115 } 116 117 121 public String getPageContentForEvent(String event) 122 throws Exception { 123 try { 124 Method method = this.getClass() 126 .getMethod(toMethodName(event), null); 127 128 String thePage = (String ) method.invoke(this, null); 130 131 return thePage; 132 } catch (InvocationTargetException ex) { 133 if (ex.getTargetException() instanceof Exception ) { 136 throw (Exception ) ex.getTargetException(); 137 } else if (ex.getTargetException() instanceof Error ) { 138 throw (Error ) ex.getTargetException(); 139 } else { 140 throw ex; 141 } 142 } catch (NoSuchMethodException ex) { 143 throw new BasePOException("No event handler found for event: " + 145 event, ex); 146 } catch (IllegalAccessException ex) { 147 throw new BasePOException( 149 "Illegal access to event handler (is it public?): " + 150 event, ex); 151 } 152 } 153 154 161 private String toMethodName(String event) { 162 StringBuffer methodName = new StringBuffer (STANDARD_METHOD_PREFIX); 163 methodName.append(Character.toUpperCase(event.charAt(0))); 164 165 if (event.length() > 1) { 166 methodName.append(event.substring(1)); 167 } 168 169 return methodName.toString(); 170 } 171 172 178 public StandardApplication getApplication() { 179 return (StandardApplication) Enhydra.getApplication(); 180 } 181 182 188 public static void writeDebugMsg(String msg) { 189 Enhydra.getLogChannel().write(Logger.DEBUG, msg); 190 } 191 } | Popular Tags |