1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.itracker.web.util;
20
21 import org.apache.log4j.Logger;
22
23
24 public class HTMLUtilities extends org.itracker.util.HTMLUtilities {
25
26 private static final Logger logger = Logger.getLogger(HTMLUtilities.class);
27
28 static {
29
30
31 }
32
33 public static String removeQuotes(String input) {
34 StringBuffer sb = new StringBuffer(input.length());
35 int len = input.length();
36 char c;
37
38 for (int i = 0; i < len; i++) {
39 c = input.charAt(i);
40 if (c == '\'') {
41 sb.append("''");
42 } else {
43 sb.append(c);
44 }
45 }
46 return sb.toString();
47 }
48
49 public static String handleQuotes(String input) {
50 if (input == null || "".equals(input) || input.indexOf('"') == -1) {
51 return input;
52 }
53
54 StringBuffer buf = new StringBuffer();
55
56 char[] chars = input.toCharArray();
57 for (int i = 0; i < chars.length; i++) {
58 if (chars[i] == '"') {
59 buf.append(""");
60 } else {
61 buf.append(chars[i]);
62 }
63 }
64
65 return buf.toString();
66 }
67
68 public static String escapeNewlines(String input) {
69 if (input == null || "".equals(input) || input.indexOf('\n') == -1) {
70 return input;
71 }
72
73 StringBuffer buf = new StringBuffer();
74 char[] chars = input.toCharArray();
75 for (int i = 0; i < chars.length; i++) {
76 if (chars[i] == '\r') {
77 continue;
78 } else if (chars[i] == '\n') {
79 buf.append("\\n");
80 } else {
81 buf.append(chars[i]);
82 }
83 }
84 return buf.toString();
85 }
86
87 public static String newlinesToBreaks(String input) {
88 if (input == null || "".equals(input) || input.indexOf('\n') == -1) {
89 return input;
90 }
91
92 StringBuffer buf = new StringBuffer();
93 char[] chars = input.toCharArray();
94 for (int i = 0; i < chars.length; i++) {
95 if (chars[i] == '\r') {
96 continue;
97 } else if (chars[i] == '\n') {
98 buf.append("<br>");
99 } else {
100 buf.append(chars[i]);
101 }
102 }
103 return buf.toString();
104 }
105
106
107
108 public static String escapeTags(String input) {
109 if (null == input) {
110 return "";
111 }
112 StringBuffer sb = new StringBuffer(input.length());
113 int len = input.length();
114 char c;
115
116 for (int i = 0; i < len; i++) {
117 c = input.charAt(i);
118 if (c == '"') {
119 sb.append(""");
120 } else if (c == '&') {
121 sb.append("&");
122 } else if (c == '<') {
123 sb.append("<");
124 } else if (c == '>') {
125 sb.append(">");
126 } else {
127 int ci = 0xffff & c;
128 if (ci < 160) {
129
130 sb.append(c);
131 } else {
132
133 sb.append("&#");
134 sb.append(new Integer(ci).toString());
135 sb.append(';');
136 }
137 }
138 }
139
140 return sb.toString();
141 }
142
143
144
145
146
147 public static final String getJSDateFormat(String format) {
148
149 String f = format.replace('m', 'n');
150 f = f.toLowerCase();
151 return f;
152
153
154 }
155
156 }
157
158