1 18 package org.apache.beehive.netui.compiler.model; 19 20 import java.util.List ; 21 import java.util.ArrayList ; 22 23 import org.apache.beehive.netui.compiler.model.schema.struts11.ForwardDocument.Forward; 24 import org.apache.beehive.netui.compiler.model.schema.struts11.SetPropertyDocument.SetProperty; 25 import org.apache.beehive.netui.compiler.JpfLanguageConstants; 26 27 30 public class ForwardModel 31 extends StrutsElementSupport 32 implements JpfLanguageConstants 33 { 34 private static final String JPF_ACTION_FWD_CLASSNAME = PAGEFLOW_PACKAGE + ".config.PageFlowActionForward"; 35 36 private boolean _isNestedReturn = false; 37 private boolean _contextRelative = false; 38 private String _name; private String _path; private boolean _redirect = false; 41 private boolean _externalRedirect = false; 42 private boolean _returnToPage = false; 43 private boolean _returnToAction = false; 44 private String _outputFormBeanType; 45 private String _outputFormBeanMember; 46 private boolean _hasExplicitRedirectValue = false; 47 private List _actionOutputs = null; 48 private boolean _restoreQueryString = false; 49 50 51 protected ForwardModel( StrutsApp parent ) 52 { 53 super( parent ); 54 } 55 56 public ForwardModel( String name, String path, StrutsApp parent ) 57 { 58 super( parent ); 59 _name = name; 60 _path = path; 61 } 62 63 public void writeToXMLBean( Forward xb ) 64 { 65 assert _name != null; 66 67 xb.setName( _name ); 68 69 if ( xb.getPath() == null ) 70 { 71 xb.setPath( _path == null ? "" : _path ); 72 } 73 74 if ( xb.getContextRelative() == null && _contextRelative ) 75 { 76 xb.setContextRelative( Forward.ContextRelative.TRUE ); 77 } 78 79 if ( xb.getRedirect() == null && _redirect ) 80 { 81 xb.setRedirect( Forward.Redirect.TRUE ); 82 } 83 84 if ( _externalRedirect ) addSetProperty( xb, "externalRedirect", "true" ); 89 90 if ( _returnToPage ) addSetProperty( xb, "returnToPage", "true" ); 95 96 if ( _returnToAction ) addSetProperty( xb, "returnToAction", "true" ); 101 102 if ( _hasExplicitRedirectValue ) addSetProperty( xb, "hasExplicitRedirectValue", "true" ); 103 104 if ( _restoreQueryString ) addSetProperty( xb, "restoreQueryString", "true" ); 105 106 if ( _actionOutputs != null && _actionOutputs.size() > 0 ) 107 { 108 if ( xb.getClassName() == null ) xb.setClassName( JPF_ACTION_FWD_CLASSNAME ); 109 110 int n = _actionOutputs.size(); 111 SetProperty countProp = xb.addNewSetProperty(); 112 countProp.setProperty( "actionOutputCount" ); 113 countProp.setValue( Integer.toString( n ) ); 114 115 for ( int i = 0; i < n; ++i ) 116 { 117 ActionOutputModel pi = ( ActionOutputModel ) _actionOutputs.get( i ); 118 SetProperty prop = xb.addNewSetProperty(); 119 prop.setProperty( "actionOutput" + i ); 120 prop.setValue( pi.getType() + '|' + pi.getNullable() + '|' + pi.getName() ); 121 } 122 } 123 124 if ( _isNestedReturn ) addSetProperty( xb, "nestedReturn", "true" ); 129 if ( _outputFormBeanType != null ) addSetProperty( xb, "returnFormType", _outputFormBeanType ); 130 if ( _outputFormBeanMember != null ) addSetProperty( xb, "returnFormMember", _outputFormBeanMember ); 131 132 addComment( xb ); 133 } 134 135 public boolean isReturnToPage() 136 { 137 return _returnToPage; 138 } 139 140 public void setReturnToPage( boolean returnToPage ) 141 { 142 _returnToPage = returnToPage; 143 } 144 145 public boolean isReturnToAction() 146 { 147 return _returnToAction; 148 } 149 150 public void setReturnToAction( boolean returnToAction ) 151 { 152 _returnToAction = returnToAction; 153 } 154 155 public void setIsNestedReturn( boolean nestedReturn ) 156 { 157 _isNestedReturn = nestedReturn; 158 } 159 160 public String getOutputFormBeanType() 161 { 162 return _outputFormBeanType; 163 } 164 165 public void setOutputFormBeanType( String outputFormBeanType ) 166 { 167 _outputFormBeanType = outputFormBeanType; 168 } 169 170 public String getOutputFormBeanMember() 171 { 172 return _outputFormBeanMember; 173 } 174 175 public void setOutputFormBeanMember( String outputFormBeanMember ) 176 { 177 _outputFormBeanMember = outputFormBeanMember; 178 } 179 180 public boolean getContextRelative() 181 { 182 return _contextRelative; 183 } 184 185 public void setContextRelative( boolean contextRelative ) 186 { 187 _contextRelative = contextRelative; 188 } 189 190 public String getName() 191 { 192 return _name; 193 } 194 195 public void setName( String name ) 196 { 197 _name = name; 198 } 199 200 public String getPath() 201 { 202 return _path; 203 } 204 205 public void setPath( String path ) 206 { 207 _path = path; 208 } 209 210 public boolean isRedirect() 211 { 212 return _redirect; 213 } 214 215 public void setRedirect( boolean redirect ) 216 { 217 _redirect = redirect; 218 _hasExplicitRedirectValue = redirect; 219 } 220 221 public boolean isExternalRedirect() 222 { 223 return _externalRedirect; 224 } 225 226 public void setExternalRedirect( boolean externalRedirect ) 227 { 228 _externalRedirect = externalRedirect; 229 if ( externalRedirect ) setRedirect( externalRedirect ); 230 } 231 232 public boolean isRestoreQueryString() 233 { 234 return _restoreQueryString; 235 } 236 237 public void setRestoreQueryString( boolean restore ) 238 { 239 _restoreQueryString = restore; 240 } 241 242 246 public final boolean isPageForward() 247 { 248 return forwardsToPage(); 249 } 250 251 public boolean forwardsToPage() 252 { 253 return ! _path.endsWith( ".do" ) && ! _path.endsWith( ".jpf" ); } 255 256 public boolean forwardsToAction() 257 { 258 return _path.endsWith( ".do" ); } 260 261 public final boolean forwardsToPageFlow() 262 { 263 return _path.endsWith( ".jpf" ); } 265 266 public String getPageName() 267 { 268 assert forwardsToPage() : "getPageName() called for non-page " + _path; 270 int slash = _path.lastIndexOf( '/' ); return slash != -1 ? _path.substring( slash + 1 ) : _path; 272 } 273 274 public String getActionName() 275 { 276 assert forwardsToAction() : "getActionName() called for non-action" + _path; 278 int index = _path.indexOf( ".do" ); assert index != -1; 280 return _path.substring( 0, index ); 281 } 282 283 public void addActionOutput( ActionOutputModel actionOutput ) 284 { 285 if ( _actionOutputs == null ) _actionOutputs = new ArrayList (); 286 _actionOutputs.add( actionOutput ); 287 } 288 289 public boolean isNestedReturn() 290 { 291 return _isNestedReturn; 292 } 293 294 private static void addSetProperty( Forward xb, String propertyName, String propertyValue ) 295 { 296 SetProperty prop = xb.addNewSetProperty(); 297 prop.setProperty( propertyName ); 298 prop.setValue( propertyValue ); 299 if ( xb.getClassName() == null ) xb.setClassName( JPF_ACTION_FWD_CLASSNAME ); 300 } 301 } 302 | Popular Tags |