- Fixed regression in rules wizards

- Added title to create/edit space dialogs
- Changed space dialogs to use required field icon
- Converted all forums and removed all old legacy beans and JSPs

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2903 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Gavin Cornwell
2006-05-16 21:27:22 +00:00
parent 76c566db61
commit e8457fe8f4
55 changed files with 1120 additions and 5470 deletions

View File

@@ -0,0 +1,171 @@
package org.alfresco.web.bean.forums;
import java.io.Serializable;
import java.text.MessageFormat;
import java.util.HashMap;
import java.util.Map;
import javax.faces.context.FacesContext;
import javax.transaction.UserTransaction;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
import org.alfresco.model.ForumModel;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
import org.alfresco.web.app.AlfrescoNavigationHandler;
import org.alfresco.web.app.Application;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.ui.common.Utils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Bean implementation for the "Create Discusssion Dialog".
*
* @author gavinc
*/
public class CreateDiscussionDialog extends CreateTopicDialog
{
protected NodeRef discussingNodeRef;
private static final Log logger = LogFactory.getLog(CreateDiscussionDialog.class);
// ------------------------------------------------------------------------------
// Wizard implementation
@Override
public void init(Map<String, String> parameters)
{
super.init(parameters);
// get the id of the node we are creating the discussion for
String id = parameters.get("id");
if (id == null || id.length() == 0)
{
throw new AlfrescoRuntimeException("createDiscussion called without an id");
}
// create the topic to hold the discussions
createTopic(id);
}
@Override
public String cancel()
{
// if the user cancels the creation of a discussion all the setup that was done
// when the dialog started needs to be undone i.e. removing the created forum
// and the discussable aspect
deleteTopic();
// as we are cancelling the creation of a discussion we know we need to go back
// to the browse screen, this also makes sure we don't end up in the forum that
// just got deleted!
return AlfrescoNavigationHandler.CLOSE_DIALOG_OUTCOME +
AlfrescoNavigationHandler.OUTCOME_SEPARATOR + "browse";
}
// ------------------------------------------------------------------------------
// Helper methods
/**
* Creates a topic for the node with the given id
*
* @param id The id of the node to discuss
*/
protected void createTopic(String id)
{
FacesContext context = FacesContext.getCurrentInstance();
UserTransaction tx = null;
NodeRef forumNodeRef = null;
try
{
tx = Repository.getUserTransaction(context);
tx.begin();
this.discussingNodeRef = new NodeRef(Repository.getStoreRef(), id);
if (this.nodeService.hasAspect(this.discussingNodeRef, ForumModel.ASPECT_DISCUSSABLE))
{
throw new AlfrescoRuntimeException("createDiscussion called for an object that already has a discussion!");
}
// add the discussable aspect
this.nodeService.addAspect(this.discussingNodeRef, ForumModel.ASPECT_DISCUSSABLE, null);
// create a child forum space using the child association just introduced by
// adding the discussable aspect
String name = (String)this.nodeService.getProperty(this.discussingNodeRef,
ContentModel.PROP_NAME);
String msg = Application.getMessage(FacesContext.getCurrentInstance(), "discussion_for");
String forumName = MessageFormat.format(msg, new Object[] {name});
Map<QName, Serializable> forumProps = new HashMap<QName, Serializable>(1);
forumProps.put(ContentModel.PROP_NAME, forumName);
ChildAssociationRef childRef = this.nodeService.createNode(this.discussingNodeRef,
ForumModel.ASSOC_DISCUSSION,
QName.createQName(ForumModel.FORUMS_MODEL_URI, "discussion"),
ForumModel.TYPE_FORUM, forumProps);
forumNodeRef = childRef.getChildRef();
// apply the uifacets aspect
Map<QName, Serializable> uiFacetsProps = new HashMap<QName, Serializable>(5);
uiFacetsProps.put(ContentModel.PROP_ICON, "forum");
this.nodeService.addAspect(forumNodeRef, ContentModel.ASPECT_UIFACETS, uiFacetsProps);
if (logger.isDebugEnabled())
logger.debug("created forum for content: " + this.discussingNodeRef.toString());
// commit the transaction
tx.commit();
}
catch (Throwable e)
{
// rollback the transaction
try { if (tx != null) {tx.rollback();} } catch (Exception ex) {}
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(
context, Repository.ERROR_GENERIC), e.getMessage()), e);
}
// finally setup the context for the forum we just created
if (forumNodeRef != null)
{
this.browseBean.clickSpace(forumNodeRef);
}
}
/**
* Deletes the setup performed during the initialisation of the dialog.
*/
protected void deleteTopic()
{
FacesContext context = FacesContext.getCurrentInstance();
UserTransaction tx = null;
try
{
tx = Repository.getUserTransaction(context);
tx.begin();
// remove the discussable aspect from the node we were going to discuss!
this.nodeService.removeAspect(this.discussingNodeRef, ForumModel.ASPECT_DISCUSSABLE);
// delete the forum space created when the wizard started
this.browseBean.setActionSpace(this.navigator.getCurrentNode());
this.browseBean.deleteSpaceOK();
// commit the transaction
tx.commit();
}
catch (Throwable e)
{
// rollback the transaction
try { if (tx != null) {tx.rollback();} } catch (Exception ex) {}
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(
context, Repository.ERROR_GENERIC), e.getMessage()), e);
}
}
}

View File

@@ -0,0 +1,34 @@
package org.alfresco.web.bean.forums;
import java.util.Map;
import javax.faces.context.FacesContext;
import org.alfresco.model.ForumModel;
import org.alfresco.web.app.Application;
import org.alfresco.web.bean.spaces.CreateSpaceDialog;
/**
* Bean used to implement the "Create Forum Dialog".
*
* @author gavinc
*/
public class CreateForumDialog extends CreateSpaceDialog
{
// ------------------------------------------------------------------------------
// Wizard implementation
@Override
public void init(Map<String, String> parameters)
{
super.init(parameters);
this.spaceType = ForumModel.TYPE_FORUM.toString();
}
@Override
public String getFinishButtonLabel()
{
return Application.getMessage(FacesContext.getCurrentInstance(), "create_forum");
}
}

View File

@@ -0,0 +1,34 @@
package org.alfresco.web.bean.forums;
import java.util.Map;
import javax.faces.context.FacesContext;
import org.alfresco.model.ForumModel;
import org.alfresco.web.app.Application;
import org.alfresco.web.bean.spaces.CreateSpaceDialog;
/**
* Bean used to implement the "Create Forums Dialog".
*
* @author gavinc
*/
public class CreateForumsDialog extends CreateSpaceDialog
{
// ------------------------------------------------------------------------------
// Wizard implementation
@Override
public void init(Map<String, String> parameters)
{
super.init(parameters);
this.spaceType = ForumModel.TYPE_FORUMS.toString();
}
@Override
public String getFinishButtonLabel()
{
return Application.getMessage(FacesContext.getCurrentInstance(), "create_forums");
}
}

View File

@@ -0,0 +1,54 @@
package org.alfresco.web.bean.forums;
import java.util.Map;
import javax.faces.context.FacesContext;
import org.alfresco.model.ForumModel;
import org.alfresco.web.app.Application;
import org.alfresco.web.bean.content.CreateContentWizard;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.ui.common.Utils;
/**
* Bean implementation of the "New Post Dialog".
*
* @author gavinc
*/
public class CreatePostDialog extends CreateContentWizard
{
// ------------------------------------------------------------------------------
// Wizard implementation
@Override
public void init(Map<String, String> parameters)
{
super.init(parameters);
// set up for creating a post
this.objectType = ForumModel.TYPE_POST.toString();
// make sure we don't show the edit properties dialog after creation
this.showOtherProperties = false;
}
@Override
protected String finishImpl(FacesContext context, String outcome) throws Exception
{
// create appropriate values for filename and content type
this.fileName = ForumsBean.createPostFileName();
this.mimeType = Repository.getMimeTypeForFileName(
FacesContext.getCurrentInstance(), this.fileName);
// remove link breaks and replace with <br/>
this.content = Utils.replaceLineBreaks(this.content);
return super.finishImpl(context, outcome);
}
@Override
public String getFinishButtonLabel()
{
return Application.getMessage(FacesContext.getCurrentInstance(), "post");
}
}

View File

@@ -0,0 +1,93 @@
package org.alfresco.web.bean.forums;
import java.util.Map;
import javax.faces.context.FacesContext;
import org.alfresco.model.ContentModel;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.web.app.Application;
import org.alfresco.web.ui.common.Utils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Bean implementation of the "Create Reply Dialog".
*
* @author gavinc
*/
public class CreateReplyDialog extends CreatePostDialog
{
protected String replyContent = null;
private static final Log logger = LogFactory.getLog(CreateReplyDialog.class);
// ------------------------------------------------------------------------------
// Wizard implementation
@Override
public void init(Map<String, String> parameters)
{
super.init(parameters);
this.replyContent = null;
}
@Override
protected String finishImpl(FacesContext context, String outcome) throws Exception
{
// remove link breaks and replace with <br/>
this.content = Utils.replaceLineBreaks(this.content);
super.finishImpl(context, outcome);
// setup the referencing aspect with the references association
// between the new post and the one being replied to
this.nodeService.addAspect(this.createdNode, ContentModel.ASPECT_REFERENCING, null);
this.nodeService.createAssociation(this.createdNode, this.browseBean.getDocument().getNodeRef(),
ContentModel.ASSOC_REFERENCES);
if (logger.isDebugEnabled())
{
logger.debug("created new node: " + this.createdNode);
logger.debug("existing node: " + this.browseBean.getDocument().getNodeRef());
}
return outcome;
}
@Override
public String getFinishButtonLabel()
{
return Application.getMessage(FacesContext.getCurrentInstance(), "reply");
}
// ------------------------------------------------------------------------------
// Bean Getters and Setters
/**
* Returns the content of the post we are replying to
*
* @return The content
*/
public String getReplyContent()
{
if (this.replyContent == null)
{
// get the content reader of the node we are replying to
NodeRef replyNode = this.browseBean.getDocument().getNodeRef();
if (replyNode != null)
{
ContentReader reader = this.contentService.getReader(replyNode, ContentModel.PROP_CONTENT);
if (reader != null)
{
this.replyContent = reader.getContentString();
}
}
}
return this.replyContent;
}
}

View File

@@ -0,0 +1,143 @@
package org.alfresco.web.bean.forums;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import javax.faces.context.FacesContext;
import org.alfresco.model.ContentModel;
import org.alfresco.model.ForumModel;
import org.alfresco.service.cmr.model.FileInfo;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
import org.alfresco.web.app.AlfrescoNavigationHandler;
import org.alfresco.web.app.Application;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.bean.spaces.CreateSpaceDialog;
import org.alfresco.web.ui.common.Utils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Bean implementation of the "Create Topic Dialog".
*
* @author gavinc
*/
public class CreateTopicDialog extends CreateSpaceDialog
{
protected String message;
protected ContentService contentService;
private static final Log logger = LogFactory.getLog(CreateTopicDialog.class);
// ------------------------------------------------------------------------------
// Wizard implementation
@Override
public void init(Map<String, String> parameters)
{
super.init(parameters);
this.spaceType = ForumModel.TYPE_TOPIC.toString();
this.message = null;
}
@Override
protected String finishImpl(FacesContext context, String outcome) throws Exception
{
super.finishImpl(context, outcome);
// do topic specific processing
// get the node ref of the node that will contain the content
NodeRef containerNodeRef = this.createdNode;
// create a unique file name for the message content
String fileName = ForumsBean.createPostFileName();
FileInfo fileInfo = this.fileFolderService.create(containerNodeRef,
fileName, ForumModel.TYPE_POST);
NodeRef postNodeRef = fileInfo.getNodeRef();
if (logger.isDebugEnabled())
logger.debug("Created post node with filename: " + fileName);
// apply the titled aspect - title and description
Map<QName, Serializable> titledProps = new HashMap<QName, Serializable>(3, 1.0f);
titledProps.put(ContentModel.PROP_TITLE, fileName);
this.nodeService.addAspect(postNodeRef, ContentModel.ASPECT_TITLED, titledProps);
if (logger.isDebugEnabled())
logger.debug("Added titled aspect with properties: " + titledProps);
Map<QName, Serializable> editProps = new HashMap<QName, Serializable>(1, 1.0f);
editProps.put(ContentModel.PROP_EDITINLINE, true);
this.nodeService.addAspect(postNodeRef, ContentModel.ASPECT_INLINEEDITABLE, editProps);
if (logger.isDebugEnabled())
logger.debug("Added inlineeditable aspect with properties: " + editProps);
// get a writer for the content and put the file
ContentWriter writer = contentService.getWriter(postNodeRef, ContentModel.PROP_CONTENT, true);
// set the mimetype and encoding
writer.setMimetype(Repository.getMimeTypeForFileName(context, fileName));
writer.setEncoding("UTF-8");
writer.putContent(Utils.replaceLineBreaks(this.message));
return outcome;
}
@Override
protected String doPostCommitProcessing(FacesContext context, String outcome)
{
// if the creation was successful we need to simulate a user
// selecting the topic, the dispatching will take us to the
// correct view.
this.browseBean.clickSpace(this.createdNode);
return outcome + AlfrescoNavigationHandler.OUTCOME_SEPARATOR + "showTopic";
}
@Override
public String getFinishButtonLabel()
{
return Application.getMessage(FacesContext.getCurrentInstance(), "create_topic");
}
// ------------------------------------------------------------------------------
// Bean Getters and Setters
/**
* Returns the message entered by the user for the first post
*
* @return The message for the first post
*/
public String getMessage()
{
return this.message;
}
/**
* Sets the message
*
* @param message The message
*/
public void setMessage(String message)
{
this.message = message;
}
// ------------------------------------------------------------------------------
// Service Injection
/**
* @param contentService The contentService to set.
*/
public void setContentService(ContentService contentService)
{
this.contentService = contentService;
}
}

View File

@@ -0,0 +1,82 @@
package org.alfresco.web.bean.forums;
import java.util.Map;
import javax.faces.context.FacesContext;
import org.alfresco.model.ContentModel;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.web.app.Application;
import org.alfresco.web.bean.repository.Node;
import org.alfresco.web.ui.common.Utils;
import org.springframework.util.StringUtils;
/**
* Bean implementation for the "Edit Post Dialog".
*
* @author gavinc
*/
public class EditPostDialog extends CreatePostDialog
{
// ------------------------------------------------------------------------------
// Wizard implementation
@Override
public void init(Map<String, String> parameters)
{
super.init(parameters);
// we need to remove the <br> tags and replace with carriage returns
// and then setup the content member variable
Node currentDocument = this.browseBean.getDocument();
ContentReader reader = this.contentService.getReader(currentDocument.getNodeRef(),
ContentModel.PROP_CONTENT);
if (reader != null)
{
String htmlContent = reader.getContentString();
if (htmlContent != null)
{
this.content = StringUtils.replace(htmlContent, "<br/>", "\r\n");
}
}
}
@Override
protected String finishImpl(FacesContext context, String outcome) throws Exception
{
// remove link breaks and replace with <br/>
this.content = Utils.replaceLineBreaks(this.content);
// update the content
NodeRef postNode = this.browseBean.getDocument().getNodeRef();
// check that the name of this post does not contain the :
// character (used in previous versions), if it does rename
// the post.
String name = (String)this.nodeService.getProperty(
postNode, ContentModel.PROP_NAME);
if (name.indexOf(":") != -1)
{
String newName = name.replace(':', '-');
this.fileFolderService.rename(postNode, newName);
}
ContentWriter writer = this.contentService.getWriter(postNode,
ContentModel.PROP_CONTENT, true);
if (writer != null)
{
writer.putContent(this.content);
}
return outcome;
}
@Override
public String getFinishButtonLabel()
{
return Application.getMessage(FacesContext.getCurrentInstance(), "ok");
}
}

File diff suppressed because it is too large Load Diff