diff --git a/ccm-core/src/main/java/com/arsdigita/bebop/BebopConfig.java b/ccm-core/src/main/java/com/arsdigita/bebop/BebopConfig.java index 46262db4c..fc4b7c502 100755 --- a/ccm-core/src/main/java/com/arsdigita/bebop/BebopConfig.java +++ b/ccm-core/src/main/java/com/arsdigita/bebop/BebopConfig.java @@ -23,16 +23,20 @@ import com.arsdigita.bebop.util.BebopConstants; import com.arsdigita.templating.PresentationManager; import com.arsdigita.ui.SimplePage; import com.arsdigita.util.UncheckedWrapperException; + import java.util.Arrays; import java.util.HashSet; import java.util.Objects; import java.util.Set; import java.util.StringJoiner; + import org.libreccm.cdi.utils.CdiUtil; import org.libreccm.configuration.Configuration; import org.libreccm.configuration.ConfigurationManager; import org.libreccm.configuration.Setting; +import java.util.stream.Collectors; + /** * * @author Jens Pelzetter @@ -40,165 +44,167 @@ import org.libreccm.configuration.Setting; @Configuration(descBundle = "com.arsdigita.bebop.BebopConfigDescription", descKey = "bebop.config.description") public final class BebopConfig { - + @Setting(descKey = "bebop.config.presenter_class_name") private String presenterClassName = PageTransformer.class.getName(); - + @Setting(descKey = "bebop.config.base_page_name") private String basePageClassName = SimplePage.class.getName(); - + @Setting(descKey = "bebop.config.tidy_config_file") private String tidyConfigFile - = "com/arsdigita/bebop/parameters/tidy.properties"; - + = "com/arsdigita/bebop/parameters/tidy.properties"; + @Setting(descKey = "bebop.config.fancy_errors") private Boolean fancyErrors = false; - + @Setting(descKey = "bebop.config.dcp_on_buttons") private Boolean dcpOnButtons = true; - + @Setting(descKey = "bebop.config.dcp_on_links") private Boolean dcpOnLinks = false; - + @Setting(descKey = "bebop.config.tree_select_enabled") private Boolean treeSelectEnabled = false; - + @Setting(descKey = "bebop.config.dhtml_editors") private Set dhtmlEditors = new HashSet<>( - Arrays.asList(new String[]{BebopConstants.BEBOP_XINHAEDITOR, - BebopConstants.BEBOP_FCKEDITOR, - BebopConstants.BEBOP_DHTMLEDITOR})); - + Arrays.asList(new String[]{BebopConstants.BEBOP_XINHAEDITOR, + BebopConstants.BEBOP_FCKEDITOR, + BebopConstants.BEBOP_DHTMLEDITOR})); + @Setting(descKey = "bebop.config.default_dhtml_editor") private String defaultDhtmlEditor = BebopConstants.BEBOP_XINHAEDITOR; - + @Setting(descKey = "bebop.config.dhtml_editor_srcfile") private String dhtmlEditorSrcFile = "/assets/xinha/XinhaLoader.js"; - + @Setting(descKey = "bebop.config.show_class_name") private Boolean showClassName = false; - + public static BebopConfig getConfig() { final CdiUtil cdiUtil = new CdiUtil(); final ConfigurationManager confManager = cdiUtil.findBean( - ConfigurationManager.class); + ConfigurationManager.class); return confManager.findConfiguration(BebopConfig.class); } - + public String getPresenterClassName() { return presenterClassName; } - + + @SuppressWarnings("unchecked") public Class getPresenterClass() { try { return (Class) Class. - forName(presenterClassName); + forName(presenterClassName); } catch (ClassNotFoundException ex) { throw new UncheckedWrapperException(ex); } } - + public void setPresenterClassName(final String presenterClassName) { this.presenterClassName = presenterClassName; } - + public void setPresenterClass( - final Class presenterClass) { + final Class presenterClass) { setPresenterClassName(presenterClass.getName()); } - + public String getBasePageClassName() { return basePageClassName; } - + + @SuppressWarnings("unchecked") public Class getBasePageClass() { try { - return (Class)Class.forName(basePageClassName); + return (Class) Class.forName(basePageClassName); } catch (ClassNotFoundException ex) { throw new UncheckedWrapperException(ex); } } - + public void setBasePageClassName(final String basePageClassName) { this.basePageClassName = basePageClassName; } - + public void setBasePageClass(final Class basePageClass) { setBasePageClassName(basePageClass.getName()); } - + public String getTidyConfigFile() { return tidyConfigFile; } - + public void setTidyConfigFile(final String tidyConfigFile) { this.tidyConfigFile = tidyConfigFile; } - + public Boolean getFancyErrors() { return fancyErrors; } - + public void setFancyErrors(final Boolean fancyErrors) { this.fancyErrors = fancyErrors; } - + public Boolean getDcpOnButtons() { return dcpOnButtons; } - + public void setDcpOnButtons(final Boolean dcpOnButtons) { this.dcpOnButtons = dcpOnButtons; } - + public Boolean getDcpOnLinks() { return dcpOnLinks; } - + public void setDcpOnLinks(final Boolean dcpOnLinks) { this.dcpOnLinks = dcpOnLinks; } - + public Boolean isTreeSelectEnabled() { return treeSelectEnabled; } - + public void setTreeSelectEnabled(final Boolean treeSelectEnabled) { this.treeSelectEnabled = treeSelectEnabled; } - + public Set getDhtmlEditors() { return new HashSet<>(dhtmlEditors); } - + public void setDhtmlEditors(final Set dhtmlEditors) { this.dhtmlEditors = dhtmlEditors; } - + public String getDefaultDhtmlEditor() { return defaultDhtmlEditor; } - + public void setDefaultDhtmlEditor(final String defaultDhtmlEditor) { this.defaultDhtmlEditor = defaultDhtmlEditor; } - + public String getDhtmlEditorSrcFile() { return dhtmlEditorSrcFile; } - + public void setDhtmlEditorSrcFile(final String dhtmlEditorSrcFile) { this.dhtmlEditorSrcFile = dhtmlEditorSrcFile; } - + public Boolean getShowClassName() { return showClassName; } - + public void setShowClassName(final Boolean showClassName) { this.showClassName = showClassName; } - + @Override public int hashCode() { int hash = 7; @@ -213,7 +219,7 @@ public final class BebopConfig { hash = 89 * hash + Objects.hashCode(showClassName); return hash; } - + @Override public boolean equals(final Object obj) { if (this == obj) { @@ -252,32 +258,31 @@ public final class BebopConfig { } return Objects.equals(showClassName, other.getShowClassName()); } - + @Override public String toString() { - final StringJoiner joiner = new StringJoiner(", "); - dhtmlEditors.forEach(s -> joiner.add(s)); - - return String.format("%s{ " - + "tidyConfigFile = %s, " - + "fancyErrors = %b, " - + "dcpOnButtons = %b, " - + "dcpOnLinks = %b, " - + "treeSelectEnabled = %b, " - + "dhtmlEditors = { %s }, " - + "defaultDhtmlEditor = %s, " - + "dhtmlEditorSrcFile = %s, " - + "showClassName = %b" - + " }", - super.toString(), - tidyConfigFile, - fancyErrors, - dcpOnButtons, - dcpOnLinks, - treeSelectEnabled, - joiner.toString(), - defaultDhtmlEditor, - dhtmlEditorSrcFile, - showClassName); + return String.format( + "%s{ " + + "tidyConfigFile = %s, " + + "fancyErrors = %b, " + + "dcpOnButtons = %b, " + + "dcpOnLinks = %b, " + + "treeSelectEnabled = %b, " + + "dhtmlEditors = { %s }, " + + "defaultDhtmlEditor = %s, " + + "dhtmlEditorSrcFile = %s, " + + "showClassName = %b" + + " }", + super.toString(), + tidyConfigFile, + fancyErrors, + dcpOnButtons, + dcpOnLinks, + treeSelectEnabled, + dhtmlEditors.stream().collect(Collectors.joining(", ")), + defaultDhtmlEditor, + dhtmlEditorSrcFile, + showClassName); } + } diff --git a/ccm-core/src/main/java/com/arsdigita/kernel/KernelConfig.java b/ccm-core/src/main/java/com/arsdigita/kernel/KernelConfig.java index 11a604d9d..d22c0c8a1 100644 --- a/ccm-core/src/main/java/com/arsdigita/kernel/KernelConfig.java +++ b/ccm-core/src/main/java/com/arsdigita/kernel/KernelConfig.java @@ -30,6 +30,7 @@ import org.libreccm.configuration.ConfigurationManager; import org.libreccm.configuration.Setting; import java.util.StringJoiner; +import java.util.stream.Collectors; /** * @@ -124,7 +125,7 @@ public final class KernelConfig { public boolean emailIsPrimaryIdentifier() { return EMAIL.equals(primaryUserIdentifier); } - + public boolean screenNameIsPrimaryIdentifier() { return SCREEN_NAME.equals(primaryUserIdentifier); } @@ -256,32 +257,28 @@ public final class KernelConfig { @Override public String toString() { - final StringJoiner joiner = new StringJoiner(", "); - if (supportedLanguages != null) { - supportedLanguages.forEach(s -> joiner.add(s)); - } - - return String.format("%s{ " - + "debugEnabled = %b, " - + "webdevSupportEnabled = %b, " - + "dataPermissionCheckEnabled = %b, " - + "primaryUserIdentifier = \"%s\", " - + "ssoEnabled = %b, " - + "rememberLoginEnabeled = %b, " - + "secureLoginEnabled = %b, " - + "supportedLanguages = \"%s\", " - + "defaultLanguage = \"%s\"" - + " }", - super.toString(), - debugEnabled, - webdevSupportEnabled, - dataPermissionCheckEnabled, - primaryUserIdentifier, - ssoEnabled, - rememberLoginEnabled, - secureLoginEnabled, - joiner.toString(), - defaultLanguage); + return String.format( + "%s{ " + + "debugEnabled = %b, " + + "webdevSupportEnabled = %b, " + + "dataPermissionCheckEnabled = %b, " + + "primaryUserIdentifier = \"%s\", " + + "ssoEnabled = %b, " + + "rememberLoginEnabeled = %b, " + + "secureLoginEnabled = %b, " + + "supportedLanguages = { \"%s\" }, " + + "defaultLanguage = \"%s\"" + + " }", + super.toString(), + debugEnabled, + webdevSupportEnabled, + dataPermissionCheckEnabled, + primaryUserIdentifier, + ssoEnabled, + rememberLoginEnabled, + secureLoginEnabled, + supportedLanguages.stream().collect(Collectors.joining(", ")), + defaultLanguage); } } diff --git a/ccm-core/src/main/java/com/arsdigita/kernel/security/SecurityConfig.java b/ccm-core/src/main/java/com/arsdigita/kernel/security/SecurityConfig.java index 85d52ae60..6e2ea1be5 100644 --- a/ccm-core/src/main/java/com/arsdigita/kernel/security/SecurityConfig.java +++ b/ccm-core/src/main/java/com/arsdigita/kernel/security/SecurityConfig.java @@ -28,6 +28,7 @@ import java.util.Arrays; import java.util.List; import java.util.Objects; import java.util.StringJoiner; +import java.util.stream.Collectors; /** * @@ -160,24 +161,22 @@ public final class SecurityConfig { @Override public String toString() { - final StringJoiner joiner = new StringJoiner(", "); - excludedExtensions.forEach(s -> joiner.add(s)); - - return String.format("%s{ " - + "excludedExtensions = { %s }, " - + "autoRegistrationEnabled = %b, " - + "passwordRecoveryEnabled = %b, " - + "hashAlgorithm = \"%s\", " - + "saltLength = %d, " - + "hashIterations = %d" - + " }", - super.toString(), - joiner.toString(), - autoRegistrationEnabled, - passwordRecoveryEnabled, - hashAlgorithm, - saltLength, - hashIterations); + return String.format( + "%s{ " + + "excludedExtensions = { %s }, " + + "autoRegistrationEnabled = %b, " + + "passwordRecoveryEnabled = %b, " + + "hashAlgorithm = \"%s\", " + + "saltLength = %d, " + + "hashIterations = %d" + + " }", + super.toString(), + excludedExtensions.stream().collect(Collectors.joining(", ")), + autoRegistrationEnabled, + passwordRecoveryEnabled, + hashAlgorithm, + saltLength, + hashIterations); } } diff --git a/ccm-core/src/main/java/com/arsdigita/mail/LegacyMailConfig.java b/ccm-core/src/main/java/com/arsdigita/mail/LegacyMailConfig.java new file mode 100755 index 000000000..3b68a910f --- /dev/null +++ b/ccm-core/src/main/java/com/arsdigita/mail/LegacyMailConfig.java @@ -0,0 +1,157 @@ +/* + * Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +package com.arsdigita.mail; + +import com.arsdigita.runtime.AbstractConfig; +import com.arsdigita.util.parameter.BooleanParameter; +import com.arsdigita.util.parameter.ErrorList; +import com.arsdigita.util.parameter.Parameter; +import com.arsdigita.util.parameter.ParameterError; +import com.arsdigita.util.parameter.StringParameter; +import com.arsdigita.util.parameter.URLParameter; +import com.arsdigita.util.UncheckedWrapperException; + +import java.io.IOException; +import java.net.URL; +import java.util.Properties; + +/** + * LegacyMailConfig + * + * @author Rafael H. Schloming <rhs@mit.edu> + * @version $Revision: #7 $ $Date: 2004/08/16 $ + * @version $Id: LegacyMailConfig.java 1513 2007-03-22 09:09:03Z chrisgilbert23 $ + */ +public final class LegacyMailConfig extends AbstractConfig { + + private Properties m_props; + + private final Parameter m_debug = new BooleanParameter + ("waf.mail.debug", Parameter.OPTIONAL, Boolean.FALSE); + + private final Parameter m_javamail = new PropertyFileParameter + ("waf.mail.javamail.configuration", Parameter.OPTIONAL, null); + + /* used by Mail when the user is not logged in. */ + private final Parameter m_defaultFrom = new StringParameter + ("waf.mail.default_from", Parameter.OPTIONAL, ""); + + private final Parameter m_sendHTML = new BooleanParameter + ("waf.mail.send_html_mail", Parameter.OPTIONAL, Boolean.FALSE); + + + /** + * Constructor registers the parameter ands loads values from config file. + * + */ + public LegacyMailConfig() { + register(m_javamail); + register(m_debug); + register(m_defaultFrom); + register(m_sendHTML); + + loadInfo(); + } + + public Properties getJavamail() { + if (m_props == null) { + URL propsFile = (URL) get(m_javamail); + if (propsFile == null) { + m_props = new Properties(); + m_props.put("mail.transport.protocol", "smtp"); + m_props.put("mail.smtp.host", "localhost"); + } else { + try { + m_props = PropertyFileParameter.getProperties(propsFile); + } catch (IOException ioe) { + throw new UncheckedWrapperException + ("unable to retrieve properties file from " + + propsFile, ioe); + } + } + } + + return m_props; + } + + /** + * + * @return + */ + public String getDefaultFrom() { + String from = (String) get(m_defaultFrom); +//TODO: usage of arsdigita.web.Web, not sure if the class will be kept in ccm_ng + +// if (null == from) +// from = "notloggedin@" + Web.getConfig().getServer().getName(); + + return from; + } + + /** + * + * @return + */ + public boolean isDebug() { + return get(m_debug).equals(Boolean.TRUE); + } + + /** + * determine whether messages with mime type text/html + * should be sent as html emails (with plain text alternative) or + * just sent as translated plain text + * @return + */ + public boolean sendHTMLMessageAsHTMLEmail () { + return ((Boolean)get(m_sendHTML)).booleanValue(); + } + + + + /** + * + */ + private static class PropertyFileParameter extends URLParameter { + PropertyFileParameter(String name, int multiplicity, Object defaalt) { + super(name, multiplicity, defaalt); + } + + @Override + protected void doValidate(Object value, ErrorList errors) { + super.doValidate(value, errors); + + if (!errors.isEmpty()) { + return; + } + + try { + getProperties((URL) value); + } catch (IOException ioe) { + errors.add(new ParameterError(this, ioe)); + } + } + + public static Properties getProperties(URL url) throws IOException { + Properties props = new Properties(); + props.load(url.openStream()); + return props; + } + } + +} diff --git a/ccm-core/src/main/java/com/arsdigita/mail/Mail.java b/ccm-core/src/main/java/com/arsdigita/mail/Mail.java index 9ed4cd898..e5c0e2955 100644 --- a/ccm-core/src/main/java/com/arsdigita/mail/Mail.java +++ b/ccm-core/src/main/java/com/arsdigita/mail/Mail.java @@ -76,16 +76,7 @@ public class Mail implements MessageType { */ private static final Logger s_log = Logger.getLogger(Mail.class); - private static MailConfig s_config; - public static MailConfig getConfig() { - if (s_config == null) { - s_config = new MailConfig(); - s_config.load("ccm-core/mail.properties"); - s_config.require("javamail.properties"); - } - return s_config; - } private static final InternetAddress[] EMPTY_ADDRESS_LIST = new InternetAddress[0]; /** @@ -293,7 +284,7 @@ public class Mail implements MessageType { // Write a copy of the message into the log file - if (getConfig().isDebug()) { + if (MailConfig.getConfig().isDebug()) { if (msg != null) { try { ByteArrayOutputStream os = new ByteArrayOutputStream(); @@ -717,7 +708,8 @@ public class Mail implements MessageType { if (s_session == null) { // Set up the properties - Properties props = new Properties(getConfig().getJavamail()); + Properties props = new Properties( + MailConfig.getConfig().getJavaMailProperties()); // Check for overrides of the server information if (s_host != null) { @@ -729,7 +721,7 @@ public class Mail implements MessageType { // Set up the session s_session = Session.getInstance(props, null); - s_session.setDebug(getConfig().isDebug()); + s_session.setDebug(MailConfig.getConfig().isDebug()); } return s_session; diff --git a/ccm-core/src/main/java/com/arsdigita/mail/MailConfig.java b/ccm-core/src/main/java/com/arsdigita/mail/MailConfig.java index cc6a76510..20d1ba25e 100755 --- a/ccm-core/src/main/java/com/arsdigita/mail/MailConfig.java +++ b/ccm-core/src/main/java/com/arsdigita/mail/MailConfig.java @@ -1,157 +1,162 @@ /* - * Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved. + * Copyright (C) 2016 LibreCCM Foundation. * * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA */ package com.arsdigita.mail; -import com.arsdigita.runtime.AbstractConfig; -import com.arsdigita.util.parameter.BooleanParameter; -import com.arsdigita.util.parameter.ErrorList; -import com.arsdigita.util.parameter.Parameter; -import com.arsdigita.util.parameter.ParameterError; -import com.arsdigita.util.parameter.StringParameter; -import com.arsdigita.util.parameter.URLParameter; import com.arsdigita.util.UncheckedWrapperException; +import org.libreccm.cdi.utils.CdiUtil; +import org.libreccm.configuration.Configuration; +import org.libreccm.configuration.ConfigurationManager; +import org.libreccm.configuration.Setting; + import java.io.IOException; import java.net.URL; +import java.util.Objects; import java.util.Properties; /** - * MailConfig * - * @author Rafael H. Schloming <rhs@mit.edu> - * @version $Revision: #7 $ $Date: 2004/08/16 $ - * @version $Id: MailConfig.java 1513 2007-03-22 09:09:03Z chrisgilbert23 $ + * @author Jens Pelzetter */ -public final class MailConfig extends AbstractConfig { +@Configuration +public final class MailConfig { - private Properties m_props; + @Setting + private Boolean debug = false; - private final Parameter m_debug = new BooleanParameter - ("waf.mail.debug", Parameter.OPTIONAL, Boolean.FALSE); + @Setting + private String javaMailPropertiesFile = null; - private final Parameter m_javamail = new PropertyFileParameter - ("waf.mail.javamail.configuration", Parameter.OPTIONAL, null); + @Setting + private String defaultFrom = ""; - /* used by Mail when the user is not logged in. */ - private final Parameter m_defaultFrom = new StringParameter - ("waf.mail.default_from", Parameter.OPTIONAL, ""); + @Setting + private Boolean sendHtml = false; - private final Parameter m_sendHTML = new BooleanParameter - ("waf.mail.send_html_mail", Parameter.OPTIONAL, Boolean.FALSE); - - - /** - * Constructor registers the parameter ands loads values from config file. - * - */ - public MailConfig() { - register(m_javamail); - register(m_debug); - register(m_defaultFrom); - register(m_sendHTML); - - loadInfo(); + public static MailConfig getConfig() { + final CdiUtil cdiUtil = new CdiUtil(); + final ConfigurationManager confManager = cdiUtil.findBean( + ConfigurationManager.class); + return confManager.findConfiguration(MailConfig.class); } - public Properties getJavamail() { - if (m_props == null) { - URL propsFile = (URL) get(m_javamail); - if (propsFile == null) { - m_props = new Properties(); - m_props.put("mail.transport.protocol", "smtp"); - m_props.put("mail.smtp.host", "localhost"); - } else { - try { - m_props = PropertyFileParameter.getProperties(propsFile); - } catch (IOException ioe) { - throw new UncheckedWrapperException - ("unable to retrieve properties file from " - + propsFile, ioe); - } - } - } - - return m_props; + public Boolean isDebug() { + return debug; } - /** - * - * @return - */ - public String getDefaultFrom() { - String from = (String) get(m_defaultFrom); -//TODO: usage of arsdigita.web.Web, not sure if the class will be kept in ccm_ng - -// if (null == from) -// from = "notloggedin@" + Web.getConfig().getServer().getName(); - - return from; + public void setDebug(final Boolean debug) { + this.debug = debug; } - /** - * - * @return - */ - public boolean isDebug() { - return get(m_debug).equals(Boolean.TRUE); + public String getJavaMailPropertiesFile() { + return javaMailPropertiesFile; } - /** - * determine whether messages with mime type text/html - * should be sent as html emails (with plain text alternative) or - * just sent as translated plain text - * @return - */ - public boolean sendHTMLMessageAsHTMLEmail () { - return ((Boolean)get(m_sendHTML)).booleanValue(); - } - - - - /** - * - */ - private static class PropertyFileParameter extends URLParameter { - PropertyFileParameter(String name, int multiplicity, Object defaalt) { - super(name, multiplicity, defaalt); - } - - @Override - protected void doValidate(Object value, ErrorList errors) { - super.doValidate(value, errors); - - if (!errors.isEmpty()) { - return; - } + public Properties getJavaMailProperties() { + final Properties properties = new Properties(); + if (javaMailPropertiesFile == null + || javaMailPropertiesFile.isEmpty()) { + properties.put("mail.transport.protocol", "smtp"); + properties.put("mail.smtp.host", "localhost"); + } else { try { - getProperties((URL) value); - } catch (IOException ioe) { - errors.add(new ParameterError(this, ioe)); + properties.load(new URL(javaMailPropertiesFile).openStream()); + } catch (IOException ex) { + throw new UncheckedWrapperException(String.format( + "Unable to retrieve properties for JavaMail from \"%s\".", + javaMailPropertiesFile)); } } - public static Properties getProperties(URL url) throws IOException { - Properties props = new Properties(); - props.load(url.openStream()); - return props; + return properties; + } + + public void setJavaMailPropertiesFile(final String javaMailPropertiesFile) { + this.javaMailPropertiesFile = javaMailPropertiesFile; + } + + public String getDefaultFrom() { + return defaultFrom; + } + + public void setDefaultFrom(final String defaultFrom) { + this.defaultFrom = defaultFrom; + } + + public Boolean getSendHtml() { + return sendHtml; + } + + public void setSendHtml(final Boolean sendHtml) { + this.sendHtml = sendHtml; + } + + @Override + public int hashCode() { + int hash = 3; + hash = 67 * hash + Objects.hashCode(debug); + hash = 67 * hash + Objects.hashCode(javaMailPropertiesFile); + hash = 67 * hash + Objects.hashCode(defaultFrom); + hash = 67 * hash + Objects.hashCode(sendHtml); + return hash; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; } + if (obj == null) { + return false; + } + if (!(obj instanceof MailConfig)) { + return false; + } + final MailConfig other = (MailConfig) obj; + if (!Objects.equals(javaMailPropertiesFile, + other.getJavaMailPropertiesFile())) { + return false; + } + if (!Objects.equals(defaultFrom, other.getDefaultFrom())) { + return false; + } + if (!Objects.equals(debug, other.isDebug())) { + return false; + } + return Objects.equals(sendHtml, other.getSendHtml()); + } + + @Override + public String toString() { + return String.format( + "%s{ " + + "debug = %b, " + + "javaMailPropertiesFile = \"%s\", " + + "defaultFrom = \"%s\", " + + "sendHtml = %b" + + " }", + super.toString(), + debug, + javaMailPropertiesFile, + defaultFrom, + sendHtml); } } diff --git a/ccm-core/src/main/java/com/arsdigita/xml/XMLConfig.java b/ccm-core/src/main/java/com/arsdigita/xml/XMLConfig.java deleted file mode 100644 index 31b98dd94..000000000 --- a/ccm-core/src/main/java/com/arsdigita/xml/XMLConfig.java +++ /dev/null @@ -1,237 +0,0 @@ -/* - * Copyright (C) 2004 Red Hat Inc. All Rights Reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ -package com.arsdigita.xml; - -import com.arsdigita.runtime.AbstractConfig; -import com.arsdigita.util.parameter.Parameter; -import com.arsdigita.util.parameter.BooleanParameter; -import com.arsdigita.util.parameter.StringParameter; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.SAXParserFactory; - -import org.apache.log4j.Logger; - -/** - * Stores the configuration record for the XML functionality. - * - * Most important: Configuration of the XML factories: - Document Builder - Sax Parser - XSL - * Transformer - * - * @version $Id: XMLConfig.java 1393 2006-11-28 09:12:32Z sskracic $ - */ -public final class XMLConfig extends AbstractConfig { - - /** - * Internal logger instance to faciliate debugging. Enable logging output by editing - * /WEB-INF/conf/log4j.properties int hte runtime environment and set - * com.arsdigita.xml.XMLConfig=DEBUG by uncommenting or adding the line. - */ - private static final Logger s_log = Logger.getLogger(XMLConfig.class); - - /** - * Private instance of this class to be returned after initialization. - */ - private static XMLConfig s_config; - - /** - * Returns the singleton configuration record for the XML functionality - * - * @return The XMLConfig record; it cannot be null - */ - public static final synchronized XMLConfig getConfig() { - if (s_config == null) { - s_config = new XMLConfig(); - // read values from the persistent storage - s_config.load(); - } - - return s_config; - } - - // supported XSL transformer implementations - private static final String RESIN = "com.caucho.xsl.Xsl"; - private static final String SAXON = "com.icl.saxon.TransformerFactoryImpl"; - private static final String SAXON_HE = "net.sf.saxon.TransformerFactoryImpl"; - private static final String XALAN = "org.apache.xalan.processor.TransformerFactoryImpl"; - private static final String XSLTC = "org.apache.xalan.xsltc.trax.TransformerFactoryImpl"; - - // supported documentBuilder implementations - private static final String DOM_XERCES = "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl"; - private static final String DOM_RESIN = "com.caucho.xml.parsers.XmlDocumentBuilderFactory"; - - // supported SAX parser implementations - private static final String SAX_XERCES = "org.apache.xerces.jaxp.SAXParserFactoryImpl"; - private static final String SAX_RESIN = "com.caucho.xml.parsers.XmlSAXParserFactory"; - - private final Parameter m_xfmr = new StringParameter( - "waf.xml.xsl_transformer", - Parameter.REQUIRED, "saxon"); - private final Parameter m_builder = new StringParameter( - "waf.xml.dom_builder", - Parameter.REQUIRED, "xerces"); - private final Parameter m_parser = new StringParameter( - "waf.xml.sax_parser", - Parameter.REQUIRED, "xerces"); - - private final Parameter m_activateFullTimeFormatter = new BooleanParameter( - "waf.xml.activate_full_date_formatter", - Parameter.OPTIONAL, false); - - /** - * Constructs an empty XMLConfig object following the singleton pattern. - * - * They are meant as a singleton pattern (with private constructor), but it does not work with - * the associated classes AbstractConfig and ConfigRegistry because they can currently not deal - * with a private constructor - */ - // private XMLConfig() { - public XMLConfig() { - - super(); - - register(m_xfmr); - register(m_builder); - register(m_parser); - register(m_activateFullTimeFormatter); - - loadInfo(); - } - - /* ************ public getter / setter section ************ */ - /** - * Returns the XSL Transformer factory class name to use. - * - * The method assures that the return value is a valid class name. - * - * @return String XSL Transformer factory class name - */ - public String getXSLTransformerFactoryClassname() { - - final String key = (String) get(m_xfmr); - - // Defined values: saxon (default)|jd.xslt|resin|xalan|xsltc - if (key.equalsIgnoreCase("xsltc")) { - return XSLTC; - } else if (key.equalsIgnoreCase("xalan")) { - return XALAN; - } else if (key.equalsIgnoreCase("resin")) { - return RESIN; - } else if (key.equalsIgnoreCase("saxonhe")) { - return SAXON_HE; - } else { - // return defaultValue - return getDefaultXSLTransformerFactoryClassname(); - } - } - - /** - * Returns the class name of the default {@link TransformerFactory}. This method encapsulates - * the default value so that is easy to change. The method is only for use by the - * classes in the {@code com.arsdigita.xml} package, therefore the method is {@code protected}. - * - * @return - */ - protected String getDefaultXSLTransformerFactoryClassname() { - return SAXON; - } - - /** - * Returns the Document Builder factory class name to use - * - * The method assures that the return value is a valid class name. - * - * Not used at the moment. - * - * @return String Document Builder factory class name - */ - public String getDOMBuilderFactoryClassname() { - - final String key = (String) get(m_builder); - - // Defined values: xerces (default)|resin - if (key.equalsIgnoreCase("resin")) { - return DOM_RESIN; - } else { - return getDefaultDOMBuilderFactoryClassname(); - } - } - - /** - * Returns the class name of the default {@link DocumentBuilderFactory}. - * This method encapsulates the default value so that is easy to change. The method is only for - * use by the classes in the {@code com.arsdigita.xml} package, therefore the method is - * {@code protected}. - * - * @return - */ - protected String getDefaultDOMBuilderFactoryClassname() { - return DOM_XERCES; - } - - /** - * Returns the Sax Parser factory class name to use. - * - * The method assures that the return value is a valid class name. - * - * Not used at the moment. - * - * @return String Sax Parser factory class name - */ - public String getSAXParserFactoryClassname() { - - final String key = (String) get(m_parser); - - // Defined values: xerces (default)|resin - if (key.equalsIgnoreCase("resin")) { - return SAX_RESIN; - } else { - return getDefaultSAXParserFactoryClassname(); - } - } - - /** - * Returns the class name of the default {@link SAXParserFactory}. - * This method encapsulates the default value so that is easy to change. The method is only for - * use by the classes in the {@code com.arsdigita.xml} package, therefore the method is - * {@code protected}. - * - * @return - */ - protected String getDefaultSAXParserFactoryClassname() { - return SAX_XERCES; - } - - /** - * Returns the activateFullTimeFormatter flag. - * - * @return - */ - public boolean getActivateFullTimeFormatter() { - return (Boolean) get(m_activateFullTimeFormatter); - } - - /** - * Sets the activateFullTimeFormatter flag. - * - * @param activateFullTimeFormatter - */ - public void setActivateFullTimeFormatter(final boolean activateFullTimeFormatter) { - set(m_activateFullTimeFormatter, activateFullTimeFormatter); - } -} diff --git a/ccm-core/src/main/java/com/arsdigita/xml/XmlConfig.java b/ccm-core/src/main/java/com/arsdigita/xml/XmlConfig.java new file mode 100644 index 000000000..9a2606270 --- /dev/null +++ b/ccm-core/src/main/java/com/arsdigita/xml/XmlConfig.java @@ -0,0 +1,254 @@ +/* + * Copyright (C) 2016 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package com.arsdigita.xml; + +import org.libreccm.cdi.utils.CdiUtil; +import org.libreccm.configuration.Configuration; +import org.libreccm.configuration.ConfigurationManager; +import org.libreccm.configuration.Setting; + +import java.util.Objects; + +/** + * Stores the configuration record for the XML functionality. + * + * Most important: Configuration of the XML factories: - Document Builder - Sax + * Parser - XSL Transformer + * + * + * @author Jens Pelzetter + */ +@Configuration +public final class XmlConfig { + + // supported XSL transformer implementations + private static final String RESIN = "com.caucho.xsl.Xsl"; + private static final String SAXON = "com.icl.saxon.TransformerFactoryImpl"; + private static final String SAXON_HE = "net.sf.saxon.TransformerFactoryImpl"; + private static final String XALAN + = "org.apache.xalan.processor.TransformerFactoryImpl"; + private static final String XSLTC + = "org.apache.xalan.xsltc.trax.TransformerFactoryImpl"; + + // supported documentBuilder implementations + private static final String DOM_XERCES + = "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl"; + private static final String DOM_RESIN + = "com.caucho.xml.parsers.XmlDocumentBuilderFactory"; + + // supported SAX saxParser implementations + private static final String SAX_XERCES + = "org.apache.xerces.jaxp.SAXParserFactoryImpl"; + private static final String SAX_RESIN + = "com.caucho.xml.parsers.XmlSAXParserFactory"; + + @Setting + private String xslTransformer = "saxonhe"; + + @Setting + private String domBuilder = "xerces"; + + @Setting + private String saxParser = "xerces"; + + @Setting + private Boolean fullTimeFormatterEnabled = false; + + public static XmlConfig getConfig() { + final CdiUtil cdiUtil = new CdiUtil(); + final ConfigurationManager confManager = cdiUtil.findBean( + ConfigurationManager.class); + return confManager.findConfiguration(XmlConfig.class); + } + + public String getXslTransformer() { + return xslTransformer; + } + + public String getXslTransformerFactoryClassname() { + switch (xslTransformer) { + case "xsltc": + return XSLTC; + case "xalan": + return XALAN; + case "resin": + return RESIN; + case "saxonhe": + return SAXON_HE; + default: + return getDefaultXslTransformerFactoryClassname(); + } + } + + /** + * Returns the class name of the default {@link TransformerFactory}. This + * method encapsulates the default value so that is easy to change. The + * method is only for use by the classes in the {@code com.arsdigita.xml} + * package, therefore the method is {@code protected}. + * + * @return + */ + protected String getDefaultXslTransformerFactoryClassname() { + return SAXON; + } + + public void setXslTransformer(final String xslTransformer) { + this.xslTransformer = xslTransformer; + } + + public String getDomBuilder() { + return domBuilder; + } + + /** + * Returns the Document Builder factory class name to use + * + * The method assures that the return value is a valid class name. + * + * Not used at the moment. + * + * @return String Document Builder factory class name + */ + public String getDomBuilderFactoryClassname() { + + switch(domBuilder) { + case "resin": + return DOM_RESIN; + default: + return getDefaultDomBuilderFactoryClassname(); + } + } + + /** + * Returns the class name of the default {@link DocumentBuilderFactory}. + * This method encapsulates the default value so that is easy to change. The method is only for + * use by the classes in the {@code com.arsdigita.xml} package, therefore the method is + * {@code protected}. + * + * @return + */ + protected String getDefaultDomBuilderFactoryClassname() { + return DOM_XERCES; + } + + + public void setDomBuilder(final String domBuilder) { + this.domBuilder = domBuilder; + } + + public String getSaxParser() { + return saxParser; + } + + /** + * Returns the Sax Parser factory class name to use. + * + * The method assures that the return value is a valid class name. + * + * Not used at the moment. + * + * @return String Sax Parser factory class name + */ + public String getSaxParserFactoryClassname() { + + switch(saxParser) { + case "resin": + return SAX_RESIN; + default: + return getDefaultSaxParserFactoryClassname(); + } + } + + /** + * Returns the class name of the default {@link SAXParserFactory}. + * This method encapsulates the default value so that is easy to change. The method is only for + * use by the classes in the {@code com.arsdigita.xml} package, therefore the method is + * {@code protected}. + * + * @return + */ + protected String getDefaultSaxParserFactoryClassname() { + return SAX_XERCES; + } + + + public void setSaxParser(final String saxParser) { + this.saxParser = saxParser; + } + + public Boolean isFullTimeFormatterEnabled() { + return fullTimeFormatterEnabled; + } + + public void setFullTimeFormatterEnabled( + final Boolean fullTimeFormatterEnabled) { + this.fullTimeFormatterEnabled = fullTimeFormatterEnabled; + } + + @Override + public int hashCode() { + int hash = 3; + hash = 19 * hash + Objects.hashCode(xslTransformer); + hash = 19 * hash + Objects.hashCode(domBuilder); + hash = 19 * hash + Objects.hashCode(saxParser); + hash = 19 * hash + Objects.hashCode(fullTimeFormatterEnabled); + return hash; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (!(obj instanceof XmlConfig)) { + return false; + } + final XmlConfig other = (XmlConfig) obj; + if (!Objects.equals(xslTransformer, other.getXslTransformer())) { + return false; + } + if (!Objects.equals(domBuilder, other.getDomBuilder())) { + return false; + } + if (!Objects.equals(saxParser, other.getSaxParser())) { + return false; + } + return Objects.equals(fullTimeFormatterEnabled, + other.isFullTimeFormatterEnabled()); + } + + @Override + public String toString() { + return String.format("%s{ " + + "xslTransformer = \"%s\", " + + "domBuilder = \"%s\", " + + "parser = \"%s\", " + + "fullTimeFormatterEnabled = %b" + + " }", + super.toString(), + xslTransformer, + domBuilder, + saxParser, + fullTimeFormatterEnabled); + } + +} diff --git a/ccm-core/src/main/java/org/libreccm/configuration/ConfigurationManager.java b/ccm-core/src/main/java/org/libreccm/configuration/ConfigurationManager.java index 443b05a42..f413d0525 100644 --- a/ccm-core/src/main/java/org/libreccm/configuration/ConfigurationManager.java +++ b/ccm-core/src/main/java/org/libreccm/configuration/ConfigurationManager.java @@ -272,8 +272,21 @@ public class ConfigurationManager { final ConfigurationInfo confInfo = new ConfigurationInfo(); confInfo.setName(configuration.getClass().getName()); - confInfo.setDescBundle(annotation.descBundle()); - confInfo.setDescKey(annotation.descKey()); + if (annotation.descBundle() == null + || annotation.descBundle().isEmpty()) { + confInfo.setDescBundle(String.join("", + configuration.getClass() + .getName(), + "Description")); + } else { + confInfo.setDescBundle(annotation.descBundle()); + } + if (annotation.descKey() == null + || annotation.descKey().isEmpty()) { + confInfo.setDescKey("description"); + } else { + confInfo.setDescKey(annotation.descKey()); + } final Field[] fields = configuration.getDeclaredFields(); for (final Field field : fields) { @@ -313,7 +326,15 @@ public class ConfigurationManager { final Configuration confAnnotation = configuration.getAnnotation( Configuration.class); - final String descBundle = confAnnotation.descBundle(); + final String descBundle; + if (confAnnotation.descBundle() == null + || confAnnotation.descBundle().isEmpty()) { + descBundle = String.join("", + configuration.getClass().getName(), + "Description"); + } else { + descBundle = confAnnotation.descBundle(); + } final Field field; try { @@ -356,7 +377,12 @@ public class ConfigurationManager { settingInfo.setConfClass(configuration.getName()); settingInfo.setDescBundle(descBundle); - settingInfo.setDescKey(settingAnnotation.descKey()); + if (settingAnnotation.descKey() == null + || settingAnnotation.descKey().isEmpty()) { + settingInfo.setDescKey(field.getName()); + } else { + settingInfo.setDescKey(settingAnnotation.descKey()); + } return settingInfo; } @@ -778,4 +804,5 @@ public class ConfigurationManager { return category; } + } diff --git a/ccm-core/src/main/resources/com/arsdigita/mail/MailConfigDescription.properties b/ccm-core/src/main/resources/com/arsdigita/mail/MailConfigDescription.properties new file mode 100644 index 000000000..cd69401c0 --- /dev/null +++ b/ccm-core/src/main/resources/com/arsdigita/mail/MailConfigDescription.properties @@ -0,0 +1,30 @@ +# Copyright (C) 2016 LibreCCM Foundation. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1301 USA + +description = Configuration for the sending mails + +debug.label = Mail debug flag +debug.description = Enables or disables debugging for the mail component + +javaMailPropertiesFile.label = JavaMail properties URL +javaMailPropertiesFile.description = URL of properties file used to create JavaMail session for outgoing mail, eg file:///etc/javamail.properties + +defaultFrom.label = Default from +defaultFrom.description = Default value for the from E-Mail address for E-Mails send by the system + +sendHtml.label = Send html messages as html emails +sendHtml.description = Determine whether to send html messages as html, or convert to plain mail \ No newline at end of file diff --git a/ccm-core/src/main/resources/com/arsdigita/xml/XMLConfig_parameter.properties b/ccm-core/src/main/resources/com/arsdigita/xml/XMLConfig_parameter.properties deleted file mode 100755 index 4ba793c76..000000000 --- a/ccm-core/src/main/resources/com/arsdigita/xml/XMLConfig_parameter.properties +++ /dev/null @@ -1,19 +0,0 @@ -waf.xml.xsl_transformer.title=XSLT transformer -waf.xml.xsl_transformer.purpose=Define the XSLT transformer factory to use -waf.xml.xsl_transformer.example=Choose one of: saxon (default)|jd.xslt|resin|xalan|xsltc -waf.xml.xsl_transformer.format=[string] - -waf.xml.dom_builder.title=DOM builder -waf.xml.dom_builder.purpose=Define the DOM builder factory to use -waf.xml.dom_builder.example=Choose one of: xerces (default)|resin -waf.xml.dom_builder.format=[string] - -waf.xml.sax_parser.title=SAX parser -waf.xml.sax_parser.purpose=Define the SAX parser factory to use -waf.xml.sax_parser.example=Choose one of: xerces (default)|resin -waf.xml.sax_parser.format=[string] - -waf.xml.activate_full_date_formatter.title=Activate FullDateFormatter -waf.xml.activate_full_date_formatter.purpose=Set this to true to make FullDateFormatter output semantic date XML; the XSL templates may need to be modified accordingly -waf.xml.activate_full_date_formatter.example=true -waf.xml.activate_full_date_formatter.format=[boolean] diff --git a/ccm-core/src/main/resources/com/arsdigita/xml/XmlConfigDescription.properties b/ccm-core/src/main/resources/com/arsdigita/xml/XmlConfigDescription.properties new file mode 100644 index 000000000..fd94dbeb1 --- /dev/null +++ b/ccm-core/src/main/resources/com/arsdigita/xml/XmlConfigDescription.properties @@ -0,0 +1,30 @@ +# Copyright (C) 2016 LibreCCM Foundation. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1301 USA + +description = Stores the configuration record for the XML functionality. + +xslTransformer.label = XSL Transformer +xslTransformer.description = Define the XSL transformer factory to use + +domBuilder.label = DOM Builder +domBuilder.description = Define the DOM builder factory to use + +saxParser.label = SAX Parser +saxParser.description = Define the SAX parser factory to use + +fullTimeFormatterEnabled.label = Enable full time formatter +fullTimeFormatterEnabled.description = Set this to true to make FullDateFormatter output semantic date XML; the XSL templates may need to be modified accordingly