KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > deliver > taglib > content > ContentParameterTag


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.deliver.taglib.content;
24
25 import java.util.ArrayList JavaDoc;
26 import java.util.HashMap JavaDoc;
27 import java.util.List JavaDoc;
28 import java.util.Map JavaDoc;
29
30 import javax.servlet.jsp.JspException JavaDoc;
31 import javax.servlet.jsp.JspTagException JavaDoc;
32
33 import org.infoglue.deliver.taglib.AbstractTag;
34
35 /**
36  * This class implements the <common:parameter> tag, which adds a parameter
37  * to the parameters of the parent tag.
38  *
39  * Note! This tag must have a <common:urlBuilder> ancestor.
40  */

41 public class ContentParameterTag extends AbstractTag
42 {
43     /**
44      * The universal version identifier.
45      */

46     private static final long serialVersionUID = 4482006814634520239L;
47
48     /**
49      * The contentVO object
50      */

51     private Map JavaDoc contentMap = new HashMap JavaDoc();
52         
53     /**
54      * Default constructor.
55      */

56     public ContentParameterTag()
57     {
58         super();
59     }
60
61     /**
62      * Initializes the parameters to make it accessible for the children tags (if any).
63      *
64      * @return indication of whether to evaluate the body or not.
65      * @throws JspException if an error occurred while processing this tag.
66      */

67     public int doStartTag() throws JspException JavaDoc
68     {
69         return EVAL_BODY_INCLUDE;
70     }
71
72     /**
73      * Adds a parameter with the specified name and value to the parameters
74      * of the parent tag.
75      *
76      * @return indication of whether to continue evaluating the JSP page.
77      * @throws JspException if an error occurred while processing this tag.
78      */

79     public int doEndTag() throws JspException JavaDoc
80     {
81         addContentMap();
82         
83         contentMap = new HashMap JavaDoc();
84         
85         return EVAL_PAGE;
86     }
87     
88     /**
89      * Adds the parameter to the ancestor tag.
90      *
91      * @throws JspException if the ancestor tag isn't a url tag.
92      */

93     protected void addContentMap() throws JspException JavaDoc
94     {
95         final RemoteContentServiceTag parent = (RemoteContentServiceTag) findAncestorWithClass(this, RemoteContentServiceTag.class);
96         if(parent == null)
97         {
98             throw new JspTagException JavaDoc("ContentParameterTag must have a RemoteContentServiceTag ancestor.");
99         }
100
101         ((RemoteContentServiceTag) parent).addContentMap(contentMap);
102     }
103     
104     /**
105      * Sets the name attribute.
106      *
107      * @param name the name to use.
108      * @throws JspException if an error occurs while evaluating name parameter.
109      */

110     public void setName(final String JavaDoc name) throws JspException JavaDoc
111     {
112         this.contentMap.put("name", evaluateString("parameter", "name", name));
113     }
114
115     /**
116      * Sets the repositoryId attribute.
117      *
118      * @param repositoryId the repositoryId the content will belong to.
119      * @throws JspException if an error occurs while evaluating name parameter.
120      */

121     public void setRepositoryId(final String JavaDoc repositoryId) throws JspException JavaDoc
122     {
123         this.contentMap.put("repositoryId", evaluateInteger("parameter", "repositoryId", repositoryId));
124     }
125
126     /**
127      * Sets the parentContentId attribute.
128      *
129      * @param repositoryId the parentContentId the content the new content will be placed under.
130      * @throws JspException if an error occurs while evaluating name parameter.
131      */

132     public void setParentContentId(final String JavaDoc parentContentId) throws JspException JavaDoc
133     {
134         this.contentMap.put("parentContentId", evaluateInteger("parameter", "parentContentId", parentContentId));
135     }
136
137     /**
138      * Sets the contentTypeDefinitionId attribute.
139      *
140      * @param contentTypeDefinitionId the contentTypeDefinitionId the content will be based on.
141      * @throws JspException if an error occurs while evaluating name parameter.
142      */

143     public void setContentTypeDefinitionId(final String JavaDoc contentTypeDefinitionId) throws JspException JavaDoc
144     {
145         this.contentMap.put("contentTypeDefinitionId", evaluateInteger("parameter", "contentTypeDefinitionId", contentTypeDefinitionId));
146     }
147
148     /**
149      * Add the contentVersion the child tag generated to the list of contentVersions that are to be persisted.
150      */

151     public void addContentVersion(final Map JavaDoc contentVersion)
152     {
153         List JavaDoc contentVersions = (List JavaDoc)this.contentMap.get("contentVersions");
154         if(contentVersions == null)
155         {
156             contentVersions = new ArrayList JavaDoc();
157             this.contentMap.put("contentVersions", contentVersions);
158         }
159
160         contentVersions.add(contentVersion);
161     }
162
163     public void clear()
164     {
165         contentMap.clear();
166     }
167 }
168
Popular Tags