KickJava   Java API By Example, From Geeks To Geeks.

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


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.FormHelper;
20 import org.outerj.daisy.frontend.components.userregistrar.UserRegistrar;
21 import org.outerj.daisy.repository.Repository;
22 import org.apache.cocoon.components.flow.apples.StatelessAppleController;
23 import org.apache.cocoon.components.flow.apples.AppleRequest;
24 import org.apache.cocoon.components.flow.apples.AppleResponse;
25 import org.apache.cocoon.forms.formmodel.Form;
26 import org.apache.cocoon.forms.FormContext;
27 import org.apache.cocoon.environment.Request;
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.Locale JavaDoc;
33 import java.util.Map JavaDoc;
34 import java.util.HashMap JavaDoc;
35
36 public class LoginReminderApple extends AbstractDaisyApple implements StatelessAppleController, Serviceable {
37     private ServiceManager serviceManager;
38
39     public void service(ServiceManager serviceManager) throws ServiceException {
40         this.serviceManager = serviceManager;
41     }
42
43     protected void processInternal(AppleRequest appleRequest, AppleResponse appleResponse) throws Exception JavaDoc {
44         Form form = FormHelper.createForm(serviceManager, "resources/form/loginreminder_definition.xml");
45         Request request = appleRequest.getCocoonRequest();
46         Repository repository = WikiHelper.getRepository(appleRequest.getCocoonRequest(), serviceManager);
47         Locale JavaDoc locale = WikiHelper.getLocale(appleRequest.getCocoonRequest());
48
49         Map JavaDoc viewData = new HashMap JavaDoc();
50         viewData.put("pageContext", new PageContext(getMountPoint(), repository, getLayoutType(), getSkin(), SkinConfHelper.getGlobalSkinConf(serviceManager), getContext()));
51         viewData.put("locale", locale);
52
53         if (request.getMethod().equals("GET")) {
54             viewData.put("CocoonFormsInstance", form);
55             viewData.put("submitPath", getMountPoint() + "/loginReminder");
56             appleResponse.sendPage("Form-loginreminder-Pipe", viewData);
57         } else if (request.getMethod().equals("POST")) {
58             // handle a form submit
59
boolean endProcessing = form.process(new FormContext(appleRequest.getCocoonRequest(), locale));
60
61             if (!endProcessing) {
62                 viewData.put("CocoonFormsInstance", form);
63                 viewData.put("submitPath", getMountPoint() + "/loginReminder");
64                 appleResponse.sendPage("Form-loginreminder-Pipe", viewData);
65             } else {
66                 String JavaDoc email = (String JavaDoc)form.getChild("email").getValue();
67                 UserRegistrar userRegistrar = (UserRegistrar)serviceManager.lookup(UserRegistrar.ROLE);
68                 String JavaDoc server = RequestUtil.getServer(request);
69                 userRegistrar.sendLoginsReminder(email, server, getMountPoint(), locale);
70                 appleResponse.sendPage("Message-loginremindersuccess-Pipe", viewData);
71             }
72         }
73     }
74
75 }
Popular Tags