mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
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:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
@@ -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;
|
||||
|
||||
|
Reference in New Issue
Block a user