KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > clipbuilder > html > struts > PreviewAction


1 package org.jahia.clipbuilder.html.struts;
2
3 import org.apache.struts.action.*;
4 import org.jahia.clipbuilder.html.struts.Util.*;
5 import org.jahia.clipbuilder.html.struts.webBrowser.*;
6 import javax.servlet.http.*;
7 import org.jahia.clipbuilder.html.*;
8 import org.jahia.clipbuilder.html.bean.*;
9 import java.util.*;
10 import org.jahia.clipbuilder.html.SessionManager;
11
12 /**
13  * Description of the Class
14  *
15  *@author Tlili Khaled
16  */

17 public class PreviewAction extends AbstractWizardAction {
18     private boolean errorHasOccured = false;
19     private static org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(PreviewAction.class);
20
21
22
23
24     /**
25      * Gets the KeyMethodMap attribute of the BrowseAction object
26      *
27      *@return The KeyMethodMap value
28      */

29     public Map getKeyMethodMap() {
30         Map map = super.getKeyMethodMap();
31         map.put("wizard.preview", "view");
32         map.put("button.done", "done");
33         map.put("button.previous", "previous");
34         map.put("preview.view", "view");
35         map.put("preview.test", "test");
36         return map;
37     }
38
39
40     /**
41      * Gets the FormId attribute of the PreviewAction object
42      *
43      *@return The FormId value
44      */

45     public int getFormId() {
46         return Constants.PREVIEW;
47     }
48
49
50
51
52     /**
53      * Action when the Next button is selected
54      *
55      *@param actionMapping Description of Parameter
56      *@param actionForm Description of Parameter
57      *@param httpServletRequest Description of Parameter
58      *@param httpServletResponse Description of Parameter
59      *@return Description of the Returned Value
60      */

61     public ActionForward done(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
62         PreviewForm previewForm = (PreviewForm) actionForm;
63
64         //test if at leat one url has been recorded
65
ClipperBean bean = SessionManager.getClipperBean(httpServletRequest);
66
67         //Handle error
68
if (bean == null) {
69             logger.error("[Clipper Bean not found]");
70             return actionMapping.findForward("description");
71         }
72         // test that the clipper has url
73
if (bean.isEmpty()) {
74             logger.error("[No url found int the clipper bean]");
75             return actionMapping.findForward("description");
76         }
77
78         //save the bean as an xml document
79
String JavaDoc path = getServlet().getServletContext().getRealPath("/") + getResources(httpServletRequest).getMessage("clippers.repository.path");
80         bean.saveAsXML(path);
81
82         //save to the database
83
//org.jahia.clipbuilder.html.database.hibernate.DatabaseManager.getUniqueInstance().saveClipper(bean);
84

85         logger.debug("[Clipper bean saved as an xml document]");
86         return actionMapping.findForward("manage");
87     }
88
89
90     /**
91      * Description of the Method
92      *
93      *@param actionMapping Description of Parameter
94      *@param actionForm Description of Parameter
95      *@param httpServletRequest Description of Parameter
96      *@param httpServletResponse Description of Parameter
97      *@return Description of the Returned Value
98      */

99     public ActionForward view(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
100         try {
101             logger.debug("[view method called]");
102             super.init(actionMapping, actionForm, httpServletRequest, httpServletResponse);
103             PreviewForm previewForm = (PreviewForm) actionForm;
104             previewForm.setFrom("wizard");
105
106             //Set the selected part
107
WebBrowserForm wb = SessionManager.getWebBrowserForm(httpServletRequest);
108             wb.setShow(Constants.WEB_BROWSER_SHOW_PREVIEW);
109
110         }
111         catch (Exception JavaDoc ex) {
112             ex.printStackTrace();
113         }
114
115         return actionMapping.getInputForward();
116     }
117
118
119     /**
120      * Description of the Method
121      *
122      *@param actionMapping Description of Parameter
123      *@param actionForm Description of Parameter
124      *@param httpServletRequest Description of Parameter
125      *@param httpServletResponse Description of Parameter
126      *@return Description of the Returned Value
127      */

128     public ActionForward init(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
129         try {
130             logger.debug("[init method called]");
131             super.init(actionMapping, actionForm, httpServletRequest, httpServletResponse);
132             PreviewForm previewForm = (PreviewForm) actionForm;
133             previewForm.setFrom("wizard");
134
135             //Set the selected part
136
WebBrowserForm wb = SessionManager.getWebBrowserForm(httpServletRequest);
137             wb.setShow(Constants.WEB_BROWSER_SHOW_PREVIEW);
138
139         }
140         catch (Exception JavaDoc ex) {
141             ex.printStackTrace();
142         }
143
144         return actionMapping.getInputForward();
145     }
146
147
148
149     /**
150      * Description of the Method
151      *
152      *@param actionMapping Description of Parameter
153      *@param actionForm Description of Parameter
154      *@param httpServletRequest Description of Parameter
155      *@param httpServletResponse Description of Parameter
156      *@return Description of the Returned Value
157      */

158     public ActionForward previous(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
159         logger.debug("[ Previous ]");
160         PreviewForm previewForm = (PreviewForm) actionForm;
161         return actionMapping.findForward("testClipper");
162     }
163
164
165     /**
166      * A unit test for JUnit
167      *
168      *@param actionMapping Description of Parameter
169      *@param actionForm Description of Parameter
170      *@param httpServletRequest Description of Parameter
171      *@param httpServletResponse Description of Parameter
172      *@return Description of the Returned Value
173      */

174     public ActionForward test(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
175         logger.debug("[ Test ]");
176         super.init(actionMapping, actionForm, httpServletRequest, httpServletResponse);
177         PreviewForm previewForm = (PreviewForm) actionForm;
178         SessionManager.getWebBrowserForm(httpServletRequest).setShow(Constants.WEB_BROWSER_SHOW_TEST);
179         return actionMapping.getInputForward();
180     }
181
182 }
183
Popular Tags