xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "TJ Teegan" <tjtee...@hotmail.com>
Subject Re: Problems Serializing a SVGDocument
Date Mon, 13 Dec 2004 21:57:49 GMT
Hello again,

I think I figured out how to go from the DOM in a string representaion back 
to a SVGDocument (See Below).

This seems to work.  My question is if this is the most efficient way to do 
it, and also is the line doc = f.createDocument(null, sr) going to cause me 
trouble in the future, specificly is it ok to use null in the call to 
createDocument, or will this come back to bite me later on?

//Put the DOM into a string, see the method below.
String DOMString = svgToString();

public void myMethod(String DOMString){
        org.apache.batik.dom.svg.SAXSVGDocumentFactory f;
	org.w3c.dom.Document doc = null;
        java.io.StringReader sr;

        try {
            String parser = 
org.apache.batik.util.XMLResourceDescriptor.getXMLParserClassName();
            f = new org.apache.batik.dom.svg.SAXSVGDocumentFactory(parser);
            sr = new java.io.StringReader(this.writeSVGToString());
            doc = f.createDocument(null, sr);
        } catch (java.io.IOException ex) {
            ex.printStackTrace();
        }
        SVGCanvas.setSVGDocument((SVGDocument)doc);
    }

Thank you,
TJ

>From: "TJ Teegan" <tjteegan@hotmail.com>
>Reply-To: "Batik Users" <batik-users@xml.apache.org>
>To: batik-users@xml.apache.org
>Subject: Re: Problems Serializing a SVGDocument
>Date: Mon, 13 Dec 2004 09:32:50 -0600
>
>Thank you for the quick response.
>
>I have sort of found a work around.  I just dump the DOM into a string like 
>this:
>public String svgToString(){
>        //Outputs the contents of the entire current DOM as a single string
>        StringWriter writer;
>        String svg;
>
>        svg = null;
>        try{
>            writer = new StringWriter();
>            DOMUtilities.writeDocument(SVGDoc, writer);
>            writer.close();
>            svg = writer.toString();
>
>        }catch (IOException e){
>            e.printStackTrace();
>        }
>        return svg;
>    }
>
>Now I have the entire DOM as a single string, which I can serialize.  But I 
>cannnot quite figure out how to get this string back into a Document, or 
>SVGDocument, so I can display it on a jSVGCanvas.
>
>I was looking around the website, but I could not find anything.  Is this 
>possible?  If so, what should I be looking at to figure out how to do it?
>
>Once again, any help is greatly appreciated.
>Thank you,
>TJ Teegan
>
>>From: Thomas DeWeese <Thomas.DeWeese@Kodak.com>
>>Reply-To: "Batik Users" <batik-users@xml.apache.org>
>>To: Batik Users <batik-users@xml.apache.org>
>>Subject: Re: Problems Serializing a SVGDocument
>>Date: Mon, 13 Dec 2004 10:20:02 -0500
>>
>>Hi TJ,
>>
>>TJ Teegan wrote:
>>
>>>I am trying to serialize a SVGDocument using the following code:
>>
>>    Our DOM is not serializable, I don't really know if there
>>are really deep issues (I would expect there are) or not.
>>
>>    You can usually serialize to XML of course.
>>
>>>public byte[] convertObjectToBytes(Object o){
>>>        byte[] bytes;
>>>        ObjectOutputStream oos;
>>>        ByteArrayOutputStream byteStreamOut;
>>>
>>>        //object o must implement the Serializable interface
>>>        bytes = new byte[0];
>>>        try{
>>>            //write the object to a bit stream
>>>            byteStreamOut = new ByteArrayOutputStream();
>>>            oos = new ObjectOutputStream(byteStreamOut);
>>>            oos.writeObject(o);
>>>            bytes = byteStreamOut.toByteArray();
>>>        }catch(IOException e){
>>>            e.printStackTrace();
>>>        }
>>>        return bytes;
>>>    }
>>>
>>>I call the method like this:
>>>byte[] b = convertObjectToBytes(svgCanvas.getSVGDocument()):
>>>
>>>I get the following error:
>>>java.io.NotSerializableException: org.apache.batik.css.engine.StyleMap
>>>        at 
>>>java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1054)
>>>        at 
>>>java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1332)
>>>        at 
>>>java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1304)
>>>        at 
>>>java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1247)
>>>
>>>        at 
>>>java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1052)
>>>        at 
>>>java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1332)
>>>        at 
>>>java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1304)
>>>        at 
>>>java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1247)
>>>
>>>        at 
>>>java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1052)
>>>        at 
>>>java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1332)
>>>        at 
>>>java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1304)
>>>        at 
>>>java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1247)
>>>
>>>        at 
>>>java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1052)
>>>        at 
>>>java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1332)
>>>        at 
>>>java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1304)
>>>        at 
>>>java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1247)
>>>
>>>        at 
>>>java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1052)
>>>        at 
>>>java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1332)
>>>        at 
>>>java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1304)
>>>        at 
>>>java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1247)
>>>
>>>        at 
>>>java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1052)
>>>        at 
>>>java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1332)
>>>        at 
>>>java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1304)
>>>        at 
>>>java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1247)
>>>
>>>        at 
>>>java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1052)
>>>        at 
>>>java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1332)
>>>        at 
>>>java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1304)
>>>        at 
>>>java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1247)
>>>
>>>        at 
>>>java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1052)
>>>        at 
>>>java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1332)
>>>        at 
>>>java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1304)
>>>        at 
>>>java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1247)
>>>
>>>        at 
>>>java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1052)
>>>        at 
>>>java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1332)
>>>        at 
>>>java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1304)
>>>        at 
>>>java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1247)
>>>
>>>        at 
>>>java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1052)
>>>        at 
>>>java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1332)
>>>        at 
>>>java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1304)
>>>        at 
>>>java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1247)
>>>
>>>        at 
>>>java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1052)
>>>        at 
>>>java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1332)
>>>        at 
>>>java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1304)
>>>        at 
>>>java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1247)
>>>
>>>        at 
>>>java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1052)
>>>        at 
>>>java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1332)
>>>        at 
>>>java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1304)
>>>        at 
>>>java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1247)
>>>
>>>        at 
>>>java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1052)
>>>        at 
>>>java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1332)
>>>        at 
>>>java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1304)
>>>        at 
>>>java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1247)
>>>
>>>        at 
>>>java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1052)
>>>        at 
>>>java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:278)
>>>        at apt.onRequest.net.NetIO.convertObjectToBytes(NetIO.java:66)
>>>        at 
>>>apt.onRequest.gui.DrawingPanel.testSave(DrawingPanel.java:2192)
>>>        at apt.onRequest.gui.DrawingPanel.zoomIn(DrawingPanel.java:282)
>>>        at 
>>>apt.onRequest.gui.MainScreen.btnZoomInActionPerformed(MainScreen.java:471)
>>>        at apt.onRequest.gui.MainScreen.access$700(MainScreen.java:17)
>>>        at 
>>>apt.onRequest.gui.MainScreen$8.actionPerformed(MainScreen.java:200)
>>>        at 
>>>javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1786)
>>>        at 
>>>javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1839)
>>>
>>>        at 
>>>javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
>>>
>>>        at 
>>>javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
>>>        at 
>>>javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)
>>>
>>>        at 
>>>java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:231)
>>>        at java.awt.Component.processMouseEvent(Component.java:5100)
>>>        at java.awt.Component.processEvent(Component.java:4897)
>>>        at java.awt.Container.processEvent(Container.java:1569)
>>>        at java.awt.Component.dispatchEventImpl(Component.java:3615)
>>>        at java.awt.Container.dispatchEventImpl(Container.java:1627)
>>>        at java.awt.Component.dispatchEvent(Component.java:3477)
>>>        at 
>>>java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3483)
>>>        at 
>>>java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198)
>>>        at 
>>>java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)
>>>        at java.awt.Container.dispatchEventImpl(Container.java:1613)
>>>        at java.awt.Window.dispatchEventImpl(Window.java:1606)
>>>        at java.awt.Component.dispatchEvent(Component.java:3477)
>>>        at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)
>>>        at 
>>>java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
>>>
>>>        at 
>>>java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
>>>
>>>        at 
>>>java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
>>>        at 
>>>java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
>>>        at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
>>>
>>>Is there anyway around this error?  I apologize if this already been 
>>>covered.  I searched the mailing list archives, but could not find an 
>>>answer.  Any help is greatly appreciated.
>>>
>>>Thank you,
>>>TJ Teegan
>>>
>>>_________________________________________________________________
>>>Is your PC infected? Get a FREE online computer virus scan from McAfeeŽ 
>>>Security. http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963
>>>
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
>>>For additional commands, e-mail: batik-users-help@xml.apache.org
>>>
>>
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
>>For additional commands, e-mail: batik-users-help@xml.apache.org
>>
>
>_________________________________________________________________
>Express yourself instantly with MSN Messenger! Download today - it's FREE! 
>http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
>For additional commands, e-mail: batik-users-help@xml.apache.org
>

_________________________________________________________________
Is your PC infected? Get a FREE online computer virus scan from McAfeeŽ 
Security. http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org


Mime
View raw message