Project

General

Profile

Download (2.31 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
 * 
3
 */
4
package eu.etaxonomy.cdm.print.out.odf;
5

    
6
import java.io.File;
7
import java.io.InputStream;
8

    
9
import org.apache.log4j.Logger;
10
import org.jdom.Document;
11
import org.jdom.transform.XSLTransformException;
12
import org.odftoolkit.odfdom.doc.OdfTextDocument;
13

    
14
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
15
import eu.etaxonomy.cdm.print.Transformator;
16
import eu.etaxonomy.cdm.print.out.PublishOutputModuleBase;
17

    
18
/**
19
 * 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 
20
 * <a href="http://www.openoffice.org/">OpenOffice</a> or any other tool that understands ODF.
21
 * 
22
 * @author n.hoffmann
23
 * @since Apr 20, 2010
24
 * @version 1.0
25
 */
26
public class OdfOutputModule extends PublishOutputModuleBase {
27
	private static final Logger logger = Logger
28
		.getLogger(OdfOutputModule.class);
29
	
30
	public static String STYLESHEET_RESOURCE_DEFAULT = "/stylesheets/odf/cdmToOdfText.xsl";
31
	
32
	private DocumentCreator documentCreator;
33
	private Transformator transformator;
34
	
35
	public OdfOutputModule() {
36
		InputStream xslt = getXsltInputStream();
37
		documentCreator = new DocumentCreator();
38
		try {
39
			transformator = new Transformator(xslt);	
40
		} 
41
		catch (XSLTransformException e) {
42
			logger.error("XSLTransformException while creating ODF output module", e);
43
		}
44
	}
45
	
46

    
47
	/* (non-Javadoc)
48
	 * @see eu.etaxonomy.printpublisher.out.IPublishOutputModule#output(org.jdom.Document, java.io.File)
49
	 */
50
	public void output(Document document, File exportFolder, IProgressMonitor progressMonitor) {
51
		
52
		super.output(document, exportFolder, progressMonitor);
53
		
54
		Document transformedDocument;
55
		String filePath = getFilePath(exportFolder);
56
			
57
		try{
58
			transformedDocument = transformator.transform(document);
59
				
60
			OdfTextDocument odfTextDocument = documentCreator.create(transformedDocument);
61
							
62
			odfTextDocument.save(filePath);
63
			logger.warn("ODF output written to disk: " + filePath);
64
		}catch(Exception e){
65
			throw new RuntimeException(e);
66
		}
67
	}
68
	
69
	/*
70
	 * (non-Javadoc)
71
	 * @see eu.etaxonomy.printpublisher.out.IPublishOutputModule#getOutputFileSuffix()
72
	 */
73
	public String getOutputFileSuffix() {
74
		return "odf";
75
	}
76
	
77
	@Override
78
	protected InputStream getDefaultXsltInputStream() {
79
		return OdfOutputModule.class.getResourceAsStream(STYLESHEET_RESOURCE_DEFAULT);
80
	}
81
}
(3-3/4)