1 18 package org.apache.batik.test.svg; 19 20 import java.io.File ; 21 22 29 public abstract class PreconfiguredRenderingTest extends SVGRenderingAccuracyTest { 30 33 public static final String PNG_EXTENSION = ".png"; 34 35 public static final String SVG_EXTENSION = ".svg"; 36 public static final String SVGZ_EXTENSION = ".svgz"; 37 38 public static final char PATH_SEPARATOR = '/'; 39 40 45 public void setId(String id){ 46 super.setId(id); 47 setFile(id); 48 } 49 50 public void setFile(String id) { 51 String svgFile = id; 52 53 String [] 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 (buildSaveVariationFile(dirNfile[0], dirNfile[1]))); 60 setCandidateReference(new File (buildCandidateReferenceFile(dirNfile[0],dirNfile[1]))); 61 } 62 63 68 public String getName(){ 69 return getId(); 70 } 71 72 78 protected String buildSVGURL(String svgDir, String svgFile, String svgExt){ 79 return getSVGURLPrefix() + svgDir + svgFile + svgExt; 80 } 81 82 protected abstract String getSVGURLPrefix(); 83 84 85 91 protected String buildRefImgURL(String svgDir, String svgFile){ 92 return getRefImagePrefix() + svgDir + getRefImageSuffix() + svgFile + PNG_EXTENSION; 93 } 94 95 protected abstract String getRefImagePrefix(); 96 97 protected abstract String getRefImageSuffix(); 98 99 104 public String buildVariationURL(String svgDir, String svgFile){ 105 return getVariationPrefix() + svgDir + getVariationSuffix() + svgFile + PNG_EXTENSION; 106 } 107 108 protected abstract String getVariationPrefix(); 109 110 protected abstract String getVariationSuffix(); 111 112 117 public String buildSaveVariationFile(String svgDir, String svgFile){ 118 return getSaveVariationPrefix() + svgDir + getSaveVariationSuffix() + svgFile + PNG_EXTENSION; 119 } 120 121 protected abstract String getSaveVariationPrefix(); 122 123 protected abstract String getSaveVariationSuffix(); 124 125 130 public String buildCandidateReferenceFile(String svgDir, String svgFile){ 131 return getCandidateReferencePrefix() + svgDir + getCandidateReferenceSuffix() + svgFile + PNG_EXTENSION; 132 } 133 134 protected abstract String getCandidateReferencePrefix(); 135 136 protected abstract String getCandidateReferenceSuffix(); 137 138 139 protected String [] breakSVGFile(String svgFile){ 140 if(svgFile == null) { 141 throw new IllegalArgumentException (svgFile); 142 } 143 144 String [] ret = new String [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 (svgFile); 152 } 153 154 svgFile = svgFile.substring(0, svgFile.length()-ret[2].length()); 155 156 int fileNameStart = svgFile.lastIndexOf(PATH_SEPARATOR); 157 String svgDir = ""; 158 if(fileNameStart != -1){ 159 if(svgFile.length() < fileNameStart + 2){ 160 throw new IllegalArgumentException (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 |