KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.util.*;
24
25 /**
26  * Defines the syntax for an end tag type.
27  * <p>
28  * An end tag type is a {@link TagType} that {@linkplain #getStartDelimiter() starts} with the characters '<code>&lt;/</code>'.
29  * <p>
30  * Instances of all the <a HREF="TagType.html#Standard">standard</a> end tag types are available in this class as static
31  * <a HREF="#field_summary">fields</a>.
32  *
33  * @see StartTagType
34  */

35 public abstract class EndTagType extends TagType {
36     static final String JavaDoc START_DELIMITER_PREFIX="</";
37
38     /**
39      * The tag type given to an {@linkplain Tag#isUnregistered() unregistered} {@linkplain EndTag end tag} (<code>&lt;/ </code>&#46;&#46;&#46;<code> &gt;</code>).
40      * <p>
41      * See the documentation of the {@link Tag#isUnregistered()} method for details.
42      * <p>
43      * <dl>
44      * <dt>Properties:</dt>
45      * <dd>
46      * <table class="bordered" style="margin: 15px" cellspacing="0">
47      * <tr><th>Property/Method<th>Value
48      * <tr><td>{@link #getDescription() Description}<td>/unregistered
49      * <tr><td>{@link #getStartDelimiter() StartDelimiter}<td><code>&lt;/</code>
50      * <tr><td>{@link #getClosingDelimiter() ClosingDelimiter}<td><code>&gt;</code>
51      * <tr><td>{@link #isServerTag() IsServerTag}<td><code>false</code>
52      * <tr><td>{@link #getNamePrefix() NamePrefix}<td><i>(empty string)</i>
53      * <tr><td>{@link #getCorrespondingStartTagType() CorrespondingStartTagType}<td><code>null</code>
54      * <tr><td>{@link #generateHTML(String) generateHTML}<code>("</code><i>StartTagName</i><code>")</code><td><code>&lt;/</code><i>StartTagName</i><code>&gt;</code>
55      * </table>
56      * <dt>Example:</dt>
57      * <dd><code>&lt;/ "This is not recognised as any of the predefined end tag types in this library"&gt;</code></dd>
58      * </dl>
59      * @see StartTagType#UNREGISTERED
60      */

61     public static final EndTagType UNREGISTERED=EndTagTypeUnregistered.INSTANCE;
62
63     /**
64      * The tag type given to a normal HTML or XML {@linkplain EndTag end tag} (<code>&lt;/</code><i>name</i><code>&gt;</code>).
65      * <p>
66      * <dl>
67      * <dt>Properties:</dt>
68      * <dd>
69      * <table class="bordered" style="margin: 15px" cellspacing="0">
70      * <tr><th>Property/Method<th>Value
71      * <tr><td>{@link #getDescription() Description}<td>/normal
72      * <tr><td>{@link #getStartDelimiter() StartDelimiter}<td><code>&lt;/</code>
73      * <tr><td>{@link #getClosingDelimiter() ClosingDelimiter}<td><code>&gt;</code>
74      * <tr><td>{@link #isServerTag() IsServerTag}<td><code>false</code>
75      * <tr><td>{@link #getNamePrefix() NamePrefix}<td><i>(empty string)</i>
76      * <tr><td>{@link #getCorrespondingStartTagType() CorrespondingStartTagType}<td>{@link StartTagType#NORMAL}
77      * <tr><td>{@link #generateHTML(String) generateHTML}<code>("</code><i>StartTagName</i><code>")</code><td><code>&lt;/</code><i>StartTagName</i><code>&gt;</code>
78      * </table>
79      * <dt>Example:</dt>
80      * <dd><code>&lt;/div&gt;</code></dd>
81      * </dl>
82      */

83     public static final EndTagType NORMAL=EndTagTypeNormal.INSTANCE;
84
85     /**
86      * Constructs a new <code>EndTagType</code> object with the specified properties.
87      * <br />(<a HREF="TagType.html#ImplementationAssistance">implementation assistance</a> method)
88      * <p>
89      * As <code>EndTagType</code> is an abstract class, this constructor is only called from sub-class constructors.
90      *
91      * @param description a {@linkplain #getDescription() description} of the new end tag type useful for debugging purposes.
92      * @param startDelimiter the {@linkplain #getStartDelimiter() start delimiter} of the new end tag type.
93      * @param closingDelimiter the {@linkplain #getClosingDelimiter() closing delimiter} of the new end tag type.
94      * @param isServerTag indicates whether the new end tag type is a {@linkplain #isServerTag() server tag}.
95      */

96     protected EndTagType(final String JavaDoc description, final String JavaDoc startDelimiter, final String JavaDoc closingDelimiter, final boolean isServerTag) {
97         super(description,startDelimiter.toLowerCase(),closingDelimiter,isServerTag,START_DELIMITER_PREFIX);
98         if (!getStartDelimiter().startsWith(START_DELIMITER_PREFIX)) throw new IllegalArgumentException JavaDoc("startDelimiter of an end tag must start with \""+START_DELIMITER_PREFIX+'"');
99     }
100
101     /**
102      * Returns the {@linkplain StartTagType type} of {@linkplain StartTag start tag} that is <i>usually</i> paired with an
103      * {@linkplain EndTag end tag} of this type to form an {@link Element}.
104      * <br />(<a HREF="TagType.html#DefaultImplementation">default implementation</a> method)
105      * <p>
106      * The default implementation returns <code>null</code>.
107      * <p>
108      * This property is informational only and is not used by the parser in any way.
109      * <p>
110      * The mapping of end tag type to the corresponding start tag type is in any case one-to-many, which is why the definition
111      * emphasises the word "usually".
112      * An example of this is the {@link PHPTagTypes#PHP_SCRIPT} start tag type,
113      * whose {@linkplain StartTagType#getCorrespondingEndTagType() corresponding end tag type} is {@link #NORMAL EndTagType.NORMAL},
114      * while the converse is not true.
115      * <p>
116      * The only <a HREF="TagType.html#Predefined">predefined</a> end tag type that returns <code>null</code> for this property is the
117      * special {@link #UNREGISTERED} end tag type.
118      * <p>
119      * Although this method is used like a <a HREF="TagType.html#Property">property</a> method, it is implemented as a
120      * <a HREF="TagType.html#DefaultImplementation">default implementation</a> method to avoid cyclic references between statically
121      * instantiated {@link StartTagType} and <code>EndTagType</code> objects.
122      * <p>
123      * <dl>
124      * <dt>Standard Tag Type Values:</dt>
125      * <dd>
126      * <table class="bordered" style="margin: 15px" cellspacing="0">
127      * <tr><th>End Tag Type<th>Corresponding Start Tag Type
128      * <tr><td>{@link EndTagType#UNREGISTERED}<td><code>null</code>
129      * <tr><td>{@link EndTagType#NORMAL}<td>{@link StartTagType#NORMAL}
130      * </table>
131      * </dl>
132      * <dl>
133      * <dt>Extended Tag Type Values:</dt>
134      * <dd>
135      * <table class="bordered" style="margin: 15px" cellspacing="0">
136      * <tr><th>End Tag Type<th>Corresponding Start Tag Type
137      * <tr><td>{@link MasonTagTypes#MASON_COMPONENT_CALLED_WITH_CONTENT_END}<td>{@link MasonTagTypes#MASON_COMPONENT_CALLED_WITH_CONTENT}
138      * <tr><td>{@link MasonTagTypes#MASON_NAMED_BLOCK_END}<td>{@link MasonTagTypes#MASON_NAMED_BLOCK}
139      * </table>
140      * </dl>
141      *
142      * @return the {@linkplain StartTagType type} of {@linkplain StartTag start tag} that is <i>usually</i> paired with an {@linkplain EndTag end tag} of this type to form an {@link Element}.
143      * @see StartTagType#getCorrespondingEndTagType()
144      */

145     public StartTagType getCorrespondingStartTagType() {
146         return null;
147     }
148
149     /**
150      * Generates the HTML text of an {@linkplain EndTag end tag} of this type given the {@linkplain StartTag#getName() name} of a {@linkplain #getCorrespondingStartTagType() corresponding} {@linkplain StartTag start tag}.
151      * <br />(<a HREF="TagType.html#Property">property</a> method)
152      * <p>
153      * This default implementation returns {@link #getStartDelimiter()}<code>+startTagName+</code>{@link #getClosingDelimiter()}.
154      * <p>
155      * <dl>
156      * <dt>Standard Tag Type Values:</dt>
157      * <dd>
158      * <table class="bordered" style="margin: 15px" cellspacing="0">
159      * <tr><th>End Tag Type<th>HTML Generated for specified <i>StartTagName</i>
160      * <tr><td>{@link EndTagType#UNREGISTERED}<td><code>&lt;/</code><i>StartTagName</i><code>&gt;</code>
161      * <tr><td>{@link EndTagType#NORMAL}<td><code>&lt;/</code><i>StartTagName</i><code>&gt;</code>
162      * </table>
163      * </dl>
164      * <dl>
165      * <dt>Extended Tag Type Values:</dt>
166      * <dd>
167      * <table class="bordered" style="margin: 15px" cellspacing="0">
168      * <tr><th>End Tag Type<th>HTML Generated for specified <i>StartTagName</i>
169      * <tr><td>{@link MasonTagTypes#MASON_COMPONENT_CALLED_WITH_CONTENT_END}<td><code>&lt;/&amp;&gt;</code>
170      * <tr><td>{@link MasonTagTypes#MASON_NAMED_BLOCK_END}<td><code>&lt;/%</code><i>StartTagName</i><code>&gt;</code>
171      * </table>
172      * </dl>
173      *
174      * @param startTagName the {@linkplain StartTag#getName() name} of a {@linkplain #getCorrespondingStartTagType() corresponding} {@linkplain StartTag start tag}.
175      * @return the HTML text of an {@linkplain EndTag end tag} of this type given the {@linkplain StartTag#getName() name} of a {@linkplain #getCorrespondingStartTagType() corresponding} {@linkplain StartTag start tag}.
176      */

177     public String JavaDoc generateHTML(final String JavaDoc startTagName) {
178         return getStartDelimiter()+startTagName+getClosingDelimiter();
179     }
180     
181     /**
182      * Internal method for the construction of an {@link EndTag} object of this type.
183      * <br />(<a HREF="TagType.html#ImplementationAssistance">implementation assistance</a> method)
184      * <p>
185      * Intended for use from within the {@link #constructTagAt(Source,int) constructTagAt(Source, int pos)} method.
186      *
187      * @param source the {@link Source} document.
188      * @param begin the character position in the source document where this tag {@linkplain Segment#getBegin() begins}.
189      * @param end the character position in the source document where this tag {@linkplain Segment#getEnd() ends}.
190      * @param name the {@linkplain Tag#getName() name} of the tag.
191      * @return the new {@link EndTag} object.
192      */

193     protected final EndTag constructEndTag(final Source source, final int begin, final int end, final String JavaDoc name) {
194         return new EndTag(source,begin,end,this,name);
195     }
196 }
197
Popular Tags