Package de.hsh.graja.util.comment
Class Content
- java.lang.Object
-
- de.hsh.graja.util.comment.Content
-
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
AbstractElementContent
,AbstractSequenceContent
public abstract class Content extends Object implements Serializable
Something that can be rendered to a presentable medium. We think of Content as an interface abstracting any class that holds data that can be transformed to HTML.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static MutualExclusiveObject<String>
EXCLUSIVE
protected Function<RenderContext,String>
renderUuid
-
Constructor Summary
Constructors Constructor Description Content(String idPrefix, IncludeSpec includeSpec)
Create a new content instance.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Action
click()
static void
disableCallerStacktraceRecording()
Disables the stacktrace recording mechanism that allows to trace a comments origin within the graja codebasestatic void
enableCallerStacktraceRecording()
Enables the stacktrace recording mechanism that allows to trace a comments origin within the graja codebaseboolean
equals(Object obj)
Two Content are equal, when theirgetIncludeSpec()
are equal.boolean
excludeGlobally()
IncludeSpec
getIncludeSpec()
abstract Iterable<Content>
getNestedContents()
String
getRenderUuid(RenderContext ctx)
ArrayList<StackTraceElement>
getStackdump()
Only relevant for the regression testing mechanism.int
hashCode()
Action
hide()
boolean
include(IncludeInfo info)
static boolean
isCallerStacktraceRecordingEnabled()
Condition
isHidden()
Condition
isShowing()
Content
onClick(Action action)
Register an action that will be rendered in the 'onClick' attribute of this content.Content
onClick(Iterable<Action> actions)
Register actions that will be rendered in the 'onClick' attribute of this content.Content
onHide(Action action)
Register an action that will be rendered byhide()
.Content
onHide(Iterable<Action> actions)
Register actions that will be rendered byhide()
.Content
onLoad(Action action)
Register an action that will be rendered at the top level besides this content's HTML markup.Content
onLoad(Iterable<Action> actions)
Register actions that will be rendered at the top level besides this content's HTML markup.Content
onShow(Action action)
Register an action that will be rendered byshow()
.Content
onShow(Iterable<Action> actions)
Register actions that will be rendered byshow()
.<T extends Action>
CallableAction<T>registerCallable(T delegate, String functionPrefix)
Places a javascript snippet besides this content defining a function of the givenfunctionName
.void
renderHtml(StringBuilder appender, IncludeInfo includeInfo, RenderContext ctx, boolean useJavascript)
render content to HTML.void
renderHtml(StringBuilder appender, IncludeInfo includeInfo, String namespace, boolean useJavascript)
render content to HTML.protected abstract void
renderHtmlImpl(StringBuilder appender, IncludeInfo includeInfo, RenderContext ctx, boolean useJavascript)
render content to HTML.protected void
renderIdAttribute(StringBuilder appender, RenderContext ctx)
static void
renderJavascriptOncePerClass(StringBuilder appender, RenderContext ctx)
This method writes javascript code toappender
.protected void
renderOnClickAttribute(StringBuilder appender, RenderContext ctx, boolean useJavascript)
void
renderPlain(StringBuilder appender, IncludeInfo includeInfo, RenderContext ctx)
render content to plain text.void
renderPlain(StringBuilder appender, IncludeInfo includeInfo, String namespace)
render content to plain text.abstract void
renderPlainImpl(StringBuilder appender, IncludeInfo includeInfo, RenderContext ctx)
render content to plain text.static void
setGlobalIncludeInfo(IncludeInfo info)
This method configures the html content classes to exclude all content not included byinfo
.void
setHref(Anchor href)
void
setIncludeSpec(IncludeSpec spec)
Action
show()
String
toString()
String
toString(String prefix)
This method is for debugging purposes.
-
-
-
Field Detail
-
renderUuid
protected Function<RenderContext,String> renderUuid
-
EXCLUSIVE
public static final MutualExclusiveObject<String> EXCLUSIVE
-
-
Constructor Detail
-
Content
public Content(String idPrefix, IncludeSpec includeSpec)
Create a new content instance. For every render context this method sets a new uuid with the given prefix. Hyphens in the uuid are eliminated, so the uuid can be used as an javascript identifier.- Parameters:
prefix
- an optional id prefixincludeSpec
- an optional include spec
-
-
Method Detail
-
setGlobalIncludeInfo
public static void setGlobalIncludeInfo(IncludeInfo info)
This method configures the html content classes to exclude all content not included byinfo
. With this setting we can speed up document generation without many debug content that is only used in developement situations.- Parameters:
info
- include info
-
excludeGlobally
public boolean excludeGlobally()
- Returns:
- true, if this content is excluded by the value set via
setGlobalIncludeInfo(IncludeInfo)
.
-
getRenderUuid
public String getRenderUuid(RenderContext ctx)
- Returns:
- the uuid for the given context, or null.
-
renderJavascriptOncePerClass
public static void renderJavascriptOncePerClass(StringBuilder appender, RenderContext ctx)
This method writes javascript code toappender
. Subclasses can also implement an own version of this method. The javascript content will be rendered only once when callingContent#renderHtml(StringBuilder, IncludeInfo, RenderContext, Boolean)
with a RenderContext parameter being null.- Parameters:
appender
-ctx
-
-
getIncludeSpec
public IncludeSpec getIncludeSpec()
- Returns:
- the specification object of this content's include behaviour
-
setIncludeSpec
public void setIncludeSpec(IncludeSpec spec)
- Parameters:
new
- include spec
-
include
public boolean include(IncludeInfo info)
- Parameters:
info
- inclusion info- Returns:
- true, if this content is to be included
-
getNestedContents
public abstract Iterable<Content> getNestedContents()
- Returns:
- the set of contents nested in this content. Nested contents can be list items in a List, elements in a Sequence, elements in a Grid, elements in a Paragraph, and so on. If this is a leaf content, the returned set is empty.
-
equals
public boolean equals(Object obj)
Two Content are equal, when theirgetIncludeSpec()
are equal.
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classObject
- See Also:
Object.hashCode()
-
toString
public String toString(String prefix)
This method is for debugging purposes.- Parameters:
prefix
- If the output has multiple lines,prefix
specifies the indentation of the subsequent lines.- Returns:
- a string representation of the content and it's internal structure.
-
toString
public String toString()
- Overrides:
toString
in classObject
- See Also:
Object.toString()
-
renderHtml
public void renderHtml(StringBuilder appender, IncludeInfo includeInfo, String namespace, boolean useJavascript)
render content to HTML.- Parameters:
appender
- HTML code resultincludeInfo
- controls, which content to be rendered.namespace
- the namespace of the rendered HTML. If null, a random namespace string will be generated.useJavascript
- if true, the generated HTML code will contain Javascript
-
renderHtml
public void renderHtml(StringBuilder appender, IncludeInfo includeInfo, RenderContext ctx, boolean useJavascript)
render content to HTML.- Parameters:
appender
- HTML code resultincludeInfo
- controls, which content to be rendered.ctx
- render context. If null, a new render context will be instantiated automatically.useJavascript
- if true, the generated HTML code will contain Javascript
-
renderHtmlImpl
protected abstract void renderHtmlImpl(StringBuilder appender, IncludeInfo includeInfo, RenderContext ctx, boolean useJavascript)
render content to HTML. This method is meant to be overriden by subclasses.- Parameters:
appender
- HTML code resultincludeInfo
- controls, which content to be rendered.ctx
- render contextuseJavascript
- if true, the generated HTML code will contain Javascript
-
renderPlainImpl
public abstract void renderPlainImpl(StringBuilder appender, IncludeInfo includeInfo, RenderContext ctx)
render content to plain text. This method is meant to be overriden by subclasses.- Parameters:
appender
- plain text resultincludeInfo
- controls, which content to be rendered.ctx
- render context (unused).
-
renderPlain
public void renderPlain(StringBuilder appender, IncludeInfo includeInfo, String namespace)
render content to plain text.- Parameters:
appender
- plain text resultincludeInfo
- controls, which content to be rendered.namespace
- unused
-
renderPlain
public void renderPlain(StringBuilder appender, IncludeInfo includeInfo, RenderContext ctx)
render content to plain text.- Parameters:
appender
- plain text resultincludeInfo
- controls, which content to be rendered.ctx
- render context (unused).
-
setHref
public void setHref(Anchor href)
-
click
public Action click()
-
hide
public Action hide()
- Returns:
- an object that can be used to render a javascript snippet that will hide this content and that will render all actions registered with onHide.
-
show
public Action show()
- Returns:
- an object that can be used to render a javascript snippet that will show this content and that will render all actions registered with onShow.
-
isHidden
public Condition isHidden()
- Returns:
- an object that can be used to render a javascript snippet that represents a boolean expression being true if this content is currently hidden.
-
isShowing
public Condition isShowing()
- Returns:
- an object that can be used to render a javascript snippet that represents a boolean expression being true if this content is currently visible.
-
onClick
public Content onClick(Action action)
Register an action that will be rendered in the 'onClick' attribute of this content.
-
onClick
public Content onClick(Iterable<Action> actions)
Register actions that will be rendered in the 'onClick' attribute of this content.
-
onHide
public Content onHide(Iterable<Action> actions)
Register actions that will be rendered byhide()
.
-
onShow
public Content onShow(Iterable<Action> actions)
Register actions that will be rendered byshow()
.
-
onLoad
public Content onLoad(Action action)
Register an action that will be rendered at the top level besides this content's HTML markup. This action will be executed when the browser loads the document.
-
onLoad
public Content onLoad(Iterable<Action> actions)
Register actions that will be rendered at the top level besides this content's HTML markup. These actions will be executed when the browser loads the document.
-
registerCallable
public <T extends Action> CallableAction<T> registerCallable(T delegate, String functionPrefix)
Places a javascript snippet besides this content defining a function of the givenfunctionName
. The function is implemented by calling the givendelegate
.- Parameters:
delegate
-functionName
-- Returns:
-
renderOnClickAttribute
protected void renderOnClickAttribute(StringBuilder appender, RenderContext ctx, boolean useJavascript)
-
renderIdAttribute
protected void renderIdAttribute(StringBuilder appender, RenderContext ctx)
-
enableCallerStacktraceRecording
public static void enableCallerStacktraceRecording()
Enables the stacktrace recording mechanism that allows to trace a comments origin within the graja codebase
-
isCallerStacktraceRecordingEnabled
public static boolean isCallerStacktraceRecordingEnabled()
- Returns:
- true, if stacktrace recording is enabled, which is only the case when regression test behavior recording is enabled
-
disableCallerStacktraceRecording
public static void disableCallerStacktraceRecording()
Disables the stacktrace recording mechanism that allows to trace a comments origin within the graja codebase
-
getStackdump
public ArrayList<StackTraceElement> getStackdump()
Only relevant for the regression testing mechanism.Generates a filtered stackdump consisting out of
StackTraceElement
s without the first two irrelevant stackframes.- Returns:
- filtered stackdump
- Throws:
UnsupportedOperationException
- if no recording has been created
-
-