lenya-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From andr...@apache.org
Subject svn commit: r1052370 - /lenya/branches/BRANCH_2_0_X/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/LinkConverter.java
Date Thu, 23 Dec 2010 20:50:07 GMT
Author: andreas
Date: Thu Dec 23 20:50:07 2010
New Revision: 1052370

URL: http://svn.apache.org/viewvc?rev=1052370&view=rev
Log:
Try new and old transaction for link rewriting. Considers #47621 and #50493.

Modified:
    lenya/branches/BRANCH_2_0_X/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/LinkConverter.java

Modified: lenya/branches/BRANCH_2_0_X/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/LinkConverter.java
URL: http://svn.apache.org/viewvc/lenya/branches/BRANCH_2_0_X/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/LinkConverter.java?rev=1052370&r1=1052369&r2=1052370&view=diff
==============================================================================
--- lenya/branches/BRANCH_2_0_X/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/LinkConverter.java
(original)
+++ lenya/branches/BRANCH_2_0_X/src/modules-core/linking/java/src/org/apache/lenya/cms/linking/LinkConverter.java
Thu Dec 23 20:50:07 2010
@@ -37,8 +37,7 @@ import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 
 /**
- * Utility class to convert <code>lenya-document:</code> links from and to URL
- * links.
+ * Utility class to convert <code>lenya-document:</code> links from and to URL
links.
  */
 public class LinkConverter extends AbstractLogEnabled {
 
@@ -64,8 +63,8 @@ public class LinkConverter extends Abstr
     }
 
     /**
-     * Converts all URL-based links to UUID-based links. The link URLs can
-     * originate from a different publication.
+     * Converts all URL-based links to UUID-based links. The link URLs can originate from
a
+     * different publication.
      * @param srcPub The publication where the content comes from.
      * @param examinedDocument The document in the target publication.
      * @param useContextPath If the request's context path should be considered.
@@ -88,16 +87,21 @@ public class LinkConverter extends Abstr
             } else {
                 Publication pub = examinedDocument.getPublication();
                 ChainLinkRewriter incomingRewriter = new ChainLinkRewriter();
-                incomingRewriter.add(new RelativeToAbsoluteLinkRewriter(examinedDocument.getCanonicalWebappURL()));
+                incomingRewriter.add(new RelativeToAbsoluteLinkRewriter(examinedDocument
+                        .getCanonicalWebappURL()));
                 incomingRewriter.add(new IncomingLinkRewriter(pub));
 
                 // Workaround:
-                // We create a new session because the sitetree of the transaction doesn't
yet contain
+                // We create a new session because the sitetree of the transaction doesn't
yet
+                // contain
                 // references to any new documents that were uploaded during the transaction.
                 // See https://issues.apache.org/bugzilla/show_bug.cgi?id=47621
-                Session readOnlySession = RepositoryUtil.createSession(this.manager, examinedDocument.getSession().getIdentity(),
false);
-                DocumentFactory newFactory = DocumentUtil.createDocumentFactory(this.manager,
readOnlySession);
-                LinkRewriter urlToUuidRewriter = new UrlToUuidRewriter(newFactory);
+                Session readOnlySession = RepositoryUtil.createSession(this.manager,
+                        examinedDocument.getSession().getIdentity(), false);
+                DocumentFactory newFactory = DocumentUtil.createDocumentFactory(this.manager,
+                        readOnlySession);
+                final LinkRewriter[] rewriters = { new UrlToUuidRewriter(pub.getFactory()),
+                        new UrlToUuidRewriter(newFactory) };
 
                 org.w3c.dom.Document xml = DocumentHelper.readDocument(examinedDocument
                         .getInputStream());
@@ -119,7 +123,8 @@ public class LinkConverter extends Abstr
                         if (getLogger().isDebugEnabled()) {
                             getLogger().debug("Convert links: Check URL [" + url + "]");
                         }
-                        final String originalUrl = url.startsWith(prefix) ? url.substring(prefix.length())
: url;
+                        final String originalUrl = url.startsWith(prefix) ? url.substring(prefix
+                                .length()) : url;
                         final String srcPubUrl;
                         if (incomingRewriter.matches(originalUrl)) {
                             srcPubUrl = incomingRewriter.rewrite(originalUrl);
@@ -128,11 +133,16 @@ public class LinkConverter extends Abstr
                         }
                         final String srcPubPrefix = "/" + srcPub.getId() + "/";
                         if (srcPubUrl.startsWith(srcPubPrefix)) {
-                            final String destPubUrl = "/" + pub.getId() + "/" + srcPubUrl.substring(srcPubPrefix.length());
-                            if (urlToUuidRewriter.matches(destPubUrl)) {
-                                String rewrittenUrl = urlToUuidRewriter.rewrite(destPubUrl);
-                                attribute.setValue(rewrittenUrl);
-                                linksRewritten = true;
+                            final String destPubUrl = "/" + pub.getId() + "/"
+                                    + srcPubUrl.substring(srcPubPrefix.length());
+                            boolean rewritten = false;
+                            for (final LinkRewriter rewriter : rewriters) {
+                                if (!rewritten && rewriter.matches(destPubUrl)) {
+                                    String rewrittenUrl = rewriter.rewrite(destPubUrl);
+                                    attribute.setValue(rewrittenUrl);
+                                    linksRewritten = true;
+                                    rewritten = !rewrittenUrl.equals(destPubUrl);
+                                }
                             }
                         }
                     }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org


Mime
View raw message