Class HtmlPageRenders


  • public class HtmlPageRenders
    extends java.lang.Object
    Utilities for implementing HTML-based PageRenderer.
    Since:
    5.0.0
    Author:
    tomyeh
    • Constructor Summary

      Constructors 
      Constructor Description
      HtmlPageRenders()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static HtmlPageRenders.RenderContext getRenderContext​(Execution exec)
      Returns the render context, or null if not available.
      static java.util.List<StyleSheet> getStyleSheets​(Execution exec, WebApp wapp, java.lang.String deviceType)
      Returns a list of StyleSheet that shall be generated to the client for the specified execution.
      static boolean isDirectContent​(Execution exec)
      Returns whether a component can directly generate HTML tags to the output.
      static boolean isZkTagsGenerated​(Execution exec)
      Returns if the ZK specific HTML tags are generated.
      static java.lang.String outDocType​(Execution exec, Page page)
      Returns the doc type, or null if not available.
      static java.lang.String outFirstLine​(Execution exec, Page page)
      Returns the first line to be generated to the output, or null if no special first line.
      static java.lang.String outHeaders​(Execution exec, Page page, boolean before)
      Returns the content of the specified condition that will be placed inside the header element of the specified page, or null if it was generated before.
      static java.lang.String outHeaderZkTags​(Execution exec, Page page)
      Generates and returns the ZK specific HTML tags including the headers defined in the specified page, or null if it was generated before.
      static java.lang.String outInitCrashScript​(Execution exec, WebApp wapp)
      Returns Script tag to include init-crash-script and init-crash-timeout defined in zk.xml
      static java.lang.String outLangJavaScripts​(Execution exec, WebApp wapp, java.lang.String deviceType)
      Returns HTML tags to include all JavaScript files and codes that are required when loading a ZUML page (never null).
      static java.lang.String outLangStyleSheets​(Execution exec, WebApp wapp, java.lang.String deviceType)
      Returns HTML tags to include all style sheets that are defined in all languages of the specified device (never null).
      static void outPageContent​(Execution exec, Page page, java.io.Writer out, boolean au)
      Returns the HTML content representing a page.
      static java.lang.String outResponseJavaScripts​(Execution exec)
      Generates the AU responses that are part of a page rendering.
      static java.lang.String outResponseJavaScripts​(Execution exec, boolean directJS)
      Generates the AU responses that are part of a page rendering.
      static void outSEOContent​(Page page, java.io.Writer out)
      Generates the SEO content for the given page.
      static java.lang.String outSpecialJS​(Desktop desktop)
      Generates the special JavaScript code, such as the application's name.
      static void outStandalone​(Execution exec, Component comp, java.io.Writer out)
      Generates the content of a standalone component that the peer widget is not a child of the page widget at the client.
      static java.lang.String outUnavailable​(Execution exec)
      Generates the unavailable message in HTML tags, if any.
      static java.lang.String outZkTags​(Execution exec, WebApp wapp, java.lang.String deviceType)
      Generates and returns the ZK specific HTML tags such as stylesheet and JavaScript.
      static void setContentType​(Execution exec, Page page)
      Sets the content type to the specified execution for the given page.
      static boolean setDirectContent​(Execution exec, boolean direct)
      Sets whether a component can directly generate HTML tags to the output.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • HtmlPageRenders

        public HtmlPageRenders()
    • Method Detail

      • setContentType

        public static final void setContentType​(Execution exec,
                                                Page page)
        Sets the content type to the specified execution for the given page.
        Parameters:
        exec - the execution (never null)
      • outDocType

        public static final java.lang.String outDocType​(Execution exec,
                                                        Page page)
        Returns the doc type, or null if not available. It is null or <!DOCTYPE ...>.
      • outUnavailable

        public static java.lang.String outUnavailable​(Execution exec)
        Generates the unavailable message in HTML tags, if any.
        Parameters:
        exec - the execution (never null)
      • outFirstLine

        public static final java.lang.String outFirstLine​(Execution exec,
                                                          Page page)
        Returns the first line to be generated to the output, or null if no special first line.
      • outResponseJavaScripts

        public static final java.lang.String outResponseJavaScripts​(Execution exec,
                                                                    boolean directJS)
        Generates the AU responses that are part of a page rendering. Notice that outPageContent(org.zkoss.zk.ui.Execution, org.zkoss.zk.ui.Page, java.io.Writer, boolean) will invoke this method automatically.
        Parameters:
        directJS - whether to generate JS directly. If true, it generates "x,y" where x and y are assumed to the responses. If false, it generates <script>zkac(x,y);</script>
        Since:
        5.0.2
      • outLangJavaScripts

        public static final java.lang.String outLangJavaScripts​(Execution exec,
                                                                WebApp wapp,
                                                                java.lang.String deviceType)
        Returns HTML tags to include all JavaScript files and codes that are required when loading a ZUML page (never null).

        FUTURE CONSIDERATION: we might generate the inclusion on demand instead of all at once.

        Parameters:
        exec - the execution (never null)
        wapp - the Web application. If null, exec.getDesktop().getWebApp() is used. So you have to specify it if the execution is not associated with desktop (a fake execution, such as JSP/DSP).
        deviceType - the device type, such as ajax. If null, exec.getDesktop().getDeviceType() is used. So you have to specify it if the execution is not associated with desktop (a fake execution).
      • outLangStyleSheets

        public static final java.lang.String outLangStyleSheets​(Execution exec,
                                                                WebApp wapp,
                                                                java.lang.String deviceType)
        Returns HTML tags to include all style sheets that are defined in all languages of the specified device (never null).

        In addition to style sheets defined in lang.xml and lang-addon.xml, it also include:

        1. The style sheet specified in the theme-uri parameter.

        FUTURE CONSIDERATION: we might generate the inclusion on demand instead of all at once.

        Parameters:
        exec - the execution (never null)
        wapp - the Web application. If null, exec.getDesktop().getWebApp() is used. So you have to specify it if the execution is not associated with desktop (a fake execution, such as JSP/DSP).
        deviceType - the device type, such as ajax. If null, exec.getDesktop().getDeviceType() is used. So you have to specify it if the execution is not associated with desktop (a fake execution).
      • getStyleSheets

        public static final java.util.List<StyleSheet> getStyleSheets​(Execution exec,
                                                                      WebApp wapp,
                                                                      java.lang.String deviceType)
        Returns a list of StyleSheet that shall be generated to the client for the specified execution.
        Parameters:
        exec - the execution (never null)
        wapp - the Web application. If null, exec.getDesktop().getWebApp() is used. So you have to specify it if the execution is not associated with desktop (a fake execution, such as JSP/DSP).
        deviceType - the device type, such as ajax. If null, exec.getDesktop().getDeviceType() is used. So you have to specify it if the execution is not associated with desktop (a fake execution).
      • outPageContent

        public static final void outPageContent​(Execution exec,
                                                Page page,
                                                java.io.Writer out,
                                                boolean au)
                                         throws java.io.IOException
        Returns the HTML content representing a page.
        Parameters:
        au - whether it is caused by asynchronous update
        exec - the execution (never null)
        Throws:
        java.io.IOException
      • outSEOContent

        public static void outSEOContent​(Page page,
                                         java.io.Writer out)
                                  throws java.io.IOException
        Generates the SEO content for the given page. Nothing is generated if the SEO content has been generated or it shall not be generated.

        The SEO content shall be placed inside <div class="z-temp">.

        If a page renderer generates <div class="z-temp"> by itself, it must invoke this method.

        Throws:
        java.io.IOException
        Since:
        5.0.9
      • outSpecialJS

        public static final java.lang.String outSpecialJS​(Desktop desktop)
        Generates the special JavaScript code, such as the application's name. It shall be called, before generating "zkmx(" and "zkx(".
        Since:
        5.0.6
      • outStandalone

        public static final void outStandalone​(Execution exec,
                                               Component comp,
                                               java.io.Writer out)
                                        throws java.io.IOException
        Generates the content of a standalone component that the peer widget is not a child of the page widget at the client.
        Parameters:
        comp - the component to render. It is null if no child component at all.
        Throws:
        java.io.IOException
      • outHeaders

        public static final java.lang.String outHeaders​(Execution exec,
                                                        Page page,
                                                        boolean before)
        Returns the content of the specified condition that will be placed inside the header element of the specified page, or null if it was generated before. For HTML, the header element is the HEAD element.

        Notice that this method ignores the following invocations against the same page in the same execution. In other words, it is safe to invoke this method multiple times.

        Parameters:
        before - whether to return the headers that shall be shown before ZK's CSS/JS headers. If true, only the headers that shall be shown before (such as meta) are returned. If true, only the headers that shall be shown after (such as link) are returned.
      • outZkTags

        public static java.lang.String outZkTags​(Execution exec,
                                                 WebApp wapp,
                                                 java.lang.String deviceType)
        Generates and returns the ZK specific HTML tags such as stylesheet and JavaScript.

        For each desktop, we have to generate a set of HTML tags to load ZK Client engine, style sheets and so on. For ZUL pages, it is generated automatically by page.dsp. However, for ZHTML pages, we have to generate these tags with special component such as org.zkoss.zhtml.Head, such that the result HTML page is legal.

        Parameters:
        exec - the execution (never null)
        wapp - the Web application. If null, exec.getDesktop().getWebApp() is used. So you have to specify it if the execution is not associated with desktop (a fake execution, such as JSP/DSP).
        deviceType - the device type, such as ajax. If null, exec.getDesktop().getDeviceType() is used. So you have to specify it if the execution is not associated with desktop (a fake execution).
        Returns:
        the string holding the HTML tags, or null if already generated.
        See Also:
        outHeaderZkTags(org.zkoss.zk.ui.Execution, org.zkoss.zk.ui.Page)
      • isZkTagsGenerated

        public static boolean isZkTagsGenerated​(Execution exec)
        Returns if the ZK specific HTML tags are generated.
        Since:
        5.0.3