1 20 21 22 package com.methodhead.reg; 23 24 import java.io.Serializable ; 25 import javax.servlet.http.HttpServletRequest ; 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 ; 35 import java.util.ArrayList ; 36 import java.util.Iterator ; 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 { 50 51 57 public void reset( 58 ActionMapping mapping, 59 HttpServletRequest request ) { 60 61 RegPolicy policy = ( RegPolicy )StrutsUtil.getPolicy( mapping ); 62 63 OperationContext op = 67 new OperationContext( 68 mapping, this, request, null, AuthUtil.getUser( request ) ); 69 70 List options = policy.getRoleOptions( op ); 74 75 MessageResources resources = 79 ( MessageResources )request.getAttribute( Globals.MESSAGES_KEY ); 80 81 for ( Iterator iter = options.iterator(); iter.hasNext(); ) { 82 LabelValueBean lv = ( LabelValueBean )iter.next(); 83 84 String label = resources.getMessage( lv.getLabel() ); 85 86 if ( label != null ) 87 lv.setLabel( label ); 88 } 89 90 set( "roleOptions", options ); 91 92 options = new ArrayList (); 96 options.add( new LabelValueBean( "Select...", "" ) ); 97 98 List siteContexts = SiteContext.loadAll(); 99 100 for ( Iterator iter = siteContexts.iterator(); iter.hasNext(); ) { 101 SiteContext sc = ( SiteContext )iter.next(); 102 103 String label = ( String )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 117 public ActionErrors validate( 118 ActionMapping mapping, 119 HttpServletRequest request ) { 120 121 if ( !StringUtils.isBlank( ( String )get( "cancel" ) ) ) { 125 return new ActionErrors(); 126 } 127 128 return super.validate( mapping, request ); 129 } 130 } 131 | Popular Tags |