SkinPropertiesImplpublic class SkinPropertiesImpl extends Object implements SkinPropertiesImplementation of SkinProperties using a java.util.Properties loaded from
hard coded paths.
Three level lookup of keys:
(plugin) skin property file
defaults property file
Azureus MessageText class
Additionally, checks each for platform specific keys.
Values containing "{*}" are replaced with a lookup of *
|
Fields Summary |
---|
private static final org.gudy.azureus2.core3.logging.LogIDs | LOGID | private static final String | PATH_SKIN_DEFS | private static final String | FILE_SKIN_DEFS | private static final String | LOCATION_SKIN | private static final Pattern | PAT_PARAM_ALPHA | private static final Pattern | PAT_PARAM_NUM | private Properties | properties | private final ClassLoader | classLoader |
Constructors Summary |
---|
public SkinPropertiesImpl()
this(SkinPropertiesImpl.class.getClassLoader(), PATH_SKIN_DEFS, FILE_SKIN_DEFS);
| public SkinPropertiesImpl(ClassLoader classLoader, String skinPath, String mainSkinFile)
this.classLoader = classLoader;
properties = new Properties();
InputStream is;
is = classLoader.getResourceAsStream(skinPath + mainSkinFile);
if (is != null) {
try {
properties.load(is);
} catch (Exception e) {
e.printStackTrace();
}
} else {
Logger.log(new LogEvent(LOGID, skinPath + mainSkinFile + " not found"));
}
is = classLoader.getResourceAsStream(LOCATION_SKIN);
if (is != null) {
try {
properties.load(is);
} catch (Exception e) {
e.printStackTrace();
}
}
String sFiles = properties.getProperty("skin.include");
if (sFiles != null) {
String[] sFilesArray = sFiles.split(",");
for (int i = 0; i < sFilesArray.length; i++) {
String sFile = (sFilesArray[i].startsWith("/")
? sFilesArray[i].substring(1) : skinPath + sFilesArray[i])
+ ".properties";
try {
is = classLoader.getResourceAsStream(sFile);
if (is != null) {
properties.load(is);
} else {
System.err.println("No Skin " + sFile + " found");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
|
Methods Summary |
---|
public void | addProperty(java.lang.String name, java.lang.String value)
properties.put(name, value);
| public boolean | getBooleanValue(java.lang.String name, boolean def)
String s = getStringValue(name, (String) null);
if (s == null) {
return def;
}
return s.toLowerCase().equals("true") || s.equals("1");
| public int[] | getColorValue(java.lang.String name)
int[] colors = new int[3];
String value = getValue(name, null);
if (value == null || value.length() == 0) {
colors[0] = colors[1] = colors[2] = -1;
return colors;
}
try {
if (value.charAt(0) == '#") {
// hex color string
long l = Long.parseLong(value.substring(1), 16);
colors[0] = (int) ((l >> 16) & 255);
colors[1] = (int) ((l >> 8) & 255);
colors[2] = (int) (l & 255);
} else {
StringTokenizer st = new StringTokenizer(value, ",");
colors[0] = Integer.parseInt(st.nextToken());
colors[1] = Integer.parseInt(st.nextToken());
colors[2] = Integer.parseInt(st.nextToken());
}
} catch (Exception e) {
e.printStackTrace();
colors[0] = colors[1] = colors[2] = -1;
}
return colors;
| public int | getIntValue(java.lang.String name, int def)
String value = getValue(name, null);
if (value == null) {
return def;
}
int result = def;
try {
result = Integer.parseInt(value);
} catch (NumberFormatException e) {
// ignore error.. it might be valid to store a non-numeric..
//e.printStackTrace();
}
return result;
| public java.util.Properties | getProperties()
return properties;
| public java.lang.String[] | getStringArray(java.lang.String name)
return getStringArray(name, (String[]) null);
| public java.lang.String[] | getStringArray(java.lang.String name, java.lang.String[] params)
String s = getValue(name, params);
if (s == null) {
return null;
}
String[] values = s.split("\\s*,\\s*");
if (values == null) {
return new String[] {
s
};
}
return values;
| public java.lang.String | getStringValue(java.lang.String name, java.lang.String[] params)
return getValue(name, params);
| public java.lang.String | getStringValue(java.lang.String name, java.lang.String[] params, java.lang.String def)
String s = getValue(name, params);
return (s == null) ? def : s;
| public java.lang.String | getStringValue(java.lang.String name)
return getStringValue(name, (String[]) null);
| public java.lang.String | getStringValue(java.lang.String name, java.lang.String def)
return getStringValue(name, (String[]) null, def);
| private java.lang.String | getValue(java.lang.String name, java.lang.String[] params)
String value = null;
String osName = null;
if (name == null) {
return null;
}
if (Constants.isOSX) {
osName = name + "._mac";
} else if (Constants.isUnix) {
osName = name + "._unix";
} else if (Constants.isFreeBSD) {
osName = name + "._freebsd";
} else if (Constants.isLinux) {
osName = name + "._linux";
} else if (Constants.isSolaris) {
osName = name + "._solaris";
} else if (Constants.isWindows) {
osName = name + "._windows";
}
if (osName != null) {
value = properties.getProperty(osName);
}
if (value == null) {
value = properties.getProperty(name);
}
if (value != null && value.indexOf('}") > 0) {
Matcher matcher;
if (params != null) {
matcher = PAT_PARAM_NUM.matcher(value);
while (matcher.find()) {
String key = matcher.group(1);
try {
int i = Integer.parseInt(key);
if (i < params.length) {
value = value.replaceAll("\\Q{" + key + "}\\E", params[i]);
}
} catch (Exception e) {
}
}
}
matcher = PAT_PARAM_ALPHA.matcher(value);
while (matcher.find()) {
String key = matcher.group(1);
String text = getValue(key, params);
if (text == null) {
text = MessageText.getString(key);
}
value = value.replaceAll("\\Q{" + key + "}\\E", text);
}
}
return value;
|
|