View Javadoc
1   /*
2    * This software was designed and created by Jason Carroll.
3    * Copyright (c) 2002, 2003, 2004 Jason Carroll.
4    * The author can be reached at jcarroll@cowsultants.com
5    * ITracker website: http://www.cowsultants.com
6    * ITracker forums: http://www.cowsultants.com/phpBB/index.php
7    *
8    * This program is free software; you can redistribute it and/or modify
9    * it only under the terms of the GNU General Public License as published by
10   * the Free Software Foundation; either version 2 of the License, or
11   * (at your option) any later version.
12   *
13   * This program is distributed in the hope that it will be useful,
14   * but WITHOUT ANY WARRANTY; without even the implied warranty of
15   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   * GNU General Public License for more details.
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("&quot;");
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("&quot;");
120             } else if (c == '&') {
121                 sb.append("&amp;");
122             } else if (c == '<') {
123                 sb.append("&lt;");
124             } else if (c == '>') {
125                 sb.append("&gt;");
126             } else {
127                 int ci = 0xffff & c;
128                 if (ci < 160) {
129                     // nothing special only 7 Bit
130                     sb.append(c);
131                 } else {
132                     // Not 7 Bit use the unicode system
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      * format a itracker date format for jacascript datepicker
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