KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > outerj > daisy > books > frontend > PublishStateApple


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.books.frontend;
17
18 import org.outerj.daisy.frontend.util.AbstractDaisyApple;
19 import org.outerj.daisy.frontend.WikiHelper;
20 import org.outerj.daisy.books.publisher.BookPublisher;
21 import org.outerj.daisy.books.store.BookStore;
22 import org.outerj.daisy.books.store.BookInstance;
23 import org.outerj.daisy.books.store.PublicationsInfo;
24 import org.outerj.daisy.repository.Repository;
25 import org.apache.cocoon.components.flow.apples.StatelessAppleController;
26 import org.apache.cocoon.components.flow.apples.AppleRequest;
27 import org.apache.cocoon.components.flow.apples.AppleResponse;
28 import org.apache.cocoon.environment.Request;
29 import org.apache.avalon.framework.service.ServiceManager;
30 import org.apache.avalon.framework.service.ServiceException;
31 import org.apache.avalon.framework.service.Serviceable;
32 import org.apache.avalon.framework.activity.Disposable;
33
34 import java.util.Map JavaDoc;
35 import java.util.HashMap JavaDoc;
36
37 public class PublishStateApple extends AbstractDaisyApple implements StatelessAppleController, Serviceable, Disposable {
38     private ServiceManager serviceManager;
39     private BookPublisher bookPublisher;
40
41     public void service(ServiceManager serviceManager) throws ServiceException {
42         this.serviceManager = serviceManager;
43         this.bookPublisher = (BookPublisher)serviceManager.lookup(BookPublisher.ROLE);
44     }
45
46     public void dispose() {
47         serviceManager.release(bookPublisher);
48     }
49
50     protected void processInternal(AppleRequest appleRequest, AppleResponse appleResponse) throws Exception JavaDoc {
51         Request request = appleRequest.getCocoonRequest();
52         Repository repository = WikiHelper.getRepository(request, serviceManager);
53         if (repository.isInRole("guest") && repository.getActiveRoleIds().length == 1) {
54             throw new Exception JavaDoc("Users in the guest role are not allowed to retrieve book publish state.");
55         }
56
57         String JavaDoc taskId = request.getParameter("taskId");
58         String JavaDoc bookInstanceName = request.getParameter("bookInstanceName");
59
60         Map JavaDoc viewData = new HashMap JavaDoc();
61         viewData.put("taskId", taskId);
62         viewData.put("bookInstanceName", bookInstanceName);
63         viewData.put("mountPoint", getMountPoint());
64
65         String JavaDoc[] taskState = bookPublisher.getTaskState(taskId);
66
67         if (taskState != null) {
68             viewData.put("taskState", taskState);
69         } else {
70             // task does not exist (is finished)
71
BookStore bookStore = (BookStore)repository.getExtension("BookStore");
72             BookInstance bookInstance = bookStore.getBookInstance(bookInstanceName);
73             PublicationsInfo publicationsInfo = bookInstance.getPublicationsInfo();
74             viewData.put("publicationsInfos", publicationsInfo.getInfos());
75         }
76
77         appleResponse.sendPage("PublishTaskStatePipe", viewData);
78     }
79 }
80
Popular Tags