/*
* 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.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import org.openharmonise.him.actions.dir.*;
import org.openharmonise.him.actions.file.*;
import org.openharmonise.him.actions.move.*;
import org.openharmonise.him.actions.publish.*;
import org.openharmonise.him.actions.system.*;
import org.openharmonise.him.harmonise.*;
import org.openharmonise.him.window.messages.*;
import org.openharmonise.vfs.status.*;
import org.openharmonise.webdav.client.*;
/**
*
* @author Matthew Large
* @version $Revision: 1.1 $
*
*/
public class VFSMessageBuilder extends AbstractMessageBuilder implements
MessageBuilder {
private static MessageBuilder m_instance = null;
private HashMap m_statusStatementMapping = new HashMap();
/**
*
*/
private VFSMessageBuilder() {
super();
this.setup();
}
private void setup() {
// Action Statements
ActionStatement actionStatement = new ActionStatement();
actionStatement.setKnownResourceOK("You have successfully ordered %NAME%.");
actionStatement.setUnknownResourceOK("You have successfully ordered this collection.");
actionStatement.setKnownResourceERROR("There was a problem ordering %NAME%.");
actionStatement.setUnknownResourceERROR("There was a problem ordering this collection.");
super.addActionStatementMapping(ActionOrder.ACTION_NAME, actionStatement);
actionStatement = new ActionStatement();
actionStatement.setKnownResourceOK("You have successfully created a copy of %NAME%.");
actionStatement.setUnknownResourceOK("You have successfully created a copy of this resource.");
actionStatement.setKnownResourceERROR("There was a problem creating a copy of %NAME%.");
actionStatement.setUnknownResourceERROR("There was a problem creating a copy of this resource.");
super.addActionStatementMapping(ActionCreateCopy.ACTION_NAME, actionStatement);
actionStatement = new ActionStatement();
actionStatement.setKnownResourceOK("You have successfully locked %NAME%.");
actionStatement.setUnknownResourceOK("You have successfully locked this resource.");
actionStatement.setKnownResourceERROR("There was a problem locking %NAME%, it is locked by %DESTINATION%.");
actionStatement.setUnknownResourceERROR("There was a problem locking this resource.");
super.addActionStatementMapping(ActionLock.ACTION_NAME, actionStatement);
actionStatement = new ActionStatement();
actionStatement.setKnownResourceOK("You have successfully created the collection %NAME%.");
actionStatement.setUnknownResourceOK("You have successfully created a new collection.");
actionStatement.setKnownResourceERROR("There was a problem creating the collection %NAME%.");
actionStatement.setUnknownResourceERROR("There was a problem creating this new collection.");
super.addActionStatementMapping(ActionNewCollection.ACTION_NAME, actionStatement);
actionStatement = new ActionStatement();
actionStatement.setKnownResourceOK("You have successfully created the resource %NAME%.");
actionStatement.setUnknownResourceOK("You have successfully created a new resource.");
actionStatement.setKnownResourceERROR("There was a problem creating the resource %NAME%.");
actionStatement.setUnknownResourceERROR("There was a problem creating this new resource.");
super.addActionStatementMapping(ActionNewFile.ACTION_NAME, actionStatement);
actionStatement = new ActionStatement();
actionStatement.setKnownResourceOK("%NAME% opened.");
actionStatement.setUnknownResourceOK("Resource opened.");
actionStatement.setKnownResourceERROR("There was a problem opening the resource %NAME%.");
actionStatement.setUnknownResourceERROR("There was a problem opening this new resource.");
super.addActionStatementMapping(ActionOpen.ACTION_NAME, actionStatement);
actionStatement = new ActionStatement();
actionStatement.setKnownResourceOK("You have successfully renamed %NAME% to %DESTINATION%.");
actionStatement.setUnknownResourceOK("You have successfully renamed this resource.");
actionStatement.setKnownResourceERROR("There was a problem renaming %NAME% to %DESTINATION%.");
actionStatement.setUnknownResourceERROR("There was a problem renaming this resource.");
super.addActionStatementMapping(ActionRename.ACTION_NAME, actionStatement);
actionStatement = new ActionStatement();
actionStatement.setKnownResourceOK("You have successfully submitted %NAME% to the server.");
actionStatement.setUnknownResourceOK("You have successfully submitted this resource to the server.");
actionStatement.setKnownResourceERROR("There was a problem submitting %NAME% to the server.");
actionStatement.setUnknownResourceERROR("There was a problem submitting this resource to the server.");
super.addActionStatementMapping(ActionSynchronise.ACTION_NAME, actionStatement);
actionStatement = new ActionStatement();
actionStatement.setKnownResourceOK("You have successfully unlocked %NAME%.");
actionStatement.setUnknownResourceOK("You have successfully unlocked this resource.");
actionStatement.setKnownResourceERROR("There was a problem unlocking %NAME%, it is locked by %DESTINATION%.");
actionStatement.setUnknownResourceERROR("There was a problem unlocking this resource.");
super.addActionStatementMapping(ActionUnlock.ACTION_NAME, actionStatement);
actionStatement = new ActionStatement();
actionStatement.setKnownResourceOK("You have successfully uploaded %NAME%.");
actionStatement.setUnknownResourceOK("You have successfully uploaded this resource.");
actionStatement.setKnownResourceERROR("There was a problem uploading %NAME%.");
actionStatement.setUnknownResourceERROR("There was a problem uploading this resource.");
super.addActionStatementMapping(ActionUpload.ACTION_NAME, actionStatement);
actionStatement = new ActionStatement();
actionStatement.setKnownResourceOK("ALIAS %NAME%.");
actionStatement.setUnknownResourceOK("ALIAS.");
actionStatement.setKnownResourceERROR("ALIAS %NAME%.");
actionStatement.setUnknownResourceERROR("ALIAS.");
super.addActionStatementMapping(ActionAlias.ACTION_NAME, actionStatement);
actionStatement = new ActionStatement();
actionStatement = new ActionStatement();
actionStatement.setKnownResourceOK("You have successfully copied %NAME% to %DESTINATION%.");
actionStatement.setUnknownResourceOK("You have successfully copied this resource.");
actionStatement.setKnownResourceERROR("There was a problem copying %NAME% to %DESTINATION%.");
actionStatement.setUnknownResourceERROR("There was a problem copying this resource.");
super.addActionStatementMapping(ActionCopy.ACTION_NAME, actionStatement);
actionStatement = new ActionStatement();
actionStatement.setKnownResourceOK("You have successfully moved %NAME% to %DESTINATION%.");
actionStatement.setUnknownResourceOK("You have successfully moved this resource.");
actionStatement.setKnownResourceERROR("There was a problem moving %NAME% to %DESTINATION%.");
actionStatement.setUnknownResourceERROR("There was a problem moving this resource.");
super.addActionStatementMapping(ActionMove.ACTION_NAME, actionStatement);
actionStatement = new ActionStatement();
actionStatement.setKnownResourceOK("You have successfully archived %NAME%.");
actionStatement.setUnknownResourceOK("You have successfully archived this resource.");
actionStatement.setKnownResourceERROR("There was a problem archiving %NAME%.");
actionStatement.setUnknownResourceERROR("There was a problem archiving this resource.");
super.addActionStatementMapping(ActionArchive.ACTION_NAME, actionStatement);
actionStatement = new ActionStatement();
actionStatement.setKnownResourceOK("You have successfully exported %NAME%.");
actionStatement.setUnknownResourceOK("You have successfully exported this resource.");
actionStatement.setKnownResourceERROR("There was a problem exporting %NAME%.");
actionStatement.setUnknownResourceERROR("There was a problem exporting this resource.");
super.addActionStatementMapping(ActionExport.ACTION_NAME, actionStatement);
actionStatement = new ActionStatement();
actionStatement.setKnownResourceOK("%NAME% opened for preview.");
actionStatement.setUnknownResourceOK("Resource opened for preview.");
actionStatement.setKnownResourceERROR("There was a problem opening %NAME% for preview.");
actionStatement.setUnknownResourceERROR("There was a problem opening this resource for preview.");
super.addActionStatementMapping(ActionPreview.ACTION_NAME, actionStatement);
actionStatement = new ActionStatement();
actionStatement.setKnownResourceOK("You have successfully published %NAME%.");
actionStatement.setUnknownResourceOK("You have successfully published this resource.");
actionStatement.setKnownResourceERROR("There was a problem publishing %NAME%.");
actionStatement.setUnknownResourceERROR("There was a problem publishing this resource.");
super.addActionStatementMapping(ActionPublishToInternet.ACTION_NAME, actionStatement);
actionStatement = new ActionStatement();
actionStatement.setKnownResourceOK("You have successfully unpublished %NAME%.");
actionStatement.setUnknownResourceOK("You have successfully unpublished this resource.");
actionStatement.setKnownResourceERROR("There was a problem unpublishing %NAME%.");
actionStatement.setUnknownResourceERROR("There was a problem unpublishing this resource.");
super.addActionStatementMapping(ActionRemoveFromInternet.ACTION_NAME, actionStatement);
actionStatement = new ActionStatement();
actionStatement.setKnownResourceOK("You have successfully retrieved %NAME%.");
actionStatement.setUnknownResourceOK("You have successfully retrieved this resource.");
actionStatement.setKnownResourceERROR("There was a problem retrieving %NAME%.");
actionStatement.setUnknownResourceERROR("There was a problem retrieving this resource.");
super.addActionStatementMapping(ActionRetrieve.ACTION_NAME, actionStatement);
actionStatement = new ActionStatement();
actionStatement.setKnownResourceOK("NO STATEMENT.");
actionStatement.setUnknownResourceOK("You have successfully submitted these resources to the server.");
actionStatement.setKnownResourceERROR("NO STATEMENT.");
actionStatement.setUnknownResourceERROR("There was a problem submitting these resources to the server.");
super.addActionStatementMapping(ActionSyncWithServer.ACTION_NAME, actionStatement);
actionStatement = new ActionStatement();
actionStatement.setKnownResourceOK("NO STATEMENT.");
actionStatement.setUnknownResourceOK("The search was successful.");
actionStatement.setKnownResourceERROR("NO STATEMENT.");
actionStatement.setUnknownResourceERROR("There was a problem searching.");
super.addActionStatementMapping("ACTION_SEARCH", actionStatement);
// Generic status messages
this.m_statusStatementMapping.put(Integer.toString(StatusData.STATUS_INVALID_PERMISSIONS), "You do not have the correct permissions, please contact an administrator. To view your permissions select the Help Menu > About > Who am I tab. ");
this.m_statusStatementMapping.put(Integer.toString(StatusData.STATUS_INVALID_REQUEST), "There was a problem with the information sent to the server, this is probably because some metadata was invalid (indicated by a red cross next to the invalid metadata). If all the metadata tabs for the resource have green ticks on them there is a problem with the metadata definiations and you should inform an administrator.");
this.m_statusStatementMapping.put(Integer.toString(StatusData.STATUS_COMMUNICATIONS_FAILURE), "There was a problem communicating with the server. Please check that you network connection is okay, if it is you should inform an administrator about this problem.");
this.m_statusStatementMapping.put(Integer.toString(StatusData.STATUS_RESOURCE_NOT_FOUND), "The resource was not found, it may have been archived or moved. Refresh the collection (System menu). If there is a still a problem you should inform a system adminstrator.");
this.m_statusStatementMapping.put(Integer.toString(StatusData.STATUS_INVALID_RESOURCE_STATE), "The state of the resource is not valid for this action. Refresh the collection. If there is a still a problem you should inform a system adminstrator.");
this.m_statusStatementMapping.put(Integer.toString(StatusData.STATUS_TIMEOUT), "The connection with the server timed out. Please check that you network connection is okay, if it is you should inform an administrator about this problem.");
this.m_statusStatementMapping.put(Integer.toString(StatusData.STATUS_SERVER_ERROR), "There was an error on the server. Please inform an administrator.");
this.m_statusStatementMapping.put(Integer.toString(StatusData.STATUS_RESOURCE_LOCKED), "The resource is already locked. Please contact the lock owner.");
this.m_statusStatementMapping.put(Integer.toString(StatusData.STATUS_REQUEST_CONDITIONS_NOT_MET), "The resource is already locked. Please contact the lock owner.");
this.m_statusStatementMapping.put(Integer.toString(StatusData.STATUS_OK), "");
this.m_statusStatementMapping.put(Integer.toString(StatusData.STATUS_RESOURCE_EXISTS), "A resource of this name already exists in the collection.");
// Action specific status messages
this.m_statusStatementMapping.put(ActionCopy.ACTION_NAME+"#"+Integer.toString(StatusData.STATUS_REQUEST_CONDITIONS_NOT_MET), "There is already a resource with that name in the destination collection.");
this.m_statusStatementMapping.put(ActionMove.ACTION_NAME+"#"+Integer.toString(StatusData.STATUS_REQUEST_CONDITIONS_NOT_MET), "Either the resource is locked by another user or there is already a resource with that name in the destination collection.");
this.m_statusStatementMapping.put(ActionRetrieve.ACTION_NAME+"#"+Integer.toString(StatusData.STATUS_REQUEST_CONDITIONS_NOT_MET), "There is already a resource with that name in the destination collection.");
this.m_statusStatementMapping.put(ActionNewCollection.ACTION_NAME+"#"+Integer.toString(StatusData.STATUS_INVALID_PERMISSIONS), "Either the collection you are in has never been published or you do not have permission to create collections here.");
this.m_statusStatementMapping.put(ActionNewFile.ACTION_NAME+"#"+Integer.toString(StatusData.STATUS_INVALID_PERMISSIONS), "Either the collection you are in has never been published or you do not have permission to create resources here.");
}
public static MessageBuilder getInstance() {
if(m_instance==null) {
m_instance = new VFSMessageBuilder();
}
return m_instance;
}
/* (non-Javadoc)
* @see com.simulacramedia.contentmanager.window.messages.builders.MessageBuilder#fireMessage(java.lang.String, java.lang.Object)
*/
public void fireMessage(String sActionName, Object statusInformation) {
StringBuffer sBuff = new StringBuffer();
String sMessageLevel = MessageHandler.TYPE_CONFIRM;
if(statusInformation!=null && !((StatusData)statusInformation).isOK()) {
sMessageLevel = MessageHandler.TYPE_ERROR;
}
sBuff.append( this.getActionStatement(sMessageLevel, sActionName) );
sBuff.append( this.buildStatusStatements(sActionName, (StatusData) statusInformation) );
System.out.println(sBuff.toString());
MessageHandler.getInstance().fireMessageEvent(sBuff.toString(), sMessageLevel);
}
/* (non-Javadoc)
* @see com.simulacramedia.contentmanager.window.messages.builders.MessageBuilder#fireMessage(java.lang.String, java.lang.Object, java.lang.String)
*/
public void fireMessage(String sActionName, Object statusInformation,
String sResourceTitle) {
StringBuffer sBuff = new StringBuffer();
String sMessageLevel = MessageHandler.TYPE_CONFIRM;
if(statusInformation!=null && !((StatusData)statusInformation).isOK()) {
sMessageLevel = MessageHandler.TYPE_ERROR;
}
sBuff.append( this.getActionStatement(sMessageLevel, sActionName, sResourceTitle) );
sBuff.append( this.buildStatusStatements(sActionName, (StatusData) statusInformation) );
System.out.println(sBuff.toString());
MessageHandler.getInstance().fireMessageEvent(sBuff.toString(), sMessageLevel);
}
/* (non-Javadoc)
* @see com.simulacramedia.contentmanager.window.messages.builders.MessageBuilder#fireMessage(java.lang.String, java.lang.String, java.lang.Object, java.lang.String, java.lang.String)
*/
public void fireMessage(String sActionName,
Object statusInformation, String sResourceTitle,
String sDestinationTitle) {
StringBuffer sBuff = new StringBuffer();
String sMessageLevel = MessageHandler.TYPE_CONFIRM;
if(statusInformation!=null && !((StatusData)statusInformation).isOK()) {
sMessageLevel = MessageHandler.TYPE_ERROR;
}
sBuff.append( this.getActionStatement(sMessageLevel, sActionName, sResourceTitle, sDestinationTitle) );
sBuff.append( this.buildStatusStatements(sActionName, (StatusData) statusInformation) );
System.out.println(sBuff.toString());
MessageHandler.getInstance().fireMessageEvent(sBuff.toString(), sMessageLevel);
}
/* (non-Javadoc)
* @see com.simulacramedia.contentmanager.window.messages.builders.MessageBuilder#fireMessage(com.simulacramedia.contentmanager.window.messages.builders.StatusMessage)
*/
public void fireMessage(StatusMessage statusMessage) {
if(statusMessage.getPath()==null) {
if(statusMessage.getResourceTitle()!=null && statusMessage.getDestinationTitle()!=null) {
this.fireMessage(statusMessage.getActionName(), statusMessage.getStatusInformation(), statusMessage.getResourceTitle(), statusMessage.getDestinationTitle());
} else if(statusMessage.getResourceTitle()!=null) {
this.fireMessage(statusMessage.getActionName(), statusMessage.getStatusInformation(), statusMessage.getResourceTitle());
} else {
this.fireMessage(statusMessage.getActionName(), statusMessage.getStatusInformation());
}
} else {
StringBuffer sBuff = new StringBuffer();
String sMessageLevel = MessageHandler.TYPE_CONFIRM;
if(statusMessage.getStatusInformation()!=null && !((StatusData)statusMessage.getStatusInformation()).isOK()) {
sMessageLevel = MessageHandler.TYPE_ERROR;
}
if(statusMessage.getResourceTitle()!=null && statusMessage.getDestinationTitle()!=null) {
sBuff.append( this.getActionStatement(sMessageLevel, statusMessage.getActionName(), statusMessage.getResourceTitle(), statusMessage.getDestinationTitle()) );
} else if(statusMessage.getResourceTitle()!=null) {
sBuff.append( this.getActionStatement(sMessageLevel, statusMessage.getActionName(), statusMessage.getResourceTitle()) );
} else {
sBuff.append( this.getActionStatement(sMessageLevel, statusMessage.getActionName()) );
}
if(statusMessage.getPath()!=null) {
sBuff.append( this.buildStatusStatements(statusMessage.getActionName(), (StatusData) statusMessage.getStatusInformation(), statusMessage.getPath()) );
} else {
sBuff.append( this.buildStatusStatements(statusMessage.getActionName(), (StatusData) statusMessage.getStatusInformation()) );
}
System.out.println(sBuff.toString());
MessageHandler.getInstance().fireMessageEvent(sBuff.toString(), sMessageLevel);
}
}
private StringBuffer buildStatusStatements(String sActionName, StatusData status, String sPath) {
StringBuffer sBuff = new StringBuffer();
ArrayList aCodes = new ArrayList();
List aWorstStatus = this.getWorstStatusData(status);
Iterator itor = aWorstStatus.iterator();
while (itor.hasNext()) {
StatusData element = (StatusData) itor.next();
aCodes.add(new Integer( element.getStatusCode() ));
}
if(sPath.startsWith(HarmonisePaths.PATH_USERS) && aCodes.contains(new Integer(StatusData.STATUS_INVALID_PERMISSIONS))) {
sBuff.append(" Either you do not have permission to do this, the user group you are in has never been published or there is another user with this name.");
} else if(sPath.startsWith(HarmonisePaths.PATH_PROPERTIES) && aCodes.contains(new Integer(StatusData.STATUS_INVALID_PERMISSIONS))) {
sBuff.append(" Either you do not have permission to do this, the property group you are in has never been published or there is another property with this name.");
} else if(sPath.startsWith(HarmonisePaths.PATH_WORKFLOW_STAGES) && aCodes.contains(new Integer(StatusData.STATUS_INVALID_PERMISSIONS))) {
sBuff.append(" Either there is a Workflow Stage in this collection (you cannot create a new collection if there is a Workflow Stage at the same level), you do not have permission to do this or the collection you are in has never been published.");
} else if(sActionName.equals(ActionPublishToInternet.ACTION_NAME) && sPath.startsWith(HarmonisePaths.PATH_WORKFLOW_PROPS) && aCodes.contains(new Integer(StatusData.STATUS_INVALID_RESOURCE_STATE))) {
sBuff.append(" This Workflow either has missing metadata or its Domain overlaps with that of another Workflow. This is not permitted, please ensure that Workflow Domains do not overlap.");
} else {
sBuff.append( this.buildStatusStatements(sActionName, status) );
}
return sBuff;
}
private StringBuffer buildStatusStatements(String sActionName, StatusData status) {
StringBuffer sBuff = new StringBuffer();
if(status!=null) {
sBuff.append(" ");
String sMessage = (String) this.m_statusStatementMapping.get(sActionName + "#" + Integer.toString(status.getStatusCode()));
if(sMessage==null) {
sMessage = (String) this.m_statusStatementMapping.get(Integer.toString(status.getStatusCode()));
}
if(sMessage!=null) {
sBuff.append(sMessage);
}
List aStatus = this.getWorstStatusData(status);
Iterator itor = aStatus.iterator();
while (itor.hasNext()) {
StatusData element = (StatusData) itor.next();
sBuff.append(" ");
sMessage = (String) this.m_statusStatementMapping.get(sActionName + "#" + Integer.toString(element.getStatusCode()));
if(sMessage==null) {
sMessage = (String) this.m_statusStatementMapping.get(Integer.toString(element.getStatusCode()));
}
sBuff.append(sMessage);
}
}
return sBuff;
}
private List getWorstStatusData(StatusData status) {
List aStatus = new ArrayList();
if(!status.isOK()) {
List tempStatus = status.getStatusData(status.getWorstLevel());
Iterator itor = tempStatus.iterator();
while(itor.hasNext()) {
StatusData tempStatusData = (StatusData) itor.next();
aStatus.addAll(this.getWorstStatusData(tempStatusData));
}
aStatus.addAll(tempStatus);
}
return aStatus;
}
public static void main(String[] args) {
StatusData status = new VFSStatusWebDAV();
StatusData status2 = new VFSStatusWebDAV(408);
((VFSStatusWebDAV)status).addStatusData(status2);
StatusData status3 = new VFSStatusWebDAV(409);
((VFSStatusWebDAV)status).addStatusData(status3);
VFSMessageBuilder.getInstance().fireMessage(ActionOrder.ACTION_NAME, status);
status = new VFSStatusWebDAV();
VFSMessageBuilder.getInstance().fireMessage(ActionOrder.ACTION_NAME, status, "Matt Col");
status = new VFSStatusWebDAV();
status2 = new VFSStatusWebDAV(401);
((VFSStatusWebDAV)status).addStatusData(status2);
status3 = new VFSStatusWebDAV(402);
((VFSStatusWebDAV)status).addStatusData(status3);
VFSMessageBuilder.getInstance().fireMessage(ActionOrder.ACTION_NAME, status, "Matt Col");
status = new VFSStatusWebDAV();
status2 = new VFSStatusWebDAV(401);
((VFSStatusWebDAV)status).addStatusData(status2);
status3 = new VFSStatusWebDAV(402);
((VFSStatusWebDAV)status).addStatusData(status3);
VFSMessageBuilder.getInstance().fireMessage(ActionCopy.ACTION_NAME, status, "resource1", "col2");
VFSMessageBuilder.getInstance().fireMessage(ActionMove.ACTION_NAME, null, "resource1", "col2");
}
}
|