KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > lowagie > text > html > HtmlTagMap


1 /*
2  * $Id: HtmlTagMap.java 2536 2007-01-19 14:17:01Z blowagie $
3  * $Name$
4  *
5  * Copyright 2001, 2002 by Bruno Lowagie.
6  *
7  * The contents of this file are subject to the Mozilla Public License Version 1.1
8  * (the "License"); you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the License.
14  *
15  * The Original Code is 'iText, a free JAVA-PDF library'.
16  *
17  * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
18  * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
19  * All Rights Reserved.
20  * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
21  * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
22  *
23  * Contributor(s): all the names of the contributors are added in the source code
24  * where applicable.
25  *
26  * Alternatively, the contents of this file may be used under the terms of the
27  * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
28  * provisions of LGPL are applicable instead of those above. If you wish to
29  * allow use of your version of this file only under the terms of the LGPL
30  * License and not to allow others to use your version of this file under
31  * the MPL, indicate your decision by deleting the provisions above and
32  * replace them with the notice and other provisions required by the LGPL.
33  * If you do not delete the provisions above, a recipient may use your version
34  * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
35  *
36  * This library is free software; you can redistribute it and/or modify it
37  * under the terms of the MPL as stated above or under the terms of the GNU
38  * Library General Public License as published by the Free Software Foundation;
39  * either version 2 of the License, or any later version.
40  *
41  * This library is distributed in the hope that it will be useful, but WITHOUT
42  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
43  * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
44  * details.
45  *
46  * If you didn't download this code from the following link, you should check if
47  * you aren't using an obsolete version:
48  * http://www.lowagie.com/iText/
49  */

50
51 package com.lowagie.text.html;
52
53 import java.util.HashMap JavaDoc;
54
55 import com.lowagie.text.ElementTags;
56 import com.lowagie.text.FontFactory;
57
58 /**
59  * The <CODE>Tags</CODE>-class maps several XHTML-tags to iText-objects.
60  */

61
62 public class HtmlTagMap extends HashMap JavaDoc {
63     
64 private static final long serialVersionUID = 5287430058473705350L;
65
66 /**
67  * Constructs an HtmlTagMap.
68  */

69     
70     public HtmlTagMap() {
71         super();
72         HtmlPeer peer;
73         
74         peer = new HtmlPeer(ElementTags.ITEXT, HtmlTags.HTML);
75         put(peer.getAlias(), peer);
76         
77         peer = new HtmlPeer(ElementTags.PHRASE, HtmlTags.SPAN);
78         put(peer.getAlias(), peer);
79         
80         peer = new HtmlPeer(ElementTags.CHUNK, HtmlTags.CHUNK);
81         peer.addAlias(ElementTags.FONT, HtmlTags.FONT);
82         peer.addAlias(ElementTags.SIZE, HtmlTags.SIZE);
83         peer.addAlias(ElementTags.COLOR, HtmlTags.COLOR);
84         put(peer.getAlias(), peer);
85         
86         peer = new HtmlPeer(ElementTags.ANCHOR, HtmlTags.ANCHOR);
87         peer.addAlias(ElementTags.NAME, HtmlTags.NAME);
88         peer.addAlias(ElementTags.REFERENCE, HtmlTags.REFERENCE);
89         put(peer.getAlias(), peer);
90         
91         peer = new HtmlPeer(ElementTags.PARAGRAPH, HtmlTags.PARAGRAPH);
92         peer.addAlias(ElementTags.ALIGN, HtmlTags.ALIGN);
93         put(peer.getAlias(), peer);
94         
95         peer = new HtmlPeer(ElementTags.PARAGRAPH, HtmlTags.DIV);
96         peer.addAlias(ElementTags.ALIGN, HtmlTags.ALIGN);
97         put(peer.getAlias(), peer);
98         
99         peer = new HtmlPeer(ElementTags.PARAGRAPH, HtmlTags.H[0]);
100         peer.addValue(ElementTags.SIZE, "20");
101         put(peer.getAlias(), peer);
102         
103         peer = new HtmlPeer(ElementTags.PARAGRAPH, HtmlTags.H[1]);
104         peer.addValue(ElementTags.SIZE, "18");
105         put(peer.getAlias(), peer);
106         
107         peer = new HtmlPeer(ElementTags.PARAGRAPH, HtmlTags.H[2]);
108         peer.addValue(ElementTags.SIZE, "16");
109         put(peer.getAlias(), peer);
110         
111         peer = new HtmlPeer(ElementTags.PARAGRAPH, HtmlTags.H[3]);
112         peer.addValue(ElementTags.SIZE, "14");
113         put(peer.getAlias(), peer);
114         
115         peer = new HtmlPeer(ElementTags.PARAGRAPH, HtmlTags.H[4]);
116         peer.addValue(ElementTags.SIZE, "12");
117         put(peer.getAlias(), peer);
118         
119         peer = new HtmlPeer(ElementTags.PARAGRAPH, HtmlTags.H[5]);
120         peer.addValue(ElementTags.SIZE, "10");
121         put(peer.getAlias(), peer);
122         
123         peer = new HtmlPeer(ElementTags.LIST, HtmlTags.ORDEREDLIST);
124         peer.addValue(ElementTags.NUMBERED, "true");
125         peer.addValue(ElementTags.SYMBOLINDENT, "20");
126         put(peer.getAlias(), peer);
127         
128         peer = new HtmlPeer(ElementTags.LIST, HtmlTags.UNORDEREDLIST);
129         peer.addValue(ElementTags.NUMBERED, "false");
130         peer.addValue(ElementTags.SYMBOLINDENT, "20");
131         put(peer.getAlias(), peer);
132         
133         peer = new HtmlPeer(ElementTags.LISTITEM, HtmlTags.LISTITEM);
134         put(peer.getAlias(), peer);
135         
136         peer = new HtmlPeer(ElementTags.PHRASE, HtmlTags.I);
137         peer.addValue(ElementTags.STYLE, Markup.CSS_VALUE_ITALIC);
138         put(peer.getAlias(), peer);
139         
140         peer = new HtmlPeer(ElementTags.PHRASE, HtmlTags.EM);
141         peer.addValue(ElementTags.STYLE, Markup.CSS_VALUE_ITALIC);
142         put(peer.getAlias(), peer);
143         
144         peer = new HtmlPeer(ElementTags.PHRASE, HtmlTags.B);
145         peer.addValue(ElementTags.STYLE, Markup.CSS_VALUE_BOLD);
146         put(peer.getAlias(), peer);
147         
148         peer = new HtmlPeer(ElementTags.PHRASE, HtmlTags.STRONG);
149         peer.addValue(ElementTags.STYLE, Markup.CSS_VALUE_BOLD);
150         put(peer.getAlias(), peer);
151         
152         peer = new HtmlPeer(ElementTags.PHRASE, HtmlTags.S);
153         peer.addValue(ElementTags.STYLE, Markup.CSS_VALUE_LINETHROUGH);
154         put(peer.getAlias(), peer);
155         
156         peer = new HtmlPeer(ElementTags.PHRASE, HtmlTags.CODE);
157         peer.addValue(ElementTags.FONT, FontFactory.COURIER);
158         put(peer.getAlias(), peer);
159         
160         peer = new HtmlPeer(ElementTags.PHRASE, HtmlTags.VAR);
161         peer.addValue(ElementTags.FONT, FontFactory.COURIER);
162         peer.addValue(ElementTags.STYLE, Markup.CSS_VALUE_ITALIC);
163         put(peer.getAlias(), peer);
164         
165         peer = new HtmlPeer(ElementTags.PHRASE, HtmlTags.U);
166         peer.addValue(ElementTags.STYLE, Markup.CSS_VALUE_UNDERLINE);
167         put(peer.getAlias(), peer);
168         
169         peer = new HtmlPeer(ElementTags.CHUNK, HtmlTags.SUP);
170         peer.addValue(ElementTags.SUBSUPSCRIPT, "6.0");
171         put(peer.getAlias(), peer);
172         
173         peer = new HtmlPeer(ElementTags.CHUNK, HtmlTags.SUB);
174         peer.addValue(ElementTags.SUBSUPSCRIPT, "-6.0");
175         put(peer.getAlias(), peer);
176         
177         peer = new HtmlPeer(ElementTags.HORIZONTALRULE, HtmlTags.HORIZONTALRULE);
178         put(peer.getAlias(), peer);
179         
180         peer = new HtmlPeer(ElementTags.TABLE, HtmlTags.TABLE);
181         peer.addAlias(ElementTags.WIDTH, HtmlTags.WIDTH);
182         peer.addAlias(ElementTags.BACKGROUNDCOLOR, HtmlTags.BACKGROUNDCOLOR);
183         peer.addAlias(ElementTags.BORDERCOLOR, HtmlTags.BORDERCOLOR);
184         peer.addAlias(ElementTags.COLUMNS, HtmlTags.COLUMNS);
185         peer.addAlias(ElementTags.CELLPADDING, HtmlTags.CELLPADDING);
186         peer.addAlias(ElementTags.CELLSPACING, HtmlTags.CELLSPACING);
187         peer.addAlias(ElementTags.BORDERWIDTH, HtmlTags.BORDERWIDTH);
188         peer.addAlias(ElementTags.ALIGN, HtmlTags.ALIGN);
189         put(peer.getAlias(), peer);
190         
191         peer = new HtmlPeer(ElementTags.ROW, HtmlTags.ROW);
192         put(peer.getAlias(), peer);
193         
194         peer = new HtmlPeer(ElementTags.CELL, HtmlTags.CELL);
195         peer.addAlias(ElementTags.WIDTH, HtmlTags.WIDTH);
196         peer.addAlias(ElementTags.BACKGROUNDCOLOR, HtmlTags.BACKGROUNDCOLOR);
197         peer.addAlias(ElementTags.BORDERCOLOR, HtmlTags.BORDERCOLOR);
198         peer.addAlias(ElementTags.COLSPAN, HtmlTags.COLSPAN);
199         peer.addAlias(ElementTags.ROWSPAN, HtmlTags.ROWSPAN);
200         peer.addAlias(ElementTags.NOWRAP, HtmlTags.NOWRAP);
201         peer.addAlias(ElementTags.HORIZONTALALIGN, HtmlTags.HORIZONTALALIGN);
202         peer.addAlias(ElementTags.VERTICALALIGN, HtmlTags.VERTICALALIGN);
203         peer.addValue(ElementTags.HEADER, "false");
204         put(peer.getAlias(), peer);
205         
206         peer = new HtmlPeer(ElementTags.CELL, HtmlTags.HEADERCELL);
207         peer.addAlias(ElementTags.WIDTH, HtmlTags.WIDTH);
208         peer.addAlias(ElementTags.BACKGROUNDCOLOR, HtmlTags.BACKGROUNDCOLOR);
209         peer.addAlias(ElementTags.BORDERCOLOR, HtmlTags.BORDERCOLOR);
210         peer.addAlias(ElementTags.COLSPAN, HtmlTags.COLSPAN);
211         peer.addAlias(ElementTags.ROWSPAN, HtmlTags.ROWSPAN);
212         peer.addAlias(ElementTags.NOWRAP, HtmlTags.NOWRAP);
213         peer.addAlias(ElementTags.HORIZONTALALIGN, HtmlTags.HORIZONTALALIGN);
214         peer.addAlias(ElementTags.VERTICALALIGN, HtmlTags.VERTICALALIGN);
215         peer.addValue(ElementTags.HEADER, "true");
216         put(peer.getAlias(), peer);
217         
218         peer = new HtmlPeer(ElementTags.IMAGE, HtmlTags.IMAGE);
219         peer.addAlias(ElementTags.URL, HtmlTags.URL);
220         peer.addAlias(ElementTags.ALT, HtmlTags.ALT);
221         peer.addAlias(ElementTags.PLAINWIDTH, HtmlTags.PLAINWIDTH);
222         peer.addAlias(ElementTags.PLAINHEIGHT, HtmlTags.PLAINHEIGHT);
223         put(peer.getAlias(), peer);
224         
225         peer = new HtmlPeer(ElementTags.NEWLINE, HtmlTags.NEWLINE);
226         put(peer.getAlias(), peer);
227     }
228     
229 /**
230  * Checks if this is the root tag.
231  * @param tag a tagvalue
232  * @return true if tag is HTML or html
233  */

234     
235     public boolean isHtml(String JavaDoc tag) {
236         return HtmlTags.HTML.equalsIgnoreCase(tag);
237     }
238     
239 /**
240  * Checks if this is the head tag.
241  * @param tag a tagvalue
242  * @return true if tag is HEAD or head
243  */

244     
245     public boolean isHead(String JavaDoc tag) {
246         return HtmlTags.HEAD.equalsIgnoreCase(tag);
247     }
248     
249 /**
250  * Checks if this is the meta tag.
251  * @param tag a tagvalue
252  * @return true if tag is META or meta
253  */

254     
255     public boolean isMeta(String JavaDoc tag) {
256         return HtmlTags.META.equalsIgnoreCase(tag);
257     }
258     
259 /**
260  * Checks if this is the linl tag.
261  * @param tag a tagvalue
262  * @return true if tag is LINK or link
263  */

264     
265     public boolean isLink(String JavaDoc tag) {
266         return HtmlTags.LINK.equalsIgnoreCase(tag);
267     }
268     
269 /**
270  * Checks if this is the title tag.
271  * @param tag a tagvalue
272  * @return true if tag is TITLE or title
273  */

274     
275     public boolean isTitle(String JavaDoc tag) {
276         return HtmlTags.TITLE.equalsIgnoreCase(tag);
277     }
278     
279 /**
280  * Checks if this is the root tag.
281  * @param tag a tagvalue
282  * @return true if tag is BODY or body
283  */

284     
285     public boolean isBody(String JavaDoc tag) {
286         return HtmlTags.BODY.equalsIgnoreCase(tag);
287     }
288     
289 /**
290  * Checks if this is a special tag.
291  * @param tag a tagvalue
292  * @return true if tag is a HTML, HEAD, META, LINK or BODY tag (case insensitive)
293  */

294     public boolean isSpecialTag(String JavaDoc tag) {
295         return isHtml(tag) || isHead(tag) || isMeta(tag) || isLink(tag) || isBody(tag);
296     }
297 }
Popular Tags