seade       2003/09/01 23:25:49

  Modified:    src/java/org/apache/turbine/util/template
                        HtmlPageAttributes.java
               xdocs/howto velocityonlylayout-howto.xml
               src/java/org/apache/turbine/modules/pages DefaultPage.java
  Log:
  Provide the ability to produce the default doctype definition when using 
VelocityOnlyLayout.
  Also removed a bunch of extra question marks that came across when the howto 
document was converted from the wiki.
  
  Revision  Changes    Path
  1.9       +131 -1    
jakarta-turbine-2/src/java/org/apache/turbine/util/template/HtmlPageAttributes.java
  
  Index: HtmlPageAttributes.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/util/template/HtmlPageAttributes.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- HtmlPageAttributes.java   9 May 2003 11:07:02 -0000       1.8
  +++ HtmlPageAttributes.java   2 Sep 2003 06:25:48 -0000       1.9
  @@ -58,12 +58,16 @@
   import java.util.List;
   import java.util.Map;
   import java.util.ArrayList;
  +import java.util.Vector;
   
   import org.apache.commons.lang.StringUtils;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  +import org.apache.turbine.Turbine;
  +import org.apache.turbine.TurbineConstants;
   import org.apache.turbine.services.pull.ApplicationTool;
   import org.apache.turbine.util.RunData;
  +import org.apache.turbine.util.TurbineException;
   
   /**
    * Template context tool that can be used to set various attributes of a
  @@ -153,6 +157,9 @@
       /** http-equiv tags */
       private Map httpEquivs = new HashMap();
   
  +    /** Doctype */
  +    private static String doctype = null;
  +
       /**
        * Default constructor. The init method must be called before use
        */
  @@ -652,4 +659,127 @@
           }
   
       }
  +    
  +    /**
  +     * Retrieve the default Doctype.  If Doctype is set to null, then an empty
  +     * string will be returned.  The default Doctype can be set in
  +     * TurbineResources as three strings giving the tag (e.g. "HTML"), dtd (e.g. 
  +     * "-//W3C//DTD HTML 4.01 Transitional//EN") and uri (e.g. 
  +     * "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd";).  For
  +     * backwards compatibility the default can be set using one of the single 
  +     * strings: Html40Strict, Html40Transitional, or Html40Frameset or as two 
  +     * strings providing the the dtd and uri (tag is assumed to be "HTML") - 
  +     * all but the three string configuration will result in an info level 
  +     * deprecation message being written to the log.
  +     *
  +     * @exception TurbineException If the default doctype is not specified in 
  +     * TurbineResources.properties.
  +     */
  +    public static String getDefaultDoctype()
  +            throws TurbineException
  +    {
  +        if (doctype == null)
  +        {
  +            String errMsg = "default.doctype property not set properly in " 
  +                    + "TurbineResources.properties!";
  +            Vector doctypeProperty = Turbine.getConfiguration()
  +                    .getVector(TurbineConstants.DEFAULT_DOCUMENT_TYPE_KEY);
  +
  +            if (doctypeProperty != null)
  +            {
  +                String tag;
  +                String identifier;
  +                String uri;
  +                switch(doctypeProperty.size())
  +                {
  +                case 1:
  +                    {
  +                        String doc = (String) doctypeProperty.firstElement();
  +                        tag = "HTML";
  +                        identifier = "-//W3C//DTD HTML 4.0 ";
  +                        uri = "http://www.w3.org/TR/REC-html40/";;
  +                        if (doc.equalsIgnoreCase(
  +                             TurbineConstants.DOCUMENT_TYPE_HTML40TRANSITIONAL))
  +                        {
  +                            identifier += "Transitional";
                            uri += "loose";
  +                        }
  +                        else if (doc.equalsIgnoreCase(
  +                                TurbineConstants.DOCUMENT_TYPE_HTML40STRICT))
  +                        {
  +                            uri += "strict";
  +                        }
  +                        else if (doc.equalsIgnoreCase(
  +                                TurbineConstants.DOCUMENT_TYPE_HTML40FRAMESET))
  +                        {
  +                            identifier = "Frameset";
  +                            uri += "frameset";
  +                        }
  +                        else
  +                        {
  +                            throw new TurbineException(errMsg);
  +                        }
  +                        identifier += "//EN";
  +                        uri += ".dtd";
  +
  +                        log.info("Defining default.doctype with a single string"
  +                            + " in TurbineResources.properties is deprecated.  "
  +                            + "Please use three strings instead (tag, dtd and "
  +                            + "uri).");
  +                        break;
  +                    }
  +                case 2:
  +                    {
  +                        tag = "HTML";
  +                        identifier = (String) doctypeProperty.elementAt(0); 
  +                        uri = (String) doctypeProperty.elementAt(1);
  +
  +                        log.info("Defining default.doctype with two strings"
  +                            + " in TurbineResources.properties is deprecated.  "
  +                            + "Please use three strings instead (tag, dtd and "
  +                            + "uri).");
  +                        break;
  +                    }
  +                case 3:
  +                    {
  +                        tag = (String) doctypeProperty.elementAt(0);
  +                        identifier = (String) doctypeProperty.elementAt(1); 
  +                        uri = (String) doctypeProperty.elementAt(2);
  +                        break;
  +                    }
  +                default:
  +                    {
  +                        throw new TurbineException(errMsg);
  +                    }
  +                }
  +                doctype = getDoctype(tag, identifier, uri);
  +            }
  +            else
  +            {
  +                doctype = "";
  +            }
  +        }
  +
  +        return doctype;
  +    }
  +    
  +    /**
  +     * Build the doctype element.
  +     * 
  +     * @param tag the tag whose DTD is being declared.
  +     * @param identifier the identifier for the doctype declaration.
  +     * @param uri the uri for the doctype declaration.
  +     * @return the doctype.
  +     */
  +    private static String getDoctype(String tag, String identifier, String uri)
  +    {
  +        StringBuffer doctypeBuf = new StringBuffer("<!DOCTYPE ");
  +        doctypeBuf.append(tag);
  +        doctypeBuf.append(" PUBLIC \"");
  +        doctypeBuf.append(identifier);
  +        doctypeBuf.append("\" \"");
  +        doctypeBuf.append(uri);
  +        doctypeBuf.append("\">");
  +        return doctypeBuf.toString();
  +    }
  +    
   }
  
  
  
  1.3       +39 -25    jakarta-turbine-2/xdocs/howto/velocityonlylayout-howto.xml
  
  Index: velocityonlylayout-howto.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-2/xdocs/howto/velocityonlylayout-howto.xml,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- velocityonlylayout-howto.xml      2 Sep 2003 04:38:51 -0000       1.2
  +++ velocityonlylayout-howto.xml      2 Sep 2003 06:25:49 -0000       1.3
  @@ -45,7 +45,7 @@
   </p>
   <source>
   <![CDATA[
  -services.VelocityService?.default.layout = VelocityOnlyLayout
  +services.VelocityService.default.layout = VelocityOnlyLayout
   ]]>
   </source>
   
  @@ -55,15 +55,15 @@
   <p>
     <ul>
        <li>$page.addAttribute(attribute,value) has been replaced with 
  -         $page.addBodyAttribute?(attribute,value)</li>
  +         $page.addBodyAttribute(attribute,value)</li>
        <li>$page.setScript(url) has been replaced with 
            $page.addScript(url)</li>
  -     <li>$page.setStyleSheet?(url) has been replaced with 
  -         $page.addStyleSheet?(url)</li>
  +     <li>$page.setStyleSheet(url) has been replaced with 
  +         $page.addStyleSheet(url)</li>
        <li>$page.setStyle(styleText) has been replaced with 
            $page.addStyle(styleText)</li>
  -     <li>$page.setStyleSheet?(url,media) has been replaced with 
  -         $page.addStyleSheet?(url,media,title,type)</li>
  +     <li>$page.setStyleSheet(url,media) has been replaced with 
  +         $page.addStyleSheet(url,media,title,type)</li>
     </ul>
   </p>
   <p>
  @@ -75,7 +75,7 @@
   </p>
   <source>
   <![CDATA[
  -services.VelocityService?.velocimacro.library = macros/TurbineMacros?.vm
  +services.VelocityService.velocimacro.library = macros/TurbineMacros.vm
   ]]>
   </source>
   <p>
  @@ -84,6 +84,18 @@
       these macros follows.
   </p>
   <p>
  +    Add the line
  +</p>
  +<source>
  +<![CDATA[
  +     $page.DefaultDoctype
  +]]>
  +</source>
  +<p>
  +    to your templates to pick up the default doctype definition from
  +    TurbineResources.properties.
  +</p>
  +<p>
       Here is a sample layout template that you can use:
   </p>
   <source>
  @@ -91,14 +103,15 @@
       ## Set defaults for all pages using this layout.  Anything set here can
       ## be overridden in the screen template.
       $page.setTitle("My default page title");
  -    $page.setHttpEquiv?("Content-Style-Type","text/css")
  -    $page.addStyleSheet?($content.getURI("myStyleSheet?.css"))
  -    $page.addScript($content.getURI("globalJavascriptCode?.js"))
  +    $page.setHttpEquiv("Content-Style-Type","text/css")
  +    $page.addStyleSheet($content.getURI("myStyleSheet.css"))
  +    $page.addScript($content.getURI("globalJavascriptCode.js"))
       ## build the HTML, HEAD, and BODY tags dynamically
   
  +     $page.DefaultDoctype
       <html>
  -      #TurbineHtmlHead?()
  -      <body #TurbineHtmlBodyAttributes?() >
  +      #TurbineHtmlHead()
  +      <body #TurbineHtmlBodyAttributes() >
         $navigation.setTemplate("default_header.vm")
         $screen_placeholder
         $navigation.setTemplate("default_footer.vm")
  @@ -116,38 +129,39 @@
       ## Set defaults for all pages using this layout.  Anything set here can
       ## be overridden in the screen template.
       $page.setTitle("My default page title");
  -    $page.setHttpEquiv?("Content-Style-Type","text/css")
  -    $page.addStyleSheet?($content.getURI("myStyleSheet?.css"))
  -    $page.addScript($content.getURI("globalJavascriptCode?.js"))
  +    $page.setHttpEquiv("Content-Style-Type","text/css")
  +    $page.addStyleSheet($content.getURI("myStyleSheet.css"))
  +    $page.addScript($content.getURI("globalJavascriptCode.js"))
       ## build the HTML, HEAD, and BODY tags dynamically
   
  +     $page.DefaultDoctype
       <html>
         <head>
  -        #if( $page.Title != "" )
  +        #if($page.Title != "")
           <title>$page.Title</title>
           #end
  -        #foreach($metaTag in $page.MetaTags?.keySet())
  -        <meta name="$metaTag" content="$page.MetaTags?.get($metaTag)">
  +        #foreach($metaTag in $page.MetaTags.keySet())
  +        <meta name="$metaTag" content="$page.MetaTags.get($metaTag)">
           #end
  -        #foreach($httpEquiv in $page.HttpEquivs?.keySet())
  -        <meta http-equiv="$httpEquiv" content="$page.HttpEquivs?.get($httpEquiv)">
  +        #foreach($httpEquiv in $page.HttpEquivs.keySet())
  +        <meta http-equiv="$httpEquiv" content="$page.HttpEquivs.get($httpEquiv)">
           #end
  -        #foreach( $styleSheet in $page.StyleSheets? )
  +        #foreach($styleSheet in $page.StyleSheets)
             <link rel="stylesheet" href="$styleSheet.Url"
               #if($styleSheet.Type != "" ) type="$styleSheet.Type" #end
               #if($styleSheet.Media != "") media="$styleSheet.Media" #end
               #if($styleSheet.Title != "") title="$styleSheet.Title" #end
             >
           #end
  -        #foreach( $script in $page.Scripts )
  -          <script type="text/javascript" src="$script" 
language="JavaScript?"></script>
  +        #foreach($script in $page.Scripts)
  +          <script type="text/javascript" src="$script" 
language="JavaScript"></script>
           #end
         </head>
   
         ## Construct the body tag.  Iterate through the body attributes to build the 
opening tag
         <body
  -        #foreach( $attributeName in $page.BodyAttributes?.keySet() )
  -          $attributeName = "$page.BodyAttributes?.get($attributeName)"
  +        #foreach($attributeName in $page.BodyAttributes.keySet())
  +          $attributeName = "$page.BodyAttributes.get($attributeName)"
           #end
         >
   
  
  
  
  1.8       +10 -1     
jakarta-turbine-2/src/java/org/apache/turbine/modules/pages/DefaultPage.java
  
  Index: DefaultPage.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/modules/pages/DefaultPage.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- DefaultPage.java  9 Mar 2003 02:41:46 -0000       1.7
  +++ DefaultPage.java  2 Sep 2003 06:25:49 -0000       1.8
  @@ -284,6 +284,15 @@
                                       .setUri((String) doctypeProperty.elementAt(1)));
                       break;
                   }
  +            case 3:
  +                {
  +                    // Ignore first string as the tag value is provided by ECS.
  +                    data.getPage()
  +                        .setDoctype(new Doctype()
  +                                    .setIdentifier((String) 
doctypeProperty.elementAt(1))
  +                                    .setUri((String) doctypeProperty.elementAt(2)));
  +                    break;
  +                }
               default:
                   {
                       throw new TurbineException(errMsg);
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to