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/workflow/ui CommandFilter.java CommandFilterImpl.java
Date Fri, 30 May 2003 19:32:44 GMT
andreas     2003/05/30 12:32:44

  Modified:    src/java/org/apache/lenya/cms/cocoon/transformation
                        WorkflowMenuTransformer.java
  Added:       src/java/org/apache/lenya/workflow/impl EventImpl.java
                        WorkflowBuilder.java StateImpl.java
                        BooleanVariableImpl.java WorkflowInstanceImpl.java
                        BooleanVariableInstanceImpl.java
                        TransitionImpl.java ActionImpl.java
                        WorkflowImpl.java ConditionFactory.java
               src/java/org/apache/lenya/workflow
                        BooleanVariableInstance.java Condition.java
                        Action.java WorkflowBuildException.java
                        BooleanVariable.java State.java
                        WorkflowInstance.java Transition.java Event.java
                        Situation.java WorkflowException.java Workflow.java
                        WorkflowFactory.java
               src/java/org/apache/lenya/cms/workflow
                        WorkflowFactoryImpl.java CommandFilter.java
                        RoleCondition.java CommandFilterImpl.java
                        CMSSituation.java WorkflowDocument.java
  Removed:     src/java/org/apache/lenya/cms/workflow/impl StateImpl.java
                        BooleanVariableImpl.java CMSSituation.java
                        WorkflowInstanceImpl.java ConditionFactory.java
                        TransitionImpl.java RoleCondition.java
                        WorkflowFactoryImpl.java
                        BooleanVariableInstanceImpl.java EventImpl.java
                        WorkflowBuilder.java WorkflowImpl.java
                        ActionImpl.java WorkflowDocument.java
               src/java/org/apache/lenya/cms/workflow Condition.java
                        WorkflowException.java AbstractWorkflowable.java
                        Situation.java Transition.java Event.java
                        WorkflowBuildException.java Workflowable.java
                        BooleanVariableInstance.java Workflow.java
                        WorkflowInstance.java WorkflowFactory.java
                        BooleanVariable.java State.java Action.java
               src/java/org/apache/lenya/cms/workflow/ui CommandFilter.java
                        CommandFilterImpl.java
  Log:
  refactored workflow package structure (better Soc)
  
  Revision  Changes    Path
  1.1                  cocoon-lenya/src/java/org/apache/lenya/workflow/impl/EventImpl.java
  
  Index: EventImpl.java
  ===================================================================
  /*
   * EventImpl.java
   *
   * Created on 8. April 2003, 19:44
   */
  
  package org.apache.lenya.workflow.impl;
  
  import org.apache.lenya.workflow.Event;
  
  /**
   *
   * @author  andreas
   */
  public class EventImpl implements Event {
  
      /** Creates a new instance of EventImpl */
      protected EventImpl(String id) {
          assert id != null;
          this.id = id;
      }
  
      private String id;
  
      protected String getId() {
          return id;
      }
  
      public String toString() {
          return getId();
      }
  
      public boolean equals(Object otherObject) {
          boolean equals = false;
  
          if (otherObject instanceof EventImpl) {
              EventImpl otherEvent = (EventImpl) otherObject;
              equals = getId().equals(otherEvent.getId());
          } else {
              equals = super.equals(otherObject);
          }
  
          return equals;
      }
  
      public int hashCode() {
          return getId().hashCode();
      }
  
      /* (non-Javadoc)
       * @see org.apache.lenya.cms.workflow.Event#getCommand()
       */
      public String getCommand() {
          return getId();
      }
  
  }
  
  
  
  1.1                  cocoon-lenya/src/java/org/apache/lenya/workflow/impl/WorkflowBuilder.java
  
  Index: WorkflowBuilder.java
  ===================================================================
  /*
   * WorkflowBuilder.java
   *
   * Created on 8. April 2003, 18:09
   */
  
  package org.apache.lenya.workflow.impl;
  
  import java.io.File;
  import java.io.IOException;
  import java.util.HashMap;
  import java.util.Map;
  import javax.xml.parsers.ParserConfigurationException;
  
  import org.apache.lenya.workflow.Action;
  import org.apache.lenya.workflow.Condition;
  import org.apache.lenya.workflow.Event;
  import org.apache.lenya.workflow.State;
  import org.apache.lenya.workflow.Workflow;
  import org.apache.lenya.workflow.WorkflowBuildException;
  import org.apache.lenya.xml.DocumentHelper;
  import org.apache.lenya.xml.NamespaceHelper;
  import org.w3c.dom.Document;
  import org.w3c.dom.Element;
  import org.w3c.dom.NodeList;
  import org.xml.sax.SAXException;
  
  /**
   *
   * @author  andreas
   */
  public class WorkflowBuilder {
  
      public static final String NAMESPACE = "http://apache.org/cocoon/lenya/workflow/1.0";
      public static final String DEFAULT_PREFIX = "wf";
  
      public static Workflow buildWorkflow(File file) throws WorkflowBuildException {
          Workflow workflow;
  
          try {
              Document document = DocumentHelper.readDocument(file);
              workflow = buildWorkflow(document);
          } catch (Exception e) {
              throw new WorkflowBuildException(e);
          }
  
          return workflow;
      }
  
      public static Workflow buildWorkflow(Document document)
          throws
              ParserConfigurationException,
              SAXException,
              IOException,
              WorkflowBuildException {
  
          NamespaceHelper helper =
              new NamespaceHelper(NAMESPACE, DEFAULT_PREFIX, document);
  
          Element root = document.getDocumentElement();
          State initialState = null;
  
          Map states = new HashMap();
          Map events = new HashMap();
  
          // load states
          NodeList stateElements =
              root.getElementsByTagNameNS(NAMESPACE, STATE_ELEMENT);
          for (int i = 0; i < stateElements.getLength(); i++) {
              Element element = (Element) stateElements.item(i);
              StateImpl state = buildState(element);
              String id = state.getId();
              states.put(id, state);
              if (isInitialStateElement(element)) {
                  initialState = state;
              }
          }
  
          assert initialState != null;
          WorkflowImpl workflow = new WorkflowImpl(initialState);
  
          // load events
          NodeList eventElements =
              root.getElementsByTagNameNS(NAMESPACE, EVENT_ELEMENT);
          for (int i = 0; i < eventElements.getLength(); i++) {
              EventImpl event = buildEvent((Element) eventElements.item(i));
              String id = event.getId();
              events.put(id, event);
          }
  
          // load transitions
          NodeList transitionElements =
              root.getElementsByTagNameNS(NAMESPACE, TRANSITION_ELEMENT);
          for (int i = 0; i < transitionElements.getLength(); i++) {
              TransitionImpl transition =
                  buildTransition(
                      (Element) transitionElements.item(i),
                      states,
                      events);
              workflow.addTransition(transition);
          }
  
          return workflow;
      }
  
      protected static boolean isInitialStateElement(Element element) {
          assert element.getLocalName().equals(STATE_ELEMENT);
          String initialAttribute = element.getAttribute(INITIAL_ATTRIBUTE);
          return initialAttribute != null
              && (initialAttribute.equals("yes") || initialAttribute.equals("true"));
      }
  
  	protected static final String STATE_ELEMENT = "state";
  	protected static final String TRANSITION_ELEMENT = "transition";
  	protected static final String EVENT_ELEMENT = "event";
  	protected static final String CONDITION_ELEMENT = "condition";
  	protected static final String ACTION_ELEMENT = "action";
  	protected static final String ID_ATTRIBUTE = "id";
  	protected static final String INITIAL_ATTRIBUTE = "initial";
  	protected static final String SOURCE_ATTRIBUTE = "source";
  	protected static final String DESTINATION_ATTRIBUTE = "destination";
  	protected static final String CLASS_ATTRIBUTE = "class";
  
      protected static StateImpl buildState(Element element) {
          assert element.getLocalName().equals(STATE_ELEMENT);
  
          String id = element.getAttribute(ID_ATTRIBUTE);
          StateImpl state = new StateImpl(id);
          return state;
      }
  
      protected static TransitionImpl buildTransition(
          Element element,
          Map states,
          Map events)
          throws WorkflowBuildException {
          assert element.getLocalName().equals(TRANSITION_ELEMENT);
  
          String sourceId = element.getAttribute(SOURCE_ATTRIBUTE);
          String destinationId = element.getAttribute(DESTINATION_ATTRIBUTE);
  
          assert sourceId != null;
          assert destinationId != null;
  
          State source = (State) states.get(sourceId);
          State destination = (State) states.get(destinationId);
  
          assert source != null;
          assert destination != null;
  
          TransitionImpl transition = new TransitionImpl(source, destination);
  
          // set event
          Element eventElement =
              (Element) element.getElementsByTagNameNS(
                  NAMESPACE,
                  EVENT_ELEMENT).item(
                  0);
          String id = eventElement.getAttribute(ID_ATTRIBUTE);
          assert id != null;
  
          Event event = (Event) events.get(id);
          assert event != null;
  
          transition.setEvent(event);
  
          // load conditions
          NodeList conditionElements =
              element.getElementsByTagNameNS(NAMESPACE, CONDITION_ELEMENT);
          for (int i = 0; i < conditionElements.getLength(); i++) {
              Condition condition =
                  buildCondition((Element) conditionElements.item(i));
              transition.addCondition(condition);
          }
  
          // load actions
          NodeList actionElements =
              element.getElementsByTagNameNS(NAMESPACE, ACTION_ELEMENT);
          for (int i = 0; i < actionElements.getLength(); i++) {
              Action action = buildAction((Element) actionElements.item(i));
              transition.addAction(action);
          }
  
          return transition;
      }
  
      protected static EventImpl buildEvent(Element element) {
          String id = element.getAttribute(ID_ATTRIBUTE);
          assert id != null;
          EventImpl event = new EventImpl(id);
          return event;
      }
  
      protected static Condition buildCondition(Element element)
          throws WorkflowBuildException {
          String className = element.getAttribute(CLASS_ATTRIBUTE);
          String expression = DocumentHelper.getSimpleElementText(element);
          Condition condition =
              ConditionFactory.createCondition(className, expression);
          return condition;
      }
  
      protected static Action buildAction(Element element) {
          String id = element.getAttribute(ID_ATTRIBUTE);
          Action action = new ActionImpl(id);
          return action;
      }
  
  }
  
  
  
  1.1                  cocoon-lenya/src/java/org/apache/lenya/workflow/impl/StateImpl.java
  
  Index: StateImpl.java
  ===================================================================
  /*
   * StateImpl.java
   *
   * Created on 8. April 2003, 18:35
   */
  
  package org.apache.lenya.workflow.impl;
  
  import org.apache.lenya.workflow.State;
  
  /**
   *
   * @author  andreas
   */
  public class StateImpl implements State {
  
      /** Creates a new instance of StateImpl */
      protected StateImpl(String id) {
          assert id != null;
          this.id = id;
      }
  
      private String id;
  
      /**
       * @return
       */
      public String getId() {
          return id;
      }
  
      /* (non-Javadoc)
       * @see java.lang.Object#toString()
       */
      public String toString() {
          return getId();
      }
  
      /* (non-Javadoc)
       * @see java.lang.Object#equals(java.lang.Object)
       */
      public boolean equals(Object object) {
          boolean result = false;
          if (object instanceof StateImpl) {
              result = getId().equals(((StateImpl) object).getId());
          } else {
              result = super.equals(object);
          }
          return result;
      }
  
      /* (non-Javadoc)
       * @see java.lang.Object#hashCode()
       */
      public int hashCode() {
          return getId().hashCode();
      }
  
  }
  
  
  
  1.1                  cocoon-lenya/src/java/org/apache/lenya/workflow/impl/BooleanVariableImpl.java
  
  Index: BooleanVariableImpl.java
  ===================================================================
  /*
   * BooleanVariableImpl.java
   *
   * Created on 27. Mai 2003, 12:37
   */
  
  package org.apache.lenya.workflow.impl;
  
  import org.apache.lenya.workflow.BooleanVariable;
  
  /**
   *
   * @author  andreas
   */
  public class BooleanVariableImpl implements BooleanVariable {
  
      /** Creates a new instance of BooleanVariableImpl */
      protected BooleanVariableImpl(String name) {
      	assert name != null;
      	this.name = name;
      }
  
      private String name;
  
      /**
       * @see org.apache.lenya.cms.workflow.BooleanVariable#getName()
       */
      public String getName() {
          return name;
      }
  
  }
  
  
  
  1.1                  cocoon-lenya/src/java/org/apache/lenya/workflow/impl/WorkflowInstanceImpl.java
  
  Index: WorkflowInstanceImpl.java
  ===================================================================
  /*
   * WorkflowInstanceImpl.java
   *
   * Created on 9. April 2003, 13:30
   */
  
  package org.apache.lenya.workflow.impl;
  
  import java.util.HashSet;
  import java.util.Set;
  import org.apache.lenya.workflow.Event;
  import org.apache.lenya.workflow.Situation;
  import org.apache.lenya.workflow.State;
  import org.apache.lenya.workflow.Transition;
  import org.apache.lenya.workflow.Workflow;
  import org.apache.lenya.workflow.WorkflowInstance;
  
  /**
   *
   * @author  andreas
   */
  public class WorkflowInstanceImpl implements WorkflowInstance {
  
  	/**
  	 * Creates a new instance of WorkflowInstanceImpl.
  	 */
  	public WorkflowInstanceImpl() {
  	}
  
      /**
       * Creates a new instance of WorkflowInstanceImpl.
       */
      protected WorkflowInstanceImpl(Workflow workflow) {
          setWorkflow(workflow);
      }
  
      private Workflow workflow;
  
      /**
       * @return
       */
      public Workflow getWorkflow() {
          return workflow;
      }
  
      /** Returns the transitions that can fire for this user.
       *
       */
      public Transition[] getExecutableTransitions(Situation situation) {
          Transition transitions[] =
              getWorkflow().getLeavingTransitions(getCurrentState());
          Set executableTransitions = new HashSet();
  
          for (int i = 0; i < transitions.length; i++) {
              if (transitions[i].canFire(situation)) {
                  executableTransitions.add(transitions[i]);
              }
          }
          return (Transition[]) executableTransitions.toArray(
              new Transition[executableTransitions.size()]);
      }
  
      /** Indicates that the user invoked an event.
       * @param user The user who invoked the event.
       * @param event The event that was invoked.
       *
       */
      public void invoke(Situation situation, Event event) {
          Transition transitions[] = getExecutableTransitions(situation);
          for (int i = 0; i < transitions.length; i++) {
              if (transitions[i].getEvent().equals(event)) {
                  fire((TransitionImpl) transitions[i]);
              }
          }
      }
  
      protected void fire(TransitionImpl transition) {
          setCurrentState(transition.getDestination());
      }
  
      private State currentState;
  
      protected void setCurrentState(State state) {
          assert state != null
              && ((WorkflowImpl) getWorkflow()).containsState(state);
          this.currentState = state;
      }
  
      /** Returns the current state of this WorkflowInstance.
       *
       */
      public State getCurrentState() {
          return currentState;
      }
  
  	/**
  	 * @param workflow
  	 */
  	protected void setWorkflow(Workflow workflow) {
  		assert workflow != null;
  		this.workflow = workflow;
  		setCurrentState(getWorkflow().getInitialState());
  	}
  	
  	/**
  	 * Returns a workflow state for a given name.
  	 */
  	protected State getState(String id) {
  		return ((WorkflowImpl) getWorkflow()).getState(id);
  	}
  
  }
  
  
  
  1.1                  cocoon-lenya/src/java/org/apache/lenya/workflow/impl/BooleanVariableInstanceImpl.java
  
  Index: BooleanVariableInstanceImpl.java
  ===================================================================
  /*
   * BooleanVariableInstanceImpl.java
   *
   * Created on 27. Mai 2003, 12:37
   */
  
  package org.apache.lenya.workflow.impl;
  
  import org.apache.lenya.workflow.BooleanVariableInstance;
  
  /**
   *
   * @author  andreas
   */
  public class BooleanVariableInstanceImpl implements BooleanVariableInstance {
  
      private boolean value;
  
      /** Creates a new instance of BooleanVariableInstanceImpl */
      protected BooleanVariableInstanceImpl() {
      }
  
      /**
       * @see org.apache.lenya.cms.workflow.BooleanVariableInstance#getValue()
       */
      public boolean getValue() {
          return value;
      }
  
      /**
       * @see org.apache.lenya.cms.workflow.BooleanVariableInstance#setValue(boolean)
       */
      public void setValue(boolean value) {
          this.value = value;
      }
  
  }
  
  
  
  1.1                  cocoon-lenya/src/java/org/apache/lenya/workflow/impl/TransitionImpl.java
  
  Index: TransitionImpl.java
  ===================================================================
  /*
   * TransitionImpl.java
   *
   * Created on 8. April 2003, 17:49
   */
  
  package org.apache.lenya.workflow.impl;
  
  import java.util.ArrayList;
  import java.util.List;
  import org.apache.lenya.workflow.Action;
  import org.apache.lenya.workflow.Condition;
  import org.apache.lenya.workflow.Event;
  import org.apache.lenya.workflow.Situation;
  import org.apache.lenya.workflow.State;
  import org.apache.lenya.workflow.Transition;
  
  /**
   *
   * @author  andreas
   */
  public class TransitionImpl implements Transition {
  
      /** Creates a new instance of TransitionImpl */
      protected TransitionImpl(State source, State destination) {
  
          assert source != null;
          assert destination != null;
  
          this.source = source;
          this.destination = destination;
      }
  
      private List actions = new ArrayList();
  
      public Action[] getActions() {
          return (Action[]) actions.toArray(new Action[actions.size()]);
      }
  
      public void addAction(Action action) {
          assert action != null;
          actions.add(action);
      }
  
      private List conditions = new ArrayList();
  
      public Condition[] getConditions() {
          return (Condition[]) conditions.toArray(
              new Condition[conditions.size()]);
      }
  
      public void addCondition(Condition condition) {
          assert condition != null;
          conditions.add(condition);
      }
  
      private Event event;
  
      public Event getEvent() {
          return event;
      }
  
      public void setEvent(Event event) {
          this.event = event;
          assert event != null;
      }
  
      private State source;
  
      public State getSource() {
          return source;
      }
  
      private State destination;
  
      public State getDestination() {
          return destination;
      }
  
      /** Returns if the transition can fire in a certain situation.
       *
       */
      public boolean canFire(Situation situation) {
          Condition conditions[] = getConditions();
          boolean canFire = true;
          for (int i = 0; i < conditions.length; i++) {
              if (!conditions[i].isComplied(situation)) {
                  canFire = false;
              }
          }
          return canFire;
      }
  
      /* (non-Javadoc)
       * @see java.lang.Object#toString()
       */
      public String toString() {
          
          String string = getEvent().getCommand() + " [";
          Condition conditions[] = getConditions();
          for (int i = 0; i < conditions.length; i++) {
              if (i > 0) string += ", ";
              string += conditions[i].toString();
          }
          
          string += "]";
          
          Action actions[] = getActions();
          if (actions.length > 0) {
              string += " / ";
              for (int i = 0; i < actions.length; i++) {
                  if (i > 0) string += ", ";
                  string += actions[i].toString();
              }
          }
          
          return string;
      }
  
  }
  
  
  
  1.1                  cocoon-lenya/src/java/org/apache/lenya/workflow/impl/ActionImpl.java
  
  Index: ActionImpl.java
  ===================================================================
  /*
   * ActionImpl.java
   *
   * Created on 9. April 2003, 10:04
   */
  
  package org.apache.lenya.workflow.impl;
  
  import org.apache.lenya.workflow.Action;
  
  /**
   *
   * @author  andreas
   */
  public class ActionImpl
      implements Action {
      
      /** Creates a new instance of ActionImpl */
      protected ActionImpl(String id) {
          assert id != null;
          this.id = id;
      }
      
      private String id;
      
      public String getId() {
          return id;
      }
      
      /* (non-Javadoc)
       * @see java.lang.Object#toString()
       */
      public String toString() {
          return getId();
      }
  
  }
  
  
  
  1.1                  cocoon-lenya/src/java/org/apache/lenya/workflow/impl/WorkflowImpl.java
  
  Index: WorkflowImpl.java
  ===================================================================
  /*
   * WorkflowImpl.java
   *
   * Created on 8. April 2003, 17:04
   */
  
  package org.apache.lenya.workflow.impl;
  
  import java.util.HashMap;
  import java.util.HashSet;
  import java.util.Map;
  import java.util.Set;
  import org.apache.lenya.workflow.State;
  import org.apache.lenya.workflow.Transition;
  import org.apache.lenya.workflow.Workflow;
  
  /**
   *
   * @author  andreas
   */
  public class WorkflowImpl implements Workflow {
  
      /** Creates a new instance of WorkflowImpl */
      protected WorkflowImpl(State initialState) {
          this.initialState = initialState;
          addState(initialState);
      }
  
      private State initialState;
  
      /** Returns the initial state of this workflow.
       * @return The initial state.
       *
       */
      public State getInitialState() {
          return initialState;
      }
  
      private Set transitions = new HashSet();
      private Map states = new HashMap();
      
      private void addState(State state) {
          states.put(((StateImpl) state).getId(), state);
      }
  
      /**
       * Adds a transition.
       */
      protected void addTransition(TransitionImpl transition) {
          assert transition != null;
          transitions.add(transition);
          addState(transition.getSource());
          addState(transition.getDestination());
      }
  
      protected TransitionImpl[] getTransitions() {
          return (TransitionImpl[]) transitions.toArray(
              new TransitionImpl[transitions.size()]);
      }
  
      /** Returns the destination state of a transition.
       * @param transition A transition.
       * @return The destination state.
       *
       */
      protected State getDestination(Transition transition) {
          assert transition instanceof TransitionImpl;
          return ((TransitionImpl) transition).getDestination();
      }
  
      /** Returns the transitions that leave a state.
       * @param state A state.
       * @return The transitions that leave the state.
       *
       */
      public Transition[] getLeavingTransitions(State state) {
          Set leavingTransitions = new HashSet();
          TransitionImpl[] transitions = getTransitions();
          for (int i = 0; i < transitions.length; i++) {
              if (transitions[i].getSource() == state) {
                  leavingTransitions.add(transitions[i]);
              }
          }
          return (Transition[]) leavingTransitions.toArray(
              new Transition[leavingTransitions.size()]);
      }
  
      /**
       * Checks if this workflow contains a state.
       * @param state The state to check.
       * @return <code>true</code> if the state is contained, <code>false</code> otherwise.
       */
      protected boolean containsState(State state) {
          return states.containsValue(state);
      }
      
      protected State[] getStates() {
          return (State[]) states.values().toArray(new State[states.size()]);
      }
      
      protected State getState(String name) {
          return (State) states.get(name); 
      }
      
  }
  
  
  
  1.1                  cocoon-lenya/src/java/org/apache/lenya/workflow/impl/ConditionFactory.java
  
  Index: ConditionFactory.java
  ===================================================================
  /*
   * ConditionFactory.java
   *
   * Created on 8. April 2003, 19:57
   */
  
  package org.apache.lenya.workflow.impl;
  
  import org.apache.lenya.workflow.Condition;
  import org.apache.lenya.workflow.WorkflowBuildException;
  
  /**
   *
   * @author  andreas
   */
  public class ConditionFactory {
  
      protected static Condition createCondition(
          String className,
          String expression)
          throws WorkflowBuildException {
  
          assert className != null;
          assert expression != null;
  
          Condition condition;
          try {
              Class clazz = Class.forName(className);
              condition = (Condition) clazz.newInstance();
              condition.setExpression(expression);
          } catch (ClassNotFoundException e) {
              throw new WorkflowBuildException(e);
          } catch (InstantiationException e) {
              throw new WorkflowBuildException(e);
          } catch (IllegalAccessException e) {
              throw new WorkflowBuildException(e);
          }
          return condition;
      }
  
  }
  
  
  
  1.3       +9 -9      cocoon-lenya/src/java/org/apache/lenya/cms/cocoon/transformation/WorkflowMenuTransformer.java
  
  Index: WorkflowMenuTransformer.java
  ===================================================================
  RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/cocoon/transformation/WorkflowMenuTransformer.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- WorkflowMenuTransformer.java	30 May 2003 15:26:18 -0000	1.2
  +++ WorkflowMenuTransformer.java	30 May 2003 19:32:43 -0000	1.3
  @@ -61,12 +61,12 @@
   import org.apache.lenya.cms.publication.PageEnvelope;
   import org.apache.lenya.cms.publication.Publication;
   import org.apache.lenya.cms.publication.PublicationFactory;
  -import org.apache.lenya.cms.workflow.Situation;
  -import org.apache.lenya.cms.workflow.WorkflowFactory;
  -import org.apache.lenya.cms.workflow.Workflowable;
  -import org.apache.lenya.cms.workflow.impl.WorkflowFactoryImpl;
  -import org.apache.lenya.cms.workflow.ui.CommandFilter;
  -import org.apache.lenya.cms.workflow.ui.CommandFilterImpl;
  +import org.apache.lenya.workflow.Situation;
  +import org.apache.lenya.workflow.WorkflowFactory;
  +import org.apache.lenya.workflow.WorkflowInstance;
  +import org.apache.lenya.cms.workflow.CommandFilter;
  +import org.apache.lenya.cms.workflow.CommandFilterImpl;
  +import org.apache.lenya.cms.workflow.WorkflowFactoryImpl;
   import org.xml.sax.Attributes;
   import org.xml.sax.SAXException;
   import org.xml.sax.helpers.AttributesImpl;
  @@ -134,11 +134,11 @@
           Document document = new DefaultDocument(publication, envelope.getDocumentId());
           
           WorkflowFactory factory = WorkflowFactoryImpl.newInstance(document, user);
  -        Workflowable workflowable = null;
  +        WorkflowInstance instance = null;
           Situation situation = null;
         
           try {
  -            workflowable = factory.buildWorkflowable();
  +            instance = factory.buildInstance();
               situation = factory.buildSituation();
           }
           catch (Exception e) {
  @@ -146,7 +146,7 @@
           }
         
           CommandFilter filter = new CommandFilterImpl();
  -        this.commands = filter.getExecutableCommands(workflowable.getInstance(), situation);
  +        this.commands = filter.getExecutableCommands(instance, situation);
         
       }
       
  
  
  
  1.1                  cocoon-lenya/src/java/org/apache/lenya/workflow/BooleanVariableInstance.java
  
  Index: BooleanVariableInstance.java
  ===================================================================
  /*
   * BooleanVariableInstance.java
   *
   * Created on 27. Mai 2003, 12:36
   */
  
  package org.apache.lenya.workflow;
  
  /**
   *
   * @author  andreas
   */
  public interface BooleanVariableInstance {
  
      /**
       * Sets the value of this variable.
       * @param value A boolean value.
       */
      void setValue(boolean value);
  
      /**
       * Returns the value of this variable.
       * @return A boolean value.
       */
      boolean getValue();
  }
  
  
  
  1.1                  cocoon-lenya/src/java/org/apache/lenya/workflow/Condition.java
  
  Index: Condition.java
  ===================================================================
  /*
   * Condition.java
   *
   * Created on 8. April 2003, 17:07
   */
  
  package org.apache.lenya.workflow;
  
  /**
   *
   * @author  andreas
   */
  public interface Condition {
  
      /**
       * Returns if the condition is complied in a certain situation.
       * @param situation The situation to check.
       * @return if the condition is complied.
       */
      boolean isComplied(Situation situation);
  
  	/** Sets the expression for this condition.
  	 * @param expression The expression.
  	 *
  	 */
  	void setExpression(String expression);
  
  }
  
  
  
  1.1                  cocoon-lenya/src/java/org/apache/lenya/workflow/Action.java
  
  Index: Action.java
  ===================================================================
  /*
   * Action.java
   *
   * Created on 8. April 2003, 17:11
   */
  
  package org.apache.lenya.workflow;
  
  /**
   *
   * @author  andreas
   */
  public interface Action {
  
  }
  
  
  
  1.1                  cocoon-lenya/src/java/org/apache/lenya/workflow/WorkflowBuildException.java
  
  Index: WorkflowBuildException.java
  ===================================================================
  /*
   * WorkflowBuildException.java
   *
   * Created on 8. April 2003, 20:01
   */
  
  package org.apache.lenya.workflow;
  
  /**
   *
   * @author  andreas
   */
  public class WorkflowBuildException
      extends Exception {
          
      /** Creates a new instance of WorkflowBuildException */
      public WorkflowBuildException() {
          super(MESSAGE);
      }
      
      /** Creates a new instance of WorkflowBuildException */
      public WorkflowBuildException(String message) {
          super(message);
      }
      
      public WorkflowBuildException(Throwable cause) {
          super(MESSAGE, cause);
      }
      
      public WorkflowBuildException(String message, Throwable cause) {
          super(message, cause);
      }
      
      protected static final String MESSAGE = "Workflow building failed: ";
      
      
  }
  
  
  
  1.1                  cocoon-lenya/src/java/org/apache/lenya/workflow/BooleanVariable.java
  
  Index: BooleanVariable.java
  ===================================================================
  /*
   * BooleanVariable.java
   *
   * Created on 27. Mai 2003, 12:35
   */
  
  package org.apache.lenya.workflow;
  
  /**
   *
   * @author  andreas
   */
  public interface BooleanVariable {
  
      /**
       * Returns the name of this variable.
       */
      String getName();
  }
  
  
  
  1.1                  cocoon-lenya/src/java/org/apache/lenya/workflow/State.java
  
  Index: State.java
  ===================================================================
  /*
   * State.java
   *
   * Created on 8. April 2003, 17:05
   */
  
  package org.apache.lenya.workflow;
  
  /**
   *
   * @author  andreas
   */
  public interface State {
  
  }
  
  
  
  1.1                  cocoon-lenya/src/java/org/apache/lenya/workflow/WorkflowInstance.java
  
  Index: WorkflowInstance.java
  ===================================================================
  /*
   * WorkflowInstance.java
   *
   * Created on 8. April 2003, 17:14
   */
  
  package org.apache.lenya.workflow;
  
  /**
   *
   * @author  andreas
   */
  public interface WorkflowInstance {
  
      /**
       * Returns the workflow this instance belongs to. 
       * @return A Workflow object.
       */
      Workflow getWorkflow();
  
      /**
       * Returns the current state of this WorkflowInstance.
       */
      State getCurrentState();
  
      /**
       * Returns the transitions that can fire for this user.
       */
      Transition[] getExecutableTransitions(Situation situation);
  
      /**
       * Indicates that the user invoked an event.
       * @param user The user who invoked the event.
       * @param event The event that was invoked.
       */
      void invoke(Situation situation, Event event) throws WorkflowException;
  
  }
  
  
  
  1.1                  cocoon-lenya/src/java/org/apache/lenya/workflow/Transition.java
  
  Index: Transition.java
  ===================================================================
  /*
   * Transition.java
   *
   * Created on 8. April 2003, 17:05
   */
  
  package org.apache.lenya.workflow;
  
  /**
   *
   * @author  andreas
   */
  public interface Transition {
  
      /**
       * Returns the event of this transition.
       */
      Event getEvent();
  
      /**
       * Returns the actions of this transition.
       */
      Action[] getActions();
  
      /**
       * Returns if the transition can fire in a certain situation.
       */
      boolean canFire(Situation situation);
  
  }
  
  
  
  1.1                  cocoon-lenya/src/java/org/apache/lenya/workflow/Event.java
  
  Index: Event.java
  ===================================================================
  /*
   * Event.java
   *
   * Created on 8. April 2003, 17:11
   */
  
  package org.apache.lenya.workflow;
  
  /**
   *
   * @author  andreas
   */
  public interface Event {
  
      String getCommand();
  
  }
  
  
  
  1.1                  cocoon-lenya/src/java/org/apache/lenya/workflow/Situation.java
  
  Index: Situation.java
  ===================================================================
  /*
   * Situation.java
   *
   * Created on 8. April 2003, 17:48
   */
  
  package org.apache.lenya.workflow;
  
  /**
   * A situation contains all information that is needed to decide which
   * workflow transitions can fire at a certain moment.
   * @author  andreas
   */
  public interface Situation {
  
  }
  
  
  
  1.1                  cocoon-lenya/src/java/org/apache/lenya/workflow/WorkflowException.java
  
  Index: WorkflowException.java
  ===================================================================
  /*
   * $Id
   * <License>
   * The Apache Software License
   *
   * Copyright (c) 2002 lenya. All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without modification,
   * 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. All advertising materials mentioning features or use of this software must
   *    display the following acknowledgment: "This product includes software developed
   *    by lenya (http://www.lenya.org)"
   *
   * 4. The name "lenya" must not be used to endorse or promote products derived from
   *    this software without prior written permission. For written permission, please
   *    contact contact@lenya.org
   *
   * 5. Products derived from this software may not be called "lenya" nor may "lenya"
   *    appear in their names without prior written permission of lenya.
   *
   * 6. Redistributions of any form whatsoever must retain the following acknowledgment:
   *    "This product includes software developed by lenya (http://www.lenya.org)"
   *
   * THIS SOFTWARE IS PROVIDED BY lenya "AS IS" WITHOUT ANY WARRANTY EXPRESS OR IMPLIED,
   * INCLUDING THE WARRANTY OF NON-INFRINGEMENT AND THE IMPLIED WARRANTIES OF MERCHANTI-
   * BILITY AND FITNESS FOR A PARTICULAR PURPOSE. lenya WILL NOT BE LIABLE FOR ANY DAMAGES
   * SUFFERED BY YOU AS A RESULT OF USING THIS SOFTWARE. IN NO EVENT WILL lenya BE LIABLE
   * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR LOST PROFITS EVEN IF lenya HAS
   * BEEN ADVISED OF THE POSSIBILITY OF THEIR OCCURRENCE. lenya WILL NOT BE LIABLE FOR ANY
   * THIRD PARTY CLAIMS AGAINST YOU.
   *
   * Lenya includes software developed by the Apache Software Foundation, W3C,
   * DOM4J Project, BitfluxEditor and Xopus.
   * </License>
   */
  package org.apache.lenya.workflow;
  
  /**
   * @author andreas
   *
   * To change the template for this generated type comment go to
   * Window>Preferences>Java>Code Generation>Code and Comments
   */
  public class WorkflowException extends Exception {
  
      /**
       * 
       */
      public WorkflowException() {
          super();
      }
  
      /**
       * @param arg0
       */
      public WorkflowException(String arg0) {
          super(arg0);
      }
  
      /**
       * @param arg0
       * @param arg1
       */
      public WorkflowException(String arg0, Throwable arg1) {
          super(arg0, arg1);
      }
  
      /**
       * @param arg0
       */
      public WorkflowException(Throwable arg0) {
          super(arg0);
      }
  
  }
  
  
  
  1.1                  cocoon-lenya/src/java/org/apache/lenya/workflow/Workflow.java
  
  Index: Workflow.java
  ===================================================================
  /*
   * Workflow.java
   *
   * Created on 8. April 2003, 17:03
   */
  
  package org.apache.lenya.workflow;
  
  /**
   *
   * @author  andreas
   */
  public interface Workflow {
      
      /**
       * Returns the initial state of this workflow.
       * @return The initial state
       */
      State getInitialState();
      
      /**
       * Returns the transitions that leave a state.
       * This method is used, e.g., to disable menu items.
       * @param state A state.
       * @return The transitions that leave the state.
       */
      Transition[] getLeavingTransitions(State state);
      
  }
  
  
  
  1.1                  cocoon-lenya/src/java/org/apache/lenya/workflow/WorkflowFactory.java
  
  Index: WorkflowFactory.java
  ===================================================================
  /*
   * $Id
   * <License>
   * The Apache Software License
   *
   * Copyright (c) 2002 lenya. All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without modification,
   * 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. All advertising materials mentioning features or use of this software must
   *    display the following acknowledgment: "This product includes software developed
   *    by lenya (http://www.lenya.org)"
   *
   * 4. The name "lenya" must not be used to endorse or promote products derived from
   *    this software without prior written permission. For written permission, please
   *    contact contact@lenya.org
   *
   * 5. Products derived from this software may not be called "lenya" nor may "lenya"
   *    appear in their names without prior written permission of lenya.
   *
   * 6. Redistributions of any form whatsoever must retain the following acknowledgment:
   *    "This product includes software developed by lenya (http://www.lenya.org)"
   *
   * THIS SOFTWARE IS PROVIDED BY lenya "AS IS" WITHOUT ANY WARRANTY EXPRESS OR IMPLIED,
   * INCLUDING THE WARRANTY OF NON-INFRINGEMENT AND THE IMPLIED WARRANTIES OF MERCHANTI-
   * BILITY AND FITNESS FOR A PARTICULAR PURPOSE. lenya WILL NOT BE LIABLE FOR ANY DAMAGES
   * SUFFERED BY YOU AS A RESULT OF USING THIS SOFTWARE. IN NO EVENT WILL lenya BE LIABLE
   * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR LOST PROFITS EVEN IF lenya HAS
   * BEEN ADVISED OF THE POSSIBILITY OF THEIR OCCURRENCE. lenya WILL NOT BE LIABLE FOR ANY
   * THIRD PARTY CLAIMS AGAINST YOU.
   *
   * Lenya includes software developed by the Apache Software Foundation, W3C,
   * DOM4J Project, BitfluxEditor and Xopus.
   * </License>
   */
  package org.apache.lenya.workflow;
  
  /**
   * @author andreas
   *
   * Abstract factory for workflow-related objects.
   *
   */
  public abstract class WorkflowFactory {
  
      /**
       * @return
       * @throws WorkflowBuildException
       */
      public abstract WorkflowInstance buildInstance() throws WorkflowBuildException;
  
      /**
      * @return
      * @throws WorkflowBuildException
      */
      public abstract Situation buildSituation() throws WorkflowBuildException;
  
  }
  
  
  
  1.1                  cocoon-lenya/src/java/org/apache/lenya/cms/workflow/WorkflowFactoryImpl.java
  
  Index: WorkflowFactoryImpl.java
  ===================================================================
  /*
   * WorkflowFactory.java
   *
   * Created on 8. April 2003, 18:08
   */
  
  package org.apache.lenya.cms.workflow;
  
  import java.io.File;
  
  import org.apache.lenya.cms.ac.User;
  import org.apache.lenya.cms.publication.Document;
  import org.apache.lenya.cms.publication.DocumentType;
  import org.apache.lenya.cms.publication.DocumentTypeBuilder;
  import org.apache.lenya.cms.publication.Publication;
  import org.apache.lenya.workflow.*;
  import org.apache.lenya.workflow.Workflow;
  import org.apache.lenya.workflow.WorkflowFactory;
  import org.apache.lenya.workflow.impl.WorkflowBuilder;
  import org.apache.lenya.xml.DocumentHelper;
  import org.apache.lenya.xml.NamespaceHelper;
  import org.w3c.dom.Element;
  
  /**
   *
   * @author andreas
   */
  public class WorkflowFactoryImpl extends WorkflowFactory {
  
      public static final String WORKFLOW_DIRECTORY =
          "config/workflow".replace('/', File.separatorChar);
  
      /** Creates a new instance of WorkflowFactory */
      protected WorkflowFactoryImpl(Document document, User user) {
  
          assert document != null;
          this.document = document;
          
          assert user != null;
          situation = new CMSSituation(user);
      }
  
      public static WorkflowFactoryImpl newInstance(Document document, User user) {
          return new WorkflowFactoryImpl(document, user);
      }
  
      public static final String WORKFLOW_ELEMENT = "workflow";
      public static final String SRC_ATTRIBUTE = "src";
      /* (non-Javadoc)
       * @see org.apache.lenya.cms.workflow.WorkflowFactory#createWorkflow()
       */
  
      private Document document;
      private User user;
  
      private WorkflowDocument workflowDocument;
      private Situation situation;
  
      public WorkflowInstance buildInstance() throws WorkflowBuildException {
          if (workflowDocument == null) {
              workflowDocument = new WorkflowDocument(document);
          }
          return workflowDocument;
      }
  
      protected static Workflow buildWorkflow(Publication publication, DocumentType documentType)
          throws WorkflowBuildException {
  
          File doctypesDirectory =
              new File(publication.getDirectory(), DocumentTypeBuilder.DOCTYPE_DIRECTORY);
          File doctypeFile = new File(doctypesDirectory, documentType.getName() + ".xml");
  
          Workflow workflow;
  
          try {
              org.w3c.dom.Document xmlDocument = DocumentHelper.readDocument(doctypeFile);
  
              NamespaceHelper helper =
                  new NamespaceHelper(
                      DocumentType.NAMESPACE,
                      DocumentType.DEFAULT_PREFIX,
                      xmlDocument);
              Element root = xmlDocument.getDocumentElement();
  
              Element workflowElement =
                  (Element) root.getElementsByTagNameNS(
                      DocumentType.NAMESPACE,
                      WORKFLOW_ELEMENT).item(
                      0);
  
              String source = workflowElement.getAttribute(SRC_ATTRIBUTE);
              assert source != null;
  
              File publicationDirectory = publication.getDirectory();
              File workflowDirectory = new File(publicationDirectory, WORKFLOW_DIRECTORY);
              File workflowFile = new File(workflowDirectory, source);
  
              WorkflowBuilder builder = new WorkflowBuilder();
              workflow = builder.buildWorkflow(workflowFile);
          } catch (Exception e) {
              throw new WorkflowBuildException(e);
          }
          return workflow;
      }
  
      /* (non-Javadoc)
       * @see org.apache.lenya.cms.workflow.WorkflowFactory#buildSituation()
       */
      public Situation buildSituation() throws WorkflowBuildException {
          return situation;
      }
  
  }
  
  
  
  1.1                  cocoon-lenya/src/java/org/apache/lenya/cms/workflow/CommandFilter.java
  
  Index: CommandFilter.java
  ===================================================================
  /*
   * Created on 27.05.2003
   *
   * To change the template for this generated file go to
   * Window>Preferences>Java>Code Generation>Code and Comments
   */
  package org.apache.lenya.cms.workflow;
  
  import org.apache.lenya.workflow.Situation;
  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 interface CommandFilter {
  
      String[] getExecutableCommands(WorkflowInstance instance, Situation situation);
  
  }
  
  
  
  1.1                  cocoon-lenya/src/java/org/apache/lenya/cms/workflow/RoleCondition.java
  
  Index: RoleCondition.java
  ===================================================================
  /*
   * RoleCondition.java
   *
   * Created on 8. April 2003, 17:28
   */
  
  package org.apache.lenya.cms.workflow;
  
  import java.util.HashSet;
  import java.util.Iterator;
  import java.util.Set;
  
  import org.apache.lenya.cms.ac.Group;
  import org.apache.lenya.cms.ac.Role;
  import org.apache.lenya.cms.ac.User;
  import org.apache.lenya.workflow.Condition;
  import org.apache.lenya.workflow.Situation;
  
  /**
   *
   * @author  andreas
   */
  public class RoleCondition implements Condition {
  
      /**
       * Returns if the condition is complied in a certain situation.
       * The condition is complied when the current user has the
       * role that is required by the RoleCondition.
       * @param situation The situation to check.
       * @return if the condition is complied.
       */
      public boolean isComplied(Situation situation) {
  
          CMSSituation situationImpl = (CMSSituation) situation;
          User user = situationImpl.getUser();
          Iterator userGroups = user.getGroups();
          Set userRoles = new HashSet();
          
          while (userGroups.hasNext()) {
          	Iterator groupRoles = ((Group)userGroups.next()).getRoles();
              assert groupRoles != null;
          	while (groupRoles.hasNext()) {
          		userRoles.add(groupRoles.next());
          	}
          }
          
          Role conditionRole = new Role(getExpression().trim());
  
          boolean complied = false;
          Iterator roles = userRoles.iterator();
          while (!complied && roles.hasNext()) {
          	if (conditionRole.equals(roles.next())) {
          		complied = true;
          	}
          }
          return complied;
      }
  
      private String expression;
  
      /** Sets the expression for this condition.
       * @param expression The expression.
       *
       */
      public void setExpression(String expression) {
          assert expression != null;
          this.expression = expression;
      }
  
      public String getExpression() {
          return expression;
      }
  
      /* (non-Javadoc)
       * @see java.lang.Object#toString()
       */
      public String toString() {
          return getExpression();
      }
  
  }
  
  
  
  1.1                  cocoon-lenya/src/java/org/apache/lenya/cms/workflow/CommandFilterImpl.java
  
  Index: CommandFilterImpl.java
  ===================================================================
  /*
   * Created on 27.05.2003
   *
   * To change the template for this generated file go to
   * Window>Preferences>Java>Code Generation>Code and Comments
   */
  package org.apache.lenya.cms.workflow;
  
  import java.util.ArrayList;
  import java.util.List;
  
  import org.apache.lenya.cms.workflow.*;
  import org.apache.lenya.workflow.Situation;
  import org.apache.lenya.workflow.Transition;
  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 CommandFilterImpl implements CommandFilter {
  
      /* (non-Javadoc)
       * @see org.apache.lena.cms.menu.MenuFilter#getExecutableItems(org.apache.lenya.cms.workflow.Situation)
       */
      public String[] getExecutableCommands(
          WorkflowInstance instance,
          Situation situation) {
  
          List commands = new ArrayList();
  
          Transition transitions[] = instance.getExecutableTransitions(situation);
          for (int i = 0; i < transitions.length; i++) {
              String command = transitions[i].getEvent().getCommand();
              commands.add(command);
          }
  
          return (String[]) commands.toArray(new String[commands.size()]);
  
      }
  
  }
  
  
  
  1.1                  cocoon-lenya/src/java/org/apache/lenya/cms/workflow/CMSSituation.java
  
  Index: CMSSituation.java
  ===================================================================
  /*
   * Situation.java
   *
   * Created on 8. April 2003, 17:42
   */
  
  package org.apache.lenya.cms.workflow;
  
  import org.apache.lenya.cms.ac.User;
  import org.apache.lenya.workflow.Situation;
  
  /**
   *
   * @author  andreas
   */
  public class CMSSituation implements Situation {
  
      /** Creates a new instance of Situation */
      protected CMSSituation(User user) {
  
          assert user != null;
          this.user = user;
  
      }
  
      private User user;
  
      /**
       * @return
       */
      public User getUser() {
          return user;
      }
  
  }
  
  
  
  1.1                  cocoon-lenya/src/java/org/apache/lenya/cms/workflow/WorkflowDocument.java
  
  Index: WorkflowDocument.java
  ===================================================================
  /*
   * $Id
   * <License>
   * The Apache Software License
   *
   * Copyright (c) 2002 lenya. All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without modification,
   * 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. All advertising materials mentioning features or use of this software must
   *    display the following acknowledgment: "This product includes software developed
   *    by lenya (http://www.lenya.org)"
   *
   * 4. The name "lenya" must not be used to endorse or promote products derived from
   *    this software without prior written permission. For written permission, please
   *    contact contact@lenya.org
   *
   * 5. Products derived from this software may not be called "lenya" nor may "lenya"
   *    appear in their names without prior written permission of lenya.
   *
   * 6. Redistributions of any form whatsoever must retain the following acknowledgment:
   *    "This product includes software developed by lenya (http://www.lenya.org)"
   *
   * THIS SOFTWARE IS PROVIDED BY lenya "AS IS" WITHOUT ANY WARRANTY EXPRESS OR IMPLIED,
   * INCLUDING THE WARRANTY OF NON-INFRINGEMENT AND THE IMPLIED WARRANTIES OF MERCHANTI-
   * BILITY AND FITNESS FOR A PARTICULAR PURPOSE. lenya WILL NOT BE LIABLE FOR ANY DAMAGES
   * SUFFERED BY YOU AS A RESULT OF USING THIS SOFTWARE. IN NO EVENT WILL lenya BE LIABLE
   * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR LOST PROFITS EVEN IF lenya HAS
   * BEEN ADVISED OF THE POSSIBILITY OF THEIR OCCURRENCE. lenya WILL NOT BE LIABLE FOR ANY
   * THIRD PARTY CLAIMS AGAINST YOU.
   *
   * Lenya includes software developed by the Apache Software Foundation, W3C,
   * DOM4J Project, BitfluxEditor and Xopus.
   * </License>
   */
  package org.apache.lenya.cms.workflow;
  
  import java.io.File;
  
  import org.apache.lenya.cms.publication.Document;
  import org.apache.lenya.cms.publication.DocumentType;
  import org.apache.lenya.workflow.State;
  import org.apache.lenya.workflow.Workflow;
  import org.apache.lenya.workflow.WorkflowBuildException;
  import org.apache.lenya.workflow.impl.WorkflowBuilder;
  import org.apache.lenya.workflow.impl.WorkflowInstanceImpl;
  import org.apache.lenya.xml.DocumentHelper;
  import org.apache.lenya.xml.NamespaceHelper;
  import org.w3c.dom.Element;
  
  /**
   * @author andreas
   *
   * To change the template for this generated type comment go to
   * Window>Preferences>Java>Code Generation>Code and Comments
   */
  public class WorkflowDocument extends WorkflowInstanceImpl {
  
      protected WorkflowDocument(Document document) throws WorkflowBuildException {
          assert document != null;
          this.document = document;
  
          DocumentType type;
          org.w3c.dom.Document xmlDocument;
          try {
              File historyFile = getHistoryFile(document);
              xmlDocument = DocumentHelper.readDocument(historyFile);
              String documentTypeName =
                  xmlDocument.getDocumentElement().getAttribute(DOCTYPE_ATTRIBUTE);
              assert documentTypeName != null;
              type = new DocumentType(documentTypeName);
          } catch (Exception e) {
              throw new WorkflowBuildException(e);
          }
  
          this.workflow = WorkflowFactoryImpl.buildWorkflow(document.getPublication(), type);
  
          // initialize instance state from last version element
          NamespaceHelper helper =
              new NamespaceHelper(
                  WorkflowBuilder.NAMESPACE,
                  WorkflowBuilder.DEFAULT_PREFIX,
                  xmlDocument);
                  
          Element versionElements[] = helper.getChildren(xmlDocument.getDocumentElement(), VERSION_ELEMENT);
          if (versionElements.length > 0) {
              Element lastElement = versionElements[versionElements.length - 1]; 
              String stateId = lastElement.getAttribute(STATE_ATTRIBUTE);
              State state = getState(stateId);
              setCurrentState(state);
          }
                  
      }
  
      private Document document;
  
      public static final String HISTORY_PATH = "history".replace('/', File.separatorChar);
  
      protected static File getHistoryFile(Document document) {
          
          String documentPath = document.getId().replace('/', File.separatorChar) + ".xml";
          
          File workflowDirectory = new File(document.getPublication().getDirectory(), WorkflowFactoryImpl.WORKFLOW_DIRECTORY);
          File historyDirectory = new File(workflowDirectory, HISTORY_PATH);
          File historyFile = new File(historyDirectory, documentPath);
          return historyFile;
      }
  
      /**
       * Returns the document of this WorkflowDocument object.
       * @return A document object.
       */
      protected Document getDocument() {
          return document;
      }
  
      private Workflow workflow;
  
      public static final String DOCTYPE_ATTRIBUTE = "doctype";
      public static final String VERSION_ELEMENT = "version";
      public static final String STATE_ATTRIBUTE = "state";
  
  }
  
  
  

---------------------------------------------------------------------
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