You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlgraphics.apache.org by bu...@apache.org on 2012/04/15 07:46:24 UTC

svn commit: r813020 [7/8] - in /websites/staging/xmlgraphics/trunk/content: ./ batik/ batik/demo/ batik/dev/ batik/tools/ batik/using/ batik/using/scripting/

Added: websites/staging/xmlgraphics/trunk/content/batik/using/scripting/security.html
==============================================================================
--- websites/staging/xmlgraphics/trunk/content/batik/using/scripting/security.html (added)
+++ websites/staging/xmlgraphics/trunk/content/batik/using/scripting/security.html Sun Apr 15 05:46:22 2012
@@ -0,0 +1,144 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html lang="en">
+  <head>
+    <title>Script security</title>
+
+    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
+    <meta property="og:image" content="http://www.apache.org/images/asf_logo.gif" />
+<!--
+    <link rel="stylesheet" type="text/css" media="screen" href="http://www.apache.org/css/style.css">
+    <link rel="stylesheet" type="text/css" media="screen" href="http://www.apache.org/css/code.css">
+-->
+    <link href="/css/xmlgraphics.css" rel="stylesheet" type="text/css">
+
+    </style>
+
+    
+
+    
+    
+  </head>
+
+  <body>
+	  <div id="banner">&nbsp;
+	  </div>
+
+	  <div id="navigation">
+	  <h1 id="xml-graphics">XML Graphics</h1>
+<ul>
+<li><a href="/">Overview</a></li>
+<li><a href="/team.html">Who We Are</a></li>
+<li><a href="/legal.html">Legal Stuff</a></li>
+<li><a href="/charter.html">Project Charter</a></li>
+<li><a href="/mail.html">Mailing Lists</a></li>
+<li><a href="/repo.html">Code Repositories</a></li>
+<li><a href="http://www.apache.org/foundation/sponsorship.html">ASF Sponsorship Program</a></li>
+<li><a href="http://www.apache.org/foundation/thanks.html">ASF Thanks</a></li>
+</ul>
+<h1 id="subprojects">Subprojects</h1>
+<ul>
+<li><a href="/batik/">Batik</a></li>
+<li><a href="/fop/">FOP</a></li>
+<li><a href="/commons/">Commons</a></li>
+</ul>
+<form name="search" id="search" action="http://www.google.com/search" method="get">
+  <input value="xmlgraphics.apache.org" name="sitesearch" type="hidden"/>
+  <input type="text" name="q" id="query" /><br />
+  <input type="submit" id="submit" value="Search" />
+</form>
+	  </div>
+	
+	  <div id="bannertext">
+        <a href="/"><img src="/images/apache-xml-graphics.gif" alt="The Apache XML Graphics Project" width="220" heigh="51" /></a>
+        <h1>Script security</h1>
+      </div>
+        <p><a href="/">Home</a>&nbsp;&raquo&nbsp;<a href="/batik/">Batik</a>&nbsp;&raquo&nbsp;<a href="/batik/using/">Using</a>&nbsp;&raquo&nbsp;<a href="/batik/using/scripting/">Scripting</a></p>
+      </div>
+      <div id="content" class="grid_16"><div class="section-content"><p>With the addition of scripting support in Batik 1.5, security features have also been added to enable users of the Batik toolkit to run scripts in a secure manner.</p>
+<p>If you are using script, please make sure you have reviewed the <a href="../../index.html#SecurityWarning">Script Security Warning</a> with regards to the Batik 1.5 release.</p>
+<h1 id="sandbox">Running scripts securely</h1>
+<p>The Java platform offers a lot of options for running applications securely. Running an application securely requires that it runs in a so-called security sand-box which controls all the access the application makes to restricted resources (such as the file system).</p>
+<p>The concept of Java security is an application-wide concept. As such, it has to be applied at the application level (and not at the framework level). In the Batik distribution, the sample applications (such as the <a href="../../tools/browser.html">Squiggle Browser</a> and the <a href="../../tools/rasterizer.html">SVG rasterizer</a> ) apply security (or disable it) but the framework does not apply it: it is security-aware (meaning that it is able to handle security exceptions).</p>
+<h2 id="enforcing">Enforcing security in a Batik application</h2>
+<p>Enforcing security in a Batik application is done by setting a <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/SecurityManager.html">java.lang.SecurityManager</a> . This security manager will apply the security settings of the Java platform (as defined by the <em>jre-dir</em>  <code>/lib/security/java.policy</code> and, optionally, by the policy file whose URL is defined in the <code>java.security.policy</code> system property).</p>
+<p>The <a href="../../javadoc/org/apache/batik/util/ApplicationSecurityEnforcer.html">org.apache.batik.util.ApplicationSecurityEnforcer</a> helper class makes it easier for Batik application developers to add security support in their applications. That helper class is used by the sample Batik applications.</p>
+<h2 id="squiggle">Squiggle security</h2>
+<p>The Squiggle browser lets the user decide whether or not scripts should be run securely (see the “Browser Options” in the preference dialog box). When scripts are run securely, Squiggle will enforce the security settings as follows:</p>
+<ul>
+<li>
+<p>The default policy is defined by the policy file found in the distribution: <code>org/apache/batik/apps/svgbrowser/svgbrowser.policy</code> . In the binary distribution, that file would be in the <code>batik-squiggle.jar</code> file. In the source distribution, that file would be in the <code>resources</code> directory. The default policy file gives appropriate permissions to the Batik code, the XML parser and the Rhino scripting engine and very limited permissions to scripts.</p>
+</li>
+<li>
+<p>At startup time, and whenever the preference settings are modified, Squiggle makes a copy of the default policy and appends any additional permissions granted to scripts by the user through the preference settings. This policy file can be found in the <code>[user.home]/.batik</code> directory, and is called <code>__svgbrowser.policy</code> . Note that this file is automatically generated and should not be modified manually (as any edits would be lost).</p>
+</li>
+<li>
+<p>The policy defined as described above is enforced unless the <code>java.security.policy</code> system property is defined. In that case, the policy defined by the system property takes precedence and the policy file generated from the Squiggle preferences is ignored.</p>
+</li>
+</ul>
+<p><strong>Important note:</strong> The default policy files assume that the applications use the Xerces parser and give appropriate permissions to its <code>lib/xerces-2_5_0.jar</code> jar file. If you are using a different XML parser, you need to modify the policy files to grant the propser permissions to your XML parser instead of Xerces. You will have to replace:
+grant codeBase "${app.dev.base}/lib/xerces_2_5_0.jar" {
+  permission java.security.AllPermission;
+};
+with:
+grant codeBase "${app.dev.base}/lib/myXMLParser.jar" {
+  permission java.security.AllPermission;
+};
+in the <code>resources/org/apache/batik/apps/svgbrowser/resources/svgbrowser.policy</code> file (for the source distribution) and do the same in <code>resources/org/apache/batik/apps/svgbrowser/resources/svgbrowser.bin.policy</code> (for the binary distribution which will then need to be rebuilt with the <code>build dist-zip</code> command.</p>
+<p>Alternatively, you can write your own policy file and specify its URL through the <code>java.security.policy</code> system property (which you can specify through the <code>-Djava.security.policy=</code>  <em>url</em> command line option).</p>
+<h1 id="externalResources">Controlling access to external resources</h1>
+<p>SVG makes a very powerful use of external resources in many elements such as <code>image</code> , <code>use</code> , <code>font</code> , <code>script</code> and <code>radialGradient</code> . There are over fifteen SVG elements that may reference external resources that way.</p>
+<p>In some environments, and typically for security reasons, it is important to control the resources referenced by an SVG document and be able to accept or reject these resources.</p>
+<p>In the Batik toolkit, this flexibility is provided by the <a href="../../javadoc/org/apache/batik/bridge/UserAgent.html">org.apache.batik.bridge.UserAgent</a> interface which can define various strategies with regards to external resources. By providing a new implementation of the <code>UserAgent</code> interface, it is possible to apply the desired security strategy for scripts and external resources.</p>
+<p>The following <code>UserAgent</code> methods are provided for that purpose:</p>
+<ul>
+<li>
+<p><code>getScriptSecurity(scriptType, scriptURL, docURL)</code> should return the <a href="../../javadoc/org/apache/batik/bridge/ScriptSecurity.html">ScriptSecurity</a> strategy for a script of type <code>scriptType</code> (e.g., <code>text/ecmascript</code> ) coming from <code>scriptURL</code> , when referenced from the document whose URL is <code>docURL</code> .</p>
+</li>
+<li>
+<p><code>getExternalResourceSecurity(resourceURL, docURL)</code> should return the <a href="../../javadoc/org/apache/batik/bridge/ExternalResourceSecurity.html">ExternalResourceSecurity</a> strategry for a resource coming from <code>resourceURL</code> referenced from the document at URL <code>docURL</code> .</p>
+</li>
+</ul>
+<p>The <code>ScriptSecurity</code> and <code>ExternalResourceSecurity</code> interfaces have methods ( <code>checkLoadScript</code> and <code>checkLoadExternalResource</code> respectively) which should throw a <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/SecurityException.html">SecurityException</a> if accessing the script or resource is considered a security violation.
+The <code>UserAgent</code> interface has two additional methods ( <code>checkLoadScript</code> and <code>checkLoadExternalResource</code> which are meant to provide a short hand for getting a security strategy object and calling the <code>checkLoad</code> * method on that object. This is how the <a href="../../javadoc/org/apache/batik/bridge/UserAgentAdapter.html">org.apache.batik.bridge.UserAgentAdapter</a> class implements this method.
+Batik provides the following set of <code>ScriptSecurity</code> implementations:</p>
+<dl>
+<dt>NoLoadScriptSecurity</dt>
+<dd>The script resource should not be loaded.</dd>
+<dt>EmbededScriptSecurity</dt>
+<dd>The script resource will only be loaded if it is embeded in the SVG document referencing it. This means that script attributes (such as <code>onclick</code> on a <code>rect</code> element), inline <code>script</code> elements and <code>script</code> elements using a <code>data:</code> URL as its <code>xlink:href</code> attribute value will be allowed. All other script resources should not be loaded.</dd>
+<dt>DefaultScriptSecurity</dt>
+<dd>The script resource will only be loaded if it is embeded in the SVG document (see the description of <code>EmbededScriptSecurity</code> ) or if it is coming from the same location as the document referencing the script. If the document comes from a network server, then any script coming from that server will be allowed. If the document comes from the file system, then only scripts under the same directory root as the SVG document will be allowed.</dd>
+<dt>RelaxedScriptSecurity</dt>
+<dd>Scripts from any location can be loaded.</dd>
+</dl>
+<p>In addition, Batik provides the following set of <code>ExternalResourceSecurity</code> implementations:</p>
+<dl>
+<dt>NoLoadExternalResourceSecurity</dt>
+<dd>No external references are allowed.</dd>
+<dt>EmbededExternalResourceSecurity</dt>
+<dd>Only resources embeded into the file are allowed (i.e., references through the <code>data:</code> protocol).</dd>
+<dt>DefaultExternalResourceSecurity</dt>
+<dd>Embeded external resources (see above) and resources coming from the same location as the document referencing them are allowed.</dd>
+<dt>RelaxedExternalResourceSecurity</dt>
+<dd>Resources from any location can be loaded.</dd>
+</dl></div></div>
+      <div class="clear"></div>
+
+	  <div id="footer">
+		<a alt="Apache Software Foundation" href="http://www.apache.org">
+		  <img id="asf-logo" alt="Apache Software Foundation" src="/images/feather-small.gif"/ width="100">
+		</a>
+		<div class="copyright">
+		  <p>
+			Copyright &copy; 2011 The Apache Software Foundation, Licensed under
+			the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.
+			<br />
+			Apache, Apache XML Graphics, the Apache feather logo, and the Apache XML Graphics logos are
+			trademarks of <a href="http://www.apache.org">The Apache Software Foundation</a>. All other
+			marks mentioned may be trademarks or registered trademarks of their respective owners.
+			<br />
+		  </p>
+		</div> 
+	  </div>
+  </body>
+</html>

Added: websites/staging/xmlgraphics/trunk/content/batik/using/svg-generator.html
==============================================================================
--- websites/staging/xmlgraphics/trunk/content/batik/using/svg-generator.html (added)
+++ websites/staging/xmlgraphics/trunk/content/batik/using/svg-generator.html Sun Apr 15 05:46:22 2012
@@ -0,0 +1,407 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html lang="en">
+  <head>
+    <title>SVG Generator: SVGGraphics2D</title>
+
+    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
+    <meta property="og:image" content="http://www.apache.org/images/asf_logo.gif" />
+<!--
+    <link rel="stylesheet" type="text/css" media="screen" href="http://www.apache.org/css/style.css">
+    <link rel="stylesheet" type="text/css" media="screen" href="http://www.apache.org/css/code.css">
+-->
+    <link href="/css/xmlgraphics.css" rel="stylesheet" type="text/css">
+
+    </style>
+
+    
+
+    
+    
+  </head>
+
+  <body>
+	  <div id="banner">&nbsp;
+	  </div>
+
+	  <div id="navigation">
+	  <h1 id="xml-graphics">XML Graphics</h1>
+<ul>
+<li><a href="/">Overview</a></li>
+<li><a href="/team.html">Who We Are</a></li>
+<li><a href="/legal.html">Legal Stuff</a></li>
+<li><a href="/charter.html">Project Charter</a></li>
+<li><a href="/mail.html">Mailing Lists</a></li>
+<li><a href="/repo.html">Code Repositories</a></li>
+<li><a href="http://www.apache.org/foundation/sponsorship.html">ASF Sponsorship Program</a></li>
+<li><a href="http://www.apache.org/foundation/thanks.html">ASF Thanks</a></li>
+</ul>
+<h1 id="subprojects">Subprojects</h1>
+<ul>
+<li><a href="/batik/">Batik</a></li>
+<li><a href="/fop/">FOP</a></li>
+<li><a href="/commons/">Commons</a></li>
+</ul>
+<form name="search" id="search" action="http://www.google.com/search" method="get">
+  <input value="xmlgraphics.apache.org" name="sitesearch" type="hidden"/>
+  <input type="text" name="q" id="query" /><br />
+  <input type="submit" id="submit" value="Search" />
+</form>
+	  </div>
+	
+	  <div id="bannertext">
+        <a href="/"><img src="/images/apache-xml-graphics.gif" alt="The Apache XML Graphics Project" width="220" heigh="51" /></a>
+        <h1>SVG Generator: SVGGraphics2D</h1>
+      </div>
+        <p><a href="/">Home</a>&nbsp;&raquo&nbsp;<a href="/batik/">Batik</a>&nbsp;&raquo&nbsp;<a href="/batik/using/">Using</a></p>
+      </div>
+      <div id="content" class="grid_16"><div class="section-content"><div class="figure"> ![Flow diagram illustrating that Java programs can have their graphics converted to SVG and then viewed in any SVG viewer](images/svggen.jpg "") </div>
+
+<p>As SVG is emerging as a promising graphics format for a wide range of domains and applications, bridging it with Java becomes important. This page explains how Batik’s <a href="../javadoc/org/apache/batik/svggen/SVGGraphics2D.html">SVGGraphics2D</a> , referred to as the SVG Generator, makes this possible.</p>
+<h1 id="whatIsIt">The SVGGraphics2D class</h1>
+<p>On the Java platform, all rendering goes through the <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Graphics2D.html">Graphics2D</a> abstract class, which offers methods such as <code>drawRect</code> , <code>fillRect</code> , and <code>drawString</code> . There are specialized implementations of this abstract class for each type of output, such as a screen or a printer. <code>SVGGraphics2D</code> is a new implementation of that interface that generates SVG content instead of drawing to a screen or a printer.</p>
+<p><code>SVGGraphics2D</code> has the following features:</p>
+<ul>
+<li>
+<p>it allows applications to export their graphics into SVG format,</p>
+</li>
+<li>
+<p>it does not require any modification of the graphics code to export to SVG, and</p>
+</li>
+<li>
+<p>it offers the user the ability to use the DOM API to manipulate the generated document.
+<div class="figure"> <img alt="Diagram illustrating how the SVGGraphics2D inherits from Graphics2D, and uses Document to generate a DOM tree" src="images/svggenHighLevelArchi.jpg" title="" /> </div>
+The above figure shows how the generator works with the DOM API. The W3C has defined an API for representing XML content with a Java object. That API allows programmers to manipulate, create, and/or modify XML content in memory. The DOM API contains interfaces such as <a href="http://java.sun.com/j2se/1.5.0/docs/api/org/w3c/dom/Document.html">Document</a> , <a href="http://java.sun.com/j2se/1.5.0/docs/api/org/w3c/dom/Element.html">Element</a> , and <a href="http://java.sun.com/j2se/1.5.0/docs/api/org/w3c/dom/Attr.html">Attr</a> , which model the Java programming language equivalent of XML documents, elements and attributes.</p>
+</li>
+</ul>
+<p>The generator manages a tree of DOM objects that represent the SVG content corresponding to the rendering calls made on the <code>SVGGraphics2D</code> instance. In other words, every time a program invokes a rendering method, such as <code>fillRect</code> , on a <code>SVGGraphics2D</code> instance, a new DOM object, representing the SVG equivalent, is appended to the DOM tree. For example, a <code>rect</code> element will be appended after the <code>fillRect</code> method has been invoked).</p>
+<p>The programmer, using this generator, can then access the DOM tree to further manipulate it or can directly write the content to an output stream, as we see in the following section.</p>
+<h1 id="howToUse">How to use SVGGraphics2D</h1>
+<p>From the figure in the previous section we can see that in order for an instance of <code>SVGGraphics2D</code> to build the SVG content (the DOM tree), an instance of a <code>Document</code> class is needed. The DOM tree is an in-memory representation of the SVG document, which can be further manipulated by the user using DOM API or be streamed out by a <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/io/Writer.html">Writer</a> object.</p>
+<p>The following example program demonstrates how to generate SVG content from Java graphics.
+import java.awt.Rectangle;
+import java.awt.Graphics2D;
+import java.awt.Color;
+import java.io.Writer;
+import java.io.OutputStreamWriter;
+import java.io.IOException;</p>
+<p>import org.apache.batik.svggen.SVGGraphics2D;
+import org.apache.batik.dom.GenericDOMImplementation;</p>
+<p>import org.w3c.dom.Document;
+import org.w3c.dom.DOMImplementation;</p>
+<p>public class TestSVGGen {</p>
+<div class="codehilite"><pre><span class="n">public</span> <span class="n">void</span> <span class="n">paint</span><span class="p">(</span><span class="n">Graphics2D</span> <span class="n">g2d</span><span class="p">)</span> <span class="p">{</span>
+    <span class="n">g2d</span><span class="o">.</span><span class="n">setPaint</span><span class="p">(</span><span class="n">Color</span><span class="o">.</span><span class="n">red</span><span class="p">);</span>
+    <span class="n">g2d</span><span class="o">.</span><span class="n">fill</span><span class="p">(</span><span class="k">new</span> <span class="n">Rectangle</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">100</span><span class="p">,</span> <span class="mi">100</span><span class="p">));</span>
+<span class="p">}</span>
+
+<span class="n">public</span> <span class="n">static</span> <span class="n">void</span> <span class="n">main</span><span class="p">(</span><span class="n">String</span><span class="o">[]</span> <span class="n">args</span><span class="p">)</span> <span class="n">throws</span> <span class="n">IOException</span> <span class="p">{</span>
+
+    <span class="sr">//</span> <span class="n">Get</span> <span class="n">a</span> <span class="n">DOMImplementation</span><span class="o">.</span>
+    <span class="n">DOMImplementation</span> <span class="n">domImpl</span> <span class="o">=</span>
+        <span class="n">GenericDOMImplementation</span><span class="o">.</span><span class="n">getDOMImplementation</span><span class="p">();</span>
+
+    <span class="sr">//</span> <span class="n">Create</span> <span class="n">an</span> <span class="n">instance</span> <span class="n">of</span> <span class="n">org</span><span class="o">.</span><span class="n">w3c</span><span class="o">.</span><span class="n">dom</span><span class="o">.</span><span class="n">Document</span><span class="o">.</span>
+    <span class="n">String</span> <span class="n">svgNS</span> <span class="o">=</span> <span class="s">&quot;http://www.w3.org/2000/svg&quot;</span><span class="p">;</span>
+    <span class="n">Document</span> <span class="n">document</span> <span class="o">=</span> <span class="n">domImpl</span><span class="o">.</span><span class="n">createDocument</span><span class="p">(</span><span class="n">svgNS</span><span class="p">,</span> <span class="s">&quot;svg&quot;</span><span class="p">,</span> <span class="n">null</span><span class="p">);</span>
+
+    <span class="sr">//</span> <span class="n">Create</span> <span class="n">an</span> <span class="n">instance</span> <span class="n">of</span> <span class="n">the</span> <span class="n">SVG</span> <span class="n">Generator</span><span class="o">.</span>
+    <span class="n">SVGGraphics2D</span> <span class="n">svgGenerator</span> <span class="o">=</span> <span class="k">new</span> <span class="n">SVGGraphics2D</span><span class="p">(</span><span class="n">document</span><span class="p">);</span>
+
+    <span class="sr">//</span> <span class="n">Ask</span> <span class="n">the</span> <span class="n">test</span> <span class="n">to</span> <span class="n">render</span> <span class="n">into</span> <span class="n">the</span> <span class="n">SVG</span> <span class="n">Graphics2D</span> <span class="n">implementation</span><span class="o">.</span>
+    <span class="n">TestSVGGen</span> <span class="n">test</span> <span class="o">=</span> <span class="k">new</span> <span class="n">TestSVGGen</span><span class="p">();</span>
+    <span class="n">test</span><span class="o">.</span><span class="n">paint</span><span class="p">(</span><span class="n">svgGenerator</span><span class="p">);</span>
+
+    <span class="sr">//</span> <span class="n">Finally</span><span class="p">,</span> <span class="n">stream</span> <span class="n">out</span> <span class="n">SVG</span> <span class="n">to</span> <span class="n">the</span> <span class="n">standard</span> <span class="n">output</span> <span class="n">using</span>
+    <span class="sr">//</span> <span class="n">UTF</span><span class="o">-</span><span class="mi">8</span> <span class="n">encoding</span><span class="o">.</span>
+    <span class="n">boolean</span> <span class="n">useCSS</span> <span class="o">=</span> <span class="n">true</span><span class="p">;</span> <span class="sr">//</span> <span class="n">we</span> <span class="n">want</span> <span class="n">to</span> <span class="k">use</span> <span class="n">CSS</span> <span class="n">style</span> <span class="n">attributes</span>
+    <span class="n">Writer</span> <span class="n">out</span> <span class="o">=</span> <span class="k">new</span> <span class="n">OutputStreamWriter</span><span class="p">(</span><span class="n">System</span><span class="o">.</span><span class="n">out</span><span class="p">,</span> <span class="s">&quot;UTF-8&quot;</span><span class="p">);</span>
+    <span class="n">svgGenerator</span><span class="o">.</span><span class="n">stream</span><span class="p">(</span><span class="n">out</span><span class="p">,</span> <span class="n">useCSS</span><span class="p">);</span>
+<span class="p">}</span>
+</pre></div>
+
+
+<p>}
+We can see that generating SVG content from our <code>TestSVGGen</code> instance is a three step process:</p>
+<ol>
+<li>
+<p>Create an instance of <code>org.w3c.dom.Document</code> that the generator will use to build its XML content, and create an SVG generator using the <code>Document</code> instance.
+        // Get a DOMImplementation.
+        DOMImplementation domImpl =
+            GenericDOMImplementation.getDOMImplementation();</p>
+<div class="codehilite"><pre><span class="sr">//</span> <span class="n">Create</span> <span class="n">an</span> <span class="n">instance</span> <span class="n">of</span> <span class="n">org</span><span class="o">.</span><span class="n">w3c</span><span class="o">.</span><span class="n">dom</span><span class="o">.</span><span class="n">Document</span><span class="o">.</span>
+<span class="n">String</span> <span class="n">svgNS</span> <span class="o">=</span> <span class="s">&quot;http://www.w3.org/2000/svg&quot;</span><span class="p">;</span>
+<span class="n">Document</span> <span class="n">document</span> <span class="o">=</span> <span class="n">domImpl</span><span class="o">.</span><span class="n">createDocument</span><span class="p">(</span><span class="n">svgNS</span><span class="p">,</span> <span class="s">&quot;svg&quot;</span><span class="p">,</span> <span class="n">null</span><span class="p">);</span>
+
+<span class="sr">//</span> <span class="n">Create</span> <span class="n">an</span> <span class="n">instance</span> <span class="n">of</span> <span class="n">the</span> <span class="n">SVG</span> <span class="n">Generator</span><span class="o">.</span>
+<span class="n">SVGGraphics2D</span> <span class="n">svgGenerator</span> <span class="o">=</span> <span class="k">new</span> <span class="n">SVGGraphics2D</span><span class="p">(</span><span class="n">document</span><span class="p">);</span>
+</pre></div>
+
+
+</li>
+<li>
+<p>Invoke the rendering code on our SVG generator. In our example, we invoke <code>TestSVGGen</code> ‘s <code>paint</code> method:
+        // Ask the test to render into the SVG Graphics2D implementation.
+        TestSVGGen test = new TestSVGGen();
+        test.paint(svgGenerator);</p>
+</li>
+<li>
+<p>Stream out the SVG content. The SVG generator can stream its content into any <code>java.io.Writer</code> . In our example, we stream the content to the standard output stream:
+        // Finally, stream out SVG to the standard output using
+        // UTF-8 encoding.
+        boolean useCSS = true; // we want to use CSS style attributes
+        Writer out = new OutputStreamWriter(System.out, "UTF-8");
+        svgGenerator.stream(out, useCSS);</p>
+</li>
+</ol>
+<p>SVG has <a href="http://www.w3.org/TR/SVG11/styling.html#AlternativesForStyling">two ways to specify styling properties</a> , such as the fill color: presentation attributes (one XML attribute per property) or the CSS <code>style</code> attribute (any number of properties in one CSS inline stylesheet). The <code>useCss</code> parameter allows the user to control that option.</p>
+<h1 id="custom">SVG Generator customization</h1>
+<p>In the previous section, we have just seen that the SVG generation process can be customized to output SVG styling properties as presentation attributes or CSS inline stylesheets. In this section we will talk about some examples of more advanced customizations.</p>
+<p>Instead of creating the <code>SVGGraphics2D</code> just by using the <code>Document</code> that will be used as a factory for creating the SVG elements, we can use the constructor that uses an <a href="../javadoc/org/apache/batik/svggen/SVGGeneratorContext.html">SVGGeneratorContext</a> instance. By providing your own <code>SVGGeneratorContext</code> instance, you will be able to do advanced customization. You will find below several examples of possible customizations.</p>
+<h2 id="have-your-own-comment-in-the-generated-svg-file-haveyourowncommentinthegeneratedsvgfile">Have your own comment in the generated SVG file ## {#Have+your+own+comment+in+the+generated+SVG+file}</h2>
+<p>We begin with the simplest possible example. If you integrate the Batik SVG generator in your own Java application, you may want to specialize the comment generated in the XML code.
+DOMImplementation impl =
+    GenericDOMImplementation.getDOMImplementation();
+String svgNS = "http://www.w3.org/2000/svg";
+Document myFactory = impl.createDocument(svgNS, "svg", null);</p>
+<p>SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(myFactory);
+ctx.setComment("Generated by FooApplication with Batik SVG Generator");
+SVGGraphics2D g2d = new SVGGraphics2D(ctx, false);</p>
+<h2 id="use-embedded-svg-fonts-in-the-generated-svg-file-useembeddedsvgfontsinthegeneratedsvgfile">Use embedded SVG Fonts in the generated SVG file ## {#Use+embedded+SVG+Fonts+in+the+generated+SVG+file}</h2>
+<p>In order to have a self-contained SVG file that doesn't have to use system fonts to be displayed, you can embed the fonts you used for drawing strings in the SVG file through the SVG fonts facility.
+DOMImplementation impl =
+    GenericDOMImplementation.getDOMImplementation();
+String svgNS = "http://www.w3.org/2000/svg";
+Document myFactory = impl.createDocument(svgNS, "svg", null);</p>
+<p>SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(myFactory);
+ctx.setEmbeddedFontsOn(true);
+SVGGraphics2D g2d = new SVGGraphics2D(ctx, true);</p>
+<h2 id="customizing-the-way-images-are-stored-customizingthewayimagesarestored">Customizing the way images are stored ## {#Customizing+the+way+images+are+stored}</h2>
+<p>Every time you call one of the <code>drawImage</code> methods provided by the <code>Graphics2D</code> interface, a default representation of your image is created in a location and put in a default file. For instance, a base64 encoding is created and embedded in the SVG file by default. Alternatively, you can choose to have your images written to separate files in a predefined directory, in one of the two raster formats required by the SVG specification: JPEG or PNG.</p>
+<p>You can change the default behavior by explicitly providing the image handler to be used by the SVG generator. Once again, you use the <code>SVGGeneratorContext</code> for this. In the example below, all images are converted to PNG format and written to directory <code>res/images</code> .
+DOMImplementation impl =
+    GenericDOMImplementation.getDOMImplementation();
+String svgNS = "http://www.w3.org/2000/svg";
+Document myFactory = impl.createDocument(svgNS, "svg", null);</p>
+<p>SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(myFactory);
+GenericImageHandler ihandler = new ImageHandlerPNGEncoder("res/images", null);
+ctx.setImageHandler(ihandler);
+SVGGraphics2D g2d = new SVGGraphics2D(ctx, false);
+Using the default image handlers results in a new copy of the image data being written to the SVG file or an external file, for every single <code>drawImage</code> call. If you use the same images over and over again, then this may result in an SVG file containing a lot of redundant data. At the price of a slight performance penalty during initial generation of the SVG DOM tree, you can choose to have your image data reused. For this you use a specialized image handler, as shown below.
+DOMImplementation impl =
+    GenericDOMImplementation.getDOMImplementation();
+String svgNS = "http://www.w3.org/2000/svg";
+Document myFactory = impl.createDocument(svgNS, "svg", null);</p>
+<p>SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(myFactory);</p>
+<p>// Reuse our embedded base64-encoded image data.
+GenericImageHandler ihandler = new CachedImageHandlerBase64Encoder();
+ctx.setGenericImageHandler(ihandler);</p>
+<p>SVGGraphics2D g2d = new SVGGraphics2D(ctx, false);
+With the caching image handlers, it is even possible to reuse the same copy of your image data across several different SVG documents. Just keep a reference to the image handler, and pass it to the <code>SVGGraphics2D</code> instance used for generating the SVG DOM tree. The following simplified example shows how different SVG trees might be created by separate SVG generators, efficiently storing any common images just once.
+class MySVGGenerator {</p>
+<div class="codehilite"><pre><span class="sr">//</span> <span class="n">The</span> <span class="n">image</span> <span class="n">handler</span> <span class="n">will</span> <span class="nb">write</span> <span class="n">all</span> <span class="n">images</span> <span class="n">files</span> <span class="n">to</span> <span class="s">&quot;res/images&quot;</span><span class="o">.</span>
+<span class="n">private</span> <span class="n">static</span> <span class="n">ImageHandler</span> <span class="n">ihandler</span> <span class="o">=</span>
+    <span class="k">new</span> <span class="n">CachedImageHandlerPNGEncoder</span><span class="p">(</span><span class="s">&quot;res/images&quot;</span><span class="p">,</span> <span class="n">null</span><span class="p">);</span>
+
+<span class="n">public</span> <span class="n">void</span> <span class="n">generateSVG</span><span class="p">(</span><span class="n">JPanel</span> <span class="n">myCanvas</span><span class="p">,</span> <span class="n">OutputStream</span> <span class="n">outStream</span><span class="p">)</span> <span class="p">{</span>
+    <span class="n">DOMImplementation</span> <span class="n">domImpl</span> <span class="o">=</span>
+        <span class="n">GenericDOMImplementation</span><span class="o">.</span><span class="n">getDOMImplementation</span><span class="p">();</span>
+    <span class="n">Document</span> <span class="n">myFactory</span> <span class="o">=</span> <span class="n">domImpl</span><span class="o">.</span><span class="n">createDocument</span><span class="p">(</span><span class="n">svgNS</span><span class="p">,</span> <span class="s">&quot;svg&quot;</span><span class="p">,</span> <span class="n">null</span><span class="p">);</span>
+    <span class="n">SVGGeneratorContext</span> <span class="n">ctx</span> <span class="o">=</span>
+        <span class="n">SVGGeneratorContext</span><span class="o">.</span><span class="n">createDefault</span><span class="p">(</span><span class="n">myFactory</span><span class="p">);</span>
+    <span class="n">ctx</span><span class="o">.</span><span class="n">setGenericImageHandler</span><span class="p">(</span><span class="n">ihandler</span><span class="p">);</span>
+
+    <span class="n">SVGGraphics2D</span> <span class="n">svgGenerator</span> <span class="o">=</span> <span class="k">new</span> <span class="n">SVGGraphics2D</span><span class="p">(</span><span class="n">ctx</span><span class="p">,</span> <span class="n">false</span><span class="p">);</span>
+
+    <span class="sr">//</span> <span class="n">Create</span> <span class="n">the</span> <span class="n">SVG</span> <span class="n">DOM</span> <span class="n">tree</span><span class="o">.</span>
+    <span class="n">myCanvas</span><span class="o">.</span><span class="n">paintComponent</span><span class="p">(</span><span class="n">svgGenerator</span><span class="p">);</span>
+
+    <span class="n">Writer</span> <span class="n">out</span> <span class="o">=</span> <span class="k">new</span> <span class="n">OutputStreamWriter</span><span class="p">(</span><span class="n">outStream</span><span class="p">,</span> <span class="s">&quot;UTF-8&quot;</span><span class="p">);</span>
+    <span class="n">svgGenerator</span><span class="o">.</span><span class="n">stream</span><span class="p">(</span><span class="n">out</span><span class="p">,</span> <span class="n">true</span><span class="p">);</span>
+<span class="p">}</span>
+</pre></div>
+
+
+<p>}</p>
+<h2 id="customizing-the-generated-svg-style-customizingthegeneratedsvgstyle">Customizing the generated SVG style ## {#Customizing+the+generated+SVG+style}</h2>
+<p>Your needs in matter of styling may be different from the two provided options (XML presentation attributes or CSS inline stylesheets). For example, you may want to put the CSS properties in a SVG <code>style</code> element section and reference them through the class attribute. In this case you will need to define a new <a href="../javadoc/org/apache/batik/svggen/StyleHandler.html">StyleHandler</a> as below.
+public class StyleSheetStyleHandler implements StyleHandler {</p>
+<div class="codehilite"><pre><span class="sr">//</span> <span class="n">The</span> <span class="n">CDATA</span> <span class="n">section</span> <span class="n">that</span> <span class="n">holds</span> <span class="n">the</span> <span class="n">CSS</span> <span class="n">stylesheet</span><span class="o">.</span>
+<span class="n">private</span> <span class="n">CDATASection</span> <span class="n">styleSheet</span><span class="p">;</span>
+
+<span class="sr">//</span> <span class="n">Build</span> <span class="n">the</span> <span class="n">handler</span> <span class="n">with</span> <span class="n">a</span> <span class="n">reference</span> <span class="n">to</span> <span class="n">the</span> <span class="n">stylesheet</span> <span class="n">section</span><span class="o">.</span>
+<span class="n">public</span> <span class="n">StyleSheetStyleHandler</span><span class="p">(</span><span class="n">CDATASection</span> <span class="n">styleSheet</span><span class="p">)</span> <span class="p">{</span>
+    <span class="n">this</span><span class="o">.</span><span class="n">styleSheet</span> <span class="o">=</span> <span class="n">styleSheet</span><span class="p">;</span>
+<span class="p">}</span>
+
+<span class="n">public</span> <span class="n">void</span> <span class="n">setStyle</span><span class="p">(</span><span class="n">Element</span> <span class="n">element</span><span class="p">,</span> <span class="n">Map</span> <span class="n">styleMap</span><span class="p">,</span>
+                     <span class="n">SVGGeneratorContext</span> <span class="n">generatorContext</span><span class="p">)</span> <span class="p">{</span>
+    <span class="n">Iterator</span> <span class="n">iter</span> <span class="o">=</span> <span class="n">styleMap</span><span class="o">.</span><span class="n">keySet</span><span class="p">()</span><span class="o">.</span><span class="n">iterator</span><span class="p">();</span>
+
+    <span class="sr">//</span> <span class="n">Create</span> <span class="n">a</span> <span class="k">new</span> <span class="n">class</span> <span class="n">in</span> <span class="n">the</span> <span class="n">style</span> <span class="n">sheet</span><span class="o">.</span>
+    <span class="n">String</span> <span class="n">id</span> <span class="o">=</span> <span class="n">generatorContext</span><span class="o">.</span><span class="n">getIDGenerator</span><span class="p">()</span><span class="o">.</span><span class="n">generateID</span><span class="p">(</span><span class="s">&quot;C&quot;</span><span class="p">);</span>
+    <span class="n">styleSheet</span><span class="o">.</span><span class="n">appendData</span><span class="p">(</span><span class="s">&quot;.&quot;</span><span class="o">+</span> <span class="n">id</span> <span class="o">+</span><span class="s">&quot; {&quot;</span><span class="p">);</span>
+
+    <span class="sr">//</span> <span class="n">Append</span> <span class="nb">each</span> <span class="n">key</span><span class="o">/</span><span class="n">value</span> <span class="n">pair</span><span class="o">.</span>
+    <span class="k">while</span> <span class="p">(</span><span class="n">iter</span><span class="o">.</span><span class="n">hasNext</span><span class="p">())</span> <span class="p">{</span>
+        <span class="n">String</span> <span class="n">key</span> <span class="o">=</span> <span class="p">(</span><span class="n">String</span><span class="p">)</span> <span class="n">iter</span><span class="o">.</span><span class="k">next</span><span class="p">();</span>
+        <span class="n">String</span> <span class="n">value</span> <span class="o">=</span> <span class="p">(</span><span class="n">String</span><span class="p">)</span> <span class="n">styleMap</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">key</span><span class="p">);</span>
+        <span class="n">styleSheet</span><span class="o">.</span><span class="n">appendData</span><span class="p">(</span><span class="n">key</span> <span class="o">+</span> <span class="s">&quot;:&quot;</span> <span class="o">+</span> <span class="n">value</span> <span class="o">+</span> <span class="s">&quot;;&quot;</span><span class="p">);</span>
+    <span class="p">}</span>
+
+    <span class="n">styleSheet</span><span class="o">.</span><span class="n">appendData</span><span class="p">(</span><span class="s">&quot;}\n&quot;</span><span class="p">);</span>
+
+    <span class="sr">//</span> <span class="n">Reference</span> <span class="n">the</span> <span class="n">stylesheet</span> <span class="n">class</span> <span class="n">on</span> <span class="n">the</span> <span class="n">element</span> <span class="n">to</span> <span class="n">be</span> <span class="n">styled</span><span class="o">.</span>
+    <span class="n">element</span><span class="o">.</span><span class="n">setAttributeNS</span><span class="p">(</span><span class="n">null</span><span class="p">,</span> <span class="s">&quot;class&quot;</span><span class="p">,</span> <span class="n">id</span><span class="p">);</span>
+<span class="p">}</span>
+</pre></div>
+
+
+<p>}
+Then you can create and use an <code>SVGGraphics2D</code> with a correctly configured <code>SVGGeneratorContext</code> .</p>
+<p>// Configure the SVGGraphics2D for a given Document myFactory.
+SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(myFactory);
+CDATASection styleSheet = myFactory.createCDATASection("");
+ctx.setStyleHandler(new StyleSheetStyleHandler(styleSheet));
+SVGGraphics2D g2d = new SVGGraphics2D(ctx, false);</p>
+<p>// Use the g2d to draw (e.g., component.paint(g2d)).</p>
+<p>// Add a stylesheet to the definition section.
+SVGSVGElement root = (SVGSVGElement) g2d.getRoot();
+Element defs = root.getElementById(SVGSyntax.ID_PREFIX_GENERIC_DEFS);
+Element style = myFactory.createElementNS
+    (SVGSyntax.SVG_NAMESPACE_URI, SVGSyntax.SVG_STYLE_TAG);
+style.setAttributeNS(null, SVGSyntax.SVG_TYPE_ATTRIBUTE, "text/css");
+style.appendChild(styleSheet);
+defs.appendChild(style);</p>
+<p>// Dump the root content to a given Writer myWriter.
+g2d.stream(root, myWriter);</p>
+<h2 id="extending-paint-object-to-svg-element-translation-extendingpaintobjecttosvgelementtranslation">Extending Paint object to SVG element translation ## {#Extending+Paint+object+to+SVG+element+translation}</h2>
+<p>The <code>SVGGraphics2D</code> is able to generate SVG elements for generic Java 2D objects, but you sometimes have your own classes such as implementations of the Java 2D <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Paint.html">Paint</a> interface. In this case, you will need to write an <a href="../javadoc/org/apache/batik/svggen/ExtensionHandler.html">ExtensionHandler</a> that you will set on your <code>SVGGeneratorContext</code> .</p>
+<p>In the following example we define the first draft of an <code>ExtensionHandler</code> allowing to translate a Batik implementation of the <code>Paint</code> interface named <a href="../javadoc/org/apache/batik/ext/awt/LinearGradientPaint.html">LinearGradientPaint</a> .
+class MyExtensionHandler extends DefaultExtensionHandler {</p>
+<div class="codehilite"><pre><span class="n">public</span> <span class="n">SVGPaintDescriptor</span> <span class="n">handlePaint</span><span class="p">(</span><span class="n">Paint</span> <span class="n">paint</span><span class="p">,</span>
+                                      <span class="n">SVGGeneratorContext</span> <span class="n">generatorCtx</span><span class="p">)</span> <span class="p">{</span>
+    <span class="k">if</span> <span class="p">(</span><span class="n">paint</span> <span class="n">instanceof</span> <span class="n">LinearGradientPaint</span><span class="p">)</span> <span class="p">{</span>
+        <span class="n">LinearGradientPaint</span> <span class="n">gradient</span> <span class="o">=</span> <span class="p">(</span><span class="n">LinearGradientPaint</span><span class="p">)</span> <span class="n">paint</span><span class="p">;</span>
+
+        <span class="sr">//</span> <span class="n">Create</span> <span class="n">a</span> <span class="k">new</span> <span class="n">SVG</span> <span class="s">&#39;linearGradient&#39;</span> <span class="n">element</span> <span class="n">to</span> <span class="n">represent</span> <span class="n">the</span>
+        <span class="sr">//</span> <span class="n">LinearGradientPaint</span> <span class="n">being</span> <span class="n">used</span><span class="o">.</span>
+        <span class="n">String</span> <span class="n">id</span> <span class="o">=</span> <span class="n">generatorCtx</span><span class="o">.</span><span class="n">getIDGenerator</span><span class="p">()</span><span class="o">.</span><span class="n">generateID</span><span class="p">(</span><span class="s">&quot;gradient&quot;</span><span class="p">);</span>
+        <span class="n">Document</span> <span class="n">doc</span> <span class="o">=</span> <span class="n">generatorCtx</span><span class="o">.</span><span class="n">getDOMFactory</span><span class="p">();</span>
+        <span class="n">Element</span> <span class="n">grad</span> <span class="o">=</span> <span class="n">doc</span><span class="o">.</span><span class="n">createElementNS</span>
+            <span class="p">(</span><span class="n">SVGSyntax</span><span class="o">.</span><span class="n">SVG_NAMESPACE_URI</span><span class="p">,</span>
+             <span class="n">SVGSyntax</span><span class="o">.</span><span class="n">SVG_LINEAR_GRADIENT_TAG</span><span class="p">);</span>
+
+        <span class="sr">//</span> <span class="n">Set</span> <span class="n">the</span> <span class="n">relevant</span> <span class="n">attributes</span> <span class="n">on</span> <span class="n">the</span> <span class="s">&#39;linearGradient&#39;</span> <span class="n">element</span><span class="o">.</span>
+        <span class="n">grad</span><span class="o">.</span><span class="n">setAttributeNS</span><span class="p">(</span><span class="n">null</span><span class="p">,</span> <span class="n">SVGSyntax</span><span class="o">.</span><span class="n">SVG_ID_ATTRIBUTE</span><span class="p">,</span> <span class="n">id</span><span class="p">);</span>
+        <span class="n">grad</span><span class="o">.</span><span class="n">setAttributeNS</span><span class="p">(</span><span class="n">null</span><span class="p">,</span> <span class="n">SVGSyntax</span><span class="o">.</span><span class="n">SVG_GRADIENT_UNITS_ATTRIBUTE</span><span class="p">,</span>
+                            <span class="n">SVGSyntax</span><span class="o">.</span><span class="n">SVG_USER_SPACE_ON_USE_VALUE</span><span class="p">);</span>
+        <span class="n">Point2D</span> <span class="n">pt</span> <span class="o">=</span> <span class="n">gradient</span><span class="o">.</span><span class="n">getStartPoint</span><span class="p">();</span>
+        <span class="n">grad</span><span class="o">.</span><span class="n">setAttributeNS</span><span class="p">(</span><span class="n">null</span><span class="p">,</span> <span class="s">&quot;x1&quot;</span><span class="p">,</span> <span class="n">pt</span><span class="o">.</span><span class="n">getX</span><span class="p">());</span>
+        <span class="n">grad</span><span class="o">.</span><span class="n">setAttributeNS</span><span class="p">(</span><span class="n">null</span><span class="p">,</span> <span class="s">&quot;y1&quot;</span><span class="p">,</span> <span class="n">pt</span><span class="o">.</span><span class="n">getY</span><span class="p">());</span>
+        <span class="n">pt</span> <span class="o">=</span> <span class="n">gradient</span><span class="o">.</span><span class="n">getEndPoint</span><span class="p">();</span>
+        <span class="n">grad</span><span class="o">.</span><span class="n">setAttributeNS</span><span class="p">(</span><span class="n">null</span><span class="p">,</span> <span class="s">&quot;x2&quot;</span><span class="p">,</span> <span class="n">pt</span><span class="o">.</span><span class="n">getX</span><span class="p">());</span>
+        <span class="n">grad</span><span class="o">.</span><span class="n">setAttributeNS</span><span class="p">(</span><span class="n">null</span><span class="p">,</span> <span class="s">&quot;y2&quot;</span><span class="p">,</span> <span class="n">pt</span><span class="o">.</span><span class="n">getY</span><span class="p">());</span>
+
+        <span class="n">switch</span> <span class="p">(</span><span class="n">gradient</span><span class="o">.</span><span class="n">getCycleMethod</span><span class="p">())</span> <span class="p">{</span>
+        <span class="k">case</span> <span class="n">MultipleGradientPaint</span><span class="o">.</span><span class="n">REFLECT:</span>
+            <span class="n">grad</span><span class="o">.</span><span class="n">setAttributeNS</span>
+                <span class="p">(</span><span class="n">null</span><span class="p">,</span> <span class="n">SVGSyntax</span><span class="o">.</span><span class="n">SVG_SPREAD_METHOD_ATTRIBUTE</span><span class="p">,</span>
+                 <span class="n">SVGSyntax</span><span class="o">.</span><span class="n">SVG_REFLECT_VALUE</span><span class="p">);</span>
+            <span class="n">break</span><span class="p">;</span>
+        <span class="k">case</span> <span class="n">MultipleGradientPaint</span><span class="o">.</span><span class="n">REPEAT:</span>
+            <span class="n">grad</span><span class="o">.</span><span class="n">setAttributeNS</span>
+                <span class="p">(</span><span class="n">null</span><span class="p">,</span> <span class="n">SVGSyntax</span><span class="o">.</span><span class="n">SVG_SPREAD_METHOD_ATTRIBUTE</span><span class="p">,</span>
+                 <span class="n">SVGSyntax</span><span class="o">.</span><span class="n">SVG_REPEAT_VALUE</span><span class="p">);</span>
+            <span class="n">break</span><span class="p">;</span>
+        <span class="sr">//</span> <span class="s">&#39;pad&#39;</span> <span class="n">is</span> <span class="n">the</span> <span class="n">default</span><span class="o">...</span>
+        <span class="p">}</span>
+
+        <span class="sr">//</span> <span class="n">Here</span> <span class="n">we</span> <span class="n">should</span> <span class="nb">write</span> <span class="n">the</span> <span class="n">transform</span> <span class="n">of</span> <span class="n">the</span> <span class="n">gradient</span>
+        <span class="sr">//</span> <span class="n">in</span> <span class="n">the</span> <span class="n">transform</span> <span class="n">attribute</span><span class="o">...</span>
+
+        <span class="sr">//</span> <span class="n">Here</span> <span class="n">we</span> <span class="n">should</span> <span class="nb">write</span> <span class="n">the</span> <span class="n">stops</span> <span class="n">of</span> <span class="n">the</span> <span class="n">gradients</span> <span class="n">as</span> 
+        <span class="sr">//</span> <span class="n">children</span> <span class="n">elements</span><span class="o">...</span>
+
+        <span class="k">return</span> <span class="k">new</span> <span class="n">SVGPaintDescriptor</span>
+            <span class="p">(</span><span class="s">&quot;url(#&quot;</span> <span class="o">+</span> <span class="nb">ref</span> <span class="o">+</span> <span class="s">&quot;)&quot;</span><span class="p">,</span> <span class="n">SVGSyntax</span><span class="o">.</span><span class="n">SVG_OPAQUE_VALUE</span><span class="p">,</span> <span class="n">grad</span><span class="p">);</span>
+    <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
+        <span class="sr">//</span> <span class="n">Let</span> <span class="n">the</span> <span class="n">default</span> <span class="n">mechanism</span> <span class="k">do</span> <span class="n">its</span> <span class="n">job</span><span class="o">.</span>
+        <span class="k">return</span> <span class="n">null</span><span class="p">;</span>
+    <span class="p">}</span>
+<span class="p">}</span>
+</pre></div>
+
+
+<p>}
+You should then set it on the <code>SVGGeneratorContext</code> by using the <code>setExtensionHandler</code> method.
+SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(myFactory);
+ctx.setExtensionHandler(new MyExtensionHandler());
+SVGGraphics2D g2d = new SVGGraphics2D(ctx, false);</p>
+<h1 id="view">How to view the generated SVG document</h1>
+<p>The following code example illustrates how to view the SVG content generated by an <code>SVGGraphics2D</code> object.
+import java.awt.<em>;
+import java.awt.geom.</em>;</p>
+<p>import javax.swing.*;</p>
+<p>import org.apache.batik.swing.<em>;
+import org.apache.batik.svggen.</em>;
+import org.apache.batik.dom.svg.SVGDOMImplementation;</p>
+<p>import org.w3c.dom.<em>;
+import org.w3c.dom.svg.</em>;</p>
+<p>public class ViewGeneratedSVGDemo {</p>
+<div class="codehilite"><pre><span class="n">public</span> <span class="n">static</span> <span class="n">void</span> <span class="n">main</span><span class="p">(</span><span class="n">String</span><span class="o">[]</span> <span class="n">args</span><span class="p">)</span> <span class="p">{</span>
+    <span class="sr">//</span> <span class="n">Create</span> <span class="n">an</span> <span class="n">SVG</span> <span class="n">document</span><span class="o">.</span>
+    <span class="n">DOMImplementation</span> <span class="n">impl</span> <span class="o">=</span> <span class="n">SVGDOMImplementation</span><span class="o">.</span><span class="n">getDOMImplementation</span><span class="p">();</span>
+    <span class="n">String</span> <span class="n">svgNS</span> <span class="o">=</span> <span class="n">SVGDOMImplementation</span><span class="o">.</span><span class="n">SVG_NAMESPACE_URI</span><span class="p">;</span>
+    <span class="n">SVGDocument</span> <span class="n">doc</span> <span class="o">=</span> <span class="p">(</span><span class="n">SVGDocument</span><span class="p">)</span> <span class="n">impl</span><span class="o">.</span><span class="n">createDocument</span><span class="p">(</span><span class="n">svgNS</span><span class="p">,</span> <span class="s">&quot;svg&quot;</span><span class="p">,</span> <span class="n">null</span><span class="p">);</span>
+
+    <span class="sr">//</span> <span class="n">Create</span> <span class="n">a</span> <span class="n">converter</span> <span class="k">for</span> <span class="n">this</span> <span class="n">document</span><span class="o">.</span>
+    <span class="n">SVGGraphics2D</span> <span class="n">g</span> <span class="o">=</span> <span class="k">new</span> <span class="n">SVGGraphics2D</span><span class="p">(</span><span class="n">doc</span><span class="p">);</span>
+
+    <span class="sr">//</span> <span class="n">Do</span> <span class="n">some</span> <span class="n">drawing</span><span class="o">.</span>
+    <span class="n">Shape</span> <span class="n">circle</span> <span class="o">=</span> <span class="k">new</span> <span class="n">Ellipse2D</span><span class="o">.</span><span class="n">Double</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">50</span><span class="p">,</span> <span class="mi">50</span><span class="p">);</span>
+    <span class="n">g</span><span class="o">.</span><span class="n">setPaint</span><span class="p">(</span><span class="n">Color</span><span class="o">.</span><span class="n">red</span><span class="p">);</span>
+    <span class="n">g</span><span class="o">.</span><span class="n">fill</span><span class="p">(</span><span class="n">circle</span><span class="p">);</span>
+    <span class="n">g</span><span class="o">.</span><span class="n">translate</span><span class="p">(</span><span class="mi">60</span><span class="p">,</span> <span class="mi">0</span><span class="p">);</span>
+    <span class="n">g</span><span class="o">.</span><span class="n">setPaint</span><span class="p">(</span><span class="n">Color</span><span class="o">.</span><span class="n">green</span><span class="p">);</span>
+    <span class="n">g</span><span class="o">.</span><span class="n">fill</span><span class="p">(</span><span class="n">circle</span><span class="p">);</span>
+    <span class="n">g</span><span class="o">.</span><span class="n">translate</span><span class="p">(</span><span class="mi">60</span><span class="p">,</span> <span class="mi">0</span><span class="p">);</span>
+    <span class="n">g</span><span class="o">.</span><span class="n">setPaint</span><span class="p">(</span><span class="n">Color</span><span class="o">.</span><span class="n">blue</span><span class="p">);</span>
+    <span class="n">g</span><span class="o">.</span><span class="n">fill</span><span class="p">(</span><span class="n">circle</span><span class="p">);</span>
+    <span class="n">g</span><span class="o">.</span><span class="n">setSVGCanvasSize</span><span class="p">(</span><span class="k">new</span> <span class="n">Dimension</span><span class="p">(</span><span class="mi">180</span><span class="p">,</span> <span class="mi">50</span><span class="p">));</span>
+
+    <span class="sr">//</span> <span class="n">Populate</span> <span class="n">the</span> <span class="n">document</span> <span class="n">root</span> <span class="n">with</span> <span class="n">the</span> <span class="n">generated</span> <span class="n">SVG</span> <span class="n">content</span><span class="o">.</span>
+    <span class="n">Element</span> <span class="n">root</span> <span class="o">=</span> <span class="n">doc</span><span class="o">.</span><span class="n">getDocumentElement</span><span class="p">();</span>
+    <span class="n">g</span><span class="o">.</span><span class="n">getRoot</span><span class="p">(</span><span class="n">root</span><span class="p">);</span>
+
+    <span class="sr">//</span> <span class="n">Display</span> <span class="n">the</span> <span class="n">document</span><span class="o">.</span>
+    <span class="n">JSVGCanvas</span> <span class="n">canvas</span> <span class="o">=</span> <span class="k">new</span> <span class="n">JSVGCanvas</span><span class="p">();</span>
+    <span class="n">JFrame</span> <span class="n">f</span> <span class="o">=</span> <span class="k">new</span> <span class="n">JFrame</span><span class="p">();</span>
+    <span class="n">f</span><span class="o">.</span><span class="n">getContentPane</span><span class="p">()</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">canvas</span><span class="p">);</span>
+    <span class="n">canvas</span><span class="o">.</span><span class="n">setSVGDocument</span><span class="p">(</span><span class="n">doc</span><span class="p">);</span>
+    <span class="n">f</span><span class="o">.</span><span class="nb">pack</span><span class="p">();</span>
+    <span class="n">f</span><span class="o">.</span><span class="n">setVisible</span><span class="p">(</span><span class="n">true</span><span class="p">);</span>
+<span class="p">}</span>
+</pre></div>
+
+
+<p>}</p></div></div>
+      <div class="clear"></div>
+
+	  <div id="footer">
+		<a alt="Apache Software Foundation" href="http://www.apache.org">
+		  <img id="asf-logo" alt="Apache Software Foundation" src="/images/feather-small.gif"/ width="100">
+		</a>
+		<div class="copyright">
+		  <p>
+			Copyright &copy; 2011 The Apache Software Foundation, Licensed under
+			the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.
+			<br />
+			Apache, Apache XML Graphics, the Apache feather logo, and the Apache XML Graphics logos are
+			trademarks of <a href="http://www.apache.org">The Apache Software Foundation</a>. All other
+			marks mentioned may be trademarks or registered trademarks of their respective owners.
+			<br />
+		  </p>
+		</div> 
+	  </div>
+  </body>
+</html>

Added: websites/staging/xmlgraphics/trunk/content/batik/using/swing.html
==============================================================================
--- websites/staging/xmlgraphics/trunk/content/batik/using/swing.html (added)
+++ websites/staging/xmlgraphics/trunk/content/batik/using/swing.html Sun Apr 15 05:46:22 2012
@@ -0,0 +1,213 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html lang="en">
+  <head>
+    <title>Batik Swing components</title>
+
+    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
+    <meta property="og:image" content="http://www.apache.org/images/asf_logo.gif" />
+<!--
+    <link rel="stylesheet" type="text/css" media="screen" href="http://www.apache.org/css/style.css">
+    <link rel="stylesheet" type="text/css" media="screen" href="http://www.apache.org/css/code.css">
+-->
+    <link href="/css/xmlgraphics.css" rel="stylesheet" type="text/css">
+
+    </style>
+
+    
+
+    
+    
+  </head>
+
+  <body>
+	  <div id="banner">&nbsp;
+	  </div>
+
+	  <div id="navigation">
+	  <h1 id="xml-graphics">XML Graphics</h1>
+<ul>
+<li><a href="/">Overview</a></li>
+<li><a href="/team.html">Who We Are</a></li>
+<li><a href="/legal.html">Legal Stuff</a></li>
+<li><a href="/charter.html">Project Charter</a></li>
+<li><a href="/mail.html">Mailing Lists</a></li>
+<li><a href="/repo.html">Code Repositories</a></li>
+<li><a href="http://www.apache.org/foundation/sponsorship.html">ASF Sponsorship Program</a></li>
+<li><a href="http://www.apache.org/foundation/thanks.html">ASF Thanks</a></li>
+</ul>
+<h1 id="subprojects">Subprojects</h1>
+<ul>
+<li><a href="/batik/">Batik</a></li>
+<li><a href="/fop/">FOP</a></li>
+<li><a href="/commons/">Commons</a></li>
+</ul>
+<form name="search" id="search" action="http://www.google.com/search" method="get">
+  <input value="xmlgraphics.apache.org" name="sitesearch" type="hidden"/>
+  <input type="text" name="q" id="query" /><br />
+  <input type="submit" id="submit" value="Search" />
+</form>
+	  </div>
+	
+	  <div id="bannertext">
+        <a href="/"><img src="/images/apache-xml-graphics.gif" alt="The Apache XML Graphics Project" width="220" heigh="51" /></a>
+        <h1>Batik Swing components</h1>
+      </div>
+        <p><a href="/">Home</a>&nbsp;&raquo&nbsp;<a href="/batik/">Batik</a>&nbsp;&raquo&nbsp;<a href="/batik/using/">Using</a></p>
+      </div>
+      <div id="content" class="grid_16"><div class="section-content"><p>The goal of the Batik Swing component module is to provide a Swing component that can used to display SVG documents. With the <a href="../javadoc/org/apache/batik/swing/JSVGCanvas.html">JSVGCanvas</a> class, you can easily display an SVG document (from a URI or a DOM tree) and allow the user to manipulate it, such as rotating, zooming, panning, selecting text or activating hyperlinks. First this document explains how to create a <code>JSVGCanvas</code> and integrate it in to a Swing application. Then, it descibes some advanced features such as the listener mechanism used to track all events that occurred while displaying or manipulating an SVG document.</p>
+<h1 id="creatingJSVGCanvas">Creating a JSVGCanvas</h1>
+<p>The following example illustrates how to create a <code>JSVGCanvas</code> , which is a Swing component that follows the Swing design rule. This means that the component is not thread safe and all operations on the component or the document it is displaying must be performed as described in <a href="http://java.sun.com/docs/books/tutorial/uiswing/overview/threads.html">the Swing tutorial</a> . The <code>JSVGCanvas</code> is also a <a href="http://java.sun.com/products/javabeans/">JavaBean</a> , so it can be used in visual application builders.
+If you try this example, do not forget to set your <code>CLASSPATH</code> so that it contains the Batik classes and resources, as well as Xerces ( <code>lib/xerces_2_5_0.jar</code> ) and the XML APIs jars ( <code>lib/xml-apis.jar</code> and <code>lib/xml-apis-ext.jar</code> ).import java.awt.<em>;
+import java.awt.event.</em>;
+import java.io.*;</p>
+<p>import javax.swing.*;</p>
+<p>import org.apache.batik.swing.JSVGCanvas;
+import org.apache.batik.swing.gvt.GVTTreeRendererAdapter;
+import org.apache.batik.swing.gvt.GVTTreeRendererEvent;
+import org.apache.batik.swing.svg.SVGDocumentLoaderAdapter;
+import org.apache.batik.swing.svg.SVGDocumentLoaderEvent;
+import org.apache.batik.swing.svg.GVTTreeBuilderAdapter;
+import org.apache.batik.swing.svg.GVTTreeBuilderEvent;</p>
+<p>public class SVGApplication {</p>
+<div class="codehilite"><pre><span class="n">public</span> <span class="n">static</span> <span class="n">void</span> <span class="n">main</span><span class="p">(</span><span class="n">String</span><span class="o">[]</span> <span class="n">args</span><span class="p">)</span> <span class="p">{</span>
+    <span class="sr">//</span> <span class="n">Create</span> <span class="n">a</span> <span class="k">new</span> <span class="n">JFrame</span><span class="o">.</span>
+    <span class="n">JFrame</span> <span class="n">f</span> <span class="o">=</span> <span class="k">new</span> <span class="n">JFrame</span><span class="p">(</span><span class="s">&quot;Batik&quot;</span><span class="p">);</span>
+    <span class="n">SVGApplication</span> <span class="n">app</span> <span class="o">=</span> <span class="k">new</span> <span class="n">SVGApplication</span><span class="p">(</span><span class="n">f</span><span class="p">);</span>
+
+    <span class="sr">//</span> <span class="n">Add</span> <span class="n">components</span> <span class="n">to</span> <span class="n">the</span> <span class="n">frame</span><span class="o">.</span>
+    <span class="n">f</span><span class="o">.</span><span class="n">getContentPane</span><span class="p">()</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">app</span><span class="o">.</span><span class="n">createComponents</span><span class="p">());</span>
+
+    <span class="sr">//</span> <span class="n">Display</span> <span class="n">the</span> <span class="n">frame</span><span class="o">.</span>
+    <span class="n">f</span><span class="o">.</span><span class="n">addWindowListener</span><span class="p">(</span><span class="k">new</span> <span class="n">WindowAdapter</span><span class="p">()</span> <span class="p">{</span>
+        <span class="n">public</span> <span class="n">void</span> <span class="n">windowClosing</span><span class="p">(</span><span class="n">WindowEvent</span> <span class="n">e</span><span class="p">)</span> <span class="p">{</span>
+            <span class="n">System</span><span class="o">.</span><span class="nb">exit</span><span class="p">(</span><span class="mi">0</span><span class="p">);</span>
+        <span class="p">}</span>
+    <span class="p">});</span>
+    <span class="n">f</span><span class="o">.</span><span class="n">setSize</span><span class="p">(</span><span class="mi">400</span><span class="p">,</span> <span class="mi">400</span><span class="p">);</span>
+    <span class="n">f</span><span class="o">.</span><span class="n">setVisible</span><span class="p">(</span><span class="n">true</span><span class="p">);</span>
+<span class="p">}</span>
+
+<span class="sr">//</span> <span class="n">The</span> <span class="n">frame</span><span class="o">.</span>
+<span class="n">protected</span> <span class="n">JFrame</span> <span class="n">frame</span><span class="p">;</span>
+
+<span class="sr">//</span> <span class="n">The</span> <span class="s">&quot;Load&quot;</span> <span class="n">button</span><span class="p">,</span> <span class="n">which</span> <span class="n">displays</span> <span class="n">up</span> <span class="n">a</span> <span class="n">file</span> <span class="n">chooser</span> <span class="n">upon</span> <span class="n">clicking</span><span class="o">.</span>
+<span class="n">protected</span> <span class="n">JButton</span> <span class="n">button</span> <span class="o">=</span> <span class="k">new</span> <span class="n">JButton</span><span class="p">(</span><span class="s">&quot;Load...&quot;</span><span class="p">);</span>
+
+<span class="sr">//</span> <span class="n">The</span> <span class="n">status</span> <span class="n">label</span><span class="o">.</span>
+<span class="n">protected</span> <span class="n">JLabel</span> <span class="n">label</span> <span class="o">=</span> <span class="k">new</span> <span class="n">JLabel</span><span class="p">();</span>
+
+<span class="sr">//</span> <span class="n">The</span> <span class="n">SVG</span> <span class="n">canvas</span><span class="o">.</span>
+<span class="n">protected</span> <span class="n">JSVGCanvas</span> <span class="n">svgCanvas</span> <span class="o">=</span> <span class="k">new</span> <span class="n">JSVGCanvas</span><span class="p">();</span>
+
+<span class="n">public</span> <span class="n">SVGApplication</span><span class="p">(</span><span class="n">JFrame</span> <span class="n">f</span><span class="p">)</span> <span class="p">{</span>
+    <span class="n">frame</span> <span class="o">=</span> <span class="n">f</span><span class="p">;</span>
+<span class="p">}</span>
+
+<span class="n">public</span> <span class="n">JComponent</span> <span class="n">createComponents</span><span class="p">()</span> <span class="p">{</span>
+    <span class="sr">//</span> <span class="n">Create</span> <span class="n">a</span> <span class="n">panel</span> <span class="ow">and</span> <span class="n">add</span> <span class="n">the</span> <span class="n">button</span><span class="p">,</span> <span class="n">status</span> <span class="n">label</span> <span class="ow">and</span> <span class="n">the</span> <span class="n">SVG</span> <span class="n">canvas</span><span class="o">.</span>
+    <span class="n">final</span> <span class="n">JPanel</span> <span class="n">panel</span> <span class="o">=</span> <span class="k">new</span> <span class="n">JPanel</span><span class="p">(</span><span class="k">new</span> <span class="n">BorderLayout</span><span class="p">());</span>
+
+    <span class="n">JPanel</span> <span class="n">p</span> <span class="o">=</span> <span class="k">new</span> <span class="n">JPanel</span><span class="p">(</span><span class="k">new</span> <span class="n">FlowLayout</span><span class="p">(</span><span class="n">FlowLayout</span><span class="o">.</span><span class="n">LEFT</span><span class="p">));</span>
+    <span class="n">p</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">button</span><span class="p">);</span>
+    <span class="n">p</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">label</span><span class="p">);</span>
+
+    <span class="n">panel</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&quot;North&quot;</span><span class="p">,</span> <span class="n">p</span><span class="p">);</span>
+    <span class="n">panel</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&quot;Center&quot;</span><span class="p">,</span> <span class="n">svgCanvas</span><span class="p">);</span>
+
+    <span class="sr">//</span> <span class="n">Set</span> <span class="n">the</span> <span class="n">button</span> <span class="n">action</span><span class="o">.</span>
+    <span class="n">button</span><span class="o">.</span><span class="n">addActionListener</span><span class="p">(</span><span class="k">new</span> <span class="n">ActionListener</span><span class="p">()</span> <span class="p">{</span>
+        <span class="n">public</span> <span class="n">void</span> <span class="n">actionPerformed</span><span class="p">(</span><span class="n">ActionEvent</span> <span class="n">ae</span><span class="p">)</span> <span class="p">{</span>
+            <span class="n">JFileChooser</span> <span class="n">fc</span> <span class="o">=</span> <span class="k">new</span> <span class="n">JFileChooser</span><span class="p">(</span><span class="s">&quot;.&quot;</span><span class="p">);</span>
+            <span class="nb">int</span> <span class="n">choice</span> <span class="o">=</span> <span class="n">fc</span><span class="o">.</span><span class="n">showOpenDialog</span><span class="p">(</span><span class="n">panel</span><span class="p">);</span>
+            <span class="k">if</span> <span class="p">(</span><span class="n">choice</span> <span class="o">==</span> <span class="n">JFileChooser</span><span class="o">.</span><span class="n">APPROVE_OPTION</span><span class="p">)</span> <span class="p">{</span>
+                <span class="n">File</span> <span class="n">f</span> <span class="o">=</span> <span class="n">fc</span><span class="o">.</span><span class="n">getSelectedFile</span><span class="p">();</span>
+                <span class="n">try</span> <span class="p">{</span>
+                    <span class="n">svgCanvas</span><span class="o">.</span><span class="n">setURI</span><span class="p">(</span><span class="n">f</span><span class="o">.</span><span class="n">toURL</span><span class="p">()</span><span class="o">.</span><span class="n">toString</span><span class="p">());</span>
+                <span class="p">}</span> <span class="n">catch</span> <span class="p">(</span><span class="n">IOException</span> <span class="n">ex</span><span class="p">)</span> <span class="p">{</span>
+                    <span class="n">ex</span><span class="o">.</span><span class="n">printStackTrace</span><span class="p">();</span>
+                <span class="p">}</span>
+            <span class="p">}</span>
+        <span class="p">}</span>
+    <span class="p">});</span>
+
+    <span class="sr">//</span> <span class="n">Set</span> <span class="n">the</span> <span class="n">JSVGCanvas</span> <span class="n">listeners</span><span class="o">.</span>
+    <span class="n">svgCanvas</span><span class="o">.</span><span class="n">addSVGDocumentLoaderListener</span><span class="p">(</span><span class="k">new</span> <span class="n">SVGDocumentLoaderAdapter</span><span class="p">()</span> <span class="p">{</span>
+        <span class="n">public</span> <span class="n">void</span> <span class="n">documentLoadingStarted</span><span class="p">(</span><span class="n">SVGDocumentLoaderEvent</span> <span class="n">e</span><span class="p">)</span> <span class="p">{</span>
+            <span class="n">label</span><span class="o">.</span><span class="n">setText</span><span class="p">(</span><span class="s">&quot;Document Loading...&quot;</span><span class="p">);</span>
+        <span class="p">}</span>
+        <span class="n">public</span> <span class="n">void</span> <span class="n">documentLoadingCompleted</span><span class="p">(</span><span class="n">SVGDocumentLoaderEvent</span> <span class="n">e</span><span class="p">)</span> <span class="p">{</span>
+            <span class="n">label</span><span class="o">.</span><span class="n">setText</span><span class="p">(</span><span class="s">&quot;Document Loaded.&quot;</span><span class="p">);</span>
+        <span class="p">}</span>
+    <span class="p">});</span>
+
+    <span class="n">svgCanvas</span><span class="o">.</span><span class="n">addGVTTreeBuilderListener</span><span class="p">(</span><span class="k">new</span> <span class="n">GVTTreeBuilderAdapter</span><span class="p">()</span> <span class="p">{</span>
+        <span class="n">public</span> <span class="n">void</span> <span class="n">gvtBuildStarted</span><span class="p">(</span><span class="n">GVTTreeBuilderEvent</span> <span class="n">e</span><span class="p">)</span> <span class="p">{</span>
+            <span class="n">label</span><span class="o">.</span><span class="n">setText</span><span class="p">(</span><span class="s">&quot;Build Started...&quot;</span><span class="p">);</span>
+        <span class="p">}</span>
+        <span class="n">public</span> <span class="n">void</span> <span class="n">gvtBuildCompleted</span><span class="p">(</span><span class="n">GVTTreeBuilderEvent</span> <span class="n">e</span><span class="p">)</span> <span class="p">{</span>
+            <span class="n">label</span><span class="o">.</span><span class="n">setText</span><span class="p">(</span><span class="s">&quot;Build Done.&quot;</span><span class="p">);</span>
+            <span class="n">frame</span><span class="o">.</span><span class="nb">pack</span><span class="p">();</span>
+        <span class="p">}</span>
+    <span class="p">});</span>
+
+    <span class="n">svgCanvas</span><span class="o">.</span><span class="n">addGVTTreeRendererListener</span><span class="p">(</span><span class="k">new</span> <span class="n">GVTTreeRendererAdapter</span><span class="p">()</span> <span class="p">{</span>
+        <span class="n">public</span> <span class="n">void</span> <span class="n">gvtRenderingPrepare</span><span class="p">(</span><span class="n">GVTTreeRendererEvent</span> <span class="n">e</span><span class="p">)</span> <span class="p">{</span>
+            <span class="n">label</span><span class="o">.</span><span class="n">setText</span><span class="p">(</span><span class="s">&quot;Rendering Started...&quot;</span><span class="p">);</span>
+        <span class="p">}</span>
+        <span class="n">public</span> <span class="n">void</span> <span class="n">gvtRenderingCompleted</span><span class="p">(</span><span class="n">GVTTreeRendererEvent</span> <span class="n">e</span><span class="p">)</span> <span class="p">{</span>
+            <span class="n">label</span><span class="o">.</span><span class="n">setText</span><span class="p">(</span><span class="s">&quot;&quot;</span><span class="p">);</span>
+        <span class="p">}</span>
+    <span class="p">});</span>
+
+    <span class="k">return</span> <span class="n">panel</span><span class="p">;</span>
+<span class="p">}</span>
+</pre></div>
+
+
+<p>}<div class="figure"> <img alt="Screenshot of the example SVGApplication program" src="images/svgapplication.png" title="" /> </div></p>
+<h1 id="eventhandling">Handling events</h1>
+<p>Each time you set a URI or an SVG DOM tree to be displayed in a <code>JSVGCanvas</code> (using the <code>setURI</code> or <code>setSVGDocument</code> method), the specified document is first parsed (in case of a URI), built, rendered and optionally updated. The proper way to be notified of these different phases is to implement a listener and attach it to the component. There are five types of listener:</p>
+<dl>
+<dt><code>SVGDocumentLoaderListener</code></dt>
+<dd>The <a href="../javadoc/org/apache/batik/swing/svg/SVGDocumentLoaderListener">SVGDocumentLoaderListener</a> provides a set of methods that can be used to track <a href="../javadoc/org/apache/batik/swing/svg/SVGDocumentLoaderEvent">SVGDocumentLoaderEvent</a> events. It describes the loading phase: contructing an SVG DOM tree using an SVG file.</dd>
+<dt><code>GVTTreeBuilderListener</code></dt>
+<dd>The <a href="../javadoc/org/apache/batik/swing/svg/GVTTreeBuilderListener">GVTTreeBuilderListener</a> provides a set of methods that can be used to track <a href="../javadoc/org/apache/batik/swing/svg/GVTTreeBuilderEvent">GVTTreeBuilderEvent</a> events. It describes the building phase: contructing a GVT (Graphics Vector Toolkit) tree using an SVG DOM tree. The GVT tree will then be used to render the document.</dd>
+<dt><code>SVGLoadEventDispatcherListener</code></dt>
+<dd>The <a href="../javadoc/org/apache/batik/swing/svg/SVGLoadEventDispatcherListener">SVGLoadEventDispatcherListener</a> provides a set of methods that can be used to track <a href="../javadoc/org/apache/batik/swing/svg/SVGLoadEventDispatcherEvent">SVGLoadEventDispatcherEvent</a> events. It describes the DOM <code>SVGLoad</code> event dispatch phase.</dd>
+</dl>
+<p>This event is triggered only in dynamic documents.</p>
+<dl>
+<dt><code>GVTTreeRendererListener</code></dt>
+<dd>The <a href="../javadoc/org/apache/batik/swing/gvt/GVTTreeRendererListener.html">GVTTreeRendererListener</a> provides a set of methods that can be used to track <a href="../javadoc/org/apache/batik/swing/gvt/GVTTreeRendererEvent.html">GVTTreeRendererEvent</a> events. It describes the rendering phase: constructing an image using a GVT tree.</dd>
+</dl>
+<p>In dynamic documents this event is fired only once for the initial rendering.</p>
+<dl>
+<dt><code>UpdateManagerListener</code></dt>
+<dd>The <a href="../javadoc/org/apache/batik/bridge/UpdateManagerListener">UpdateManagerListener</a> provides a set of methods that can be used to track <a href="../javadoc/org/apache/batik/bridge/UpdateManagerEvent">UpdateManagerEvent</a> events. It describes the running phase: the update manager is started and then it can be suspended, resumed or stopped, and graphics updates can be tracked.</dd>
+</dl>
+<p>This event is triggered only in dynamic documents.</p>
+<p>These listeners give a complete description of the different steps of the five phases (including error states). Adapter classes are available to ease the creation of new listener implementation— <a href="../javadoc/org/apache/batik/swing/svg/SVGDocumentLoaderAdapter.html">SVGDocumentLoaderAdapter</a> , <a href="../javadoc/org/apache/batik/swing/svg/GVTTreeBuilderListenerAdapter.html">GVTTreeBuilderListenerAdapter</a> , <a href="../javadoc/org/apache/batik/swing/svg/SVGLoadEventDispatcherAdapter.html">SVGLoadEventDispatcherAdapter</a> , <a href="../javadoc/org/apache/batik/swing/gvt/GVTTreeRendererAdapter.html">GVTTreeRendererAdapter</a> and <a href="../javadoc/org/apache/batik/bridge/UpdateManagerAdapter.html">UpdateManagerAdapter</a> ,</p>
+<p>For static documents, you can assume that the JSVGCanvas has completed its job (parsing, building and rendering) when the <code>gvtRenderingCompleted</code> method call is called, following a <code>setURI</code> or a <code>setSVGDocument</code> method call.</p>
+<p>In the case of dynamic documents, the end of the computation (parsing, building, SVGLoad dispatch, initial rendering and updates) is marked by a call to the <code>updateManagerStopped</code> method.</p>
+<h1 id="interactor">Adding an Interactor</h1>
+<p>The <code>JSVGCanvas</code> provides a set of build-in interactors that let the users manipulate the displayed document, including ones for zooming, panning and rotating. Interactors catch user input to the <code>JSVGCanvas</code> component and translate them into behaviour. If you want to add new behaviors to the <code>JSVGCanvas</code> , you can implement the <a href="../javadoc/org/apache/batik/swing/gvt/Interactor.html">Interactor</a> interface. Then, you can register this new interactor to the component by adding an element to the <code>List</code> returned by the <code>getInteractors()</code> method of the canvas.</p></div></div>
+      <div class="clear"></div>
+
+	  <div id="footer">
+		<a alt="Apache Software Foundation" href="http://www.apache.org">
+		  <img id="asf-logo" alt="Apache Software Foundation" src="/images/feather-small.gif"/ width="100">
+		</a>
+		<div class="copyright">
+		  <p>
+			Copyright &copy; 2011 The Apache Software Foundation, Licensed under
+			the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.
+			<br />
+			Apache, Apache XML Graphics, the Apache feather logo, and the Apache XML Graphics logos are
+			trademarks of <a href="http://www.apache.org">The Apache Software Foundation</a>. All other
+			marks mentioned may be trademarks or registered trademarks of their respective owners.
+			<br />
+		  </p>
+		</div> 
+	  </div>
+  </body>
+</html>



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: commits-help@xmlgraphics.apache.org