25 |
25 |
import org.w3c.dom.NodeList;
|
26 |
26 |
import org.xml.sax.SAXException;
|
27 |
27 |
|
28 |
|
public class BaseOldParameters implements IParameters {
|
29 |
|
|
|
28 |
public class BaseOldParameters implements IParameters {
|
|
29 |
|
30 |
30 |
public static final DateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd"); //$NON-NLS-1$
|
|
31 |
|
31 |
32 |
public static final DateFormat shortUKDateformat = new SimpleDateFormat("dd-MM-yy"); //$NON-NLS-1$
|
32 |
|
|
33 |
|
HashMap<String, Object> keyValueParameters = new HashMap<String, Object>();
|
34 |
|
|
|
33 |
|
|
34 |
HashMap<String, Object> keyValueParameters = new HashMap<>();
|
|
35 |
|
35 |
36 |
public static final String ANNOTATE = "annotate"; //$NON-NLS-1$
|
|
37 |
|
36 |
38 |
public static final String CORPUS = "corpus"; //$NON-NLS-1$
|
|
39 |
|
37 |
40 |
public static final String CURRENTVERSION = "0.8.0"; //$NON-NLS-1$
|
|
41 |
|
38 |
42 |
public static final String DATE = "date"; //$NON-NLS-1$
|
|
43 |
|
39 |
44 |
public static final String DEFAULT = "default"; //$NON-NLS-1$
|
|
45 |
|
40 |
46 |
public static final String DESC = "desc"; //$NON-NLS-1$
|
|
47 |
|
41 |
48 |
public static final String ENCODING = "encoding"; //$NON-NLS-1$
|
|
49 |
|
42 |
50 |
public static final String LANG = "lang"; //$NON-NLS-1$
|
|
51 |
|
43 |
52 |
public static final String LINK = "link"; //$NON-NLS-1$
|
|
53 |
|
44 |
54 |
public static final String NAME = "name"; //$NON-NLS-1$
|
|
55 |
|
45 |
56 |
public static final String PARAM = "param"; //$NON-NLS-1$
|
|
57 |
|
46 |
58 |
public static final String QUERY = "query"; //$NON-NLS-1$
|
|
59 |
|
47 |
60 |
public static final String TARGET = "target"; //$NON-NLS-1$
|
|
61 |
|
48 |
62 |
public static final String TYPE = "BASE"; //$NON-NLS-1$
|
|
63 |
|
49 |
64 |
public static final String PARAMETERS = "parameters"; //$NON-NLS-1$
|
|
65 |
|
50 |
66 |
public static final String PARAMETERKEY = "key"; //$NON-NLS-1$
|
|
67 |
|
51 |
68 |
public static final String PARAMETERVALUE = "value"; //$NON-NLS-1$
|
52 |
|
|
|
69 |
|
53 |
70 |
public static final String TRUE = "true"; //$NON-NLS-1$
|
|
71 |
|
54 |
72 |
public static final String FALSE = "false"; //$NON-NLS-1$
|
55 |
|
|
|
73 |
|
56 |
74 |
public static String VALUE = "value"; //$NON-NLS-1$
|
57 |
|
public static void createEmptyParams(File paramFile, String basename) throws IOException
|
58 |
|
{
|
|
75 |
|
|
76 |
public static void createEmptyParams(File paramFile, String basename) throws IOException {
|
59 |
77 |
paramFile.getParentFile().mkdirs();
|
60 |
78 |
FileOutputStream fwriter = new FileOutputStream(paramFile);
|
61 |
79 |
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(fwriter, "UTF-8")); //$NON-NLS-1$
|
62 |
|
|
|
80 |
|
63 |
81 |
String AUTHOR = System.getProperty("user.name"); //$NON-NLS-1$
|
64 |
82 |
String DATE = dateformat.format(new Date());
|
65 |
83 |
DATE = DATE.replace("/", "-"); //$NON-NLS-1$ //$NON-NLS-2$
|
66 |
|
|
67 |
|
String description = "<pre><br/>"+"- "+basename+"<br/>- "+AUTHOR+"<br/>- "+DATE+"</pre>"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
|
|
84 |
|
|
85 |
String description = "<pre><br/>" + "- " + basename + "<br/>- " + AUTHOR + "<br/>- " + DATE + "</pre>"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
|
68 |
86 |
String path = paramFile.getParentFile().getAbsolutePath();
|
69 |
87 |
path = path.replaceAll("&", "&").replaceAll("<", "<").replaceAll("\"", """); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
|
70 |
88 |
writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); //$NON-NLS-1$
|
71 |
|
writer.write("<import version=\""+CURRENTVERSION+"\" author=\""+AUTHOR+"\" date=\""+DATE+"\" desc=\"\" name=\""+basename+"\" rootDir=\""+path+"\" script=\"\">\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
|
|
89 |
writer.write("<import version=\"" + CURRENTVERSION + "\" author=\"" + AUTHOR + "\" date=\"" + DATE + "\" desc=\"\" name=\"" + basename + "\" rootDir=\"" + path + "\" script=\"\">\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
|
72 |
90 |
writer.write(" <linkGrp type=\"align\"></linkGrp>\n"); //$NON-NLS-1$
|
73 |
91 |
writer.write(" <corpora>\n"); //$NON-NLS-1$
|
74 |
|
writer.write(" <corpus desc=\""+description+"\" cqpid=\"\" encoding=\""+System.getProperty("file.encoding")+"\" lang=\""+Locale.getDefault().getLanguage()+"\" font=\"\" annotate=\"true\" name=\""+basename.toUpperCase()+"\">\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
|
|
92 |
writer.write(" <corpus desc=\"" + description + "\" cqpid=\"\" encoding=\"" + System.getProperty("file.encoding") + "\" lang=\"" + Locale.getDefault().getLanguage() //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
|
|
93 |
+ "\" font=\"\" annotate=\"true\" name=\"" + basename.toUpperCase() + "\">\n"); //$NON-NLS-1$ //$NON-NLS-2$
|
75 |
94 |
writer.write(" <tokenizer onlyThoseTests=\"false\"></tokenizer>\n"); //$NON-NLS-1$
|
76 |
95 |
writer.write(" <xslt xsl=\"\"></xslt>\n"); //$NON-NLS-1$
|
77 |
96 |
writer.write(" <pattributes></pattributes>\n"); //$NON-NLS-1$
|
... | ... | |
89 |
108 |
writer.write(" </corpus>\n"); //$NON-NLS-1$
|
90 |
109 |
writer.write(" </corpora>\n"); //$NON-NLS-1$
|
91 |
110 |
writer.write("</import>\n"); //$NON-NLS-1$
|
92 |
|
|
|
111 |
|
93 |
112 |
writer.close();
|
94 |
113 |
}
|
95 |
114 |
|
... | ... | |
98 |
117 |
return root.getDocumentElement().getAttribute("name"); //$NON-NLS-1$
|
99 |
118 |
}
|
100 |
119 |
|
101 |
|
public static void main(String args[]) throws ParserConfigurationException, SAXException, IOException
|
102 |
|
{
|
|
120 |
public static void main(String args[]) throws ParserConfigurationException, SAXException, IOException {
|
103 |
121 |
String home = System.getProperty("user.home"); //$NON-NLS-1$
|
104 |
122 |
File paramFile = new File(home, "TXM/corpora/xmltxmpara/param.xml"); //$NON-NLS-1$
|
105 |
123 |
BaseOldParameters p = new BaseOldParameters(paramFile);
|
106 |
124 |
p.load();
|
107 |
125 |
System.out.println(p.toString());
|
108 |
126 |
}
|
109 |
|
|
|
127 |
|
110 |
128 |
public HashMap<String, Element> getCorpora() {
|
111 |
129 |
return corpora;
|
112 |
130 |
}
|
113 |
|
|
|
131 |
|
114 |
132 |
public String author;
|
|
133 |
|
115 |
134 |
String AVOIDXMLSTEPSDEFAULT = FALSE;
|
|
135 |
|
116 |
136 |
String CLEANTEMPDIRSDEFAULT = TRUE;
|
117 |
|
public HashMap<String, Element> corpora = new HashMap<String, Element>();
|
|
137 |
|
|
138 |
public HashMap<String, Element> corpora = new HashMap<>();
|
|
139 |
|
118 |
140 |
public Element corporaElement;
|
|
141 |
|
119 |
142 |
public Date date;
|
|
143 |
|
120 |
144 |
String DEFAULT_CQPLIMITS = "text"; //$NON-NLS-1$
|
|
145 |
|
121 |
146 |
boolean DEFAULT_DOEDITION = true;
|
|
147 |
|
122 |
148 |
String DEFAULT_PAGEELEMENT = "pb"; //$NON-NLS-1$
|
123 |
|
|
|
149 |
|
124 |
150 |
int DEFAULT_WORDSPERPAGE = 500;
|
|
151 |
|
125 |
152 |
public String description;
|
126 |
|
|
|
153 |
|
127 |
154 |
String DOEDITIONSTEPSDEFAULT = TRUE;
|
128 |
|
public HashMap<String, Element> links = new HashMap<String, Element>();
|
129 |
|
|
|
155 |
|
|
156 |
public HashMap<String, Element> links = new HashMap<>();
|
|
157 |
|
130 |
158 |
public String name;
|
131 |
|
|
|
159 |
|
132 |
160 |
public File paramFile;
|
133 |
|
|
|
161 |
|
134 |
162 |
public Element root;
|
135 |
|
|
|
163 |
|
136 |
164 |
public String rootDir;
|
137 |
|
|
|
165 |
|
138 |
166 |
public String scriptFile;
|
139 |
|
|
|
167 |
|
140 |
168 |
public String version;
|
141 |
|
|
142 |
|
public BaseOldParameters(File paramFile) throws ParserConfigurationException, SAXException, IOException
|
143 |
|
{
|
|
169 |
|
|
170 |
public BaseOldParameters(File paramFile) throws ParserConfigurationException, SAXException, IOException {
|
144 |
171 |
this.paramFile = paramFile;
|
145 |
172 |
this.root = DomUtils.load(paramFile).getDocumentElement();
|
146 |
173 |
}
|
147 |
|
|
148 |
|
public Element addCorpusNode(String name, String cqpid, String lang, String encoding, boolean annotate)
|
149 |
|
{
|
|
174 |
|
|
175 |
public Element addCorpusNode(String name, String cqpid, String lang, String encoding, boolean annotate) {
|
150 |
176 |
if (corporaElement == null)
|
151 |
177 |
return null;
|
152 |
178 |
Element corpusElem = root.getOwnerDocument().createElement(CORPUS);
|
153 |
179 |
corporaElement.appendChild(corpusElem);
|
154 |
|
|
|
180 |
|
155 |
181 |
corpusElem.setAttribute(NAME, name);
|
156 |
182 |
corpusElem.setAttribute("cqpid", cqpid); //$NON-NLS-1$
|
157 |
183 |
corpusElem.setAttribute(LANG, lang);
|
158 |
184 |
corpusElem.setAttribute(ENCODING, encoding);
|
159 |
|
corpusElem.setAttribute(ANNOTATE, ""+annotate); //$NON-NLS-1$
|
160 |
|
|
|
185 |
corpusElem.setAttribute(ANNOTATE, "" + annotate); //$NON-NLS-1$
|
|
186 |
|
161 |
187 |
corpusElem.appendChild(corpusElem.getOwnerDocument().createElement("texts")); //$NON-NLS-1$
|
162 |
188 |
corpusElem.appendChild(corpusElem.getOwnerDocument().createElement("queries")); //$NON-NLS-1$
|
163 |
189 |
corpusElem.appendChild(corpusElem.getOwnerDocument().createElement("xslt")); //$NON-NLS-1$
|
... | ... | |
173 |
199 |
Element editions = corpusElem.getOwnerDocument().createElement("editions"); //$NON-NLS-1$
|
174 |
200 |
editions.setAttribute(DEFAULT, DEFAULT);
|
175 |
201 |
corpusElem.appendChild(editions);
|
176 |
|
|
|
202 |
|
177 |
203 |
corpora.put(name, corpusElem);
|
178 |
204 |
return corpusElem;
|
179 |
205 |
}
|
180 |
|
|
|
206 |
|
181 |
207 |
/**
|
182 |
208 |
* Add an edition (already declared in the 'editions' element to a text element
|
183 |
209 |
*
|
... | ... | |
187 |
213 |
* @param type default is 'html'
|
188 |
214 |
* @return the created Element
|
189 |
215 |
*/
|
190 |
|
public Element addEdition(Element textElem, String name, String index, String type)
|
191 |
|
{
|
|
216 |
public Element addEdition(Element textElem, String name, String index, String type) {
|
192 |
217 |
NodeList editionsList = textElem.getElementsByTagName("editions");//$NON-NLS-1$
|
193 |
218 |
Element editions = null;
|
194 |
219 |
if (editionsList.getLength() == 0) {
|
195 |
220 |
editions = textElem.getOwnerDocument().createElement("editions");//$NON-NLS-1$
|
196 |
221 |
textElem.appendChild(editions);
|
197 |
|
} else {
|
|
222 |
}
|
|
223 |
else {
|
198 |
224 |
editions = (Element) editionsList.item(0);
|
199 |
225 |
}
|
200 |
|
|
|
226 |
|
201 |
227 |
Element editionElement = editions.getOwnerDocument().createElement("edition");//$NON-NLS-1$
|
202 |
228 |
editionElement.setAttribute(NAME, name);
|
203 |
229 |
editionElement.setAttribute("index", index);//$NON-NLS-1$
|
204 |
230 |
editionElement.setAttribute("type", type);//$NON-NLS-1$
|
205 |
231 |
editions.appendChild(editionElement);
|
206 |
|
|
|
232 |
|
207 |
233 |
return editionElement;
|
208 |
234 |
}
|
209 |
|
|
|
235 |
|
210 |
236 |
/**
|
211 |
237 |
*
|
212 |
238 |
* @param corpusElem the corpus Element. the new edition definition will be added to corpusElem/editions
|
... | ... | |
219 |
245 |
Element editionsElement = getEditionsElement(corpusElem);
|
220 |
246 |
Element editionElement = editionsElement.getOwnerDocument().createElement("edition");//$NON-NLS-1$
|
221 |
247 |
editionElement.setAttribute(NAME, name);
|
222 |
|
editionElement.setAttribute("build_edition", ""+DEFAULT_DOEDITION);//$NON-NLS-1$ //$NON-NLS-2$
|
223 |
|
editionElement.setAttribute("page_break_tag", ""+DEFAULT_PAGEELEMENT);//$NON-NLS-1$ //$NON-NLS-2$
|
224 |
|
editionElement.setAttribute("words_per_page", ""+DEFAULT_WORDSPERPAGE);//$NON-NLS-1$ //$NON-NLS-2$
|
|
248 |
editionElement.setAttribute("build_edition", "" + DEFAULT_DOEDITION);//$NON-NLS-1$ //$NON-NLS-2$
|
|
249 |
editionElement.setAttribute("page_break_tag", "" + DEFAULT_PAGEELEMENT);//$NON-NLS-1$ //$NON-NLS-2$
|
|
250 |
editionElement.setAttribute("words_per_page", "" + DEFAULT_WORDSPERPAGE);//$NON-NLS-1$ //$NON-NLS-2$
|
225 |
251 |
editionElement.setAttribute("mode", mode);//$NON-NLS-1$
|
226 |
252 |
editionElement.setAttribute("script", script);//$NON-NLS-1$
|
227 |
253 |
editionElement.setAttribute("type", "html");//$NON-NLS-1$ //$NON-NLS-2$
|
228 |
254 |
editionElement.setAttribute("index", ".");//$NON-NLS-1$ //$NON-NLS-2$
|
229 |
255 |
editionsElement.appendChild(editionElement);
|
230 |
|
|
|
256 |
|
231 |
257 |
return editionElement;
|
232 |
258 |
}
|
233 |
|
|
234 |
|
public Element addPage(Element edition, String idx, String wordid)
|
235 |
|
{
|
|
259 |
|
|
260 |
public Element addPage(Element edition, String idx, String wordid) {
|
236 |
261 |
Element page = edition.getOwnerDocument().createElement("page");//$NON-NLS-1$
|
237 |
262 |
page.setAttribute("id", idx);//$NON-NLS-1$
|
238 |
263 |
page.setAttribute("wordid", wordid);//$NON-NLS-1$
|
239 |
264 |
edition.appendChild(page);
|
240 |
265 |
return page;
|
241 |
266 |
}
|
242 |
|
|
|
267 |
|
243 |
268 |
public void addPartition(Element corpusElem, String name, String[] queries,
|
244 |
269 |
String[] names) {
|
245 |
270 |
Element preBuildElement = this.getPreBuildElement(corpusElem);
|
246 |
271 |
Element partitionElem = preBuildElement.getOwnerDocument().createElement("partition");//$NON-NLS-1$
|
247 |
272 |
partitionElem.setAttribute(NAME, name);
|
248 |
|
for (int i = 0 ; i < queries.length ; i++) {
|
|
273 |
for (int i = 0; i < queries.length; i++) {
|
249 |
274 |
Element partElem = preBuildElement.getOwnerDocument().createElement("part");//$NON-NLS-1$
|
250 |
275 |
partElem.setAttribute(NAME, names[i]);
|
251 |
276 |
partElem.setAttribute(QUERY, queries[i]);
|
... | ... | |
253 |
278 |
}
|
254 |
279 |
preBuildElement.appendChild(partitionElem);
|
255 |
280 |
}
|
256 |
|
|
257 |
|
public Element addPAttribute(Element corpusElem, String name, String shortname, String longname, String type, String renderer, String tooltip, String pattern, String importB, String mandatory, String inputFormat, String outputFormat)
|
258 |
|
{
|
|
281 |
|
|
282 |
public Element addPAttribute(Element corpusElem, String name, String shortname, String longname, String type, String renderer, String tooltip, String pattern, String importB, String mandatory,
|
|
283 |
String inputFormat, String outputFormat) {
|
259 |
284 |
NodeList pattributesList = corpusElem.getElementsByTagName("pattributes");//$NON-NLS-1$
|
260 |
|
if(pattributesList.getLength() == 0)
|
|
285 |
if (pattributesList.getLength() == 0)
|
261 |
286 |
return null;
|
262 |
|
|
|
287 |
|
263 |
288 |
Element pattributes = (Element) pattributesList.item(0);
|
264 |
289 |
Element pattribute = pattributes.getOwnerDocument().createElement("pattribute");//$NON-NLS-1$
|
265 |
290 |
pattribute.setAttribute("id", name);//$NON-NLS-1$
|
... | ... | |
274 |
299 |
pattribute.setAttribute("inputFormat", inputFormat);//$NON-NLS-1$
|
275 |
300 |
pattribute.setAttribute("outputFormat", outputFormat);//$NON-NLS-1$
|
276 |
301 |
pattributes.appendChild(pattribute);
|
277 |
|
|
|
302 |
|
278 |
303 |
return pattribute;
|
279 |
304 |
}
|
280 |
|
|
281 |
|
public Element addPreBuildCorpus(Element corpusElem, String name, String query, String exemple)
|
282 |
|
{
|
|
305 |
|
|
306 |
public Element addPreBuildCorpus(Element corpusElem, String name, String query, String exemple) {
|
283 |
307 |
NodeList prebuildsList = corpusElem.getElementsByTagName("preBuild");//$NON-NLS-1$
|
284 |
|
if(prebuildsList.getLength() == 0)
|
|
308 |
if (prebuildsList.getLength() == 0)
|
285 |
309 |
return null;
|
286 |
|
|
|
310 |
|
287 |
311 |
Element preBuild = (Element) prebuildsList.item(0);
|
288 |
312 |
Element subcorpus = preBuild.getOwnerDocument().createElement("subcorpus");//$NON-NLS-1$
|
289 |
313 |
subcorpus.setAttribute(NAME, name);
|
290 |
314 |
subcorpus.setAttribute(QUERY, query);
|
291 |
|
|
|
315 |
|
292 |
316 |
preBuild.appendChild(subcorpus);
|
293 |
317 |
return subcorpus;
|
294 |
318 |
}
|
295 |
|
|
296 |
|
public Element addQuery(Element corpusElem, String name, String query, String desc)
|
297 |
|
{
|
|
319 |
|
|
320 |
public Element addQuery(Element corpusElem, String name, String query, String desc) {
|
298 |
321 |
NodeList queriesList = corpusElem.getElementsByTagName("queries");//$NON-NLS-1$
|
299 |
|
if(queriesList.getLength() == 0)
|
|
322 |
if (queriesList.getLength() == 0)
|
300 |
323 |
return null;
|
301 |
|
|
|
324 |
|
302 |
325 |
Element queries = (Element) queriesList.item(0);
|
303 |
326 |
Element queryElem = queries.getOwnerDocument().createElement(QUERY);
|
304 |
327 |
queryElem.setAttribute(NAME, name);
|
305 |
328 |
queryElem.setAttribute(QUERY, query);
|
306 |
329 |
queryElem.setAttribute(DESC, desc);
|
307 |
|
|
|
330 |
|
308 |
331 |
queries.appendChild(queryElem);
|
309 |
332 |
return queryElem;
|
310 |
333 |
}
|
311 |
|
|
312 |
|
public Element addSAttribute(Element corpusElem, String name, String shortname, String longname, String type, String renderer, String tooltip, String pattern, String importB, String mandatory, String inputFormat, String outputFormat)
|
313 |
|
{
|
|
334 |
|
|
335 |
public Element addSAttribute(Element corpusElem, String name, String shortname, String longname, String type, String renderer, String tooltip, String pattern, String importB, String mandatory,
|
|
336 |
String inputFormat, String outputFormat) {
|
314 |
337 |
NodeList sattributesList = corpusElem.getElementsByTagName("sattributes");//$NON-NLS-1$
|
315 |
|
if(sattributesList.getLength() == 0)
|
|
338 |
if (sattributesList.getLength() == 0)
|
316 |
339 |
return null;
|
317 |
|
|
|
340 |
|
318 |
341 |
Element sattributes = (Element) sattributesList.item(0);
|
319 |
342 |
Element sattribute = sattributes.getOwnerDocument().createElement("sattribute");//$NON-NLS-1$
|
320 |
343 |
sattribute.setAttribute("id", name);//$NON-NLS-1$
|
... | ... | |
329 |
352 |
sattribute.setAttribute("inputFormat", inputFormat);//$NON-NLS-1$
|
330 |
353 |
sattribute.setAttribute("outputFormat", outputFormat);//$NON-NLS-1$
|
331 |
354 |
sattributes.appendChild(sattribute);
|
332 |
|
|
|
355 |
|
333 |
356 |
return sattribute;
|
334 |
357 |
}
|
335 |
|
|
|
358 |
|
336 |
359 |
public void addSubcorpus(Element corpusElem, String name, String query,
|
337 |
360 |
String desc) {
|
338 |
361 |
Element preBuildElement = this.getPreBuildElement(corpusElem);
|
... | ... | |
342 |
365 |
subcorpusElem.setAttribute(DESC, desc);
|
343 |
366 |
preBuildElement.appendChild(subcorpusElem);
|
344 |
367 |
}
|
345 |
|
|
|
368 |
|
346 |
369 |
/**
|
347 |
370 |
*
|
348 |
371 |
* @param corpusElem
|
... | ... | |
350 |
373 |
* @param sourceFile the XML-TXM file
|
351 |
374 |
* @return
|
352 |
375 |
*/
|
353 |
|
public Element addText(Element corpusElem, String name, File sourceFile)
|
354 |
|
{
|
|
376 |
public Element addText(Element corpusElem, String name, File sourceFile) {
|
355 |
377 |
NodeList textsList = corpusElem.getElementsByTagName("texts");//$NON-NLS-1$
|
356 |
378 |
Element texts = null;
|
357 |
379 |
if (textsList.getLength() == 0) {
|
358 |
380 |
texts = corpusElem.getOwnerDocument().createElement("texts");//$NON-NLS-1$
|
359 |
381 |
corpusElem.appendChild(texts);
|
360 |
|
} else {
|
|
382 |
}
|
|
383 |
else {
|
361 |
384 |
texts = (Element) textsList.item(0);
|
362 |
385 |
}
|
363 |
|
|
|
386 |
|
364 |
387 |
Element text = texts.getOwnerDocument().createElement("text");//$NON-NLS-1$
|
365 |
388 |
text.setAttribute(NAME, name);
|
366 |
389 |
texts.appendChild(text);
|
367 |
|
|
|
390 |
|
368 |
391 |
Element source = texts.getOwnerDocument().createElement("source");//$NON-NLS-1$
|
369 |
392 |
source.setAttribute("file", sourceFile.getAbsolutePath());//$NON-NLS-1$
|
370 |
393 |
source.setAttribute("type", ".xml");//$NON-NLS-1$ //$NON-NLS-2$
|
371 |
394 |
text.appendChild(source);
|
372 |
395 |
text.appendChild(texts.getOwnerDocument().createElement("editions"));//$NON-NLS-1$
|
373 |
|
|
|
396 |
|
374 |
397 |
return text;
|
375 |
398 |
}
|
376 |
|
|
377 |
|
|
|
399 |
|
|
400 |
|
378 |
401 |
public Element getTextsElement(Element corpusElement) {
|
379 |
402 |
NodeList textsList = corpusElement.getElementsByTagName("texts");//$NON-NLS-1$
|
380 |
|
if(textsList.getLength() == 0) {
|
|
403 |
if (textsList.getLength() == 0) {
|
381 |
404 |
Element texts = corpusElement.getOwnerDocument().createElement("texts");//$NON-NLS-1$
|
382 |
405 |
corpusElement.appendChild(texts);
|
383 |
406 |
return texts;
|
384 |
|
} else {
|
|
407 |
}
|
|
408 |
else {
|
385 |
409 |
Element texts = (Element) textsList.item(0);
|
386 |
410 |
return texts;
|
387 |
411 |
}
|
388 |
412 |
}
|
389 |
|
|
|
413 |
|
390 |
414 |
public Element getParametersElement(Element corpusElement) {
|
391 |
415 |
NodeList parametersList = corpusElement.getElementsByTagName(PARAMETERS);
|
392 |
416 |
if (parametersList.getLength() == 0) {
|
393 |
417 |
Element parametersElement = corpusElement.getOwnerDocument().createElement(PARAMETERS);
|
394 |
418 |
corpusElement.appendChild(parametersElement);
|
395 |
419 |
return parametersElement;
|
396 |
|
} else {
|
|
420 |
}
|
|
421 |
else {
|
397 |
422 |
Element parametersElement = (Element) parametersList.item(0);
|
398 |
423 |
return parametersElement;
|
399 |
424 |
}
|
400 |
425 |
}
|
401 |
|
|
|
426 |
|
402 |
427 |
public Element getTextElement(Element textsElement, String name) {
|
403 |
428 |
NodeList textsList = textsElement.getElementsByTagName("text");//$NON-NLS-1$
|
404 |
|
|
405 |
|
for (int i = 0 ; i < textsList.getLength() ;i++) {
|
|
429 |
|
|
430 |
for (int i = 0; i < textsList.getLength(); i++) {
|
406 |
431 |
Element text = (Element) textsList.item(i);
|
407 |
432 |
if (name.equals(text.getAttribute("name"))) return text;//$NON-NLS-1$
|
408 |
433 |
}
|
409 |
434 |
return null;
|
410 |
|
|
|
435 |
|
411 |
436 |
}
|
412 |
|
|
|
437 |
|
413 |
438 |
public Element getEditionElement(Element textElement, String name) {
|
414 |
439 |
NodeList editionsList = textElement.getElementsByTagName("edition");//$NON-NLS-1$
|
415 |
|
|
416 |
|
for (int i = 0 ; i < editionsList.getLength() ;i++) {
|
|
440 |
|
|
441 |
for (int i = 0; i < editionsList.getLength(); i++) {
|
417 |
442 |
Element editionElement = (Element) editionsList.item(i);
|
418 |
443 |
if (name.equals(editionElement.getAttribute("name"))) {//$NON-NLS-1$
|
419 |
444 |
return editionElement;
|
420 |
445 |
}
|
421 |
446 |
}
|
422 |
|
//System.out.println("Warning no edition found with name="+name);
|
|
447 |
// System.out.println("Warning no edition found with name="+name);
|
423 |
448 |
return null;
|
424 |
|
|
|
449 |
|
425 |
450 |
}
|
426 |
|
|
|
451 |
|
427 |
452 |
public void addTokenizerParameter(Element corpusElem, String name, String value) {
|
428 |
453 |
Element tokenizer = getTokenizerElement(corpusElem);
|
429 |
454 |
// check if param already exists
|
430 |
455 |
NodeList paramList = tokenizer.getElementsByTagName(PARAM);
|
431 |
|
for (int i = 0 ; i < paramList.getLength() ; i++) {
|
432 |
|
String pname = ((Element)paramList.item(i)).getAttribute(NAME);
|
|
456 |
for (int i = 0; i < paramList.getLength(); i++) {
|
|
457 |
String pname = ((Element) paramList.item(i)).getAttribute(NAME);
|
433 |
458 |
if (name.equals(pname)) {
|
434 |
|
((Element)paramList.item(i)).setTextContent(value);
|
|
459 |
((Element) paramList.item(i)).setTextContent(value);
|
435 |
460 |
return;
|
436 |
461 |
}
|
437 |
462 |
}
|
... | ... | |
440 |
465 |
param.setTextContent(value);
|
441 |
466 |
tokenizer.appendChild(param);
|
442 |
467 |
}
|
443 |
|
|
|
468 |
|
444 |
469 |
public void addTokenizerTest(Element corpusElem, String regex,
|
445 |
470 |
String type, String before, String hit, String after) {
|
446 |
471 |
Element tokenizer = getTokenizerElement(corpusElem);
|
... | ... | |
452 |
477 |
test.setAttribute("after", after);//$NON-NLS-1$
|
453 |
478 |
tokenizer.appendChild(test);
|
454 |
479 |
}
|
455 |
|
|
|
480 |
|
456 |
481 |
public void addXsltParameter(Element corpusElem, String name, String value) {
|
457 |
482 |
Element xslt = getXsltElement(corpusElem);
|
458 |
483 |
Element param = xslt.getOwnerDocument().createElement(PARAM);
|
... | ... | |
460 |
485 |
param.setAttribute(VALUE, value);
|
461 |
486 |
xslt.appendChild(param);
|
462 |
487 |
}
|
463 |
|
|
|
488 |
|
464 |
489 |
public boolean getAvoidXMLSteps(Element corpusElem) {
|
465 |
490 |
String str = corpusElem.getAttribute(CorpusBuild.AVOIDXMLSTEPS);
|
466 |
491 |
if (str == null || str.length() == 0) str = AVOIDXMLSTEPSDEFAULT;
|
467 |
492 |
return TRUE.equals(str);
|
468 |
493 |
}
|
469 |
|
|
|
494 |
|
470 |
495 |
public Element getBibliosElement(Element corpusElem) {
|
471 |
496 |
return getElement(corpusElem, "biblios");//$NON-NLS-1$
|
472 |
497 |
}
|
473 |
|
|
|
498 |
|
474 |
499 |
public boolean getCleanTEMPDirectories(Element corpusElem) {
|
475 |
|
String str = ""+this.getKeyValueParameters().get("clean.directories"); //$NON-NLS-1$ //$NON-NLS-2$
|
|
500 |
String str = "" + this.getKeyValueParameters().get("clean.directories"); //$NON-NLS-1$ //$NON-NLS-2$
|
476 |
501 |
if (str == null || str.length() == 0) str = CLEANTEMPDIRSDEFAULT;
|
477 |
502 |
return TRUE.equals(str);
|
478 |
503 |
}
|
479 |
|
|
|
504 |
|
480 |
505 |
public Element getCorpusElement() {
|
481 |
506 |
return corpora.get(getCorpusName());
|
482 |
507 |
}
|
483 |
|
|
|
508 |
|
484 |
509 |
/**
|
485 |
510 |
*
|
486 |
511 |
* @return the first found corpus name
|
487 |
512 |
*/
|
488 |
|
public String getCorpusName()
|
489 |
|
{
|
|
513 |
public String getCorpusName() {
|
490 |
514 |
if (corpora != null) {
|
491 |
515 |
for (String c : corpora.keySet()) {
|
492 |
516 |
return c;
|
... | ... | |
496 |
520 |
Log.warning(NLS.bind(TXMCoreMessages.BaseOldParameters_96, paramFile));
|
497 |
521 |
return null;
|
498 |
522 |
}
|
499 |
|
|
|
523 |
|
500 |
524 |
public Element getCQLLimitElement(Element uiElement) {
|
501 |
525 |
NodeList uiList = uiElement.getElementsByTagName("context_limits");//$NON-NLS-1$
|
502 |
526 |
if (uiList.getLength() > 0) {
|
503 |
|
return (Element)(uiList.item(0));
|
504 |
|
} else {
|
|
527 |
return (Element) (uiList.item(0));
|
|
528 |
}
|
|
529 |
else {
|
505 |
530 |
Element context_limitsElement = uiElement.getOwnerDocument().createElement("context_limits");//$NON-NLS-1$
|
506 |
531 |
context_limitsElement.setAttribute("type", "list");//$NON-NLS-1$ //$NON-NLS-2$ $NON-NLS-2$
|
507 |
532 |
context_limitsElement.setTextContent(DEFAULT_CQPLIMITS);
|
... | ... | |
509 |
534 |
return context_limitsElement;
|
510 |
535 |
}
|
511 |
536 |
}
|
512 |
|
|
|
537 |
|
513 |
538 |
public Element getWordElement() {
|
514 |
539 |
Element textualPlanEelement = getTextualPlans();
|
515 |
540 |
NodeList uiList = textualPlanEelement.getElementsByTagName("word");//$NON-NLS-1$
|
516 |
541 |
if (uiList.getLength() > 0) {
|
517 |
|
return (Element)(uiList.item(0));
|
518 |
|
} else {
|
|
542 |
return (Element) (uiList.item(0));
|
|
543 |
}
|
|
544 |
else {
|
519 |
545 |
Element wordElement = textualPlanEelement.getOwnerDocument().createElement("word");//$NON-NLS-1$
|
520 |
546 |
wordElement.setTextContent("w");//$NON-NLS-1$
|
521 |
547 |
textualPlanEelement.appendChild(wordElement);
|
522 |
548 |
return wordElement;
|
523 |
549 |
}
|
524 |
550 |
}
|
525 |
|
|
|
551 |
|
526 |
552 |
public Element getMilestonesElement() {
|
527 |
553 |
Element textualPlanEelement = getTextualPlans();
|
528 |
554 |
NodeList uiList = textualPlanEelement.getElementsByTagName("milestones");//$NON-NLS-1$
|
529 |
555 |
if (uiList.getLength() > 0) {
|
530 |
|
return (Element)(uiList.item(0));
|
531 |
|
} else {
|
|
556 |
return (Element) (uiList.item(0));
|
|
557 |
}
|
|
558 |
else {
|
532 |
559 |
Element wordElement = textualPlanEelement.getOwnerDocument().createElement("milestones");//$NON-NLS-1$
|
533 |
560 |
wordElement.setTextContent(""); //$NON-NLS-1$
|
534 |
561 |
textualPlanEelement.appendChild(wordElement);
|
535 |
562 |
return wordElement;
|
536 |
563 |
}
|
537 |
564 |
}
|
538 |
|
|
|
565 |
|
539 |
566 |
public Element setWordElement(String tag) {
|
540 |
567 |
if (tag == null) return null;
|
541 |
568 |
tag = tag.trim();
|
542 |
569 |
if (tag.length() == 0) return null;
|
543 |
|
|
|
570 |
|
544 |
571 |
getWordElement().setTextContent(tag);
|
545 |
572 |
return getWordElement();
|
546 |
573 |
}
|
547 |
|
|
|
574 |
|
548 |
575 |
public Element getOutSideTextTagsElement() {
|
549 |
576 |
Element textualPlanEelement = getTextualPlans();
|
550 |
577 |
NodeList uiList = textualPlanEelement.getElementsByTagName("outsidetexttags");//$NON-NLS-1$
|
551 |
578 |
if (uiList.getLength() > 0) {
|
552 |
|
return (Element)(uiList.item(0));
|
553 |
|
} else {
|
|
579 |
return (Element) (uiList.item(0));
|
|
580 |
}
|
|
581 |
else {
|
554 |
582 |
Element context_limitsElement = textualPlanEelement.getOwnerDocument().createElement("outsidetexttags");//$NON-NLS-1$
|
555 |
583 |
context_limitsElement.setAttribute("type", "list");//$NON-NLS-1$ //$NON-NLS-2$ $NON-NLS-2$
|
556 |
584 |
context_limitsElement.setTextContent("");//$NON-NLS-1$
|
... | ... | |
563 |
591 |
Element textualPlanEelement = getTextualPlans();
|
564 |
592 |
NodeList uiList = textualPlanEelement.getElementsByTagName("outside_text_tags_and_keep_content");//$NON-NLS-1$
|
565 |
593 |
if (uiList.getLength() > 0) {
|
566 |
|
return (Element)(uiList.item(0));
|
567 |
|
} else {
|
|
594 |
return (Element) (uiList.item(0));
|
|
595 |
}
|
|
596 |
else {
|
568 |
597 |
Element element = textualPlanEelement.getOwnerDocument().createElement("outside_text_tags_and_keep_content");//$NON-NLS-1$
|
569 |
598 |
element.setAttribute("type", "list");//$NON-NLS-1$ //$NON-NLS-2$ $NON-NLS-2$
|
570 |
599 |
element.setTextContent("");//$NON-NLS-1$
|
... | ... | |
577 |
606 |
Element textualPlanElement = getTextualPlans();
|
578 |
607 |
NodeList noteList = textualPlanElement.getElementsByTagName("note");//$NON-NLS-1$
|
579 |
608 |
if (noteList.getLength() > 0) {
|
580 |
|
return (Element)(noteList.item(0));
|
581 |
|
} else {
|
|
609 |
return (Element) (noteList.item(0));
|
|
610 |
}
|
|
611 |
else {
|
582 |
612 |
Element element = textualPlanElement.getOwnerDocument().createElement("note");//$NON-NLS-1$
|
583 |
613 |
element.setAttribute("type", "list");//$NON-NLS-1$ //$NON-NLS-2$
|
584 |
614 |
element.setTextContent("");//$NON-NLS-1$
|
... | ... | |
586 |
616 |
return element;
|
587 |
617 |
}
|
588 |
618 |
}
|
589 |
|
|
|
619 |
|
590 |
620 |
public boolean getDoEdition(String edition) {
|
591 |
621 |
Element corpusElement = getCorpusElement();
|
592 |
622 |
if (corpusElement == null) return DEFAULT_DOEDITION;
|
... | ... | |
594 |
624 |
if (editionsElement == null) return DEFAULT_DOEDITION;
|
595 |
625 |
Element editionElement = getEditionDefinitionElement(editionsElement, edition);
|
596 |
626 |
if (editionElement == null) return DEFAULT_DOEDITION;
|
597 |
|
|
|
627 |
|
598 |
628 |
String value = editionElement.getAttribute("build_edition");//$NON-NLS-1$
|
599 |
629 |
if (value == null | value.length() == 0) return DEFAULT_DOEDITION;
|
600 |
|
|
|
630 |
|
601 |
631 |
return TRUE.equals(value);
|
602 |
632 |
}
|
603 |
|
|
604 |
|
/**
|
605 |
|
*
|
|
633 |
|
|
634 |
/**
|
|
635 |
*
|
606 |
636 |
* @param editionsElem
|
607 |
637 |
* @param name
|
608 |
638 |
* @return the edition Element corresponding to the asked edition name
|
609 |
639 |
*/
|
610 |
640 |
public Element getEditionDefinitionElement(Element editionsElem, String name) {
|
611 |
641 |
NodeList editionList = editionsElem.getElementsByTagName("edition");//$NON-NLS-1$
|
612 |
|
for (int i = 0 ; i < editionList.getLength() ; i++) {
|
613 |
|
Element elem = (Element)editionList.item(i);
|
|
642 |
for (int i = 0; i < editionList.getLength(); i++) {
|
|
643 |
Element elem = (Element) editionList.item(i);
|
614 |
644 |
if (name.equals(elem.getAttribute("name")))//$NON-NLS-1$
|
615 |
645 |
return elem;
|
616 |
646 |
}
|
617 |
647 |
//
|
618 |
|
// Element editionElement = editionsElem.getOwnerDocument().createElement("edition");
|
619 |
|
// editionElement.setAttribute("name", name);
|
620 |
|
// editionElement.setAttribute("build_edition", ""+DEFAULT_DOEDITION);
|
621 |
|
// editionElement.setAttribute("page_break_tag", ""+DEFAULT_PAGEELEMENT);
|
622 |
|
// editionElement.setAttribute("words_per_page", ""+DEFAULT_WORDSPERPAGE);
|
623 |
|
// editionElement.setAttribute("mode", "groovy");
|
624 |
|
// editionElement.setAttribute("script", "pager.groovy");
|
625 |
|
// editionElement.setAttribute("type", "html");
|
626 |
|
// editionElement.setAttribute("index", ".");
|
|
648 |
// Element editionElement = editionsElem.getOwnerDocument().createElement("edition");
|
|
649 |
// editionElement.setAttribute("name", name);
|
|
650 |
// editionElement.setAttribute("build_edition", ""+DEFAULT_DOEDITION);
|
|
651 |
// editionElement.setAttribute("page_break_tag", ""+DEFAULT_PAGEELEMENT);
|
|
652 |
// editionElement.setAttribute("words_per_page", ""+DEFAULT_WORDSPERPAGE);
|
|
653 |
// editionElement.setAttribute("mode", "groovy");
|
|
654 |
// editionElement.setAttribute("script", "pager.groovy");
|
|
655 |
// editionElement.setAttribute("type", "html");
|
|
656 |
// editionElement.setAttribute("index", ".");
|
627 |
657 |
return null;
|
628 |
658 |
}
|
629 |
|
|
|
659 |
|
630 |
660 |
/**
|
631 |
661 |
* returns the corpus "editions" element and creates it if missing
|
632 |
662 |
*
|
... | ... | |
642 |
672 |
elem.setAttribute(DEFAULT, DEFAULT);
|
643 |
673 |
return elem;
|
644 |
674 |
}
|
645 |
|
|
|
675 |
|
646 |
676 |
/**
|
647 |
677 |
* Utility to get the first 'name' element from a node 'elem'
|
648 |
678 |
*
|
... | ... | |
654 |
684 |
NodeList editionsList = elem.getElementsByTagName(tag);
|
655 |
685 |
if (editionsList.getLength() > 0)
|
656 |
686 |
return (Element) editionsList.item(0);
|
657 |
|
|
|
687 |
|
658 |
688 |
Element editionsElem = elem.getOwnerDocument().createElement(tag);
|
659 |
689 |
elem.appendChild(editionsElem);
|
660 |
690 |
return editionsElem;
|
661 |
691 |
}
|
662 |
|
|
|
692 |
|
663 |
693 |
public ArrayList<String> getExcludeXpaths() {
|
664 |
694 |
Element filter = getFilterElement();
|
665 |
|
ArrayList<String> xpaths = new ArrayList<String>();
|
|
695 |
ArrayList<String> xpaths = new ArrayList<>();
|
666 |
696 |
NodeList excludeList = filter.getElementsByTagName("exclude");//$NON-NLS-1$
|
667 |
|
for (int i = 0 ; i < excludeList.getLength() ; i++) {
|
|
697 |
for (int i = 0; i < excludeList.getLength(); i++) {
|
668 |
698 |
Element exclude = (Element) excludeList.item(i);
|
669 |
699 |
if ("xpath".equals(exclude.getAttribute("type")))//$NON-NLS-1$ //$NON-NLS-2$ $NON-NLS-2$
|
670 |
700 |
xpaths.add(exclude.getTextContent().trim());
|
671 |
701 |
}
|
672 |
702 |
return xpaths;
|
673 |
703 |
}
|
674 |
|
|
|
704 |
|
675 |
705 |
public Element getFilterElement() {
|
676 |
706 |
Element corpusElem = corpora.get(getCorpusName());
|
677 |
707 |
return getElement(corpusElem, "xmlfilter");//$NON-NLS-1$
|
678 |
708 |
}
|
679 |
|
|
|
709 |
|
680 |
710 |
public String getLang(Element corpusElem) {
|
681 |
711 |
String str = corpusElem.getAttribute(LANG);
|
682 |
712 |
if (str == null) str = System.getProperty("user.locale");//$NON-NLS-1$
|
683 |
713 |
return str;
|
684 |
714 |
}
|
685 |
|
|
|
715 |
|
686 |
716 |
public String getPageElement(String edition) {
|
687 |
717 |
Element corpusElement = getCorpusElement();
|
688 |
718 |
if (corpusElement == null) return DEFAULT_PAGEELEMENT;
|
... | ... | |
690 |
720 |
if (editionsElement == null) return DEFAULT_PAGEELEMENT;
|
691 |
721 |
Element editionElement = getEditionDefinitionElement(editionsElement, edition);
|
692 |
722 |
if (editionElement == null) return DEFAULT_PAGEELEMENT;
|
693 |
|
|
|
723 |
|
694 |
724 |
String value = editionElement.getAttribute("page_break_tag");//$NON-NLS-1$
|
695 |
725 |
if (value == null || value.length() == 0) return DEFAULT_PAGEELEMENT;
|
696 |
|
|
|
726 |
|
697 |
727 |
return value;
|
698 |
728 |
}
|
699 |
|
|
|
729 |
|
700 |
730 |
public NodeList getPAttributes(Element corpusElem) {
|
701 |
731 |
NodeList pattributesList = corpusElem.getElementsByTagName("pattributes");//$NON-NLS-1$
|
702 |
|
if(pattributesList.getLength() == 0)
|
|
732 |
if (pattributesList.getLength() == 0)
|
703 |
733 |
return null;
|
704 |
|
return ((Element)pattributesList.item(0)).getElementsByTagName("pattribute");//$NON-NLS-1$
|
|
734 |
return ((Element) pattributesList.item(0)).getElementsByTagName("pattribute");//$NON-NLS-1$
|
705 |
735 |
}
|
706 |
|
|
|
736 |
|
707 |
737 |
public Element getPAttributesElement(Element corpusElem) {
|
708 |
738 |
return getElement(corpusElem, "pattributes");//$NON-NLS-1$
|
709 |
739 |
}
|
710 |
|
|
|
740 |
|
711 |
741 |
public Element getPreBuildElement() {
|
712 |
742 |
Element corpusElem = corpora.get(getCorpusName());
|
713 |
743 |
return getElement(corpusElem, "preBuild");//$NON-NLS-1$
|
714 |
744 |
}
|
715 |
|
|
|
745 |
|
716 |
746 |
public Element getPreBuildElement(Element corpusElem) {
|
717 |
747 |
return getElement(corpusElem, "preBuild");//$NON-NLS-1$
|
718 |
748 |
}
|
719 |
|
|
|
749 |
|
720 |
750 |
public Element getQueriesElement(Element corpusElem) {
|
721 |
751 |
return getElement(corpusElem, "queries");//$NON-NLS-1$
|
722 |
752 |
}
|
723 |
|
|
|
753 |
|
724 |
754 |
public Element getSAttributesElement(Element corpusElem) {
|
725 |
755 |
return getElement(corpusElem, "sattributes");//$NON-NLS-1$
|
726 |
756 |
}
|
727 |
|
|
|
757 |
|
728 |
758 |
public Element getTokenizerElement(Element corpusElem) {
|
729 |
759 |
return getElement(corpusElem, "tokenizer");//$NON-NLS-1$
|
730 |
760 |
}
|
731 |
|
|
|
761 |
|
732 |
762 |
public Element getUIElement(Element corpusElem, String command) {
|
733 |
763 |
Element uisElement = getUIsElement(corpusElem);
|
734 |
764 |
Element uiElement = null;
|
735 |
765 |
NodeList uiList = uisElement.getElementsByTagName("ui");//$NON-NLS-1$
|
736 |
766 |
if (uiList.getLength() > 0) {
|
737 |
|
for (int i = 0 ; i < uiList.getLength() ; i++ ) {
|
738 |
|
Element ui = (Element)(uiList.item(i));
|
|
767 |
for (int i = 0; i < uiList.getLength(); i++) {
|
|
768 |
Element ui = (Element) (uiList.item(i));
|
739 |
769 |
if (command.equals(ui.getAttribute("command"))) {//$NON-NLS-1$
|
740 |
770 |
return ui;
|
741 |
771 |
}
|
742 |
772 |
}
|
743 |
|
}
|
744 |
|
if (uiElement == null){
|
|
773 |
}
|
|
774 |
if (uiElement == null) {
|
745 |
775 |
uiElement = uisElement.getOwnerDocument().createElement("ui");//$NON-NLS-1$
|
746 |
776 |
uiElement.setAttribute("command", command);//$NON-NLS-1$
|
747 |
777 |
uisElement.appendChild(uiElement);
|
748 |
778 |
}
|
749 |
779 |
return uiElement;
|
750 |
780 |
}
|
751 |
|
|
|
781 |
|
752 |
782 |
public Element getUIsElement(Element corpusElem) {
|
753 |
783 |
return getElement(corpusElem, "uis"); //$NON-NLS-1$
|
754 |
784 |
}
|
755 |
|
|
|
785 |
|
756 |
786 |
public int getWordsPerPage(String edition) {
|
757 |
787 |
Element corpusElement = getCorpusElement();
|
758 |
788 |
if (corpusElement == null) return DEFAULT_WORDSPERPAGE;
|
... | ... | |
760 |
790 |
if (editionsElement == null) return DEFAULT_WORDSPERPAGE;
|
761 |
791 |
Element editionElement = getEditionDefinitionElement(editionsElement, edition);
|
762 |
792 |
if (editionElement == null) return DEFAULT_WORDSPERPAGE;
|
763 |
|
|
|
793 |
|
764 |
794 |
String value = editionElement.getAttribute("words_per_page");//$NON-NLS-1$
|
765 |
795 |
if (value == null) return DEFAULT_WORDSPERPAGE;
|
766 |
|
|
|
796 |
|
767 |
797 |
try {
|
768 |
798 |
return Integer.parseInt(value);
|
769 |
|
} catch (NumberFormatException e) {
|
770 |
|
Log.fine("words_per_page value is not an Integer value: "+value);//$NON-NLS-1$
|
|
799 |
}
|
|
800 |
catch (NumberFormatException e) {
|
|
801 |
Log.fine("words_per_page value is not an Integer value: " + value);//$NON-NLS-1$
|
771 |
802 |
return DEFAULT_WORDSPERPAGE;
|
772 |
803 |
}
|
773 |
804 |
}
|
774 |
|
|
|
805 |
|
775 |
806 |
public Element getXsltElement(Element corpusElem) {
|
776 |
807 |
Element elem = getElement(corpusElem, "xslt");//$NON-NLS-1$
|
777 |
808 |
if (!elem.hasAttribute("xsl"))//$NON-NLS-1$
|
778 |
809 |
elem.setAttribute("xsl", "");//$NON-NLS-1$ //$NON-NLS-2$
|
779 |
810 |
return elem;
|
780 |
811 |
}
|
781 |
|
|
|
812 |
|
782 |
813 |
public HashMap<String, String> getXsltParams(Element corpusElem) {
|
783 |
814 |
Element elem = getElement(corpusElem, "xslt");//$NON-NLS-1$
|
784 |
815 |
if (!elem.hasAttribute("xsl"))//$NON-NLS-1$
|
785 |
816 |
elem.setAttribute("xsl", "");//$NON-NLS-1$ //$NON-NLS-2$
|
786 |
|
HashMap<String, String> hash = new HashMap<String, String>();
|
|
817 |
HashMap<String, String> hash = new HashMap<>();
|
787 |
818 |
NodeList params = elem.getElementsByTagName("param");//$NON-NLS-1$
|
788 |
|
for(int i = 0 ; i < params.getLength() ; i++) {
|
|
819 |
for (int i = 0; i < params.getLength(); i++) {
|
789 |
820 |
Element paramElem = (Element) params.item(i);
|
790 |
821 |
String name = paramElem.getAttribute("name");//$NON-NLS-1$
|
791 |
822 |
String value = paramElem.getAttribute("value");//$NON-NLS-1$
|
... | ... | |
795 |
826 |
}
|
796 |
827 |
return hash;
|
797 |
828 |
}
|
798 |
|
|
|
829 |
|
799 |
830 |
public void loadKeyValueParameters(Element parametersElem) {
|
800 |
|
//HashMap<String, String> hash = new HashMap<String, String>();
|
|
831 |
// HashMap<String, String> hash = new HashMap<String, String>();
|
801 |
832 |
NodeList params = parametersElem.getElementsByTagName("param");//$NON-NLS-1$
|
802 |
|
for (int i = 0 ; i < params.getLength() ; i++) {
|
|
833 |
for (int i = 0; i < params.getLength(); i++) {
|
803 |
834 |
Element paramElem = (Element) params.item(i);
|
804 |
835 |
String name = paramElem.getAttribute(PARAMETERKEY);
|
805 |
836 |
String value = paramElem.getAttribute(PARAMETERVALUE);
|
... | ... | |
810 |
841 |
}
|
811 |
842 |
|
812 |
843 |
public void saveKeyValueParameters(Element parametersElem) {
|
813 |
|
//HashMap<String, String> hash = new HashMap<String, String>();
|
|
844 |
// HashMap<String, String> hash = new HashMap<String, String>();
|
814 |
845 |
|
815 |
846 |
NodeList params = parametersElem.getElementsByTagName("param");//$NON-NLS-1$
|
816 |
|
HashSet<String> existingNames = new HashSet<String>();
|
817 |
|
for (int i = 0 ; i < params.getLength() ; i++) {
|
|
847 |
HashSet<String> existingNames = new HashSet<>();
|
|
848 |
for (int i = 0; i < params.getLength(); i++) {
|
818 |
849 |
Element paramElem = (Element) params.item(i);
|
819 |
850 |
String name = paramElem.getAttribute(PARAMETERKEY);
|
820 |
851 |
existingNames.add(name);
|
821 |
852 |
if (keyValueParameters.containsKey(name)) { // update existing element
|
822 |
853 |
String value = keyValueParameters.get(name).toString();
|
823 |
854 |
paramElem.setAttribute(PARAMETERVALUE, value);
|
824 |
|
} else { // the parameter has been removed -> delete element
|
|
855 |
}
|
|
856 |
else { // the parameter has been removed -> delete element
|
825 |
857 |
parametersElem.removeChild(paramElem);
|
826 |
858 |
}
|
827 |
859 |
}
|
... | ... | |
835 |
867 |
}
|
836 |
868 |
}
|
837 |
869 |
}
|
838 |
|
|
839 |
|
|
840 |
|
public HashMap<String, Object> getKeyValueParameters() {
|
|
870 |
|
|
871 |
|
|
872 |
public HashMap<String, Object> getKeyValueParameters() {
|
841 |
873 |
return keyValueParameters;
|
842 |
874 |
}
|
843 |
|
|
|
875 |
|
844 |
876 |
/**
|
845 |
877 |
* Load import infos.
|
846 |
878 |
*
|
... | ... | |
853 |
885 |
try {
|
854 |
886 |
if (root.getAttribute(DATE).matches("....-..-..")) {//$NON-NLS-1$
|
855 |
887 |
this.date = dateformat.parse(root.getAttribute(DATE));
|
856 |
|
} else { // try with DateFormat.getDateInstance(DateFormat.SHORT, Locale.UK)
|
|
888 |
}
|
|
889 |
else { // try with DateFormat.getDateInstance(DateFormat.SHORT, Locale.UK)
|
857 |
890 |
this.date = shortUKDateformat.parse(root.getAttribute(DATE));
|
858 |
|
//System.out.println("Warning in "+paramFile+": date format '"+root.getAttribute(DATE)+"' does not match '....-..-..', date is set to "+this.date);
|
|
891 |
// System.out.println("Warning in "+paramFile+": date format '"+root.getAttribute(DATE)+"' does not match '....-..-..', date is set to "+this.date);
|
859 |
892 |
}
|
860 |
|
} catch (ParseException e) {
|
|
893 |
}
|
|
894 |
catch (ParseException e) {
|
861 |
895 |
this.date = new Date(0);
|
862 |
|
System.out.println("Warning: can't parse date '"+root.getAttribute(DATE)+"' in file "+paramFile+": "+e);//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
896 |
System.out.println("Warning: can't parse date '" + root.getAttribute(DATE) + "' in file " + paramFile + ": " + e);//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
863 |
897 |
}
|
864 |
898 |
this.version = root.getAttribute("version");//$NON-NLS-1$
|
865 |
899 |
this.name = root.getAttribute(NAME).toUpperCase();
|
... | ... | |
868 |
902 |
this.description = root.getAttribute(DESC);
|
869 |
903 |
this.rootDir = root.getAttribute("rootDir");//$NON-NLS-1$
|
870 |
904 |
this.scriptFile = root.getAttribute("script");//$NON-NLS-1$
|
871 |
|
|
|
905 |
|
872 |
906 |
// get Alignements
|
873 |
907 |
NodeList alignNodes = root.getElementsByTagName("linkGrp"); //$NON-NLS-1$
|
874 |
908 |
if (alignNodes.getLength() > 0) {
|
875 |
909 |
Element alignNode = (Element) alignNodes.item(0);
|
876 |
910 |
NodeList linkNodes = alignNode.getElementsByTagName(LINK);
|
877 |
|
for (int i = 0 ; i < linkNodes.getLength() ; i++) {
|
878 |
|
Element link = (Element)linkNodes.item(i);
|
|
911 |
for (int i = 0; i < linkNodes.getLength(); i++) {
|
|
912 |
Element link = (Element) linkNodes.item(i);
|
879 |
913 |
String target = link.getAttribute(TARGET);
|
880 |
914 |
String[] split = target.split("#");//$NON-NLS-1$
|
881 |
915 |
if (split.length != 3) {
|
882 |
|
System.out.println("Error: linkGrp/link/@target malformed: "+target);//$NON-NLS-1$
|
|
916 |
System.out.println("Error: linkGrp/link/@target malformed: " + target);//$NON-NLS-1$
|
883 |
917 |
continue;
|
884 |
918 |
}
|
885 |
919 |
String from = split[1].trim();
|
886 |
920 |
String to = split[2].trim();
|
887 |
|
|
888 |
|
links.put("#"+to+" #"+from, link);//$NON-NLS-1$ //$NON-NLS-2$
|
|
921 |
|
|
922 |
links.put("#" + to + " #" + from, link);//$NON-NLS-1$ //$NON-NLS-2$
|
889 |
923 |
}
|
890 |
924 |
}
|
891 |
|
|
|
925 |
|
892 |
926 |
// corpora
|
893 |
927 |
NodeList corporaNodes = root.getElementsByTagName("corpora");//$NON-NLS-1$
|
894 |
928 |
if (corporaNodes.getLength() > 0) {
|
895 |
929 |
corporaElement = (Element) corporaNodes.item(0);
|
896 |
930 |
NodeList corpusNodes = corporaElement.getElementsByTagName(CORPUS);
|
897 |
|
for (int i = 0 ; i < corpusNodes.getLength() ; i++) {
|
898 |
|
|
899 |
|
Element corpusElement = (Element)corpusNodes.item(i);
|
|
931 |
for (int i = 0; i < corpusNodes.getLength(); i++) {
|
|
932 |
|
|
933 |
Element corpusElement = (Element) corpusNodes.item(i);
|
900 |
934 |
String id = corpusElement.getAttribute(NAME);
|
901 |
935 |
corpora.put(id, corpusElement);
|
902 |
|
|
|
936 |
|
903 |
937 |
// replace the properties file of some import module
|
904 |
938 |
Element parametersElement = getParametersElement(corpusElement);
|
905 |
939 |
loadKeyValueParameters(parametersElement);
|
906 |
940 |
}
|
907 |
941 |
}
|
908 |
|
|
|
942 |
|
909 |
943 |
return true;
|
910 |
944 |
}
|
911 |
|
|
|
945 |
|
912 |
946 |
public boolean save() {
|
913 |
947 |
return save(this.paramFile);
|
914 |
948 |
}
|
915 |
|
|
|
949 |
|
916 |
950 |
public boolean save(File paramFile) {
|
917 |
951 |
try {
|
918 |
952 |
this.saveToElement(); // save informations
|
919 |
953 |
this.saveKeyValueParameters(getParametersElement(getCorpusElement())); // save additional parameters
|
920 |
954 |
return DomUtils.save(root.getOwnerDocument(), paramFile);
|
921 |
|
} catch (Exception e) {
|
922 |
|
System.out.println("Fail to save parameters in "+paramFile+". Reason: "+e);//$NON-NLS-1$ //$NON-NLS-2$
|
|
955 |
}
|
|
956 |
catch (Exception e) {
|
|
957 |
System.out.println("Fail to save parameters in " + paramFile + ". Reason: " + e);//$NON-NLS-1$ //$NON-NLS-2$
|
923 |
958 |
org.txm.utils.logger.Log.printStackTrace(e);
|
924 |
959 |
}
|
925 |
960 |
return false;
|
926 |
961 |
}
|
927 |
|
|
|
962 |
|
928 |
963 |
public void saveToElement() {
|
929 |
964 |
root.setAttribute(NAME, name);
|
930 |
965 |
root.setAttribute(DESC, description);
|
931 |
966 |
root.setAttribute("script", scriptFile);//$NON-NLS-1$
|
932 |
967 |
root.setAttribute("rootDir", rootDir);//$NON-NLS-1$
|
|
968 |
root.setAttribute("version", version);//$NON-NLS-1$
|
933 |
969 |
}
|
934 |
|
|
935 |
|
/* (non-Javadoc)
|
|
970 |
|
|
971 |
/*
|
|
972 |
* (non-Javadoc)
|
936 |
973 |
* @see java.lang.Object#toString()
|
937 |
974 |
*/
|
938 |
975 |
@Override
|
... | ... | |
940 |
977 |
return "BaseOldParameters [name=" + name + ", date=" + date + ", author=" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
941 |
978 |
+ author + ", version=" + version + ", description=" //$NON-NLS-1$ //$NON-NLS-2$
|
942 |
979 |
+ description + ",\n links=" + links + ", corpora=" + corpora //$NON-NLS-1$ //$NON-NLS-2$
|
943 |
|
+ ",\n root=" + root + ", corporaElement=" + corporaElement + ", keyValueParameters="+super.toString()+"]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
|
|
980 |
+ ",\n root=" + root + ", corporaElement=" + corporaElement + ", keyValueParameters=" + super.toString() + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
|
944 |
981 |
}
|
945 |
|
|
|
982 |
|
946 |
983 |
public String getCQPLimits() {
|
947 |
984 |
Element concordanceElement = this.getUIElement(getCorpusElement(), "concordance");//$NON-NLS-1$
|
948 |
985 |
if (concordanceElement != null) {
|
... | ... | |
955 |
992 |
}
|
956 |
993 |
return DEFAULT_CQPLIMITS;
|
957 |
994 |
}
|
|
995 |
|
958 |
996 |
public Element getTextualPlans() {
|
959 |
997 |
Element uiElement = this.getUIElement(this.getCorpusElement(), "textualplans");//$NON-NLS-1$
|
960 |
998 |
if (uiElement == null) {
|
... | ... | |
977 |
1015 |
if (editionsElement == null) return ""; //$NON-NLS-1$
|
978 |
1016 |
Element editionElement = getEditionDefinitionElement(editionsElement, "facs"); //$NON-NLS-1$
|
979 |
1017 |
if (editionElement == null) return ""; //$NON-NLS-1$
|
980 |
|
|
|
1018 |
|
981 |
1019 |
String value = editionElement.getAttribute("images_directory");//$NON-NLS-1$
|
982 |
1020 |
if (value == null || value.length() == 0) return ""; //$NON-NLS-1$
|
983 |
|
|
|
1021 |
|
984 |
1022 |
return value;
|
985 |
1023 |
}
|
986 |
1024 |
|
... | ... | |
991 |
1029 |
if (editionsElement == null) return false;
|
992 |
1030 |
Element editionElement = getEditionDefinitionElement(editionsElement, "facs"); //$NON-NLS-1$
|
993 |
1031 |
if (editionElement == null) return false;
|
994 |
|
|
|
1032 |
|
995 |
1033 |
String value = editionElement.getAttribute("build_edition"); //$NON-NLS-1$
|
996 |
1034 |
if (value == null | value.length() == 0) return DEFAULT_DOEDITION;
|
997 |
|
|
|
1035 |
|
998 |
1036 |
return TRUE.equals(value);
|
999 |
1037 |
}
|
1000 |
1038 |
|
... | ... | |
1031 |
1069 |
|
1032 |
1070 |
Element milestonesElement = getMilestonesElement();
|
1033 |
1071 |
milestonesElement.setTextContent(milestoneElements.trim());
|
1034 |
|
} else {
|
|
1072 |
}
|
|
1073 |
else {
|
1035 |
1074 |
System.out.println("Error: Textual plan parameters not saved."); //$NON-NLS-1$
|
1036 |
1075 |
}
|
1037 |
1076 |
}
|
... | ... | |
1040 |
1079 |
Element editionsElement = this.getEditionsElement(this.getCorpusElement());
|
1041 |
1080 |
if (editionsElement != null) {
|
1042 |
1081 |
Element defaultEditionElement = this.getEditionDefinitionElement(editionsElement, "default"); //$NON-NLS-1$
|
1043 |
|
|
|
1082 |
|
1044 |
1083 |
if (defaultEditionElement != null) {
|
1045 |
1084 |
defaultEditionElement.setAttribute("words_per_page", Integer.toString(n)); //$NON-NLS-1$
|
1046 |
|
}
|
|
1085 |
}
|
1047 |
1086 |
}
|
1048 |
1087 |
}
|
1049 |
1088 |
|
... | ... | |
1051 |
1090 |
Element editionsElement = this.getEditionsElement(this.getCorpusElement());
|
1052 |
1091 |
if (editionsElement != null) {
|
1053 |
1092 |
Element defaultEditionElement = this.getEditionDefinitionElement(editionsElement, "default"); //$NON-NLS-1$
|
1054 |
|
|
|
1093 |
|
1055 |
1094 |
if (defaultEditionElement != null) {
|
1056 |
1095 |
defaultEditionElement.setAttribute("page_break_tag", pageBreak); //$NON-NLS-1$
|
1057 |
|
}
|
|
1096 |
}
|
1058 |
1097 |
}
|
1059 |
1098 |
}
|
1060 |
|
|
|
1099 |
|
1061 |
1100 |
public void initializeProject(Project project) {
|
1062 |
1101 |
EditionDefinition defaultEditionDef = project.getEditionDefinition("default"); //$NON-NLS-1$
|
1063 |
1102 |
defaultEditionDef.setBuildEdition(this.getDoEdition("default")); //$NON-NLS-1$
|
... | ... | |
1073 |
1112 |
facsEditionDef.setBuildEdition(this.getDoEdition("facs")); //$NON-NLS-1$
|
1074 |
1113 |
facsEditionDef.setWordsPerPage(this.getWordsPerPage("facs")); //$NON-NLS-1$
|
1075 |
1114 |
facsEditionDef.setPageBreakTag(this.getPageElement("facs")); //$NON-NLS-1$
|
1076 |
|
facsEditionDef.setImagesDirectory(this.getFacsEditionImageDirectory()); //$NON-NLS-1$
|
|
1115 |
facsEditionDef.setImagesDirectory(this.getFacsEditionImageDirectory());
|
1077 |
1116 |
|
1078 |
1117 |
if (this.getCorpusElement().getAttribute("font") != null) { //$NON-NLS-1$
|
1079 |
1118 |
project.setFont(this.getCorpusElement().getAttribute("font")); //$NON-NLS-1$
|
... | ... | |
1091 |
1130 |
}
|
1092 |
1131 |
|
1093 |
1132 |
NodeList nodes = this.getTokenizerElement(this.getCorpusElement()).getElementsByTagName("param"); //$NON-NLS-1$
|
1094 |
|
for (int i = 0 ; i < nodes.getLength() ; i++) {
|
|
1133 |
for (int i = 0; i < nodes.getLength(); i++) {
|
1095 |
1134 |
Element paramElement = (Element) nodes.item(i);
|
1096 |
1135 |
project.addTokenizerParameter(paramElement.getAttribute("name"), paramElement.getTextContent()); //$NON-NLS-1$
|
1097 |
1136 |
}
|