1 16 19 20 package org.apache.xalan.xsltc.compiler.util; 21 22 import java.util.StringTokenizer ; 23 24 import org.apache.bcel.generic.Type; 25 import org.apache.xalan.xsltc.compiler.Constants; 26 import org.apache.xml.utils.XMLChar; 27 28 32 public final class Util { 33 private static char filesep; 34 35 static { 36 String temp = System.getProperty("file.separator", "/"); 37 filesep = temp.charAt(0); 38 } 39 40 public static String noExtName(String name) { 41 final int index = name.lastIndexOf('.'); 42 return name.substring(0, index >= 0 ? index : name.length()); 43 } 44 45 49 public static String baseName(String name) { 50 int index = name.lastIndexOf('\\'); 51 if (index < 0) { 52 index = name.lastIndexOf('/'); 53 } 54 55 if (index >= 0) 56 return name.substring(index + 1); 57 else { 58 int lastColonIndex = name.lastIndexOf(':'); 59 if (lastColonIndex > 0) 60 return name.substring(lastColonIndex + 1); 61 else 62 return name; 63 } 64 } 65 66 70 public static String pathName(String name) { 71 int index = name.lastIndexOf('/'); 72 if (index < 0) { 73 index = name.lastIndexOf('\\'); 74 } 75 return name.substring(0, index + 1); 76 } 77 78 81 public static String toJavaName(String name) { 82 if (name.length() > 0) { 83 final StringBuffer result = new StringBuffer (); 84 85 char ch = name.charAt(0); 86 result.append(Character.isJavaIdentifierStart(ch) ? ch : '_'); 87 88 final int n = name.length(); 89 for (int i = 1; i < n; i++) { 90 ch = name.charAt(i); 91 result.append(Character.isJavaIdentifierPart(ch) ? ch : '_'); 92 } 93 return result.toString(); 94 } 95 return name; 96 } 97 98 public static Type getJCRefType(String signature) { 99 return Type.getType(signature); 100 } 101 102 public static String internalName(String cname) { 103 return cname.replace('.', filesep); 104 } 105 106 public static void println(String s) { 107 System.out.println(s); 108 } 109 110 public static void println(char ch) { 111 System.out.println(ch); 112 } 113 114 public static void TRACE1() { 115 System.out.println("TRACE1"); 116 } 117 118 public static void TRACE2() { 119 System.out.println("TRACE2"); 120 } 121 122 public static void TRACE3() { 123 System.out.println("TRACE3"); 124 } 125 126 129 public static String replace(String base, char ch, String str) { 130 return (base.indexOf(ch) < 0) ? base : 131 replace(base, String.valueOf(ch), new String [] { str }); 132 } 133 134 public static String replace(String base, String delim, String [] str) { 135 final int len = base.length(); 136 final StringBuffer result = new StringBuffer (); 137 138 for (int i = 0; i < len; i++) { 139 final char ch = base.charAt(i); 140 final int k = delim.indexOf(ch); 141 142 if (k >= 0) { 143 result.append(str[k]); 144 } 145 else { 146 result.append(ch); 147 } 148 } 149 return result.toString(); 150 } 151 152 155 public static String escape(String input) { 156 return replace(input, ".-/:", 157 new String [] { "$dot$", "$dash$", "$slash$", "$colon$" }); 158 } 159 160 public static String getLocalName(String qname) { 161 final int index = qname.lastIndexOf(":"); 162 return (index > 0) ? qname.substring(index + 1) : qname; 163 } 164 165 public static String getPrefix(String qname) { 166 final int index = qname.lastIndexOf(":"); 167 return (index > 0) ? qname.substring(0, index) : 168 Constants.EMPTYSTRING; 169 } 170 171 174 public static boolean isLiteral(String str) { 175 final int length = str.length(); 176 for (int i = 0; i < length - 1; i++) { 177 if (str.charAt(i) == '{' && str.charAt(i + 1) != '{') { 178 return false; 179 } 180 } 181 return true; 182 } 183 184 187 public static boolean isValidQNames(String str) { 188 if ((str != null) && (!str.equals(Constants.EMPTYSTRING))) { 189 final StringTokenizer tokens = new StringTokenizer (str); 190 while (tokens.hasMoreTokens()) { 191 if (!XMLChar.isValidQName(tokens.nextToken())) { 192 return false; 193 } 194 } 195 } 196 return true; 197 } 198 199 } 200 201 | Popular Tags |