1 16 package org.outerj.daisy.frontend; 17 18 import org.apache.avalon.framework.service.ServiceManager; 19 import org.apache.excalibur.source.Source; 20 21 public class WikiStylesheetProvider implements DocumentTypeSpecificStyler.StylesheetProvider { 22 private String publishType; 23 private ServiceManager serviceManager; 24 private String stylesheetBasePath; 25 26 public WikiStylesheetProvider(String publishType, ServiceManager serviceManager) { 27 this.publishType = publishType; 28 this.serviceManager = serviceManager; 29 this.stylesheetBasePath = "daisyskin:document-styling/"; 30 } 31 32 public String getStylesheet(String documentTypeName) throws Exception { 33 return determineStylesheet(stylesheetBasePath + publishType + "/" + documentTypeName + ".xsl"); 34 } 35 36 public String getStylesheetByHint(String styleHint) throws Exception { 37 return determineStylesheet(stylesheetBasePath + publishType + "/" + styleHint); 38 } 39 40 private String determineStylesheet(String path) throws Exception { 41 org.apache.excalibur.source.SourceResolver sourceResolver = (org.apache.excalibur.source.SourceResolver)serviceManager.lookup(org.apache.excalibur.source.SourceResolver.ROLE); 42 Source source = null; 43 try { 44 source = sourceResolver.resolveURI(path); 46 if (source.exists()) { 47 return source.getURI(); 48 } else { 49 return getDefaultStylesheet(); 50 } 51 } finally { 52 if (source != null) 53 sourceResolver.release(source); 54 serviceManager.release(sourceResolver); 55 } 56 } 57 58 public String getDefaultStylesheet() throws Exception { 59 return "daisyskin:xslt/document-to-" + publishType + ".xsl"; 60 } 61 } 62 | Popular Tags |