Author: almaw
Date: Tue Dec  5 14:51:45 2006
New Revision: 482814

URL: http://svn.apache.org/viewvc?view=rev&rev=482814
Log:
WICKET-107 Allow HeaderContributor CSS to set the media type (e.g. print, 
screen).

Modified:
    
incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/behavior/HeaderContributor.java
    
incubator/wicket/trunk/wicket/src/main/java/wicket/behavior/HeaderContributor.java

Modified: 
incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/behavior/HeaderContributor.java
URL: 
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/behavior/HeaderContributor.java?view=diff&rev=482814&r1=482813&r2=482814
==============================================================================
--- 
incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/behavior/HeaderContributor.java
 (original)
+++ 
incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/behavior/HeaderContributor.java
 Tue Dec  5 14:51:45 2006
@@ -136,7 +136,7 @@
                        for (int i = 0; i < len; i++)
                        {
                                contributor.addContributor(new 
CSSReferenceHeaderContributor(scope, resources[i]
-                                               .getPath()));
+                                               .getPath(), null));
                        }
                }
                return contributor;
@@ -211,6 +211,19 @@
                 */
                public CSSHeaderContributor(final String location)
                {
+                       this(location, null);
+               }
+               
+               /**
+                * Construct.
+                * 
+                * @param location
+                *            the location of the CSS file relative to the 
context path.
+                * @param media
+                *            the media type for this CSS ("print", "screen", 
etc.)
+                */
+               public CSSHeaderContributor(final String location, final String 
media)
+               {
                        super(new AbstractReadOnlyModel()
                        {
 
@@ -240,7 +253,12 @@
                                                        b.append("/");
                                                }
                                                b.append((location != null) ? 
location : "");
-                                               b.append("\"></link>");
+                                               if (media != null)
+                                               {
+                                                       b.append("\" media=\"");
+                                                       b.append(media);
+                                               }
+                                               b.append("\" />");
                                                path = b.toString();
                                        }
                                        return path;
@@ -252,12 +270,14 @@
        /**
         * prints a css resource reference.
         */
-       public static final class CSSReferenceHeaderContributor
+       private static final class CSSReferenceHeaderContributor
                        extends
                                ResourceReferenceHeaderContributor
        {
                private static final long serialVersionUID = 1L;
 
+               private String media;
+
                /**
                 * Construct.
                 * 
@@ -265,20 +285,26 @@
                 *            The scope of the reference (typically the calling 
class)
                 * @param name
                 *            The name of the reference.
+                * @param media
+                *            The media type for this CSS ("print", "screen", 
etc.)
                 */
-               public CSSReferenceHeaderContributor(Class scope, String name)
+               public CSSReferenceHeaderContributor(Class scope, String name, 
String media)
                {
                        super(scope, name);
+                       this.media = media;
                }
 
                /**
                 * Construct.
                 * 
                 * @param reference
+                * @param media
+                *            The media type for this CSS ("print", "screen", 
etc.)
                 */
-               public CSSReferenceHeaderContributor(ResourceReference 
reference)
+               public CSSReferenceHeaderContributor(ResourceReference 
reference, String media)
                {
                        super(reference);
+                       this.media = media;
                }
 
                /**
@@ -290,7 +316,12 @@
                        final CharSequence url = 
RequestCycle.get().urlFor(getResourceReference());
                        response.write("<link rel=\"stylesheet\" 
type=\"text/css\" href=\"");
                        response.write(url);
-                       response.println("\"></link>");
+                       if (media != null)
+                       {
+                               response.write("\" media=\"");
+                               response.write(media);
+                       }
+                       response.println("\" />");
                }
        }
 
@@ -479,11 +510,30 @@
         *            resource lives).
         * @param path
         *            The path
+        * @param media
+        *            The media type for this CSS ("print", "screen", etc.)
+        * @return the new header contributor instance
+        */
+       public static final HeaderContributor forCss(final Class scope, final 
String path, final String media)
+       {
+               return new HeaderContributor(new 
CSSReferenceHeaderContributor(scope, path, media));
+       }
+       
+       /**
+        * Returns a new instance of [EMAIL PROTECTED] HeaderContributor} with 
a header
+        * contributor that references a CSS file that lives in a package.
+        * 
+        * @param scope
+        *            The scope of the package resource (typically the class of 
the
+        *            caller, or a class that lives in the package where the
+        *            resource lives).
+        * @param path
+        *            The path
         * @return the new header contributor instance
         */
        public static final HeaderContributor forCss(final Class scope, final 
String path)
        {
-               return new HeaderContributor(new 
CSSReferenceHeaderContributor(scope, path));
+               return new HeaderContributor(new 
CSSReferenceHeaderContributor(scope, path, null));
        }
 
        /**
@@ -491,12 +541,26 @@
         * contributor that references a CSS file that lives in a package.
         * 
         * @param reference
+        * @param media
+        *            The media type for this CSS ("print", "screen", etc.)
+        * @return the new header contributor instance
+        */
+       public static final HeaderContributor forCss(ResourceReference 
reference, final String media)
+       {
+               return new HeaderContributor(new 
CSSReferenceHeaderContributor(reference, media));
+       }
+       
+       /**
+        * Returns a new instance of [EMAIL PROTECTED] HeaderContributor} with 
a header
+        * contributor that references a CSS file that lives in a package.
+        * 
+        * @param reference
         * 
         * @return the new header contributor instance
         */
        public static final HeaderContributor forCss(ResourceReference 
reference)
        {
-               return new HeaderContributor(new 
CSSReferenceHeaderContributor(reference));
+               return new HeaderContributor(new 
CSSReferenceHeaderContributor(reference, null));
        }
 
        /**
@@ -506,11 +570,27 @@
         * 
         * @param location
         *            The location of the css file relative to the context path
+        * @param media
+        *            The media type for this CSS ("print", "screen", etc.)
+        * @return the new header contributor instance
+        */
+       public static final HeaderContributor forCss(final String location, 
final String media)
+       {
+               return new HeaderContributor(new CSSHeaderContributor(location, 
media));                
+       }
+       
+       /**
+        * Returns a new instance of [EMAIL PROTECTED] HeaderContributor} with 
a header
+        * contributor that references a CSS file that lives in the web 
application
+        * directory and that is addressed relative to the context path.
+        * 
+        * @param location
+        *            The location of the css file relative to the context path
         * @return the new header contributor instance
         */
        public static final HeaderContributor forCss(final String location)
        {
-               return new HeaderContributor(new 
CSSHeaderContributor(location));
+               return new HeaderContributor(new CSSHeaderContributor(location, 
null));
        }
 
        /**
@@ -632,7 +712,7 @@
         */
        public final void addCssReference(final Class scope, final String path)
        {
-               addContributor(new CSSReferenceHeaderContributor(scope, path));
+               addContributor(new CSSReferenceHeaderContributor(scope, path, 
null));
        }
 
        /**

Modified: 
incubator/wicket/trunk/wicket/src/main/java/wicket/behavior/HeaderContributor.java
URL: 
http://svn.apache.org/viewvc/incubator/wicket/trunk/wicket/src/main/java/wicket/behavior/HeaderContributor.java?view=diff&rev=482814&r1=482813&r2=482814
==============================================================================
--- 
incubator/wicket/trunk/wicket/src/main/java/wicket/behavior/HeaderContributor.java
 (original)
+++ 
incubator/wicket/trunk/wicket/src/main/java/wicket/behavior/HeaderContributor.java
 Tue Dec  5 14:51:45 2006
@@ -119,6 +119,19 @@
                 */
                public CSSHeaderContributor(final String location)
                {
+                       this(location, null);
+               }
+               
+               /**
+                * Construct.
+                * 
+                * @param location
+                *            the location of the CSS file relative to the 
context path.
+                * @param media
+                *            the media type for this CSS ("print", "screen", 
etc.)
+                */
+               public CSSHeaderContributor(final String location, final String 
media)
+               {
                        super(new AbstractReadOnlyModel<String>()
                        {
 
@@ -149,7 +162,12 @@
                                                        b.append("/");
                                                }
                                                b.append((location != null) ? 
location : "");
-                                               b.append("\"></link>");
+                                               if (media != null)
+                                               {
+                                                       b.append("\" media=\"");
+                                                       b.append(media);
+                                               }
+                                               b.append("\" />");
                                                path = b.toString();
                                        }
                                        return path;
@@ -161,12 +179,14 @@
        /**
         * prints a css resource reference.
         */
-       public static final class CSSReferenceHeaderContributor
+       private static final class CSSReferenceHeaderContributor
                        extends
                                ResourceReferenceHeaderContributor
        {
                private static final long serialVersionUID = 1L;
 
+               private String media;
+
                /**
                 * Construct.
                 * 
@@ -174,20 +194,26 @@
                 *            The scope of the reference (typically the calling 
class)
                 * @param name
                 *            The name of the reference.
+                * @param media
+                *            The media type for this CSS ("print", "screen", 
etc.)
                 */
-               public CSSReferenceHeaderContributor(Class scope, String name)
+               public CSSReferenceHeaderContributor(Class scope, String name, 
String media)
                {
                        super(scope, name);
+                       this.media = media;
                }
 
                /**
                 * Construct.
                 * 
                 * @param reference
+                * @param media
+                *            The media type for this CSS ("print", "screen", 
etc.)
                 */
-               public CSSReferenceHeaderContributor(ResourceReference 
reference)
+               public CSSReferenceHeaderContributor(ResourceReference 
reference, String media)
                {
                        super(reference);
+                       this.media = media;
                }
 
                /**
@@ -199,7 +225,12 @@
                        final CharSequence url = 
RequestCycle.get().urlFor(getResourceReference());
                        response.write("<link rel=\"stylesheet\" 
type=\"text/css\" href=\"");
                        response.write(url);
-                       response.println("\"></link>");
+                       if (media != null)
+                       {
+                               response.write("\" media=\"");
+                               response.write(media);
+                       }
+                       response.println("\" />");
                }
        }
 
@@ -333,11 +364,27 @@
         * 
         * @param location
         *            The location of the css file relative to the context path
+        * @param media
+        *            The media type for this CSS ("print", "screen", etc.)
+        * @return the new header contributor instance
+        */
+       public static final HeaderContributor forCss(final String location, 
final String media)
+       {
+               return new HeaderContributor(new CSSHeaderContributor(location, 
media));                
+       }
+       
+       /**
+        * Returns a new instance of [EMAIL PROTECTED] HeaderContributor} with 
a header
+        * contributor that references a CSS file that lives in the web 
application
+        * directory and that is addressed relative to the context path.
+        * 
+        * @param location
+        *            The location of the css file relative to the context path
         * @return the new header contributor instance
         */
        public static final HeaderContributor forCss(final String location)
        {
-               return new HeaderContributor(new 
CSSHeaderContributor(location));
+               return new HeaderContributor(new CSSHeaderContributor(location, 
null));
        }
 
        /**
@@ -345,12 +392,26 @@
         * contributor that references a CSS file that lives in a package.
         * 
         * @param reference
+        * @param media
+        *            The media type for this CSS ("print", "screen", etc.)
+        * @return the new header contributor instance
+        */
+       public static final HeaderContributor forCss(ResourceReference 
reference, final String media)
+       {
+               return new HeaderContributor(new 
CSSReferenceHeaderContributor(reference, media));
+       }
+       
+       /**
+        * Returns a new instance of [EMAIL PROTECTED] HeaderContributor} with 
a header
+        * contributor that references a CSS file that lives in a package.
+        * 
+        * @param reference
         * 
         * @return the new header contributor instance
         */
        public static final HeaderContributor forCss(ResourceReference 
reference)
        {
-               return new HeaderContributor(new 
CSSReferenceHeaderContributor(reference));
+               return new HeaderContributor(new 
CSSReferenceHeaderContributor(reference, null));
        }
 
        /**
@@ -377,11 +438,30 @@
         *            resource lives).
         * @param path
         *            The path
+        * @param media
+        *            The media type for this CSS ("print", "screen", etc.)
+        * @return the new header contributor instance
+        */
+       public static final HeaderContributor forCss(final Class scope, final 
String path, final String media)
+       {
+               return new HeaderContributor(new 
CSSReferenceHeaderContributor(scope, path, media));
+       }
+       
+       /**
+        * Returns a new instance of [EMAIL PROTECTED] HeaderContributor} with 
a header
+        * contributor that references a CSS file that lives in a package.
+        * 
+        * @param scope
+        *            The scope of the package resource (typically the class of 
the
+        *            caller, or a class that lives in the package where the
+        *            resource lives).
+        * @param path
+        *            The path
         * @return the new header contributor instance
         */
        public static final HeaderContributor forCss(final Class scope, final 
String path)
        {
-               return new HeaderContributor(new 
CSSReferenceHeaderContributor(scope, path));
+               return new HeaderContributor(new 
CSSReferenceHeaderContributor(scope, path, null));
        }
 
        /**
@@ -488,7 +568,7 @@
         */
        public final void addCssReference(final Class scope, final String path)
        {
-               addContributor(new CSSReferenceHeaderContributor(scope, path));
+               addContributor(new CSSReferenceHeaderContributor(scope, path, 
null));
        }
 
        /**


Reply via email to