cdmlib-print/src/main/java/eu/etaxonomy/cdm/print/out/pdf/PdfOutputModule.java -text
cdmlib-print/src/main/java/eu/etaxonomy/cdm/print/out/taxpub/TaxPubOutputModule.java -text
cdmlib-print/src/main/java/eu/etaxonomy/cdm/print/out/xml/XMLOutputModule.java -text
-cdmlib-print/src/main/resources/eu/etaxonomy/cdm/print/out/odf/cdmToOdfText.xsl -text
-cdmlib-print/src/main/resources/eu/etaxonomy/cdm/print/out/pdf/cdmToPdf.xsl -text
cdmlib-print/src/main/resources/eu/etaxonomy/cdm/print/package.html -text
cdmlib-print/src/main/resources/log4j.properties -text
+cdmlib-print/src/main/resources/stylesheets/odf/cdmToOdfText.xsl -text
+cdmlib-print/src/main/resources/stylesheets/pdf/cdmToPdf.xsl -text
cdmlib-print/src/site/apt/download.apt -text
cdmlib-print/src/site/apt/formats.apt -text
cdmlib-print/src/site/apt/getting-started.apt -text
/**
* Implementation of an IXMLEntityFactory that is connected to a CDM Community Server on
- * a remote machine. API call will be executed by accessing the the servers REST API.
+ * a remote machine. API call will be executed by accessing the servers REST API.
*
* @author n.hoffmann
* @created Apr 6, 2010
package eu.etaxonomy.cdm.print.out;
import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Calendar;
+import java.util.List;
+
+import javax.imageio.stream.FileImageInputStream;
import org.apache.log4j.Logger;
import org.jdom.Document;
+import eu.etaxonomy.cdm.common.CdmUtils;
import eu.etaxonomy.cdm.common.IProgressMonitor;
/**
* The date format used by {@link #generateFilenameWithDate(String, String)}
*/
public static final String DATE_FORMAT_NOW = "yyyyMMdd-HHmm";
+
+ private FilenameFilter filter = new FilenameFilter() {
+
+ @Override
+ public boolean accept(File dir, String fileName) {
+ return fileName.substring(fileName.length() - 3).equals("xsl");
+ }
+ };
+
+ private File xslt;
/**
* Generates a string containing the current date followed by the given name.
logger.trace(message);
progressMonitor.subTask(message);
}
+
+
+ @Override
+ public List<File> getStylesheets() throws IOException {
+ List<File> stylesheets = new ArrayList<File>();
+
+ for(File directory : getStylesheetLocations()){
+ if(directory.exists() && directory.isDirectory()){
+ stylesheets.addAll(getStylesheetsByLocation(directory));
+ }else{
+ logger.info(String.format("Tried to read styleshets from '%s', but it does not exist or is not a directory", directory));
+ }
+ }
+
+ return stylesheets;
+
+ }
+
+ private List<File> getStylesheetLocations() throws IOException {
+ List<File> locationList = new ArrayList<File>();
+
+ String l = File.separator;
+
+ URL shippedStylesheetsResource = AbstractPublishOutputModule.class.getResource("/stylesheets/pdf/");
+ File shippedStylesheetsDir = new File(shippedStylesheetsResource.getFile());
+ locationList.add(shippedStylesheetsDir);
+
+ // TODO this should be configured in a central place, see #2387
+ String cdmlibHomeDir = CdmUtils.getHomeDir() + l + ".cdmLibrary";
+
+ File userdir = new File(cdmlibHomeDir + l + "stylesheets" + l + getOutputFileSuffix());
+ locationList.add(userdir);
+
+ return locationList;
+ }
+
+ @Override
+ public File getXslt() {
+ return xslt;
+ }
+
+ @Override
+ public void setXslt(File xslt){
+ this.xslt = xslt;
+ }
+
+ public InputStream getXsltInputStream(){
+ if(getXslt() == null){
+ return getDefaultXsltInputStream();
+ }
+
+ try {
+ return new FileInputStream(getXslt());
+ } catch (FileNotFoundException e) {
+ logger.error(e);
+ }
+ return null;
+ }
+
+ protected InputStream getDefaultXsltInputStream() {
+ return null;
+ }
+
+ public List<File> getStylesheetsByLocation(File stylesheetFolder){
+
+ File[] stylesheets = stylesheetFolder.listFiles(filter);
+
+ return Arrays.asList(stylesheets);
+ }
}
package eu.etaxonomy.cdm.print.out;
import java.io.File;
+import java.io.IOException;
+import java.util.List;
import org.jdom.Document;
*/
public void output(Document document, File targetFolder, IProgressMonitor progressMonitor);
+ /**
+ * Returns all available stylesheets for this output module. Search path will include the users ~/.cdmLibrary directory
+ * to allow for custom stylesheets
+ *
+ * @return a set of xsl files
+ * @throws IOException TODO
+ */
+ public List<File> getStylesheets() throws IOException;
+
+ /**
+ * @return the xslt file associated with this output module
+ */
+ public File getXslt();
+
+ /**
+ * Associate an xsl file to be used by this output module
+ *
+ * @param xslt a file
+ */
+ public void setXslt(File xslt);
}
package eu.etaxonomy.cdm.print.out.odf;
import java.io.File;
+import java.io.IOException;
import java.io.InputStream;
+import java.util.List;
import org.apache.log4j.Logger;
import org.jdom.Document;
private static final Logger logger = Logger
.getLogger(OdfOutputModule.class);
- public static String STYLESHEET_RESOURCE_DEFAULT = "/eu/etaxonomy/cdm/print/out/odf/cdmToOdfText.xsl";
+ public static String STYLESHEET_RESOURCE_DEFAULT = "/stylesheets/odf/cdmToOdfText.xsl";
private DocumentCreator documentCreator;
private Transformator transformator;
-
- private InputStream stylesheet;
public OdfOutputModule() {
- stylesheet = OdfOutputModule.class.getResourceAsStream(STYLESHEET_RESOURCE_DEFAULT);
+ InputStream xslt = getXsltInputStream();
documentCreator = new DocumentCreator();
try {
- transformator = new Transformator(stylesheet);
+ transformator = new Transformator(xslt);
}
catch (XSLTransformException e) {
logger.error("XSLTransformException while creating ODF output module", e);
public String getOutputFileSuffix() {
return "odf";
}
-
+
+ @Override
+ protected InputStream getDefaultXsltInputStream() {
+ return OdfOutputModule.class.getResourceAsStream(STYLESHEET_RESOURCE_DEFAULT);
+ }
}
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
+import java.util.Set;
import javax.xml.transform.Result;
import javax.xml.transform.Transformer;
private static final Logger logger = Logger
.getLogger(PdfOutputModule.class);
- public static String STYLESHEET_RESOURCE_DEFAULT = "/eu/etaxonomy/cdm/print/out/pdf/cdmToPdf.xsl";
+ public static String STYLESHEET_RESOURCE_DEFAULT = "/stylesheets/pdf/cdmToPdf.xsl";
/*
* (non-Javadoc)
Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out);
// Setup XSLT
- InputStream xslt = getXslt();
+ InputStream xslt = getXsltInputStream();
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(new StreamSource(xslt));
return "pdf";
}
- public InputStream getXslt(){
+ public InputStream getDefaultXsltInputStream(){
return PdfOutputModule.class.getResourceAsStream(STYLESHEET_RESOURCE_DEFAULT);
}
}
package eu.etaxonomy.cdm.print.out.taxpub;
import java.io.File;
+import java.io.IOException;
+import java.util.List;
import org.apache.log4j.Logger;
import org.jdom.Document;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.util.List;
import org.apache.log4j.Logger;
import org.jdom.Document;
package eu.etaxonomy.cdm.print.out.pdf;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.List;
import org.junit.Test;
+import eu.etaxonomy.cdm.print.out.AbstractPublishOutputModule;
+
/**
* @author n.hoffmann
/**
+ * @throws IOException
*
*/
@Test
- public void testGetXslt() {
+ public void testGetXslt() throws IOException {
PdfOutputModule outputModule = new PdfOutputModule();
- assertNotNull(outputModule.getXslt());
+ InputStream xslt = outputModule.getXsltInputStream();
+
+ assertNotNull(xslt);
+ assertTrue(xslt.available() > 0);
}
+ @Test
+ public void testGetStylesheetByLocation() throws IOException {
+ PdfOutputModule outputModule = new PdfOutputModule();
+
+ URL shippedStylesheetsResource = AbstractPublishOutputModule.class.getResource("/stylesheets/pdf/");
+ File shippedStylesheetsDir = new File(shippedStylesheetsResource.getFile());
+
+ List<File> stylesheets = outputModule.getStylesheetsByLocation(shippedStylesheetsDir);
+
+ assertNotNull("There should be stylesheets", stylesheets);
+ assertEquals("There should be one stylesheet", 1, stylesheets.size());
+ }
+
+
}