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 BaseWapPO { 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 returnWML = null; 107 108 if ((event == null) || (event.length() == 0)) { 109 returnWML = handleDefault(); 110 } else { 111 returnWML = getPageContentForEvent(event); 112 } 113 114 HttpPresentationResponse response = comms.response; 115 response.setContentType("text/vnd.wap.wml"); 116 117 HttpPresentationOutputStream out = response.getOutputStream(); 118 out.println(returnWML); 119 response.flush(); 120 } 121 122 126 public String getPageContentForEvent(String event) 127 throws Exception { 128 try { 129 Method method = this.getClass() 131 .getMethod(toMethodName(event), null); 132 133 String thePage = (String ) method.invoke(this, null); 135 136 return thePage; 137 } catch (InvocationTargetException ex) { 138 if (ex.getTargetException() instanceof Exception ) { 141 throw (Exception ) ex.getTargetException(); 142 } else if (ex.getTargetException() instanceof Error ) { 143 throw (Error ) ex.getTargetException(); 144 } else { 145 throw ex; 146 } 147 } catch (NoSuchMethodException ex) { 148 throw new BasePOException("No event handler found for event: " + 150 event, ex); 151 } catch (IllegalAccessException ex) { 152 throw new BasePOException( 154 "Illegal access to event handler (is it public?): " + 155 event, ex); 156 } 157 } 158 159 166 private String toMethodName(String event) { 167 StringBuffer methodName = new StringBuffer (STANDARD_METHOD_PREFIX); 168 methodName.append(Character.toUpperCase(event.charAt(0))); 169 170 if (event.length() > 1) { 171 methodName.append(event.substring(1)); 172 } 173 174 return methodName.toString(); 175 } 176 177 183 public StandardApplication getApplication() { 184 return (StandardApplication) Enhydra.getApplication(); 185 } 186 187 193 public static void writeDebugMsg(String msg) { 194 Enhydra.getLogChannel().write(Logger.DEBUG, msg); 195 } 196 } | Popular Tags |