KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > jsp > CmsJspTagIncludeTEI


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/jsp/CmsJspTagIncludeTEI.java,v $
3  * Date : $Date: 2005/06/27 23:22:20 $
4  * Version: $Revision: 1.9 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.jsp;
33
34 import javax.servlet.jsp.tagext.TagData JavaDoc;
35 import javax.servlet.jsp.tagext.TagExtraInfo JavaDoc;
36
37 /**
38  * This is a TagExtraInfo evaluation class that checks the attibutes of
39  * the <code>&lt;cms:include /&gt;</code> tag.<p>
40  *
41  * @author Alexander Kandzior
42  *
43  * @version $Revision: 1.9 $
44  *
45  * @since 6.0.0
46  */

47 public class CmsJspTagIncludeTEI extends TagExtraInfo JavaDoc {
48
49     private static final String JavaDoc ATTR_ATTRIBUTE = "attribute";
50     private static final String JavaDoc ATTR_FILE = "file";
51     private static final String JavaDoc ATTR_PAGE = "page";
52     private static final String JavaDoc ATTR_PROPERTY = "property";
53     private static final String JavaDoc ATTR_SUFFIX = "suffix";
54
55     /**
56      * Returns true if the given attribute name is specified, false otherwise.<p>
57      *
58      * @param data the tag data
59      * @param attributeName the attribute name
60      * @return true if the given attribute name is specified, false otherwise
61      */

62     public static boolean isSpecified(TagData JavaDoc data, String JavaDoc attributeName) {
63
64         return (data.getAttribute(attributeName) != null);
65     }
66
67     /**
68      * Checks the validity of the <code>&lt;cms:include /&gt;</code> attributes.<p>
69      *
70      * The logic used is:
71      * <pre>
72      * if (hasFile && (hasSuffix || hasProperty || hasAttribute)) return false;
73      * if (hasProperty && hasAttribute) return false;
74      * if (hasSuffix && !(hasProperty || hasAttribute)) return false;
75      * </pre>
76      *
77      * @param data the tag data
78      * @return true if attributes are valid, false otherwise
79      */

80     public boolean isValid(TagData JavaDoc data) {
81
82         boolean hasFile = isSpecified(data, ATTR_FILE) || isSpecified(data, ATTR_PAGE);
83         boolean hasSuffix = isSpecified(data, ATTR_SUFFIX);
84         boolean hasProperty = isSpecified(data, ATTR_PROPERTY);
85         boolean hasAttribute = isSpecified(data, ATTR_ATTRIBUTE);
86         // boolean hasElement = isSpecified(data, C_ATTR_ELEMENT);
87

88         if (hasFile && (hasSuffix || hasProperty || hasAttribute)) {
89             return false;
90         }
91         if (hasProperty && hasAttribute) {
92             return false;
93         }
94         if (hasSuffix && !(hasProperty || hasAttribute)) {
95             return false;
96         }
97
98         return true;
99     }
100 }
101
Popular Tags