- first pass at freemarker integration

- hello world freemarker template for simple test (works!)
- fixing edit-xml - it was referring to CreateXmlContentTypeWizard which was renamed yesterday
- separating out customer code from prototype util code in press release example.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@4116 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Ariel Backenroth
2006-10-16 19:45:00 +00:00
parent ea6c85be54
commit b068224185
15 changed files with 285 additions and 142 deletions

View File

@@ -651,6 +651,7 @@ selected_templateoutputmethods=Selected Template Output Methods
configure_output_methods_step1_desc=Upload template output method and specify the extension to use for its generated assets. configure_output_methods_step1_desc=Upload template output method and specify the extension to use for its generated assets.
template_output_method_file=Template Output Method File template_output_method_file=Template Output Method File
extension_for_generated_assets=Extension For Generated Assets extension_for_generated_assets=Extension For Generated Assets
file_extension=Extension
schema=Schema schema=Schema
schema_root_tag_name=Root Tag schema_root_tag_name=Root Tag
edit_xml_schema=Edit XML Schema edit_xml_schema=Edit XML Schema

View File

@@ -43,7 +43,7 @@ import org.alfresco.service.namespace.QName;
import org.alfresco.web.app.Application; import org.alfresco.web.app.Application;
import org.alfresco.web.bean.FileUploadBean; import org.alfresco.web.bean.FileUploadBean;
import org.alfresco.web.bean.wizard.BaseWizardBean; import org.alfresco.web.bean.wizard.BaseWizardBean;
import org.alfresco.web.templating.xforms.SchemaFormBuilder; import org.alfresco.web.templating.xforms.*;
import org.alfresco.web.templating.TemplatingService; import org.alfresco.web.templating.TemplatingService;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@@ -60,27 +60,25 @@ public class CreateFormWizard extends BaseWizardBean
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
private static final String FILE_TEMPLATEOUTPUT = "template-output-method";
private static final String FILE_SCHEMA = "schema";
/** /**
* Simple wrapper class to represent a template output method * Simple wrapper class to represent a template output method
*/ */
public static class TemplateOutputMethodData public class TemplateOutputMethodData
{ {
private final String fileName; private final String fileName;
private final File file; private final File file;
private final String fileExtension; private final String fileExtension;
private final Class templateOutputMethodType;
public TemplateOutputMethodData(final String fileName, public TemplateOutputMethodData(final String fileName,
final File file, final File file,
final String fileExtension) final String fileExtension,
final Class templateOutputMethodType)
{ {
this.fileName = fileName; this.fileName = fileName;
this.file = file; this.file = file;
this.fileExtension = fileExtension; this.fileExtension = fileExtension;
this.templateOutputMethodType = templateOutputMethodType;
} }
public String getFileExtension() public String getFileExtension()
@@ -98,20 +96,29 @@ public class CreateFormWizard extends BaseWizardBean
return this.file; return this.file;
} }
public String getLabel() public Class getTemplateOutputMethodType()
{ {
return this.getFileExtension().toUpperCase() + " (" + this.getFileName() + ")"; return this.templateOutputMethodType;
}
public String getTemplateOutputMethodTypeName()
{
return CreateFormWizard.this.getTemplateOutputMethodTypeName(this.getTemplateOutputMethodType());
} }
} }
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
private static final String FILE_TEMPLATEOUTPUT = "template-output-method";
private static final String FILE_SCHEMA = "schema";
private final static Log LOGGER = private final static Log LOGGER =
LogFactory.getLog(CreateFormWizard.class); LogFactory.getLog(CreateFormWizard.class);
private String schemaRootTagName; private String schemaRootTagName;
private String templateName; private String templateName;
private String presentationTemplateType; private Class templateOutputMethodType = null;
protected ContentService contentService; protected ContentService contentService;
private DataModel templateOutputMethodsDataModel; private DataModel templateOutputMethodsDataModel;
private List<TemplateOutputMethodData> templateOutputMethods = null; private List<TemplateOutputMethodData> templateOutputMethods = null;
@@ -136,14 +143,14 @@ public class CreateFormWizard extends BaseWizardBean
this.fileFolderService.create(folderInfo.getNodeRef(), this.fileFolderService.create(folderInfo.getNodeRef(),
this.getSchemaFileName(), this.getSchemaFileName(),
ContentModel.TYPE_CONTENT); ContentModel.TYPE_CONTENT);
final NodeRef schemaFileNodeRef = fileInfo.getNodeRef(); final NodeRef schemaNodeRef = fileInfo.getNodeRef();
if (LOGGER.isDebugEnabled()) if (LOGGER.isDebugEnabled())
LOGGER.debug("Created file node for file: " + LOGGER.debug("Created file node for file: " +
this.getSchemaFileName()); this.getSchemaFileName());
// get a writer for the content and put the file // get a writer for the content and put the file
ContentWriter writer = this.contentService.getWriter(schemaFileNodeRef, ContentWriter writer = this.contentService.getWriter(schemaNodeRef,
ContentModel.PROP_CONTENT, ContentModel.PROP_CONTENT,
true); true);
// set the mimetype and encoding // set the mimetype and encoding
@@ -155,24 +162,24 @@ public class CreateFormWizard extends BaseWizardBean
Map<QName, Serializable> props = new HashMap<QName, Serializable>(2, 1.0f); Map<QName, Serializable> props = new HashMap<QName, Serializable>(2, 1.0f);
props.put(ContentModel.PROP_TITLE, this.getTemplateName()); props.put(ContentModel.PROP_TITLE, this.getTemplateName());
props.put(ContentModel.PROP_DESCRIPTION, ""); props.put(ContentModel.PROP_DESCRIPTION, "");
this.nodeService.addAspect(schemaFileNodeRef, ContentModel.ASPECT_TITLED, props); this.nodeService.addAspect(schemaNodeRef, ContentModel.ASPECT_TITLED, props);
props = new HashMap<QName, Serializable>(1, 1.0f); props = new HashMap<QName, Serializable>(1, 1.0f);
props.put(WCMModel.PROP_SCHEMA_ROOT_TAG_NAME, this.getSchemaRootTagName()); props.put(WCMModel.PROP_SCHEMA_ROOT_TAG_NAME, this.getSchemaRootTagName());
this.nodeService.addAspect(schemaFileNodeRef, WCMModel.ASPECT_TEMPLATE, props); this.nodeService.addAspect(schemaNodeRef, WCMModel.ASPECT_TEMPLATE, props);
for (TemplateOutputMethodData tomd : this.templateOutputMethods) for (TemplateOutputMethodData tomd : this.templateOutputMethods)
{ {
fileInfo = this.fileFolderService.create(folderInfo.getNodeRef(), fileInfo = this.fileFolderService.create(folderInfo.getNodeRef(),
tomd.getFileName(), tomd.getFileName(),
ContentModel.TYPE_CONTENT); ContentModel.TYPE_CONTENT);
final NodeRef presentationTemplateFileNodeRef = fileInfo.getNodeRef(); final NodeRef templateOutputMethodNodeRef = fileInfo.getNodeRef();
if (LOGGER.isDebugEnabled()) if (LOGGER.isDebugEnabled())
LOGGER.debug("Created file node for file: " + tomd.getFileName()); LOGGER.debug("Created file node for file: " + tomd.getFileName());
// get a writer for the content and put the file // get a writer for the content and put the file
writer = this.contentService.getWriter(presentationTemplateFileNodeRef, writer = this.contentService.getWriter(templateOutputMethodNodeRef,
ContentModel.PROP_CONTENT, ContentModel.PROP_CONTENT,
true); true);
// set the mimetype and encoding // set the mimetype and encoding
@@ -180,15 +187,15 @@ public class CreateFormWizard extends BaseWizardBean
writer.setEncoding("UTF-8"); writer.setEncoding("UTF-8");
writer.putContent(tomd.getFile()); writer.putContent(tomd.getFile());
this.nodeService.createAssociation(schemaFileNodeRef, this.nodeService.createAssociation(schemaNodeRef,
presentationTemplateFileNodeRef, templateOutputMethodNodeRef,
WCMModel.ASSOC_TEMPLATE_OUTPUT_METHODS); WCMModel.ASSOC_TEMPLATE_OUTPUT_METHODS);
props = new HashMap<QName, Serializable>(3, 1.0f); props = new HashMap<QName, Serializable>(3, 1.0f);
props.put(WCMModel.PROP_TEMPLATE_OUTPUT_METHOD_TYPE, this.getTemplateOutputMethodType()); props.put(WCMModel.PROP_TEMPLATE_OUTPUT_METHOD_TYPE, tomd.getTemplateOutputMethodType().getName());
props.put(WCMModel.PROP_TEMPLATE_SOURCE, schemaFileNodeRef); props.put(WCMModel.PROP_TEMPLATE_SOURCE, schemaNodeRef);
props.put(WCMModel.PROP_TEMPLATE_OUTPUT_METHOD_DERIVED_FILE_EXTENSION, tomd.getFileExtension()); props.put(WCMModel.PROP_TEMPLATE_OUTPUT_METHOD_DERIVED_FILE_EXTENSION, tomd.getFileExtension());
this.nodeService.addAspect(presentationTemplateFileNodeRef, WCMModel.ASPECT_TEMPLATE_OUTPUT_METHOD, props); this.nodeService.addAspect(templateOutputMethodNodeRef, WCMModel.ASPECT_TEMPLATE_OUTPUT_METHOD, props);
} }
// return the default outcome // return the default outcome
return outcome; return outcome;
@@ -203,8 +210,9 @@ public class CreateFormWizard extends BaseWizardBean
this.removeUploadedTemplateOutputMethodFile(); this.removeUploadedTemplateOutputMethodFile();
this.schemaRootTagName = null; this.schemaRootTagName = null;
this.templateName = null; this.templateName = null;
this.templateOutputMethodType = null;
this.templateOutputMethods = new ArrayList<TemplateOutputMethodData>(); this.templateOutputMethods = new ArrayList<TemplateOutputMethodData>();
this.fileExtension = "shtml"; this.fileExtension = null;
} }
@Override @Override
@@ -242,7 +250,9 @@ public class CreateFormWizard extends BaseWizardBean
*/ */
public boolean getAddToListDisabled() public boolean getAddToListDisabled()
{ {
return (getTemplateOutputMethodFileName() == null || fileExtension == null || fileExtension.length() == 0); return (getTemplateOutputMethodFileName() == null ||
fileExtension == null ||
fileExtension.length() == 0);
} }
/** /**
@@ -276,11 +286,14 @@ public class CreateFormWizard extends BaseWizardBean
} }
final TemplateOutputMethodData data = final TemplateOutputMethodData data =
new TemplateOutputMethodData(this.getTemplateOutputMethodFileName(), this.new TemplateOutputMethodData(this.getTemplateOutputMethodFileName(),
this.getTemplateOutputMethodFile(), this.getTemplateOutputMethodFile(),
this.fileExtension); this.fileExtension,
this.templateOutputMethodType);
this.templateOutputMethods.add(data); this.templateOutputMethods.add(data);
this.removeUploadedTemplateOutputMethodFile(); this.removeUploadedTemplateOutputMethodFile();
this.templateOutputMethodType = null;
this.fileExtension = null;
} }
/** /**
@@ -345,21 +358,53 @@ public class CreateFormWizard extends BaseWizardBean
*/ */
public String getTemplateOutputMethodType() public String getTemplateOutputMethodType()
{ {
if (this.getTemplateOutputMethodFileName() != null) if (this.templateOutputMethodType == null &&
this.getTemplateOutputMethodFileName() != null)
{ {
// String s = this.getTemplateOutputMethodFileName(); this.templateOutputMethodType =
// String extension = (this.getTemplateOutputMethodFileName().endsWith(".xsl")
this.presentationTemplateType = "XSL"; ? XSLTOutputMethod.class
: (this.getTemplateOutputMethodFileName().endsWith(".ftl")
? FreeMarkerOutputMethod.class
: null));
} }
return this.presentationTemplateType; return (this.templateOutputMethodType == null
? null
: this.templateOutputMethodType.getName());
} }
/** /**
* @param presentationTemplateType Sets the currently selected mime type * @param templateOutputMethodType Sets the currently selected mime type
*/ */
public void setTemplateOutputMethodType(String presentationTemplateType) public void setTemplateOutputMethodType(final String templateOutputMethodType)
throws ClassNotFoundException
{ {
this.presentationTemplateType = presentationTemplateType; this.templateOutputMethodType = (templateOutputMethodType == null
? null
: Class.forName(templateOutputMethodType));
}
/**
* @return Returns a list of mime types to allow the user to select from
*/
public List<SelectItem> getTemplateOutputMethodTypeChoices()
{
return (List<SelectItem>)Arrays.asList(new SelectItem[]
{
new SelectItem(FreeMarkerOutputMethod.class.getName(),
getTemplateOutputMethodTypeName(FreeMarkerOutputMethod.class)),
new SelectItem(XSLTOutputMethod.class.getName(),
getTemplateOutputMethodTypeName(XSLTOutputMethod.class))
});
}
private String getTemplateOutputMethodTypeName(Class type)
{
return (FreeMarkerOutputMethod.class.equals(type)
? "FreeMarker"
: (XSLTOutputMethod.class.equals(type)
? "XSLT"
: null));
} }
private FileUploadBean getFileUploadBean(final String id) private FileUploadBean getFileUploadBean(final String id)
@@ -490,17 +535,6 @@ public class CreateFormWizard extends BaseWizardBean
: this.templateName); : this.templateName);
} }
/**
* @return Returns a list of mime types to allow the user to select from
*/
public List<SelectItem> getCreateTemplateOutputMethodTypes()
{
return (List<SelectItem>)Arrays.asList(new SelectItem[] {
new SelectItem("freemarker", "FreeMarker"),
new SelectItem("xslt", "XSLT")
});
}
/** /**
* @return Returns the summary data for the wizard. * @return Returns the summary data for the wizard.
*/ */

View File

@@ -17,6 +17,7 @@
package org.alfresco.web.templating; package org.alfresco.web.templating;
import java.io.*; import java.io.*;
import java.lang.reflect.Constructor;
import java.util.*; import java.util.*;
import javax.xml.parsers.*; import javax.xml.parsers.*;
@@ -37,7 +38,6 @@ import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.model.ContentModel; import org.alfresco.model.ContentModel;
import org.alfresco.model.WCMModel; import org.alfresco.model.WCMModel;
import org.alfresco.util.TempFileProvider;
import org.alfresco.service.ServiceRegistry; import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.dictionary.DictionaryService; import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.repository.AssociationRef; import org.alfresco.service.cmr.repository.AssociationRef;
@@ -213,11 +213,25 @@ public final class TemplatingService implements Serializable
for (AssociationRef assoc : this.nodeService.getTargetAssocs(schemaNodeRef, for (AssociationRef assoc : this.nodeService.getTargetAssocs(schemaNodeRef,
WCMModel.ASSOC_TEMPLATE_OUTPUT_METHODS)) WCMModel.ASSOC_TEMPLATE_OUTPUT_METHODS))
{ {
final NodeRef xslNodeRef = assoc.getTargetRef(); final NodeRef tomNodeRef = assoc.getTargetRef();
final TemplateOutputMethod tom = new XSLTOutputMethod(xslNodeRef, this.nodeService); try
LOGGER.debug("loaded template output method " + tom.getFileExtension() + ", " + xslNodeRef); {
final Class templateOutputMethodType =
Class.forName((String)this.nodeService.getProperty(tomNodeRef,
WCMModel.PROP_TEMPLATE_OUTPUT_METHOD_TYPE));
final Constructor c = templateOutputMethodType.getConstructor(NodeRef.class, NodeService.class, ContentService.class);
final TemplateOutputMethod tom = (TemplateOutputMethod)
c.newInstance(tomNodeRef, this.nodeService, this.contentService);
LOGGER.debug("loaded template output method type " + tom.getClass().getName() +
" for extension " + tom.getFileExtension() + ", " + tomNodeRef);
tt.addOutputMethod(tom); tt.addOutputMethod(tom);
} }
catch (Exception e)
{
LOGGER.error(e);
}
}
return tt; return tt;
} }

View File

@@ -16,11 +16,22 @@
*/ */
package org.alfresco.web.templating.xforms; package org.alfresco.web.templating.xforms;
import freemarker.ext.dom.NodeModel;
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;
import freemarker.template.TemplateExceptionHandler;
import java.io.*; import java.io.*;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.alfresco.model.ContentModel;
import org.alfresco.model.WCMModel;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.web.templating.*; import org.alfresco.web.templating.*;
import org.chiba.xml.util.DOMUtil; import org.chiba.xml.util.DOMUtil;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Node; import org.w3c.dom.Node;
@@ -28,19 +39,43 @@ public class FreeMarkerOutputMethod
implements TemplateOutputMethod implements TemplateOutputMethod
{ {
public FreeMarkerOutputMethod() private final NodeRef nodeRef;
private final NodeService nodeService;
private final ContentService contentService;
public FreeMarkerOutputMethod(final NodeRef nodeRef,
final NodeService nodeService,
final ContentService contentService)
{ {
this.nodeRef = nodeRef;
this.nodeService = nodeService;
this.contentService = contentService;
} }
public void generate(final Document xmlContent, public void generate(final Document xmlContent,
final TemplateType tt, final TemplateType tt,
final Map<String, String> parameters, final Map<String, String> parameters,
final Writer out) final Writer out)
throws IOException,
TemplateException
{ {
final ContentReader contentReader =
this.contentService.getReader(nodeRef, ContentModel.TYPE_CONTENT);
final Reader reader = new InputStreamReader(contentReader.getContentInputStream());
final Configuration cfg = new Configuration();
cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
final Template t = new Template("freemarker_template", reader, cfg);
final Map<String, Object> root = new HashMap<String, Object>();
root.put("doc", NodeModel.wrap(xmlContent));
t.process(root, out);
out.flush();
} }
public String getFileExtension() public String getFileExtension()
{ {
return "unimpleemnted"; return (String)
this.nodeService.getProperty(this.nodeRef,
WCMModel.PROP_TEMPLATE_OUTPUT_METHOD_DERIVED_FILE_EXTENSION);
} }
} }

View File

@@ -19,8 +19,7 @@ package org.alfresco.web.templating.xforms;
import java.io.*; import java.io.*;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import org.alfresco.web.templating.*; import java.util.Map;
import org.chiba.xml.util.DOMUtil;
import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Source; import javax.xml.transform.Source;
import javax.xml.transform.Templates; import javax.xml.transform.Templates;
@@ -32,18 +31,19 @@ import javax.xml.transform.URIResolver;
import javax.xml.transform.dom.DOMSource; import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.sax.SAXTransformerFactory; import javax.xml.transform.sax.SAXTransformerFactory;
import javax.xml.transform.sax.TransformerHandler; import javax.xml.transform.sax.TransformerHandler;
import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import org.alfresco.model.WCMModel;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.web.templating.*;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.alfresco.model.WCMModel; import org.chiba.xml.util.DOMUtil;
import org.alfresco.service.cmr.repository.NodeService;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import org.alfresco.service.cmr.repository.NodeRef;
import java.util.Map;
public class XSLTOutputMethod public class XSLTOutputMethod
implements TemplateOutputMethod implements TemplateOutputMethod
@@ -55,7 +55,8 @@ public class XSLTOutputMethod
private final NodeService nodeService; private final NodeService nodeService;
public XSLTOutputMethod(final NodeRef nodeRef, public XSLTOutputMethod(final NodeRef nodeRef,
final NodeService nodeService) final NodeService nodeService,
final ContentService contentService)
{ {
this.nodeRef = nodeRef; this.nodeRef = nodeRef;
this.nodeService = nodeService; this.nodeService = nodeService;

View File

@@ -16,8 +16,32 @@
*/ */
package org.alfresco.web.pr; package org.alfresco.web.pr;
import java.util.*;
import javax.servlet.jsp.PageContext;
import org.w3c.dom.*;
public class CompanyFooterBean public class CompanyFooterBean
{ {
public static List<CompanyFooterBean> getCompanyFooters(final PageContext pageContext)
throws Exception
{
final Map<String, Document> entries = Util.loadXMLDocuments(pageContext,
"/media/releases/content/company_footers",
"alfresco:company-footer");
final List<CompanyFooterBean> result = new ArrayList<CompanyFooterBean>(entries.size());
for (Map.Entry<String, Document> entry : entries.entrySet())
{
String fileName = entry.getKey();
Document d = entry.getValue();
Element n = (Element)d.getElementsByTagName("alfresco:name").item(0);
String href = "/media/releases/content/company_footers/" + fileName;
result.add(new CompanyFooterBean(n.getFirstChild().getNodeValue(),
href));
}
return result;
}
private final String name; private final String name;
private final String href; private final String href;

View File

@@ -16,10 +16,38 @@
*/ */
package org.alfresco.web.pr; package org.alfresco.web.pr;
import java.util.Date; import java.util.*;
import java.text.*;
import javax.servlet.jsp.PageContext;
import org.w3c.dom.*;
public class PressReleaseBean public class PressReleaseBean
{ {
public static List<PressReleaseBean> getPressReleases(final PageContext pageContext)
throws Exception
{
final Map<String, Document> entries = Util.loadXMLDocuments(pageContext,
"/media/releases/content",
"alfresco:press-release");
final List<PressReleaseBean> result = new ArrayList<PressReleaseBean>(entries.size());
for (Map.Entry<String, Document> entry : entries.entrySet() )
{
String fileName = entry.getKey();
Document d = entry.getValue();
Element t = (Element)d.getElementsByTagName("alfresco:title").item(0);
Element a = (Element)d.getElementsByTagName("alfresco:abstract").item(0);
Element dateEl = (Element)d.getElementsByTagName("alfresco:launch_date").item(0);
Date date = new SimpleDateFormat("yyyy-MM-dd").parse(dateEl.getFirstChild().getNodeValue());
String href = "/media/releases/content/" + fileName;
href = href.replaceAll(".xml$", ".shtml");
result.add(new PressReleaseBean(t.getFirstChild().getNodeValue(),
a.getFirstChild().getNodeValue(),
date,
href));
}
return result;
}
private final String title; private final String title;
private final String theAbstract; private final String theAbstract;
private final Date launchDate; private final Date launchDate;

View File

@@ -26,55 +26,11 @@ import org.alfresco.repo.avm.AVMRemote;
import org.alfresco.service.cmr.avm.AVMNodeDescriptor; import org.alfresco.service.cmr.avm.AVMNodeDescriptor;
import org.w3c.dom.*; import org.w3c.dom.*;
import javax.xml.parsers.*; import javax.xml.parsers.*;
import java.text.*;
public class Util public class Util
{ {
public static List<PressReleaseBean> getPressReleases(final PageContext pageContext)
throws Exception
{
final Map<String, Document> entries = Util.loadXMLDocuments(pageContext,
"/media/releases/content",
"alfresco:press-release");
final List<PressReleaseBean> result = new ArrayList<PressReleaseBean>(entries.size());
for (Map.Entry<String, Document> entry : entries.entrySet() )
{
String fileName = entry.getKey();
Document d = entry.getValue();
Element t = (Element)d.getElementsByTagName("alfresco:title").item(0);
Element a = (Element)d.getElementsByTagName("alfresco:abstract").item(0);
Element dateEl = (Element)d.getElementsByTagName("alfresco:launch_date").item(0);
Date date = new SimpleDateFormat("yyyy-MM-dd").parse(dateEl.getFirstChild().getNodeValue());
String href = "/media/releases/content/" + fileName;
href = href.replaceAll(".xml$", ".shtml");
result.add(new PressReleaseBean(t.getFirstChild().getNodeValue(),
a.getFirstChild().getNodeValue(),
date,
href));
}
return result;
}
public static List<CompanyFooterBean> getCompanyFooters(final PageContext pageContext) public static Map<String, Document> loadXMLDocuments(final PageContext pageContext,
throws Exception
{
final Map<String, Document> entries = Util.loadXMLDocuments(pageContext,
"/media/releases/content/company_footers",
"alfresco:company-footer");
final List<CompanyFooterBean> result = new ArrayList<CompanyFooterBean>(entries.size());
for (Map.Entry<String, Document> entry : entries.entrySet())
{
String fileName = entry.getKey();
Document d = entry.getValue();
Element n = (Element)d.getElementsByTagName("alfresco:name").item(0);
String href = "/media/releases/content/company_footers/" + fileName;
result.add(new CompanyFooterBean(n.getFirstChild().getNodeValue(),
href));
}
return result;
}
private static Map<String, Document> loadXMLDocuments(final PageContext pageContext,
final String path, final String path,
final String documentElementNodeName) final String documentElementNodeName)
throws Exception throws Exception

View File

@@ -10,12 +10,12 @@
<uri>http://www.alfresco.org/pr</uri> <uri>http://www.alfresco.org/pr</uri>
<function> <function>
<name>getPressReleases</name> <name>getPressReleases</name>
<function-class>org.alfresco.web.pr.Util</function-class> <function-class>org.alfresco.web.pr.PressReleaseBean</function-class>
<function-signature>java.util.List getPressReleases(javax.servlet.jsp.PageContext)</function-signature> <function-signature>java.util.List getPressReleases(javax.servlet.jsp.PageContext)</function-signature>
</function> </function>
<function> <function>
<name>getCompanyFooters</name> <name>getCompanyFooters</name>
<function-class>org.alfresco.web.pr.Util</function-class> <function-class>org.alfresco.web.pr.CompanyFooterBean</function-class>
<function-signature>java.util.List getCompanyFooters(javax.servlet.jsp.PageContext)</function-signature> <function-signature>java.util.List getCompanyFooters(javax.servlet.jsp.PageContext)</function-signature>
</function> </function>
</taglib> </taglib>

View File

@@ -1,10 +1,8 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:alfresco="http://www.alfresco.org/alfresco" xmlns:alfresco="http://www.alfresco.org/alfresco"
xml:base="http://wacko.org"
targetNamespace="http://www.alfresco.org/alfresco" targetNamespace="http://www.alfresco.org/alfresco"
elementFormDefault="qualified"> elementFormDefault="qualified">
<xs:include schemaLocation="/GetCompanyFooterSimpleType"/>
<xs:element name="company-footer"> <xs:element name="company-footer">
<xs:complexType> <xs:complexType>
<xs:sequence> <xs:sequence>

View File

@@ -0,0 +1,27 @@
<html>
<head>
<style type="text/css">
body
{
font-family: Tahoma, Arial, Helvetica, sans-serif;
background-color: white;
font-size: 11px;
}
.name {
color: #003366;
font-weight: bold;
margin-right: 10px;
}
</style>
<title>Simple Test</title>
</head>
<body>
<div>Generated by simple-test.ftl</div>
<div style="line-height: 25px;">
<span class="name">Captured string value:</span>
<span>${doc.simple.string}</span>
</div>
</body>
</html>

View File

@@ -1,7 +1,7 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"> elementFormDefault="qualified">
<xs:element name="simple-test"> <xs:element name="simple">
<xs:complexType> <xs:complexType>
<xs:sequence> <xs:sequence>
<xs:element name="string" type="xs:string" default="default string value"/> <xs:element name="string" type="xs:string" default="default string value"/>

View File

@@ -30,11 +30,16 @@ body
<title>Simple Test</title> <title>Simple Test</title>
</head> </head>
<body> <body>
<div>Generated by simple-test.xsl</div>
<xsl:apply-templates/> <xsl:apply-templates/>
</body> </body>
</html> </html>
</xsl:template> </xsl:template>
<xsl:template match="/simple-test/string"> <xsl:template match="/simple/string">
<div style="line-height: 25px;"><span class="name">Captured string value:</span> <xsl:value-of select="/simple-test/string"/></div> <div style="line-height: 25px;">
<span class="name">Captured string value:</span>
<span><xsl:value-of select="/simple/string"/></span>
</div>
</xsl:template> </xsl:template>
</xsl:stylesheet> </xsl:stylesheet>

View File

@@ -46,21 +46,12 @@
<h:panelGrid id="panel_grid_3" <h:panelGrid id="panel_grid_3"
columns="3" cellpadding="3" cellspacing="3" border="0" columns="3" cellpadding="3" cellspacing="3" border="0"
width="100%"> width="100%">
<%--
<h:graphicImage id="required-image-type" value="/images/icons/required_field.gif" alt="Required Field" />
<h:outputText id="panel_grid_3_output_text_1"
value="Presentation Template Type:" escape="false" />
<h:selectOneRadio value="#{WizardManager.bean.templateOutputMethodType}">
<f:selectItems value="#{WizardManager.bean.createTemplateOutputMethodTypes}"/>
</h:selectOneRadio>
--%>
<h:graphicImage id="required_image_pt" <h:graphicImage id="required_image_pt"
value="/images/icons/required_field.gif" alt="Required Field" /> value="/images/icons/required_field.gif" alt="Required Field" />
<h:outputText id="output_text_pt" <h:outputText id="output_text_pt"
value="#{msg.template_output_method_file}:"/> value="#{msg.template_output_method_file}:"/>
<% <%
FileUploadBean upload = (FileUploadBean) final FileUploadBean upload = (FileUploadBean)
session.getAttribute(FileUploadBean.getKey("template-output-method")); session.getAttribute(FileUploadBean.getKey("template-output-method"));
if (upload == null || upload.getFile() == null) if (upload == null || upload.getFile() == null)
{ {
@@ -80,6 +71,16 @@ if (upload == null || upload.getFile() == null)
<% <%
} }
%> %>
<h:graphicImage id="required_image_template_output_method_type"
value="/images/icons/required_field.gif" alt="Required Field" />
<h:outputText id="template_output_method_type_output_text"
value="#{msg.type}:"/>
<h:selectOneRadio id="template_output_method_type"
value="#{WizardManager.bean.templateOutputMethodType}">
<f:selectItems id="template_output_method_type_choices"
value="#{WizardManager.bean.templateOutputMethodTypeChoices}"/>
</h:selectOneRadio>
<h:graphicImage id="required_image_file_extension" <h:graphicImage id="required_image_file_extension"
value="/images/icons/required_field.gif" alt="Required Field" /> value="/images/icons/required_field.gif" alt="Required Field" />
<h:outputText id="file_extension_output_text" <h:outputText id="file_extension_output_text"
@@ -95,21 +96,37 @@ if (upload == null || upload.getFile() == null)
styleClass="wizardButton" disabled="#{WizardManager.bean.addToListDisabled}" /> styleClass="wizardButton" disabled="#{WizardManager.bean.addToListDisabled}" />
</h:panelGroup> </h:panelGroup>
<h:outputText id="selected_template_output_methods_output_text" <h:outputText id="selected_template_output_methods_output_text"
styleClass="mainSubText" value="#{msg.selected_templateoutputmethods}" /> styleClass="mainSubText"
value="#{msg.selected_templateoutputmethods}" />
<h:panelGroup id="data-table-panel-group"> <h:panelGroup id="data-table-panel-group">
<h:dataTable id="template_output_method_data_table" <h:dataTable id="template_output_method_data_table"
value="#{WizardManager.bean.templateOutputMethodsDataModel}" var="row" value="#{WizardManager.bean.templateOutputMethodsDataModel}"
var="row"
rowClasses="selectedItemsRow,selectedItemsRowAlt" rowClasses="selectedItemsRow,selectedItemsRowAlt"
styleClass="selectedItems" headerClass="selectedItemsHeader" styleClass="selectedItems"
cellspacing="0" cellpadding="4" headerClass="selectedItemsHeader"
cellspacing="0"
cellpadding="4"
rendered="#{WizardManager.bean.templateOutputMethodsDataModel.rowCount != 0}"> rendered="#{WizardManager.bean.templateOutputMethodsDataModel.rowCount != 0}">
<h:column id="data-table-column-1"> <h:column id="data-table-column-1">
<f:facet name="header"> <f:facet name="header">
<h:outputText id="data-table-name" value="#{msg.name}" /> <h:outputText id="data-table-name-1" value="#{msg.file_name}" />
</f:facet> </f:facet>
<h:outputText id="data-table-value" value="#{row.label}" /> <h:outputText id="data-table-value-1" value="#{row.fileName}" />
</h:column> </h:column>
<h:column id="data-table-column-2"> <h:column id="data-table-column-2">
<f:facet name="header">
<h:outputText id="data-table-name-2" value="#{msg.type}" />
</f:facet>
<h:outputText id="data-table-value-2" value="#{row.templateOutputMethodTypeName}" />
</h:column>
<h:column id="data-table-column-3">
<f:facet name="header">
<h:outputText id="data-table-name-3" value="#{msg.file_extension}" />
</f:facet>
<h:outputText id="data-table-value-3" value="#{row.fileExtension}" />
</h:column>
<h:column id="data-table-column-4">
<a:actionLink id="remove-select-template-output-method-action-link" <a:actionLink id="remove-select-template-output-method-action-link"
actionListener="#{WizardManager.bean.removeSelectedTemplateOutputMethod}" actionListener="#{WizardManager.bean.removeSelectedTemplateOutputMethod}"
image="/images/icons/delete.gif" image="/images/icons/delete.gif"
@@ -118,7 +135,11 @@ if (upload == null || upload.getFile() == null)
</h:dataTable> </h:dataTable>
<a:panel id="no-items" rendered="#{WizardManager.bean.templateOutputMethodsDataModel.rowCount == 0}"> <a:panel id="no-items" rendered="#{WizardManager.bean.templateOutputMethodsDataModel.rowCount == 0}">
<h:panelGrid id="no-items-panel-grid" columns="1" cellpadding="2" styleClass="selectedItems" rowClasses="selectedItemsHeader,selectedItemsRow"> <h:panelGrid id="no-items-panel-grid"
columns="1"
cellpadding="2"
styleClass="selectedItems"
rowClasses="selectedItemsHeader,selectedItemsRow">
<h:outputText styleClass="selectedItemsHeader" id="no-items-name" value="#{msg.name}" /> <h:outputText styleClass="selectedItemsHeader" id="no-items-name" value="#{msg.name}" />
<h:outputText styleClass="selectedItemsRow" id="no-items-msg" value="#{msg.no_selected_items}" /> <h:outputText styleClass="selectedItemsRow" id="no-items-msg" value="#{msg.no_selected_items}" />
</h:panelGrid> </h:panelGrid>

View File

@@ -29,7 +29,6 @@
org.alfresco.web.templating.*" %> org.alfresco.web.templating.*" %>
<%@ page import="java.io.*" %> <%@ page import="java.io.*" %>
<%@ page import="org.alfresco.web.app.Application" %> <%@ page import="org.alfresco.web.app.Application" %>
<%@ page import="org.alfresco.web.bean.content.CreateXmlContentTypeWizard" %>
<%@ page import="org.alfresco.web.templating.*" %> <%@ page import="org.alfresco.web.templating.*" %>
<%@ page import="org.w3c.dom.Document" %> <%@ page import="org.w3c.dom.Document" %>
<% <%