public static String[] parseTokenizedString(String string2BeParsed, String demiliter) { StringTokenizer tokenizer = new StringTokenizer(string2BeParsed, demiliter); String[] choices = new String[tokenizer.countTokens()]; int index = 0; // each token is the display name for the column while (tokenizer.hasMoreTokens()) { choices[index] = tokenizer.nextToken(); index++; } return choices; }
/** Create the relationship of Java key to properties key */ private HashMap createMapping() { mapping = new HashMap(); try { String line; BufferedReader in = new BufferedReader(new FileReader(dir + javaFileName)); while ((line = in.readLine()) != null) { StringTokenizer tokenizer = new StringTokenizer(line); int numberOfTokens = tokenizer.countTokens(); if (numberOfTokens > 5) { String firstToken = tokenizer.nextToken(); String secondToken = tokenizer.nextToken(); tokenizer.nextToken(); tokenizer.nextToken(); String key = tokenizer.nextToken(); String value = tokenizer.nextToken(); if (firstToken.equals(PUBLIC) && secondToken.equals(STATIC)) { if (numberOfTokens == 6) { // handle "=" with key and value both in one token because there was no space before // the equal sign int offset = key.indexOf('='); String key1 = key.substring(0, offset); String key2 = key.substring(offset + 2, key.length() - 2); mapping.put(key2, key1); } else if (numberOfTokens == 7) { // handle " =" and "= " with key and value both in different tokens if (value.charAt(0) == '=') { value = value.substring(2, value.length() - 2); } else { key = key.substring(0, key.length() - 1); } mapping.put(value, key); } else if (numberOfTokens == 8) { // handle " = " with key and value both in different tokens value = tokenizer.nextToken(); value = value.substring(1, value.length() - 2); mapping.put(value, key); } else { System.out.println(key + " - I do not understand this line!!!"); } } } } } catch (IOException e) { e.printStackTrace(); } return mapping; }
private void createClassFile() { try { String line; BufferedReader in = new BufferedReader(new FileReader(dir + javaFileName)); while ((line = in.readLine()) != null) { line = removeEverythingAfterEquals( line); // This handles the case where there is no space before the equal sign StringTokenizer tokenizer = new StringTokenizer(line); if (tokenizer.countTokens() > 1) { String firstToken = tokenizer.nextToken(); String secondToken = tokenizer.nextToken(); if (firstToken.equals(PACKAGE)) { System.out.println(line); System.out.println(); createNLSImportStatement(); System.out.println(); } else if (firstToken.equals(PUBLIC) && secondToken.equals(INTERFACE)) { String className = tokenizer.nextToken(); System.out.println(); createClassSignature(className); System.out.println(); createBundleNameDeclaration(); System.out.println(); createClassConstructor(className); System.out.println(); createStaticInitializer(className); } else { if (firstToken.equals(PUBLIC) && secondToken.equals(STATIC)) createStaticDeclaration(tokenizer); else System.out.println(line); // not interested in this line, no changes } } else System.out.println(line); // not interested in this line, no changes } } catch (IOException e) { e.printStackTrace(); } }