KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > text > comment > Java2HTMLEntityReader


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.ui.text.comment;
12
13 import java.io.Reader JavaDoc;
14 import java.util.HashMap JavaDoc;
15 import java.util.Map JavaDoc;
16 import org.eclipse.jdt.internal.ui.text.SubstitutionTextReader;
17
18
19 /**
20  * <code>SubstitutionTextReader</code> that will substitute html entities for
21  * html symbols encountered in the original text. Line breaks and whitespaces
22  * are preserved.
23  *
24  * @since 3.0
25  */

26 public class Java2HTMLEntityReader extends SubstitutionTextReader {
27
28     /** The hardcoded entity map. */
29     private static final Map JavaDoc fgEntityLookup;
30     
31     static {
32         fgEntityLookup= new HashMap JavaDoc(7);
33         fgEntityLookup.put("<", "&lt;"); //$NON-NLS-1$ //$NON-NLS-2$
34
fgEntityLookup.put(">", "&gt;"); //$NON-NLS-1$ //$NON-NLS-2$
35
fgEntityLookup.put("&", "&amp;"); //$NON-NLS-1$ //$NON-NLS-2$
36
fgEntityLookup.put("^", "&circ;"); //$NON-NLS-1$ //$NON-NLS-2$
37
fgEntityLookup.put("~", "&tilde;"); //$NON-NLS-2$ //$NON-NLS-1$
38
fgEntityLookup.put("\"", "&quot;"); //$NON-NLS-1$ //$NON-NLS-2$
39
}
40
41     /**
42      * Creates a new instance that will read from <code>reader</code>
43      *
44      * @param reader the source reader
45      */

46     public Java2HTMLEntityReader(Reader JavaDoc reader) {
47         super(reader);
48         setSkipWhitespace(false);
49     }
50
51     /*
52      * @see org.eclipse.jdt.internal.ui.text.SubstitutionTextReader#computeSubstitution(int)
53      */

54     protected String JavaDoc computeSubstitution(int c) {
55         String JavaDoc lookup= (String JavaDoc) fgEntityLookup.get(String.valueOf((char) c));
56         return lookup;
57     }
58 }
59
Popular Tags