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 import java.io.File ; 39 import org.apache.commons.validator.GenericValidator; 40 41 public final class ModuleForm 42 extends 43 DynaValidatorForm 44 implements 45 Serializable { 46 47 public void reset( 48 ActionMapping mapping, 49 HttpServletRequest request ) { 50 51 set( "fragments", ShimUtils.getHtmlFragmentOptions( request ) ); 52 } 53 54 protected void validateConfigureNavModule( 55 ActionMapping mapping, 56 HttpServletRequest request, 57 ActionErrors errors ) { 58 59 if ( errors.size() == 0 ) { 60 61 if ( "jsp".equals( get( "type" ) ) ) { 65 String jsp = ( String )get( "jsp" ); 66 67 if ( StringUtils.isBlank( jsp ) ) { 68 errors.add( 69 "jsp", new ActionError( "shim.moduleForm.missingJsp" ) ); 70 } 71 else { 72 73 if ( !jsp.endsWith( ".jsp" ) ) 77 errors.add( 78 "jsp", new ActionError( "shim.moduleForm.invalidJsp" ) ); 79 80 File file = 84 new File ( request.getSession().getServletContext().getRealPath( 85 "/WEB-INF/resources/" + 86 SiteContext.getContext( request ).getInt( "id" ) + "/" + 87 get( "jsp" ) ) ); 88 89 if ( !file.exists() || !file.isFile() ) 90 errors.add( 91 "jsp", new ActionError( "shim.moduleForm.jspDoesNotExist" ) ); 92 } 93 } 94 95 else if ( "folding".equals( get( "type" ) ) ) { 99 100 if ( !GenericValidator.isInt( ( String )get( "startlev" ) ) ) 104 errors.add( 105 "startlev", new ActionError( "shim.moduleForm.invalidStartLev" ) ); 106 107 if ( !GenericValidator.isInt( ( String )get( "contextlev" ) ) ) 108 errors.add( 109 "contextlev", 110 new ActionError( "shim.moduleForm.invalidStartLev" ) ); 111 112 if ( !GenericValidator.isInt( ( String )get( "depthlev" ) ) ) 113 errors.add( 114 "depthlev", new ActionError( "shim.moduleForm.invalidStartLev" ) ); 115 116 if ( !GenericValidator.isInt( ( String )get( "toplev" ) ) ) 117 errors.add( 118 "toplev", new ActionError( "shim.moduleForm.invalidTopLev" ) ); 119 120 String s = null; 124 125 s = ( String )get( "header" ); 126 if ( s.length() > 512 ) 127 errors.add( 128 "header", new ActionError( "shim.moduleForm.headerTooLong" ) ); 129 130 s = ( String )get( "link" ); 131 if ( s.length() > 512 ) 132 errors.add( 133 "link", new ActionError( "shim.moduleForm.linkTooLong" ) ); 134 135 s = ( String )get( "curlink" ); 136 if ( s.length() > 512 ) 137 errors.add( 138 "curlink", new ActionError( "shim.moduleForm.curlinkTooLong" ) ); 139 140 s = ( String )get( "footer" ); 141 if ( s.length() > 512 ) 142 errors.add( 143 "footer", new ActionError( "shim.moduleForm.footerTooLong" ) ); 144 } 145 } 146 } 147 148 protected void validateConfigureIncludeModule( 149 ActionMapping mapping, 150 HttpServletRequest request, 151 ActionErrors errors ) { 152 153 if ( errors.size() == 0 ) { 154 155 String jsp = ( String )get( "jsp" ); 156 157 if ( StringUtils.isBlank( jsp ) ) { 158 errors.add( 159 "jsp", new ActionError( "shim.moduleForm.missingJsp" ) ); 160 return; 161 } 162 163 if ( !jsp.endsWith( ".jsp" ) ) 167 errors.add( 168 "jsp", new ActionError( "shim.moduleForm.invalidJsp" ) ); 169 170 else { 174 File file = 175 new File ( request.getSession().getServletContext().getRealPath( 176 "/WEB-INF/resources/" + 177 SiteContext.getContext( request ).getInt( "id" ) + "/" + 178 get( "jsp" ) ) ); 179 180 if ( !file.exists() || !file.isFile() ) 181 errors.add( 182 "jsp", new ActionError( "shim.moduleForm.jspDoesNotExist" ) ); 183 } 184 } 185 } 186 187 public ActionErrors validate( 188 ActionMapping mapping, 189 HttpServletRequest request ) { 190 191 if ( !StringUtils.isBlank( ( String )get( "cancel" ) ) ) 195 return new ActionErrors(); 196 197 ActionErrors errors = super.validate( mapping, request ); 198 199 if ( "/configureNavModule".equals( mapping.getPath() ) ) 200 validateConfigureNavModule( mapping, request, errors ); 201 else if ( "/configureIncludeModule".equals( mapping.getPath() ) ) 202 validateConfigureIncludeModule( mapping, request, errors ); 203 else if ( "/configureTextModule".equals( mapping.getPath() ) ) { 204 } 206 else 207 throw new ShimException( 208 "Unexpected mapping \"" + mapping.getPath() + "\"." ); 209 210 return errors; 211 } 212 } 213 | Popular Tags |