Hi everyone,
I've got a problem trying to change the contents of the SVG DOM-tree that is
created with the svggen module of Batik after I've done some drawing
operations
in Java2D using the SVGGraphics2D class as input to my Java2D drawing
routines.
I know that the drawing routines creates the SVG-document fine when I dont
try to alter
the contents of the DOM-tree as I am able to render the unaltered SVG
DOM-tree.
The problem is that I want to add some <a xlink:href="link here"> links to
the circles that
I am drawing. I am creating a graph where I want the nodes in the graph to
be clickeable.
What I try to do to alter the tree is the following :
//Here are my import statements
import org.apache.batik.svggen.SVGGraphics2D;
import org.apache.batik.svggen.SVGSyntax;
import org.apache.batik.svggen.XmlWriter;
import org.apache.batik.dom.*;
import org.apache.batik.dom.traversal.DOMNodeIterator;
import org.w3c.dom.*;
import org.w3c.dom.traversal.NodeFilter;
import org.apache.batik.util.XMLConstants;
import org.apache.batik.ext.awt.g2d.AbstractGraphics2D;
import org.apache.batik.ext.awt.g2d.GraphicContext;
//Getting a DOMNodeIterator to traverse the nodes of the SVG DOM-tree.
svgGenerator is of class SVGGraphics2D.
DOMNodeIterator dniterator = new DOMNodeIterator((AbstractDocument)
svgGenerator.getDOMFactory(),svgGenerator.getRoot(),Node.ELEMENT_NODE,null,t
rue);
//Declaring a node nodeindoc
Node nodeindoc;
//Declaring a node parentnode, which will act as the parent for the
nodeindoc in the DOM-tree traversal
Node parentnode;
//Declaring an element elementnode.
Element elementnode;
//Creating a DocumentFragment to hold the elementnode and its child.
DocumentFragment df;
df = svgGenerator.getDOMFactory().createDocumentFragment();
//Setting the node nodeindoc equal to the first element in the
DOMNodeIterator.
nodeindoc = dniterator.nextNode();
while(nodeindoc != null)
{
if(nodeindoc.getNodeType() == Node.ELEMENT_NODE)
{
if(((Element) nodeindoc).getTagName() == SVGSyntax.SVG_CIRCLE_TAG)
{
//Creating the elementnode as part of the document holding the SVG-DOM
tree.
//If the nodeindoc node points to an element that is a circle,
//I will append the circle to this elementnode, trying to create a
circle node with a link.
elementnode =
svgGenerator.getDOMFactory().createElement(SVGSyntax.SVG_A_TAG);
elementnode.setAttributeNS(null,SVGSyntax.ATTR_XLINK_HREF,"http://xml.apache
.org/batik/index.html");
//Setting the nodeindoc as a child of the elementnode, and elementnode
as child of the documentfragment.
elementnode.appendChild(nodeindoc);
df.appendChild(elementnode);
//Getting the parent node of nodeindoc, replacing nodeindoc with the
nodes of the documentfragment
parentnode = nodeindoc.getParentNode();
parentnode.replaceChild(df,nodeindoc);
parentnode = null;
df = null;
}
}
nodeindoc = dniterator.nextNode();
}
//Creating an output stream that will be used to stream out the contents
of the svgGenerator to a web-page.
boolean useCSS = false;
Writer svgOutPutStream = new OutputStreamWriter(out, "UTF-8");
//finally I stream the contents of the svgGenerator out to the output
stream.
svgGenerator.stream(svgOutPutStream,useCSS);
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!
The problem is however that after I have done this none of my circles have
any <a> tags attached to them, and more often than not
the program hangs when I try to append the nodeindoc to the elementnode.
Does anyone have any input as to how I can manipulate the contents of the
SVG DOM-tree after it has been created and stream
out circles with links attached to them I would be very grateful for any
feedback.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!
Thankyou in advance
Yours sincerely
Phillip Larsen
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]