- adding in the structure for an XSL FO rendering engine

- terminology cleanups to model and screens
- extracting company-footer back into its own xsd; no reason to shove that feature in everyone's face.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@4227 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Ariel Backenroth
2006-10-26 04:16:16 +00:00
parent 0b3147e8c2
commit 07686ab8ce
13 changed files with 284 additions and 63 deletions

View File

@@ -69,13 +69,25 @@ public abstract class AbstractRenderingEngine
*
* @return the file extension to use for generated assets.
*/
public String getFileExtension()
public String getFileExtensionForRendition()
{
return (String)
this.nodeService.getProperty(this.nodeRef,
WCMModel.PROP_FILE_EXTENSION_FOR_RENDITION);
}
/**
* Returns the file extension to use for generated assets.
*
* @return the file extension to use for generated assets.
*/
public String getMimetypeForRendition()
{
return (String)
this.nodeService.getProperty(this.nodeRef,
WCMModel.PROP_MIMETYPE_FOR_RENDITION);
}
protected static AVMRemote getAVMRemote()
{
final FacesContext fc =

View File

@@ -43,13 +43,13 @@ public interface FormProcessor
/////////////////////////////////////////////////////////////////////////////
/**
* Generates a user interface for inputing data into a form.
* Processes a user interface for inputing data into a form.
*
* @param instanceData provides the xml instance data if available.
* @param form the form to generate for
* @param out the writer to write the output to.
*/
public void generate(final FormProcessor.InstanceData instanceData,
final Form form,
final Writer out);
public void process(final FormProcessor.InstanceData instanceData,
final Form form,
final Writer out);
}

View File

@@ -238,7 +238,8 @@ public final class FormsService
final RenderingEngine tom = (RenderingEngine)
c.newInstance(tomNodeRef, this.nodeService, this.contentService);
LOGGER.debug("loaded form data renderer type " + tom.getClass().getName() +
" for extension " + tom.getFileExtension() + ", " + tomNodeRef);
" for extension " + tom.getFileExtensionForRendition() +
", " + tomNodeRef);
tt.addRenderingEngine(tom);
}
catch (Exception e)
@@ -271,19 +272,19 @@ public final class FormsService
{
// get the node ref of the node that will contain the content
final String renditionFileName =
this.stripExtension(formInstanceDataFileName) + "." + re.getFileExtension();
final OutputStream fileOut = this.avmService.createFile(parentPath, renditionFileName);
(this.stripExtension(formInstanceDataFileName) +
"." + re.getFileExtensionForRendition());
final OutputStream out = this.avmService.createFile(parentPath, renditionFileName);
final String renditionAvmPath = parentPath + '/' + renditionFileName;
if (LOGGER.isDebugEnabled())
LOGGER.debug("Created file node for file: " + renditionAvmPath);
final OutputStreamWriter out = new OutputStreamWriter(fileOut);
final HashMap<String, String> parameters =
this.getRenderingEngineParameters(formInstanceDataFileName,
renditionFileName,
parentPath);
re.generate(formInstanceData, parameters, out);
renditionFileName,
parentPath);
re.render(formInstanceData, parameters, out);
out.close();
final NodeRef renditionNodeRef =
@@ -335,7 +336,8 @@ public final class FormsService
for (RenderingEngine re : form.getRenderingEngines())
{
final String renditionFileName =
this.stripExtension(formInstanceDataFileName) + "." + re.getFileExtension();
(this.stripExtension(formInstanceDataFileName) + "." +
re.getFileExtensionForRendition());
if (LOGGER.isDebugEnabled())
LOGGER.debug("regenerating file node for : " + formInstanceDataFileName +
@@ -354,13 +356,12 @@ public final class FormsService
out = this.avmService.createFile(parentPath, renditionFileName);
}
final OutputStreamWriter writer = new OutputStreamWriter(out);
final HashMap<String, String> parameters =
this.getRenderingEngineParameters(formInstanceDataFileName,
renditionFileName,
parentPath);
re.generate(formInstanceData, parameters, writer);
writer.close();
re.render(formInstanceData, parameters, out);
out.close();
LOGGER.debug("generated " + renditionFileName + " using " + re);
}

View File

@@ -56,14 +56,14 @@ public class FreeMarkerRenderingEngine
}
/**
* Generates the rendition using the configured freemarker template. This
* Renders the rendition using the configured freemarker template. This
* provides a root map to the freemarker template which places the xml document, and
* a variable named alfresco at the root. the alfresco variable contains a hash of
* all parameters and all extension functions.
*/
public void generate(final Document xmlContent,
final Map<String, String> parameters,
final Writer out)
public void render(final Document xmlContent,
final Map<String, String> parameters,
final OutputStream out)
throws IOException,
RenderingEngine.RenderingException
{
@@ -200,9 +200,10 @@ public class FreeMarkerRenderingEngine
};
// process the form
final Writer writer = new OutputStreamWriter(out);
try
{
t.process(rootModel, out);
t.process(rootModel, writer);
}
catch (final TemplateException te)
{
@@ -211,7 +212,7 @@ public class FreeMarkerRenderingEngine
}
finally
{
out.flush();
writer.flush();
}
}
}

View File

@@ -18,8 +18,8 @@ package org.alfresco.web.forms;
import org.alfresco.service.cmr.repository.NodeRef;
import java.io.IOException;
import java.io.OutputStream;
import java.io.Serializable;
import java.io.Writer;
import java.util.Map;
import org.w3c.dom.Document;
@@ -50,20 +50,25 @@ public interface RenderingEngine
/////////////////////////////////////////////////////////////////////////////
/** the noderef associated with this output method */
/**
* XXXarielb this shouldn't be in the interface... i'll figure out a
* different id scheme once i make rendering engines configurable.
*
* the noderef associated with this output method
*/
public NodeRef getNodeRef();
/**
* Serializes the xml data in to a presentation format.
* Renders the xml data in to a presentation format.
*
* @param xmlContent the xml content to serialize
* @param formInstanceData the xml content to serialize
* @param form the form that collected the xml content.
* @param sandBoxUrl the url of the current sandbox
* @param out the writer to serialize to.
* @param parameters the set of parameters to the rendering engine
* @param out the output stream to serialize to.
*/
public void generate(final Document xmlContent,
final Map<String, String> parameters,
final Writer out)
public void render(final Document formInstanceData,
final Map<String, String> parameters,
final OutputStream out)
throws IOException, RenderingException;
/**
@@ -71,7 +76,16 @@ public interface RenderingEngine
* output method.
*
* @return the file extension to use when generating content for this
* output method, such as html, rss, pdf.
* output method, such as html, xml, pdf.
*/
public String getFileExtension();
public String getFileExtensionForRendition();
/**
* Returns the mimetype to use when generating content for this
* output method.
*
* @return the mimetype to use when generating content for this
* output method, such as text/html, text/xml, application/pdf.
*/
public String getMimetypeForRendition();
}

View File

@@ -0,0 +1,93 @@
/*
* 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.
*/
package org.alfresco.web.forms;
import java.io.*;
import java.util.*;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.sax.SAXResult;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.w3c.dom.*;
import org.xml.sax.SAXException;
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.Fop;
import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.FopFactory;
import org.apache.fop.apps.FormattingResults;
import org.apache.fop.apps.MimeConstants;
import org.apache.fop.apps.PageSequenceResults;
/**
* A rendering engine which uses xsl-fo templates to generate renditions of
* form instance data.
*
* @author Ariel Backenroth
*/
public class XSLFORenderingEngine
extends XSLTRenderingEngine
{
private static final Log LOGGER = LogFactory.getLog(XSLFORenderingEngine.class);
public XSLFORenderingEngine(final NodeRef nodeRef,
final NodeService nodeService,
final ContentService contentService)
{
super(nodeRef, nodeService, contentService);
}
public void generate(final Document xmlContent,
final Map<String, String> parameters,
final OutputStream out)
throws IOException,
RenderingEngine.RenderingException
{
try
{
final FopFactory fopFactory = FopFactory.newInstance();
final FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
final Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out);
// Resulting SAX events (the generated FO) must be piped through to FOP
final Result result = new SAXResult(fop.getDefaultHandler());
super.render(new DOMSource(xmlContent), parameters, result);
// Result processing
FormattingResults foResults = fop.getResults();
java.util.List pageSequences = foResults.getPageSequences();
for (java.util.Iterator it = pageSequences.iterator(); it.hasNext();)
{
PageSequenceResults pageSequenceResults = (PageSequenceResults)it.next();
System.out.println("PageSequence "
+ (String.valueOf(pageSequenceResults.getID()).length() > 0
? pageSequenceResults.getID() : "<no id>")
+ " generated " + pageSequenceResults.getPageCount() + " pages.");
}
System.out.println("Generated " + foResults.getPageCount() + " pages in total.");
}
catch (FOPException fope)
{
}
}
}

View File

@@ -45,9 +45,9 @@ public class XFormsProcessor
* Generates html text which bootstraps the JavaScript code that will
* call back into the XFormsBean and get the xform and build the ui.
*/
public void generate(final InstanceData instanceData,
final Form tt,
final Writer out)
public void process(final InstanceData instanceData,
final Form tt,
final Writer out)
{
final FormsService ts = FormsService.getInstance();
final FacesContext fc = FacesContext.getCurrentInstance();