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-94f89814c4dfpull/2/head
parent
d1251b5fc0
commit
05102e0269
|
|
@ -1,106 +1,134 @@
|
|||
/*
|
||||
* 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.dispatcher;
|
||||
|
||||
import com.arsdigita.runtime.AbstractConfig;
|
||||
import com.arsdigita.util.parameter.BooleanParameter;
|
||||
import com.arsdigita.util.parameter.IntegerParameter;
|
||||
import com.arsdigita.util.parameter.Parameter;
|
||||
import com.arsdigita.util.parameter.StringParameter;
|
||||
import org.apache.log4j.Logger;
|
||||
import java.util.Objects;
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
import org.libreccm.configuration.Configuration;
|
||||
import org.libreccm.configuration.ConfigurationManager;
|
||||
import org.libreccm.configuration.Setting;
|
||||
|
||||
/**
|
||||
* @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;
|
||||
private final Parameter m_defaultExpiry;
|
||||
private final Parameter m_staticURLPrefix;
|
||||
@Setting(descKey = "dispatcher.config.default_expiry")
|
||||
private Integer defaultExpiry = 259200;
|
||||
|
||||
/** Default top-level container for all Bebop components and containersPage
|
||||
* to use for dispatching Bebop pages. A custom installation may provide
|
||||
* 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");
|
||||
@Setting(descKey = "dispatcher.config.static_url_prefix")
|
||||
private String staticUrlPrefix = "/STATICII/";
|
||||
|
||||
public DispatcherConfig() {
|
||||
m_cachingActive = new BooleanParameter
|
||||
("waf.dispatcher.is_caching_active",
|
||||
Parameter.REQUIRED, Boolean.TRUE);
|
||||
@Setting(descKey = "dispatcher.config.default_page_class")
|
||||
private String defaultPageClass = "com.arsdigita.bebop.Page";
|
||||
|
||||
// defaults to three days
|
||||
m_defaultExpiry = new IntegerParameter
|
||||
("waf.dispatcher.default_expiry", Parameter.REQUIRED,
|
||||
new Integer(259200));
|
||||
|
||||
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 static DispatcherConfig getConfig() {
|
||||
final CdiUtil cdiUtil = new CdiUtil();
|
||||
final ConfigurationManager confManager = cdiUtil.findBean(
|
||||
ConfigurationManager.class);
|
||||
return confManager.findConfiguration(DispatcherConfig.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the URL for static items
|
||||
*/
|
||||
public String getStaticURLPrefix() {
|
||||
return (String)get(m_staticURLPrefix);
|
||||
public Boolean isCachingActive() {
|
||||
return cachingActive;
|
||||
}
|
||||
|
||||
/**
|
||||
* This returns Boolean.TRUE if the caching is active
|
||||
*/
|
||||
public Boolean getCachingActive() {
|
||||
return (Boolean)get(m_cachingActive);
|
||||
public void setCachingActive(final Boolean cachingActive) {
|
||||
this.cachingActive = cachingActive;
|
||||
}
|
||||
|
||||
public boolean isCachingActive() {
|
||||
return Boolean.TRUE.equals(getCachingActive());
|
||||
public Integer getDefaultExpiry() {
|
||||
return defaultExpiry;
|
||||
}
|
||||
|
||||
/**
|
||||
* This returns the number of seconds something is cached for
|
||||
*/
|
||||
public Integer getDefaultExpiryTime() {
|
||||
return (Integer)get(m_defaultExpiry);
|
||||
public void setDefaultExpiry(final Integer defaultExpiry) {
|
||||
this.defaultExpiry = defaultExpiry;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 getStaticUrlPrefix() {
|
||||
return staticUrlPrefix;
|
||||
}
|
||||
|
||||
public void setStaticUrlPrefix(final String staticUrlPrefix) {
|
||||
this.staticUrlPrefix = staticUrlPrefix;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,7 +69,6 @@ public final class DispatcherHelper implements DispatcherConstants {
|
|||
private static String s_staticURL;
|
||||
private static boolean s_cachingActive;
|
||||
private static int s_defaultExpiry;
|
||||
private static DispatcherConfig s_config;
|
||||
public static SimpleDateFormat rfc1123_formatter;
|
||||
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.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||
|
||||
// set the defaults
|
||||
s_config = getConfig();
|
||||
s_staticURL = s_config.getStaticURLPrefix();
|
||||
s_defaultExpiry = s_config.getDefaultExpiryTime().intValue();
|
||||
s_cachingActive = s_config.isCachingActive();
|
||||
s_staticURL = DispatcherConfig.getConfig().getStaticUrlPrefix();
|
||||
s_defaultExpiry = DispatcherConfig.getConfig().getDefaultExpiry();
|
||||
s_cachingActive = DispatcherConfig.getConfig().isCachingActive();
|
||||
|
||||
initialized = true;
|
||||
}
|
||||
|
|
@ -1115,18 +1112,6 @@ public final class DispatcherHelper implements DispatcherConstants {
|
|||
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
|
||||
* to the other methods available this one will also respect the
|
||||
|
|
|
|||
|
|
@ -1,104 +1,84 @@
|
|||
/*
|
||||
* 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
|
||||
* 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.globalization;
|
||||
|
||||
import com.arsdigita.runtime.AbstractConfig;
|
||||
import com.arsdigita.util.parameter.StringParameter;
|
||||
import com.arsdigita.util.parameter.Parameter;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.util.Objects;
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
import org.libreccm.configuration.Configuration;
|
||||
import org.libreccm.configuration.ConfigurationManager;
|
||||
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
|
||||
* to trap null return values in their code.
|
||||
*
|
||||
* @author Peter Boy <pboy@barkhof.uni-bremen.de>
|
||||
* @version $Id: $
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class GlobalizationConfig extends AbstractConfig {
|
||||
@Configuration(
|
||||
descBundle = "com.arsdigita.globalization.GlobalizationConfigDescription",
|
||||
descKey = "globalization.config.description")
|
||||
public class GlobalizationConfig {
|
||||
|
||||
/** A logger instance. */
|
||||
private static final Logger s_log = Logger.getLogger(GlobalizationConfig.class);
|
||||
@Setting(descKey = "globalization.config.default_charset")
|
||||
private String defaultCharset = "UTF-8";
|
||||
|
||||
/** Singelton config object. */
|
||||
private static GlobalizationConfig s_conf;
|
||||
|
||||
/**
|
||||
* Gain a UIConfig object.
|
||||
*
|
||||
* 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;
|
||||
public static GlobalizationConfig getConfig() {
|
||||
final CdiUtil cdiUtil = new CdiUtil();
|
||||
final ConfigurationManager confManager = cdiUtil.findBean(
|
||||
ConfigurationManager.class);
|
||||
return confManager.findConfiguration(GlobalizationConfig.class);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,6 @@ import com.arsdigita.bebop.event.ActionEvent;
|
|||
import com.arsdigita.bebop.event.ActionListener;
|
||||
import com.arsdigita.bebop.page.BebopApplicationServlet;
|
||||
import com.arsdigita.dispatcher.DispatcherConfig;
|
||||
import com.arsdigita.dispatcher.DispatcherHelper;
|
||||
import com.arsdigita.kernel.security.SecurityConfig;
|
||||
import com.arsdigita.ui.UI;
|
||||
import com.arsdigita.web.ReturnSignal;
|
||||
|
|
@ -227,7 +226,7 @@ public class LoginServlet extends BebopApplicationServlet {
|
|||
*/
|
||||
private static Page checkForPageSubClass() {
|
||||
//check to see if there is subclass of Page defined in Config
|
||||
DispatcherConfig dc = DispatcherHelper.getConfig();
|
||||
DispatcherConfig dc = DispatcherConfig.getConfig();
|
||||
String pageClass = dc.getDefaultPageClass();
|
||||
Page p = null;
|
||||
if (!pageClass.equals("com.arsdigita.bebop.Page")) {
|
||||
|
|
|
|||
|
|
@ -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!
|
||||
|
|
@ -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]
|
||||
|
|
@ -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.
|
||||
|
|
@ -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]
|
||||
Loading…
Reference in New Issue