From: mh Date: Tue, 10 Dec 2002 09:07:50 +0000 (+0000) Subject: re-introduce leaner/simpler encodeHTML(String aText) method, we need it for the admin... X-Git-Tag: MIR_1_0_0_RC4~20 X-Git-Url: http://erislabs.net/gitweb/?p=mir.git;a=commitdiff_plain;h=0ea8b821ae0f09a7638fe9e427654ddd395c48d8 re-introduce leaner/simpler encodeHTML(String aText) method, we need it for the admin interface so that we can actually edit the HTML. It needed indexOfCharacters and interpretAsString. all taken from the StringRoutines file in HEAD. also add deleteHTMLTableTags.. --- diff --git a/source/mir/misc/StringUtil.java b/source/mir/misc/StringUtil.java index 4315a452..0e96f4cc 100755 --- a/source/mir/misc/StringUtil.java +++ b/source/mir/misc/StringUtil.java @@ -40,7 +40,7 @@ import gnu.regexp.*; /** * 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 * */ @@ -413,6 +413,41 @@ public final class StringUtil { 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 (nextPositionelement im String-Array array + /** + * Finds element in String-Array array * @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) @@ -632,6 +667,32 @@ public final class StringUtil { return -1; } + /** + * Finds position of first in aCharacters array in String + * aString starting from position aFrom + * + * @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; ielement in array * @param array String-Array @@ -677,6 +738,21 @@ public final class StringUtil { } } + 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 @@ -823,6 +899,20 @@ public final class StringUtil { } } + /** + * deleteHTMLTableTags + * this method deletes all , and
-tags + */ + public static final String deleteHTMLTableTags(String haystack) { + try { + RE regex = new RE("",RE.REG_ICASE); + haystack = regex.substituteAll(haystack,""); + return haystack; + } catch(REException ex){ + return null; + } + } + /** * this method deletes all html tags */