KickJava   Java API By Example, From Geeks To Geeks.

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


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.php.net">PHP</a> server platform.
25  * <p>
26  * There is no specific tag type defined for the
27  * <a target="_blank" HREF="http://www.php.net/manual/en/ini.core.php#ini.asp-tags">ASP-style PHP 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 PHPTagTypes {
34
35     /**
36      * The tag type given to a
37      * <a target="_blank" HREF="http://www.php.net/manual/en/language.basic-syntax.php#language.basic-syntax.phpmode">standard PHP tag</a>
38      * (<code>&lt;&#63;php </code>&#46;&#46;&#46;<code> &#63;&gt;</code>).
39      * <p>
40      * Note that the standard PHP processor includes as part of the tag any newline characters directly following the
41      * {@linkplain TagType#getClosingDelimiter() closing delimiter}, but PHP tags recognised by this library do not include
42      * trailing newlines. They must be removed manually if required.
43      * <p>
44      * This library only correctly recognises standard PHP tags that comply with the XML syntax for processing instructions.
45      * Specifically, the tag is terminated by the first occurrence of the {@linkplain TagType#getClosingDelimiter() closing delimiter}
46      * "<code>?&gt;</code>", even if it occurs within a PHP string expression.
47      * Unfortunately there is no reliable way to determine the end of a PHP tag without the use of a PHP parser.
48      * The following code is an example of a standard PHP tag that is <b>not</b> recognised correctly by this parser
49      * because of the presence of the closing delimiter within a string expression:
50      * <p>
51      * <pre>&lt;?php echo("&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\n"); ?&gt;</pre>
52      * <p>
53      * This is recognised as the PHP tag: <code>&lt;?php echo("&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;</code><br />
54      * followed by the plain text: <code>\n"); ?&gt;</code>
55      * <p>
56      * <dl>
57      * <dt>Properties:</dt>
58      * <dd>
59      * <table class="bordered" style="margin: 15px" cellspacing="0">
60      * <tr><th>Property<th>Value
61      * <tr><td>{@link StartTagType#getDescription() Description}<td>PHP standard tag
62      * <tr><td>{@link StartTagType#getStartDelimiter() StartDelimiter}<td><code>&lt;?php</code>
63      * <tr><td>{@link StartTagType#getClosingDelimiter() ClosingDelimiter}<td><code>?&gt;</code>
64      * <tr><td>{@link StartTagType#isServerTag() IsServerTag}<td><code>true</code>
65      * <tr><td>{@link StartTagType#getNamePrefix() NamePrefix}<td><code>?php</code>
66      * <tr><td>{@link StartTagType#getCorrespondingEndTagType() CorrespondingEndTagType}<td><code>null</code>
67      * <tr><td>{@link StartTagType#hasAttributes() HasAttributes}<td><code>false</code>
68      * <tr><td>{@link StartTagType#isNameAfterPrefixRequired() IsNameAfterPrefixRequired}<td><code>false</code>
69      * </table>
70      * <dt>Example:</dt>
71      * <dd><code>&lt;?php echo '&lt;p&gt;Hello World&lt;/p&gt;'; ?&gt;</code></dd>
72      * </dl>
73      */

74     public static final StartTagType PHP_STANDARD=StartTagTypePHPStandard.INSTANCE;
75
76     /**
77      * The tag type given to a
78      * <a target="_blank" HREF="http://www.php.net/manual/en/ini.core.php#ini.short-open-tag">short-form PHP tag</a>
79      * (<code>&lt;&#63; </code>&#46;&#46;&#46;<code> &#63;&gt;</code>).
80      * <p>
81      * When this tag type is {@linkplain TagType#register() registered}, all
82      * {@linkplain StartTagType#XML_PROCESSING_INSTRUCTION XML processing instructions} are recognised as short-form PHP tags instead.
83      * <p>
84      * The comments in the documentation of the {@link #PHP_STANDARD} tag type regarding the termination of PHP tags and
85      * trailing newlines are also applicable to this tag type.
86      * <p>
87      * <dl>
88      * <dt>Properties:</dt>
89      * <dd>
90      * <table class="bordered" style="margin: 15px" cellspacing="0">
91      * <tr><th>Property<th>Value
92      * <tr><td>{@link StartTagType#getDescription() Description}<td>PHP short tag
93      * <tr><td>{@link StartTagType#getStartDelimiter() StartDelimiter}<td><code>&lt;?</code>
94      * <tr><td>{@link StartTagType#getClosingDelimiter() ClosingDelimiter}<td><code>?&gt;</code>
95      * <tr><td>{@link StartTagType#isServerTag() IsServerTag}<td><code>true</code>
96      * <tr><td>{@link StartTagType#getNamePrefix() NamePrefix}<td><code>?</code>
97      * <tr><td>{@link StartTagType#getCorrespondingEndTagType() CorrespondingEndTagType}<td><code>null</code>
98      * <tr><td>{@link StartTagType#hasAttributes() HasAttributes}<td><code>false</code>
99      * <tr><td>{@link StartTagType#isNameAfterPrefixRequired() IsNameAfterPrefixRequired}<td><code>false</code>
100      * </table>
101      * <dt>Example:</dt>
102      * <dd><code>&lt;? echo '&lt;p&gt;Hello World&lt;/p&gt;'; ?&gt;</code></dd>
103      * </dl>
104      */

105     public static final StartTagType PHP_SHORT=StartTagTypePHPShort.INSTANCE;
106
107     /**
108      * The tag type given to a
109      * <a target="_blank" HREF="http://www.php.net/manual/en/language.basic-syntax.php#language.basic-syntax.phpmode">script-style PHP start tag</a>
110      * (<code>&lt;script language="php"&gt; </code>&#46;&#46;&#46;<code> &lt;/script&gt;</code>).
111      * <p>
112      * <dl>
113      * <dt>Properties:</dt>
114      * <dd>
115      * <table class="bordered" style="margin: 15px" cellspacing="0">
116      * <tr><th>Property<th>Value
117      * <tr><td>{@link StartTagType#getDescription() Description}<td>PHP script
118      * <tr><td>{@link StartTagType#getStartDelimiter() StartDelimiter}<td><code>&lt;script</code>
119      * <tr><td>{@link StartTagType#getClosingDelimiter() ClosingDelimiter}<td><code>&gt;</code>
120      * <tr><td>{@link StartTagType#isServerTag() IsServerTag}<td><code>true</code>
121      * <tr><td>{@link StartTagType#getNamePrefix() NamePrefix}<td><code>script</code>
122      * <tr><td>{@link StartTagType#getCorrespondingEndTagType() CorrespondingEndTagType}<td>{@link EndTagType#NORMAL}
123      * <tr><td>{@link StartTagType#hasAttributes() HasAttributes}<td><code>true</code>
124      * <tr><td>{@link StartTagType#isNameAfterPrefixRequired() IsNameAfterPrefixRequired}<td><code>false</code>
125      * </table>
126      * <dt>Example:</dt>
127      * <dd><code>&lt;script language="php"&gt; echo '&lt;p&gt;Hello World&lt;/p&gt;'; &lt;/script&gt;</code></dd>
128      * </dl>
129      */

130     public static final StartTagType PHP_SCRIPT=StartTagTypePHPScript.INSTANCE;
131
132     private static final TagType[] TAG_TYPES={
133         PHP_STANDARD,
134         PHP_SHORT,
135         PHP_SCRIPT
136     };
137
138     private PHPTagTypes() {}
139
140     /**
141      * {@linkplain TagType#register() Registers} all of the tag types defined in this class at once.
142      * <p>
143      * The tag types must be registered before the parser will recognise them.
144      */

145     public static void register() {
146         for (int i=0; i<TAG_TYPES.length; i++) TAG_TYPES[i].register();
147     }
148     
149     /**
150      * Indicates whether the specified tag type is defined in this class.
151      *
152      * @param tagType the {@link TagType} to test.
153      * @return <code>true</code> if the specified tag type is defined in this class, otherwise <code>false</code>.
154      */

155     public static boolean defines(final TagType tagType) {
156         for (int i=0; i<TAG_TYPES.length; i++)
157             if (tagType==TAG_TYPES[i]) return true;
158         return false;
159     }
160     
161     /**
162      * Indicates whether the specified tag type is recognised by a <a target="_blank" HREF="http://www.php.net">PHP</a> parser.
163      * <p>
164      * This is true if the specified tag type is {@linkplain #defines(TagType) defined in this class} or if it is the
165      * {@linkplain StartTagType#SERVER_COMMON common server tag type}.
166      *
167      * @param tagType the {@link TagType} to test.
168      * @return <code>true</code> if the specified tag type is recognised by a <a target="_blank" HREF="http://www.php.net">PHP</a> parser, otherwise <code>false</code>.
169      */

170     public static boolean isParsedByPHP(final TagType tagType) {
171         return tagType==StartTagType.SERVER_COMMON || defines(tagType);
172     }
173 }
174
Popular Tags