KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > transcoder > image > GenericDocumentTest


1 /*
2
3    Copyright 2003 The Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16
17  */

18 package org.apache.batik.transcoder.image;
19
20 import java.io.IOException JavaDoc;
21 import java.net.URL JavaDoc;
22
23 import org.w3c.dom.DOMImplementation JavaDoc;
24 import org.w3c.dom.Document JavaDoc;
25
26 import org.apache.batik.dom.GenericDOMImplementation;
27 import org.apache.batik.dom.util.SAXDocumentFactory;
28 import org.apache.batik.transcoder.TranscoderInput;
29 import org.apache.batik.util.XMLResourceDescriptor;
30
31 /**
32  * Test the ImageTranscoder input with a GenericDocument.
33  *
34  * @author <a HREF="mailto:Thierry.Kormann@sophia.inria.fr">Thierry Kormann</a>
35  * @version $Id: GenericDocumentTest.java,v 1.4 2004/08/18 07:17:12 vhardy Exp $
36  */

37 public class GenericDocumentTest extends AbstractImageTranscoderTest {
38
39     /** The URI of the input image. */
40     protected String JavaDoc inputURI;
41
42     /** The URI of the reference image. */
43     protected String JavaDoc refImageURI;
44
45     /**
46      * Constructs a new <tt>GenericDocumentTest</tt>.
47      *
48      * @param inputURI the URI of the input image
49      * @param the URI of the reference image
50      */

51     public GenericDocumentTest(String JavaDoc inputURI, String JavaDoc refImageURI) {
52     this.inputURI = inputURI;
53     this.refImageURI = refImageURI;
54     }
55
56     /**
57      * Creates the <tt>TranscoderInput</tt>.
58      */

59     protected TranscoderInput createTranscoderInput() {
60     try {
61         URL JavaDoc url = resolveURL(inputURI);
62             String JavaDoc parser = XMLResourceDescriptor.getXMLParserClassName();
63             DOMImplementation JavaDoc impl =
64                 GenericDOMImplementation.getDOMImplementation();
65             SAXDocumentFactory f = new SAXDocumentFactory(impl, parser);
66             Document JavaDoc doc = f.createDocument(url.toString());
67         TranscoderInput input = new TranscoderInput(doc);
68         input.setURI(url.toString()); // Needed for external resources
69
return input;
70     } catch (IOException JavaDoc ex) {
71             ex.printStackTrace();
72             throw new IllegalArgumentException JavaDoc(inputURI);
73     }
74     }
75
76     /**
77      * Returns the reference image for this test.
78      */

79     protected byte [] getReferenceImageData() {
80     return createBufferedImageData(resolveURL(refImageURI));
81     }
82 }
83
Popular Tags