Changeset 286:001ecebe946a
- Timestamp:
- 09/04/09 17:59:43 (4 years ago)
- Branch:
- default
- convert_revision:
- svn:cdcfb263-7567-472c-a848-e2c2df3466e7/trunk@287
- Location:
- src/org/w3c/unicorn/action
- Files:
-
- 3 modified
-
Action.java (modified) (1 diff)
-
IndexAction.java (modified) (6 diffs)
-
ObserveAction.java (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/org/w3c/unicorn/action/Action.java
r214 r286 1 1 package org.w3c.unicorn.action; 2 2 3 import java.io.IOException; 4 import java.net.URLConnection; 5 import java.util.ArrayList; 6 7 import javax.servlet.ServletException; 3 8 import javax.servlet.http.HttpServlet; 9 import javax.servlet.http.HttpServletRequest; 10 import javax.servlet.http.HttpServletResponse; 11 12 import org.w3c.unicorn.Framework; 13 import org.w3c.unicorn.util.Language; 14 import org.w3c.unicorn.util.Message; 15 import org.w3c.unicorn.util.Property; 4 16 5 17 public abstract class Action extends HttpServlet { 6 18 7 19 private static final long serialVersionUID = 1L; 20 21 @Override 22 protected void doGet(HttpServletRequest req, HttpServletResponse resp) 23 throws ServletException, IOException { 24 25 if (!Framework.isUcnInitialized) { 26 resp.sendError(500, "Unicorn is not initialized properly. Check logs."); 27 return; 28 } 29 30 ArrayList<Message> messages = new ArrayList<Message>(); 31 32 String langParameter = req.getParameter(Property.get("UNICORN_PARAMETER_PREFIX") + "lang"); 33 if (langParameter == null || !Framework.getLanguageProperties().containsKey(langParameter)) 34 langParameter = Language.negociate(req.getLocales()); 35 36 if (!langParameter.equals(req.getLocale().getLanguage())) 37 messages.add(new Message(Message.Level.INFO, "$message_unavailable_language (" + req.getLocale().getDisplayLanguage(req.getLocale()) + "). $message_translation", null)); 38 39 if (!Language.isComplete(langParameter)) 40 messages.add(new Message(Message.Level.INFO, "$message_incomplete_language. $message_translation", null)); 41 42 43 44 45 } 46 47 protected String getQueryStringWithout(String parameterName, HttpServletRequest req) { 48 String query = req.getQueryString(); 49 String queryString; 50 if (query == null) { 51 queryString = "./?"; 52 } else { 53 queryString = "?"; 54 queryString += query.replaceAll("&?" + parameterName + "=[^&]*", ""); 55 if (!queryString.equals("?")) 56 queryString += "&"; 57 } 58 return queryString; 59 } 60 61 @Override 62 protected void doPost(HttpServletRequest req, HttpServletResponse resp) 63 throws ServletException, IOException { 64 // TODO Auto-generated method stub 65 super.doPost(req, resp); 66 } 67 68 @Override 69 public void init() throws ServletException { 70 // TODO Auto-generated method stub 71 super.init(); 72 } 73 74 8 75 9 76 } -
src/org/w3c/unicorn/action/IndexAction.java
r265 r286 1 // $Id: IndexAction.java,v 1.11 2009-09-04 17:59:43 tgambet Exp $Id $ 2 // Author: Thomas Gambet 3 // (c) COPYRIGHT MIT, ERCIM and Keio, 2009. 4 // Please first read the full copyright statement in file COPYRIGHT.html 1 5 package org.w3c.unicorn.action; 2 6 … … 8 12 import javax.servlet.http.HttpServletResponse; 9 13 14 import org.apache.commons.logging.Log; 15 import org.apache.commons.logging.LogFactory; 10 16 import org.apache.velocity.VelocityContext; 11 17 import org.w3c.unicorn.Framework; … … 17 23 public class IndexAction extends Action { 18 24 19 private static final long serialVersionUID = 1L; 25 private static final long serialVersionUID = 599055553694915687L; 26 27 private static Log logger = LogFactory.getLog(IndexAction.class); 28 20 29 private VelocityContext velocityContext; 21 30 22 31 @Override 23 32 public void init() throws ServletException { 24 super.init(); 33 //logger.trace("Init IndexAction"); 34 //super.init(); 25 35 } 26 36 … … 41 51 if (langParameter == null || !Framework.getLanguageProperties().containsKey(langParameter)) { 42 52 langParameter = Language.negociate(req.getLocales()); 43 if (!langParameter.equals(req.getLocale().getLanguage())) { 44 messages.add(new Message(Message.Level.INFO, "$message_unavailable_language (" + req.getLocale().getDisplayLanguage(req.getLocale()) + "). $message_translation", null)); 45 } else { 46 String requested_parameter = req.getParameter(Property.get("UNICORN_PARAMETER_PREFIX") + "lang"); 47 if (requested_parameter != null && !Framework.getLanguageProperties().containsKey(requested_parameter)) 48 messages.add(new Message(Message.Level.INFO, "$message_unavailable_requested_language. $message_translation", null)); 49 } 53 } 54 55 if (!langParameter.equals(req.getLocale().getLanguage())) { 56 messages.add(new Message(Message.Level.INFO, "$message_unavailable_language (" + req.getLocale().getDisplayLanguage(req.getLocale()) + "). $message_translation", null)); 50 57 } 51 58 … … 55 62 velocityContext = new VelocityContext(Language.getContext(langParameter)); 56 63 57 String query = req.getQueryString(); 64 velocityContext.put("queryString", getQueryStringWithout(Property.get("UNICORN_PARAMETER_PREFIX") + "lang", req)); 65 66 /*String query = req.getQueryString(); 58 67 String queryString; 59 68 if (query == null) { … … 72 81 if (!queryString.equals("?")) 73 82 queryString += "&";*/ 74 velocityContext.put("queryString", queryString);83 //velocityContext.put("queryString", queryString); 75 84 76 85 /*messages.add(new Message(Message.Level.WARNING, "un warning", null)); -
src/org/w3c/unicorn/action/ObserveAction.java
r265 r286 1 // $Id: ObserveAction.java,v 1.1 1 2009-09-03 14:04:12tgambet Exp $1 // $Id: ObserveAction.java,v 1.12 2009-09-04 17:59:43 tgambet Exp $ 2 2 // Author: Jean-Guilhem Rouel 3 3 // (c) COPYRIGHT MIT, ERCIM and Keio, 2006. … … 33 33 import org.w3c.unicorn.UnicornCall; 34 34 import org.w3c.unicorn.contract.EnumInputMethod; 35 import org.w3c.unicorn.exceptions.UnsupportedMimeTypeException; 35 36 import org.w3c.unicorn.output.OutputFactory; 36 37 import org.w3c.unicorn.output.OutputFormater; … … 46 47 * @author Jean-Guilhem ROUEL 47 48 */ 48 public class ObserveAction extends HttpServlet { 49 50 private static final Log logger = LogFactory.getLog(ObserveAction.class); 49 public class ObserveAction extends Action { 51 50 52 51 private static final long serialVersionUID = -1375355420965607571L; 53 54 private static final DiskFileItemFactory factory = new DiskFileItemFactory(); 52 53 private static Log logger = LogFactory.getLog(ObserveAction.class); 54 55 private static DiskFileItemFactory factory; 55 56 56 57 /** 57 58 * Creates a new file upload handler. 58 59 */ 59 private static final ServletFileUpload upload = new ServletFileUpload( 60 ObserveAction.factory); 60 private static ServletFileUpload upload; 61 61 62 62 /* … … 66 66 */ 67 67 @Override 68 public void init(final ServletConfig aServletConfig) 69 throws ServletException { 70 ObserveAction.logger.trace("init"); 71 72 ObserveAction.factory.setRepository(new File(Property 73 .get("UPLOADED_FILES_REPOSITORY"))); 74 68 public void init(final ServletConfig aServletConfig) throws ServletException { 69 logger.trace("Init ObserverAction"); 70 super.init(); 71 72 factory = new DiskFileItemFactory(); 73 factory.setRepository(new File(Property.get("UPLOADED_FILES_REPOSITORY"))); 74 upload = new ServletFileUpload(factory); 75 logger.debug("Created a ServletFileUpload with repository set to: " + Property.get("UPLOADED_FILES_REPOSITORY")); 75 76 } 76 77 … … 166 167 this.createOutput(resp, aUnicornCall, 167 168 mapOfSpecificParameter, mapOfOutputParameter, mapOfStringObject); 169 } catch (final UnsupportedMimeTypeException aException) { 170 if (mapOfOutputParameter.get("mimetype").equals("text/html")) { 171 Message mess = new Message(Message.Level.ERROR, "$message_unsupported_mime_type", null); 172 req.setAttribute("unicorn_message", mess); 173 (new IndexAction()).doGet(req, resp); 174 175 } 168 176 } catch (final Exception aException) { 169 177 ObserveAction.logger.error("Exception : " + aException.getMessage(), … … 291 299 this.createOutput(resp, aUnicornCall, 292 300 mapOfSpecificParameter, mapOfOutputParameter, mapOfStringObject); 293 } catch (final IOException aException) { 294 301 } catch (final UnsupportedMimeTypeException aException) { 302 if (mapOfOutputParameter.get("mimetype").equals("text/html")) { 303 Message mess = new Message(Message.Level.ERROR, "$message_unsupported_mime_type", null); 304 req.setAttribute("unicorn_message", mess); 305 (new IndexAction()).doGet(req, resp); 306 307 } 295 308 } catch (final Exception aException) { 296 309 ObserveAction.logger.error("Exception : " + aException.getMessage(),
