01: /*
02: * Copyright 2004 Outerthought bvba and Schaubroeck nv
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
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
22: DocumentTypeSpecificStyler.StylesheetProvider {
23: private String publishType;
24: private ServiceManager serviceManager;
25: private String stylesheetBasePath;
26:
27: public WikiStylesheetProvider(String publishType,
28: ServiceManager serviceManager) {
29: this .publishType = publishType;
30: this .serviceManager = serviceManager;
31: this .stylesheetBasePath = "daisyskin:document-styling/";
32: }
33:
34: public String getStylesheet(String documentTypeName)
35: throws Exception {
36: return determineStylesheet(stylesheetBasePath + publishType
37: + "/" + documentTypeName + ".xsl");
38: }
39:
40: public String getStylesheetByHint(String styleHint)
41: throws Exception {
42: return determineStylesheet(stylesheetBasePath + publishType
43: + "/" + styleHint);
44: }
45:
46: private String determineStylesheet(String path) throws Exception {
47: org.apache.excalibur.source.SourceResolver sourceResolver = (org.apache.excalibur.source.SourceResolver) serviceManager
48: .lookup(org.apache.excalibur.source.SourceResolver.ROLE);
49: Source source = null;
50: try {
51: // first try the specified path otherwise return default
52: source = sourceResolver.resolveURI(path);
53: if (source.exists()) {
54: return source.getURI();
55: } else {
56: return getDefaultStylesheet();
57: }
58: } finally {
59: if (source != null)
60: sourceResolver.release(source);
61: serviceManager.release(sourceResolver);
62: }
63: }
64:
65: public String getDefaultStylesheet() throws Exception {
66: return "daisyskin:xslt/document-to-" + publishType + ".xsl";
67: }
68: }
|