Revision 1094 tmp/org.txm.groovy.core/src/groovy/org/txm/scripts/importer/txt/txtLoader.groovy

txtLoader.groovy (revision 1094)
33 33
import org.txm.objects.*;
34 34
import org.txm.importer.scripts.xmltxm.*;
35 35
import org.txm.*;
36
import org.txm.objects.*;
36 37
import org.txm.core.engines.*;
37 38
import org.txm.utils.i18n.*;
38 39
import org.txm.metadatas.*;
......
44 45
String userDir = System.getProperty("user.home");
45 46
boolean debug = org.txm.utils.logger.Log.isPrintingErrors();
46 47
def MONITOR;
47
BaseParameters params;
48
try {params = paramsBinding;MONITOR=monitor} catch (Exception)
49
{	println "DEV MODE";//exception means we debug
50
	debug = true
51
	params = new BaseParameters(new File(userDir, "TXM/clipboard/clipboard2/import.xml"))
52
	params.load()
53
	if (!org.txm.Toolbox.isInitialized()) {
54
		Toolbox.setParam(Toolbox.INSTALL_DIR,new File("C:/Program Files/TXM"));
55
		Toolbox.setParam(Toolbox.TREETAGGER_MODELS_PATH, new File("C:/Users/mdecorde/TXM/treetagger"));
56
		Toolbox.setParam(Toolbox.METADATA_ENCODING, "UTF-8");
57
		Toolbox.setParam(Toolbox.METADATA_COLSEPARATOR, ",");
58
		Toolbox.setParam(Toolbox.METADATA_TXTSEPARATOR, "\"");
59
		Toolbox.setParam(Toolbox.USER_TXM_HOME, new File(userDir, "TXM"));
60
	}
61
}
62
if (params == null) { println "No parameters file. Aborting"; return;}
48
Project project;
49
boolean debug = org.txm.utils.logger.Log.isPrintingErrors();
63 50

  
64
String corpusname = params.getCorpusName();
65
Element corpusElem = params.corpora.get(corpusname);
66
String basename = params.name;
67
String rootDir = params.rootDir;
68
String lang = corpusElem.getAttribute("lang");
51
try {project=projectBinding;MONITOR=monitor} catch (Exception)
52
{	}
53
if (project == null) { println "no project set. Aborting"; return; }
54

  
55
String corpusname = project.getName();
56
String basename = corpusname
57
String rootDir = project.getSrcdir();
58
String lang = project.getLang()
69 59
String model = lang
70
String encoding = corpusElem.getAttribute("encoding");
71
boolean annotate = "true" == corpusElem.getAttribute("annotate");
72
String xsl = params.getXsltElement(corpusElem).getAttribute("xsl")
73
def xslParams = params.getXsltParams(corpusElem);
74
int wordsPerPage = params.getWordsPerPage("default")
75
boolean build_edition = params.getDoEdition("default")
60
String encoding = project.getEncoding()
61
boolean annotate = project.getAnnotate()
62
String xsl = project.getFrontXSL();
63
def xslParams = project.getXsltParameters();
64
int wordsPerPage = project.getEditionDefinition("default").getWordsPerPage()
65
boolean build_edition = project.getEditionDefinition("default").getBuildEdition()
76 66

  
77 67
File srcDir = new File(rootDir);
78
File binDir = new File(Toolbox.getTxmHomePath(), "corpora/"+basename);
79
binDir.deleteDir();
68
File binDir = project.getProjectDirectory();
80 69
binDir.mkdirs();
81 70
if (!binDir.exists()) {
82 71
	println "Could not create binDir "+binDir
......
186 175
		List<String> NoSpaceBefore = LangFormater.getNoSpaceBefore(lang);
187 176
		List<String> NoSpaceAfter = LangFormater.getNoSpaceAfter(lang);
188 177

  
189
		Element text = params.addText(params.corpora.get(corpusname), txtname, srcfile);
190

  
178
		Text t = new Text(project);
179
		t.setName(txtname);
180
		t.setSourceFile(srcfile)
181
		t.setTXMFile(srcfile)
182
		
191 183
		def ed = new pager(srcfile, outdir, txtname, NoSpaceBefore, NoSpaceAfter, wordsPerPage, basename, null);
192
		Element edition = params.addEdition(text, "default", outdir.getAbsolutePath(), "html");
193

  
184
		Edition edition = new Edition(t);
185
		edition.setName("default");
186
		edition.setIndex(outdir.getAbsolutePath());
194 187
		for (i = 0 ; i < ed.getPageFiles().size();) {
195 188
			File f = ed.getPageFiles().get(i);
196 189
			String wordid = ed.getIdx().get(i);
197
			params.addPage(edition, ""+(++i), wordid);
190
			edition.addPage(""+(++i), wordid);
198 191
		}
199 192
	}
200 193
}
201 194
if (MONITOR != null && MONITOR.isCanceled()) { return MONITOR.done(); }
202 195
if (MONITOR != null) MONITOR.worked(20, "FINALIZING")
203
File paramFile = new File(binDir, "import.xml");
204
DomUtils.save(params.root.getOwnerDocument(), paramFile);readyToLoad = true;
196

  
197
readyToLoad = project.save();

Also available in: Unified diff