diff --git a/source/java/org/alfresco/web/bean/wcm/AVMEditBean.java b/source/java/org/alfresco/web/bean/wcm/AVMEditBean.java index 654e075c11..ccea987d33 100644 --- a/source/java/org/alfresco/web/bean/wcm/AVMEditBean.java +++ b/source/java/org/alfresco/web/bean/wcm/AVMEditBean.java @@ -21,6 +21,7 @@ import java.io.File; import java.io.FileNotFoundException; import java.text.MessageFormat; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; import javax.faces.context.FacesContext; @@ -590,12 +591,44 @@ public class AVMEditBean if (LOGGER.isDebugEnabled()) LOGGER.debug("regenerating renditions of " + fid); + String originalParentAvmPath = (String) + this.nodeService.getProperty(((FormInstanceDataImpl)fid).getNodeRef(), + WCMAppModel.PROP_ORIGINAL_PARENT_PATH); + if (originalParentAvmPath == null) + { + originalParentAvmPath = AVMNodeConverter.SplitBase(avmPath)[0]; + } + final HashSet allRets = + new HashSet(this.getForm().getRenderingEngineTemplates()); - for (RenderingEngineTemplate ret : this.getForm().getRenderingEngineTemplates()) + // regenerate existing renditions + for (final Rendition r : fid.getRenditions()) + { + final RenderingEngineTemplate ret = r.getRenderingEngineTemplate(); + if (!allRets.contains(ret)) + { + continue; + } + try + { + ret.render(fid, r); + allRets.remove(ret); + } + catch (Exception e) + { + Utils.addErrorMessage("error regenerating rendition using " + ret.getName() + + ": " + e.getMessage(), + e); + } + } + + // render all renditions for newly added templates + for (final RenderingEngineTemplate ret : allRets) { try { - ret.render(fid); + final String path = ret.getOutputPathForRendition(fid, originalParentAvmPath); + ret.render(fid, path); } catch (Exception e) { diff --git a/source/java/org/alfresco/web/bean/wcm/CreateWebContentWizard.java b/source/java/org/alfresco/web/bean/wcm/CreateWebContentWizard.java index db497d2d7a..3ba2c948df 100644 --- a/source/java/org/alfresco/web/bean/wcm/CreateWebContentWizard.java +++ b/source/java/org/alfresco/web/bean/wcm/CreateWebContentWizard.java @@ -465,16 +465,16 @@ public class CreateWebContentWizard extends BaseContentWizard if (LOGGER.isDebugEnabled()) LOGGER.debug("saving file content to " + fileName); - String path = this.avmBrowseBean.getCurrentPath(); - path = AVMConstants.getCorrespondingPathInPreviewStore(path); + final String cwd = AVMConstants.getCorrespondingPathInPreviewStore(this.avmBrowseBean.getCurrentPath()); final Form form = (MimetypeMap.MIMETYPE_XML.equals(this.mimeType) ? this.getForm() : null); + String path = null; if (form != null) { path = form.getOutputPathForFormInstanceData(this.instanceDataDocument, fileName, - path, + cwd, this.avmBrowseBean.getWebapp()); this.content = XMLUtil.toString(this.instanceDataDocument, false); final String[] sb = AVMNodeConverter.SplitBase(path); @@ -513,6 +513,7 @@ public class CreateWebContentWizard extends BaseContentWizard }; props.clear(); props.put(WCMAppModel.PROP_PARENT_FORM_NAME, form.getName()); + props.put(WCMAppModel.PROP_ORIGINAL_PARENT_PATH, cwd); this.nodeService.addAspect(formInstanceDataNodeRef, WCMAppModel.ASPECT_FORM_INSTANCE_DATA, props); this.renditions = new LinkedList(); @@ -520,7 +521,8 @@ public class CreateWebContentWizard extends BaseContentWizard { try { - this.renditions.add(ret.render(this.formInstanceData)); + path = ret.getOutputPathForRendition(this.formInstanceData, cwd); + this.renditions.add(ret.render(this.formInstanceData, path)); } catch (Exception e) { diff --git a/source/java/org/alfresco/web/forms/FormImpl.java b/source/java/org/alfresco/web/forms/FormImpl.java index 3b95442484..3f7d0e5bbb 100644 --- a/source/java/org/alfresco/web/forms/FormImpl.java +++ b/source/java/org/alfresco/web/forms/FormImpl.java @@ -154,6 +154,7 @@ public class FormImpl root.put("xml", NodeModel.wrap(formInstanceData)); root.put("name", formInstanceDataName); root.put("date", new SimpleDate(new Date(), SimpleDate.DATETIME)); + root.put("cwd", AVMConstants.getWebappRelativePath(parentAVMPath)); final TemplateService templateService = this.getServiceRegistry().getTemplateService(); diff --git a/source/java/org/alfresco/web/forms/RenderingEngineTemplate.java b/source/java/org/alfresco/web/forms/RenderingEngineTemplate.java index 233709400d..c8d836fd5c 100644 --- a/source/java/org/alfresco/web/forms/RenderingEngineTemplate.java +++ b/source/java/org/alfresco/web/forms/RenderingEngineTemplate.java @@ -69,9 +69,13 @@ public interface RenderingEngineTemplate /** * Returns the output path for the rendition. * + * @param formInstanceData the form instance data to use for + * processing the pattern. + * @param currentAVMPath the current path where the form is being created. * @return the output path for the rendition. */ - public String getOutputPathForRendition(final FormInstanceData formInstanceData); + public String getOutputPathForRendition(final FormInstanceData formInstanceData, + final String currentAVMPath); /** * Returns the mimetype to use when generating content for this @@ -87,8 +91,10 @@ public interface RenderingEngineTemplate * * @param formInstanceData the form instance data for which to produce * the rendition. + * @param renditionAVMPath the path to use for the rendition. */ - public Rendition render(final FormInstanceData formInstanceData) + public Rendition render(final FormInstanceData formInstanceData, + final String renditionAVMPath) throws IOException, SAXException, RenderingEngine.RenderingException; diff --git a/source/java/org/alfresco/web/forms/RenderingEngineTemplateImpl.java b/source/java/org/alfresco/web/forms/RenderingEngineTemplateImpl.java index 7ab1c46dbb..390f5131a7 100644 --- a/source/java/org/alfresco/web/forms/RenderingEngineTemplateImpl.java +++ b/source/java/org/alfresco/web/forms/RenderingEngineTemplateImpl.java @@ -178,9 +178,12 @@ public class RenderingEngineTemplateImpl * Generates an output path for the rendition by compiling the output path pattern * as a freemarker template. * + * @param formInstanceData the form instance data to use for the rendition path. + * @param currentAVMPath the current path in which the form is being created. + * * @return the output path to use for renditions. */ - public String getOutputPathForRendition(final FormInstanceData formInstanceData /*,final String parentAVMPath */) + public String getOutputPathForRendition(final FormInstanceData formInstanceData, final String currentAVMPath) { final ServiceRegistry sr = this.getServiceRegistry(); final NodeService nodeService = sr.getNodeService(); @@ -212,11 +215,12 @@ public class RenderingEngineTemplateImpl LOGGER.error(e); throw new AlfrescoRuntimeException(e.getMessage(), e); } + final String parentAVMPath = AVMNodeConverter.SplitBase(formInstanceDataAVMPath)[0]; root.put("xml", NodeModel.wrap(formInstanceDataDocument)); root.put("node", new TemplateNode(((FormInstanceDataImpl)formInstanceData).getNodeRef(), sr, null)); root.put("date", new SimpleDate(new Date(), SimpleDate.DATETIME)); - + root.put("cwd", AVMConstants.getWebappRelativePath(currentAVMPath)); final TemplateService templateService = sr.getTemplateService(); final String outputPathPattern = (FreeMarkerUtil.buildNamespaceDeclaration(formInstanceDataDocument) + this.getOutputPathPattern()); @@ -236,7 +240,7 @@ public class RenderingEngineTemplateImpl ":\n" + te.getMessage(), te); } - final String parentAVMPath = AVMNodeConverter.SplitBase(formInstanceDataAVMPath)[0]; + result = AVMConstants.buildPath(parentAVMPath, result, AVMConstants.PathRelation.SANDBOX_RELATIVE); @@ -251,13 +255,13 @@ public class RenderingEngineTemplateImpl WCMAppModel.PROP_MIMETYPE_FOR_RENDITION); } - public Rendition render(final FormInstanceData formInstanceData) + public Rendition render(final FormInstanceData formInstanceData, + final String renditionAvmPath) throws IOException, SAXException, RenderingEngine.RenderingException { final AVMService avmService = this.getServiceRegistry().getAVMService(); - final String renditionAvmPath = this.getOutputPathForRendition(formInstanceData); final boolean isRegenerate = avmService.lookup(-1, renditionAvmPath) != null; if (!isRegenerate) { @@ -559,5 +563,10 @@ public class RenderingEngineTemplateImpl final FacesContext fc = FacesContext.getCurrentInstance(); return Repository.getServiceRegistry(fc); } + + public int hashCode() + { + return this.getName().hashCode(); + } } diff --git a/source/web/jsp/wcm/output-path-pattern-help.jsp b/source/web/jsp/wcm/output-path-pattern-help.jsp index 65129f572f..dddfc5bdfb 100644 --- a/source/web/jsp/wcm/output-path-pattern-help.jsp +++ b/source/web/jsp/wcm/output-path-pattern-help.jsp @@ -18,10 +18,12 @@ nameThe name of the form instance data as entered by the user in the create web content wizard. webappThe name of the webapp in which the form instance data is being created. Typically, if specifying an absolute output path pattern, the path will begin with the webapp folder (i.e. /${webapp}/...) + cwdThe webapp relative path in which the form is being created. extensionThe default extension associated with the mime-type configured for the rendering engine template. This variable is only available for rendition ouput path patterns. xmlThe xml instance data collected by the form. nodeThe form instance data node. This variable is only available for rendition ouput path patterns. dateThe current date at which the form instance data is being saved. Refer to the FreeMarker date reference for more information. +