KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ofbiz > webapp > region > RegionTag


1 /*
2  * $Id: RegionTag.java 5462 2005-08-05 18:35:48Z jonesde $
3  *
4  * Copyright (c) 2001-2003 Sun Microsystems Inc., published in "Advanced Java Server Pages" by Prentice Hall PTR
5  * Copyright (c) 2001-2002 The Open For Business Project - www.ofbiz.org
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a
8  * copy of this software and associated documentation files (the "Software"),
9  * to deal in the Software without restriction, including without limitation
10  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11  * and/or sell copies of the Software, and to permit persons to whom the
12  * Software is furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included
15  * in all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
22  * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
23  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24  *
25  */

26 package org.ofbiz.webapp.region;
27
28 import java.net.URL JavaDoc;
29 import javax.servlet.jsp.JspException JavaDoc;
30 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
31
32 /**
33  * Base tag for other region tags, uses "/WEB-INF/regions.xml" file
34  *
35  * @author David M. Geary in the book "Advanced Java Server Pages"
36  * @author <a HREF="mailto:jonesde@ofbiz.org">David E. Jones</a>
37  * @version $Rev: 5462 $
38  * @since 2.0
39  */

40 public class RegionTag extends TagSupport JavaDoc {
41     protected Region regionObj = null;
42     protected String JavaDoc template = null;
43     private String JavaDoc region = null;
44
45     public void setTemplate(String JavaDoc template) {
46         this.template = template;
47     }
48
49     public void setRegion(String JavaDoc region) {
50         this.region = region;
51     }
52
53     protected boolean findRegionByKey() throws JspException JavaDoc {
54         URL JavaDoc regionFile = null;
55
56         try {
57             regionFile = pageContext.getServletContext().getResource("/WEB-INF/regions.xml");
58         } catch (java.net.MalformedURLException JavaDoc e) {
59             throw new IllegalArgumentException JavaDoc("regions.xml file URL invalid: " + e.getMessage());
60         }
61
62         if (region != null) {
63             regionObj = RegionManager.getRegion(regionFile, region);
64             if (regionObj == null) {
65                 throw new JspException JavaDoc("can't find page definition attribute with this key: " + region);
66             }
67         }
68         return regionObj != null;
69     }
70
71     protected void createRegionFromTemplate(String JavaDoc id) throws JspException JavaDoc {
72         if (template == null)
73             throw new JspException JavaDoc("can't find template");
74
75         regionObj = new Region(id, template);
76     }
77
78     protected void createRegionFromRegion(String JavaDoc id) throws JspException JavaDoc {
79         findRegionByKey();
80
81         if (regionObj == null)
82             return;
83
84         // made from template and sections
85
regionObj = new Region(id, regionObj.getContent(), regionObj.getSections());
86     }
87
88     public void put(Section section) {
89         regionObj.put(section);
90     }
91
92     public void release() {
93         super.release();
94         regionObj = null;
95         region = null;
96         template = null;
97     }
98 }
99
Popular Tags