vhardy      2003/07/03 00:53:59

  Modified:    sources/org/apache/batik/svggen SVGGraphics2D.java
               test-resources/org/apache/batik/svggen regsvggen.xml
  Added:       test-sources/org/apache/batik/svggen Bug21259.java
  Log:
  Fixed bug 21259
  
  Revision  Changes    Path
  1.1                  xml-batik/test-sources/org/apache/batik/svggen/Bug21259.java
  
  Index: Bug21259.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1, a copy of which has been included with this distribution in  *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  
  package org.apache.batik.svggen;
  
  import java.awt.*;
  import java.io.*;
  import org.apache.batik.svggen.*;
  import org.apache.batik.transcoder.image.*;
  import org.apache.batik.transcoder.*;
  import org.apache.batik.dom.svg.*;
  import org.w3c.dom.*;
  
  import org.apache.batik.test.AbstractTest;
  import org.apache.batik.test.TestReport;
  
  /**
   * Checks that the streamed root is not removed from its parent 
   * as shown by bug report 21259.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Vincent Hardy</a>
   * @version $Id: Bug21259.java,v 1.1 2003/07/03 07:53:59 vhardy Exp $
   */
  public class Bug21259 extends AbstractTest{
      public TestReport runImpl() throws Exception {
          Document document = 
              SVGDOMImplementation.getDOMImplementation()
              .createDocument(SVGDOMImplementation.SVG_NAMESPACE_URI , "svg", null);
          SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(document);
          ctx.setComment("Test");
          SVGGraphics2D graphics = new SVGGraphics2D(ctx, false);
          graphics.setSVGCanvasSize(new Dimension(600, 400));
  
          graphics.setColor(Color.red);
          graphics.setBackground(Color.black);
          graphics.fill(new Rectangle(0,0,100,100));
  
          // Populate the Document's root with the content of the tree
          Element root = document.getDocumentElement();
          graphics.getRoot(root);
          Writer writer = new StringWriter();
          graphics.stream(root, writer);
  
          assertTrue(root.getParentNode() == document);
          return reportSuccess();
      }
  }
  
  
  
  1.35      +14 -1     xml-batik/sources/org/apache/batik/svggen/SVGGraphics2D.java
  
  Index: SVGGraphics2D.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/svggen/SVGGraphics2D.java,v
  retrieving revision 1.34
  retrieving revision 1.35
  diff -u -r1.34 -r1.35
  --- SVGGraphics2D.java        11 Apr 2003 13:59:05 -0000      1.34
  +++ SVGGraphics2D.java        3 Jul 2003 07:53:59 -0000       1.35
  @@ -41,6 +41,7 @@
   import org.w3c.dom.Document;
   import org.w3c.dom.DocumentFragment;
   import org.w3c.dom.Element;
  +import org.w3c.dom.Node;
   
   /**
    * This implementation of the java.awt.Graphics2D abstract class
  @@ -403,6 +404,9 @@
        */
       public void stream(Element svgRoot, Writer writer, boolean useCss)
           throws SVGGraphics2DIOException {
  +        Node rootParent = svgRoot.getParentNode();
  +        Node nextSibling = svgRoot.getNextSibling();
  +
           try {
               //
               // Enforce that the default and xlink namespace
  @@ -437,6 +441,15 @@
           } catch (IOException io) {
               generatorCtx.errorHandler.
                   handleError(new SVGGraphics2DIOException(io));
  +        } finally {
  +            // Restore the svgRoot to its original tree position
  +            if (rootParent != null) {
  +                if (nextSibling == null) {
  +                    rootParent.appendChild(svgRoot);
  +                } else {
  +                    rootParent.insertBefore(svgRoot, nextSibling);
  +                }
  +            }
           }
       }
   
  
  
  
  1.19      +3 -1      xml-batik/test-resources/org/apache/batik/svggen/regsvggen.xml
  
  Index: regsvggen.xml
  ===================================================================
  RCS file: /home/cvs/xml-batik/test-resources/org/apache/batik/svggen/regsvggen.xml,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- regsvggen.xml     2 Jul 2003 13:51:43 -0000       1.18
  +++ regsvggen.xml     3 Jul 2003 07:53:59 -0000       1.19
  @@ -42,4 +42,6 @@
   
       <test id="ShowSVG" class="org.apache.batik.svggen.ShowGraphics2DOutput" />
       <test id="GetRootTest" class="org.apache.batik.svggen.GetRootTest" />
  +
  +    <test id="bug21259" class="org.apache.batik.svggen.Bug21259" />
   </testSuite>
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to