Author: mgrigorov
Date: Sun Mar 20 17:15:11 2011
New Revision: 1083509

URL: http://svn.apache.org/viewvc?rev=1083509&view=rev
Log:
WICKET-3458 Rename PackagedTextTemplate -> PackageTextTemplate


Added:
    
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/util/template/PackageTextTemplate.java
Removed:
    
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/util/template/PackagedTextTemplate.java
Modified:
    
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/resource/TextTemplateResourceReference.java
    
wicket/trunk/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/DatePicker.java

Modified: 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/resource/TextTemplateResourceReference.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/main/java/org/apache/wicket/resource/TextTemplateResourceReference.java?rev=1083509&r1=1083508&r2=1083509&view=diff
==============================================================================
--- 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/resource/TextTemplateResourceReference.java
 (original)
+++ 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/resource/TextTemplateResourceReference.java
 Sun Mar 20 17:15:11 2011
@@ -25,11 +25,11 @@ import org.apache.wicket.request.resourc
 import org.apache.wicket.request.resource.ResourceReference;
 import org.apache.wicket.request.resource.ResourceStreamResource;
 import org.apache.wicket.util.resource.StringResourceStream;
-import org.apache.wicket.util.template.PackagedTextTemplate;
+import org.apache.wicket.util.template.PackageTextTemplate;
 import org.apache.wicket.util.template.TextTemplate;
 
 /**
- * A class which adapts a {@link PackagedTextTemplate} to a {@link 
ResourceReference}.
+ * A class which adapts a {@link PackageTextTemplate} to a {@link 
ResourceReference}.
  * 
  * @see {@link 
"https://cwiki.apache.org/WICKET/dynamically-generate-a-css-stylesheet.html"}
  * 
@@ -51,7 +51,7 @@ public class TextTemplateResourceReferen
 // 
**********************************************************************************************************************
 
        /**
-        * Creates a resource reference to a {@link PackagedTextTemplate}.
+        * Creates a resource reference to a {@link PackageTextTemplate}.
         * 
         * @param scope
         *            the <code>Class</code> to be used for retrieving the 
classloader for loading the
@@ -64,12 +64,12 @@ public class TextTemplateResourceReferen
        public TextTemplateResourceReference(final Class<?> scope, final String 
fileName,
                IModel<Map<String, Object>> variablesModel)
        {
-               this(scope, fileName, PackagedTextTemplate.DEFAULT_CONTENT_TYPE,
-                       PackagedTextTemplate.DEFAULT_ENCODING, variablesModel);
+               this(scope, fileName, PackageTextTemplate.DEFAULT_CONTENT_TYPE,
+                       PackageTextTemplate.DEFAULT_ENCODING, variablesModel);
        }
 
        /**
-        * Creates a resource reference to a {@link PackagedTextTemplate}.
+        * Creates a resource reference to a {@link PackageTextTemplate}.
         * 
         * @param scope
         *            the <code>Class</code> to be used for retrieving the 
classloader for loading the
@@ -85,11 +85,11 @@ public class TextTemplateResourceReferen
        public TextTemplateResourceReference(final Class<?> scope, final String 
fileName,
                final String contentType, IModel<Map<String, Object>> 
variablesModel)
        {
-               this(scope, fileName, contentType, 
PackagedTextTemplate.DEFAULT_ENCODING, variablesModel);
+               this(scope, fileName, contentType, 
PackageTextTemplate.DEFAULT_ENCODING, variablesModel);
        }
 
        /**
-        * Creates a resource reference to a {@link PackagedTextTemplate}.
+        * Creates a resource reference to a {@link PackageTextTemplate}.
         * 
         * @param scope
         *            the <code>Class</code> to be used for retrieving the 
classloader for loading the
@@ -138,7 +138,7 @@ public class TextTemplateResourceReferen
        {
                super(scope, fileName, locale, style, variation);
 
-               textTemplate = new PackagedTextTemplate(scope, fileName, 
contentType, encoding);
+               textTemplate = new PackageTextTemplate(scope, fileName, 
contentType, encoding);
                this.variablesModel = variablesModel;
        }
 

Added: 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/util/template/PackageTextTemplate.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/main/java/org/apache/wicket/util/template/PackageTextTemplate.java?rev=1083509&view=auto
==============================================================================
--- 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/util/template/PackageTextTemplate.java
 (added)
+++ 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/util/template/PackageTextTemplate.java
 Sun Mar 20 17:15:11 2011
@@ -0,0 +1,212 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.util.template;
+
+import java.io.IOException;
+import java.util.Map;
+
+import org.apache.wicket.Application;
+import org.apache.wicket.javascript.IJavaScriptCompressor;
+import org.apache.wicket.util.io.Streams;
+import org.apache.wicket.util.lang.Packages;
+import org.apache.wicket.util.resource.IResourceStream;
+import org.apache.wicket.util.resource.ResourceStreamNotFoundException;
+import org.apache.wicket.util.resource.locator.ResourceStreamLocator;
+import org.apache.wicket.util.string.interpolator.MapVariableInterpolator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * A <code>String</code> resource that can be appended to.
+ * 
+ * @author Eelco Hillenius
+ * @since 1.2.6
+ */
+public class PackageTextTemplate extends TextTemplate
+{
+       /** log. */
+       private static final Logger log = 
LoggerFactory.getLogger(PackageTextTemplate.class);
+
+       private static final long serialVersionUID = 1L;
+
+       /** The content type used if not provided in the constructor */
+       public static final String DEFAULT_CONTENT_TYPE = "text";
+
+       /** The encoding used if not provided in the constructor */
+       public static final String DEFAULT_ENCODING = null;
+
+       /** contents */
+       private final StringBuilder buffer = new StringBuilder();
+
+       /**
+        * Constructor.
+        * 
+        * @param clazz
+        *            the <code>Class</code> to be used for retrieving the 
classloader for loading the
+        *            <code>PackagedTextTemplate</code>
+        * @param fileName
+        *            the name of the file, relative to the <code>clazz</code> 
position
+        */
+       public PackageTextTemplate(final Class<?> clazz, final String fileName)
+       {
+               this(clazz, fileName, DEFAULT_CONTENT_TYPE);
+       }
+
+       /**
+        * Constructor.
+        * 
+        * @param clazz
+        *            the <code>Class</code> to be used for retrieving the 
classloader for loading the
+        *            <code>PackagedTextTemplate</code>
+        * @param fileName
+        *            the name of the file, relative to the <code>clazz</code> 
position
+        * @param contentType
+        *            the mime type of this resource, such as 
"<code>image/jpeg</code>" or "
+        *            <code>text/html</code>"
+        */
+       public PackageTextTemplate(final Class<?> clazz, final String fileName,
+               final String contentType)
+       {
+               this(clazz, fileName, contentType, DEFAULT_ENCODING);
+       }
+
+       /**
+        * Constructor.
+        * 
+        * @param clazz
+        *            the <code>Class</code> to be used for retrieving the 
classloader for loading the
+        *            <code>PackagedTextTemplate</code>
+        * @param fileName
+        *            the name of the file, relative to the <code>clazz</code> 
position
+        * @param contentType
+        *            the mime type of this resource, such as 
"<code>image/jpeg</code>" or "
+        *            <code>text/html</code>"
+        * @param encoding
+        *            the file's encoding, for example, "<code>UTF-8</code>"
+        */
+       public PackageTextTemplate(final Class<?> clazz, final String fileName,
+               final String contentType, final String encoding)
+       {
+               super(contentType);
+
+               String path = Packages.absolutePath(clazz, fileName);
+
+               Application app = Application.get();
+
+               // first try default class loading locator to find the resource
+               IResourceStream stream = app.getResourceSettings()
+                       .getResourceStreamLocator()
+                       .locate(clazz, path);
+
+               if (stream == null)
+               {
+                       // if default locator couldnt find the resource, than 
some fallback
+                       stream = new ResourceStreamLocator().locate(clazz, 
path);
+               }
+
+               if (stream == null)
+               {
+                       throw new IllegalArgumentException("resource " + 
fileName + " not found for scope " +
+                               clazz + " (path = " + path + ")");
+               }
+
+               setLastModified(stream.lastModifiedTime());
+
+               try
+               {
+                       if (encoding != null)
+                       {
+                               
buffer.append(Streams.readString(stream.getInputStream(), encoding));
+                       }
+                       else
+                       {
+                               
buffer.append(Streams.readString(stream.getInputStream()));
+                       }
+               }
+               catch (IOException e)
+               {
+                       throw new RuntimeException(e);
+               }
+               catch (ResourceStreamNotFoundException e)
+               {
+                       throw new RuntimeException(e);
+               }
+               finally
+               {
+                       try
+                       {
+                               stream.close();
+                       }
+                       catch (IOException e)
+                       {
+                               log.error(e.getMessage(), e);
+                       }
+               }
+       }
+
+       /**
+        * @see 
org.apache.wicket.util.resource.AbstractStringResourceStream#getString()
+        */
+       @Override
+       public String getString()
+       {
+               IJavaScriptCompressor compressor = Application.get()
+                       .getResourceSettings()
+                       .getJavaScriptCompressor();
+
+               if (compressor != null)
+               {
+                       return compressor.compress(buffer.toString());
+               }
+               else
+               {
+                       // don't strip the comments
+                       return buffer.toString();
+               }
+       }
+
+       /**
+        * Interpolates a <code>Map</code> of variables with the content and 
replaces the content with
+        * the result. Variables are denoted in the <code>String</code> by the
+        * <code>syntax ${variableName}</code>. The contents will be altered by 
replacing each variable
+        * of the form <code>${variableName}</code> with the value returned by
+        * <code>variables.getValue("variableName")</code>.
+        * <p>
+        * WARNING: there is no going back to the original contents after the 
interpolation is done. If
+        * you need to do different interpolations on the same original 
contents, use the method
+        * {@link #asString(Map)} instead.
+        * </p>
+        * 
+        * @param variables
+        *            a <code>Map</code> of variables to interpolate
+        * @return this for chaining
+        */
+       @Override
+       public final TextTemplate interpolate(Map<String, ?> variables)
+       {
+               if (variables != null)
+               {
+                       String result = new 
MapVariableInterpolator(buffer.toString(), variables).toString();
+                       buffer.delete(0, buffer.length());
+                       buffer.append(result);
+               }
+               return this;
+       }
+
+
+}

Modified: 
wicket/trunk/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/DatePicker.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/DatePicker.java?rev=1083509&r1=1083508&r2=1083509&view=diff
==============================================================================
--- 
wicket/trunk/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/DatePicker.java
 (original)
+++ 
wicket/trunk/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/DatePicker.java
 Sun Mar 20 17:15:11 2011
@@ -50,7 +50,7 @@ import org.apache.wicket.util.convert.IC
 import org.apache.wicket.util.convert.converter.DateConverter;
 import org.apache.wicket.util.lang.Objects;
 import org.apache.wicket.util.string.Strings;
-import org.apache.wicket.util.template.PackagedTextTemplate;
+import org.apache.wicket.util.template.PackageTextTemplate;
 import org.apache.wicket.util.template.TextTemplate;
 import org.joda.time.DateTime;
 
@@ -269,7 +269,7 @@ public class DatePicker extends Behavior
                variables.put("calendarInit", calendarInit.toString());
 
                // render initialization script with the variables interpolated
-               TextTemplate datePickerJs = new 
PackagedTextTemplate(DatePicker.class, "DatePicker.js");
+               TextTemplate datePickerJs = new 
PackageTextTemplate(DatePicker.class, "DatePicker.js");
                datePickerJs.interpolate(variables);
                response.renderOnDomReadyJavaScript(datePickerJs.asString());
 
@@ -320,7 +320,7 @@ public class DatePicker extends Behavior
                        variables.put("allowRollup", true);
                }
 
-               TextTemplate template = new 
PackagedTextTemplate(DatePicker.class, key);
+               TextTemplate template = new 
PackageTextTemplate(DatePicker.class, key);
                
response.renderOnDomReadyJavaScript(template.asString(variables));
 
                response.markRendered(key);


Reply via email to