Révision 965

tmp/org.txm.concordance.rcp/src/org/txm/concordance/rcp/editors/ConcordanceEditor.java (revision 965)
26 26
package org.txm.concordance.rcp.editors;
27 27

  
28 28
import java.util.ArrayList;
29
import java.util.Arrays;
30
import java.util.HashSet;
31 29
import java.util.List;
32 30

  
33
import org.apache.commons.lang.StringUtils;
34 31
import org.eclipse.core.runtime.CoreException;
35 32
import org.eclipse.core.runtime.IConfigurationElement;
36 33
import org.eclipse.core.runtime.IProgressMonitor;
37
import org.eclipse.core.runtime.ISafeRunnable;
38 34
import org.eclipse.core.runtime.IStatus;
39 35
import org.eclipse.core.runtime.Platform;
40
import org.eclipse.core.runtime.SafeRunner;
41 36
import org.eclipse.core.runtime.Status;
42
import org.eclipse.e4.ui.workbench.modeling.EModelService;
43 37
import org.eclipse.jface.action.Action;
44 38
import org.eclipse.jface.action.IMenuListener;
45 39
import org.eclipse.jface.action.IMenuManager;
......
87 81
import org.eclipse.swt.widgets.TableItem;
88 82
import org.eclipse.ui.IEditorInput;
89 83
import org.eclipse.ui.IEditorSite;
90
import org.eclipse.ui.IWorkbenchPage;
91 84
import org.eclipse.ui.IWorkbenchPartSite;
92 85
import org.eclipse.ui.PartInitException;
93 86
import org.txm.concordance.core.functions.Concordance;
......
111 104
import org.txm.concordance.rcp.handlers.DeleteLines;
112 105
import org.txm.concordance.rcp.messages.ConcordanceUIMessages;
113 106
import org.txm.concordance.rcp.widgets.ComplexSortSelector;
114
import org.txm.core.preferences.TBXPreferences;
115 107
import org.txm.core.preferences.TXMPreferences;
116 108
import org.txm.core.results.Parameter;
117 109
import org.txm.core.results.TXMResult;
......
119 111
import org.txm.rcp.IImageKeys;
120 112
import org.txm.rcp.JobsTimer;
121 113
import org.txm.rcp.StatusLine;
122
import org.txm.rcp.TXMWindows;
123 114
import org.txm.rcp.editors.TXMBrowser;
124 115
import org.txm.rcp.editors.TXMEditor;
125
import org.txm.rcp.editors.TXMResultEditorInput;
126 116
import org.txm.rcp.editors.TableKeyListener;
127 117
import org.txm.rcp.editors.listeners.ComputeKeyListener;
128 118
import org.txm.rcp.editors.listeners.ComputeSelectionListener;
129 119
import org.txm.rcp.messages.TXMUIMessages;
130 120
import org.txm.rcp.preferences.RCPPreferences;
131 121
import org.txm.rcp.swt.GLComposite;
132
import org.txm.rcp.swt.dialog.ViewPropertySelectionDialog;
133 122
import org.txm.rcp.swt.widget.AssistedQueryWidget;
134 123
import org.txm.rcp.swt.widget.NavigationWidget;
135 124
import org.txm.rcp.swt.widget.PropertiesSelector;
136
import org.txm.rcp.swt.widget.structures.PropertiesComboViewer;
137 125
import org.txm.rcp.utils.JobHandler;
138
import org.txm.rcp.utils.SWTEditorsUtils;
139 126
import org.txm.rcp.views.QueriesView;
140
import org.txm.rcp.views.corpora.CorporaView;
141 127
import org.txm.searchengine.cqp.CQPSearchEngine;
142 128
import org.txm.searchengine.cqp.ReferencePattern;
143
import org.txm.searchengine.cqp.clientExceptions.CqiClientException;
144 129
import org.txm.searchengine.cqp.corpus.Corpus;
145 130
import org.txm.searchengine.cqp.corpus.Property;
146
import org.txm.searchengine.cqp.corpus.StructuralUnitProperty;
147 131
import org.txm.searchengine.cqp.corpus.WordProperty;
148 132
import org.txm.utils.logger.Log;
149 133

  
......
686 670
		data3.right = new FormAttachment(100);
687 671
		viewer.getTable().setLayoutData(data3);
688 672
		
689
		
690 673
		createContextMenu();
691

  
692 674
	}
693 675

  
694 676
	/**
tmp/org.txm.groovy.core/src/groovy/org/txm/macroproto/importer/XTZImporterMacro.groovy (revision 965)
167 167
	println " stop if a XML source is malformed: "+stopIfMalformed
168 168
}
169 169

  
170
File allmetadatasfile = new File(srcDir, "metadata.csv");
170
File allmetadatasfile = Metadatas.findMetadataFile(srcDir);
171 171

  
172 172
// Apply XSL
173 173
if (MONITOR != null && MONITOR.isCanceled()) { return MONITOR.done(); }
tmp/org.txm.groovy.core/src/groovy/org/txm/importer/txt/txtLoader.groovy (revision 965)
88 88

  
89 89
//get metadata values from CSV
90 90
Metadatas metadatas; // text metadata
91
File allmetadatasfile = new File(srcDir, "metadata.csv");
91
File allmetadatasfile = Metadatas.findMetadataFile(srcDir);
92 92

  
93 93
if (allmetadatasfile.exists()) {
94 94
	println "Trying to read metadata from: "+allmetadatasfile
tmp/org.txm.groovy.core/src/groovy/org/txm/importer/xml/xmlLoader.groovy (revision 965)
129 129
	println " stop if a XML source is malformed: "+stopIfMalformed
130 130
}
131 131

  
132
File allmetadatasfile = new File(srcDir, "metadata.csv");
132
File allmetadatasfile = Metadatas.findMetadataFile(srcDir);
133 133

  
134 134
// Apply XSL
135 135
if (MONITOR != null && MONITOR.isCanceled()) { return MONITOR.done(); }
tmp/org.txm.groovy.core/src/groovy/org/txm/importer/factiva/factivaLoader.groovy (revision 965)
128 128
	println " stop if a XML source is malformed: "+stopIfMalformed
129 129
}
130 130

  
131
File allmetadatasfile = new File(srcDir, "metadata.csv");
131
File allmetadatasfile = Metadatas.findMetadataFile(srcDir);
132 132

  
133 133
// Apply Factiva2XMLTXM
134 134
println "Factiva -> xml/w"
tmp/org.txm.groovy.core/src/groovy/org/txm/importer/doc/docLoader.groovy (revision 965)
99 99
String paginationElement = "pb";
100 100
boolean normalizeMetadata = true;
101 101

  
102
File allmetadatasfile = new File(srcDir, "metadata.csv");
102
File allmetadatasfile = Metadatas.findMetadataFile(srcDir);
103 103

  
104 104
if (txmDir.listFiles() == null) {
105 105
	println "No file to process"
tmp/org.txm.groovy.core/src/groovy/org/txm/importer/xmltxm/xmltxmLoader.groovy (revision 965)
95 95
txmDir.deleteDir();
96 96
txmDir.mkdirs();
97 97

  
98
File allmetadatasfile = new File(srcDir, "metadata.csv");
98
File allmetadatasfile = Metadatas.findMetadataFile(srcDir);
99 99

  
100 100
// Apply XSL
101 101
if (MONITOR != null && MONITOR.isCanceled()) { return MONITOR.done(); }
tmp/org.txm.groovy.core/src/groovy/org/txm/importer/discours/importer.groovy (revision 965)
88 88
		Collections.sort(filelist);
89 89

  
90 90
		// get the headers
91
		def csvfile = new File(srcDir, "metadata.csv");
91
		def csvfile = Metadatas.findMetadataFile(srcDir);
92 92
		Metadatas metadatas; // text metadata
93 93
		
94 94
		println "Trying to read metadata from: "+csvfile
tmp/org.txm.groovy.core/src/groovy/org/txm/importer/transcriber/transcriberLoader.groovy (revision 965)
114 114

  
115 115
//get metadata values from CSV
116 116
Metadatas metadatas; // text metadata
117
File allmetadatasfile = new File(srcDir, "metadata.csv");
117
File allmetadatasfile = Metadatas.findMetadataFile(srcDir);
118 118
println "Trying to read metadatas values from: "+allmetadatasfile
119 119
if (allmetadatasfile.exists()) {
120 120
	File copy = new File(binDir, "metadata.csv")
tmp/org.txm.core/src/java/org/txm/metadatas/Metadatas.java (revision 965)
31 31

  
32 32
import java.io.BufferedWriter;
33 33
import java.io.File;
34
import java.io.FileNotFoundException;
34 35
import java.io.FileOutputStream;
35 36
import java.io.IOException;
36 37
import java.io.OutputStreamWriter;
......
61 62
import javax.xml.xpath.XPathExpressionException;
62 63
import javax.xml.xpath.XPathFactory;
63 64

  
65
import org.odftoolkit.odfdom.dom.element.table.TableTableElement;
66
import org.odftoolkit.simple.SpreadsheetDocument;
67
import org.odftoolkit.simple.table.Row;
68
import org.odftoolkit.simple.table.Table;
64 69
import org.txm.importer.AddAttributeInXml;
65 70
import org.txm.importer.PersonalNamespaceContext;
71
import org.txm.libs.msoffice.ReadExcel;
72
import org.txm.libs.office.ReadODS;
66 73
import org.txm.utils.AsciiUtils;
67 74
import org.txm.utils.CsvReader;
68 75
import org.txm.utils.Pair;
......
77 84
 * The Class Metadatas.
78 85
 */
79 86
public class Metadatas extends LinkedHashMap<String , TextInjection> {
80
	
87

  
81 88
	/** Load metadatas from a xml file $lt;metadatas> $lt;meta key="key1"> $lt;entry name="attr1" value="value1"/> $lt;entry name="attr1" value="value1"/> $lt;meta/> $lt;/metadatas>. */
82 89
	File xmlfile;
83
	
90

  
84 91
	/** The metadatas. */
85 92
	ArrayList<Metadata> metadatas = new ArrayList<Metadata>();
86
	
93

  
87 94
	/** The headers list. */
88 95
	ArrayList<String> headersList = new ArrayList<String>();
89
	
96

  
90 97
	/** The isinialize. */
91 98
	boolean isinialize = false;
92
	
99

  
93 100
	/**
94 101
	 * Checks if is initialized.
95 102
	 *
......
99 106
	{
100 107
		return isinialize;
101 108
	}
102
	
109

  
103 110
	/** The ns context. */
104 111
	NamespaceContext nsContext = new PersonalNamespaceContext();
105
	
112

  
106 113
	/**
107 114
	 * Instantiates a new metadatas.
108 115
	 *
......
114 121
		if(!initialize())
115 122
			System.out.println("Error: failed to load metadata from the file "+xmlfile);
116 123
	}
124

  
125
	/**
126
	 * Find a metadata file in a directory
127
	 * 
128
	 * @param directory
129
	 * @return an input file, try in order : ods, xlsx, tsv and finally csv extension
130
	 */
131
	public static File findMetadataFile(File directory) {
132
		File f = new File(directory, "metadata.ods");
133
		if (f.exists()) return f;
134
		
135
		f = new File(directory, "metadata.xlsx");
136
		if (f.exists()) return f;
137
		
138
		f = new File(directory, "metadata.tsv");
139
		if (f.exists()) return f;
140
		
141
		f = new File(directory, "metadata.csv");
142
		if (f.exists()) return f;
143
		
144
		return null;
145
	}
117 146
	
118 147
	/**
119
	 * Instantiates a new metadatas.
148
	 * Instantiates a new metadatas using an input file : ods, xlsx, tsv or csv.
120 149
	 *
121
	 * @param csvfile the csvfile
150
	 * @param inputFile the CSV, XSLS or ODS
122 151
	 * @param encoding the encoding
123 152
	 * @param separator the separator
124 153
	 * @param nbheaderline the nbheaderline
125 154
	 */
126
	public Metadatas(File csvfile, String encoding, String separator, String txtseparator, int nbheaderline)
155
	public Metadatas(File inputFile, String encoding, String separator, String txtseparator, int nbheaderline)
127 156
	{
128
		File xmlfile = new File(csvfile.getParent(), csvfile.getName()+".xml");
157
		File xmlfile = new File(inputFile.getParent(), inputFile.getName()+".xml");
129 158
		//println "create xml file version of "+csvfile+" : "+xmlfile
130 159
		try {
131
			if(convertCsvToXml(csvfile, xmlfile, encoding, separator, txtseparator, nbheaderline))
132
			{	
133
				this.xmlfile = xmlfile;
134
				//println "xml file : "+xmlfile
135
				if(!initialize())
136
					System.out.println("Error: failed to load metadata from the file "+xmlfile);
160
			if (inputFile.getName().endsWith(".ods")) {
161
				if (convertODSToXml(inputFile, xmlfile)) {	
162
					this.xmlfile = xmlfile;
163
					//println "xml file : "+xmlfile
164

  
165
				}
166
			} else if (inputFile.getName().endsWith(".xlsx")) {
167
				if (convertXLSXToXml(inputFile, xmlfile)) {	
168
					this.xmlfile = xmlfile;
169
					//println "xml file : "+xmlfile
170

  
171
				}
172
			} else if (inputFile.getName().endsWith(".tsv")) {
173
				if (convertCsvToXml(inputFile, xmlfile, encoding, "\t", "", 0)) {	
174
					this.xmlfile = xmlfile;
175
					//println "xml file : "+xmlfile
176

  
177
				}
178
			} else {
179
				if (convertCsvToXml(inputFile, xmlfile, encoding, separator, txtseparator, nbheaderline)) {	
180
					this.xmlfile = xmlfile;
181
					//println "xml file : "+xmlfile
182

  
183
				}
137 184
			}
185

  
186
			if (!initialize()) {
187
				System.out.println("Error: failed to load metadata from the file "+xmlfile);
188
			}
138 189
		} catch (Exception e) {
139 190
			// TODO Auto-generated catch block
140 191
			org.txm.utils.logger.Log.printStackTrace(e);
141 192
			Log.severe(e.toString());
142 193
		}
143 194
	}
144
	
195

  
196
	private boolean convertXLSXToXml(File inputFile, File xmlFile) throws Exception {
197
		ArrayList<ArrayList<String>> data = ReadExcel.toTable(inputFile, "metadata");
198
		System.out.println(data);
199
		return data.size() > 0 && convertTableToXml(data, xmlFile);
200
	}
201

  
202
	private boolean convertTableToXml(ArrayList<ArrayList<String>> data, File xmlFile) throws Exception {
203
		XMLOutputFactory factory = XMLOutputFactory.newInstance();
204
		FileOutputStream output = new FileOutputStream(xmlFile);
205
		XMLStreamWriter writer = factory.createXMLStreamWriter(output, "UTF-8");//create a new file
206

  
207
		writer.writeStartDocument("UTF-8", "1.0");
208
		writer.writeCharacters("\n");
209
		writer.writeStartElement("enrichissement");
210
		writer.writeCharacters("\n");
211
		writer.writeStartElement("metadatas");
212
		writer.writeCharacters("\n");
213

  
214
		ArrayList<String> headers = data.get(0); // first line
215

  
216
		for (int i = 1 ; i < headers.size() ; i++) {
217
			if (headers.get(i).length() == 0) {
218
				headers.set(i, "noname");
219
				System.out.println("Warning: the "+(i+1)+"the column name is empty");
220
			}
221
			//if(!headers[i].equals("id"))// the first
222
			//{
223
			writer.writeStartElement("metadata");
224
			writer.writeAttribute("id", AsciiUtils.buildId(headers.get(i)));
225
			writer.writeAttribute("shortname", headers.get(i));
226
			writer.writeAttribute("longname", headers.get(i));
227
			writer.writeAttribute("type", "String");
228
			writer.writeAttribute("colwidth", "100");
229
			writer.writeAttribute("selection", "true");
230
			writer.writeAttribute("partition", "true");
231
			writer.writeAttribute("display", "true");
232

  
233
			writer.writeEndElement();
234
			writer.writeCharacters("\n");
235
			//}	
236
		}
237
		writer.writeEndElement(); //close metadatas
238
		writer.writeCharacters("\n");
239

  
240
		writer.writeStartElement("texts");
241
		writer.writeCharacters("\n");
242
		for (int i = 1 ; i < data.size() ; i++) { // the next lines
243
			ArrayList<String> dataline = data.get(i);
244

  
245
			writer.writeStartElement("text");
246

  
247
			// write the id attribute 
248
			for (int j = 0 ; j < headers.size() ; j++) {
249
				if (headers.get(j).equals("id")) {
250
					writer.writeAttribute("id", dataline.get(j));
251
				}
252
			}
253
			// write the other attributes
254
			for (int j = 0 ; j < headers.size() ; j++) {
255
				if (!headers.get(j).equals("id")) {
256
					writer.writeAttribute(headers.get(j), dataline.get(j));
257
				}
258
			}
259
			writer.writeEndElement();
260
			writer.writeCharacters("\n");
261
		}
262
		writer.writeEndElement();//close texts
263
		writer.writeCharacters("\n");
264
		writer.writeEndElement();//close metadatas
265

  
266
		writer.close();
267
		output.close();
268

  
269
		writer.close();
270
		return true;
271
	}
272

  
273
	private boolean convertODSToXml(File inputFile, File xmlFile) throws Exception {
274
		ArrayList<ArrayList<String>> data = ReadODS.toTable(inputFile, "metadata");
275

  
276
		return data.size() > 0 && convertTableToXml(data, xmlFile);
277
	}
278

  
145 279
	public File getXMLFile() {
146 280
		return xmlfile;
147 281
	}
148
	
282

  
149 283
	/** The sattr. */
150 284
	String sattr = "";
151
	
285

  
152 286
	/**
153 287
	 * Initialize.
154 288
	 *
......
183 317
			sattr +="+"+m.id;
184 318
			headersList.add(m.id);
185 319
		}
186
		
320

  
187 321
		// List<Node> Lmetadatas = doc.texts.text;
188 322
		// get metadata nodes
189 323
		NodeList textsNodes = doc.getElementsByTagName("texts");
......
198 332
			TextInjection inj = new TextInjection(e);
199 333
			this.put(inj.id, inj);
200 334
		}
201
		
335

  
202 336
		isinialize = true;
203 337
		return true;
204 338
	}
205
	
339

  
206 340
	public HashMap<String, String> getTextMetadata(File f)
207 341
	{
208 342
		HashMap<String, String> data = new HashMap<String, String>();
209 343
		String txtname = f.getName();
210 344
		int idx = txtname.lastIndexOf(".");
211 345
		if(idx > 0) txtname = txtname.substring(0, idx);
212
		
346

  
213 347
		TextInjection injection = this.get(txtname);
214 348
		if (injection == null) {
215 349
			System.out.println("Could not find injection for text "+txtname);
......
218 352
		for (Entry e : injection) {
219 353
			data.put(e.getId(), e.getValue());
220 354
		}
221
		
355

  
222 356
		return data;
223 357
	}
224
	
358

  
225 359
	/**
226 360
	 * Convert csv to xml.
227 361
	 *
......
248 382
			System.out.println("Error: CSV file does not exists");
249 383
			return false;
250 384
		}
251
		
385

  
252 386
		XMLOutputFactory factory = XMLOutputFactory.newInstance();
253 387
		FileOutputStream output = new FileOutputStream(xmlFile);
254 388
		XMLStreamWriter writer = factory.createXMLStreamWriter(output, "UTF-8");//create a new file
255
		
389

  
256 390
		CsvReader reader = new CsvReader(csvfile.getAbsolutePath(), separator.charAt(0), Charset.forName(encoding));
257 391
		if (txtseparator != null && txtseparator.length() > 0)
258 392
			reader.setTextQualifier(txtseparator.charAt(0));
259
		
393

  
260 394
		reader.readHeaders();
261
		
395

  
262 396
		String[] headers = reader.getHeaders();
263
		
397

  
264 398
		if (headers.length == 0)
265 399
		{
266 400
			System.out.println("Error: No header in the metadata file "+csvfile);
267 401
			return false;
268 402
		}
269
		
403

  
270 404
		if(!headers[0].equals("id"))
271 405
		{
272 406
			System.out.println("Error: The first column name in the header line of the metadata file '$csvfile' must be 'id' and found '"+headers[0]+"'");
273 407
			return false;
274 408
		}
275
			
409

  
276 410
		//check for double columns
277 411
		HashSet<String> testhash = new HashSet<String>();
278 412
		HashSet<String> doubles = new HashSet<String>();
......
287 421
			System.out.println("Error: the metadata file '$csvfile' contains duplicated column names: "+doubles);
288 422
			return false;
289 423
		}
290
		
424

  
291 425
		String[] longnames = new String[headers.length];
292 426
		String[] types = new String[headers.length];
293 427
		if (nbheaderline > 1)//get longnames
......
301 435
			for (int i = 0 ; i < headers.length ; i++) {
302 436
				longnames[i] = headers[i];
303 437
			}
304
		
438

  
305 439
		if (nbheaderline > 2)//got types
306 440
		{
307 441
			reader.readRecord();
......
316 450
				types[i] = "String";
317 451
			}
318 452
		}
319
		
453

  
320 454
		writer.writeStartDocument("UTF-8", "1.0");
321 455
		writer.writeStartElement("enrichissement");
322 456
		writer.writeStartElement("metadatas");
457
		writer.writeCharacters("\n");
323 458
		//println "headers : "+Arrays.toString(headers)
324 459
		for (int i = 1 ; i < headers.length ; i++) {
325 460
			if (headers[i].length() == 0) {
......
337 472
			writer.writeAttribute("selection", "true");
338 473
			writer.writeAttribute("partition", "true");
339 474
			writer.writeAttribute("display", "true");
340
			
475

  
341 476
			writer.writeEndElement();
477
			writer.writeCharacters("\n");
342 478
			//}	
343 479
		}
344 480
		writer.writeEndElement();//close metadatas
481
		writer.writeCharacters("\n");
345 482
		
346 483
		writer.writeStartElement("texts");
484
		writer.writeCharacters("\n");
347 485
		while (reader.readRecord())	{
348 486
			writer.writeStartElement("text");
349 487
			for(int i = 0 ; i < headers.length ; i++)
......
352 490
				} else if(headers[i].equals("xpath")) {
353 491
					writer.writeAttribute("xpath", reader.get(headers[i]));
354 492
				}
355
			
493

  
356 494
			for(int i = 0 ; i < headers.length ; i++)
357 495
				if(!headers[i].equals("id") && !headers[i].equals("xpath"))
358 496
				{
......
363 501
						writer.writeAttribute("value", "N/A");
364 502
					else
365 503
						writer.writeAttribute("value", value);
366
					
504

  
367 505
				}
368 506
			writer.writeEndElement();
507
			writer.writeCharacters("\n");
369 508
		}
370 509
		writer.writeEndElement();//close texts
510
		writer.writeCharacters("\n");
371 511
		writer.writeEndElement();//close metadatas
372
		
512

  
373 513
		reader.close();
374 514
		writer.close();
375 515
		output.close();
376
		
516

  
377 517
		output = null;
378 518
		writer = null;
379 519
		return true;
380 520
	}
381
	
521

  
382 522
	/**
383 523
	 * Keep only metadatas.
384 524
	 *
......
398 538
				i--;
399 539
			}
400 540
		}
401
		
541

  
402 542
		for(TextInjection inj : this.values())
403 543
		{
404 544
			for(int i = 0 ; i < inj.size() ; i++)
......
412 552
			}
413 553
		}
414 554
	}
415
	
555

  
416 556
	/**
417 557
	 * Inject metadatas in xml txm.
418 558
	 *
......
427 567
	{
428 568
		return injectMetadatasInXml(infile, outfile,"text", "tei");
429 569
	}
430
	
570

  
431 571
	/**
432 572
	 * Inject metadatas in xml.
433 573
	 *
......
443 583
	{
444 584
		return injectMetadatasInXml(infile, outfile,tag, null);
445 585
	}
446
	
586

  
447 587
	/**
448 588
	 * Inject metadatas in xml.
449 589
	 *
......
461 601
		String key = infile.getName();
462 602
		if(key.lastIndexOf(".") > 0)
463 603
			key = key.substring(0, key.lastIndexOf("."));
464
		
604

  
465 605
		ArrayList<org.txm.metadatas.Entry> metas = get(key);
466
		
606

  
467 607
		if (metas == null) {
468 608
			System.out.println("\nError: can't find metadata for text of id="+key);
469 609
			System.out.println("Maybe the metadata file doesn't have the right format (comma separated values are needed)");
470 610
			return false;
471 611
		}
472
		
612

  
473 613
		AddAttributeInXml builder = new AddAttributeInXml(infile, tag, metas);
474 614
		builder.onlyOneElement();
475 615
		return builder.process(outfile);
476 616
	}
477
	
617

  
478 618
	/**
479 619
	 * Save.
480 620
	 *
......
487 627
		try {
488 628
			// Création de la source DOM
489 629
			Source source = new DOMSource(doc);
490
			
630

  
491 631
			// Création du fichier de sortie
492 632
			Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outfile), "UTF-8")); 
493 633
			Result resultat = new StreamResult(writer);
494
			
634

  
495 635
			// Configuration du transformer
496 636
			TransformerFactory fabrique = new net.sf.saxon.TransformerFactoryImpl();
497 637
			Transformer transformer = fabrique.newTransformer();
498 638
			transformer.setOutputProperty(OutputKeys.INDENT, "yes");
499 639
			transformer.setOutputProperty(OutputKeys.METHOD, "xml");
500 640
			transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
501
			
641

  
502 642
			// Transformation
503 643
			transformer.transform(source, resultat);
504 644
			writer.close();
......
509 649
			return false;
510 650
		}
511 651
	}
512
	
652

  
513 653
	/**
514 654
	 * Insert.
515 655
	 *
......
524 664
		//println ("insert $pairs into $xpath")
525 665
		XPathFactory factory = XPathFactory.newInstance();
526 666
		XPath XpathObj = factory.newXPath();
527
		
667

  
528 668
		XpathObj.setNamespaceContext(nsContext);
529 669
		XPathExpression expr = XpathObj.compile(xpath);
530
		
670

  
531 671
		NodeList nodes = (NodeList) expr.evaluate(doc, XPathConstants.NODESET);
532 672
		int count = 0;
533 673
		for(int i = 0 ; i < nodes.getLength() ; i++) {
......
539 679
			}
540 680
			count++;
541 681
		}
542
		
682

  
543 683
		factory = null;
544 684
		XpathObj = null;
545 685
		expr = null;
......
551 691
			return false;
552 692
		}
553 693
	}
554
	
694

  
555 695
	/**
556 696
	 * Gets the property names.
557 697
	 *
......
561 701
	{
562 702
		return headersList;
563 703
	}
564
	
704

  
565 705
	/**
566 706
	 * Gets the sattributes.
567 707
	 *
......
574 714
			sattr += "+"+attr;
575 715
		return sattr;
576 716
	}
577
	
717

  
578 718
	/* (non-Javadoc)
579 719
	 * @see java.util.AbstractMap#toString()
580 720
	 */
581 721
	@Override
582
	public String toString()
583
	{
722
	public String toString() {
584 723
		StringBuffer str = new StringBuffer();
585 724
		str.append("Metadata: \n");
586
		for(Metadata data : metadatas)
725
		for (Metadata data : metadatas) {
587 726
			str.append(" "+data.toString()+"\n");
588
		
727
		}
728

  
589 729
		str.append("Injections: \n");
590
		for(TextInjection injection : this.values())
591
		{
730
		for(TextInjection injection : this.values()) {
592 731
			str.append(" "+injection.toString()+"\n");
593 732
		}
594 733
		return str.toString();
595 734
	}
596
	
735

  
597 736
	/**
598 737
	 * The main method.
599 738
	 *
600 739
	 * @param args the arguments
601 740
	 */
602
	public static void main(String[] args)
603
	{
741
	public static void main(String[] args) {
604 742
		String userhome = System.getProperty("user.home");
605 743
		File xmlfile = new File(userhome, "/xml/metadata.xml");
606 744
		File csvfile = new File(userhome, "/xml/metadata.csv");
745
		File odsfile = new File(userhome, "/xml/metadata.ods");
746
		File xlsxfile = new File(userhome, "/xml/metadata.xlsx");
607 747

  
608
		Metadatas m = new Metadatas(csvfile, "UTF-8", ",","\"", 1);
609
		if(m.isInitialized())
610
		{
611
			String[] okmetadatas = {"date", "lieu"};
748
		Metadatas m = new Metadatas(odsfile, "UTF-8", ",","\"", 1);
749
		if (m.isInitialized()) {
612 750
			System.out.println(m.toString());
613 751
		}
614 752
	}
......
616 754
	public ArrayList<Metadata> getMetadatas() {
617 755
		return metadatas;
618 756
	}	
619
	
757

  
620 758
	public ArrayList<String> getHeadersList(){
621 759
		return this.headersList;
622 760
	}
tmp/org.txm.core/META-INF/MANIFEST.MF (revision 965)
1 1
Manifest-Version: 1.0
2
Require-Bundle: org.txm.utils;bundle-version="1.0.0";visibility:=reexp
3
 ort,org.txm.libs.groovy-all;bundle-version="1.0.0";visibility:=reexpo
4
 rt,org.eclipse.core.runtime;bundle-version="3.10.0";visibility:=reexp
5
 ort,org.eclipse.osgi.util;bundle-version="3.2.0";visibility:=reexport
6
 ,org.eclipse.core.net;visibility:=reexport,org.eclipse.osgi;visibilit
7
 y:=reexport,org.eclipse.ui.workbench;visibility:=reexport,org.eclipse
8
 .core.commands;visibility:=reexport,org.eclipse.core.resources;visibi
9
 lity:=reexport
2
Require-Bundle: org.txm.utils;bundle-version="1.0.0";visibility:=reexport,
3
 org.txm.libs.groovy-all;bundle-version="1.0.0";visibility:=reexport,
4
 org.eclipse.core.runtime;bundle-version="3.10.0";visibility:=reexport,
5
 org.eclipse.osgi.util;bundle-version="3.2.0";visibility:=reexport,
6
 org.eclipse.core.net;visibility:=reexport,
7
 org.eclipse.osgi;visibility:=reexport,
8
 org.eclipse.ui.workbench;visibility:=reexport,
9
 org.eclipse.core.commands;visibility:=reexport,
10
 org.eclipse.core.resources;visibility:=reexport,
11
 org.txm.libs.office;bundle-version="0.0.0",
12
 org.txm.libs.msoffice;bundle-version="1.0.0"
10 13
Export-Package: .,
11 14
 EDU.oswego.cs.dl.util.concurrent,
12 15
 EDU.oswego.cs.dl.util.concurrent.misc,

Formats disponibles : Unified diff