Author: jcompagner
Date: Wed May  7 15:38:20 2008
New Revision: 654312

URL: http://svn.apache.org/viewvc?rev=654312&view=rev
Log:
WICKET-1507 MarkupCache style/variation/locale support broken (merge from 1.3)

Added:
    
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/MarkupInheritanceBase_1_style1.html
      - copied unchanged from r654304, 
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/MarkupInheritanceBase_1_style1.html
    
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/MarkupInheritanceBase_1_style2.html
      - copied unchanged from r654304, 
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/MarkupInheritanceBase_1_style2.html
    
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/MarkupInheritanceExpectedResult_1_style1.html
      - copied unchanged from r654304, 
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/MarkupInheritanceExpectedResult_1_style1.html
    
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/MarkupInheritanceExpectedResult_1_style2.html
      - copied unchanged from r654304, 
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/MarkupInheritanceExpectedResult_1_style2.html
Modified:
    wicket/trunk/wicket/   (props changed)
    wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/Markup.java
    wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/MarkupCache.java
    
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/MarkupResourceData.java
    wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/MergedMarkup.java
    
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/MarkupInheritanceTest.java

Propchange: wicket/trunk/wicket/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed May  7 15:38:20 2008
@@ -1 +1 @@
-/wicket/branches/wicket-1.3.x/jdk-1.4/wicket:653208,653212,653215,653226,653231
+/wicket/branches/wicket-1.3.x/jdk-1.4/wicket:653208,653212,653215,653226,653231,654304

Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/Markup.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/Markup.java?rev=654312&r1=654311&r2=654312&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/Markup.java 
(original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/Markup.java Wed 
May  7 15:38:20 2008
@@ -97,6 +97,19 @@
        {
                return markupResourceData;
        }
+       
+       /**
+        * Allowing the markup to return its own location allows special types 
of Markup
+        * (i.e. MergedMarkup) to override their location, as they are composed 
of multiple
+        * Markups in different locations.
+        * SEE WICKET-1507 (Jeremy Thomerson)
+        * @return the location of this markup
+        */
+       public String locationAsString()
+       {
+               return markupResourceData.getResource().locationAsString();
+       }
+
 
        /**
         * For Wicket it would be sufficient for this method to be package 
protected. However to allow

Modified: 
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/MarkupCache.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/MarkupCache.java?rev=654312&r1=654311&r2=654312&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/MarkupCache.java 
(original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/MarkupCache.java 
Wed May  7 15:38:20 2008
@@ -436,6 +436,9 @@
 
                        if (cacheKey != null)
                        {
+                               if (markup.locationAsString() != null) {
+                                       locationString = 
markup.locationAsString();
+                               }
                                // add the markup to the cache.
                                markupKeyCache.put(cacheKey, locationString);
                                return putIntoCache(locationString, markup);

Modified: 
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/MarkupResourceData.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/MarkupResourceData.java?rev=654312&r1=654311&r2=654312&view=diff
==============================================================================
--- 
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/MarkupResourceData.java
 (original)
+++ 
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/MarkupResourceData.java
 Wed May  7 15:38:20 2008
@@ -40,8 +40,8 @@
        /** The markup's resource stream */
        private MarkupResourceStream resource;
 
-       /** In case of the inherited markup, the base markup's resource stream 
*/
-       private MarkupResourceData baseMarkupResourceData;
+       /** In case of the inherited markup, this is the base markup */
+       private Markup baseMarkup;
 
        /** If found in the markup, the <?xml ...?> string */
        private String xmlDeclaration;
@@ -116,7 +116,7 @@
         */
        public String getWicketNamespace()
        {
-               return this.wicketNamespace;
+               return wicketNamespace;
        }
 
        /**
@@ -148,7 +148,7 @@
        public final void setWicketNamespace(final String wicketNamespace)
        {
                this.wicketNamespace = wicketNamespace;
-               this.wicketId = wicketNamespace + ":id";
+               wicketId = wicketNamespace + ":id";
 
                if 
(!ComponentTag.DEFAULT_WICKET_NAMESPACE.equals(wicketNamespace))
                {
@@ -185,17 +185,29 @@
         */
        public MarkupResourceData getBaseMarkupResourceData()
        {
-               return this.baseMarkupResourceData;
+               if (baseMarkup == null)
+                       return null;
+               return baseMarkup.getMarkupResourceData();
+       }
+
+       /**
+        * In case of markup inheritance, the base markup.
+        * 
+        * @param baseMarkup
+        *            The base markup
+        */
+       public void setBaseMarkup(Markup baseMarkup)
+       {
+               this.baseMarkup = baseMarkup;
        }
 
        /**
         * In case of markup inheritance, the base markup resource.
         * 
-        * @param baseMarkupResourceData
-        *            The base markup resource
+        * @return The base markup
         */
-       public void setBaseMarkupResourceData(MarkupResourceData 
baseMarkupResourceData)
+       public Markup getBaseMarkup()
        {
-               this.baseMarkupResourceData = baseMarkupResourceData;
+               return baseMarkup;
        }
 }
\ No newline at end of file

Modified: 
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/MergedMarkup.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/MergedMarkup.java?rev=654312&r1=654311&r2=654312&view=diff
==============================================================================
--- 
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/MergedMarkup.java 
(original)
+++ 
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/MergedMarkup.java 
Wed May  7 15:38:20 2008
@@ -68,7 +68,7 @@
                
getMarkupResourceData().setEncoding(markup.getMarkupResourceData().getEncoding());
                getMarkupResourceData().setWicketNamespace(
                        markup.getMarkupResourceData().getWicketNamespace());
-               
getMarkupResourceData().setBaseMarkupResourceData(baseMarkup.getMarkupResourceData());
+               getMarkupResourceData().setBaseMarkup(baseMarkup);
 
                if (log.isDebugEnabled())
                {
@@ -94,6 +94,17 @@
                }
        }
 
+       public String locationAsString()
+       {
+               /*
+                * Uses both resource locations so that if the child does not 
have a style and the parent
+                * does, the location is unique to this combination (or vice 
versa) SEE WICKET-1507 (Jeremy
+                * Thomerson)
+                */
+               return 
getMarkupResourceData().getBaseMarkup().locationAsString() + ":" +
+                       
getMarkupResourceData().getResource().locationAsString();
+       }
+
        /**
         * Merge inherited and base markup.
         * 

Modified: 
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/MarkupInheritanceTest.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/MarkupInheritanceTest.java?rev=654312&r1=654311&r2=654312&view=diff
==============================================================================
--- 
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/MarkupInheritanceTest.java
 (original)
+++ 
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/MarkupInheritanceTest.java
 Wed May  7 15:38:20 2008
@@ -18,6 +18,7 @@
 
 import org.apache.wicket.WicketTestCase;
 import org.apache.wicket.markup.html.link.Link;
+import org.apache.wicket.protocol.http.WebRequestCycle;
 import org.apache.wicket.util.diff.DiffUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -41,6 +42,31 @@
        }
 
        /**
+        * TEST FOR WICKET-1507
+        * @throws Exception
+        */
+       public void testRenderChildPageWithStyleVariation() throws Exception
+       {
+               // first, render page with no style
+               executeTest(MarkupInheritanceExtension_1.class, 
"MarkupInheritanceExpectedResult_1.html");
+
+               // then, render with style1
+               tester.setupRequestAndResponse();
+               WebRequestCycle cycle = tester.createRequestCycle();
+               cycle.getSession().setStyle("style1");
+               tester.startPage(MarkupInheritanceExtension_1.class);
+               tester.assertRenderedPage(MarkupInheritanceExtension_1.class);
+               tester.assertResultPage(getClass(), 
"MarkupInheritanceExpectedResult_1_style1.html");
+
+               // then, render with style2
+               tester.setupRequestAndResponse();
+               cycle = tester.createRequestCycle();
+               cycle.getSession().setStyle("style2");
+               tester.startPage(MarkupInheritanceExtension_1.class);
+               tester.assertRenderedPage(MarkupInheritanceExtension_1.class);
+               tester.assertResultPage(getClass(), 
"MarkupInheritanceExpectedResult_1_style2.html");
+       }
+       /**
         * @throws Exception
         */
        public void testRenderHomePage_1() throws Exception


Reply via email to