6
|
1 /**
|
|
2 *
|
|
3 * Copyright INRA-URGI 2009-2010
|
|
4 *
|
|
5 * This software is governed by the CeCILL license under French law and
|
|
6 * abiding by the rules of distribution of free software. You can use,
|
|
7 * modify and/ or redistribute the software under the terms of the CeCILL
|
|
8 * license as circulated by CEA, CNRS and INRIA at the following URL
|
|
9 * "http://www.cecill.info".
|
|
10 *
|
|
11 * As a counterpart to the access to the source code and rights to copy,
|
|
12 * modify and redistribute granted by the license, users are provided only
|
|
13 * with a limited warranty and the software's author, the holder of the
|
|
14 * economic rights, and the successive licensors have only limited
|
|
15 * liability.
|
|
16 *
|
|
17 * In this respect, the user's attention is drawn to the risks associated
|
|
18 * with loading, using, modifying and/or developing or reproducing the
|
|
19 * software by the user in light of its specific status of free software,
|
|
20 * that may mean that it is complicated to manipulate, and that also
|
|
21 * therefore means that it is reserved for developers and experienced
|
|
22 * professionals having in-depth computer knowledge. Users are therefore
|
|
23 * encouraged to load and test the software's suitability as regards their
|
|
24 * requirements in conditions enabling the security of their systems and/or
|
|
25 * data to be ensured and, more generally, to use and operate it in the
|
|
26 * same conditions as regards security.
|
|
27 *
|
|
28 * The fact that you are presently reading this means that you have had
|
|
29 * knowledge of the CeCILL license and that you accept its terms.
|
|
30 *
|
|
31 */
|
|
32 import java.util.*;
|
|
33 import java.io.File;
|
|
34 import java.io.*;
|
|
35
|
|
36
|
|
37 public class ProgramFileReader {
|
|
38 String fileName;
|
|
39 Vector <Program> programs;
|
|
40
|
|
41
|
|
42 public ProgramFileReader(String fileName) {
|
|
43 this.fileName = fileName;
|
|
44 this.programs = new Vector <Program> ();
|
|
45 }
|
|
46
|
|
47
|
|
48 public boolean read() {
|
|
49 // File file = new File(this.fileName);
|
|
50 // Program program = null;
|
|
51 // int step = 0;
|
|
52 // TreeMap <String, ProgramOption> options = new TreeMap <String, ProgramOption> ();
|
|
53
|
|
54 // try {
|
|
55 // BufferedReader reader = new BufferedReader(new FileReader(file));
|
|
56 // String line = null;
|
|
57 // String section = null;
|
|
58
|
|
59 // while ((line = reader.readLine()) != null) {
|
|
60
|
|
61 // line = line.trim();
|
|
62
|
|
63 // if (line.length() == 0) {
|
|
64 // if (program != null) {
|
|
65 // programs.add(program);
|
|
66 // }
|
|
67 // program = null;
|
|
68 // step = 0;
|
|
69 // continue;
|
|
70 // }
|
|
71
|
|
72 // if ((line.charAt(0) == '[') && (line.charAt(line.length() - 1) == ']')) {
|
|
73 // section = line.substring(1, line.length() - 1).trim();
|
|
74 // continue;
|
|
75 // }
|
|
76 // switch (step) {
|
|
77 // case 0:
|
|
78 // program = new Program();
|
|
79 // program.setName(line);
|
|
80 // if (section == null) {
|
|
81 // System.out.println("Error! Section of program '" + line + "' is not set!");
|
|
82 // }
|
|
83 // program.setSection(section);
|
|
84 // step = 1;
|
|
85 // break;
|
|
86 // case 1:
|
|
87 // program.setShortName(line);
|
|
88 // step = 2;
|
|
89 // break;
|
|
90 // case 2:
|
|
91 // ProgramOption option = new ProgramOption();
|
|
92
|
|
93 // String[] elements = line.split(":");
|
|
94 // boolean input = elements[0].trim().equalsIgnoreCase("input")? true: false;
|
|
95 // String[] subElements = elements[1].split(";");
|
|
96 // String identifier = subElements[0].trim();
|
|
97
|
|
98 // option.setInput(input);
|
|
99
|
|
100 // if (input) {
|
|
101
|
|
102 // if (subElements.length < 4) {
|
|
103 // System.out.println("Line '" + line + "' is weird...");
|
|
104 // }
|
|
105
|
|
106 // String type = subElements[1].trim();
|
|
107 // String comment = subElements[2].trim();
|
|
108 // boolean compulsory = subElements[3].trim().equalsIgnoreCase("0")? false: true;
|
|
109
|
|
110 // option.setIdentifier(identifier);
|
|
111 // option.setType(type);
|
|
112 // option.setComment(comment);
|
|
113 // option.setCompulsory(compulsory);
|
|
114
|
|
115 // if ("file".compareToIgnoreCase(type) == 0) {
|
|
116 // if (subElements.length < 5) {
|
|
117 // System.out.println("Line '" + line + "' is weird...");
|
|
118 // }
|
|
119
|
|
120 // String formatIdentifier = subElements[4].trim();
|
|
121 // option.setFormatIdentifier(formatIdentifier);
|
|
122 // }
|
|
123 // else if ("choice".compareToIgnoreCase(type) == 0) {
|
|
124 // if (subElements.length < 5) {
|
|
125 // System.out.println("Line '" + line + "' is weird...");
|
|
126 // }
|
|
127
|
|
128 // String[] choices = subElements[4].trim().split(",");
|
|
129 // for (int i = 0; i < choices.length; i++) {
|
|
130 // choices[i] = choices[i].trim();
|
|
131 // }
|
|
132 // option.setChoices(choices);
|
|
133 // }
|
|
134 // options.put(identifier, option);
|
|
135 // }
|
|
136 // else {
|
|
137 // String format = subElements[1].trim();
|
|
138
|
|
139 // option.setFormat(format);
|
|
140 // option.setAssociatedOption(options.get(identifier));
|
|
141 // }
|
|
142
|
|
143 // program.addOption(option);
|
|
144
|
|
145 // break;
|
|
146 // default:
|
|
147 // return false;
|
|
148 // }
|
|
149 // }
|
|
150
|
|
151 // reader.close();
|
|
152 // }
|
|
153 // catch (FileNotFoundException e) {
|
|
154 // return false;
|
|
155 // }
|
|
156 // catch (IOException e) {
|
|
157 // return false;
|
|
158 // }
|
|
159
|
|
160 // if (program != null) {
|
|
161 // programs.add(program);
|
|
162 // }
|
|
163
|
|
164 return true;
|
|
165 }
|
|
166
|
|
167 public int getNbPrograms() {
|
|
168 return programs.size();
|
|
169 }
|
|
170
|
|
171 public Program getProgram(int i) {
|
|
172 return programs.get(i);
|
|
173 }
|
|
174 }
|