* @throws RepositoryException if a problem occurs building the URL
*/
protected String constructImageURL(final String srcUrl,
PreservedArea preservedArea)
throws RepositoryException {
PluggableAssetTranscoder transcoder =
getVolantisBean().getAssetTranscoder();
String newURL = srcUrl;
InternalDevice device = getDevice();
TranscodingRule transcodingRule = getTranscodingRule(device);
if (transcodingRule != null) {
String ruleName = transcodingRule.getName();
// We got a rule so let's generate the requirNameed URL
String ruleValue = device.getPolicyValue(ruleName);
StringBuffer value;
int width;
int maxSize;
// Determine the width to be requested
if (getCurrentPane() == null) {
// If we are not in a pane, use the device width
width = device.getPixelsX();
} else {
width = getProtocol().calculatePaneWidth(getCurrentPane());
}
// Determine the maxSize to be requested
try {
maxSize = device.getIntegerPolicyValue("maximagesize", -1);
// parse out the values of image maxsize that have been entered
// by the user
MarinerURL murl = new MarinerURL(srcUrl);
String[] paramValues =
murl.getParameterValues(transcoder.getMaxImageSizeParameter());
int min = Integer.MAX_VALUE;
if (null != paramValues) {
// always iterate over the parameter values even if there
// is only one as we need to set up "min"
if (paramValues.length > 0) {
// remove the parameters as they will be added back later
murl.removeParameter(
transcoder.getMaxImageSizeParameter());
// reassign the newURL variable with the removed
newURL = murl.getExternalForm();
for (int i=0; i< paramValues.length; i++) {
int val = Integer.parseInt(paramValues[i]);
if (val < min) {
min = val;
}
}
}
// if min is valid (>-1) and is less then a valid maxSize
// then use its value otherwise use the value in the
// device repository
if (min >= 0 && min < Integer.MAX_VALUE &&
maxSize >=0 && min < maxSize) {
maxSize = min;
}
}
} catch (NumberFormatException e) {
logger.warn("maximagesize-not-valid",
new Object[]{
device.getPolicyValue("maximagesize")}, e);
maxSize = -1;
}
try {
AssetTranscoderContext ctx = new AssetTranscoderContext(
newURL,
ruleValue,
width,
maxSize,
getRequestContext(),
preservedArea);
value = new StringBuffer(
transcoder.constructImageURL(ctx));
} catch (TranscodingException e) {
throw new RepositoryException(e);
}
// Allow the ImageURLModifier (if there is one) in the