01: /*
02: * This program is free software; you can redistribute it and/or modify
03: * it under the terms of the GNU General Public License as published by
04: * the Free Software Foundation; either version 2 of the License, or
05: * (at your option) any later version.
06: *
07: * This program is distributed in the hope that it will be useful,
08: * but WITHOUT ANY WARRANTY; without even the implied warranty of
09: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10: * GNU Library General Public License for more details.
11: *
12: * You should have received a copy of the GNU General Public License
13: * along with this program; if not, write to the Free Software
14: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15: */
16: package dlog4j.action;
17:
18: import java.sql.SQLException;
19:
20: import javax.servlet.http.HttpServletRequest;
21: import javax.servlet.http.HttpServletResponse;
22:
23: import net.sf.hibernate.HibernateException;
24: import net.sf.hibernate.Session;
25:
26: import org.apache.struts.action.ActionError;
27: import org.apache.struts.action.ActionErrors;
28: import org.apache.struts.action.ActionForm;
29: import org.apache.struts.action.ActionForward;
30: import org.apache.struts.action.ActionMapping;
31:
32: import dlog4j.SiteManager;
33: import dlog4j.formbean.ParamForm;
34: import dlog4j.formbean.SiteForm;
35:
36: /**
37: * 参数设置的Action
38: *
39: * @author Liudong
40: */
41: public class DlogParamAction extends AdminActionBase {
42:
43: /**
44: * 修改参数值
45: * @param mapping
46: * @param form
47: * @param request
48: * @param response
49: * @return
50: * @throws Exception
51: */
52: public ActionForward doUpdateParam(ActionMapping mapping,
53: ActionForm form, HttpServletRequest request,
54: HttpServletResponse response) throws Exception {
55: ActionErrors errors = new ActionErrors();
56: ParamForm param = (ParamForm) form;
57: Session ssn = null;
58: try {
59: ssn = getSession();
60: SiteForm site = SiteManager.getCurrentSite(request);
61: ParamForm pa = (ParamForm) ssn.load(ParamForm.class,
62: new Integer(param.getId()));
63: if (pa != null) {
64: if (!pa.getValue().equals(param.getValue())) {
65: pa.setType(param.getType());
66: pa.setValue(param.getValue());
67: ssn.update(pa);
68: }
69: }
70: } catch (SQLException e) {
71: errors.add("param", new ActionError("database_exception"));
72: } catch (HibernateException e) {
73: errors.add("param", new ActionError("hibernate_exception"));
74: } finally {
75: commitSession(ssn, true);
76: }
77: // Report any errors we have discovered back to the original form
78: if (!errors.isEmpty())
79: saveErrors(request, errors);
80: ActionForward forward = mapping.getInputForward();
81: if (errors.isEmpty())
82: forward.setRedirect(true);
83: return forward;
84: }
85:
86: }
|