[21919] | 1 | package org.greenstone.admin.guiext;
|
---|
| 2 |
|
---|
| 3 | import org.w3c.dom.Element;
|
---|
| 4 |
|
---|
| 5 | import java.io.File;
|
---|
| 6 | import java.io.FileInputStream;
|
---|
| 7 |
|
---|
| 8 | import java.util.Properties;
|
---|
| 9 |
|
---|
| 10 | public class OptionList
|
---|
| 11 | {
|
---|
| 12 | Option[] _options = null;
|
---|
| 13 | String _label = null;
|
---|
| 14 | String _id = null;
|
---|
| 15 | String _file = null;
|
---|
| 16 | PropertiesStep _parent = null;
|
---|
| 17 |
|
---|
| 18 | public OptionList(Element optionListElement, PropertiesStep parent, boolean fromFile)
|
---|
| 19 | {
|
---|
| 20 | _parent = parent;
|
---|
| 21 |
|
---|
| 22 | if(optionListElement != null){
|
---|
| 23 | _label = optionListElement.getAttribute("label");
|
---|
| 24 | _id = optionListElement.getAttribute("id");
|
---|
| 25 | _file = optionListElement.getAttribute("file");
|
---|
| 26 |
|
---|
| 27 | Element[] optionElements = ExtXMLHelper.getMultipleChildElements(optionListElement, ExtXMLHelper.OPTION, true);
|
---|
| 28 | if(optionElements == null){
|
---|
| 29 | System.err.println("This optionList element does not contain any option elements");
|
---|
| 30 | }
|
---|
| 31 |
|
---|
| 32 | Properties properties = null;
|
---|
| 33 | if(fromFile){
|
---|
| 34 | File propertiesFile = null;
|
---|
| 35 | if(_file.equals("")){
|
---|
| 36 | propertiesFile = new File(_parent.getParent().getParent().getExtensionDirectory() + System.getProperty("file.separator") + "build.properties");
|
---|
| 37 | }
|
---|
| 38 | else{
|
---|
| 39 | propertiesFile = new File(_parent.getParent().getParent().getExtensionDirectory() + System.getProperty("file.separator") + _file);
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | if(propertiesFile.exists()){
|
---|
| 43 | properties = new Properties();
|
---|
| 44 |
|
---|
| 45 | try{
|
---|
| 46 | properties.load(new FileInputStream(propertiesFile));
|
---|
| 47 | }
|
---|
| 48 | catch(Exception ex){
|
---|
| 49 | System.err.println("Error loading previous properties values from the properties file, using default values");
|
---|
| 50 | //ex.printStackTrace();
|
---|
| 51 | }
|
---|
| 52 | }
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | _options = new Option[optionElements.length];
|
---|
| 56 | for(int i = 0; i < optionElements.length; i++){
|
---|
| 57 | _options[i] = new Option(optionElements[i], this);
|
---|
| 58 |
|
---|
| 59 | if(fromFile && properties != null){
|
---|
| 60 | String value = null;
|
---|
| 61 | if(_id.equals("")){
|
---|
| 62 | value = properties.getProperty(_options[i].getId());
|
---|
| 63 | }
|
---|
| 64 | else{
|
---|
| 65 | value = properties.getProperty(_id + "." + _options[i].getId());
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | if(value != null){
|
---|
| 69 | _options[i].setValue(value);
|
---|
| 70 | }
|
---|
| 71 | }
|
---|
| 72 | }
|
---|
| 73 | }
|
---|
| 74 | else{
|
---|
| 75 | System.err.println("This <" + ExtXMLHelper.OPTION_LIST + "> element is null");
|
---|
| 76 | }
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | public Option[] getOptions()
|
---|
| 80 | {
|
---|
| 81 | return _options;
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | public String getLabel()
|
---|
| 85 | {
|
---|
| 86 | return _label;
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | public String getId()
|
---|
| 90 | {
|
---|
| 91 | return _id;
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | public String getFilename()
|
---|
| 95 | {
|
---|
| 96 | return _file;
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 | public PropertiesStep getParent()
|
---|
| 100 | {
|
---|
| 101 | return _parent;
|
---|
| 102 | }
|
---|
| 103 | } |
---|