2006/unicorn/src/org/w3c/unicorn/action IndexAction.java,1.10,1.11 Action.java,1.2,1.3 ObserveAction.java,1.11,1.12

Update of /sources/public/2006/unicorn/src/org/w3c/unicorn/action
In directory hutz:/tmp/cvs-serv9189/src/org/w3c/unicorn/action

Modified Files:
	IndexAction.java Action.java ObserveAction.java 
Log Message:
refactoring in progress

Index: IndexAction.java
===================================================================
RCS file: /sources/public/2006/unicorn/src/org/w3c/unicorn/action/IndexAction.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- IndexAction.java	3 Sep 2009 14:04:12 -0000	1.10
+++ IndexAction.java	4 Sep 2009 17:59:43 -0000	1.11
@@ -1,3 +1,7 @@
+// $Id$Id $
+// Author: Thomas Gambet
+// (c) COPYRIGHT MIT, ERCIM and Keio, 2009.
+// Please first read the full copyright statement in file COPYRIGHT.html
 package org.w3c.unicorn.action;
 
 import java.io.IOException;
@@ -7,6 +11,8 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.velocity.VelocityContext;
 import org.w3c.unicorn.Framework;
 import org.w3c.unicorn.util.Language;
@@ -16,12 +22,16 @@
 
 public class IndexAction extends Action {
 
-	private static final long serialVersionUID = 1L;
+	private static final long serialVersionUID = 599055553694915687L;
+	
+	private static Log logger = LogFactory.getLog(IndexAction.class);
+	
 	private VelocityContext velocityContext;
 	
 	@Override
 	public void init() throws ServletException {
-		super.init();
+		//logger.trace("Init IndexAction");
+		//super.init();
 	}
 	
 	@Override
@@ -40,13 +50,10 @@
 		String langParameter = req.getParameter(Property.get("UNICORN_PARAMETER_PREFIX") + "lang");
 		if (langParameter == null || !Framework.getLanguageProperties().containsKey(langParameter)) {
 			langParameter = Language.negociate(req.getLocales());
-			if (!langParameter.equals(req.getLocale().getLanguage())) {
-				messages.add(new Message(Message.Level.INFO, "$message_unavailable_language (" + req.getLocale().getDisplayLanguage(req.getLocale()) + "). $message_translation", null));
-			} else {
-				String requested_parameter = req.getParameter(Property.get("UNICORN_PARAMETER_PREFIX") + "lang");
-				if (requested_parameter != null && !Framework.getLanguageProperties().containsKey(requested_parameter)) 
-					messages.add(new Message(Message.Level.INFO, "$message_unavailable_requested_language. $message_translation", null));
-			}
+		}
+		
+		if (!langParameter.equals(req.getLocale().getLanguage())) {
+			messages.add(new Message(Message.Level.INFO, "$message_unavailable_language (" + req.getLocale().getDisplayLanguage(req.getLocale()) + "). $message_translation", null));
 		}
 		
 		if (!Language.isComplete(langParameter))
@@ -54,7 +61,9 @@
 		
 		velocityContext = new VelocityContext(Language.getContext(langParameter));
 		
-		String query = req.getQueryString();
+		velocityContext.put("queryString", getQueryStringWithout(Property.get("UNICORN_PARAMETER_PREFIX") + "lang", req));
+		
+		/*String query = req.getQueryString();
 		String queryString;
 		if (query == null) {
 			queryString = "./?";
@@ -71,7 +80,7 @@
 			queryString += query.replaceAll("&?ucn_lang=[^&]*", "");
 		if (!queryString.equals("?"))
 			queryString += "&";*/
-		velocityContext.put("queryString", queryString);
+		//velocityContext.put("queryString", queryString);
 		
 		/*messages.add(new Message(Message.Level.WARNING, "un warning", null));
 		messages.add(new Message(Message.Level.ERROR, "une error", null));

Index: ObserveAction.java
===================================================================
RCS file: /sources/public/2006/unicorn/src/org/w3c/unicorn/action/ObserveAction.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- ObserveAction.java	3 Sep 2009 14:04:12 -0000	1.11
+++ ObserveAction.java	4 Sep 2009 17:59:43 -0000	1.12
@@ -32,6 +32,7 @@
 import org.w3c.unicorn.Framework;
 import org.w3c.unicorn.UnicornCall;
 import org.w3c.unicorn.contract.EnumInputMethod;
+import org.w3c.unicorn.exceptions.UnsupportedMimeTypeException;
 import org.w3c.unicorn.output.OutputFactory;
 import org.w3c.unicorn.output.OutputFormater;
 import org.w3c.unicorn.output.OutputModule;
@@ -45,19 +46,18 @@
  * 
  * @author Jean-Guilhem ROUEL
  */
-public class ObserveAction extends HttpServlet {
-
-	private static final Log logger = LogFactory.getLog(ObserveAction.class);
+public class ObserveAction extends Action {
 
 	private static final long serialVersionUID = -1375355420965607571L;
+	
+	private static Log logger = LogFactory.getLog(ObserveAction.class);
 
-	private static final DiskFileItemFactory factory = new DiskFileItemFactory();
+	private static DiskFileItemFactory factory;
 
 	/**
 	 * Creates a new file upload handler.
 	 */
-	private static final ServletFileUpload upload = new ServletFileUpload(
-			ObserveAction.factory);
+	private static ServletFileUpload upload;
 
 	/*
 	 * (non-Javadoc)
@@ -65,13 +65,14 @@
 	 * @see javax.servlet.GenericServlet#init()
 	 */
 	@Override
-	public void init(final ServletConfig aServletConfig)
-			throws ServletException {
-		ObserveAction.logger.trace("init");
-
-		ObserveAction.factory.setRepository(new File(Property
-				.get("UPLOADED_FILES_REPOSITORY")));
-
+	public void init(final ServletConfig aServletConfig) throws ServletException {
+		logger.trace("Init ObserverAction");
+		super.init();
+		
+		factory = new DiskFileItemFactory();
+		factory.setRepository(new File(Property.get("UPLOADED_FILES_REPOSITORY")));
+		upload = new ServletFileUpload(factory);
+		logger.debug("Created a ServletFileUpload with repository set to: " + Property.get("UPLOADED_FILES_REPOSITORY"));
 	}
 
 	/*
@@ -165,6 +166,13 @@
 
 			this.createOutput(resp, aUnicornCall,
 					mapOfSpecificParameter, mapOfOutputParameter, mapOfStringObject);
+		} catch (final UnsupportedMimeTypeException aException) {
+			if (mapOfOutputParameter.get("mimetype").equals("text/html")) {
+				Message mess = new Message(Message.Level.ERROR, "$message_unsupported_mime_type", null);
+				req.setAttribute("unicorn_message", mess);
+				(new IndexAction()).doGet(req, resp);
+				
+			}
 		} catch (final Exception aException) {
 			ObserveAction.logger.error("Exception : " + aException.getMessage(),
 					aException);
@@ -290,8 +298,13 @@
 
 			this.createOutput(resp, aUnicornCall,
 					mapOfSpecificParameter, mapOfOutputParameter, mapOfStringObject);
-		} catch (final IOException aException) {
-		
+		} catch (final UnsupportedMimeTypeException aException) {
+			if (mapOfOutputParameter.get("mimetype").equals("text/html")) {
+				Message mess = new Message(Message.Level.ERROR, "$message_unsupported_mime_type", null);
+				req.setAttribute("unicorn_message", mess);
+				(new IndexAction()).doGet(req, resp);
+				
+			}
 		} catch (final Exception aException) {
 			ObserveAction.logger.error("Exception : " + aException.getMessage(),
 					aException);

Index: Action.java
===================================================================
RCS file: /sources/public/2006/unicorn/src/org/w3c/unicorn/action/Action.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- Action.java	28 Aug 2009 12:40:09 -0000	1.2
+++ Action.java	4 Sep 2009 17:59:43 -0000	1.3
@@ -1,9 +1,76 @@
 package org.w3c.unicorn.action;
 
+import java.io.IOException;
+import java.net.URLConnection;
+import java.util.ArrayList;
+
+import javax.servlet.ServletException;
 import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.w3c.unicorn.Framework;
+import org.w3c.unicorn.util.Language;
+import org.w3c.unicorn.util.Message;
+import org.w3c.unicorn.util.Property;
 
 public abstract class Action extends HttpServlet {
 	
 	private static final long serialVersionUID = 1L;
+	
+	@Override
+	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+			throws ServletException, IOException {
+		
+		if (!Framework.isUcnInitialized) {
+			resp.sendError(500, "Unicorn is not initialized properly. Check logs.");
+			return;
+		}
+		
+		ArrayList<Message> messages = new ArrayList<Message>();
+		
+		String langParameter = req.getParameter(Property.get("UNICORN_PARAMETER_PREFIX") + "lang");
+		if (langParameter == null || !Framework.getLanguageProperties().containsKey(langParameter))
+			langParameter = Language.negociate(req.getLocales());
+		
+		if (!langParameter.equals(req.getLocale().getLanguage()))
+			messages.add(new Message(Message.Level.INFO, "$message_unavailable_language (" + req.getLocale().getDisplayLanguage(req.getLocale()) + "). $message_translation", null));
+		
+		if (!Language.isComplete(langParameter))
+			messages.add(new Message(Message.Level.INFO, "$message_incomplete_language. $message_translation", null));
+		
+		
+		
+		
+	}
+
+	protected String getQueryStringWithout(String parameterName, HttpServletRequest req) {
+		String query = req.getQueryString();
+		String queryString;
+		if (query == null) {
+			queryString = "./?";
+		} else {
+			queryString = "?";
+			queryString += query.replaceAll("&?" + parameterName + "=[^&]*", "");
+			if (!queryString.equals("?"))
+				queryString += "&";
+		}
+		return queryString;
+	}
+
+	@Override
+	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
+			throws ServletException, IOException {
+		// TODO Auto-generated method stub
+		super.doPost(req, resp);
+	}
+
+	@Override
+	public void init() throws ServletException {
+		// TODO Auto-generated method stub
+		super.init();
+	}
+	
+	
 
 }

Received on Friday, 4 September 2009 18:00:01 UTC