From d26fe8cbb5e31570c2e12a09d372e0f26af2e815 Mon Sep 17 00:00:00 2001 From: Ariel Backenroth Date: Fri, 6 Oct 2006 02:26:38 +0000 Subject: [PATCH] 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 --- config/alfresco/messages/webclient.properties | 20 +- config/alfresco/web-client-config-actions.xml | 8 +- config/alfresco/web-client-config-wizards.xml | 30 +-- .../content/CreateXmlContentTypeWizard.java | 220 +++++++++++++----- .../alfresco/web/bean/wcm/AVMEditBean.java | 5 +- .../web/bean/wcm/CreateWebContentWizard.java | 10 + .../alfresco/web/templating/OutputUtil.java | 137 ++++++----- .../web/templating/TemplateOutputMethod.java | 37 +-- .../web/templating/TemplatingService.java | 15 +- .../xforms/FreeMarkerOutputMethod.java | 25 +- .../templating/xforms/SchemaFormBuilder.java | 4 +- .../templating/xforms/XSLTOutputMethod.java | 136 ++++++----- .../configure-presentation-templates.jsp | 87 ------- .../configure-template-output-methods.jsp | 126 ++++++++++ .../create-form-wizard}/details.jsp | 0 .../create-form-wizard}/edit.jsp | 0 16 files changed, 521 insertions(+), 339 deletions(-) delete mode 100644 source/web/jsp/content/create-xml-content-type-wizard/configure-presentation-templates.jsp create mode 100644 source/web/jsp/wcm/create-form-wizard/configure-template-output-methods.jsp rename source/web/jsp/{content/create-xml-content-type-wizard => wcm/create-form-wizard}/details.jsp (100%) rename source/web/jsp/{content/create-xml-content-type-wizard => wcm/create-form-wizard}/edit.jsp (100%) diff --git a/config/alfresco/messages/webclient.properties b/config/alfresco/messages/webclient.properties index 2885ae5157..ea97ecf1a7 100644 --- a/config/alfresco/messages/webclient.properties +++ b/config/alfresco/messages/webclient.properties @@ -238,7 +238,7 @@ remove_user=Remove User create_space=Create Space add_content=Add Content create_content=Create Content -create_xml_content_type=Create Form +create_form=Create Form add_multiple_files=Add Multiple Files import_directory=Import Directory advanced_space_wizard=Advanced Space Wizard @@ -641,17 +641,21 @@ content=Content text_content=Plain Text Content html_content=HTML Content xml_content=XML Content -create_xml_content_type_title=Create Form Wizard -create_xml_content_type_desc=Create Form -create_xml_content_type_step1_title=Upload an XML Schema -create_xml_content_type_step1_desc=Upload an XML Schema -create_xml_content_type_step2_title=Edit the XML Schema -create_xml_content_type_step2_desc=This is the generated XForm based on the schema provided. +create_form_title=Create Form Wizard +create_form_desc=Create Form +create_form_step1_title=Upload an XML Schema +create_form_step1_desc=Upload an XML Schema +create_form_step2_title=Edit the XML Schema +create_form_step2_desc=This is the generated XForm based on the schema provided. +selected_templateoutputmethods=Selected Template Output Methods +configure_output_methods_step1_desc=Upload template output method and specify the extension to use for it\'s generated assets. +template_output_method_file=Template Output Method File +extension_for_generated_assets=Extension For Generated Assets schema=Schema schema_root_tag_name=Root Tag edit_xml_schema=Edit XML Schema template_type=Template Type -configure_presentation_templates=Configure Presentation Templates +configure_template_output_methods=Configure Template Output Methods # Rule and Action Wizard messages run_action_title=Run Action Wizard diff --git a/config/alfresco/web-client-config-actions.xml b/config/alfresco/web-client-config-actions.xml index 30a5f274e4..c4e078c073 100644 --- a/config/alfresco/web-client-config-actions.xml +++ b/config/alfresco/web-client-config-actions.xml @@ -325,13 +325,13 @@ - + CreateChildren - create_xml_content_type + create_form /images/icons/new_content.gif - wizard:createXMLContentType + wizard:createForm @@ -581,7 +581,7 @@ - + diff --git a/config/alfresco/web-client-config-wizards.xml b/config/alfresco/web-client-config-wizards.xml index a0c4abd52e..28bf559e4b 100644 --- a/config/alfresco/web-client-config-wizards.xml +++ b/config/alfresco/web-client-config-wizards.xml @@ -226,29 +226,21 @@ - - - + - - + diff --git a/source/java/org/alfresco/web/bean/content/CreateXmlContentTypeWizard.java b/source/java/org/alfresco/web/bean/content/CreateXmlContentTypeWizard.java index 9291c080b9..b696766a0d 100644 --- a/source/java/org/alfresco/web/bean/content/CreateXmlContentTypeWizard.java +++ b/source/java/org/alfresco/web/bean/content/CreateXmlContentTypeWizard.java @@ -19,6 +19,10 @@ package org.alfresco.web.bean.content; import java.io.*; import java.util.*; +import javax.faces.component.UIOutput; +import javax.faces.event.ActionEvent; +import javax.faces.model.DataModel; +import javax.faces.model.ListDataModel; import javax.faces.context.FacesContext; import javax.faces.event.ValueChangeEvent; import javax.faces.model.SelectItem; @@ -59,6 +63,50 @@ import org.xml.sax.SAXException; */ public class CreateXmlContentTypeWizard extends BaseWizardBean { + + ///////////////////////////////////////////////////////////////////////////// + + /** + * Simple wrapper class to represent a template output method + */ + public static class TemplateOutputMethodData + { + private final String fileName; + private final File file; + private final String fileExtension; + + public TemplateOutputMethodData(final String fileName, + final File file, + final String fileExtension) + { + this.fileName = fileName; + this.file = file; + this.fileExtension = fileExtension; + } + + public String getFileExtension() + { + return this.fileExtension; + } + + public String getFileName() + { + return this.fileName; + } + + public File getFile() + { + return this.file; + } + + public String getLabel() + { + return this.getFileExtension().toUpperCase() + " (" + this.getFileName() + ")"; + } + } + + ///////////////////////////////////////////////////////////////////////////// + private final static Log LOGGER = LogFactory.getLog(CreateXmlContentTypeWizard.class); @@ -66,8 +114,9 @@ public class CreateXmlContentTypeWizard extends BaseWizardBean private String templateName; private String presentationTemplateType; protected ContentService contentService; - - + private DataModel templateOutputMethodsDataModel; + private List templateOutputMethods = null; + // ------------------------------------------------------------------------------ // Wizard implementation @@ -101,41 +150,46 @@ public class CreateXmlContentTypeWizard extends BaseWizardBean writer.setMimetype("text/xml"); writer.setEncoding("UTF-8"); writer.putContent(this.getSchemaFile()); - - fileInfo = this.fileFolderService.create(folderInfo.getNodeRef(), - this.getPresentationTemplateFileName(), - ContentModel.TYPE_CONTENT); - final NodeRef presentationTemplateFileNodeRef = fileInfo.getNodeRef(); - - if (LOGGER.isDebugEnabled()) - LOGGER.debug("Created file node for file: " + - this.getPresentationTemplateFileName()); - - // get a writer for the content and put the file - writer = this.contentService.getWriter(presentationTemplateFileNodeRef, - ContentModel.PROP_CONTENT, - true); - // set the mimetype and encoding - writer.setMimetype("text/xml"); - writer.setEncoding("UTF-8"); - writer.putContent(this.getPresentationTemplateFile()); - - Map props = new HashMap(2, 1.0f); - props.put(WCMModel.PROP_SCHEMA_ROOT_TAG_NAME, this.getSchemaRootTagName()); - props.put(WCMModel.ASSOC_TEMPLATE_OUTPUT_METHODS, presentationTemplateFileNodeRef); - this.nodeService.addAspect(schemaFileNodeRef, WCMModel.ASPECT_TEMPLATE, props); // apply the titled aspect - title and description - props = new HashMap(2, 1.0f); + Map props = new HashMap(2, 1.0f); props.put(ContentModel.PROP_TITLE, this.getTemplateName()); props.put(ContentModel.PROP_DESCRIPTION, ""); this.nodeService.addAspect(schemaFileNodeRef, ContentModel.ASPECT_TITLED, props); + + props = new HashMap(1, 1.0f); + props.put(WCMModel.PROP_SCHEMA_ROOT_TAG_NAME, this.getSchemaRootTagName()); + this.nodeService.addAspect(schemaFileNodeRef, WCMModel.ASPECT_TEMPLATE, props); + + for (TemplateOutputMethodData tomd : this.templateOutputMethods) + { + fileInfo = this.fileFolderService.create(folderInfo.getNodeRef(), + tomd.getFileName(), + ContentModel.TYPE_CONTENT); + final NodeRef presentationTemplateFileNodeRef = fileInfo.getNodeRef(); - props = new HashMap(2, 1.0f); - props.put(WCMModel.PROP_TEMPLATE_OUTPUT_METHOD_TYPE, this.getPresentationTemplateType()); - props.put(WCMModel.PROP_TEMPLATE_SOURCE, schemaFileNodeRef); - this.nodeService.addAspect(presentationTemplateFileNodeRef, WCMModel.ASPECT_TEMPLATE_OUTPUT_METHOD, props); + if (LOGGER.isDebugEnabled()) + LOGGER.debug("Created file node for file: " + tomd.getFileName()); + // get a writer for the content and put the file + writer = this.contentService.getWriter(presentationTemplateFileNodeRef, + ContentModel.PROP_CONTENT, + true); + // set the mimetype and encoding + writer.setMimetype("text/xml"); + writer.setEncoding("UTF-8"); + writer.putContent(tomd.getFile()); + + this.nodeService.createAssociation(schemaFileNodeRef, + presentationTemplateFileNodeRef, + WCMModel.ASSOC_TEMPLATE_OUTPUT_METHODS); + + props = new HashMap(3, 1.0f); + props.put(WCMModel.PROP_TEMPLATE_OUTPUT_METHOD_TYPE, this.getTemplateOutputMethodType()); + props.put(WCMModel.PROP_TEMPLATE_SOURCE, schemaFileNodeRef); + props.put(WCMModel.PROP_TEMPLATE_OUTPUT_METHOD_DERIVED_FILE_EXTENSION, tomd.getFileExtension()); + this.nodeService.addAspect(presentationTemplateFileNodeRef, WCMModel.ASPECT_TEMPLATE_OUTPUT_METHOD, props); + } // return the default outcome return outcome; } @@ -146,18 +200,19 @@ public class CreateXmlContentTypeWizard extends BaseWizardBean super.init(parameters); this.removeUploadedSchemaFile(); - this.removeUploadedPresentationTemplateFile(); + this.removeUploadedTemplateOutputMethodFile(); this.schemaRootTagName = null; this.templateName = null; + this.templateOutputMethods = new ArrayList(); clearUpload("schema"); - clearUpload("pt"); + clearUpload("template-output-method"); } @Override public String cancel() { this.removeUploadedSchemaFile(); - this.removeUploadedPresentationTemplateFile(); + this.removeUploadedTemplateOutputMethodFile(); return super.cancel(); } @@ -182,6 +237,38 @@ public class CreateXmlContentTypeWizard extends BaseWizardBean return disabled; } + + public void addSelectedTemplateOutputMethod(ActionEvent event) + { + final UIOutput fileNameComponent = (UIOutput) + event.getComponent().findComponent("template-output-method-file-name"); + final UIOutput fileExtensionComponent = (UIOutput) + event.getComponent().findComponent("file-extension"); + final String fileName = (String)fileNameComponent.getValue(); + assert fileName != null; + assert this.getTemplateOutputMethodFileName() != null; + assert this.getTemplateOutputMethodFileName().equals(fileName); + final TemplateOutputMethodData data = + new TemplateOutputMethodData(fileName, + this.getTemplateOutputMethodFile(), + (String)fileExtensionComponent.getValue()); + this.templateOutputMethods.add(data); + this.removeUploadedTemplateOutputMethodFile(); + } + + /** + * Action handler called when the Remove button is pressed to remove a + * template output method + */ + public void removeSelectedTemplateOutputMethod(ActionEvent event) + { + final TemplateOutputMethodData wrapper = (TemplateOutputMethodData) + this.templateOutputMethodsDataModel.getRowData(); + if (wrapper != null) + { + this.templateOutputMethods.remove(wrapper); + } + } /** * Action handler called when the user wishes to remove an uploaded file @@ -197,9 +284,9 @@ public class CreateXmlContentTypeWizard extends BaseWizardBean /** * Action handler called when the user wishes to remove an uploaded file */ - public String removeUploadedPresentationTemplateFile() + public String removeUploadedTemplateOutputMethodFile() { - clearUpload("pt"); + clearUpload("template-output-method"); // refresh the current page return null; @@ -208,15 +295,32 @@ public class CreateXmlContentTypeWizard extends BaseWizardBean // ------------------------------------------------------------------------------ // Bean Getters and Setters + + /** + * Returns the properties for current configured output methods JSF DataModel + * + * @return JSF DataModel representing the current configured output methods + */ + public DataModel getTemplateOutputMethodsDataModel() + { + if (this.templateOutputMethodsDataModel == null) + { + this.templateOutputMethodsDataModel = new ListDataModel(); + } + + this.templateOutputMethodsDataModel.setWrappedData(this.templateOutputMethods); + + return this.templateOutputMethodsDataModel; + } /** * @return Returns the mime type currenty selected */ - public String getPresentationTemplateType() + public String getTemplateOutputMethodType() { - if (this.getPresentationTemplateFileName() != null) + if (this.getTemplateOutputMethodFileName() != null) { - // String s = this.getPresentationTemplateFileName(); + // String s = this.getTemplateOutputMethodFileName(); // String extension = this.presentationTemplateType = "XSL"; } @@ -226,7 +330,7 @@ public class CreateXmlContentTypeWizard extends BaseWizardBean /** * @param presentationTemplateType Sets the currently selected mime type */ - public void setPresentationTemplateType(String presentationTemplateType) + public void setTemplateOutputMethodType(String presentationTemplateType) { this.presentationTemplateType = presentationTemplateType; } @@ -281,17 +385,17 @@ public class CreateXmlContentTypeWizard extends BaseWizardBean /** * @return Returns the schema file or null */ - public String getPresentationTemplateFileName() + public String getTemplateOutputMethodFileName() { - return this.getFileName("pt"); + return this.getFileName("template-output-method"); } /** * @return Returns the presentationTemplate file or null */ - public File getPresentationTemplateFile() + public File getTemplateOutputMethodFile() { - return this.getFile("pt"); + return this.getFile("template-output-method"); } /** @@ -333,7 +437,7 @@ public class CreateXmlContentTypeWizard extends BaseWizardBean /** * @return Returns a list of mime types to allow the user to select from */ - public List getCreatePresentationTemplateTypes() + public List getCreateTemplateOutputMethodTypes() { return (List)Arrays.asList(new SelectItem[] { new SelectItem("freemarker", "FreeMarker"), @@ -346,19 +450,21 @@ public class CreateXmlContentTypeWizard extends BaseWizardBean */ public String getSummary() { - ResourceBundle bundle = Application.getBundle(FacesContext.getCurrentInstance()); - - // TODO: show first few lines of content here? - return buildSummary(new String[] { - "Schema File", - "Presentation Template Type", - "Presentation Template" - }, - new String[] { - this.getSchemaFileName(), - this.getPresentationTemplateType(), - this.getPresentationTemplateFileName() - }); + final ResourceBundle bundle = Application.getBundle(FacesContext.getCurrentInstance()); + final String[] labels = new String[2 + this.templateOutputMethods.size()]; + final String[] values = new String[2 + this.templateOutputMethods.size()]; + labels[0] = "Schema File"; + values[0] = this.getSchemaFileName(); + labels[1] = "Template output method type"; + values[1] = this.getTemplateOutputMethodType(); + for (int i = 0; i < this.templateOutputMethods.size(); i++) + { + final TemplateOutputMethodData tomd = this.templateOutputMethods.get(i); + labels[2 + i] = "Template output method for " + tomd.getFileExtension(); + values[2 + i] = tomd.getFileName(); + } + + return this.buildSummary(labels, values); } diff --git a/source/java/org/alfresco/web/bean/wcm/AVMEditBean.java b/source/java/org/alfresco/web/bean/wcm/AVMEditBean.java index 9934372486..7def9e9adf 100644 --- a/source/java/org/alfresco/web/bean/wcm/AVMEditBean.java +++ b/source/java/org/alfresco/web/bean/wcm/AVMEditBean.java @@ -312,8 +312,9 @@ public class AVMEditBean if (nodeService.getProperty(avmRef, TemplatingService.TT_QNAME) != null) { OutputUtil.regenerate(avmRef, - this.contentService, - this.nodeService); + this.contentService, + this.nodeService, + this.avmService); } resetState(); diff --git a/source/java/org/alfresco/web/bean/wcm/CreateWebContentWizard.java b/source/java/org/alfresco/web/bean/wcm/CreateWebContentWizard.java index c7dfbfd6f2..c900179148 100644 --- a/source/java/org/alfresco/web/bean/wcm/CreateWebContentWizard.java +++ b/source/java/org/alfresco/web/bean/wcm/CreateWebContentWizard.java @@ -189,6 +189,16 @@ public class CreateWebContentWizard extends BaseContentWizard // ------------------------------------------------------------------------------ // Bean Getters and Setters + + /** + * @param fileName The name of the file + */ + public void setFileName(String fileName) + { + super.setFileName(fileName != null && fileName.indexOf('.') == -1 + ? fileName + ".xml" + : fileName); + } /** * @return Returns the content from the edited form. diff --git a/source/java/org/alfresco/web/templating/OutputUtil.java b/source/java/org/alfresco/web/templating/OutputUtil.java index a211171c28..221796c509 100644 --- a/source/java/org/alfresco/web/templating/OutputUtil.java +++ b/source/java/org/alfresco/web/templating/OutputUtil.java @@ -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) { diff --git a/source/java/org/alfresco/web/templating/TemplateOutputMethod.java b/source/java/org/alfresco/web/templating/TemplateOutputMethod.java index 0e1157d653..ed0e5ab309 100644 --- a/source/java/org/alfresco/web/templating/TemplateOutputMethod.java +++ b/source/java/org/alfresco/web/templating/TemplateOutputMethod.java @@ -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(); } diff --git a/source/java/org/alfresco/web/templating/TemplatingService.java b/source/java/org/alfresco/web/templating/TemplatingService.java index dffb0ffe47..a68fc0e4c2 100644 --- a/source/java/org/alfresco/web/templating/TemplatingService.java +++ b/source/java/org/alfresco/web/templating/TemplatingService.java @@ -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; } diff --git a/source/java/org/alfresco/web/templating/xforms/FreeMarkerOutputMethod.java b/source/java/org/alfresco/web/templating/xforms/FreeMarkerOutputMethod.java index a5a579eb97..5dde4b54f8 100644 --- a/source/java/org/alfresco/web/templating/xforms/FreeMarkerOutputMethod.java +++ b/source/java/org/alfresco/web/templating/xforms/FreeMarkerOutputMethod.java @@ -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"; + } } diff --git a/source/java/org/alfresco/web/templating/xforms/SchemaFormBuilder.java b/source/java/org/alfresco/web/templating/xforms/SchemaFormBuilder.java index 0bab78a18f..9ff1fced30 100644 --- a/source/java/org/alfresco/web/templating/xforms/SchemaFormBuilder.java +++ b/source/java/org/alfresco/web/templating/xforms/SchemaFormBuilder.java @@ -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 element and add it to the model. Element bindElement = xForm.createElementNS(XFORMS_NS, SchemaFormBuilder.XFORMS_NS_PREFIX + "bind"); diff --git a/source/java/org/alfresco/web/templating/xforms/XSLTOutputMethod.java b/source/java/org/alfresco/web/templating/xforms/XSLTOutputMethod.java index 00488d21ac..492e7a9963 100644 --- a/source/java/org/alfresco/web/templating/xforms/XSLTOutputMethod.java +++ b/source/java/org/alfresco/web/templating/xforms/XSLTOutputMethod.java @@ -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); + } } diff --git a/source/web/jsp/content/create-xml-content-type-wizard/configure-presentation-templates.jsp b/source/web/jsp/content/create-xml-content-type-wizard/configure-presentation-templates.jsp deleted file mode 100644 index ac9ac327cc..0000000000 --- a/source/web/jsp/content/create-xml-content-type-wizard/configure-presentation-templates.jsp +++ /dev/null @@ -1,87 +0,0 @@ -<%-- - Copyright (C) 2005 Alfresco, Inc. - - Licensed under the Mozilla Public License version 1.1 - with a permitted attribution clause. You may obtain a - copy of the License at - - http://www.alfresco.org/legal/license.txt - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - either express or implied. See the License for the specific - language governing permissions and limitations under the - License. ---%> -<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %> -<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %> -<%@ taglib uri="/WEB-INF/alfresco.tld" prefix="a" %> -<%@ taglib uri="/WEB-INF/repo.tld" prefix="r" %> -<%@ page import="java.io.*" %> -<%@ page import="org.alfresco.web.bean.FileUploadBean" %> - - - - - - - - - - -<%-- - - - - - ---%> - - - - -<% -FileUploadBean upload = (FileUploadBean)session.getAttribute(FileUploadBean.getKey("pt")); -if (upload == null || upload.getFile() == null) -{ -%> - - - - - -<% -} else { -%> - - - -<% -} -%> - - - diff --git a/source/web/jsp/wcm/create-form-wizard/configure-template-output-methods.jsp b/source/web/jsp/wcm/create-form-wizard/configure-template-output-methods.jsp new file mode 100644 index 0000000000..52e9cf3fe2 --- /dev/null +++ b/source/web/jsp/wcm/create-form-wizard/configure-template-output-methods.jsp @@ -0,0 +1,126 @@ +<%-- + Copyright (C) 2005 Alfresco, Inc. + + Licensed under the Mozilla Public License version 1.1 + with a permitted attribution clause. You may obtain a + copy of the License at + + http://www.alfresco.org/legal/license.txt + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + either express or implied. See the License for the specific + language governing permissions and limitations under the + License. + --%> +<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %> +<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %> +<%@ taglib uri="/WEB-INF/alfresco.tld" prefix="a" %> +<%@ taglib uri="/WEB-INF/repo.tld" prefix="r" %> + + + + + + + + + + + + + + <%-- + + + + + + --%> + + + +<% +FileUploadBean upload = (FileUploadBean) +session.getAttribute(FileUploadBean.getKey("template-output-method")); +if (upload == null || upload.getFile() == null) +{ +%> + + + + + + + +<% +} else { +%> + +<% +} +%> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/source/web/jsp/content/create-xml-content-type-wizard/details.jsp b/source/web/jsp/wcm/create-form-wizard/details.jsp similarity index 100% rename from source/web/jsp/content/create-xml-content-type-wizard/details.jsp rename to source/web/jsp/wcm/create-form-wizard/details.jsp diff --git a/source/web/jsp/content/create-xml-content-type-wizard/edit.jsp b/source/web/jsp/wcm/create-form-wizard/edit.jsp similarity index 100% rename from source/web/jsp/content/create-xml-content-type-wizard/edit.jsp rename to source/web/jsp/wcm/create-form-wizard/edit.jsp