cancel
Showing results for 
Search instead for 
Did you mean: 

webscripts and wcm

jego
Star Contributor
Star Contributor
Hello,

I want to use a webscript to deliver created content of several web forms. My approach was to adapt the freemarker template which is delivered with the blog-article example (http://community.alfresco.com/alfresco/n/browse/workspace/SpacesStore/a6d453bc-6878-11dd-ac51-d1d10f...)

I have following web script:

Web Script: org/alfresco/sample/blog-article.get
Alfresco Enterprise Network v2.2.0 (159)
Generated from /alfresco/service/script/org/alfresco/sample/blog-article.get on Aug 21, 2008 1:55:52 PM

Script Properties
Id:   org/alfresco/sample/blog-article.get
Short Name:   Blog Article data
Description:   
Authentication:   admin
Transaction:   required
Method:   GET
URL Template:   /sample/blog/article
Format Style:   extension
Default Format:   html
Implementation:   class org.alfresco.web.scripts.DeclarativeWebScript

Store: workspace://SpacesStore/app:company_home/app:dictionary/cm:extensionwebscripts

[No implementation files]

Store: workspace://SpacesStore/app:company_home/app:dictionary/cm:webscripts

File: org/alfresco/sample/blog-article.get.desc.xml

<webscript>
  <shortname>Blog Article data</shortname>
  <description></description>
   <url>/sample/blog/article</url>
   <format default="html">extension</format>
   <authentication>admin</authentication>
   <transaction>required</transaction>
</webscript>

File: org/alfresco/sample/blog-article.get.html.ftl

<#assign docs = alf.parseXMLDocuments('blog-article', '/')>
<#list docs as x>
<blog>
<title>${x.title}</title>
<abstract>${x.abstract}</abstract>
<body>${x.body}</body>
</blog>
</#list>
 

Store: classpath:/alfresco/templates/webscripts

[No implementation files]

———————————————–

The problem is that the variable alf is not injected in this context, so by calling the webscript following error occurs:

Error during processing of the template 'Expression alf is undefined on line 1, column 17 in org/alfresco/sample/blog-article.get.html.ftl.'. Please contact your system administrator.

Exception:   freemarker.core.InvalidReferenceException - Expression alf is undefined on line 1, column 17 in org/alfresco/sample/blog-article.get.html.ftl.
   
   freemarker.core.TemplateObject.assertNonNull(TemplateObject.java:124)
   freemarker.core.TemplateObject.invalidTypeException(TemplateObject.java:134)
   freemarker.core.Dot._getAsTemplateModel(Dot.java:78)
   freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
   freemarker.core.MethodCall._getAsTemplateModel(MethodCall.java:86)
   freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
   freemarker.core.Assignment.accept(Assignment.java:90)
   freemarker.core.Environment.visit(Environment.java:196)
   freemarker.core.MixedContent.accept(MixedContent.java:92)
   freemarker.core.Environment.visit(Environment.java:196)
   freemarker.core.Environment.process(Environment.java:176)
   freemarker.template.Template.process(Template.java:232)
   org.alfresco.repo.template.FreeMarkerProcessor.process(FreeMarkerProcessor.java:201)
   org.alfresco.web.scripts.AbstractWebScript.renderTemplate(AbstractWebScript.java:406)
   org.alfresco.web.scripts.DeclarativeWebScript.renderFormatTemplate(DeclarativeWebScript.java:268)
   org.alfresco.web.scripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:174)
   org.alfresco.web.scripts.WebScriptRuntime.wrappedExecute(WebScriptRuntime.java:364)
   org.alfresco.web.scripts.WebScriptRuntime$1.execute(WebScriptRuntime.java:330)
   org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:241)
   org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:171)
   org.alfresco.web.scripts.WebScriptRuntime.transactionedExecute(WebScriptRuntime.java:341)
   org.alfresco.web.scripts.WebScriptRuntime.authenticatedExecute(WebScriptRuntime.java:284)
   org.alfresco.web.scripts.WebScriptRuntime.executeScript(WebScriptRuntime.java:150)
   org.alfresco.web.scripts.WebScriptServlet.service(WebScriptServlet.java:109)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
   org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
   org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
   org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
   org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
   org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
   org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
   org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
   org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
   org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
   org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
   org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
   java.lang.Thread.run(Thread.java:619)
   
Exception:   org.alfresco.service.cmr.repository.TemplateException - Error during processing of the template 'Expression alf is undefined on line 1, column 17 in org/alfresco/sample/blog-article.get.html.ftl.'. Please contact your system administrator.
   
   org.alfresco.repo.template.FreeMarkerProcessor.process(FreeMarkerProcessor.java:205)


Any idea how I can get access to the function parseXMLDocuments?

Thanks,
Jens
1 REPLY 1

zaizi
Champ in-the-making
Champ in-the-making
The alf object is only injected into freemarker and xslt during form rendering. It is not available within the web script context AFIK. To parse XML files from within web scripts take a look at this thread: http://forums.alfresco.com/en/viewtopic.php?f=36&t=12067.
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.