It Works!! Thank you Geert.
I attach an example performing a digital signature over a PDF using iText.
Your sitemap.xmap must have the new serializer defined:
<map:serializer logger="sitemap.serializer.fo2spdf"
mime-type="application/pdf"
name="fo2spdf" src="
org.apache.cocoon.serialization.PDFSignSerializer"/>
And you need a new "match" using this serializer:
<map:match pattern="kk">
<map:generate src="samples/hello-world/content/hello.xml" />
<map:transform src="samples/hello-world/style/xsl/page2fo.xsl"
/>
<map:serialize type="fo2spdf" />
</map:match>
Hope it helps :)
--
Salut,
====================================
Ricardo Borillo Domenech
Analista/Programador - Servei d'Informàtica
Universitat Jaume I
http://xml-utils.com
On 11/17/06, Ricardo Borillo <[EMAIL PROTECTED]> wrote:
Thank's for the tip. I will give it a try ...
On 11/16/06, Geert Josten <[EMAIL PROTECTED]> wrote:
>
> A not very nice, but workable method is:
>
> - create a buffering output stream at setOutputStream(out) and pass that
> to the super, while saving a reference to the output stream that is passed
> as parameter for later.
> - close and read the buffered output at endDocument(), passing it to
> your signing library, dump the signed result to the real output stream.
>
> Kind regards,
> Geert
>
> >
>
>
> Drs. G.P.H. Josten
> Consultant
>
>
>
> Daidalos BV
> Source of Innovation
> Hoekeindsehof 1-4
> 2665 JZ Bleiswijk
> Tel.: +31 (0) 10 850 1200
> Fax: +31 (0) 10 850 1199
> www.daidalos.nl
> KvK 27164984
>
>
> De informatie - verzonden in of met dit emailbericht - is afkomstig van
> Daidalos BV en is uitsluitend bestemd voor de geadresseerde. Indien u dit
> bericht onbedoeld hebt ontvangen, verzoeken wij u het te verwijderen. Aan
> dit bericht kunnen geen rechten worden ontleend.
>
>
> > Van: Ricardo Borillo [mailto:[EMAIL PROTECTED]
> > Verzonden: donderdag 16 november 2006 19:28
> > Aan: [email protected]
> > Onderwerp: FOPSerializer question
> >
> > Hi all!!
> >
> > I want to generate a PDF with a digital signature. I have
> > found a Java example that do the work:
> > http://itextpdf.sourceforge.net/howtosign.html#howtosign
> >
> > How can i integrate this with Cocoon?
> > I have worked with custom generators, but never with serializers ...
> >
> > Thanks in advance
> >
> > --
> > Salut,
> > ====================================
> > Ricardo Borillo Domenech
> > Analista/Programador - Servei d'Informàtica Universitat Jaume
> > I http://xml-utils.com
> >
>
--
Salut,
====================================
Ricardo Borillo Domenech
Analista/Programador - Servei d'Informàtica
Universitat Jaume I
http://xml-utils.com
package org.apache.cocoon.serialization;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.OutputStream;
import java.security.KeyStore;
import java.security.PrivateKey;
import java.security.cert.Certificate;
import org.apache.cocoon.serialization.FOPSerializer;
import org.xml.sax.SAXException;
import com.lowagie.text.pdf.PdfReader;
import com.lowagie.text.pdf.PdfSignatureAppearance;
import com.lowagie.text.pdf.PdfStamper;
public class PDFSignSerializer extends FOPSerializer
{
private OutputStream pdfOut;
private ByteArrayOutputStream internalOS;
public void setOutputStream(OutputStream out)
{
this.pdfOut = out;
this.internalOS = new ByteArrayOutputStream();
super.setOutputStream(this.internalOS);
}
public void endDocument() throws SAXException
{
super.endDocument();
try
{
this.internalOS.flush();
byte[] fopPDF = this.internalOS.toByteArray();
this.internalOS.close();
KeyStore ks = KeyStore.getInstance("pkcs12");
ks.load(new FileInputStream("/a.pfx"), "kk".toCharArray());
String alias = (String) ks.aliases().nextElement();
PrivateKey key = (PrivateKey) ks.getKey(alias, "kk".toCharArray());
Certificate[] chain = ks.getCertificateChain(alias);
PdfReader reader = new PdfReader(fopPDF);
PdfStamper stp = PdfStamper.createSignature(reader, this.pdfOut, '\0', new File("/tmp"));
PdfSignatureAppearance sap = stp.getSignatureAppearance();
sap.setCrypto(key, chain, null, PdfSignatureAppearance.WINCER_SIGNED);
sap.setReason("My Reason");
sap.setLocation("Spain");
stp.close();
this.pdfOut.flush();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}