1 | package de.dass_it.vanhelsing.gui;
|
---|
2 |
|
---|
3 |
|
---|
4 |
|
---|
5 | import javax.faces.application.FacesMessage;
|
---|
6 | import javax.faces.application.FacesMessage.Severity;
|
---|
7 | import javax.faces.context.FacesContext;
|
---|
8 | import javax.faces.model.SelectItem;
|
---|
9 | import java.util.ResourceBundle;
|
---|
10 | import java.util.Locale;
|
---|
11 |
|
---|
12 |
|
---|
13 |
|
---|
14 | //import org.apache.log4j.Logger;
|
---|
15 |
|
---|
16 | /*
|
---|
17 | * Helper class to encapsulate common bean methods.
|
---|
18 | * Managed beans will extend this class either directly or
|
---|
19 | * via a data structure helper class like TreeNavigation
|
---|
20 | */
|
---|
21 | public class BeanUtil {
|
---|
22 | //Logging
|
---|
23 |
|
---|
24 | //protected final Logger logger = Logger.getLogger(this.getClass());
|
---|
25 |
|
---|
26 | //Messagebundles
|
---|
27 | public static String getProperty(String key){
|
---|
28 | String s = PropertyBundle.getProperty(key);
|
---|
29 | return s;
|
---|
30 | }
|
---|
31 |
|
---|
32 | public static String[] getProperties(String key){
|
---|
33 | String[] suffix = {"ref", "type", "required", "def"};
|
---|
34 | String[] bundle = new String[4];
|
---|
35 | for (int i = 0; i < 4; i++) {
|
---|
36 | bundle[i] = BeanUtil.getProperty(key+"."+suffix[i]);
|
---|
37 | }
|
---|
38 | return bundle;
|
---|
39 | }
|
---|
40 | //getRenderer returns rendererType based on properties
|
---|
41 | public static String getRenderer(String type, String key){
|
---|
42 | String daemon = "director";
|
---|
43 | String res = "inputText";
|
---|
44 | if (type.startsWith("SD")){
|
---|
45 | daemon = "storagedaemon";
|
---|
46 | }
|
---|
47 | if (type.startsWith("FD")){
|
---|
48 | daemon = "filedaemon";
|
---|
49 | }
|
---|
50 | type = type.toLowerCase();
|
---|
51 | key = key.toLowerCase();
|
---|
52 | String result[] = getProperties((daemon+"."+type+"."+key));
|
---|
53 | if (result[1].equals("boolean")){
|
---|
54 | return "radioGroup";
|
---|
55 | }
|
---|
56 | if (!(result[0].equals("0"))){
|
---|
57 | return "selectOneMenu";
|
---|
58 | }
|
---|
59 |
|
---|
60 | return res;
|
---|
61 | }
|
---|
62 | //Statusmeldungen an den Client
|
---|
63 | public static void setInfoMessage(String client, String message){
|
---|
64 | FacesContext.getCurrentInstance().addMessage(client, new FacesMessage(FacesMessage.SEVERITY_INFO, message, message));
|
---|
65 | }
|
---|
66 | public static void setErrorMessage(String client, String message){
|
---|
67 | FacesContext.getCurrentInstance().addMessage(client, new FacesMessage(FacesMessage.SEVERITY_ERROR, message, message));
|
---|
68 | }
|
---|
69 |
|
---|
70 | //Linkout to Bacula documentation
|
---|
71 | //ListItemsConfigView
|
---|
72 | //ListItemsTopologyView
|
---|
73 | //ListItemsJobSchedule
|
---|
74 |
|
---|
75 | //GetParameterFromContext
|
---|
76 | public static String getRequestParameter(String name){
|
---|
77 | return (String) FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get(name);
|
---|
78 | }
|
---|
79 |
|
---|
80 | }
|
---|