001: /*
002: * Copyright (C) 2006 Methodhead Software LLC. All rights reserved.
003: *
004: * This file is part of TransferCM.
005: *
006: * TransferCM is free software; you can redistribute it and/or modify it under the
007: * terms of the GNU General Public License as published by the Free Software
008: * Foundation; either version 2 of the License, or (at your option) any later
009: * version.
010: *
011: * TransferCM is distributed in the hope that it will be useful, but WITHOUT ANY
012: * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
013: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
014: * details.
015: *
016: * You should have received a copy of the GNU General Public License along with
017: * TransferCM; if not, write to the Free Software Foundation, Inc., 51 Franklin St,
018: * Fifth Floor, Boston, MA 02110-1301 USA
019: */
020:
021: package com.methodhead.shim;
022:
023: import java.io.Serializable;
024: import javax.servlet.http.HttpServletRequest;
025:
026: import org.apache.struts.action.ActionMapping;
027: import org.apache.struts.action.ActionErrors;
028: import org.apache.struts.action.ActionError;
029: import org.apache.struts.validator.DynaValidatorForm;
030: import java.util.List;
031: import java.util.ArrayList;
032: import java.util.Iterator;
033: import org.apache.struts.util.LabelValueBean;
034: import com.methodhead.sitecontext.SiteContext;
035: import com.methodhead.auth.AuthUtil;
036: import com.methodhead.tree.Tree;
037: import org.apache.commons.lang.StringUtils;
038:
039: public final class PanelForm extends DynaValidatorForm implements
040: Serializable {
041:
042: /**
043: * Instantiates the policy for this action.
044: */
045: private ShimPolicy getPolicy(ActionMapping mapping) {
046:
047: try {
048: return (ShimPolicy) Class.forName(mapping.getParameter())
049: .newInstance();
050: } catch (Exception e) {
051: throw new ShimException(
052: "Unexpected exception while instantiating \""
053: + mapping.getParameter() + "\":"
054: + e.getMessage());
055: }
056: }
057:
058: public void reset(ActionMapping mapping, HttpServletRequest request) {
059:
060: //
061: // don't do anything if no one is logged in; action will forward to login
062: //
063: if (AuthUtil.getUser(request) == null)
064: return;
065:
066: ShimPolicy policy = getPolicy(mapping);
067:
068: //
069: // get page options
070: //
071: List options = new ArrayList();
072: options.add(new LabelValueBean("Select...", ""));
073:
074: List modules = ShimUtils.getModules(SiteContext
075: .getContext(request));
076:
077: for (Iterator iter = modules.iterator(); iter.hasNext();) {
078: Module m = (Module) iter.next();
079: options.add(new LabelValueBean(m.getName(), m.getClass()
080: .getName()));
081: }
082:
083: set("modules", options);
084: }
085:
086: public ActionErrors validate(ActionMapping mapping,
087: HttpServletRequest request) {
088:
089: //
090: // don't do anything if we're cancelling
091: //
092: if (!StringUtils.isBlank((String) get("cancel")))
093: return new ActionErrors();
094:
095: ActionErrors errors = super .validate(mapping, request);
096:
097: if (errors.size() == 0) {
098: }
099:
100: return errors;
101: }
102: }
|