Revision: 641
http://stripes.svn.sourceforge.net/stripes/?rev=641&view=rev
Author: bengunter
Date: 2007-12-03 11:07:36 -0800 (Mon, 03 Dec 2007)
Log Message:
-----------
Fixed STS-444: Friendly URLs and suffixes. If a literal suffix is present in a
@UrlBinding, then that suffix will always be appended even if one or more
parameters are omitted when the URL is built. Likewise, the suffix will always
be ignored when parsing parameter values out of a URI.
Modified Paths:
--------------
trunk/stripes/src/net/sourceforge/stripes/controller/UrlBinding.java
trunk/stripes/src/net/sourceforge/stripes/controller/UrlBindingFactory.java
trunk/stripes/src/net/sourceforge/stripes/util/UrlBuilder.java
Modified: trunk/stripes/src/net/sourceforge/stripes/controller/UrlBinding.java
===================================================================
--- trunk/stripes/src/net/sourceforge/stripes/controller/UrlBinding.java
2007-12-03 13:57:57 UTC (rev 640)
+++ trunk/stripes/src/net/sourceforge/stripes/controller/UrlBinding.java
2007-12-03 19:07:36 UTC (rev 641)
@@ -29,7 +29,7 @@
*/
public class UrlBinding {
protected Class<? extends ActionBean> beanType;
- protected String path;
+ protected String path, suffix;
protected List<Object> components;
protected List<UrlBindingParameter> parameters;
@@ -52,6 +52,13 @@
this.parameters.add((UrlBindingParameter) component);
}
}
+
+ if (this.parameters.size() > 0) {
+ Object last = this.components.get(this.components.size() - 1);
+ if (last instanceof String) {
+ this.suffix = (String) last;
+ }
+ }
}
/**
@@ -97,6 +104,14 @@
return path;
}
+ /**
+ * If this binding includes one or more parameters and the last component
is a [EMAIL PROTECTED] String},
+ * then this method will return that last component. Otherwise, it returns
null.
+ */
+ public String getSuffix() {
+ return suffix;
+ }
+
@Override
public String toString() {
StringBuilder buf = new StringBuilder(getPath());
Modified:
trunk/stripes/src/net/sourceforge/stripes/controller/UrlBindingFactory.java
===================================================================
--- trunk/stripes/src/net/sourceforge/stripes/controller/UrlBindingFactory.java
2007-12-03 13:57:57 UTC (rev 640)
+++ trunk/stripes/src/net/sourceforge/stripes/controller/UrlBindingFactory.java
2007-12-03 19:07:36 UTC (rev 641)
@@ -152,6 +152,12 @@
while (uri.charAt(length - 1) == '/')
--length;
+ // check for literal suffix in prototype and ignore it if found
+ String suffix = prototype.getSuffix();
+ if (suffix != null && uri.endsWith(suffix)) {
+ length -= suffix.length();
+ }
+
// extract the request parameters and add to new binding object
ArrayList<Object> components = new
ArrayList<Object>(prototype.getComponents().size());
int index = prototype.getPath().length();
Modified: trunk/stripes/src/net/sourceforge/stripes/util/UrlBuilder.java
===================================================================
--- trunk/stripes/src/net/sourceforge/stripes/util/UrlBuilder.java
2007-12-03 13:57:57 UTC (rev 640)
+++ trunk/stripes/src/net/sourceforge/stripes/util/UrlBuilder.java
2007-12-03 19:07:36 UTC (rev 641)
@@ -434,9 +434,14 @@
break;
}
}
+
+ // always append trailing literal if one is present
if (nextLiteral != null) {
buf.append(nextLiteral);
}
+ else if (binding.getSuffix() != null) {
+ buf.append(binding.getSuffix());
+ }
return buf.toString();
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper
from Novell. From the desktop to the data center, Linux is going
mainstream. Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
_______________________________________________
Stripes-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-development