/**
* Statische Hilfsmethoden zur Stringbehandlung
*
- * @version $Id: StringUtil.java,v 1.23.2.3 2002/12/09 06:23:38 mh Exp $
+ * @version $Id: StringUtil.java,v 1.23.2.4 2002/12/10 09:07:50 mh Exp $
* @author rk, mir-coders group
*
*/
return buf.toString();
}
+ /*
+ * replaces characters that cannot appera in HTML with escaped equivalents.
+ */
+ public static String encodeHTML(String aText) {
+ final char[] CHARACTERS_TO_ESCAPE = { '&', '<', '>', '"', '\'' };
+ final String[] ESCAPE_CODES = { "&", "<", ">", """, "'" };
+
+ int position, nextPosition;
+ int i;
+ StringBuffer result = new StringBuffer();
+
+ position=0;
+
+ do {
+ nextPosition = indexOfCharacters(aText, CHARACTERS_TO_ESCAPE, position);
+
+ if (nextPosition<0)
+ nextPosition = aText.length();
+
+ result.append(aText.substring(position, nextPosition));
+
+ if (nextPosition<aText.length())
+ for (i=0; i<CHARACTERS_TO_ESCAPE.length; i++) {
+ if (CHARACTERS_TO_ESCAPE[i] == aText.charAt(nextPosition)) {
+ result.append(ESCAPE_CODES[i]);
+ break;
+ }
+ }
+ position=nextPosition+1;
+ }
+ while (nextPosition<aText.length()) ;
+
+ return result.toString();
+ }
+
/**
* Wandelet String in byte[] um.
* @param s
return new String(a);
}
- /**
- * Findet <code>element</code> im String-Array <code>array</code>
+ /**
+ * Finds <code>element</code> in String-Array <code>array</code>
* @param array
* @param element
- * @return Fundstelle als int oder -1
+ * @return Position where the element was found or -1
*/
public static int indexOf(String[] array, String element) {
if (array != null)
return -1;
}
+ /**
+ * Finds position of first in <code>aCharacters</code> array in String
+ * <code>aString</code> starting from position <code>aFrom</code>
+ *
+ * @param aString
+ * @param aCharacters
+ * @param aFrom
+ * @return Position where the element was found or -1
+ */
+ public static int indexOfCharacters(String aString, char[] aCharacters, int aFrom) {
+ int i;
+ int result=-1;
+ int position;
+
+ for (i=0; i<aCharacters.length ; i++) {
+ position = aString.indexOf(aCharacters[i], aFrom);
+
+ if (position != -1 && ( result == -1 || position < result )) {
+ result = position;
+ }
+ }
+
+ return result;
+ }
+
+
/**
* Testet auf Vorkommen von <code>element</code> in <code>array</code>
* @param array String-Array
}
}
+ public static String interpretAsString(Object aValue) throws Exception {
+ if (aValue instanceof String)
+ return (String) aValue;
+
+ if (aValue instanceof Integer)
+ return ((Integer) aValue).toString();
+
+ if (aValue == null)
+ return "";
+
+ throw new Exception("String expected, "+aValue+" found");
+ }
+
+
+
/**
* Liefert Defaultwert def zurück, wenn s nicht zu einem float geparsed werden kann.
* @param s
}
}
+ /**
+ * deleteHTMLTableTags
+ * this method deletes all <table>, <tr> and <td>-tags
+ */
+ public static final String deleteHTMLTableTags(String haystack) {
+ try {
+ RE regex = new RE("</?(table|td|tr)>",RE.REG_ICASE);
+ haystack = regex.substituteAll(haystack,"");
+ return haystack;
+ } catch(REException ex){
+ return null;
+ }
+ }
+
/**
* this method deletes all html tags
*/