Author: jeremias
Date: Tue Aug  4 08:12:18 2009
New Revision: 800697

URL: http://svn.apache.org/viewvc?rev=800697&view=rev
Log:
Added ability to create single-page SVG 1.1 using a DOMResult or SAXResult.

Modified:
    
xmlgraphics/fop/trunk/src/sandbox/org/apache/fop/render/svg/SVGDocumentHandler.java

Modified: 
xmlgraphics/fop/trunk/src/sandbox/org/apache/fop/render/svg/SVGDocumentHandler.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/sandbox/org/apache/fop/render/svg/SVGDocumentHandler.java?rev=800697&r1=800696&r2=800697&view=diff
==============================================================================
--- 
xmlgraphics/fop/trunk/src/sandbox/org/apache/fop/render/svg/SVGDocumentHandler.java
 (original)
+++ 
xmlgraphics/fop/trunk/src/sandbox/org/apache/fop/render/svg/SVGDocumentHandler.java
 Tue Aug  4 08:12:18 2009
@@ -22,9 +22,6 @@
 import java.awt.Dimension;
 import java.io.IOException;
 import java.io.OutputStream;
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
 
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
@@ -66,6 +63,9 @@
     private StreamResult firstStream;
     private StreamResult currentStream;
 
+    /** Used for single-page documents rendered to a DOM or SAX. */
+    private Result simpleResult;
+
     private Document reusedParts;
 
     /**
@@ -92,7 +92,7 @@
                     getUserAgent().getOutputFile());
             this.firstStream = (StreamResult)result;
         } else {
-            throw new UnsupportedOperationException("Result is not supported: 
" + result);
+            this.simpleResult = result;
         }
     }
 
@@ -152,46 +152,19 @@
     /** {...@inheritdoc} */
     public void startPage(int index, String name, String pageMasterName, 
Dimension size)
                 throws IFException {
-        OutputStream out;
-        try {
-            if (index == 0) {
-                out = null;
-            } else {
-                out = this.multiFileUtil.createOutputStream(index);
-                if (out == null) {
-                    //TODO Convert to event
-                    throw new IFException(
-                            "No filename information available. Stopping after 
first page.", null);
-                }
-            }
-        } catch (IOException ioe) {
-            throw new IFException("I/O exception while setting up output 
file", ioe);
-        }
-        if (out == null) {
-            this.handler = decorate(createContentHandler(this.firstStream));
+        if (this.multiFileUtil != null) {
+            prepareHandlerWithOutputStream(index);
         } else {
-            this.currentStream = new StreamResult(out);
-            this.handler = decorate(createContentHandler(this.currentStream));
-        }
-        if (false) {
-            final ContentHandler originalHandler = this.handler;
-            this.handler = decorate((ContentHandler)Proxy.newProxyInstance(
-                    ContentHandler.class.getClassLoader(),
-                    new Class[] {ContentHandler.class},
-                    new InvocationHandler() {
-                        public Object invoke(Object proxy, Method method, 
Object[] args)
-                                throws Throwable {
-                            String methodName = method.getName();
-                            System.out.println(methodName + ":");
-                            if (args != null) {
-                                for (int i = 0; i < args.length; i++) {
-                                    System.out.println("  " + args[i]);
-                                }
-                            }
-                            return method.invoke(originalHandler, args);
-                        }
-                    }));
+            if (this.simpleResult == null) {
+                //Only one page is supported with this approach at the moment
+                throw new IFException(
+                        "Only one page is supported for output with the given 
Result instance!",
+                        null);
+            }
+            super.setResult(this.simpleResult);
+            this.simpleResult = null;
         }
+
         try {
             handler.startDocument();
             handler.startPrefixMapping("", NAMESPACE);
@@ -227,6 +200,30 @@
         }
     }
 
+    private void prepareHandlerWithOutputStream(int index) throws IFException {
+        OutputStream out;
+        try {
+            if (index == 0) {
+                out = null;
+            } else {
+                out = this.multiFileUtil.createOutputStream(index);
+                if (out == null) {
+                    //TODO Convert to event
+                    throw new IFException(
+                            "No filename information available. Stopping after 
first page.", null);
+                }
+            }
+        } catch (IOException ioe) {
+            throw new IFException("I/O exception while setting up output 
file", ioe);
+        }
+        if (out == null) {
+            this.handler = decorate(createContentHandler(this.firstStream));
+        } else {
+            this.currentStream = new StreamResult(out);
+            this.handler = decorate(createContentHandler(this.currentStream));
+        }
+    }
+
     private GenerationHelperContentHandler decorate(ContentHandler 
contentHandler) {
         return new GenerationHelperContentHandler(contentHandler, 
getMainNamespace());
     }



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to