first stab at the multi channel thing

- renamed create-xml-content-type wizard to create-form wizard and moved it into the wcm source tree
- modified the create form wizard to accept 0 to n template output methods
- changed terminology from presentation template to template output method
- using associations to track output methods
- added file extension as property of templateoutputmethod to parameterize what the name of the output file should be
- auto adding .xml to file name in create web content if none specified.
- making associating an output method with a template optional 



git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@4043 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Ariel Backenroth
2006-10-06 02:26:38 +00:00
parent fe50122847
commit d26fe8cbb5
16 changed files with 521 additions and 339 deletions

View File

@@ -21,6 +21,7 @@ import java.io.OutputStreamWriter;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.avm.AVMNodeConverter;
import org.alfresco.service.cmr.avm.AVMNotFoundException;
import org.alfresco.service.cmr.avm.AVMService;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentService;
@@ -47,46 +48,44 @@ public class OutputUtil
}
public static void generate(String parentPath,
Document xml,
TemplateType tt,
String fileName,
ContentService contentService,
NodeService nodeService,
AVMService avmService)
Document xml,
TemplateType tt,
String fileName,
ContentService contentService,
NodeService nodeService,
AVMService avmService)
throws Exception
{
try
{
// get the node ref of the node that will contain the content
String generatedFileName = stripExtension(fileName) + ".shtml";
for (TemplateOutputMethod tom : tt.getOutputMethods())
{
// get the node ref of the node that will contain the content
final String generatedFileName = stripExtension(fileName) + "." + tom.getFileExtension();
final OutputStream fileOut = avmService.createFile(parentPath, generatedFileName);
final String fullAvmPath = parentPath + '/' + generatedFileName;
final String avmStore = parentPath.substring(0, parentPath.indexOf(":/"));
final String sandBoxUrl = AVMConstants.buildAVMStoreUrl(avmStore);
OutputStream fileOut = avmService.createFile(parentPath, generatedFileName);
String fullAvmPath = parentPath + '/' + generatedFileName;
String avmStore = parentPath.substring(0, parentPath.indexOf(":/"));
String sandBoxUrl = AVMConstants.buildAVMStoreUrl(avmStore);
if (LOGGER.isDebugEnabled())
LOGGER.debug("Created file node for file: " +
fullAvmPath);
TemplateOutputMethod tom = tt.getOutputMethods().get(0);
OutputStreamWriter out = new OutputStreamWriter(fileOut);
tom.generate(xml, tt, sandBoxUrl, out);
out.close();
NodeRef outputNodeRef = AVMNodeConverter.ToNodeRef(-1, fullAvmPath);
nodeService.setProperty(outputNodeRef,
TemplatingService.TT_QNAME,
tt.getName());
LOGGER.debug("generated " + generatedFileName + " using " + tom);
NodeRef createdNodeRef = AVMNodeConverter.ToNodeRef(-1, parentPath + '/' + fileName);
nodeService.setProperty(createdNodeRef,
TemplatingService.TT_GENERATED_OUTPUT_QNAME,
outputNodeRef.toString());
if (LOGGER.isDebugEnabled())
LOGGER.debug("Created file node for file: " +
fullAvmPath);
final OutputStreamWriter out = new OutputStreamWriter(fileOut);
tom.generate(xml, tt, sandBoxUrl, out);
out.close();
NodeRef outputNodeRef = AVMNodeConverter.ToNodeRef(-1, fullAvmPath);
nodeService.setProperty(outputNodeRef,
TemplatingService.TT_QNAME,
tt.getName());
LOGGER.debug("generated " + generatedFileName + " using " + tom);
NodeRef createdNodeRef = AVMNodeConverter.ToNodeRef(-1, parentPath + '/' + fileName);
nodeService.setProperty(createdNodeRef,
TemplatingService.TT_GENERATED_OUTPUT_QNAME,
outputNodeRef.toString());
}
}
catch (Exception e)
{
@@ -97,50 +96,50 @@ public class OutputUtil
}
public static void regenerate(final NodeRef nodeRef,
final ContentService contentService,
final NodeService nodeService)
final ContentService contentService,
final NodeService nodeService,
final AVMService avmService)
throws Exception
{
try
{
final TemplatingService ts = TemplatingService.getInstance();
final String templateTypeName = (String)
nodeService.getProperty(nodeRef, TemplatingService.TT_QNAME);
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);
String avmPath = AVMNodeConverter.ToAVMVersionPath(nodeRef).getSecond();
String avmStore = avmPath.substring(0, avmPath.indexOf(":/"));
String sandBoxUrl = AVMConstants.buildAVMStoreUrl(avmStore);
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");
// put a loop to generate all output methods
TemplateOutputMethod tom = tt.getOutputMethods().get(0);
OutputStreamWriter out = new OutputStreamWriter(writer.getContentOutputStream());
tom.generate(xml, tt, sandBoxUrl, out);
out.close();
LOGGER.debug("generated " + fileName + " using " + tom);
final String fileName = (String)
nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
final String avmPath = AVMNodeConverter.ToAVMVersionPath(nodeRef).getSecond();
final String avmStore = avmPath.substring(0, avmPath.indexOf(":/"));
final String sandBoxUrl = AVMConstants.buildAVMStoreUrl(avmStore);
final String parentPath = AVMNodeConverter.SplitBase(avmPath)[0];
for (TemplateOutputMethod tom : tt.getOutputMethods())
{
final String generatedFileName = stripExtension(fileName) + "." + tom.getFileExtension();
if (LOGGER.isDebugEnabled())
LOGGER.debug("regenerating file node for : " + fileName + " (" +
nodeRef.toString() + ") to " + parentPath + "/" + generatedFileName);
// get a writer for the content and put the file
OutputStream out = null;
try
{
out = avmService.getFileOutputStream(parentPath + "/" + generatedFileName);
}
catch (AVMNotFoundException e)
{
out = avmService.createFile(parentPath, generatedFileName);
}
final OutputStreamWriter writer = new OutputStreamWriter(out);
tom.generate(xml, tt, sandBoxUrl, writer);
writer.close();
LOGGER.debug("generated " + fileName + " using " + tom);
}
}
catch (Exception e)
{

View File

@@ -24,20 +24,29 @@ import org.w3c.dom.Document;
* Serializes the xml data to a writer.
*/
public interface TemplateOutputMethod
extends Serializable
extends Serializable
{
/**
* Serializes the xml data in to a presentation format.
*
* @param xmlContent the xml content to serialize
* @param tt the template type that collected the xml content.
* @param sandBoxUrl the url of the current sandbox
* @param out the writer to serialize to.
*/
public void generate(final Document xmlContent,
final TemplateType tt,
final String sandBoxUrl,
final Writer out)
throws Exception;
/**
* Serializes the xml data in to a presentation format.
*
* @param xmlContent the xml content to serialize
* @param tt the template type that collected the xml content.
* @param sandBoxUrl the url of the current sandbox
* @param out the writer to serialize to.
*/
public void generate(final Document xmlContent,
final TemplateType tt,
final String sandBoxUrl,
final Writer out)
throws Exception;
/**
* Returns the file extension to use when generating content for this
* output method.
*
* @return the file extension to use when generating content for this
* output method, such as html, rss, pdf.
*/
public String getFileExtension();
}

View File

@@ -40,6 +40,7 @@ import org.alfresco.model.WCMModel;
import org.alfresco.util.TempFileProvider;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.repository.AssociationRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.search.*;
import org.alfresco.service.cmr.model.*;
@@ -196,11 +197,15 @@ public final class TemplatingService implements Serializable
final String schemaRootTagName = (String)
this.nodeService.getProperty(schemaNodeRef, WCMModel.PROP_SCHEMA_ROOT_TAG_NAME);
LOGGER.debug("root tag name is " + schemaRootTagName);
TemplateType tt = new TemplateTypeImpl(title, schemaNodeRef, schemaRootTagName);
final NodeRef xslNodeRef = (NodeRef)
this.nodeService.getProperty(schemaNodeRef, WCMModel.ASSOC_TEMPLATE_OUTPUT_METHODS);
LOGGER.debug("xsl noderef is " + xslNodeRef);
tt.addOutputMethod(new XSLTOutputMethod(xslNodeRef));
final TemplateType tt = new TemplateTypeImpl(title, schemaNodeRef, schemaRootTagName);
for (AssociationRef assoc : this.nodeService.getTargetAssocs(schemaNodeRef,
WCMModel.ASSOC_TEMPLATE_OUTPUT_METHODS))
{
final NodeRef xslNodeRef = assoc.getTargetRef();
final TemplateOutputMethod tom = new XSLTOutputMethod(xslNodeRef, this.nodeService);
LOGGER.debug("loaded template output method " + tom.getFileExtension() + ", " + xslNodeRef);
tt.addOutputMethod(tom);
}
return tt;
}

View File

@@ -24,17 +24,22 @@ import org.w3c.dom.Document;
import org.w3c.dom.Node;
public class FreeMarkerOutputMethod
implements TemplateOutputMethod
implements TemplateOutputMethod
{
public FreeMarkerOutputMethod()
{
}
public FreeMarkerOutputMethod()
{
}
public void generate(final Document xmlContent,
final TemplateType tt,
final String sandBoxUrl,
final Writer out)
{
}
public void generate(final Document xmlContent,
final TemplateType tt,
final String sandBoxUrl,
final Writer out)
{
}
public String getFileExtension()
{
return "unimpleemnted";
}
}

View File

@@ -2251,8 +2251,8 @@ public class SchemaFormBuilder
" (owningElementName=" + owningElementName + ")");
if (owner != null)
LOGGER.debug("*************** owner is " + owner.getClass() +
" name is " + owner.getName() + " ****************");
LOGGER.debug("owner is " + owner.getClass() +
", name is " + owner.getName());
// create the <xforms:bind> element and add it to the model.
Element bindElement = xForm.createElementNS(XFORMS_NS,
SchemaFormBuilder.XFORMS_NS_PREFIX + "bind");

View File

@@ -36,6 +36,8 @@ import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.stream.StreamResult;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.alfresco.model.WCMModel;
import org.alfresco.service.cmr.repository.NodeService;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
@@ -46,69 +48,79 @@ public class XSLTOutputMethod
implements TemplateOutputMethod
{
private static final Log LOGGER = LogFactory.getLog(XSLTOutputMethod.class);
private static final Log LOGGER = LogFactory.getLog(XSLTOutputMethod.class);
private final NodeRef nodeRef;
private final NodeService nodeService;
private final NodeRef nodeRef;
public XSLTOutputMethod(final NodeRef nodeRef,
final NodeService nodeService)
{
this.nodeRef = nodeRef;
this.nodeService = nodeService;
}
public XSLTOutputMethod(final NodeRef nodeRef)
{
this.nodeRef = nodeRef;
}
public void generate(final Document xmlContent,
final TemplateType tt,
final String sandBoxUrl,
final Writer out)
throws ParserConfigurationException,
TransformerConfigurationException,
TransformerException,
SAXException,
IOException
{
final TransformerFactory tf = TransformerFactory.newInstance();
final TemplatingService ts = TemplatingService.getInstance();
final DOMSource source = new DOMSource(ts.parseXML(this.nodeRef));
final Templates templates = tf.newTemplates(source);
final Transformer t = templates.newTransformer();
t.setURIResolver(new URIResolver()
{
public Source resolve(final String href, final String base)
throws TransformerException
{
URI uri = null;
try
{
uri = new URI(sandBoxUrl + href);
}
catch (URISyntaxException e)
{
throw new TransformerException("unable to create uri " + sandBoxUrl + href, e);
}
try
{
LOGGER.debug("loading " + uri);
final Document d = ts.parseXML(uri.toURL().openStream());
LOGGER.debug("loaded " + ts.writeXMLToString(d));
return new DOMSource(d);
}
catch (Exception e)
{
LOGGER.warn(e);
throw new TransformerException("unable to load " + uri, e);
}
}
});
t.setParameter("avm_store_url", sandBoxUrl);
LOGGER.debug("setting parameter avm_store_url=" + sandBoxUrl);
final StreamResult result = new StreamResult(out);
try
{
t.transform(new DOMSource(xmlContent), result);
}
catch (TransformerException e)
{
LOGGER.error(e.getMessageAndLocation());
throw e;
}
}
public void generate(final Document xmlContent,
final TemplateType tt,
final String sandBoxUrl,
final Writer out)
throws ParserConfigurationException,
TransformerConfigurationException,
TransformerException,
SAXException,
IOException
{
TransformerFactory tf = TransformerFactory.newInstance();
final TemplatingService ts = TemplatingService.getInstance();
DOMSource source = new DOMSource(ts.parseXML(this.nodeRef));
final Templates templates = tf.newTemplates(source);
final Transformer t = templates.newTransformer();
t.setURIResolver(new URIResolver()
{
public Source resolve(final String href, final String base)
throws TransformerException
{
URI uri = null;
try
{
uri = new URI(sandBoxUrl + href);
}
catch (URISyntaxException e)
{
throw new TransformerException("unable to create uri " + sandBoxUrl + href, e);
}
try
{
LOGGER.debug("loading " + uri);
final Document d = ts.parseXML(uri.toURL().openStream());
LOGGER.debug("loaded " + ts.writeXMLToString(d));
return new DOMSource(d);
}
catch (Exception e)
{
LOGGER.warn(e);
throw new TransformerException("unable to load " + uri, e);
}
}
});
t.setParameter("avm_store_url", sandBoxUrl);
LOGGER.debug("setting parameter avm_store_url=" + sandBoxUrl);
final StreamResult result = new StreamResult(out);
try
{
t.transform(new DOMSource(xmlContent), result);
}
catch (TransformerException e)
{
LOGGER.error(e.getMessageAndLocation());
throw e;
}
}
public String getFileExtension()
{
return (String)
this.nodeService.getProperty(this.nodeRef,
WCMModel.PROP_TEMPLATE_OUTPUT_METHOD_DERIVED_FILE_EXTENSION);
}
}