Lines 26-35
Link Here
|
26 |
import org.apache.tools.ant.taskdefs.MatchingTask; |
26 |
import org.apache.tools.ant.taskdefs.MatchingTask; |
27 |
import org.apache.tools.ant.types.EnumeratedAttribute; |
27 |
import org.apache.tools.ant.types.EnumeratedAttribute; |
28 |
import org.apache.tools.ant.types.FileSet; |
28 |
import org.apache.tools.ant.types.FileSet; |
|
|
29 |
import org.apache.tools.ant.types.Mapper; |
29 |
import org.apache.tools.ant.util.JAXPUtils; |
30 |
import org.apache.tools.ant.util.JAXPUtils; |
|
|
31 |
import org.apache.tools.ant.util.FileNameMapper; |
30 |
|
32 |
|
31 |
// -- Batik classes ---------------------------------------------------------- |
33 |
// -- Batik classes ---------------------------------------------------------- |
32 |
import org.apache.batik.apps.rasterizer.SVGConverter; |
|
|
33 |
import org.apache.batik.apps.rasterizer.DestinationType; |
34 |
import org.apache.batik.apps.rasterizer.DestinationType; |
34 |
import org.apache.batik.apps.rasterizer.SVGConverterException; |
35 |
import org.apache.batik.apps.rasterizer.SVGConverterException; |
35 |
import org.apache.batik.transcoder.image.JPEGTranscoder; |
36 |
import org.apache.batik.transcoder.image.JPEGTranscoder; |
Lines 47-52
Link Here
|
47 |
import java.util.Iterator; |
48 |
import java.util.Iterator; |
48 |
import java.util.ArrayList; |
49 |
import java.util.ArrayList; |
49 |
import java.util.List; |
50 |
import java.util.List; |
|
|
51 |
import java.util.Collections; |
50 |
|
52 |
|
51 |
|
53 |
|
52 |
|
54 |
|
Lines 116-124
Link Here
|
116 |
protected File destDir = null; |
118 |
protected File destDir = null; |
117 |
/** Contents of <code>fileset</code> elements. */ |
119 |
/** Contents of <code>fileset</code> elements. */ |
118 |
protected Vector filesets = new Vector(); |
120 |
protected Vector filesets = new Vector(); |
|
|
121 |
/** Contents of <code>mapper</code> elements. */ |
122 |
protected Mapper mapperElement = null; |
123 |
/** Whether to strip directories from resulting paths. */ |
124 |
protected boolean flatten = true; |
119 |
|
125 |
|
120 |
/** Converter object used to convert SVG images to raster images. */ |
126 |
/** Converter object used to convert SVG images to raster images. */ |
121 |
protected SVGConverter converter; |
127 |
protected RasterizerTaskSVGConverter converter; |
122 |
|
128 |
|
123 |
|
129 |
|
124 |
|
130 |
|
Lines 127-133
Link Here
|
127 |
* Initializes a new rasterizer task. |
133 |
* Initializes a new rasterizer task. |
128 |
*/ |
134 |
*/ |
129 |
public RasterizerTask() { |
135 |
public RasterizerTask() { |
130 |
converter = new SVGConverter(new RasterizerTaskSVGConverterController(this)); |
|
|
131 |
} |
136 |
} |
132 |
|
137 |
|
133 |
|
138 |
|
Lines 323-328
Link Here
|
323 |
} |
328 |
} |
324 |
|
329 |
|
325 |
/** |
330 |
/** |
|
|
331 |
* Sets <code>flatten</code> attribute value. |
332 |
* |
333 |
* <p>If this attribute is set to <code>true</code>, all generated |
334 |
* files will be placed directly within the directory specified |
335 |
* through the <code>destdir</code> attribute, without any |
336 |
* intermediate subdirectories. When set to <code>false</code> the |
337 |
* structure of the source tree is reproduced.</p> |
338 |
* |
339 |
* <p>This attribute is ignored when a nested <code>mapper</code> |
340 |
* element is given. For backwards compatibility reasons, this |
341 |
* attribute defaults to <code>true</code>.</p> |
342 |
*/ |
343 |
public void setFlatten(boolean flatten) { |
344 |
this.flatten = flatten; |
345 |
} |
346 |
|
347 |
/** |
326 |
* Reads <code>fileset</code> elements. |
348 |
* Reads <code>fileset</code> elements. |
327 |
* |
349 |
* |
328 |
* <p><code>fileset</code> elements can be used when there are many files |
350 |
* <p><code>fileset</code> elements can be used when there are many files |
Lines 335-340
Link Here
|
335 |
} |
357 |
} |
336 |
|
358 |
|
337 |
/** |
359 |
/** |
|
|
360 |
* Creates <code>mapper</code> child element. |
361 |
* |
362 |
* <p>A <code>mapper</code> element can be used to specify |
363 |
* the output file(s) for every input file in a flexible way.</p> |
364 |
* |
365 |
* @return the <code>mapper</code> element to be configured by Ant |
366 |
*/ |
367 |
public Mapper createMapper() throws BuildException { |
368 |
if (mapperElement != null) { |
369 |
throw new BuildException("Cannot define more than one mapper", |
370 |
getLocation()); |
371 |
} |
372 |
mapperElement = new Mapper(getProject()); |
373 |
return mapperElement; |
374 |
} |
375 |
|
376 |
/** |
377 |
* Add a nested file name mapper. |
378 |
* @param fileNameMapper the mapper to add. |
379 |
*/ |
380 |
public void add(FileNameMapper fileNameMapper) { |
381 |
createMapper().add(fileNameMapper); |
382 |
} |
383 |
|
384 |
/** |
338 |
* Validates and sets input values and files, then starts the conversion |
385 |
* Validates and sets input values and files, then starts the conversion |
339 |
* process. |
386 |
* process. |
340 |
* |
387 |
* |
Lines 345-352
Link Here
|
345 |
*/ |
392 |
*/ |
346 |
public void execute() throws BuildException { |
393 |
public void execute() throws BuildException { |
347 |
|
394 |
|
348 |
String[] sources; // Array of input files. |
|
|
349 |
|
350 |
// Store default XML parser information and set user class. |
395 |
// Store default XML parser information and set user class. |
351 |
String defaultParser = XMLResourceDescriptor.getXMLParserClassName(); |
396 |
String defaultParser = XMLResourceDescriptor.getXMLParserClassName(); |
352 |
// Throws BuildException. |
397 |
// Throws BuildException. |
Lines 367-392
Link Here
|
367 |
} |
412 |
} |
368 |
} |
413 |
} |
369 |
|
414 |
|
|
|
415 |
// Actually create our converter |
416 |
converter = new RasterizerTaskSVGConverter(this); |
417 |
|
370 |
// Throws BuildException. |
418 |
// Throws BuildException. |
371 |
setRasterizingParameters(); |
419 |
setRasterizingParameters(); |
372 |
|
420 |
|
373 |
// Get and set source(s). |
421 |
// Get and set source(s) and destination(s). |
374 |
sources = getSourceFiles(); |
422 |
setFileLists(); |
375 |
converter.setSources(sources); |
|
|
376 |
|
423 |
|
377 |
// Set destination. |
|
|
378 |
if(this.srcFile != null) { |
379 |
converter.setDst(this.destFile); |
380 |
} else { |
381 |
converter.setDst(this.destDir); |
382 |
} |
383 |
|
384 |
// Input filenames are stored in the converter and |
424 |
// Input filenames are stored in the converter and |
385 |
// everything is ready for the conversion. |
425 |
// everything is ready for the conversion. |
386 |
|
426 |
|
|
|
427 |
/* |
387 |
log("Rasterizing " + sources.length + |
428 |
log("Rasterizing " + sources.length + |
388 |
(sources.length == 1 ? " image " : " images ") + |
429 |
(sources.length == 1 ? " image " : " images ") + |
389 |
"from SVG to " + this.resultType.toString() + "."); |
430 |
"from SVG to " + this.resultType.toString() + "."); |
|
|
431 |
*/ |
390 |
|
432 |
|
391 |
try { |
433 |
try { |
392 |
converter.execute(); |
434 |
converter.execute(); |
Lines 394-399
Link Here
|
394 |
throw new BuildException(sce.getMessage()); |
436 |
throw new BuildException(sce.getMessage()); |
395 |
} |
437 |
} |
396 |
} finally { |
438 |
} finally { |
|
|
439 |
converter = null; // just to make sure it won't be reused |
440 |
|
397 |
// Restore default XML parser for the next execute. |
441 |
// Restore default XML parser for the next execute. |
398 |
XMLResourceDescriptor.setXMLParserClassName(defaultParser); |
442 |
XMLResourceDescriptor.setXMLParserClassName(defaultParser); |
399 |
} |
443 |
} |
Lines 487-537
Link Here
|
487 |
* |
531 |
* |
488 |
* @return Array of source filename strings. |
532 |
* @return Array of source filename strings. |
489 |
*/ |
533 |
*/ |
490 |
protected String[] getSourceFiles() { |
534 |
protected void setFileLists() { |
491 |
|
535 |
|
492 |
List inputFiles = new ArrayList(); // Input files in temp list. |
|
|
493 |
|
494 |
if(this.srcFile != null) { |
536 |
if(this.srcFile != null) { |
495 |
// Only one source and destination file have been set. |
537 |
// Only one source and destination file have been set. |
496 |
inputFiles.add(this.srcFile.getAbsolutePath()); |
538 |
List srcs = Collections.singletonList(srcFile); |
|
|
539 |
List dests = Collections.singletonList(destFile); |
540 |
converter.setSourceFiles(srcs); |
541 |
converter.setDestinationFiles(dests); |
497 |
} else { |
542 |
} else { |
498 |
// Unknown number of files have to be converted. destdir |
543 |
// Unknown number of files have to be converted. destdir |
499 |
// attribute and either srcdir attribute or fileset element |
544 |
// attribute and either srcdir attribute or fileset element |
500 |
// have been set. |
545 |
// have been set. |
501 |
|
546 |
|
|
|
547 |
List srcs = new ArrayList(); // Input files |
548 |
List dests = new ArrayList(); // Output dirs or files |
549 |
List filesets = this.filesets; // local reference, modifyable |
550 |
FileNameMapper mapper = null; |
551 |
if (mapperElement != null) |
552 |
mapper = mapperElement.getImplementation(); |
553 |
|
502 |
// Read source files from the child patterns. |
554 |
// Read source files from the child patterns. |
503 |
// The value of srcdir attribute overrides the dir attribute in |
555 |
// The value of srcdir attribute overrides the dir attribute in |
504 |
// fileset element. |
556 |
// fileset element. |
505 |
if(this.srcDir != null) { |
557 |
if(this.srcDir != null) { |
506 |
// fileset is declared in the super class. |
558 |
// fileset is declared in the super class. |
507 |
// Scan to get all the files in srcdir directory that |
559 |
// Add to list of filesets in order to get all the files |
508 |
// should be in input files. |
560 |
// in srcdir directory that should be in input files. |
509 |
fileset.setDir(this.srcDir); |
561 |
fileset.setDir(this.srcDir); |
510 |
DirectoryScanner ds = fileset.getDirectoryScanner(project); |
562 |
filesets = new ArrayList(filesets); // local copy, just in case |
511 |
String[] includedFiles = ds.getIncludedFiles(); |
563 |
filesets.add(fileset); |
512 |
// Add file and its path to the input file vector. |
|
|
513 |
for (int j = 0 ; j < includedFiles.length ; j++) { |
514 |
File newFile = new File(srcDir.getPath(), includedFiles[j]); |
515 |
inputFiles.add(newFile.getAbsolutePath()); |
516 |
} |
517 |
} |
564 |
} |
518 |
// Read source files from child filesets. |
565 |
|
|
|
566 |
// Read source files from child filesets and child patterns. |
519 |
for (int i = 0 ; i < filesets.size() ; i++) { |
567 |
for (int i = 0 ; i < filesets.size() ; i++) { |
520 |
// Scan to get all the files in this fileset that |
568 |
// Scan to get all the files in this fileset that |
521 |
// should be in input files. |
569 |
// should be in input files. |
522 |
FileSet fs = (FileSet) filesets.elementAt(i); |
570 |
FileSet fs = (FileSet) filesets.get(i); |
|
|
571 |
File fsDir = fs.getDir(project); |
523 |
DirectoryScanner ds = fs.getDirectoryScanner(project); |
572 |
DirectoryScanner ds = fs.getDirectoryScanner(project); |
524 |
String[] includedFiles = ds.getIncludedFiles(); |
573 |
String[] includedFiles = ds.getIncludedFiles(); |
525 |
// Add file and its path to the input file vector. |
574 |
// Add file and its path to the input file vector. |
526 |
for (int j = 0 ; j < includedFiles.length ; j++) { |
575 |
for (int j = 0 ; j < includedFiles.length ; j++) { |
527 |
File newFile = new File(fs.getDir(project).getPath(), includedFiles[j]); |
576 |
File src = new File(fsDir, includedFiles[j]); |
528 |
inputFiles.add(newFile.getAbsolutePath()); |
577 |
if (mapper != null) { |
|
|
578 |
String[] mapped = mapper.mapFileName(includedFiles[j]); |
579 |
if (mapped != null) { |
580 |
for (int k = 0; k < mapped.length; ++k) { |
581 |
File dest = new File(destDir, mapped[k]); |
582 |
srcs.add(src); |
583 |
dests.add(dest); |
584 |
} |
585 |
} |
586 |
} |
587 |
else if (flatten) { |
588 |
dests.add(destDir); |
589 |
} |
590 |
else { |
591 |
File dest = new File(destDir, includedFiles[j]); |
592 |
srcs.add(src); |
593 |
dests.add(dest.getParentFile()); // destination dir |
594 |
} |
529 |
} |
595 |
} |
530 |
} |
596 |
} |
|
|
597 |
|
598 |
converter.setSourceFiles(srcs); |
599 |
if (mapper == null) |
600 |
converter.setDestinationDirectories(dests); |
601 |
else |
602 |
converter.setDestinationFiles(dests); |
531 |
} |
603 |
} |
532 |
|
|
|
533 |
// Convert List to array and return the array. |
534 |
return (String[])inputFiles.toArray(new String[0]); |
535 |
} |
604 |
} |
536 |
|
605 |
|
537 |
/** |
606 |
/** |