CCM NG: Migrated DispatcherConfig and GlobalizationConfig to the new configuration system

git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@3796 8810af33-2d31-482b-a856-94f89814c4df
pull/2/head
jensp 2016-01-14 13:47:16 +00:00
parent d1251b5fc0
commit 05102e0269
8 changed files with 207 additions and 195 deletions

View File

@ -1,10 +1,10 @@
/* /*
* 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 * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License * modify it under the terms of the GNU Lesser General Public
* as published by the Free Software Foundation; either version 2.1 of * License as published by the Free Software Foundation; either
* the License, or (at your option) any later version. * 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, * This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
@ -13,94 +13,122 @@
* *
* You should have received a copy of the GNU Lesser General Public * You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software * 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.dispatcher; package com.arsdigita.dispatcher;
import com.arsdigita.runtime.AbstractConfig; import java.util.Objects;
import com.arsdigita.util.parameter.BooleanParameter; import org.libreccm.cdi.utils.CdiUtil;
import com.arsdigita.util.parameter.IntegerParameter; import org.libreccm.configuration.Configuration;
import com.arsdigita.util.parameter.Parameter; import org.libreccm.configuration.ConfigurationManager;
import com.arsdigita.util.parameter.StringParameter; import org.libreccm.configuration.Setting;
import org.apache.log4j.Logger;
/** /**
* @author Randy Graebner *
* @version $Id: DispatcherConfig.java 1169 2006-06-14 13:08:25Z fabrice $ * @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/ */
public final class DispatcherConfig extends AbstractConfig { @Configuration(descBundle = "com.arsdigita.dispatcher.DispatcherConfigDescription",
descKey = "dispatcher.config.description")
public final class DispatcherConfig {
private static final Logger s_log = Logger.getLogger(DispatcherConfig.class); @Setting(descKey = "dispatcher.config.caching_active")
private Boolean cachingActive = true;
private final Parameter m_cachingActive; @Setting(descKey = "dispatcher.config.default_expiry")
private final Parameter m_defaultExpiry; private Integer defaultExpiry = 259200;
private final Parameter m_staticURLPrefix;
/** Default top-level container for all Bebop components and containersPage @Setting(descKey = "dispatcher.config.static_url_prefix")
* to use for dispatching Bebop pages. A custom installation may provide private String staticUrlPrefix = "/STATICII/";
* it's own implementation. Use with care because all pages inherit from
* this class!
* Default is {@see com.arsdigita.bebop.Page} */
private final Parameter m_defaultPageClass= new
StringParameter("waf.dispatcher.default_page_class",
Parameter.OPTIONAL,
"com.arsdigita.bebop.Page");
public DispatcherConfig() { @Setting(descKey = "dispatcher.config.default_page_class")
m_cachingActive = new BooleanParameter private String defaultPageClass = "com.arsdigita.bebop.Page";
("waf.dispatcher.is_caching_active",
Parameter.REQUIRED, Boolean.TRUE);
// defaults to three days public static DispatcherConfig getConfig() {
m_defaultExpiry = new IntegerParameter final CdiUtil cdiUtil = new CdiUtil();
("waf.dispatcher.default_expiry", Parameter.REQUIRED, final ConfigurationManager confManager = cdiUtil.findBean(
new Integer(259200)); ConfigurationManager.class);
return confManager.findConfiguration(DispatcherConfig.class);
m_staticURLPrefix = new StringParameter
("waf.dispatcher.static_url_prefix", Parameter.REQUIRED,
"/STATICII/");
register(m_staticURLPrefix);
register(m_cachingActive);
register(m_defaultExpiry);
register(m_defaultPageClass);
loadInfo();
} }
/** public Boolean isCachingActive() {
* Get the URL for static items return cachingActive;
*/
public String getStaticURLPrefix() {
return (String)get(m_staticURLPrefix);
} }
/** public void setCachingActive(final Boolean cachingActive) {
* This returns Boolean.TRUE if the caching is active this.cachingActive = cachingActive;
*/
public Boolean getCachingActive() {
return (Boolean)get(m_cachingActive);
} }
public boolean isCachingActive() { public Integer getDefaultExpiry() {
return Boolean.TRUE.equals(getCachingActive()); return defaultExpiry;
} }
/** public void setDefaultExpiry(final Integer defaultExpiry) {
* This returns the number of seconds something is cached for this.defaultExpiry = defaultExpiry;
*/ }
public Integer getDefaultExpiryTime() {
return (Integer)get(m_defaultExpiry); public String getStaticUrlPrefix() {
return staticUrlPrefix;
}
public void setStaticUrlPrefix(final String staticUrlPrefix) {
this.staticUrlPrefix = staticUrlPrefix;
} }
/**
* Retrieve the top-level container for all Bebop components and
* containersPage to use by dispatcher.
* Most installation should use the provided default implementation in
* {@see com.arsdigita.bebop.Page}
*/
public String getDefaultPageClass() { public String getDefaultPageClass() {
return (String)get(m_defaultPageClass); return defaultPageClass;
}
public void setDefaultPageClass(final String defaultPageClass) {
this.defaultPageClass = defaultPageClass;
}
@Override
public int hashCode() {
int hash = 7;
hash = 97 * hash + Objects.hashCode(cachingActive);
hash = 97 * hash + Objects.hashCode(defaultExpiry);
hash = 97 * hash + Objects.hashCode(staticUrlPrefix);
hash = 97 * hash + Objects.hashCode(defaultPageClass);
return hash;
}
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof DispatcherConfig)) {
return false;
}
final DispatcherConfig other = (DispatcherConfig) obj;
if (!Objects.equals(staticUrlPrefix, other.getStaticUrlPrefix())) {
return false;
}
if (!Objects.equals(defaultPageClass, other.getDefaultPageClass())) {
return false;
}
if (!Objects.equals(cachingActive, other.isCachingActive())) {
return false;
}
return Objects.equals(defaultExpiry, other.getDefaultExpiry());
}
@Override
public String toString() {
return String.format("%s{ "
+ "cachingActive = %b, "
+ "defaultExpiry = %d, "
+ "staticUrlPrefix = \"%s\", "
+ "defaultPageClass = \"%s\""
+ " }",
super.toString(),
cachingActive,
defaultExpiry,
staticUrlPrefix,
defaultPageClass);
} }
} }

View File

@ -69,7 +69,6 @@ public final class DispatcherHelper implements DispatcherConstants {
private static String s_staticURL; private static String s_staticURL;
private static boolean s_cachingActive; private static boolean s_cachingActive;
private static int s_defaultExpiry; private static int s_defaultExpiry;
private static DispatcherConfig s_config;
public static SimpleDateFormat rfc1123_formatter; public static SimpleDateFormat rfc1123_formatter;
private static boolean initialized = false; private static boolean initialized = false;
@ -81,11 +80,9 @@ public final class DispatcherHelper implements DispatcherConstants {
rfc1123_formatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z"); rfc1123_formatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z");
rfc1123_formatter.setTimeZone(TimeZone.getTimeZone("GMT")); rfc1123_formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
// set the defaults s_staticURL = DispatcherConfig.getConfig().getStaticUrlPrefix();
s_config = getConfig(); s_defaultExpiry = DispatcherConfig.getConfig().getDefaultExpiry();
s_staticURL = s_config.getStaticURLPrefix(); s_cachingActive = DispatcherConfig.getConfig().isCachingActive();
s_defaultExpiry = s_config.getDefaultExpiryTime().intValue();
s_cachingActive = s_config.isCachingActive();
initialized = true; initialized = true;
} }
@ -1115,18 +1112,6 @@ public final class DispatcherHelper implements DispatcherConstants {
cacheForWorld(response, (int) ((expiry.getTime() - (new Date()).getTime()) / 1000l)); cacheForWorld(response, (int) ((expiry.getTime() - (new Date()).getTime()) / 1000l));
} }
/**
* This returns a reference to the dispatcher configuration file
* @return
*/
public static DispatcherConfig getConfig() {
if (s_config == null) {
s_config = new DispatcherConfig();
s_config.load();
}
return s_config;
}
/** /**
* This method returns the best matching locale for the request. In contrast * This method returns the best matching locale for the request. In contrast
* to the other methods available this one will also respect the * to the other methods available this one will also respect the

View File

@ -1,10 +1,10 @@
/* /*
* Copyright (C) 2010 pboy (pboy@barkhof.uni-bremen.de) All Rights Reserved. * Copyright (C) 2016 LibreCCM Foundation.
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License * modify it under the terms of the GNU Lesser General Public
* as published by the Free Software Foundation; either version 2.1 of * License as published by the Free Software Foundation; either
* the License, or (at your option) any later version. * 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, * This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
@ -13,92 +13,72 @@
* *
* You should have received a copy of the GNU Lesser General Public * You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software * 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.globalization; package com.arsdigita.globalization;
import com.arsdigita.runtime.AbstractConfig; import java.util.Objects;
import com.arsdigita.util.parameter.StringParameter; import org.libreccm.cdi.utils.CdiUtil;
import com.arsdigita.util.parameter.Parameter; import org.libreccm.configuration.Configuration;
import org.libreccm.configuration.ConfigurationManager;
import org.apache.log4j.Logger; import org.libreccm.configuration.Setting;
/** /**
* A configuration record for configuration of the core globalization package
* *
* Accessors of this class may return null. Developers should take care * @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
* to trap null return values in their code.
*
* @author Peter Boy &lt;pboy@barkhof.uni-bremen.de&gt;
* @version $Id: $
*/ */
public class GlobalizationConfig extends AbstractConfig { @Configuration(
descBundle = "com.arsdigita.globalization.GlobalizationConfigDescription",
descKey = "globalization.config.description")
public class GlobalizationConfig {
/** A logger instance. */ @Setting(descKey = "globalization.config.default_charset")
private static final Logger s_log = Logger.getLogger(GlobalizationConfig.class); private String defaultCharset = "UTF-8";
/** Singelton config object. */ public static GlobalizationConfig getConfig() {
private static GlobalizationConfig s_conf; final CdiUtil cdiUtil = new CdiUtil();
final ConfigurationManager confManager = cdiUtil.findBean(
/** ConfigurationManager.class);
* Gain a UIConfig object. return confManager.findConfiguration(GlobalizationConfig.class);
*
* Singelton pattern, don't instantiate a lifecacle object using the
* constructor directly!
* @return
*/
public static synchronized GlobalizationConfig getConfig() {
if (s_conf == null) {
s_conf = new GlobalizationConfig();
s_conf.load();
} }
return s_conf;
}
/**
* Default character set for locales not explicitly listed above in the
* locales parameter.
* This parameter is read each time the system starts. Therefore, modifications
* will take effect after a CCM restart.
*/
// In OLD initializer: DEFAULT_CHARSET as String
private final Parameter m_defaultCharset =
new StringParameter(
"core.globalization.default_charset",
Parameter.REQUIRED, "UTF-8");
/**
* Constructs an empty RuntimeConfig object.
*
*/
public GlobalizationConfig() {
// pboy: According to the comment for the getConfig() method a singleton
// pattern is to be used. Therefore the constructor should be changed to
// private!
// private GlobalizationConfig() {
register(m_defaultCharset);
loadInfo();
}
/**
* Retrieve the default char set to be used for locales not explicitly
* listed in the supported locales list.
*
* @return root page url
*/
public String getDefaultCharset() { public String getDefaultCharset() {
return (String)get(m_defaultCharset) ; return defaultCharset;
} }
public void setDefaultCharset(final String defaultCharset) {
this.defaultCharset = defaultCharset;
}
@Override
public int hashCode() {
int hash = 5;
hash = 43 * hash + Objects.hashCode(defaultCharset);
return hash;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof GlobalizationConfig)) {
return false;
}
final GlobalizationConfig other = (GlobalizationConfig) obj;
return Objects.equals(defaultCharset, other.defaultCharset);
}
@Override
public String toString() {
return String.format("%s{ "
+ "defaultCharset = \"%s\""
+ " }",
super.toString(),
defaultCharset);
}
} }

View File

@ -29,7 +29,6 @@ import com.arsdigita.bebop.event.ActionEvent;
import com.arsdigita.bebop.event.ActionListener; import com.arsdigita.bebop.event.ActionListener;
import com.arsdigita.bebop.page.BebopApplicationServlet; import com.arsdigita.bebop.page.BebopApplicationServlet;
import com.arsdigita.dispatcher.DispatcherConfig; import com.arsdigita.dispatcher.DispatcherConfig;
import com.arsdigita.dispatcher.DispatcherHelper;
import com.arsdigita.kernel.security.SecurityConfig; import com.arsdigita.kernel.security.SecurityConfig;
import com.arsdigita.ui.UI; import com.arsdigita.ui.UI;
import com.arsdigita.web.ReturnSignal; import com.arsdigita.web.ReturnSignal;
@ -227,7 +226,7 @@ public class LoginServlet extends BebopApplicationServlet {
*/ */
private static Page checkForPageSubClass() { private static Page checkForPageSubClass() {
//check to see if there is subclass of Page defined in Config //check to see if there is subclass of Page defined in Config
DispatcherConfig dc = DispatcherHelper.getConfig(); DispatcherConfig dc = DispatcherConfig.getConfig();
String pageClass = dc.getDefaultPageClass(); String pageClass = dc.getDefaultPageClass();
Page p = null; Page p = null;
if (!pageClass.equals("com.arsdigita.bebop.Page")) { if (!pageClass.equals("com.arsdigita.bebop.Page")) {

View File

@ -0,0 +1,23 @@
# 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
dispatcher.config.description = Configuration for the Dispatcher
dispatcher.config.caching_active = Toggle whether or not to use HTTP/1.1 caching
dispatcher.config.default_expiry = Set the default expiration time for HTTP caching
dispatcher.config.static_url_prefix = Prefix used for serving static files
dispatcher.config.default_page_class = The default page class. A custom installation may provide it's own implementation. Use with care because all pages inherit from this class!

View File

@ -1,19 +0,0 @@
waf.dispatcher.static_url_prefix.title=Static URL Prefix
waf.dispatcher.static_url_prefix.purpose=Prefix used for serving static files
waf.dispatcher.static_url_prefix.example=/STATIC/
waf.dispatcher.static_url_prefix.format=[url]
waf.dispatcher.is_caching_active.title=Dispatcher caching enabled
waf.dispatcher.is_caching_active.purpose=Toggle whether or not to use HTTP/1.1 caching
waf.dispatcher.is_caching_active.example=true
waf.dispatcher.is_caching_active.format=true|false
waf.dispatcher.default_expiry.title=Default cache expiration
waf.dispatcher.default_expiry.purpose=Set the default expiration time for HTTP caching
waf.dispatcher.default_expiry.example=259200
waf.dispatcher.default_expiry.format=[integer]
waf.dispatcher.default_page_class.title=Default page class
waf.dispatcher.default_page_class.purpose=the default page class
waf.dispatcher.default_page_class.example=com.arsdigita.bebop.Page
waf.dispatcher.default_page_class.format=[String]

View File

@ -0,0 +1,20 @@
# 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
globalization.config.description = A configuration record for configuration of the core globalization package
globalization.config.default_charset = Default character set for locales not explicitly listed in the locales parameter.

View File

@ -1,4 +0,0 @@
core.globalization.default_charset.title=Default Charset
core.globalization.default_charset.purpose=Default character set for locales not explicitly listed in the locales parameter.
core.globalization.default_charset.example="UTF-8"
core.globalization.default_charset.format=[String]