- changing terminology from root tag name to root element name

- fixing form data functions calls with absolute paths - making them webapp relative - and adding test cases

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@4218 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Ariel Backenroth
2006-10-24 23:40:05 +00:00
parent 3d6221f39e
commit 5b6772ac2c
10 changed files with 99 additions and 40 deletions

View File

@@ -651,10 +651,11 @@ create_form_step2_desc=This is the generated XForm based on the schema provided.
selected_rendering_engines=Selected Rendering Engines selected_rendering_engines=Selected Rendering Engines
configure_rendering_engines_step1_desc=Upload rendering engine template and specify the extension to use for its generated assets. configure_rendering_engines_step1_desc=Upload rendering engine template and specify the extension to use for its generated assets.
rendering_engine_file=Rendering Engine Template File rendering_engine_file=Rendering Engine Template File
rendering_engine_type=Rendering Engine Type
extension_for_generated_assets=Extension For Generated Assets extension_for_generated_assets=Extension For Generated Assets
file_extension=Extension file_extension=Extension
schema=Schema schema=Schema
schema_root_tag_name=Root Tag schema_root_element_name=Root Element
edit_xml_schema=Edit XML Schema edit_xml_schema=Edit XML Schema
form=Form form=Form
configure_rendering_engines=Configure Rendering Engines configure_rendering_engines=Configure Rendering Engines

View File

@@ -113,7 +113,7 @@ public class CreateFormWizard extends BaseWizardBean
private final static Log LOGGER = LogFactory.getLog(CreateFormWizard.class); private final static Log LOGGER = LogFactory.getLog(CreateFormWizard.class);
private String schemaRootTagName; private String schemaRootElementName;
private String formName; private String formName;
private String formDescription; private String formDescription;
private Class renderingEngineType = null; private Class renderingEngineType = null;
@@ -163,7 +163,7 @@ public class CreateFormWizard extends BaseWizardBean
this.nodeService.addAspect(schemaNodeRef, 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_ELEMENT_NAME, this.getSchemaRootElementName());
this.nodeService.addAspect(schemaNodeRef, WCMModel.ASPECT_FORM, props); this.nodeService.addAspect(schemaNodeRef, WCMModel.ASPECT_FORM, props);
for (RenderingEngineData tomd : this.renderingEngines) for (RenderingEngineData tomd : this.renderingEngines)
@@ -210,7 +210,7 @@ public class CreateFormWizard extends BaseWizardBean
this.removeUploadedSchemaFile(); this.removeUploadedSchemaFile();
this.removeUploadedRenderingEngineFile(); this.removeUploadedRenderingEngineFile();
this.schemaRootTagName = null; this.schemaRootElementName = null;
this.formName = null; this.formName = null;
this.formDescription = null; this.formDescription = null;
this.renderingEngineType = null; this.renderingEngineType = null;
@@ -473,26 +473,26 @@ public class CreateFormWizard extends BaseWizardBean
} }
/** /**
* Sets the root tag name to use when processing the schema. * Sets the root element name to use when processing the schema.
*/ */
public void setSchemaRootTagName(final String schemaRootTagName) public void setSchemaRootElementName(final String schemaRootElementName)
{ {
this.schemaRootTagName = schemaRootTagName; this.schemaRootElementName = schemaRootElementName;
} }
/** /**
* Returns the root tag name to use when processing the schema. * Returns the root element name to use when processing the schema.
*/ */
public String getSchemaRootTagName() public String getSchemaRootElementName()
{ {
return this.schemaRootTagName; return this.schemaRootElementName;
} }
/** /**
* @return the possible root tag names for use with the schema based on * @return the possible root element names for use with the schema based on
* the element declarations it defines. * the element declarations it defines.
*/ */
public List<SelectItem> getSchemaRootTagNameChoices() public List<SelectItem> getSchemaRootElementNameChoices()
{ {
final List<SelectItem> result = new LinkedList<SelectItem>(); final List<SelectItem> result = new LinkedList<SelectItem>();
if (this.getSchemaFile() != null) if (this.getSchemaFile() != null)

View File

@@ -16,6 +16,8 @@
*/ */
package org.alfresco.web.forms; package org.alfresco.web.forms;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.faces.context.FacesContext; import javax.faces.context.FacesContext;
import org.alfresco.model.WCMModel; import org.alfresco.model.WCMModel;
import org.alfresco.repo.avm.AVMRemote; import org.alfresco.repo.avm.AVMRemote;
@@ -91,17 +93,23 @@ public abstract class AbstractRenderingEngine
return parentAVMPath; return parentAVMPath;
} }
if (path.charAt(0) == '/') if (path.charAt(0) == '/')
{ {
//XXXarielb this doesn't work with context paths for the website final Pattern p = Pattern.compile("([^:]+:/" + AVMConstants.DIR_APPBASE +
parent = parentAVMPath.substring(0, "/[^/]+/[^/]+).*");
parentAVMPath.indexOf(':') + final Matcher m = p.matcher(parentAVMPath);
('/' + AVMConstants.DIR_APPBASE + if (m.matches())
'/' + AVMConstants.DIR_WEBAPPS).length()); {
parent = m.group(1);
}
}
else if (parentAVMPath.charAt(parentAVMPath.length() - 1) != '/')
{
parent = parent + '/';
} }
final String result = final String result = parent + path;
parent + (parent.endsWith("/") || path.startsWith("/") ? path : '/' + path);
LOGGER.debug("built full avmPath " + result + LOGGER.debug("built full avmPath " + result +
" for parent " + parentAVMPath + " for parent " + parentAVMPath +
" and request path " + path); " and request path " + path);

View File

@@ -221,7 +221,7 @@ public final class FormsService
this.nodeService.getProperty(schemaNodeRef, ContentModel.PROP_TITLE); this.nodeService.getProperty(schemaNodeRef, ContentModel.PROP_TITLE);
LOGGER.debug("title is " + title); LOGGER.debug("title is " + title);
final String schemaRootTagName = (String) final String schemaRootTagName = (String)
this.nodeService.getProperty(schemaNodeRef, WCMModel.PROP_SCHEMA_ROOT_TAG_NAME); this.nodeService.getProperty(schemaNodeRef, WCMModel.PROP_SCHEMA_ROOT_ELEMENT_NAME);
LOGGER.debug("root tag name is " + schemaRootTagName); LOGGER.debug("root tag name is " + schemaRootTagName);
final Form tt = new FormImpl(title, schemaNodeRef, schemaRootTagName); final Form tt = new FormImpl(title, schemaNodeRef, schemaRootTagName);
for (AssociationRef assoc : this.nodeService.getTargetAssocs(schemaNodeRef, for (AssociationRef assoc : this.nodeService.getTargetAssocs(schemaNodeRef,

View File

@@ -79,7 +79,9 @@ public class FreeMarkerRenderingEngine
final TemplateHashModel instanceDataModel = NodeModel.wrap(xmlContent); final TemplateHashModel instanceDataModel = NodeModel.wrap(xmlContent);
// build models for each of the extension functions // build models for each of the extension functions
final TemplateModel parseXMLDocumentModel = new TemplateMethodModel() final HashMap<String, TemplateMethodModel> methodModels =
new HashMap<String, TemplateMethodModel>(3, 1.0f);
methodModels.put("parseXMLDocument", new TemplateMethodModel()
{ {
public Object exec(final List args) public Object exec(final List args)
throws TemplateModelException throws TemplateModelException
@@ -97,8 +99,9 @@ public class FreeMarkerRenderingEngine
throw new TemplateModelException(e); throw new TemplateModelException(e);
} }
} }
}; });
final TemplateModel parseXMLDocumentsModel = new TemplateMethodModel()
methodModels.put("parseXMLDocuments", new TemplateMethodModel()
{ {
public Object exec(final List args) public Object exec(final List args)
throws TemplateModelException throws TemplateModelException
@@ -143,24 +146,37 @@ public class FreeMarkerRenderingEngine
throw new TemplateModelException(e); throw new TemplateModelException(e);
} }
} }
}; });
// for debugging
methodModels.put("_getAVMPath", new TemplateMethodModel()
{
public Object exec(final List args)
throws TemplateModelException
{
try
{
return FreeMarkerRenderingEngine.toAVMPath(parameters.get("parent_path"),
(String)args.get(0));
}
catch (Exception e)
{
throw new TemplateModelException(e);
}
}
});
// build a wrapper for the parameters. this also wraps the extension functions // build a wrapper for the parameters. this also wraps the extension functions
// so they appear in the namespace alfresco. // so they appear in the namespace alfresco.
final TemplateHashModel parameterModel = new SimpleHash(parameters) final TemplateHashModel parameterModel = new SimpleHash(parameters)
{ {
public TemplateModel get(final String key) public TemplateModel get(final String key)
throws TemplateModelException throws TemplateModelException
{ {
if ("parseXMLDocument".equals(key)) return (methodModels.containsKey(key)
{ ? methodModels.get(key)
return parseXMLDocumentModel; : super.get(key));
}
if ("parseXMLDocuments".equals(key))
{
return parseXMLDocumentsModel;
}
return super.get(key);
} }
}; };
@@ -172,7 +188,9 @@ public class FreeMarkerRenderingEngine
public TemplateModel get(final String key) public TemplateModel get(final String key)
throws TemplateModelException throws TemplateModelException
{ {
return ALFRESCO_NS_PREFIX.equals(key) ? parameterModel : instanceDataModel.get(key); return (ALFRESCO_NS_PREFIX.equals(key)
? parameterModel
: instanceDataModel.get(key));
} }
public boolean isEmpty() public boolean isEmpty()

View File

@@ -194,6 +194,17 @@ public class XSLTRenderingEngine
}; };
} }
// for debugging
public static String _getAVMPath(final ExpressionContext ec,
final String path)
throws TransformerException,
IOException,
SAXException
{
final FormDataFunctions ef = XSLTRenderingEngine.getFormDataFunctions();
return XSLTRenderingEngine.toAVMPath(ec, path);
}
private void addScript(final Document d) private void addScript(final Document d)
{ {
final Element docEl = d.getDocumentElement(); final Element docEl = d.getDocumentElement();

View File

@@ -37,6 +37,12 @@
<div class="name"><#noparse>${alfresco.request_context_path}</#noparse></div> <div class="name"><#noparse>${alfresco.request_context_path}</#noparse></div>
<span>${alfresco.request_context_path}</span> <span>${alfresco.request_context_path}</span>
<div class="name"><#noparse>${alfresco._getAVMPath('foo')}</#noparse></div>
<span>${alfresco._getAVMPath('foo')}</span>
<div class="name"><#noparse>${alfresco._getAVMPath('/foo')}</#noparse></div>
<span>${alfresco._getAVMPath('/foo')}</span>
<div class="name">My value accessed using <#noparse>${simple.string}</#noparse>:</div> <div class="name">My value accessed using <#noparse>${simple.string}</#noparse>:</div>
<span>${simple.string}</span> <span>${simple.string}</span>

View File

@@ -32,27 +32,42 @@ body
</head> </head>
<body> <body>
<div>Generated by output-method-callout.xsl</div> <div>Generated by output-method-callout.xsl</div>
<div class="name"> <div class="name">
&lt;xsl:value-of select="$alfresco:avm_sandbox_url"/&gt; &lt;xsl:value-of select="$alfresco:avm_sandbox_url"/&gt;
</div> </div>
<span><xsl:value-of select="$alfresco:avm_sandbox_url"/></span> <span><xsl:value-of select="$alfresco:avm_sandbox_url"/></span>
<div class="name"> <div class="name">
&lt;xsl:value-of select="$alfresco:form_instance_data_file_name"/&gt; &lt;xsl:value-of select="$alfresco:form_instance_data_file_name"/&gt;
</div> </div>
<span><xsl:value-of select="$alfresco:form_instance_data_file_name"/></span> <span><xsl:value-of select="$alfresco:form_instance_data_file_name"/></span>
<div class="name"> <div class="name">
&lt;xsl:value-of select="$alfresco:rendition_file_name"/&gt; &lt;xsl:value-of select="$alfresco:rendition_file_name"/&gt;
</div> </div>
<span><xsl:value-of select="$alfresco:rendition_file_name"/></span> <span><xsl:value-of select="$alfresco:rendition_file_name"/></span>
<div class="name"> <div class="name">
&lt;xsl:value-of select="$alfresco:parent_path"/&gt; &lt;xsl:value-of select="$alfresco:parent_path"/&gt;
</div> </div>
<span><xsl:value-of select="$alfresco:parent_path"/></span> <span><xsl:value-of select="$alfresco:parent_path"/></span>
<div class="name"> <div class="name">
&lt;xsl:value-of select="$alfresco:request_context_path"/&gt; &lt;xsl:value-of select="$alfresco:request_context_path"/&gt;
</div> </div>
<span><xsl:value-of select="$alfresco:request_context_path"/></span> <span><xsl:value-of select="$alfresco:request_context_path"/></span>
<div class="name">
&lt;xsl:value-of select="alfresco:_getAVMPath('foo')"/&gt;
</div>
<span><xsl:value-of select="alfresco:_getAVMPath('foo')"/></span>
<div class="name">
&lt;xsl:value-of select="alfresco:_getAVMPath('/foo')"/&gt;
</div>
<span><xsl:value-of select="alfresco:_getAVMPath('/foo')"/></span>
<div class="name">My value accessed using /simple/string:</div> <div class="name">My value accessed using /simple/string:</div>
<span><xsl:value-of select="/simple/string"/></span> <span><xsl:value-of select="/simple/string"/></span>
<div class="name">My value accessed using alfresco:parseXMLDocument($alfresco:form_instance_data_file_name):</div> <div class="name">My value accessed using alfresco:parseXMLDocument($alfresco:form_instance_data_file_name):</div>

View File

@@ -77,7 +77,7 @@ else
<h:graphicImage id="required-image-rendering-engine-type" <h:graphicImage id="required-image-rendering-engine-type"
value="/images/icons/required_field.gif" alt="Required Field" /> value="/images/icons/required_field.gif" alt="Required Field" />
<h:outputText id="rendering-engine-type-output-text" <h:outputText id="rendering-engine-type-output-text"
value="#{msg.type}:"/> value="#{msg.rendering_engine_type}:"/>
<h:selectOneRadio id="rendering-engine-type" <h:selectOneRadio id="rendering-engine-type"
value="#{WizardManager.bean.renderingEngineType}"> value="#{WizardManager.bean.renderingEngineType}">
<f:selectItems id="rendering-engine-type-choices" <f:selectItems id="rendering-engine-type-choices"

View File

@@ -96,12 +96,12 @@ if (upload == null || upload.getFile() == null)
%> %>
</h:column> </h:column>
<h:graphicImage id="graphic_image_root_tag_name" <h:graphicImage id="graphic_image_root_element_name"
value="/images/icons/required_field.gif" alt="Required Field" /> value="/images/icons/required_field.gif" alt="Required Field" />
<h:outputText id="output_text_root_tag_name" value="#{msg.schema_root_tag_name}:"/> <h:outputText id="output_text_root_element_name" value="#{msg.schema_root_element_name}:"/>
<h:selectOneMenu id="schema-root-tag-name" <h:selectOneMenu id="schema-root-element-name"
value="#{WizardManager.bean.schemaRootTagName}"> value="#{WizardManager.bean.schemaRootElementName}">
<f:selectItems value="#{WizardManager.bean.schemaRootTagNameChoices}"/> <f:selectItems value="#{WizardManager.bean.schemaRootElementNameChoices}"/>
</h:selectOneMenu> </h:selectOneMenu>
<h:graphicImage id="graphic_image_name" value="/images/icons/required_field.gif" alt="Required Field" /> <h:graphicImage id="graphic_image_name" value="/images/icons/required_field.gif" alt="Required Field" />