KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > au > id > jericho > lib > html > MasonTagTypes


1 // Jericho HTML Parser - Java based library for analysing and manipulating HTML
2
// Version 2.2
3
// Copyright (C) 2006 Martin Jericho
4
// http://sourceforge.net/projects/jerichohtml/
5
//
6
// This library is free software; you can redistribute it and/or
7
// modify it under the terms of the GNU Lesser General Public
8
// License as published by the Free Software Foundation; either
9
// version 2.1 of the License, or (at your option) any later version.
10
// http://www.gnu.org/copyleft/lesser.html
11
//
12
// This library is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
// Lesser General Public License for more details.
16
//
17
// You should have received a copy of the GNU Lesser General Public
18
// License along with this library; if not, write to the Free Software
19
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20

21 package au.id.jericho.lib.html;
22
23 /**
24  * Contains {@linkplain TagType tag types} related to the <a target="_blank" HREF="http://www.masonhq.com/">Mason</a> server platform.
25  * <p>
26  * There is no specific tag type defined for the
27  * <a target="_blank" HREF="http://www.masonbook.com/book/chapter-2.mhtml#CHP-2-SECT-3.1">Mason substitution tag</a>
28  * as it is recognised using the {@linkplain StartTagType#SERVER_COMMON common server tag type}.
29  * <p>
30  * The tag types defined in this class are not {@linkplain TagType#register() registered} by default.
31  * The {@link #register()} method is provided as a convenient way to register them all at once.
32  */

33 public final class MasonTagTypes {
34
35     /**
36      * The tag type given to a
37      * <a target="_blank" HREF="http://www.masonbook.com/book/chapter-2.mhtml#CHP-2-SECT-3.3">Mason component call</a>
38      * (<code>&lt;&amp; </code>&#46;&#46;&#46;<code> &amp;&gt;</code>).
39      * <p>
40      * <dl>
41      * <dt>Properties:</dt>
42      * <dd>
43      * <table class="bordered" style="margin: 15px" cellspacing="0">
44      * <tr><th>Property<th>Value
45      * <tr><td>{@link StartTagType#getDescription() Description}<td>mason component call
46      * <tr><td>{@link StartTagType#getStartDelimiter() StartDelimiter}<td><code>&lt;&amp;</code>
47      * <tr><td>{@link StartTagType#getClosingDelimiter() ClosingDelimiter}<td><code>&amp;&gt;</code>
48      * <tr><td>{@link StartTagType#isServerTag() IsServerTag}<td><code>true</code>
49      * <tr><td>{@link StartTagType#getNamePrefix() NamePrefix}<td><code>&amp;</code>
50      * <tr><td>{@link StartTagType#getCorrespondingEndTagType() CorrespondingEndTagType}<td><code>null</code>
51      * <tr><td>{@link StartTagType#hasAttributes() HasAttributes}<td><code>false</code>
52      * <tr><td>{@link StartTagType#isNameAfterPrefixRequired() IsNameAfterPrefixRequired}<td><code>false</code>
53      * </table>
54      * <dt>Example:</dt>
55      * <dd><code>&lt;&amp; menu &amp;&gt;</code></dd>
56      * </dl>
57      */

58     public static final StartTagType MASON_COMPONENT_CALL=StartTagTypeMasonComponentCall.INSTANCE;
59
60     /**
61      * The tag type given to the start tag of a
62      * <a target="_blank" HREF="http://www.masonbook.com/book/chapter-2.mhtml#CHP-2-SECT-3.3.1">Mason component called with content</a>
63      * (<code>&lt;&amp;| </code>&#46;&#46;&#46;<code> &amp;&gt; </code>&#46;&#46;&#46;<code> &lt;/&amp;&gt;</code>).
64      * <p>
65      * <dl>
66      * <dt>Properties:</dt>
67      * <dd>
68      * <table class="bordered" style="margin: 15px" cellspacing="0">
69      * <tr><th>Property<th>Value
70      * <tr><td>{@link StartTagType#getDescription() Description}<td>mason component called with content
71      * <tr><td>{@link StartTagType#getStartDelimiter() StartDelimiter}<td><code>&lt;&amp;|</code>
72      * <tr><td>{@link StartTagType#getClosingDelimiter() ClosingDelimiter}<td><code>&amp;&gt;</code>
73      * <tr><td>{@link StartTagType#isServerTag() IsServerTag}<td><code>true</code>
74      * <tr><td>{@link StartTagType#getNamePrefix() NamePrefix}<td><code>&amp;|</code>
75      * <tr><td>{@link StartTagType#getCorrespondingEndTagType() CorrespondingEndTagType}<td>{@link #MASON_COMPONENT_CALLED_WITH_CONTENT_END}
76      * <tr><td>{@link StartTagType#hasAttributes() HasAttributes}<td><code>false</code>
77      * <tr><td>{@link StartTagType#isNameAfterPrefixRequired() IsNameAfterPrefixRequired}<td><code>false</code>
78      * </table>
79      * <dt>Example:</dt>
80      * <dd><pre> &lt;&amp;| /sql/select, query =&gt; 'SELECT name, age FROM User' &amp;&gt;
81      * &lt;tr&gt;&lt;td&gt;%name&lt;/td&gt;&lt;td&gt;%age&lt;/td&gt;&lt;/tr&gt;
82      * &lt;/&amp;&gt;</pre></dd>
83      * </dl>
84      */

85     public static final StartTagType MASON_COMPONENT_CALLED_WITH_CONTENT=StartTagTypeMasonComponentCalledWithContent.INSTANCE;
86
87     /**
88      * The tag type given to the end tag of a
89      * <a target="_blank" HREF="http://www.masonbook.com/book/chapter-2.mhtml#CHP-2-SECT-3.3.1">Mason component called with content</a>.
90      * <p>
91      * See the {@linkplain EndTagType#getCorrespondingStartTagType() corresponding start tag type}
92      * {@link #MASON_COMPONENT_CALLED_WITH_CONTENT} for more details.
93      * <p>
94      * <dl>
95      * <dt>Properties:</dt>
96      * <dd>
97      * <table class="bordered" style="margin: 15px" cellspacing="0">
98      * <tr><th>Property/Method<th>Value
99      * <tr><td>{@link EndTagType#getDescription() Description}<td>/mason component called with content
100      * <tr><td>{@link EndTagType#getStartDelimiter() StartDelimiter}<td><code>&lt;/&amp;</code>
101      * <tr><td>{@link EndTagType#getClosingDelimiter() ClosingDelimiter}<td><code>&gt;</code>
102      * <tr><td>{@link EndTagType#isServerTag() IsServerTag}<td><code>true</code>
103      * <tr><td>{@link EndTagType#getNamePrefix() NamePrefix}<td><code>/&amp;</code>
104      * <tr><td>{@link EndTagType#getCorrespondingStartTagType() CorrespondingStartTagType}<td>{@link #MASON_COMPONENT_CALLED_WITH_CONTENT}
105      * <tr><td>{@link EndTagType#generateHTML(String) generateHTML}<code>("</code><i>StartTagName</i><code>")</code><td><code>&lt;/&amp;&gt;</code>
106      * </table>
107      * <dt>Example:</dt>
108      * <dd><code>&lt;/&amp;&gt;</code></dd>
109      * </dl>
110      * @see #MASON_COMPONENT_CALLED_WITH_CONTENT
111      */

112     public static final EndTagType MASON_COMPONENT_CALLED_WITH_CONTENT_END=EndTagTypeMasonComponentCalledWithContent.INSTANCE;
113     
114     /**
115      * The tag type given to the start tag of a
116      * <a target="_blank" HREF="http://www.masonbook.com/book/chapter-2.mhtml#CHP-2-SECT-3.4">Mason named block</a>
117      * (<code>&lt;%<i>name</i> </code>&#46;&#46;&#46;<code> &gt; </code>&#46;&#46;&#46;<code> &lt;/%<i>name</i>&gt;</code>).
118      * <p>
119      * A tag of this type <b>must not</b> have a '<code>%</code>' character before its
120      * {@linkplain StartTagType#getClosingDelimiter() closing delimiter}, otherwise it is most likely a
121      * {@linkplain StartTagType#SERVER_COMMON common server tag}.
122      * <p>
123      * For the start tag to be recognised, a {@linkplain StartTagType#getCorrespondingEndTagType() corresponding} end tag of the
124      * {@linkplain #MASON_NAMED_BLOCK_END correct type} <b>must</b> exist somewhere in the source document following the start tag.
125      * <p>
126      * <dl>
127      * <dt>Properties:</dt>
128      * <dd>
129      * <table class="bordered" style="margin: 15px" cellspacing="0">
130      * <tr><th>Property<th>Value
131      * <tr><td>{@link StartTagType#getDescription() Description}<td>mason named block
132      * <tr><td>{@link StartTagType#getStartDelimiter() StartDelimiter}<td><code>&lt;%</code>
133      * <tr><td>{@link StartTagType#getClosingDelimiter() ClosingDelimiter}<td><code>&gt;</code>
134      * <tr><td>{@link StartTagType#isServerTag() IsServerTag}<td><code>true</code>
135      * <tr><td>{@link StartTagType#getNamePrefix() NamePrefix}<td><code>%</code>
136      * <tr><td>{@link StartTagType#getCorrespondingEndTagType() CorrespondingEndTagType}<td>{@link #MASON_NAMED_BLOCK_END}
137      * <tr><td>{@link StartTagType#hasAttributes() HasAttributes}<td><code>false</code>
138      * <tr><td>{@link StartTagType#isNameAfterPrefixRequired() IsNameAfterPrefixRequired}<td><code>true</code>
139      * </table>
140      * <dt>Example:</dt>
141      * <dd><code>&lt;%perl&gt; print "hello world"; &lt;/%perl&gt;</code></dd>
142      * </dl>
143      */

144     public static final StartTagType MASON_NAMED_BLOCK=StartTagTypeMasonNamedBlock.INSTANCE;
145
146     /**
147      * The tag type given to the end tag of a
148      * <a target="_blank" HREF="http://www.masonbook.com/book/chapter-2.mhtml#CHP-2-SECT-3.4">Mason named block</a>.
149      * <p>
150      * See the {@linkplain EndTagType#getCorrespondingStartTagType() corresponding start tag type}
151      * {@link #MASON_NAMED_BLOCK} for more details.
152      * <p>
153      * <dl>
154      * <dt>Properties:</dt>
155      * <dd>
156      * <table class="bordered" style="margin: 15px" cellspacing="0">
157      * <tr><th>Property/Method<th>Value
158      * <tr><td>{@link EndTagType#getDescription() Description}<td>/mason named block
159      * <tr><td>{@link EndTagType#getStartDelimiter() StartDelimiter}<td><code>&lt;/%</code>
160      * <tr><td>{@link EndTagType#getClosingDelimiter() ClosingDelimiter}<td><code>&gt;</code>
161      * <tr><td>{@link EndTagType#isServerTag() IsServerTag}<td><code>true</code>
162      * <tr><td>{@link EndTagType#getNamePrefix() NamePrefix}<td><code>/%</code>
163      * <tr><td>{@link EndTagType#getCorrespondingStartTagType() CorrespondingStartTagType}<td>{@link #MASON_NAMED_BLOCK}
164      * <tr><td>{@link EndTagType#generateHTML(String) generateHTML}<code>("</code><i>StartTagName</i><code>")</code><td><code>&lt;/%</code><i>StartTagName</i><code>&gt;</code>
165      * </table>
166      * <dt>Example:</dt>
167      * <dd><code>&lt;/%perl&gt;</code></dd>
168      * </dl>
169      * @see #MASON_NAMED_BLOCK
170      */

171     public static final EndTagType MASON_NAMED_BLOCK_END=EndTagTypeMasonNamedBlock.INSTANCE;
172
173     private static final TagType[] TAG_TYPES={
174         MASON_COMPONENT_CALL,
175         MASON_COMPONENT_CALLED_WITH_CONTENT,
176         MASON_COMPONENT_CALLED_WITH_CONTENT_END,
177         MASON_NAMED_BLOCK,
178         MASON_NAMED_BLOCK_END
179     };
180
181     private MasonTagTypes() {}
182     
183     /**
184      * {@linkplain TagType#register() Registers} all of the tag types defined in this class at once.
185      * <p>
186      * The tag types must be registered before the parser will recognise them.
187      */

188     public static void register() {
189         for (int i=0; i<TAG_TYPES.length; i++) TAG_TYPES[i].register();
190     }
191
192     /**
193      * Indicates whether the specified tag type is defined in this class.
194      *
195      * @param tagType the {@link TagType} to test.
196      * @return <code>true</code> if the specified tag type is defined in this class, otherwise <code>false</code>.
197      */

198     public static boolean defines(final TagType tagType) {
199         for (int i=0; i<TAG_TYPES.length; i++)
200             if (tagType==TAG_TYPES[i]) return true;
201         return false;
202     }
203     
204     /**
205      * Indicates whether the specified tag type is recognised by a <a target="_blank" HREF="http://www.masonhq.com/">Mason</a> parser.
206      * <p>
207      * This is true if the specified tag type is {@linkplain #defines(TagType) defined in this class} or if it is the
208      * {@linkplain StartTagType#SERVER_COMMON common server tag type}.
209      *
210      * @param tagType the {@link TagType} to test.
211      * @return <code>true</code> if the specified tag type is recognised by a <a target="_blank" HREF="http://www.masonhq.com/">Mason</a> parser, otherwise <code>false</code>.
212      */

213     public static boolean isParsedByMason(final TagType tagType) {
214         return tagType==StartTagType.SERVER_COMMON || defines(tagType);
215     }
216 }
217
Popular Tags