Revision 1971
tmp/org.txm.groovy.core/src/groovy/org/txm/scripts/importer/xtz/XTZImporter.groovy (revision 1971) | ||
---|---|---|
132 | 132 |
if ("true".equals(cleanDirectories)) { |
133 | 133 |
new File(module.getBinaryDirectory(), "tokenized").deleteDir() |
134 | 134 |
new File(module.getBinaryDirectory(), "src").deleteDir() |
135 |
new File(module.getBinaryDirectory(), "split").deleteDir() |
|
135 | 136 |
} |
136 | 137 |
} |
137 | 138 |
|
... | ... | |
144 | 145 |
*/ |
145 | 146 |
public boolean doFixSurrogates() { |
146 | 147 |
File srcDirectory = new File(module.getBinaryDirectory(), "src") |
147 |
srcDirectory.mkdir() |
|
148 |
|
|
148 | 149 |
def files = inputDirectory.listFiles() |
149 | 150 |
if (files == null) { |
150 | 151 |
reason = "No file to process in $inputDirectory" |
151 | 152 |
return false; |
152 | 153 |
} |
153 |
|
|
154 |
srcDirectory.deleteDir() // clean before copying |
|
155 |
srcDirectory.mkdir() |
|
156 |
|
|
154 | 157 |
for (File file : files) { |
155 | 158 |
def outputFile = new File(srcDirectory, file.getName()); |
156 | 159 |
if (file.getName().toLowerCase().endsWith(".xml")) { |
... | ... | |
171 | 174 |
* |
172 | 175 |
*/ |
173 | 176 |
public boolean doSplitMergeXSLStep() { |
174 |
File srcDirectory = new File(module.getBinaryDirectory(), "src") |
|
175 |
srcDirectory.mkdir()
|
|
176 |
xslParams["output-directory"] = srcDirectory.getAbsoluteFile().toURI().toString();
|
|
177 |
|
|
177 |
|
|
178 |
File splitedDirectory = new File(module.getBinaryDirectory(), "split")
|
|
179 |
splitedDirectory.deleteDir()
|
|
180 |
|
|
178 | 181 |
File xslDirectory = new File(module.getSourceDirectory(), "xsl/1-split-merge") |
179 | 182 |
println "-- Split-Merge XSL Step with $xslDirectory" |
180 | 183 |
def xslFiles = xslDirectory.listFiles() |
181 | 184 |
if (xslDirectory.exists() && xslFiles != null && xslFiles.size() > 0) { |
182 |
|
|
185 |
|
|
186 |
splitedDirectory.mkdir() |
|
187 |
xslParams["output-directory"] = splitedDirectory.getAbsoluteFile().toURI().toString(); |
|
188 |
|
|
183 | 189 |
xslFiles.sort() |
184 | 190 |
for (File xslFile : xslFiles) { |
185 | 191 |
if (xslFile.isDirectory() || xslFile.isHidden() || !xslFile.getName().endsWith(".xsl")) continue; |
186 | 192 |
//if (!xslFile.getName().matches("[1-9]-.+")) continue; |
187 | 193 |
|
188 |
if (ApplyXsl2.processImportSources(xslFile, inputDirectory.listFiles(), xslParams, false)) {
|
|
194 |
if (ApplyXsl2.processImportSources(xslFile, inputDirectory.listFiles(), xslParams)) { |
|
189 | 195 |
println "" |
190 | 196 |
} else { |
191 | 197 |
reason = "Fail to apply split-merge XSL: $xslPath" |
192 | 198 |
} |
193 | 199 |
break; // THERE IS ONLY ONE XSL FILE TO APPLY |
194 | 200 |
} |
195 |
inputDirectory = srcDirectory; // the files to process are now in the "src" directory
|
|
201 |
inputDirectory = splitedDirectory; // the files to process are now in the "src" directory
|
|
196 | 202 |
} else { |
197 | 203 |
//println "Nothing to do." |
198 | 204 |
} |
... | ... | |
248 | 254 |
File frontXSLdirectory = new File(module.getSourceDirectory(), "xsl/2-front") |
249 | 255 |
println "-- Front XSL Step with the $frontXSLdirectory directory." |
250 | 256 |
def xslFiles = frontXSLdirectory.listFiles() |
257 |
|
|
258 |
xslParams["output-directory"] = outputDirectory.getAbsoluteFile().toURI().toString(); |
|
259 |
|
|
251 | 260 |
if (frontXSLdirectory.exists() && xslFiles != null && xslFiles.size() > 0) { |
252 | 261 |
|
253 | 262 |
xslFiles.sort() |
tmp/org.txm.groovy.core/src/groovy/org/txm/scripts/importer/xtz/XTZImport.groovy (revision 1971) | ||
---|---|---|
109 | 109 |
if (origDirectory.exists()) { |
110 | 110 |
print "." |
111 | 111 |
File copyDirectory = new File(this.binaryDirectory, dir) |
112 |
copyDirectory.deleteDir(); // clean before copying |
|
112 | 113 |
FileCopy.copyFiles(origDirectory, copyDirectory) |
113 | 114 |
} |
114 | 115 |
} |
tmp/org.txm.core/src/java/org/txm/importer/ApplyXsl2.java (revision 1971) | ||
---|---|---|
59 | 59 |
import java.util.ArrayList; |
60 | 60 |
import java.util.Arrays; |
61 | 61 |
import java.util.HashMap; |
62 |
import java.util.List; |
|
62 | 63 |
import java.util.logging.Level; |
63 | 64 |
|
64 | 65 |
import javax.xml.transform.Source; |
... | ... | |
306 | 307 |
if (xmloutfile != null) { |
307 | 308 |
BufferedWriter w = new BufferedWriter(new FileWriter(xmloutfile)); |
308 | 309 |
w.write(strWriter.toString()); |
310 |
// System.out.println("DEBUG: "+xmloutfile); |
|
311 |
// System.out.println(" : "+strWriter.toString().substring(0, 60)); |
|
309 | 312 |
w.close(); |
310 | 313 |
|
311 | 314 |
// if (debug && inputfile_copy != null) { |
... | ... | |
412 | 415 |
File[] files = listFiles(srcdir); // get files XSL compatible |
413 | 416 |
if (files == null) return false; |
414 | 417 |
|
415 |
System.out.println("-- Applying "+xslFile+" XSL to "+files.length+" files with parameters: "+params+" on directory "+srcdir+" result written in "+outdir); |
|
418 |
System.out.println("-- Applying "+xslFile+" XSL to "+files.length+" (from "+srcdir+") files with parameters: "+params+" on directory "+srcdir+" result written in "+outdir);
|
|
416 | 419 |
|
417 | 420 |
ConsoleProgressBar cpb = new ConsoleProgressBar(files.length); |
418 | 421 |
for (File f : files) { |
... | ... | |
426 | 429 |
continue; // input file is older than output file |
427 | 430 |
} |
428 | 431 |
|
429 |
if (deleteOutput) outfile = null; |
|
432 |
if (deleteOutput) outfile = null; // if outfile is null builder.process won't create the output file adn will replace f
|
|
430 | 433 |
|
431 | 434 |
if (!builder.process(f, outfile)) { |
432 | 435 |
System.out.println("Failed to process file "+ f); |
... | ... | |
454 | 457 |
* @throws TransformerException |
455 | 458 |
* @throws IOException |
456 | 459 |
*/ |
460 |
public static boolean processImportSources(File xslFile, List<File> files, HashMap<String, Object> params) throws TransformerException, IOException |
|
461 |
{ |
|
462 |
return processImportSources(xslFile, files.toArray(new File[files.size()]), params); |
|
463 |
} |
|
464 |
|
|
465 |
/** |
|
466 |
* Transform files and select files : nor hidden and nor technical (DTD, XSL, etc.) |
|
467 |
* |
|
468 |
* Apply one XSL, XML files are replaced |
|
469 |
* |
|
470 |
* @param xslFile |
|
471 |
* @param pSrcDirectory |
|
472 |
* @param outdir |
|
473 |
* @param params XSL parameters |
|
474 |
* @return |
|
475 |
* @throws TransformerException |
|
476 |
* @throws IOException |
|
477 |
*/ |
|
457 | 478 |
public static boolean processImportSources(File xslFile, File[] files, HashMap<String, Object> params) throws TransformerException, IOException |
458 | 479 |
{ |
459 | 480 |
if (xslFile.exists()) { |
... | ... | |
484 | 505 |
} |
485 | 506 |
cpb.tick(); |
486 | 507 |
|
487 |
if (!builder.process(f, f)) {
|
|
508 |
if (!builder.process(f, null)) {
|
|
488 | 509 |
System.out.println("Failed with file "+ f); |
489 | 510 |
} |
490 | 511 |
} |
Also available in: Unified diff