Author: cbrisson
Date: Thu Jun 2 14:32:52 2016
New Revision: 1746583
URL: http://svn.apache.org/viewvc?rev=1746583&view=rev
Log:
remove deprecated site files from tools
Removed:
velocity/tools/trunk/src/site/resources/images/velocitytools.png
velocity/tools/trunk/src/site/resources/images/velstruts_diag1.png
velocity/tools/trunk/src/site/site.xml
velocity/tools/trunk/src/site/xdoc/changes.xml
velocity/tools/trunk/src/site/xdoc/config-xml.xml
velocity/tools/trunk/src/site/xdoc/config.java.xml
velocity/tools/trunk/src/site/xdoc/config.project.xml
velocity/tools/trunk/src/site/xdoc/config.properties.xml
velocity/tools/trunk/src/site/xdoc/config.xml
velocity/tools/trunk/src/site/xdoc/creatingtools.xml
velocity/tools/trunk/src/site/xdoc/css/maven-base.css
velocity/tools/trunk/src/site/xdoc/css/maven-theme.css
velocity/tools/trunk/src/site/xdoc/css/print.css
velocity/tools/trunk/src/site/xdoc/css/style.css
velocity/tools/trunk/src/site/xdoc/dependencies.xml
velocity/tools/trunk/src/site/xdoc/frameworks.xml
velocity/tools/trunk/src/site/xdoc/generic.project.xml
velocity/tools/trunk/src/site/xdoc/generic.xml
velocity/tools/trunk/src/site/xdoc/index.xml
velocity/tools/trunk/src/site/xdoc/project.xml
velocity/tools/trunk/src/site/xdoc/site.dvsl
velocity/tools/trunk/src/site/xdoc/standalone.xml
velocity/tools/trunk/src/site/xdoc/struts.project.xml
velocity/tools/trunk/src/site/xdoc/struts.userguide.xml
velocity/tools/trunk/src/site/xdoc/struts.xml
velocity/tools/trunk/src/site/xdoc/summary.xml
velocity/tools/trunk/src/site/xdoc/upgrading.xml
velocity/tools/trunk/src/site/xdoc/view.layoutservlet.xml
velocity/tools/trunk/src/site/xdoc/view.project.xml
velocity/tools/trunk/src/site/xdoc/view.servlet.xml
velocity/tools/trunk/src/site/xdoc/view.tag.xml
velocity/tools/trunk/src/site/xdoc/view.xml
velocity/tools/trunk/velocity-tools-assembly/src/site/site.xml
velocity/tools/trunk/velocity-tools-examples/src/site/site.xml
velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/config/OldXmlFactoryConfigurationRuleSet.java
velocity/tools/trunk/velocity-tools-generic/src/site/site.xml
velocity/tools/trunk/velocity-tools-struts/src/site/site.xml
velocity/tools/trunk/velocity-tools-uberjar/src/site/site.xml
velocity/tools/trunk/velocity-tools-view-jsp/src/site/site.xml
velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/DataInfo.java
velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/ToolboxManager.java
velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/ToolboxRuleSet.java
velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/ViewToolInfo.java
velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/XMLToolboxManager.java
velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/context/
velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/servlet/
velocity/tools/trunk/velocity-tools-view/src/site/site.xml
velocity/tools/trunk/velocity-tools-xml/src/site/site.xml
Modified:
velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/EscapeTool.java
velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/ServletUtils.java
velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/VelocityView.java
velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/VelocityViewServlet.java
velocity/tools/trunk/velocity-tools-view/src/test/java/org/apache/velocity/tools/view/VelocityViewTest.java
Modified:
velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/EscapeTool.java
URL:
http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/EscapeTool.java?rev=1746583&r1=1746582&r2=1746583&view=diff
==============================================================================
---
velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/EscapeTool.java
(original)
+++
velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/EscapeTool.java
Thu Jun 2 14:32:52 2016
@@ -19,14 +19,15 @@ package org.apache.velocity.tools.generi
* under the License.
*/
+import java.net.URLDecoder;
import java.net.URLEncoder;
import java.io.UnsupportedEncodingException;
import org.apache.velocity.shaded.commons.lang3.StringEscapeUtils;
import org.apache.velocity.tools.config.DefaultKey;
/**
- * Tool for working with escaping in Velocity templates.
- * It provides methods to escape outputs for Velocity, Java, JavaScript,
HTML, HTTP, XML and SQL.
+ * Tool for working with escaping and unescaping in Velocity templates.
+ * It provides methods to escape or unescape outputs for Velocity, Java,
JavaScript, HTML, HTTP, XML and SQL.
* Also provides methods to render VTL characters that otherwise needs
escaping.
*
* <p><pre>
@@ -36,21 +37,27 @@ import org.apache.velocity.tools.config.
*
* $java -> He didn't say, "Stop!"
* $esc.java($java) -> He didn't say, \"Stop!\"
+ * $esc.unjava($esc($java)) -> He didn't say, "Stop!"
*
* $javascript -> He didn't say, "Stop!"
* $esc.javascript($javascript) -> He didn\'t say, \"Stop!\"
+ * $esc.unjavascript($esc.javascript($javascript)) -> He didn't say,
"Stop!"
*
* $html -> "bread" & "butter"
* $esc.html($html) -> &quot;bread&quot; &amp;
&quot;butter&quot;
+ * $esc.unhtml($esc.html($html)) -> "bread" & "butter"
*
* $xml -> "bread" & "butter"
* $esc.xml($xml) -> &quot;bread&quot; &amp;
&quot;butter&quot;
+ * $esc.unxml($esc.xml($xml)) -> "bread" & "butter"
*
* $sql -> McHale's Navy
* $esc.sql($sql) -> McHale''s Navy
+ * $esc.sql($esc.unsql($sqlà )) -> McHale''s Navy
*
* $url -> hello here & there
- * $esc.url -> hello+here+%26+there
+ * $esc.url($url) -> hello+here+%26+there
+ * $esc.unurl($esc.url($url)) -> hello+here+%26+there
*
* $esc.dollar -> $
* $esc.d -> $
@@ -190,6 +197,27 @@ public class EscapeTool extends SafeConf
}
return StringEscapeUtils.escapeJava(String.valueOf(string));
}
+
+ /**
+ * Unescapes the characters in a <code>String</code> using Java
String rules.
+ * <br />
+ * Delegates the process to {@link
StringEscapeUtils#unescapeJava(String)}.
+ *
+ * @param string the string to unescape values, may be null
+ * @return String with unescaped values, <code>null</code> if null
string input
+ *
+ * @see StringEscapeUtils#unescapeJava(String)
+ * @since VelocityTools 3.0
+ */
+ public String unjava(Object string)
+ {
+ if (string == null)
+ {
+ return null;
+ }
+ return StringEscapeUtils.unescapeJava(String.valueOf(string));
+ }
+
/**
* Escapes the characters in a <code>String</code> using
java.util.Properties rules for escaping property keys.
@@ -272,12 +300,12 @@ public class EscapeTool extends SafeConf
/**
* Escapes the characters in a <code>String</code> using JavaScript
String rules.
* <br />
- * Delegates the process to {@link
StringEscapeUtils#escapeJavaScript(String)}.
+ * Delegates the process to {@link
StringEscapeUtils#escapeEcmaScript(String)}.
*
* @param string the string to escape values, may be null
* @return String with escaped values, <code>null</code> if null
string input
*
- * @see StringEscapeUtils#escapeJavaScript(String)
+ * @see StringEscapeUtils#escapeEcmaScript(String)
*/
public String javascript(Object string)
{
@@ -289,9 +317,29 @@ public class EscapeTool extends SafeConf
}
/**
+ * Unescapes the characters in a <code>String</code> using JavaScript
String rules.
+ * <br />
+ * Delegates the process to {@link
StringEscapeUtils#unescapeEcmaScript(String)}.
+ *
+ * @param string the string to unescape, may be null
+ * @return unescaped String, <code>null</code> if null string input
+ *
+ * @see StringEscapeUtils#unescapeEcmaScript(String)
+ * @since VelocityTools 3.0
+ */
+ public String unjavascript(Object string)
+ {
+ if (string == null)
+ {
+ return null;
+ }
+ return
StringEscapeUtils.unescapeEcmaScript(String.valueOf(string));
+ }
+
+ /**
* Escapes the characters in a <code>String</code> using HTML
entities.
* <br />
- * Delegates the process to {@link
StringEscapeUtils#escapeHtml(String)}.
+ * Delegates the process to {@link
StringEscapeUtils#escapeHtml4(String)}.
*
* @param string the string to escape, may be null
* @return a new escaped <code>String</code>, <code>null</code> if
null string input
@@ -308,6 +356,26 @@ public class EscapeTool extends SafeConf
}
/**
+ * Unescapes the characters in a <code>String</code> encoded with
HTML entities.
+ * <br />
+ * Delegates the process to {@link
StringEscapeUtils#unescapeHtml4(String)}.
+ *
+ * @param string the string to unescape, may be null
+ * @return a new unescaped <code>String</code>, <code>null</code> if
null string input
+ *
+ * @see StringEscapeUtils#unescapeHtml4(String)
+ * @since VelocityTools 3.0
+ */
+ public String unhtml(Object string)
+ {
+ if (string == null)
+ {
+ return null;
+ }
+ return StringEscapeUtils.unescapeHtml4(String.valueOf(string));
+ }
+
+ /**
* Escape the characters in a <code>String</code> to be suitable to
use as an HTTP parameter value.
* <br/>
* Uses UTF-8 as default character encoding.
@@ -329,6 +397,27 @@ public class EscapeTool extends SafeConf
}
/**
+ * Unscape the characters in a <code>String</code> encoded as an HTTP
parameter value.
+ * <br/>
+ * Uses UTF-8 as default character encoding.
+ * @param string the string to unescape, may be null
+ * @return a new unescaped <code>String</code>, <code>null</code> if
null string input
+ *
+ * @see java.net.URLDecoder#decode(String,String).
+ * @since VelocityTools 3.0
+ */
+ public String unurl(Object string) {
+ if (string == null) {
+ return null;
+ }
+ try {
+ return URLDecoder.decode(String.valueOf(string),"UTF-8");
+ } catch(UnsupportedEncodingException uee) {
+ return null;
+ }
+ }
+
+ /**
* Escapes the characters in a <code>String</code> using XML entities.
* <br />
* Delegates the process to {@link
StringEscapeUtils#escapeXml(String)}.
@@ -348,19 +437,56 @@ public class EscapeTool extends SafeConf
}
/**
+ * Unescapes the characters in a <code>String</code> encoded with XML
entities.
+ * <br />
+ * Delegates the process to {@link
StringEscapeUtils#escapeXml(String)}.
+ *
+ * @param string the string to unescape, may be null
+ * @return a new unescaped <code>String</code>, <code>null</code> if
null string input
+ *
+ * @see StringEscapeUtils#unescapeXml(String)
+ * @since VelocityTools 3.0
+ */
+ public String unxml(Object string)
+ {
+ if (string == null)
+ {
+ return null;
+ }
+ return StringEscapeUtils.unescapeXml(String.valueOf(string));
+ }
+
+ /**
* Escapes the characters in a <code>String</code> to be suitable to
pass to an SQL query.
* <br />
- * Delegates the process to {@link
StringEscapeUtils#escapeSql(String)}.
*
* @param string the string to escape, may be null
* @return a new String, escaped for SQL, <code>null</code> if null
string input
*
- * @see StringEscapeUtils#escapeSql(String)
*/
public String sql(Object string)
{
if (string == null)
{
+ return null;
+ }
+ return String.valueOf(string).replace("'", "''");
+ }
+
+ /**
+ * Unescapes the characters in a <code>String</code> already encoded
for use in a SQL query.
+ * <br />
+ * Delegates the process to {@link
StringEscapeUtils#escapeSql(String)}.
+ *
+ * @param string the string to escape, may be null
+ * @return a new unescaped String, <code>null</code> if null string
input
+ * @since VelocityTools 3.0
+ *
+ */
+ public String unsql(Object string)
+ {
+ if (string == null)
+ {
return null;
}
return String.valueOf(string).replace("'", "''");
Modified:
velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/ServletUtils.java
URL:
http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/ServletUtils.java?rev=1746583&r1=1746582&r2=1746583&view=diff
==============================================================================
---
velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/ServletUtils.java
(original)
+++
velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/ServletUtils.java
Thu Jun 2 14:32:52 2016
@@ -25,6 +25,8 @@ import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.IOException;
import java.lang.reflect.Constructor;
+import java.util.HashMap;
+import java.util.Map;
import javax.servlet.FilterConfig;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
@@ -347,13 +349,6 @@ public class ServletUtils
public static FactoryConfiguration getConfiguration(String path,
ServletContext
application)
{
- return getConfiguration(path, application,
path.endsWith("toolbox.xml"));
- }
-
- public static FactoryConfiguration getConfiguration(String path,
- ServletContext
application,
- boolean
deprecationSupportMode)
- {
// first make sure we can even get such a file
InputStream inputStream = getInputStream(path, application);
if (inputStream == null)
@@ -363,10 +358,10 @@ public class ServletUtils
// then make sure it's a file type we recognize
FileFactoryConfiguration config = null;
- String source =
"ServletUtils.getConfiguration("+path+",ServletContext[,depMode="+deprecationSupportMode+"])";
+ String source = "ServletUtils.getConfiguration("+path+")";
if (path.endsWith(".xml"))
{
- config = new XmlFactoryConfiguration(deprecationSupportMode,
source);
+ config = new XmlFactoryConfiguration(source);
}
else if (path.endsWith(".properties"))
{
@@ -438,4 +433,40 @@ public class ServletUtils
{
}
+ private static Map<String,String> mimeTypesMap = null;
+
+ static
+ {
+ // limit ourselves to text mime types, with "vtl" and "vhtml"
extensions
+ mimeTypesMap = new HashMap<String,String>();
+ mimeTypesMap.put("cal", "text/calendar");
+ mimeTypesMap.put("css", "text/css");
+ mimeTypesMap.put("csv", "text/csv");
+ mimeTypesMap.put("html", "text/html");
+ mimeTypesMap.put("html4", "text/html");
+ mimeTypesMap.put("html5", "text/html");
+ mimeTypesMap.put("json", "application/json");
+ mimeTypesMap.put("js", "text/javascript");
+ mimeTypesMap.put("jsp", "text/html");
+ mimeTypesMap.put("md", "text/markdown");
+ mimeTypesMap.put("php", "text/html");
+ mimeTypesMap.put("ps", "application/postscript");
+ mimeTypesMap.put("rss", "application/rss+xml");
+ mimeTypesMap.put("rtf", "text/rtf");
+ mimeTypesMap.put("sgml", "text/sgml");
+ mimeTypesMap.put("svg", "image/svg+xml");
+ mimeTypesMap.put("tsv", "text/tab-separated-values");
+ mimeTypesMap.put("txt", "text/plain");
+ mimeTypesMap.put("vhtml", "text/html");
+ mimeTypesMap.put("vtl", "text/html");
+ mimeTypesMap.put("xhtml", "text/html");
+ mimeTypesMap.put("xml", "text/xml");
+ mimeTypesMap.put("xslt", "application/xstl+xml");
+ }
+
+ public static String getMimeTypeFromExtension(String extension)
+ {
+ return mimeTypesMap.get(extension);
+ }
+
}
Modified:
velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/VelocityView.java
URL:
http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/VelocityView.java?rev=1746583&r1=1746582&r2=1746583&view=diff
==============================================================================
---
velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/VelocityView.java
(original)
+++
velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/VelocityView.java
Thu Jun 2 14:32:52 2016
@@ -86,6 +86,7 @@ import org.apache.velocity.util.SimplePo
* @author <a href="mailto:kjohn...@transparent.com">Kent Johnson</a>
* @author <a href="mailto:d...@finemaltcoding.com">Daniel Rall</a>
* @author Nathan Bubna
+ * @author <a href="mailto:cbris...@apache.org">Claude Brisson</a>
*
* @version $Id: VelocityView.java 511959 2007-02-26 19:24:39Z nbubna $
*/
@@ -105,7 +106,7 @@ public class VelocityView extends ViewTo
public static final String DEFAULT_CONTENT_TYPE = "text/html";
/** Default encoding for the output stream */
- public static final String DEFAULT_OUTPUT_ENCODING = "ISO-8859-1";
+ public static final String DEFAULT_OUTPUT_ENCODING = "UTF-8";
/**
* Key used to access the toolbox configuration file path from the
@@ -114,9 +115,6 @@ public class VelocityView extends ViewTo
* placed in the ServletContext attributes.
*/
public static final String TOOLS_KEY = ServletUtils.CONFIGURATION_KEY;
- @Deprecated
- public static final String DEPRECATED_TOOLS_KEY =
- "org.apache.velocity.toolbox";
/**
* Default toolbox configuration file path. If no alternate value for
@@ -124,9 +122,6 @@ public class VelocityView extends ViewTo
*/
public static final String USER_TOOLS_PATH =
"/WEB-INF/tools.xml";
- @Deprecated
- public static final String DEPRECATED_USER_TOOLS_PATH =
- "/WEB-INF/toolbox.xml";
/**
* Default Runtime properties.
@@ -150,14 +145,9 @@ public class VelocityView extends ViewTo
/**
* Controls loading of available default tool configurations
- * provided by VelocityTools. The default behavior is conditional;
- * if {@link #DEPRECATION_SUPPORT_MODE_KEY} has not been set to
- * {@code false} and there is an old {@code toolbox.xml} configuration
- * present, then the defaults will not be loaded unless you explicitly
- * set this property to {@code true} in your init params. If there
- * is no {@code toolbox.xml} and/or the deprecation support is turned
off,
- * then the default tools will be loaded automatically unless you
- * explicitly set this property to {@code false} in your init params.
+ * provided by VelocityTools. The default tools will be loaded
+ * automatically unless you explicitly set this property to {@code
false}
+ * in your init params.
*/
public static final String LOAD_DEFAULTS_KEY =
"org.apache.velocity.tools.loadDefaults";
@@ -178,18 +168,8 @@ public class VelocityView extends ViewTo
public static final String USER_OVERWRITE_KEY =
"org.apache.velocity.tools.userCanOverwriteTools";
- /**
- * Controls support for deprecated tools and configuration.
- * The default is {@code true}; set to {@code false} to turn off
- * support for deprecated tools and configuration.
- */
- public static final String DEPRECATION_SUPPORT_MODE_KEY =
- "org.apache.velocity.tools.deprecationSupportMode";
-
-
private static SimplePool writerPool = new SimplePool(40);
private String defaultContentType = DEFAULT_CONTENT_TYPE;
- private boolean deprecationSupportMode = true;
public VelocityView(ServletConfig config)
{
@@ -214,16 +194,6 @@ public class VelocityView extends ViewTo
init(config);
}
- @Deprecated
- protected final void setDeprecationSupportMode(boolean support)
- {
- if (deprecationSupportMode != support)
- {
- this.deprecationSupportMode = support;
- debug("deprecationSupportMode is now %s", (support ? "on" :
"off"));
- }
- }
-
/**
* Overrides super class to ensure engine is not set to null.
*/
@@ -295,12 +265,6 @@ public class VelocityView extends ViewTo
this.velocity = new VelocityEngine();
}
- // default is true for these, so just watch for false
- String depMode =
config.findInitParameter(DEPRECATION_SUPPORT_MODE_KEY);
- if (depMode != null && depMode.equalsIgnoreCase("false"))
- {
- setDeprecationSupportMode(false);
- }
String allowOverwrite =
config.findInitParameter(USER_OVERWRITE_KEY);
if (allowOverwrite != null &&
allowOverwrite.equalsIgnoreCase("false"))
{
@@ -410,16 +374,10 @@ public class VelocityView extends ViewTo
/**
* Here's the configuration lookup/loading order:
* <ol>
- * <li>If deprecationSupportMode is true:
- * <ol>
- * <li>Config file optionally specified by {@code
org.apache.velocity.toolbox} init-param (servlet or servletContext)</li>
- * <li>If none, config file optionally at {@code
/WEB-INF/toolbox.xml} (deprecated conventional location)</li>
- * </ol>
- * </li>
- * <li>If no old toolbox or loadDefaults is true, {@link
ConfigurationUtils#getDefaultTools()}</li>
+ * <li>{@link ConfigurationUtils#getDefaultTools()}</li>
* <li>{@link ConfigurationUtils#getAutoLoaded}(false)</li>
* <li>Config file optionally specified by servletContext {@code
org.apache.velocity.tools} init-param</li>
- * <li>Config file optionally at {@code /WEB-INF/tools.xml} (new
conventional location)</li>
+ * <li>Config file optionally at {@code /WEB-INF/tools.xml}
(conventional location)</li>
* <li>Config file optionally specified by servlet {@code
org.apache.velocity.tools} init-param</li>
* </ol>
* Remember that as these configurations are added on top of each
other,
@@ -433,21 +391,10 @@ public class VelocityView extends ViewTo
{
FactoryConfiguration factoryConfig = new
FactoryConfiguration("VelocityView.configure(config,factory)");
- boolean hasOldToolbox = false;
- if (this.deprecationSupportMode)
- {
- FactoryConfiguration oldToolbox = getDeprecatedConfig(config);
- if (oldToolbox != null)
- {
- hasOldToolbox = true;
- factoryConfig.addConfiguration(oldToolbox);
- }
- }
-
// only load the default tools if they have explicitly said to
// or if they are not using an old toolbox and have said nothing
String loadDefaults = config.findInitParameter(LOAD_DEFAULTS_KEY);
- if ((!hasOldToolbox && loadDefaults == null) ||
+ if ((loadDefaults == null) ||
"true".equalsIgnoreCase(loadDefaults))
{
// add all available default tools
@@ -457,10 +404,7 @@ public class VelocityView extends ViewTo
else
{
// let the user know that the defaults were suppressed
- debug("Default tools configuration has been suppressed%s",
- (hasOldToolbox ?
- " to avoid conflicts with older application's context
and toolbox definition." :
- "."));
+ debug("Default tools configuration has been suppressed.");
}
// this gets the auto loaded config from the classpath
@@ -505,45 +449,6 @@ public class VelocityView extends ViewTo
configure(factoryConfig);
}
- /**
- * First tries to find a path to a toolbox under the deprecated
- * {@code org.apache.velocity.toolbox} key.
- * If found, it tries to load the configuration there and will blow up
- * if there is no config file there.
- * If not found, it looks for a config file at /WEB-INF/toolbox.xml
- * (the deprecated default location) and tries to load it if found.
- */
- @Deprecated
- protected FactoryConfiguration getDeprecatedConfig(JeeConfig config)
- {
- FactoryConfiguration toolbox = null;
-
- // look for specified path under the deprecated toolbox key
- String oldPath = config.findInitParameter(DEPRECATED_TOOLS_KEY);
- if (oldPath != null)
- {
- // ok, they said the toolbox.xml should be there
- // so this should blow up if it is not
- toolbox = getConfiguration(oldPath, true);
- }
- else
- {
- // check for deprecated user configuration at the old
conventional
- // location. be silent if missing, log deprecation warning
otherwise
- oldPath = DEPRECATED_USER_TOOLS_PATH;
- toolbox = getConfiguration(oldPath);
- }
-
- if (toolbox != null)
- {
- debug("Loaded deprecated configuration from: %s", oldPath);
- getLog().warn("Please upgrade to new \"/WEB-INF/tools.xml\"
format and conventional location."+
- " Support for \"/WEB-INF/toolbox.xml\" format
and conventional file name will "+
- "be removed in a future version.");
- }
- return toolbox;
- }
-
private boolean setConfig(FactoryConfiguration factory, String path,
boolean require)
{
if (path == null)
@@ -656,8 +561,7 @@ public class VelocityView extends ViewTo
try
{
config = ServletUtils.getConfiguration(path,
- this.servletContext,
-
this.deprecationSupportMode);
+ this.servletContext);
if (config == null)
{
String msg = "Did not find resource at: "+path;
@@ -699,32 +603,36 @@ public class VelocityView extends ViewTo
String encoding = getProperty(RuntimeConstants.OUTPUT_ENCODING,
DEFAULT_OUTPUT_ENCODING);
- // For non Latin-1 encodings, ensure that the charset is
- // included in the Content-Type header.
- if (!DEFAULT_OUTPUT_ENCODING.equalsIgnoreCase(encoding))
+ // Ensure that the charset is included in the Content-Type header.
+ int index = defaultContentType.lastIndexOf("charset=");
+ if (index < 0)
+ {
+ // the charset specifier is not yet present in header.
+ // append character encoding to default content-type
+ defaultContentType += "; charset=" + encoding;
+ }
+ else
{
- int index = defaultContentType.lastIndexOf("charset");
- if (index < 0)
- {
- // the charset specifier is not yet present in header.
- // append character encoding to default content-type
- this.defaultContentType += "; charset=" + encoding;
- }
- else
- {
- // The user may have configuration issues.
- getLog().info("Charset was already " +
- "specified in the Content-Type property. "
+
- "Output encoding property will be
ignored.");
- }
+ // The user may have configuration issues.
+ getLog().info("Charset was already specified in the
Content-Type property.");
+ // but listen to the last to speak
+ defaultContentType = defaultContentType.substring(0, index +
8) + encoding;
}
- debug("Default Content-Type is: %s", defaultContentType);
+ debug("Default ContentType was changed to %s",
defaultContentType);
}
-
-
-
+ /**
+ * Returns the configured default encoding (parsed from content type,
+ * or UTF-8 by default)
+ */
+ public String getEncoding()
+ {
+ int i = this.defaultContentType.lastIndexOf("charset=");
+ return i != -1 ?
+ this.defaultContentType.substring(i + 8).replace('"','
').trim() :
+ DEFAULT_OUTPUT_ENCODING;
+ }
/******************* REQUEST PROCESSING ****************************/
@@ -781,14 +689,7 @@ public class VelocityView extends ViewTo
HttpServletResponse response)
{
ViewToolContext ctx;
- if (this.deprecationSupportMode)
- {
- ctx = new ChainedContext(velocity, request, response,
servletContext);
- }
- else
- {
- ctx = new ViewToolContext(velocity, request, response,
servletContext);
- }
+ ctx = new ViewToolContext(velocity, request, response,
servletContext);
prepareContext(ctx, request);
return ctx;
}
@@ -807,29 +708,6 @@ public class VelocityView extends ViewTo
}
/**
- * <p>Gets the requested template.</p>
- *
- * @param request client request
- * @param response client response.
- * @return Velocity Template object or null
- * @deprecated Use {@link #getTemplate(HttpServletRequest)}.
- */
- public Template getTemplate(HttpServletRequest request,
- HttpServletResponse response)
- {
- String path = ServletUtils.getPath(request);
- if (response == null)
- {
- return getTemplate(path);
- }
- else
- {
- return getTemplate(path, response.getCharacterEncoding());
- }
- }
-
-
- /**
* Retrieves the requested template.
*
* @param name The file name of the template to retrieve relative to
the
Modified:
velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/VelocityViewServlet.java
URL:
http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/VelocityViewServlet.java?rev=1746583&r1=1746582&r2=1746583&view=diff
==============================================================================
---
velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/VelocityViewServlet.java
(original)
+++
velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/VelocityViewServlet.java
Thu Jun 2 14:32:52 2016
@@ -275,7 +275,8 @@ public class VelocityViewServlet extends
* Sets the content type of the response. This is available to be
overriden
* by a derived class.
*
- * <p>The default implementation is :
+ * <p>The default implementation is to detect content type based on
the
+ * requested path extension, if any, or otherwise to rely on:
* <code>
*
response.setContentType(getVelocityView().getDefaultContentType());
* </code>
@@ -289,7 +290,24 @@ public class VelocityViewServlet extends
protected void setContentType(HttpServletRequest request,
HttpServletResponse response)
{
-
response.setContentType(getVelocityView().getDefaultContentType());
+ String contentType = null;
+ String uri = request.getRequestURI();
+ int dot = uri.lastIndexOf('.');
+ if (dot != -1)
+ {
+ String extension = uri.substring(dot + 1);
+ contentType =
ServletUtils.getMimeTypeFromExtension(extension);
+ }
+ if (contentType == null)
+ {
+ contentType = getVelocityView().getDefaultContentType();
+ }
+ else
+ {
+ // append charset
+ contentType += ";charset=" + getVelocityView().getEncoding();
+ }
+ response.setContentType(contentType);
}
protected Template getTemplate(HttpServletRequest request,
Modified:
velocity/tools/trunk/velocity-tools-view/src/test/java/org/apache/velocity/tools/view/VelocityViewTest.java
URL:
http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-view/src/test/java/org/apache/velocity/tools/view/VelocityViewTest.java?rev=1746583&r1=1746582&r2=1746583&view=diff
==============================================================================
---
velocity/tools/trunk/velocity-tools-view/src/test/java/org/apache/velocity/tools/view/VelocityViewTest.java
(original)
+++
velocity/tools/trunk/velocity-tools-view/src/test/java/org/apache/velocity/tools/view/VelocityViewTest.java
Thu Jun 2 14:32:52 2016
@@ -61,7 +61,6 @@ public class VelocityViewTest
Context context = createMock(Context.class);
expect(config.getServletContext()).andReturn(servletContext);
-
expect(config.findInitParameter(VelocityView.DEPRECATION_SUPPORT_MODE_KEY)).andReturn("false");
expect(config.findInitParameter(VelocityView.USER_OVERWRITE_KEY)).andReturn(null);
expect(config.findInitParameter(VelocityView.LOAD_DEFAULTS_KEY)).andReturn("false");
expect(servletContext.getInitParameter(VelocityView.PROPERTIES_KEY)).andReturn(null);