1 | /* | |
2 | * $Id: HtmlTagMap.java 3528 2008-07-07 14:46:09Z Howard_s $ | |
3 | * | |
4 | * Copyright 2001, 2002 by Bruno Lowagie. | |
5 | * | |
6 | * The contents of this file are subject to the Mozilla Public License Version 1.1 | |
7 | * (the "License"); you may not use this file except in compliance with the License. | |
8 | * You may obtain a copy of the License at http://www.mozilla.org/MPL/ | |
9 | * | |
10 | * Software distributed under the License is distributed on an "AS IS" basis, | |
11 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | |
12 | * for the specific language governing rights and limitations under the License. | |
13 | * | |
14 | * The Original Code is 'iText, a free JAVA-PDF library'. | |
15 | * | |
16 | * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by | |
17 | * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie. | |
18 | * All Rights Reserved. | |
19 | * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer | |
20 | * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved. | |
21 | * | |
22 | * Contributor(s): all the names of the contributors are added in the source code | |
23 | * where applicable. | |
24 | * | |
25 | * Alternatively, the contents of this file may be used under the terms of the | |
26 | * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the | |
27 | * provisions of LGPL are applicable instead of those above. If you wish to | |
28 | * allow use of your version of this file only under the terms of the LGPL | |
29 | * License and not to allow others to use your version of this file under | |
30 | * the MPL, indicate your decision by deleting the provisions above and | |
31 | * replace them with the notice and other provisions required by the LGPL. | |
32 | * If you do not delete the provisions above, a recipient may use your version | |
33 | * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE. | |
34 | * | |
35 | * This library is free software; you can redistribute it and/or modify it | |
36 | * under the terms of the MPL as stated above or under the terms of the GNU | |
37 | * Library General Public License as published by the Free Software Foundation; | |
38 | * either version 2 of the License, or any later version. | |
39 | * | |
40 | * This library is distributed in the hope that it will be useful, but WITHOUT | |
41 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
42 | * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more | |
43 | * details. | |
44 | * | |
45 | * Contributions by: | |
46 | * Lubos Strapko | |
47 | * | |
48 | * If you didn't download this code from the following link, you should check if | |
49 | * you aren't using an obsolete version: | |
50 | * http://www.lowagie.com/iText/ | |
51 | */ | |
52 | ||
53 | package com.lowagie.text.html; | |
54 | ||
55 | import java.util.HashMap; | |
56 | ||
57 | import com.lowagie.text.ElementTags; | |
58 | import com.lowagie.text.FontFactory; | |
59 | ||
60 | /** | |
61 | * The <CODE>Tags</CODE>-class maps several XHTML-tags to iText-objects. | |
62 | */ | |
63 | ||
64 | public class HtmlTagMap extends HashMap { | |
65 | ||
66 | private static final long serialVersionUID = 5287430058473705350L; | |
67 | ||
68 | /** | |
69 | * Constructs an HtmlTagMap. | |
70 | */ | |
71 | ||
72 | public HtmlTagMap() { | |
73 | super(); | |
74 | HtmlPeer peer; | |
75 | ||
76 | peer = new HtmlPeer(ElementTags.ITEXT, HtmlTags.HTML); | |
77 | put(peer.getAlias(), peer); | |
78 | ||
79 | peer = new HtmlPeer(ElementTags.PHRASE, HtmlTags.SPAN); | |
80 | put(peer.getAlias(), peer); | |
81 | ||
82 | peer = new HtmlPeer(ElementTags.CHUNK, HtmlTags.CHUNK); | |
83 |
1
1. |
peer.addAlias(ElementTags.FONT, HtmlTags.FONT); |
84 |
1
1. |
peer.addAlias(ElementTags.SIZE, HtmlTags.SIZE); |
85 |
1
1. |
peer.addAlias(ElementTags.COLOR, HtmlTags.COLOR); |
86 | put(peer.getAlias(), peer); | |
87 | ||
88 | peer = new HtmlPeer(ElementTags.ANCHOR, HtmlTags.ANCHOR); | |
89 |
1
1. |
peer.addAlias(ElementTags.NAME, HtmlTags.NAME); |
90 |
1
1. |
peer.addAlias(ElementTags.REFERENCE, HtmlTags.REFERENCE); |
91 | put(peer.getAlias(), peer); | |
92 | ||
93 | peer = new HtmlPeer(ElementTags.PARAGRAPH, HtmlTags.PARAGRAPH); | |
94 |
1
1. |
peer.addAlias(ElementTags.ALIGN, HtmlTags.ALIGN); |
95 | put(peer.getAlias(), peer); | |
96 | ||
97 | peer = new HtmlPeer(ElementTags.PARAGRAPH, HtmlTags.DIV); | |
98 |
1
1. |
peer.addAlias(ElementTags.ALIGN, HtmlTags.ALIGN); |
99 | put(peer.getAlias(), peer); | |
100 | ||
101 | peer = new HtmlPeer(ElementTags.PARAGRAPH, HtmlTags.H[0]); | |
102 |
1
1. |
peer.addValue(ElementTags.SIZE, "20"); |
103 | put(peer.getAlias(), peer); | |
104 | ||
105 | peer = new HtmlPeer(ElementTags.PARAGRAPH, HtmlTags.H[1]); | |
106 |
1
1. |
peer.addValue(ElementTags.SIZE, "18"); |
107 | put(peer.getAlias(), peer); | |
108 | ||
109 | peer = new HtmlPeer(ElementTags.PARAGRAPH, HtmlTags.H[2]); | |
110 |
1
1. |
peer.addValue(ElementTags.SIZE, "16"); |
111 | put(peer.getAlias(), peer); | |
112 | ||
113 | peer = new HtmlPeer(ElementTags.PARAGRAPH, HtmlTags.H[3]); | |
114 |
1
1. |
peer.addValue(ElementTags.SIZE, "14"); |
115 | put(peer.getAlias(), peer); | |
116 | ||
117 | peer = new HtmlPeer(ElementTags.PARAGRAPH, HtmlTags.H[4]); | |
118 |
1
1. |
peer.addValue(ElementTags.SIZE, "12"); |
119 | put(peer.getAlias(), peer); | |
120 | ||
121 | peer = new HtmlPeer(ElementTags.PARAGRAPH, HtmlTags.H[5]); | |
122 |
1
1. |
peer.addValue(ElementTags.SIZE, "10"); |
123 | put(peer.getAlias(), peer); | |
124 | ||
125 | peer = new HtmlPeer(ElementTags.LIST, HtmlTags.ORDEREDLIST); | |
126 |
1
1. |
peer.addValue(ElementTags.NUMBERED, "true"); |
127 |
1
1. |
peer.addValue(ElementTags.SYMBOLINDENT, "20"); |
128 | put(peer.getAlias(), peer); | |
129 | ||
130 | peer = new HtmlPeer(ElementTags.LIST, HtmlTags.UNORDEREDLIST); | |
131 |
1
1. |
peer.addValue(ElementTags.NUMBERED, "false"); |
132 |
1
1. |
peer.addValue(ElementTags.SYMBOLINDENT, "20"); |
133 | put(peer.getAlias(), peer); | |
134 | ||
135 | peer = new HtmlPeer(ElementTags.LISTITEM, HtmlTags.LISTITEM); | |
136 | put(peer.getAlias(), peer); | |
137 | ||
138 | peer = new HtmlPeer(ElementTags.PHRASE, HtmlTags.I); | |
139 |
1
1. |
peer.addValue(ElementTags.STYLE, Markup.CSS_VALUE_ITALIC); |
140 | put(peer.getAlias(), peer); | |
141 | ||
142 | peer = new HtmlPeer(ElementTags.PHRASE, HtmlTags.EM); | |
143 |
1
1. |
peer.addValue(ElementTags.STYLE, Markup.CSS_VALUE_ITALIC); |
144 | put(peer.getAlias(), peer); | |
145 | ||
146 | peer = new HtmlPeer(ElementTags.PHRASE, HtmlTags.B); | |
147 |
1
1. |
peer.addValue(ElementTags.STYLE, Markup.CSS_VALUE_BOLD); |
148 | put(peer.getAlias(), peer); | |
149 | ||
150 | peer = new HtmlPeer(ElementTags.PHRASE, HtmlTags.STRONG); | |
151 |
1
1. |
peer.addValue(ElementTags.STYLE, Markup.CSS_VALUE_BOLD); |
152 | put(peer.getAlias(), peer); | |
153 | ||
154 | peer = new HtmlPeer(ElementTags.PHRASE, HtmlTags.S); | |
155 |
1
1. |
peer.addValue(ElementTags.STYLE, Markup.CSS_VALUE_LINETHROUGH); |
156 | put(peer.getAlias(), peer); | |
157 | ||
158 | peer = new HtmlPeer(ElementTags.PHRASE, HtmlTags.CODE); | |
159 |
1
1. |
peer.addValue(ElementTags.FONT, FontFactory.COURIER); |
160 | put(peer.getAlias(), peer); | |
161 | ||
162 | peer = new HtmlPeer(ElementTags.PHRASE, HtmlTags.VAR); | |
163 |
1
1. |
peer.addValue(ElementTags.FONT, FontFactory.COURIER); |
164 |
1
1. |
peer.addValue(ElementTags.STYLE, Markup.CSS_VALUE_ITALIC); |
165 | put(peer.getAlias(), peer); | |
166 | ||
167 | peer = new HtmlPeer(ElementTags.PHRASE, HtmlTags.U); | |
168 |
1
1. |
peer.addValue(ElementTags.STYLE, Markup.CSS_VALUE_UNDERLINE); |
169 | put(peer.getAlias(), peer); | |
170 | ||
171 | peer = new HtmlPeer(ElementTags.CHUNK, HtmlTags.SUP); | |
172 |
1
1. |
peer.addValue(ElementTags.SUBSUPSCRIPT, "6.0"); |
173 | put(peer.getAlias(), peer); | |
174 | ||
175 | peer = new HtmlPeer(ElementTags.CHUNK, HtmlTags.SUB); | |
176 |
1
1. |
peer.addValue(ElementTags.SUBSUPSCRIPT, "-6.0"); |
177 | put(peer.getAlias(), peer); | |
178 | ||
179 | peer = new HtmlPeer(ElementTags.HORIZONTALRULE, HtmlTags.HORIZONTALRULE); | |
180 | put(peer.getAlias(), peer); | |
181 | ||
182 | peer = new HtmlPeer(ElementTags.TABLE, HtmlTags.TABLE); | |
183 |
1
1. |
peer.addAlias(ElementTags.WIDTH, HtmlTags.WIDTH); |
184 |
1
1. |
peer.addAlias(ElementTags.BACKGROUNDCOLOR, HtmlTags.BACKGROUNDCOLOR); |
185 |
1
1. |
peer.addAlias(ElementTags.BORDERCOLOR, HtmlTags.BORDERCOLOR); |
186 |
1
1. |
peer.addAlias(ElementTags.COLUMNS, HtmlTags.COLUMNS); |
187 |
1
1. |
peer.addAlias(ElementTags.CELLPADDING, HtmlTags.CELLPADDING); |
188 |
1
1. |
peer.addAlias(ElementTags.CELLSPACING, HtmlTags.CELLSPACING); |
189 |
1
1. |
peer.addAlias(ElementTags.BORDERWIDTH, HtmlTags.BORDERWIDTH); |
190 |
1
1. |
peer.addAlias(ElementTags.ALIGN, HtmlTags.ALIGN); |
191 | put(peer.getAlias(), peer); | |
192 | ||
193 | peer = new HtmlPeer(ElementTags.ROW, HtmlTags.ROW); | |
194 | put(peer.getAlias(), peer); | |
195 | ||
196 | peer = new HtmlPeer(ElementTags.CELL, HtmlTags.CELL); | |
197 |
1
1. |
peer.addAlias(ElementTags.WIDTH, HtmlTags.WIDTH); |
198 |
1
1. |
peer.addAlias(ElementTags.BACKGROUNDCOLOR, HtmlTags.BACKGROUNDCOLOR); |
199 |
1
1. |
peer.addAlias(ElementTags.BORDERCOLOR, HtmlTags.BORDERCOLOR); |
200 |
1
1. |
peer.addAlias(ElementTags.COLSPAN, HtmlTags.COLSPAN); |
201 |
1
1. |
peer.addAlias(ElementTags.ROWSPAN, HtmlTags.ROWSPAN); |
202 |
1
1. |
peer.addAlias(ElementTags.NOWRAP, HtmlTags.NOWRAP); |
203 |
1
1. |
peer.addAlias(ElementTags.HORIZONTALALIGN, HtmlTags.HORIZONTALALIGN); |
204 |
1
1. |
peer.addAlias(ElementTags.VERTICALALIGN, HtmlTags.VERTICALALIGN); |
205 |
1
1. |
peer.addValue(ElementTags.HEADER, "false"); |
206 | put(peer.getAlias(), peer); | |
207 | ||
208 | peer = new HtmlPeer(ElementTags.CELL, HtmlTags.HEADERCELL); | |
209 |
1
1. |
peer.addAlias(ElementTags.WIDTH, HtmlTags.WIDTH); |
210 |
1
1. |
peer.addAlias(ElementTags.BACKGROUNDCOLOR, HtmlTags.BACKGROUNDCOLOR); |
211 |
1
1. |
peer.addAlias(ElementTags.BORDERCOLOR, HtmlTags.BORDERCOLOR); |
212 |
1
1. |
peer.addAlias(ElementTags.COLSPAN, HtmlTags.COLSPAN); |
213 |
1
1. |
peer.addAlias(ElementTags.ROWSPAN, HtmlTags.ROWSPAN); |
214 |
1
1. |
peer.addAlias(ElementTags.NOWRAP, HtmlTags.NOWRAP); |
215 |
1
1. |
peer.addAlias(ElementTags.HORIZONTALALIGN, HtmlTags.HORIZONTALALIGN); |
216 |
1
1. |
peer.addAlias(ElementTags.VERTICALALIGN, HtmlTags.VERTICALALIGN); |
217 |
1
1. |
peer.addValue(ElementTags.HEADER, "true"); |
218 | put(peer.getAlias(), peer); | |
219 | ||
220 | peer = new HtmlPeer(ElementTags.IMAGE, HtmlTags.IMAGE); | |
221 | // peer.addAlias(ElementTags.URL, HtmlTags.URL); | |
222 |
1
1. |
peer.addAlias(ElementTags.URL, ElementTags.SRC); // contributed by Lubos Strapko |
223 | ||
224 |
1
1. |
peer.addAlias(ElementTags.ALT, HtmlTags.ALT); |
225 |
1
1. |
peer.addAlias(ElementTags.PLAINWIDTH, HtmlTags.PLAINWIDTH); |
226 |
1
1. |
peer.addAlias(ElementTags.PLAINHEIGHT, HtmlTags.PLAINHEIGHT); |
227 | put(peer.getAlias(), peer); | |
228 | ||
229 | peer = new HtmlPeer(ElementTags.NEWLINE, HtmlTags.NEWLINE); | |
230 | put(peer.getAlias(), peer); | |
231 | } | |
232 | ||
233 | /** | |
234 | * Checks if this is the root tag. | |
235 | * @param tag a tagvalue | |
236 | * @return true if tag is HTML or html | |
237 | */ | |
238 | ||
239 | public static boolean isHtml(String tag) { | |
240 |
1
1. isHtml : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return HtmlTags.HTML.equalsIgnoreCase(tag); |
241 | } | |
242 | ||
243 | /** | |
244 | * Checks if this is the head tag. | |
245 | * @param tag a tagvalue | |
246 | * @return true if tag is HEAD or head | |
247 | */ | |
248 | ||
249 | public static boolean isHead(String tag) { | |
250 |
1
1. isHead : replaced return of integer sized value with (x == 0 ? 1 : 0) → SURVIVED |
return HtmlTags.HEAD.equalsIgnoreCase(tag); |
251 | } | |
252 | ||
253 | /** | |
254 | * Checks if this is the meta tag. | |
255 | * @param tag a tagvalue | |
256 | * @return true if tag is META or meta | |
257 | */ | |
258 | ||
259 | public static boolean isMeta(String tag) { | |
260 |
1
1. isMeta : replaced return of integer sized value with (x == 0 ? 1 : 0) → SURVIVED |
return HtmlTags.META.equalsIgnoreCase(tag); |
261 | } | |
262 | ||
263 | /** | |
264 | * Checks if this is the link tag. | |
265 | * @param tag a tagvalue | |
266 | * @return true if tag is LINK or link | |
267 | */ | |
268 | ||
269 | public static boolean isLink(String tag) { | |
270 |
1
1. isLink : replaced return of integer sized value with (x == 0 ? 1 : 0) → SURVIVED |
return HtmlTags.LINK.equalsIgnoreCase(tag); |
271 | } | |
272 | ||
273 | /** | |
274 | * Checks if this is the title tag. | |
275 | * @param tag a tagvalue | |
276 | * @return true if tag is TITLE or title | |
277 | */ | |
278 | ||
279 | public static boolean isTitle(String tag) { | |
280 |
1
1. isTitle : replaced return of integer sized value with (x == 0 ? 1 : 0) → SURVIVED |
return HtmlTags.TITLE.equalsIgnoreCase(tag); |
281 | } | |
282 | ||
283 | /** | |
284 | * Checks if this is the root tag. | |
285 | * @param tag a tagvalue | |
286 | * @return true if tag is BODY or body | |
287 | */ | |
288 | ||
289 | public static boolean isBody(String tag) { | |
290 |
1
1. isBody : replaced return of integer sized value with (x == 0 ? 1 : 0) → SURVIVED |
return HtmlTags.BODY.equalsIgnoreCase(tag); |
291 | } | |
292 | ||
293 | /** | |
294 | * Checks if this is a special tag. | |
295 | * @param tag a tagvalue | |
296 | * @return true if tag is a HTML, HEAD, META, LINK or BODY tag (case insensitive) | |
297 | */ | |
298 | public static boolean isSpecialTag(String tag) { | |
299 |
5
1. isSpecialTag : negated conditional → NO_COVERAGE 2. isSpecialTag : negated conditional → NO_COVERAGE 3. isSpecialTag : negated conditional → NO_COVERAGE 4. isSpecialTag : negated conditional → NO_COVERAGE 5. isSpecialTag : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return isHtml(tag) || isHead(tag) || isMeta(tag) || isLink(tag) |
300 |
1
1. isSpecialTag : negated conditional → NO_COVERAGE |
|| isBody(tag); |
301 | } | |
302 | } | |
Mutations | ||
83 |
1.1 |
|
84 |
1.1 |
|
85 |
1.1 |
|
89 |
1.1 |
|
90 |
1.1 |
|
94 |
1.1 |
|
98 |
1.1 |
|
102 |
1.1 |
|
106 |
1.1 |
|
110 |
1.1 |
|
114 |
1.1 |
|
118 |
1.1 |
|
122 |
1.1 |
|
126 |
1.1 |
|
127 |
1.1 |
|
131 |
1.1 |
|
132 |
1.1 |
|
139 |
1.1 |
|
143 |
1.1 |
|
147 |
1.1 |
|
151 |
1.1 |
|
155 |
1.1 |
|
159 |
1.1 |
|
163 |
1.1 |
|
164 |
1.1 |
|
168 |
1.1 |
|
172 |
1.1 |
|
176 |
1.1 |
|
183 |
1.1 |
|
184 |
1.1 |
|
185 |
1.1 |
|
186 |
1.1 |
|
187 |
1.1 |
|
188 |
1.1 |
|
189 |
1.1 |
|
190 |
1.1 |
|
197 |
1.1 |
|
198 |
1.1 |
|
199 |
1.1 |
|
200 |
1.1 |
|
201 |
1.1 |
|
202 |
1.1 |
|
203 |
1.1 |
|
204 |
1.1 |
|
205 |
1.1 |
|
209 |
1.1 |
|
210 |
1.1 |
|
211 |
1.1 |
|
212 |
1.1 |
|
213 |
1.1 |
|
214 |
1.1 |
|
215 |
1.1 |
|
216 |
1.1 |
|
217 |
1.1 |
|
222 |
1.1 |
|
224 |
1.1 |
|
225 |
1.1 |
|
226 |
1.1 |
|
240 |
1.1 |
|
250 |
1.1 |
|
260 |
1.1 |
|
270 |
1.1 |
|
280 |
1.1 |
|
290 |
1.1 |
|
299 |
1.1 2.2 3.3 4.4 5.5 |
|
300 |
1.1 |