/*
 * $Id: HodderArnoldPdfTransform.java,v 1.5 2009-10-28 19:00:29 thib_gc Exp $
 */ 

/*

Copyright (c) 2000-2009 Board of Trustees of Leland Stanford Jr. University,
all rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
STANFORD UNIVERSITY BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Except as contained in this notice, the name of Stanford University shall not
be used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from Stanford University.

*/

package org.lockss.plugin.ingenta;

import java.io.*;

import org.lockss.filter.pdf.*;
import org.lockss.filter.pdf.PageTransformUtil.ExtractStringsToOutputStream;
import org.lockss.util.*;
import org.pdfbox.cos.*;

public class HodderArnoldPdfTransform implements OutputDocumentTransform {

  public boolean transform(PdfDocument pdfDocument,
                           OutputStream outputStream) {
    
    try {
      if ("RealPage PDF Generator 2.0".equals(pdfDocument.getCreator())) {
        IngentaPdfFilterFactory.logger.debug2("RealPage");
        
        // Extract all text
        return new TransformEachPage(new ExtractStringsToOutputStream(outputStream)).transform(pdfDocument);
      }
      else if ("iText 2.0.7 (by lowagie.com)".equals(pdfDocument.getProducer())) {
        IngentaPdfFilterFactory.logger.debug2("iText");
        boolean ret = false;
        
        // Remove autogenerated creation and modification dates
        pdfDocument.removeCreationDate();
        pdfDocument.removeModificationDate();
        
        COSDictionary trailer = pdfDocument.getTrailer();
        if (trailer != null) {
          // Put bogus ID to prevent autogenerated (variable) ID
          COSArray id = new COSArray();
          id.add(new COSString("12345678901234567890123456789012"));
          id.add(id.get(0));
          trailer.setItem(COSName.getPDFName("ID"), id);
          ret = true;
        }

        pdfDocument.save(outputStream);
        return ret;
      }
      else {
        IngentaPdfFilterFactory.logger.debug2("None");
        pdfDocument.save(outputStream);
        return true;
      }
    }
    catch (IOException ioe) {
      IngentaPdfFilterFactory.logger.debug2("IOException in HodderArnoldPdfTransform", ioe);
      return false;
    }
  }

  public boolean transform(PdfDocument pdfDocument) throws IOException {
    throw new IOException("HodderArnoldPdfTransform is an OutputDocumentTransform");
  }

}

@@ -42,37 +42,35 @@
 v 1.
-5 2009-10-28 19:00:29 thib_gc
+6 2010-09-01 21:11:28 pgust
  Exp
@@ -1627,33 +1627,8 @@
 l.*;
-%0Aimport org.pdfbox.cos.*;
 %0A%0Apu
@@ -1701,16 +1701,28 @@
 form %7B%0A%0A
+  @Override%0A
   public
@@ -2275,589 +2275,46 @@
     
-boolean ret = false;%0A        %0A        // Remove autogenerated creation and modification dates%0A        pdfDocument.removeCreationDate();%0A        pdfDocument.removeModificationDate();%0A        %0A        COSDictionary trailer = pdfDocument.getTrailer();%0A        if (trailer != null) %7B%0A          // Put bogus ID to prevent autogenerated (variable) ID%0A          COSArray id = new COSArray();%0A          id.add(new COSString(%2212345678901234567890123456789012%22));%0A          id.add(id.get(0));%0A          trailer.setItem(COSName.getPDFName(%22ID%22), id);%0A          ret = true;%0A        %7D%0A%0A        
+return IngentaPdfUtil.simpleTransform(
 pdfD
@@ -2312,38 +2312,34 @@
 form(pdfDocument
-.save(
+, 
 outputStream);%0A 
@@ -2341,28 +2341,8 @@
 m);%0A
-        return ret;%0A
     
@@ -2642,16 +2642,28 @@
  %7D%0A  %7D%0A%0A
+  @Override%0A
   public

Update transform() method to use new IngentaPdfUtil.simpleTransform() method.