From 78bab1222b4ad3739e298ebf911141ab33184af4 Mon Sep 17 00:00:00 2001 From: rkv Date: Thu, 29 Nov 2012 13:12:31 +0000 Subject: [PATCH] Fix for the bug: urls to documents in the repository are cached for all users with server name taken from the first request. --- Workspace/Siman/WebContent/jsp/menuitem.jsp | 2 +- .../WebContent/study/searchKnowledge.jsp | 24 +- .../Siman/WebContent/study/searchStudy.jsp | 24 +- .../org/splat/simer/AbstractOpenObject.java | 16 +- .../splat/simer/AbstractSearchBaseAction.java | 17 +- .../Siman/src/org/splat/simer/Action.java | 4 +- .../org/splat/simer/ApplicationSettings.java | 514 +++++++++--------- .../Siman/src/org/splat/simer/Converter.java | 3 +- .../splat/simer/DisplayStudyStepAction.java | 117 ++-- .../src/org/splat/simer/DocumentFacade.java | 196 ++++--- .../Siman/src/org/splat/simer/FileFacade.java | 99 ++-- .../splat/simer/KnowledgeElementFacade.java | 30 +- .../Siman/src/org/splat/simer/MenuAction.java | 2 +- .../src/org/splat/simer/OpenKnowledge.java | 3 +- .../Siman/src/org/splat/simer/OpenStudy.java | 14 +- .../splat/simer/SimulationContextFacade.java | 10 +- .../src/org/splat/simer/StampFacade.java | 9 +- .../src/org/splat/simer/StartAction.java | 17 +- .../splat/simer/StudyPropertiesAction.java | 212 +++++--- .../src/org/splat/simer/ValidationFacade.java | 38 +- .../simer/admin/SimulationContextAction.java | 2 +- .../Siman/src/spring/applicationContext.xml | 2 +- 22 files changed, 745 insertions(+), 610 deletions(-) diff --git a/Workspace/Siman/WebContent/jsp/menuitem.jsp b/Workspace/Siman/WebContent/jsp/menuitem.jsp index 57f88f8..5d01a89 100644 --- a/Workspace/Siman/WebContent/jsp/menuitem.jsp +++ b/Workspace/Siman/WebContent/jsp/menuitem.jsp @@ -5,9 +5,9 @@ <%@ page import="org.splat.wapp.Menu"%> <%@ page import="org.splat.wapp.MenuItem"%> <%@ page import="org.splat.simer.Action"%> +<%@page import="com.opensymphony.xwork2.ActionContext"%> <%@ taglib prefix="s" uri="/struts-tags"%> - <%@page import="com.opensymphony.xwork2.ActionContext"%> diff --git a/Workspace/Siman/WebContent/study/searchKnowledge.jsp b/Workspace/Siman/WebContent/study/searchKnowledge.jsp index 93b8fcb..5be4186 100644 --- a/Workspace/Siman/WebContent/study/searchKnowledge.jsp +++ b/Workspace/Siman/WebContent/study/searchKnowledge.jsp @@ -1,15 +1,15 @@ -<%@ page language="java" contentType="text/html; charset=ISO-8859-1" +<%@page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" %> -<%@ page import="org.splat.dal.bo.som.KnowledgeElement"%> -<%@ page import="org.splat.som.ApplicationRights"%> -<%@ page import="org.splat.simer.ApplicationSettings"%> -<%@ page import="java.util.ResourceBundle"%> -<%@ page import="java.util.Calendar"%> -<%@ page import="java.text.SimpleDateFormat"%> -<%@ - taglib prefix="s" uri="/struts-tags" -%> +<%@page import="org.splat.dal.bo.som.KnowledgeElement"%> +<%@page import="org.splat.som.ApplicationRights"%> +<%@page import="org.splat.simer.ApplicationSettings"%> +<%@page import="java.util.ResourceBundle"%> +<%@page import="java.util.Calendar"%> +<%@page import="java.text.SimpleDateFormat"%> +<%@page import="org.splat.simer.Action"%> +<%@page import="com.opensymphony.xwork2.ActionContext"%> +<%@taglib prefix="s" uri="/struts-tags"%> <% ApplicationRights rights = (ApplicationRights)session.getAttribute("user.rights"); - ResourceBundle locale = ResourceBundle.getBundle("som", ApplicationSettings.getCurrentLocale()); + Action anAction = (Action)ActionContext.getContext().getActionInvocation().getAction(); + ResourceBundle locale = ResourceBundle.getBundle("som", + anAction.getApplicationSettings().getCurrentLocale()); String format = locale.getString("date.format"); SimpleDateFormat tostring = new SimpleDateFormat(format); String result = "uptodate"; diff --git a/Workspace/Siman/WebContent/study/searchStudy.jsp b/Workspace/Siman/WebContent/study/searchStudy.jsp index ef8461f..f62b825 100644 --- a/Workspace/Siman/WebContent/study/searchStudy.jsp +++ b/Workspace/Siman/WebContent/study/searchStudy.jsp @@ -1,15 +1,15 @@ -<%@ page language="java" contentType="text/html; charset=ISO-8859-1" +<%@page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" %> -<%@ page import="org.splat.dal.bo.som.Study"%> -<%@ page import="org.splat.som.ApplicationRights"%> -<%@ page import="org.splat.simer.ApplicationSettings"%> -<%@ page import="java.util.ResourceBundle"%> -<%@ page import="java.util.Calendar"%> -<%@ page import="java.text.SimpleDateFormat"%> -<%@ - taglib prefix="s" uri="/struts-tags" -%> +<%@page import="org.splat.dal.bo.som.Study"%> +<%@page import="org.splat.som.ApplicationRights"%> +<%@page import="org.splat.simer.ApplicationSettings"%> +<%@page import="java.util.ResourceBundle"%> +<%@page import="java.util.Calendar"%> +<%@page import="java.text.SimpleDateFormat"%> +<%@page import="org.splat.simer.Action"%> +<%@page import="com.opensymphony.xwork2.ActionContext"%> +<%@taglib prefix="s" uri="/struts-tags"%> <% ApplicationRights rights = (ApplicationRights)session.getAttribute("user.rights"); - ResourceBundle locale = ResourceBundle.getBundle("som", ApplicationSettings.getCurrentLocale()); + Action anAction = (Action)ActionContext.getContext().getActionInvocation().getAction(); + ResourceBundle locale = ResourceBundle.getBundle("som", + anAction.getApplicationSettings().getCurrentLocale()); String format = locale.getString("date.format"); SimpleDateFormat tostring = new SimpleDateFormat(format); String result = "uptodate"; diff --git a/Workspace/Siman/src/org/splat/simer/AbstractOpenObject.java b/Workspace/Siman/src/org/splat/simer/AbstractOpenObject.java index 43a0391..5b67ecd 100644 --- a/Workspace/Siman/src/org/splat/simer/AbstractOpenObject.java +++ b/Workspace/Siman/src/org/splat/simer/AbstractOpenObject.java @@ -30,8 +30,14 @@ import org.splat.wapp.PopupMenu; */ public abstract class AbstractOpenObject implements Proxy { - protected static Map docpres = null; - protected static Map knowpres = null; + /** + * Current open study step cache for presented documents. + */ + protected Map docpres = null; + /** + * Current open study step cache for presented knowledges. + */ + protected Map knowpres = null; /** * Connected user. @@ -303,7 +309,8 @@ public abstract class AbstractOpenObject implements Proxy { .getIndex()); if (facade == null) { facade = new KnowledgeElementFacade(BeanHelper - .copyBean(current, KnowledgeElementDTO.class)); + .copyBean(current, KnowledgeElementDTO.class), + getApplicationSettings()); knowpres.put(current.getIndex(), facade); } display.add(facade); @@ -329,7 +336,8 @@ public abstract class AbstractOpenObject implements Proxy { DocumentFacade facade = docpres.get(index); if (facade == null) { facade = new DocumentFacade(this, present, - getProjectSettings(), getPublicationService()); + getProjectSettings(), getPublicationService(), + getApplicationSettings()); docpres.put(index, facade); } _contents.add(facade); diff --git a/Workspace/Siman/src/org/splat/simer/AbstractSearchBaseAction.java b/Workspace/Siman/src/org/splat/simer/AbstractSearchBaseAction.java index f62ade4..c966268 100644 --- a/Workspace/Siman/src/org/splat/simer/AbstractSearchBaseAction.java +++ b/Workspace/Siman/src/org/splat/simer/AbstractSearchBaseAction.java @@ -22,7 +22,7 @@ public abstract class AbstractSearchBaseAction extends Action { * Serial version ID. */ private static final long serialVersionUID = 7863055790228544510L; - + /** * Search result key in the session. */ @@ -124,8 +124,8 @@ public abstract class AbstractSearchBaseAction extends Action { _newtype = getSimulationContextService().selectType( Integer.valueOf(_ctype)); - _newvalue = getSimulationContextService().selectSimulationContextsWhere( - sprop.setType(_newtype)); + _newvalue = getSimulationContextService() + .selectSimulationContextsWhere(sprop.setType(_newtype)); if (_cindex.length() > 0 && Integer.valueOf(_cindex) == 0) { getSession().remove(RESULT_KEY); } else { @@ -226,7 +226,8 @@ public abstract class AbstractSearchBaseAction extends Action { ApplicationRights he = new ApplicationRights(next); if (he.canCreateStudy()) { if (next.equals(me)) { - _candidates.add(0, new ValidationFacade.ByManager(me)); + _candidates.add(0, new ValidationFacade.ByManager(me, + getApplicationSettings().getCurrentLocale())); } else { _candidates.add(next); } @@ -234,7 +235,8 @@ public abstract class AbstractSearchBaseAction extends Action { } } - protected void setContextTypeOptions(final List critext) { + protected void setContextTypeOptions( + final List critext) { for (Iterator i = _context.iterator(); i.hasNext();) { critext.remove(i.next().getType()); // Already used context type } @@ -298,6 +300,7 @@ public abstract class AbstractSearchBaseAction extends Action { /** * Get the userService. + * * @return the userService */ public UserService getUserService() { @@ -306,7 +309,9 @@ public abstract class AbstractSearchBaseAction extends Action { /** * Set the userService. - * @param userService the userService to set + * + * @param userService + * the userService to set */ public void setUserService(final UserService userService) { _userService = userService; diff --git a/Workspace/Siman/src/org/splat/simer/Action.java b/Workspace/Siman/src/org/splat/simer/Action.java index f2848e7..a6eb8c3 100644 --- a/Workspace/Siman/src/org/splat/simer/Action.java +++ b/Workspace/Siman/src/org/splat/simer/Action.java @@ -117,7 +117,7 @@ public class Action extends ActionSupport implements ServletRequestAware, */ public int compare(final DocumentType t1, final DocumentType t2) { ResourceBundle locale = ResourceBundle.getBundle("som", - ApplicationSettings.getCurrentLocale()); + getApplicationSettings().getCurrentLocale()); String name1 = t1.getName(); if (t1.isApproved()) { name1 = locale.getString("type.document." + name1); @@ -144,7 +144,7 @@ public class Action extends ActionSupport implements ServletRequestAware, public int compare(final SimulationContextType t1, final SimulationContextType t2) { ResourceBundle locale = ResourceBundle.getBundle("som", - ApplicationSettings.getCurrentLocale()); + getApplicationSettings().getCurrentLocale()); String name1 = t1.getName(); if (t1.isApproved()) { name1 = locale.getString("type.context." + name1); diff --git a/Workspace/Siman/src/org/splat/simer/ApplicationSettings.java b/Workspace/Siman/src/org/splat/simer/ApplicationSettings.java index 0c30875..0445fc5 100644 --- a/Workspace/Siman/src/org/splat/simer/ApplicationSettings.java +++ b/Workspace/Siman/src/org/splat/simer/ApplicationSettings.java @@ -12,7 +12,7 @@ import java.util.Map; import java.util.Properties; import java.util.Set; -import javax.servlet.ServletContext; +import javax.servlet.http.HttpServletRequest; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; @@ -34,7 +34,8 @@ import org.splat.wapp.PopupItem; import org.splat.wapp.PopupMenu; import org.splat.wapp.SimpleMenu; import org.splat.wapp.ToolBar; -import org.springframework.web.context.ServletContextAware; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.NodeList; @@ -42,18 +43,89 @@ import org.w3c.dom.NodeList; /** * SIMAN project settings service. Provides settings according to XML customization. */ -public class ApplicationSettings implements ServletContextAware { +public class ApplicationSettings { /** * Application settings logger. */ protected final static Logger LOG = Logger .getLogger(ApplicationSettings.class); - /** - * Singleton instance of application settings service. + * JNDI context for launching converters. + */ + private transient static final Properties _jndprops; + /** + * Siman web application name. */ - private static final ApplicationSettings MY_APP = new ApplicationSettings(); + private transient static String _wappname; + /** + * General properties from the application properties files. + */ + private transient static final Properties _wapprops = new Properties(); + /** + * Siman web application root path on the server. + */ + private transient static String _wapproot; + /** + * Available template files. + */ + private transient static Map _tempfile; + /** + * List of file extensions mapped to a viewer. + */ + private transient static String[] _viewermap; + /** + * Available document format converters. + */ + private transient static Map _convertmap; + + static { + synchronized (_wapprops) { + // Do common configuration for all users + + _jndprops = new Properties(); + _tempfile = new HashMap(); + _viewermap = new String[0]; + _convertmap = new HashMap(); + + ClassLoader cloader = Thread.currentThread() + .getContextClassLoader(); + HttpServletRequest curRequest = ((ServletRequestAttributes) RequestContextHolder + .currentRequestAttributes()).getRequest(); + String appname = curRequest.getContextPath(); + if (appname.startsWith("/")) { + _wappname = appname.substring(1); + } + // Set local path on the server to the application root. + _wapproot = curRequest.getSession().getServletContext() + .getRealPath("/"); + + try { + _jndprops.load(cloader.getResourceAsStream("jndi.properties")); + _wapprops.load(cloader.getResourceAsStream(_wappname + + ".properties")); + } catch (IOException e) { + LOG.info( + "Can't load application properties: " + e.getMessage(), + e); + } + + // Configure login security + System.setProperty("java.security.auth.login.config", _wapproot + + ApplicationSettings.getApplicationProperty("wapp.login")); + + // Customization (must be done after above default settings) + File config = new File(_wapproot + + getApplicationProperty("wapp.customization")); + if (config.exists()) { + loadCustomization(config); // Sets default document types, installed modules and available templates + } else { + LOG.info("Could not find the application configuration file \"" + + config.getAbsolutePath() + + "\", using default settings"); + } + } + } /** * All value. @@ -170,23 +242,10 @@ public class ApplicationSettings implements ServletContextAware { */ private static final String ACT_VERSION = "select-file?nextAction=version"; - /** - * Injected servlet context to get path to resources. - */ - private transient ServletContext _servletContext; - /** * Siman application server name. */ - private transient String _wappserver; - /** - * Siman web application name. - */ - private transient String _wappname; - /** - * General properties from the application properties files. - */ - private transient final Properties _wapprops = new Properties(); + private transient final String _wappserver; /** * Current user locale. */ @@ -207,22 +266,6 @@ public class ApplicationSettings implements ServletContextAware { * Named search filters. */ private transient Map> _filter = null; - /** - * Available template files. - */ - private transient Map _tempfile = null; - /** - * List of file extensions mapped to a viewer. - */ - private transient String[] _viewermap = null; - /** - * Available document format converters. - */ - private transient Map _convertmap = null; - /** - * JNDI context for launching converters. - */ - private transient final Properties _jndprops = new Properties(); /** * Injected project settings service. */ @@ -232,6 +275,19 @@ public class ApplicationSettings implements ServletContextAware { */ private DocumentTypeService _documentTypeService; + /** + * Application settings constructor. + */ + public ApplicationSettings() { + HttpServletRequest curRequest = ((ServletRequestAttributes) RequestContextHolder + .currentRequestAttributes()).getRequest(); + _wappserver = curRequest.getServerName() + ":" + + curRequest.getServerPort(); + + LOG.info("Application server is set to " + _wappserver); + LOG.info("Application name is set to " + _wappname); + } + /** * Get the projectSettingsService. * @@ -257,12 +313,12 @@ public class ApplicationSettings implements ServletContextAware { super("create"); addItem("new-empty", "menu.new.empty", "image.empty.png", "select?menu=create&item=new-empty"); - addItem("new-copy", - new MenuItem("menu.new.copy").icon("image.copy.png")); - addItem("new-instance", - new MenuItem("menu.new.instance").icon(IMG_HOLD)); - addItem("new-import", - new MenuItem("menu.new.import").icon("icon.upload.png")); + addItem("new-copy", new MenuItem("menu.new.copy") + .icon("image.copy.png")); + addItem("new-instance", new MenuItem("menu.new.instance") + .icon(IMG_HOLD)); + addItem("new-import", new MenuItem("menu.new.import") + .icon("icon.upload.png")); this.selects("new-empty"); } } @@ -274,8 +330,8 @@ public class ApplicationSettings implements ServletContextAware { "select?menu=search&item=search-study"); addItem("search-knowledge", "menu.search.idea", "image.idea.png", "select?menu=search&item=search-knowledge"); - addItem("search-document", - new MenuItem("menu.search.document").icon("icon.any.png")); + addItem("search-document", new MenuItem("menu.search.document") + .icon("icon.any.png")); this.selects("search-study"); } } @@ -303,8 +359,8 @@ public class ApplicationSettings implements ServletContextAware { "select?menu=datadmin&item=admin-scontext"); addItem("admin-knowelm", "menu.admin.knowledge", "image.idea.png", "select?menu=datadmin&item=admin-knowelm"); - addItem("admin-study", - new MenuItem("menu.admin.study").icon("image.study.png")); + addItem("admin-study", new MenuItem("menu.admin.study") + .icon("image.study.png")); } } @@ -329,31 +385,26 @@ public class ApplicationSettings implements ServletContextAware { private EditableStudyPopup() { super(); - addItem(MNU_PUBLISH, - new PopupItem(MNU_NAME_PUBLISH).icon("image.publish.png") - .action("edit-study?action=publish") - .confirmation("message.publish.study")); + addItem(MNU_PUBLISH, new PopupItem(MNU_NAME_PUBLISH).icon( + "image.publish.png").action("edit-study?action=publish") + .confirmation("message.publish.study")); addItem(MNU_PROMOTE, new PopupItem("menu.archive")); addSeparator(); - addItem(MNU_EDIT, - new PopupItem("menu.properties").icon("icon.ed.png") - .action("../select?menu=properties")); + addItem(MNU_EDIT, new PopupItem("menu.properties").icon( + "icon.ed.png").action("../select?menu=properties")); addSeparator(); - addItem(MNU_SCRIPT, - new PopupItem(MNU_NAME_SCRIPT).action("add-scenario")); - addItem(MNU_VERSION, - new PopupItem(MNU_NAME_VERSION).icon(IMG_VERSION).action( - ACT_NOT_YET_IMPLEMENTED)); + addItem(MNU_SCRIPT, new PopupItem(MNU_NAME_SCRIPT) + .action("add-scenario")); + addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon( + IMG_VERSION).action(ACT_NOT_YET_IMPLEMENTED)); addSeparator(); - addItem(MNU_PURGE, - new PopupItem(MNU_NAME_PURGE) - .confirmation("message.purge.study")); - addItem("export", - new PopupItem("menu.export").icon("image.export.png")); // For future needs - addItem(MNU_REMOVE, - new PopupItem(MNU_NAME_REMOVE).icon(IMG_DELETE) - .action(ACT_NOT_YET_IMPLEMENTED) - .confirmation("message.delete.study")); + addItem(MNU_PURGE, new PopupItem(MNU_NAME_PURGE) + .confirmation("message.purge.study")); + addItem("export", new PopupItem("menu.export") + .icon("image.export.png")); // For future needs + addItem(MNU_REMOVE, new PopupItem(MNU_NAME_REMOVE).icon(IMG_DELETE) + .action(ACT_NOT_YET_IMPLEMENTED).confirmation( + "message.delete.study")); } @Override @@ -411,36 +462,30 @@ public class ApplicationSettings implements ServletContextAware { private EditableDocumentPopup() { super(); - addItem("accept", - new PopupItem("menu.accept").icon("image.accept.png") - .action("setDocument?action=accept") - .confirmation("message.accept.document")); - addItem(MNU_PROMOTE, - new PopupItem(MNU_NAME_PROMOTE).icon("image.publish.png") - .action("setDocument?action=promote") - .confirmation("message.promote.document")); + addItem("accept", new PopupItem("menu.accept").icon( + "image.accept.png").action("setDocument?action=accept") + .confirmation("message.accept.document")); + addItem(MNU_PROMOTE, new PopupItem(MNU_NAME_PROMOTE).icon( + "image.publish.png").action("setDocument?action=promote") + .confirmation("message.promote.document")); addSeparator(); - addItem(MNU_RENAME, - new PopupItem(MNU_NAME_RENAME) - .action("edit-document?action=renameDocument")); + addItem(MNU_RENAME, new PopupItem(MNU_NAME_RENAME) + .action("edit-document?action=renameDocument")); addItem(MNU_ATTACH, new PopupItem(MNU_NAME_ATTACH).icon(IMG_ATTACH) .action(ACT_ATTACH)); addSeparator(); - addItem(MNU_VERSION, - new PopupItem(MNU_NAME_VERSION).icon(IMG_VERSION).action( - ACT_VERSION)); - addItem("replace", - new PopupItem("menu.replace").icon("image.replace.png") - .action("select-file?nextAction=replace")); + addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon( + IMG_VERSION).action(ACT_VERSION)); + addItem("replace", new PopupItem("menu.replace").icon( + "image.replace.png").action( + "select-file?nextAction=replace")); addSeparator(); - addItem(MNU_PURGE, - new PopupItem(MNU_NAME_PURGE).action( - ACT_NOT_YET_IMPLEMENTED).confirmation( - "message.purge.document")); - addItem(MNU_REMOVE, - new PopupItem(MNU_NAME_REMOVE).icon(IMG_DELETE) - .action("remove-document") - .confirmation("message.delete.document")); + addItem(MNU_PURGE, new PopupItem(MNU_NAME_PURGE).action( + ACT_NOT_YET_IMPLEMENTED).confirmation( + "message.purge.document")); + addItem(MNU_REMOVE, new PopupItem(MNU_NAME_REMOVE).icon(IMG_DELETE) + .action("remove-document").confirmation( + "message.delete.document")); } @Override @@ -503,26 +548,22 @@ public class ApplicationSettings implements ServletContextAware { private ReviewableDocumentPopup() { super(); - addItem(MNU_DEMOTE, - new PopupItem(MNU_NAME_DEMOTE).icon("image.demote.png") - .action("setDocument?action=demote") - .confirmation("message.demote.document")); - addItem(MNU_PROMOTE, - new PopupItem("menu.review").icon("image.review.png") - .action("setDocument?action=review") - .confirmation("message.review.document")); + addItem(MNU_DEMOTE, new PopupItem(MNU_NAME_DEMOTE).icon( + "image.demote.png").action("setDocument?action=demote") + .confirmation("message.demote.document")); + addItem(MNU_PROMOTE, new PopupItem("menu.review").icon( + "image.review.png").action("setDocument?action=review") + .confirmation("message.review.document")); addSeparator(); addItem(MNU_ATTACH, new PopupItem(MNU_NAME_ATTACH).icon(IMG_ATTACH) .action(ACT_ATTACH)); addSeparator(); - addItem(MNU_VERSION, - new PopupItem(MNU_NAME_VERSION).icon(IMG_VERSION).action( - ACT_VERSION)); + addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon( + IMG_VERSION).action(ACT_VERSION)); addSeparator(); - addItem(MNU_PURGE, - new PopupItem(MNU_NAME_PURGE).action( - ACT_NOT_YET_IMPLEMENTED).confirmation( - "message.purge.document")); + addItem(MNU_PURGE, new PopupItem(MNU_NAME_PURGE).action( + ACT_NOT_YET_IMPLEMENTED).confirmation( + "message.purge.document")); } @Override @@ -566,26 +607,22 @@ public class ApplicationSettings implements ServletContextAware { private NotResultDocumentPopup() { super(); - addItem(MNU_DEMOTE, - new PopupItem(MNU_NAME_DEMOTE).icon("image.demote.png") - .action("setDocument?action=demote") - .confirmation("message.demote.document")); + addItem(MNU_DEMOTE, new PopupItem(MNU_NAME_DEMOTE).icon( + "image.demote.png").action("setDocument?action=demote") + .confirmation("message.demote.document")); addSeparator(); addItem(MNU_ATTACH, new PopupItem(MNU_NAME_ATTACH).icon(IMG_ATTACH) .action(ACT_ATTACH)); addSeparator(); - addItem(MNU_VERSION, - new PopupItem(MNU_NAME_VERSION).icon(IMG_VERSION).action( - ACT_VERSION)); + addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon( + IMG_VERSION).action(ACT_VERSION)); addSeparator(); - addItem(MNU_PURGE, - new PopupItem(MNU_NAME_PURGE).action( - ACT_NOT_YET_IMPLEMENTED).confirmation( - "message.purge.document")); - addItem(MNU_REMOVE, - new PopupItem(MNU_NAME_REMOVE).icon(IMG_DELETE) - .action("remove-document") - .confirmation("message.delete.document")); + addItem(MNU_PURGE, new PopupItem(MNU_NAME_PURGE).action( + ACT_NOT_YET_IMPLEMENTED).confirmation( + "message.purge.document")); + addItem(MNU_REMOVE, new PopupItem(MNU_NAME_REMOVE).icon(IMG_DELETE) + .action("remove-document").confirmation( + "message.delete.document")); } } @@ -597,18 +634,16 @@ public class ApplicationSettings implements ServletContextAware { private ApprovableDocumentPopup() { super(); - addItem("undo", - new PopupItem(MNU_NAME_DEMOTE).icon("image.invalidate.png") - .action("setDocument?action=invalidate") - .confirmation("message.demote.document")); - addItem(MNU_DEMOTE, - new PopupItem("menu.disapprove").icon("image.demote.png") - .action("setDocument?action=disapprove") - .confirmation("message.disapprove.document")); - addItem("approve", - new PopupItem("menu.approve").icon("icon.APPROVED.png") - .action("setDocument?action=approve") - .confirmation("message.approve.document")); + addItem("undo", new PopupItem(MNU_NAME_DEMOTE).icon( + "image.invalidate.png").action( + "setDocument?action=invalidate").confirmation( + "message.demote.document")); + addItem(MNU_DEMOTE, new PopupItem("menu.disapprove").icon( + "image.demote.png").action("setDocument?action=disapprove") + .confirmation("message.disapprove.document")); + addItem("approve", new PopupItem("menu.approve").icon( + "icon.APPROVED.png").action("setDocument?action=approve") + .confirmation("message.approve.document")); } @Override @@ -650,9 +685,8 @@ public class ApplicationSettings implements ServletContextAware { addItem(MNU_ATTACH, new PopupItem(MNU_NAME_ATTACH).icon(IMG_ATTACH) .action(ACT_ATTACH)); addSeparator(); - addItem(MNU_VERSION, - new PopupItem(MNU_NAME_VERSION).icon(IMG_VERSION).action( - ACT_VERSION)); + addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon( + IMG_VERSION).action(ACT_VERSION)); } } @@ -664,17 +698,15 @@ public class ApplicationSettings implements ServletContextAware { private ExternPopup() { super(); - addItem(MNU_RENAME, - new PopupItem(MNU_NAME_RENAME) - .action("edit-document?action=renameDocument")); - addItem("replace", - new PopupItem("menu.replace").icon("image.replace.png") - .action("select-file?nextAction=replace")); + addItem(MNU_RENAME, new PopupItem(MNU_NAME_RENAME) + .action("edit-document?action=renameDocument")); + addItem("replace", new PopupItem("menu.replace").icon( + "image.replace.png").action( + "select-file?nextAction=replace")); addSeparator(); - addItem(MNU_REMOVE, - new PopupItem("menu.remove.document").icon(IMG_DELETE) - .action("remove-document") - .confirmation("message.delete.document")); + addItem(MNU_REMOVE, new PopupItem("menu.remove.document").icon( + IMG_DELETE).action("remove-document").confirmation( + "message.delete.document")); } @Override @@ -713,17 +745,14 @@ public class ApplicationSettings implements ServletContextAware { private ScontextPopup() { super(); - addItem(MNU_RENAME, - new PopupItem(MNU_NAME_RENAME) - .action("edit-context?action=renameContext")); - addItem(MNU_EDIT, - new PopupItem(MNU_NAME_EDIT) - .action("edit-context?action=editContext")); + addItem(MNU_RENAME, new PopupItem(MNU_NAME_RENAME) + .action("edit-context?action=renameContext")); + addItem(MNU_EDIT, new PopupItem(MNU_NAME_EDIT) + .action("edit-context?action=editContext")); addSeparator(); - addItem(MNU_REMOVE, - new PopupItem("menu.remove").icon(IMG_DELETE) - .action("remove-context") - .confirmation("message.delete.context")); + addItem(MNU_REMOVE, new PopupItem("menu.remove").icon(IMG_DELETE) + .action("remove-context").confirmation( + "message.delete.context")); } @Override @@ -756,26 +785,21 @@ public class ApplicationSettings implements ServletContextAware { private FeedbexPopup() { super(); - addItem(MNU_PROMOTE, - new PopupItem(MNU_NAME_PROMOTE).icon("image.review.png") - .action("promote-knowledge") - .confirmation("message.promote.knowledge")); - addItem(MNU_DEMOTE, - new PopupItem(MNU_NAME_DEMOTE).icon("image.invalidate.png") - .action("demote-knowledge") - .confirmation("message.demote.knowledge")); + addItem(MNU_PROMOTE, new PopupItem(MNU_NAME_PROMOTE).icon( + "image.review.png").action("promote-knowledge") + .confirmation("message.promote.knowledge")); + addItem(MNU_DEMOTE, new PopupItem(MNU_NAME_DEMOTE).icon( + "image.invalidate.png").action("demote-knowledge") + .confirmation("message.demote.knowledge")); addSeparator(); - addItem(MNU_RENAME, - new PopupItem(MNU_NAME_RENAME) - .action("edit-knowledge?action=renameKnowledge")); - addItem(MNU_EDIT, - new PopupItem(MNU_NAME_EDIT) - .action("edit-knowledge?action=editKnowledge")); + addItem(MNU_RENAME, new PopupItem(MNU_NAME_RENAME) + .action("edit-knowledge?action=renameKnowledge")); + addItem(MNU_EDIT, new PopupItem(MNU_NAME_EDIT) + .action("edit-knowledge?action=editKnowledge")); addSeparator(); - addItem(MNU_REMOVE, - new PopupItem("menu.remove").icon(IMG_DELETE) - .action("remove-knowledge") - .confirmation("message.delete.knowledge")); + addItem(MNU_REMOVE, new PopupItem("menu.remove").icon(IMG_DELETE) + .action("remove-knowledge").confirmation( + "message.delete.knowledge")); } @Override @@ -808,42 +832,11 @@ public class ApplicationSettings implements ServletContextAware { // Construction // ============================================================================================================================== - public static ApplicationSettings getMe() { - return MY_APP; // The application is supposed being previously created below - } - - /** - * @param wappurl - * @param lang - * @return - */ - public ApplicationSettings init(final String wappurl, final Locale lang) - throws IOException { - ClassLoader cloader = Thread.currentThread().getContextClassLoader(); - String[] wurl = wappurl.split("/"); // [0]="http:", [1]="", [2]="{server}:{port}", [3]="name" - - synchronized (MY_APP) { - MY_APP._locale = lang; - MY_APP._wappserver = wurl[2]; - MY_APP._wappname = wurl[3]; - MY_APP._wapprops.clear(); - MY_APP._jndprops.clear(); - MY_APP._wapprops.load(cloader.getResourceAsStream(_wappname - + ".properties")); - MY_APP._jndprops.load(cloader - .getResourceAsStream("jndi.properties")); - } - - LOG.info("Application root set to " - + _wapprops.getProperty("wapp.root")); - return MY_APP; - } - // ============================================================================================================================== // Public member functions // ============================================================================================================================== - public void configure(final String filename) { + public void configure() { // Non customizable settings _menus.clear(); SimpleMenu menu = new NewMenu(); @@ -893,18 +886,6 @@ public class ApplicationSettings implements ServletContextAware { _filter.put("study", fprop); _filter.put("knowledge", gprop); - _tempfile = new HashMap(); - _viewermap = new String[0]; - _convertmap = new HashMap(); - - // Customization (must be done after above default settings) - File config = new File(filename); - if (config.exists()) { - loadCustomization(config); // Sets default document types, installed modules and available templates - } else { - LOG.info("Could not find the application configuration file \"" - + config.getAbsolutePath() + "\", using default settings"); - } // Settings based on the customization configureToolbars(); } @@ -953,8 +934,9 @@ public class ApplicationSettings implements ServletContextAware { } else { icon = "tool." + icon.toLowerCase() + ".png"; } - File image = new File( - ApplicationSettings.getApplicationSkinPath() + icon); + File image = new File(ApplicationSettings + .getApplicationSkinPath() + + icon); if (!image.exists()) { icon = "tool.any.png"; } @@ -962,8 +944,9 @@ public class ApplicationSettings implements ServletContextAware { } else { docname = "/jsp/newDocument.jsp?type=" + docname; String icon = "tool." + name[0].toLowerCase() + ".png"; - File image = new File( - ApplicationSettings.getApplicationSkinPath() + icon); + File image = new File(ApplicationSettings + .getApplicationSkinPath() + + icon); if (!image.exists()) { icon = "tool.any.png"; } @@ -976,18 +959,18 @@ public class ApplicationSettings implements ServletContextAware { } } - public String getApplicationProperty(final String name) { + public static String getApplicationProperty(final String name) { return _wapprops.getProperty(name); // May be null } - public String getApplicationRootPath() { - // RKV: return getApplicationProperty("wapp.root"); // The property is supposed including the Web application name - return _servletContext.getRealPath("/"); + public static String getApplicationRootPath() { + // The property is supposed including the Web application name + return _wapproot; } public String getApplicationURL() { - StringBuffer url = new StringBuffer("http://") - .append(MY_APP._wappserver).append("/").append(_wappname); + StringBuffer url = new StringBuffer("http://").append(_wappserver) + .append("/").append(_wappname); return url.toString(); } @@ -999,7 +982,7 @@ public class ApplicationSettings implements ServletContextAware { return _bars.get(step.getNumber()); } - public Properties getNamingProperties() { + static public Properties getNamingProperties() { return _jndprops; } @@ -1008,20 +991,20 @@ public class ApplicationSettings implements ServletContextAware { // ============================================================================================================================== public static String getApplicationPluginPath() { - return MY_APP.getApplicationRootPath() + "plugin/"; + return getApplicationRootPath() + "plugin/"; } public static String getApplicationResourcePath() { - return MY_APP.getApplicationRootPath() + "WEB-INF/classes/"; + return getApplicationRootPath() + "WEB-INF/classes/"; } public static String getApplicationSkinPath() { - return MY_APP.getApplicationRootPath() + "skin/"; + return getApplicationRootPath() + "skin/"; } public static Converter getConverter(final DocumentType type, final String format) { - return MY_APP._convertmap.get(format + type.getName()); // May be null; + return _convertmap.get(format + type.getName()); // May be null; } public DocumentType getDefaultDocumentType(final Step step, @@ -1030,34 +1013,32 @@ public class ApplicationSettings implements ServletContextAware { format); // May be null } - public static String getDownloadURL(final User user) { - StringBuffer url = new StringBuffer("http://") - .append(MY_APP._wappserver).append("/download/") - .append(user.getUsername()).append("/"); + public String getDownloadURL(final User user) { + StringBuffer url = new StringBuffer("http://").append(_wappserver) + .append("/download/").append(user.getUsername()).append("/"); return url.toString(); // The download Tomcat context is supposed being defined } - public static Locale getCurrentLocale() { - return MY_APP._locale; + public Locale getCurrentLocale() { + return _locale; } - public static SimpleMenu getMenu(final String name) { - return MY_APP._menus.get(name); + public SimpleMenu getMenu(final String name) { + return _menus.get(name); } - public static PopupMenu getPopupMenu(final String name) { - return MY_APP._popups.get(name); + public PopupMenu getPopupMenu(final String name) { + return _popups.get(name); } - public static String getRepositoryURL() { - StringBuffer url = new StringBuffer("http://").append( - MY_APP._wappserver).append("/repository/"); + public String getRepositoryURL() { + StringBuffer url = new StringBuffer("http://").append(_wappserver) + .append("/repository/"); return url.toString(); // The repository Tomcat context is supposed being defined } public static Locale[] getSupportedLocales() { - String[] code = MY_APP._wapprops.getProperty("locale.supported").split( - ","); + String[] code = _wapprops.getProperty("locale.supported").split(","); Locale[] result = new Locale[code.length]; for (int i = 0; i < code.length; i++) { result[i] = new Locale(code[i]); @@ -1066,15 +1047,15 @@ public class ApplicationSettings implements ServletContextAware { } public static String[] getViewersMapping() { - return MY_APP._viewermap; + return _viewermap; } public static String getWebSiteURL() { - return MY_APP.getApplicationProperty("wapp.website"); + return getApplicationProperty("wapp.website"); } public static String getHelpURL() { - return MY_APP.getApplicationProperty("wapp.onlinehelp"); + return getApplicationProperty("wapp.onlinehelp"); } // ============================================================================================================================== @@ -1082,12 +1063,12 @@ public class ApplicationSettings implements ServletContextAware { // ============================================================================================================================== /** - * Load customization of workflow from the given XML file. + * Load application custom configuration from the given XML file (see conf/my.xml). * * @param config * the XML configuration file */ - private void loadCustomization(final File config) { + private static void loadCustomization(final File config) { try { DocumentBuilderFactory dfactory = javax.xml.parsers.DocumentBuilderFactory .newInstance(); @@ -1116,7 +1097,7 @@ public class ApplicationSettings implements ServletContextAware { * @param children * XML nodes */ - private void loadModules(final Map children) { + private static void loadModules(final Map children) { Node child = children.get("modules"); NodeList nlist = child.getChildNodes(); for (int i = 0; i < nlist.getLength(); i++) { @@ -1142,7 +1123,7 @@ public class ApplicationSettings implements ServletContextAware { * @param children * XML nodes */ - private void loadConverters(final Map children) { + private static void loadConverters(final Map children) { Node child = children.get("converters"); NodeList nlist = child.getChildNodes(); for (int i = 0; i < nlist.getLength(); i++) { @@ -1165,7 +1146,7 @@ public class ApplicationSettings implements ServletContextAware { * @param children * XML nodes */ - private void loadTemplates(final Map children) { + private static void loadTemplates(final Map children) { Node child = children.get("templates"); NodeList nlist = child.getChildNodes(); for (int i = 0; i < nlist.getLength(); i++) { @@ -1202,13 +1183,22 @@ public class ApplicationSettings implements ServletContextAware { } /** - * {@inheritDoc} + * Get the locale. + * + * @return the locale + */ + public Locale getLocale() { + return _locale; + } + + /** + * Set the locale. * - * @see org.apache.struts2.util.ServletContextAware#setServletContext(javax.servlet.ServletContext) + * @param locale + * the locale to set */ - @Override - public void setServletContext(final ServletContext context) { - _servletContext = context; + public void setLocale(final Locale locale) { + _locale = locale; } } \ No newline at end of file diff --git a/Workspace/Siman/src/org/splat/simer/Converter.java b/Workspace/Siman/src/org/splat/simer/Converter.java index 37657d3..af2237d 100644 --- a/Workspace/Siman/src/org/splat/simer/Converter.java +++ b/Workspace/Siman/src/org/splat/simer/Converter.java @@ -61,8 +61,7 @@ public class Converter implements MessageListener { } try { // Initialization of the asynchronous communication with the actual converter - ApplicationSettings settings = ApplicationSettings.getMe(); - Context context = new InitialContext(settings.getNamingProperties()); + Context context = new InitialContext(ApplicationSettings.getNamingProperties()); ConnectionFactory factory = (javax.jms.QueueConnectionFactory)context.lookup("QueueConnectionFactory"); Connection connex = factory.createConnection(); Session session = connex.createSession(false, Session.AUTO_ACKNOWLEDGE); diff --git a/Workspace/Siman/src/org/splat/simer/DisplayStudyStepAction.java b/Workspace/Siman/src/org/splat/simer/DisplayStudyStepAction.java index b0852f0..d0a30e6 100644 --- a/Workspace/Siman/src/org/splat/simer/DisplayStudyStepAction.java +++ b/Workspace/Siman/src/org/splat/simer/DisplayStudyStepAction.java @@ -13,8 +13,9 @@ import org.splat.wapp.SimpleMenu; /** * Presents the current open study information. + * * @author Daniel Brunier-Coulin. - * + * */ public class DisplayStudyStepAction extends AbstractDisplayAction { @@ -32,35 +33,30 @@ public class DisplayStudyStepAction extends AbstractDisplayAction { * Injected study service. */ private StudyService _studyService; - + /** - * Value of the menu property. - * It can be: none, create, open, study, knowledge, sysadmin, help. + * Value of the menu property. It can be: none, create, open, study, knowledge, sysadmin, help. */ private String _menuProperty; - + /** - * Value of the title bar property. - * It can be: study, knowledge. + * Value of the title bar property. It can be: study, knowledge. */ private String _titleProperty; - + /** - * Value of the tool bar property. - * It can be: none, standard, study, back. + * Value of the tool bar property. It can be: none, standard, study, back. */ private String _toolProperty; - + /** - * Value of the left menu property. - * It can be: open, study, knowledge, scenario. + * Value of the left menu property. It can be: open, study, knowledge, scenario. */ private String _leftMenuProperty; - + /** - * Property that indicates whether the current open study is editable or not. - * On the screen it looks like pen on the status icon, pop-up menu also can be called. - * It is necessary for correct building the title bar. + * Property that indicates whether the current open study is editable or not. On the screen it looks like pen on the status icon, pop-up + * menu also can be called. It is necessary for correct building the title bar. */ private String _editDisabledProperty = "false"; @@ -103,10 +99,10 @@ public class DisplayStudyStepAction extends AbstractDisplayAction { res = ERROR; } } - if (!ERROR.equals(res)){ + if (!ERROR.equals(res)) { // Initialization of menus ProjectElement owner = _openStudy.getSelectedStep().getOwner(); - SimpleMenu menu = ApplicationSettings.getMenu("configuration"); + SimpleMenu menu = getApplicationSettings().getMenu("configuration"); if (owner instanceof Scenario) { menu.enables(Constants.PROP_SCENARIO); menu.selects(Constants.PROP_SCENARIO); @@ -115,18 +111,20 @@ public class DisplayStudyStepAction extends AbstractDisplayAction { menu.selects("prop-general"); } getSession().put("menu.study", _openStudy.getMenu()); - + setMenuProperty(Constants.STUDY_MENU); setTitleProperty(Constants.STUDY_MENU); - if (Constants.TRUE.equals(getWriteAccess()) && getUserRights().canCreateDocument()) { + if (Constants.TRUE.equals(getWriteAccess()) + && getUserRights().canCreateDocument()) { setToolProperty(Constants.STUDY_MENU); } else { setToolProperty(Constants.STANDARD_MENU); } - + setLeftMenuProperty(Constants.STUDY_MENU); - - initializationFullScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty, _leftMenuProperty); + + initializationFullScreenContext(_menuProperty, _titleProperty, + _editDisabledProperty, _toolProperty, _leftMenuProperty); } return res; } @@ -141,7 +139,7 @@ public class DisplayStudyStepAction extends AbstractDisplayAction { } // Re-initialization of the properties menu according to the selected step ProjectElement owner = _openStudy.getSelectedStep().getOwner(); - SimpleMenu menu = ApplicationSettings.getMenu("configuration"); + SimpleMenu menu = getApplicationSettings().getMenu("configuration"); if (owner instanceof Scenario) { menu.enables(Constants.PROP_SCENARIO); menu.selects(Constants.PROP_SCENARIO); @@ -149,18 +147,20 @@ public class DisplayStudyStepAction extends AbstractDisplayAction { menu.disables(Constants.PROP_SCENARIO); menu.selects("prop-general"); } - + setMenuProperty(Constants.STUDY_MENU); setTitleProperty(Constants.STUDY_MENU); - if (Constants.TRUE.equals(getWriteAccess()) && getUserRights().canCreateDocument()) { + if (Constants.TRUE.equals(getWriteAccess()) + && getUserRights().canCreateDocument()) { setToolProperty(Constants.STUDY_MENU); } else { setToolProperty(Constants.STANDARD_MENU); } - + setLeftMenuProperty(Constants.STUDY_MENU); - initializationFullScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty, _leftMenuProperty); - + initializationFullScreenContext(_menuProperty, _titleProperty, + _editDisabledProperty, _toolProperty, _leftMenuProperty); + return SUCCESS; } @@ -174,17 +174,19 @@ public class DisplayStudyStepAction extends AbstractDisplayAction { } else if (todo == Execute.reduceall) { _openStudy.reduceDocument(_myindex); } - + setMenuProperty(Constants.STUDY_MENU); setTitleProperty(Constants.STUDY_MENU); - if (Constants.TRUE.equals(getWriteAccess()) && getUserRights().canCreateDocument()) { + if (Constants.TRUE.equals(getWriteAccess()) + && getUserRights().canCreateDocument()) { setToolProperty(Constants.STUDY_MENU); } else { setToolProperty(Constants.STANDARD_MENU); } setLeftMenuProperty(Constants.STUDY_MENU); - initializationFullScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty, _leftMenuProperty); - + initializationFullScreenContext(_menuProperty, _titleProperty, + _editDisabledProperty, _toolProperty, _leftMenuProperty); + return SUCCESS; } @@ -196,26 +198,28 @@ public class DisplayStudyStepAction extends AbstractDisplayAction { } else if (todo == Execute.reduce) { _openStudy.reduceKnowledge(_myindex); } - + setMenuProperty(Constants.STUDY_MENU); setTitleProperty(Constants.STUDY_MENU); - if (Constants.TRUE.equals(getWriteAccess()) && getUserRights().canCreateDocument()) { + if (Constants.TRUE.equals(getWriteAccess()) + && getUserRights().canCreateDocument()) { setToolProperty(Constants.STUDY_MENU); } else { setToolProperty(Constants.STANDARD_MENU); } setLeftMenuProperty(Constants.STUDY_MENU); - initializationFullScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty, _leftMenuProperty); - + initializationFullScreenContext(_menuProperty, _titleProperty, + _editDisabledProperty, _toolProperty, _leftMenuProperty); + return SUCCESS; } public String doClose() { closeStudy(); - + setMenuProperty("none"); initializationScreenContext(_menuProperty); - + return SUCCESS; } @@ -289,9 +293,10 @@ public class DisplayStudyStepAction extends AbstractDisplayAction { super.setOpenStudy(study); _openStudy = study; } - + /** * Get the menuProperty. + * * @return the menuProperty */ public String getMenuProperty() { @@ -300,14 +305,17 @@ public class DisplayStudyStepAction extends AbstractDisplayAction { /** * Set the menuProperty. - * @param menuProperty the menuProperty to set + * + * @param menuProperty + * the menuProperty to set */ public void setMenuProperty(final String menuProperty) { this._menuProperty = menuProperty; } - + /** * Get the _titleProperty. + * * @return the _titleProperty */ public String getTitleProperty() { @@ -316,7 +324,9 @@ public class DisplayStudyStepAction extends AbstractDisplayAction { /** * Set the _titleProperty. - * @param _titleProperty the titleProperty to set + * + * @param _titleProperty + * the titleProperty to set */ public void setTitleProperty(final String titleProperty) { _titleProperty = titleProperty; @@ -324,6 +334,7 @@ public class DisplayStudyStepAction extends AbstractDisplayAction { /** * Get the editDisabledProperty. + * * @return the editDisabledProperty */ public String getEditDisabledProperty() { @@ -332,14 +343,17 @@ public class DisplayStudyStepAction extends AbstractDisplayAction { /** * Set the editDisabledProperty. - * @param editDisabledProperty the editDisabledProperty to set + * + * @param editDisabledProperty + * the editDisabledProperty to set */ public void setEditDisabledProperty(final String editDisabledProperty) { _editDisabledProperty = editDisabledProperty; } - + /** * Get the toolProperty. + * * @return the toolProperty */ public String getToolProperty() { @@ -348,14 +362,17 @@ public class DisplayStudyStepAction extends AbstractDisplayAction { /** * Set the toolProperty. - * @param toolProperty the toolProperty to set + * + * @param toolProperty + * the toolProperty to set */ public void setToolProperty(final String toolProperty) { _toolProperty = toolProperty; } - + /** * Get the leftMenuProperty. + * * @return the leftMenuProperty */ public String getLeftMenuProperty() { @@ -364,7 +381,9 @@ public class DisplayStudyStepAction extends AbstractDisplayAction { /** * Set the leftMenuProperty. - * @param leftMenuProperty the leftMenuProperty to set + * + * @param leftMenuProperty + * the leftMenuProperty to set */ public void setLeftMenuProperty(final String leftMenuProperty) { _leftMenuProperty = leftMenuProperty; diff --git a/Workspace/Siman/src/org/splat/simer/DocumentFacade.java b/Workspace/Siman/src/org/splat/simer/DocumentFacade.java index f94b37c..c96c999 100644 --- a/Workspace/Siman/src/org/splat/simer/DocumentFacade.java +++ b/Workspace/Siman/src/org/splat/simer/DocumentFacade.java @@ -14,28 +14,31 @@ import java.util.Iterator; import java.util.List; import java.util.ResourceBundle; -import org.splat.manox.XMLDocument; import org.splat.dal.bo.kernel.Relation; import org.splat.dal.bo.som.ConvertsRelation; import org.splat.dal.bo.som.Document; -import org.splat.som.DocumentRights; import org.splat.dal.bo.som.DocumentType; import org.splat.dal.bo.som.ProgressState; -import org.splat.service.PublicationService; -import org.splat.service.technical.ProjectSettingsService; import org.splat.dal.bo.som.Publication; -import org.splat.som.Revision; -import org.splat.som.Step; import org.splat.dal.bo.som.Timestamp; import org.splat.dal.bo.som.UsesRelation; import org.splat.dal.bo.som.VersionsRelation; +import org.splat.manox.XMLDocument; +import org.splat.service.PublicationService; +import org.splat.service.technical.ProjectSettingsService; +import org.splat.som.DocumentRights; +import org.splat.som.Revision; +import org.splat.som.Step; import org.splat.wapp.PopupMenu; +/** + * Document wrapper class for presentation layer. + */ public class DocumentFacade implements HistoryFacade { - private AbstractOpenObject owner; - private Publication me; - private Document my; // Published document + private final AbstractOpenObject owner; + private final Publication me; + private final Document my; // Published document private ProgressState state; // Document state private String version; // My document version in customized format private State display; // Presentation state @@ -51,8 +54,18 @@ public class DocumentFacade implements HistoryFacade { private List exports; private List history; private PopupMenu popup; + /** + * Injected project settings service. + */ private ProjectSettingsService _projectSettingsService; + /** + * Injected publication service. + */ private PublicationService _publicationService; + /** + * Injected application settings. + */ + private ApplicationSettings _applicationSettings; private enum State { closed, open, deepopen @@ -62,12 +75,14 @@ public class DocumentFacade implements HistoryFacade { // Constructors // ============================================================================================================================== - public DocumentFacade(AbstractOpenObject opened, Publication represented, - ProjectSettingsService projectSettings, - PublicationService publicationService) { - // ------------------------------------------------------------------ + public DocumentFacade(final AbstractOpenObject opened, + final Publication represented, + final ProjectSettingsService projectSettings, + final PublicationService publicationService, + final ApplicationSettings applicationSettings) { setProjectSettings(projectSettings); setPublicationService(publicationService); + setApplicationSettings(applicationSettings); owner = opened; me = represented; my = me.value(); @@ -88,19 +103,21 @@ public class DocumentFacade implements HistoryFacade { * @param represented * the represented history document */ - private DocumentFacade(AbstractOpenObject opened, Document represented, - ProjectSettingsService projectSettings, - PublicationService publicationService) { - // ---------------------------------------------------------------- + private DocumentFacade(final AbstractOpenObject opened, + final Document represented, + final ProjectSettingsService projectSettings, + final PublicationService publicationService, + final ApplicationSettings applicationSettings) { setProjectSettings(projectSettings); setPublicationService(publicationService); + setApplicationSettings(applicationSettings); owner = opened; me = null; // Marks the history context my = represented; state = my.getProgressState(); // In reality, HISTORY display = State.open; // Because the given document is a history document description = ResourceBundle.getBundle("som", - ApplicationSettings.getCurrentLocale()).getString( + applicationSettings.getCurrentLocale()).getString( "history.creation") + " " + my.getAuthor().toString(); uses = null; @@ -116,7 +133,6 @@ public class DocumentFacade implements HistoryFacade { // ============================================================================================================================== public void develop() { - // ------------------- if (display != State.open) { // Opening the document if (uses == null) { List relist = me.getRelations(UsesRelation.class); @@ -125,10 +141,13 @@ public class DocumentFacade implements HistoryFacade { for (Iterator i = relist.iterator(); i.hasNext();) { Publication used = i.next(); long index = used.getIndex(); - DocumentFacade facade = AbstractOpenObject.docpres.get(index); + DocumentFacade facade = owner.docpres + .get(index); if (facade == null) { - facade = new DocumentFacade(owner, used, getProjectSettings(), getPublicationService()); - AbstractOpenObject.docpres.put(index, facade); + facade = new DocumentFacade(owner, used, + getProjectSettings(), getPublicationService(), + getApplicationSettings()); + owner.docpres.put(index, facade); } uses.add(facade); } @@ -140,31 +159,34 @@ public class DocumentFacade implements HistoryFacade { exports = new ArrayList(relation.size()); for (Iterator i = relation.iterator(); i.hasNext();) { ConvertsRelation export = (ConvertsRelation) i.next(); - exports.add(new FileFacade(export)); + exports + .add(new FileFacade(export, + getApplicationSettings())); } } if (history == null) { if (my.getPreviousVersion() != null || state == ProgressState.inCHECK - || state == ProgressState.APPROVED) + || state == ProgressState.APPROVED) { history = new ArrayList(); + } } display = State.open; } else { // Opening the history of document, if exist - if (history.isEmpty()) + if (history.isEmpty()) { collectHistory(my); + } display = State.deepopen; } } public void reduce() { - // --------------------- - if (display == State.deepopen) + if (display == State.deepopen) { display = State.open; + } } public void reduceAll() { - // ------------------------ display = State.closed; } @@ -173,98 +195,79 @@ public class DocumentFacade implements HistoryFacade { // ============================================================================================================================== public List getAttachments() { - // ------------------------------------------ return exports; } public String getDate() { - // ------------------------ return date; } public String getDescription() { - // ------------------------------- return description; } public String getEditIcon() { - // ---------------------------- return "icon.ed" + state + ".png"; } public String getFileIcon() { - // ---------------------------- return icon; } public List getHistory() { - // ---------------------------------------- return history; } public String getIndex() { - // ------------------------- return String.valueOf(my.getIndex()); } public PopupMenu getPopup() { // Contextualizes the pop-up - // ---------------------------- popup.setContext("document", new DocumentRights(owner.getUser(), me)); return popup; // callers must "use" the returned pop-up before getting another pop-up } public String getPresentationState() { - // ------------------------------------- return display.toString(); } public String getProgressState() { - // --------------------------------- return state.toString(); } public String getSharingIcon() { - // ------------------------------- return sharing; } public String getSize() { - // ------------------------ return size; } public String getStateIcon() { - // ----------------------------- return "icon." + state + ".png"; } public String getTitle() { - // ------------------------- return my.getTitle(); } public String getURL() { - // ----------------------- return surl; } public List getUses() { - // --------------------------------------- return uses; } public String getVersion() { - // --------------------------- return version; } public String getVersioningIcon() { - // ---------------------------------- return updated; } - public boolean isFacadeOf(Publication represented) { - // --------------------------------------------------- + public boolean isFacadeOf(final Publication represented) { return me.equals(represented); } @@ -273,9 +276,8 @@ public class DocumentFacade implements HistoryFacade { // ============================================================================================================================== protected void refresh() { - // ------------------------- ResourceBundle custom = ResourceBundle.getBundle("som", - ApplicationSettings.getCurrentLocale()); + getApplicationSettings().getCurrentLocale()); DecimalFormat sizstring = new DecimalFormat(custom .getString("size.format")); // Locale size display format SimpleDateFormat datstring = new SimpleDateFormat(custom @@ -287,16 +289,18 @@ public class DocumentFacade implements HistoryFacade { for (int i = 0; i < mapping.length; i++) { org.splat.dal.bo.som.File export = my.getAttachedFile(mapping[i]); - if (export == null) + if (export == null) { continue; + } path = export.getRelativePath(); break; } - surl = ApplicationSettings.getRepositoryURL() + path; + surl = getApplicationSettings().getRepositoryURL() + path; surl = surl.replaceAll("'", "\\\\'"); format = my.getFormat(); - if (format.equals("xml")) + if (format.equals("xml")) { format = XMLDocument.getActualFormat(my.getSourceFile().asFile()); + } // Document state (overridable by the publication - see below) state = my.getProgressState(); @@ -308,23 +312,26 @@ public class DocumentFacade implements HistoryFacade { updated = "image.hold.gif"; File image = new File(ApplicationSettings.getApplicationSkinPath() + icon); - if (!image.exists()) + if (!image.exists()) { icon = "icon.any.png"; + } if (me != null) { if (me.getOwnerStudy().shares(my)) { sharing = "image.share.png"; updated = "icon.hold.png"; } - if (me.isOutdated()) + if (me.isOutdated()) { state = ProgressState.inWORK; // Overrides the document state + } } else { // Facade in the history folder if (!my.isVersioned()) { // History of the last version - if (state != ProgressState.inWORK) + if (state != ProgressState.inWORK) { icon = "icon.inWORK.png"; - else + } else { icon = "icon." + state.toString() + ".png"; + } } else if (my.isPublished()) { sharing = "image.share.png"; // Not correct if published in a previous version of the study updated = "icon.hold.png"; @@ -337,8 +344,9 @@ public class DocumentFacade implements HistoryFacade { description = versions.getDescription(); } // File details - if (state != ProgressState.EXTERN) + if (state != ProgressState.EXTERN) { version = verstring.format(version); + } size = sizstring.format(my.getSourceFile().asFile().length() / 1000); date = datstring.format(my.getLastModificationDate()); @@ -348,28 +356,29 @@ public class DocumentFacade implements HistoryFacade { collectHistory(my); } // Popup menus - if (me == null) + if (me == null) { return; // No pop-up (yet) in the history folder - if (state == ProgressState.EXTERN) - popup = ApplicationSettings.getPopupMenu("extern"); - else if (state == ProgressState.inWORK) - popup = ApplicationSettings.getPopupMenu("editable"); - else if (state == ProgressState.inDRAFT) - popup = ApplicationSettings.getPopupMenu("reviewable"); - else if (state == ProgressState.APPROVED) - popup = ApplicationSettings.getPopupMenu("approved"); - else { // (state == ProgressState.inCHECK) + } + if (state == ProgressState.EXTERN) { + popup = getApplicationSettings().getPopupMenu("extern"); + } else if (state == ProgressState.inWORK) { + popup = getApplicationSettings().getPopupMenu("editable"); + } else if (state == ProgressState.inDRAFT) { + popup = getApplicationSettings().getPopupMenu("reviewable"); + } else if (state == ProgressState.APPROVED) { + popup = getApplicationSettings().getPopupMenu("approved"); + } else { // (state == ProgressState.inCHECK) DocumentType mytype = me.value().getType(); // Only result documents need to be approved Step mystep = getPublicationService().getInvolvedStep(me); - if (mytype.isResultOf(mystep.getStep())) - popup = ApplicationSettings.getPopupMenu("approvable"); - else - popup = ApplicationSettings.getPopupMenu("notresult"); + if (mytype.isResultOf(mystep.getStep())) { + popup = getApplicationSettings().getPopupMenu("approvable"); + } else { + popup = getApplicationSettings().getPopupMenu("notresult"); + } } } protected void setVersioned() { - // ------------------------------ updated = "image.modified.png"; } @@ -377,17 +386,20 @@ public class DocumentFacade implements HistoryFacade { // Private services // ============================================================================================================================== - private void collectHistory(Document given) { - // -------------------------------------------- + private void collectHistory(final Document given) { VersionsRelation versions = (VersionsRelation) given .getFirstRelation(VersionsRelation.class); Timestamp[] stamp = given.getStamps(); // Stamps in ascending order of date - for (int i = stamp.length - 1; i > -1; i--) - history.add(new StampFacade(stamp[i])); - history.add(new DocumentFacade(owner, given, getProjectSettings(), getPublicationService())); - if (versions != null) + for (int i = stamp.length - 1; i > -1; i--) { + history.add(new StampFacade(stamp[i], getApplicationSettings() + .getCurrentLocale())); + } + history.add(new DocumentFacade(owner, given, getProjectSettings(), + getPublicationService(), getApplicationSettings())); + if (versions != null) { collectHistory(versions.getTo()); + } } /** @@ -405,7 +417,8 @@ public class DocumentFacade implements HistoryFacade { * @param projectSettingsService * project settings service */ - public void setProjectSettings(ProjectSettingsService projectSettingsService) { + public void setProjectSettings( + final ProjectSettingsService projectSettingsService) { _projectSettingsService = projectSettingsService; } @@ -424,7 +437,28 @@ public class DocumentFacade implements HistoryFacade { * @param publicationService * the publicationService to set */ - public void setPublicationService(PublicationService publicationService) { + public void setPublicationService( + final PublicationService publicationService) { _publicationService = publicationService; } + + /** + * Get the applicationSettings. + * + * @return the applicationSettings + */ + public ApplicationSettings getApplicationSettings() { + return _applicationSettings; + } + + /** + * Set the applicationSettings. + * + * @param applicationSettings + * the applicationSettings to set + */ + public void setApplicationSettings( + final ApplicationSettings applicationSettings) { + _applicationSettings = applicationSettings; + } } \ No newline at end of file diff --git a/Workspace/Siman/src/org/splat/simer/FileFacade.java b/Workspace/Siman/src/org/splat/simer/FileFacade.java index 740a2a7..0fd141d 100644 --- a/Workspace/Siman/src/org/splat/simer/FileFacade.java +++ b/Workspace/Siman/src/org/splat/simer/FileFacade.java @@ -7,59 +7,62 @@ import java.util.ResourceBundle; import org.splat.dal.bo.som.ConvertsRelation; - public class FileFacade { - private String surl; // URL of the file - private String format; // Extension of the file - private String comment; // Short description - private String size; - private String date; + private String surl; // URL of the file + private final String format; // Extension of the file + private String comment; // Short description + private final String size; + private final String date; + + // ============================================================================================================================== + // Constructor + // ============================================================================================================================== + + public FileFacade(final ConvertsRelation represented, + final ApplicationSettings applicationSettings) { + ResourceBundle custom = ResourceBundle.getBundle("som", + applicationSettings.getCurrentLocale()); + File export = represented.getTo().asFile(); + String path = export.getPath(); + String[] table = path.split("\\x2E"); + DecimalFormat tostring = new DecimalFormat(custom + .getString("size.format")); // Locale size display format + SimpleDateFormat convert = new SimpleDateFormat(custom + .getString("date.format")); // Date display format + + surl = applicationSettings.getRepositoryURL() + path; + surl = surl.replaceAll("'", "\\\\'"); + format = table[table.length - 1].toUpperCase(); + size = tostring.format(export.length() / 1000); + date = convert.format(represented.getTo().getDate()); + comment = represented.getDescription(); + if (comment == null) { + comment = ""; + } + } + + // ============================================================================================================================== + // Getters + // ============================================================================================================================== -// ============================================================================================================================== -// Constructor -// ============================================================================================================================== + public String getDate() { + return date; + } - public FileFacade (ConvertsRelation represented) { -// ------------------------------------------------ - ResourceBundle custom = ResourceBundle.getBundle("som", ApplicationSettings.getCurrentLocale()); - File export = represented.getTo().asFile(); - String path = export.getPath(); - String[] table = path.split("\\x2E"); - DecimalFormat tostring = new DecimalFormat(custom.getString("size.format")); // Locale size display format - SimpleDateFormat convert = new SimpleDateFormat(custom.getString("date.format")); // Date display format + public String getDescription() { + return comment; + } - surl = ApplicationSettings.getRepositoryURL() + path; - surl = surl.replaceAll("'", "\\\\'"); - format = table[table.length-1].toUpperCase(); - size = tostring.format(export.length()/1000); - date = convert.format(represented.getTo().getDate()); - comment = represented.getDescription(); - if (comment == null) comment = ""; - } + public String getFormat() { + return format; + } -// ============================================================================================================================== -// Getters -// ============================================================================================================================== + public String getSize() { + return size; + } - public String getDate () { -// ------------------------ - return date; - } - public String getDescription () { -// ------------------------------- - return comment; - } - public String getFormat () { -// ----------------------- - return format; - } - public String getSize () { -// ------------------------ - return size; - } - public String getURL () { -// ----------------------- - return surl; - } + public String getURL() { + return surl; + } } \ No newline at end of file diff --git a/Workspace/Siman/src/org/splat/simer/KnowledgeElementFacade.java b/Workspace/Siman/src/org/splat/simer/KnowledgeElementFacade.java index 2564f29..03265a4 100644 --- a/Workspace/Siman/src/org/splat/simer/KnowledgeElementFacade.java +++ b/Workspace/Siman/src/org/splat/simer/KnowledgeElementFacade.java @@ -9,6 +9,10 @@ public class KnowledgeElementFacade { private transient State _state; private transient String _value; private transient PopupMenu _popup; + /** + * Injected application settings service. + */ + private ApplicationSettings _applicationSettings; private enum State { closed, open @@ -18,9 +22,11 @@ public class KnowledgeElementFacade { // Constructor // ============================================================================================================================== - public KnowledgeElementFacade(final KnowledgeElementDTO represented) { + public KnowledgeElementFacade(final KnowledgeElementDTO represented, + final ApplicationSettings app) { _my = represented; _state = State.closed; + setApplicationSettings(app); this.refresh(); // Initializes the presentation of my knowledge } @@ -106,7 +112,7 @@ public class KnowledgeElementFacade { private void refresh() { String[] tags = { "", "", "", "", "" }; - _popup = ApplicationSettings.getPopupMenu("feedbex"); + _popup = getApplicationSettings().getPopupMenu("feedbex"); _value = _my.getValue(); // One line extract of the knowledge value @@ -211,4 +217,24 @@ public class KnowledgeElementFacade { } return res; } + + /** + * Get the applicationSettings. + * + * @return the applicationSettings + */ + public ApplicationSettings getApplicationSettings() { + return _applicationSettings; + } + + /** + * Set the applicationSettings. + * + * @param applicationSettings + * the applicationSettings to set + */ + public void setApplicationSettings( + final ApplicationSettings applicationSettings) { + _applicationSettings = applicationSettings; + } } \ No newline at end of file diff --git a/Workspace/Siman/src/org/splat/simer/MenuAction.java b/Workspace/Siman/src/org/splat/simer/MenuAction.java index c9c0dc9..6342b7b 100644 --- a/Workspace/Siman/src/org/splat/simer/MenuAction.java +++ b/Workspace/Siman/src/org/splat/simer/MenuAction.java @@ -30,7 +30,7 @@ public class MenuAction extends Action { * @return the selected menu item */ public String doSelectItem() { - SimpleMenu menu = ApplicationSettings.getMenu(_menu); + SimpleMenu menu = getApplicationSettings().getMenu(_menu); if (_item == null) { // Switch back to the menu, keeping the last selection getSession().put("menu.open", menu); // Activates the menu diff --git a/Workspace/Siman/src/org/splat/simer/OpenKnowledge.java b/Workspace/Siman/src/org/splat/simer/OpenKnowledge.java index cca5b9f..2b8347b 100644 --- a/Workspace/Siman/src/org/splat/simer/OpenKnowledge.java +++ b/Workspace/Siman/src/org/splat/simer/OpenKnowledge.java @@ -100,7 +100,8 @@ public class OpenKnowledge extends AbstractOpenObject { for (Iterator j = next .getAllSimulationContexts().iterator(); j.hasNext();) { _context.add(new SimulationContextFacade(j.next(), - getProjectSettings().getAllSteps())); + getProjectSettings().getAllSteps(), + getApplicationSettings())); } } value.append("

").append("").append( diff --git a/Workspace/Siman/src/org/splat/simer/OpenStudy.java b/Workspace/Siman/src/org/splat/simer/OpenStudy.java index 432d45a..256f84c 100644 --- a/Workspace/Siman/src/org/splat/simer/OpenStudy.java +++ b/Workspace/Siman/src/org/splat/simer/OpenStudy.java @@ -120,7 +120,8 @@ public class OpenStudy extends AbstractOpenObject implements OpenStudyServices { for (Iterator i = _ustep.getAllSimulationContexts() .iterator(); i.hasNext();) { _context.add(new SimulationContextFacade(i.next(), - getProjectSettings().getAllSteps())); + getProjectSettings().getAllSteps(), + getApplicationSettings())); } if (getStudyService().isStaffedBy(_mystudy, _cuser) || getStudyService().hasActor(_mystudy, _cuser)) { @@ -322,7 +323,8 @@ public class OpenStudy extends AbstractOpenObject implements OpenStudyServices { protected void add(final Publication doc) { DocumentFacade facade = new DocumentFacade(this, doc, - getProjectSettings(), getPublicationService()); + getProjectSettings(), getPublicationService(), + getApplicationSettings()); boolean first = (_contents.size() == 0); docpres.put(doc.getIndex(), facade); @@ -335,14 +337,15 @@ public class OpenStudy extends AbstractOpenObject implements OpenStudyServices { protected void add(final SimulationContext contex) { SimulationContextFacade facade = new SimulationContextFacade(contex, - getProjectSettings().getAllSteps()); + getProjectSettings().getAllSteps(), getApplicationSettings()); _context.add(facade); } protected void add(final KnowledgeElement kelm) { KnowledgeElementFacade facade = new KnowledgeElementFacade(BeanHelper - .copyBean(kelm, KnowledgeElementDTO.class)); + .copyBean(kelm, KnowledgeElementDTO.class), + getApplicationSettings()); // RKV KnowledgeIterator known = knowledge.get(kelm.getType().getIndex() - 2); // Knowledges are ordered by type index, from 0 to n-1, the first one being reserved (reason for -2) // RKV:Begin: Find a knowledge iterator for appropriate knowledge type @@ -437,7 +440,8 @@ public class OpenStudy extends AbstractOpenObject implements OpenStudyServices { for (Iterator j = i.next() .getAllSimulationContexts().iterator(); j.hasNext();) { _context.add(new SimulationContextFacade(j.next(), - getProjectSettings().getAllSteps())); + getProjectSettings().getAllSteps(), + getApplicationSettings())); } } } diff --git a/Workspace/Siman/src/org/splat/simer/SimulationContextFacade.java b/Workspace/Siman/src/org/splat/simer/SimulationContextFacade.java index 1124d3d..a85ecc9 100644 --- a/Workspace/Siman/src/org/splat/simer/SimulationContextFacade.java +++ b/Workspace/Siman/src/org/splat/simer/SimulationContextFacade.java @@ -23,9 +23,10 @@ public class SimulationContextFacade { // ============================================================================================================================== public SimulationContextFacade(final SimulationContext represented, - final List allSteps) { + final List allSteps, + final ApplicationSettings app) { _my = represented; - _popup = ApplicationSettings.getPopupMenu("scontext"); + _popup = app.getPopupMenu("scontext"); SimulationContextType type = _my.getType(); for (Iterator i = allSteps.iterator(); i @@ -40,9 +41,8 @@ public class SimulationContextFacade { _state = _my.getProgressState(); // inCHECK or APPROVED _name = type.getName(); if (type.isApproved()) { - _name = ResourceBundle.getBundle("som", - ApplicationSettings.getCurrentLocale()).getString( - "type.context." + _name); + _name = ResourceBundle.getBundle("som", app.getCurrentLocale()) + .getString("type.context." + _name); } else { _state = ProgressState.inDRAFT; } diff --git a/Workspace/Siman/src/org/splat/simer/StampFacade.java b/Workspace/Siman/src/org/splat/simer/StampFacade.java index 368f1da..5c43387 100644 --- a/Workspace/Siman/src/org/splat/simer/StampFacade.java +++ b/Workspace/Siman/src/org/splat/simer/StampFacade.java @@ -7,6 +7,7 @@ package org.splat.simer; */ import java.text.SimpleDateFormat; +import java.util.Locale; import java.util.ResourceBundle; import org.splat.dal.bo.som.Timestamp; @@ -24,11 +25,9 @@ public class StampFacade implements HistoryFacade { // Constructor // ============================================================================================================================== - public StampFacade(final Timestamp stamp) { - ResourceBundle labels = ResourceBundle.getBundle("labels", - ApplicationSettings.getCurrentLocale()); - ResourceBundle custom = ResourceBundle.getBundle("som", - ApplicationSettings.getCurrentLocale()); + public StampFacade(final Timestamp stamp, final Locale locale) { + ResourceBundle labels = ResourceBundle.getBundle("labels", locale); + ResourceBundle custom = ResourceBundle.getBundle("som", locale); SimpleDateFormat convert = new SimpleDateFormat(custom .getString("date.format")); // Date display format ValidationStep type = stamp.getType(); diff --git a/Workspace/Siman/src/org/splat/simer/StartAction.java b/Workspace/Siman/src/org/splat/simer/StartAction.java index 1299731..ab2832e 100644 --- a/Workspace/Siman/src/org/splat/simer/StartAction.java +++ b/Workspace/Siman/src/org/splat/simer/StartAction.java @@ -74,21 +74,18 @@ public class StartAction extends Action implements ServletRequestAware { .append("...").toString()); try { ProjectSettingsService project = getProjectSettings(); - ApplicationSettings wapp = getApplicationSettings().init( - wappurl.toString(), this.getLocale()); - String root = wapp.getApplicationRootPath(); + ApplicationSettings wapp = getApplicationSettings(); + wapp.setLocale(this.getLocale()); + String root = ApplicationSettings.getApplicationRootPath(); LOG.debug("Application root: " + root); // Database configuration project.configure(root - + wapp.getApplicationProperty("wapp.configuration")); - - // Application configuration - System.setProperty("java.security.auth.login.config", root - + wapp.getApplicationProperty("wapp.login")); - wapp.configure(root - + wapp.getApplicationProperty("wapp.customization")); + + ApplicationSettings.getApplicationProperty("wapp.configuration")); + // Configure menus for the current user + wapp.configure(); + // Initialization of the user session Map session = getSession(); diff --git a/Workspace/Siman/src/org/splat/simer/StudyPropertiesAction.java b/Workspace/Siman/src/org/splat/simer/StudyPropertiesAction.java index 00efb1d..5f460ef 100644 --- a/Workspace/Siman/src/org/splat/simer/StudyPropertiesAction.java +++ b/Workspace/Siman/src/org/splat/simer/StudyPropertiesAction.java @@ -4,18 +4,18 @@ import java.util.Iterator; import java.util.List; import java.util.Vector; +import org.splat.dal.bo.kernel.User; +import org.splat.dal.bo.som.DocumentType; +import org.splat.dal.bo.som.Study; +import org.splat.dal.bo.som.ValidationCycle; +import org.splat.dal.bo.som.ValidationStep; import org.splat.kernel.InvalidPropertyException; import org.splat.kernel.Name; -import org.splat.dal.bo.kernel.User; import org.splat.service.DocumentTypeService; import org.splat.service.StudyService; import org.splat.service.UserService; import org.splat.som.ApplicationRights; -import org.splat.dal.bo.som.DocumentType; -import org.splat.dal.bo.som.Study; import org.splat.som.StudyRights; -import org.splat.dal.bo.som.ValidationCycle; -import org.splat.dal.bo.som.ValidationStep; /** * Edit/display study properties (study configuration) screen action. @@ -59,35 +59,30 @@ public class StudyPropertiesAction extends DisplayStudyStepAction { * Injected user service. */ private UserService _userService; - + /** - * Value of the menu property. - * It can be: none, create, open, study, knowledge, sysadmin, help. + * Value of the menu property. It can be: none, create, open, study, knowledge, sysadmin, help. */ private String _menuProperty; - + /** - * Value of the title bar property. - * It can be: study, knowledge. + * Value of the title bar property. It can be: study, knowledge. */ private String _titleProperty; - + /** - * Value of the tool bar property. - * It can be: none, standard, study, back. + * Value of the tool bar property. It can be: none, standard, study, back. */ private String _toolProperty; - + /** - * Value of the left menu property. - * It can be: open, study, knowledge, scenario. + * Value of the left menu property. It can be: open, study, knowledge, scenario. */ private String _leftMenuProperty; - + /** - * Property that indicates whether the current open study is editable or not. - * On the screen it looks like pen on the status icon, pop-up menu also can be called. - * It is necessary for correct building the title bar. + * Property that indicates whether the current open study is editable or not. On the screen it looks like pen on the status icon, pop-up + * menu also can be called. It is necessary for correct building the title bar. */ private String _editDisabledProperty = "false"; @@ -129,38 +124,42 @@ public class StudyPropertiesAction extends DisplayStudyStepAction { StudyRights user = _openStudy.getStudyRights(); for (Iterator i = other.iterator(); i.hasNext();) { DocumentType type = i.next(); - ValidationCycle cycle = getStudyService().getValidationCycleOf(study, type); + ValidationCycle cycle = getStudyService().getValidationCycleOf( + study, type); if (cycle.isDefault()) { - validefault = new ValidationFacade(cycle); + validefault = new ValidationFacade(cycle, + getApplicationSettings().getCurrentLocale()); continue; } - validation.add(new ValidationFacade(cycle)); + validation.add(new ValidationFacade(cycle, getApplicationSettings() + .getCurrentLocale())); i.remove(); } - if (validefault != null) + if (validefault != null) { validation.add(validefault); // In order to be at the end + } member = getStudyService().getContributors(study); staff = null; validor = null; - + setMenuProperty("study"); setTitleProperty("study"); setEditDisabledProperty("true"); setToolProperty("back"); setLeftMenuProperty("open"); - initializationFullScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty, _leftMenuProperty); + initializationFullScreenContext(_menuProperty, _titleProperty, + _editDisabledProperty, _toolProperty, _leftMenuProperty); - if (_openStudy.isOpenForWriting() && user.canEditProperties()) { + if (_openStudy.isOpenForWriting() && user.canEditProperties()) { return "edit"; - } - else { + } else { return "display"; } } public String doEditTitle() { -// Session connex = Database.getCurSession(); -// Transaction transax = connex.beginTransaction(); + // Session connex = Database.getCurSession(); + // Transaction transax = connex.beginTransaction(); _openStudy = getOpenStudy(); validation = new Vector(); @@ -170,36 +169,41 @@ public class StudyPropertiesAction extends DisplayStudyStepAction { Study study = _openStudy.getStudyObject(); for (Iterator i = other.iterator(); i.hasNext();) { DocumentType type = i.next(); - ValidationCycle cycle = getStudyService().getValidationCycleOf(study, type); + ValidationCycle cycle = getStudyService().getValidationCycleOf( + study, type); if (cycle.isDefault()) { - validefault = new ValidationFacade(cycle); + validefault = new ValidationFacade(cycle, + getApplicationSettings().getCurrentLocale()); continue; } - validation.add(new ValidationFacade(cycle)); + validation.add(new ValidationFacade(cycle, getApplicationSettings() + .getCurrentLocale())); } - if (validefault != null) + if (validefault != null) { validation.add(validefault); // In order to be at the end + } member = getStudyService().getContributors(study); staff = null; validor = null; other = null; -// transax.commit(); - + // transax.commit(); + setMenuProperty("study"); setTitleProperty("study"); setEditDisabledProperty("true"); setToolProperty("back"); setLeftMenuProperty("open"); - initializationFullScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty, _leftMenuProperty); + initializationFullScreenContext(_menuProperty, _titleProperty, + _editDisabledProperty, _toolProperty, _leftMenuProperty); setActionType("edititle"); return SUCCESS; } public String doEditContributors() { -// Session connex = Database.getCurSession(); -// Transaction transax = connex.beginTransaction(); + // Session connex = Database.getCurSession(); + // Transaction transax = connex.beginTransaction(); _openStudy = getOpenStudy(); validation = new Vector(); @@ -209,15 +213,19 @@ public class StudyPropertiesAction extends DisplayStudyStepAction { Study study = _openStudy.getStudyObject(); for (Iterator i = other.iterator(); i.hasNext();) { DocumentType type = i.next(); - ValidationCycle cycle = getStudyService().getValidationCycleOf(study, type); + ValidationCycle cycle = getStudyService().getValidationCycleOf( + study, type); if (cycle.isDefault()) { - validefault = new ValidationFacade(cycle); + validefault = new ValidationFacade(cycle, + getApplicationSettings().getCurrentLocale()); continue; } - validation.add(new ValidationFacade(cycle)); + validation.add(new ValidationFacade(cycle, getApplicationSettings() + .getCurrentLocale())); } - if (validefault != null) + if (validefault != null) { validation.add(validefault); // In order to be at the end + } member = getStudyService().getContributors(study); staff = getUserService().selectAllUsers(); validor = null; @@ -227,25 +235,27 @@ public class StudyPropertiesAction extends DisplayStudyStepAction { User next = i.next(); ApplicationRights he = new ApplicationRights(next); if (next.equals(me) || member.contains(next) - || !he.canContributeToStudy()) + || !he.canContributeToStudy()) { i.remove(); + } } -// transax.commit(); - + // transax.commit(); + setMenuProperty("study"); setTitleProperty("study"); setEditDisabledProperty("true"); setToolProperty("back"); setLeftMenuProperty("open"); - initializationFullScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty, _leftMenuProperty); + initializationFullScreenContext(_menuProperty, _titleProperty, + _editDisabledProperty, _toolProperty, _leftMenuProperty); setActionType("edibutor"); return SUCCESS; } public String doEditCycle() { -// Session connex = Database.getCurSession(); -// Transaction transax = connex.beginTransaction(); + // Session connex = Database.getCurSession(); + // Transaction transax = connex.beginTransaction(); _openStudy = getOpenStudy(); validation = new Vector(); @@ -255,19 +265,23 @@ public class StudyPropertiesAction extends DisplayStudyStepAction { Study study = _openStudy.getStudyObject(); for (Iterator i = other.iterator(); i.hasNext();) { DocumentType type = i.next(); - ValidationCycle cycle = getStudyService().getValidationCycleOf(study, type); + ValidationCycle cycle = getStudyService().getValidationCycleOf( + study, type); if (cycle.isDefault()) { - validefault = new ValidationFacade(cycle); + validefault = new ValidationFacade(cycle, + getApplicationSettings().getCurrentLocale()); continue; } if (type.getName().equals(edicycle)) { this.type = type.getIndex(); } - validation.add(new ValidationFacade(cycle)); + validation.add(new ValidationFacade(cycle, getApplicationSettings() + .getCurrentLocale())); i.remove(); } - if (validefault != null) + if (validefault != null) { validation.add(validefault); // In order to be at the end + } member = getStudyService().getContributors(study); validor = new Vector(); staff = null; @@ -276,30 +290,33 @@ public class StudyPropertiesAction extends DisplayStudyStepAction { User next = i.next(); ApplicationRights he = new ApplicationRights(next); if (he.canValidate()) { - if (next.equals(study.getAuthor())) - validor.add(new ValidationFacade.ByManager(next)); - else + if (next.equals(study.getAuthor())) { + validor.add(new ValidationFacade.ByManager(next, + getApplicationSettings().getCurrentLocale())); + } else { validor.add(next); + } } } -// transax.commit(); - + // transax.commit(); + setMenuProperty("study"); setTitleProperty("study"); setEditDisabledProperty("true"); setToolProperty("back"); setLeftMenuProperty("open"); - initializationFullScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty, _leftMenuProperty); + initializationFullScreenContext(_menuProperty, _titleProperty, + _editDisabledProperty, _toolProperty, _leftMenuProperty); setActionType("edicycle"); - + return SUCCESS; } public String doEdition() { // -------------------------- -// Session connex = Database.getCurSession(); -// Transaction transax = connex.beginTransaction(); + // Session connex = Database.getCurSession(); + // Transaction transax = connex.beginTransaction(); Study study = getOpenStudy().getStudyObject(); if (tosave == Save.title) { @@ -314,35 +331,42 @@ public class StudyPropertiesAction extends DisplayStudyStepAction { } else if (tosave == Save.contributor) { // Edition of contributors - if (contributors == null) + if (contributors == null) { contributors = ""; - if (candidates == null) + } + if (candidates == null) { candidates = ""; + } String[] parsekept = contributors.split(","); String[] parsenew = candidates.split(","); - Vector toremove = new Vector(getStudyService().getContributors(study)); + Vector toremove = new Vector(getStudyService() + .getContributors(study)); for (int i = 0; i < parsekept.length; i++) { - if (parsekept[i].length() == 0) + if (parsekept[i].length() == 0) { continue; // Yet no contributor + } int index = Integer.valueOf(parsekept[i].trim()); for (Iterator j = toremove.iterator(); j.hasNext();) { long present = j.next().getIndex(); - if (present != index) + if (present != index) { continue; + } j.remove(); break; } } int size = toremove.size(); - if (size > 0) + if (size > 0) { getStudyService().removeContributor(study, toremove.toArray(new User[size])); + } for (int i = 0; i < parsenew.length; i++) { - if (parsenew[i].length() == 0) + if (parsenew[i].length() == 0) { continue; // No any new contributor + } int index = Integer.valueOf(parsenew[i].trim()); User newser = getUserService().selectUser(index); @@ -367,16 +391,17 @@ public class StudyPropertiesAction extends DisplayStudyStepAction { } getStudyService().setValidationCycle(study, apply, vprop); } -// transax.commit(); + // transax.commit(); doInitialize(); // Re-initialization following the above edition - + setMenuProperty("study"); setTitleProperty("study"); setEditDisabledProperty("true"); setToolProperty("back"); setLeftMenuProperty("open"); - initializationFullScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty, _leftMenuProperty); + initializationFullScreenContext(_menuProperty, _titleProperty, + _editDisabledProperty, _toolProperty, _leftMenuProperty); return SUCCESS; } @@ -530,12 +555,14 @@ public class StudyPropertiesAction extends DisplayStudyStepAction { * @param documentTypeService * the documentTypeService to set */ - public void setDocumentTypeService(final DocumentTypeService documentTypeService) { + public void setDocumentTypeService( + final DocumentTypeService documentTypeService) { _documentTypeService = documentTypeService; } /** * Get the userService. + * * @return the userService */ public UserService getUserService() { @@ -544,14 +571,17 @@ public class StudyPropertiesAction extends DisplayStudyStepAction { /** * Set the userService. - * @param userService the userService to set + * + * @param userService + * the userService to set */ public void setUserService(final UserService userService) { _userService = userService; } - + /** * Get the menuProperty. + * * @return the menuProperty */ @Override @@ -561,15 +591,18 @@ public class StudyPropertiesAction extends DisplayStudyStepAction { /** * Set the menuProperty. - * @param menuProperty the menuProperty to set + * + * @param menuProperty + * the menuProperty to set */ @Override public void setMenuProperty(final String menuProperty) { this._menuProperty = menuProperty; } - + /** * Get the _titleProperty. + * * @return the _titleProperty */ @Override @@ -579,7 +612,9 @@ public class StudyPropertiesAction extends DisplayStudyStepAction { /** * Set the _titleProperty. - * @param _titleProperty the titleProperty to set + * + * @param _titleProperty + * the titleProperty to set */ @Override public void setTitleProperty(final String titleProperty) { @@ -588,6 +623,7 @@ public class StudyPropertiesAction extends DisplayStudyStepAction { /** * Get the editDisabledProperty. + * * @return the editDisabledProperty */ @Override @@ -597,7 +633,9 @@ public class StudyPropertiesAction extends DisplayStudyStepAction { /** * Set the editDisabledProperty. - * @param editDisabledProperty the editDisabledProperty to set + * + * @param editDisabledProperty + * the editDisabledProperty to set */ @Override public final void setEditDisabledProperty(final String editDisabledProperty) { @@ -606,6 +644,7 @@ public class StudyPropertiesAction extends DisplayStudyStepAction { /** * Get the toolProperty. + * * @return the toolProperty */ @Override @@ -615,15 +654,18 @@ public class StudyPropertiesAction extends DisplayStudyStepAction { /** * Set the toolProperty. - * @param toolProperty the toolProperty to set + * + * @param toolProperty + * the toolProperty to set */ @Override public void setToolProperty(final String toolProperty) { _toolProperty = toolProperty; } - + /** * Get the leftMenuProperty. + * * @return the leftMenuProperty */ @Override @@ -633,7 +675,9 @@ public class StudyPropertiesAction extends DisplayStudyStepAction { /** * Set the leftMenuProperty. - * @param leftMenuProperty the leftMenuProperty to set + * + * @param leftMenuProperty + * the leftMenuProperty to set */ @Override public void setLeftMenuProperty(final String leftMenuProperty) { diff --git a/Workspace/Siman/src/org/splat/simer/ValidationFacade.java b/Workspace/Siman/src/org/splat/simer/ValidationFacade.java index ba40df6..065042a 100644 --- a/Workspace/Siman/src/org/splat/simer/ValidationFacade.java +++ b/Workspace/Siman/src/org/splat/simer/ValidationFacade.java @@ -1,5 +1,6 @@ package org.splat.simer; +import java.util.Locale; import java.util.ResourceBundle; import org.splat.dal.bo.kernel.User; @@ -19,6 +20,16 @@ public class ValidationFacade { protected transient String _name; protected transient long _index; + /** + * Create a localized named user option. + * @param key option label key + * @param locale current locale + */ + public UserOption(final String key, final Locale locale) { + super(); + _name = ResourceBundle.getBundle("labels", locale).getString(key); + } + public long getIndex() { return _index; } @@ -30,31 +41,22 @@ public class ValidationFacade { } protected static class NotRequired extends UserOption { - protected NotRequired() { - super(); - _name = ResourceBundle.getBundle("labels", - ApplicationSettings.getCurrentLocale()).getString( - "label.skipped"); + protected NotRequired(final Locale locale) { + super("label.skipped", locale); _index = 0; } } protected static class ByAuthor extends UserOption { - protected ByAuthor() { - super(); - _name = ResourceBundle.getBundle("labels", - ApplicationSettings.getCurrentLocale()).getString( - "label.bytheauthor"); + protected ByAuthor(final Locale locale) { + super("label.bytheauthor", locale); _index = 0; } } protected static class ByManager extends UserOption { - protected ByManager(final User manager) { - super(); - _name = ResourceBundle.getBundle("labels", - ApplicationSettings.getCurrentLocale()).getString( - "label.me"); + protected ByManager(final User manager, final Locale locale) { + super("label.me", locale); _index = manager.getIndex(); } } @@ -63,7 +65,7 @@ public class ValidationFacade { // Constructors // ============================================================================================================================== - public ValidationFacade(final ValidationCycle cycle) { + public ValidationFacade(final ValidationCycle cycle, final Locale locale) { _myicon = "icon.empty.png"; if (cycle.isDefault()) { _myname = "default"; @@ -77,10 +79,10 @@ public class ValidationFacade { _myreviewer = cycle.getActor(ValidationStep.REVIEW); _myapprover = cycle.getActor(ValidationStep.APPROVAL); if (_mypublisher == null) { - _mypublisher = new ByAuthor(); + _mypublisher = new ByAuthor(locale); } if (_myreviewer == null || _myapprover == null) { - Name skipped = new NotRequired(); + Name skipped = new NotRequired(locale); if (_myreviewer == null) { _myreviewer = skipped; } diff --git a/Workspace/Siman/src/org/splat/simer/admin/SimulationContextAction.java b/Workspace/Siman/src/org/splat/simer/admin/SimulationContextAction.java index 05d56fb..d952aef 100644 --- a/Workspace/Siman/src/org/splat/simer/admin/SimulationContextAction.java +++ b/Workspace/Siman/src/org/splat/simer/admin/SimulationContextAction.java @@ -149,7 +149,7 @@ public class SimulationContextAction extends Action { } public boolean isCurrent() { - return _locale.equals(ApplicationSettings.getCurrentLocale()); + return _locale.equals(getApplicationSettings().getCurrentLocale()); } } diff --git a/Workspace/Siman/src/spring/applicationContext.xml b/Workspace/Siman/src/spring/applicationContext.xml index 0fc145c..70c4bb4 100644 --- a/Workspace/Siman/src/spring/applicationContext.xml +++ b/Workspace/Siman/src/spring/applicationContext.xml @@ -34,7 +34,7 @@ http://www.springframework.org/schema/context/spring-context-3.0.xsd"> + class="org.splat.simer.ApplicationSettings" scope="session"> -- 2.39.2