Revision 148

tmp/org.txm.core/src/java/org/txm/core/messages/TXMCoreMessages.java (revision 148)
1 1
package org.txm.core.messages;
2 2

  
3 3
import java.lang.reflect.Field;
4

  
4 5
import org.eclipse.osgi.util.NLS;
5 6

  
6 7
/**
......
11 12
public class TXMCoreMessages {
12 13

  
13 14
	
14
	
15
	/**
16
	 * Initializes messages using UTF-8 encoding.
17
	 * @param baseName
18
	 * @param clazz
19
	 */
15
	//TODO: factorize this methods in a Utilities plugin
20 16
	public static void initializeMessages(final String baseName, final Class<?> clazz) {
21 17
		// initialize resource bundle
22 18
		NLS.initializeMessages(baseName, clazz);
......
39 35
			}
40 36
		}
41 37
	}
38

  
42 39
	
43 40
	
44 41
}
tmp/org.txm.core/src/java/org/txm/objects/Result.java (revision 148)
1
// Copyright © 2010-2013 ENS de Lyon.
2
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of
3
// Lyon 2, University of Franche-Comté, University of Nice
4
// Sophia Antipolis, University of Paris 3.
5
// 
6
// The TXM platform is free software: you can redistribute it
7
// and/or modify it under the terms of the GNU General Public
8
// License as published by the Free Software Foundation,
9
// either version 2 of the License, or (at your option) any
10
// later version.
11
// 
12
// The TXM platform is distributed in the hope that it will be
13
// useful, but WITHOUT ANY WARRANTY; without even the implied
14
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15
// PURPOSE. See the GNU General Public License for more
16
// details.
17
// 
18
// You should have received a copy of the GNU General
19
// Public License along with the TXM platform. If not, see
20
// http://www.gnu.org/licenses.
21
// 
22
// 
23
// 
24
// $LastChangedDate: 2013-08-29 14:23:55 +0200 (jeu., 29 août 2013) $
25
// $LastChangedRevision: 2519 $
26
// $LastChangedBy: nilskredens $ 
27
//
28
package org.txm.objects;
29

  
30
import java.io.File;
31
import java.lang.reflect.InvocationTargetException;
32
import java.lang.reflect.Method;
33
import java.util.List;
34

  
35
// TODO: Auto-generated Javadoc
36
/**
37
 * The Class Result.
38
 */
39
public class Result extends TxmObject {
40

  
41
	/** The Constant serialVersionUID. */
42
	private static final long serialVersionUID = -9187579566956874452L;
43

  
44
	/** The source. */
45
	TxmObject source;
46
	
47
	/** The data. */
48
	Object data;
49

  
50
	/**
51
	 * Instantiates a new result.
52
	 *
53
	 * @param source the source
54
	 * @param result the result
55
	 */
56
	public Result(TxmObject source, Object result) {
57
		this.setPath(source.getPath() + getName());
58
		this.source = source;
59
		this.data = result;
60
	}
61

  
62
	/**
63
	 * To txt.
64
	 *
65
	 * @param file the file
66
	 */
67
	public void toTxt(File file) {
68
		try {
69
			Method method = data.getClass().getMethod("toTxt", File.class); //$NON-NLS-1$
70
			method.invoke(data, file);
71
		} catch (SecurityException e) {
72
			// TODO Auto-generated catch block
73
			org.txm.utils.logger.Log.printStackTrace(e);
74
		} catch (NoSuchMethodException e) {
75
			// TODO Auto-generated catch block
76
			org.txm.utils.logger.Log.printStackTrace(e);
77
		} catch (IllegalArgumentException e) {
78
			// TODO Auto-generated catch block
79
			org.txm.utils.logger.Log.printStackTrace(e);
80
		} catch (IllegalAccessException e) {
81
			// TODO Auto-generated catch block
82
			org.txm.utils.logger.Log.printStackTrace(e);
83
		} catch (InvocationTargetException e) {
84
			// TODO Auto-generated catch block
85
			org.txm.utils.logger.Log.printStackTrace(e);
86
		}
87

  
88
	}
89

  
90
	/* (non-Javadoc)
91
	 * @see org.txm.objects.TxmObject#getChildren()
92
	 */
93
	@Override
94
	public List<TxmObject> getChildren() {
95
		// TODO Auto-generated method stub
96
		return null;
97
	}
98

  
99
	/* (non-Javadoc)
100
	 * @see org.txm.objects.TxmObject#hasChildren(org.txm.objects.TxmObject)
101
	 */
102
	@Override
103
	public boolean hasChildren(TxmObject children) {
104
		// TODO Auto-generated method stub
105
		return false;
106
	}
107

  
108
	/* (non-Javadoc)
109
	 * @see org.txm.objects.TxmObject#load()
110
	 */
111
	@Override
112
	public boolean load() {
113
		loadMetadata();
114
		return false;
115
	}
116

  
117
	/* (non-Javadoc)
118
	 * @see org.txm.objects.TxmObject#removeChildren(org.txm.objects.TxmObject)
119
	 */
120
	@Override
121
	public TxmObject removeChildren(TxmObject children) {
122
		// TODO Auto-generated method stub
123
		return null;
124
	}
125

  
126
	/* (non-Javadoc)
127
	 * @see org.txm.objects.TxmObject#save()
128
	 */
129
	@Override
130
	public boolean save() {
131
		// TODO Auto-generated method stub
132
		return false;
133
	}
134

  
135
	/* (non-Javadoc)
136
	 * @see org.txm.objects.TxmObject#getParent()
137
	 */
138
	@Override
139
	public TxmObject getParent() {
140
		// TODO Auto-generated method stub
141
		return null;
142
	}
143

  
144
}
tmp/org.txm.core/src/java/org/txm/objects/BaseParameters.java (revision 148)
18 18
import javax.xml.parsers.ParserConfigurationException;
19 19

  
20 20
import org.txm.annotation.repository.SQLKnowledgeRepository;
21
import org.txm.importer.DomUtils;
22 21
import org.txm.importer.xtz.ImportKeys;
23 22
import org.txm.sql.SQLConnection;
23
import org.txm.utils.xml.DomUtils;
24 24
import org.txm.utils.logger.Log;
25 25
import org.w3c.dom.Document;
26 26
import org.w3c.dom.Element;
tmp/org.txm.core/src/java/org/txm/objects/Base.java (revision 148)
47 47

  
48 48
import org.txm.Messages;
49 49
import org.txm.Toolbox;
50
import org.txm.doc.Zip;
51 50
import org.txm.functions.ProgressWatcher;
52 51
import org.txm.searchengine.cqp.corpus.Alignement;
53 52
import org.txm.searchengine.cqp.corpus.CorpusManager;
54 53
import org.txm.searchengine.cqp.corpus.MainCorpus;
55 54
import org.txm.utils.logger.Log;
55
import org.txm.utils.zip.Zip;
56 56
import org.w3c.dom.Document;
57 57
import org.w3c.dom.Element;
58 58

  
tmp/org.txm.core/src/java/org/txm/objects/Corpus.java (revision 148)
44 44
import org.txm.annotation.DatabasePersistenceManager;
45 45
import org.txm.annotation.repository.KnowledgeRepository;
46 46
import org.txm.annotation.repository.KnowledgeRepositoryManager;
47
import org.txm.doc.Zip;
48 47
import org.txm.functions.ProgressWatcher;
49 48
import org.txm.metadatas.DateMetadata;
50 49
import org.txm.metadatas.Metadata;
......
54 53
import org.txm.searchengine.cqp.corpus.query.Query;
55 54
import org.txm.sql.SQLConnection;
56 55
import org.txm.utils.logger.Log;
56
import org.txm.utils.zip.Zip;
57 57
import org.w3c.dom.Document;
58 58
import org.w3c.dom.Element;
59 59
import org.w3c.dom.NodeList;
tmp/org.txm.core/src/java/org/txm/searchengine/cqp/corpus/Lexicon.java (revision 148)
42 42
import org.txm.searchengine.cqp.CqpDataProxy;
43 43
import org.txm.stat.StatException;
44 44
import org.txm.stat.data.Vector;
45
import org.txm.stat.engine.r.RDevice;
46 45
import org.txm.stat.engine.r.RWorkspace;
47 46
import org.txm.stat.engine.r.data.VectorImpl;
48 47

  
......
254 253
		return v;
255 254
	}
256 255

  
257
	/**
258
	 * Draw a pareto graphic with this frequency list and record it into the
259
	 * provided filename into svg format.
260
	 *
261
	 * @param file where to save the pareto graphic.
262
	 * @return the pareto graphic
263
	 * @throws StatException if anything goes wrong.
264
	 */
265
	public void getParetoGraphic(File file) throws StatException {
266
		String rName = asVector().getSymbol();
267
		String expr = "pareto(" + rName + ")"; //$NON-NLS-1$ //$NON-NLS-2$
268
		try {
269
			RWorkspace.getRWorkspaceInstance().plot(file, expr, RDevice.SVG);
270
		} catch (Exception e) {
271
			throw new StatException(e);
272
		}
273
	}
256
	//TODO: move this into a Lexicon chart renderer
257
//	/**
258
//	 * Draw a pareto graphic with this frequency list and record it into the
259
//	 * provided filename into svg format.
260
//	 *
261
//	 * @param file where to save the pareto graphic.
262
//	 * @return the pareto graphic
263
//	 * @throws StatException if anything goes wrong.
264
//	 */
265
//	public void getParetoGraphic(File file) throws StatException {
266
//		String rName = asVector().getSymbol();
267
//		String expr = "pareto(" + rName + ")"; //$NON-NLS-1$ //$NON-NLS-2$
268
//		try {
269
//			RWorkspace.getRWorkspaceInstance().plot(file, expr, RDevice.SVG);
270
//		} catch (Exception e) {
271
//			throw new StatException(e);
272
//		}
273
//	}
274 274

  
275 275
	/**
276 276
	 * The corpus or subcorpus this lexicon is build on.
tmp/org.txm.core/src/java/org/txm/searchengine/cqp/corpus/CorpusManager.java (revision 148)
30 30
import java.util.ArrayList;
31 31
import java.util.List;
32 32

  
33
import org.eclipse.persistence.annotations.Structure;
33 34
import org.txm.Messages;
34 35
import org.txm.Toolbox;
35 36
import org.txm.searchengine.cqp.AbstractCqiClient;
tmp/org.txm.core/src/java/org/txm/searchengine/cqp/corpus/Partition.java (revision 148)
27 27
//
28 28
package org.txm.searchengine.cqp.corpus;
29 29

  
30
import java.io.IOException;
31 30
import java.text.Collator;
32 31
import java.text.DateFormat;
33 32
import java.text.ParseException;
......
40 39
import java.util.HashMap;
41 40
import java.util.List;
42 41
import java.util.Locale;
43
import java.util.Map;
44
import java.util.UUID;
42
import java.util.TreeMap;
45 43

  
46 44
import org.eclipse.osgi.util.NLS;
47 45
import org.txm.HasResults;
......
52 50
import org.txm.searchengine.cqp.clientExceptions.CqiClientException;
53 51
import org.txm.searchengine.cqp.corpus.query.Query;
54 52
import org.txm.searchengine.cqp.corpus.query.QueryPart;
55
import org.txm.searchengine.cqp.serverException.CqiServerError;
56
import org.txm.stat.StatException;
57
import org.txm.stat.data.LexicalTable;
58
import org.txm.stat.engine.r.data.LexicalTableImpl;
53
//import org.txm.stat.data.LexicalTable;
54
//import org.txm.stat.engine.r.data.LexicalTableImpl;
59 55
import org.txm.utils.logger.Log;
60 56
import org.w3c.dom.Document;
61 57
import org.w3c.dom.Element;
......
85 81
	private Property property;
86 82

  
87 83
	/** An association between name of analysis property and lexical table. */
88
	private Map<String, LexicalTable> lexicalTables = new HashMap<String, LexicalTable>();
84
//	private Map<String, LexicalTable> lexicalTables = new HashMap<String, LexicalTable>();
89 85

  
90
	/** The results. */
91
	private List<Object> results = new ArrayList<Object>();
86
	
87
	/** The results stored by class. */
88
	private TreeMap<Class, List<Object>> results = new TreeMap<Class, List<Object>>();
92 89

  
93 90
	/**
94 91
	 * Creates a new partition on a corpus given a structure, a property of this
......
450 447
		return property;
451 448
	}
452 449

  
453
	/**
454
	 * Create a lexical table for this partition given an analysis property.
455
	 * Lexical table are cached and recycled. In order to drop from memory a
456
	 * lexical table, use {@link #dropLexicalTable(Property)}.
457
	 *
458
	 * @param analysisProperty the analysis property
459
	 * @param Fmin the fmin
460
	 * @return the lexical table
461
	 * @throws StatException the stat exception
462
	 * @throws CqiClientException the cqi client exception
463
	 * @author sloiseau
464
	 */
465
	public LexicalTable getLexicalTable(Property analysisProperty, int Fmin)
466
	throws StatException, CqiClientException {
467
		// System.out.println("CL : test si déja existant ds cache");
468
		/*if (lexicalTables.containsKey(analysisProperty.getName())) {
469
			if (lexicalTables.get(analysisProperty.getName()).getConstructorFmin() == Fmin)
470
				return lexicalTables.get(analysisProperty.getName());
471
		}*/
472
		// System.out.println("CL : fait un new lexique");
473
		LexicalTable t = LexicalTableImpl.getLexicalTable(this,
474
				analysisProperty, Fmin);
475 450

  
476
		// System.out.println("CL : put results ds le cache");
477
		lexicalTables.put(analysisProperty.getName(), t);
478
		return t;
479
	}
480 451

  
481 452
	/**
482
	 * Drop a lexical table from the cache. Return the dropped lexical table, or
483
	 * <code>null</code> if no lexical table was existing for this analysis
484
	 * property.
485
	 *
486
	 * @param analysisProperty the analysis property
487
	 * @return the lexical table
488
	 * @author sloiseau
489
	 */
490
	public LexicalTable dropLexicalTable(Property analysisProperty) {
491
		return lexicalTables.remove(analysisProperty.getName());
492
	}
493

  
494
	/**
495 453
	 * Stores the result of textometric computation in this corpus.
496 454
	 *
497 455
	 * @param result the result
498 456
	 */
499 457
	public void storeResult(Object result) {
500
		results.add(result);
458
		if (!results.containsKey(result.getClass())) results.put(result.getClass(), new ArrayList<Object>());
459
		results.get(result.getClass()).add(result);
501 460
	}
502 461

  
503 462
	/**
......
508 467
	 */
509 468
	@Override
510 469
	public boolean removeResult(Object result) {
511
		boolean ret = results.remove(result);
512
		if (result instanceof LexicalTable)
513
		{
514
			lexicalTables.remove(((LexicalTable)result).getProperty().getName());
515
		}
470
		if (!results.containsKey(result.getClass())) return false;
471
		
472
		boolean ret = results.get(result.getClass()).remove(result);
516 473
		return ret;
517 474
	}
518 475

  
......
523 480
	 */
524 481
	@Override
525 482
	public List<Object> getResults() {
526
		return results;
483
		ArrayList<Object> tmp = new ArrayList<Object>();
484
		for (Class k : results.keySet()) {
485
			tmp.addAll(results.get(k));
486
		}
487
		return tmp;
527 488
	}
528 489

  
529 490
	/**
tmp/org.txm.core/src/java/org/txm/searchengine/cqp/corpus/Corpus.java (revision 148)
39 39
import org.eclipse.osgi.util.NLS;
40 40
import org.txm.HasResults;
41 41
import org.txm.Messages;
42
import org.txm.annotation.AnnotationManager;
43 42
import org.txm.functions.selection.SelectionResult;
44 43
import org.txm.objects.Base;
45 44
import org.txm.objects.TxmObject;
......
306 305
	 * @throws CqiClientException
307 306
	 *             the cqi client exception
308 307
	 * 
309
	 * @see org.txm.corpus.Partition#Partition
308
	 * @see org.txm.searchengine.cqp.corpus.partition.core.corpusengine.cqp.corpus.Partition#Partition
310 309
	 */
311 310
	public Partition createPartition(StructuralUnit structure,
312 311
			StructuralUnitProperty property) throws CqiClientException {
......
351 350
	 * @throws CqiClientException
352 351
	 *             the cqi client exception
353 352
	 * 
354
	 * @see org.txm.corpus.Partition#Partition
353
	 * @see org.txm.searchengine.cqp.corpus.partition.core.corpusengine.cqp.corpus.Partition#Partition
355 354
	 */
356 355
	public Partition createPartition(StructuralUnit structure,
357 356
			StructuralUnitProperty property, List<String> values)
tmp/org.txm.core/src/java/org/txm/searchengine/cqp/corpus/Subcorpus.java (revision 148)
30 30
import java.io.IOException;
31 31
import java.util.ArrayList;
32 32
import java.util.List;
33
import java.util.UUID;
34 33

  
35 34
import org.eclipse.osgi.util.NLS;
36 35
import org.txm.Messages;
tmp/org.txm.core/src/java/org/txm/searchengine/cqp/corpus/query/PartitionFocus.java (revision 148)
30 30
import java.util.ArrayList;
31 31
import java.util.List;
32 32

  
33
import org.txm.Messages;
33 34
import org.txm.searchengine.cqp.corpus.Part;
34 35
import org.txm.searchengine.cqp.corpus.Partition;
35 36
import org.txm.utils.logger.Log;
36
import org.txm.Messages;
37 37

  
38 38
// TODO: Auto-generated Javadoc
39 39
/**
tmp/org.txm.core/src/java/org/txm/utils/FixString.java (revision 148)
1
// Copyright © 2010-2013 ENS de Lyon.
2
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of
3
// Lyon 2, University of Franche-Comté, University of Nice
4
// Sophia Antipolis, University of Paris 3.
5
// 
6
// The TXM platform is free software: you can redistribute it
7
// and/or modify it under the terms of the GNU General Public
8
// License as published by the Free Software Foundation,
9
// either version 2 of the License, or (at your option) any
10
// later version.
11
// 
12
// The TXM platform is distributed in the hope that it will be
13
// useful, but WITHOUT ANY WARRANTY; without even the implied
14
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15
// PURPOSE. See the GNU General Public License for more
16
// details.
17
// 
18
// You should have received a copy of the GNU General
19
// Public License along with the TXM platform. If not, see
20
// http://www.gnu.org/licenses.
21

  
22
//
23
// This file is part of the TXM platform.
24
//
25
// The TXM platform is free software: you can redistribute it and/or modif y
26
// it under the terms of the GNU General Public License as published by
27
// the Free Software Foundation, either version 3 of the License, or
28
// (at your option) any later version.
29
//
30
// The TXM platform is distributed in the hope that it will be useful,
31
// but WITHOUT ANY WARRANTY; without even the implied warranty of
32
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
33
// GNU General Public License for more details.
34
//
35
// You should have received a copy of the GNU General Public License
36
// along with the TXM platform.  If not, see <http://www.gnu.org/licenses/>.
37
// 
38
// 
39
// 
40
// $LastChangedDate: 2013-05-06 17:38:43 +0200 (lun., 06 mai 2013) $
41
// $LastChangedRevision: 2386 $
42
// $LastChangedBy: mdecorde $ 
43
//
44
package org.txm.utils;
45

  
46
// TODO: Auto-generated Javadoc
47
/**
48
 * syntaxic sugar for CQP queries.
49
 *
50
 * @author mdecorde
51
 */
52
public class FixString {
53
	
54
	/**
55
	 * Normalize.
56
	 *
57
	 * @param line the line
58
	 * @return the string
59
	 */
60
	public static String normalize(String line) {
61
		char[] array = line.toCharArray();
62
		for (int i = 0; i < array.length; i++) {
63
			char c = array[i];
64
			if (c <= 0x1f) {
65
				// System.out.println(
66
				// "fix : "+c+" code "+Character.getNumericValue(c));
67
				array[i] = ' ';
68
			}
69
		}
70
		return String.valueOf(array);
71
	}
72
}
tmp/org.txm.core/src/java/org/txm/utils/package.html (revision 148)
1
<html>
2
<body>
3
<p>Contains usefull tools</p>
4
</body>
5
</html>
tmp/org.txm.core/src/java/org/txm/utils/LS.java (revision 148)
1
package org.txm.utils;
2
import java.io.*;
3
import java.util.ArrayList;
4

  
5
import org.txm.Messages;
6

  
7
class LS {
8

  
9
	/**
10
	 * Prints the Content of the Directory
11
	 *
12
	 * @param dir
13
	 *            Directory
14
	 * @param recur
15
	 *            Recursion
16
	 * @param size
17
	 *            SizeRecursion
18
	 * @param hidden
19
	 *            Show hidden Files
20
	 */
21
	public static ArrayList<File> list(File dir, boolean recur, boolean hidden) {
22
		ArrayList<File> result = new ArrayList<File>();
23
		if ((dir != null) && dir.exists() && dir.isDirectory()) {
24
			File[] filelist = dir.listFiles();
25

  
26
			for (File file : filelist) {
27
				if (hidden || !file.isHidden()) {
28
					result.add(file);
29
					if (file.isDirectory() && recur) {
30
						result.addAll(list(file, recur, hidden));
31
					} 
32
				}
33
			}
34
		} else {
35
			System.err.println(Messages.LS_0 + dir + Messages.LS_1);
36
		}
37
		return result;
38
	}
39
	
40
	public static void main(String args[]) {
41
		ArrayList<File> files1 = LS.list(new File("/home/mdecorde"), false, false); //$NON-NLS-1$
42
		System.out.println(files1.size());
43
		
44
		ArrayList<File> files2 = LS.list(new File("/home/mdecorde"), true, false); //$NON-NLS-1$
45
		System.out.println(files2.size());
46
		
47
		ArrayList<File> files3 = LS.list(new File("/home/mdecorde"), false, true); //$NON-NLS-1$
48
		System.out.println(files3.size());
49
		
50
		ArrayList<File> files4 = LS.list(new File("/home/mdecorde"), true, true); //$NON-NLS-1$
51
		System.out.println(files4.size());
52
	}
53
}
tmp/org.txm.core/src/java/org/txm/utils/LangDetector.groovy (revision 148)
1
package org.txm.utils;
2

  
3
import java.io.File;
4
import java.io.IOException;
5
import java.util.LinkedHashMap;
6
import org.knallgrau.utils.textcat.TextCategorizer
7
import org.txm.importer.DomUtils;
8

  
9

  
10

  
11
public class LangDetector {
12
	public static int MINIMALSIZE = 10000
13

  
14
	String lang = System.getProperty("user.language");
15
	String encoding = System.getProperty("file.encoding");
16

  
17
	LinkedHashMap<String, Integer> langs = new LinkedHashMap<String, Integer>();
18
	static HashMap<String, String> translations = ["french":"fr", "english":"en",
19
		"spanish":"sp", "italian":"it",
20
		"danish":"da", "swedish":"sv",
21
		"hungarian":"hu", "slovakian":"sk",
22
		"german":"de","dutch":"nl",
23
		"albanian":"al", "norwegian":"no",
24
		"finnish":"fi", "slovenian":"sl",
25
		"polish":"pl"];
26
	TextCategorizer guesser = new TextCategorizer()
27

  
28
	public LangDetector(File file) {
29
		this(file, "UTF-8")
30
	}
31

  
32
	public LangDetector(File file, String encoding)
33
	{
34
		if(file.isDirectory())
35
			processDirectory(file);
36
		else
37
			processFile(file);
38
	}
39

  
40
	private void processDirectory(File dir)
41
	{
42
		//println "process $dir"
43
		if(dir.isDirectory()) {
44
			for (File file : dir.listFiles())
45
				if (file.isFile())
46
					processFile(file);
47
		} else {
48
			processFile(dir);
49
		}
50

  
51
	}
52

  
53
	private void processFile(File file) throws IOException
54
	{
55
		//println "process $file"
56
		String text = null;
57
		if (file.getName().endsWith(".xml") || file.getName().endsWith(".XML")) {
58
			text = DomUtils.load(file).getDocumentElement().getTextContent();
59
		} else {
60
			text = file.getText(encoding);
61
		}
62
		//println "text: "+text.length()
63
		String langcode = guesser.categorize(text);
64
		String guessedLang = translations.get(langcode);
65
		if (guessedLang == null) {
66
			guessedLang = langcode;
67
		}
68

  
69
		//println "$file guessed $guessedLang"
70
		if (!langs.containsKey(guessedLang))
71
			langs.put(guessedLang, 0);
72
		langs.put(guessedLang, langs.get(guessedLang)+1);
73
	}
74

  
75
	public String getLang()
76
	{
77
		int max = 0;
78
		//println "LANGS: "+langs
79
		for (String s : langs.keySet()) {
80
			if (max < langs.get(s)) {
81
				max = langs.get(s);
82
				lang = s;
83
			}
84
		}
85
		return lang;
86
	}
87

  
88
	public static configFromModels(File dir)
89
	{
90
		def files = dir.listFiles()
91
		files.sort()
92
		for(File f : files)
93
			if(f.getName().contains(".lm") && !f.getName().contains("-"))
94
				println f.getAbsolutePath()+"\t"+f.getName().substring(0, f.getName().length()-3);
95
	}
96

  
97
	public HashMap<String, Integer> getLangs()
98
	{
99
		return langs;
100
	}
101
}
tmp/org.txm.core/src/java/org/txm/utils/LocalXhtmlDtdEntityResolver.java (revision 148)
1
package org.txm.utils;
2
import java.io.IOException;
3

  
4
import org.xml.sax.EntityResolver;
5
import org.xml.sax.InputSource;
6
import org.xml.sax.SAXException;
7

  
8
public class LocalXhtmlDtdEntityResolver implements EntityResolver {
9

  
10
    /* (non-Javadoc)
11
     * @see org.xml.sax.EntityResolver#resolveEntity(java.lang.String, java.lang.String)
12
     */
13
    @Override
14
    public InputSource resolveEntity( String publicId, String systemId )
15
            throws SAXException, IOException {
16
        String fileName = systemId.substring( systemId.lastIndexOf( "/" ) + 1 ); 
17
        System.out.println("FILENAME: "+fileName);
18
        
19
        return new InputSource( 
20
                getClass().getClassLoader().getResourceAsStream( fileName ) );
21
    }
22

  
23
}
tmp/org.txm.core/src/java/org/txm/utils/CharsetDetector.java (revision 148)
1
package org.txm.utils;
2

  
3
import java.io.File;
4
import java.io.IOException;
5
import java.util.LinkedHashMap;
6

  
7
import org.mozilla.universalchardet.CharsetListener;
8
import org.mozilla.universalchardet.UniversalDetector;
9

  
10
public class CharsetDetector {
11
	public static int MINIMALSIZE=2000;
12
	String encoding = System.getProperty("file.encoding"); //$NON-NLS-1$
13
	LinkedHashMap<String, Integer> encodings = new LinkedHashMap<String, Integer>();
14
	
15
	public CharsetDetector(File file)
16
	{
17
		if(file.isDirectory())
18
			processDirectory(file);
19
		else
20
			try {
21
				processFile(file);
22
			} catch (IOException e) {
23
				// TODO Auto-generated catch block
24
				org.txm.utils.logger.Log.printStackTrace(e);
25
			}
26
	}
27
	
28
	private void processDirectory(File dir)
29
	{
30
		for (File file : dir.listFiles()) {
31
			if (file.isFile()) {
32
				try {
33
					processFile(file);
34
				} catch (IOException e) {
35
					// TODO Auto-generated catch block
36
					org.txm.utils.logger.Log.printStackTrace(e);
37
				}
38
			}
39
		}
40
	}
41
	
42
	String guessedCharset = System.getProperty("file.encoding"); //$NON-NLS-1$
43
	private void processFile(File file) throws IOException
44
	{
45
		guessedCharset = System.getProperty("file.encoding"); //$NON-NLS-1$
46
		UniversalDetector detector = new UniversalDetector(
47
                new CharsetListener() {
48
                    @Override
49
					public void report(String name)
50
                    {
51
                        guessedCharset = name;
52
                    }
53
                }
54
                );
55
        
56
        byte[] buf = new byte[4096];
57
        java.io.FileInputStream fis = new java.io.FileInputStream(file);
58
        
59
        int nread;
60
        while ((nread = fis.read(buf)) > 0 && !detector.isDone()) {
61
            detector.handleData(buf, 0, nread);
62
        }
63
        detector.dataEnd();
64

  
65
		if(!encodings.containsKey(guessedCharset))
66
			encodings.put(guessedCharset, 0);
67
		encodings.put(guessedCharset, encodings.get(guessedCharset)+1);
68
	}
69
	
70
	public String getEncoding()
71
	{
72
		int max = 0;
73
		for(String s : encodings.keySet())
74
		{
75
			if(max < encodings.get(s))
76
			{
77
				max = encodings.get(s);
78
				encoding = s;
79
			}
80
		}
81
		return encoding;
82
	}
83
	
84
	public LinkedHashMap<String, Integer> getEncodings()
85
	{
86
		return encodings;
87
	}
88
	
89
	public static void main(String[] args) {
90
		CharsetDetector detector = new CharsetDetector(new File("/home/mdecorde/Bureau/testencoding")); //$NON-NLS-1$
91
		System.out.println(detector.getEncodings());
92
	}
93
}
tmp/org.txm.core/src/java/org/txm/utils/ExecTimer.java (revision 148)
1
package org.txm.utils;
2

  
3
import java.util.Date;
4

  
5
import org.txm.Messages;
6

  
7
public class ExecTimer {
8
	static long startTime = 0, endTime = 0;
9
	static String message = ""; //$NON-NLS-1$
10
	public static void start() {
11
		startTime = new Date().getTime();
12
	}
13

  
14
	public static String stop() {
15
		endTime = new Date().getTime();
16
		return setMessage(endTime - startTime);
17
	}
18

  
19
	static float t;
20
	private static String setMessage(float time) {
21
		t = time;
22
		if (t < 1000) {
23
			message = ""+((int)t)+Messages.ExecTimer_0; //$NON-NLS-1$
24
		}
25
		else {
26
			t = t/1000;
27
			if (t < 3) {
28
				message = ""+t; //$NON-NLS-1$
29
				message = ""+(message.substring(0, 3))+Messages.ExecTimer_1; //$NON-NLS-1$
30
			} else if (t < 60) 
31
				message = ""+((int)t)+Messages.ExecTimer_1; //$NON-NLS-1$
32
			else if (t < 3600) 
33
				message = ""+((int)t/60)+Messages.ExecTimer_2+((int)t%60)+Messages.ExecTimer_1; //$NON-NLS-1$
34
			else 
35
				message = ""+((int)t/3600)+Messages.ExecTimer_3+((int)(t%3600)/60)+Messages.ExecTimer_2+((int)(t%3600)%60)+ Messages.ExecTimer_1; //$NON-NLS-1$
36
		}
37
		return message + " ("+(int)time+" ms)"; //$NON-NLS-1$ //$NON-NLS-2$
38
	}
39

  
40
	public static String getMessage() {
41
		return message;
42
	}
43
}
tmp/org.txm.core/src/java/org/txm/utils/DiffPrint.java (revision 148)
1
package org.txm.utils;
2
/*
3
 * $Log: DiffPrint.java,v $
4
 * Revision 1.10  2009/04/20 18:53:29  stuart
5
 * Make print_header public.
6
 *
7
 * Revision 1.9  2009/01/19 03:05:26  stuart
8
 * Fix StackOverflow bug with heuristic on reported by Jimmy Han.
9
 *
10
 * Revision 1.8  2007/12/20 05:04:21  stuart
11
 * Can no longer import from default package.
12
 *
13
 * Revision 1.7  2007/12/20 04:29:53  stuart
14
 * Fix setupOutput permission.  Thanks to Sargon Benjamin
15
 *
16
 * Revision 1.6  2005/04/27 02:13:40  stuart
17
 * Add Str.dup()
18
 *
19
 * Revision 1.5  2004/01/29 02:35:35  stuart
20
 * Test for out of bounds exception in UnifiedPrint.print_hunk.
21
 * Add setOutput() to DiffPrint.Base.
22
 *
23
 * Revision 1.4  2003/04/22  01:50:47  stuart
24
 * add Unified format diff
25
 *
26
 * Revision 1.3  2003/04/22  01:00:32  stuart
27
 * added context diff format
28
 *
29
 * Revision 1.2  2000/03/02  16:59:54  stuart
30
 * add GPL
31
 *
32
 */
33

  
34
import java.io.*;
35
import java.util.Vector;
36
import java.util.Date;
37

  
38
interface UnaryPredicate {
39
  boolean execute(Object obj);
40
}
41

  
42
/** A simple framework for printing change lists produced by <code>Diff</code>.
43
    @see bmsi.util.Diff
44
    @author Stuart D. Gathman
45
    Copyright (C) 2000 Business Management Systems, Inc.
46
<p>
47
    This program is free software; you can redistribute it and/or modify
48
    it under the terms of the GNU General Public License as published by
49
    the Free Software Foundation; either version 1, or (at your option)
50
    any later version.
51
<p>
52
    This program is distributed in the hope that it will be useful,
53
    but WITHOUT ANY WARRANTY; without even the implied warranty of
54
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
55
    GNU General Public License for more details.
56
<p>
57
    You should have received a copy of the GNU General Public License
58
    along with this program; if not, write to the Free Software
59
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
60
 */
61
public class DiffPrint {
62
  /** A Base class for printing edit scripts produced by Diff.
63
      This class divides the change list into "hunks", and calls
64
      <code>print_hunk</code> for each hunk.  Various utility methods
65
      are provided as well.
66
   */
67
  public static abstract class Base {
68
    protected PrintWriter outfile;
69
    public void setOutput(Writer wtr) {
70
      outfile = new PrintWriter(wtr);
71
    }
72
    protected void setupOutput() {
73
      if (outfile == null)
74
	outfile = new PrintWriter(new OutputStreamWriter(System.out));
75
    }
76
    protected Base(Object[] a,Object[] b) {
77
      file0 = a;
78
      file1 = b;
79
    }
80
    /** Set to ignore certain kinds of lines when printing
81
	an edit script.  For example, ignoring blank lines or comments.
82
     */
83
    protected UnaryPredicate ignore = null;
84

  
85
    /** Set to the lines of the files being compared.
86
     */
87
    protected Object[] file0, file1;
88

  
89
    /** Divide SCRIPT into pieces by calling HUNKFUN and
90
       print each piece with PRINTFUN.
91
       Both functions take one arg, an edit script.
92

  
93
       PRINTFUN takes a subscript which belongs together (with a null
94
       link at the end) and prints it.  */
95
    public void print_script(Diff.change script) {
96
      setupOutput();
97
      Diff.change next = script;
98

  
99
      while (next != null)
100
	{
101
	  Diff.change t, end;
102

  
103
	  /* Find a set of changes that belong together.  */
104
	  t = next;
105
	  end = hunkfun(next);
106

  
107
	  /* Disconnect them from the rest of the changes,
108
	     making them a hunk, and remember the rest for next iteration.  */
109
	  next = end.link;
110
	  end.link = null;
111
	  //if (DEBUG)
112
	  //  debug_script(t);
113

  
114
	  /* Print this hunk.  */
115
	  print_hunk(t);
116

  
117
	  /* Reconnect the script so it will all be freed properly.  */
118
	  end.link = next;
119
	}
120
	outfile.flush();
121
    }
122

  
123
    /** Called with the tail of the script
124
       and returns the last link that belongs together with the start
125
       of the tail. */
126

  
127
    protected Diff.change hunkfun(Diff.change hunk) {
128
      return hunk;
129
    }
130

  
131
    protected int first0, last0, first1, last1, deletes, inserts;
132

  
133
    /** Look at a hunk of edit script and report the range of lines in each file
134
      that it applies to.  HUNK is the start of the hunk, which is a chain
135
      of `struct change'.  The first and last line numbers of file 0 are stored
136
      in *FIRST0 and *LAST0, and likewise for file 1 in *FIRST1 and *LAST1. 
137
      Note that these are internal line numbers that count from 0.
138

  
139
      If no lines from file 0 are deleted, then FIRST0 is LAST0+1.
140

  
141
      Also set *DELETES nonzero if any lines of file 0 are deleted
142
      and set *INSERTS nonzero if any lines of file 1 are inserted.
143
      If only ignorable lines are inserted or deleted, both are
144
      set to 0.  */
145

  
146
    protected void analyze_hunk(Diff.change hunk) {
147
      int f0, l0 = 0, f1, l1 = 0, show_from = 0, show_to = 0;
148
      int i;
149
      Diff.change next;
150
      boolean nontrivial = (ignore == null);
151

  
152
      show_from = show_to = 0;
153

  
154
      f0 = hunk.line0;
155
      f1 = hunk.line1;
156

  
157
      for (next = hunk; next != null; next = next.link)
158
	{
159
	  l0 = next.line0 + next.deleted - 1;
160
	  l1 = next.line1 + next.inserted - 1;
161
	  show_from += next.deleted;
162
	  show_to += next.inserted;
163
	  for (i = next.line0; i <= l0 && ! nontrivial; i++)
164
	    if (!ignore.execute(file0[i]))
165
	      nontrivial = true;
166
	  for (i = next.line1; i <= l1 && ! nontrivial; i++)
167
	    if (!ignore.execute(file1[i]))
168
	      nontrivial = true;
169
	}
170

  
171
      first0 = f0;
172
      last0 = l0;
173
      first1 = f1;
174
      last1 = l1;
175

  
176
      /* If all inserted or deleted lines are ignorable,
177
	 tell the caller to ignore this hunk.  */
178

  
179
      if (!nontrivial)
180
	show_from = show_to = 0;
181

  
182
      deletes = show_from;
183
      inserts = show_to;
184
    }
185

  
186
    /** Called to print the script header which identifies the files compared.
187
      The default does nothing (except set output to system.out if
188
      not otherwise set).  Derived style classes can override to print 
189
      the files compared in the format for that style.
190
     */
191
    public void print_header(String filea, String fileb) {
192
      setupOutput();
193
    }
194

  
195
    protected abstract void print_hunk(Diff.change hunk);
196
    
197
    protected void print_1_line(String pre,Object linbuf) {
198
      outfile.println(pre + linbuf.toString());
199
    }
200

  
201
    /** Print a pair of line numbers with SEPCHAR, translated for file FILE.
202
       If the two numbers are identical, print just one number.
203

  
204
       Args A and B are internal line numbers.
205
       We print the translated (real) line numbers.  */
206

  
207
    protected void print_number_range (char sepchar, int a, int b) {
208
      /* Note: we can have B < A in the case of a range of no lines.
209
	 In this case, we should print the line number before the range,
210
	 which is B.  */
211
      if (++b > ++a)
212
	outfile.print("" + a + sepchar + b);
213
      else
214
	outfile.print(b);
215
    }
216

  
217
    public static char change_letter(int inserts, int deletes) {
218
      if (inserts == 0)
219
	return 'd';
220
      else if (deletes == 0)
221
	return 'a';
222
      else
223
	return 'c';
224
    }
225
  }
226

  
227
  /** Print a change list in the standard diff format.
228
   */
229
  public static class NormalPrint extends Base {
230

  
231
    public NormalPrint(Object[] a,Object[] b) {
232
      super(a,b);
233
    }
234

  
235
    /** Print a hunk of a normal diff.
236
       This is a contiguous portion of a complete edit script,
237
       describing changes in consecutive lines.  */
238

  
239
    protected void print_hunk (Diff.change hunk) {
240

  
241
      /* Determine range of line numbers involved in each file.  */
242
      analyze_hunk(hunk);
243
      if (deletes == 0 && inserts == 0)
244
	return;
245

  
246
      /* Print out the line number header for this hunk */
247
      print_number_range (',', first0, last0);
248
      outfile.print(change_letter(inserts, deletes));
249
      print_number_range (',', first1, last1);
250
      outfile.println();
251

  
252
      /* Print the lines that the first file has.  */
253
      if (deletes != 0)
254
	for (int i = first0; i <= last0; i++)
255
	  print_1_line ("< ", file0[i]);
256

  
257
      if (inserts != 0 && deletes != 0)
258
	outfile.println("---");
259

  
260
      /* Print the lines that the second file has.  */
261
      if (inserts != 0)
262
	for (int i = first1; i <= last1; i++)
263
	  print_1_line ("> ", file1[i]);
264
    }
265
  }
266

  
267
  /** Prints an edit script in a format suitable for input to <code>ed</code>.
268
      The edit script must be generated with the reverse option to
269
      be useful as actual <code>ed</code> input.
270
   */
271
  public static class EdPrint extends Base {
272

  
273
    public EdPrint(Object[] a,Object[] b) {
274
      super(a,b);
275
    }
276

  
277
    /** Print a hunk of an ed diff */
278
    protected void print_hunk(Diff.change hunk) {
279

  
280
      /* Determine range of line numbers involved in each file.  */
281
      analyze_hunk (hunk);
282
      if (deletes == 0 && inserts == 0)
283
	return;
284

  
285
      /* Print out the line number header for this hunk */
286
      print_number_range (',', first0, last0);
287
      outfile.println(change_letter(inserts, deletes));
288

  
289
      /* Print new/changed lines from second file, if needed */
290
      if (inserts != 0)
291
	{
292
	  boolean inserting = true;
293
	  for (int i = first1; i <= last1; i++)
294
	    {
295
	      /* Resume the insert, if we stopped.  */
296
	      if (! inserting)
297
		outfile.println(i - first1 + first0 + "a");
298
	      inserting = true;
299

  
300
	      /* If the file's line is just a dot, it would confuse `ed'.
301
		 So output it with a double dot, and set the flag LEADING_DOT
302
		 so that we will output another ed-command later
303
		 to change the double dot into a single dot.  */
304

  
305
	      if (".".equals(file1[i]))
306
		{
307
		  outfile.println("..");
308
		  outfile.println(".");
309
		  /* Now change that double dot to the desired single dot.  */
310
		  outfile.println(i - first1 + first0 + 1 + "s/^\\.\\././");
311
		  inserting = false;
312
		}
313
	      else
314
		/* Line is not `.', so output it unmodified.  */
315
		print_1_line ("", file1[i]);
316
	    }
317

  
318
	  /* End insert mode, if we are still in it.  */
319
	  if (inserting)
320
	    outfile.println(".");
321
	}
322
    }
323
  }
324

  
325
  /** Prints an edit script in context diff format.  This and its
326
    'unified' variation is used for source code patches.
327
   */
328
  public static class ContextPrint extends Base {
329

  
330
    protected int context = 3;
331

  
332
    public ContextPrint(Object[] a,Object[] b) {
333
      super(a,b);
334
    }
335

  
336
    protected void print_context_label (String mark, File inf, String label) {
337
      setupOutput();
338
      if (label != null)
339
	outfile.println(mark + ' ' + label);
340
      else if (inf.lastModified() > 0)
341
        // FIXME: use DateFormat to get precise format needed.
342
	outfile.println(
343
	  mark + ' ' + inf.getPath() + '\t' + new Date(inf.lastModified())
344
	);
345
      else
346
	/* Don't pretend that standard input is ancient.  */
347
	outfile.println(mark + ' ' + inf.getPath());
348
    }
349

  
350
    public void print_header(String filea,String fileb) {
351
      print_context_label ("***", new File(filea), filea);
352
      print_context_label ("---", new File(fileb), fileb);
353
    }
354

  
355
    /** If function_regexp defined, search for start of function. */
356
    private String find_function(Object[] lines, int start) {
357
      return null;
358
    }
359

  
360
    protected void print_function(Object[] file,int start) {
361
      String function = find_function (file0, first0);
362
      if (function != null) {
363
	outfile.print(" ");
364
	outfile.print(
365
	  (function.length() < 40) ? function : function.substring(0,40)
366
	);
367
      }
368
    }
369

  
370
    protected void print_hunk(Diff.change hunk) {
371

  
372
      /* Determine range of line numbers involved in each file.  */
373

  
374
      analyze_hunk (hunk);
375

  
376
      if (deletes == 0 && inserts == 0)
377
	return;
378

  
379
      /* Include a context's width before and after.  */
380

  
381
      first0 = Math.max(first0 - context, 0);
382
      first1 = Math.max(first1 - context, 0);
383
      last0 = Math.min(last0 + context, file0.length - 1);
384
      last1 = Math.min(last1 + context, file1.length - 1);
385

  
386

  
387
      outfile.print("***************");
388

  
389
      /* If we looked for and found a function this is part of,
390
	 include its name in the header of the diff section.  */
391
      print_function (file0, first0);
392

  
393
      outfile.println();
394
      outfile.print("*** ");
395
      print_number_range (',', first0, last0);
396
      outfile.println(" ****");
397

  
398
      if (deletes != 0) {
399
	Diff.change next = hunk;
400

  
401
	for (int i = first0; i <= last0; i++) {
402
	  /* Skip past changes that apply (in file 0)
403
	     only to lines before line I.  */
404

  
405
	  while (next != null && next.line0 + next.deleted <= i)
406
	    next = next.link;
407

  
408
	  /* Compute the marking for line I.  */
409

  
410
	  String prefix = " ";
411
	  if (next != null && next.line0 <= i)
412
	    /* The change NEXT covers this line.
413
	       If lines were inserted here in file 1, this is "changed".
414
	       Otherwise it is "deleted".  */
415
	    prefix = (next.inserted > 0) ? "!" : "-";
416

  
417
	  print_1_line (prefix, file0[i]);
418
	}
419
      }
420

  
421
      outfile.print("--- ");
422
      print_number_range (',', first1, last1);
423
      outfile.println(" ----");
424

  
425
      if (inserts != 0) {
426
	Diff.change next = hunk;
427

  
428
	for (int i = first1; i <= last1; i++) {
429
	  /* Skip past changes that apply (in file 1)
430
	     only to lines before line I.  */
431

  
432
	  while (next != null && next.line1 + next.inserted <= i)
433
	    next = next.link;
434

  
435
	  /* Compute the marking for line I.  */
436

  
437
	  String prefix = " ";
438
	  if (next != null && next.line1 <= i)
439
	    /* The change NEXT covers this line.
440
	       If lines were deleted here in file 0, this is "changed".
441
	       Otherwise it is "inserted".  */
442
	    prefix = (next.deleted > 0) ? "!" : "+";
443

  
444
	  print_1_line (prefix, file1[i]);
445
	}
446
      }
447
    }
448
  }
449

  
450
  /** Prints an edit script in context diff format.  This and its
451
    'unified' variation is used for source code patches.
452
   */
453
  public static class UnifiedPrint extends ContextPrint {
454

  
455
    public UnifiedPrint(Object[] a,Object[] b) {
456
      super(a,b);
457
    }
458

  
459
    public void print_header(String filea,String fileb) {
460
      print_context_label ("---", new File(filea), filea);
461
      print_context_label ("+++", new File(fileb), fileb);
462
    }
463

  
464
    private void print_number_range (int a, int b) {
465
      //translate_range (file, a, b, &trans_a, &trans_b);
466

  
467
      /* Note: we can have B < A in the case of a range of no lines.
468
	 In this case, we should print the line number before the range,
469
	 which is B.  */
470
      if (b < a)
471
	outfile.print(b + ",0");
472
      else
473
        super.print_number_range(',',a,b);
474
    }
475

  
476
    protected void print_hunk(Diff.change hunk) {
477
      /* Determine range of line numbers involved in each file.  */
478
      analyze_hunk (hunk);
479

  
480
      if (deletes == 0 && inserts == 0)
481
	return;
482

  
483
      /* Include a context's width before and after.  */
484

  
485
      first0 = Math.max(first0 - context, 0);
486
      first1 = Math.max(first1 - context, 0);
487
      last0 = Math.min(last0 + context, file0.length - 1);
488
      last1 = Math.min(last1 + context, file1.length - 1);
489

  
490
      outfile.print("@@ -");
491
      print_number_range (first0, last0);
492
      outfile.print(" +");
493
      print_number_range (first1, last1);
494
      outfile.print(" @@");
495

  
496
      /* If we looked for and found a function this is part of,
497
	 include its name in the header of the diff section.  */
498
      print_function(file0,first0);
499

  
500
      outfile.println();
501

  
502
      Diff.change next = hunk;
503
      int i = first0;
504
      int j = first1;
505

  
506
      while (i <= last0 || j <= last1) {
507

  
508
	/* If the line isn't a difference, output the context from file 0. */
509

  
510
	if (next == null || i < next.line0) {
511
	  if (i < file0.length) {
512
	    outfile.print(' ');
513
	    print_1_line ("", file0[i++]);
514
	  }
515
	  j++;
516
	}
517
	else {
518
	  /* For each difference, first output the deleted part. */
519

  
520
	  int k = next.deleted;
521
	  while (k-- > 0) {
522
	    outfile.print('-');
523
	    print_1_line ("", file0[i++]);
524
	  }
525

  
526
	  /* Then output the inserted part. */
527

  
528
	  k = next.inserted;
529
	  while (k-- > 0) {
530
	    outfile.print('+');
531
	    print_1_line ("", file1[j++]);
532
	  }
533

  
534
	  /* We're done with this hunk, so on to the next! */
535

  
536
	  next = next.link;
537
	}
538
      }
539
    }
540
  }
541

  
542

  
543
  /** Read a text file into an array of String.  This provides basic diff
544
     functionality.  A more advanced diff utility will use specialized
545
     objects to represent the text lines, with options to, for example,
546
     convert sequences of whitespace to a single space for comparison
547
     purposes.
548
   */
549
  static String[] slurp(String file) throws IOException {
550
    BufferedReader rdr = new BufferedReader(new FileReader(file));
551
    Vector s = new Vector();
552
    for (;;) {
553
      String line = rdr.readLine();
554
      if (line == null) break;
555
      s.addElement(line);
556
    }
557
    String[] a = new String[s.size()];
558
    s.copyInto(a);
559
    return a;
560
  }
561

  
562
  public static void main(String[] argv) throws IOException {
563
    String filea = argv[argv.length - 2];
564
    String fileb = argv[argv.length - 1];
565
    String[] a = slurp(filea);
566
    String[] b = slurp(fileb);
567
    Diff d = new Diff(a,b);
568
    char style = 'n';
569
    d.heuristic = false;
570
    for (int i = 0; i < argv.length - 2; ++i) {
571
      String f = argv[i];
572
      if (f.startsWith("-")) {
573
        for (int j = 1; j < f.length(); ++j) {
574
	  switch (f.charAt(j)) {
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff