001: /*
002: * This file is part of the WfMOpen project.
003: * Copyright (C) 2001-2005 Danet GmbH (www.danet.de), BU BTS.
004: * All rights reserved.
005: *
006: * This program is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU General Public License as published by
008: * the Free Software Foundation; either version 2 of the License, or
009: * (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: * $Id: StateNameMapper.java,v 1.6 2007/03/27 21:59:44 mlipp Exp $
021: *
022: * $Log: StateNameMapper.java,v $
023: * Revision 1.6 2007/03/27 21:59:44 mlipp
024: * Fixed lots of checkstyle warnings.
025: *
026: * Revision 1.5 2006/09/29 12:32:11 drmlipp
027: * Consistently using WfMOpen as projct name now.
028: *
029: * Revision 1.4 2005/10/24 15:30:49 drmlipp
030: * Implemented context data change display.
031: *
032: * Revision 1.3 2005/10/05 21:41:24 mlipp
033: * Fixed state name mapping.
034: *
035: * Revision 1.2 2005/10/05 15:29:54 drmlipp
036: * Improved status display.
037: *
038: * Revision 1.1 2005/10/01 20:53:55 mlipp
039: * Improved status display.
040: *
041: */
042: package de.danet.an.workflow.clients.mgmtportlets.process;
043:
044: import java.util.ArrayList;
045: import java.util.Collections;
046: import java.util.Comparator;
047: import java.util.Enumeration;
048: import java.util.HashMap;
049: import java.util.Iterator;
050: import java.util.List;
051: import java.util.Locale;
052: import java.util.Map;
053: import java.util.ResourceBundle;
054:
055: import de.danet.an.util.jsf.JSFUtil;
056:
057: /**
058: * Mapper for state names.
059: * @author mnl
060: */
061: public class StateNameMapper {
062:
063: private static final org.apache.commons.logging.Log logger = org.apache.commons.logging.LogFactory
064: .getLog(StateNameMapper.class);
065:
066: private static Map stateNamesLists = new HashMap();
067: private static Map stateNamesMaps = new HashMap();
068:
069: public static String mapState(String state) {
070: Locale locale = JSFUtil.activeLocale();
071: Map stateNamesMap = (Map) stateNamesMaps.get(locale);
072: if (stateNamesMap == null) {
073: stateNamesMap = new HashMap();
074: stateNamesMaps.put(locale, stateNamesMap);
075: }
076: String res = (String) stateNamesMap.get(state);
077: if (res != null) {
078: return res;
079: }
080: ResourceBundle rb = ResourceBundle
081: .getBundle(
082: "de.danet.an.workflow.clients.mgmtportlets.process.L10n",
083: locale, StateNameMapper.class.getClassLoader());
084: List stateList = (List) stateNamesLists.get(locale);
085: if (stateList == null) {
086: if (logger.isDebugEnabled()) {
087: logger.debug("Creating state names list for " + locale);
088: }
089: stateList = new ArrayList();
090: for (Enumeration e = rb.getKeys(); e.hasMoreElements();) {
091: String key = (String) e.nextElement();
092: if (key.startsWith("state.")) {
093: String stateName = key.substring("state.".length());
094: if (logger.isDebugEnabled()) {
095: logger.debug("Adding " + stateName + " ("
096: + rb.getString(key) + ")");
097: }
098: stateList.add(stateName);
099: }
100: }
101: Collections.sort(stateList, new Comparator() {
102: public int compare(Object o1, Object o2) {
103: return ((String) o2).length()
104: - ((String) o1).length();
105: }
106: });
107: stateNamesLists.put(locale, stateList);
108: }
109: for (Iterator i = stateList.iterator(); i.hasNext();) {
110: String stateName = (String) i.next();
111: if (state.startsWith(stateName)) {
112: res = (String) rb.getString("state." + stateName);
113: if (logger.isDebugEnabled()) {
114: logger.debug("Using " + stateName + ": " + res);
115: }
116: break;
117: }
118: }
119: stateNamesMap.put(state, res);
120: return res;
121: }
122:
123: public static String stateIconUrl(String state) {
124: if (state.startsWith("open.running")) {
125: return "/images/icon_running_sml.gif";
126: }
127: if (state.startsWith("open.not_running.suspended")) {
128: return "/images/icon_warning_sml.gif";
129: }
130: if (state.startsWith("closed.completed.abandoned")) {
131: return "/images/icon_abandoned_sml.gif";
132: }
133: if (state.startsWith("closed.completed")) {
134: return "/images/icon_success_sml.gif";
135: }
136: if (state.startsWith("closed.aborted")
137: || state.startsWith("closed.terminated")) {
138: return "/images/icon_error_sml.gif";
139: }
140: return "/images/icon_empty_sml.gif";
141: }
142:
143: }
|