mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
Next phase of forums functionality
Simple dialog framework implementation git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2056 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version
|
||||
* 2.1 of the License, or (at your option) any later version.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.gnu.org/licenses/lgpl.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
package org.alfresco.web.bean.wizard;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.faces.event.ActionEvent;
|
||||
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.Application;
|
||||
import org.alfresco.web.bean.repository.Repository;
|
||||
import org.alfresco.web.ui.common.Utils;
|
||||
import org.alfresco.web.ui.common.component.UIActionLink;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
/**
|
||||
* Backing bean class used to create discussions for documents
|
||||
*
|
||||
* @author gavinc
|
||||
*/
|
||||
public class NewDiscussionWizard extends NewTopicWizard
|
||||
{
|
||||
private static final Log logger = LogFactory.getLog(NewDiscussionWizard.class);
|
||||
|
||||
private NodeRef discussingNodeRef;
|
||||
|
||||
/**
|
||||
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#startWizard(javax.faces.event.ActionEvent)
|
||||
*/
|
||||
@Override
|
||||
public void startWizard(ActionEvent event)
|
||||
{
|
||||
UIActionLink link = (UIActionLink)event.getComponent();
|
||||
Map<String, String> params = link.getParameterMap();
|
||||
String id = params.get("id");
|
||||
if (id == null || id.length() == 0)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("startDiscussion called without an 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("startDiscussion 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_large");
|
||||
this.nodeService.addAspect(forumNodeRef, ContentModel.ASPECT_UIFACETS, uiFacetsProps);
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("created forum for content: " + forumNodeRef.toString());
|
||||
|
||||
// commit the transaction
|
||||
tx.commit();
|
||||
}
|
||||
catch (Exception 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);
|
||||
|
||||
// now initialise the wizard and navigate to it
|
||||
super.startWizard(event);
|
||||
context.getApplication().getNavigationHandler().handleNavigation(context, null, "dialog:createDiscussion");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -17,12 +17,8 @@
|
||||
*/
|
||||
package org.alfresco.web.bean.wizard;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.faces.context.FacesContext;
|
||||
|
||||
import org.alfresco.model.ForumModel;
|
||||
import org.alfresco.web.ui.common.component.UIListItem;
|
||||
import org.alfresco.web.app.AlfrescoNavigationHandler;
|
||||
|
||||
/**
|
||||
* Wizard bean used for creating and editing forum spaces
|
||||
@@ -31,30 +27,6 @@ import org.alfresco.web.ui.common.component.UIListItem;
|
||||
*/
|
||||
public class NewForumWizard extends NewSpaceWizard
|
||||
{
|
||||
protected String forumStatus;
|
||||
|
||||
protected List<UIListItem> forumIcons;
|
||||
|
||||
/**
|
||||
* Returns the status of the forum
|
||||
*
|
||||
* @return The status of the forum
|
||||
*/
|
||||
public String getForumStatus()
|
||||
{
|
||||
return this.forumStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the status of the forum
|
||||
*
|
||||
* @param forumStatus The status
|
||||
*/
|
||||
public void setForumStatus(String forumStatus)
|
||||
{
|
||||
this.forumStatus = forumStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#init()
|
||||
*/
|
||||
@@ -63,15 +35,27 @@ public class NewForumWizard extends NewSpaceWizard
|
||||
super.init();
|
||||
|
||||
this.spaceType = ForumModel.TYPE_FORUM.toString();
|
||||
this.forumStatus = "0";
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#finish()
|
||||
*/
|
||||
@Override
|
||||
public String finish()
|
||||
{
|
||||
super.finish();
|
||||
|
||||
return AlfrescoNavigationHandler.CLOSE_DIALOG_OUTCOME;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.web.bean.wizard.NewSpaceWizard#performCustomProcessing(javax.faces.context.FacesContext)
|
||||
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#cancel()
|
||||
*/
|
||||
@Override
|
||||
protected void performCustomProcessing(FacesContext context)
|
||||
public String cancel()
|
||||
{
|
||||
// add or update the ForumModel.PROP_STATUS property depending on the editMode
|
||||
super.cancel();
|
||||
|
||||
return AlfrescoNavigationHandler.CLOSE_DIALOG_OUTCOME;
|
||||
}
|
||||
}
|
||||
|
@@ -17,10 +17,8 @@
|
||||
*/
|
||||
package org.alfresco.web.bean.wizard;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.model.ForumModel;
|
||||
import org.alfresco.web.ui.common.component.UIListItem;
|
||||
import org.alfresco.web.app.AlfrescoNavigationHandler;
|
||||
|
||||
/**
|
||||
* Wizard bean used for creating and editing forums spaces
|
||||
@@ -29,8 +27,6 @@ import org.alfresco.web.ui.common.component.UIListItem;
|
||||
*/
|
||||
public class NewForumsWizard extends NewSpaceWizard
|
||||
{
|
||||
protected List<UIListItem> forumsIcons;
|
||||
|
||||
/**
|
||||
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#init()
|
||||
*/
|
||||
@@ -40,4 +36,26 @@ public class NewForumsWizard extends NewSpaceWizard
|
||||
|
||||
this.spaceType = ForumModel.TYPE_FORUMS.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#finish()
|
||||
*/
|
||||
@Override
|
||||
public String finish()
|
||||
{
|
||||
super.finish();
|
||||
|
||||
return AlfrescoNavigationHandler.CLOSE_DIALOG_OUTCOME;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#cancel()
|
||||
*/
|
||||
@Override
|
||||
public String cancel()
|
||||
{
|
||||
super.cancel();
|
||||
|
||||
return AlfrescoNavigationHandler.CLOSE_DIALOG_OUTCOME;
|
||||
}
|
||||
}
|
||||
|
@@ -25,6 +25,8 @@ import org.alfresco.model.ForumModel;
|
||||
import org.alfresco.service.cmr.repository.ContentReader;
|
||||
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||
import org.alfresco.util.GUID;
|
||||
import org.alfresco.web.app.AlfrescoNavigationHandler;
|
||||
import org.alfresco.web.bean.ForumsBean;
|
||||
import org.alfresco.web.bean.repository.Node;
|
||||
import org.alfresco.web.bean.repository.Repository;
|
||||
import org.alfresco.web.ui.common.Utils;
|
||||
@@ -56,7 +58,8 @@ public class NewPostWizard extends CreateContentWizard
|
||||
public void startWizardForEdit(ActionEvent event)
|
||||
{
|
||||
// TODO: Allow action link to have multiple action listeners
|
||||
// then we wouldn't need to have this coupling in here
|
||||
// then we wouldn't need to have this coupling back
|
||||
// to the browse bean in here
|
||||
|
||||
// we need to setup the content in the browse bean first
|
||||
this.browseBean.setupContentAction(event);
|
||||
@@ -101,17 +104,18 @@ public class NewPostWizard extends CreateContentWizard
|
||||
}
|
||||
else
|
||||
{
|
||||
// create appropriate values for filename, title and content type
|
||||
this.fileName = GUID.generate() + ".html";
|
||||
// create appropriate values for filename and content type
|
||||
this.fileName = ForumsBean.createPostFileName();
|
||||
this.contentType = Repository.getMimeTypeForFileName(
|
||||
FacesContext.getCurrentInstance(), this.fileName);
|
||||
this.title = this.fileName;
|
||||
|
||||
// remove link breaks and replace with <br/>
|
||||
this.content = Utils.replaceLineBreaks(this.content);
|
||||
}
|
||||
|
||||
return super.finish();
|
||||
super.finish();
|
||||
|
||||
return AlfrescoNavigationHandler.CLOSE_DIALOG_OUTCOME;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -120,16 +124,28 @@ public class NewPostWizard extends CreateContentWizard
|
||||
@Override
|
||||
protected void performCustomProcessing()
|
||||
{
|
||||
// update the content
|
||||
Node currentDocument = this.browseBean.getDocument();
|
||||
|
||||
ContentWriter writer = this.contentService.getWriter(currentDocument.getNodeRef(),
|
||||
ContentModel.PROP_CONTENT, true);
|
||||
if (writer != null)
|
||||
if (this.editMode)
|
||||
{
|
||||
writer.putContent(this.content);
|
||||
// update the content
|
||||
Node currentDocument = this.browseBean.getDocument();
|
||||
|
||||
ContentWriter writer = this.contentService.getWriter(currentDocument.getNodeRef(),
|
||||
ContentModel.PROP_CONTENT, true);
|
||||
if (writer != null)
|
||||
{
|
||||
writer.putContent(this.content);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#cancel()
|
||||
*/
|
||||
@Override
|
||||
public String cancel()
|
||||
{
|
||||
super.cancel();
|
||||
|
||||
return AlfrescoNavigationHandler.CLOSE_DIALOG_OUTCOME;
|
||||
}
|
||||
}
|
||||
|
@@ -20,6 +20,7 @@ package org.alfresco.web.bean.wizard;
|
||||
import javax.faces.event.ActionEvent;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.web.app.AlfrescoNavigationHandler;
|
||||
import org.alfresco.web.ui.common.Utils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
@@ -55,7 +56,9 @@ public class NewReplyWizard extends NewPostWizard
|
||||
// remove link breaks and replace with <br/>
|
||||
this.content = Utils.replaceLineBreaks(this.content);
|
||||
|
||||
return super.finish();
|
||||
super.finish();
|
||||
|
||||
return AlfrescoNavigationHandler.CLOSE_DIALOG_OUTCOME;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -79,4 +82,15 @@ public class NewReplyWizard extends NewPostWizard
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#cancel()
|
||||
*/
|
||||
@Override
|
||||
public String cancel()
|
||||
{
|
||||
super.cancel();
|
||||
|
||||
return AlfrescoNavigationHandler.CLOSE_DIALOG_OUTCOME;
|
||||
}
|
||||
}
|
||||
|
@@ -80,10 +80,10 @@ public class NewSpaceWizard extends AbstractWizardBean
|
||||
private static final String DEFAULT_SPACE_TYPE_ICON = "/images/icons/space.gif";
|
||||
|
||||
// new space wizard specific properties
|
||||
private SearchService searchService;
|
||||
private NamespaceService namespaceService;
|
||||
private DictionaryService dictionaryService;
|
||||
private ConfigService configService;
|
||||
protected SearchService searchService;
|
||||
protected NamespaceService namespaceService;
|
||||
protected DictionaryService dictionaryService;
|
||||
protected ConfigService configService;
|
||||
|
||||
protected String spaceType;
|
||||
protected String icon;
|
||||
@@ -996,7 +996,7 @@ public class NewSpaceWizard extends AbstractWizardBean
|
||||
*
|
||||
* @param context Faces context
|
||||
*/
|
||||
protected void performCustomProcessing(FacesContext context)
|
||||
protected void performCustomProcessing(FacesContext context) throws Exception
|
||||
{
|
||||
// used by subclasses if necessary
|
||||
}
|
||||
|
@@ -18,26 +18,22 @@
|
||||
package org.alfresco.web.bean.wizard;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.faces.model.SelectItem;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.model.ForumModel;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
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.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.GUID;
|
||||
import org.alfresco.web.app.AlfrescoNavigationHandler;
|
||||
import org.alfresco.web.bean.ForumsBean;
|
||||
import org.alfresco.web.bean.repository.Repository;
|
||||
import org.alfresco.web.ui.common.Utils;
|
||||
import org.alfresco.web.ui.common.component.UIListItem;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
@@ -51,51 +47,8 @@ public class NewTopicWizard extends NewSpaceWizard
|
||||
private static final Log logger = LogFactory.getLog(NewTopicWizard.class);
|
||||
|
||||
protected String message;
|
||||
protected String topicType;
|
||||
protected List<UIListItem> topicIcons;
|
||||
protected List<SelectItem> topicTypes;
|
||||
|
||||
protected ContentService contentService;
|
||||
|
||||
/**
|
||||
* Returns a list of topic types for the user to select from
|
||||
*
|
||||
* @return The topic types
|
||||
*/
|
||||
public List<SelectItem> getTopicTypes()
|
||||
{
|
||||
if (this.topicTypes == null)
|
||||
{
|
||||
this.topicTypes = new ArrayList<SelectItem>(3);
|
||||
|
||||
// TODO: change this to be based on categories
|
||||
this.topicTypes.add(new SelectItem("1", "Announcement"));
|
||||
this.topicTypes.add(new SelectItem("0", "Normal"));
|
||||
this.topicTypes.add(new SelectItem("2", "Sticky"));
|
||||
}
|
||||
|
||||
return this.topicTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the type of the topic
|
||||
*
|
||||
* @return The type of topic
|
||||
*/
|
||||
public String getTopicType()
|
||||
{
|
||||
return this.topicType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the type of the topic
|
||||
*
|
||||
* @param topicType The type of the topic
|
||||
*/
|
||||
public void setTopicType(String topicType)
|
||||
{
|
||||
this.topicType = topicType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the message entered by the user for the first post
|
||||
@@ -133,7 +86,6 @@ public class NewTopicWizard extends NewSpaceWizard
|
||||
super.init();
|
||||
|
||||
this.spaceType = ForumModel.TYPE_TOPIC.toString();
|
||||
this.topicType = "0";
|
||||
this.message = null;
|
||||
}
|
||||
|
||||
@@ -141,34 +93,19 @@ public class NewTopicWizard extends NewSpaceWizard
|
||||
* @see org.alfresco.web.bean.wizard.NewSpaceWizard#performCustomProcessing(javax.faces.context.FacesContext)
|
||||
*/
|
||||
@Override
|
||||
protected void performCustomProcessing(FacesContext context)
|
||||
protected void performCustomProcessing(FacesContext context) throws Exception
|
||||
{
|
||||
if (this.editMode == false)
|
||||
{
|
||||
// *************************
|
||||
// TODO: Add or update the ForumModel.PROP_TYPE property depending on the editMode
|
||||
// *************************
|
||||
|
||||
// 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 = GUID.generate() + ".txt";
|
||||
String fileName = ForumsBean.createPostFileName();
|
||||
|
||||
// create properties for content type
|
||||
Map<QName, Serializable> contentProps = new HashMap<QName, Serializable>(5, 1.0f);
|
||||
contentProps.put(ContentModel.PROP_NAME, fileName);
|
||||
|
||||
// create the node to represent the content
|
||||
String assocName = QName.createValidLocalName(fileName);
|
||||
ChildAssociationRef assocRef = this.nodeService.createNode(
|
||||
containerNodeRef,
|
||||
ContentModel.ASSOC_CONTAINS,
|
||||
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, assocName),
|
||||
Repository.resolveToQName(ForumModel.TYPE_POST.toString()),
|
||||
contentProps);
|
||||
|
||||
NodeRef postNodeRef = assocRef.getChildRef();
|
||||
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);
|
||||
@@ -196,4 +133,26 @@ public class NewTopicWizard extends NewSpaceWizard
|
||||
writer.putContent(Utils.replaceLineBreaks(this.message));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#finish()
|
||||
*/
|
||||
@Override
|
||||
public String finish()
|
||||
{
|
||||
super.finish();
|
||||
|
||||
return AlfrescoNavigationHandler.CLOSE_DIALOG_OUTCOME;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#cancel()
|
||||
*/
|
||||
@Override
|
||||
public String cancel()
|
||||
{
|
||||
super.cancel();
|
||||
|
||||
return AlfrescoNavigationHandler.CLOSE_DIALOG_OUTCOME;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user