From: zapata Date: Sun, 9 Mar 2003 05:52:12 +0000 (+0000) Subject: internationalized user error messages X-Git-Tag: BEFORE_MERGE_1_1~231 X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=c50e1b4daf2cf34868b509382c525dd8849471a9;p=mir.git internationalized user error messages --- diff --git a/bundles/admin_en.properties b/bundles/admin_en.properties index aae640d5..15305c02 100755 --- a/bundles/admin_en.properties +++ b/bundles/admin_en.properties @@ -1,6 +1,6 @@ ########## admin ########## # language: english -# $Id: admin_en.properties,v 1.37 2003/03/05 04:33:29 zapata Exp $ +# $Id: admin_en.properties,v 1.38 2003/03/09 05:52:12 zapata Exp $ languagename=English @@ -385,6 +385,7 @@ articletypes.startspecial=Startpage-special # Comment status values commentstatus.normal=Normal + ########## error ########## error.htmltitle=the system caused an error @@ -392,11 +393,16 @@ error.title=The system caused an error error.text=This can happen. Even if the following error message is not be comprehensible for you, it might be helpful to {1}: error.text2=So please send an e-mail with the red text and detailed information regarding the events that led to this error to {1}. Thanks! -usererror.htmltitle=validation error -usererror.title=Validation error +usererror.htmltitle=User error +usererror.title=User error usererror.text=Your input caused the following error: usererror.what_to_do=Please press the back button and try it again +media.error.unsupportedformat=The format of the media you uploaded is not supported +user.error.missingpasswords=The new password must be entered twice +user.error.passwordmismatch=The passwords are not equal +user.error.missingpassword=A password must be entered + infomessage.htmltitle = Information infomessage.produceAllNewAddedToQueue = Your request has been added to the queue. diff --git a/etc/bundles/open_en.properties b/etc/bundles/open_en.properties index 6f5be33a..5a246314 100755 --- a/etc/bundles/open_en.properties +++ b/etc/bundles/open_en.properties @@ -5,35 +5,6 @@ langcode=en optional=optional required=required -comment.htmltitle=Mir | comment -comment.header=Adding a coment to an article -comment.password=Password -comment.note= -comment.formtitle=Comment -comment.title=title of this comment -comment.name=your name -comment.email=your eMail -comment.url=your web site address -comment.phone=your telephone number. -comment.address=your address -comment.language=language of your comment -comment.text=your comment -comment.submit=submit comment -comment.reset=reset form - -commentdone.htmltitle=Mir | open posting -commentdone.thanks=Your comment is on the way! -commentdone.wait=It will take some minutes until your addition appears under the article.
It may take even longer in case of technical problems.
-commentdone.criteria= -commentdone.stay_calm=Please wait a few minutes -commentdone.back=Back to the article - -commentdupe.htmltitle=Mir | open posting - duplicate entry -commentdupe.title=Stay calm. Things will happen soon. -commentdupe.explanation=You probably clicked on the reload button or submitted your comment a second time. The fact that you can read this text means that your comment has been recieved and will soon be included in the article page. -commentdupe.no_panic=Don't panic -commentdupe.back=Back to the article - posting.htmltitle=Mir | open posting posting.password=Password posting.meta.description=Mir CMS system @@ -70,6 +41,10 @@ posting.submit.info=Please press submit only once!
It will appear in a posting.criteria= posting.submit=Submit (patience is a virtue!) posting.reset=Form Reset +posting.error.missingpassword=The one-time password must be copied into the password field +posting.error.invalidpassword=The one-time password was not copied correctly into the password field +posting.error.missingfield=At least one field was not correctly entered +media.error.unsupportedformat=The format of the media you uploaded is not supported postingdone.htmltitle=open posting postingdone.title=You have successfully submitted your article @@ -83,6 +58,37 @@ postingdupe.explanation=You probably clicked on the reload button or submitted y postingdupe.no_panic=Don't panic postingdupe.back=Back +comment.htmltitle=Mir | comment +comment.header=Adding a coment to an article +comment.password=Password +comment.note= +comment.formtitle=Comment +comment.title=title of this comment +comment.name=your name +comment.email=your eMail +comment.url=your web site address +comment.phone=your telephone number. +comment.address=your address +comment.language=language of your comment +comment.text=your comment +comment.submit=submit comment +comment.reset=reset form +comment.error.missingpassword=The one-time password must be copied into the password field +comment.error.invalidpassword=The one-time password was not copied correctly into the password field + +commentdone.htmltitle=Mir | open posting +commentdone.thanks=Your comment is on the way! +commentdone.wait=It will take some minutes until your addition appears under the article.
It may take even longer in case of technical problems.
+commentdone.criteria= +commentdone.stay_calm=Please wait a few minutes +commentdone.back=Back to the article + +commentdupe.htmltitle=Mir | open posting - duplicate entry +commentdupe.title=Stay calm. Things will happen soon. +commentdupe.explanation=You probably clicked on the reload button or submitted your comment a second time. The fact that you can read this text means that your comment has been recieved and will soon be included in the article page. +commentdupe.no_panic=Don't panic +commentdupe.back=Back to the article + search.info=Results of your search: search.title=SEARCH search.htmltitle=MirSearch (powered by lucene) @@ -124,4 +130,9 @@ email.prepare.chooselanguage=The language you want the explanatory text of the f email.prepare.send=SEND email.sent.htmltitle=Email sent successfully email.sent.title=Your email has been sent -email.sent.text=The aticle has been forwarded to the specified address. \ No newline at end of file +email.sent.text=The article has been forwarded to the specified address. +email.error.invalidtoaddress=The address to send the article to is not valid +email.error.invalidfromaddress=Your email address is not valid + + + diff --git a/source/Mir.java b/source/Mir.java index 61ba5161..62ae28fc 100755 --- a/source/Mir.java +++ b/source/Mir.java @@ -46,6 +46,13 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; +import org.apache.struts.util.MessageResources; + +import freemarker.template.SimpleHash; +import freemarker.template.SimpleList; +import freemarker.template.SimpleScalar; +import freemarker.template.TemplateModel; + import mir.config.MirPropertiesConfiguration; import mir.generator.FreemarkerGenerator; import mir.log.LoggerWrapper; @@ -66,12 +73,6 @@ import mircoders.storage.DatabaseArticleType; import mircoders.storage.DatabaseMessages; import mircoders.storage.DatabaseUsers; -import org.apache.struts.util.MessageResources; - -import freemarker.template.SimpleHash; -import freemarker.template.SimpleList; -import freemarker.template.SimpleScalar; -import freemarker.template.TemplateModel; @@ -79,7 +80,7 @@ import freemarker.template.TemplateModel; * Mir.java - main servlet, that dispatches to servletmodules * * @author $Author: zapata $ - * @version $Id: Mir.java,v 1.36 2003/03/09 03:53:10 zapata Exp $ + * @version $Id: Mir.java,v 1.37 2003/03/09 05:52:12 zapata Exp $ * */ public class Mir extends AbstractServlet { @@ -356,20 +357,26 @@ public class Mir extends AbstractServlet { catch (Exception e) { throw new ServletModuleExc("*** error resolving classname for " + moduleName + " -- " + e.getMessage()); } - } else { + } + else { return (ServletModule) servletModuleInstanceHash.get(moduleName); } } private void handleUserError(HttpServletRequest aRequest, HttpServletResponse aResponse, - PrintWriter out, Throwable anException) { + PrintWriter out, ServletModuleUserExc anException) { try { logger.info("user error: " + anException.getMessage()); SimpleHash modelRoot = new SimpleHash(); - modelRoot.put("errorstring", new SimpleScalar(anException.getMessage())); + MessageResources messages = MessageResources.getMessageResources("bundles.admin"); + modelRoot.put("errorstring", + new SimpleScalar( + messages.getMessage(getLocale(aRequest), anException.getMessage(), anException.getParameters()) + )); modelRoot.put("date", new SimpleScalar(StringUtil.date2readableDateTime(new GregorianCalendar()))); - HTMLTemplateProcessor.process(aResponse,MirPropertiesConfiguration.instance().getString("Mir.UserErrorTemplate"), - modelRoot, out, aRequest.getLocale() ); + HTMLTemplateProcessor.process( + aResponse,MirPropertiesConfiguration.instance().getString("Mir.UserErrorTemplate"), + modelRoot, out, getLocale(aRequest)); out.close(); } catch (Exception e) { @@ -387,7 +394,7 @@ public class Mir extends AbstractServlet { modelRoot.put("date", new SimpleScalar(StringUtil.date2readableDateTime( new GregorianCalendar()))); HTMLTemplateProcessor.process(aResponse,MirPropertiesConfiguration.instance().getString("Mir.ErrorTemplate"), - modelRoot,out, aRequest.getLocale()); + modelRoot,out, getLocale(aRequest)); out.close(); } catch (Exception e) { diff --git a/source/OpenMir.java b/source/OpenMir.java index c3c6108e..3ba08b4c 100755 --- a/source/OpenMir.java +++ b/source/OpenMir.java @@ -39,6 +39,11 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; +import org.apache.struts.util.MessageResources; + +import freemarker.template.SimpleHash; +import freemarker.template.SimpleScalar; + import mir.config.MirPropertiesConfiguration; import mir.misc.HTMLTemplateProcessor; import mir.misc.StringUtil; @@ -47,14 +52,12 @@ import mir.servlet.ServletModuleDispatch; import mir.servlet.ServletModuleUserExc; import mir.util.ExceptionFunctions; import mircoders.servlet.ServletModuleOpenIndy; -import freemarker.template.SimpleHash; -import freemarker.template.SimpleScalar; /** * OpenMir.java - main servlet for open posting and comment feature to articles * * @author RK 1999-2001, the mir-coders group - * @version $Id: OpenMir.java,v 1.25 2003/03/09 03:53:10 zapata Exp $ + * @version $Id: OpenMir.java,v 1.26 2003/03/09 05:52:12 zapata Exp $ * */ @@ -109,14 +112,18 @@ public class OpenMir extends AbstractServlet { } private void handleUserError(HttpServletRequest aRequest, HttpServletResponse aResponse, - PrintWriter out, Throwable anException) { + PrintWriter out, ServletModuleUserExc anException) { try { logger.info("user error: " + anException.getMessage()); SimpleHash modelRoot = new SimpleHash(); - modelRoot.put("errorstring", new SimpleScalar(anException.getMessage())); + MessageResources messages = MessageResources.getMessageResources("bundles.open"); + modelRoot.put("errorstring", + new SimpleScalar( + messages.getMessage(getLocale(aRequest), anException.getMessage(), anException.getParameters()) + )); modelRoot.put("date", new SimpleScalar(StringUtil.date2readableDateTime(new GregorianCalendar()))); HTMLTemplateProcessor.process(aResponse,MirPropertiesConfiguration.instance().getString("ServletModule.OpenIndy.UserErrorTemplate"), - modelRoot, out, aRequest.getLocale() ); + modelRoot, out, getLocale(aRequest)); out.close(); } catch (Exception e) { @@ -128,11 +135,12 @@ public class OpenMir extends AbstractServlet { try { logger.error("error: " + anException); SimpleHash modelRoot = new SimpleHash(); + modelRoot.put("errorstring", new SimpleScalar(anException.getMessage())); modelRoot.put("date", new SimpleScalar(StringUtil.date2readableDateTime( new GregorianCalendar()))); HTMLTemplateProcessor.process(aResponse,MirPropertiesConfiguration.instance().getString("ServletModule.OpenIndy.ErrorTemplate"), - modelRoot,out, aRequest.getLocale()); + modelRoot,out, getLocale(aRequest)); out.close(); } catch (Exception e) { diff --git a/source/mir/servlet/ServletModuleUserExc.java b/source/mir/servlet/ServletModuleUserExc.java index 5d42ff30..7eacef03 100755 --- a/source/mir/servlet/ServletModuleUserExc.java +++ b/source/mir/servlet/ServletModuleUserExc.java @@ -32,9 +32,18 @@ package mir.servlet; import multex.Exc; +/** + * + *

Title: ServletModuleUserExc

+ *

Description:

+ *

Copyright: Copyright (c) 2003

+ *

Company:

+ * @author Zapata + * @version 1.0 + */ public class ServletModuleUserExc extends Exc { - public ServletModuleUserExc(String aMessage) { - super(aMessage); + public ServletModuleUserExc(String aMessageName, String[] aParameterArray) { + super(aMessageName, aParameterArray); } } diff --git a/source/mir/storage/store/StoreContainer.java b/source/mir/storage/store/StoreContainer.java index 7ab20735..fcff1f6d 100755 --- a/source/mir/storage/store/StoreContainer.java +++ b/source/mir/storage/store/StoreContainer.java @@ -52,6 +52,7 @@ import java.util.ListIterator; import javax.servlet.http.HttpServletRequest; import mir.misc.StringUtil; +import mir.log.LoggerWrapper; public class StoreContainer { private final static int DEFAULT_SIZE = 10; @@ -64,9 +65,12 @@ public class StoreContainer { private int hitCount = 0, missCount = 0; private static ObjectStore o_store = ObjectStore.getInstance(); + protected LoggerWrapper logger = new LoggerWrapper("Database.ObjectStore"); + // avoid construction without parameters private StoreContainer() {}; + public StoreContainer(StoreContainerType stoc_type) { this.uniqueId = ++uniqueCounter; this.stocType = stoc_type; @@ -105,8 +109,7 @@ public class StoreContainer { if (sid != null && sid.hasReference()) { if (has(sid)) { moveToHead(sid); - System.err.println("OBJECTStore: tried to add sid " + sid.toString() + - " that was already in store."); + logger.error("OBJECTStore: tried to add sid " + sid.toString() + " that was already in store."); } else { container.addFirst(sid); diff --git a/source/mir/storage/store/StoreIdentifier.java b/source/mir/storage/store/StoreIdentifier.java index 6aa40926..91949aa7 100755 --- a/source/mir/storage/store/StoreIdentifier.java +++ b/source/mir/storage/store/StoreIdentifier.java @@ -47,6 +47,7 @@ import java.util.Iterator; import java.util.Set; import mir.entity.EntityList; +import mir.log.LoggerWrapper; public class StoreIdentifier { @@ -61,6 +62,8 @@ public class StoreIdentifier { private long timesUsed; private boolean invalidating = false; + protected LoggerWrapper logger = new LoggerWrapper("Database.ObjectStore"); + /** @todo initialize logfile */ private StoreIdentifier() {} @@ -97,14 +100,13 @@ public class StoreIdentifier { * @return */ public void invalidate() { - System.out.println("Invalidating: " + toString()); + logger.info("Invalidating: " + toString()); // avoid deadlock due to propagation. if (!invalidating) { invalidating = true; if (stocType != null && stocType.getStocType() == StoreContainerType.STOC_TYPE_ENTITY) { - System.out.println("Propagating invalidation to EntityList for " + - toString()); + logger.info("Propagating invalidation to EntityList for " + toString()); // we should invalidate related ENTITY_LIST StoreContainerType entityListStocType = StoreContainerType.valueOf(stocType.getStocClass(), @@ -118,14 +120,12 @@ public class StoreIdentifier { for (Iterator it = set.iterator(); it.hasNext(); ) { Object o = it.next(); if (o instanceof StoreIdentifier) { - System.out.println("Propagating invalidation to StoreIdentifier: " + - o.toString()); + logger.info("Propagating invalidation to StoreIdentifier: " + o.toString()); // propagate invalidation to a specific StoreIdentifier in cache o_store.invalidate( (StoreIdentifier) o); } else if (o instanceof StoreContainerType) { - System.out.println("Propagating invalidation to StoreContainer: " + - o.toString()); + logger.info("Propagating invalidation to StoreContainer: " + o.toString()); // propagate invalidation to a whole StoreContainer o_store.invalidate( (StoreContainerType) o); } diff --git a/source/mircoders/servlet/ServletModuleOpenIndy.java b/source/mircoders/servlet/ServletModuleOpenIndy.java index fd522dd9..b87c5d14 100755 --- a/source/mircoders/servlet/ServletModuleOpenIndy.java +++ b/source/mircoders/servlet/ServletModuleOpenIndy.java @@ -119,7 +119,7 @@ import mircoders.storage.DatabaseTopics; * open-postings to the newswire * * @author mir-coders group - * @version $Id: ServletModuleOpenIndy.java,v 1.65 2003/03/09 03:53:12 zapata Exp $ + * @version $Id: ServletModuleOpenIndy.java,v 1.66 2003/03/09 05:52:13 zapata Exp $ * */ @@ -239,11 +239,14 @@ public class ServletModuleOpenIndy extends ServletModule HttpSession session = req.getSession(false); String sessionPasswd = (String)session.getAttribute("passwd"); if ( sessionPasswd == null){ - throw new ServletModuleUserExc("Lost password"); + throw new ServletModuleExc("Lost password"); } String passwd = req.getParameter("passwd"); - if ( passwd == null || (!sessionPasswd.equals(passwd))) { - throw new ServletModuleUserExc("Missing password"); + if ( passwd == null || passwd.length()==0) { + throw new ServletModuleUserExc("comment.error.missingpassword", new String[] {}); + } + if (!sessionPasswd.equals(passwd)) { + throw new ServletModuleUserExc("comment.error.invalidpassword", new String[] {}); } session.invalidate(); } @@ -254,7 +257,8 @@ public class ServletModuleOpenIndy extends ServletModule //insert was not successfull if(id==null){ deliver(req, res, new SimpleHash(), commentFormDupeTemplate); - } else { + } + else { DatabaseContent.getInstance().setUnproduced("id="+aid); try { @@ -339,8 +343,7 @@ public class ServletModuleOpenIndy extends ServletModule * the postingDone Page */ - public void insposting(HttpServletRequest req, HttpServletResponse res) - throws ServletModuleExc, ServletModuleUserExc, ServletModuleFailure + public void insposting(HttpServletRequest req, HttpServletResponse res) throws ServletModuleExc, ServletModuleUserExc, ServletModuleFailure { SimpleHash mergeData = new SimpleHash(); boolean setMedia=false; @@ -367,11 +370,14 @@ public class ServletModuleOpenIndy extends ServletModule HttpSession session = req.getSession(false); String sessionPasswd = (String)session.getAttribute("passwd"); if ( sessionPasswd == null){ - throw new ServletModuleUserExc("Lost password"); + throw new ServletModuleExc("Lost password"); } String passwd = (String)withValues.get("passwd"); - if ( passwd == null || (!sessionPasswd.equals(passwd))) { - throw new ServletModuleUserExc("Missing password"); + if ( passwd == null || passwd.length()==0) { + throw new ServletModuleUserExc("posting.error.missingpassword", new String[] {}); + } + if (!sessionPasswd.equals(passwd)) { + throw new ServletModuleUserExc("posting.error.invalidpassword", new String[] {}); } session.invalidate(); } @@ -379,7 +385,7 @@ public class ServletModuleOpenIndy extends ServletModule if ((((String)withValues.get("title")).length() == 0) || (((String)withValues.get("description")).length() == 0) || (((String)withValues.get("content_data")).length() == 0)) - throw new ServletModuleUserExc("Missing field"); + throw new ServletModuleUserExc("posting.error.missingfield", new String[] {}); // call the routines that escape html @@ -464,7 +470,7 @@ public class ServletModuleOpenIndy extends ServletModule Throwable cause = ExceptionFunctions.traceCauseException(e); if (cause instanceof UnsupportedMediaFormatExc) { - throw new ServletModuleUserExc("Unsupported media format"); + throw new ServletModuleUserExc("media.unsupportedformat", new String[] {} ); } throw new ServletModuleFailure(e); } @@ -481,7 +487,7 @@ public class ServletModuleOpenIndy extends ServletModule { String aid = req.getParameter("mail_aid"); if (aid == null){ - throw new ServletModuleUserExc("An article id must be specified in requests to email an article. Something therefore went badly wrong...."); + throw new ServletModuleExc("An article id must be specified in requests to email an article. Something therefore went badly wrong...."); } String to = req.getParameter("mail_to"); @@ -504,17 +510,19 @@ public class ServletModuleOpenIndy extends ServletModule } else { //run checks on to and from and mail_language to make sure no monkey business occurring - if (mail_language.indexOf('.') != -1 || mail_language.indexOf('/') != -1 ){ - throw new ServletModuleUserExc("Sorry, you've entered an illegal character into the language field. Go back and try again, asshole."); + if (mail_language.indexOf('.') != -1 || mail_language.indexOf('/') != -1 ) { + throw new ServletModuleExc("Invalid language"); } if (to.indexOf('\n') != -1 || to.indexOf('\r') != -1 - || to.indexOf(',') != -1 - || from.indexOf('\n') != -1 - || from.indexOf('\r') != -1 - || from.indexOf(',') != -1 ){ - throw new ServletModuleUserExc("Sorry, you've entered an illegal character into the from or to field. Go back and try again."); + || to.indexOf(',') != -1) { + throw new ServletModuleUserExc("email.error.invalidtoaddress", new String[] {to}); + } + if (from.indexOf('\n') != -1 || from.indexOf('\r') != -1 || from.indexOf(',') != -1 ) { + throw new ServletModuleUserExc("email.error.invalidfromaddress", new String[] {from}); } + + EntityContent contentEnt; try{ contentEnt = (EntityContent)contentModule.getById(aid); @@ -925,7 +933,7 @@ public class ServletModuleOpenIndy extends ServletModule res.getOutputStream().flush(); } else { - throw new ServletModuleUserExc("Missing id parameter."); + throw new ServletModuleExc("Missing id."); } } catch (Exception ex) { diff --git a/source/mircoders/servlet/ServletModuleUploadedMedia.java b/source/mircoders/servlet/ServletModuleUploadedMedia.java index 0c159938..e74ada6f 100755 --- a/source/mircoders/servlet/ServletModuleUploadedMedia.java +++ b/source/mircoders/servlet/ServletModuleUploadedMedia.java @@ -72,7 +72,7 @@ import mircoders.storage.DatabaseMediafolder; * ServletModuleBilder - * liefert HTML fuer Bilder * - * @version $Id: ServletModuleUploadedMedia.java,v 1.21 2003/03/09 03:53:12 zapata Exp $ + * @version $Id: ServletModuleUploadedMedia.java,v 1.22 2003/03/09 05:52:13 zapata Exp $ * @author RK, the mir-coders group */ @@ -137,7 +137,7 @@ public abstract class ServletModuleUploadedMedia Throwable cause = ExceptionFunctions.traceCauseException(t); if (cause instanceof UnsupportedMediaFormatExc) { - throw new ServletModuleUserExc("Unsupported media format"); + throw new ServletModuleUserExc("media.error.unsupportedformat", new String[] {}); } throw new ServletModuleFailure("ServletModuleUploadedMedia.insert: " + t.toString(), t); } diff --git a/source/mircoders/servlet/ServletModuleUsers.java b/source/mircoders/servlet/ServletModuleUsers.java index 1ad22ea8..80874323 100755 --- a/source/mircoders/servlet/ServletModuleUsers.java +++ b/source/mircoders/servlet/ServletModuleUsers.java @@ -115,11 +115,11 @@ public class ServletModuleUsers extends ServletModule String newPassword2 = aRequestParser.getParameterWithDefault("newpassword2", ""); if (newPassword.length() == 0 || newPassword2.length() == 0) { - throw new ServletModuleUserExc("The new password must be entered twice!"); + throw new ServletModuleUserExc("user.error.missingpasswords", new String[] {}); } if (!newPassword.equals(newPassword2)) { - throw new ServletModuleUserExc("New password differes from confirmation"); + throw new ServletModuleUserExc("user.error.passwordmismatch", new String[] {}); } return newPassword; @@ -139,7 +139,7 @@ public class ServletModuleUsers extends ServletModule if (newPassword!=null) withValues.put("password", newPassword); else - throw new ServletModuleUserExc("Password is empty"); + throw new ServletModuleUserExc("user.error.missingpassword", new String[] {}); String id = mainModule.add(withValues); if (requestParser.hasParameter("returnurl"))