KickJava   Java API By Example, From Geeks To Geeks.

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


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.cocoon.xml.SaxBuffer;
19 import org.apache.cocoon.environment.Request;
20 import org.apache.avalon.framework.service.ServiceManager;
21 import org.apache.avalon.framework.context.Context;
22 import org.outerx.daisy.x10Publisher.PublisherRequestDocument;
23 import org.outerj.daisy.publisher.Publisher;
24 import org.outerj.daisy.repository.Repository;
25 import org.outerj.daisy.frontend.components.siteconf.SiteConf;
26 import org.xml.sax.ContentHandler JavaDoc;
27
28 /**
29  * Helper class for making publisher requests in the context of the Daisy Wiki.
30  * The result of the publisher request is pulled through a PreparedDocumentsHandler
31  * to apply document type specific styling, if needed.
32  */

33 public class WikiPublisherHelper {
34     private final Request request;
35     private final Context context;
36     private final ServiceManager serviceManager;
37     private final Repository repository;
38     private final String JavaDoc mountPoint;
39     private final SiteConf siteConf;
40     private final String JavaDoc daisyCocoonPath;
41     private final String JavaDoc skin;
42     private final String JavaDoc layoutType;
43
44     public WikiPublisherHelper(Request request, Context context, ServiceManager serviceManager) throws Exception JavaDoc {
45         this(WikiHelper.getRepository(request, serviceManager), request, context, serviceManager);
46     }
47     
48     public WikiPublisherHelper(Repository repository, Request request, Context context, ServiceManager serviceManager) throws Exception JavaDoc {
49         this.repository = repository;
50         this.request = request;
51         this.context = context;
52         this.serviceManager = serviceManager;
53         this.mountPoint = WikiHelper.getMountPoint(request);
54         this.daisyCocoonPath = WikiHelper.getDaisyCocoonPath(request);
55         this.siteConf = WikiHelper.getSiteConf(request);
56         this.skin = WikiHelper.getSkin(request);
57         this.layoutType = WikiHelper.getLayoutType(request);
58     }
59
60     public PublisherRequestDocument buildPublisherRequest(String JavaDoc pipe, Object JavaDoc params) throws Exception JavaDoc {
61         return PublisherXmlRequestBuilder.loadPublisherRequest(pipe, params, serviceManager, context);
62     }
63
64     public SaxBuffer performPublisherRequest(String JavaDoc pipe, Object JavaDoc params, String JavaDoc publishType) throws Exception JavaDoc {
65         PublisherRequestDocument publisherRequestDocument = buildPublisherRequest(pipe, params);
66         SaxBuffer result = new SaxBuffer();
67         Publisher publisher = (Publisher)repository.getExtension("Publisher");
68         publisher.processRequest(publisherRequestDocument, createPreparedDocumentsHandler(result, publishType));
69         return result;
70     }
71
72     private PreparedDocumentsHandler createPreparedDocumentsHandler(ContentHandler JavaDoc consumer, String JavaDoc publishType) {
73         String JavaDoc basePath = mountPoint + "/" + siteConf.getName() + "/";
74
75         PageContext pageContext = new PageContext(mountPoint, siteConf, repository, layoutType, skin, context);
76         DocumentTypeSpecificStyler.StylesheetProvider stylesheetProvider = new WikiStylesheetProvider(publishType, serviceManager);
77         DocumentTypeSpecificStyler documentTypeSpecificStyler = new DocumentTypeSpecificStyler(publishType, basePath,
78                 daisyCocoonPath, stylesheetProvider, pageContext, repository, context, serviceManager);
79         return new PreparedDocumentsHandler(consumer, request, documentTypeSpecificStyler);
80     }
81 }
82
Popular Tags