View Javadoc

1   /**
2    * This file Copyright (c) 2003-2010 Magnolia International
3    * Ltd.  (http://www.magnolia-cms.com). All rights reserved.
4    *
5    *
6    * This file is dual-licensed under both the Magnolia
7    * Network Agreement and the GNU General Public License.
8    * You may elect to use one or the other of these licenses.
9    *
10   * This file is distributed in the hope that it will be
11   * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
12   * implied warranty of MERCHANTABILITY or FITNESS FOR A
13   * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
14   * Redistribution, except as permitted by whichever of the GPL
15   * or MNA you select, is prohibited.
16   *
17   * 1. For the GPL license (GPL), you can redistribute and/or
18   * modify this file under the terms of the GNU General
19   * Public License, Version 3, as published by the Free Software
20   * Foundation.  You should have received a copy of the GNU
21   * General Public License, Version 3 along with this program;
22   * if not, write to the Free Software Foundation, Inc., 51
23   * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24   *
25   * 2. For the Magnolia Network Agreement (MNA), this file
26   * and the accompanying materials are made available under the
27   * terms of the MNA which accompanies this distribution, and
28   * is available at http://www.magnolia-cms.com/mna.html
29   *
30   * Any modifications to this file must keep this entire header
31   * intact.
32   *
33   */
34  package info.magnolia.module.workflow.commands;
35  
36  import java.util.ArrayList;
37  import java.util.Collection;
38  import java.util.Iterator;
39  
40  import org.apache.commons.lang.StringUtils;
41  
42  /**
43   * Map paths to workflows.
44   * @author philipp
45   * @version $Id: PathMappedFlowCommand.java 32667 2010-03-13 00:37:06Z gjoseph $
46   *
47   */
48  public class PathMappedFlowCommand extends FlowCommand {
49  
50      private Collection<Mapping> mappings = new ArrayList<Mapping>();
51  
52      private String repository;
53  
54      private String path;
55  
56      /**
57       * In case there is a mapping defined the mapping is used otherwise we fall back to the normal behavior.
58       */
59      public String getWorkflowName() {
60          for (Iterator<Mapping> iter = getMappings().iterator(); iter.hasNext();) {
61              Mapping mapping = iter.next();
62              if(path.startsWith(mapping.getPath())){
63                  return mapping.getWorkflowName();
64              }
65          }
66          return super.getWorkflowName();
67      }
68      public String getDialogName() {
69          for (Iterator<Mapping> iter = getMappings().iterator(); iter.hasNext();) {
70              Mapping mapping = iter.next();
71              if(path.startsWith(mapping.getPath()) && StringUtils.isNotEmpty(mapping.getDialogName())){
72                  return mapping.getDialogName();
73              }
74          }
75          return super.getDialogName();
76      }
77  
78      public Collection<Mapping> getMappings() {
79          return this.mappings;
80      }
81  
82      public void setMappings(Collection<Mapping> mappings) {
83          this.mappings = mappings;
84      }
85  
86      public void addMapping(Mapping mapping) {
87          if (mapping.isEnabled()) {
88              this.mappings.add(mapping);
89          }
90      }
91  
92      public String getPath() {
93          return this.path;
94      }
95  
96      public void setPath(String path) {
97          this.path = path;
98      }
99  
100     public String getRepository() {
101         return this.repository;
102     }
103 
104     public void setRepository(String repository) {
105         this.repository = repository;
106     }
107 
108     @Override
109     public void release() {
110         super.release();
111         mappings = new ArrayList<Mapping>();
112         repository = null;
113         path = null;
114     }
115 
116     /**
117      * Used to definen the mappings
118      */
119     public static class Mapping {
120 
121         private String path;
122 
123         private String workflowName;
124 
125         private String dialogName;
126 
127         private boolean enabled = true;
128 
129         public String getPath() {
130             return this.path;
131         }
132 
133         public void setPath(String path) {
134             this.path = path;
135         }
136 
137         public String getWorkflowName() {
138             return this.workflowName;
139         }
140 
141         public void setWorkflowName(String workflowName) {
142             this.workflowName = workflowName;
143         }
144 
145         public boolean isEnabled() {
146             return this.enabled;
147         }
148 
149         public void setEnabled(boolean enabled) {
150             this.enabled = enabled;
151         }
152 
153 
154         public String getDialogName() {
155             return this.dialogName;
156         }
157 
158 
159         public void setDialogName(String dialogName) {
160             this.dialogName = dialogName;
161         }
162     }
163 
164 
165 }