KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > test > web > core > syntax > SyntaxUtils


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.test.web.core.syntax;
21
22 import java.io.PrintStream JavaDoc;
23 import org.netbeans.editor.TokenContext;
24 import org.netbeans.editor.TokenContextPath;
25
26 /** Syntax utils class.
27  *
28  * @author mf100882
29  */

30 public class SyntaxUtils {
31
32     /** Dumps token context names for given {@link org.netbeans.editor.TokenContextPath} */
33     public static void dumpTokenContextPath(TokenContextPath tcp, PrintStream JavaDoc out) {
34         TokenContext[] tcs = tcp.getContexts();
35         for(int i = 0; i < tcs.length; i++ ) {
36             String JavaDoc tcClassName = tcs[i].getClass().getName();
37             tcClassName = tcClassName.substring(tcClassName.lastIndexOf(".") + 1);
38             out.print(tcClassName + ( (i < (tcs.length - 1)) ? ", " : ""));
39         }
40     }
41     
42     /** converts \n to <NL> \t to <TAB> etc... */
43     public static String JavaDoc normalize(String JavaDoc s, String JavaDoc[][] translationTable) {
44         StringBuffer JavaDoc normalized = new StringBuffer JavaDoc();
45         for(int i = 0; i < s.length(); i++) {
46             String JavaDoc ch = s.substring(i,i+1);
47             for(int j = 0; j < normalizeTable.length; j++) {
48                 if(ch.equals(normalizeTable[j][0])) ch = normalizeTable[j][1];
49             }
50             normalized.append(ch);
51         }
52         return normalized.toString();
53     }
54     
55     /** the some as {@ling normalize(String s, String[][] translationTable)}
56      * but uses default translation table. */

57     public static String JavaDoc normalize(String JavaDoc s) {
58         return normalize(s, normalizeTable);
59     }
60     
61     public static final String JavaDoc[][] normalizeTable = {{"\n", "<NL>"},
62                                                       {"\t", "<TAB>"}};
63     
64 }
65
Popular Tags