KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > cms > applications > workflowtool > function > email > ContentVersionAddressProvider


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.email;
24
25 import org.apache.log4j.Logger;
26 import org.infoglue.cms.applications.workflowtool.function.ContentFunction;
27 import org.infoglue.cms.applications.workflowtool.function.defaultvalue.StringPopulator;
28 import org.infoglue.cms.controllers.kernel.impl.simple.ContentVersionController;
29 import org.infoglue.cms.entities.content.ContentVersionVO;
30
31 import com.opensymphony.workflow.WorkflowException;
32
33 /**
34  *
35  */

36 public class ContentVersionAddressProvider extends AddressProvider
37 {
38     private final static Logger logger = Logger.getLogger(ContentVersionAddressProvider.class.getName());
39
40     /**
41      * The name of the attribute argument.
42      */

43     private static final String JavaDoc ATTRIBUTE_ARGUMENT = "attribute";
44     
45     /**
46      * To name of the attribute containing the email.
47      */

48     private String JavaDoc attributeName;
49     
50     /**
51      *
52      */

53     private ContentVersionVO contentVersionVO;
54     
55     /**
56      * Default constructor.
57      */

58     public ContentVersionAddressProvider()
59     {
60         super();
61     }
62
63     /**
64      * Add all recipients. Note that empty email-addresses will be discarded
65      * if the <code>required</code> attribute is <code>false</code>.
66      */

67     protected void populate() throws WorkflowException
68     {
69         logger.debug("Creating email from the [" + attributeName + "] attribute.");
70         addRecipient(getAttribute());
71     }
72     
73     /**
74      *
75      */

76     private String JavaDoc getAttribute() throws WorkflowException
77     {
78         String JavaDoc value = "";
79         try
80         {
81             value = ContentVersionController.getContentVersionController().getAttributeValue(contentVersionVO, attributeName, false);
82         }
83         catch(Exception JavaDoc e)
84         {
85             throwException(e);
86         }
87         return value;
88     }
89     
90     /**
91      * Method used for initializing the function; will be called before <code>execute</code> is called.
92      * <p><strong>Note</strong>! You must call <code>super.initialize()</code> first.</p>
93      *
94      * @throws WorkflowException if an error occurs during the initialization.
95      */

96     protected void initialize() throws WorkflowException
97     {
98         super.initialize();
99         attributeName = getArgument(ATTRIBUTE_ARGUMENT);
100         contentVersionVO = (ContentVersionVO) getParameter(ContentFunction.CONTENT_VERSION_PARAMETER);
101     }
102 }
103
Popular Tags