KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > cms > applications > workflowtool > function > ContentPropertysetPopulator


1 /* ===============================================================================
2 *
3 * Part of the InfoGlue Content Management Platform (www.infoglue.org)
4 *
5 * ===============================================================================
6 *
7 * Copyright (C)
8 *
9 * This program is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License version 2, as published by the
11 * Free Software Foundation. See the file LICENSE.html for more information.
12 *
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
19 * Place, Suite 330 / Boston, MA 02111-1307 / USA.
20 *
21 * ===============================================================================
22 */

23 package org.infoglue.cms.applications.workflowtool.function;
24
25 import java.util.Collection JavaDoc;
26 import java.util.HashMap JavaDoc;
27 import java.util.Iterator JavaDoc;
28 import java.util.Map JavaDoc;
29
30 import org.infoglue.cms.controllers.kernel.impl.simple.ContentTypeDefinitionController;
31 import org.infoglue.cms.controllers.kernel.impl.simple.ContentVersionController;
32 import org.infoglue.cms.entities.management.ContentTypeAttribute;
33 import org.infoglue.cms.entities.management.ContentTypeDefinition;
34
35 import com.opensymphony.workflow.WorkflowException;
36
37 /**
38  *
39  */

40 public class ContentPropertysetPopulator extends ContentFunction
41 {
42     /**
43      *
44      */

45     private final String JavaDoc PROPERTYSET_PREFIX_ARGUMENT = "propertysetPrefix";
46     
47     /**
48      *
49      */

50     private final String JavaDoc ATTRIBUTE_PREFIX_ARGUMENT = "attributePrefix";
51     
52     /**
53      *
54      */

55     private String JavaDoc propertysetPrefix;
56     
57     /**
58      *
59      */

60     private String JavaDoc attributePrefix;
61     
62     /**
63      * Default constructor.
64      */

65     public ContentPropertysetPopulator()
66     {
67         super();
68     }
69
70     /**
71      *
72      */

73     protected void execute() throws WorkflowException
74     {
75         final Map JavaDoc attributeValues = getAttributeValues();
76         for(final Iterator JavaDoc i = attributeValues.keySet().iterator(); i.hasNext(); )
77         {
78             final String JavaDoc name = i.next().toString();
79             final String JavaDoc value = (String JavaDoc) attributeValues.get(name);
80             if(name.startsWith(attributePrefix))
81             {
82                 setPropertySetDataString(propertysetPrefix + name, value);
83             }
84         }
85     }
86
87     /**
88      * TODO: MOVE TO CONTROLLER?
89      */

90     protected final Map JavaDoc getAttributeValues() throws WorkflowException
91     {
92         final Map JavaDoc values = new HashMap JavaDoc();
93         if(getContentVO() != null && getContentVersionVO() != null)
94         {
95             try
96             {
97                 final ContentTypeDefinitionController ctdController = ContentTypeDefinitionController.getController();
98                 final ContentTypeDefinition ctd = ctdController.getContentTypeDefinitionWithId(getContentVO().getContentTypeDefinitionId(), getDatabase());
99                 final Collection JavaDoc contentTypeAttributes = ctdController.getContentTypeAttributes(ctd.getSchemaValue());
100                 for(final Iterator JavaDoc i=contentTypeAttributes.iterator(); i.hasNext(); )
101                 {
102                     final ContentTypeAttribute attribute = (ContentTypeAttribute) i.next();
103                     values.put(attribute.getName(), ContentVersionController.getContentVersionController().getAttributeValue(getContentVersionVO(), attribute.getName(), false));
104                 }
105             }
106             catch(Exception JavaDoc e)
107             {
108                 throwException(e);
109             }
110         }
111         return values;
112     }
113     
114     /**
115      * Method used for initializing the function; will be called before <code>execute</code> is called.
116      * <p><strong>Note</strong>! You must call <code>super.initialize()</code> first.</p>
117      *
118      * @throws WorkflowException if an error occurs during the initialization.
119      */

120     protected void initialize() throws WorkflowException
121     {
122         super.initialize();
123         this.propertysetPrefix = getArgument(PROPERTYSET_PREFIX_ARGUMENT, "");
124         this.attributePrefix = getArgument(ATTRIBUTE_PREFIX_ARGUMENT, "");
125     }
126 }
127
Popular Tags