Class Template


  • public abstract class Template
    extends java.lang.Object
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected javax.servlet.ServletContext application  
      protected javax.servlet.ServletConfig config  
      protected java.lang.Throwable exception  
      protected javax.servlet.jsp.JspWriter out  
      protected Template page  
      protected javax.servlet.jsp.PageContext pageContext  
      protected javax.servlet.http.HttpServletRequest request  
      protected javax.servlet.http.HttpServletResponse response  
      protected javax.servlet.http.HttpSession session  
    • Constructor Summary

      Constructors 
      Constructor Description
      Template​(javax.servlet.jsp.PageContext pc)  
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected void attribute​(java.lang.String key, boolean b)
      Boolean attribute: write the key if the value is true.
      protected void attribute​(java.lang.String key, java.lang.Object v)
      Attribute: If the value is empty, writes just the key, otherwise key and value, quoted.
      protected java.lang.String escape​(int i)
      Escapes an int for html: just convert it to String.
      protected java.lang.String escape​(java.lang.Object o)
      escape for html: ≤ & Called from generated write().
      protected void forward​(java.lang.String u)
      Forward.
      protected java.lang.String quote​(java.lang.Object o)
      Quotes a value so that it can be an attribute's value.
      protected void redirect​(java.lang.String location)
      Sends a temporary redirect response to the client using the specified redirect location URL.
      abstract void render()
      This is the method that template must implement.
      protected java.lang.String unquote​(java.lang.Object o)
      Escapes " by " .
      Template write​(int i)
      Writes an int to out.
      Template write​(java.lang.Object o)
      Writes an object to out.
      Template write​(java.lang.String s)
      Writes a String to out.
      Template writeln()
      Write a string to output.
      Template writeln​(java.lang.String s)
      Write a string to output.
      • Methods inherited from class java.lang.Object

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

      • request

        protected javax.servlet.http.HttpServletRequest request
      • response

        protected javax.servlet.http.HttpServletResponse response
      • pageContext

        protected javax.servlet.jsp.PageContext pageContext
      • session

        protected javax.servlet.http.HttpSession session
      • application

        protected javax.servlet.ServletContext application
      • out

        protected javax.servlet.jsp.JspWriter out
      • config

        protected javax.servlet.ServletConfig config
      • exception

        protected java.lang.Throwable exception
    • Constructor Detail

      • Template

        public Template​(javax.servlet.jsp.PageContext pc)
    • Method Detail

      • render

        public abstract void render()
                             throws java.lang.Exception
        This is the method that template must implement.
        Throws:
        java.lang.Exception - Java-islands threw an exception.
      • redirect

        protected void redirect​(java.lang.String location)
                         throws java.io.IOException
        Sends a temporary redirect response to the client using the specified redirect location URL. This method can accept relative URLs; the servlet container must convert the relative URL to an absolute URL before sending the response to the client. If the location is relative without a leading '/' the container interprets it as relative to the current request URI. If the location is relative with a leading '/' the container interprets it as relative to the servlet container root. If the response has already been committed, this method throws an IllegalStateException. After using this method, the response should be considered to be committed and should not be written to. After redirect, template execution continues. There will be no more output to the response, but maybe there are other effects. In order to avoid it, you can follow it by if(true) return; Uses status code 302.
        Parameters:
        location - the redirect location URL, can be relative
        Throws:
        java.io.IOException - If an input or output exception occurs
        java.lang.IllegalStateException - If the response was committed or if a partial URL is given and cannot be converted into a valid URL
      • forward

        protected void forward​(java.lang.String u)
                        throws javax.servlet.ServletException,
                               java.io.IOException
        Forward. After forward, template execution continues. There will be no more output to the response, but maybe there are other effects. In order to avoid it, you can follow it by if(true) return;
        Parameters:
        u - the forward location URL, can be relative
        Throws:
        javax.servlet.ServletException - if the target resource throws this exception
        java.io.IOException - if the target resource throws this exception
        java.lang.IllegalStateException - If the response was committed or if a partial URL is given and cannot be converted into a valid URL
      • quote

        protected final java.lang.String quote​(java.lang.Object o)
        Quotes a value so that it can be an attribute's value. Escapes " by " and encloses in ". For null returns quote(""). Called from generated write().
        Parameters:
        o - object
        Returns:
        quoted
      • unquote

        protected final java.lang.String unquote​(java.lang.Object o)
        Escapes " by " . For null returns "". Called from generated write().
        Parameters:
        o - Object
      • escape

        protected final java.lang.String escape​(java.lang.Object o)
        escape for html: ≤ & Called from generated write().
        Parameters:
        o - Object
        Returns:
        escaped
      • escape

        protected final java.lang.String escape​(int i)
        Escapes an int for html: just convert it to String. Called from generated write().
        Parameters:
        i - int
        Returns:
        escaped
      • attribute

        protected final void attribute​(java.lang.String key,
                                       boolean b)
                                throws java.io.IOException
        Boolean attribute: write the key if the value is true. Called from generated write().
        Parameters:
        key - key
        b - value
        Throws:
        java.io.IOException - couldn't write
      • attribute

        protected final void attribute​(java.lang.String key,
                                       java.lang.Object v)
                                throws java.io.IOException
        Attribute: If the value is empty, writes just the key, otherwise key and value, quoted.
        Parameters:
        key - key
        v - value
        Throws:
        java.io.IOException - bad IO
      • write

        public final Template write​(int i)
                             throws java.io.IOException
        Writes an int to out. Called from generated write().
        Throws:
        java.io.IOException
      • write

        public final Template write​(java.lang.Object o)
                             throws java.io.IOException
        Writes an object to out. Does nothing if the object is empty (null or its toString() is null or "").
        Throws:
        java.io.IOException
      • write

        public final Template write​(java.lang.String s)
                             throws java.io.IOException
        Writes a String to out. Does nothing if the String is null or "".
        Throws:
        java.io.IOException
      • writeln

        public final Template writeln()
                               throws java.io.IOException
        Write a string to output.
        Throws:
        java.io.IOException
      • writeln

        public final Template writeln​(java.lang.String s)
                               throws java.io.IOException
        Write a string to output.
        Throws:
        java.io.IOException