mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
15897: Merged V3.1 to V3.2 14485: (RECORD ONLY) ETHREEOH-1937 14915: (RECORD ONLY) Fix for ETHREEOH-2011: chaining-authentication-context.xml.sample 14954: (RECORD ONLY) Fix merge error 14966: (RECORD ONLY) Merged V2.2 to V3.1 14131: *RECORD ONLY* 14605: Merged HEAD to V2.2 (workaround for ETWOTWO-1137) 14368: Fix for ETHREEOH-1936 14607: Fixed NPE in TextMiningContentTransformer: Lead-up to fix for ETWOTWO-1174 14992: (RECORD ONLY) Updated svn:mergeinfo for V2.1-A 15080: Applied suggested fix for ETHREEOH-2252: Emailed content created in wrong space 15131: Merged V2.1-A to V3.1 (ETHREEOH-2270) 13465: Fix for ADB-161 ACT 7870 - added 'xsd' to mimetype map. 15134: Merged V2.2 to V3.1 14332: (RECORD-ONLY) 14717: (RECORD-ONLY) 14745: (RECORD-ONLY) 14746: Fixed error relating to detection and clean-up of duplicate child associations 14759: Missed check-in: Set transactionService for post-transaction duplicate child assoc cleanup 14761: (RECORD-ONLY) 14885: (RECORD-ONLY) 14893: (RECORD-ONLY) 14903: (RECORD-ONLY) 15204: Fixed ETHREEOH-2303: FixNameCrcValuesPatch throws ConstraintViolationException during upgrade ... 15214: Fixed ETHREEOH-1861: Offline synchronization updates file content without any changes 15271: Applied patch fix: Imported users don't conform to case-sensitivity switch 15352: ETHREEOH-2322 15361: ETHREEOH-1112 15369: ETHREEOH-2448 15419: ETHREEOH-2479 15431: ETHREEOH-2520 and ETHREEOH-2521 15587: (RECORD ONLY) Moved Enterprise-only scripts to correct location 15616: Fix ETHREEOH-2581 - WCM layered folder - can't submit deleted file 15675: WCM fixes (ETHREEOH-2110 & ETHREEOH-2645) 15836: Check for null username in ContentUsage service getUserUsage() method 15840: (RECORD ONLY) Merged V3.2 to V3.1 14760: Fix for ALFCOM-586 - trims and ignores leading/trailing whitespace before validation in JSF client forms. 15841: Fixes for ETHREEOH-2702 and ETHREEOH-2687 15860: (RECORD ONLY) Added Oracle and MS SQL Server config 15891: Removed unused compiler directive ___________________________________________________________________ Modified: svn:mergeinfo Merged /alfresco/BRANCHES/DEV/BELARUS/ETHREEOH-2221:r14753 Merged /alfresco/BRANCHES/V2.1-A: lots Merged /alfresco/BRANCHES/V2.2:r14131,14332,14605,14607,14717,14745-14746,14759,14761,14885,14893,14903 Merged /alfresco/BRANCHES/V3.1:r14485,14915,14954,14966,14992,15080,15131,15134,15204,15214,15271,15352,15361,15369,15419,15431,15587,15616,15675,15818,15836,15840-15841,15860,15891 Merged /alfresco/BRANCHES/V3.2:r15897 git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@16886 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
416 lines
13 KiB
Java
416 lines
13 KiB
Java
/*
|
|
* Copyright (C) 2005-2007 Alfresco Software Limited.
|
|
*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public License
|
|
* as published by the Free Software Foundation; either version 2
|
|
* of the License, or (at your option) any later version.
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
* As a special exception to the terms and conditions of version 2.0 of
|
|
* the GPL, you may redistribute this Program in connection with Free/Libre
|
|
* and Open Source Software ("FLOSS") applications as described in Alfresco's
|
|
* FLOSS exception. You should have recieved a copy of the text describing
|
|
* the FLOSS exception, and it is also available here:
|
|
* http://www.alfresco.com/legal/licensing"
|
|
*/
|
|
package org.alfresco.web.bean.content;
|
|
|
|
import java.io.Serializable;
|
|
import java.text.MessageFormat;
|
|
import java.util.ArrayList;
|
|
import java.util.Collection;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.ResourceBundle;
|
|
|
|
import javax.faces.context.FacesContext;
|
|
import javax.faces.event.ValueChangeEvent;
|
|
import javax.faces.model.SelectItem;
|
|
|
|
import org.alfresco.config.Config;
|
|
import org.alfresco.config.ConfigElement;
|
|
import org.alfresco.config.ConfigService;
|
|
import org.alfresco.model.WCMAppModel;
|
|
import org.alfresco.repo.content.MimetypeMap;
|
|
import org.alfresco.service.cmr.model.FileExistsException;
|
|
import org.alfresco.service.namespace.QName;
|
|
import org.alfresco.web.app.AlfrescoNavigationHandler;
|
|
import org.alfresco.web.app.Application;
|
|
import org.alfresco.web.app.servlet.FacesHelper;
|
|
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.forms.Form;
|
|
import org.alfresco.web.forms.FormNotFoundException;
|
|
import org.alfresco.web.forms.FormProcessor;
|
|
import org.alfresco.web.forms.FormsService;
|
|
import org.alfresco.web.forms.XMLUtil;
|
|
import org.alfresco.web.ui.common.Utils;
|
|
import org.apache.commons.io.FilenameUtils;
|
|
import org.apache.commons.logging.Log;
|
|
import org.apache.commons.logging.LogFactory;
|
|
import org.w3c.dom.Document;
|
|
|
|
/**
|
|
* Bean implementation for the "Create Content Wizard" dialog
|
|
*
|
|
* @author gavinc
|
|
*/
|
|
public class CreateContentWizard extends BaseContentWizard
|
|
{
|
|
private static final long serialVersionUID = -2740634368271194418L;
|
|
|
|
protected String content = null;
|
|
protected List<SelectItem> createMimeTypes;
|
|
|
|
transient protected FormsService formsService;
|
|
protected String formName;
|
|
protected FormProcessor.Session formProcessorSession = null;
|
|
transient protected Document instanceDataDocument = null;
|
|
|
|
private static Log logger = LogFactory.getLog(CreateContentWizard.class);
|
|
|
|
|
|
/**
|
|
* @param formsService The FormsService to set.
|
|
*/
|
|
public void setFormsService(final FormsService formsService)
|
|
{
|
|
this.formsService = formsService;
|
|
}
|
|
|
|
/**
|
|
* @return the formsService
|
|
*/
|
|
private FormsService getFormsService()
|
|
{
|
|
//check for null for cluster environment
|
|
if (formsService == null)
|
|
{
|
|
formsService = (FormsService) FacesHelper.getManagedBean(FacesContext.getCurrentInstance(), "FormsService");
|
|
}
|
|
return formsService;
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------
|
|
// Wizard implementation
|
|
|
|
|
|
@Override
|
|
public String finish()
|
|
{
|
|
// if a form is entered, then save the form instance data as XML ...
|
|
if (this.instanceDataDocument != null)
|
|
{
|
|
this.content = XMLUtil.toString(this.instanceDataDocument, true);
|
|
|
|
this.mimeType = MimetypeMap.MIMETYPE_XML; // belts & braces - override mimetype (in case is not set to XML)
|
|
}
|
|
|
|
String result = super.finish();
|
|
|
|
if ((super.createdNode != null) && (this.instanceDataDocument != null))
|
|
{
|
|
final Map<QName, Serializable> props = new HashMap<QName, Serializable>(1, 1.0f);
|
|
props.put(WCMAppModel.PROP_PARENT_FORM_NAME, getFormName());
|
|
props.put(WCMAppModel.PROP_ORIGINAL_PARENT_PATH, "");
|
|
getNodeService().addAspect(super.createdNode, WCMAppModel.ASPECT_FORM_INSTANCE_DATA, props);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
@Override
|
|
protected String finishImpl(FacesContext context, String outcome)
|
|
throws Exception
|
|
{
|
|
saveContent(null, this.content);
|
|
|
|
// return the default outcome
|
|
return outcome;
|
|
}
|
|
|
|
@Override
|
|
public void init(Map<String, String> parameters)
|
|
{
|
|
super.init(parameters);
|
|
|
|
this.content = null;
|
|
this.inlineEdit = true;
|
|
this.mimeType = MimetypeMap.MIMETYPE_HTML;
|
|
this.formName = "";
|
|
|
|
this.instanceDataDocument = null;
|
|
if (this.formProcessorSession != null)
|
|
{
|
|
this.formProcessorSession.destroy();
|
|
}
|
|
this.formProcessorSession = null;
|
|
}
|
|
|
|
@Override
|
|
public boolean getNextButtonDisabled()
|
|
{
|
|
// TODO: Allow the next button state to be configured so that
|
|
// wizard implementations don't have to worry about
|
|
// checking step numbers
|
|
|
|
boolean disabled = false;
|
|
int step = Application.getWizardManager().getCurrentStep();
|
|
switch(step)
|
|
{
|
|
case 1:
|
|
{
|
|
disabled = (this.fileName == null || this.fileName.length() == 0);
|
|
break;
|
|
}
|
|
}
|
|
|
|
return disabled;
|
|
}
|
|
|
|
|
|
@Override
|
|
public boolean getFinishButtonDisabled()
|
|
{
|
|
boolean disabled = false;
|
|
int step = Application.getWizardManager().getCurrentStep();
|
|
switch(step)
|
|
{
|
|
case 1:
|
|
{
|
|
disabled = (this.fileName == null || this.fileName.length() == 0);
|
|
break;
|
|
}
|
|
}
|
|
|
|
return disabled;
|
|
}
|
|
|
|
@Override
|
|
protected String doPostCommitProcessing(FacesContext context, String outcome)
|
|
{
|
|
// as we were successful, go to the set properties dialog if asked
|
|
// to otherwise just return
|
|
if (this.showOtherProperties)
|
|
{
|
|
// we are going to immediately edit the properties so we need
|
|
// to setup the BrowseBean context appropriately
|
|
this.browseBean.setDocument(new Node(this.createdNode));
|
|
|
|
return getDefaultFinishOutcome() + AlfrescoNavigationHandler.OUTCOME_SEPARATOR +
|
|
"dialog:setContentProperties";
|
|
}
|
|
else
|
|
{
|
|
return outcome;
|
|
}
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------
|
|
// Bean Getters and Setters
|
|
|
|
/**
|
|
* @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;
|
|
}
|
|
|
|
/**
|
|
* @return Returns a list of mime types to allow the user to select from
|
|
*/
|
|
public List<SelectItem> getCreateMimeTypes()
|
|
{
|
|
if ((this.createMimeTypes == null) || (Application.isDynamicConfig(FacesContext.getCurrentInstance())))
|
|
{
|
|
FacesContext context = FacesContext.getCurrentInstance();
|
|
|
|
// add the well known object type to start with
|
|
this.createMimeTypes = new ArrayList<SelectItem>(5);
|
|
|
|
// add the configured create mime types to the list
|
|
ConfigService svc = Application.getConfigService(context);
|
|
Config wizardCfg = svc.getConfig("Content Wizards");
|
|
if (wizardCfg != null)
|
|
{
|
|
ConfigElement typesCfg = wizardCfg.getConfigElement("create-mime-types");
|
|
if (typesCfg != null)
|
|
{
|
|
for (ConfigElement child : typesCfg.getChildren())
|
|
{
|
|
String currentMimeType = child.getAttribute("name");
|
|
if (currentMimeType != null)
|
|
{
|
|
String label = getSummaryMimeType(currentMimeType);
|
|
this.createMimeTypes.add(new SelectItem(currentMimeType, 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 'create-mime-types' configuration element");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
logger.warn("Could not find 'Content Wizards' configuration section");
|
|
}
|
|
|
|
}
|
|
|
|
return this.createMimeTypes;
|
|
}
|
|
|
|
/**
|
|
* @return Returns the summary data for the wizard.
|
|
*/
|
|
public String getSummary()
|
|
{
|
|
ResourceBundle bundle = Application.getBundle(FacesContext.getCurrentInstance());
|
|
|
|
if (this.instanceDataDocument != null)
|
|
{
|
|
this.mimeType = MimetypeMap.MIMETYPE_XML; // belts & braces - override mimetype (in case is not set to XML)
|
|
}
|
|
|
|
// TODO: show first few lines of content here?
|
|
return buildSummary(
|
|
new String[] {bundle.getString("file_name"),
|
|
bundle.getString("type"),
|
|
bundle.getString("content_type")},
|
|
new String[] {Utils.encode(this.fileName), getSummaryObjectType(),
|
|
getSummaryMimeType(this.mimeType)});
|
|
}
|
|
|
|
/**
|
|
* @return List of UI items to represent the full list of available ECM Forms
|
|
*/
|
|
public List<SelectItem> getFormsList()
|
|
{
|
|
Collection<Form> forms = this.getFormsService().getForms();
|
|
List<SelectItem> items = new ArrayList<SelectItem>(forms.size()+1);
|
|
items.add(new SelectItem("", ""));
|
|
for (Form form : forms)
|
|
{
|
|
items.add(new SelectItem(form.getName(), form.getTitle()));
|
|
}
|
|
return items;
|
|
}
|
|
|
|
public String getFormName()
|
|
{
|
|
return this.formName;
|
|
}
|
|
|
|
public void setFormName(String formName)
|
|
{
|
|
this.formName = formName;
|
|
}
|
|
|
|
public Form getForm() throws FormNotFoundException
|
|
{
|
|
return (this.getFormName() != null
|
|
? getFormsService().getForm(formName)
|
|
: null);
|
|
}
|
|
|
|
public FormProcessor.Session getFormProcessorSession()
|
|
{
|
|
return this.formProcessorSession;
|
|
}
|
|
|
|
public void setFormProcessorSession(final FormProcessor.Session formProcessorSession)
|
|
{
|
|
this.formProcessorSession = formProcessorSession;
|
|
}
|
|
|
|
public Document getInstanceDataDocument()
|
|
{
|
|
if (this.instanceDataDocument == null)
|
|
{
|
|
final String content = this.getContent();
|
|
try
|
|
{
|
|
this.instanceDataDocument = (content != null
|
|
? XMLUtil.parse(content)
|
|
: XMLUtil.newDocument());
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Utils.addErrorMessage("error parsing document", e);
|
|
this.instanceDataDocument = XMLUtil.newDocument();
|
|
}
|
|
}
|
|
return this.instanceDataDocument;
|
|
}
|
|
|
|
/** Overrides in order to strip an xml extension if the user entered it */
|
|
// TODO do we need ? it is currently referenced in create-forms.jsp (copied from wcm create-xml.jsp)
|
|
@Override
|
|
public String getFileName()
|
|
{
|
|
final String result = super.getFileName();
|
|
return (result != null &&
|
|
MimetypeMap.MIMETYPE_XML.equals(this.mimeType) &&
|
|
this.getFormName() != null &&
|
|
"xml".equals(FilenameUtils.getExtension(result).toLowerCase())
|
|
? FilenameUtils.removeExtension(result)
|
|
: result);
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------
|
|
// Action event handlers
|
|
|
|
/**
|
|
* 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;
|
|
}
|
|
|
|
@Override
|
|
protected String formatErrorMessage(Throwable exception)
|
|
{
|
|
if (exception instanceof FileExistsException)
|
|
{
|
|
return MessageFormat.format(Application.getMessage(
|
|
FacesContext.getCurrentInstance(), Repository.ERROR_EXISTS),
|
|
((FileExistsException)exception).getName());
|
|
}
|
|
else
|
|
{
|
|
return MessageFormat.format(Application.getMessage(
|
|
FacesContext.getCurrentInstance(), "error_content"),
|
|
exception.getMessage());
|
|
}
|
|
}
|
|
|
|
}
|