KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > cve > util > ConfigurationRead


1 /**
2 * @(#) ConfigurationRead.java
3 */

4 package cve.util;
5
6 import java.io.*;
7 import java.util.*;
8
9 import org.jdom.*;
10 import org.jdom.input.SAXBuilder;
11 import org.jdom.output.XMLOutputter;
12
13 import org.apache.log4j.Logger;
14
15 import cve.staticLayout.Cve;
16
17 /**
18 * It manages configuration read (cveConfiguration.xml)
19 *
20 * @see <code>Cve</code>
21 *
22 * @version 1.1.0 09/01/02
23 * @author Domenico Ventriglia
24 * @author Francesco Guerrisi
25 */

26 public final class ConfigurationRead {
27    
28    /**
29    * It returns cveRoot
30    */

31    static public String JavaDoc getCveRoot() {
32       Cve.errLog.debug("");
33       Element rootXml=ConfigurationRead();
34       Element ele=rootXml.getChild("cveRoot");
35       String JavaDoc cveRoot=(String JavaDoc)ele.getAttributeValue("name");
36       return cveRoot;
37    }
38
39    /**
40    * It returns cveVCARWRoot (Path Definizione CVE VCARW)
41    * @author Francesco Guerrisi
42    */

43    static public String JavaDoc getCveVCARWRoot() {
44       Cve.errLog.debug("");
45       Element rootXml=ConfigurationRead();
46       Element ele=rootXml.getChild("cveVCARWRoot");
47       String JavaDoc cveVCARWRoot=(String JavaDoc)ele.getAttributeValue("name");
48       return cveVCARWRoot;
49    }
50
51    /**
52    * It returns cveWSpeRoot (Path Specifiche Macchine WIPPOG)
53    * @author Francesco Guerrisi
54    */

55    static public String JavaDoc getCveWSpeRoot() {
56       Cve.errLog.debug("");
57       Element rootXml=ConfigurationRead();
58       Element ele=rootXml.getChild("cveWSpeRoot");
59       String JavaDoc cveWSpeRoot=(String JavaDoc)ele.getAttributeValue("name");
60       return cveWSpeRoot;
61    }
62
63    /**
64    * It returns cveWSpeSemantic (Path Specifiche OUT Semantica)
65    * @author Francesco Guerrisi
66    */

67    static public String JavaDoc getCveWSpeSemantic() {
68       Cve.errLog.debug("");
69       Element rootXml=ConfigurationRead();
70       Element ele=rootXml.getChild("cveWSpeSemantic");
71       String JavaDoc cveWSpeSemantic=(String JavaDoc)ele.getAttributeValue("name");
72       return cveWSpeSemantic;
73    }
74
75    /**
76    * It returns cveWSpeSentence (Path Specifiche OUT Sentenza)
77    * @author Francesco Guerrisi
78    */

79    static public String JavaDoc getCveWSpeSentence() {
80       Cve.errLog.debug("");
81       Element rootXml=ConfigurationRead();
82       Element ele=rootXml.getChild("cveWSpeSentence");
83       String JavaDoc cveWSpeSentence=(String JavaDoc)ele.getAttributeValue("name");
84       return cveWSpeSentence;
85    }
86
87    /**
88    * It returns cveWSpeSentence (Path Specifiche OUT Sentenza)
89    * @author Francesco Guerrisi
90    */

91    static public String JavaDoc getIntSemTranslation() {
92       Cve.errLog.debug("");
93       Element rootXml=ConfigurationRead();
94       Element ele=rootXml.getChild("intSemTranslation");
95       String JavaDoc intSemTranslation=(String JavaDoc)ele.getAttributeValue("name");
96       return intSemTranslation;
97    }
98
99    /**
100    * It returns the title environment choicer
101    */

102    static public String JavaDoc getEnvironmentTitle() {
103       Cve.errLog.debug("");
104       Element rootXml=ConfigurationRead();
105       Element ele=rootXml.getChild("cveChoiceEnvironment");
106       String JavaDoc title=(String JavaDoc)ele.getAttributeValue("name");
107       return title;
108    }
109
110    /**
111    * It returns a cve environment container
112    */

113    static public Collection getEnvironmentContainer() {
114       Cve.errLog.debug("");
115       Vector app=new Vector();
116       Element rootXml=ConfigurationRead();
117       Element ele=rootXml.getChild("cveChoiceEnvironment");
118       java.util.List JavaDoc containerEnv=ele.getChildren();
119       Iterator itContainer=containerEnv.iterator();
120       if (itContainer!=null){
121          while (itContainer.hasNext()){
122             Element newEle=(Element)itContainer.next();
123             String JavaDoc containerName=(String JavaDoc)newEle.getAttributeValue("name");
124             app.add(containerName);
125          }
126       }
127       return app;
128    }
129
130    /**
131    * It return cve environments.
132    *
133    * @param index: item relativi al container index
134    */

135    static public List getEnvironmentItem(int index) {
136       Cve.errLog.debug("");
137       Vector app=new Vector();
138       Element rootXml=ConfigurationRead();
139       Element ele=rootXml.getChild("cveChoiceEnvironment");
140       // prendo i container
141
java.util.List JavaDoc containerEnv=ele.getChildren();
142       Iterator itContainer=containerEnv.iterator();
143       int cont=0;
144       if (itContainer!=null){ // per ogni container
145
while (itContainer.hasNext()){
146             Element newEle=(Element)itContainer.next();
147             if (cont==index){ // se container giusto
148
java.util.List JavaDoc items=newEle.getChildren();
149                Iterator itItem=items.iterator();
150                if (itItem!=null){
151                   while (itItem.hasNext()){ // per ogni item
152
Element newItem=(Element)itItem.next();
153                      String JavaDoc itemName=(String JavaDoc)newItem.getAttributeValue("name");
154                      app.add(itemName);
155                   }
156                }
157             }
158             cont++;
159          }
160       }
161       return app;
162    }
163
164    /**
165    * It returns environment cve class.
166    *
167    * @param index: item relativi al container index
168    * @author Francesco Guerrisi
169    *
170    */

171    static public List getEnvironmentItemClass(int index) {
172       Cve.errLog.debug("");
173       Vector app=new Vector();
174       Element rootXml=ConfigurationRead();
175       Element ele=rootXml.getChild("cveChoiceEnvironment");
176       // prendo i container
177
java.util.List JavaDoc containerEnv=ele.getChildren();
178       Iterator itContainer=containerEnv.iterator();
179       int cont=0;
180       if (itContainer!=null){ // per ogni container
181
while (itContainer.hasNext()){
182             Element newEle=(Element)itContainer.next();
183             if (cont==index){ // se container giusto
184
java.util.List JavaDoc items=newEle.getChildren();
185                Iterator itItem=items.iterator();
186                if (itItem!=null){
187                   while (itItem.hasNext()){ // per ogni item
188
Element newItem=(Element)itItem.next();
189                      String JavaDoc itemName=(String JavaDoc)newItem.getAttributeValue("class");
190                      app.add(itemName);
191                   }
192                }
193             }
194             cont++;
195          }
196       }
197       return app;
198    }
199
200    /**
201    * It returns environment icon.
202    * These names are used to Presenter
203    *
204    * @param index: item relativi al container index
205    * @author Francesco Guerrisi
206    *
207    */

208    static public List getEnvironmentItemIcon(int index) {
209       Cve.errLog.debug("");
210       Vector app=new Vector();
211       Element rootXml=ConfigurationRead();
212       Element ele=rootXml.getChild("cveChoiceEnvironment");
213       // prendo i container
214
java.util.List JavaDoc containerEnv=ele.getChildren();
215       Iterator itContainer=containerEnv.iterator();
216       int cont=0;
217       if (itContainer!=null) { // per ogni container
218
while (itContainer.hasNext()) {
219             Element newEle=(Element)itContainer.next();
220             if (cont==index){ // se container giusto
221
java.util.List JavaDoc items=newEle.getChildren();
222                Iterator itItem=items.iterator();
223                if (itItem!=null) {
224                   while (itItem.hasNext()){ // per ogni item
225
Element newItem=(Element)itItem.next();
226                      String JavaDoc itemName=(String JavaDoc)newItem.getAttributeValue("icon");
227                      //GF Impostazione Icona di Default
228
// Impostazione root -->Path completo
229
if (itemName == null) {
230                         itemName = getCveRoot() + "/resource/cve/CVE.gif";
231                      }else {
232                         itemName = getCveRoot() + itemName;
233                      }
234                      app.add(itemName);
235                   }
236                }
237             }
238             cont++;
239          }
240       }
241       return app;
242    }
243
244    /**
245    * It reads the configuration file
246    */

247    static private Element ConfigurationRead() {
248       Cve.errLog.debug("");
249       File fileConfig=new File("conf/cveConfiguration.xml");
250       Document docConfig=null;
251       try {
252          // vanno messi i controlli di correttezza
253
SAXBuilder builder = new SAXBuilder(false);
254          docConfig = builder.build(fileConfig);
255       } catch (JDOMException e) {
256          Cve.errLog.error(e.toString());
257       }
258       Element rootXml=docConfig.getRootElement();
259       return rootXml;
260    }
261
262 }
Popular Tags