001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. The ASF licenses this file to You
004: * under the Apache License, Version 2.0 (the "License"); you may not
005: * use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License. For additional information regarding
015: * copyright in this work, please see the NOTICE file in the top level
016: * directory of this distribution.
017: */
018: package org.apache.roller.util;
019:
020: import java.util.ArrayList;
021: import java.util.Iterator;
022: import java.util.List;
023:
024: /**
025: * Holds collection of error messages and collection of status messages.
026: * @author David M Johnson
027: */
028: public class RollerMessages {
029: private List mErrors = new ArrayList();
030: private List mMessages = new ArrayList();
031:
032: public RollerMessages() {
033: }
034:
035: public void addError(String key) {
036: mErrors.add(new RollerMessage(key, null));
037: }
038:
039: public void addError(String key, String arg) {
040: mErrors.add(new RollerMessage(key, new String[] { arg }));
041: }
042:
043: public void addError(String key, String[] args) {
044: mErrors.add(new RollerMessage(key, args));
045: }
046:
047: public void addMessage(String key) {
048: mMessages.add(new RollerMessage(key, null));
049: }
050:
051: public void addMessage(String key, String arg) {
052: mMessages.add(new RollerMessage(key, new String[] { arg }));
053: }
054:
055: public void addMessage(String key, String[] args) {
056: mMessages.add(new RollerMessage(key, args));
057: }
058:
059: public Iterator getErrors() {
060: return mErrors.iterator();
061: }
062:
063: public Iterator getMessages() {
064: return mMessages.iterator();
065: }
066:
067: public int getErrorCount() {
068: return mErrors.size();
069: }
070:
071: public int getMessageCount() {
072: return mMessages.size();
073: }
074:
075: public String toString() {
076: StringBuffer sb = new StringBuffer();
077: Iterator msgs = mMessages.iterator();
078: while (msgs.hasNext()) {
079: RollerMessage msg = (RollerMessage) msgs.next();
080: sb.append(msg.getKey());
081: sb.append(" : ");
082: }
083: Iterator errs = mErrors.iterator();
084: while (errs.hasNext()) {
085: RollerMessage msg = (RollerMessage) errs.next();
086: sb.append(msg.getKey());
087: sb.append(" : ");
088: }
089: return sb.toString();
090: }
091:
092: public static class RollerMessage {
093: private String mKey;
094: private String[] mArgs;
095:
096: public RollerMessage(String key, String[] args) {
097: mKey = key;
098: mArgs = args;
099: }
100:
101: public String[] getArgs() {
102: return mArgs;
103: }
104:
105: public void setArgs(String[] args) {
106: mArgs = args;
107: }
108:
109: public String getKey() {
110: return mKey;
111: }
112:
113: public void setKey(String key) {
114: mKey = key;
115: }
116: }
117: }
|