cancel
Showing results for 
Search instead for 
Did you mean: 

Alfresco Webscript/Freemarker and content-disposition

alexr
Champ in-the-making
Champ in-the-making
I have created a webscript that generates a text-file which is in fact a CSV file (delimited values), which serves as a "report" for the end-user.
When activating the Webscript URL a new browser tab is opened and the content of the text file is shown.

How can a SaveAs Excel file (test1.xls) be realized?   From what I gathered sofar is that it has to do with implementing content-disposition, but
I can't see where and how to apply this in the webscript/freemarker template structure of Alfresco 2.2 Enterprise.

Regards,

Alex
5 REPLIES 5

alexr
Champ in-the-making
Champ in-the-making
I think I am onto something.
When I add the following "xls" entry to web-scripts-application-context.xml  (should really change this to an extension).

  <!–  Default set of API Formats –>
   <bean id="webscripts.formats" parent="webscripts.formatmap">
      <property name="formats">
         <props>
            <prop key="html">text/html</prop>
            <prop key="text">text/plain</prop>
            <prop key="xml">text/xml</prop>
            <prop key="atom">application/atom+xml</prop>
            <prop key="rss">application/rss+xml</prop>
            <prop key="json">application/json</prop>
            <prop key="opensearchdescription">application/opensearchdescription+xml</prop>
            <prop key="mediawiki">text/plain</prop>
            <prop key="portlet">text/html</prop>
            <prop key="xls">application/msexcel</prop>
         </props>
      </property>
   </bean>

My template file has a name format like: reports.get.xls.ftl

And in the related .desc file I have the following entry:
<format default="xls">extension</format>

After restarting the appserver and clicking on the webscript URL, FireFox opens a box to ask me whether to save or search for an application.
When I point FireFox to use MS Excel, I can choose for FireFox to always use that application.

So this looks like it, but not quite. It's elaborate and although most of the times the end-user needs to "format"  the columns in excel, it should be possible
to have a SaveAs "export.xls" dialogbox.

Regards,

Alex

alexr
Champ in-the-making
Champ in-the-making
Got a slightly different mime-type definition and an entry in the "IE" section and it now works for IE to:

   <!–  Default set of API Formats –>
   <bean id="webscripts.formats" parent="webscripts.formatmap">
      <property name="formats">
         <props>
            <prop key="html">text/html</prop>
            <prop key="text">text/plain</prop>
            <prop key="xml">text/xml</prop>
            <prop key="atom">application/atom+xml</prop>
            <prop key="rss">application/rss+xml</prop>
            <prop key="json">application/json</prop>
            <prop key="opensearchdescription">application/opensearchdescription+xml</prop>
            <prop key="mediawiki">text/plain</prop>
            <prop key="portlet">text/html</prop>
       <prop key="xls">application/vnd.ms-excel</prop>
         </props>
      </property>
   </bean>

   <!–  IE Specific set of API Formats –>
   <bean id="webscripts.formats.IE" parent="webscripts.formatmap">
      <property name="agent"><value>MSIE</value></property>
      <property name="formats">
         <props>
            <prop key="atom">text/xml</prop>
            <prop key="rss">text/xml</prop>
            <prop key="opensearchdescription">text/xml</prop>
            <prop key="xls">application/vnd.ms-excel</prop>
         </props>
      </property>
   </bean>

If someone has a better solution please let me know.

Regards,

Alex

alexr
Champ in-the-making
Champ in-the-making
Issue:
A custom-web-scripts-application-context.xml in the alfresco.extension package is not used to override the original web-scripts-application-context.xml
Have seen a related JIRA issue entry from August 2008.

Regards,

Alex

ivo_costa
Champ in-the-making
Champ in-the-making
Hi

this looks like an interesting post Smiley Wink
thank you for this information, it will be usefull for me Smiley Happy

bhaskar
Champ in-the-making
Champ in-the-making
Hi Alxer,

Can u provide steps for getting .csv file format output.
actually i impled the webscript and ftl .