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