1 package org.roller.util; 2 3 import java.util.ArrayList ; 4 import java.util.Iterator ; 5 import java.util.List ; 6 7 11 public class RollerMessages 12 { 13 private List mErrors = new ArrayList (); 14 private List mMessages = new ArrayList (); 15 16 public RollerMessages() 17 { 18 } 19 public void addError(String key) 20 { 21 mErrors.add(new RollerMessage(key, null)); 22 } 23 public void addError(String key, String arg) 24 { 25 mErrors.add(new RollerMessage(key, new String []{arg})); 26 } 27 public void addError(String key, String [] args) 28 { 29 mErrors.add(new RollerMessage(key, args)); 30 } 31 public void addMessage(String key) 32 { 33 mMessages.add(new RollerMessage(key, null)); 34 } 35 public void addMessage(String key, String arg) 36 { 37 mMessages.add(new RollerMessage(key, new String []{arg})); 38 } 39 public void addMessage(String key, String [] args) 40 { 41 mMessages.add(new RollerMessage(key, args)); 42 } 43 public Iterator getErrors() 44 { 45 return mErrors.iterator(); 46 } 47 public Iterator getMessages() 48 { 49 return mMessages.iterator(); 50 } 51 public int getErrorCount() 52 { 53 return mErrors.size(); 54 } 55 public int getMessageCount() 56 { 57 return mMessages.size(); 58 } 59 public String toString() 60 { 61 StringBuffer sb = new StringBuffer (); 62 Iterator msgs = mMessages.iterator(); 63 while (msgs.hasNext()) 64 { 65 RollerMessage msg = (RollerMessage) msgs.next(); 66 sb.append(msg.getKey()); 67 sb.append(" : "); 68 } 69 Iterator errs = mErrors.iterator(); 70 while (errs.hasNext()) 71 { 72 RollerMessage msg = (RollerMessage) errs.next(); 73 sb.append(msg.getKey()); 74 sb.append(" : "); 75 } 76 return sb.toString(); 77 } 78 public static class RollerMessage 79 { 80 private String mKey; 81 private String [] mArgs; 82 public RollerMessage(String key, String [] args) 83 { 84 mKey = key; 85 mArgs = args; 86 } 87 public String [] getArgs() 88 { 89 return mArgs; 90 } 91 public void setArgs(String [] args) 92 { 93 mArgs = args; 94 } 95 public String getKey() 96 { 97 return mKey; 98 } 99 public void setKey(String key) 100 { 101 mKey = key; 102 } 103 } 104 } 105 | Popular Tags |