/[aagtl_public1]/src/net/htmlparser/jericho/PHPTagTypes.java
aagtl

Contents of /src/net/htmlparser/jericho/PHPTagTypes.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (show annotations) (download)
Sun Aug 5 13:48:36 2012 UTC (11 years, 7 months ago) by zoffadmin
File size: 9204 byte(s)
initial import of aagtl source code
1 // Jericho HTML Parser - Java based library for analysing and manipulating HTML
2 // Version 3.2
3 // Copyright (C) 2004-2009 Martin Jericho
4 // http://jericho.htmlparser.net/
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of either one of the following licences:
8 //
9 // 1. The Eclipse Public License (EPL) version 1.0,
10 // included in this distribution in the file licence-epl-1.0.html
11 // or available at http://www.eclipse.org/legal/epl-v10.html
12 //
13 // 2. The GNU Lesser General Public License (LGPL) version 2.1 or later,
14 // included in this distribution in the file licence-lgpl-2.1.txt
15 // or available at http://www.gnu.org/licenses/lgpl.txt
16 //
17 // This library is distributed on an "AS IS" basis,
18 // WITHOUT WARRANTY OF ANY KIND, either express or implied.
19 // See the individual licence texts for more details.
20
21 package net.htmlparser.jericho;
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<var> &#46;&#46;&#46; </var>&#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;<var> &#46;&#46;&#46; </var>&#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;<var> &#46;&#46;&#46; </var>&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 (TagType tagType : TAG_TYPES) tagType.register();
147 }
148
149 /**
150 * {@linkplain TagType#deregister() Deregisters} all of the tag types defined in this class at once.
151 */
152 public static void deregister() {
153 for (TagType tagType : TAG_TYPES) tagType.deregister();
154 }
155
156 /**
157 * Indicates whether the specified tag type is defined in this class.
158 *
159 * @param tagType the {@link TagType} to test.
160 * @return <code>true</code> if the specified tag type is defined in this class, otherwise <code>false</code>.
161 */
162 public static boolean defines(final TagType tagType) {
163 for (TagType definedTagType : TAG_TYPES) if (tagType==definedTagType) return true;
164 return false;
165 }
166
167 /**
168 * Indicates whether the specified tag type is recognised by a <a target="_blank" href="http://www.php.net">PHP</a> parser.
169 * <p>
170 * This is true if the specified tag type is {@linkplain #defines(TagType) defined in this class} or if it is the
171 * {@linkplain StartTagType#SERVER_COMMON common server tag type}.
172 *
173 * @param tagType the {@link TagType} to test.
174 * @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>.
175 */
176 public static boolean isParsedByPHP(final TagType tagType) {
177 return tagType==StartTagType.SERVER_COMMON || defines(tagType);
178 }
179 }

   
Visit the aagtl Website