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.Arrays ; 33 import java.io.File ; 34 import org.apache.struts.util.LabelValueBean; 35 import com.methodhead.util.Comparators; 36 import com.methodhead.sitecontext.SiteContext; 37 import com.methodhead.auth.AuthUtil; 38 39 public final class EditorForm 40 extends 41 DynaValidatorForm 42 implements 43 Serializable { 44 45 48 protected void getPathOptions( 49 List options, 50 String path, 51 File dir ) { 52 53 if ( path == null ) 57 options.add( new LabelValueBean( "/", "" ) ); 58 else if ( "".equals( path ) ) 59 options.add( new LabelValueBean( "/" + dir.getName(), dir.getName() ) ); 60 else 61 options.add( new LabelValueBean( 62 "/" + path + "/" + dir.getName(), path + "/" + dir.getName() ) ); 63 64 65 File [] files = dir.listFiles(); 66 if ( files == null ) 67 throw new ShimException( "Couldn't list files for \"" + dir + "\"" ); 68 69 Arrays.sort( files, Comparators.fileComparator() ); 70 71 for ( int i = 0; i < files.length; i++ ) { 72 if ( files[ i ].isDirectory() ) { 73 if ( "thumbs".equals( files[ i ].getName() ) ) 74 continue; 75 76 if ( path == null ) 77 getPathOptions( options, "", files[ i ] ); 78 else if ( "".equals( path ) ) 79 getPathOptions( options, dir.getName(), files[ i ] ); 80 else 81 getPathOptions( options, path + "/" + dir.getName(), files[ i ] ); 82 } 83 } 84 } 85 86 public void reset( 87 ActionMapping mapping, 88 HttpServletRequest request ) { 89 90 if ( AuthUtil.getUser( request ) == null ) 94 return; 95 96 SiteContext siteContext = SiteContext.getContext( request ); 100 101 File dir = 102 new File ( 103 request.getSession().getServletContext().getRealPath( 104 "/" + siteContext.getInt( "id" ) ) ); 105 106 List options = new ArrayList (); 110 getPathOptions( options, null, dir ); 111 set( "paths", options ); 112 } 113 114 public ActionErrors validate( 115 ActionMapping mapping, 116 HttpServletRequest request ) { 117 118 return super.validate( mapping, request ); 119 } 120 } 121 | Popular Tags |