1 20 21 package com.methodhead.shim; 22 23 import java.io.Serializable ; 24 import javax.servlet.http.HttpServletRequest ; 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 ; 31 import java.util.ArrayList ; 32 import java.util.Iterator ; 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 { 44 45 48 private ShimPolicy getPolicy( 49 ActionMapping mapping ) { 50 51 try { 52 return 53 ( ShimPolicy )Class.forName( mapping.getParameter() ).newInstance(); 54 } 55 catch ( Exception 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 request ) { 65 66 if ( AuthUtil.getUser( request ) == null ) 70 return; 71 72 ShimPolicy policy = getPolicy( mapping ); 73 74 List options = new ArrayList (); 78 options.add( new LabelValueBean( "Select...", "" ) ); 79 80 List modules = ShimUtils.getModules( SiteContext.getContext( request ) ); 81 82 for ( Iterator 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 request ) { 93 94 if ( !StringUtils.isBlank( ( String )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 |