KickJava   Java API By Example, From Geeks To Geeks.

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


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.siteconf.SitesManager;
20 import org.outerj.daisy.frontend.components.siteconf.SiteConf;
21 import org.outerj.daisy.repository.Repository;
22 import org.outerj.daisy.repository.VariantKey;
23 import org.outerj.daisy.repository.acl.AclPermission;
24 import org.apache.cocoon.components.flow.apples.AppleRequest;
25 import org.apache.cocoon.components.flow.apples.AppleResponse;
26 import org.apache.cocoon.components.flow.apples.StatelessAppleController;
27 import org.apache.avalon.framework.service.Serviceable;
28 import org.apache.avalon.framework.service.ServiceManager;
29 import org.apache.avalon.framework.service.ServiceException;
30 import org.apache.avalon.framework.activity.Disposable;
31
32 import java.util.*;
33
34 public class IndexPageApple extends AbstractDaisyApple implements StatelessAppleController, Serviceable, Disposable {
35     private ServiceManager serviceManager;
36     private SitesManager sitesManager;
37
38     public void service(ServiceManager serviceManager) throws ServiceException {
39         this.serviceManager = serviceManager;
40         this.sitesManager = (SitesManager)serviceManager.lookup(SitesManager.ROLE);
41     }
42
43     public void dispose() {
44         if (sitesManager != null)
45             serviceManager.release(sitesManager);
46     }
47
48     protected void processInternal(AppleRequest appleRequest, AppleResponse appleResponse) throws Exception JavaDoc {
49         Repository repository = WikiHelper.getRepository(appleRequest.getCocoonRequest(), serviceManager);
50
51         // create array containg home page document IDs
52
Collection siteConfs = sitesManager.getSiteConfs();
53         List homePageDocKeys = new ArrayList(siteConfs.size());
54         Iterator siteConfsIt = siteConfs.iterator();
55         while (siteConfsIt.hasNext()) {
56             SiteConf siteConf = (SiteConf)siteConfsIt.next();
57             if (siteConf.getHomePageDocId() != -1)
58                 homePageDocKeys.add(new VariantKey(siteConf.getHomePageDocId(), siteConf.getBranchId(), siteConf.getLanguageId()));
59         }
60
61         WikiVersionMode versionMode = WikiHelper.getVersionMode(appleRequest.getCocoonRequest());
62         AclPermission filterPermission = versionMode == WikiVersionMode.LAST ? AclPermission.READ : AclPermission.READ_LIVE;
63
64         // filter them
65
VariantKey[] filteredHomePageDocKeys = repository.getAccessManager().filterDocuments((VariantKey[])homePageDocKeys.toArray(new VariantKey[homePageDocKeys.size()]), filterPermission);
66         Arrays.sort(filteredHomePageDocKeys);
67
68         // create filtered site confs collection
69
ArrayList filteredSiteConfs = new ArrayList(siteConfs.size());
70         siteConfsIt = siteConfs.iterator();
71         while (siteConfsIt.hasNext()) {
72             SiteConf siteConf = (SiteConf)siteConfsIt.next();
73             if (siteConf.getHomePageDocId() == -1
74                     || (Arrays.binarySearch(filteredHomePageDocKeys, new VariantKey(siteConf.getHomePageDocId(), siteConf.getBranchId(), siteConf.getLanguageId())) >= 0)) {
75                 filteredSiteConfs.add(siteConf);
76             }
77         }
78
79         Map viewData = new HashMap();
80         viewData.put("sites", filteredSiteConfs);
81         viewData.put("pageContext", new PageContext(getMountPoint(), repository, getLayoutType(), getSkin(), SkinConfHelper.getGlobalSkinConf(serviceManager), getContext()));
82
83         appleResponse.sendPage("IndexPagePipe", viewData);
84     }
85 }
86
Popular Tags