1 18 package org.apache.batik.test.svg; 19 20 import java.io.File ; 21 import java.net.MalformedURLException ; 22 import java.net.URL ; 23 24 31 public class SVGReferenceRenderingAccuracyTest 32 extends ParametrizedRenderingAccuracyTest { 33 protected String alias; 34 35 42 public void setId(String id){ 43 this.id = id; 44 45 String svgFile = id; 46 47 int n = svgFile.lastIndexOf('#'); 48 if(n == -1 || n+1 >= svgFile.length() ){ 49 throw new IllegalArgumentException (id); 50 } 51 52 parameter = svgFile.substring(n+1, svgFile.length()); 53 svgFile = svgFile.substring(0, n); 54 55 n = parameter.lastIndexOf('-'); 56 if(n == -1 || n+1 >= parameter.length()){ 57 throw new IllegalArgumentException (id); 58 } 59 60 alias = parameter.substring(n+1, parameter.length()); 61 parameter = parameter.substring(0, n); 62 63 String [] dirNfile = breakSVGFile(svgFile); 64 65 setConfig(buildSVGURL(dirNfile[0], dirNfile[1]), 66 buildRefImgURL(dirNfile[0], dirNfile[1])); 67 68 setVariationURL(buildVariationURL(dirNfile[0], dirNfile[1])); 69 setSaveVariation(new File (buildSaveVariationFile(dirNfile[0], dirNfile[1]))); 70 setCandidateReference(new File (buildCandidateReferenceFile(dirNfile[0], dirNfile[1]))); 71 } 72 73 83 protected URL resolveURL(String url){ 84 String fragment = null; 87 String file = url; 88 int n = file.lastIndexOf('#'); 89 if (n != -1) { 90 fragment = file.substring(n); file = file.substring(0,n); 92 } 93 94 File f = (new File (file)).getAbsoluteFile(); 96 if(f.getParentFile().exists()){ 97 try{ 98 if (fragment == null) { 99 return f.toURL(); } else { 101 return new URL (f.toURL(), fragment); 103 } 104 }catch(MalformedURLException e){ 105 throw new IllegalArgumentException (); 106 } 107 } 108 109 try{ 111 return new URL (url); 112 }catch(MalformedURLException e){ 113 throw new IllegalArgumentException (url); 114 } 115 } 116 117 123 protected String buildSVGURL(String svgDir, String svgFile){ 124 return getSVGURLPrefix() + svgDir + 125 svgFile + SVG_EXTENSION + "#" + parameter; 126 } 127 128 134 protected String buildRefImgURL(String svgDir, String svgFile){ 135 return getRefImagePrefix() + svgDir + getRefImageSuffix() + svgFile + alias + PNG_EXTENSION; 136 } 137 138 143 public String buildVariationURL(String svgDir, String svgFile){ 144 return getVariationPrefix() + svgDir + getVariationSuffix() + svgFile + alias + PNG_EXTENSION; 145 } 146 147 152 public String buildSaveVariationFile(String svgDir, String svgFile){ 153 return getSaveVariationPrefix() + svgDir + getSaveVariationSuffix() + svgFile + alias + PNG_EXTENSION; 154 } 155 156 161 public String buildCandidateReferenceFile(String svgDir, String svgFile){ 162 return getCandidateReferencePrefix() + svgDir + getCandidateReferenceSuffix() + svgFile + alias + PNG_EXTENSION; 163 } 164 165 } 166 | Popular Tags |