00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 package com.realtime.crossfire.jxclient.skin.source;
00023
00024 import com.realtime.crossfire.jxclient.skin.skin.JXCSkinException;
00025 import java.io.IOException;
00026 import java.io.InputStream;
00027 import org.jetbrains.annotations.NotNull;
00028
00033 public class JXCSkinClassSource extends AbstractJXCSkinSource {
00034
00038 @NotNull
00039 private final String baseName;
00040
00046 public JXCSkinClassSource(@NotNull final String baseName) throws JXCSkinException {
00047 this.baseName = baseName;
00048 checkAccess();
00049 }
00050
00054 @NotNull
00055 @Override
00056 public InputStream getInputStream(@NotNull final String name) throws IOException {
00057 final InputStream inputStream = getClassLoader().getResourceAsStream(baseName+"/"+name);
00058 if (inputStream == null) {
00059 throw new IOException("resource '"+baseName+"/"+name+"' not found");
00060 }
00061 return inputStream;
00062 }
00063
00067 @NotNull
00068 @Override
00069 public String getURI(@NotNull final String name) {
00070 return "resource:"+baseName+"/"+name;
00071 }
00072
00077 @NotNull
00078 private ClassLoader getClassLoader() {
00079 final ClassLoader classLoader = getClass().getClassLoader();
00080 if (classLoader != null) {
00081 return classLoader;
00082 }
00083
00084 final ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
00085 if (systemClassLoader != null) {
00086 return systemClassLoader;
00087 }
00088
00089 throw new InternalError("cannot find class loader");
00090 }
00091
00092 }