package NET.worlds.scape; import NET.worlds.network.URL; import java.io.File; import java.util.Hashtable; import java.util.StringTokenizer; public abstract class TextureDecoder { protected static Hashtable handlers = new Hashtable(); private static TextureDecoder defaultDecoder; private static String allExts; static { addHandler(defaultDecoder = new FileTextureDecoder()); addHandler(new StandardTextureDecoder()); addHandler(new ScapePicTextureDecoder()); } protected abstract String getExts(); protected abstract Texture read(String var1, String var2); private static void addHandler(TextureDecoder decoder) { StringTokenizer e = new StringTokenizer(decoder.getExts(), ";"); while (e.hasMoreTokens()) { String ext = e.nextToken().toLowerCase(); handlers.put(ext, decoder); if (allExts == null) { allExts = ext; } else { allExts = allExts + File.pathSeparator + ext; } } } public static String getAllExts() { return allExts; } public static String getJavaExts() { return new StandardTextureDecoder().getExts(); } public static Texture decode(URL url, String filename) { return decode(url, url.getAbsolute(), filename); } public static Texture decode(URL url, String lookupName, String filename) { Texture tex = FileTexture.dictLookup(lookupName); if (tex != null) { return tex; } else { String urlName = url.getInternal(); int delim = urlName.lastIndexOf(46); int lastPath = urlName.lastIndexOf(47); lastPath = Math.max(lastPath, urlName.lastIndexOf(92)); lastPath = Math.max(lastPath, urlName.lastIndexOf(58)); if (delim > lastPath) { String ext = urlName.substring(delim + 1).toLowerCase(); TextureDecoder decoder = (TextureDecoder)handlers.get(ext); if (decoder != null) { Texture t = decoder.read(lookupName, filename); if (t.textureID != 0) { return t; } } } return null; } } }