Robby Pelssers <Robby.Pelssers <at> nxp.com> writes:
>
>
> Hi guys,
>
> Just wanted to know if the issue in below thread has ever been fixed.
>
> http://web.archiveorange.com/archive/v/uRmkWnxszXP6g7Xuw33H
>
> To shortly describe the use case:
>
> http://cocoon.apache.org/2.1/userdocs/ziparchive-serializer.html
>
> The zipserializer only allows either:
> - You specify a <at> src pointing to some cocoon pipeline using
cocoon:// (Ideally it would also support the servlet: protocol as now I have
to provide a façade in the calling cocoon block)
> - You specify inline content and the <at> serializer
>
> In a ideal world you should be able to use <at> src in combination with the
<at> serializer because now I have to first include the content from a pipeline
by using <cinclude> before calling
> <map:serialize type=”zip”/>
>
>
>
> I actually created some nice generic functionality to work around some issues:
>
>
> ************************ FLOWSCRIPT ***************************************
> function downloadImdsZip() {
> var entries = [];
> new
Collection(cocoon.request.getParameterValues("id")).forEach(function(id){
> var entry = {"name": id + ".xml", "source":
"cocoon://chemicalcontent/imds/" + id + ".xml", "serializer": "upload"};
> print('Adding entry [name=' + entry.name + ', source=' +
entry.source + '] to ZIP archive.');
> entries.push(entry);
> });
> var response = cocoon.response;
> response.setHeader(
> "Content-Disposition",
> "attachment; filename=imds.zip"
> );
> cocoon.sendPage("zipArchive", {"entries": entries});
> }
>
> *************************************************************************
> <?xml version="1.0" encoding="UTF-8"?>
> <jx:template
> xmlns:jx="http://apache.org/cocoon/templates/jx/1.0"
> xmlns:zip="http://apache.org/cocoon/zip-archive/1.0"
> xmlns:cinclude="http://apache.org/cocoon/include/1.0">
> <!--
> This jx expects an array called 'entries' containing objects with
> following
properties:
> * name (mandatory)
> * source (mandatory)
> * serializer (optional)
> *
> * If both source and serializer are provided, we assume that we want to
include the content inline so we can specify the serializer
> -->
> <zip:archive>
> <jx:forEach var="entry" items="${entries}">
> <zip:entry name="${entry.name}">
> <jx:choose>
> <jx:when test="${entry.serializer != null}">
> <jx:attribute name="serializer" value="${entry.serializer}"/>
> <cinclude:include src="${entry.source}"/>
> </jx:when>
> <jx:otherwise>
> <jx:attribute name="src" value="${entry.source}"/>
> </jx:otherwise>
> </jx:choose>
> </zip:entry>
> </jx:forEach>
> </zip:archive>
> </jx:template>
> *************************************************************************
> <map:match pattern="zipArchive">
> <map:generate src="jx/zipArchive.jx" type="jx"/>
> <map:transform type="cinclude"/>
> <map:serialize type="zip"/>
> </map:match>
> *************************************************************************
>
> But I now am facing the same nullpointer exception as in the link above.
>
> Anyone some usefull input on this matter?
>
> Cheers,
> Robby Pelssers
>
>
Hi Robby,
Just want to share my fix with the community. The NullPointerException was
caused by ZipArchiveSerializer (improper usage of a setter method). If you read
javadocs, they'll tell you that you shouldn't provide null to setConsumer
method. You can use the specific method to deinitialize consumer. Here is the
patch:
Index: src/main/java/org/apache/cocoon/serialization/ZipArchiveSerializer.java
===================================================================
--- src/main/java/org/apache/cocoon/serialization/ZipArchiveSerializer.java
(revision 1208405)
+++ src/main/java/org/apache/cocoon/serialization/ZipArchiveSerializer.java
(revision )
@@ -369,7 +369,7 @@
throw this.exception = new SAXException(ioe);
}
- super.setConsumer(null);
+ super.recycle();
this.selector.release(this.serializer);
this.serializer = null;
Best regards,
Ivan Lagunov