Author: hlship
Date: Sun Jan 11 15:53:02 2009
New Revision: 733547

URL: http://svn.apache.org/viewvc?rev=733547&view=rev
Log:
TAP5-446: Tapestry should output a <meta> tag to identify Tapestry as the 
generator (with an option to turn this off for applications that don't want to 
advertise their technology)

Added:
    
tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/include_generator_meta.txt
Modified:
    tapestry/tapestry5/trunk/src/site/apt/guide/conf.apt
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/SymbolConstants.java
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/DocumentLinkerImpl.java
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
    
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/DocumentLinkerImplTest.java

Modified: tapestry/tapestry5/trunk/src/site/apt/guide/conf.apt
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/src/site/apt/guide/conf.apt?rev=733547&r1=733546&r2=733547&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/src/site/apt/guide/conf.apt (original)
+++ tapestry/tapestry5/trunk/src/site/apt/guide/conf.apt Sun Jan 11 15:53:02 
2009
@@ -161,7 +161,11 @@
 
   [tapestry.min-gzip-size]
     The minimum stream size necessary for Tapestry to use GZIP compression on 
the response stream.
-    
+
+  [tapestry.omit-generator-meta]
+    If "true", then the \<meta\> tag that Tapestry normally writes into the 
\<head\>, identifying the Tapestry version,
+    will be omitted.  Use this when you do not wish to advertise your 
application's use of Tapestry.
+
   [tapestry.production-mode]
     A flag (true or false) indicating whether the application is running in 
production or in development. The default
     is true, which means that runtime exceptions are not reported with full 
detail (only the root exception message

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/SymbolConstants.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/SymbolConstants.java?rev=733547&r1=733546&r2=733547&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/SymbolConstants.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/SymbolConstants.java
 Sun Jan 11 15:53:02 2009
@@ -124,4 +124,12 @@
      * @since 5.1.0.0
      */
     public static final String APPLICATION_VERSION = 
"tapestry.application-version";
+
+    /**
+     * Used to omit the normal Tapestry framework generator meta tag. The meta 
tag is rendered by default, but clients
+     * who do not wish to advertise their use of Tapstry may set this symbol 
to "true".
+     *
+     * @since 5.1.0.0
+     */
+    public static final String OMIT_GENERATOR_META = 
"tapestry.omit-generator-meta";
 }

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/DocumentLinkerImpl.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/DocumentLinkerImpl.java?rev=733547&r1=733546&r2=733547&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/DocumentLinkerImpl.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/DocumentLinkerImpl.java
 Sun Jan 11 15:53:02 2009
@@ -1,4 +1,4 @@
-// Copyright 2007, 2008 The Apache Software Foundation
+// Copyright 2007, 2008, 2009 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -36,10 +36,19 @@
 
     private final boolean scriptsAtTop;
 
-    public DocumentLinkerImpl(boolean productionMode, boolean scriptsAtTop)
+    private final boolean omitGeneratorMetaTag;
+
+    private final String tapestryBanner;
+
+    public DocumentLinkerImpl(boolean productionMode, boolean scriptsAtTop, 
boolean omitGeneratorMetaTag,
+                              String tapestryVersion)
     {
+
         developmentMode = !productionMode;
         this.scriptsAtTop = scriptsAtTop;
+        this.omitGeneratorMetaTag = omitGeneratorMetaTag;
+
+        tapestryBanner = String.format("Apache Tapestry Framework (version 
%s)", tapestryVersion);
     }
 
     public void addStylesheetLink(String styleURL, String media)
@@ -82,6 +91,14 @@
         if (!stylesheets.isEmpty())
             addStylesheetsToHead(root, includedStylesheets);
 
+        if (!omitGeneratorMetaTag)
+        {
+            Element head = findOrCreateElement(root, "head", true);
+            head.element("meta",
+                         "name", "generator",
+                         "content", tapestryBanner);
+        }
+
         addScriptElements(root);
     }
 

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java?rev=733547&r1=733546&r2=733547&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
 Sun Jan 11 15:53:02 2009
@@ -1490,6 +1490,12 @@
                                          @Path("${tapestry.spacer-image}")
                                          final Asset spacerImage,
 
+                                         
@Symbol(SymbolConstants.OMIT_GENERATOR_META)
+                                         final boolean omitGeneratorMeta,
+
+                                         @Inject 
@Symbol(SymbolConstants.TAPESTRY_VERSION)
+                                         final String tapestryVersion,
+
                                          final ValidationMessagesSource 
validationMessagesSource,
 
                                          final SymbolSource symbolSource,
@@ -1500,7 +1506,8 @@
         {
             public void renderMarkup(MarkupWriter writer, MarkupRenderer 
renderer)
             {
-                DocumentLinkerImpl linker = new 
DocumentLinkerImpl(productionMode, scriptsAtTop);
+                DocumentLinkerImpl linker = new 
DocumentLinkerImpl(productionMode, scriptsAtTop, omitGeneratorMeta,
+                                                                   
tapestryVersion);
 
                 environment.push(DocumentLinker.class, linker);
 
@@ -1913,6 +1920,7 @@
         configuration.add(SymbolConstants.MIN_GZIP_SIZE, "100");
 
         configuration.add(SymbolConstants.APPLICATION_VERSION, 
Long.toHexString(System.currentTimeMillis()));
+        configuration.add(SymbolConstants.OMIT_GENERATOR_META, "false");
     }
 
 

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/DocumentLinkerImplTest.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/DocumentLinkerImplTest.java?rev=733547&r1=733546&r2=733547&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/DocumentLinkerImplTest.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/DocumentLinkerImplTest.java
 Sun Jan 11 15:53:02 2009
@@ -1,4 +1,4 @@
-// Copyright 2007, 2008 The Apache Software Foundation
+// Copyright 2007, 2008, 2009 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -34,7 +34,7 @@
 
         document.newRootElement("not-html").text("not an HTML document");
 
-        DocumentLinkerImpl linker = new DocumentLinkerImpl(true, false);
+        DocumentLinkerImpl linker = new DocumentLinkerImpl(true, false, true, 
"1.2.3");
 
         // Only checked if there's something to link.
 
@@ -60,7 +60,7 @@
 
         document.newRootElement("not-html").text("not an HTML document");
 
-        DocumentLinkerImpl linker = new DocumentLinkerImpl(true, false);
+        DocumentLinkerImpl linker = new DocumentLinkerImpl(true, false, true, 
"1.2.3");
 
         // Only checked if there's something to link.
 
@@ -82,7 +82,7 @@
     {
         Document document = new Document();
 
-        DocumentLinkerImpl linker = new DocumentLinkerImpl(true, false);
+        DocumentLinkerImpl linker = new DocumentLinkerImpl(true, false, true, 
"1.2.3");
 
         linker.addScript("foo.js");
         linker.addScript("doSomething();");
@@ -99,7 +99,7 @@
 
         
document.newRootElement("html").element("body").element("p").text("Ready to be 
updated with scripts.");
 
-        DocumentLinkerImpl linker = new DocumentLinkerImpl(true, false);
+        DocumentLinkerImpl linker = new DocumentLinkerImpl(true, false, true, 
"1.2.3");
 
         linker.addScriptLink("foo.js");
         linker.addScriptLink("bar/baz.js");
@@ -110,6 +110,24 @@
         check(document, "add_script_links.txt");
     }
 
+    /**
+     * TAP5-446
+     */
+    @Test
+    public void include_generator_meta() throws Exception
+    {
+        Document document = new Document(new XMLMarkupModel());
+
+        
document.newRootElement("html").element("body").element("p").text("Ready to be 
marked with generator meta.");
+
+        DocumentLinkerImpl linker = new DocumentLinkerImpl(true, false, false, 
"1.2.3");
+
+        linker.updateDocument(document);
+
+
+        check(document, "include_generator_meta.txt");
+    }
+
     @Test
     public void empty_document_with_scripts_at_top() throws Exception
     {
@@ -117,7 +135,7 @@
 
         document.newRootElement("html");
 
-        DocumentLinkerImpl linker = new DocumentLinkerImpl(true, true);
+        DocumentLinkerImpl linker = new DocumentLinkerImpl(true, true, true, 
"1.2.3");
 
         linker.addStylesheetLink("style.css", "print");
         linker.addScriptLink("foo.js");
@@ -136,7 +154,7 @@
 
         document.newRootElement("html");
 
-        DocumentLinkerImpl linker = new DocumentLinkerImpl(true, false);
+        DocumentLinkerImpl linker = new DocumentLinkerImpl(true, false, true, 
"1.2.3");
 
         linker.addStylesheetLink("style.css", "print");
         linker.addScriptLink("foo.js");
@@ -155,7 +173,7 @@
 
         
document.newRootElement("html").element("body").element("p").text("Ready to be 
updated with scripts at top.");
 
-        DocumentLinkerImpl linker = new DocumentLinkerImpl(true, true);
+        DocumentLinkerImpl linker = new DocumentLinkerImpl(true, true, true, 
"1.2.3");
 
         linker.addScriptLink("foo.js");
         linker.addScriptLink("bar/baz.js");
@@ -173,7 +191,7 @@
 
         
document.newRootElement("html").element("body").element("p").text("Ready to be 
updated with styles.");
 
-        DocumentLinkerImpl linker = new DocumentLinkerImpl(true, false);
+        DocumentLinkerImpl linker = new DocumentLinkerImpl(true, false, true, 
"1.2.3");
 
         linker.addStylesheetLink("foo.css", null);
         linker.addStylesheetLink("bar/baz.css", "print");
@@ -190,7 +208,7 @@
 
         
document.newRootElement("html").element("body").element("p").text("Ready to be 
updated with styles.");
 
-        DocumentLinkerImpl linker = new DocumentLinkerImpl(true, false);
+        DocumentLinkerImpl linker = new DocumentLinkerImpl(true, false, true, 
"1.2.3");
 
         linker.addStylesheetLink("foo.css", null);
         linker.addStylesheetLink("bar/baz.css", "print");
@@ -211,7 +229,7 @@
         document.newRootElement("html").element("head").comment("existing 
head").getParent()
                 .element("body").text("body content");
 
-        DocumentLinkerImpl linker = new DocumentLinkerImpl(true, false);
+        DocumentLinkerImpl linker = new DocumentLinkerImpl(true, false, true, 
"1.2.3");
 
         linker.addStylesheetLink("foo.css", null);
 
@@ -227,7 +245,7 @@
 
         
document.newRootElement("html").element("body").element("p").text("Ready to be 
updated with scripts.");
 
-        DocumentLinkerImpl linker = new DocumentLinkerImpl(true, false);
+        DocumentLinkerImpl linker = new DocumentLinkerImpl(true, false, true, 
"1.2.3");
 
         for (int i = 0; i < 3; i++)
         {
@@ -248,7 +266,7 @@
 
         
document.newRootElement("html").element("body").element("p").text("Ready to be 
updated with scripts.");
 
-        DocumentLinkerImpl linker = new DocumentLinkerImpl(true, false);
+        DocumentLinkerImpl linker = new DocumentLinkerImpl(true, false, true, 
"1.2.3");
 
         linker.addScript("doSomething();");
         linker.addScript("doSomethingElse();");
@@ -265,7 +283,7 @@
 
         
document.newRootElement("html").element("body").element("p").text("Ready to be 
updated with scripts.");
 
-        DocumentLinkerImpl linker = new DocumentLinkerImpl(false, false);
+        DocumentLinkerImpl linker = new DocumentLinkerImpl(false, false, true, 
"1.2.3");
 
         linker.addScriptLink("foo.js");
 
@@ -284,7 +302,7 @@
 
         
document.newRootElement("html").element("notbody").element("p").text("Ready to 
be updated with scripts.");
 
-        DocumentLinkerImpl linker = new DocumentLinkerImpl(true, false);
+        DocumentLinkerImpl linker = new DocumentLinkerImpl(true, false, true, 
"1.2.3");
 
         linker.addScriptLink("foo.js");
 
@@ -293,6 +311,7 @@
         check(document, "no_body_element.txt");
     }
 
+
     @Test
     public void script_written_raw() throws Exception
     {
@@ -300,7 +319,7 @@
 
         
document.newRootElement("html").element("body").element("p").text("Ready to be 
updated with scripts.");
 
-        DocumentLinkerImpl linker = new DocumentLinkerImpl(true, false);
+        DocumentLinkerImpl linker = new DocumentLinkerImpl(true, false, true, 
"1.2.3");
 
         linker.addScript("for (var i = 0; i < 5; i++)  { doIt(i); }");
 

Added: 
tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/include_generator_meta.txt
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/include_generator_meta.txt?rev=733547&view=auto
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/include_generator_meta.txt
 (added)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/include_generator_meta.txt
 Sun Jan 11 15:53:02 2009
@@ -0,0 +1,2 @@
+<?xml version="1.0"?>
+<html><head><meta content="Apache Tapestry Framework (version 1.2.3)" 
name="generator"/></head><body><p>Ready to be marked with generator 
meta.</p></body></html>
\ No newline at end of file


Reply via email to