this.transcoder = (Transcoder)ClassUtils.newInstance(transcoderName);
} catch (Exception ex) {
if (getLogger().isDebugEnabled()) {
getLogger().debug("Cannot load class " + transcoderName, ex);
}
throw new ConfigurationException("Cannot load class " + transcoderName, ex);
}
}
}
// Do we have a transcoder yet?
if (this.transcoder == null ) {
throw new ConfigurationException(
"Could not autodetect transcoder for SVGSerializer and "
+ "no transcoder was specified in the sitemap configuration."
);
}
// Now run through the other parameters, using them as hints
// to the transcoder
for (int i = 0; i < parameters.length; i++ ) {
String name = parameters[i].getAttribute("name");
// Skip over the parameters we've dealt with. Ensure this
// is kept in sync with the above list!
if ("transcoder".equals(name)) {
continue;
}
// Now try and get the hints out
try {
// Turn it into a key name (assume the current Batik style continues!
name = ("KEY_" + name).toUpperCase();
// Use reflection to get a reference to the key object
TranscodingHints.Key key = (TranscodingHints.Key)
(transcoder.getClass().getField(name).get(transcoder));
Object value;
String keyType = parameters[i].getAttribute("type", "STRING").toUpperCase();
if ("FLOAT".equals(keyType)) {
// Can throw an exception.
value = new Float(parameters[i].getAttributeAsFloat("value"));
} else if ("INTEGER".equals(keyType)) {
// Can throw an exception.
value = new Integer(parameters[i].getAttributeAsInteger("value"));
} else if ("BOOLEAN".equals(keyType)) {
// Can throw an exception.
value = Boolean.valueOf(parameters[i].getAttributeAsBoolean("value"));
} else if ("COLOR".equals(keyType)) {
// Can throw an exception
String stringValue = parameters[i].getAttribute("value");
if (stringValue.startsWith("#")) {
stringValue = stringValue.substring(1);
}
value = new Color(Integer.parseInt(stringValue, 16));
} else {
// Assume String, and get the value. Allow an empty string.
value = parameters[i].getAttribute("value", "");
}
if(getLogger().isDebugEnabled()) {
getLogger().debug("Adding hint \"" + name + "\" with value \"" + value.toString() + "\"");
}
transcoder.addTranscodingHint(key, value);
} catch (ClassCastException ex) {
// This is only thrown from the String keyType... line
throw new ConfigurationException("Specified key (" + name + ") is not a valid Batik Transcoder key.", ex);
} catch (ConfigurationException ex) {
throw new ConfigurationException("Name or value not specified.", ex);
} catch (IllegalAccessException ex) {
throw new ConfigurationException("Cannot access the key for parameter \"" + name + "\"", ex);
} catch (NoSuchFieldException ex) {
throw new ConfigurationException("No field available for parameter \"" + name + "\"", ex);
}
}
}