1 18 19 package org.netbeans.modules.changelog; 20 21 22 import java.util.*; 23 import org.openide.*; 24 import java.io.*; 25 26 27 31 public class ChangeLogUtils { 32 33 36 public static int[] convertRevisionToIntArray(String revision) { 37 StringTokenizer token = new StringTokenizer(revision, "."); 38 int[] array = new int[token.countTokens()]; 39 int index = 0; 40 while (token.hasMoreTokens()) { 41 String item = token.nextToken(); 42 try { 43 int parsedNumber = Integer.parseInt(item); 44 array[index] = parsedNumber; 45 } catch (NumberFormatException exc) { 46 array[index] = 0; 47 } 48 index = index + 1; 49 } 50 return array; 51 } 52 53 57 public static String convertIntArrayToRevision(int[] arr) { 58 StringBuffer buffer = new StringBuffer (); 59 for (int i = 0; i < arr.length; i++) { 60 if (arr[i] == 0) { 61 continue; 62 } 63 if (i != 0) { 64 buffer.append('.'); 65 } 66 buffer.append(arr[i]); 67 } 68 return buffer.toString(); 69 } 70 71 72 76 public static String replaceArguments(String original, HashMap replMap) { 77 Iterator it = replMap.keySet().iterator(); 78 while (it.hasNext()) { 79 String pattern = (String )it.next(); 80 String value = (String )replMap.get(pattern); 81 pattern = "{" + pattern + "}"; 82 int index = original.indexOf(pattern); 83 if (index >= 0) { 84 original = original.substring(0, index) + 85 value + original.substring(index + pattern.length()); 86 } 87 } 88 return original; 89 } 90 91 private static final char[] charArray = new char[] {'>', '<', '&'}; 92 private static final String [] stringArray = 93 new String [] { ">", "<", "&"}; 94 95 public static String escapeString(String original) { 96 StringBuffer buffer = new StringBuffer (original); 97 int index = 0; 98 while (index < buffer.length()) { 99 char character = buffer.charAt(index); 100 for (int i = 0; i < charArray.length; i++) { 101 if (character == charArray[i]) { 102 buffer.deleteCharAt(index); 103 buffer.insert(index, stringArray[i]); 104 index = index + stringArray[i].length(); 105 continue; 106 } 107 } 108 index = index + 1; 109 } 110 return buffer.toString(); 111 } 112 113 private static final char[] xmlcharArray = new char[] {'>', '<', '&', '"', '\''}; 114 private static final String [] xmlstringArray = 115 new String [] { ">", "<", "&", """, "'" }; 116 117 public static String xmlescapeString(String original) { 118 StringBuffer buffer = new StringBuffer (original); 119 int index = 0; 120 while (index < buffer.length()) { 121 char character = buffer.charAt(index); 122 for (int i = 0; i < xmlcharArray.length; i++) { 123 if (character == xmlcharArray[i]) { 124 buffer.deleteCharAt(index); 125 buffer.insert(index, xmlstringArray[i]); 126 index = index + xmlstringArray[i].length(); 127 continue; 128 } 129 } 130 index = index + 1; 131 } 132 return buffer.toString(); 133 } 134 135 } 136 | Popular Tags |