import java.io.File;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
-import java.util.Vector;
import javax.servlet.ServletContext;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.w3c.dom.NamedNodeMap;
import org.apache.log4j.Logger;
import org.splat.dal.bo.kernel.User;
-import org.splat.manox.XDOM;
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.KnowledgeElement;
import org.splat.dal.bo.som.ProgressState;
+import org.splat.dal.bo.som.SimulationContext;
+import org.splat.manox.XDOM;
import org.splat.service.DocumentTypeService;
import org.splat.service.technical.ProjectSettingsService;
-import org.splat.simer.Converter;
-import org.splat.dal.bo.som.SimulationContext;
+import org.splat.som.DocumentRights;
import org.splat.som.Step;
import org.splat.som.StudyRights;
import org.splat.wapp.MenuItem;
-import org.splat.wapp.PopupMenu;
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.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
public class ApplicationSettings implements ServletContextAware {
/**
* Application settings logger.
*/
- protected final static Logger logger = Logger
+ protected final static Logger LOG = Logger
.getLogger(ApplicationSettings.class);
/**
private String wappserver;
private String wappname;
- private Properties wapprops = new Properties(); // General properties from the application properties files
+ private final Properties wapprops = new Properties(); // General properties from the application properties files
private Locale locale; // Current user locale
- private Map<String, SimpleMenu> menus = new HashMap<String, SimpleMenu>(); // Application menus
+ private final Map<String, SimpleMenu> menus = new HashMap<String, SimpleMenu>(); // Application menus
private Map<Integer, ToolBar> bars = null; // Study module-bars structured by steps
private Map<String, PopupMenu> popups = null;
private Map<String, Map<String, Object>> filter = null; // Named search filters
private Map<String, String> tempfile = null; // Available template files
private String[] viewermap = null; // List of file extensions mapped to a viewer
private Map<String, Converter> convertmap = null; // Available document format converters
- private Properties jndprops = new Properties(); // JNDI context for launching converters
+ private final Properties jndprops = new Properties(); // JNDI context for launching converters
- private static ApplicationSettings my = null; // Singleton instance
+ private static ApplicationSettings my = new ApplicationSettings(); // Singleton instance
/**
* Injected project settings service.
*/
* @param projectSettingsService
* the projectSettingsService to set
*/
- public void setProjectSettings(ProjectSettingsService projectSettingsService) {
+ public void setProjectSettings(final ProjectSettingsService projectSettingsService) {
_projectSettingsService = projectSettingsService;
}
.confirmation("message.delete.study"));
}
- public boolean isEnabled(String name) {
- if (user == null)
+ @Override
+ public boolean isEnabled(final String name) {
+ if (user == null) {
return false; // Should not happen
+ }
Item item = Item.valueOf(name);
- if (item == Item.publish)
+ if (item == Item.publish) {
return user.canPublish();
- if (item == Item.edit)
+ }
+ if (item == Item.edit) {
return user.canEditProperties();
- if (item == Item.script)
+ }
+ if (item == Item.script) {
return user.canAddScenario();
- if (item == Item.version)
+ }
+ if (item == Item.version) {
return user.canVersion();
- if (item == Item.remove)
+ }
+ if (item == Item.remove) {
return user.canRemove();
- if (item == Item.purge)
+ }
+ if (item == Item.purge) {
return user.canPurge();
+ }
return false;
}
- public void setContext(String name, Object context) {
+ @Override
+ public void setContext(final String name, final Object context) {
if (context instanceof StudyRights) {
user = (StudyRights) context; // Just for optimizing
boolean history = user.getOperand().isVersioned();
PopupItem item = this.item("remove");
- if (history)
+ if (history) {
item.rename("menu.remove.version");
- else
+ } else {
item.rename("menu.remove.study");
+ }
}
}
}
"message.delete.document"));
}
- public boolean isEnabled(String name) {
- if (user == null)
+ @Override
+ public boolean isEnabled(final String name) {
+ if (user == null) {
return false; // Should not happen
+ }
Item item = Item.valueOf(name);
- if (item == Item.accept)
+ if (item == Item.accept) {
return user.canAccept();
- if (item == Item.promote)
+ }
+ if (item == Item.promote) {
return user.canPromote();
- if (item == Item.rename)
+ }
+ if (item == Item.rename) {
return user.canRename();
- if (item == Item.attach)
+ }
+ if (item == Item.attach) {
return user.canAttach();
- if (item == Item.version)
+ }
+ if (item == Item.version) {
return user.canVersion();
- if (item == Item.replace)
+ }
+ if (item == Item.replace) {
return user.canReplace();
- if (item == Item.purge)
+ }
+ if (item == Item.purge) {
return user.canPurge();
- if (item == Item.remove)
+ }
+ if (item == Item.remove) {
return user.canRemove();
+ }
return false;
}
- public void setContext(String name, Object context) {
+ @Override
+ public void setContext(final String name, final Object context) {
if (context instanceof DocumentRights) {
user = (DocumentRights) context; // Just for optimizing
Document downer = user.getOperand();
PopupItem item = this.item("remove");
- if (downer.isVersioned())
+ if (downer.isVersioned()) {
item.rename("menu.remove.version");
- else
+ } else {
item.rename("menu.remove.document");
+ }
}
}
}
"notyetimplemented").confirmation("message.purge.document"));
}
- public boolean isEnabled(String name) {
- if (user == null)
+ @Override
+ public boolean isEnabled(final String name) {
+ if (user == null) {
return false; // Should not happen
+ }
Item item = Item.valueOf(name);
- if (item == Item.demote)
+ if (item == Item.demote) {
return user.canDemote();
- if (item == Item.promote)
+ }
+ if (item == Item.promote) {
return user.canReview();
- if (item == Item.attach)
+ }
+ if (item == Item.attach) {
return user.canAttach();
- if (item == Item.version)
+ }
+ if (item == Item.version) {
return user.canVersion();
- if (item == Item.purge)
+ }
+ if (item == Item.purge) {
return user.canPurge();
+ }
return false;
}
- public void setContext(String name, Object context) {
+ @Override
+ public void setContext(final String name, final Object context) {
if (context instanceof DocumentRights) {
user = (DocumentRights) context; // Just for optimizing
}
private static class NotResultDocumentPopup extends PopupMenu {
// ----------------------------------------------------------------
- private DocumentRights user = null;
+ private final DocumentRights user = null;
private NotResultDocumentPopup() {
addItem("demote", new PopupItem("menu.demote").icon(
.confirmation("message.approve.document"));
}
- public boolean isEnabled(String name) {
- if (user == null)
+ @Override
+ public boolean isEnabled(final String name) {
+ if (user == null) {
return false; // Should not happen
+ }
Item item = Item.valueOf(name);
- if (item == Item.undo)
+ if (item == Item.undo) {
return user.canInvalidate();
- if (item == Item.demote)
+ }
+ if (item == Item.demote) {
return user.canDemote();
- if (item == Item.approve)
+ }
+ if (item == Item.approve) {
return user.canApprove();
+ }
return false;
}
- public void setContext(String name, Object context) {
+ @Override
+ public void setContext(final String name, final Object context) {
if (context instanceof DocumentRights) {
user = (DocumentRights) context; // Just for optimizing
}
"message.delete.document"));
}
- public boolean isEnabled(String name) {
- if (user == null)
+ @Override
+ public boolean isEnabled(final String name) {
+ if (user == null) {
return false; // Should not happen
+ }
Item item = Item.valueOf(name);
- if (item == Item.rename)
+ if (item == Item.rename) {
return user.canRename();
- if (item == Item.replace)
+ }
+ if (item == Item.replace) {
return user.canReplace();
- if (item == Item.remove)
+ }
+ if (item == Item.remove) {
return user.canRemove();
+ }
return false;
}
- public void setContext(String name, Object context) {
+ @Override
+ public void setContext(final String name, final Object context) {
if (context instanceof DocumentRights) {
user = (DocumentRights) context; // Just for optimizing
}
"message.delete.context"));
}
- public boolean isEnabled(String name) {
+ @Override
+ public boolean isEnabled(final String name) {
Item item = Item.valueOf(name);
if (item == Item.rename) {
return true;
}
- public void setContext(String name, Object context) {
+ @Override
+ public void setContext(final String name, final Object context) {
if (context instanceof SimulationContextFacade) {
owner = (SimulationContextFacade) context; // Just for optimizing
} else {
"message.delete.knowledge"));
}
- public boolean isEnabled(String name) {
+ @Override
+ public boolean isEnabled(final String name) {
Item item = Item.valueOf(name);
if (item == Item.promote) {
- if (owner.getProgressState() != ProgressState.inDRAFT)
+ if (owner.getProgressState() != ProgressState.inDRAFT) {
return false;
+ }
} else if (item == Item.demote) {
- if (owner.getProgressState() != ProgressState.inCHECK)
+ if (owner.getProgressState() != ProgressState.inCHECK) {
return false;
+ }
}
return true;
}
- public void setContext(String name, Object context) {
- if (context instanceof KnowledgeElement)
+ @Override
+ public void setContext(final String name, final Object context) {
+ if (context instanceof KnowledgeElement) {
owner = (KnowledgeElement) context; // Just for optimizing
- else {
+ } else {
super.setContext(name, context);
}
}
// ==============================================================================================================================
public static ApplicationSettings getMe() {
- // ------------------------------------------
- if (my == null) {
- my = new ApplicationSettings();
- }
return my; // The application is supposed being previously created below
}
* @param lang
* @return
*/
- public ApplicationSettings init(String wappurl, Locale lang)
+ public ApplicationSettings init(final String wappurl, final Locale lang)
throws IOException {
ClassLoader cloader = getClass().getClassLoader();
String[] wurl = wappurl.split("/"); // [0]="http:", [1]="", [2]="{server}:{port}", [3]="name"
wapprops.load(cloader.getResourceAsStream(wappname + ".properties"));
jndprops.load(cloader.getResourceAsStream("jndi.properties"));
- logger.info("Application root set to "
+ LOG.info("Application root set to "
+ wapprops.getProperty("wapp.root"));
if (my == null) {
my = this;
// Public member functions
// ==============================================================================================================================
- public void configure(String filename) {
+ public void configure(final String filename) {
// ---------------------------------------
// Non customizable settings
menus.clear();
fprop.put("author", "0");
fprop.put("reference", "");
fprop.put("title", "");
- fprop.put("context", new Vector<SimulationContext>());
+ fprop.put("context", new ArrayList<SimulationContext>());
Map<String, Object> gprop = new HashMap<String, Object>();
gprop.put("visibility", "PUBLIC");
gprop.put("author", "0");
gprop.put("reference", "");
gprop.put("title", "");
- gprop.put("context", new Vector<SimulationContext>());
+ gprop.put("context", new ArrayList<SimulationContext>());
defdoctype = new LinkedHashMap<String, DocumentType>();
tempfile = new HashMap<String, String>();
if (config.exists()) {
loadCustomization(config); // Sets default document types, installed modules and available templates
} else {
- logger.info("Could not find the application configuration file \""
+ LOG.info("Could not find the application configuration file \""
+ config.getAbsolutePath() + "\", using default settings");
}
// Settings based on the customization
.hasNext();) {
ProjectSettingsService.Step step = i.next();
List<String> formats = getDefaultFormats(step);
- if (formats.size() == 0)
+ if (formats.size() == 0) {
continue;
+ }
ToolBar bar = new ToolBar(24); // Height of the module-bar
HashSet<String> module = new HashSet<String>(); // For not duplicating modules
for (Iterator<String> j = formats.iterator(); j.hasNext();) {
String format = j.next();
String command = getApplicationProperty("executable." + format);
- if (command == null)
+ if (command == null) {
continue; // Module not installed
- if (module.contains(command))
+ }
+ if (module.contains(command)) {
continue;
+ }
module.add(command);
String[] parsed = command.split("/");
String[] name = parsed[parsed.length - 1].split("\\x2E");
File image = new File(ApplicationSettings
.getApplicationSkinPath()
+ icon);
- if (!image.exists())
+ if (!image.exists()) {
icon = "tool.any.png";
+ }
bar.addTool(tool, icon, command);
} else {
docname = "/jsp/newDocument.jsp?type=" + docname;
File image = new File(ApplicationSettings
.getApplicationSkinPath()
+ icon);
- if (!image.exists())
+ if (!image.exists()) {
icon = "tool.any.png";
+ }
bar.addTool(name[0], icon, command, docname);
}
}
- if (!bar.isEmpty())
+ if (!bar.isEmpty()) {
bars.put(step.getNumber(), bar);
+ }
}
}
- public String getApplicationProperty(String name) {
+ public String getApplicationProperty(final String name) {
return wapprops.getProperty(name); // May be null
}
return url.toString();
}
- public Map<String, Object> getFilter(String name) {
+ public Map<String, Object> getFilter(final String name) {
// --------------------------------------------------
return filter.get(name);
}
- public ToolBar getModuleBar(Step step) {
+ public ToolBar getModuleBar(final Step step) {
// -----------------------------------------
return bars.get(step.getNumber());
}
return my.getApplicationRootPath() + "skin/";
}
- public static Converter getConverter(DocumentType type, String format) {
+ public static Converter getConverter(final DocumentType type, final String format) {
// -----------------------------------------------------------------------
return my.convertmap.get(format + type.getName()); // May be null;
}
- public static DocumentType getDefaultDocumentType(Step step, String format) {
+ public static DocumentType getDefaultDocumentType(final Step step, final String format) {
// ----------------------------------------------------------------------------
String[] table = format.split("\\x2E");
return my.defdoctype.get(step.getNumber() + "."
+ table[table.length - 1]); // May be null
}
- public static String getDownloadURL(User user) {
+ public static String getDownloadURL(final User user) {
// --------------------------------------------------
StringBuffer url = new StringBuffer("http://").append(my.wappserver)
.append("/download/").append(user.getUsername()).append("/");
return my.locale;
}
- public static SimpleMenu getMenu(String name) {
+ public static SimpleMenu getMenu(final String name) {
// ----------------------------------------------
return my.menus.get(name);
}
- public static PopupMenu getPopupMenu(String name) {
+ public static PopupMenu getPopupMenu(final String name) {
// --------------------------------------------------
return my.popups.get(name);
}
// ---------------------------------------------
String[] code = my.wapprops.getProperty("locale.supported").split(",");
Locale[] result = new Locale[code.length];
- for (int i = 0; i < code.length; i++)
+ for (int i = 0; i < code.length; i++) {
result[i] = new Locale(code[i]);
+ }
return result;
}
// Private services
// ==============================================================================================================================
- private List<String> getDefaultFormats(ProjectSettingsService.Step step) {
+ private List<String> getDefaultFormats(final ProjectSettingsService.Step step) {
// ------------------------------------------------------------------
Set<String> keys = defdoctype.keySet();
int number = step.getNumber();
- Vector<String> result = new Vector<String>();
+ List<String> result = new ArrayList<String>();
for (Iterator<String> i = keys.iterator(); i.hasNext();) {
String[] key = i.next().split("\\x2E");
- if (Integer.valueOf(key[0]) != number)
+ if (Integer.valueOf(key[0]) != number) {
continue;
- if (key[1].equals("pdf"))
+ }
+ if (key[1].equals("pdf")) {
continue; // PDF is not an authoring format
+ }
result.add(key[1]); // Formats are unique
}
return result;
}
- private void loadCustomization(File config) {
+ private void loadCustomization(final File config) {
// --------------------------------------------
try {
DocumentBuilderFactory dfactory = javax.xml.parsers.DocumentBuilderFactory
}
for (int i = 0; i < nlist.getLength(); i++) {
child = nlist.item(i);
- if (!child.getNodeName().equals("step"))
+ if (!child.getNodeName().equals("step")) {
continue;
+ }
String nstep = child.getAttributes().getNamedItem("number")
.getNodeValue();
NodeList map = child.getChildNodes();
for (int j = 0; j < map.getLength(); j++) {
child = map.item(j);
- if (!child.getNodeName().equals("mapping"))
+ if (!child.getNodeName().equals("mapping")) {
continue;
+ }
NamedNodeMap natr = child.getAttributes();
String dext = natr.getNamedItem("extension").getNodeValue();
String type = natr.getNamedItem("type").getNodeValue();
nlist = child.getChildNodes();
for (int i = 0; i < nlist.getLength(); i++) {
child = nlist.item(i);
- if (!child.getNodeName().equals("mapping"))
+ if (!child.getNodeName().equals("mapping")) {
continue;
+ }
NamedNodeMap natr = child.getAttributes();
String dext = natr.getNamedItem("extension").getNodeValue();
nlist = child.getChildNodes();
for (int i = 0; i < nlist.getLength(); i++) {
child = nlist.item(i);
- if (!child.getNodeName().equals("document"))
+ if (!child.getNodeName().equals("document")) {
continue;
+ }
NamedNodeMap natr = child.getAttributes();
String type = natr.getNamedItem("type").getNodeValue();
tempfile.put(type, file);
}
} catch (Exception error) {
- logger.info("Error in customization", error);
+ LOG.info("Error in customization", error);
}
}
* @param documentTypeService
* the documentTypeService to set
*/
- public void setDocumentTypeService(DocumentTypeService documentTypeService) {
+ public void setDocumentTypeService(final DocumentTypeService documentTypeService) {
_documentTypeService = documentTypeService;
}
* @see org.apache.struts2.util.ServletContextAware#setServletContext(javax.servlet.ServletContext)
*/
@Override
- public void setServletContext(ServletContext context) {
+ public void setServletContext(final ServletContext context) {
_servletContext = context;
}