public void copy(Document destination, String newName) throws MappingException, RemoteException, WorkflowException, RepositoryException {
ReviewedActionsWorkflowImpl.log.info("copy document");
if (newName == null || newName.equals("")) {
throw new WorkflowException("missing required name to copy document");
}
if(publishedDocument == null && unpublishedDocument == null)
throw new WorkflowException("cannot copy unsaved document");
String folderWorkflowCategory = "embedded";
RepositoryMap config = getWorkflowContext().getWorkflowConfiguration();
if (config != null && config.exists() && config.get("folder-workflow-category") instanceof String) {
folderWorkflowCategory = (String) config.get("folder-workflow-category");
}
if (unpublishedDocument == null) {
Document folder = getWorkflowContext().getDocument("embedded", publishedDocument.getIdentity());
Workflow workflow = getWorkflowContext(null).getWorkflow(folderWorkflowCategory, destination);
if (workflow instanceof EmbedWorkflow) {
Document copy = ((EmbedWorkflow)workflow).copyTo(folder, publishedDocument, newName, null);
FullReviewedActionsWorkflow copiedDocumentWorkflow = (FullReviewedActionsWorkflow) getWorkflowContext(null).getWorkflow("default", copy);
copiedDocumentWorkflow.depublish();
} else
throw new WorkflowException("cannot copy document which is not contained in a folder");
} else {
Document folder = getWorkflowContext().getDocument("embedded", unpublishedDocument.getIdentity());
Workflow workflow = getWorkflowContext().getWorkflow(folderWorkflowCategory, destination);
if(workflow instanceof EmbedWorkflow)
((EmbedWorkflow)workflow).copyTo(folder, unpublishedDocument, newName, null);
else
throw new WorkflowException("cannot copy document which is not contained in a folder");
}
}