regenerate html output after editing xml asset.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@3559 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Ariel Backenroth
2006-08-21 23:56:02 +00:00
parent 80bf0acd64
commit 6d52906338
5 changed files with 192 additions and 79 deletions

View File

@@ -45,6 +45,8 @@ import org.alfresco.web.app.context.UIContextService;
import org.alfresco.web.app.servlet.DownloadContentServlet; import org.alfresco.web.app.servlet.DownloadContentServlet;
import org.alfresco.web.bean.repository.Node; import org.alfresco.web.bean.repository.Node;
import org.alfresco.web.bean.repository.Repository; 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.Utils;
import org.alfresco.web.ui.common.component.UIActionLink; import org.alfresco.web.ui.common.component.UIActionLink;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
@@ -374,8 +376,8 @@ public class CheckinCheckoutBean
*/ */
private Node setupContentDocument(String id) private Node setupContentDocument(String id)
{ {
if (logger.isDebugEnabled()) if (LOGGER.isDebugEnabled())
logger.debug("Setup for action, setting current document to: " + id); LOGGER.debug("Setup for action, setting current document to: " + id);
Node node = null; Node node = null;
@@ -425,14 +427,14 @@ public class CheckinCheckoutBean
tx = Repository.getUserTransaction(FacesContext.getCurrentInstance()); tx = Repository.getUserTransaction(FacesContext.getCurrentInstance());
tx.begin(); tx.begin();
if (logger.isDebugEnabled()) if (LOGGER.isDebugEnabled())
logger.debug("Trying to checkout content node Id: " + node.getId()); LOGGER.debug("Trying to checkout content node Id: " + node.getId());
// checkout the node content to create a working copy // checkout the node content to create a working copy
if (logger.isDebugEnabled()) if (LOGGER.isDebugEnabled())
{ {
logger.debug("Checkout copy location: " + getCopyLocation()); LOGGER.debug("Checkout copy location: " + getCopyLocation());
logger.debug("Selected Space Id: " + this.selectedSpaceId); LOGGER.debug("Selected Space Id: " + this.selectedSpaceId);
} }
NodeRef workingCopyRef; NodeRef workingCopyRef;
if (getCopyLocation().equals(COPYLOCATION_OTHER) && this.selectedSpaceId != null) if (getCopyLocation().equals(COPYLOCATION_OTHER) && this.selectedSpaceId != null)
@@ -476,7 +478,7 @@ public class CheckinCheckoutBean
} }
else else
{ {
logger.warn("WARNING: checkoutFile called without a current Document!"); LOGGER.warn("WARNING: checkoutFile called without a current Document!");
} }
return outcome; return outcome;
@@ -501,7 +503,7 @@ public class CheckinCheckoutBean
} }
else else
{ {
logger.warn("WARNING: checkoutFileOK called without a current WorkingDocument!"); LOGGER.warn("WARNING: checkoutFileOK called without a current WorkingDocument!");
} }
return outcome; return outcome;
@@ -526,7 +528,7 @@ public class CheckinCheckoutBean
} }
else else
{ {
logger.warn("WARNING: editFileOK called without a current Document!"); LOGGER.warn("WARNING: editFileOK called without a current Document!");
} }
return outcome; return outcome;
@@ -618,8 +620,8 @@ public class CheckinCheckoutBean
tx = Repository.getUserTransaction(FacesContext.getCurrentInstance()); tx = Repository.getUserTransaction(FacesContext.getCurrentInstance());
tx.begin(); tx.begin();
if (logger.isDebugEnabled()) if (LOGGER.isDebugEnabled())
logger.debug("Trying to update content node Id: " + node.getId()); 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 // 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); ContentWriter writer = this.contentService.getWriter(node.getNodeRef(), ContentModel.PROP_CONTENT, true);
@@ -628,6 +630,14 @@ public class CheckinCheckoutBean
// commit the transaction // commit the transaction
tx.commit(); 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 // clean up and clear action context
clearUpload(); clearUpload();
setDocument(null); setDocument(null);
@@ -646,7 +656,7 @@ public class CheckinCheckoutBean
} }
else else
{ {
logger.warn("WARNING: editInlineOK called without a current Document!"); LOGGER.warn("WARNING: editInlineOK called without a current Document!");
} }
return outcome; return outcome;
@@ -679,7 +689,7 @@ public class CheckinCheckoutBean
} }
else else
{ {
logger.warn("WARNING: undoCheckout called without a current WorkingDocument!"); LOGGER.warn("WARNING: undoCheckout called without a current WorkingDocument!");
} }
return outcome; return outcome;
@@ -728,7 +738,7 @@ public class CheckinCheckoutBean
} }
else else
{ {
logger.warn("WARNING: undoCheckout called without a current WorkingDocument!"); LOGGER.warn("WARNING: undoCheckout called without a current WorkingDocument!");
} }
return outcome; return outcome;
@@ -752,8 +762,8 @@ public class CheckinCheckoutBean
tx = Repository.getUserTransaction(FacesContext.getCurrentInstance()); tx = Repository.getUserTransaction(FacesContext.getCurrentInstance());
tx.begin(); tx.begin();
if (logger.isDebugEnabled()) if (LOGGER.isDebugEnabled())
logger.debug("Trying to checkin content node Id: " + node.getId()); LOGGER.debug("Trying to checkin content node Id: " + node.getId());
// we can either checkin the content from the current working copy node // we can either checkin the content from the current working copy node
// which would have been previously updated by the user // which would have been previously updated by the user
@@ -815,7 +825,7 @@ public class CheckinCheckoutBean
} }
else else
{ {
logger.warn("WARNING: checkinFileOK called without a current Document!"); LOGGER.warn("WARNING: checkinFileOK called without a current Document!");
} }
return outcome; return outcome;
@@ -839,8 +849,8 @@ public class CheckinCheckoutBean
tx = Repository.getUserTransaction(FacesContext.getCurrentInstance()); tx = Repository.getUserTransaction(FacesContext.getCurrentInstance());
tx.begin(); tx.begin();
if (logger.isDebugEnabled()) if (LOGGER.isDebugEnabled())
logger.debug("Trying to update content node Id: " + node.getId()); 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 // 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); ContentWriter writer = this.contentService.getWriter(node.getNodeRef(), ContentModel.PROP_CONTENT, true);
@@ -865,7 +875,7 @@ public class CheckinCheckoutBean
} }
else else
{ {
logger.warn("WARNING: updateFileOK called without a current Document!"); LOGGER.warn("WARNING: updateFileOK called without a current Document!");
} }
return outcome; return outcome;
@@ -910,7 +920,7 @@ public class CheckinCheckoutBean
// ------------------------------------------------------------------------------ // ------------------------------------------------------------------------------
// Private data // Private data
private static Log logger = LogFactory.getLog(CheckinCheckoutBean.class); private static final Log LOGGER = LogFactory.getLog(CheckinCheckoutBean.class);
/** I18N messages */ /** I18N messages */
private static final String MSG_ERROR_CHECKIN = "error_checkin"; private static final String MSG_ERROR_CHECKIN = "error_checkin";

View File

@@ -78,16 +78,14 @@ public class CreateContentWizard extends BaseContentWizard
this.templateTypeName); this.templateTypeName);
TemplatingService ts = TemplatingService.getInstance(); TemplatingService ts = TemplatingService.getInstance();
TemplateType tt = this.getTemplateType(); TemplateType tt = this.getTemplateType();
if (tt.getOutputMethods().size() != 0) OutputUtil.generate(this.createdNode,
{ ts.parseXML(this.content),
OutputUtil.generate(ts.parseXML(this.content), tt,
tt, this.fileName,
this.fileName, this.getContainerNodeRef(),
this.getContainerNodeRef(), this.fileFolderService,
this.fileFolderService, this.contentService,
this.contentService, this.nodeService);
this.nodeService);
}
} }
// return the default outcome // return the default outcome

View File

@@ -42,6 +42,7 @@ import org.apache.commons.logging.LogFactory;
import org.alfresco.model.ContentModel; import org.alfresco.model.ContentModel;
import org.alfresco.service.cmr.model.FileInfo; import org.alfresco.service.cmr.model.FileInfo;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentWriter; import org.alfresco.service.cmr.repository.ContentWriter;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import org.alfresco.web.app.servlet.FacesHelper; import org.alfresco.web.app.servlet.FacesHelper;
@@ -55,7 +56,8 @@ public class OutputUtil
{ {
private static final Log LOGGER = LogFactory.getLog(OutputUtil.class); 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, TemplateType tt,
String fileName, String fileName,
NodeRef containerNodeRef, NodeRef containerNodeRef,
@@ -64,55 +66,129 @@ public class OutputUtil
NodeService nodeService) NodeService nodeService)
throws Exception 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 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)); out = new OutputStreamWriter(avmService.createFile(parentPath, fileName));
} }
catch (AVMExistsException e) catch (AVMExistsException e)
{ {
out = new OutputStreamWriter(avmService.getFileOutputStream(parentPath + "/" + fileName)); out = new OutputStreamWriter(avmService.getFileOutputStream(parentPath + "/" + fileName));
} }
LOGGER.debug("generating " + fileName + " to avm"); LOGGER.debug("generating " + fileName + " to avm");
tom.generate(xml, tt, out); tom.generate(xml, tt, out);
out.close(); out.close();
} }
catch (Exception e) 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); out = new OutputStreamWriter(avmService.createFile(parentPath, generatedFileName));
e.printStackTrace();
throw e;
} }
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;
}
} }
} }

View File

@@ -92,6 +92,9 @@ public final class TemplatingService
public static final org.alfresco.service.namespace.QName TT_QNAME = 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"); 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 final Log LOGGER = LogFactory.getLog(TemplatingService.class);
private static TemplatingService INSTANCE; private static TemplatingService INSTANCE;

View File

@@ -36,7 +36,7 @@
final CheckinCheckoutBean ccb = (CheckinCheckoutBean) final CheckinCheckoutBean ccb = (CheckinCheckoutBean)
session.getAttribute("CheckinCheckoutBean"); session.getAttribute("CheckinCheckoutBean");
NodeRef nr = ccb.getDocument().getNodeRef(); 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 TemplatingService ts = TemplatingService.getInstance();
final TemplateType tt = ts.getTemplateType(ttName); final TemplateType tt = ts.getTemplateType(ttName);
TemplateInputMethod tim = tt.getInputMethods().get(0); TemplateInputMethod tim = tt.getInputMethods().get(0);
@@ -158,7 +158,7 @@ final InstanceData instanceData = new InstanceData() {
<table cellpadding="1" cellspacing="1" border="0"> <table cellpadding="1" cellspacing="1" border="0">
<tr> <tr>
<td align="center"> <td align="center">
<h:commandButton value="#{msg.save}" action="#{CheckinCheckoutBean.editInlineOK}" styleClass="dialogControls" /> <h:commandButton id="save-button" value="#{msg.save}" action="#{CheckinCheckoutBean.editInlineOK}" styleClass="dialogControls" />
</td> </td>
</tr> </tr>
<tr><td class="dialogButtonSpacing"></td></tr> <tr><td class="dialogButtonSpacing"></td></tr>
@@ -211,5 +211,31 @@ final InstanceData instanceData = new InstanceData() {
</h:form> </h:form>
</f:view> </f:view>
<script type="text/javascript">
dojo.addOnLoad(function()
{
//alert('foo');
var b = document.getElementById("edit-file:save-button");
var baseOnClick = b.onclick;
b.onclick = function()
{
if (!document.submitTrigger.done)
{
document.submitTrigger.buttonClick();
return false;
}
else
{
return baseOnClick();
}
}
});
function doSubmit()
{
var b = document.getElementById("edit-file:save-button");
b.click();
}
</script>
</r:page> </r:page>