You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2010/10/19 21:58:03 UTC
svn commit: r1024386 - in
/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5:
internal/services/ContextPathEncoderImpl.java
services/ContextPathEncoder.java
Author: hlship
Date: Tue Oct 19 19:58:03 2010
New Revision: 1024386
URL: http://svn.apache.org/viewvc?rev=1024386&view=rev
Log:
TAP5-1306: Add method for encoding a single value to ContextPathEncoder
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ContextPathEncoderImpl.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/ContextPathEncoder.java
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ContextPathEncoderImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ContextPathEncoderImpl.java?rev=1024386&r1=1024385&r2=1024386&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ContextPathEncoderImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ContextPathEncoderImpl.java Tue Oct 19 19:58:03 2010
@@ -1,10 +1,10 @@
-// Copyright 2008, 2010 The Apache Software Foundation
+// Copyright 2008, 2010 The Apache Software Foundation
//
// 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
+// 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,
@@ -43,29 +43,36 @@ public class ContextPathEncoderImpl impl
this.typeCoercer = typeCoercer;
}
+ public String encodeValue(Object value)
+ {
+ String valueEncoded = value == null ? null : valueEncoder.toClient(value);
+
+ return urlEncoder.encode(valueEncoded);
+ }
+
public String encodeIntoPath(Object[] context)
{
- if (context == null || context.length == 0) return "";
+ if (context == null || context.length == 0)
+ return "";
- return encodeIntoPath(new ArrayEventContext(typeCoercer, context));
+ return encodeIntoPath(new ArrayEventContext(typeCoercer, context));
}
public String encodeIntoPath(EventContext context)
{
assert context != null;
int count = context.getCount();
-
+
StringBuilder output = new StringBuilder(BUFFER_SIZE);
for (int i = 0; i < count; i++)
{
Object raw = context.get(Object.class, i);
- String valueEncoded = raw == null ? null : valueEncoder.toClient(raw);
-
- String urlEncoded = urlEncoder.encode(valueEncoded);
+ String urlEncoded = encodeValue(raw);
- if (i > 0) output.append("/");
+ if (i > 0)
+ output.append("/");
output.append(urlEncoded);
}
@@ -75,7 +82,8 @@ public class ContextPathEncoderImpl impl
public EventContext decodePath(String path)
{
- if (InternalUtils.isBlank(path)) return EMPTY;
+ if (InternalUtils.isBlank(path))
+ return EMPTY;
String[] split = TapestryInternalUtils.splitPath(path);
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/ContextPathEncoder.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/ContextPathEncoder.java?rev=1024386&r1=1024385&r2=1024386&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/ContextPathEncoder.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/ContextPathEncoder.java Tue Oct 19 19:58:03 2010
@@ -1,10 +1,10 @@
-// Copyright 2008 The Apache Software Foundation
+// Copyright 2008, 2010 The Apache Software Foundation
//
// 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
+// 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,
@@ -23,21 +23,31 @@ import org.apache.tapestry5.EventContext
public interface ContextPathEncoder
{
/**
+ * Encodes a single value via the {@link ContextValueEncoder} service, returning the resulting string. Even null
+ * is encoded, as per {@link URLEncoder#encode(String)}.
+ *
+ * @since 5.2.2
+ */
+ String encodeValue(Object value);
+
+ /**
* Encodes the context values into a path string. Each context value (if non-null) is first value encoded into a
- * string via the {@link org.apache.tapestry5.services.ContextValueEncoder} service. Those values are then encoded,
- * via {@link URLEncoder#encode(String)} into URL-safe strings. The URL-safe strings are then concatinated
- * together, seperated with "/" characters.
- *
- * @param context an array of objects to encode as the context (may be null)
+ * string via the {@link org.apache.tapestry5.services.ContextValueEncoder} service. Those values are then encoded,
+ * via {@link URLEncoder#encode(String)} into URL-safe strings. The URL-safe strings are then concatenated
+ * together, separated with "/" characters.
+ *
+ * @param context
+ * an array of objects to encode as the context (may be null)
* @return the path-encoded context, or the blank string if the context is empty
*/
String encodeIntoPath(Object[] context);
/**
* Encodes the context into a string. Returns the empty string if the context is empty.
- *
- * @param context to encode
- * @return encoded values seperated by "/" characters, or the empty string
+ *
+ * @param context
+ * to encode
+ * @return encoded values separated by "/" characters, or the empty string
* @since 5.1.0.2
*/
String encodeIntoPath(EventContext context);
@@ -45,8 +55,9 @@ public interface ContextPathEncoder
/**
* Inverse of {@link #encodeIntoPath(Object[])}; the path is split into strings, and the string are decoded and
* constructed into an {@link org.apache.tapestry5.EventContext}.
- *
- * @param path to decode, possibly empty or null
+ *
+ * @param path
+ * to decode, possibly empty or null
* @return corresponding event context
*/
EventContext decodePath(String path);