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