001: /*
002: * The contents of this file are subject to the
003: * Mozilla Public License Version 1.1 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
006: *
007: * Software distributed under the License is distributed on an "AS IS"
008: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
009: * See the License for the specific language governing rights and
010: * limitations under the License.
011: *
012: * The Initial Developer of the Original Code is Simulacra Media Ltd.
013: * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
014: *
015: * All Rights Reserved.
016: *
017: * Contributor(s):
018: */
019: package org.openharmonise.him.window.messages.builders;
020:
021: import java.util.HashMap;
022:
023: import org.openharmonise.him.window.messages.*;
024: import org.openharmonise.vfs.status.*;
025:
026: /**
027: *
028: * @author Matthew Large
029: * @version $Revision: 1.1 $
030: *
031: */
032: public abstract class AbstractMessageBuilder {
033:
034: private HashMap m_actionStatementMap = new HashMap();
035:
036: public AbstractMessageBuilder() {
037: super ();
038: }
039:
040: protected void addActionStatementMapping(String sActionName,
041: ActionStatement statement) {
042: this .m_actionStatementMap.put(sActionName, statement);
043: }
044:
045: public String getActionStatement(String sMessageLevel,
046: String sActionName) {
047: return this
048: .getActionStatement(sMessageLevel, sActionName, null);
049: }
050:
051: public String getActionStatement(String sMessageLevel,
052: String sActionName, String sResourceTitle) {
053: return this .getActionStatement(sMessageLevel, sActionName,
054: sResourceTitle, null);
055: }
056:
057: public String getActionStatement(String sMessageLevel,
058: String sActionName, String sResourceTitle,
059: String sDestinationTitle) {
060: String sStatement = "NO STATEMENT.";
061: if (this .m_actionStatementMap.keySet().contains(sActionName)) {
062: if (sMessageLevel.equals(MessageHandler.TYPE_CONFIRM)) {
063: if (sResourceTitle != null && sDestinationTitle != null) {
064: sStatement = ((ActionStatement) this .m_actionStatementMap
065: .get(sActionName)).getKnownResourceOK()
066: .replaceAll("%NAME%", sResourceTitle)
067: .replaceAll("%DESTINATION%",
068: sDestinationTitle);
069: } else if (sResourceTitle != null) {
070: sStatement = ((ActionStatement) this .m_actionStatementMap
071: .get(sActionName)).getKnownResourceOK()
072: .replaceAll("%NAME%", sResourceTitle);
073: } else {
074: sStatement = ((ActionStatement) this .m_actionStatementMap
075: .get(sActionName)).getUnknownResourceOK();
076: }
077: } else {
078: if (sResourceTitle != null && sDestinationTitle != null) {
079: sStatement = ((ActionStatement) this .m_actionStatementMap
080: .get(sActionName)).getKnownResourceERROR()
081: .replaceAll("%NAME%", sResourceTitle)
082: .replaceAll("%DESTINATION%",
083: sDestinationTitle);
084: } else if (sResourceTitle != null) {
085: sStatement = ((ActionStatement) this .m_actionStatementMap
086: .get(sActionName)).getKnownResourceERROR()
087: .replaceAll("%NAME%", sResourceTitle);
088: } else {
089: sStatement = ((ActionStatement) this .m_actionStatementMap
090: .get(sActionName))
091: .getUnknownResourceERROR();
092: }
093: }
094: } else {
095: if (sMessageLevel.equals(MessageHandler.TYPE_CONFIRM)) {
096: sStatement = "";
097: } else {
098: sStatement = "There was a problem completing this action.";
099: }
100: }
101:
102: return sStatement;
103: }
104:
105: }
|