KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > methodhead > shim > PanelForm


1 /*
2  * Copyright (C) 2006 Methodhead Software LLC. All rights reserved.
3  *
4  * This file is part of TransferCM.
5  *
6  * TransferCM is free software; you can redistribute it and/or modify it under the
7  * terms of the GNU General Public License as published by the Free Software
8  * Foundation; either version 2 of the License, or (at your option) any later
9  * version.
10  *
11  * TransferCM is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the GNU General Public License along with
17  * TransferCM; if not, write to the Free Software Foundation, Inc., 51 Franklin St,
18  * Fifth Floor, Boston, MA 02110-1301 USA
19  */

20
21 package com.methodhead.shim;
22
23 import java.io.Serializable JavaDoc;
24 import javax.servlet.http.HttpServletRequest JavaDoc;
25
26 import org.apache.struts.action.ActionMapping;
27 import org.apache.struts.action.ActionErrors;
28 import org.apache.struts.action.ActionError;
29 import org.apache.struts.validator.DynaValidatorForm;
30 import java.util.List JavaDoc;
31 import java.util.ArrayList JavaDoc;
32 import java.util.Iterator JavaDoc;
33 import org.apache.struts.util.LabelValueBean;
34 import com.methodhead.sitecontext.SiteContext;
35 import com.methodhead.auth.AuthUtil;
36 import com.methodhead.tree.Tree;
37 import org.apache.commons.lang.StringUtils;
38
39 public final class PanelForm
40 extends
41   DynaValidatorForm
42 implements
43   Serializable JavaDoc {
44
45   /**
46    * Instantiates the policy for this action.
47    */

48   private ShimPolicy getPolicy(
49     ActionMapping mapping ) {
50
51     try {
52       return
53         ( ShimPolicy )Class.forName( mapping.getParameter() ).newInstance();
54     }
55     catch ( Exception JavaDoc e ) {
56       throw new ShimException(
57         "Unexpected exception while instantiating \"" +
58         mapping.getParameter() +"\":" + e.getMessage() );
59     }
60   }
61
62   public void reset(
63     ActionMapping mapping,
64     HttpServletRequest JavaDoc request ) {
65
66     //
67
// don't do anything if no one is logged in; action will forward to login
68
//
69
if ( AuthUtil.getUser( request ) == null )
70       return;
71
72     ShimPolicy policy = getPolicy( mapping );
73
74     //
75
// get page options
76
//
77
List JavaDoc options = new ArrayList JavaDoc();
78     options.add( new LabelValueBean( "Select...", "" ) );
79
80     List JavaDoc modules = ShimUtils.getModules( SiteContext.getContext( request ) );
81
82     for ( Iterator JavaDoc iter = modules.iterator(); iter.hasNext(); ) {
83       Module m = ( Module )iter.next();
84       options.add( new LabelValueBean( m.getName(), m.getClass().getName() ) );
85     }
86
87     set( "modules", options );
88   }
89
90   public ActionErrors validate(
91     ActionMapping mapping,
92     HttpServletRequest JavaDoc request ) {
93
94     //
95
// don't do anything if we're cancelling
96
//
97
if ( !StringUtils.isBlank( ( String JavaDoc )get( "cancel" ) ) )
98       return new ActionErrors();
99
100     ActionErrors errors = super.validate( mapping, request );
101
102     if ( errors.size() == 0 ) {
103     }
104
105     return errors;
106   }
107 }
108
Popular Tags