mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
8372: Merged V2.1 to V2.2 8314: Merged V2.0 to V2.1 7750: Fix for ACT-475: ContentStoreCleaner causes OutOfMemoryError 8332: Made content URL column larger to accommodate the extra locale info present in 2.1 8334: Build fix: V2.1 tighter on authentication for getTempWriter 8376: Merged V2.1 to V2.2 8325: Fix for AWC-1089 8361: Workaround for WCM-882: All metadata extracters can now handle zero length files git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@8497 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
260 lines
10 KiB
Java
260 lines
10 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.wcm;
|
|
|
|
import java.util.LinkedList;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
import org.alfresco.repo.content.MimetypeMap;
|
|
import org.alfresco.service.cmr.avm.locking.AVMLock;
|
|
import org.alfresco.service.cmr.repository.ContentWriter;
|
|
import org.alfresco.web.app.Application;
|
|
import org.alfresco.web.forms.Form;
|
|
import org.alfresco.web.forms.FormInstanceData;
|
|
import org.alfresco.web.forms.FormNotFoundException;
|
|
import org.alfresco.web.forms.Rendition;
|
|
import org.alfresco.web.forms.XMLUtil;
|
|
import org.alfresco.web.ui.common.Utils;
|
|
import org.apache.commons.logging.Log;
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
/**
|
|
* Bean implementation for the "Edit Web Content Wizard" dialog
|
|
*/
|
|
public class EditWebContentWizard extends CreateWebContentWizard
|
|
{
|
|
private static final long serialVersionUID = 439996926303151006L;
|
|
|
|
private static final Log logger = LogFactory.getLog(EditWebContentWizard.class);
|
|
|
|
private AVMNode avmNode;
|
|
private Form form;
|
|
|
|
private boolean wasFormLockPresent = false;
|
|
private boolean wasRenditionLockPresent = false;
|
|
|
|
// ------------------------------------------------------------------------------
|
|
// Wizard implementation
|
|
|
|
@Override
|
|
public void init(final Map<String, String> parameters)
|
|
{
|
|
super.init(parameters);
|
|
this.avmNode = this.avmBrowseBean.getAvmActionNode();
|
|
if (this.avmNode == null)
|
|
{
|
|
throw new IllegalArgumentException("Edit Form wizard requires action node context.");
|
|
}
|
|
|
|
if (logger.isDebugEnabled())
|
|
logger.debug("path is " + this.avmNode.getPath());
|
|
|
|
this.createdPath = AVMUtil.getCorrespondingPathInPreviewStore(this.avmNode.getPath());
|
|
this.formInstanceData = this.getFormsService().getFormInstanceData(-1, this.createdPath);
|
|
final WebProject webProject = new WebProject(this.createdPath);
|
|
try
|
|
{
|
|
this.formName = this.formInstanceData.getForm().getName();
|
|
this.form = webProject.getForm(this.formName);
|
|
}
|
|
catch (FormNotFoundException fnfe)
|
|
{
|
|
Utils.addErrorMessage(fnfe.getMessage(), fnfe);
|
|
}
|
|
this.content = this.getAvmService().getContentReader(-1, this.createdPath).getContentString();
|
|
this.fileName = this.formInstanceData.getName();
|
|
this.mimeType = MimetypeMap.MIMETYPE_XML;
|
|
this.wasFormLockPresent = false;
|
|
this.wasRenditionLockPresent = false;
|
|
}
|
|
|
|
@Override
|
|
public String cancel()
|
|
{
|
|
if (this.formInstanceData != null && this.renditions != null)
|
|
{
|
|
if (this.wasFormLockPresent == false)
|
|
{
|
|
// there wasn't a lock on the form at the start of the
|
|
// wizard so remove the one present now
|
|
if (logger.isDebugEnabled())
|
|
logger.debug("removing form instance data lock from " +
|
|
AVMUtil.getCorrespondingPathInMainStore(this.createdPath) +
|
|
" as user chose to cancel");
|
|
|
|
this.getAvmLockingService().removeLock(AVMUtil.getStoreId(this.createdPath),
|
|
AVMUtil.getStoreRelativePath(this.createdPath));
|
|
}
|
|
|
|
if (this.wasRenditionLockPresent == false)
|
|
{
|
|
// there weren't locks on renditions at the start of
|
|
// the wizard so remove the ones present now
|
|
for (Rendition r : this.renditions)
|
|
{
|
|
if (logger.isDebugEnabled())
|
|
logger.debug("removing lock from " +
|
|
AVMUtil.getCorrespondingPathInMainStore(r.getPath()) +
|
|
" as user chose to cancel");
|
|
|
|
this.getAvmLockingService().removeLock(AVMUtil.getStoreId(r.getPath()),
|
|
AVMUtil.getStoreRelativePath(r.getPath()));
|
|
}
|
|
}
|
|
}
|
|
|
|
return super.cancel();
|
|
}
|
|
|
|
@Override
|
|
public String back()
|
|
{
|
|
if ("content".equals(Application.getWizardManager().getCurrentStepName()))
|
|
{
|
|
//override in order not to delete these items
|
|
this.formInstanceData = null;
|
|
this.renditions = null;
|
|
}
|
|
return super.back();
|
|
}
|
|
|
|
@Override
|
|
protected void saveContent()
|
|
throws Exception
|
|
{
|
|
if (logger.isDebugEnabled())
|
|
logger.debug("saving " + this.createdPath);
|
|
|
|
AVMLock lock = this.getAvmLockingService().getLock(AVMUtil.getStoreId(this.createdPath),
|
|
AVMUtil.getStoreRelativePath(this.createdPath));
|
|
if (lock != null)
|
|
{
|
|
if (logger.isDebugEnabled())
|
|
logger.debug("transferring lock from " + lock.getStore() +
|
|
" to " + AVMUtil.getStoreName(this.createdPath));
|
|
|
|
this.getAvmLockingService().modifyLock(AVMUtil.getStoreId(this.createdPath),
|
|
AVMUtil.getStoreRelativePath(this.createdPath),
|
|
null,
|
|
AVMUtil.getStoreName(this.createdPath),
|
|
null,
|
|
null);
|
|
|
|
// set the lock present flag
|
|
this.wasFormLockPresent = true;
|
|
}
|
|
|
|
final ContentWriter writer = this.getAvmService().getContentWriter(this.createdPath);
|
|
this.content = XMLUtil.toString(this.getInstanceDataDocument(), false);
|
|
writer.putContent(this.content);
|
|
|
|
// XXXarielb might not need to do this reload
|
|
this.formInstanceData = this.getFormsService().getFormInstanceData(-1, this.createdPath);
|
|
for (final Rendition r : this.formInstanceData.getRenditions())
|
|
{
|
|
lock = this.getAvmLockingService().getLock(AVMUtil.getStoreId(r.getPath()),
|
|
AVMUtil.getStoreRelativePath(r.getPath()));
|
|
if (lock != null)
|
|
{
|
|
if (logger.isDebugEnabled())
|
|
logger.debug("transferring lock from " + lock.getStore() +
|
|
" to " + AVMUtil.getStoreName(r.getPath()));
|
|
|
|
this.getAvmLockingService().modifyLock(AVMUtil.getStoreId(r.getPath()),
|
|
AVMUtil.getStoreRelativePath(r.getPath()),
|
|
null,
|
|
AVMUtil.getStoreName(r.getPath()),
|
|
null,
|
|
null);
|
|
|
|
// set the lock present flag
|
|
this.wasRenditionLockPresent = true;
|
|
}
|
|
}
|
|
final List<FormInstanceData.RegenerateResult> result = this.formInstanceData.regenerateRenditions();
|
|
this.renditions = new LinkedList<Rendition>();
|
|
for (FormInstanceData.RegenerateResult rr : result)
|
|
{
|
|
if (rr.getException() != null)
|
|
{
|
|
Utils.addErrorMessage("error regenerating rendition using " + rr.getRenderingEngineTemplate().getName() +
|
|
": " + rr.getException().getMessage(),
|
|
rr.getException());
|
|
}
|
|
else
|
|
{
|
|
final Rendition r = rr.getRendition();
|
|
this.renditions.add(r);
|
|
|
|
if (logger.isDebugEnabled())
|
|
logger.debug("transferring lock for " + r.getPath() +
|
|
" back to " + AVMUtil.getCorrespondingMainStoreName(AVMUtil.getStoreName(r.getPath())));
|
|
|
|
this.getAvmLockingService().modifyLock(AVMUtil.getStoreId(r.getPath()),
|
|
AVMUtil.getStoreRelativePath(r.getPath()),
|
|
null,
|
|
AVMUtil.getCorrespondingMainStoreName(AVMUtil.getStoreName(r.getPath())),
|
|
null,
|
|
null);
|
|
}
|
|
}
|
|
|
|
if (logger.isDebugEnabled())
|
|
logger.debug("transferring form instance data lock back to " +
|
|
AVMUtil.getCorrespondingMainStoreName(AVMUtil.getStoreName(this.createdPath)));
|
|
|
|
this.getAvmLockingService().modifyLock(AVMUtil.getStoreId(this.createdPath),
|
|
AVMUtil.getStoreRelativePath(this.createdPath),
|
|
null,
|
|
AVMUtil.getCorrespondingMainStoreName(AVMUtil.getStoreName(this.createdPath)),
|
|
null,
|
|
null);
|
|
}
|
|
|
|
/** Indicates whether or not the wizard is currently in edit mode */
|
|
@Override
|
|
public boolean getEditMode()
|
|
{
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public boolean getSubmittable()
|
|
{
|
|
return !AVMUtil.isWorkflowStore(AVMUtil.getStoreName(this.createdPath));
|
|
}
|
|
|
|
/**
|
|
* Overridden to avoid calling getWebProject since potentially there is no web project
|
|
* context in workflow scenario.
|
|
*/
|
|
@Override
|
|
public Form getForm()
|
|
{
|
|
return this.form;
|
|
}
|
|
}
|