Created
June 3, 2013 09:59
-
-
Save hoehrmann/5697227 to your computer and use it in GitHub Desktop.
The following is a very simple example using Batik to execute the onload scripts in a document and write the resulting document tree to stdout. Originally http://lists.w3.org/Archives/Public/www-archive/2005Mar/0030.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.OutputStreamWriter; | |
import org.w3c.dom.Document; | |
import org.apache.batik.bridge.BaseScriptingEnvironment; | |
import org.apache.batik.bridge.BridgeContext; | |
import org.apache.batik.bridge.GVTBuilder; | |
import org.apache.batik.bridge.UserAgentAdapter; | |
import org.apache.batik.transcoder.svg2svg.SVGTranscoder; | |
import org.apache.batik.transcoder.TranscoderInput; | |
import org.apache.batik.transcoder.TranscoderOutput; | |
import org.apache.batik.dom.svg.SAXSVGDocumentFactory; | |
import org.apache.batik.util.XMLResourceDescriptor; | |
public class BatikPostScriptPP | |
{ | |
void run() throws Exception | |
{ | |
String parser = XMLResourceDescriptor.getXMLParserClassName(); | |
SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser); | |
String uri = "http://..."; | |
Document doc = f.createDocument(uri); | |
UserAgentAdapter userAgent = new UserAgentAdapter(); | |
GVTBuilder builder = new GVTBuilder(); | |
BridgeContext ctx = new BridgeContext(userAgent); | |
ctx.setDynamic(true); | |
builder.build(ctx, doc); | |
BaseScriptingEnvironment scriptEnvironment | |
= new BaseScriptingEnvironment(ctx); | |
scriptEnvironment.loadScripts(); | |
scriptEnvironment.dispatchSVGLoadEvent(); | |
SVGTranscoder p = new SVGTranscoder(); | |
TranscoderInput in = new TranscoderInput(doc); | |
OutputStreamWriter ow = new OutputStreamWriter(System.out); | |
TranscoderOutput out = new TranscoderOutput(ow); | |
p.transcode(in, out); | |
} | |
public static void main(String[] args) throws Exception | |
{ | |
(new BatikPostScriptPP()).run(); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment