[Yanel-dev] PDF Resource is not working any more

Paloma Gomez paloma.gomez at wyona.com
Tue Mar 27 10:59:53 CEST 2007


Hi all,

A few days ago I realized that the pdf resource is not working. I have 
tried to find out what's wrong with it but I haven't succeeded so far. 
This is what I know:

*The changes made to this resource has been related to replacing Path to 
String (See below for a diff between the original and the current version)
*The file is actually created, but I get the following error message 
when I try to open it

"The file was damaged and could not be repaired"

*The problem seems to lie in the transformation since the resulting file 
contents are:

---------------------------------------
%PDF-1.3
%ª«¬­
4 0 obj
<< /Type /Info
/Producer (null) >>
endobj
5 0 obj
<< /Length 94 /Filter /Flat
----------------------------------------------------
*However, if I run fop 0.20.5 from the command line the transformation 
works:
--------------------------------------------
%PDF-1.3
%ª«¬­
4 0 obj
<< /Type /Info
/Producer (FOP 0.20.5) >>
endobj
5 0 obj
<< /Length 120 /Filter [ /ASCII85Decode /FlateDecode ]
 >>
stream


[....]
----------------------------------------------

Therefore I guess the problem is the java code performing the 
transformation. However, since that part of the code has not been 
changed significantly I can't see why it shouldn't work. Any hints? 
Anyway,  I'll keep on looking into it and let you know about my findings.

Regards,
Paloma


--------------------------------------------------------------------------------------------------------------------------------------------------------

@@ -65,7 +65,7 @@
      */
     public View getView(String viewId) {
         View defaultView = new View();
-        defaultView.setMimeType("application/pdf");
+        defaultView.setMimeType(getMimeType(viewId));

         try {
             Repository repo = getRealm().getRepository();
@@ -76,11 +76,11 @@
             driver.setRenderer(Driver.RENDER_PDF);
             driver.setOutputStream(baos);

-            Transformer transformer = 
TransformerFactory.newInstance().newTrans 
former(getXSLTStreamSource(path,repo));
+            Transformer transformer = 
TransformerFactory.newInstance().newTrans 
former(getXSLTStreamSource(getPath(),repo));

             org.xml.sax.XMLReader xmlReader = 
org.xml.sax.helpers.XMLReaderFact ory.createXMLReader();
             xmlReader.setEntityResolver(new 
org.apache.xml.resolver.tools.Catal ogResolver());
-            Source src = new SAXSource(xmlReader, new 
org.xml.sax.InputSource(r epo.getInputStream(path)));
+            Source src = new SAXSource(xmlReader, new 
org.xml.sax.InputSource(r epo.getInputStream(new Path(getPath()))));

             Result res = new SAXResult(driver.getContentHandler());

@@ -109,16 +109,16 @@
      *
      */
     public long getSize() throws Exception {
-        return getRealm().getRepository().getSize(path);
+        return getRealm().getRepository().getSize(new Path(getPath()));
     }

   /**
   *
   */
- private StreamSource getXSLTStreamSource(Path path, Repository repo) 
throws Re positoryException {
-     Path xsltPath = getXSLTPath(path);
+ private StreamSource getXSLTStreamSource(String path, Repository repo) 
throws RepositoryException {
+     String xsltPath = getXSLTPath(path);
      if(xsltPath != null) {
-         return new StreamSource(repo.getInputStream(xsltPath));
+         return new StreamSource(repo.getInputStream(new Path(xsltPath)));
      } else {
          File xsltFile = org.wyona.commons.io.FileUtil.file(
                  rtd.getConfigFile().getParentFile().getAbsolutePath(), 
"xslt" + File.separator + "xml2fo.xsl");
@@ -130,12 +130,17 @@
  /**
   *
   */
- private Path getXSLTPath(Path path) {
+ private String getXSLTPath(String path) {
      String xsltPath = getRTI().getProperty("xslt");
-     if (xsltPath != null) return new Path(xsltPath);
+     if (xsltPath != null) return xsltPath;
      log.info("No XSLT Path within: " + path);
      return null;
  }
-
-
+
+    /**
+     *
+     */
+    public String getMimeType(String viewId) {
+        return "application/pdf";
+    }
 }




More information about the Yanel-development mailing list