You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by an...@apache.org on 2008/06/03 23:34:08 UTC
svn commit: r662899 - in /lenya/trunk/src/modules-core/linking/java:
src/org/apache/lenya/cms/linking/
test/org/apache/lenya/cms/cocoon/transformation/
test/org/apache/lenya/cms/linking/
Author: andreas
Date: Tue Jun 3 14:34:08 2008
New Revision: 662899
URL: http://svn.apache.org/viewvc?rev=662899&view=rev
Log:
Always configure proxy URLs in proxy test, handle query strings when rewriting links, handle URLs with trailing slashes correctly when rewriting links.
Modified:
lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/OutgoingLinkRewriter.java
lenya/trunk/src/modules-core/linking/java/test/org/apache/lenya/cms/cocoon/transformation/ProxyTransformerTest.java
lenya/trunk/src/modules-core/linking/java/test/org/apache/lenya/cms/linking/OutgoingLinkRewriterTest.java
Modified: lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/OutgoingLinkRewriter.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/OutgoingLinkRewriter.java?rev=662899&r1=662898&r2=662899&view=diff
==============================================================================
--- lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/OutgoingLinkRewriter.java (original)
+++ lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/OutgoingLinkRewriter.java Tue Jun 3 14:34:08 2008
@@ -141,9 +141,29 @@
public String rewrite(final String url) {
String rewrittenUrl = "";
-
+
+ String path;
+ String suffix;
+
+ int numIndex = url.indexOf('#');
+ if (numIndex > -1) {
+ path = url.substring(0, numIndex);
+ suffix = url.substring(numIndex);
+ }
+ else {
+ int qmIndex = url.indexOf('?');
+ if (qmIndex > -1) {
+ path = url.substring(0, qmIndex);
+ suffix = url.substring(qmIndex);
+ }
+ else {
+ path = url;
+ suffix = "";
+ }
+ }
+
try {
- String normalizedUrl = normalizeUrl(url);
+ String normalizedUrl = normalizeUrl(path);
if (this.relativeUrls) {
rewrittenUrl = getRelativeUrlTo(normalizedUrl);
} else {
@@ -176,7 +196,7 @@
} catch (Exception e) {
throw new RuntimeException(e);
}
- return rewrittenUrl;
+ return rewrittenUrl + suffix;
}
protected String normalizeUrl(final String url) throws URISyntaxException {
@@ -242,10 +262,12 @@
else {
List sourceSteps = toList(this.requestUrl);
List targetSteps = toList(webappUrl);
+
+ String lastEqualStep = null;
while (!sourceSteps.isEmpty() && !targetSteps.isEmpty()
&& sourceSteps.get(0).equals(targetSteps.get(0))) {
- sourceSteps.remove(0);
+ lastEqualStep = (String) sourceSteps.remove(0);
targetSteps.remove(0);
}
@@ -259,6 +281,9 @@
else if (sourceSteps.size() > 1) {
prefix = generateUpDots(sourceSteps.size() - 1) + "/";
}
+ else if (sourceSteps.size() == 1 && targetSteps.get(0).equals("")) {
+ prefix = generateUpDots(1) + "/" + lastEqualStep + "/";
+ }
String[] targetArray = (String[]) targetSteps.toArray(new String[targetSteps.size()]);
String targetPath = StringUtil.join(targetArray, "/");
Modified: lenya/trunk/src/modules-core/linking/java/test/org/apache/lenya/cms/cocoon/transformation/ProxyTransformerTest.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/linking/java/test/org/apache/lenya/cms/cocoon/transformation/ProxyTransformerTest.java?rev=662899&r1=662898&r2=662899&view=diff
==============================================================================
--- lenya/trunk/src/modules-core/linking/java/test/org/apache/lenya/cms/cocoon/transformation/ProxyTransformerTest.java (original)
+++ lenya/trunk/src/modules-core/linking/java/test/org/apache/lenya/cms/cocoon/transformation/ProxyTransformerTest.java Tue Jun 3 14:34:08 2008
@@ -123,8 +123,6 @@
selector = (ServiceSelector) getManager().lookup(Instantiator.ROLE + "Selector");
instantiator = (Instantiator) selector.select(defaultPub.getInstantiatorHint());
instantiator.instantiate(defaultPub, pubId, "Mock");
- Publication mockPub = getFactory().getPublication(pubId);
- configureProxy(mockPub, area, proxyUrl);
} finally {
if (selector != null) {
if (instantiator != null) {
@@ -134,6 +132,8 @@
}
}
}
+ Publication mockPub = getFactory().getPublication(pubId);
+ configureProxy(mockPub, area, proxyUrl);
}
protected void configureProxy(Publication pub, String area, String proxyUrl) throws Exception {
Modified: lenya/trunk/src/modules-core/linking/java/test/org/apache/lenya/cms/linking/OutgoingLinkRewriterTest.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/linking/java/test/org/apache/lenya/cms/linking/OutgoingLinkRewriterTest.java?rev=662899&r1=662898&r2=662899&view=diff
==============================================================================
--- lenya/trunk/src/modules-core/linking/java/test/org/apache/lenya/cms/linking/OutgoingLinkRewriterTest.java (original)
+++ lenya/trunk/src/modules-core/linking/java/test/org/apache/lenya/cms/linking/OutgoingLinkRewriterTest.java Tue Jun 3 14:34:08 2008
@@ -25,8 +25,14 @@
public void testRelativeUrls() throws Exception {
Session session = login("lenya");
String url = "/aaa/bbb/ccc";
- OutgoingLinkRewriter rewriter = new OutgoingLinkRewriter(getManager(), session, url, false, false, true);
-
+
+ boolean ssl = false;
+ boolean considerSslPolicies = false;
+ boolean relativeUrls = true;
+
+ OutgoingLinkRewriter rewriter = new OutgoingLinkRewriter(getManager(), session, url, ssl,
+ considerSslPolicies, relativeUrls);
+
assertEquals(rewriter.rewrite("/aaa/bbb/foo"), "foo");
assertEquals(rewriter.rewrite("/aaa/bbb"), "..");
assertEquals(rewriter.rewrite("/aaa/bbb/ccc/ddd"), "ccc/ddd");
@@ -34,6 +40,9 @@
assertEquals(rewriter.rewrite("/aaa/foo/bar"), "../foo/bar");
assertEquals(rewriter.rewrite("/foo/bar"), "../../foo/bar");
assertEquals(rewriter.rewrite("/aaa/foo/bar/baz"), "../foo/bar/baz");
+ assertEquals(rewriter.rewrite("/aaa/bbb/?hello"), "../bbb/?hello");
+ assertEquals(rewriter.rewrite("/aaa/?hello"), "../?hello");
+ assertEquals(rewriter.rewrite("/?hello"), "../../?hello");
}
-
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org