1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.itracker.services.util;
20
21 import java.util.ArrayList;
22 import java.util.Collections;
23 import java.util.EnumMap;
24 import java.util.Hashtable;
25 import java.util.List;
26 import java.util.Locale;
27 import java.util.Map;
28
29 import org.itracker.core.resources.ITrackerResources;
30 import org.itracker.model.Status;
31
32
33 public class ProjectUtilities {
34
35 public static final int OPTION_SURPRESS_HISTORY_HTML = 1;
36 public static final int OPTION_ALLOW_ASSIGN_TO_CLOSE = 2;
37 public static final int OPTION_PREDEFINED_RESOLUTIONS = 4;
38 public static final int OPTION_ALLOW_SELF_REGISTERED_CREATE = 8;
39 public static final int OPTION_ALLOW_SELF_REGISTERED_VIEW_ALL = 16;
40 public static final int OPTION_NO_ATTACHMENTS = 32;
41 public static final int OPTION_LITERAL_HISTORY_HTML = 64;
42
43
44
45
46
47
48
49
50 private static Map<Locale, Map<Status, String>> statusNames =
51 new Hashtable<Locale, Map<Status, String>>();
52
53
54
55
56 private ProjectUtilities() {
57 }
58
59
60
61
62
63
64
65
66 public static String getStatusName(Status status) {
67 return getStatusName(status, ITrackerResources.getLocale());
68 }
69
70
71
72
73
74
75
76
77
78 public static String getStatusName(Status status, Locale locale) {
79 return ITrackerResources.getString(
80 ITrackerResources.KEY_BASE_PROJECT_STATUS + status.getCode(),
81 locale);
82 }
83
84
85
86
87 public static Map<Status, String> getStatusNames() {
88 return getStatusNames(ITrackerResources.getLocale());
89 }
90
91
92
93
94
95
96
97
98
99
100 public static Map<Status, String> getStatusNames(Locale locale) {
101 Map<Status, String> statuses = statusNames.get(locale);
102
103
104
105 if (statuses == null) {
106
107 statuses = new EnumMap<Status, String>(Status.class);
108
109 for (Status status : Status.values()) {
110 statuses.put(status, getStatusName(status, locale));
111
112
113 }
114 statusNames.put(locale, Collections.unmodifiableMap(statuses));
115
116 }
117 return statuses;
118
119 }
120
121 public static boolean hasOption(int option, int currentOptions) {
122 return ((option & currentOptions) == option);
123 }
124
125 public static Integer[] getOptions(int currentOptions) {
126 List<Integer> options = new ArrayList<Integer>();
127 if(hasOption(OPTION_SURPRESS_HISTORY_HTML, currentOptions)) {
128 options.add(OPTION_SURPRESS_HISTORY_HTML);
129 }
130 if(hasOption(OPTION_ALLOW_ASSIGN_TO_CLOSE, currentOptions)) {
131 options.add(OPTION_ALLOW_ASSIGN_TO_CLOSE);
132 }
133 if(hasOption(OPTION_PREDEFINED_RESOLUTIONS, currentOptions)) {
134 options.add(OPTION_PREDEFINED_RESOLUTIONS);
135 }
136 if(hasOption(OPTION_ALLOW_SELF_REGISTERED_CREATE, currentOptions)) {
137 options.add(OPTION_ALLOW_SELF_REGISTERED_CREATE);
138 }
139 if(hasOption(OPTION_ALLOW_SELF_REGISTERED_VIEW_ALL, currentOptions)) {
140 options.add(OPTION_ALLOW_SELF_REGISTERED_VIEW_ALL);
141 }
142 if(hasOption(OPTION_NO_ATTACHMENTS, currentOptions)) {
143 options.add(OPTION_NO_ATTACHMENTS);
144 }
145 if(hasOption(OPTION_LITERAL_HISTORY_HTML, currentOptions)) {
146 options.add(OPTION_LITERAL_HISTORY_HTML);
147 }
148 Integer[] optionsArray = new Integer[options.size()];
149 options.toArray(optionsArray);
150 return optionsArray;
151 }
152 public static String getScriptPriorityLabelKey(Integer fieldId) {
153 return ITrackerResources.getString(ITrackerResources.KEY_BASE_PRIORITY + fieldId + ITrackerResources.KEY_BASE_PRIORITY_LABEL);
154 }
155
156 public static String getScriptPrioritySize() {
157 return ITrackerResources.getString(ITrackerResources.KEY_BASE_PRIORITY + ITrackerResources.KEY_BASE_PRIORITY_SIZE);
158 }
159 }