001: /*
002: * Copyright 2005-2006 The Kuali Foundation.
003: *
004: *
005: * Licensed under the Educational Community License, Version 1.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.opensource.org/licenses/ecl1.php
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package edu.iu.uis.eden.help.web;
018:
019: import java.util.ArrayList;
020: import java.util.List;
021:
022: import javax.servlet.http.HttpServletRequest;
023: import javax.servlet.http.HttpServletResponse;
024:
025: import org.apache.struts.action.ActionForm;
026: import org.apache.struts.action.ActionForward;
027: import org.apache.struts.action.ActionMapping;
028: import org.apache.struts.action.ActionMessage;
029: import org.apache.struts.action.ActionMessages;
030:
031: import edu.iu.uis.eden.EdenConstants;
032: import edu.iu.uis.eden.KEWServiceLocator;
033: import edu.iu.uis.eden.export.ExportDataSet;
034: import edu.iu.uis.eden.export.ExportFormat;
035: import edu.iu.uis.eden.help.HelpEntry;
036: import edu.iu.uis.eden.help.HelpService;
037: import edu.iu.uis.eden.web.WorkflowAction;
038: import edu.iu.uis.eden.web.session.UserSession;
039:
040: /**
041: * Struts action for interfacing with the Help system.
042: *
043: * @see HelpService
044: * @see HelpEntry
045: *
046: * @author xqi
047: * @author shenl
048: */
049: public class HelpAction extends WorkflowAction {
050: private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger
051: .getLogger(HelpAction.class);
052:
053: public ActionForward start(ActionMapping mapping, ActionForm form,
054: HttpServletRequest request, HttpServletResponse response)
055: throws Exception {
056: return mapping.findForward("basic");
057: }
058:
059: public ActionMessages establishRequiredState(
060: HttpServletRequest request, ActionForm form)
061: throws Exception {
062: return null;
063: }
064:
065: public ActionForward save(ActionMapping mapping, ActionForm form,
066: HttpServletRequest request, HttpServletResponse response)
067: throws Exception {
068: HelpForm helpForm = (HelpForm) form;
069: HelpEntry helpEntry = helpForm.getHelpEntry();
070: getHelpService().save(helpEntry);
071: ActionMessages messages = new ActionMessages();
072: messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
073: "helpentry.saved"));
074: saveMessages(request, messages);
075: return mapping.findForward("summary");
076: }
077:
078: public ActionForward delete(ActionMapping mapping, ActionForm form,
079: HttpServletRequest request, HttpServletResponse response)
080: throws Exception {
081: HelpForm helpForm = (HelpForm) form;
082: HelpEntry helpEntry = helpForm.getHelpEntry();
083: LOG.info(helpEntry.getHelpName());
084: getHelpService().delete(helpEntry);
085: helpForm.setShowDelete("no");
086: ActionMessages messages = new ActionMessages();
087: messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
088: "helpentry.deleted"));
089: saveMessages(request, messages);
090: return mapping.findForward("delete");
091: }
092:
093: public ActionForward getSearch(ActionMapping mapping,
094: ActionForm form, HttpServletRequest request,
095: HttpServletResponse response) throws Exception {
096: LOG.debug("getSearch");
097: UserSession uSession = getUserSession(request);
098: HelpForm helpForm = (HelpForm) form;
099: helpForm.setIsAdmin(uSession.isAdmin());
100: return mapping.findForward("getSearch");
101: }
102:
103: public ActionForward search(ActionMapping mapping, ActionForm form,
104: HttpServletRequest request, HttpServletResponse response)
105: throws Exception {
106: HelpForm helpForm = (HelpForm) form;
107: HelpEntry helpEntry = helpForm.getHelpEntry();
108: List searchResults = getHelpService().search(helpEntry);
109:
110: if (searchResults != null && searchResults.size() > 0) {
111: request.setAttribute("reqSearchResults", searchResults);
112: }
113: UserSession uSession = getUserSession(request);
114: helpForm.setIsAdmin(uSession.isAdmin());
115: return mapping.findForward("getSearch");
116: }
117:
118: public ActionForward clearSearch(ActionMapping mapping,
119: ActionForm form, HttpServletRequest request,
120: HttpServletResponse response) throws Exception {
121: HelpForm helpForm = (HelpForm) form;
122: helpForm.getHelpEntry().setHelpId(null);
123: helpForm.getHelpEntry().setHelpName(null);
124: helpForm.getHelpEntry().setHelpText(null);
125: request.setAttribute("reqSearchResults", null);
126: UserSession uSession = getUserSession(request);
127: helpForm.setIsAdmin(uSession.isAdmin());
128: return mapping.findForward("getSearch");
129: }
130:
131: public ActionForward report(ActionMapping mapping, ActionForm form,
132: HttpServletRequest request, HttpServletResponse response)
133: throws Exception {
134: HelpForm helpForm = (HelpForm) form;
135: helpForm.setHelpEntry(getHelpService().findById(
136: new Long(request.getParameter("helpId"))));
137: return mapping.findForward("report");
138: }
139:
140: public ActionForward showEdit(ActionMapping mapping,
141: ActionForm form, HttpServletRequest request,
142: HttpServletResponse response) throws Exception {
143: HelpForm helpForm = (HelpForm) form;
144: if (helpForm.getHelpEntry().getHelpId() == null) {
145: Long helpId = new Long(request.getParameter("helpId"));
146: helpForm.setHelpEntry(getHelpService().findById(helpId));
147: }
148: return mapping.findForward("basic");
149: }
150:
151: public ActionForward showDelete(ActionMapping mapping,
152: ActionForm form, HttpServletRequest request,
153: HttpServletResponse response) throws Exception {
154: HelpForm helpForm = (HelpForm) form;
155: if (helpForm.getHelpEntry().getHelpId() == null) {
156: Long helpId = new Long(request.getParameter("helpId"));
157: helpForm.setHelpEntry(getHelpService().findById(helpId));
158: }
159: UserSession uSession = getUserSession(request);
160: helpForm.setIsAdmin(uSession.isAdmin());
161: return mapping.findForward("delete");
162: }
163:
164: private HelpService getHelpService() {
165: return (HelpService) KEWServiceLocator
166: .getService(KEWServiceLocator.HELP_SERVICE);
167: }
168:
169: public ActionForward getHelpEntry(ActionMapping mapping,
170: ActionForm form, HttpServletRequest request,
171: HttpServletResponse response) throws Exception {
172: HelpForm helpForm = (HelpForm) form;
173: String helpKey = request.getParameter("helpKey");
174: helpForm.setHelpEntry(getHelpService().findByKey(helpKey));
175: helpForm.setShowEdit(EdenConstants.NO_LABEL);
176: return mapping.findForward("popHelp");
177: }
178:
179: /**
180: * TODO implement the help search as a lookupable, rendering this code redundant
181: */
182: public ActionForward export(ActionMapping mapping, ActionForm form,
183: HttpServletRequest request, HttpServletResponse response)
184: throws Exception {
185: HelpForm helpForm = (HelpForm) form;
186: HelpEntry helpEntry = helpForm.getHelpEntry();
187: List searchResults = getHelpService().search(helpEntry);
188: if (searchResults == null) {
189: searchResults = new ArrayList();
190: }
191: ExportDataSet dataSet = new ExportDataSet(ExportFormat.XML);
192: dataSet.getHelp().addAll(searchResults);
193: return exportDataSet(request, dataSet);
194: }
195:
196: }
|