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 2003/10/10 17:41:07 UTC

cvs commit: cocoon-lenya/src/java/org/apache/lenya/cms/cocoon/components/modules/input FallbackModule.java AbstractPageEnvelopeModule.java PageEnvelopeModule.java

andreas     2003/10/10 08:41:07

  Modified:    src/java/org/apache/lenya/cms/cocoon/components/modules/input
                        PageEnvelopeModule.java
  Added:       src/java/org/apache/lenya/cms/cocoon/components/modules/input
                        FallbackModule.java AbstractPageEnvelopeModule.java
  Log:
  introducing AbstractPageEnvelopeModule and FallbackModule
  
  Revision  Changes    Path
  1.31      +2 -3      cocoon-lenya/src/java/org/apache/lenya/cms/cocoon/components/modules/input/PageEnvelopeModule.java
  
  Index: PageEnvelopeModule.java
  ===================================================================
  RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/cocoon/components/modules/input/PageEnvelopeModule.java,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- PageEnvelopeModule.java	26 Sep 2003 10:16:39 -0000	1.30
  +++ PageEnvelopeModule.java	10 Oct 2003 15:41:07 -0000	1.31
  @@ -62,7 +62,6 @@
   import org.apache.avalon.framework.service.ServiceManager;
   import org.apache.avalon.framework.service.Serviceable;
   
  -import org.apache.cocoon.components.modules.input.AbstractInputModule;
   import org.apache.cocoon.environment.ObjectModelHelper;
   import org.apache.cocoon.environment.Request;
   import org.apache.lenya.cms.cocoon.uriparameterizer.URIParameterizer;
  @@ -84,7 +83,7 @@
    * 
    * @author  andreas
    */
  -public class PageEnvelopeModule extends AbstractInputModule implements Serviceable {
  +public class PageEnvelopeModule extends AbstractPageEnvelopeModule implements Serviceable {
   
       private ServiceManager manager;
   
  
  
  
  1.1                  cocoon-lenya/src/java/org/apache/lenya/cms/cocoon/components/modules/input/FallbackModule.java
  
  Index: FallbackModule.java
  ===================================================================
  /*
  $Id: FallbackModule.java,v 1.1 2003/10/10 15:41:07 andreas Exp $
  <License>
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Lenya" and  "Apache Software Foundation"  must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Michael Wechner <mi...@apache.org>. For more information on the Apache Soft-
   ware Foundation, please see <http://www.apache.org/>.
  
   Lenya includes software developed by the Apache Software Foundation, W3C,
   DOM4J Project, BitfluxEditor, Xopus, and WebSHPINX.
  </License>
  */
  package org.apache.lenya.cms.cocoon.components.modules.input;
  
  import java.util.Collections;
  import java.util.Iterator;
  import java.util.Map;
  
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.service.ServiceException;
  import org.apache.avalon.framework.service.ServiceManager;
  import org.apache.avalon.framework.service.Serviceable;
  import org.apache.excalibur.source.Source;
  import org.apache.excalibur.source.SourceResolver;
  import org.apache.lenya.cms.publication.PageEnvelope;
  import org.apache.lenya.cms.publication.Publication;
  
  /**
   * <p>
   * This module checks if a file exists in a publiation, and if not,
   * it chooses the core file. The attribute name must a path relatively
   * to the <code>webapps/lenya/lenya</code> directory.
   * </p>
   * <p>Example:
   * <code>{fallback:xslt/style.xsl}</code> looks if
   * <code>lenya/pubs/(publication-id)/lenya/xslt/style.xsl</code> exists,
   * and if not, it uses <code>lenya/xslt/style.xsl</code>.
   * 
   * </p>
   * @author <a href="mailto:andreas@apache.org">Andreas Hartmann</a>
   */
  public class FallbackModule extends AbstractPageEnvelopeModule implements Serviceable {
  
      private ServiceManager manager;
      public static final String PATH_PREFIX = "lenya/";
  
      /**
       * @see org.apache.cocoon.components.modules.input.InputModule#getAttribute(java.lang.String, org.apache.avalon.framework.configuration.Configuration, java.util.Map)
       */
      public Object getAttribute(String name, Configuration modeConf, Map objectModel)
          throws ConfigurationException {
          String resolvedPath;
  
          PageEnvelope envelope = getEnvelope(objectModel);
          String publicationId = envelope.getPublication().getId();
  
          String corePath = PATH_PREFIX + name;
          String publicationPath =
              Publication.PUBLICATION_PREFIX_URI + "/" + publicationId + "/" + corePath;
  
          SourceResolver resolver = null;
          Source source = null;
          try {
              resolver = (SourceResolver) manager.lookup(SourceResolver.ROLE);
              source = resolver.resolveURI("context://" + publicationPath);
              if (source.exists()) {
                  resolvedPath = publicationPath;
              } else {
                  resolvedPath = corePath;
              }
          } catch (Exception e) {
              throw new ConfigurationException("Resolving attribute [" + name + "] failed: ", e);
          } finally {
              if (resolver != null) {
                  if (source != null) {
                      resolver.release(source);
                  }
                  manager.release(resolver);
              }
          }
          resolvedPath = resolvedPath.substring("lenya/".length());
          return resolvedPath;
      }
  
      /**
       * @see org.apache.cocoon.components.modules.input.InputModule#getAttributeNames(org.apache.avalon.framework.configuration.Configuration, java.util.Map)
       */
      public Iterator getAttributeNames(Configuration modeConf, Map objectModel)
          throws ConfigurationException {
          return Collections.EMPTY_SET.iterator();
      }
  
      /**
       * @see org.apache.cocoon.components.modules.input.InputModule#getAttributeValues(java.lang.String, org.apache.avalon.framework.configuration.Configuration, java.util.Map)
       */
      public Object[] getAttributeValues(String name, Configuration modeConf, Map objectModel)
          throws ConfigurationException {
          Object[] objects = { getAttribute(name, modeConf, objectModel)};
  
          return objects;
      }
  
      /**
       * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
       */
      public void service(ServiceManager manager) throws ServiceException {
          this.manager = manager;
      }
  
  }
  
  
  
  1.1                  cocoon-lenya/src/java/org/apache/lenya/cms/cocoon/components/modules/input/AbstractPageEnvelopeModule.java
  
  Index: AbstractPageEnvelopeModule.java
  ===================================================================
  /*
  $Id: AbstractPageEnvelopeModule.java,v 1.1 2003/10/10 15:41:07 andreas Exp $
  <License>
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Lenya" and  "Apache Software Foundation"  must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Michael Wechner <mi...@apache.org>. For more information on the Apache Soft-
   ware Foundation, please see <http://www.apache.org/>.
  
   Lenya includes software developed by the Apache Software Foundation, W3C,
   DOM4J Project, BitfluxEditor, Xopus, and WebSHPINX.
  </License>
  */
  package org.apache.lenya.cms.cocoon.components.modules.input;
  
  import java.util.Map;
  
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.cocoon.components.modules.input.AbstractInputModule;
  import org.apache.cocoon.environment.ObjectModelHelper;
  import org.apache.cocoon.environment.Request;
  import org.apache.lenya.cms.publication.PageEnvelope;
  import org.apache.lenya.cms.publication.PageEnvelopeFactory;
  
  /**
   * Abstract superclass for classes which need access to the page envelope.
   * 
   * @author <a href="mailto:andreas@apache.org">Andreas Hartmann</a>
   */
  public abstract class AbstractPageEnvelopeModule extends AbstractInputModule {
  
      /**
       * Get the the page envelope for the given objectModel.
       * 
       * @param objectModel the objectModel for which the page enevelope is requested.
       * 
       * @return a <code>PageEnvelope</code>
       * 
       * @throws ConfigurationException if the page envelope could not be instantiated.
       */
      protected PageEnvelope getEnvelope(Map objectModel) throws ConfigurationException {
          
          PageEnvelope envelope = null;
  
          if (getLogger().isDebugEnabled()) {
              Request request = ObjectModelHelper.getRequest(objectModel);
              getLogger().debug("Resolving page envelope for URL [" + request.getRequestURI() + "]");
          }
  
          try {
              envelope = PageEnvelopeFactory.getInstance().getPageEnvelope(objectModel);
          } catch (Exception e) {
              throw new ConfigurationException("Resolving page envelope failed: ", e);
          }
  
          return envelope;
      }
  
  }
  
  
  

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