com.cc.framework.ui.painter.imp
Class PainterContextImp

java.lang.Object
  extended bycom.cc.framework.ui.painter.imp.PainterContextImp
All Implemented Interfaces:
HttpContext, PainterContext, RequestContext

public class PainterContextImp
extends java.lang.Object
implements PainterContext

This class encapsulates all the necessary objects for painting the control.

Since:
1.2
Version:
$Revision: 1.11 $
Author:
Harald Schulz

Field Summary
private  java.util.Hashtable attributes
          Attributes
private  java.util.Stack attributesSave
          Stack for saving the whole Attribute collection
private  Control control
          Instance of the Control
private  PainterFactory factory
          The Painter Factory
private  java.util.Locale locale
          The Locale for this Painter
private  javax.servlet.jsp.PageContext pageContext
          PageContext of the JSP-Page
private  PainterContext parentContext
          The nesting Painter Context when the actual control is nested within another control e.g. form elements
private  Principal principal
          The Principal Object.
 
Constructor Summary
PainterContextImp(javax.servlet.jsp.PageContext pageContext, Control control)
          Constructor
 
Method Summary
 java.lang.String attr(java.lang.Object raw)
          Converts a String to an equivalent HTML-String
 java.lang.String attr(java.lang.Object raw, boolean filter)
          Converts a String to an equivalent HTML-String
 java.lang.String attr(java.lang.Object raw, boolean filter, int maxlength)
          Converts a String to an equivalent HTML-String
 void close()
          After the painter context has been used it has to be closed.
 ActionPainter createActionPainter(ControlActionDef action)
          Creates an ActionPainter.
 ActionPainter createActionPainter(ControlActionDef action, java.lang.String actionName)
          Creates an ActionPainter.
 org.apache.ecs.html.IMG createImage(ImageModel image)
          Retrieves an image for the specified Id
 org.apache.ecs.html.IMG createImage(int size, java.lang.String resourceId)
          Retrieves an image for the specified Id
 org.apache.ecs.html.IMG createImage(java.lang.String resourceId)
          Retrieves an image for the specified Id
 org.apache.ecs.html.IMG createImage(java.lang.String resourceId, java.lang.Object param)
          Retrieves an image for the specified Id
 org.apache.ecs.html.Input createInput(ImageModel image)
          Retrieves an image for the specified Id
 org.apache.ecs.html.Input createInput(java.lang.String resourceId)
          Retrieves an image for the specified Id
 java.lang.String decorateURL(java.lang.String url)
          Decorates the URL with RequestDecorator settings and appends the JSESSIONID when URL-rewriting is enabled to track sessions Every URL has to be decorated this way!
 java.lang.String getAsString(Converter converter, java.lang.Object value)
          Uses a Bean Converter to convert the given object to a String representation.
 java.lang.Object getAttribute(java.lang.String key, boolean searchParent)
          Gets an Attribute from the Painter Context hierarchy
 java.lang.Object getAttribute(java.lang.String name, HttpScope scope)
          Returns the attribute with the given name from the specified scope
 java.awt.Color getAwtColor(java.lang.String resourceId)
          Retrieves an color for the specified Id
 Color getColor(java.lang.String resourceId)
          Retrieves an color for the specified Id
protected  java.util.Stack getContextStack()
          Retrieves the painter context stack for the current request.
 Control getControl()
           
 java.lang.String getElementName()
          Retrieves the name of the HTML element.
 java.lang.String getFrameworkString(java.lang.String resourceId)
          Returns a framework string resource
 java.lang.String getFrameworkString(java.lang.String resourceId, java.lang.Object[] arguments)
          Returns a framework string resource
 ImageModel getImage(int size, java.lang.String resourceId)
          Retrieves an image for the specified Id
 ImageModel getImage(java.lang.String resourceId)
          Retrieves an image for the specified Id
 ImageModel getImage(java.lang.String resourceId, java.lang.Object param)
          Retrieves an image for the specified Id
 java.lang.String getImageSrc(int size, java.lang.String resourceId)
          Retrieves an image for the specified Id
 java.lang.String getImageSrc(java.lang.String resourceId)
          Retrieves an image for the specified Id
 java.lang.String getImageSrc(java.lang.String resourceId, java.lang.Object param)
          Retrieves an image for the specified Id
 java.util.Locale getLocale()
          Gets the Locale Setting for this Control
 RequestContext getNestedContext()
          Gets the nested Action Context
 javax.servlet.jsp.PageContext getPageContext()
          Gets the Page Context
 Principal getPrincipal()
          Returns the Principal Object in the current User session
 javax.servlet.http.HttpServletRequest getRequest()
          Deprecated. use request()
 java.lang.String getResourceDir()
          Returns the base directory used for resource by the painter factory
 javax.servlet.http.HttpServletResponse getResponse()
          Deprecated. use response()
 javax.servlet.ServletContext getServletContext()
          Returns the Servlet Context
 javax.servlet.http.HttpSession getSession()
          Deprecated. use session()
 java.lang.String getSource(ImageModel image)
          Gets the localized resource name
 java.lang.String getSource(java.lang.String base, java.lang.String src)
          Returns the localized Image resource name
 java.lang.String getStringResource(java.lang.String stringOrKey)
          Returns a string resource
 java.lang.String getStyleId()
          Returns the Style Id of the control.
 boolean hasAttribute(java.lang.String key, boolean searchParent)
          Gets an Attribute from the Painter Context hierarchy
 java.lang.String html(java.lang.Object raw)
          Converts a String to an equivalent HTML-String
 java.lang.String html(java.lang.Object raw, boolean filter)
          Converts a String to an equivalent HTML-String
 java.lang.String html(java.lang.Object raw, boolean filter, int maxlength)
          Converts a String to an equivalent HTML-String
protected  void initLocale()
          Sets the locale configuration for this Painter Context.
 boolean isDisplayOnly()
          This method checks if a control that is rendered within this Painter context has to be "display only"
 boolean isRunAtClient()
          This Method checks if the control should run on the client
 java.lang.String localize(java.lang.String keyOrString)
          Localizes a string depending on the localization settings of the Painter context
 java.lang.String localize(java.lang.String keyOrString, java.util.Locale locale)
          Localizes a string depending on the localization settings of the Painter context
 java.lang.String localize(java.lang.String keyOrString, java.lang.Object[] arguments)
          Localizes a string depending on the localization settings of the Painter context
 java.lang.String localizeKey(java.lang.String resourceId, java.lang.Object[] arguments, boolean returnNull)
          Localizes a string depending on the localization settings of the Painter context.
 void open()
          The painter context has to be opened before it can be used.
 void popAttributes()
          Restores the attributes from the Stack all current attributes are lost
 void pushAttributes()
          Pushes the current attributes on a stack for later restore
 java.lang.Object removeAttribute(java.lang.String key)
          Removes an Attribute for this Painter
 java.lang.String removeHtml(java.lang.Object html)
          Removes all HTML formatting from the given HTML-String
 java.lang.String removeHtml(java.lang.Object html, boolean filter)
          Removes all HTML formatting from the given HTML-String depending on the filter setting
 javax.servlet.http.HttpServletRequest request()
          Returns the HTTP Request
 javax.servlet.http.HttpServletResponse response()
          Returns the HTTP Response
 javax.servlet.http.HttpSession session()
          Gets the session object
 void setAttribute(java.lang.String key, java.lang.Object value)
          Sets an Attribute for this Painter
 void setFactory(PainterFactory factory)
          Sets the painter factory
 boolean showComments()
          This method checks if HTML comments should be written to the output
 java.lang.String truncate(java.lang.Object obj, int maxlength)
          Truncates a given string to a maximum number of characters
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pageContext

private javax.servlet.jsp.PageContext pageContext
PageContext of the JSP-Page


control

private Control control
Instance of the Control


locale

private java.util.Locale locale
The Locale for this Painter


parentContext

private PainterContext parentContext
The nesting Painter Context when the actual control is nested within another control e.g. form elements


principal

private Principal principal
The Principal Object.


factory

private PainterFactory factory
The Painter Factory


attributes

private java.util.Hashtable attributes
Attributes


attributesSave

private java.util.Stack attributesSave
Stack for saving the whole Attribute collection

Constructor Detail

PainterContextImp

public PainterContextImp(javax.servlet.jsp.PageContext pageContext,
                         Control control)
Constructor

Parameters:
pageContext - the JSP-PageContext
control - The selected Control
Method Detail

getContextStack

protected java.util.Stack getContextStack()
Retrieves the painter context stack for the current request. The context stack is used to nest control painters.

Returns:
painter context stack

open

public void open()
The painter context has to be opened before it can be used. It initializes some internal variables

Specified by:
open in interface PainterContext

close

public void close()
After the painter context has been used it has to be closed. This will remove some internal variables from the request

Specified by:
close in interface PainterContext

getElementName

public java.lang.String getElementName()
Retrieves the name of the HTML element. This could be a path name when the control is nested within another control

Specified by:
getElementName in interface PainterContext
Returns:
The name to use for the name-attribute of a HTML element

initLocale

protected void initLocale()
Sets the locale configuration for this Painter Context. Search Path:
  1. the control
  2. the parent control
  3. the page scope
  4. the request scope
  5. the session scope
  6. the session application scope


setFactory

public void setFactory(PainterFactory factory)
Sets the painter factory

Specified by:
setFactory in interface PainterContext
Parameters:
factory - Painter factory

getPageContext

public javax.servlet.jsp.PageContext getPageContext()
Gets the Page Context

Specified by:
getPageContext in interface PainterContext
Returns:
PageContext

getNestedContext

public RequestContext getNestedContext()
Description copied from interface: RequestContext
Gets the nested Action Context

Specified by:
getNestedContext in interface RequestContext
Returns:
The nested Action Context
See Also:
RequestContext.getNestedContext()

getPrincipal

public Principal getPrincipal()
Description copied from interface: RequestContext
Returns the Principal Object in the current User session

Specified by:
getPrincipal in interface RequestContext
Returns:
The object which implements the principal interface
See Also:
RequestContext.getPrincipal()

getSession

public javax.servlet.http.HttpSession getSession()
Deprecated. use session()

Returns the HttpSession

Returns:
The HttpSession or null

getRequest

public javax.servlet.http.HttpServletRequest getRequest()
Deprecated. use request()

Returns:
HttpServletRequest

getResponse

public javax.servlet.http.HttpServletResponse getResponse()
Deprecated. use response()

Returns:
HttpServletResponse

getAsString

public java.lang.String getAsString(Converter converter,
                                    java.lang.Object value)
                             throws ConverterException
Uses a Bean Converter to convert the given object to a String representation.

Specified by:
getAsString in interface PainterContext
Parameters:
converter - The converter to use or null to use a default Converter
value - The Bean to convert
Returns:
String or null
Throws:
ConverterException - Is thrown when a conversion exception occurs

decorateURL

public java.lang.String decorateURL(java.lang.String url)
Decorates the URL with RequestDecorator settings and appends the JSESSIONID when URL-rewriting is enabled to track sessions Every URL has to be decorated this way!

Specified by:
decorateURL in interface PainterContext
Parameters:
url - the URL to encode
Returns:
encoded URL

getResourceDir

public java.lang.String getResourceDir()
Returns the base directory used for resource by the painter factory

Specified by:
getResourceDir in interface PainterContext
Returns:
The web resource directory

getStringResource

public java.lang.String getStringResource(java.lang.String stringOrKey)
Returns a string resource

Specified by:
getStringResource in interface PainterContext
Parameters:
stringOrKey - Id of the resource/key
Returns:
The value for the resource id

getFrameworkString

public java.lang.String getFrameworkString(java.lang.String resourceId)
Returns a framework string resource

Specified by:
getFrameworkString in interface PainterContext
Parameters:
resourceId - Id of the resource/key
Returns:
The value for the resource id

getFrameworkString

public java.lang.String getFrameworkString(java.lang.String resourceId,
                                           java.lang.Object[] arguments)
Returns a framework string resource

Specified by:
getFrameworkString in interface PainterContext
Parameters:
resourceId - Id of the resource/key
arguments - MessageFormat arguments
Returns:
The value for the resource id

getImage

public ImageModel getImage(java.lang.String resourceId)
Retrieves an image for the specified Id

Specified by:
getImage in interface PainterContext
Parameters:
resourceId - Image Code
Returns:
The Image or null

getImage

public ImageModel getImage(int size,
                           java.lang.String resourceId)
Retrieves an image for the specified Id

Specified by:
getImage in interface PainterContext
Parameters:
size - Image size
resourceId - Image Code
Returns:
The Image or null

getImage

public ImageModel getImage(java.lang.String resourceId,
                           java.lang.Object param)
Retrieves an image for the specified Id

Specified by:
getImage in interface PainterContext
Parameters:
resourceId - Image Code
param - Markup parameter
Returns:
The Image or null

getImageSrc

public java.lang.String getImageSrc(java.lang.String resourceId)
Retrieves an image for the specified Id

Specified by:
getImageSrc in interface PainterContext
Parameters:
resourceId - Image Code
Returns:
The Image Source

getImageSrc

public java.lang.String getImageSrc(java.lang.String resourceId,
                                    java.lang.Object param)
Retrieves an image for the specified Id

Specified by:
getImageSrc in interface PainterContext
Parameters:
resourceId - Image Code
param - Markup Parameter
Returns:
The Image Source

getImageSrc

public java.lang.String getImageSrc(int size,
                                    java.lang.String resourceId)
Retrieves an image for the specified Id

Specified by:
getImageSrc in interface PainterContext
Parameters:
size - Image size
resourceId - Image Code
Returns:
The Image Source

getColor

public Color getColor(java.lang.String resourceId)
Retrieves an color for the specified Id

Specified by:
getColor in interface PainterContext
Parameters:
resourceId - Color Code
Returns:
The Color or null

getAwtColor

public java.awt.Color getAwtColor(java.lang.String resourceId)
Retrieves an color for the specified Id

Specified by:
getAwtColor in interface PainterContext
Parameters:
resourceId - Color Code
Returns:
The Color or null

getControl

public Control getControl()
Specified by:
getControl in interface PainterContext
Returns:
Gets the Control

isRunAtClient

public boolean isRunAtClient()
This Method checks if the control should run on the client

Specified by:
isRunAtClient in interface PainterContext
Returns:
Returns true when the component should run on the client

getStyleId

public java.lang.String getStyleId()
Returns the Style Id of the control. Under some circumstances this method will generate an unique Style id if no style id is explicit set.

Specified by:
getStyleId in interface PainterContext
Returns:
style id for this control

showComments

public boolean showComments()
This method checks if HTML comments should be written to the output

Specified by:
showComments in interface PainterContext
Returns:
false when comments should be hidden

isDisplayOnly

public boolean isDisplayOnly()
This method checks if a control that is rendered within this Painter context has to be "display only"

Specified by:
isDisplayOnly in interface PainterContext
Returns:
returns true if a control should be rendered as display only

createActionPainter

public ActionPainter createActionPainter(ControlActionDef action)
Creates an ActionPainter. The Painter is used by Controls to render Actions into the user interface

Specified by:
createActionPainter in interface PainterContext
Parameters:
action - ControlAction
Returns:
ActionPainter

createActionPainter

public ActionPainter createActionPainter(ControlActionDef action,
                                         java.lang.String actionName)
Creates an ActionPainter. The Painter is used by Controls to render Actions into the user interface

Specified by:
createActionPainter in interface PainterContext
Parameters:
action - ControlAction
actionName - Additional Action Name
Returns:
ActionPainter

createInput

public org.apache.ecs.html.Input createInput(ImageModel image)
Retrieves an image for the specified Id

Specified by:
createInput in interface PainterContext
Parameters:
image - Image
Returns:
The Image or null

createInput

public org.apache.ecs.html.Input createInput(java.lang.String resourceId)
Retrieves an image for the specified Id

Specified by:
createInput in interface PainterContext
Parameters:
resourceId - Image Code
Returns:
The Image or null

createImage

public org.apache.ecs.html.IMG createImage(ImageModel image)
Retrieves an image for the specified Id

Specified by:
createImage in interface PainterContext
Parameters:
image - Image
Returns:
The Image or null

createImage

public org.apache.ecs.html.IMG createImage(java.lang.String resourceId)
Retrieves an image for the specified Id

Specified by:
createImage in interface PainterContext
Parameters:
resourceId - Image Code
Returns:
The Image or null

createImage

public org.apache.ecs.html.IMG createImage(java.lang.String resourceId,
                                           java.lang.Object param)
Retrieves an image for the specified Id

Specified by:
createImage in interface PainterContext
Parameters:
resourceId - Image Code
param - Markup parameter
Returns:
The Image or null

createImage

public org.apache.ecs.html.IMG createImage(int size,
                                           java.lang.String resourceId)
Retrieves an image for the specified Id

Specified by:
createImage in interface PainterContext
Parameters:
size - Image size
resourceId - Image Code
Returns:
The Image or null

getLocale

public java.util.Locale getLocale()
Gets the Locale Setting for this Control

Specified by:
getLocale in interface PainterContext
Returns:
Locale Setting

localize

public java.lang.String localize(java.lang.String keyOrString)
Localizes a string depending on the localization settings of the Painter context

Specified by:
localize in interface PainterContext
Parameters:
keyOrString - String Literal or Resource Key
Returns:
localized String

localize

public java.lang.String localize(java.lang.String keyOrString,
                                 java.util.Locale locale)
Localizes a string depending on the localization settings of the Painter context

Specified by:
localize in interface PainterContext
Parameters:
keyOrString - String Literal or Resource Key
locale - the locale to use
Returns:
localized String

localize

public java.lang.String localize(java.lang.String keyOrString,
                                 java.lang.Object[] arguments)
Localizes a string depending on the localization settings of the Painter context

Specified by:
localize in interface PainterContext
Parameters:
keyOrString - String Literal or Resource Key
arguments - MessageFormat arguments
Returns:
localized String

localizeKey

public java.lang.String localizeKey(java.lang.String resourceId,
                                    java.lang.Object[] arguments,
                                    boolean returnNull)
Localizes a string depending on the localization settings of the Painter context. A key is searched in the following order: 1) If no user defined resource bundle is used. The resource is searched under the STRUTS_MESSAGES_KEY.
2) If an user defined resource bundle is used (key@bundle) the resource is searched in the specified resource bundle.
3) If the key was not found before, the resource is searched in the framework resource bundle under the key Globals.MESSAGE.

Specified by:
localizeKey in interface PainterContext
Parameters:
resourceId - The resource key.
arguments - MessageFormat arguments or null
returnNull - controls whether to return null or a not present indicator
Returns:
localized String

removeHtml

public java.lang.String removeHtml(java.lang.Object html)
Description copied from interface: PainterContext
Removes all HTML formatting from the given HTML-String

Specified by:
removeHtml in interface PainterContext
Parameters:
html - Object in HTML format
Returns:
String
See Also:
PainterContext.removeHtml(java.lang.Object)

removeHtml

public java.lang.String removeHtml(java.lang.Object html,
                                   boolean filter)
Description copied from interface: PainterContext
Removes all HTML formatting from the given HTML-String depending on the filter setting

Specified by:
removeHtml in interface PainterContext
Parameters:
html - Object in HTML format
filter - Filter
Returns:
String
See Also:
PainterContext.removeHtml(java.lang.Object, boolean)

html

public java.lang.String html(java.lang.Object raw)
Converts a String to an equivalent HTML-String

Specified by:
html in interface PainterContext
Parameters:
raw - Object
Returns:
String

html

public java.lang.String html(java.lang.Object raw,
                             boolean filter)
Converts a String to an equivalent HTML-String

Specified by:
html in interface PainterContext
Parameters:
raw - Object
filter - Filter
Returns:
String

html

public java.lang.String html(java.lang.Object raw,
                             boolean filter,
                             int maxlength)
Converts a String to an equivalent HTML-String

Specified by:
html in interface PainterContext
Parameters:
raw - Object
filter - Filter
maxlength - The maximum number of visible characters
Returns:
String

attr

public java.lang.String attr(java.lang.Object raw)
Converts a String to an equivalent HTML-String

Specified by:
attr in interface PainterContext
Parameters:
raw - Object
Returns:
String

attr

public java.lang.String attr(java.lang.Object raw,
                             boolean filter)
Converts a String to an equivalent HTML-String

Specified by:
attr in interface PainterContext
Parameters:
raw - Object
filter - Filter
Returns:
String

attr

public java.lang.String attr(java.lang.Object raw,
                             boolean filter,
                             int maxlength)
Converts a String to an equivalent HTML-String

Specified by:
attr in interface PainterContext
Parameters:
raw - Object
filter - Filter
maxlength - The maximum number of visible characters
Returns:
String

truncate

public java.lang.String truncate(java.lang.Object obj,
                                 int maxlength)
Truncates a given string to a maximum number of characters

Specified by:
truncate in interface PainterContext
Parameters:
obj - The string to truncate
maxlength - The maximum number of characters
Returns:
truncated string

getSource

public java.lang.String getSource(java.lang.String base,
                                  java.lang.String src)
Returns the localized Image resource name

Specified by:
getSource in interface PainterContext
Parameters:
base - Base Directory or resource Identifier
src - Resource name
Returns:
localized Resource name

getSource

public java.lang.String getSource(ImageModel image)
Gets the localized resource name

Specified by:
getSource in interface PainterContext
Parameters:
image - Image Model
Returns:
localized Resource name

setAttribute

public void setAttribute(java.lang.String key,
                         java.lang.Object value)
Sets an Attribute for this Painter

Specified by:
setAttribute in interface PainterContext
Parameters:
key - Attribute Key
value - Attribute Value

removeAttribute

public java.lang.Object removeAttribute(java.lang.String key)
Removes an Attribute for this Painter

Specified by:
removeAttribute in interface PainterContext
Parameters:
key - Attribute Key
Returns:
Value or null

getAttribute

public java.lang.Object getAttribute(java.lang.String key,
                                     boolean searchParent)
Gets an Attribute from the Painter Context hierarchy

Specified by:
getAttribute in interface PainterContext
Parameters:
key - Attribute Key
searchParent - if set to true the attribute will be search up the PainterContext hierarchy
Returns:
Value or null

hasAttribute

public boolean hasAttribute(java.lang.String key,
                            boolean searchParent)
Gets an Attribute from the Painter Context hierarchy

Specified by:
hasAttribute in interface PainterContext
Parameters:
key - Attribute Key
searchParent - if set to true the attribute will be search up the PainterContext hierarchy
Returns:
Value or null

pushAttributes

public void pushAttributes()
Pushes the current attributes on a stack for later restore

Specified by:
pushAttributes in interface PainterContext

popAttributes

public void popAttributes()
Restores the attributes from the Stack all current attributes are lost

Specified by:
popAttributes in interface PainterContext

getAttribute

public java.lang.Object getAttribute(java.lang.String name,
                                     HttpScope scope)
Description copied from interface: HttpContext
Returns the attribute with the given name from the specified scope

Specified by:
getAttribute in interface HttpContext
Parameters:
name - the attribute name
scope - the scope to search
Returns:
attribute value or null
See Also:
HttpContext.getAttribute(java.lang.String, com.cc.framework.http.HttpScope)

getServletContext

public javax.servlet.ServletContext getServletContext()
Description copied from interface: HttpContext
Returns the Servlet Context

Specified by:
getServletContext in interface HttpContext
Returns:
ServletContext
See Also:
HttpContext.getServletContext()

request

public javax.servlet.http.HttpServletRequest request()
Description copied from interface: HttpContext
Returns the HTTP Request

Specified by:
request in interface HttpContext
Returns:
the HttpServletRequest
See Also:
HttpContext.request()

response

public javax.servlet.http.HttpServletResponse response()
Description copied from interface: HttpContext
Returns the HTTP Response

Specified by:
response in interface HttpContext
Returns:
the HttpServletResponse
See Also:
HttpContext.response()

session

public javax.servlet.http.HttpSession session()
Description copied from interface: HttpContext
Gets the session object

Specified by:
session in interface HttpContext
Returns:
HttpSession
See Also:
HttpContext.session()


Copyright © 2000-2005 SCC Informationssysteme GmbH. All Rights Reserved.