KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.HttpMethodNotAllowedException;
20 import org.outerj.daisy.frontend.components.siteconf.SiteConf;
21 import org.outerj.daisy.repository.LocaleHelper;
22 import org.outerj.daisy.repository.clientimpl.RemoteRepositoryImpl;
23 import org.outerj.daisy.publisher.Publisher;
24 import org.apache.cocoon.components.flow.apples.StatelessAppleController;
25 import org.apache.cocoon.components.flow.apples.AppleRequest;
26 import org.apache.cocoon.components.flow.apples.AppleResponse;
27 import org.apache.cocoon.environment.Request;
28 import org.apache.cocoon.xml.SaxBuffer;
29 import org.apache.avalon.framework.service.Serviceable;
30 import org.apache.avalon.framework.service.ServiceManager;
31 import org.apache.avalon.framework.service.ServiceException;
32 import org.outerx.daisy.x10Publisher.PublisherRequestDocument;
33
34 import java.util.Map JavaDoc;
35 import java.util.HashMap JavaDoc;
36 import java.util.Locale JavaDoc;
37
38 public class MyCommentsApple extends AbstractDaisyApple implements StatelessAppleController, Serviceable {
39     private ServiceManager serviceManager;
40
41     public void service(ServiceManager serviceManager) throws ServiceException {
42         this.serviceManager = serviceManager;
43     }
44
45     protected void processInternal(AppleRequest appleRequest, AppleResponse appleResponse) throws Exception JavaDoc {
46         Request request = appleRequest.getCocoonRequest();
47
48         RemoteRepositoryImpl repository = (RemoteRepositoryImpl)WikiHelper.getRepository(request, serviceManager);
49         Locale JavaDoc locale = WikiHelper.getLocale(request);
50         SiteConf siteConf = WikiHelper.getSiteConf(request);
51
52         //
53
// Handle actions, if any
54
//
55

56         String JavaDoc action = request.getParameter("action");
57         if (action == null) {
58             // ignore
59
} else if (action.equals("deleteComment")) {
60             if (request.getMethod().equals("POST")) {
61                 long commentId = RequestUtil.getLongParameter(request, "commentId");
62                 long documentId = RequestUtil.getLongParameter(request, "documentId");
63                 long branchId = RequestUtil.getBranchId(request, siteConf.getBranchId(), repository);
64                 long languageId = RequestUtil.getLanguageId(request, siteConf.getLanguageId(), repository);
65                 repository.getCommentManager().deleteComment(documentId, branchId, languageId, commentId);
66             } else {
67                 throw new HttpMethodNotAllowedException(request.getMethod());
68             }
69         } else {
70             throw new Exception JavaDoc("Unsupported action parameter value: \"" + action + "\".");
71         }
72
73         //
74
// Show comments
75
//
76

77         Map JavaDoc viewData = new HashMap JavaDoc();
78         viewData.put("localeAsString", LocaleHelper.getString(locale));
79         viewData.put("pageContext", new PageContext(getMountPoint(), siteConf, repository, getLayoutType(), getSkin(), getContext()));
80
81         PublisherRequestDocument publisherRequestDocument = PublisherXmlRequestBuilder.loadPublisherRequest("mycommentspage_pubreq.xml", viewData, serviceManager, getContext());
82         SaxBuffer publisherResponse = new SaxBuffer();
83         Publisher publisher = (Publisher)repository.getExtension("Publisher");
84         publisher.processRequest(publisherRequestDocument, publisherResponse);
85
86         viewData.put("pageXml", publisherResponse);
87
88         appleResponse.sendPage("MyCommentsPipe", viewData);
89     }
90 }
Popular Tags