KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > him > window > messages > builders > AbstractMessageBuilder


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  */

19 package org.openharmonise.him.window.messages.builders;
20
21 import java.util.HashMap JavaDoc;
22
23 import org.openharmonise.him.window.messages.*;
24 import org.openharmonise.vfs.status.*;
25
26
27 /**
28  *
29  * @author Matthew Large
30  * @version $Revision: 1.1 $
31  *
32  */

33 public abstract class AbstractMessageBuilder {
34
35     private HashMap JavaDoc m_actionStatementMap = new HashMap JavaDoc();
36     
37     public AbstractMessageBuilder() {
38         super();
39     }
40     
41     protected void addActionStatementMapping(String JavaDoc sActionName, ActionStatement statement) {
42         this.m_actionStatementMap.put(sActionName, statement);
43     }
44     
45     public String JavaDoc getActionStatement(String JavaDoc sMessageLevel, String JavaDoc sActionName) {
46         return this.getActionStatement(sMessageLevel, sActionName, null);
47     }
48     
49     public String JavaDoc getActionStatement(String JavaDoc sMessageLevel, String JavaDoc sActionName, String JavaDoc sResourceTitle) {
50         return this.getActionStatement(sMessageLevel, sActionName, sResourceTitle, null);
51     }
52     
53     public String JavaDoc getActionStatement(String JavaDoc sMessageLevel, String JavaDoc sActionName, String JavaDoc sResourceTitle, String JavaDoc sDestinationTitle) {
54         String JavaDoc sStatement = "NO STATEMENT.";
55         if(this.m_actionStatementMap.keySet().contains(sActionName)) {
56             if(sMessageLevel.equals(MessageHandler.TYPE_CONFIRM)) {
57                 if(sResourceTitle!=null && sDestinationTitle!=null) {
58                     sStatement = ((ActionStatement) this.m_actionStatementMap.get(sActionName)).getKnownResourceOK().replaceAll("%NAME%", sResourceTitle).replaceAll("%DESTINATION%", sDestinationTitle);
59                 } else if(sResourceTitle!=null) {
60                     sStatement = ((ActionStatement) this.m_actionStatementMap.get(sActionName)).getKnownResourceOK().replaceAll("%NAME%", sResourceTitle);
61                 } else {
62                     sStatement = ((ActionStatement) this.m_actionStatementMap.get(sActionName)).getUnknownResourceOK();
63                 }
64             } else {
65                 if(sResourceTitle!=null && sDestinationTitle!=null) {
66                     sStatement = ((ActionStatement) this.m_actionStatementMap.get(sActionName)).getKnownResourceERROR().replaceAll("%NAME%", sResourceTitle).replaceAll("%DESTINATION%", sDestinationTitle);
67                 } else if(sResourceTitle!=null) {
68                     sStatement = ((ActionStatement) this.m_actionStatementMap.get(sActionName)).getKnownResourceERROR().replaceAll("%NAME%", sResourceTitle);
69                 } else {
70                     sStatement = ((ActionStatement) this.m_actionStatementMap.get(sActionName)).getUnknownResourceERROR();
71                 }
72             }
73         } else {
74             if(sMessageLevel.equals(MessageHandler.TYPE_CONFIRM)) {
75                 sStatement = "";
76             } else {
77                 sStatement = "There was a problem completing this action.";
78             }
79         }
80
81         return sStatement;
82     }
83
84 }
85
Popular Tags