summaryrefslogtreecommitdiff
path: root/BKUOnline/src/main/java/at
diff options
context:
space:
mode:
authorwbauer <wbauer@8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4>2008-10-09 15:18:40 +0000
committerwbauer <wbauer@8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4>2008-10-09 15:18:40 +0000
commit32d579c45b0fc8a99e4f9b71164415fa09e2d79f (patch)
tree41068cce7c33c09c9688b415e9ed87272ae3a67c /BKUOnline/src/main/java/at
parent144c0133dcb107b30799a310ba51460d6479358d (diff)
downloadmocca-32d579c45b0fc8a99e4f9b71164415fa09e2d79f.tar.gz
mocca-32d579c45b0fc8a99e4f9b71164415fa09e2d79f.tar.bz2
mocca-32d579c45b0fc8a99e4f9b71164415fa09e2d79f.zip
Introduced SL Request parameters to customize Applet layout
git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@92 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4
Diffstat (limited to 'BKUOnline/src/main/java/at')
-rw-r--r--BKUOnline/src/main/java/at/gv/egiz/bku/online/webapp/BKURequestHandler.java136
1 files changed, 94 insertions, 42 deletions
diff --git a/BKUOnline/src/main/java/at/gv/egiz/bku/online/webapp/BKURequestHandler.java b/BKUOnline/src/main/java/at/gv/egiz/bku/online/webapp/BKURequestHandler.java
index 544bbc99..6f3b9d7f 100644
--- a/BKUOnline/src/main/java/at/gv/egiz/bku/online/webapp/BKURequestHandler.java
+++ b/BKUOnline/src/main/java/at/gv/egiz/bku/online/webapp/BKURequestHandler.java
@@ -16,6 +16,9 @@
*/
package at.gv.egiz.bku.online.webapp;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Locale;
@@ -32,6 +35,7 @@ import org.apache.commons.logging.LogFactory;
import at.gv.egiz.bku.binding.HTTPBindingProcessor;
import at.gv.egiz.bku.binding.HttpUtil;
import at.gv.egiz.bku.binding.IdFactory;
+import at.gv.egiz.bku.utils.StreamUtil;
import at.gv.egiz.org.apache.tomcat.util.http.AcceptLanguage;
/**
@@ -40,51 +44,99 @@ import at.gv.egiz.org.apache.tomcat.util.http.AcceptLanguage;
*/
public class BKURequestHandler extends SpringBKUServlet {
- public final static String REDIRECT_URL = "appletPage.jsp";
+ public final static String REDIRECT_URL = "appletPage.jsp";
- protected Log log = LogFactory.getLog(BKURequestHandler.class);
+ protected Log log = LogFactory.getLog(BKURequestHandler.class);
- protected void doPost(HttpServletRequest req, HttpServletResponse resp)
- throws ServletException, java.io.IOException {
- log.debug("Got new request");
- String lang = req.getHeader("Accept-Language");
- Locale locale = AcceptLanguage.getLocale(lang);
- log.debug("Using locale: " + locale);
- HttpSession session = req.getSession();
- if (session != null) {
- log.warn("Already a session with id: "+session.getId()+ " active, deleting this one");
- getBindingProcessorManager().removeBindingProcessor(IdFactory.getInstance().createId(session.getId()));
- }
- String id = req.getSession(true).getId();
- log.debug("Using session id: " + id);
- HTTPBindingProcessor bindingProcessor;
+ private static String getStringFromStream(InputStream is, String encoding) throws IOException {
+ if (is == null) {
+ return null;
+ }
+ if (encoding == null) {
+ encoding = HttpUtil.DEFAULT_CHARSET;
+ }
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
+ StreamUtil.copyStream(is, os);
+ return new String(os.toByteArray(), encoding);
+ }
+
+
+ protected void doPost(HttpServletRequest req, HttpServletResponse resp)
+ throws ServletException, java.io.IOException {
+ log.debug("Got new request");
+ HttpSession session = req.getSession();
+ String lang = req.getHeader("Accept-Language");
+ Locale locale = AcceptLanguage.getLocale(lang);
+ log.debug("Using locale: " + locale);
- bindingProcessor = (HTTPBindingProcessor) getBindingProcessorManager()
- .createBindingProcessor(req.getRequestURL().toString(), id, locale);
+ if (session != null) {
+ log.warn("Already a session with id: " + session.getId()
+ + " active, deleting this one");
+ getBindingProcessorManager().removeBindingProcessor(
+ IdFactory.getInstance().createId(session.getId()));
+ }
+ String id = req.getSession(true).getId();
+ log.debug("Using session id: " + id);
+ HTTPBindingProcessor bindingProcessor;
- Map<String, String> headerMap = new HashMap<String, String>();
- for (Enumeration<String> headerName = req.getHeaderNames(); headerName
- .hasMoreElements();) {
- String header = headerName.nextElement();
- if (header != null) {
- headerMap.put(header, req.getHeader(header));
- }
- }
- String charset = req.getCharacterEncoding();
- String contentType = req.getContentType();
- if (charset != null) {
- contentType += ";" + charset;
- }
- headerMap.put(HttpUtil.HTTP_HEADER_CONTENT_TYPE, contentType);
- bindingProcessor.setHTTPHeaders(headerMap);
- bindingProcessor.consumeRequestStream(req.getInputStream());
- req.getInputStream().close();
- getBindingProcessorManager().process(bindingProcessor);
- resp.sendRedirect(REDIRECT_URL);
- }
+ bindingProcessor = (HTTPBindingProcessor) getBindingProcessorManager()
+ .createBindingProcessor(req.getRequestURL().toString(), id, locale);
- protected void doGet(HttpServletRequest req, HttpServletResponse resp)
- throws ServletException, java.io.IOException {
- doPost(req, resp);
- }
+ Map<String, String> headerMap = new HashMap<String, String>();
+ for (Enumeration<String> headerName = req.getHeaderNames(); headerName
+ .hasMoreElements();) {
+ String header = headerName.nextElement();
+ if (header != null) {
+ headerMap.put(header, req.getHeader(header));
+ }
+ }
+ String charset = req.getCharacterEncoding();
+ String contentType = req.getContentType();
+ if (charset != null) {
+ contentType += ";" + charset;
+ }
+ headerMap.put(HttpUtil.HTTP_HEADER_CONTENT_TYPE, contentType);
+ bindingProcessor.setHTTPHeaders(headerMap);
+ bindingProcessor.consumeRequestStream(req.getInputStream());
+ req.getInputStream().close();
+ getBindingProcessorManager().process(bindingProcessor);
+
+ log.trace("Trying to find applet parameters in request");
+ String width = getStringFromStream(bindingProcessor.getFormData("appletWidth"), charset);
+ String height = getStringFromStream(bindingProcessor.getFormData("appletHeight"), charset);
+ String background = getStringFromStream(bindingProcessor.getFormData("appletBackground"), charset);
+ if (width != null) {
+ try {
+ log.trace("Found applet width parameter: " + width);
+ int wI = Integer.parseInt(width);
+ session.setAttribute("appletWidth", wI);
+ } catch (NumberFormatException nfe) {
+ log.warn(nfe);
+ }
+ }
+ if (height != null) {
+ try {
+ log.trace("Found applet height parameter: " + height);
+ int hI = Integer.parseInt(height);
+ session.setAttribute("appletHeight", hI);
+ } catch (NumberFormatException nfe) {
+ log.warn(nfe);
+ }
+ }
+ if (background != null) {
+ try {
+ log.trace("Found applet background parameter: " + background);
+ session.setAttribute("appletBackground", background);
+ } catch (NumberFormatException nfe) {
+ log.warn(nfe);
+ }
+ }
+
+ resp.sendRedirect(REDIRECT_URL);
+ }
+
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+ throws ServletException, java.io.IOException {
+ doPost(req, resp);
+ }
}