1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.print.out.odf;
|
10
|
|
11
|
import java.io.File;
|
12
|
import java.io.InputStream;
|
13
|
|
14
|
import org.apache.logging.log4j.LogManager;
|
15
|
import org.apache.logging.log4j.Logger;
|
16
|
import org.jdom.Document;
|
17
|
import org.jdom.transform.XSLTransformException;
|
18
|
import org.odftoolkit.odfdom.doc.OdfTextDocument;
|
19
|
|
20
|
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
|
21
|
import eu.etaxonomy.cdm.print.Transformator;
|
22
|
import eu.etaxonomy.cdm.print.out.PublishOutputModuleBase;
|
23
|
|
24
|
/**
|
25
|
* This output module will transform the given document into <a href="http://www.oasis-open.org/committees/office/">ODF</a> format for further editing in
|
26
|
* <a href="http://www.openoffice.org/">OpenOffice</a> or any other tool that understands ODF.
|
27
|
*
|
28
|
* @author n.hoffmann
|
29
|
* @since Apr 20, 2010
|
30
|
*/
|
31
|
public class OdfOutputModule extends PublishOutputModuleBase {
|
32
|
|
33
|
private static final Logger logger = LogManager.getLogger(OdfOutputModule.class);
|
34
|
|
35
|
public static String STYLESHEET_RESOURCE_DEFAULT = "/stylesheets/odf/cdmToOdfText.xsl";
|
36
|
|
37
|
private DocumentCreator documentCreator;
|
38
|
private Transformator transformator;
|
39
|
|
40
|
public OdfOutputModule() {
|
41
|
InputStream xslt = getXsltInputStream();
|
42
|
documentCreator = new DocumentCreator();
|
43
|
try {
|
44
|
transformator = new Transformator(xslt);
|
45
|
}
|
46
|
catch (XSLTransformException e) {
|
47
|
logger.error("XSLTransformException while creating ODF output module", e);
|
48
|
}
|
49
|
}
|
50
|
|
51
|
@Override
|
52
|
public void output(Document document, File exportFolder, IProgressMonitor progressMonitor) {
|
53
|
|
54
|
super.output(document, exportFolder, progressMonitor);
|
55
|
|
56
|
Document transformedDocument;
|
57
|
String filePath = getFilePath(exportFolder);
|
58
|
|
59
|
try{
|
60
|
transformedDocument = transformator.transform(document);
|
61
|
|
62
|
OdfTextDocument odfTextDocument = documentCreator.create(transformedDocument);
|
63
|
|
64
|
odfTextDocument.save(filePath);
|
65
|
logger.warn("ODF output written to disk: " + filePath);
|
66
|
}catch(Exception e){
|
67
|
throw new RuntimeException(e);
|
68
|
}
|
69
|
}
|
70
|
|
71
|
@Override
|
72
|
public String getOutputFileSuffix() {
|
73
|
return "odf";
|
74
|
}
|
75
|
|
76
|
@Override
|
77
|
protected InputStream getDefaultXsltInputStream() {
|
78
|
return OdfOutputModule.class.getResourceAsStream(STYLESHEET_RESOURCE_DEFAULT);
|
79
|
}
|
80
|
}
|