com.bowstreet.builders.webapp.foundation
Class BaseWebAppControlBuilder

java.lang.Object
  extended by com.bowstreet.builders.webapp.foundation.BaseWebAppControlBuilder
All Implemented Interfaces:
WebAppControlBuilder

public class BaseWebAppControlBuilder
extends java.lang.Object
implements WebAppControlBuilder

Base class typical WebApp control builders will want to override.


Field Summary
protected  BuilderCall builderCall
           
protected  BuilderInputs builderInputs
           
protected static java.lang.String DOJO_ADDED
           
protected static java.lang.String DOJO_TYPE
           
protected  GenContext genContext
           
protected  com.bowstreet.webapp.PageContentInserter pageContentInserter
           
protected  PageLocation pageLocation
           
protected  java.util.Collection pageLocationEntries
           
protected static boolean removeDojoType
           
protected static java.lang.String TRUE
           
protected  WebApp webApp
           
 
Constructor Summary
BaseWebAppControlBuilder()
           
 
Method Summary
protected  void addCommonHTMLAttributes(IXml element)
          Used to set common HTML elements in an automated fashion.
 boolean containsSpecialCharacters(java.lang.String candidate)
          Method to determine if a string input contains special characters that may need to be escaped to avoid a JSP compile issue.
 boolean deferSelfFirst()
          This determines whether or not this builder will defer itself before calling handleConstruction.
 void doBuilderCall(GenContext genContext, WebApp webApp, BuilderCall builderCall, BuilderInputs builderInputs, PageLocation pageLocation)
          doBuilderCall - WebApp builders do their regen work here, getting inputs from builderInputs and adding/modifying elements in the WebApp.
 java.lang.String generateIndirectReference(java.lang.String input, java.lang.String runtimeType)
          Create Java source expression for a builder input which can be an indirect reference, for example: ${Variables/strVar} is resolved to: webAppAccess.getVariables().getString("strVar") If "input" is a literal (does not use ${ syntax) it is returned as-is
 java.lang.String generatePageIndirectReference(java.lang.String input, java.lang.String runtimeType)
          Transform a ${...} reference to an equivalent JSP expression.
protected  BuilderCall getBuilderCall()
          Return BuilderCall object for this builder invocation.
protected  BuilderInputs getBuilderInputs()
          Return the builder inputs specified in builder call
protected  com.bowstreet.webapp.structures.PageDomainObject getDomainObjectForBuilderCall(java.lang.String pageName, java.lang.String builderId, IXml node)
          Finds a domain object that pertains to ther curent builder call.
protected  GenContext getGenContext()
          Return the GenContext object for this builder invocation.
 java.lang.String getHtmlSafePageIndirectInput(java.lang.String inputName, java.lang.String defaultValue)
          Transform a builder input which might contain a ${...} reference to an equivalent JSP expression.
 java.lang.String getIndirectInput(java.lang.String inputName, java.lang.String defaultValue, java.lang.String type)
          Transform a builder input which might contain a ${...} reference to equivalent Java code.
 java.lang.String getIndirectStringInput(java.lang.String inputName, java.lang.String defaultValue)
          Transform a builder input which might contain a ${...} reference to equivalent Java code.
protected  java.lang.String getIndirectText(java.lang.String inputName, java.lang.String defaultValue)
          Transform a builder input which might contain a ${...} reference to an equivalent Java code.
 java.lang.String getIndirectXmlInput(java.lang.String inputName, java.lang.String defaultValue)
          Transform a builder input which might contain a ${...} reference to equivalent Java code.
static java.lang.String getJavaFromJSP(java.lang.String inp)
          Extract the Java code from inside a JSP expression.
 java.lang.String getPageIndirectInput(java.lang.String inputName, java.lang.String defaultValue)
          Transform a builder input which might contain a ${...} reference to an equivalent JSP expression.
protected  java.lang.String getPageIndirectText(java.lang.String inputName, java.lang.String defaultValue)
          Transform a builder input which might contain a ${...} reference to an equivalent JSP expression.
protected  java.util.Collection getPageLocationEntries()
           
protected  java.lang.String getPreferredPhase()
          Get preferred phase, to run the handlePage and handleControl methods in; Return PHASE_POSTCONSTRUCTION, PHASE_MODIFICATION or PHASE_VALIDATION.
protected  WebApp getWebApp()
          Return the top-level object under contstruction.
protected  void handleConstruction()
          Called once per invocation, to handle non-page/control work in the contsruction phase.
protected  void handleControl(Page page, IXml element)
          Called for each location needing modification.
protected  void handleModification()
          Called once per invocation, to handle non-page/control work in the modification phase.
protected  void handlePage(Page page)
          Called for each page needing modification.
protected  void handlePostConstruction()
          Called once per invocation, to handle non-page/control work in the post-contsruction phase.
protected  void handleValidation()
          Called once per invocation, to handle validation and other operations which must happen very late.
protected  void preprocessControl(Page page, IXml element)
          Hook for base classes to pre-process an element before it is passed off to handleControl().
protected  void preprocessElement(IXml element)
          If a control builder is being applied then remove the existing dojoType, if one of our builder has added it.
protected  void processCommonInputs(IXml element)
          Common input handling support - called just before handleControl.
static void replaceElement(IXml element, IXml newNode)
          Convenience routine: replace element with new node, if possible.
static void replaceElement(IXml element, java.util.List newNodes)
          Convenience routine: replace element with new nodes, if possible.
 java.lang.String resolvePageIndirectReference(java.lang.String input, java.lang.String runtimeType)
          Transform a ${...} reference to an equivalent JSP expression.
static boolean tagDisplaysChildContent(java.lang.String tagName)
          Returns false if the specified HTML tag isn't allowed to have child elements (e.g., <INPUT>) or won't directly display contained content (e.g., <SELECT>)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

builderCall

protected BuilderCall builderCall

builderInputs

protected BuilderInputs builderInputs

DOJO_ADDED

protected static final java.lang.String DOJO_ADDED
See Also:
Constant Field Values

DOJO_TYPE

protected static final java.lang.String DOJO_TYPE
See Also:
Constant Field Values

genContext

protected GenContext genContext

pageContentInserter

protected com.bowstreet.webapp.PageContentInserter pageContentInserter

pageLocation

protected PageLocation pageLocation

pageLocationEntries

protected java.util.Collection pageLocationEntries

removeDojoType

protected static boolean removeDojoType

TRUE

protected static final java.lang.String TRUE
See Also:
Constant Field Values

webApp

protected WebApp webApp
Constructor Detail

BaseWebAppControlBuilder

public BaseWebAppControlBuilder()
Method Detail

addCommonHTMLAttributes

protected void addCommonHTMLAttributes(IXml element)
Used to set common HTML elements in an automated fashion. Looks as the XML valued input HTMLAttributes, and sets matching attributes on the element.


containsSpecialCharacters

public boolean containsSpecialCharacters(java.lang.String candidate)
Method to determine if a string input contains special characters that may need to be escaped to avoid a JSP compile issue. We only worry about detecting these special characters in constant strings. That is, we ignore indirect references assuming that what ever generates the associated Java code will do the right thing with respect to special characters. We also ignore JSP code fragments since those have already been turned into code before we got a chance to look at them.

Parameters:
candidate - The string to check for special characters.
Returns:
Returns <@code>true if the string contains a double quote or a back-slash that may need to be escaped. Returns <@code>false otherwise.

deferSelfFirst

public boolean deferSelfFirst()
This determines whether or not this builder will defer itself before calling handleConstruction. If you've extended this class for your builder, AND you invoke some other builder (like, say, AttributeSetter) in handleConstruction AND you need to take over the DesignViewFixing, then override this method and return true. Otherwise, you'll be behind the builder you called in the Post-Construction list and therefore won't be the DesignViewFixer for this element.

Returns:
true to be deferred before invoking handleConstruction.

doBuilderCall

public void doBuilderCall(GenContext genContext,
                          WebApp webApp,
                          BuilderCall builderCall,
                          BuilderInputs builderInputs,
                          PageLocation pageLocation)
doBuilderCall - WebApp builders do their regen work here, getting inputs from builderInputs and adding/modifying elements in the WebApp. This is generally not overriden by derived classes - see handlePage, handleControl and handleConstruction.

Specified by:
doBuilderCall in interface WebAppControlBuilder
Parameters:
genContext - The GenContext for this regen
webApp - The WebApp under construction
builderCall - Use this to set errors, get BuilderDef, etc.
builderInputs - The inputs for this builder call
pageLocation - A PageLocation instance describing where to insert the control

generateIndirectReference

public java.lang.String generateIndirectReference(java.lang.String input,
                                                  java.lang.String runtimeType)
Create Java source expression for a builder input which can be an indirect reference, for example: ${Variables/strVar} is resolved to: webAppAccess.getVariables().getString("strVar") If "input" is a literal (does not use ${ syntax) it is returned as-is

Parameters:
input - The indirect literal or reference, e.g. ${Variables/foo}
runtimeType - The runtime type expected (must be one of the Variable.TYPE_ values)
Returns:
The Java expression, if input is a reference, or input unmodified if not.

generatePageIndirectReference

public java.lang.String generatePageIndirectReference(java.lang.String input,
                                                      java.lang.String runtimeType)
Transform a ${...} reference to an equivalent JSP expression.

Parameters:
input - The indirect literal or reference, e.g. ${Variables/foo}
runtimeType - The runtime type expected (must be one of the Variable.TYPE_ values)
Returns:
The JSP expression, if input is a reference, or input unmodified if not.

getBuilderCall

protected BuilderCall getBuilderCall()
Return BuilderCall object for this builder invocation.

Returns:
The current BuilderCall

getBuilderInputs

protected BuilderInputs getBuilderInputs()
Return the builder inputs specified in builder call

Returns:
The inputs to this builder call

getDomainObjectForBuilderCall

protected com.bowstreet.webapp.structures.PageDomainObject getDomainObjectForBuilderCall(java.lang.String pageName,
                                                                                         java.lang.String builderId,
                                                                                         IXml node)
Finds a domain object that pertains to ther curent builder call.

Parameters:
pageName - nam eof the page object
builderId - builder call ID to filter out other domain objects in the same page.
Returns:
an instance of PageDomainObject if one is found or null otherwise.

getGenContext

protected GenContext getGenContext()
Return the GenContext object for this builder invocation.

Returns:
The GenContext for this call

getHtmlSafePageIndirectInput

public java.lang.String getHtmlSafePageIndirectInput(java.lang.String inputName,
                                                     java.lang.String defaultValue)
Transform a builder input which might contain a ${...} reference to an equivalent JSP expression. Any offending characters will be converted to html-safe escape sequences.


getIndirectInput

public java.lang.String getIndirectInput(java.lang.String inputName,
                                         java.lang.String defaultValue,
                                         java.lang.String type)
Transform a builder input which might contain a ${...} reference to equivalent Java code.

Parameters:
type - One of the Variable.TYPE_ Strings

getIndirectStringInput

public java.lang.String getIndirectStringInput(java.lang.String inputName,
                                               java.lang.String defaultValue)
Transform a builder input which might contain a ${...} reference to equivalent Java code.


getIndirectText

protected java.lang.String getIndirectText(java.lang.String inputName,
                                           java.lang.String defaultValue)
Transform a builder input which might contain a ${...} reference to an equivalent Java code. Where the ${...} evaluates to null, this will convert it to "" (So you don't end up with "null" on your page).

Parameters:
inputName - The name of the builder input
defaultValue - the value to return use if the specified inputName does not exist.
Returns:
If ${...} then the generated Java code, else the value of the specified Builder input.

getIndirectXmlInput

public java.lang.String getIndirectXmlInput(java.lang.String inputName,
                                            java.lang.String defaultValue)
Transform a builder input which might contain a ${...} reference to equivalent Java code.


getJavaFromJSP

public static java.lang.String getJavaFromJSP(java.lang.String inp)
Extract the Java code from inside a JSP expression.


getPageIndirectInput

public java.lang.String getPageIndirectInput(java.lang.String inputName,
                                             java.lang.String defaultValue)
Transform a builder input which might contain a ${...} reference to an equivalent JSP expression.


getPageIndirectText

protected java.lang.String getPageIndirectText(java.lang.String inputName,
                                               java.lang.String defaultValue)
Transform a builder input which might contain a ${...} reference to an equivalent JSP expression. Where the ${...} evaluates to null, this will convert it to "" (So you don't end up with "null" on your page).

Parameters:
inputName - The name of the builder input
defaultValue - the value to return use if the specified inputName does not exist.
Returns:
If ${...} then the generated JSP, else the value of the specified Builder input.

getPageLocationEntries

protected java.util.Collection getPageLocationEntries()

getPreferredPhase

protected java.lang.String getPreferredPhase()
Get preferred phase, to run the handlePage and handleControl methods in; Return PHASE_POSTCONSTRUCTION, PHASE_MODIFICATION or PHASE_VALIDATION.

Returns:
phase to handle page and control in (postconstruction, modification or validation).

getWebApp

protected WebApp getWebApp()
Return the top-level object under contstruction.

Returns:
The WebApp object being built

handleConstruction

protected void handleConstruction()
Called once per invocation, to handle non-page/control work in the contsruction phase.


handleControl

protected void handleControl(Page page,
                             IXml element)
Called for each location needing modification. Override this method to modify specific elements on a page.

Parameters:
page - The page hosting the element
element - The element to be modified

handleModification

protected void handleModification()
Called once per invocation, to handle non-page/control work in the modification phase.


handlePage

protected void handlePage(Page page)
Called for each page needing modification. Override this method to modify the page directly.

Parameters:
page - The page to be modified

handlePostConstruction

protected void handlePostConstruction()
Called once per invocation, to handle non-page/control work in the post-contsruction phase. At this point, for example, all other pages, methods, and variables are available for inspection.


handleValidation

protected void handleValidation()
Called once per invocation, to handle validation and other operations which must happen very late.


preprocessControl

protected void preprocessControl(Page page,
                                 IXml element)
Hook for base classes to pre-process an element before it is passed off to handleControl().

Parameters:
page - The page hosting the element
element - The element to be modified by the builder

preprocessElement

protected void preprocessElement(IXml element)
If a control builder is being applied then remove the existing dojoType, if one of our builder has added it.

Parameters:
element -

processCommonInputs

protected void processCommonInputs(IXml element)
Common input handling support - called just before handleControl.


replaceElement

public static void replaceElement(IXml element,
                                  IXml newNode)
Convenience routine: replace element with new node, if possible.


replaceElement

public static void replaceElement(IXml element,
                                  java.util.List newNodes)
Convenience routine: replace element with new nodes, if possible.


resolvePageIndirectReference

public java.lang.String resolvePageIndirectReference(java.lang.String input,
                                                     java.lang.String runtimeType)
Transform a ${...} reference to an equivalent JSP expression.

Parameters:
input - The indirect literal or reference, e.g. ${Variables/foo}
runtimeType - The runtime type expected (must be one of the Variable.TYPE_ values)
Returns:
The JSP expression, if input is a reference, or input unmodified if not.

tagDisplaysChildContent

public static boolean tagDisplaysChildContent(java.lang.String tagName)
Returns false if the specified HTML tag isn't allowed to have child elements (e.g., <INPUT>) or won't directly display contained content (e.g., <SELECT>)



Copyright © 2009 IBM. All Rights Reserved.