KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > methodhead > reg > RolesForm


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
22 package com.methodhead.reg;
23
24 import java.io.Serializable JavaDoc;
25 import javax.servlet.http.HttpServletRequest JavaDoc;
26
27 import org.apache.struts.action.ActionMapping;
28 import org.apache.struts.action.DynaActionForm;
29 import org.apache.struts.action.ActionErrors;
30 import org.apache.struts.action.ActionError;
31 import org.apache.struts.validator.DynaValidatorForm;
32 import com.methodhead.aikp.AikpForm;
33 import com.methodhead.auth.AuthUtil;
34 import java.util.List JavaDoc;
35 import java.util.ArrayList JavaDoc;
36 import java.util.Iterator JavaDoc;
37 import org.apache.struts.Globals;
38 import org.apache.struts.util.LabelValueBean;
39 import org.apache.struts.util.MessageResources;
40 import com.methodhead.sitecontext.SiteContext;
41 import com.methodhead.util.StrutsUtil;
42 import com.methodhead.util.OperationContext;
43 import org.apache.commons.lang.StringUtils;
44
45 public class RolesForm
46 extends
47   DynaValidatorForm
48 implements
49   Serializable JavaDoc {
50
51   /**
52    * Populates <code>form.roleOptions</code> with roles returned by {@link
53    * RegPolicy#getRoleOptions RegPolicy.getRoleOptions()}, fetching message
54    * resources for labels where possible. Populates
55    * <code>form.siteOptions</code> with options for each site in the database.
56    */

57   public void reset(
58     ActionMapping mapping,
59     HttpServletRequest JavaDoc request ) {
60   
61     RegPolicy policy = ( RegPolicy )StrutsUtil.getPolicy( mapping );
62
63     //
64
// create a op
65
//
66
OperationContext op =
67       new OperationContext(
68         mapping, this, request, null, AuthUtil.getUser( request ) );
69
70     //
71
// get role options
72
//
73
List JavaDoc options = policy.getRoleOptions( op );
74
75     //
76
// look up message resources
77
//
78
MessageResources resources =
79       ( MessageResources )request.getAttribute( Globals.MESSAGES_KEY );
80
81     for ( Iterator JavaDoc iter = options.iterator(); iter.hasNext(); ) {
82       LabelValueBean lv = ( LabelValueBean )iter.next();
83
84       String JavaDoc label = resources.getMessage( lv.getLabel() );
85
86       if ( label != null )
87         lv.setLabel( label );
88     }
89
90     set( "roleOptions", options );
91
92     //
93
// get site context options
94
//
95
options = new ArrayList JavaDoc();
96     options.add( new LabelValueBean( "Select...", "" ) );
97
98     List JavaDoc siteContexts = SiteContext.loadAll();
99
100     for ( Iterator JavaDoc iter = siteContexts.iterator(); iter.hasNext(); ) {
101       SiteContext sc = ( SiteContext )iter.next();
102
103       String JavaDoc label = ( String JavaDoc )sc.getDomains().get( 0 );
104       if ( !StringUtils.isBlank( sc.getString( "path" ) ) )
105         label += "/" + sc.getString( "path" );
106
107       options.add(
108         new LabelValueBean( label, "" + sc.getInt( "id" ) ) );
109     }
110
111     set( "siteOptions", options );
112   }
113
114   /**
115    * Overrides default to bypass validation if cancel was clicked.
116    */

117   public ActionErrors validate(
118     ActionMapping mapping,
119     HttpServletRequest JavaDoc request ) {
120
121     //
122
// no errors if we're cancelling
123
//
124
if ( !StringUtils.isBlank( ( String JavaDoc )get( "cancel" ) ) ) {
125       return new ActionErrors();
126     }
127
128     return super.validate( mapping, request );
129   }
130 }
131
Popular Tags