KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > verge > mvc > view > jsp > repository > RepositoryItemTag


1 /*
2  * Copyright (c) 2003, Inversoft
3  *
4  * This software is distribuable under the GNU Lesser General Public License.
5  * For more information visit gnu.org.
6  */

7 package com.inversoft.verge.mvc.view.jsp.repository;
8
9
10 import javax.servlet.http.HttpServletRequest JavaDoc;
11 import javax.servlet.jsp.JspException JavaDoc;
12 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
13
14 import com.inversoft.verge.mvc.model.ModelResolution;
15 import com.inversoft.verge.mvc.model.repository.RepositoryMetaData;
16 import com.inversoft.verge.mvc.view.jsp.model.ModelResolutionRegistry;
17 import com.inversoft.verge.repository.Repository;
18
19
20 /**
21  * <p>
22  * This class is identical to the JSTL set tag and the JSP
23  * useBean tag except that it sets the page variable to the
24  * instance of a repository item.
25  * </p>
26  *
27  * @author Brian Pontarelli
28  */

29 public class RepositoryItemTag extends TagSupport JavaDoc {
30
31     private String JavaDoc item;
32     private String JavaDoc var;
33
34
35     /**
36      * Gets the name of the item, repository id, that is being included on the page
37      *
38      * @return The name of the item, repository ID
39      */

40     public String JavaDoc getItem() {
41         return item;
42     }
43
44     /**
45      * Sets the name of the item, repository id, that is being included on the page
46      *
47      * @param item The name of the item, repository ID
48      */

49     public void setItem(String JavaDoc item) {
50         this.item = item;
51     }
52
53     /**
54      * Gets the name of the page variable that the repository Item will be stored
55      * under in the pageContext and also published via the TEI class.
56      *
57      * @return The name of the page variable of the repository item
58      */

59     public String JavaDoc getVar() {
60         return var;
61     }
62
63     /**
64      * Sets the name of the page variable that the repository Item will be stored
65      * under in the pageContext and also published via the TEI class.
66      *
67      * @param var The name of the page variable of the repository item
68      */

69     public void setVar(String JavaDoc var) {
70         this.var = var;
71     }
72
73     /**
74      * The first thing this method does is verfiy that the included handler
75      * exists in the application. Second, it adds the include into the form
76      * tag so that submit tags can verify that the hanlder they are using was
77      * included. Lastly, it writes out a hidden input tag so that when the form
78      * is submitted, the ActionServlet can figure out what handler to use.
79      * @return Always returns SKIP_BODY
80      * @throws JspException If this tag is not inside a form tag
81      */

82     public int doStartTag() throws JspException JavaDoc {
83
84         // check the config repository for the handler
85
if (!Repository.getInstance().isValidItem(pageContext.getRequest(), item)) {
86             throw new JspException JavaDoc("Repository item with an ID of: " + item +
87                 " is not in the repository");
88         }
89
90         Object JavaDoc itemObj = Repository.getInstance().lookupItem(
91             (HttpServletRequest JavaDoc) pageContext.getRequest(), item);
92
93         pageContext.setAttribute(var, itemObj);
94
95         // Store the ModelResolution for model tags
96
RepositoryMetaData md = new RepositoryMetaData(item, null);
97
98         ModelResolution modelResolution = new ModelResolution(itemObj, md);
99         ModelResolutionRegistry.store(var, modelResolution, pageContext);
100
101         return SKIP_BODY;
102     }
103 }
104
Popular Tags