* @param xml The xml containing the configuration.
* @return The jpmail configuration.
* @throws ApsSystemException In case of parsing errors.
*/
public WebMailConfig extractConfig(String xml) throws ApsSystemException {
WebMailConfig config = new WebMailConfig();
try {
Element root = this.getRootElement(xml);
Element domainNameElem = root.getChild(DOMAIN_ELEM);
if (null != domainNameElem) {
String domainName = domainNameElem.getText();
config.setDomainName(domainName);
}
Element localhostElem = root.getChild(LOCALHOST_ELEM);
if (null != localhostElem) {
String localhost = localhostElem.getText();
config.setLocalhost(localhost);
}
Element smtpElem = root.getChild(SMTP_ELEM);
String debug = smtpElem.getAttributeValue(SMTP_DEBUG_ATTR);
config.setDebug(new Boolean(debug).booleanValue());
String japsUserAuth = smtpElem.getAttributeValue(SMTP_JAPS_USER_AUTH_ATTR);
config.setSmtpJapsUserAuth(new Boolean(japsUserAuth).booleanValue());
config.setSmtpHost(smtpElem.getChildText(SMTP_HOST_CHILD));
config.setSmtpUserName(smtpElem.getChildText(SMTP_USER_CHILD));
config.setSmtpPassword(smtpElem.getChildText(SMTP_PASSWORD_CHILD));
String smtpPort = smtpElem.getChildText(SMTP_PORT_CHILD);
Integer smtpPortValue = (smtpPort==null || smtpPort.length()==0) ? null : new Integer(smtpPort);
config.setSmtpPort(smtpPortValue);
Element certElem = root.getChild(CERTIFICATES_ELEM);
String enable = certElem.getChildText(CERTIFICATES_ENABLE_CHILD);
config.setCertificateEnable(new Boolean(enable).booleanValue());
String lazyCheck = certElem.getChildText(CERTIFICATES_LAZYCHECK_CHILD);
config.setCertificateLazyCheck(new Boolean(lazyCheck).booleanValue());
String certificatePath = certElem.getChildText(CERTIFICATES_CERTPATH_CHILD);
config.setCertificatePath(certificatePath);
String debugOnConsole = certElem.getChildText(CERTIFICATES_DEBUGONCONSOLE_CHILD);
config.setCertificateDebugOnConsole(new Boolean(debugOnConsole).booleanValue());
Element imapElem = root.getChild(IMAP_ELEM);
config.setImapHost(imapElem.getChildText(IMAP_HOST_CHILD));
String imapPort = imapElem.getChildText(IMAP_PORT_CHILD);
Integer imapPortValue = (imapPort==null || imapPort.length()==0) ? null : new Integer(imapPort);
config.setImapPort(imapPortValue);
config.setImapProtocol(imapElem.getChildText(IMAP_PROTOCOL_CHILD));
Element folderElem = root.getChild(FOLDER_ELEM);
if (null != folderElem) {
config.setTrashFolderName(folderElem.getChildText(FOLDER_TRASH_CHILD));
config.setSentFolderName(folderElem.getChildText(FOLDER_SENT_CHILD));
}
} catch (Throwable t) {
ApsSystemUtils.logThrowable(t, this, "extractConfig");
throw new ApsSystemException("Error extracting config", t);
}