source: main/trunk/greenstone3/src/java/org/greenstone/admin/guiext/OptionList.java@ 21919

Last change on this file since 21919 was 21919, checked in by sjm84, 14 years ago

New code for GAI extension manager

File size: 2.5 KB
Line 
1package org.greenstone.admin.guiext;
2
3import org.w3c.dom.Element;
4
5import java.io.File;
6import java.io.FileInputStream;
7
8import java.util.Properties;
9
10public 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}
Note: See TracBrowser for help on using the repository browser.