KickJava   Java API By Example, From Geeks To Geeks.

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


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.outerj.daisy.frontend.util.AbstractDaisyApple;
19 import org.outerj.daisy.frontend.components.docbasket.DocumentBasket;
20 import org.outerj.daisy.frontend.components.docbasket.DocumentBasketHelper;
21 import org.outerj.daisy.frontend.components.siteconf.SiteConf;
22 import org.outerj.daisy.repository.Repository;
23 import org.apache.cocoon.components.flow.apples.StatelessAppleController;
24 import org.apache.cocoon.components.flow.apples.AppleRequest;
25 import org.apache.cocoon.components.flow.apples.AppleResponse;
26 import org.apache.cocoon.environment.Request;
27 import org.apache.cocoon.xml.SaxBuffer;
28 import org.apache.avalon.framework.service.Serviceable;
29 import org.apache.avalon.framework.service.ServiceManager;
30 import org.apache.avalon.framework.service.ServiceException;
31
32 import java.util.Map JavaDoc;
33 import java.util.HashMap JavaDoc;
34 import java.util.List JavaDoc;
35
36 /**
37  * Apple that lets the user get an aggregated rendering of all documents in their document basket.
38  */

39 public class AggregateDocumentBasketApple extends AbstractDaisyApple implements StatelessAppleController, Serviceable {
40     private ServiceManager serviceManager;
41     private static final int LIMIT_FOR_HTML = 150;
42     private static final int LIMIT_FOR_XSLFO = 50;
43
44     public void service(ServiceManager serviceManager) throws ServiceException {
45         this.serviceManager = serviceManager;
46     }
47
48     protected void processInternal(AppleRequest appleRequest, AppleResponse appleResponse) throws Exception JavaDoc {
49         Request request = appleRequest.getCocoonRequest();
50         SiteConf siteConf = WikiHelper.getSiteConf(request);
51         Repository repository = WikiHelper.getRepository(request, serviceManager);
52         String JavaDoc publishType = appleRequest.getSitemapParameter("publishType");
53
54         DocumentBasket documentBasket = DocumentBasketHelper.getDocumentBasket(request, true);
55
56         // List of entries is retrieved before checking the size, and we then keep working with
57
// this copy of the list, since the basket may be updated (and thus grow) concurrently
58
List JavaDoc entries = documentBasket.getEntries();
59
60         if (publishType.equals("html") && documentBasket.size() > LIMIT_FOR_HTML) {
61             throw new Exception JavaDoc("Aggregation of multiple documents into one HTML page is limited to " + LIMIT_FOR_HTML + " documents.");
62         } else if (publishType.equals("xslfo") && documentBasket.size() > LIMIT_FOR_XSLFO) {
63             throw new Exception JavaDoc("Aggregation of multiple documents into one PDF is limited to " + LIMIT_FOR_XSLFO + " documents.");
64         }
65
66         Map JavaDoc viewData = new HashMap JavaDoc();
67         viewData.put("documentBasketEntries", entries);
68         viewData.put("localeAsString", WikiHelper.getLocaleAsString(request));
69         viewData.put("pageContext", new PageContext(getMountPoint(), siteConf, repository, getLayoutType(), getSkin(), getContext()));
70
71         WikiPublisherHelper publisherHelper = new WikiPublisherHelper(request, getContext(), serviceManager);
72         SaxBuffer pubReqResult = publisherHelper.performPublisherRequest("internal/documentBasket/pubReqForAggregate", viewData, publishType);
73
74         viewData.put("pageXml", pubReqResult);
75
76         appleResponse.sendPage("internal/documentBasket/" + publishType + "-publishAggregate", viewData);
77     }
78
79 }
80
Popular Tags