svn commit: r596631 - /lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/cocoon/source/DocumentSourceFactory.java

[email protected]
Newsgroups gmane.comp.cms.lenya.cvs
Message-ID <[email protected]>
Author: andreas
Date: Tue Nov 20 03:39:12 2007
New Revision: 596631

URL: http://svn.apache.org/viewvc?rev=596631&view=rev
Log:
DocumentSourceFactory: Provide available context information to links

Modified:
    lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/cocoon/source/DocumentSourceFactory.java

Modified: lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/cocoon/source/DocumentSourceFactory.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/cocoon/source/DocumentSourceFactory.java?rev=596631&r1=596630&r2=596631&view=diff
==============================================================================
--- lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/cocoon/source/DocumentSourceFactory.java (original)
+++ lenya/trunk/src/modules-core/linking/java/src/org/apache/lenya/cms/cocoon/source/DocumentSourceFactory.java Tue Nov 20 03:39:12 2007
@@ -39,12 +39,14 @@
 import org.apache.excalibur.source.SourceException;
 import org.apache.excalibur.source.SourceFactory;
 import org.apache.excalibur.source.SourceResolver;
+import org.apache.lenya.cms.linking.Link;
 import org.apache.lenya.cms.linking.LinkResolver;
 import org.apache.lenya.cms.linking.LinkTarget;
 import org.apache.lenya.cms.publication.Document;
 import org.apache.lenya.cms.publication.DocumentException;
 import org.apache.lenya.cms.publication.DocumentFactory;
 import org.apache.lenya.cms.publication.DocumentUtil;
+import org.apache.lenya.cms.publication.URLInformation;
 import org.apache.lenya.util.Query;
 import org.apache.lenya.util.ServletHelper;
 
@@ -130,7 +132,9 @@
                 target = resolver.resolve(currentDoc, linkUri);
             }
             else {
-                target = resolver.resolve(factory, linkUri);
+                Link link = new Link(linkUri);
+                contextualize(link, webappUrl);
+                target = resolver.resolve(factory, link.getUri());
             }
 
             Document doc = target.getDocument();
@@ -161,6 +165,21 @@
             throw new RuntimeException(e);
         }
 
+    }
+
+    /**
+     * If the link doesn't contain context information (publication ID, area), provide it.
+     * @param link The link.
+     * @param webappUrl The web application URL to extract the context information from..
+     */
+    protected void contextualize(Link link, String webappUrl) {
+        URLInformation url = new URLInformation(webappUrl);
+        if (link.getPubId() == null) {
+            link.setPubId(url.getPublicationId());
+        }
+        if (link.getArea() == null) {
+            link.setArea(url.getArea());
+        }
     }
 
     protected Source getFormatSource(Document doc, String format) throws DocumentException,
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.