if (keyString.startsWith(PARAM_PREFIX_ENTRY)) {
String paramName = keyString.substring(PARAM_PREFIX_ENTRY.length());
String paramValue = getParameter(paramName);
if (paramValue == null) {
String message = "No parameter " + String.valueOf(keyString) + " available.";
throw new ContextException(message);
}
return paramValue;
} else if (keyString.startsWith(PARAM_INTEGER_PREFIX_ENTRY)) {
String paramName = keyString.substring(PARAM_INTEGER_PREFIX_ENTRY.length());
try {
Integer paramValue = getParameterAsInteger(paramName);
return paramValue;
} catch (NumberFormatException nfe) {
String message = "Cannot create Integer for parameter " + String.valueOf(keyString);
throw new ContextException(message, nfe);
}
} else if (keyString.startsWith(PARAM_FOLDER_PREFIX_ENTRY)) {
String paramName = keyString.substring(PARAM_FOLDER_PREFIX_ENTRY.length());
String folderName = getParameter(paramName);
if (folderName == null) {
// no folderName is available in the parameters bag
// try to get the current working folder
try {
folderName = (String) super.get(MAIL_CURRENT_WORKING_FOLDER_ENTRY);
} catch (ContextException ce) {
// no current working folder entry available
String message = "No " + MAIL_CURRENT_WORKING_FOLDER_ENTRY + " entry available ";
getLogger().error(message);
throw new ContextException(message, ce);
}
}
// get folder object, folderName is okay
Folder folder = null;
try {
folder = (Folder) getFolder(folderName);
} catch (ContextException ce) {
// folder is not stored yet
Store store = (Store) get(MAIL_STORE_ENTRY);
// get folder, eventually connect the store
try {
if (!store.isConnected()) {
store.connect();
}
final String DEFAULT_FOLDER_NAME = "~";
// empty folder name is specified by empty string, or "~"
if (folderName.equals(DEFAULT_FOLDER_NAME) || folderName.length() == 0) {
folder = store.getDefaultFolder();
} else {
folder = store.getFolder(folderName);
}
// save the Folder, for later access
putFolder(folder);
} catch (MessagingException me) {
String message = "Cannot get folder " + String.valueOf(folderName);
throw new ContextException(message, ce);
}
}
return folder;
} else {
return super.get(key);