source: trunk/greenstone3-extensions/gs3build/src/org/greenstone/gsdl3/gs3build/util/XMLTools.java@ 12188

Last change on this file since 12188 was 12188, checked in by kjdon, 18 years ago

Initial revision

  • Property svn:keywords set to Author Date Id Revision
File size: 1.9 KB
Line 
1package org.greenstone.gsdl3.gs3build.util;
2
3public class XMLTools
4{
5 public static String getTag(String namespace, String label, boolean open)
6 {
7 StringBuffer reply = new StringBuffer();
8
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(":");
17 }
18 reply.append(label);
19 reply.append(">");
20 return reply.toString();
21 }
22
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);
63 }
64
65 while (buffer.charAt(buffer.length() - 1) <= 32){
66 buffer.deleteCharAt(buffer.length() - 1);
67 }
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 ++;
79 }
80 return buffer.toString();
81 }
82}
Note: See TracBrowser for help on using the repository browser.