From d3d011143972c3d2e639855836f135e3c869a680 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Wed, 18 Feb 2009 23:51:03 +0000 Subject: [PATCH] polishing --- .../cache/ehcache/EhCacheFactoryBean.java | 10 +- .../ehcache/EhCacheManagerFactoryBean.java | 12 +- .../support/AbstractApplicationContext.java | 4 +- .../jdbc/core/StatementCreatorUtils.java | 29 +- ...ractAnnotationAwareTransactionalTests.java | 3 + .../test/annotation/DirtiesContext.java | 17 +- .../test/annotation/Rollback.java | 6 +- .../web/servlet/tags/ParamAware.java | 21 +- .../web/servlet/tags/UrlTag.java | 257 ++++++++---------- 9 files changed, 154 insertions(+), 205 deletions(-) diff --git a/org.springframework.context.support/src/main/java/org/springframework/cache/ehcache/EhCacheFactoryBean.java b/org.springframework.context.support/src/main/java/org/springframework/cache/ehcache/EhCacheFactoryBean.java index 67c917250e3..6ebd92ee8e0 100644 --- a/org.springframework.context.support/src/main/java/org/springframework/cache/ehcache/EhCacheFactoryBean.java +++ b/org.springframework.context.support/src/main/java/org/springframework/cache/ehcache/EhCacheFactoryBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2009 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,7 +37,7 @@ import org.springframework.beans.factory.InitializingBean; import org.springframework.util.Assert; /** - * FactoryBean that creates a named EHCache {@link net.sf.ehcache.Cache} instance + * {@link FactoryBean} that creates a named EHCache {@link net.sf.ehcache.Cache} instance * (or a decorator that implements the {@link net.sf.ehcache.Ehcache} interface), * representing a cache region within an EHCache {@link net.sf.ehcache.CacheManager}. * @@ -56,7 +56,7 @@ import org.springframework.util.Assert; * @see EhCacheManagerFactoryBean * @see net.sf.ehcache.Cache */ -public class EhCacheFactoryBean implements FactoryBean, BeanNameAware, InitializingBean { +public class EhCacheFactoryBean implements FactoryBean, BeanNameAware, InitializingBean { protected final Log logger = LogFactory.getLog(getClass()); @@ -298,11 +298,11 @@ public class EhCacheFactoryBean implements FactoryBean, BeanNameAware, Initializ } - public Object getObject() { + public Ehcache getObject() { return this.cache; } - public Class getObjectType() { + public Class getObjectType() { return (this.cache != null ? this.cache.getClass() : Ehcache.class); } diff --git a/org.springframework.context.support/src/main/java/org/springframework/cache/ehcache/EhCacheManagerFactoryBean.java b/org.springframework.context.support/src/main/java/org/springframework/cache/ehcache/EhCacheManagerFactoryBean.java index 85f1da4e301..0638ab81079 100644 --- a/org.springframework.context.support/src/main/java/org/springframework/cache/ehcache/EhCacheManagerFactoryBean.java +++ b/org.springframework.context.support/src/main/java/org/springframework/cache/ehcache/EhCacheManagerFactoryBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2007 the original author or authors. + * Copyright 2002-2009 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,8 +29,8 @@ import org.springframework.beans.factory.InitializingBean; import org.springframework.core.io.Resource; /** - * FactoryBean that exposes an EHCache {@link net.sf.ehcache.CacheManager} instance - * (independent or shared), configured from a specified config location. + * {@link FactoryBean} that exposes an EHCache {@link net.sf.ehcache.CacheManager} + * instance (independent or shared), configured from a specified config location. * *

If no config location is specified, a CacheManager will be configured from * "ehcache.xml" in the root of the class path (that is, default EHCache initialization @@ -52,7 +52,7 @@ import org.springframework.core.io.Resource; * @see EhCacheFactoryBean * @see net.sf.ehcache.CacheManager */ -public class EhCacheManagerFactoryBean implements FactoryBean, InitializingBean, DisposableBean { +public class EhCacheManagerFactoryBean implements FactoryBean, InitializingBean, DisposableBean { protected final Log logger = LogFactory.getLog(getClass()); @@ -122,11 +122,11 @@ public class EhCacheManagerFactoryBean implements FactoryBean, InitializingBean, } - public Object getObject() { + public CacheManager getObject() { return this.cacheManager; } - public Class getObjectType() { + public Class getObjectType() { return (this.cacheManager != null ? this.cacheManager.getClass() : CacheManager.class); } diff --git a/org.springframework.context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java b/org.springframework.context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java index 992a0e4f2d3..42d875aa6d8 100644 --- a/org.springframework.context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java +++ b/org.springframework.context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java @@ -1078,8 +1078,8 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader * @param lifecycleBeans Map with bean name as key and Lifecycle instance as value * @param beanName the name of the bean to start */ - private void doStart(Map lifecycleBeans, String beanName) { - Lifecycle bean = (Lifecycle) lifecycleBeans.get(beanName); + private void doStart(Map lifecycleBeans, String beanName) { + Lifecycle bean = lifecycleBeans.get(beanName); if (bean != null) { String[] dependenciesForBean = getBeanFactory().getDependenciesForBean(beanName); for (String dependency : dependenciesForBean) { diff --git a/org.springframework.jdbc/src/main/java/org/springframework/jdbc/core/StatementCreatorUtils.java b/org.springframework.jdbc/src/main/java/org/springframework/jdbc/core/StatementCreatorUtils.java index 197e0da4d33..855dd9ae2e8 100644 --- a/org.springframework.jdbc/src/main/java/org/springframework/jdbc/core/StatementCreatorUtils.java +++ b/org.springframework.jdbc/src/main/java/org/springframework/jdbc/core/StatementCreatorUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2009 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,7 +29,6 @@ import java.util.Arrays; import java.util.Calendar; import java.util.Collection; import java.util.HashMap; -import java.util.Iterator; import java.util.Map; import org.apache.commons.logging.Log; @@ -122,8 +121,8 @@ public abstract class StatementCreatorUtils { * @throws SQLException if thrown by PreparedStatement methods */ public static void setParameterValue( - PreparedStatement ps, int paramIndex, SqlParameter param, Object inValue) - throws SQLException { + PreparedStatement ps, int paramIndex, SqlParameter param, Object inValue) + throws SQLException { setParameterValueInternal(ps, paramIndex, param.getSqlType(), param.getTypeName(), param.getScale(), inValue); } @@ -139,8 +138,8 @@ public abstract class StatementCreatorUtils { * @see SqlTypeValue */ public static void setParameterValue( - PreparedStatement ps, int paramIndex, int sqlType, Object inValue) - throws SQLException { + PreparedStatement ps, int paramIndex, int sqlType, Object inValue) + throws SQLException { setParameterValueInternal(ps, paramIndex, sqlType, null, null, inValue); } @@ -158,8 +157,8 @@ public abstract class StatementCreatorUtils { * @see SqlTypeValue */ public static void setParameterValue( - PreparedStatement ps, int paramIndex, int sqlType, String typeName, Object inValue) - throws SQLException { + PreparedStatement ps, int paramIndex, int sqlType, String typeName, Object inValue) + throws SQLException { setParameterValueInternal(ps, paramIndex, sqlType, typeName, null, inValue); } @@ -179,8 +178,8 @@ public abstract class StatementCreatorUtils { * @see SqlTypeValue */ private static void setParameterValueInternal( - PreparedStatement ps, int paramIndex, int sqlType, String typeName, Integer scale, Object inValue) - throws SQLException { + PreparedStatement ps, int paramIndex, int sqlType, String typeName, Integer scale, Object inValue) + throws SQLException { String typeNameToUse = typeName; int sqlTypeToUse = sqlType; @@ -218,7 +217,13 @@ public abstract class StatementCreatorUtils { } } - private static void setNull(PreparedStatement ps, int paramIndex, int sqlType, String typeName) throws SQLException { + /** + * Set the specified PreparedStatement parameter to null, + * respecting database-specific peculiarities. + */ + private static void setNull(PreparedStatement ps, int paramIndex, int sqlType, String typeName) + throws SQLException { + if (sqlType == SqlTypeValue.TYPE_UNKNOWN) { boolean useSetObject = false; sqlType = Types.NULL; @@ -356,7 +361,7 @@ public abstract class StatementCreatorUtils { * Check whether the given value can be treated as a String value. */ private static boolean isStringValue(Class inValueType) { - // Consider any CharSequence (including JDK 1.5's StringBuilder) as String. + // Consider any CharSequence (including StringBuffer and StringBuilder) as a String. return (CharSequence.class.isAssignableFrom(inValueType) || StringWriter.class.isAssignableFrom(inValueType)); } diff --git a/org.springframework.test/src/main/java/org/springframework/test/annotation/AbstractAnnotationAwareTransactionalTests.java b/org.springframework.test/src/main/java/org/springframework/test/annotation/AbstractAnnotationAwareTransactionalTests.java index c7c0e3df790..656251dedcb 100644 --- a/org.springframework.test/src/main/java/org/springframework/test/annotation/AbstractAnnotationAwareTransactionalTests.java +++ b/org.springframework.test/src/main/java/org/springframework/test/annotation/AbstractAnnotationAwareTransactionalTests.java @@ -67,7 +67,10 @@ import org.springframework.util.Assert; * @author Sam Brannen * @author Juergen Hoeller * @since 2.0 + * @deprecated as of Spring 3.0, in favor of using the listener-based test context framework + * ({@link org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests}) */ +@Deprecated public abstract class AbstractAnnotationAwareTransactionalTests extends AbstractTransactionalDataSourceSpringContextTests { diff --git a/org.springframework.test/src/main/java/org/springframework/test/annotation/DirtiesContext.java b/org.springframework.test/src/main/java/org/springframework/test/annotation/DirtiesContext.java index 288c5b0d42f..b22ff817820 100644 --- a/org.springframework.test/src/main/java/org/springframework/test/annotation/DirtiesContext.java +++ b/org.springframework.test/src/main/java/org/springframework/test/annotation/DirtiesContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2007 the original author or authors. + * Copyright 2002-2009 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,27 +23,14 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** - *

* Test annotation to indicate that a test method dirties the context * for the current test. - *

- *

- * Using this annotation in conjunction with - * {@link AbstractAnnotationAwareTransactionalTests} is less error-prone than - * calling - * {@link org.springframework.test.AbstractSingleSpringContextTests#setDirty() setDirty()} - * explicitly because the call to setDirty() is guaranteed to - * occur, even if the test failed. If only a particular code path in the test - * dirties the context, prefer calling setDirty() explicitly -- - * and take care! - *

* * @author Rod Johnson * @author Sam Brannen * @since 2.0 - * @see org.springframework.test.AbstractSingleSpringContextTests */ -@Target( { ElementType.METHOD }) +@Target({ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) @Documented public @interface DirtiesContext { diff --git a/org.springframework.test/src/main/java/org/springframework/test/annotation/Rollback.java b/org.springframework.test/src/main/java/org/springframework/test/annotation/Rollback.java index e4620f9a2e6..03c902c341b 100644 --- a/org.springframework.test/src/main/java/org/springframework/test/annotation/Rollback.java +++ b/org.springframework.test/src/main/java/org/springframework/test/annotation/Rollback.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2007 the original author or authors. + * Copyright 2002-2009 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,16 +31,14 @@ import java.lang.annotation.Target; * @author Sam Brannen * @since 2.5 */ -@Target( { ElementType.METHOD }) +@Target({ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) @Documented public @interface Rollback { /** - *

* Whether or not the transaction for the annotated method should be rolled * back after the method has completed. - *

*/ boolean value() default true; diff --git a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/tags/ParamAware.java b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/tags/ParamAware.java index b4c4fb505e1..58a6b8c86cd 100644 --- a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/tags/ParamAware.java +++ b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/tags/ParamAware.java @@ -1,12 +1,12 @@ /* - * Copyright 2008 the original author or authors. - * + * Copyright 2002-2009 the original author or authors. + * * Licensed 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. @@ -17,8 +17,8 @@ package org.springframework.web.servlet.tags; /** - * Allows implementing tag to utilize nested spring:param tags. - * + * Allows implementing tag to utilize nested spring:param tags. + * * @author Scott Andrews * @since 3.0 * @see ParamTag @@ -26,11 +26,10 @@ package org.springframework.web.servlet.tags; public interface ParamAware { /** - * Callback hook for nested spring:param tags to pass their value to the - * parent tag. - * - * @param param the result of the nested spring:param tag + * Callback hook for nested spring:param tags to pass their value + * to the parent tag. + * @param param the result of the nested spring:param tag */ - public void addParam(Param param); + void addParam(Param param); } diff --git a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/tags/UrlTag.java b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/tags/UrlTag.java index fd92db6686f..9a03b6be643 100644 --- a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/tags/UrlTag.java +++ b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/tags/UrlTag.java @@ -1,12 +1,12 @@ /* - * Copyright 2008 the original author or authors. - * + * Copyright 2002-2009 the original author or authors. + * * Licensed 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. @@ -23,7 +23,6 @@ import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Set; - import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.jsp.JspException; @@ -76,12 +75,9 @@ public class UrlTag extends TagSupport implements ParamAware { private static final String URL_TYPE_ABSOLUTE = "://"; - private enum UrlType { - CONTEXT_RELATIVE, RELATIVE, ABSOLUTE - }; - private static final char[] XML_CHARS = { '&', '<', '>', '"', '\'' }; + private List params; private Set templateParams; @@ -98,21 +94,79 @@ public class UrlTag extends TagSupport implements ParamAware { private boolean escapeXml = false; - // tag lifecycle + + /** + * Sets the value of the URL + */ + public void setValue(String value) { + if (value.contains(URL_TYPE_ABSOLUTE)) { + this.type = UrlType.ABSOLUTE; + this.value = value; + } + else if (value.startsWith("/")) { + this.type = UrlType.CONTEXT_RELATIVE; + this.value = value; + } + else { + this.type = UrlType.RELATIVE; + this.value = value; + } + } + + /** + * Set the context path for the URL. Defaults to the current context + */ + public void setContext(String context) { + if (context.startsWith("/")) { + this.context = context; + } + else { + this.context = "/" + context; + } + } + + /** + * Set the variable name to expose the URL under. Defaults to rendering the + * URL to the current JspWriter + */ + public void setVar(String var) { + this.var = var; + } + + /** + * Set the scope to export the URL variable to. This attribute has no + * meaning unless var is also defined. + */ + public void setScope(String scope) { + this.scope = TagUtils.getScope(scope); + } + + /** + * Instructs the tag to XML entity encode the resulting URL. + *

Defaults to false to maintain compatibility with the JSTL c:url tag. + *

NOTE: Strongly recommended to set as 'true' when rendering + * directly to the JspWriter in an XML or HTML based file. + */ + public void setEscapeXml(String escapeXml) { + this.escapeXml = Boolean.valueOf(escapeXml); + } + + public void addParam(Param param) { + this.params.add(param); + } + @Override public int doStartTag() throws JspException { - params = new LinkedList(); - templateParams = new HashSet(); - + this.params = new LinkedList(); + this.templateParams = new HashSet(); return EVAL_BODY_INCLUDE; } @Override public int doEndTag() throws JspException { String url = createUrl(); - - if (var == null) { + if (this.var == null) { // print the url to the writer try { pageContext.getOut().print(url); @@ -125,74 +179,50 @@ public class UrlTag extends TagSupport implements ParamAware { // store the url as a variable pageContext.setAttribute(var, url, scope); } - return EVAL_PAGE; } - // from ParamAware - - public void addParam(Param param) { - params.add(param); - } - - // support methods /** * Build the URL for the tag from the tag attributes and parameters. - * * @return the URL value as a String * @throws JspException */ private String createUrl() throws JspException { - HttpServletRequest request = (HttpServletRequest) pageContext - .getRequest(); - HttpServletResponse response = (HttpServletResponse) pageContext - .getResponse(); + HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); + HttpServletResponse response = (HttpServletResponse) pageContext.getResponse(); StringBuilder url = new StringBuilder(); - - if (type == UrlType.CONTEXT_RELATIVE) { + if (this.type == UrlType.CONTEXT_RELATIVE) { // add application context to url - if (context == null) { + if (this.context == null) { url.append(request.getContextPath()); } else { - url.append(context); + url.append(this.context); } } - - if (type != UrlType.RELATIVE && type != UrlType.ABSOLUTE - && !value.startsWith("/")) { + if (this.type != UrlType.RELATIVE && this.type != UrlType.ABSOLUTE && !this.value.startsWith("/")) { url.append("/"); } + url.append(replaceUriTemplateParams(this.value, this.params, this.templateParams)); + url.append(createQueryString(this.params, this.templateParams, (url.indexOf("?") == -1))); - url.append(replaceUriTemplateParams(value, params, templateParams)); - url.append(createQueryString(params, templateParams, - (url.indexOf("?") == -1))); - - String urlStr; - if (type != UrlType.ABSOLUTE) { - // add the session identifier if needed - urlStr = response.encodeURL(url.toString()); + String urlStr = url.toString(); + if (this.type != UrlType.ABSOLUTE) { + // Add the session identifier if needed + // (Do not embed the session identifier in a remote link!) + urlStr = response.encodeURL(urlStr); } - else { - // do not embed the session identifier in a remote link - urlStr = url.toString(); - } - - if (escapeXml) { + if (this.escapeXml) { urlStr = escapeXml(urlStr); } - return urlStr; } /** - * Builds the query string from available parameters that have not already + * Build the query string from available parameters that have not already * been applied as template params. - * - *

- * The names and values of parameters are URL encoded. - * + *

The names and values of parameters are URL encoded. * @param params the parameters to build the query string from * @param usedParams set of parameter names that have been applied as * template params @@ -201,13 +231,13 @@ public class UrlTag extends TagSupport implements ParamAware { * @return the query string * @throws JspException */ - protected String createQueryString(List params, - Set usedParams, boolean includeQueryStringDelimiter) + protected String createQueryString( + List params, Set usedParams, boolean includeQueryStringDelimiter) throws JspException { + StringBuilder qs = new StringBuilder(); for (Param param : params) { - if (!usedParams.contains(param.getName()) - && param.getName() != null && !"".equals(param.getName())) { + if (!usedParams.contains(param.getName()) && param.getName() != null && !"".equals(param.getName())) { if (includeQueryStringDelimiter && qs.length() == 0) { qs.append("?"); } @@ -221,28 +251,24 @@ public class UrlTag extends TagSupport implements ParamAware { } } } - return qs.toString(); } /** - * Replaces template markers in the URL matching available parameters. The + * Replace template markers in the URL matching available parameters. The * name of matched parameters are added to the used parameters set. - * - *

- * Parameter values are URL encoded. - * + *

Parameter values are URL encoded. * @param uri the URL with template parameters to replace * @param params parameters used to replace template markers * @param usedParams set of template parameter names that have been replaced * @return the URL with template parameters replaced * @throws JspException */ - protected String replaceUriTemplateParams(String uri, List params, - Set usedParams) throws JspException { + protected String replaceUriTemplateParams(String uri, List params, Set usedParams) + throws JspException { + for (Param param : params) { - String template = URL_TEMPLATE_DELIMITER_PREFIX + param.getName() - + URL_TEMPLATE_DELIMITER_SUFFIX; + String template = URL_TEMPLATE_DELIMITER_PREFIX + param.getName() + URL_TEMPLATE_DELIMITER_SUFFIX; if (uri.contains(template)) { usedParams.add(param.getName()); uri = uri.replace(template, urlEncode(param.getValue())); @@ -252,9 +278,7 @@ public class UrlTag extends TagSupport implements ParamAware { } /** - * URL encode the provided string using the character encoding for the - * response. - * + * URL-encode the providedSstring using the character encoding for the response. * @param value the value to encode * @return the URL encoded value * @throws JspException if the character encoding is invalid @@ -263,20 +287,17 @@ public class UrlTag extends TagSupport implements ParamAware { if (value == null) { return null; } - try { - return URLEncoder.encode(value, pageContext.getResponse() - .getCharacterEncoding()); + return URLEncoder.encode(value, pageContext.getResponse().getCharacterEncoding()); } - catch (UnsupportedEncodingException e) { - throw new JspException(e); + catch (UnsupportedEncodingException ex) { + throw new JspException(ex); } } /** * XML entity encode the provided string. &, <, >, ' and * " are encoded to their entity values. - * * @param xml the value to escape * @return the escaped value */ @@ -284,95 +305,31 @@ public class UrlTag extends TagSupport implements ParamAware { if (xml == null) { return null; } - String escapedXml = xml; for (char xmlChar : XML_CHARS) { - escapedXml = StringUtils.replace(escapedXml, String - .valueOf(xmlChar), entityValue(xmlChar)); + escapedXml = StringUtils.replace(escapedXml, String.valueOf(xmlChar), entityValue(xmlChar)); } - return escapedXml; } /** - * Convert a character value to a XML entity value. The decimal value of the - * character is used. - * - *

- * For example, 'A' is converted to "&#65;". - * + * Convert a character value to a XML entity value. + * The decimal value of the character is used. + *

For example, 'A' is converted to "&#65;". * @param xmlChar the character to encode * @return the entity value */ protected String entityValue(char xmlChar) { - return new StringBuilder().append("&#").append( - Integer.toString(xmlChar)).append(";").toString(); + return new StringBuilder().append("&#").append(Integer.toString(xmlChar)).append(";").toString(); } - // tag attribute accessors /** - * Sets the value of the URL + * Internal enum that classifies URLs by type. */ - public void setValue(String value) { - if (value.contains(URL_TYPE_ABSOLUTE)) { - type = UrlType.ABSOLUTE; - this.value = value; - } - else if (value.startsWith("/")) { - type = UrlType.CONTEXT_RELATIVE; - this.value = value; - } - else { - type = UrlType.RELATIVE; - this.value = value; - } - } + private enum UrlType { - /** - * Sets the context path for the URL. Defaults to the current context - */ - public void setContext(String context) { - if (context.startsWith("/")) { - this.context = context; - } - else { - this.context = "/" + context; - } - } - - /** - * Sets the variable name to expose the URL under. Defaults to rendering the - * URL to the current JspWriter - */ - public void setVar(String var) { - this.var = var; - } - - /** - * Sets the scope to export the URL variable to. This attribute has no - * meaning unless var is also defined. - * - * @param scope the string name of the scope - * @see TagUtils#getScope(String) - */ - public void setScope(String scope) { - this.scope = TagUtils.getScope(scope); - } - - /** - * Instructs the tag to XML entity encode the resulting URL. - *

- * Defaults to false to maintain compatibility with the JSTL c:url tag. - *

- * NOTE: Strongly recommended to set as 'true' when rendering - * directly to the JspWriter in an XML or HTML based file. - * - * @param escapeXml string representation of a boolean - * @see Boolean#valueOf(String) - */ - public void setEscapeXml(String escapeXml) { - this.escapeXml = Boolean.valueOf(escapeXml); + CONTEXT_RELATIVE, RELATIVE, ABSOLUTE } }