- terminology changes to wcmModel (needs to be propogated to java classes as well). template is now form. template output method is now form transformer.

- added an aspect to differentiate form derived from form transformer derived (allowed removing some workarounds from XSLTOutputMethod)

- namespacing variables passed to the xsl processor with alfresco:



git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@4154 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Ariel Backenroth
2006-10-18 19:01:45 +00:00
parent 2e3cbebd82
commit 1507f7387a
15 changed files with 122 additions and 111 deletions

View File

@@ -310,7 +310,7 @@ public class AVMEditBean
tx.commit();
// TODO: regenerate template content
if (nodeService.getProperty(avmRef, WCMModel.PROP_TEMPLATE_DERIVED_FROM) != null)
if (nodeService.getProperty(avmRef, WCMModel.PROP_FORM_DERIVED_FROM) != null)
{
OutputUtil.regenerate(avmRef,
this.contentService,

View File

@@ -166,7 +166,7 @@ public class CreateFormWizard extends BaseWizardBean
props = new HashMap<QName, Serializable>(1, 1.0f);
props.put(WCMModel.PROP_SCHEMA_ROOT_TAG_NAME, this.getSchemaRootTagName());
this.nodeService.addAspect(schemaNodeRef, WCMModel.ASPECT_TEMPLATE, props);
this.nodeService.addAspect(schemaNodeRef, WCMModel.ASPECT_FORM, props);
for (TemplateOutputMethodData tomd : this.templateOutputMethods)
{
@@ -189,13 +189,17 @@ public class CreateFormWizard extends BaseWizardBean
this.nodeService.createAssociation(schemaNodeRef,
templateOutputMethodNodeRef,
WCMModel.ASSOC_TEMPLATE_OUTPUT_METHODS);
WCMModel.ASSOC_FORM_TRANSFORMERS);
props = new HashMap<QName, Serializable>(3, 1.0f);
props.put(WCMModel.PROP_TEMPLATE_OUTPUT_METHOD_TYPE, tomd.getTemplateOutputMethodType().getName());
props.put(WCMModel.PROP_TEMPLATE_SOURCE, schemaNodeRef);
props.put(WCMModel.PROP_TEMPLATE_OUTPUT_METHOD_DERIVED_FILE_EXTENSION, tomd.getFileExtension());
this.nodeService.addAspect(templateOutputMethodNodeRef, WCMModel.ASPECT_TEMPLATE_OUTPUT_METHOD, props);
props.put(WCMModel.PROP_FORM_TRANSFORMER_TYPE,
tomd.getTemplateOutputMethodType().getName());
props.put(WCMModel.PROP_FORM_SOURCE, schemaNodeRef);
props.put(WCMModel.PROP_FORM_TRANSFORMER_DERIVED_FILE_EXTENSION,
tomd.getFileExtension());
this.nodeService.addAspect(templateOutputMethodNodeRef,
WCMModel.ASPECT_FORM_TRANSFORMER,
props);
}
// return the default outcome
return outcome;

View File

@@ -106,11 +106,11 @@ public class CreateWebContentWizard extends BaseContentWizard
final TemplateType tt = this.getTemplateType();
final TemplatingService ts = TemplatingService.getInstance();
final Map<QName, Serializable> props = new HashMap<QName, Serializable>();
props.put(WCMModel.PROP_TEMPLATE_DERIVED_FROM, tt.getNodeRef());
props.put(WCMModel.PROP_TEMPLATE_DERIVED_FROM_NAME, tt.getName());
final Map<QName, Serializable> props = new HashMap<QName, Serializable>(1, 1.0f);
props.put(WCMModel.PROP_FORM_DERIVED_FROM, tt.getNodeRef());
props.put(WCMModel.PROP_FORM_DERIVED_FROM_NAME, tt.getName());
this.nodeService.addAspect(AVMNodeConverter.ToNodeRef(-1, this.createdPath),
WCMModel.ASPECT_TEMPLATE_DERIVED,
WCMModel.ASPECT_FORM_DERIVED,
props);
OutputUtil.generate(this.createdPath.substring(0, this.createdPath.lastIndexOf('/')),

View File

@@ -1,30 +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.
*/
package org.alfresco.web.templating;
import org.w3c.dom.Document;
/**
* An abstraction layer around the xml content which allows
* for reseting the xml content being collected by the input method.
*/
public interface InstanceData
{
public Document getContent();
public void setContent(final Document d);
}

View File

@@ -83,10 +83,17 @@ public class OutputUtil
out.close();
NodeRef outputNodeRef = AVMNodeConverter.ToNodeRef(-1, fullAvmPath);
Map<QName, Serializable> props = new HashMap<QName, Serializable>();
props.put(WCMModel.PROP_TEMPLATE_DERIVED_FROM, tt.getNodeRef());
props.put(WCMModel.PROP_TEMPLATE_DERIVED_FROM_NAME, tt.getName());
nodeService.addAspect(outputNodeRef, WCMModel.ASPECT_TEMPLATE_DERIVED, props);
Map<QName, Serializable> props = new HashMap<QName, Serializable>(2, 1.0f);
props.put(WCMModel.PROP_FORM_DERIVED_FROM, tt.getNodeRef());
props.put(WCMModel.PROP_FORM_DERIVED_FROM_NAME, tt.getName());
nodeService.addAspect(outputNodeRef, WCMModel.ASPECT_FORM_DERIVED, props);
props = new HashMap<QName, Serializable>(2, 1.0f);
props.put(WCMModel.PROP_FORM_TRANSFORMER_DERIVED_FROM, tom.getNodeRef());
props.put(WCMModel.PROP_PRIMARY_FORM_DERIVED,
AVMNodeConverter.ToNodeRef(-1, parentPath + fileName));
nodeService.addAspect(outputNodeRef, WCMModel.ASPECT_FORM_TRANSFORMER_DERIVED, props);
props = new HashMap<QName, Serializable>(1, 1.0f);
props.put(ContentModel.PROP_TITLE, fileName);
@@ -113,7 +120,7 @@ public class OutputUtil
{
final TemplatingService ts = TemplatingService.getInstance();
final NodeRef templateTypeNodeRef = (NodeRef)
nodeService.getProperty(nodeRef, WCMModel.PROP_TEMPLATE_DERIVED_FROM);
nodeService.getProperty(nodeRef, WCMModel.PROP_FORM_DERIVED_FROM);
final TemplateType tt = ts.getTemplateType(templateTypeNodeRef);

View File

@@ -27,6 +27,21 @@ public interface TemplateInputMethod
extends Serializable
{
/////////////////////////////////////////////////////////////////////////////
/**
* An abstraction layer around the xml content which allows
* for reseting the xml content being collected by the input method.
*/
public interface InstanceData
{
public Document getContent();
public void setContent(final Document d);
}
/////////////////////////////////////////////////////////////////////////////
/**
* Generates a user interface for inputing data into this template.
*
@@ -34,7 +49,7 @@ public interface TemplateInputMethod
* @param tt the template type to generate for
* @param out the writer to write the output to.
*/
public void generate(final InstanceData instanceData,
public void generate(final TemplateInputMethod.InstanceData instanceData,
final TemplateType tt,
final Writer out);
}

View File

@@ -16,6 +16,7 @@
*/
package org.alfresco.web.templating;
import org.alfresco.service.cmr.repository.NodeRef;
import java.io.Serializable;
import java.io.Writer;
import java.util.Map;
@@ -27,6 +28,8 @@ import org.w3c.dom.Document;
public interface TemplateOutputMethod
extends Serializable
{
/** the noderef associated with this output method */
public NodeRef getNodeRef();
/**
* Serializes the xml data in to a presentation format.

View File

@@ -128,7 +128,7 @@ public final class TemplatingService implements Serializable
final SearchParameters sp = new SearchParameters();
sp.addStore(Repository.getStoreRef());
sp.setLanguage(SearchService.LANGUAGE_LUCENE);
sp.setQuery("ASPECT:\"" + WCMModel.ASPECT_TEMPLATE + "\"");
sp.setQuery("ASPECT:\"" + WCMModel.ASPECT_FORM + "\"");
LOGGER.debug("running query [" + sp.getQuery() + "]");
final ResultSet rs = this.searchService.query(sp);
LOGGER.debug("received " + rs.length() + " results");
@@ -155,7 +155,7 @@ public final class TemplatingService implements Serializable
final SearchParameters sp = new SearchParameters();
sp.addStore(Repository.getStoreRef());
sp.setLanguage(SearchService.LANGUAGE_LUCENE);
sp.setQuery("ASPECT:\"" + WCMModel.ASPECT_TEMPLATE +
sp.setQuery("ASPECT:\"" + WCMModel.ASPECT_FORM +
"\" AND @" + Repository.escapeQName(ContentModel.PROP_TITLE) +
":\"" + name + "\"");
LOGGER.debug("running query [" + sp.getQuery() + "]");
@@ -203,14 +203,14 @@ public final class TemplatingService implements Serializable
LOGGER.debug("root tag name is " + schemaRootTagName);
final TemplateType tt = new TemplateTypeImpl(title, schemaNodeRef, schemaRootTagName);
for (AssociationRef assoc : this.nodeService.getTargetAssocs(schemaNodeRef,
WCMModel.ASSOC_TEMPLATE_OUTPUT_METHODS))
WCMModel.ASSOC_FORM_TRANSFORMERS))
{
final NodeRef tomNodeRef = assoc.getTargetRef();
try
{
final Class templateOutputMethodType =
Class.forName((String)this.nodeService.getProperty(tomNodeRef,
WCMModel.PROP_TEMPLATE_OUTPUT_METHOD_TYPE));
WCMModel.PROP_FORM_TRANSFORMER_TYPE));
final Constructor c = templateOutputMethodType.getConstructor(NodeRef.class, NodeService.class, ContentService.class);
final TemplateOutputMethod tom = (TemplateOutputMethod)

View File

@@ -78,47 +78,41 @@ public class ExtensionFunctions
AVMNodeDescriptor entryNode = entry.getValue();
if (entryNode.isFile())
{
final PropertyValue pv =
PropertyValue pv =
this.avmRemote.getNodeProperty(-1,
avmPath + '/' + entryName,
WCMModel.PROP_TEMPLATE_DERIVED_FROM_NAME);
if (pv != null &&
pv.getStringValue() != null &&
((String)pv.getStringValue()).equals(templateTypeName))
WCMModel.PROP_FORM_DERIVED_FROM_NAME);
if (pv == null ||
pv.getStringValue() == null ||
!((String)pv.getStringValue()).equals(templateTypeName))
{
// it's not generated by the same template type
continue;
}
InputStream istream = null;
try
pv = this.avmRemote.getNodeProperty(-1,
avmPath + '/' + entryName,
WCMModel.PROP_FORM_TRANSFORMER_DERIVED_FROM);
if (pv != null)
{
istream = new AVMRemoteInputStream(this.avmRemote.getInputHandle(-1, avmPath + '/' + entryName),
// it's generated by a transformer (not the xml file)
continue;
}
final InputStream istream =
new AVMRemoteInputStream(this.avmRemote.getInputHandle(-1, avmPath + '/' + entryName),
this.avmRemote);
}
catch (AVMNotFoundException avmnfe)
{
// this is most likely happening because this is the current file we're generating
// and the avm is telling us that it has no content yet. we won't hit this once
// we have a way of distinguishing templateoutputmethodgenerated
// from templategenerated
LOGGER.debug("skipping "+ entryName, avmnfe);
}
try
{
result.put(entryName, db.parse(istream));
}
catch (SAXException sax)
{
// this is most likely happening because we have the same property for defined
// for tempalteoutputmethodderived and templatederived so we can't distinguish them right now
// need to clean this up
LOGGER.debug("error parsing " + entryName+ "... skipping", sax);
}
finally
{
istream.close();
}
}
}
}
return result;
}

View File

@@ -52,6 +52,11 @@ public class FreeMarkerOutputMethod
this.contentService = contentService;
}
public NodeRef getNodeRef()
{
return this.nodeRef;
}
public void generate(final Document xmlContent,
final TemplateType tt,
final Map<String, String> parameters,
@@ -76,6 +81,6 @@ public class FreeMarkerOutputMethod
{
return (String)
this.nodeService.getProperty(this.nodeRef,
WCMModel.PROP_TEMPLATE_OUTPUT_METHOD_DERIVED_FILE_EXTENSION);
WCMModel.PROP_FORM_TRANSFORMER_DERIVED_FILE_EXTENSION);
}
}

View File

@@ -60,7 +60,7 @@ public class XFormsBean
private static final Log LOGGER = LogFactory.getLog(XFormsBean.class);
private TemplateType tt;
private InstanceData instanceData = null;
private TemplateInputMethod.InstanceData instanceData = null;
private ChibaBean chibaBean;
private final LinkedList<XFormsEvent> eventLog = new LinkedList<XFormsEvent>();
@@ -77,7 +77,7 @@ public class XFormsBean
}
/** @param instanceData the instance data being modified. */
public void setInstanceData(final InstanceData instanceData)
public void setInstanceData(final TemplateInputMethod.InstanceData instanceData)
{
this.instanceData = instanceData;
}

View File

@@ -54,6 +54,7 @@ import org.xml.sax.SAXException;
public class XSLTOutputMethod
implements TemplateOutputMethod
{
//XXXarielb these should go into a more common location
private static final String ALFRESCO_NS = "http://www.alfresco.org/alfresco";
private static final String ALFRESCO_NS_PREFIX = "alfresco";
@@ -70,6 +71,11 @@ public class XSLTOutputMethod
this.nodeService = nodeService;
}
public NodeRef getNodeRef()
{
return this.nodeRef;
}
//XXXarielb this is totally dirty - need to figure a better way to do this
private static AVMRemote getAVMRemote()
{
@@ -88,7 +94,7 @@ public class XSLTOutputMethod
private static String toAVMPath(final ExpressionContext ec, String path)
throws TransformerException
{
final XObject o = ec.getVariableOrParam(new QName("parent_path"));
final XObject o = ec.getVariableOrParam(new QName(ALFRESCO_NS, ALFRESCO_NS_PREFIX, "parent_path"));
if (o == null)
return null;
String avmPath = o.toString();
@@ -111,6 +117,15 @@ public class XSLTOutputMethod
return ef.getXMLDocument(XSLTOutputMethod.toAVMPath(ec, path));
}
public static NodeIterator getXMLDocuments(final ExpressionContext ec,
final String templateTypeName)
throws TransformerException,
IOException,
SAXException
{
return XSLTOutputMethod.getXMLDocuments(ec, templateTypeName, "");
}
public static NodeIterator getXMLDocuments(final ExpressionContext ec,
final String templateTypeName,
String path)
@@ -228,7 +243,7 @@ public class XSLTOutputMethod
for (Map.Entry<String, String> e : parameters.entrySet())
{
final Element el = xslDocument.createElementNS(XSL_NS, XSL_NS_PREFIX + ":variable");
el.setAttribute("name", e.getKey());
el.setAttribute("name", ALFRESCO_NS_PREFIX + ':' + e.getKey());
el.appendChild(xslDocument.createTextNode(e.getValue()));
docEl.insertBefore(el, docEl.getFirstChild());
}
@@ -300,6 +315,6 @@ public class XSLTOutputMethod
{
return (String)
this.nodeService.getProperty(this.nodeRef,
WCMModel.PROP_TEMPLATE_OUTPUT_METHOD_DERIVED_FILE_EXTENSION);
WCMModel.PROP_FORM_TRANSFORMER_DERIVED_FILE_EXTENSION);
}
}

View File

@@ -9,8 +9,6 @@
doctype-system="http://www.w3.org/TR/html4/loose.dtd"/>
<xsl:preserve-space elements="*"/>
<xsl:variable name="my_variable">my_variable has a value</xsl:variable>
<xsl:variable name="my_variable_as_arg">my_variable_as_arg has a value</xsl:variable>
<xsl:template match="/">
<html>
<head>
@@ -36,11 +34,11 @@ body
<div>Generated by output-method-callout.xsl</div>
<div class="name">My value accessed using /simple/string:</div>
<span><xsl:value-of select="/simple/string"/></span>
<div class="name">My value accessed using alfresco:getXMLDocument(<xsl:value-of select="$derived_from_file_name"/>):</div>
<span><xsl:value-of select="alfresco:getXMLDocument($derived_from_file_name)/simple/string"/></span>
<div class="name">Values from xml files generated by in <xsl:value-of select="$parent_path"/>:</div>
<div class="name">My value accessed using alfresco:getXMLDocument(<xsl:value-of select="$alfresco:derived_from_file_name"/>):</div>
<span><xsl:value-of select="alfresco:getXMLDocument($alfresco:derived_from_file_name)/simple/string"/></span>
<div class="name">Values from xml files generated by in <xsl:value-of select="$alfresco:parent_path"/>:</div>
<ul>
<xsl:for-each select="alfresco:getXMLDocuments('output-method-callout', '')/simple">
<xsl:for-each select="alfresco:getXMLDocuments('output-method-callout')/simple">
<li><xsl:value-of select="@alfresco:file-name"/> = <xsl:value-of select="string"/></li>
</xsl:for-each>
</ul>

View File

@@ -37,7 +37,7 @@ final CreateWebContentWizard wiz = (CreateWebContentWizard)
TemplateType tt = wiz.getTemplateType();
TemplateInputMethod tim = tt.getInputMethods().get(0);
final TemplatingService ts = TemplatingService.getInstance();
final InstanceData instanceData = new InstanceData()
final TemplateInputMethod.InstanceData instanceData = new TemplateInputMethod.InstanceData()
{
public Document getContent()
{

View File

@@ -36,11 +36,11 @@
final AVMBrowseBean browseBean = (AVMBrowseBean)session.getAttribute("AVMBrowseBean");
NodeRef nr = browseBean.getAvmActionNode().getNodeRef();
final AVMEditBean editBean = (AVMEditBean)session.getAttribute("AVMEditBean");
final NodeRef ttNodeRef = (NodeRef)browseBean.getNodeService().getProperty(nr, WCMModel.PROP_TEMPLATE_DERIVED_FROM);
final NodeRef ttNodeRef = (NodeRef)browseBean.getNodeService().getProperty(nr, WCMModel.PROP_FORM_DERIVED_FROM);
final TemplatingService ts = TemplatingService.getInstance();
final TemplateType tt = ts.getTemplateType(ttNodeRef);
TemplateInputMethod tim = tt.getInputMethods().get(0);
final InstanceData instanceData = new InstanceData()
final TemplateInputMethod.InstanceData instanceData = new TemplateInputMethod.InstanceData()
{
public Document getContent()
{
@@ -62,7 +62,7 @@ final InstanceData instanceData = new InstanceData()
};
%>
<r:page titleId="title_edit_text_inline">
<r:page titleId="title_edit_xml_inline">
<script type="text/javascript">
function _xforms_getSubmitButtons()
{