Moving to root below branch label

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2005 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2005-12-08 07:13:07 +00:00
commit d051d1153c
920 changed files with 98871 additions and 0 deletions

View File

@@ -0,0 +1,314 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.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 javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import org.alfresco.service.cmr.model.FileFolderService;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.search.SearchService;
import org.alfresco.web.app.Application;
import org.alfresco.web.app.context.UIContextService;
import org.alfresco.web.bean.BrowseBean;
import org.alfresco.web.bean.NavigationBean;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Abstract bean used as the base class for all wizard backing beans.
*
* @author gavinc
*/
public abstract class AbstractWizardBean
{
private static Log logger = LogFactory.getLog(AbstractWizardBean.class);
/** I18N messages */
private static final String MSG_NOT_SET = "value_not_set";
protected static final String FINISH_OUTCOME = "finish";
protected static final String CANCEL_OUTCOME = "cancel";
protected static final String DEFAULT_INSTRUCTION_ID = "default_instruction";
protected static final String SUMMARY_TITLE_ID = "summary";
protected static final String SUMMARY_DESCRIPTION_ID = "summary_desc";
// common wizard properties
protected int currentStep = 1;
protected boolean editMode = false;
protected NodeService nodeService;
protected FileFolderService fileFolderService;
protected SearchService searchService;
protected NavigationBean navigator;
protected BrowseBean browseBean;
/**
* @return Returns the wizard description
*/
public abstract String getWizardDescription();
/**
* @return Returns the wizard title
*/
public abstract String getWizardTitle();
/**
* @return Returns the title for the current step
*/
public abstract String getStepTitle();
/**
* @return Returns the description for the current step
*/
public abstract String getStepDescription();
/**
* @return Returns the instructional text for the current step
*/
public abstract String getStepInstructions();
/**
* Determines the outcome string for the given step number
*
* @param step The step number to get the outcome for
* @return The outcome
*/
protected abstract String determineOutcomeForStep(int step);
/**
* Handles the finish button being pressed
*
* @return The finish outcome
*/
public abstract String finish();
/**
* Action listener called when the wizard is being launched allowing
* state to be setup
*/
public void startWizard(ActionEvent event)
{
// refresh the UI, calling this method now is fine as it basically makes sure certain
// beans clear the state - so when we finish the wizard other beans will have been reset
UIContextService.getInstance(FacesContext.getCurrentInstance()).notifyBeans();
// make sure the wizard is not in edit mode
this.editMode = false;
// initialise the wizard in case we are launching
// after it was navigated away from
init();
if (logger.isDebugEnabled())
logger.debug("Started wizard : " + getWizardTitle());
}
/**
* Action listener called when the wizard is being launched for
* editing an existing node.
*/
public void startWizardForEdit(ActionEvent event)
{
// refresh the UI, calling this method now is fine as it basically makes sure certain
// beans clear the state - so when we finish the wizard other beans will have been reset
UIContextService.getInstance(FacesContext.getCurrentInstance()).notifyBeans();
// set the wizard in edit mode
this.editMode = true;
// populate the wizard's default values with the current value
// from the node being edited
init();
populate();
if (logger.isDebugEnabled())
logger.debug("Started wizard : " + getWizardTitle() + " for editing");
}
/**
* Deals with the next button being pressed
*
* @return
*/
public String next()
{
this.currentStep++;
// determine which page to go to next
String outcome = determineOutcomeForStep(this.currentStep);
if (logger.isDebugEnabled())
{
logger.debug("current step is now: " + this.currentStep);
logger.debug("Next outcome: " + outcome);
}
// return the outcome for navigation
return outcome;
}
/**
* Deals with the back button being pressed
*
* @return
*/
public String back()
{
this.currentStep--;
// determine which page to go to next
String outcome = determineOutcomeForStep(this.currentStep);
if (logger.isDebugEnabled())
{
logger.debug("current step is now: " + this.currentStep);
logger.debug("Back outcome: " + outcome);
}
// return the outcome for navigation
return outcome;
}
/**
* Handles the cancelling of the wizard
*
* @return The cancel outcome
*/
public String cancel()
{
// reset the state
init();
return CANCEL_OUTCOME;
}
/**
* Initialises the wizard
*/
public void init()
{
this.currentStep = 1;
}
/**
* Populates the wizard's values with the current values
* of the node about to be edited
*/
public void populate()
{
// subclasses will override this method to setup accordingly
}
/**
* @return Returns the nodeService.
*/
public NodeService getNodeService()
{
return this.nodeService;
}
/**
* @param nodeService The nodeService to set.
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* @param fileFolderService used to manipulate folder/folder model nodes
*/
public void setFileFolderService(FileFolderService fileFolderService)
{
this.fileFolderService = fileFolderService;
}
/**
* @param searchService the service used to find nodes
*/
public void setSearchService(SearchService searchService)
{
this.searchService = searchService;
}
/**
* @return Returns the navigation bean instance.
*/
public NavigationBean getNavigator()
{
return navigator;
}
/**
* @param navigator The NavigationBean to set.
*/
public void setNavigator(NavigationBean navigator)
{
this.navigator = navigator;
}
/**
* @return The BrowseBean
*/
public BrowseBean getBrowseBean()
{
return this.browseBean;
}
/**
* @param browseBean The BrowseBean to set.
*/
public void setBrowseBean(BrowseBean browseBean)
{
this.browseBean = browseBean;
}
/**
* Build summary table from the specified list of Labels and Values
*
* @param labels Array of labels to display
* @param values Array of values to display
*
* @return summary table HTML
*/
protected String buildSummary(String[] labels, String[] values)
{
if (labels == null || values == null || labels.length != values.length)
{
throw new IllegalArgumentException("Labels and Values passed to summary must be valid and of equal length.");
}
String msg = Application.getMessage(FacesContext.getCurrentInstance(), MSG_NOT_SET);
String notSetMsg = "<" + msg + ">";
StringBuilder buf = new StringBuilder(256);
buf.append("<table cellspacing='4' cellpadding='2' border='0' class='summary'>");
for (int i=0; i<labels.length; i++)
{
String value = values[i];
buf.append("<tr><td valign='top'><b>");
buf.append(labels[i]);
buf.append(":</b></td><td>");
buf.append(value != null ? value : notSetMsg);
buf.append("</td></tr>");
}
buf.append("</table>");
return buf.toString();
}
}

View File

@@ -0,0 +1,320 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.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.File;
import java.io.Serializable;
import java.text.MessageFormat;
import java.util.HashMap;
import java.util.Map;
import java.util.ResourceBundle;
import javax.faces.context.FacesContext;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.content.filestore.FileContentReader;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.namespace.QName;
import org.alfresco.web.app.Application;
import org.alfresco.web.bean.FileUploadBean;
import org.alfresco.web.bean.repository.Repository;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Handler class used by the Add Content Wizard
*
* @author gavinc
*/
public class AddContentWizard extends BaseContentWizard
{
private static Log logger = LogFactory.getLog(AddContentWizard.class);
// TODO: retrieve these from the config service
private static final String WIZARD_TITLE_ID = "add_content_title";
private static final String WIZARD_DESC_ID = "add_content_desc";
private static final String STEP1_TITLE_ID = "add_conent_step1_title";
private static final String STEP1_DESCRIPTION_ID = "add_conent_step1_desc";
private static final String STEP2_TITLE_ID = "add_conent_step2_title";
private static final String STEP2_DESCRIPTION_ID = "add_conent_step2_desc";
// add content wizard specific properties
private File file;
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#next()
*/
public String next()
{
String outcome = super.next();
// if the outcome is "properties" we pre-set the content type and other
// fields accordingly
if (outcome.equals("properties"))
{
this.contentType = Repository.getMimeTypeForFileName(
FacesContext.getCurrentInstance(), this.fileName);
// set default for in-line editing flag
this.inlineEdit = (this.contentType.equals(MimetypeMap.MIMETYPE_HTML));
// Try and extract metadata from the file
ContentReader cr = new FileContentReader(this.file);
cr.setMimetype(this.contentType);
// create properties for content type
Map<QName, Serializable> contentProps = new HashMap<QName, Serializable>(5, 1.0f);
if (Repository.extractMetadata(FacesContext.getCurrentInstance(), cr, contentProps))
{
this.author = (String)(contentProps.get(ContentModel.PROP_CREATOR));
this.title = (String)(contentProps.get(ContentModel.PROP_TITLE));
this.description = (String)(contentProps.get(ContentModel.PROP_DESCRIPTION));
}
if (this.title == null)
{
this.title = this.fileName;
}
}
return outcome;
}
/**
* Deals with the finish button being pressed
*
* @return outcome
*/
public String finish()
{
String outcome = saveContent(this.file, null);
// now we know the new details are in the repository, reset the
// client side node representation so the new details are retrieved
if (this.editMode)
{
this.browseBean.getDocument().reset();
}
return outcome;
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#getWizardDescription()
*/
public String getWizardDescription()
{
return Application.getMessage(FacesContext.getCurrentInstance(), WIZARD_DESC_ID);
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#getWizardTitle()
*/
public String getWizardTitle()
{
return Application.getMessage(FacesContext.getCurrentInstance(), WIZARD_TITLE_ID);
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#getStepDescription()
*/
public String getStepDescription()
{
String stepDesc = null;
switch (this.currentStep)
{
case 1:
{
stepDesc = Application.getMessage(FacesContext.getCurrentInstance(), STEP1_DESCRIPTION_ID);
break;
}
case 2:
{
stepDesc = Application.getMessage(FacesContext.getCurrentInstance(), STEP2_DESCRIPTION_ID);
break;
}
case 3:
{
stepDesc = Application.getMessage(FacesContext.getCurrentInstance(), SUMMARY_DESCRIPTION_ID);
break;
}
default:
{
stepDesc = "";
}
}
return stepDesc;
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#getStepTitle()
*/
public String getStepTitle()
{
String stepTitle = null;
switch (this.currentStep)
{
case 1:
{
stepTitle = Application.getMessage(FacesContext.getCurrentInstance(), STEP1_TITLE_ID);
break;
}
case 2:
{
stepTitle = Application.getMessage(FacesContext.getCurrentInstance(), STEP2_TITLE_ID);
break;
}
case 3:
{
stepTitle = Application.getMessage(FacesContext.getCurrentInstance(), SUMMARY_TITLE_ID);
break;
}
default:
{
stepTitle = "";
}
}
return stepTitle;
}
/**
* Initialises the wizard
*/
public void init()
{
super.init();
clearUpload();
this.file = null;
}
/**
* @return Returns the message to display when a file has been uploaded
*/
public String getFileUploadSuccessMsg()
{
String msg = Application.getMessage(FacesContext.getCurrentInstance(), "file_upload_success");
return MessageFormat.format(msg, new Object[] {getFileName()});
}
/**
* @return Returns the name of the file
*/
public String getFileName()
{
// try and retrieve the file and filename from the file upload bean
// representing the file we previously uploaded.
FacesContext ctx = FacesContext.getCurrentInstance();
FileUploadBean fileBean = (FileUploadBean)ctx.getExternalContext().getSessionMap().
get(FileUploadBean.FILE_UPLOAD_BEAN_NAME);
if (fileBean != null)
{
this.file = fileBean.getFile();
this.fileName = fileBean.getFileName();
}
return this.fileName;
}
/**
* @param fileName The name of the file
*/
public void setFileName(String fileName)
{
this.fileName = fileName;
// we also need to keep the file upload bean in sync
FacesContext ctx = FacesContext.getCurrentInstance();
FileUploadBean fileBean = (FileUploadBean)ctx.getExternalContext().getSessionMap().
get(FileUploadBean.FILE_UPLOAD_BEAN_NAME);
if (fileBean != null)
{
fileBean.setFileName(this.fileName);
}
}
/**
* @return Returns the summary data for the wizard.
*/
public String getSummary()
{
ResourceBundle bundle = Application.getBundle(FacesContext.getCurrentInstance());
return buildSummary(
new String[] {bundle.getString("file_name"), bundle.getString("type"),
bundle.getString("content_type"), bundle.getString("title"),
bundle.getString("description"), bundle.getString("author"),
bundle.getString("inline_editable")},
new String[] {this.fileName, getSummaryObjectType(), getSummaryContentType(), this.title,
this.description, this.author, Boolean.toString(this.inlineEdit)});
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#determineOutcomeForStep(int)
*/
protected String determineOutcomeForStep(int step)
{
String outcome = null;
switch(step)
{
case 1:
{
outcome = "upload";
break;
}
case 2:
{
outcome = "properties";
break;
}
case 3:
{
outcome = "summary";
break;
}
default:
{
outcome = CANCEL_OUTCOME;
}
}
return outcome;
}
/**
* Deletes the uploaded file and removes the FileUploadBean from the session
*/
private void clearUpload()
{
// delete the temporary file we uploaded earlier
if (this.file != null)
{
this.file.delete();
}
// remove the file upload bean from the session
FacesContext ctx = FacesContext.getCurrentInstance();
ctx.getExternalContext().getSessionMap().remove(FileUploadBean.FILE_UPLOAD_BEAN_NAME);
}
}

View File

@@ -0,0 +1,921 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.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.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.config.Config;
import org.alfresco.config.ConfigElement;
import org.alfresco.config.ConfigService;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.action.executer.AddFeaturesActionExecuter;
import org.alfresco.repo.action.executer.CheckInActionExecuter;
import org.alfresco.repo.action.executer.CheckOutActionExecuter;
import org.alfresco.repo.action.executer.CopyActionExecuter;
import org.alfresco.repo.action.executer.ImageTransformActionExecuter;
import org.alfresco.repo.action.executer.ImporterActionExecuter;
import org.alfresco.repo.action.executer.LinkCategoryActionExecuter;
import org.alfresco.repo.action.executer.MailActionExecuter;
import org.alfresco.repo.action.executer.MoveActionExecuter;
import org.alfresco.repo.action.executer.SimpleWorkflowActionExecuter;
import org.alfresco.repo.action.executer.SpecialiseTypeActionExecuter;
import org.alfresco.repo.action.executer.TransformActionExecuter;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.action.ActionDefinition;
import org.alfresco.service.cmr.action.ActionService;
import org.alfresco.service.cmr.dictionary.AspectDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.dictionary.TypeDefinition;
import org.alfresco.service.cmr.repository.MimetypeService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.web.app.Application;
import org.alfresco.web.bean.repository.Node;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.data.IDataContainer;
import org.alfresco.web.data.QuickSort;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.jsf.FacesContextUtils;
/**
* Base handler class containing common code used by the New Space Wizard and New Action Wizard
*
* @author gavinc kevinr
*/
public abstract class BaseActionWizard extends AbstractWizardBean
{
// parameter names for actions
public static final String PROP_CATEGORY = "category";
public static final String PROP_ASPECT = "aspect";
public static final String PROP_DESTINATION = "destinationLocation";
public static final String PROP_APPROVE_STEP_NAME = "approveStepName";
public static final String PROP_APPROVE_ACTION = "approveAction";
public static final String PROP_APPROVE_FOLDER = "approveFolder";
public static final String PROP_REJECT_STEP_PRESENT = "rejectStepPresent";
public static final String PROP_REJECT_STEP_NAME = "rejectStepName";
public static final String PROP_REJECT_ACTION = "rejectAction";
public static final String PROP_REJECT_FOLDER = "rejectFolder";
public static final String PROP_CHECKIN_DESC = "checkinDescription";
public static final String PROP_CHECKIN_MINOR = "checkinMinorChange";
public static final String PROP_TRANSFORMER = "transformer";
public static final String PROP_IMAGE_TRANSFORMER = "imageTransformer";
public static final String PROP_TRANSFORM_OPTIONS = "transformOptions";
public static final String PROP_ENCODING = "encoding";
public static final String PROP_MESSAGE = "message";
public static final String PROP_SUBJECT = "subject";
public static final String PROP_TO = "to";
public static final String PROP_OBJECT_TYPE = "objecttype";
private static final Log logger = LogFactory.getLog(BaseActionWizard.class);
private static final String IMPORT_ENCODING = "UTF-8";
// new rule/action wizard specific properties
protected boolean multiActionMode = false;
protected String action;
protected ActionService actionService;
protected DictionaryService dictionaryService;
protected MimetypeService mimetypeService;
protected List<SelectItem> actions;
protected List<SelectItem> transformers;
protected List<SelectItem> imageTransformers;
protected List<SelectItem> aspects;
protected List<SelectItem> users;
protected List<SelectItem> encodings;
protected Map<String, String> actionDescriptions;
protected Map<String, Serializable> currentActionProperties;
protected List<SelectItem> objectTypes;
/**
* Initialises the wizard
*/
public void init()
{
super.init();
this.action = "add-features";
this.users = null;
this.actions = null;
this.actionDescriptions = null;
this.currentActionProperties = new HashMap<String, Serializable>(3);
// default the approve and reject actions
this.currentActionProperties.put(PROP_APPROVE_ACTION, "move");
this.currentActionProperties.put(PROP_REJECT_STEP_PRESENT, "yes");
this.currentActionProperties.put(PROP_REJECT_ACTION, "move");
// default the checkin minor change
this.currentActionProperties.put(PROP_CHECKIN_MINOR, new Boolean(true));
}
/**
* Build the param map for the current Action instance
*
* @return param map
*/
protected Map<String, Serializable> buildActionParams()
{
// set up parameters maps for the action
Map<String, Serializable> actionParams = new HashMap<String, Serializable>();
if (this.action.equals(AddFeaturesActionExecuter.NAME))
{
QName aspect = Repository.resolveToQName((String)this.currentActionProperties.get(PROP_ASPECT));
actionParams.put(AddFeaturesActionExecuter.PARAM_ASPECT_NAME, aspect);
}
else if (this.action.equals(CopyActionExecuter.NAME))
{
// add the destination space id to the action properties
NodeRef destNodeRef = (NodeRef)this.currentActionProperties.get(PROP_DESTINATION);
actionParams.put(CopyActionExecuter.PARAM_DESTINATION_FOLDER, destNodeRef);
// add the type and name of the association to create when the copy
// is performed
actionParams.put(CopyActionExecuter.PARAM_ASSOC_TYPE_QNAME,
ContentModel.ASSOC_CONTAINS);
actionParams.put(CopyActionExecuter.PARAM_ASSOC_QNAME,
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "copy"));
}
else if (this.action.equals(MoveActionExecuter.NAME))
{
// add the destination space id to the action properties
NodeRef destNodeRef = (NodeRef)this.currentActionProperties.get(PROP_DESTINATION);
actionParams.put(MoveActionExecuter.PARAM_DESTINATION_FOLDER, destNodeRef);
// add the type and name of the association to create when the move
// is performed
actionParams.put(MoveActionExecuter.PARAM_ASSOC_TYPE_QNAME,
ContentModel.ASSOC_CONTAINS);
actionParams.put(MoveActionExecuter.PARAM_ASSOC_QNAME,
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "move"));
}
else if (this.action.equals(SimpleWorkflowActionExecuter.NAME))
{
// add the approve step name
actionParams.put(SimpleWorkflowActionExecuter.PARAM_APPROVE_STEP,
(String)this.currentActionProperties.get(PROP_APPROVE_STEP_NAME));
// add whether the approve step will copy or move the content
boolean approveMove = true;
String approveAction = (String)this.currentActionProperties.get(PROP_APPROVE_ACTION);
if (approveAction != null && approveAction.equals("copy"))
{
approveMove = false;
}
actionParams.put(SimpleWorkflowActionExecuter.PARAM_APPROVE_MOVE, Boolean.valueOf(approveMove));
// add the destination folder of the content
NodeRef approveDestNodeRef = null;
Object approveDestNode = this.currentActionProperties.get(PROP_APPROVE_FOLDER);
if (approveDestNode instanceof NodeRef)
{
approveDestNodeRef = (NodeRef)approveDestNode;
}
else if (approveDestNode instanceof String)
{
approveDestNodeRef = new NodeRef((String)approveDestNode);
}
actionParams.put(SimpleWorkflowActionExecuter.PARAM_APPROVE_FOLDER, approveDestNodeRef);
// determine whether we have a reject step or not
boolean requireReject = true;
String rejectStepPresent = (String)this.currentActionProperties.get(PROP_REJECT_STEP_PRESENT);
if (rejectStepPresent != null && rejectStepPresent.equals("no"))
{
requireReject = false;
}
if (requireReject)
{
// add the reject step name
actionParams.put(SimpleWorkflowActionExecuter.PARAM_REJECT_STEP,
(String)this.currentActionProperties.get(PROP_REJECT_STEP_NAME));
// add whether the reject step will copy or move the content
boolean rejectMove = true;
String rejectAction = (String)this.currentActionProperties.get(PROP_REJECT_ACTION);
if (rejectAction != null && rejectAction.equals("copy"))
{
rejectMove = false;
}
actionParams.put(SimpleWorkflowActionExecuter.PARAM_REJECT_MOVE, Boolean.valueOf(rejectMove));
// add the destination folder of the content
NodeRef rejectDestNodeRef = null;
Object rejectDestNode = this.currentActionProperties.get(PROP_REJECT_FOLDER);
if (rejectDestNode instanceof NodeRef)
{
rejectDestNodeRef = (NodeRef)rejectDestNode;
}
else if (rejectDestNode instanceof String)
{
rejectDestNodeRef = new NodeRef((String)rejectDestNode);
}
actionParams.put(SimpleWorkflowActionExecuter.PARAM_REJECT_FOLDER, rejectDestNodeRef);
}
}
else if (this.action.equals(LinkCategoryActionExecuter.NAME))
{
// add the classifiable aspect
actionParams.put(LinkCategoryActionExecuter.PARAM_CATEGORY_ASPECT,
ContentModel.ASPECT_GEN_CLASSIFIABLE);
// put the selected category in the action params
NodeRef catNodeRef = (NodeRef)this.currentActionProperties.get(PROP_CATEGORY);
actionParams.put(LinkCategoryActionExecuter.PARAM_CATEGORY_VALUE,
catNodeRef);
}
else if (this.action.equals(CheckOutActionExecuter.NAME))
{
// specify the location the checked out working copy should go
// add the destination space id to the action properties
NodeRef destNodeRef = (NodeRef)this.currentActionProperties.get(PROP_DESTINATION);
actionParams.put(CheckOutActionExecuter.PARAM_DESTINATION_FOLDER, destNodeRef);
// add the type and name of the association to create when the
// check out is performed
actionParams.put(CheckOutActionExecuter.PARAM_ASSOC_TYPE_QNAME,
ContentModel.ASSOC_CONTAINS);
actionParams.put(CheckOutActionExecuter.PARAM_ASSOC_QNAME,
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "checkout"));
}
else if (this.action.equals(CheckInActionExecuter.NAME))
{
// add the description for the checkin to the action params
actionParams.put(CheckInActionExecuter.PARAM_DESCRIPTION,
this.currentActionProperties.get(PROP_CHECKIN_DESC));
// add the minor change flag
actionParams.put(CheckInActionExecuter.PARAM_MINOR_CHANGE,
this.currentActionProperties.get(PROP_CHECKIN_MINOR));
}
else if (this.action.equals(TransformActionExecuter.NAME))
{
// add the transformer to use
actionParams.put(TransformActionExecuter.PARAM_MIME_TYPE,
this.currentActionProperties.get(PROP_TRANSFORMER));
// add the destination space id to the action properties
NodeRef destNodeRef = (NodeRef)this.currentActionProperties.get(PROP_DESTINATION);
actionParams.put(TransformActionExecuter.PARAM_DESTINATION_FOLDER, destNodeRef);
// add the type and name of the association to create when the copy
// is performed
actionParams.put(TransformActionExecuter.PARAM_ASSOC_TYPE_QNAME,
ContentModel.ASSOC_CONTAINS);
actionParams.put(TransformActionExecuter.PARAM_ASSOC_QNAME,
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "copy"));
}
else if (this.action.equals(ImageTransformActionExecuter.NAME))
{
// add the transformer to use
actionParams.put(ImageTransformActionExecuter.PARAM_MIME_TYPE,
this.currentActionProperties.get(PROP_IMAGE_TRANSFORMER));
// add the options
actionParams.put(ImageTransformActionExecuter.PARAM_CONVERT_COMMAND,
this.currentActionProperties.get(PROP_TRANSFORM_OPTIONS));
// add the destination space id to the action properties
NodeRef destNodeRef = (NodeRef)this.currentActionProperties.get(PROP_DESTINATION);
actionParams.put(TransformActionExecuter.PARAM_DESTINATION_FOLDER, destNodeRef);
// add the type and name of the association to create when the copy
// is performed
actionParams.put(TransformActionExecuter.PARAM_ASSOC_TYPE_QNAME,
ContentModel.ASSOC_CONTAINS);
actionParams.put(TransformActionExecuter.PARAM_ASSOC_QNAME,
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "copy"));
}
else if (this.action.equals(MailActionExecuter.NAME))
{
// add the actual email text to send
actionParams.put(MailActionExecuter.PARAM_TEXT,
this.currentActionProperties.get(PROP_MESSAGE));
// add the person it's going to
actionParams.put(MailActionExecuter.PARAM_TO,
this.currentActionProperties.get(PROP_TO));
// add the subject for the email
actionParams.put(MailActionExecuter.PARAM_SUBJECT,
this.currentActionProperties.get(PROP_SUBJECT));
}
else if (this.action.equals(ImporterActionExecuter.NAME))
{
// add the encoding
actionParams.put(ImporterActionExecuter.PARAM_ENCODING, IMPORT_ENCODING);
// add the destination for the import
NodeRef destNodeRef = (NodeRef)this.currentActionProperties.get(PROP_DESTINATION);
actionParams.put(ImporterActionExecuter.PARAM_DESTINATION_FOLDER, destNodeRef);
}
else if (this.action.equals(SpecialiseTypeActionExecuter.NAME) == true)
{
// add the specialisation type
String objectType = (String)this.currentActionProperties.get(PROP_OBJECT_TYPE);
actionParams.put(SpecialiseTypeActionExecuter.PARAM_TYPE_NAME, QName.createQName(objectType));
}
return actionParams;
}
/**
* Populate the actionProperties member variable with correct props for the current action
* using the supplied property map.
*
* @param actionProps Map to retrieve props appropriate to the current action from
*/
protected void populateActionFromProperties(Map<String, Serializable> actionProps)
{
if (this.action.equals(AddFeaturesActionExecuter.NAME))
{
QName aspect = (QName)actionProps.get(AddFeaturesActionExecuter.PARAM_ASPECT_NAME);
this.currentActionProperties.put(PROP_ASPECT, aspect.toString());
}
else if (this.action.equals(CopyActionExecuter.NAME))
{
NodeRef destNodeRef = (NodeRef)actionProps.get(CopyActionExecuter.PARAM_DESTINATION_FOLDER);
this.currentActionProperties.put(PROP_DESTINATION, destNodeRef);
}
else if (this.action.equals(MoveActionExecuter.NAME))
{
NodeRef destNodeRef = (NodeRef)actionProps.get(MoveActionExecuter.PARAM_DESTINATION_FOLDER);
this.currentActionProperties.put(PROP_DESTINATION, destNodeRef);
}
else if (this.action.equals(SimpleWorkflowActionExecuter.NAME))
{
String approveStep = (String)actionProps.get(SimpleWorkflowActionExecuter.PARAM_APPROVE_STEP);
Boolean approveMove = (Boolean)actionProps.get(SimpleWorkflowActionExecuter.PARAM_APPROVE_MOVE);
NodeRef approveFolderNode = (NodeRef)actionProps.get(
SimpleWorkflowActionExecuter.PARAM_APPROVE_FOLDER);
String rejectStep = (String)actionProps.get(SimpleWorkflowActionExecuter.PARAM_REJECT_STEP);
Boolean rejectMove = (Boolean)actionProps.get(SimpleWorkflowActionExecuter.PARAM_REJECT_MOVE);
NodeRef rejectFolderNode = (NodeRef)actionProps.get(
SimpleWorkflowActionExecuter.PARAM_REJECT_FOLDER);
this.currentActionProperties.put(PROP_APPROVE_STEP_NAME, approveStep);
this.currentActionProperties.put(PROP_APPROVE_ACTION, approveMove ? "move" : "copy");
this.currentActionProperties.put(PROP_APPROVE_FOLDER, approveFolderNode);
if (rejectStep == null && rejectMove == null && rejectFolderNode == null)
{
this.currentActionProperties.put(PROP_REJECT_STEP_PRESENT, "no");
}
else
{
this.currentActionProperties.put(PROP_REJECT_STEP_PRESENT, "yes");
this.currentActionProperties.put(PROP_REJECT_STEP_NAME, rejectStep);
this.currentActionProperties.put(PROP_REJECT_ACTION, rejectMove ? "move" : "copy");
this.currentActionProperties.put(PROP_REJECT_FOLDER, rejectFolderNode);
}
}
else if (this.action.equals(LinkCategoryActionExecuter.NAME))
{
NodeRef catNodeRef = (NodeRef)actionProps.get(LinkCategoryActionExecuter.PARAM_CATEGORY_VALUE);
this.currentActionProperties.put(PROP_CATEGORY, catNodeRef);
}
else if (this.action.equals(CheckOutActionExecuter.NAME))
{
NodeRef destNodeRef = (NodeRef)actionProps.get(CheckOutActionExecuter.PARAM_DESTINATION_FOLDER);
this.currentActionProperties.put(PROP_DESTINATION, destNodeRef);
}
else if (this.action.equals(CheckInActionExecuter.NAME))
{
String checkDesc = (String)actionProps.get(CheckInActionExecuter.PARAM_DESCRIPTION);
this.currentActionProperties.put(PROP_CHECKIN_DESC, checkDesc);
Boolean minorChange = (Boolean)actionProps.get(CheckInActionExecuter.PARAM_MINOR_CHANGE);
this.currentActionProperties.put(PROP_CHECKIN_MINOR, minorChange);
}
else if (this.action.equals(TransformActionExecuter.NAME))
{
String transformer = (String)actionProps.get(TransformActionExecuter.PARAM_MIME_TYPE);
this.currentActionProperties.put(PROP_TRANSFORMER, transformer);
NodeRef destNodeRef = (NodeRef)actionProps.get(CopyActionExecuter.PARAM_DESTINATION_FOLDER);
this.currentActionProperties.put(PROP_DESTINATION, destNodeRef);
}
else if (this.action.equals(ImageTransformActionExecuter.NAME))
{
String transformer = (String)actionProps.get(TransformActionExecuter.PARAM_MIME_TYPE);
this.currentActionProperties.put(PROP_IMAGE_TRANSFORMER, transformer);
String options = (String)actionProps.get(ImageTransformActionExecuter.PARAM_CONVERT_COMMAND);
this.currentActionProperties.put(PROP_TRANSFORM_OPTIONS, options != null ? options : "");
NodeRef destNodeRef = (NodeRef)actionProps.get(CopyActionExecuter.PARAM_DESTINATION_FOLDER);
this.currentActionProperties.put(PROP_DESTINATION, destNodeRef);
}
else if (this.action.equals(MailActionExecuter.NAME))
{
String subject = (String)actionProps.get(MailActionExecuter.PARAM_SUBJECT);
this.currentActionProperties.put(PROP_SUBJECT, subject);
String message = (String)actionProps.get(MailActionExecuter.PARAM_TEXT);
this.currentActionProperties.put(PROP_MESSAGE, message);
String to = (String)actionProps.get(MailActionExecuter.PARAM_TO);
this.currentActionProperties.put(PROP_TO, to);
}
else if (this.action.equals(ImporterActionExecuter.NAME))
{
NodeRef destNodeRef = (NodeRef)actionProps.get(ImporterActionExecuter.PARAM_DESTINATION_FOLDER);
this.currentActionProperties.put(PROP_DESTINATION, destNodeRef);
}
else if (this.action.equals(SpecialiseTypeActionExecuter.NAME) == true)
{
QName specialiseType = (QName)actionProps.get(SpecialiseTypeActionExecuter.PARAM_TYPE_NAME);
this.currentActionProperties.put(PROP_OBJECT_TYPE, specialiseType.toString());
}
}
/**
* @return Returns the selected action
*/
public String getAction()
{
return this.action;
}
/**
* @param action Sets the selected action
*/
public void setAction(String action)
{
this.action = action;
}
/**
* Sets the action service
*
* @param actionRegistration the action service
*/
public void setActionService(ActionService actionService)
{
this.actionService = actionService;
}
/**
* Sets the dictionary service
*
* @param dictionaryService the dictionary service
*/
public void setDictionaryService(DictionaryService dictionaryService)
{
this.dictionaryService = dictionaryService;
}
/**
* Sets the mimetype service
*
* @param mimetypeService The mimetype service
*/
public void setMimetypeService(MimetypeService mimetypeService)
{
this.mimetypeService = mimetypeService;
}
/**
* @return Returns the list of selectable actions
*/
public List<SelectItem> getActions()
{
if (this.actions == null)
{
List<ActionDefinition> ruleActions = this.actionService.getActionDefinitions();
this.actions = new ArrayList<SelectItem>();
for (ActionDefinition ruleActionDef : ruleActions)
{
this.actions.add(new SelectItem(ruleActionDef.getName(), ruleActionDef.getTitle()));
}
// make sure the list is sorted by the label
QuickSort sorter = new QuickSort(this.actions, "label", true, IDataContainer.SORT_CASEINSENSITIVE);
sorter.sort();
}
return this.actions;
}
/**
* @return Returns a map of all the action descriptions
*/
public Map<String, String> getActionDescriptions()
{
if (this.actionDescriptions == null)
{
List<ActionDefinition> ruleActions = this.actionService.getActionDefinitions();
this.actionDescriptions = new HashMap<String, String>();
for (ActionDefinition ruleActionDef : ruleActions)
{
this.actionDescriptions.put(ruleActionDef.getName(), ruleActionDef.getDescription());
}
}
return this.actionDescriptions;
}
/**
* @return Gets the action settings
*/
public Map<String, Serializable> getActionProperties()
{
return this.currentActionProperties;
}
/**
* Returns a list of encodings the import and export actions can use
*
* @return List of SelectItem objects representing the available encodings
*/
public List<SelectItem> getEncodings()
{
if (this.encodings == null)
{
ConfigService svc = (ConfigService)FacesContextUtils.getRequiredWebApplicationContext(
FacesContext.getCurrentInstance()).getBean(Application.BEAN_CONFIG_SERVICE);
Config wizardCfg = svc.getConfig("Action Wizards");
if (wizardCfg != null)
{
ConfigElement encodingsCfg = wizardCfg.getConfigElement("encodings");
if (encodingsCfg != null)
{
FacesContext context = FacesContext.getCurrentInstance();
this.encodings = new ArrayList<SelectItem>();
for (ConfigElement child : encodingsCfg.getChildren())
{
String id = child.getAttribute("name");
// look for a client localized string
String label = null;
String msgId = child.getAttribute("displayLabelId");
if (msgId != null)
{
label = Application.getMessage(context, msgId);
}
// if there wasn't an externalized string look for one in the config
if (label == null)
{
label = child.getAttribute("displayLabel");
}
this.encodings.add(new SelectItem(id, label));
}
// make sure the list is sorted by the label
QuickSort sorter = new QuickSort(this.encodings, "label", true, IDataContainer.SORT_CASEINSENSITIVE);
sorter.sort();
}
else
{
logger.warn("Could not find encodings configuration element");
}
}
else
{
logger.warn("Could not find Action Wizards configuration section");
}
}
return this.encodings;
}
/**
* Returns the transformers that are available
*
* @return List of SelectItem objects representing the available transformers
*/
public List<SelectItem> getTransformers()
{
if (this.transformers == null)
{
ConfigService svc = (ConfigService)FacesContextUtils.getRequiredWebApplicationContext(
FacesContext.getCurrentInstance()).getBean(Application.BEAN_CONFIG_SERVICE);
Config wizardCfg = svc.getConfig("Action Wizards");
if (wizardCfg != null)
{
ConfigElement transformersCfg = wizardCfg.getConfigElement("transformers");
if (transformersCfg != null)
{
FacesContext context = FacesContext.getCurrentInstance();
Map<String, String> mimeTypes = this.mimetypeService.getDisplaysByMimetype();
this.transformers = new ArrayList<SelectItem>();
for (ConfigElement child : transformersCfg.getChildren())
{
String id = child.getAttribute("name");
// look for a client localized string
String label = null;
String msgId = child.getAttribute("displayLabelId");
if (msgId != null)
{
label = Application.getMessage(context, msgId);
}
// if there wasn't an externalized string look for one in the config
if (label == null)
{
label = child.getAttribute("displayLabel");
}
// if there wasn't a client based label get it from the mime type service
if (label == null)
{
label = mimeTypes.get(id);
}
this.transformers.add(new SelectItem(id, label));
}
// make sure the list is sorted by the label
QuickSort sorter = new QuickSort(this.transformers, "label", true, IDataContainer.SORT_CASEINSENSITIVE);
sorter.sort();
}
else
{
logger.warn("Could not find transformers configuration element");
}
}
else
{
logger.warn("Could not find Action Wizards configuration section");
}
}
return this.transformers;
}
/**
* Returns the image transformers that are available
*
* @return List of SelectItem objects representing the available image transformers
*/
public List<SelectItem> getImageTransformers()
{
if (this.imageTransformers == null)
{
ConfigService svc = (ConfigService)FacesContextUtils.getRequiredWebApplicationContext(
FacesContext.getCurrentInstance()).getBean(Application.BEAN_CONFIG_SERVICE);
Config wizardCfg = svc.getConfig("Action Wizards");
if (wizardCfg != null)
{
ConfigElement transformersCfg = wizardCfg.getConfigElement("image-transformers");
if (transformersCfg != null)
{
FacesContext context = FacesContext.getCurrentInstance();
Map<String, String> mimeTypes = this.mimetypeService.getDisplaysByMimetype();
this.imageTransformers = new ArrayList<SelectItem>();
for (ConfigElement child : transformersCfg.getChildren())
{
String id = child.getAttribute("name");
// look for a client localized string
String label = null;
String msgId = child.getAttribute("displayLabelId");
if (msgId != null)
{
label = Application.getMessage(context, msgId);
}
// if there wasn't an externalized string look for one in the config
if (label == null)
{
label = child.getAttribute("displayLabel");
}
// if there wasn't a client based label get it from the mime type service
if (label == null)
{
label = mimeTypes.get(id);
}
this.imageTransformers.add(new SelectItem(id, label));
}
// make sure the list is sorted by the label
QuickSort sorter = new QuickSort(this.imageTransformers, "label", true, IDataContainer.SORT_CASEINSENSITIVE);
sorter.sort();
}
else
{
logger.warn("Could not find image-transformers configuration element");
}
}
else
{
logger.warn("Could not find Action Wizards configuration section");
}
}
return this.imageTransformers;
}
/**
* Returns the aspects that are available
*
* @return List of SelectItem objects representing the available aspects
*/
public List<SelectItem> getAspects()
{
if (this.aspects == null)
{
ConfigService svc = (ConfigService)FacesContextUtils.getRequiredWebApplicationContext(
FacesContext.getCurrentInstance()).getBean(Application.BEAN_CONFIG_SERVICE);
Config wizardCfg = svc.getConfig("Action Wizards");
if (wizardCfg != null)
{
ConfigElement aspectsCfg = wizardCfg.getConfigElement("aspects");
if (aspectsCfg != null)
{
FacesContext context = FacesContext.getCurrentInstance();
this.aspects = new ArrayList<SelectItem>();
for (ConfigElement child : aspectsCfg.getChildren())
{
QName idQName = Repository.resolveToQName(child.getAttribute("name"));
// look for a client localized string
String label = null;
String msgId = child.getAttribute("displayLabelId");
if (msgId != null)
{
label = Application.getMessage(context, msgId);
}
// if there wasn't an externalized string look for one in the config
if (label == null)
{
label = child.getAttribute("displayLabel");
}
// if there wasn't a client based label try and get it from the dictionary
if (label == null)
{
AspectDefinition aspectDef = this.dictionaryService.getAspect(idQName);
if (aspectDef != null)
{
label = aspectDef.getTitle();
}
else
{
label = idQName.getLocalName();
}
}
this.aspects.add(new SelectItem(idQName.toString(), label));
}
// make sure the list is sorted by the label
QuickSort sorter = new QuickSort(this.aspects, "label", true, IDataContainer.SORT_CASEINSENSITIVE);
sorter.sort();
}
else
{
logger.warn("Could not find aspects configuration element");
}
}
else
{
logger.warn("Could not find Action Wizards configuration section");
}
}
return this.aspects;
}
/**
* @return Returns a list of object types to allow the user to select from
*/
public List<SelectItem> getObjectTypes()
{
if (this.objectTypes == null)
{
FacesContext context = FacesContext.getCurrentInstance();
// add the well known object type to start with
this.objectTypes = new ArrayList<SelectItem>(5);
this.objectTypes.add(new SelectItem(ContentModel.TYPE_CONTENT.toString(),
Application.getMessage(context, "content")));
// add any configured content sub-types to the list
ConfigService svc = (ConfigService)FacesContextUtils.getRequiredWebApplicationContext(
FacesContext.getCurrentInstance()).getBean(Application.BEAN_CONFIG_SERVICE);
Config wizardCfg = svc.getConfig("Custom Content Types");
if (wizardCfg != null)
{
ConfigElement typesCfg = wizardCfg.getConfigElement("content-types");
if (typesCfg != null)
{
for (ConfigElement child : typesCfg.getChildren())
{
QName idQName = Repository.resolveToQName(child.getAttribute("name"));
TypeDefinition typeDef = this.dictionaryService.getType(idQName);
if (typeDef != null &&
this.dictionaryService.isSubClass(typeDef.getName(), ContentModel.TYPE_CONTENT))
{
// look for a client localized string
String label = null;
String msgId = child.getAttribute("displayLabelId");
if (msgId != null)
{
label = Application.getMessage(context, msgId);
}
// if there wasn't an externalized string look for one in the config
if (label == null)
{
label = child.getAttribute("displayLabel");
}
// if there wasn't a client based label try and get it from the dictionary
if (label == null)
{
label = typeDef.getTitle();
}
// finally, just use the localname
if (label == null)
{
label = idQName.getLocalName();
}
this.objectTypes.add(new SelectItem(idQName.toString(), label));
}
}
// make sure the list is sorted by the label
QuickSort sorter = new QuickSort(this.objectTypes, "label", true, IDataContainer.SORT_CASEINSENSITIVE);
sorter.sort();
}
else
{
logger.warn("Could not find 'content-types' configuration element");
}
}
else
{
logger.warn("Could not find 'Custom Content Types' configuration section");
}
}
return this.objectTypes;
}
/**
* @return the List of users in the system wrapped in SelectItem objects
*/
public List<SelectItem> getUsers()
{
if (this.users == null)
{
List<Node> userNodes = Repository.getUsers(
FacesContext.getCurrentInstance(),
this.nodeService,
this.searchService);
this.users = new ArrayList<SelectItem>();
for (Node user : userNodes)
{
String email = (String)user.getProperties().get("email");
if (email != null && email.length() > 0)
{
this.users.add(new SelectItem(email, (String)user.getProperties().get("fullName")));
}
}
// make sure the list is sorted by the label
QuickSort sorter = new QuickSort(this.users, "label", true, IDataContainer.SORT_CASEINSENSITIVE);
sorter.sort();
}
return this.users;
}
}

View File

@@ -0,0 +1,611 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.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.File;
import java.io.Serializable;
import java.text.MessageFormat;
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 javax.transaction.UserTransaction;
import org.alfresco.config.Config;
import org.alfresco.config.ConfigElement;
import org.alfresco.config.ConfigService;
import org.alfresco.model.ContentModel;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.dictionary.TypeDefinition;
import org.alfresco.service.cmr.model.FileExistsException;
import org.alfresco.service.cmr.model.FileInfo;
import org.alfresco.service.cmr.repository.ContentData;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.MimetypeService;
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.Node;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.data.IDataContainer;
import org.alfresco.web.data.QuickSort;
import org.alfresco.web.ui.common.Utils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.jsf.FacesContextUtils;
/**
* Base Handler class used by the Content Wizards
*
* @author gavinc kevinr
*/
public abstract class BaseContentWizard extends AbstractWizardBean
{
private static Log logger = LogFactory.getLog(BaseContentWizard.class);
protected static final String FINISH_INSTRUCTION_ID = "content_finish_instruction";
// content wizard specific attributes
protected String fileName;
protected String author;
protected String title;
protected String description;
protected String contentType;
protected String objectType;
protected boolean inlineEdit;
protected List<SelectItem> contentTypes;
protected List<SelectItem> objectTypes;
protected ContentService contentService;
protected DictionaryService dictionaryService;
// the NodeRef of the node created during finish
protected NodeRef createdNode;
/**
* Save the specified content using the currently set wizard attributes
*
* @param fileContent File content to save
* @param strContent String content to save
*/
protected String saveContent(File fileContent, String strContent)
{
String outcome = FINISH_OUTCOME;
UserTransaction tx = null;
try
{
FacesContext context = FacesContext.getCurrentInstance();
tx = Repository.getUserTransaction(context);
tx.begin();
if (this.editMode)
{
// update the existing node in the repository
Node currentDocument = this.browseBean.getDocument();
NodeRef nodeRef = currentDocument.getNodeRef();
// move the file - location and name checks will be performed
this.fileFolderService.move(nodeRef, null, this.fileName);
// set up the content data
// update the modified timestamp and other content props
Map<QName, Serializable> contentProps = this.nodeService.getProperties(nodeRef);
contentProps.put(ContentModel.PROP_TITLE, this.title);
contentProps.put(ContentModel.PROP_DESCRIPTION, this.description);
contentProps.put(ContentModel.PROP_CREATOR, this.author);
// set up content properties - copy or create the compound property
ContentData contentData = (ContentData)contentProps.get(ContentModel.PROP_CONTENT);
if (contentData == null)
{
contentData = new ContentData(null, this.contentType, 0L, "UTF-8");
}
else
{
contentData = new ContentData(
contentData.getContentUrl(),
this.contentType,
contentData.getSize(),
contentData.getEncoding());
}
contentProps.put(ContentModel.PROP_CONTENT, contentData);
if (this.nodeService.hasAspect(nodeRef, ContentModel.ASPECT_INLINEEDITABLE) == false)
{
Map<QName, Serializable> editProps = new HashMap<QName, Serializable>(1, 1.0f);
editProps.put(ContentModel.PROP_EDITINLINE, this.inlineEdit);
this.nodeService.addAspect(nodeRef, ContentModel.ASPECT_INLINEEDITABLE, editProps);
}
else
{
contentProps.put(ContentModel.PROP_EDITINLINE, this.inlineEdit);
}
this.nodeService.setProperties(nodeRef, contentProps);
}
else
{
// get the node ref of the node that will contain the content
NodeRef containerNodeRef;
String nodeId = getNavigator().getCurrentNodeId();
if (nodeId == null)
{
containerNodeRef = this.nodeService.getRootNode(Repository.getStoreRef());
}
else
{
containerNodeRef = new NodeRef(Repository.getStoreRef(), nodeId);
}
FileInfo fileInfo = fileFolderService.create(
containerNodeRef,
this.fileName,
Repository.resolveToQName(this.objectType));
NodeRef fileNodeRef = fileInfo.getNodeRef();
// set the author (if we have)
if (this.author != null && this.author.length() > 0)
{
this.nodeService.setProperty(fileNodeRef, ContentModel.PROP_CREATOR, this.author);
}
if (logger.isDebugEnabled())
logger.debug("Created file node for file: " + this.fileName);
// apply the titled aspect - title and description
Map<QName, Serializable> titledProps = new HashMap<QName, Serializable>(3, 1.0f);
titledProps.put(ContentModel.PROP_TITLE, this.title);
titledProps.put(ContentModel.PROP_DESCRIPTION, this.description);
this.nodeService.addAspect(fileNodeRef, ContentModel.ASPECT_TITLED, titledProps);
if (logger.isDebugEnabled())
logger.debug("Added titled aspect with properties: " + titledProps);
// apply the inlineeditable aspect
if (this.inlineEdit == true)
{
Map<QName, Serializable> editProps = new HashMap<QName, Serializable>(1, 1.0f);
editProps.put(ContentModel.PROP_EDITINLINE, this.inlineEdit);
this.nodeService.addAspect(fileNodeRef, 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(fileNodeRef, ContentModel.PROP_CONTENT, true);
// set the mimetype and encoding
writer.setMimetype(this.contentType);
writer.setEncoding("UTF-8");
if (fileContent != null)
{
writer.putContent(fileContent);
}
else if (strContent != null)
{
writer.putContent(strContent);
}
// remember the created node now
this.createdNode = fileNodeRef;
}
// give subclasses a chance to perform custom processing before committing
performCustomProcessing();
// commit the transaction
tx.commit();
}
catch (FileExistsException e)
{
// rollback the transaction
try { if (tx != null) {tx.rollback();} } catch (Exception ex) {}
// print status message
String statusMsg = MessageFormat.format(
Application.getMessage(
FacesContext.getCurrentInstance(), "error_exists"),
e.getExisting().getName());
Utils.addErrorMessage(statusMsg);
// no outcome
outcome = null;
}
catch (Exception e)
{
// rollback the transaction
try { if (tx != null) {tx.rollback();} } catch (Exception ex) {}
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(
FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), e.getMessage()), e);
outcome = null;
}
return outcome;
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#getStepInstructions()
*/
public String getStepInstructions()
{
String stepInstruction = null;
switch (this.currentStep)
{
case 3:
{
stepInstruction = Application.getMessage(FacesContext.getCurrentInstance(), FINISH_INSTRUCTION_ID);
break;
}
default:
{
stepInstruction = Application.getMessage(FacesContext.getCurrentInstance(), DEFAULT_INSTRUCTION_ID);
}
}
return stepInstruction;
}
/**
* Initialises the wizard
*/
public void init()
{
super.init();
this.fileName = null;
this.author = null;
this.title = null;
this.description = null;
this.contentType = null;
this.inlineEdit = false;
this.contentTypes = null;
this.objectTypes = null;
this.objectType = ContentModel.TYPE_CONTENT.toString();
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#populate()
*/
public void populate()
{
// get hold of the current document and populate the appropriate values
Node currentDocument = this.browseBean.getDocument();
Map<String, Object> props = currentDocument.getProperties();
Boolean inline = (Boolean)props.get("editInline");
this.inlineEdit = inline != null ? inline.booleanValue() : false;
this.author = (String)props.get("creator");
this.contentType = null;
ContentData contentData = (ContentData)props.get(ContentModel.PROP_CONTENT);
if (contentData != null)
{
this.contentType = contentData.getMimetype();
}
this.description = (String)props.get("description");
this.fileName = currentDocument.getName();
this.title = (String)props.get("title");
}
/**
* @return Returns the contentService.
*/
public ContentService getContentService()
{
return contentService;
}
/**
* @param contentService The contentService to set.
*/
public void setContentService(ContentService contentService)
{
this.contentService = contentService;
}
/**
* Sets the dictionary service
*
* @param dictionaryService the dictionary service
*/
public void setDictionaryService(DictionaryService dictionaryService)
{
this.dictionaryService = dictionaryService;
}
/**
* @return Returns the name of the file
*/
public String getFileName()
{
return this.fileName;
}
/**
* @param fileName The name of the file
*/
public void setFileName(String fileName)
{
this.fileName = fileName;
}
/**
* @return Returns the author
*/
public String getAuthor()
{
return this.author;
}
/**
* @param author Sets the author
*/
public void setAuthor(String author)
{
this.author = author;
}
/**
* @return Returns the content type currenty selected
*/
public String getContentType()
{
return this.contentType;
}
/**
* @param contentType Sets the currently selected content type
*/
public void setContentType(String contentType)
{
this.contentType = contentType;
}
/**
* @return Returns the object type currenty selected
*/
public String getObjectType()
{
return this.objectType;
}
/**
* @param objectType Sets the currently selected object type
*/
public void setObjectType(String objectType)
{
this.objectType = objectType;
}
/**
* @return Returns the description
*/
public String getDescription()
{
return this.description;
}
/**
* @param description Sets the description
*/
public void setDescription(String description)
{
this.description = description;
}
/**
* @return Returns the title
*/
public String getTitle()
{
return this.title;
}
/**
* @param title Sets the title
*/
public void setTitle(String title)
{
this.title = title;
}
/**
* @return Returns the inline edit flag.
*/
public boolean isInlineEdit()
{
return this.inlineEdit;
}
/**
* @param inlineEdit The inline edit flag to set.
*/
public void setInlineEdit(boolean inlineEdit)
{
this.inlineEdit = inlineEdit;
}
/**
* @return Returns a list of content types to allow the user to select from
*/
public List<SelectItem> getContentTypes()
{
if (this.contentTypes == null)
{
this.contentTypes = new ArrayList<SelectItem>(80);
ServiceRegistry registry = Repository.getServiceRegistry(FacesContext.getCurrentInstance());
MimetypeService mimetypeService = registry.getMimetypeService();
// get the mime type display names
Map<String, String> mimeTypes = mimetypeService.getDisplaysByMimetype();
for (String mimeType : mimeTypes.keySet())
{
this.contentTypes.add(new SelectItem(mimeType, mimeTypes.get(mimeType)));
}
// make sure the list is sorted by the values
QuickSort sorter = new QuickSort(this.contentTypes, "label", true, IDataContainer.SORT_CASEINSENSITIVE);
sorter.sort();
}
return this.contentTypes;
}
/**
* @return Returns a list of object types to allow the user to select from
*/
public List<SelectItem> getObjectTypes()
{
if (this.objectTypes == null)
{
FacesContext context = FacesContext.getCurrentInstance();
// add the well known object type to start with
this.objectTypes = new ArrayList<SelectItem>(5);
this.objectTypes.add(new SelectItem(ContentModel.TYPE_CONTENT.toString(),
Application.getMessage(context, "content")));
// add any configured content sub-types to the list
ConfigService svc = (ConfigService)FacesContextUtils.getRequiredWebApplicationContext(
FacesContext.getCurrentInstance()).getBean(Application.BEAN_CONFIG_SERVICE);
Config wizardCfg = svc.getConfig("Custom Content Types");
if (wizardCfg != null)
{
ConfigElement typesCfg = wizardCfg.getConfigElement("content-types");
if (typesCfg != null)
{
for (ConfigElement child : typesCfg.getChildren())
{
QName idQName = Repository.resolveToQName(child.getAttribute("name"));
TypeDefinition typeDef = this.dictionaryService.getType(idQName);
if (typeDef != null &&
this.dictionaryService.isSubClass(typeDef.getName(), ContentModel.TYPE_CONTENT))
{
// look for a client localized string
String label = null;
String msgId = child.getAttribute("displayLabelId");
if (msgId != null)
{
label = Application.getMessage(context, msgId);
}
// if there wasn't an externalized string look for one in the config
if (label == null)
{
label = child.getAttribute("displayLabel");
}
// if there wasn't a client based label try and get it from the dictionary
if (label == null)
{
label = typeDef.getTitle();
}
// finally, just use the localname
if (label == null)
{
label = idQName.getLocalName();
}
this.objectTypes.add(new SelectItem(idQName.toString(), label));
}
}
// make sure the list is sorted by the label
QuickSort sorter = new QuickSort(this.objectTypes, "label", true, IDataContainer.SORT_CASEINSENSITIVE);
sorter.sort();
}
else
{
logger.warn("Could not find 'content-types' configuration element");
}
}
else
{
logger.warn("Could not find 'Custom Content Types' configuration section");
}
}
return this.objectTypes;
}
/**
* @return Determines whether the next and finish button should be enabled
*/
public boolean getNextFinishDisabled()
{
boolean disabled = false;
if (this.fileName == null || this.fileName.length() == 0 ||
this.title == null || this.title.length() == 0 ||
this.contentType == null)
{
disabled = true;
}
return disabled;
}
/**
* Returns the display label for the content type currently chosen
*
* @return The human readable version of the content type
*/
protected String getSummaryContentType()
{
ServiceRegistry registry = Repository.getServiceRegistry(FacesContext.getCurrentInstance());
MimetypeService mimetypeService = registry.getMimetypeService();
// get the mime type display name
Map<String, String> mimeTypes = mimetypeService.getDisplaysByMimetype();
return mimeTypes.get(this.contentType);
}
/**
* Returns the display label for the currently selected object type
*
* @return The objevt type label
*/
protected String getSummaryObjectType()
{
String objType = null;
for (SelectItem item : this.getObjectTypes())
{
if (item.getValue().equals(this.objectType))
{
objType = item.getLabel();
break;
}
}
return objType;
}
/**
* Performs any processing sub classes may wish to do before commit is called
*/
protected void performCustomProcessing()
{
// used by subclasses if necessary
}
}

View File

@@ -0,0 +1,300 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.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.util.ResourceBundle;
import javax.faces.context.FacesContext;
import javax.faces.event.ValueChangeEvent;
import org.alfresco.web.app.Application;
import org.alfresco.web.bean.repository.Repository;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Handler class used by the Create In-line Content Wizard
*
* @author Kevin Roast
*/
public class CreateContentWizard extends BaseContentWizard
{
protected static final String CONTENT_TEXT = "txt";
protected static final String CONTENT_HTML = "html";
private static Log logger = LogFactory.getLog(CreateContentWizard.class);
// TODO: retrieve these from the config service
private static final String WIZARD_TITLE_ID = "create_content_title";
private static final String WIZARD_DESC_ID = "create_content_desc";
private static final String STEP1_TITLE_ID = "create_content_step1_title";
private static final String STEP1_DESCRIPTION_ID = "create_content_step1_desc";
private static final String STEP2_TITLE_ID = "create_content_step2_title";
private static final String STEP2_DESCRIPTION_ID = "create_content_step2_desc";
private static final String STEP3_TITLE_ID = "create_content_step3_title";
private static final String STEP3_DESCRIPTION_ID = "create_content_step3_desc";
// create content wizard specific properties
protected String content;
protected String createType = CONTENT_HTML;
/**
* Deals with the finish button being pressed
*
* @return outcome
*/
public String finish()
{
return saveContent(null, this.content);
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#getWizardDescription()
*/
public String getWizardDescription()
{
return Application.getMessage(FacesContext.getCurrentInstance(), WIZARD_DESC_ID);
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#getWizardTitle()
*/
public String getWizardTitle()
{
return Application.getMessage(FacesContext.getCurrentInstance(), WIZARD_TITLE_ID);
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#getStepDescription()
*/
public String getStepDescription()
{
String stepDesc = null;
switch (this.currentStep)
{
case 1:
{
stepDesc = Application.getMessage(FacesContext.getCurrentInstance(), STEP1_DESCRIPTION_ID);
break;
}
case 2:
{
stepDesc = Application.getMessage(FacesContext.getCurrentInstance(), STEP2_DESCRIPTION_ID);
break;
}
case 3:
{
stepDesc = Application.getMessage(FacesContext.getCurrentInstance(), STEP3_DESCRIPTION_ID);
break;
}
case 4:
{
stepDesc = Application.getMessage(FacesContext.getCurrentInstance(), SUMMARY_DESCRIPTION_ID);
break;
}
default:
{
stepDesc = "";
}
}
return stepDesc;
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#getStepInstructions()
*/
public String getStepInstructions()
{
String stepInstruction = null;
switch (this.currentStep)
{
case 4:
{
stepInstruction = Application.getMessage(FacesContext.getCurrentInstance(), FINISH_INSTRUCTION_ID);
break;
}
default:
{
stepInstruction = Application.getMessage(FacesContext.getCurrentInstance(), DEFAULT_INSTRUCTION_ID);
}
}
return stepInstruction;
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#getStepTitle()
*/
public String getStepTitle()
{
String stepTitle = null;
switch (this.currentStep)
{
case 1:
{
stepTitle = Application.getMessage(FacesContext.getCurrentInstance(), STEP1_TITLE_ID);
break;
}
case 2:
{
stepTitle = Application.getMessage(FacesContext.getCurrentInstance(), STEP2_TITLE_ID);
break;
}
case 3:
{
stepTitle = Application.getMessage(FacesContext.getCurrentInstance(), STEP3_TITLE_ID);
break;
}
case 4:
{
stepTitle = Application.getMessage(FacesContext.getCurrentInstance(), SUMMARY_TITLE_ID);
break;
}
default:
{
stepTitle = "";
}
}
return stepTitle;
}
/**
* @return Returns the content from the edited form.
*/
public String getContent()
{
return this.content;
}
/**
* @param content The content to edit (should be clear initially)
*/
public void setContent(String content)
{
this.content = content;
}
/**
* Initialises the wizard
*/
public void init()
{
super.init();
this.content = null;
// created content is inline editable by default
this.inlineEdit = true;
}
/**
* @return Returns the summary data for the wizard.
*/
public String getSummary()
{
ResourceBundle bundle = Application.getBundle(FacesContext.getCurrentInstance());
// TODO: show first few lines of content here?
return buildSummary(
new String[] {bundle.getString("file_name"), bundle.getString("type"),
bundle.getString("content_type"), bundle.getString("title"),
bundle.getString("description"), bundle.getString("author")},
new String[] {this.fileName, getSummaryObjectType(), getSummaryContentType(),
this.title, this.description, this.author});
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#determineOutcomeForStep(int)
*/
protected String determineOutcomeForStep(int step)
{
String outcome = null;
switch(step)
{
case 1:
{
outcome = "select";
break;
}
case 2:
{
if (getCreateType().equals(CONTENT_HTML))
{
outcome = "create-html";
}
else if (getCreateType().equals(CONTENT_TEXT))
{
outcome = "create-text";
}
break;
}
case 3:
{
this.fileName = "newfile." + getCreateType();
this.contentType = Repository.getMimeTypeForFileName(
FacesContext.getCurrentInstance(), this.fileName);
this.title = this.fileName;
outcome = "properties";
break;
}
case 4:
{
outcome = "summary";
break;
}
default:
{
outcome = CANCEL_OUTCOME;
}
}
return outcome;
}
/**
* Create content type value changed by the user
*/
public void createContentChanged(ValueChangeEvent event)
{
// clear the content as HTML is not compatible with the plain text box etc.
this.content = null;
}
/**
* @return Returns the createType.
*/
public String getCreateType()
{
return this.createType;
}
/**
* @param createType The createType to set.
*/
public void setCreateType(String createType)
{
this.createType = createType;
}
}

View File

@@ -0,0 +1,806 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.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.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.ResourceBundle;
import java.util.Set;
import javax.faces.component.UISelectOne;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;
import javax.faces.model.SelectItem;
import javax.transaction.UserTransaction;
import org.alfresco.model.ContentModel;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.security.AuthorityService;
import org.alfresco.service.cmr.security.AuthorityType;
import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.cmr.security.PersonService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.web.app.Application;
import org.alfresco.web.app.context.UIContextService;
import org.alfresco.web.bean.repository.Node;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.bean.repository.User;
import org.alfresco.web.ui.common.SortableSelectItem;
import org.alfresco.web.ui.common.Utils;
import org.alfresco.web.ui.common.component.UIGenericPicker;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
/**
* @author Kevin Roast
*/
public class InviteUsersWizard extends AbstractWizardBean
{
private static Log logger = LogFactory.getLog(InviteUsersWizard.class);
/** I18N message strings */
private static final String MSG_USERS = "users";
private static final String MSG_GROUPS = "groups";
private static final String MSG_INVITED_SPACE = "invite_space";
private static final String MSG_INVITED_ROLE = "invite_role";
private static final String WIZARD_TITLE_ID = "invite_title";
private static final String WIZARD_DESC_ID = "invite_desc";
private static final String STEP1_TITLE_ID = "invite_step1_title";
private static final String STEP1_DESCRIPTION_ID = "invite_step1_desc";
private static final String STEP2_TITLE_ID = "invite_step2_title";
private static final String STEP2_DESCRIPTION_ID = "invite_step2_desc";
private static final String FINISH_INSTRUCTION_ID = "invite_finish_instruction";
private static final String NOTIFY_YES = "yes";
/** NamespaceService bean reference */
private NamespaceService namespaceService;
/** JavaMailSender bean reference */
private JavaMailSender mailSender;
/** AuthorityService bean reference */
private AuthorityService authorityService;
/** PermissionService bean reference */
private PermissionService permissionService;
/** personService bean reference */
private PersonService personService;
/** datamodel for table of roles for users */
private DataModel userRolesDataModel = null;
/** list of user/group role wrapper objects */
private List<UserGroupRole> userGroupRoles = null;
/** Cache of available folder permissions */
Set<String> folderPermissions = null;
/** dialog state */
private String notify = NOTIFY_YES;
private String subject = null;
private String body = null;
private String internalSubject = null;
private String automaticText = null;
/**
* @param namespaceService The NamespaceService to set.
*/
public void setNamespaceService(NamespaceService namespaceService)
{
this.namespaceService = namespaceService;
}
/**
* @param mailSender The JavaMailSender to set.
*/
public void setMailSender(JavaMailSender mailSender)
{
this.mailSender = mailSender;
}
/**
* @param permissionService The PermissionService to set.
*/
public void setPermissionService(PermissionService permissionService)
{
this.permissionService = permissionService;
}
/**
* @param permissionService The PermissionService to set.
*/
public void setPersonService(PersonService personService)
{
this.personService = personService;
}
/**
* @param authorityService The authorityService to set.
*/
public void setAuthorityService(AuthorityService authorityService)
{
this.authorityService = authorityService;
}
/**
* Initialises the wizard
*/
public void init()
{
super.init();
notify = NOTIFY_YES;
userGroupRoles = new ArrayList<UserGroupRole>(8);
subject = "";
body = "";
automaticText = "";
internalSubject = null;
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#finish()
*/
public String finish()
{
String outcome = FINISH_OUTCOME;
UserTransaction tx = null;
try
{
FacesContext context = FacesContext.getCurrentInstance();
tx = Repository.getUserTransaction(context);
tx.begin();
String subject = this.subject;
if (subject == null || subject.length() == 0)
{
subject = this.internalSubject;
}
User user = Application.getCurrentUser(context);
String from = (String)this.nodeService.getProperty(user.getPerson(), ContentModel.PROP_EMAIL);
if (from == null || from.length() == 0)
{
// TODO: get this from spring config?
from = "alfresco@alfresco.org";
}
// get the Space to apply changes too
NodeRef folderNodeRef = this.browseBean.getActionSpace().getNodeRef();
// set permissions for each user and send them a mail
for (int i=0; i<this.userGroupRoles.size(); i++)
{
UserGroupRole userGroupRole = this.userGroupRoles.get(i);
String authority = userGroupRole.getAuthority();
// find the selected permission ref from it's name and apply for the specified user
Set<String> perms = getFolderPermissions();
for (String permission : perms)
{
if (userGroupRole.getRole().equals(permission))
{
this.permissionService.setPermission(
folderNodeRef,
authority,
permission,
true);
break;
}
}
// Create the mail message for sending to each User
if (NOTIFY_YES.equals(this.notify))
{
// if User, email then, else if Group get all members and email them
AuthorityType authType = AuthorityType.getAuthorityType(authority);
if (authType.equals(AuthorityType.USER))
{
if (this.personService.personExists(authority) == true)
{
notifyUser(this.personService.getPerson(authority), folderNodeRef, from, userGroupRole.getRole());
}
}
else if (authType.equals(AuthorityType.GROUP))
{
// else notify all members of the group
Set<String> users = this.authorityService.getContainedAuthorities(AuthorityType.USER, authority, false);
for (String userAuth : users)
{
if (this.personService.personExists(userAuth) == true)
{
notifyUser(this.personService.getPerson(userAuth), folderNodeRef, from, userGroupRole.getRole());
}
}
}
}
}
// commit the transaction
tx.commit();
UIContextService.getInstance(context).notifyBeans();
}
catch (Exception e)
{
// rollback the transaction
try { if (tx != null) {tx.rollback();} } catch (Exception ex) {}
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(
FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), e.getMessage()), e);
outcome = null;
}
return outcome;
}
/**
* Send an email notification to the specified User authority
*
* @param person Person node representing the user
* @param folder Folder node they are invited too
* @param from From text message
* @param roleText The role display label for the user invite notification
*/
private void notifyUser(NodeRef person, NodeRef folder, String from, String roleText)
{
String to = (String)this.nodeService.getProperty(person, ContentModel.PROP_EMAIL);
if (to != null && to.length() != 0)
{
String msgRole = Application.getMessage(FacesContext.getCurrentInstance(), MSG_INVITED_ROLE);
String roleMessage = MessageFormat.format(msgRole, new Object[] {roleText});
// TODO: include External Authentication link to the invited space
//String args = folder.getStoreRef().getProtocol() + '/' +
// folder.getStoreRef().getIdentifier() + '/' +
// folder.getId();
//String url = ExternalAccessServlet.generateExternalURL(LoginBean.OUTCOME_SPACEDETAILS, args);
String body = this.internalSubject + "\r\n\r\n" + roleMessage + "\r\n\r\n";// + url + "\r\n\r\n";
if (this.body != null && this.body.length() != 0)
{
body += this.body;
}
SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
simpleMailMessage.setTo(to);
simpleMailMessage.setSubject(subject);
simpleMailMessage.setText(body);
simpleMailMessage.setFrom(from);
if (logger.isDebugEnabled())
logger.debug("Sending notification email to: " + to + "\n...with subject:\n" + subject + "\n...with body:\n" + body);
try
{
// Send the message
this.mailSender.send(simpleMailMessage);
}
catch (Throwable e)
{
// don't stop the action but let admins know email is not getting sent
logger.error("Failed to send email to " + to, e);
}
}
}
/**
* Returns the properties for current user-roles JSF DataModel
*
* @return JSF DataModel representing the current user-roles
*/
public DataModel getUserRolesDataModel()
{
if (this.userRolesDataModel == null)
{
this.userRolesDataModel = new ListDataModel();
}
this.userRolesDataModel.setWrappedData(this.userGroupRoles);
return this.userRolesDataModel;
}
/**
* Query callback method executed by the Generic Picker component.
* This method is part of the contract to the Generic Picker, it is up to the backing bean
* to execute whatever query is appropriate and return the results.
*
* @param filterIndex Index of the filter drop-down selection
* @param contains Text from the contains textbox
*
* @return An array of SelectItem objects containing the results to display in the picker.
*/
public SelectItem[] pickerCallback(int filterIndex, String contains)
{
FacesContext context = FacesContext.getCurrentInstance();
SelectItem[] items;
UserTransaction tx = null;
try
{
tx = Repository.getUserTransaction(context, true);
tx.begin();
if (filterIndex == 0)
{
// build xpath to match available User/Person objects
NodeRef peopleRef = personService.getPeopleContainer();
// NOTE: see SearcherComponentTest
String xpath = "*[like(@" + NamespaceService.CONTENT_MODEL_PREFIX + ":" + "firstName, '%" + contains + "%', false)" +
" or " + "like(@" + NamespaceService.CONTENT_MODEL_PREFIX + ":" + "lastName, '%" + contains + "%', false)]";
List<NodeRef> nodes = searchService.selectNodes(
peopleRef,
xpath,
null,
this.namespaceService,
false);
items = new SelectItem[nodes.size()];
for (int index=0; index<nodes.size(); index++)
{
NodeRef personRef = nodes.get(index);
String firstName = (String)this.nodeService.getProperty(personRef, ContentModel.PROP_FIRSTNAME);
String lastName = (String)this.nodeService.getProperty(personRef, ContentModel.PROP_LASTNAME);
String username = (String)this.nodeService.getProperty(personRef, ContentModel.PROP_USERNAME);
SelectItem item = new SortableSelectItem(username, firstName + " " + lastName, lastName);
items[index] = item;
}
}
else
{
// groups - simple text based match on name
Set<String> groups = authorityService.getAllAuthorities(AuthorityType.GROUP);
groups.addAll(authorityService.getAllAuthorities(AuthorityType.EVERYONE));
List<SelectItem> results = new ArrayList<SelectItem>(groups.size());
String containsLower = contains.toLowerCase();
int offset = PermissionService.GROUP_PREFIX.length();
for (String group : groups)
{
if (group.toLowerCase().indexOf(containsLower) != -1)
{
results.add(new SortableSelectItem(group, group.substring(offset), group));
}
}
items = new SelectItem[results.size()];
results.toArray(items);
}
Arrays.sort(items);
// commit the transaction
tx.commit();
}
catch (Exception err)
{
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(
FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), err.getMessage()), err );
try { if (tx != null) {tx.rollback();} } catch (Exception tex) {}
items = new SelectItem[0];
}
return items;
}
/**
* Action handler called when the Add button is pressed to process the current selection
*/
public void addSelection(ActionEvent event)
{
UIGenericPicker picker = (UIGenericPicker)event.getComponent().findComponent("picker");
UISelectOne rolePicker = (UISelectOne)event.getComponent().findComponent("roles");
String[] results = picker.getSelectedResults();
if (results != null)
{
String role = (String)rolePicker.getValue();
if (role != null)
{
for (int i=0; i<results.length; i++)
{
String authority = results[i];
// only add if authority not already present in the list with same role
boolean foundExisting = false;
for (int n=0; n<this.userGroupRoles.size(); n++)
{
UserGroupRole wrapper = this.userGroupRoles.get(n);
if (authority.equals(wrapper.getAuthority()) &&
role.equals(wrapper.getRole()))
{
foundExisting = true;
break;
}
}
if (foundExisting == false)
{
StringBuilder label = new StringBuilder(64);
// build a display label showing the user and their role for the space
AuthorityType authType = AuthorityType.getAuthorityType(authority);
if (authType.equals(AuthorityType.USER))
{
if (this.personService.personExists(authority) == true)
{
// found a User authority
NodeRef ref = this.personService.getPerson(authority);
String firstName = (String)this.nodeService.getProperty(ref, ContentModel.PROP_FIRSTNAME);
String lastName = (String)this.nodeService.getProperty(ref, ContentModel.PROP_LASTNAME);
label.append(firstName)
.append(" ")
.append(lastName)
.append(" (")
.append(Application.getMessage(FacesContext.getCurrentInstance(), role))
.append(")");
}
}
else
{
// found a group authority
label.append(authority.substring(PermissionService.GROUP_PREFIX.length()));
}
this.userGroupRoles.add(new UserGroupRole(authority, role, label.toString()));
}
}
}
}
}
/**
* Action handler called when the Remove button is pressed to remove a user+role
*/
public void removeSelection(ActionEvent event)
{
UserGroupRole wrapper = (UserGroupRole)this.userRolesDataModel.getRowData();
if (wrapper != null)
{
this.userGroupRoles.remove(wrapper);
}
}
/**
* Property accessed by the Generic Picker component.
*
* @return the array of filter options to show in the users/groups picker
*/
public SelectItem[] getFilters()
{
ResourceBundle bundle = Application.getBundle(FacesContext.getCurrentInstance());
return new SelectItem[] {
new SelectItem("0", bundle.getString(MSG_USERS)),
new SelectItem("1", bundle.getString(MSG_GROUPS)) };
}
/**
* @return The list of available roles for the users/groups
*/
public SelectItem[] getRoles()
{
ResourceBundle bundle = Application.getBundle(FacesContext.getCurrentInstance());
// get available roles (grouped permissions) from the permission service
Set<String> perms = getFolderPermissions();
SelectItem[] roles = new SelectItem[perms.size()];
int index = 0;
for (String permission : perms)
{
String displayLabel = bundle.getString(permission);
roles[index++] = new SelectItem(permission, displayLabel);
}
return roles;
}
/**
* @return Returns the notify listbox selection.
*/
public String getNotify()
{
return this.notify;
}
/**
* @param notify The notify listbox selection to set.
*/
public void setNotify(String notify)
{
this.notify = notify;
}
/**
* @return Returns the automaticText.
*/
public String getAutomaticText()
{
return this.automaticText;
}
/**
* @param automaticText The automaticText to set.
*/
public void setAutomaticText(String automaticText)
{
this.automaticText = automaticText;
}
/**
* @return Returns the email body text.
*/
public String getBody()
{
return this.body;
}
/**
* @param body The email body text to set.
*/
public void setBody(String body)
{
this.body = body;
}
/**
* @return Returns the email subject text.
*/
public String getSubject()
{
return this.subject;
}
/**
* @param subject The email subject text to set.
*/
public void setSubject(String subject)
{
this.subject = subject;
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#getWizardDescription()
*/
public String getWizardDescription()
{
return Application.getMessage(FacesContext.getCurrentInstance(), WIZARD_DESC_ID);
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#getWizardTitle()
*/
public String getWizardTitle()
{
return Application.getMessage(FacesContext.getCurrentInstance(), WIZARD_TITLE_ID);
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#getStepDescription()
*/
public String getStepDescription()
{
String stepDesc = null;
switch (this.currentStep)
{
case 1:
{
stepDesc = Application.getMessage(FacesContext.getCurrentInstance(), STEP1_DESCRIPTION_ID);
break;
}
case 2:
{
stepDesc = Application.getMessage(FacesContext.getCurrentInstance(), STEP2_DESCRIPTION_ID);
break;
}
default:
{
stepDesc = "";
}
}
return stepDesc;
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#getStepTitle()
*/
public String getStepTitle()
{
String stepTitle = null;
switch (this.currentStep)
{
case 1:
{
stepTitle = Application.getMessage(FacesContext.getCurrentInstance(), STEP1_TITLE_ID);
break;
}
case 2:
{
stepTitle = Application.getMessage(FacesContext.getCurrentInstance(), STEP2_TITLE_ID);
break;
}
default:
{
stepTitle = "";
}
}
return stepTitle;
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#getStepInstructions()
*/
public String getStepInstructions()
{
String stepInstruction = null;
switch (this.currentStep)
{
case 2:
{
stepInstruction = Application.getMessage(FacesContext.getCurrentInstance(), FINISH_INSTRUCTION_ID);
break;
}
default:
{
stepInstruction = Application.getMessage(FacesContext.getCurrentInstance(), DEFAULT_INSTRUCTION_ID);
}
}
return stepInstruction;
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#next()
*/
public String next()
{
String outcome = super.next();
if (outcome.equals("notify"))
{
FacesContext context = FacesContext.getCurrentInstance();
// prepare automatic text for email and screen
StringBuilder buf = new StringBuilder(256);
String personName = Application.getCurrentUser(context).getFullName(getNodeService());
String msgInvite = Application.getMessage(context, MSG_INVITED_SPACE);
Node node = this.browseBean.getActionSpace();
String path = this.nodeService.getPath(node.getNodeRef()).toDisplayPath(this.nodeService);
buf.append(MessageFormat.format(msgInvite, new Object[] {
path + '/' + node.getName(),
personName}) );
this.internalSubject = buf.toString();
buf.append("<br>");
String msgRole = Application.getMessage(context, MSG_INVITED_ROLE);
String roleText;
if (this.userGroupRoles.size() != 0)
{
String roleMsg = Application.getMessage(context, userGroupRoles.get(0).getRole());
roleText = MessageFormat.format(msgRole, roleMsg);
}
else
{
roleText = MessageFormat.format(msgRole, "[role]");
}
buf.append(roleText);
this.automaticText = buf.toString();
}
return outcome;
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#determineOutcomeForStep(int)
*/
protected String determineOutcomeForStep(int step)
{
String outcome = null;
switch(step)
{
case 1:
{
outcome = "invite";
break;
}
case 2:
{
outcome = "notify";
break;
}
default:
{
outcome = CANCEL_OUTCOME;
}
}
return outcome;
}
/**
* @return a cached list of available folder permissions
*/
private Set<String> getFolderPermissions()
{
if (this.folderPermissions == null)
{
this.folderPermissions = this.permissionService.getSettablePermissions(ContentModel.TYPE_FOLDER);
}
return this.folderPermissions;
}
/**
* Simple wrapper class to represent a user/group and a role combination
*/
public static class UserGroupRole
{
public UserGroupRole(String authority, String role, String label)
{
this.authority = authority;
this.role = role;
this.label = label;
}
public String getAuthority()
{
return this.authority;
}
public String getRole()
{
return this.role;
}
public String getLabel()
{
return this.label;
}
private String authority;
private String role;
private String label;
}
}

View File

@@ -0,0 +1,236 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.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.Map;
import javax.faces.context.FacesContext;
import javax.transaction.UserTransaction;
import org.alfresco.service.cmr.action.Action;
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;
/**
* Handler class used by the New Action Wizard
*
* @author Kevin Roast
*/
public class NewActionWizard extends BaseActionWizard
{
private static Log logger = LogFactory.getLog(NewActionWizard.class);
private static final String ERROR = "error_action";
// TODO: retrieve these from the config service
private static final String WIZARD_TITLE_ID = "create_action_title";
private static final String WIZARD_DESC_ID = "create_action_desc";
private static final String STEP1_TITLE_ID = "create_action_step1_title";
private static final String STEP2_TITLE_ID = "create_action_step2_title";
private static final String FINISH_INSTRUCTION_ID = "create_action_finish_instruction";
/**
* Deals with the finish button being pressed
*
* @return outcome
*/
public String finish()
{
String outcome = FINISH_OUTCOME;
UserTransaction tx = null;
try
{
tx = Repository.getUserTransaction(FacesContext.getCurrentInstance());
tx.begin();
// build the action params map based on the selected action instance
Map<String, Serializable> actionParams = buildActionParams();
// build the action to execute
Action action = this.actionService.createAction(getAction());
action.setParameterValues(actionParams);
// execute the action on the current document node
this.actionService.executeAction(action, this.browseBean.getDocument().getNodeRef());
if (logger.isDebugEnabled())
{
logger.debug("Executed action '" + this.action +
"' with action params of " +
this.currentActionProperties);
}
// reset the current document properties/aspects in case we have changed them
// during the execution of the custom action
this.browseBean.getDocument().reset();
// 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(
FacesContext.getCurrentInstance(), ERROR), e.getMessage()), e);
outcome = null;
}
return outcome;
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#getWizardDescription()
*/
public String getWizardDescription()
{
return Application.getMessage(FacesContext.getCurrentInstance(), WIZARD_DESC_ID);
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#getWizardTitle()
*/
public String getWizardTitle()
{
return Application.getMessage(FacesContext.getCurrentInstance(), WIZARD_TITLE_ID);
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#getStepDescription()
*/
public String getStepDescription()
{
return "";
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#getStepTitle()
*/
public String getStepTitle()
{
String stepTitle = null;
switch (this.currentStep)
{
case 1:
{
stepTitle = Application.getMessage(FacesContext.getCurrentInstance(), STEP1_TITLE_ID);
break;
}
case 2:
{
stepTitle = Application.getMessage(FacesContext.getCurrentInstance(), STEP2_TITLE_ID);
break;
}
case 3:
{
stepTitle = Application.getMessage(FacesContext.getCurrentInstance(), SUMMARY_TITLE_ID);
break;
}
default:
{
stepTitle = "";
}
}
return stepTitle;
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#getStepInstructions()
*/
public String getStepInstructions()
{
String stepInstruction = null;
switch (this.currentStep)
{
case 3:
{
stepInstruction = Application.getMessage(FacesContext.getCurrentInstance(), FINISH_INSTRUCTION_ID);
break;
}
default:
{
stepInstruction = Application.getMessage(FacesContext.getCurrentInstance(), DEFAULT_INSTRUCTION_ID);
}
}
return stepInstruction;
}
/**
* Initialises the wizard
*/
public void init()
{
super.init();
}
/**
* @return Returns the summary data for the wizard.
*/
public String getSummary()
{
String summaryAction = this.actionService.getActionDefinition(
this.action).getTitle();
return buildSummary(
new String[] {"Action"},
new String[] {summaryAction});
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#determineOutcomeForStep(int)
*/
protected String determineOutcomeForStep(int step)
{
String outcome = null;
switch(step)
{
case 1:
{
outcome = "action";
break;
}
case 2:
{
outcome = this.action;
break;
}
case 3:
{
outcome = "summary";
break;
}
default:
{
outcome = CANCEL_OUTCOME;
}
}
return outcome;
}
}

View File

@@ -0,0 +1,103 @@
/*
* 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.util.ArrayList;
import java.util.List;
import javax.faces.context.FacesContext;
import org.alfresco.model.ForumModel;
import org.alfresco.web.ui.common.component.UIListItem;
/**
* Wizard bean used for creating and editing forum spaces
*
* @author gavinc
*/
public class NewForumWizard extends NewSpaceWizard
{
public static final String FORUM_ICON_DEFAULT = "forum_large";
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()
*/
public void init()
{
super.init();
this.spaceType = ForumModel.TYPE_FORUM.toString();
this.icon = FORUM_ICON_DEFAULT;
this.forumStatus = "0";
}
/**
* Returns a list of icons to allow the user to select from.
*
* @return A list of icons
*/
@SuppressWarnings("unchecked")
public List<UIListItem> getIcons()
{
// return the various forum icons
if (this.forumIcons == null)
{
this.forumIcons = new ArrayList<UIListItem>(1);
UIListItem item = new UIListItem();
item.setValue(FORUM_ICON_DEFAULT);
item.getAttributes().put("image", "/images/icons/forum_large.gif");
this.forumIcons.add(item);
}
return this.forumIcons;
}
/**
* @see org.alfresco.web.bean.wizard.NewSpaceWizard#performCustomProcessing(javax.faces.context.FacesContext)
*/
@Override
protected void performCustomProcessing(FacesContext context)
{
// add or update the ForumModel.PROP_STATUS property depending on the editMode
}
}

View File

@@ -0,0 +1,69 @@
/*
* 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.util.ArrayList;
import java.util.List;
import org.alfresco.model.ForumModel;
import org.alfresco.web.ui.common.component.UIListItem;
/**
* Wizard bean used for creating and editing forums spaces
*
* @author gavinc
*/
public class NewForumsWizard extends NewSpaceWizard
{
public static final String FORUMS_ICON_DEFAULT = "forums_large";
protected List<UIListItem> forumsIcons;
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#init()
*/
public void init()
{
super.init();
this.spaceType = ForumModel.TYPE_FORUMS.toString();
this.icon = FORUMS_ICON_DEFAULT;
}
/**
* Returns a list of icons to allow the user to select from.
*
* @return A list of icons
*/
@SuppressWarnings("unchecked")
public List<UIListItem> getIcons()
{
// return the various forums icons
if (this.forumsIcons == null)
{
this.forumsIcons = new ArrayList<UIListItem>(1);
UIListItem item = new UIListItem();
item.setValue(FORUMS_ICON_DEFAULT);
item.getAttributes().put("image", "/images/icons/forums_large.gif");
this.forumsIcons.add(item);
}
return this.forumsIcons;
}
}

View File

@@ -0,0 +1,62 @@
/*
* 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 javax.faces.context.FacesContext;
import org.alfresco.model.ForumModel;
import org.alfresco.util.GUID;
import org.alfresco.web.bean.repository.Repository;
/**
* Backing bean for posting forum articles.
*
* @author gavinc
*/
public class NewPostWizard extends CreateContentWizard
{
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#init()
*/
@Override
public void init()
{
super.init();
// set up for creating a post instead of HTML
this.createType = CONTENT_TEXT;
this.objectType = ForumModel.TYPE_POST.toString();
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#finish()
*/
@Override
public String finish()
{
// create appropriate values for filename, title and content type
this.fileName = GUID.generate() + ".txt";
this.contentType = Repository.getMimeTypeForFileName(
FacesContext.getCurrentInstance(), this.fileName);
this.title = this.fileName;
return super.finish();
}
}

View File

@@ -0,0 +1,69 @@
/*
* 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 javax.faces.event.ActionEvent;
import org.alfresco.model.ContentModel;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Backing bean for posting replies to forum articles.
*
* @author gavinc
*/
public class NewReplyWizard extends NewPostWizard
{
private static Log logger = LogFactory.getLog(NewReplyWizard.class);
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#startWizard(javax.faces.event.ActionEvent)
*/
@Override
public void startWizard(ActionEvent event)
{
super.startWizard(event);
// also setup the content in the browse bean
this.browseBean.setupContentAction(event);
}
/**
* @see org.alfresco.web.bean.wizard.BaseContentWizard#performCustomProcessing()
*/
@Override
protected void performCustomProcessing()
{
if (this.editMode == false)
{
// 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());
}
}
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,223 @@
/*
* 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.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.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.bean.repository.Repository;
import org.alfresco.web.ui.common.component.UIListItem;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Wizard bean used for creating and editing topic spaces
*
* @author gavinc
*/
public class NewTopicWizard extends NewSpaceWizard
{
public static final String TOPIC_ICON_DEFAULT = "topic_large";
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
*
* @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;
}
/**
* @param contentService The contentService to set.
*/
public void setContentService(ContentService contentService)
{
this.contentService = contentService;
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#init()
*/
public void init()
{
super.init();
this.spaceType = ForumModel.TYPE_TOPIC.toString();
this.icon = TOPIC_ICON_DEFAULT;
this.topicType = "0";
this.message = null;
}
/**
* Returns a list of icons to allow the user to select from.
*
* @return A list of icons
*/
@SuppressWarnings("unchecked")
public List<UIListItem> getIcons()
{
// return the various forum icons
if (this.topicIcons == null)
{
this.topicIcons = new ArrayList<UIListItem>(2);
UIListItem item = new UIListItem();
item.setValue(TOPIC_ICON_DEFAULT);
item.getAttributes().put("image", "/images/icons/topic_large.gif");
this.topicIcons.add(item);
}
return this.topicIcons;
}
/**
* @see org.alfresco.web.bean.wizard.NewSpaceWizard#performCustomProcessing(javax.faces.context.FacesContext)
*/
@Override
protected void performCustomProcessing(FacesContext context)
{
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";
// 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();
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(this.message);
}
}
}

View File

@@ -0,0 +1,981 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.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.List;
import java.util.Map;
import java.util.ResourceBundle;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.validator.ValidatorException;
import javax.transaction.UserTransaction;
import org.alfresco.config.ConfigService;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
import org.alfresco.service.cmr.security.AuthenticationService;
import org.alfresco.service.cmr.security.OwnableService;
import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.cmr.security.PersonService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.web.app.Application;
import org.alfresco.web.app.ContextListener;
import org.alfresco.web.app.context.UIContextService;
import org.alfresco.web.bean.repository.Node;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.bean.users.UsersBean;
import org.alfresco.web.config.ClientConfigElement;
import org.alfresco.web.ui.common.Utils;
import org.alfresco.web.ui.common.component.UIActionLink;
import org.apache.log4j.Logger;
/**
* @author Kevin Roast
*/
public class NewUserWizard extends AbstractWizardBean
{
private static Logger logger = Logger.getLogger(NewUserWizard.class);
private static final String WIZARD_TITLE_NEW_ID = "new_user_title";
private static final String WIZARD_DESC_NEW_ID = "new_user_desc";
private static final String WIZARD_TITLE_EDIT_ID = "new_user_title_edit";
private static final String WIZARD_DESC_EDIT_ID = "new_user_desc_edit";
private static final String STEP1_TITLE_ID = "new_user_step1_title";
private static final String STEP1_DESCRIPTION_ID = "new_user_step1_desc";
private static final String STEP2_TITLE_ID = "new_user_step2_title";
private static final String STEP2_DESCRIPTION_ID = "new_user_step2_desc";
private static final String FINISH_INSTRUCTION_ID = "new_user_finish_instruction";
private static final String ERROR = "error_person";
/** form variables */
private String firstName = null;
private String lastName = null;
private String userName = null;
private String password = null;
private String confirm = null;
private String email = null;
private String companyId = null;
private String homeSpaceName = "";
private NodeRef homeSpaceLocation = null;
/** AuthenticationService bean reference */
private AuthenticationService authenticationService;
/** NamespaceService bean reference */
private NamespaceService namespaceService;
/** PermissionService bean reference */
private PermissionService permissionService;
/** PersonService bean reference */
private PersonService personService;
/** OwnableService bean reference */
private OwnableService ownableService;
/** ConfigService bean reference */
private ConfigService configService;
/** action context */
private Node person = null;
/** ref to system people folder */
private NodeRef peopleRef = null;
/** ref to the company home space folder */
private NodeRef companyHomeSpaceRef = null;
/**
* @param authenticationService The AuthenticationService to set.
*/
public void setAuthenticationService(AuthenticationService authenticationService)
{
this.authenticationService = authenticationService;
}
/**
* @param namespaceService The namespaceService to set.
*/
public void setNamespaceService(NamespaceService namespaceService)
{
this.namespaceService = namespaceService;
}
/**
* @param permissionService The PermissionService to set.
*/
public void setPermissionService(PermissionService permissionService)
{
this.permissionService = permissionService;
}
/**
* @param personService The person service.
*/
public void setPersonService(PersonService personService)
{
this.personService = personService;
}
/**
* @param ownableService The ownableService to set.
*/
public void setOwnableService(OwnableService ownableService)
{
this.ownableService = ownableService;
}
/**
* @param configService The ConfigService to set.
*/
public void setConfigService(ConfigService configService)
{
this.configService = configService;
}
/**
* Initialises the wizard
*/
public void init()
{
super.init();
// reset all variables
this.firstName = "";
this.lastName = "";
this.userName = "";
this.password = "";
this.confirm = "";
this.email = "";
this.companyId = "";
this.homeSpaceName = "";
this.homeSpaceLocation = getCompanyHomeSpace();
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#populate()
*/
public void populate()
{
// set values for edit mode
Map<String, Object> props = getPerson().getProperties();
this.firstName = (String) props.get("firstName");
this.lastName = (String) props.get("lastName");
this.userName = (String) props.get("userName");
this.password = "";
this.confirm = "";
this.email = (String) props.get("email");
this.companyId = (String) props.get("organizationId");
// calculate home space name and parent space Id from homeFolderId
this.homeSpaceLocation = null; // default to Company root space
this.homeSpaceName = ""; // default to none set below root
NodeRef homeFolderRef = (NodeRef) props.get("homeFolder");
if (this.nodeService.exists(homeFolderRef) == true)
{
ChildAssociationRef childAssocRef = this.nodeService.getPrimaryParent(homeFolderRef);
NodeRef parentRef = childAssocRef.getParentRef();
if (this.nodeService.getRootNode(Repository.getStoreRef()).equals(parentRef) == false)
{
this.homeSpaceLocation = parentRef;
this.homeSpaceName = Repository.getNameForNode(nodeService, homeFolderRef);
}
else
{
this.homeSpaceLocation = homeFolderRef;
}
}
if (logger.isDebugEnabled())
logger.debug("Edit user home space location: " + homeSpaceLocation + " home space name: " + homeSpaceName);
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#getWizardDescription()
*/
public String getWizardDescription()
{
if (this.editMode)
{
return Application.getMessage(FacesContext.getCurrentInstance(), WIZARD_DESC_EDIT_ID);
}
else
{
return Application.getMessage(FacesContext.getCurrentInstance(), WIZARD_DESC_NEW_ID);
}
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#getWizardTitle()
*/
public String getWizardTitle()
{
if (this.editMode)
{
return Application.getMessage(FacesContext.getCurrentInstance(), WIZARD_TITLE_EDIT_ID);
}
else
{
return Application.getMessage(FacesContext.getCurrentInstance(), WIZARD_TITLE_NEW_ID);
}
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#getStepTitle()
*/
public String getStepTitle()
{
String stepTitle = null;
switch (this.currentStep)
{
case 1:
{
stepTitle = Application.getMessage(FacesContext.getCurrentInstance(), STEP1_TITLE_ID);
break;
}
case 2:
{
stepTitle = Application.getMessage(FacesContext.getCurrentInstance(), STEP2_TITLE_ID);
break;
}
case 3:
{
stepTitle = Application.getMessage(FacesContext.getCurrentInstance(), SUMMARY_TITLE_ID);
break;
}
default:
{
stepTitle = "";
}
}
return stepTitle;
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#getStepDescription()
*/
public String getStepDescription()
{
String stepDesc = null;
switch (this.currentStep)
{
case 1:
{
stepDesc = Application.getMessage(FacesContext.getCurrentInstance(), STEP1_DESCRIPTION_ID);
break;
}
case 2:
{
stepDesc = Application.getMessage(FacesContext.getCurrentInstance(), STEP2_DESCRIPTION_ID);
break;
}
case 3:
{
stepDesc = Application.getMessage(FacesContext.getCurrentInstance(), SUMMARY_DESCRIPTION_ID);
break;
}
default:
{
stepDesc = "";
}
}
return stepDesc;
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#getStepInstructions()
*/
public String getStepInstructions()
{
String stepInstruction = null;
switch (this.currentStep)
{
case 3:
{
stepInstruction = Application.getMessage(FacesContext.getCurrentInstance(), FINISH_INSTRUCTION_ID);
break;
}
default:
{
stepInstruction = Application.getMessage(FacesContext.getCurrentInstance(), DEFAULT_INSTRUCTION_ID);
}
}
return stepInstruction;
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#determineOutcomeForStep(int)
*/
protected String determineOutcomeForStep(int step)
{
String outcome = null;
switch (step)
{
case 1:
{
outcome = "person-properties";
break;
}
case 2:
{
outcome = "user-properties";
break;
}
case 3:
{
outcome = "summary";
break;
}
default:
{
outcome = CANCEL_OUTCOME;
}
}
return outcome;
}
/**
* @see org.alfresco.web.bean.wizard.AbstractWizardBean#finish()
*/
public String finish()
{
String outcome = FINISH_OUTCOME;
// TODO: implement create new Person object from specified details
UserTransaction tx = null;
try
{
FacesContext context = FacesContext.getCurrentInstance();
tx = Repository.getUserTransaction(context);
tx.begin();
if (this.editMode)
{
// update the existing node in the repository
NodeRef nodeRef = getPerson().getNodeRef();
Map<QName, Serializable> props = this.nodeService.getProperties(nodeRef);
props.put(ContentModel.PROP_USERNAME, this.userName);
props.put(ContentModel.PROP_FIRSTNAME, this.firstName);
props.put(ContentModel.PROP_LASTNAME, this.lastName);
// calculate whether we need to move the old home space or create new
NodeRef newHomeFolderRef;
NodeRef oldHomeFolderRef = (NodeRef)this.nodeService.getProperty(nodeRef, ContentModel.PROP_HOMEFOLDER);
boolean moveHomeSpace = false;
boolean renameHomeSpace = false;
if (oldHomeFolderRef != null && this.nodeService.exists(oldHomeFolderRef) == true)
{
// the original home folder ref exists so may need moving if it has been changed
ChildAssociationRef childAssocRef = this.nodeService.getPrimaryParent(oldHomeFolderRef);
NodeRef currentHomeSpaceLocation = childAssocRef.getParentRef();
if (this.homeSpaceName.length() != 0)
{
if (currentHomeSpaceLocation.equals(this.homeSpaceLocation) == false &&
oldHomeFolderRef.equals(this.homeSpaceLocation) == false &&
currentHomeSpaceLocation.equals(getCompanyHomeSpace()) == false)
{
moveHomeSpace = true;
}
String oldHomeSpaceName = Repository.getNameForNode(nodeService, oldHomeFolderRef);
if (oldHomeSpaceName.equals(this.homeSpaceName) == false &&
oldHomeFolderRef.equals(this.homeSpaceLocation) == false)
{
renameHomeSpace = true;
}
}
}
if (logger.isDebugEnabled())
logger.debug("Moving space: " + moveHomeSpace + " and renaming space: " + renameHomeSpace);
if (moveHomeSpace == false && renameHomeSpace == false)
{
if (this.homeSpaceLocation != null && this.homeSpaceName.length() != 0)
{
newHomeFolderRef = createHomeSpace(this.homeSpaceLocation.getId(), this.homeSpaceName, false);
}
else if (this.homeSpaceLocation != null)
{
// location selected but no home space name entered,
// so the home ref should be set to the newly selected space
newHomeFolderRef = this.homeSpaceLocation;
// set the permissions for this space so the user can access it
}
else
{
// nothing selected - use Company Home by default
newHomeFolderRef = getCompanyHomeSpace();
}
}
else
{
// either move, rename or both required
if (moveHomeSpace == true)
{
this.nodeService.moveNode(
oldHomeFolderRef,
this.homeSpaceLocation,
ContentModel.ASSOC_CONTAINS,
this.nodeService.getPrimaryParent(oldHomeFolderRef).getQName());
}
newHomeFolderRef = oldHomeFolderRef; // ref ID doesn't change
if (renameHomeSpace == true)
{
// change HomeSpace node name
this.nodeService.setProperty(newHomeFolderRef, ContentModel.PROP_NAME, this.homeSpaceName);
}
}
props.put(ContentModel.PROP_HOMEFOLDER, newHomeFolderRef);
props.put(ContentModel.PROP_EMAIL, this.email);
props.put(ContentModel.PROP_ORGID, this.companyId);
this.nodeService.setProperties(nodeRef, props);
// TODO: RESET HomeSpace Ref found in top-level navigation bar!
// NOTE: not need cos only admin can do this?
}
else
{
if (this.password.equals(this.confirm))
{
if (!this.personService.getUserNamesAreCaseSensitive())
{
this.userName = this.userName.toLowerCase();
}
// create properties for Person type from submitted Form data
Map<QName, Serializable> props = new HashMap<QName, Serializable>(7, 1.0f);
props.put(ContentModel.PROP_USERNAME, this.userName);
props.put(ContentModel.PROP_FIRSTNAME, this.firstName);
props.put(ContentModel.PROP_LASTNAME, this.lastName);
NodeRef homeSpaceNodeRef;
if (this.homeSpaceLocation != null && this.homeSpaceName.length() != 0)
{
// create new
homeSpaceNodeRef = createHomeSpace(this.homeSpaceLocation.getId(), this.homeSpaceName, true);
}
else if (this.homeSpaceLocation != null)
{
// set to existing
homeSpaceNodeRef = homeSpaceLocation;
setupHomeSpacePermissions(homeSpaceNodeRef);
}
else
{
// default to Company Home
homeSpaceNodeRef = getCompanyHomeSpace();
}
props.put(ContentModel.PROP_HOMEFOLDER, homeSpaceNodeRef);
props.put(ContentModel.PROP_EMAIL, this.email);
props.put(ContentModel.PROP_ORGID, this.companyId);
// create the node to represent the Person
String assocName = QName.createValidLocalName(this.userName);
NodeRef newPerson = this.personService.createPerson(props);
// ensure the user can access their own Person object
this.permissionService.setPermission(newPerson, this.userName, permissionService.getAllPermission(), true);
if (logger.isDebugEnabled()) logger.debug("Created Person node for username: " + this.userName);
// create the ACEGI Authentication instance for the new user
this.authenticationService.createAuthentication(this.userName, this.password.toCharArray());
if (logger.isDebugEnabled()) logger.debug("Created User Authentication instance for username: " + this.userName);
}
else
{
outcome = null;
Utils.addErrorMessage(Application.getMessage(context, UsersBean.ERROR_PASSWORD_MATCH));
}
}
// commit the transaction
tx.commit();
// reset the richlist component so it rebinds to the users list
invalidateUserList();
}
catch (Exception e)
{
// rollback the transaction
try { if (tx != null) {tx.rollback();} } catch (Exception tex) {}
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), ERROR), e
.getMessage()), e);
outcome = null;
}
return outcome;
}
/**
* @return Returns the summary data for the wizard.
*/
public String getSummary()
{
String homeSpaceLabel = this.homeSpaceName;
if (this.homeSpaceName.length() == 0 && this.homeSpaceLocation != null)
{
homeSpaceLabel = Repository.getNameForNode(this.nodeService, this.homeSpaceLocation);
}
ResourceBundle bundle = Application.getBundle(FacesContext.getCurrentInstance());
return buildSummary(new String[] { bundle.getString("name"), bundle.getString("username"),
bundle.getString("password"), bundle.getString("homespace") }, new String[] {
this.firstName + " " + this.lastName, this.userName, "********", homeSpaceLabel });
}
/**
* Init the users screen
*/
public void setupUsers(ActionEvent event)
{
invalidateUserList();
}
/**
* Action listener called when the wizard is being launched for editing an
* existing node.
*/
public void startWizardForEdit(ActionEvent event)
{
UIActionLink link = (UIActionLink) event.getComponent();
Map<String, String> params = link.getParameterMap();
String id = params.get("id");
if (id != null && id.length() != 0)
{
try
{
// create the node ref, then our node representation
NodeRef ref = new NodeRef(Repository.getStoreRef(), id);
Node node = new Node(ref);
// remember the Person node
setPerson(node);
// set the wizard in edit mode
this.editMode = true;
// populate the wizard's default values with the current value
// from the node being edited
init();
populate();
// clear the UI state in preparation for finishing the action
// and returning to the main page
invalidateUserList();
if (logger.isDebugEnabled()) logger.debug("Started wizard : " + getWizardTitle() + " for editing");
}
catch (InvalidNodeRefException refErr)
{
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(),
Repository.ERROR_NODEREF), new Object[] { id }));
}
}
else
{
setPerson(null);
}
}
/**
* @return Returns the companyId.
*/
public String getCompanyId()
{
return this.companyId;
}
/**
* @param companyId
* The companyId to set.
*/
public void setCompanyId(String companyId)
{
this.companyId = companyId;
}
/**
* @return Returns the email.
*/
public String getEmail()
{
return this.email;
}
/**
* @param email
* The email to set.
*/
public void setEmail(String email)
{
this.email = email;
}
/**
* @return Returns the firstName.
*/
public String getFirstName()
{
return this.firstName;
}
/**
* @param firstName The firstName to set.
*/
public void setFirstName(String firstName)
{
this.firstName = firstName;
}
/**
* @return Returns the homeSpaceLocation.
*/
public NodeRef getHomeSpaceLocation()
{
return this.homeSpaceLocation;
}
/**
* @param homeSpaceLocation The homeSpaceLocation to set.
*/
public void setHomeSpaceLocation(NodeRef homeSpaceLocation)
{
this.homeSpaceLocation = homeSpaceLocation;
}
/**
* @return Returns the homeSpaceName.
*/
public String getHomeSpaceName()
{
return this.homeSpaceName;
}
/**
* @param homeSpaceName The homeSpaceName to set.
*/
public void setHomeSpaceName(String homeSpaceName)
{
this.homeSpaceName = homeSpaceName;
}
/**
* @return Returns the lastName.
*/
public String getLastName()
{
return this.lastName;
}
/**
* @param lastName The lastName to set.
*/
public void setLastName(String lastName)
{
this.lastName = lastName;
}
/**
* @return Returns the userName.
*/
public String getUserName()
{
return this.userName;
}
/**
* @param userName The userName to set.
*/
public void setUserName(String userName)
{
this.userName = userName;
}
/**
* @return Returns the password.
*/
public String getPassword()
{
return this.password;
}
/**
* @param password The password to set.
*/
public void setPassword(String password)
{
this.password = password;
}
/**
* @return Returns the confirm password.
*/
public String getConfirm()
{
return this.confirm;
}
/**
* @param confirm The confirm password to set.
*/
public void setConfirm(String confirm)
{
this.confirm = confirm;
}
/**
* @return Returns the person context.
*/
public Node getPerson()
{
return this.person;
}
/**
* @param person The person context to set.
*/
public void setPerson(Node person)
{
this.person = person;
}
public boolean getEditMode()
{
return this.editMode;
}
// ------------------------------------------------------------------------------
// Validator methods
/**
* Validate password field data is acceptable
*/
public void validatePassword(FacesContext context, UIComponent component, Object value) throws ValidatorException
{
String pass = (String) value;
if (pass.length() < 5 || pass.length() > 12)
{
String err = "Password must be between 5 and 12 characters in length.";
throw new ValidatorException(new FacesMessage(err));
}
for (int i = 0; i < pass.length(); i++)
{
if (Character.isLetterOrDigit(pass.charAt(i)) == false)
{
String err = "Password can only contain characters or digits.";
throw new ValidatorException(new FacesMessage(err));
}
}
}
/**
* Validate Username field data is acceptable
*/
public void validateUsername(FacesContext context, UIComponent component, Object value) throws ValidatorException
{
String pass = (String) value;
if (pass.length() < 5 || pass.length() > 12)
{
String err = "Username must be between 5 and 12 characters in length.";
throw new ValidatorException(new FacesMessage(err));
}
for (int i = 0; i < pass.length(); i++)
{
if (Character.isLetterOrDigit(pass.charAt(i)) == false)
{
String err = "Username can only contain characters or digits.";
throw new ValidatorException(new FacesMessage(err));
}
}
}
// ------------------------------------------------------------------------------
// Helper methods
/**
* Helper to return the company home space
*
* @return company home space NodeRef
*/
private NodeRef getCompanyHomeSpace()
{
if (this.companyHomeSpaceRef == null)
{
String companyXPath = Application.getRootPath(FacesContext.getCurrentInstance());
NodeRef rootNodeRef = this.nodeService.getRootNode(Repository.getStoreRef());
List<NodeRef> nodes = this.searchService.selectNodes(rootNodeRef, companyXPath, null, this.namespaceService,
false);
if (nodes.size() == 0)
{
throw new IllegalStateException("Unable to find company home space path: " + companyXPath);
}
this.companyHomeSpaceRef = nodes.get(0);
}
return this.companyHomeSpaceRef;
}
/**
* Create the specified home space if it does not exist, and return the ID
*
* @param locationId
* Parent location
* @param spaceName
* Home space to create, can be null to simply return the parent
* @param error
* True to throw an error if the space already exists, else
* ignore and return
*
* @return ID of the home space
*/
private NodeRef createHomeSpace(String locationId, String spaceName, boolean error)
{
String homeSpaceId = locationId;
NodeRef homeSpaceNodeRef = null;
if (spaceName != null && spaceName.length() != 0)
{
NodeRef parentRef = new NodeRef(Repository.getStoreRef(), locationId);
// check for existance of home space with same name - return immediately
// if it exists or throw an exception an give user chance to enter another name
// TODO: this might be better replaced with an XPath query!
List<ChildAssociationRef> children = this.nodeService.getChildAssocs(parentRef);
for (ChildAssociationRef ref : children)
{
String childNodeName = (String) this.nodeService.getProperty(ref.getChildRef(), ContentModel.PROP_NAME);
if (spaceName.equals(childNodeName))
{
if (error)
{
throw new AlfrescoRuntimeException("A Home Space with the same name already exists.");
}
else
{
return ref.getChildRef();
}
}
}
// space does not exist already, create a new Space under it with
// the specified name
String qname = QName.createValidLocalName(spaceName);
ChildAssociationRef assocRef = this.nodeService.createNode(parentRef, ContentModel.ASSOC_CONTAINS,
QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, qname), ContentModel.TYPE_FOLDER);
NodeRef nodeRef = assocRef.getChildRef();
// set the name property on the node
this.nodeService.setProperty(nodeRef, ContentModel.PROP_NAME, spaceName);
if (logger.isDebugEnabled()) logger.debug("Created Home Space for with name: " + spaceName);
// apply the uifacets aspect - icon, title and description props
Map<QName, Serializable> uiFacetsProps = new HashMap<QName, Serializable>(3);
uiFacetsProps.put(ContentModel.PROP_ICON, NewSpaceWizard.SPACE_ICON_DEFAULT);
uiFacetsProps.put(ContentModel.PROP_TITLE, spaceName);
this.nodeService.addAspect(nodeRef, ContentModel.ASPECT_UIFACETS, uiFacetsProps);
setupHomeSpacePermissions(nodeRef);
// return the ID of the created space
homeSpaceNodeRef = nodeRef;
homeSpaceId = nodeRef.getId();
}
return homeSpaceNodeRef;
}
/**
* Setup the default permissions for this and other users on the Home Space
*
* @param homeSpaceRef Home Space reference
*/
private void setupHomeSpacePermissions(NodeRef homeSpaceRef)
{
// Admin Authority has full permissions by default (automatic - set in the permission config)
// give full permissions to the new user
this.permissionService.setPermission(homeSpaceRef, this.userName, permissionService.getAllPermission(), true);
// by default other users will only have GUEST access to the space contents
// or whatever is configured as the default in the web-client-xml config
String permission = getDefaultPermission();
if (permission != null && permission.length() != 0)
{
this.permissionService.setPermission(homeSpaceRef, permissionService.getAllAuthorities(), permission, true);
}
// the new user is the OWNER of their own space and always has full permissions
this.ownableService.setOwner(homeSpaceRef, this.userName);
this.permissionService.setPermission(homeSpaceRef, permissionService.getOwnerAuthority(), permissionService.getAllPermission(), true);
// now detach (if we did this first we could not set any permissions!)
this.permissionService.setInheritParentPermissions(homeSpaceRef, false);
}
/**
* @return default permission string to set for other users for a new Home Space
*/
private String getDefaultPermission()
{
ClientConfigElement config = (ClientConfigElement)this.configService.getGlobalConfig().getConfigElement(
ClientConfigElement.CONFIG_ELEMENT_ID);
return config.getHomeSpacePermission();
}
private void invalidateUserList()
{
UIContextService.getInstance(FacesContext.getCurrentInstance()).notifyBeans();
}
}