Changeset 8704 for trunk/gsdl3/src/java/org
- Timestamp:
- 2004-11-30T11:27:39+13:00 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/util/XMLTools.java
r5800 r8704 3 3 public class XMLTools 4 4 { 5 public static String getTag(String namespace, String label, boolean open) 6 { StringBuffer reply = new StringBuffer(); 5 public static String getTag(String namespace, String label, boolean open) 6 { 7 StringBuffer reply = new StringBuffer(); 7 8 8 reply.append("<"); 9 if (!open) 10 { reply.append("/"); 11 } 12 if (namespace != null && namespace.length() > 0) { 13 reply.append(namespace); 14 reply.append(":"); 15 } 16 reply.append(label); 17 reply.append(">"); 18 return reply.toString(); 9 reply.append("<"); 10 if (!open) 11 { 12 reply.append("/"); 13 } 14 if (namespace != null && namespace.length() > 0) { 15 reply.append(namespace); 16 reply.append(":"); 19 17 } 18 reply.append(label); 19 reply.append(">"); 20 return reply.toString(); 21 } 20 22 21 public static String addAttribute(String tag, String attribute, String value) 22 { StringBuffer reply = new StringBuffer(tag); 23 reply.insert(reply.length() - 1 , ' '); 24 reply.insert(reply.length() - 1 , attribute); 25 reply.insert(reply.length() - 1 , "=\""); 26 reply.insert(reply.length() - 1 , value); 27 reply.insert(reply.length() - 1 , '\"'); 28 return reply.toString(); 23 public static String addAttribute(String tag, String attribute, String value) 24 { 25 StringBuffer reply = new StringBuffer(tag); 26 reply.insert(reply.length() - 1 , ' '); 27 reply.insert(reply.length() - 1 , attribute); 28 reply.insert(reply.length() - 1 , "=\""); 29 reply.insert(reply.length() - 1 , value); 30 reply.insert(reply.length() - 1 , '\"'); 31 return reply.toString(); 32 } 33 34 public static String makeSingleton(String tag) 35 { 36 StringBuffer reply = new StringBuffer(tag); 37 reply.insert(tag.length() - 1, " /"); 38 return reply.toString(); 39 } 40 41 public static String getOpenTag(String namespace, String label) 42 { 43 return getTag(namespace, label, true); 44 } 45 46 public static String getCloseTag(String namespace, String label) 47 { 48 return getTag(namespace, label, false); 49 } 50 51 /** 52 * Clean a string to remove whitespace... 53 * 54 * @param <code>String</code> the original text 55 * @return <code>String</code> the 'cleaned' text 56 */ 57 public static String cleanString(String original) 58 { 59 StringBuffer buffer = new StringBuffer(original); 60 61 while (buffer.charAt(0) <= 32) { 62 buffer.deleteCharAt(0); 29 63 } 30 31 public static String makeSingleton(String tag) 32 { StringBuffer reply = new StringBuffer(tag); 33 reply.insert(tag.length() - 1, " /"); 34 return reply.toString(); 64 65 while (buffer.charAt(buffer.length() - 1) <= 32){ 66 buffer.deleteCharAt(buffer.length() - 1); 35 67 } 36 37 public static String getOpenTag(String namespace, String label) 38 { return getTag(namespace, label, true); 68 69 int c = 1; 70 while (c < buffer.length()){ 71 if (buffer.charAt(c) < 32){ 72 buffer.setCharAt(c, ' '); 73 } 74 if (buffer.charAt(c) == ' ' && buffer.charAt(c-1) == ' '){ 75 buffer.deleteCharAt(c); 76 continue; 77 } 78 c ++; 39 79 } 40 41 public static String getCloseTag(String namespace, String label) 42 { return getTag(namespace, label, false); 43 } 44 45 /** 46 * Clean a string to remove whitespace... 47 * 48 * @param <code>String</code> the original text 49 * @return <code>String</code> the 'cleaned' text 50 */ 51 public static String cleanString(String original) 52 { StringBuffer buffer = new StringBuffer(original); 53 54 while (buffer.charAt(0) <= 32) 55 { buffer.deleteCharAt(0); 56 } 57 58 while (buffer.charAt(buffer.length() - 1) <= 32) 59 { buffer.deleteCharAt(buffer.length() - 1); 60 } 61 62 int c = 1; 63 while (c < buffer.length()) 64 { if (buffer.charAt(c) < 32) 65 { buffer.setCharAt(c, ' '); 66 } 67 if (buffer.charAt(c) == ' ' && buffer.charAt(c-1) == ' ') 68 { buffer.deleteCharAt(c); 69 continue; 70 } 71 c ++; 72 } 73 return buffer.toString(); 74 } 80 return buffer.toString(); 81 } 75 82 }
Note:
See TracChangeset
for help on using the changeset viewer.