[830] | 1 | package de.dass_it.vanhelsing.gui;
|
---|
| 2 |
|
---|
[856] | 3 |
|
---|
| 4 |
|
---|
| 5 | import javax.faces.application.FacesMessage;
|
---|
| 6 | import javax.faces.application.FacesMessage.Severity;
|
---|
[848] | 7 | import javax.faces.context.FacesContext;
|
---|
[856] | 8 | import javax.faces.model.SelectItem;
|
---|
| 9 | import java.util.ResourceBundle;
|
---|
[857] | 10 | import java.util.Locale;
|
---|
[832] | 11 |
|
---|
[848] | 12 |
|
---|
[856] | 13 |
|
---|
[832] | 14 | //import org.apache.log4j.Logger;
|
---|
| 15 |
|
---|
[830] | 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 {
|
---|
[832] | 22 | //Logging
|
---|
| 23 |
|
---|
| 24 | //protected final Logger logger = Logger.getLogger(this.getClass());
|
---|
| 25 |
|
---|
| 26 | //Messagebundles
|
---|
[857] | 27 | public static String getProperty(String key){
|
---|
| 28 | String s = PropertyBundle.getProperty(key);
|
---|
| 29 | return s;
|
---|
| 30 | }
|
---|
[856] | 31 |
|
---|
[857] | 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 | }
|
---|
[858] | 40 | public static boolean getRequired(String type, String key){
|
---|
| 41 | String s = getFieldProperty(type, key, 2);
|
---|
| 42 | if (s.equals("true") )return true;
|
---|
| 43 | return false;
|
---|
| 44 | }
|
---|
[857] | 45 | //getRenderer returns rendererType based on properties
|
---|
| 46 | public static String getRenderer(String type, String key){
|
---|
[858] | 47 | return getFieldProperty(type, key, 1);
|
---|
| 48 | }
|
---|
| 49 | public static String getFieldProperty(String type, String key, int i){
|
---|
[857] | 50 | String daemon = "director";
|
---|
| 51 | String res = "inputText";
|
---|
| 52 | if (type.startsWith("SD")){
|
---|
| 53 | daemon = "storagedaemon";
|
---|
| 54 | }
|
---|
| 55 | if (type.startsWith("FD")){
|
---|
| 56 | daemon = "filedaemon";
|
---|
| 57 | }
|
---|
| 58 | type = type.toLowerCase();
|
---|
| 59 | key = key.toLowerCase();
|
---|
| 60 | String result[] = getProperties((daemon+"."+type+"."+key));
|
---|
[858] | 61 | if (i == 1) {
|
---|
| 62 | if (result[1].equals("boolean")){
|
---|
| 63 | return "radioGroup";
|
---|
| 64 | }
|
---|
| 65 | if (!(result[0].equals("0"))){
|
---|
| 66 | return "selectOneMenu";
|
---|
| 67 | }
|
---|
| 68 | return res;
|
---|
[857] | 69 | }
|
---|
[858] | 70 | if (i == 2) return result[2];
|
---|
[857] | 71 | return res;
|
---|
| 72 | }
|
---|
[858] | 73 |
|
---|
[856] | 74 | //Statusmeldungen an den Client
|
---|
| 75 | public static void setInfoMessage(String client, String message){
|
---|
| 76 | FacesContext.getCurrentInstance().addMessage(client, new FacesMessage(FacesMessage.SEVERITY_INFO, message, message));
|
---|
| 77 | }
|
---|
| 78 | public static void setErrorMessage(String client, String message){
|
---|
| 79 | FacesContext.getCurrentInstance().addMessage(client, new FacesMessage(FacesMessage.SEVERITY_ERROR, message, message));
|
---|
| 80 | }
|
---|
[832] | 81 |
|
---|
| 82 | //Linkout to Bacula documentation
|
---|
| 83 | //ListItemsConfigView
|
---|
| 84 | //ListItemsTopologyView
|
---|
| 85 | //ListItemsJobSchedule
|
---|
[848] | 86 |
|
---|
| 87 | //GetParameterFromContext
|
---|
| 88 | public static String getRequestParameter(String name){
|
---|
| 89 | return (String) FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get(name);
|
---|
| 90 | }
|
---|
[856] | 91 |
|
---|
[858] | 92 | public static String getAccessType(String type){
|
---|
| 93 | if (type.equals("jobdefs")) return "job";
|
---|
| 94 | return type;
|
---|
| 95 | }
|
---|
| 96 |
|
---|
[830] | 97 | }
|
---|