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 2006/06/12 10:31:02 UTC

svn commit: r413608 - /lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentUtil.java

Author: andreas
Date: Mon Jun 12 01:31:01 2006
New Revision: 413608

URL: http://svn.apache.org/viewvc?rev=413608&view=rev
Log:
Added method to get the currently requested document to DocumentUtil

Modified:
    lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentUtil.java

Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentUtil.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentUtil.java?rev=413608&r1=413607&r2=413608&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentUtil.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentUtil.java Mon Jun 12 01:31:01 2006
@@ -18,7 +18,11 @@
 
 import org.apache.avalon.framework.service.ServiceException;
 import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.cocoon.environment.Request;
+import org.apache.lenya.cms.repository.RepositoryException;
+import org.apache.lenya.cms.repository.RepositoryUtil;
 import org.apache.lenya.cms.repository.Session;
+import org.apache.lenya.util.ServletHelper;
 
 /**
  * Document utility class.
@@ -39,13 +43,32 @@
             map = docManager.createDocumentIdentityMap(session);
         } catch (ServiceException e) {
             throw new RuntimeException(e);
-        }
-        finally {
+        } finally {
             if (docManager != null) {
                 manager.release(docManager);
             }
         }
         return map;
     }
-    
+
+    /**
+     * Returns the currently requested document or <code>null</code> if no document is requested.
+     * @param manager The service manager.
+     * @param request The request.
+     * @return A document.
+     * @throws RepositoryException if an error occurs.
+     * @throws DocumentBuildException if an error occurs.
+     */
+    public static Document getCurrentDocument(ServiceManager manager, Request request)
+            throws RepositoryException, DocumentBuildException {
+        Session session = RepositoryUtil.getSession(manager, request);
+        DocumentFactory factory = DocumentUtil.createDocumentIdentityMap(manager, session);
+        String url = ServletHelper.getWebappURI(request);
+        Document doc = null;
+        if (factory.isDocument(url)) {
+            doc = factory.getFromURL(url);
+        }
+        return doc;
+    }
+
 }



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