diff --git a/source/java/org/alfresco/web/bean/CheckinCheckoutBean.java b/source/java/org/alfresco/web/bean/CheckinCheckoutBean.java index 1964fb629f..7db8022d9d 100644 --- a/source/java/org/alfresco/web/bean/CheckinCheckoutBean.java +++ b/source/java/org/alfresco/web/bean/CheckinCheckoutBean.java @@ -45,6 +45,8 @@ import org.alfresco.web.app.context.UIContextService; import org.alfresco.web.app.servlet.DownloadContentServlet; import org.alfresco.web.bean.repository.Node; import org.alfresco.web.bean.repository.Repository; +import org.alfresco.web.templating.OutputUtil; +import org.alfresco.web.templating.TemplatingService; import org.alfresco.web.ui.common.Utils; import org.alfresco.web.ui.common.component.UIActionLink; import org.apache.commons.logging.Log; @@ -374,8 +376,8 @@ public class CheckinCheckoutBean */ private Node setupContentDocument(String id) { - if (logger.isDebugEnabled()) - logger.debug("Setup for action, setting current document to: " + id); + if (LOGGER.isDebugEnabled()) + LOGGER.debug("Setup for action, setting current document to: " + id); Node node = null; @@ -425,14 +427,14 @@ public class CheckinCheckoutBean tx = Repository.getUserTransaction(FacesContext.getCurrentInstance()); tx.begin(); - if (logger.isDebugEnabled()) - logger.debug("Trying to checkout content node Id: " + node.getId()); + if (LOGGER.isDebugEnabled()) + LOGGER.debug("Trying to checkout content node Id: " + node.getId()); // checkout the node content to create a working copy - if (logger.isDebugEnabled()) + if (LOGGER.isDebugEnabled()) { - logger.debug("Checkout copy location: " + getCopyLocation()); - logger.debug("Selected Space Id: " + this.selectedSpaceId); + LOGGER.debug("Checkout copy location: " + getCopyLocation()); + LOGGER.debug("Selected Space Id: " + this.selectedSpaceId); } NodeRef workingCopyRef; if (getCopyLocation().equals(COPYLOCATION_OTHER) && this.selectedSpaceId != null) @@ -476,7 +478,7 @@ public class CheckinCheckoutBean } else { - logger.warn("WARNING: checkoutFile called without a current Document!"); + LOGGER.warn("WARNING: checkoutFile called without a current Document!"); } return outcome; @@ -501,7 +503,7 @@ public class CheckinCheckoutBean } else { - logger.warn("WARNING: checkoutFileOK called without a current WorkingDocument!"); + LOGGER.warn("WARNING: checkoutFileOK called without a current WorkingDocument!"); } return outcome; @@ -526,7 +528,7 @@ public class CheckinCheckoutBean } else { - logger.warn("WARNING: editFileOK called without a current Document!"); + LOGGER.warn("WARNING: editFileOK called without a current Document!"); } return outcome; @@ -618,15 +620,23 @@ public class CheckinCheckoutBean tx = Repository.getUserTransaction(FacesContext.getCurrentInstance()); tx.begin(); - if (logger.isDebugEnabled()) - logger.debug("Trying to update content node Id: " + node.getId()); + if (LOGGER.isDebugEnabled()) + LOGGER.debug("Trying to update content node Id: " + node.getId()); // get an updating writer that we can use to modify the content on the current node ContentWriter writer = this.contentService.getWriter(node.getNodeRef(), ContentModel.PROP_CONTENT, true); writer.putContent(this.editorOutput); - + // commit the transaction tx.commit(); + + if (nodeService.getProperty(node.getNodeRef(), + TemplatingService.TT_QNAME) != null) + { + OutputUtil.regenerate(node.getNodeRef(), + this.contentService, + this.nodeService); + } // clean up and clear action context clearUpload(); @@ -646,7 +656,7 @@ public class CheckinCheckoutBean } else { - logger.warn("WARNING: editInlineOK called without a current Document!"); + LOGGER.warn("WARNING: editInlineOK called without a current Document!"); } return outcome; @@ -679,7 +689,7 @@ public class CheckinCheckoutBean } else { - logger.warn("WARNING: undoCheckout called without a current WorkingDocument!"); + LOGGER.warn("WARNING: undoCheckout called without a current WorkingDocument!"); } return outcome; @@ -728,7 +738,7 @@ public class CheckinCheckoutBean } else { - logger.warn("WARNING: undoCheckout called without a current WorkingDocument!"); + LOGGER.warn("WARNING: undoCheckout called without a current WorkingDocument!"); } return outcome; @@ -752,8 +762,8 @@ public class CheckinCheckoutBean tx = Repository.getUserTransaction(FacesContext.getCurrentInstance()); tx.begin(); - if (logger.isDebugEnabled()) - logger.debug("Trying to checkin content node Id: " + node.getId()); + if (LOGGER.isDebugEnabled()) + LOGGER.debug("Trying to checkin content node Id: " + node.getId()); // we can either checkin the content from the current working copy node // which would have been previously updated by the user @@ -815,7 +825,7 @@ public class CheckinCheckoutBean } else { - logger.warn("WARNING: checkinFileOK called without a current Document!"); + LOGGER.warn("WARNING: checkinFileOK called without a current Document!"); } return outcome; @@ -839,8 +849,8 @@ public class CheckinCheckoutBean tx = Repository.getUserTransaction(FacesContext.getCurrentInstance()); tx.begin(); - if (logger.isDebugEnabled()) - logger.debug("Trying to update content node Id: " + node.getId()); + if (LOGGER.isDebugEnabled()) + LOGGER.debug("Trying to update content node Id: " + node.getId()); // get an updating writer that we can use to modify the content on the current node ContentWriter writer = this.contentService.getWriter(node.getNodeRef(), ContentModel.PROP_CONTENT, true); @@ -865,7 +875,7 @@ public class CheckinCheckoutBean } else { - logger.warn("WARNING: updateFileOK called without a current Document!"); + LOGGER.warn("WARNING: updateFileOK called without a current Document!"); } return outcome; @@ -910,7 +920,7 @@ public class CheckinCheckoutBean // ------------------------------------------------------------------------------ // Private data - private static Log logger = LogFactory.getLog(CheckinCheckoutBean.class); + private static final Log LOGGER = LogFactory.getLog(CheckinCheckoutBean.class); /** I18N messages */ private static final String MSG_ERROR_CHECKIN = "error_checkin"; diff --git a/source/java/org/alfresco/web/bean/content/CreateContentWizard.java b/source/java/org/alfresco/web/bean/content/CreateContentWizard.java index 5756cbb7a3..c943b8166e 100644 --- a/source/java/org/alfresco/web/bean/content/CreateContentWizard.java +++ b/source/java/org/alfresco/web/bean/content/CreateContentWizard.java @@ -78,16 +78,14 @@ public class CreateContentWizard extends BaseContentWizard this.templateTypeName); TemplatingService ts = TemplatingService.getInstance(); TemplateType tt = this.getTemplateType(); - if (tt.getOutputMethods().size() != 0) - { - OutputUtil.generate(ts.parseXML(this.content), - tt, - this.fileName, - this.getContainerNodeRef(), - this.fileFolderService, - this.contentService, - this.nodeService); - } + OutputUtil.generate(this.createdNode, + ts.parseXML(this.content), + tt, + this.fileName, + this.getContainerNodeRef(), + this.fileFolderService, + this.contentService, + this.nodeService); } // return the default outcome diff --git a/source/java/org/alfresco/web/templating/OutputUtil.java b/source/java/org/alfresco/web/templating/OutputUtil.java index ccdd5e0aab..ee9bd854a1 100644 --- a/source/java/org/alfresco/web/templating/OutputUtil.java +++ b/source/java/org/alfresco/web/templating/OutputUtil.java @@ -42,6 +42,7 @@ import org.apache.commons.logging.LogFactory; import org.alfresco.model.ContentModel; import org.alfresco.service.cmr.model.FileInfo; import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.repository.ContentReader; import org.alfresco.service.cmr.repository.ContentWriter; import java.io.OutputStreamWriter; import org.alfresco.web.app.servlet.FacesHelper; @@ -55,7 +56,8 @@ public class OutputUtil { private static final Log LOGGER = LogFactory.getLog(OutputUtil.class); - public static void generate(Document xml, + public static void generate(NodeRef createdNode, + Document xml, TemplateType tt, String fileName, NodeRef containerNodeRef, @@ -64,55 +66,129 @@ public class OutputUtil NodeService nodeService) throws Exception { - try { - // get the node ref of the node that will contain the content - fileName = fileName + "-generated.html"; - FileInfo fileInfo = - fileFolderService.create(containerNodeRef, - fileName, - ContentModel.TYPE_CONTENT); - NodeRef fileNodeRef = fileInfo.getNodeRef(); - - if (LOGGER.isDebugEnabled()) - LOGGER.debug("Created file node for file: " + - fileName); - - // 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("text/html"); - writer.setEncoding("UTF-8"); - TemplateOutputMethod tom = tt.getOutputMethods().get(0); - OutputStreamWriter out = - new OutputStreamWriter(writer.getContentOutputStream()); - tom.generate(xml, tt, out); - out.close(); - nodeService.setProperty(fileNodeRef, - TemplatingService.TT_QNAME, - tt.getName()); - - LOGGER.debug("generated " + fileName + " using " + tom); - - AVMService avmService = AVMContext.fgInstance.getAVMService(); - String parentPath = "repo-1:/repo-1/alice/appBase/avm_webapps/my_webapp"; try + { + // get the node ref of the node that will contain the content + fileName = fileName + "-generated.html"; + FileInfo fileInfo = + fileFolderService.create(containerNodeRef, + fileName, + ContentModel.TYPE_CONTENT); + NodeRef fileNodeRef = fileInfo.getNodeRef(); + + if (LOGGER.isDebugEnabled()) + LOGGER.debug("Created file node for file: " + + fileName); + + // 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("text/html"); + writer.setEncoding("UTF-8"); + TemplateOutputMethod tom = tt.getOutputMethods().get(0); + OutputStreamWriter out = + new OutputStreamWriter(writer.getContentOutputStream()); + tom.generate(xml, tt, out); + out.close(); + nodeService.setProperty(fileNodeRef, + TemplatingService.TT_QNAME, + tt.getName()); + + LOGGER.debug("generated " + fileName + " using " + tom); + + if (createdNode != null) + { + nodeService.setProperty(createdNode, + TemplatingService.TT_GENERATED_OUTPUT_QNAME, + fileNodeRef.toString()); + } + + AVMService avmService = AVMContext.fgInstance.getAVMService(); + String parentPath = "repo-1:/repo-1/alice/appBase/avm_webapps/my_webapp"; + try { out = new OutputStreamWriter(avmService.createFile(parentPath, fileName)); - } - catch (AVMExistsException e) - { - out = new OutputStreamWriter(avmService.getFileOutputStream(parentPath + "/" + fileName)); - } - LOGGER.debug("generating " + fileName + " to avm"); - tom.generate(xml, tt, out); - out.close(); + } + catch (AVMExistsException e) + { + out = new OutputStreamWriter(avmService.getFileOutputStream(parentPath + "/" + fileName)); + } + LOGGER.debug("generating " + fileName + " to avm"); + tom.generate(xml, tt, out); + out.close(); } catch (Exception e) + { + LOGGER.error(e); + e.printStackTrace(); + throw e; + } + } + + + public static void regenerate(final NodeRef nodeRef, + final ContentService contentService, + final NodeService nodeService) + throws Exception + { + try + { + final TemplatingService ts = TemplatingService.getInstance(); + final String templateTypeName = (String) + nodeService.getProperty(nodeRef, TemplatingService.TT_QNAME); + final TemplateType tt = ts.getTemplateType(templateTypeName); + + final ContentReader reader = contentService.getReader(nodeRef, ContentModel.PROP_CONTENT); + final Document xml = ts.parseXML(reader.getContentInputStream()); + String fileName = (String) + nodeService.getProperty(nodeRef, ContentModel.PROP_NAME); + NodeRef generatedNodeRef = + new NodeRef((String) + nodeService.getProperty(nodeRef, + TemplatingService.TT_GENERATED_OUTPUT_QNAME)); + String generatedFileName = (String) + nodeService.getProperty(generatedNodeRef, + ContentModel.PROP_NAME); + + if (LOGGER.isDebugEnabled()) + LOGGER.debug("regenerating file node for : " + fileName + " (" + + nodeRef.toString() + ") to " + generatedNodeRef.toString()); + + // get a writer for the content and put the file + ContentWriter writer = contentService.getWriter(generatedNodeRef, + ContentModel.PROP_CONTENT, + true); + // set the mimetype and encoding + writer.setMimetype("text/html"); + writer.setEncoding("UTF-8"); + TemplateOutputMethod tom = tt.getOutputMethods().get(0); + OutputStreamWriter out = + new OutputStreamWriter(writer.getContentOutputStream()); + tom.generate(xml, tt, out); + out.close(); + + LOGGER.debug("generated " + fileName + " using " + tom); + + AVMService avmService = AVMContext.fgInstance.getAVMService(); + String parentPath = "repo-1:/repo-1/alice/appBase/avm_webapps/my_webapp"; + try { - LOGGER.error(e); - e.printStackTrace(); - throw e; + out = new OutputStreamWriter(avmService.createFile(parentPath, generatedFileName)); } + catch (AVMExistsException e) + { + out = new OutputStreamWriter(avmService.getFileOutputStream(parentPath + "/" + generatedFileName)); + } + LOGGER.debug("generating " + generatedFileName + " to avm"); + tom.generate(xml, tt, out); + out.close(); + } + catch (Exception e) + { + LOGGER.error(e); + e.printStackTrace(); + throw e; + } } } \ No newline at end of file diff --git a/source/java/org/alfresco/web/templating/TemplatingService.java b/source/java/org/alfresco/web/templating/TemplatingService.java index 3d5030b409..20c422a9ac 100644 --- a/source/java/org/alfresco/web/templating/TemplatingService.java +++ b/source/java/org/alfresco/web/templating/TemplatingService.java @@ -92,6 +92,9 @@ public final class TemplatingService public static final org.alfresco.service.namespace.QName TT_QNAME = org.alfresco.service.namespace.QName.createQName(org.alfresco.service.namespace.NamespaceService.CONTENT_MODEL_1_0_URI, "tt"); + public static final org.alfresco.service.namespace.QName TT_GENERATED_OUTPUT_QNAME = + org.alfresco.service.namespace.QName.createQName(org.alfresco.service.namespace.NamespaceService.CONTENT_MODEL_1_0_URI, "tt_generated_output"); + private static final Log LOGGER = LogFactory.getLog(TemplatingService.class); private static TemplatingService INSTANCE; diff --git a/source/web/jsp/dialog/edit-xml-inline.jsp b/source/web/jsp/dialog/edit-xml-inline.jsp index c48b5d6d27..2c0cd1e521 100644 --- a/source/web/jsp/dialog/edit-xml-inline.jsp +++ b/source/web/jsp/dialog/edit-xml-inline.jsp @@ -36,7 +36,7 @@ final CheckinCheckoutBean ccb = (CheckinCheckoutBean) session.getAttribute("CheckinCheckoutBean"); NodeRef nr = ccb.getDocument().getNodeRef(); -String ttName = (String)ccb.getNodeService().getProperty(nr, CreateContentWizard.TT_QNAME); +String ttName = (String)ccb.getNodeService().getProperty(nr, TemplatingService.TT_QNAME); final TemplatingService ts = TemplatingService.getInstance(); final TemplateType tt = ts.getTemplateType(ttName); TemplateInputMethod tim = tt.getInputMethods().get(0); @@ -158,7 +158,7 @@ final InstanceData instanceData = new InstanceData() {
- |