KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > outerj > daisy > frontend > WikiStylesheetProvider


1 /*
2  * Copyright 2004 Outerthought bvba and Schaubroeck nv
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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 DocumentTypeSpecificStyler.StylesheetProvider {
22     private String JavaDoc publishType;
23     private ServiceManager serviceManager;
24     private String JavaDoc stylesheetBasePath;
25
26     public WikiStylesheetProvider(String JavaDoc publishType, ServiceManager serviceManager) {
27         this.publishType = publishType;
28         this.serviceManager = serviceManager;
29         this.stylesheetBasePath = "daisyskin:document-styling/";
30     }
31
32     public String JavaDoc getStylesheet(String JavaDoc documentTypeName) throws Exception JavaDoc {
33         return determineStylesheet(stylesheetBasePath + publishType + "/" + documentTypeName + ".xsl");
34     }
35
36     public String JavaDoc getStylesheetByHint(String JavaDoc styleHint) throws Exception JavaDoc {
37         return determineStylesheet(stylesheetBasePath + publishType + "/" + styleHint);
38     }
39
40     private String JavaDoc determineStylesheet(String JavaDoc path) throws Exception JavaDoc {
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             // first try the specified path otherwise return default
45
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 JavaDoc getDefaultStylesheet() throws Exception JavaDoc {
59         return "daisyskin:xslt/document-to-" + publishType + ".xsl";
60     }
61 }
62
Popular Tags