+
+
+ @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);
+ }