lenya-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From andr...@apache.org
Subject cvs commit: cocoon-lenya/src/java/org/apache/lenya/cms/ac2/workflow WorkflowAuthorizer.java
Date Tue, 05 Aug 2003 11:56:57 GMT
andreas     2003/08/05 04:56:57

  Modified:    src/java/org/apache/lenya/cms/publication
                        PublicationFactory.java
               src/java/org/apache/lenya/cms/ac2/workflow
                        WorkflowAuthorizer.java
  Log:
  new method in PublicationFactory
  
  Revision  Changes    Path
  1.12      +50 -17    cocoon-lenya/src/java/org/apache/lenya/cms/publication/PublicationFactory.java
  
  Index: PublicationFactory.java
  ===================================================================
  RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/publication/PublicationFactory.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- PublicationFactory.java	18 Jul 2003 18:02:02 -0000	1.11
  +++ PublicationFactory.java	5 Aug 2003 11:56:57 -0000	1.12
  @@ -58,11 +58,15 @@
   import org.apache.cocoon.environment.Context;
   import org.apache.cocoon.environment.ObjectModelHelper;
   import org.apache.cocoon.environment.Request;
  +import org.apache.excalibur.source.Source;
  +import org.apache.excalibur.source.SourceResolver;
   
  +import org.apache.lenya.util.ServletHelper;
   import org.apache.log4j.Category;
   
   import java.io.File;
   import java.io.IOException;
  +import java.net.URI;
   import java.util.HashMap;
   import java.util.Map;
   
  @@ -76,10 +80,10 @@
        * Create a new <code>PublicationFactory</code>.
        * 
        */
  -    private PublicationFactory() {}
  +    private PublicationFactory() {
  +    }
   
  -    private static Category log =
  -        Category.getInstance(PublicationFactory.class);
  +    private static Category log = Category.getInstance(PublicationFactory.class);
       private static Map idToPublication = new HashMap();
   
       /**
  @@ -93,9 +97,8 @@
        * 
        * @throws PublicationException if there was a problem creating the publication.
        */
  -    public static Publication getPublication(Map objectModel)
  -        throws PublicationException {
  -        	
  +    public static Publication getPublication(Map objectModel) throws PublicationException
{
  +
           assert objectModel != null;
           Request request = ObjectModelHelper.getRequest(objectModel);
           Context context = ObjectModelHelper.getContext(objectModel);
  @@ -113,9 +116,7 @@
        * 
        * @throws PublicationException if there was a problem creating the publication.
        */
  -    public static Publication getPublication(
  -        String id,
  -        String servletContextPath)
  +    public static Publication getPublication(String id, String servletContextPath)
           throws PublicationException {
   
           assert id != null;
  @@ -124,7 +125,7 @@
           Publication publication;
   
           if (idToPublication.containsKey(id)) {
  -            publication = (Publication)idToPublication.get(id);
  +            publication = (Publication) idToPublication.get(id);
           } else {
               publication = new Publication(id, servletContextPath);
               idToPublication.put(id, publication);
  @@ -154,8 +155,7 @@
               contextPath = "";
           }
   
  -        String webappUri =
  -            request.getRequestURI().substring(contextPath.length());
  +        String webappUri = request.getRequestURI().substring(contextPath.length());
   
           String publicationId = webappUri.split("/")[1];
           assert !"".equals(publicationId);
  @@ -163,10 +163,17 @@
           String servletContextPath = context.getRealPath("");
           return getPublication(publicationId, servletContextPath);
       }
  -    
  +
  +    /**
  +     * Creates a publication from a webapp URL and a servlet context directory.
  +     * @param webappUrl The URL within the web application (without context prefix)
  +     * @param servletContext The Lenya servlet context directory
  +     * @return A publication
  +     * @throws PublicationException when something went wrong
  +     */
       public static Publication getPublication(String webappUrl, File servletContext)
           throws PublicationException {
  -        
  +
           String url = webappUrl;
           if (url.startsWith("/")) {
               url = url.substring(1);
  @@ -178,7 +185,7 @@
           }
   
           String publicationId = url.substring(0, slashIndex);
  -        
  +
           Publication publication;
           try {
               publication = getPublication(publicationId, servletContext.getCanonicalPath());
  @@ -203,9 +210,35 @@
                   new File(servletContext, Publication.PUBLICATION_PREFIX + File.separator
+ id);
               if (publicationDirectory.isDirectory()) {
                   exists = true;
  -}
  +            }
           }
           return exists;
  +    }
  +
  +    /**
  +     * Creates a publication using a source resolver and a request.
  +     * @param resolver The source resolver.
  +     * @param request The request.
  +     * @return A publication.
  +     * @throws PublicationException when something went wrong.
  +     */
  +    public static Publication getPublication(SourceResolver resolver, Request request)
  +        throws PublicationException {
  +        Publication publication;
  +        String webappUri = ServletHelper.getWebappURI(request);
  +        Source source = null;
  +        try {
  +            source = resolver.resolveURI("context:///");
  +            File servletContext = new File(new URI(source.getURI()));
  +            publication = PublicationFactory.getPublication(webappUri, servletContext);
  +        } catch (Exception e) {
  +            throw new PublicationException(e);
  +        } finally {
  +            if (source != null) {
  +                resolver.release(source);
  +            }
  +        }
  +        return publication;
       }
   
   }
  
  
  
  1.15      +2 -7      cocoon-lenya/src/java/org/apache/lenya/cms/ac2/workflow/WorkflowAuthorizer.java
  
  Index: WorkflowAuthorizer.java
  ===================================================================
  RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/ac2/workflow/WorkflowAuthorizer.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- WorkflowAuthorizer.java	30 Jul 2003 15:06:04 -0000	1.14
  +++ WorkflowAuthorizer.java	5 Aug 2003 11:56:57 -0000	1.15
  @@ -60,7 +60,6 @@
   import org.apache.avalon.framework.service.ServiceManager;
   import org.apache.avalon.framework.service.Serviceable;
   import org.apache.cocoon.environment.Request;
  -import org.apache.excalibur.source.Source;
   import org.apache.excalibur.source.SourceResolver;
   
   import org.apache.lenya.cms.ac.AccessControlException;
  @@ -79,8 +78,6 @@
   import org.apache.lenya.workflow.Situation;
   import org.apache.lenya.workflow.WorkflowInstance;
   
  -import java.io.File;
  -import java.net.URI;
   import java.util.Arrays;
   
   /**
  @@ -126,9 +123,7 @@
           if (event != null) {
               try {
                   resolver = (SourceResolver) manager.lookup(SourceResolver.ROLE);
  -                Source servletContextSource = resolver.resolveURI("context:///");
  -                File servletContext = new File(new URI(servletContextSource.getURI()));
  -                Publication publication = PublicationFactory.getPublication(url, servletContext);
  +                Publication publication = PublicationFactory.getPublication(resolver, request);
   
                   if (DefaultDocumentBuilder.getInstance().isDocument(publication, url))
{
   
  
  
  

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


Mime
View raw message