AbstractMessageBuilder.java :  » Content-Management-System » harmonise » org » openharmonise » him » window » messages » builders » Java Open Source

Java Open Source » Content Management System » harmonise 
harmonise » org » openharmonise » him » window » messages » builders » AbstractMessageBuilder.java
/*
 * The contents of this file are subject to the 
 * Mozilla Public License Version 1.1 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. 
 * See the License for the specific language governing rights and 
 * limitations under the License.
 *
 * The Initial Developer of the Original Code is Simulacra Media Ltd.
 * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
 *
 * All Rights Reserved.
 *
 * Contributor(s):
 */
package org.openharmonise.him.window.messages.builders;

import java.util.HashMap;

import org.openharmonise.him.window.messages.*;
import org.openharmonise.vfs.status.*;


/**
 * 
 * @author Matthew Large
 * @version $Revision: 1.1 $
 *
 */
public abstract class AbstractMessageBuilder {

  private HashMap m_actionStatementMap = new HashMap();
  
  public AbstractMessageBuilder() {
    super();
  }
  
  protected void addActionStatementMapping(String sActionName, ActionStatement statement) {
    this.m_actionStatementMap.put(sActionName, statement);
  }
  
  public String getActionStatement(String sMessageLevel, String sActionName) {
    return this.getActionStatement(sMessageLevel, sActionName, null);
  }
  
  public String getActionStatement(String sMessageLevel, String sActionName, String sResourceTitle) {
    return this.getActionStatement(sMessageLevel, sActionName, sResourceTitle, null);
  }
  
  public String getActionStatement(String sMessageLevel, String sActionName, String sResourceTitle, String sDestinationTitle) {
    String sStatement = "NO STATEMENT.";
    if(this.m_actionStatementMap.keySet().contains(sActionName)) {
      if(sMessageLevel.equals(MessageHandler.TYPE_CONFIRM)) {
        if(sResourceTitle!=null && sDestinationTitle!=null) {
          sStatement = ((ActionStatement) this.m_actionStatementMap.get(sActionName)).getKnownResourceOK().replaceAll("%NAME%", sResourceTitle).replaceAll("%DESTINATION%", sDestinationTitle);
        } else if(sResourceTitle!=null) {
          sStatement = ((ActionStatement) this.m_actionStatementMap.get(sActionName)).getKnownResourceOK().replaceAll("%NAME%", sResourceTitle);
        } else {
          sStatement = ((ActionStatement) this.m_actionStatementMap.get(sActionName)).getUnknownResourceOK();
        }
      } else {
        if(sResourceTitle!=null && sDestinationTitle!=null) {
          sStatement = ((ActionStatement) this.m_actionStatementMap.get(sActionName)).getKnownResourceERROR().replaceAll("%NAME%", sResourceTitle).replaceAll("%DESTINATION%", sDestinationTitle);
        } else if(sResourceTitle!=null) {
          sStatement = ((ActionStatement) this.m_actionStatementMap.get(sActionName)).getKnownResourceERROR().replaceAll("%NAME%", sResourceTitle);
        } else {
          sStatement = ((ActionStatement) this.m_actionStatementMap.get(sActionName)).getUnknownResourceERROR();
        }
      }
    } else {
      if(sMessageLevel.equals(MessageHandler.TYPE_CONFIRM)) {
        sStatement = "";
      } else {
        sStatement = "There was a problem completing this action.";
      }
    }

    return sStatement;
  }

}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.