You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by ad...@apache.org on 2015/06/04 16:19:55 UTC
[1/9] wicket git commit: WICKET-5909 Session style is not taken into
account when loading mounted resources.
Repository: wicket
Updated Branches:
refs/heads/WICKET-5906-7.x 830794f88 -> b9f600f44 (forced update)
WICKET-5909 Session style is not taken into account when loading mounted resources.
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/55cfd279
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/55cfd279
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/55cfd279
Branch: refs/heads/WICKET-5906-7.x
Commit: 55cfd279c7a554a744ba0810c144ad68653c15d6
Parents: 3dd37b3
Author: Andrea Del Bene <“adelbene@apache.org”>
Authored: Wed Jun 3 09:54:22 2015 +0200
Committer: Andrea Del Bene <“adelbene@apache.org”>
Committed: Thu Jun 4 16:19:11 2015 +0200
----------------------------------------------------------------------
.../mapper/AbstractResourceReferenceMapper.java | 156 -------------------
.../mapper/BasicResourceReferenceMapper.java | 6 +-
.../core/request/mapper/ResourceMapper.java | 4 +-
.../resource/PackageResourceReference.java | 22 ++-
.../apache/wicket/resource/ResourceUtil.java | 148 +++++++++++++++++-
.../AbstractResourceReferenceMapperOwnTest.java | 5 +-
.../org/apache/wicket/util/lang/Objects.java | 5 +
.../org/apache/wicket/util/string/Strings.java | 12 ++
8 files changed, 189 insertions(+), 169 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/wicket/blob/55cfd279/wicket-core/src/main/java/org/apache/wicket/core/request/mapper/AbstractResourceReferenceMapper.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/core/request/mapper/AbstractResourceReferenceMapper.java b/wicket-core/src/main/java/org/apache/wicket/core/request/mapper/AbstractResourceReferenceMapper.java
index f95ca9e..7dea46e 100644
--- a/wicket-core/src/main/java/org/apache/wicket/core/request/mapper/AbstractResourceReferenceMapper.java
+++ b/wicket-core/src/main/java/org/apache/wicket/core/request/mapper/AbstractResourceReferenceMapper.java
@@ -16,12 +16,8 @@
*/
package org.apache.wicket.core.request.mapper;
-import java.util.Locale;
-
import org.apache.wicket.request.Url;
import org.apache.wicket.request.resource.ResourceReference;
-import org.apache.wicket.util.lang.Args;
-import org.apache.wicket.util.string.Strings;
/**
* Base class for encoding and decoding {@link ResourceReference}s
@@ -31,158 +27,6 @@ import org.apache.wicket.util.string.Strings;
public abstract class AbstractResourceReferenceMapper extends AbstractComponentMapper
{
/**
- * Escapes any occurrences of <em>-</em> character in the style and variation
- * attributes with <em>~</em>. Any occurrence of <em>~</em> is encoded as <em>~~</em>.
- *
- * @param attribute
- * the attribute to escape
- * @return the attribute with escaped separator character
- */
- public static CharSequence escapeAttributesSeparator(String attribute)
- {
- CharSequence tmp = Strings.replaceAll(attribute, "~", "~~");
- return Strings.replaceAll(tmp, "-", "~");
- }
-
- /**
- * Reverts the escaping applied by {@linkplain #escapeAttributesSeparator(String)} - unescapes
- * occurrences of <em>~</em> character in the style and variation attributes with <em>-</em>.
- *
- * @param attribute
- * the attribute to unescape
- * @return the attribute with escaped separator character
- */
- public static String unescapeAttributesSeparator(String attribute)
- {
- String tmp = attribute.replaceAll("(\\w)~(\\w)", "$1-$2");
- return Strings.replaceAll(tmp, "~~", "~").toString();
- }
-
- protected final String encodeResourceReferenceAttributes(ResourceReference.UrlAttributes attributes)
- {
- if (attributes == null ||
- (attributes.getLocale() == null && attributes.getStyle() == null && attributes.getVariation() == null))
- {
- return null;
- }
- else
- {
- StringBuilder res = new StringBuilder(32);
- if (attributes.getLocale() != null)
- {
- res.append(attributes.getLocale());
- }
- boolean styleEmpty = Strings.isEmpty(attributes.getStyle());
- if (!styleEmpty)
- {
- res.append('-');
- res.append(escapeAttributesSeparator(attributes.getStyle()));
- }
- if (!Strings.isEmpty(attributes.getVariation()))
- {
- if (styleEmpty)
- {
- res.append("--");
- }
- else
- {
- res.append('-');
- }
- res.append(escapeAttributesSeparator(attributes.getVariation()));
- }
- return res.toString();
- }
- }
-
- private static String nonEmpty(String s)
- {
- if (Strings.isEmpty(s))
- {
- return null;
- }
- else
- {
- return s;
- }
- }
-
- protected final ResourceReference.UrlAttributes decodeResourceReferenceAttributes(String attributes)
- {
- Locale locale = null;
- String style = null;
- String variation = null;
-
- if (Strings.isEmpty(attributes) == false)
- {
- String split[] = Strings.split(attributes, '-');
- locale = parseLocale(split[0]);
- if (split.length == 2)
- {
- style = nonEmpty(unescapeAttributesSeparator(split[1]));
- }
- else if (split.length == 3)
- {
- style = nonEmpty(unescapeAttributesSeparator(split[1]));
- variation = nonEmpty(unescapeAttributesSeparator(split[2]));
- }
- }
- return new ResourceReference.UrlAttributes(locale, style, variation);
- }
-
- private static Locale parseLocale(String locale)
- {
- if (Strings.isEmpty(locale))
- {
- return null;
- }
- else
- {
- String parts[] = locale.toLowerCase().split("_", 3);
- if (parts.length == 1)
- {
- return new Locale(parts[0]);
- }
- else if (parts.length == 2)
- {
- return new Locale(parts[0], parts[1]);
- }
- else if (parts.length == 3)
- {
- return new Locale(parts[0], parts[1], parts[2]);
- }
- else
- {
- return null;
- }
- }
- }
-
- protected void encodeResourceReferenceAttributes(Url url, ResourceReference reference)
- {
- String encoded = encodeResourceReferenceAttributes(reference.getUrlAttributes());
- if (!Strings.isEmpty(encoded))
- {
- url.getQueryParameters().add(new Url.QueryParameter(encoded, ""));
- }
- }
-
- protected ResourceReference.UrlAttributes getResourceReferenceAttributes(Url url)
- {
- Args.notNull(url, "url");
-
- if (url.getQueryParameters().size() > 0)
- {
- Url.QueryParameter param = url.getQueryParameters().get(0);
- if (Strings.isEmpty(param.getValue()))
- {
- return decodeResourceReferenceAttributes(param.getName());
- }
- }
- return new ResourceReference.UrlAttributes(null, null, null);
- }
-
-
- /**
* {@inheritDoc}
*
* Remove the first parameter because it brings meta information like locale
http://git-wip-us.apache.org/repos/asf/wicket/blob/55cfd279/wicket-core/src/main/java/org/apache/wicket/core/request/mapper/BasicResourceReferenceMapper.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/core/request/mapper/BasicResourceReferenceMapper.java b/wicket-core/src/main/java/org/apache/wicket/core/request/mapper/BasicResourceReferenceMapper.java
index e7d14b7..6438f1e 100755
--- a/wicket-core/src/main/java/org/apache/wicket/core/request/mapper/BasicResourceReferenceMapper.java
+++ b/wicket-core/src/main/java/org/apache/wicket/core/request/mapper/BasicResourceReferenceMapper.java
@@ -33,6 +33,7 @@ import org.apache.wicket.request.resource.ResourceReferenceRegistry;
import org.apache.wicket.request.resource.caching.IResourceCachingStrategy;
import org.apache.wicket.request.resource.caching.IStaticCacheableResource;
import org.apache.wicket.request.resource.caching.ResourceUrl;
+import org.apache.wicket.resource.ResourceUtil;
import org.apache.wicket.resource.bundles.ResourceBundleReference;
import org.apache.wicket.util.IProvider;
import org.apache.wicket.util.lang.Args;
@@ -124,7 +125,7 @@ public class BasicResourceReferenceMapper extends AbstractResourceReferenceMappe
name.append(segment);
}
- ResourceReference.UrlAttributes attributes = getResourceReferenceAttributes(url);
+ ResourceReference.UrlAttributes attributes = ResourceUtil.decodeResourceReferenceAttributes(url);
Class<?> scope = resolveClass(className);
@@ -212,7 +213,8 @@ public class BasicResourceReferenceMapper extends AbstractResourceReferenceMappe
// need to remove indexed parameters otherwise the URL won't be able to decode
parameters.clearIndexed();
}
- encodeResourceReferenceAttributes(url, reference);
+
+ ResourceUtil.encodeResourceReferenceAttributes(url, reference);
StringTokenizer tokens = new StringTokenizer(reference.getName(), "/");
http://git-wip-us.apache.org/repos/asf/wicket/blob/55cfd279/wicket-core/src/main/java/org/apache/wicket/core/request/mapper/ResourceMapper.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/core/request/mapper/ResourceMapper.java b/wicket-core/src/main/java/org/apache/wicket/core/request/mapper/ResourceMapper.java
index cc6f6d3..eb2278e 100644
--- a/wicket-core/src/main/java/org/apache/wicket/core/request/mapper/ResourceMapper.java
+++ b/wicket-core/src/main/java/org/apache/wicket/core/request/mapper/ResourceMapper.java
@@ -37,6 +37,7 @@ import org.apache.wicket.request.resource.ResourceReference;
import org.apache.wicket.request.resource.caching.IResourceCachingStrategy;
import org.apache.wicket.request.resource.caching.IStaticCacheableResource;
import org.apache.wicket.request.resource.caching.ResourceUrl;
+import org.apache.wicket.resource.ResourceUtil;
import org.apache.wicket.util.lang.Args;
import org.apache.wicket.util.string.Strings;
@@ -201,7 +202,8 @@ public class ResourceMapper extends AbstractMapper implements IRequestMapper
// add caching information
addCachingDecoration(url, parameters);
-
+
+ ResourceUtil.encodeResourceReferenceAttributes(url, resourceReference);
// create url
return encodePageParameters(url, parameters, parametersEncoder);
}
http://git-wip-us.apache.org/repos/asf/wicket/blob/55cfd279/wicket-core/src/main/java/org/apache/wicket/request/resource/PackageResourceReference.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/request/resource/PackageResourceReference.java b/wicket-core/src/main/java/org/apache/wicket/request/resource/PackageResourceReference.java
index 4bd20f0..c7f8da1 100644
--- a/wicket-core/src/main/java/org/apache/wicket/request/resource/PackageResourceReference.java
+++ b/wicket-core/src/main/java/org/apache/wicket/request/resource/PackageResourceReference.java
@@ -22,7 +22,11 @@ import java.util.concurrent.ConcurrentMap;
import org.apache.wicket.Application;
import org.apache.wicket.Session;
import org.apache.wicket.core.util.resource.locator.IResourceStreamLocator;
+import org.apache.wicket.request.Url;
+import org.apache.wicket.request.cycle.RequestCycle;
+import org.apache.wicket.resource.ResourceUtil;
import org.apache.wicket.util.lang.Generics;
+import org.apache.wicket.util.lang.Objects;
import org.apache.wicket.util.lang.Packages;
import org.apache.wicket.util.resource.IResourceStream;
import org.apache.wicket.util.resource.ResourceUtils;
@@ -119,21 +123,27 @@ public class PackageResourceReference extends ResourceReference
final String extension = getExtension();
final PackageResource resource;
+
+ final Url url = RequestCycle.get().getRequest().getUrl();
+ final UrlAttributes urlAttributes = ResourceUtil.decodeResourceReferenceAttributes(url);
if (CSS_EXTENSION.equals(extension))
{
- resource = new CssPackageResource(getScope(), getName(), getLocale(), getStyle(),
- getVariation()).readBuffered(readBuffered);
+ resource = new CssPackageResource(getScope(), getName(), Objects.defaultIfNull(getLocale(), urlAttributes.getLocale()),
+ Objects.defaultIfNull(getStyle(), urlAttributes.getStyle()),
+ Objects.defaultIfNull(getVariation(), urlAttributes.getVariation())).readBuffered(readBuffered);
}
else if (JAVASCRIPT_EXTENSION.equals(extension))
{
- resource = new JavaScriptPackageResource(getScope(), getName(), getLocale(),
- getStyle(), getVariation()).readBuffered(readBuffered);
+ resource = new JavaScriptPackageResource(getScope(), getName(), Objects.defaultIfNull(getLocale(), urlAttributes.getLocale()),
+ Objects.defaultIfNull(getStyle(), urlAttributes.getStyle()),
+ Objects.defaultIfNull(getVariation(), urlAttributes.getVariation())).readBuffered(readBuffered);
}
else
{
- resource = new PackageResource(getScope(), getName(), getLocale(), getStyle(),
- getVariation()).readBuffered(readBuffered);
+ resource = new PackageResource(getScope(), getName(), Objects.defaultIfNull(getLocale(), urlAttributes.getLocale()),
+ Objects.defaultIfNull(getStyle(), urlAttributes.getStyle()),
+ Objects.defaultIfNull(getVariation(), urlAttributes.getVariation())).readBuffered(readBuffered);
}
removeCompressFlagIfUnnecessary(resource);
http://git-wip-us.apache.org/repos/asf/wicket/blob/55cfd279/wicket-core/src/main/java/org/apache/wicket/resource/ResourceUtil.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/resource/ResourceUtil.java b/wicket-core/src/main/java/org/apache/wicket/resource/ResourceUtil.java
index 3f03207..b94ad25 100644
--- a/wicket-core/src/main/java/org/apache/wicket/resource/ResourceUtil.java
+++ b/wicket-core/src/main/java/org/apache/wicket/resource/ResourceUtil.java
@@ -19,11 +19,16 @@ package org.apache.wicket.resource;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
+import java.util.Locale;
import org.apache.wicket.WicketRuntimeException;
+import org.apache.wicket.request.Url;
+import org.apache.wicket.request.resource.ResourceReference;
import org.apache.wicket.util.io.IOUtils;
+import org.apache.wicket.util.lang.Args;
import org.apache.wicket.util.resource.IResourceStream;
import org.apache.wicket.util.resource.ResourceStreamNotFoundException;
+import org.apache.wicket.util.string.Strings;
/**
* Utilities for resources.
@@ -33,9 +38,129 @@ import org.apache.wicket.util.resource.ResourceStreamNotFoundException;
public class ResourceUtil
{
- private ResourceUtil()
+ public static ResourceReference.UrlAttributes decodeResourceReferenceAttributes(String attributes)
{
- // no-op
+ Locale locale = null;
+ String style = null;
+ String variation = null;
+
+ if (Strings.isEmpty(attributes) == false)
+ {
+ String split[] = Strings.split(attributes, '-');
+ locale = parseLocale(split[0]);
+ if (split.length == 2)
+ {
+ style = Strings.notEmpty(unescapeAttributesSeparator(split[1]), null);
+ }
+ else if (split.length == 3)
+ {
+ style = Strings.notEmpty(unescapeAttributesSeparator(split[1]), null);
+ variation = Strings.notEmpty(unescapeAttributesSeparator(split[2]), null);
+ }
+ }
+ return new ResourceReference.UrlAttributes(locale, style, variation);
+ }
+
+ public static ResourceReference.UrlAttributes decodeResourceReferenceAttributes(Url url)
+ {
+ Args.notNull(url, "url");
+
+ if (url.getQueryParameters().size() > 0)
+ {
+ Url.QueryParameter param = url.getQueryParameters().get(0);
+ if (Strings.isEmpty(param.getValue()))
+ {
+ return decodeResourceReferenceAttributes(param.getName());
+ }
+ }
+ return new ResourceReference.UrlAttributes(null, null, null);
+ }
+
+ public static String encodeResourceReferenceAttributes(ResourceReference.UrlAttributes attributes)
+ {
+ if (attributes == null ||
+ (attributes.getLocale() == null && attributes.getStyle() == null && attributes.getVariation() == null))
+ {
+ return null;
+ }
+ else
+ {
+ StringBuilder res = new StringBuilder(32);
+ if (attributes.getLocale() != null)
+ {
+ res.append(attributes.getLocale());
+ }
+ boolean styleEmpty = Strings.isEmpty(attributes.getStyle());
+ if (!styleEmpty)
+ {
+ res.append('-');
+ res.append(escapeAttributesSeparator(attributes.getStyle()));
+ }
+ if (!Strings.isEmpty(attributes.getVariation()))
+ {
+ if (styleEmpty)
+ {
+ res.append("--");
+ }
+ else
+ {
+ res.append('-');
+ }
+ res.append(escapeAttributesSeparator(attributes.getVariation()));
+ }
+ return res.toString();
+ }
+ }
+
+ public static void encodeResourceReferenceAttributes(Url url, ResourceReference reference)
+ {
+ String encoded = encodeResourceReferenceAttributes(reference.getUrlAttributes());
+ if (!Strings.isEmpty(encoded))
+ {
+ url.getQueryParameters().add(new Url.QueryParameter(encoded, ""));
+ }
+ }
+
+ /**
+ * Escapes any occurrences of <em>-</em> character in the style and variation
+ * attributes with <em>~</em>. Any occurrence of <em>~</em> is encoded as <em>~~</em>.
+ *
+ * @param attribute
+ * the attribute to escape
+ * @return the attribute with escaped separator character
+ */
+ public static CharSequence escapeAttributesSeparator(String attribute)
+ {
+ CharSequence tmp = Strings.replaceAll(attribute, "~", "~~");
+ return Strings.replaceAll(tmp, "-", "~");
+ }
+
+ public static Locale parseLocale(String locale)
+ {
+ if (Strings.isEmpty(locale))
+ {
+ return null;
+ }
+ else
+ {
+ String parts[] = locale.toLowerCase().split("_", 3);
+ if (parts.length == 1)
+ {
+ return new Locale(parts[0]);
+ }
+ else if (parts.length == 2)
+ {
+ return new Locale(parts[0], parts[1]);
+ }
+ else if (parts.length == 3)
+ {
+ return new Locale(parts[0], parts[1], parts[2]);
+ }
+ else
+ {
+ return null;
+ }
+ }
}
/**
@@ -91,4 +216,23 @@ public class ResourceUtil
throw new WicketRuntimeException("failed to locate stream from " + resourceStream, e);
}
}
+
+ /**
+ * Reverts the escaping applied by {@linkplain #escapeAttributesSeparator(String)} - unescapes
+ * occurrences of <em>~</em> character in the style and variation attributes with <em>-</em>.
+ *
+ * @param attribute
+ * the attribute to unescape
+ * @return the attribute with escaped separator character
+ */
+ public static String unescapeAttributesSeparator(String attribute)
+ {
+ String tmp = attribute.replaceAll("(\\w)~(\\w)", "$1-$2");
+ return Strings.replaceAll(tmp, "~~", "~").toString();
+ }
+
+ private ResourceUtil()
+ {
+ // no-op
+ }
}
http://git-wip-us.apache.org/repos/asf/wicket/blob/55cfd279/wicket-core/src/test/java/org/apache/wicket/core/request/mapper/AbstractResourceReferenceMapperOwnTest.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/core/request/mapper/AbstractResourceReferenceMapperOwnTest.java b/wicket-core/src/test/java/org/apache/wicket/core/request/mapper/AbstractResourceReferenceMapperOwnTest.java
index 478fe19..1345687 100644
--- a/wicket-core/src/test/java/org/apache/wicket/core/request/mapper/AbstractResourceReferenceMapperOwnTest.java
+++ b/wicket-core/src/test/java/org/apache/wicket/core/request/mapper/AbstractResourceReferenceMapperOwnTest.java
@@ -19,6 +19,7 @@ package org.apache.wicket.core.request.mapper;
import org.apache.wicket.request.IRequestHandler;
import org.apache.wicket.request.Request;
import org.apache.wicket.request.Url;
+import org.apache.wicket.resource.ResourceUtil;
import org.junit.Assert;
import org.junit.Test;
@@ -31,7 +32,7 @@ public class AbstractResourceReferenceMapperOwnTest extends Assert
public void testEscapeAttributesSeparator() throws Exception
{
AbstractResourceReferenceMapper mapper = new Mapper();
- CharSequence escaped = mapper.escapeAttributesSeparator("my-style~is~~cool");
+ CharSequence escaped = ResourceUtil.escapeAttributesSeparator("my-style~is~~cool");
assertEquals("my~style~~is~~~~cool", escaped.toString());
}
@@ -39,7 +40,7 @@ public class AbstractResourceReferenceMapperOwnTest extends Assert
public void testUnescapeAttributesSeparator() throws Exception
{
AbstractResourceReferenceMapper mapper = new Mapper();
- CharSequence escaped = mapper.unescapeAttributesSeparator("my~style~~is~~~~cool");
+ CharSequence escaped = ResourceUtil.unescapeAttributesSeparator("my~style~~is~~~~cool");
assertEquals("my-style~is~~cool", escaped.toString());
}
http://git-wip-us.apache.org/repos/asf/wicket/blob/55cfd279/wicket-util/src/main/java/org/apache/wicket/util/lang/Objects.java
----------------------------------------------------------------------
diff --git a/wicket-util/src/main/java/org/apache/wicket/util/lang/Objects.java b/wicket-util/src/main/java/org/apache/wicket/util/lang/Objects.java
index 4757401..42b14c5 100755
--- a/wicket-util/src/main/java/org/apache/wicket/util/lang/Objects.java
+++ b/wicket-util/src/main/java/org/apache/wicket/util/lang/Objects.java
@@ -772,4 +772,9 @@ public final class Objects
private Objects()
{
}
+
+ public static <T> T defaultIfNull(T originalObj, T defaultObj)
+ {
+ return originalObj != null ? originalObj : defaultObj;
+ }
}
http://git-wip-us.apache.org/repos/asf/wicket/blob/55cfd279/wicket-util/src/main/java/org/apache/wicket/util/string/Strings.java
----------------------------------------------------------------------
diff --git a/wicket-util/src/main/java/org/apache/wicket/util/string/Strings.java b/wicket-util/src/main/java/org/apache/wicket/util/string/Strings.java
index 49119f7..a9a54b9 100755
--- a/wicket-util/src/main/java/org/apache/wicket/util/string/Strings.java
+++ b/wicket-util/src/main/java/org/apache/wicket/util/string/Strings.java
@@ -1562,4 +1562,16 @@ public final class Strings
String.format("Cannot convert '%s' to enum constant of type '%s'.", value, enumClass), e);
}
}
+
+ public static String notEmpty(String originalString, String normalizedValue)
+ {
+ if (isEmpty(originalString))
+ {
+ return normalizedValue;
+ }
+ else
+ {
+ return originalString;
+ }
+ }
}
[4/9] wicket git commit: Cleaned up LoadableDetachableModel state
tracking
Posted by ad...@apache.org.
Cleaned up LoadableDetachableModel state tracking
Previous implementation crafted by me was a tad overengineered, and had some
lousy naming. Fixed the naming and removed the unnecessary booleans.
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/545d731b
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/545d731b
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/545d731b
Branch: refs/heads/WICKET-5906-7.x
Commit: 545d731b5d7eacedcface86a40e5c762ddaa16df
Parents: 99b2746
Author: Martijn Dashorst <ma...@gmail.com>
Authored: Sat May 30 21:47:59 2015 +0200
Committer: Andrea Del Bene <“adelbene@apache.org”>
Committed: Thu Jun 4 16:19:29 2015 +0200
----------------------------------------------------------------------
.../wicket/model/LoadableDetachableModel.java | 57 +++++++-------------
1 file changed, 18 insertions(+), 39 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/wicket/blob/545d731b/wicket-core/src/main/java/org/apache/wicket/model/LoadableDetachableModel.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/model/LoadableDetachableModel.java b/wicket-core/src/main/java/org/apache/wicket/model/LoadableDetachableModel.java
index e3a7fc0..16c6271 100644
--- a/wicket-core/src/main/java/org/apache/wicket/model/LoadableDetachableModel.java
+++ b/wicket-core/src/main/java/org/apache/wicket/model/LoadableDetachableModel.java
@@ -52,39 +52,16 @@ import org.slf4j.LoggerFactory;
*/
public abstract class LoadableDetachableModel<T> implements IModel<T>
{
- /**
- *
- */
+ /** */
private static final long serialVersionUID = 1L;
/** Logger. */
private static final Logger log = LoggerFactory.getLogger(LoadableDetachableModel.class);
- private enum AttachingState
- {
- DETACHED(false, false),
- ATTACHING(true, false),
- ATTACHED(true, true);
-
- private boolean attaching;
- private boolean attached;
-
- private AttachingState(boolean attaching, boolean attached)
- {
- this.attached = attached;
- this.attaching = attaching;
- }
-
- public boolean isAttached()
- {
- return attached;
- }
+ /** Internal state of the LoadableDetachableModel. */
+ private enum InternalState {
+ DETACHED, ATTACHING, ATTACHED;
- public boolean isAttaching()
- {
- return attaching;
- }
-
@Override
public String toString()
{
@@ -92,14 +69,15 @@ public abstract class LoadableDetachableModel<T> implements IModel<T>
}
}
- /** keeps track of whether this model is attached or detached */
- private transient AttachingState attached = AttachingState.DETACHED;
+ /** Keeps track of whether this model is attached or detached */
+ private transient InternalState state = InternalState.DETACHED;
/** temporary, transient object. */
private transient T transientModelObject;
/**
- * Construct.
+ * Default constructor, constructs the model in detached state with no data associated with the
+ * model.
*/
public LoadableDetachableModel()
{
@@ -107,7 +85,8 @@ public abstract class LoadableDetachableModel<T> implements IModel<T>
/**
* This constructor is used if you already have the object retrieved and want to wrap it with a
- * detachable model.
+ * detachable model. Constructs the model in attached state. Calls to {@link #getObject()} will
+ * return {@code object} until {@link #detach()} is called.
*
* @param object
* retrieved instance of the detachable object
@@ -115,7 +94,7 @@ public abstract class LoadableDetachableModel<T> implements IModel<T>
public LoadableDetachableModel(T object)
{
this.transientModelObject = object;
- attached = AttachingState.ATTACHED;
+ state = InternalState.ATTACHED;
}
/**
@@ -124,7 +103,7 @@ public abstract class LoadableDetachableModel<T> implements IModel<T>
@Override
public void detach()
{
- if (attached == AttachingState.ATTACHED)
+ if (state == InternalState.ATTACHED)
{
try
{
@@ -132,7 +111,7 @@ public abstract class LoadableDetachableModel<T> implements IModel<T>
}
finally
{
- attached = AttachingState.DETACHED;
+ state = InternalState.DETACHED;
transientModelObject = null;
log.debug("removed transient object for {}, requestCycle {}", this,
@@ -147,10 +126,10 @@ public abstract class LoadableDetachableModel<T> implements IModel<T>
@Override
public final T getObject()
{
- if (attached == AttachingState.DETACHED)
+ if (state == InternalState.DETACHED)
{
// prevent infinite attachment loops
- attached = AttachingState.ATTACHING;
+ state = InternalState.ATTACHING;
transientModelObject = load();
@@ -160,7 +139,7 @@ public abstract class LoadableDetachableModel<T> implements IModel<T>
", requestCycle " + RequestCycle.get());
}
- attached = AttachingState.ATTACHED;
+ state = InternalState.ATTACHED;
onAttach();
}
return transientModelObject;
@@ -173,7 +152,7 @@ public abstract class LoadableDetachableModel<T> implements IModel<T>
*/
public final boolean isAttached()
{
- return attached.isAttached();
+ return state == InternalState.ATTACHED;
}
/**
@@ -225,7 +204,7 @@ public abstract class LoadableDetachableModel<T> implements IModel<T>
@Override
public void setObject(final T object)
{
- attached = AttachingState.ATTACHED;
+ state = InternalState.ATTACHED;
transientModelObject = object;
}
}
[2/9] wicket git commit: Fixed serialization issue in state handling
LDM
Posted by ad...@apache.org.
Fixed serialization issue in state handling LDM
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/53db8470
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/53db8470
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/53db8470
Branch: refs/heads/WICKET-5906-7.x
Commit: 53db8470e213d60a85e2ec85e90c567ea2ee6c82
Parents: 545d731
Author: Martijn Dashorst <ma...@gmail.com>
Authored: Sat May 30 22:55:33 2015 +0200
Committer: Andrea Del Bene <“adelbene@apache.org”>
Committed: Thu Jun 4 16:19:29 2015 +0200
----------------------------------------------------------------------
.../wicket/model/LoadableDetachableModel.java | 2 +-
.../model/LoadableDetachableModelTest.java | 71 ++++++++++++++++++++
2 files changed, 72 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/wicket/blob/53db8470/wicket-core/src/main/java/org/apache/wicket/model/LoadableDetachableModel.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/model/LoadableDetachableModel.java b/wicket-core/src/main/java/org/apache/wicket/model/LoadableDetachableModel.java
index 16c6271..75e91bd 100644
--- a/wicket-core/src/main/java/org/apache/wicket/model/LoadableDetachableModel.java
+++ b/wicket-core/src/main/java/org/apache/wicket/model/LoadableDetachableModel.java
@@ -126,7 +126,7 @@ public abstract class LoadableDetachableModel<T> implements IModel<T>
@Override
public final T getObject()
{
- if (state == InternalState.DETACHED)
+ if (state == null || state == InternalState.DETACHED)
{
// prevent infinite attachment loops
state = InternalState.ATTACHING;
http://git-wip-us.apache.org/repos/asf/wicket/blob/53db8470/wicket-core/src/test/java/org/apache/wicket/model/LoadableDetachableModelTest.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/model/LoadableDetachableModelTest.java b/wicket-core/src/test/java/org/apache/wicket/model/LoadableDetachableModelTest.java
index a087a78..453bd7b 100644
--- a/wicket-core/src/test/java/org/apache/wicket/model/LoadableDetachableModelTest.java
+++ b/wicket-core/src/test/java/org/apache/wicket/model/LoadableDetachableModelTest.java
@@ -18,6 +18,13 @@ package org.apache.wicket.model;
import static org.hamcrest.core.Is.is;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+
import org.apache.wicket.WicketTestCase;
import org.junit.Test;
@@ -84,4 +91,68 @@ public class LoadableDetachableModelTest extends WicketTestCase
assertThat(ldm.isAttached(), is(false));
}
}
+
+ private static class SerializedLoad extends LoadableDetachableModel<Integer>
+ {
+ private static final long serialVersionUID = 1L;
+
+ private int count = 0;
+
+ @Override
+ protected Integer load()
+ {
+ return ++count;
+ }
+ }
+
+ /**
+ * Tests serialization/deserialization of LDM retaining the correct state.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void serializationDeserializationRetainsInternalState() throws Exception
+ {
+ SerializedLoad ldm = new SerializedLoad();
+ assertThat(ldm.getObject(), is(1));
+ ldm.detach();
+
+ byte[] serialized = serialize(ldm);
+
+ LoadableDetachableModel<Integer> deserialized = deserialize(serialized);
+
+ assertThat(deserialized.isAttached(), is(false));
+ assertThat(deserialized.getObject(), is(2));
+ assertThat(deserialized.isAttached(), is(true));
+ deserialized.detach();
+ assertThat(deserialized.isAttached(), is(false));
+ }
+
+ /** Serialization helper */
+ @SuppressWarnings("unchecked")
+ private <T> LoadableDetachableModel<T> deserialize(byte[] serialized) throws IOException,
+ ClassNotFoundException
+ {
+ LoadableDetachableModel<T> deserialized = null;
+
+ try (ByteArrayInputStream bais = new ByteArrayInputStream(serialized);
+ ObjectInputStream ois = new ObjectInputStream(bais);)
+ {
+ deserialized = (LoadableDetachableModel<T>)ois.readObject();
+ }
+ return deserialized;
+ }
+
+ /** Deserialization helper */
+ private byte[] serialize(Serializable ldm) throws IOException
+ {
+ byte[] stream = { };
+ try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(baos);)
+ {
+ oos.writeObject(ldm);
+ stream = baos.toByteArray();
+ }
+ return stream;
+ }
}
[9/9] wicket git commit: Suppress warnings for unit test javadoc
Posted by ad...@apache.org.
Suppress warnings for unit test javadoc
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/93ad80d0
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/93ad80d0
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/93ad80d0
Branch: refs/heads/WICKET-5906-7.x
Commit: 93ad80d078b989fba97a84e7d712f594982ade33
Parents: 53db847
Author: Martijn Dashorst <ma...@gmail.com>
Authored: Tue Jun 2 13:57:40 2015 +0200
Committer: Andrea Del Bene <“adelbene@apache.org”>
Committed: Thu Jun 4 16:19:29 2015 +0200
----------------------------------------------------------------------
.../java/org/apache/wicket/model/LoadableDetachableModelTest.java | 1 +
1 file changed, 1 insertion(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/wicket/blob/93ad80d0/wicket-core/src/test/java/org/apache/wicket/model/LoadableDetachableModelTest.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/model/LoadableDetachableModelTest.java b/wicket-core/src/test/java/org/apache/wicket/model/LoadableDetachableModelTest.java
index 453bd7b..375b60a 100644
--- a/wicket-core/src/test/java/org/apache/wicket/model/LoadableDetachableModelTest.java
+++ b/wicket-core/src/test/java/org/apache/wicket/model/LoadableDetachableModelTest.java
@@ -31,6 +31,7 @@ import org.junit.Test;
/**
* Tests the states of a LoadableDetachableModel
*/
+@SuppressWarnings("javadoc")
public class LoadableDetachableModelTest extends WicketTestCase
{
/**
[6/9] wicket git commit: WICKET-5916 StackOverflowError in
LoadableDetachableModel
Posted by ad...@apache.org.
WICKET-5916 StackOverflowError in LoadableDetachableModel
This fixes a circular calling issue with LoadableDetachableModel where
getObject() is called from the context of a load(). By tracking the
state of the LoadableDetachableModel more closely, we can short-circuit
the call chain and break out of the infinite calling loop.
I've opted to use an enum instead of adding a new flag to keep the
amount of flags to a minimum and to keep the memory requirements
low (instead of 2 flags, just one enum is referenced). The external
public and protected interfaces are still the same, so I don't
expect any problems within user applications, unless they are
manipulating the attached flag using reflection.
Fixes WICKET-5916
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/5049aa85
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/5049aa85
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/5049aa85
Branch: refs/heads/WICKET-5906-7.x
Commit: 5049aa8525e6ee268c3e78ec77dc7012da13e51c
Parents: 55cfd27
Author: Martijn Dashorst <ma...@gmail.com>
Authored: Fri May 29 19:11:28 2015 +0200
Committer: Andrea Del Bene <“adelbene@apache.org”>
Committed: Thu Jun 4 16:19:29 2015 +0200
----------------------------------------------------------------------
.../wicket/model/LoadableDetachableModel.java | 65 +++++++++++----
.../model/LoadableDetachableModelTest.java | 87 ++++++++++++++++++++
2 files changed, 138 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/wicket/blob/5049aa85/wicket-core/src/main/java/org/apache/wicket/model/LoadableDetachableModel.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/model/LoadableDetachableModel.java b/wicket-core/src/main/java/org/apache/wicket/model/LoadableDetachableModel.java
index c172678..e3a7fc0 100644
--- a/wicket-core/src/main/java/org/apache/wicket/model/LoadableDetachableModel.java
+++ b/wicket-core/src/main/java/org/apache/wicket/model/LoadableDetachableModel.java
@@ -23,8 +23,8 @@ import org.slf4j.LoggerFactory;
/**
* Model that makes working with detachable models a breeze. LoadableDetachableModel holds a
- * temporary, transient model object, that is set when {@link #getObject()} is called by
- * calling abstract method 'load', and that will be reset/ set to null on {@link #detach()}.
+ * temporary, transient model object, that is set when {@link #getObject()} is called by calling
+ * abstract method 'load', and that will be reset/ set to null on {@link #detach()}.
*
* A usage example:
*
@@ -60,8 +60,40 @@ public abstract class LoadableDetachableModel<T> implements IModel<T>
/** Logger. */
private static final Logger log = LoggerFactory.getLogger(LoadableDetachableModel.class);
+ private enum AttachingState
+ {
+ DETACHED(false, false),
+ ATTACHING(true, false),
+ ATTACHED(true, true);
+
+ private boolean attaching;
+ private boolean attached;
+
+ private AttachingState(boolean attaching, boolean attached)
+ {
+ this.attached = attached;
+ this.attaching = attaching;
+ }
+
+ public boolean isAttached()
+ {
+ return attached;
+ }
+
+ public boolean isAttaching()
+ {
+ return attaching;
+ }
+
+ @Override
+ public String toString()
+ {
+ return name().toLowerCase();
+ }
+ }
+
/** keeps track of whether this model is attached or detached */
- private transient boolean attached = false;
+ private transient AttachingState attached = AttachingState.DETACHED;
/** temporary, transient object. */
private transient T transientModelObject;
@@ -83,7 +115,7 @@ public abstract class LoadableDetachableModel<T> implements IModel<T>
public LoadableDetachableModel(T object)
{
this.transientModelObject = object;
- attached = true;
+ attached = AttachingState.ATTACHED;
}
/**
@@ -92,7 +124,7 @@ public abstract class LoadableDetachableModel<T> implements IModel<T>
@Override
public void detach()
{
- if (attached)
+ if (attached == AttachingState.ATTACHED)
{
try
{
@@ -100,7 +132,7 @@ public abstract class LoadableDetachableModel<T> implements IModel<T>
}
finally
{
- attached = false;
+ attached = AttachingState.DETACHED;
transientModelObject = null;
log.debug("removed transient object for {}, requestCycle {}", this,
@@ -115,8 +147,11 @@ public abstract class LoadableDetachableModel<T> implements IModel<T>
@Override
public final T getObject()
{
- if (!attached)
+ if (attached == AttachingState.DETACHED)
{
+ // prevent infinite attachment loops
+ attached = AttachingState.ATTACHING;
+
transientModelObject = load();
if (log.isDebugEnabled())
@@ -125,7 +160,7 @@ public abstract class LoadableDetachableModel<T> implements IModel<T>
", requestCycle " + RequestCycle.get());
}
- attached = true;
+ attached = AttachingState.ATTACHED;
onAttach();
}
return transientModelObject;
@@ -138,7 +173,7 @@ public abstract class LoadableDetachableModel<T> implements IModel<T>
*/
public final boolean isAttached()
{
- return attached;
+ return attached.isAttached();
}
/**
@@ -147,9 +182,12 @@ public abstract class LoadableDetachableModel<T> implements IModel<T>
@Override
public String toString()
{
- StringBuilder sb = new StringBuilder(super.toString());
- sb.append(":attached=").append(attached).append(":tempModelObject=[").append(
- this.transientModelObject).append("]");
+ StringBuilder sb = new StringBuilder(super.toString());
+ sb.append(":attached=")
+ .append(isAttached())
+ .append(":tempModelObject=[")
+ .append(this.transientModelObject)
+ .append("]");
return sb.toString();
}
@@ -187,8 +225,7 @@ public abstract class LoadableDetachableModel<T> implements IModel<T>
@Override
public void setObject(final T object)
{
- attached = true;
+ attached = AttachingState.ATTACHED;
transientModelObject = object;
}
-
}
http://git-wip-us.apache.org/repos/asf/wicket/blob/5049aa85/wicket-core/src/test/java/org/apache/wicket/model/LoadableDetachableModelTest.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/model/LoadableDetachableModelTest.java b/wicket-core/src/test/java/org/apache/wicket/model/LoadableDetachableModelTest.java
new file mode 100644
index 0000000..a087a78
--- /dev/null
+++ b/wicket-core/src/test/java/org/apache/wicket/model/LoadableDetachableModelTest.java
@@ -0,0 +1,87 @@
+/*
+ * 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.model;
+
+import static org.hamcrest.core.Is.is;
+
+import org.apache.wicket.WicketTestCase;
+import org.junit.Test;
+
+/**
+ * Tests the states of a LoadableDetachableModel
+ */
+public class LoadableDetachableModelTest extends WicketTestCase
+{
+ /**
+ * Checks whether the LDM can escape recursive calls.
+ */
+ @Test
+ public void recursiveGetObjectDoesntCauseInfiteLoop()
+ {
+ class RecursiveLoad extends LoadableDetachableModel<Integer>
+ {
+ private static final long serialVersionUID = 1L;
+
+ private int count = 0;
+
+ @Override
+ protected Integer load()
+ {
+ count++;
+ getObject();
+ return count;
+ }
+ }
+
+ RecursiveLoad ldm = new RecursiveLoad();
+
+ assertThat(ldm.isAttached(), is(false));
+ assertThat(ldm.getObject(), is(1));
+ assertThat(ldm.isAttached(), is(true));
+ }
+
+ /**
+ * Checks whether the LDM can escape recursive calls.
+ */
+ @Test
+ public void exceptionDuringLoadKeepsLDMDetached()
+ {
+ class ExceptionalLoad extends LoadableDetachableModel<Integer>
+ {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ protected Integer load()
+ {
+ throw new RuntimeException();
+ }
+ }
+
+ ExceptionalLoad ldm = new ExceptionalLoad();
+
+ assertThat(ldm.isAttached(), is(false));
+ try
+ {
+ assertThat(ldm.getObject(), is(1));
+ fail("shouldn't get here");
+ }
+ catch (RuntimeException e)
+ {
+ assertThat(ldm.isAttached(), is(false));
+ }
+ }
+}
[7/9] wicket git commit: WICKET-5901 Leaving veil when ajax
processing ends with redirect
Posted by ad...@apache.org.
WICKET-5901 Leaving veil when ajax processing ends with redirect
Add unit tests for preserving the ajax indicator until page unload (if there is redirect)
(cherry picked from commit 22e6f69b3896c011f113f6d97957e6cd46304223)
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/99b27463
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/99b27463
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/99b27463
Branch: refs/heads/WICKET-5906-7.x
Commit: 99b27463b152736045900df73e3680349c46e15a
Parents: adb475f
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Sat May 30 15:51:03 2015 +0300
Committer: Andrea Del Bene <“adelbene@apache.org”>
Committed: Thu Jun 4 16:19:29 2015 +0200
----------------------------------------------------------------------
.../wicket/ajax/res/js/wicket-ajax-jquery.js | 15 ++++--
wicket-core/src/test/js/ajax.js | 54 ++++++++++++++++++++
wicket-core/src/test/js/all.html | 2 +
.../test/js/data/ajax/redirectAjaxResponse.xml | 18 +++++++
4 files changed, 86 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/wicket/blob/99b27463/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js b/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js
index 88d3983..e62451f 100644
--- a/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js
+++ b/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js
@@ -767,7 +767,7 @@
// support/check for non-relative redirectUrl like as provided and needed in a portlet context
if (redirectUrl.charAt(0) === '/' || rhttp.test(redirectUrl) || rhttps.test(redirectUrl)) {
context.isRedirecting = true;
- window.location = redirectUrl;
+ Wicket.Ajax.redirect(redirectUrl);
}
else {
var urlDepth = 0;
@@ -792,7 +792,7 @@
}
context.isRedirecting = true;
- window.location = calculatedRedirect;
+ Wicket.Ajax.redirect(calculatedRedirect);
}
}
else {
@@ -1241,7 +1241,7 @@
var text = Wicket.DOM.text(node);
Wicket.Log.info("Redirecting to: " + text);
context.isRedirecting = true;
- window.location = text;
+ Wicket.Ajax.redirect(text);
},
// mark the focused component so that we know if it has been replaced by response
@@ -1972,6 +1972,15 @@
process: function(data) {
var call = new Wicket.Ajax.Call();
call.process(data);
+ },
+
+ /**
+ * An abstraction over native window.location.replace() to be able to suppress it for unit tests
+ *
+ * @param url The url to redirect to
+ */
+ redirect: function(url) {
+ window.location = url;
}
},
http://git-wip-us.apache.org/repos/asf/wicket/blob/99b27463/wicket-core/src/test/js/ajax.js
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/js/ajax.js b/wicket-core/src/test/js/ajax.js
index d969d6d..9adf553 100644
--- a/wicket-core/src/test/js/ajax.js
+++ b/wicket-core/src/test/js/ajax.js
@@ -1288,5 +1288,59 @@ jQuery(document).ready(function() {
target.off("event1");
});
+ asyncTest('Do not hide the indicator if redirecting.', function () {
+
+ expect(2);
+
+ var oldRedirect = Wicket.Ajax.redirect;
+ Wicket.Ajax.redirect = function() {};
+
+ var attrs = {
+ u: 'data/ajax/redirectAjaxResponse.xml',
+ e: 'event1',
+ i: 'ajaxIndicator',
+ sh: [function(attrs, jqXHR, data, textStatus) {
+ var indicatorEl = Wicket.$(attrs.i);
+ equal("1", indicatorEl.getAttribute("showIncrementallyCount"));
+ }],
+ coh: [function(attrs, jqXHR, textStatus) {
+ var indicatorEl = Wicket.$(attrs.i);
+ equal("1", indicatorEl.getAttribute("showIncrementallyCount"));
+ Wicket.Ajax.redirect = oldRedirect;
+ start();
+ }]
+ };
+
+ Wicket.Ajax.ajax(attrs);
+ var target = jQuery(window);
+ target.triggerHandler("event1");
+ target.off("event1");
+ });
+
+ asyncTest('Do hide the indicator if not redirecting.', function () {
+
+ expect(2);
+
+ var attrs = {
+ u: 'data/ajax/emptyAjaxResponse.xml',
+ e: 'event1',
+ i: 'ajaxIndicator',
+ sh: [function(attrs, jqXHR, data, textStatus) {
+ var indicatorEl = Wicket.$(attrs.i);
+ equal("1", indicatorEl.getAttribute("showIncrementallyCount"));
+ }],
+ coh: [function(attrs, jqXHR, textStatus) {
+ var indicatorEl = Wicket.$(attrs.i);
+ equal("0", indicatorEl.getAttribute("showIncrementallyCount"));
+ start();
+ }]
+ };
+
+ Wicket.Ajax.ajax(attrs);
+ var target = jQuery(window);
+ target.triggerHandler("event1");
+ target.off("event1");
+ });
+
}
});
http://git-wip-us.apache.org/repos/asf/wicket/blob/99b27463/wicket-core/src/test/js/all.html
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/js/all.html b/wicket-core/src/test/js/all.html
index b58688f..6a03f52 100644
--- a/wicket-core/src/test/js/all.html
+++ b/wicket-core/src/test/js/all.html
@@ -169,6 +169,8 @@
<div id="usedAsContextWicket5025"></div>
<input type="text" id="inputChangeInput">
+
+ <div id="ajaxIndicator"></div>
</div>
</body>
</html>
http://git-wip-us.apache.org/repos/asf/wicket/blob/99b27463/wicket-core/src/test/js/data/ajax/redirectAjaxResponse.xml
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/js/data/ajax/redirectAjaxResponse.xml b/wicket-core/src/test/js/data/ajax/redirectAjaxResponse.xml
new file mode 100644
index 0000000..19d89e7
--- /dev/null
+++ b/wicket-core/src/test/js/data/ajax/redirectAjaxResponse.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<ajax-response><redirect><![CDATA[http://127.0.0.1]]></redirect></ajax-response>
[8/9] wicket git commit: [WICKET-5909] Session style is not taken
into account when loading mounted resources.
Posted by ad...@apache.org.
[WICKET-5909] Session style is not taken into account when loading mounted resources.
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/b9f600f4
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/b9f600f4
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/b9f600f4
Branch: refs/heads/WICKET-5906-7.x
Commit: b9f600f44ccef68c5c644f1e13e8d3d5dbcf1033
Parents: 93ad80d
Author: Andrea Del Bene <“adelbene@apache.org”>
Authored: Wed Jun 3 15:10:13 2015 +0200
Committer: Andrea Del Bene <“adelbene@apache.org”>
Committed: Thu Jun 4 16:19:29 2015 +0200
----------------------------------------------------------------------
.../resource/PackageResourceReference.java | 1 +
.../apache/wicket/resource/ResourceUtil.java | 63 ++++++++++++++++----
.../org/apache/wicket/util/lang/Objects.java | 19 ++++--
.../org/apache/wicket/util/string/Strings.java | 21 ++++---
4 files changed, 81 insertions(+), 23 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/wicket/blob/b9f600f4/wicket-core/src/main/java/org/apache/wicket/request/resource/PackageResourceReference.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/request/resource/PackageResourceReference.java b/wicket-core/src/main/java/org/apache/wicket/request/resource/PackageResourceReference.java
index c7f8da1..e50dbc6 100644
--- a/wicket-core/src/main/java/org/apache/wicket/request/resource/PackageResourceReference.java
+++ b/wicket-core/src/main/java/org/apache/wicket/request/resource/PackageResourceReference.java
@@ -125,6 +125,7 @@ public class PackageResourceReference extends ResourceReference
final PackageResource resource;
final Url url = RequestCycle.get().getRequest().getUrl();
+ //resource attributes (locale, style, variation) might be encoded in the URL
final UrlAttributes urlAttributes = ResourceUtil.decodeResourceReferenceAttributes(url);
if (CSS_EXTENSION.equals(extension))
http://git-wip-us.apache.org/repos/asf/wicket/blob/b9f600f4/wicket-core/src/main/java/org/apache/wicket/resource/ResourceUtil.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/resource/ResourceUtil.java b/wicket-core/src/main/java/org/apache/wicket/resource/ResourceUtil.java
index b94ad25..6e55197 100644
--- a/wicket-core/src/main/java/org/apache/wicket/resource/ResourceUtil.java
+++ b/wicket-core/src/main/java/org/apache/wicket/resource/ResourceUtil.java
@@ -37,30 +37,47 @@ import org.apache.wicket.util.string.Strings;
*/
public class ResourceUtil
{
-
- public static ResourceReference.UrlAttributes decodeResourceReferenceAttributes(String attributes)
+ /**
+ * Reads resource reference attributes (style, locale, variation) encoded in the given string.
+ *
+ * @param encodedAttributes
+ * the string containing the resource attributes
+ * @return the encoded attributes
+ *
+ * @see ResourceReference.UrlAttributes
+ */
+ public static ResourceReference.UrlAttributes decodeResourceReferenceAttributes(String encodedAttributes)
{
Locale locale = null;
String style = null;
String variation = null;
- if (Strings.isEmpty(attributes) == false)
+ if (Strings.isEmpty(encodedAttributes) == false)
{
- String split[] = Strings.split(attributes, '-');
+ String split[] = Strings.split(encodedAttributes, '-');
locale = parseLocale(split[0]);
if (split.length == 2)
{
- style = Strings.notEmpty(unescapeAttributesSeparator(split[1]), null);
+ style = Strings.defaultIfEmpty(unescapeAttributesSeparator(split[1]), null);
}
else if (split.length == 3)
{
- style = Strings.notEmpty(unescapeAttributesSeparator(split[1]), null);
- variation = Strings.notEmpty(unescapeAttributesSeparator(split[2]), null);
+ style = Strings.defaultIfEmpty(unescapeAttributesSeparator(split[1]), null);
+ variation = Strings.defaultIfEmpty(unescapeAttributesSeparator(split[2]), null);
}
}
return new ResourceReference.UrlAttributes(locale, style, variation);
}
-
+
+ /**
+ * Reads resource reference attributes (style, locale, variation) encoded in the given URL.
+ *
+ * @param url
+ * the url containing the resource attributes
+ * @return the encoded attributes
+ *
+ * @see ResourceReference.UrlAttributes
+ */
public static ResourceReference.UrlAttributes decodeResourceReferenceAttributes(Url url)
{
Args.notNull(url, "url");
@@ -76,6 +93,15 @@ public class ResourceUtil
return new ResourceReference.UrlAttributes(null, null, null);
}
+ /**
+ * Encodes the given resource reference attributes returning the corresponding textual representation.
+ *
+ * @param attributes
+ * the resource reference attributes to encode
+ * @return the textual representation for the given attributes
+ *
+ * @see ResourceReference.UrlAttributes
+ */
public static String encodeResourceReferenceAttributes(ResourceReference.UrlAttributes attributes)
{
if (attributes == null ||
@@ -111,7 +137,17 @@ public class ResourceUtil
return res.toString();
}
}
-
+
+ /**
+ * Encodes the attributes of the given resource reference in the specified url.
+ *
+ * @param url
+ * the resource reference attributes to encode
+ * @param reference
+ *
+ * @see ResourceReference.UrlAttributes
+ * @see Url
+ */
public static void encodeResourceReferenceAttributes(Url url, ResourceReference reference)
{
String encoded = encodeResourceReferenceAttributes(reference.getUrlAttributes());
@@ -134,7 +170,14 @@ public class ResourceUtil
CharSequence tmp = Strings.replaceAll(attribute, "~", "~~");
return Strings.replaceAll(tmp, "-", "~");
}
-
+
+ /**
+ * Parses the string representation of a {@link java.util.Locale} (for example 'en_GB').
+ *
+ * @param locale
+ * the string representation of a {@link java.util.Locale}
+ * @return the corresponding {@link java.util.Locale} instance
+ */
public static Locale parseLocale(String locale)
{
if (Strings.isEmpty(locale))
http://git-wip-us.apache.org/repos/asf/wicket/blob/b9f600f4/wicket-util/src/main/java/org/apache/wicket/util/lang/Objects.java
----------------------------------------------------------------------
diff --git a/wicket-util/src/main/java/org/apache/wicket/util/lang/Objects.java b/wicket-util/src/main/java/org/apache/wicket/util/lang/Objects.java
index 42b14c5..787778b 100755
--- a/wicket-util/src/main/java/org/apache/wicket/util/lang/Objects.java
+++ b/wicket-util/src/main/java/org/apache/wicket/util/lang/Objects.java
@@ -767,14 +767,25 @@ public final class Objects
}
/**
+ * Returns the original object if this one is != null. If the original object is null
+ * the default one is returned. The default object has no restriction, it might be itself null.
+ *
+ * @param originalObj
+ * the original object
+ * @param defaultObj
+ * the default object
+ * @return the original object if not null, the default one otherwise.
+ */
+ public static <T> T defaultIfNull(T originalObj, T defaultObj)
+ {
+ return originalObj != null ? originalObj : defaultObj;
+ }
+
+ /**
* Instantiation not allowed
*/
private Objects()
{
}
- public static <T> T defaultIfNull(T originalObj, T defaultObj)
- {
- return originalObj != null ? originalObj : defaultObj;
- }
}
http://git-wip-us.apache.org/repos/asf/wicket/blob/b9f600f4/wicket-util/src/main/java/org/apache/wicket/util/string/Strings.java
----------------------------------------------------------------------
diff --git a/wicket-util/src/main/java/org/apache/wicket/util/string/Strings.java b/wicket-util/src/main/java/org/apache/wicket/util/string/Strings.java
index a9a54b9..3ac1c10 100755
--- a/wicket-util/src/main/java/org/apache/wicket/util/string/Strings.java
+++ b/wicket-util/src/main/java/org/apache/wicket/util/string/Strings.java
@@ -1563,15 +1563,18 @@ public final class Strings
}
}
- public static String notEmpty(String originalString, String normalizedValue)
+ /**
+ * Returns the original string if this one is not empty (i.e. {@link #isEmpty(CharSequence)} returns false),
+ * otherwise the default one is returned. The default string might be itself an empty one.
+ *
+ * @param originalString
+ * the original sting value
+ * @param defaultValue
+ * the default string to return if the original is empty
+ * @return the original string value if not empty, the default one otherwise
+ */
+ public static String defaultIfEmpty(String originalString, String defaultValue)
{
- if (isEmpty(originalString))
- {
- return normalizedValue;
- }
- else
- {
- return originalString;
- }
+ return isEmpty(originalString) ? defaultValue : originalString;
}
}
[3/9] wicket git commit: Update the version of Jetty used for the
quickstart
Posted by ad...@apache.org.
Update the version of Jetty used for the quickstart
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/f54d6476
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/f54d6476
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/f54d6476
Branch: refs/heads/WICKET-5906-7.x
Commit: f54d64765bf19e6645f52136b77da5fb1507b8aa
Parents: 5049aa8
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Sat May 30 15:04:32 2015 +0300
Committer: Andrea Del Bene <“adelbene@apache.org”>
Committed: Thu Jun 4 16:19:29 2015 +0200
----------------------------------------------------------------------
.../quickstart/src/main/resources/archetype-resources/pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/wicket/blob/f54d6476/archetypes/quickstart/src/main/resources/archetype-resources/pom.xml
----------------------------------------------------------------------
diff --git a/archetypes/quickstart/src/main/resources/archetype-resources/pom.xml b/archetypes/quickstart/src/main/resources/archetype-resources/pom.xml
index ebe6881..836f9df 100644
--- a/archetypes/quickstart/src/main/resources/archetype-resources/pom.xml
+++ b/archetypes/quickstart/src/main/resources/archetype-resources/pom.xml
@@ -43,7 +43,7 @@
</licenses>
<properties>
<wicket.version>7.0.0-SNAPSHOT</wicket.version>
- <jetty9.version>9.2.10.v20150310</jetty9.version>
+ <jetty9.version>9.2.11.v20150529</jetty9.version>
<log4j.version>2.3</log4j.version>
<junit.version>4.12</junit.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
[5/9] wicket git commit: WICKET-5901 Leaving veil when ajax
processing ends with redirect
Posted by ad...@apache.org.
WICKET-5901 Leaving veil when ajax processing ends with redirect
Do not hide the Ajax indicator if there is a redirect to another page
(cherry picked from commit ad89910da115454f0f54cc33f9a14a6fc4a41e52)
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/adb475f3
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/adb475f3
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/adb475f3
Branch: refs/heads/WICKET-5906-7.x
Commit: adb475f3004644fdad78570714f4542c8a8fa95f
Parents: f54d647
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Fri May 22 23:53:31 2015 +0300
Committer: Andrea Del Bene <“adelbene@apache.org”>
Committed: Thu Jun 4 16:19:29 2015 +0200
----------------------------------------------------------------------
.../java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/wicket/blob/adb475f3/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js b/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js
index 0261de3..88d3983 100644
--- a/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js
+++ b/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js
@@ -695,7 +695,7 @@
complete: function (jqXHR, textStatus) {
context.steps.push(jQuery.proxy(function (notify) {
- if (attrs.i) {
+ if (attrs.i && context.isRedirecting !== true) {
Wicket.DOM.hideIncrementally(attrs.i);
}
@@ -766,6 +766,7 @@
// support/check for non-relative redirectUrl like as provided and needed in a portlet context
if (redirectUrl.charAt(0) === '/' || rhttp.test(redirectUrl) || rhttps.test(redirectUrl)) {
+ context.isRedirecting = true;
window.location = redirectUrl;
}
else {
@@ -790,6 +791,7 @@
calculatedRedirect = window.location.protocol + "//" + window.location.host + calculatedRedirect;
}
+ context.isRedirecting = true;
window.location = calculatedRedirect;
}
}
@@ -920,7 +922,7 @@
}, 0);
var attrs = context.attrs;
- if (attrs.i) {
+ if (attrs.i && context.isRedirecting !== true) {
// hide the indicator
Wicket.DOM.hideIncrementally(attrs.i);
}
@@ -1238,6 +1240,7 @@
processRedirect: function (context, node) {
var text = Wicket.DOM.text(node);
Wicket.Log.info("Redirecting to: " + text);
+ context.isRedirecting = true;
window.location = text;
},