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/09/02 15:15:07 UTC

cvs commit: cocoon-lenya/src/webapp/WEB-INF cocoon-xconf.xsl

andreas     2003/09/02 06:15:07

  Modified:    src/webapp/WEB-INF cocoon-xconf.xsl
  Added:       src/java/org/apache/lenya/cms/cocoon/components/modules/input
                        WorkflowModule.java
  Log:
  added WorkflowModule
  
  Revision  Changes    Path
  1.1                  cocoon-lenya/src/java/org/apache/lenya/cms/cocoon/components/modules/input/WorkflowModule.java
  
  Index: WorkflowModule.java
  ===================================================================
  /*
  $Id: WorkflowModule.java,v 1.1 2003/09/02 13:15: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.Arrays;
  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.cocoon.components.modules.input.AbstractInputModule;
  import org.apache.lenya.cms.publication.Document;
  import org.apache.lenya.cms.publication.PageEnvelope;
  import org.apache.lenya.cms.publication.PageEnvelopeFactory;
  import org.apache.lenya.cms.workflow.WorkflowFactory;
  import org.apache.lenya.workflow.WorkflowInstance;
  
  /**
   * @author andreas
   *
   * To change the template for this generated type comment go to
   * Window - Preferences - Java - Code Generation - Code and Comments
   */
  public class WorkflowModule extends AbstractInputModule {
  
      public static final String STATE = "state";
      public static final String VARIABLE_PREFIX = "variable.";
  
      protected static final String[] PARAMETER_NAMES = { STATE };
  
      /**
       * @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 {
  
          Object value = null;
  
          try {
              PageEnvelope envelope = PageEnvelopeFactory.getInstance().getPageEnvelope(objectModel);
              Document document = envelope.getDocument();
  
              WorkflowFactory factory = WorkflowFactory.newInstance();
              if (factory.hasWorkflow(document)) {
                  WorkflowInstance instance = factory.buildInstance(document);
                  if (name.equals(STATE)) {
                      value = instance.getCurrentState().toString();
                  }
                  else if (name.startsWith(VARIABLE_PREFIX)) {
                      String variableName = name.substring(VARIABLE_PREFIX.length());
                      value = new Boolean(instance.getValue(variableName));
                  }
              }
          } catch (Exception e) {
              throw new ConfigurationException("Resolving attribute failed: ", e);
          }
          return value;
      }
  
      /**
       * @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 Arrays.asList(PARAMETER_NAMES).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;
      }
  
  }
  
  
  
  1.28      +3 -0      cocoon-lenya/src/webapp/WEB-INF/cocoon-xconf.xsl
  
  Index: cocoon-xconf.xsl
  ===================================================================
  RCS file: /home/cvs/cocoon-lenya/src/webapp/WEB-INF/cocoon-xconf.xsl,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- cocoon-xconf.xsl	15 Aug 2003 14:52:23 -0000	1.27
  +++ cocoon-xconf.xsl	2 Sep 2003 13:15:07 -0000	1.28
  @@ -69,6 +69,9 @@
       <component-instance logger="core.modules.input" name="access-control"
           class="org.apache.lenya.cms.cocoon.components.modules.input.AccessControlModule"/>
       
  +    <component-instance logger="core.modules.input" name="workflow"
  +        class="org.apache.lenya.cms.cocoon.components.modules.input.WorkflowModule"/>
  +    
     </xsl:copy>
   </xsl:template>
   
  
  
  

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