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:
  • Field Details

  • Constructor Details

    • 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 prefix
      includeSpec - an optional include spec
  • Method Details

    • setGlobalIncludeInfo

      public static void setGlobalIncludeInfo(IncludeInfo info)
      This method configures the html content classes to exclude all content not included by info. 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 to appender. Subclasses can also implement an own version of this method. The javascript content will be rendered only once when calling Content#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.
    • isInlineContent

      public abstract boolean isInlineContent()
      Returns:
      true, if this content can be used as a child content of a Paragraph.
    • equals

      public boolean equals(Object obj)
      Two Content are equal, when their getIncludeSpec() are equal.
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
      See Also:
    • 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 class Object
      See Also:
    • renderHtml

      public void renderHtml(StringBuilder appender, IncludeInfo includeInfo, String namespace, boolean useJavascript)
      render content to HTML.
      Parameters:
      appender - HTML code result
      includeInfo - 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 result
      includeInfo - 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 result
      includeInfo - controls, which content to be rendered.
      ctx - render context
      useJavascript - 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 result
      includeInfo - 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 result
      includeInfo - 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 result
      includeInfo - 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.
    • highlight

      public Action highlight()
      Returns:
      an object that can be used to render a javascript snippet that highlights content
    • dehighlight

      public Action dehighlight()
      Returns:
      an object that can be used to render a javascript snippet that dehighlights content
    • 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(Action action)
      Register an action that will be rendered by hide().
    • onHide

      public Content onHide(Iterable<Action> actions)
      Register actions that will be rendered by hide().
    • onShow

      public Content onShow(Action action)
      Register an action that will be rendered by show().
    • onShow

      public Content onShow(Iterable<Action> actions)
      Register actions that will be rendered by show().
    • 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 given functionName. The function is implemented by calling the given delegate.
      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 StackTraceElements without the first two irrelevant stackframes.

      Returns:
      filtered stackdump
      Throws:
      UnsupportedOperationException - if no recording has been created