add in query_.. parameters to the delete request url so that we come back to the...
[mir.git] / source / mir / util / StringRoutines.java
index b670ae3..ddb6ccb 100755 (executable)
@@ -55,10 +55,7 @@ public class StringRoutines {
     return result;
   }
 
-  public static String encodeHTML(String aText) {
-    final char[] CHARACTERS_TO_ESCAPE = { '&', '<', '>', '"', '\'' };
-    final String[] ESCAPE_CODES = { "&amp;", "&lt;", "&gt;", "&quot;", "&apos;" };
-
+  static String replaceStringCharacters(String aText, char[] aCharactersToReplace, String[] aStringsToSubstitute) {
     int position, nextPosition;
     int i;
     StringBuffer result = new StringBuffer();
@@ -66,7 +63,7 @@ public class StringRoutines {
     position=0;
 
     do {
-      nextPosition = indexOfCharacters(aText, CHARACTERS_TO_ESCAPE, position);
+      nextPosition = StringRoutines.indexOfCharacters(aText, aCharactersToReplace, position);
 
       if (nextPosition<0)
         nextPosition = aText.length();
@@ -74,9 +71,9 @@ public class StringRoutines {
       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]);
+        for (i=0; i<aCharactersToReplace.length; i++) {
+          if (aCharactersToReplace[i] == aText.charAt(nextPosition)) {
+            result.append(aStringsToSubstitute[i]);
             break;
           }
         }
@@ -87,6 +84,35 @@ public class StringRoutines {
     return result.toString();
   }
 
+
+  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");
+  }
+
+  public static int interpretAsInteger(Object aValue) throws Exception {
+    if (aValue instanceof Integer)
+      return ((Integer) aValue).intValue();
+
+    if (aValue instanceof String)
+      try {
+        return Integer.parseInt((String) aValue);
+      }
+      catch (Throwable t) {
+        throw new Exception("Integer expected, "+aValue+" found");
+      }
+
+    throw new Exception("Integer expected, "+aValue+" found");
+  }
+
   public static String performRegularExpressionReplacement(String aSource,
       String aSearchExpression, String aReplacement) throws Exception {
 
@@ -106,42 +132,19 @@ public class StringRoutines {
     return regularExpression.isMatch(aSource);
   }
 
-/*
-  return StringUtil.createHTML(
-      StringUtil.deleteForbiddenTags(aText),
-      MirGlobal.getConfigProperty("Producer.ImageRoot"),
-      MirGlobal.getConfigProperty("Producer.MailLinkName"),
-      MirGlobal.getConfigProperty("Producer.ExtLinkName"),
-      MirGlobal.getConfigProperty("Producer.IntLinkName")
-  );
- public static String createHTML(String content){
-         content=convertNewline2Break(content);
-         content=convertNewline2P(content);
-         content=createMailLinks(content);
-         content=createURLLinks(content);
-         return content;
-
- public static String convertNewline2Break(String haystack) {
-         return re_newline2br.substituteAll(haystack,"$0<br />");
- }
-
- public static String convertNewline2P(String haystack) {
-                 return re_brbr2p.substituteAll(haystack,"\n</p><p>");
- }
-
- public static String createMailLinks(String haystack, String imageRoot, String mailImage) {
-         return re_mail.substituteAll(haystack,"<img src=\""+imageRoot+"/"+mailImage+"\" border=\"0\"/>&#160;<a href=\"mailto:$0\">$0</a>");
- }
-
- public static String createURLLinks(String haystack, String title, String imageRoot,String extImage) {
-         if (title == null) {
-                 return re_url.substituteAll(haystack,"<img src=\""+imageRoot+"/"+extImage+"\" border=\"0\"/>&#160;<a href=\"$0\">$0</a>");
-         } else {
-                 title = removeHTMLTags(title);
-                 return re_url.substituteAll(haystack,"<img src=\""+imageRoot+"/"+extImage+"\" border=\"0\"/>&#160;<a href=\"$0\">"+title+"</a>");
-         }
- }
-
- }
-*/
+  public static List splitString(String aString, String aSeparator) {
+    List result= new Vector();
+    int previousPosition = 0;
+    int position;
+    int endOfNamePosition;
+
+    while ((position = aString.indexOf(aSeparator, previousPosition))>=0) {
+      result.add(aString.substring(previousPosition, position));
+      previousPosition = position + aSeparator.length();
+    }
+
+    result.add(aString.substring(previousPosition, aString.length()));
+
+    return result;
+  }
 }
\ No newline at end of file