KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > test > svg > PreconfiguredRenderingTest


1 /*
2
3    Copyright 2001,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.test.svg;
19
20 import java.io.File JavaDoc;
21
22 /**
23  * Convenience class for creating a SVGRenderingAccuracyTest with predefined
24  * rules for the various configuration parameters.
25  *
26  * @author <a HREF="mailto:vhardy@apache.org">Vincent Hardy</a>
27  * @version $Id: PreconfiguredRenderingTest.java,v 1.8 2005/03/27 08:58:37 cam Exp $
28  */

29 public abstract class PreconfiguredRenderingTest extends SVGRenderingAccuracyTest {
30     /**
31      * Generic constants
32      */

33     public static final String JavaDoc PNG_EXTENSION = ".png";
34
35     public static final String JavaDoc SVG_EXTENSION = ".svg";
36     public static final String JavaDoc SVGZ_EXTENSION = ".svgz";
37
38     public static final char PATH_SEPARATOR = '/';
39
40     /**
41      * For preconfigured tests, the configuration has to be
42      * derived from the test identifier. The identifier should
43      * characterize the SVG file to be tested.
44      */

45     public void setId(String JavaDoc id){
46         super.setId(id);
47         setFile(id);
48     }
49
50     public void setFile(String JavaDoc id) {
51         String JavaDoc svgFile = id;
52
53         String JavaDoc[] dirNfile = breakSVGFile(svgFile);
54
55         setConfig(buildSVGURL(dirNfile[0], dirNfile[1], dirNfile[2]),
56                   buildRefImgURL(dirNfile[0], dirNfile[1]));
57
58         setVariationURL(buildVariationURL(dirNfile[0], dirNfile[1]));
59         setSaveVariation(new File JavaDoc(buildSaveVariationFile(dirNfile[0], dirNfile[1])));
60         setCandidateReference(new File JavaDoc(buildCandidateReferenceFile(dirNfile[0],dirNfile[1])));
61     }
62
63     /**
64      * Make the name as simple as possible. For preconfigured SVG files,
65      * we use the test id, which is the relevant identifier for the test
66      * user.
67      */

68     public String JavaDoc getName(){
69         return getId();
70     }
71
72     /**
73      * Gives a chance to the subclass to prepend a prefix to the
74      * svgFile name.
75      * The svgURL is built as:
76      * getSVGURLPrefix() + svgDir + svgFile
77      */

78     protected String JavaDoc buildSVGURL(String JavaDoc svgDir, String JavaDoc svgFile, String JavaDoc svgExt){
79         return getSVGURLPrefix() + svgDir + svgFile + svgExt;
80     }
81
82     protected abstract String JavaDoc getSVGURLPrefix();
83
84     
85     /**
86      * Gives a chance to the subclass to control the construction
87      * of the reference PNG file from the svgFile name
88      * The refImgURL is built as:
89      * getRefImagePrefix() + svgDir + getRefImageSuffix() + svgFile
90      */

91     protected String JavaDoc buildRefImgURL(String JavaDoc svgDir, String JavaDoc svgFile){
92         return getRefImagePrefix() + svgDir + getRefImageSuffix() + svgFile + PNG_EXTENSION;
93     }
94
95     protected abstract String JavaDoc getRefImagePrefix();
96
97     protected abstract String JavaDoc getRefImageSuffix();
98
99     /**
100      * Gives a chance to the subclass to control the construction
101      * of the variation URL, which is built as:
102      * getVariationPrefix() + svgDir + getVariationSuffix() + svgFile + PNG_EXTENSION
103      */

104     public String JavaDoc buildVariationURL(String JavaDoc svgDir, String JavaDoc svgFile){
105         return getVariationPrefix() + svgDir + getVariationSuffix() + svgFile + PNG_EXTENSION;
106     }
107
108     protected abstract String JavaDoc getVariationPrefix();
109
110     protected abstract String JavaDoc getVariationSuffix();
111
112     /**
113      * Gives a chance to the subclass to control the construction
114      * of the saveVariation URL, which is built as:
115      * getSaveVariationPrefix() + svgDir + getSaveVariationSuffix() + svgFile + PNG_EXTENSION
116      */

117     public String JavaDoc buildSaveVariationFile(String JavaDoc svgDir, String JavaDoc svgFile){
118         return getSaveVariationPrefix() + svgDir + getSaveVariationSuffix() + svgFile + PNG_EXTENSION;
119     }
120
121     protected abstract String JavaDoc getSaveVariationPrefix();
122
123     protected abstract String JavaDoc getSaveVariationSuffix();
124
125     /**
126      * Gives a chance to the subclass to control the construction
127      * of the candidateReference URL, which is built as:
128      * getCandidatereferencePrefix() + svgDir + getCandidatereferenceSuffix() + svgFile + PNG_EXTENSION
129      */

130     public String JavaDoc buildCandidateReferenceFile(String JavaDoc svgDir, String JavaDoc svgFile){
131         return getCandidateReferencePrefix() + svgDir + getCandidateReferenceSuffix() + svgFile + PNG_EXTENSION;
132     }
133
134     protected abstract String JavaDoc getCandidateReferencePrefix();
135
136     protected abstract String JavaDoc getCandidateReferenceSuffix();
137
138
139     protected String JavaDoc[] breakSVGFile(String JavaDoc svgFile){
140         if(svgFile == null) {
141             throw new IllegalArgumentException JavaDoc(svgFile);
142         }
143
144         String JavaDoc [] ret = new String JavaDoc[3];
145
146         if (svgFile.endsWith(SVG_EXTENSION)) {
147             ret[2] = SVG_EXTENSION;
148         } else if (svgFile.endsWith(SVGZ_EXTENSION)) {
149             ret[2] = SVGZ_EXTENSION;
150         } else {
151             throw new IllegalArgumentException JavaDoc(svgFile);
152         }
153
154         svgFile = svgFile.substring(0, svgFile.length()-ret[2].length());
155
156         int fileNameStart = svgFile.lastIndexOf(PATH_SEPARATOR);
157         String JavaDoc svgDir = "";
158         if(fileNameStart != -1){
159             if(svgFile.length() < fileNameStart + 2){
160                 // Nothing after PATH_SEPARATOR
161
throw new IllegalArgumentException JavaDoc(svgFile);
162             }
163             svgDir = svgFile.substring(0, fileNameStart + 1);
164             svgFile = svgFile.substring(fileNameStart + 1);
165         }
166         ret[0] = svgDir;
167         ret[1] = svgFile;
168         return ret;
169     }
170
171 }
172
Popular Tags