diff --git a/ccm-core/src/main/java/com/arsdigita/bebop/page/PageTransformer.java b/ccm-core/src/main/java/com/arsdigita/bebop/page/PageTransformer.java
index df46062e6..b9cfa1c65 100755
--- a/ccm-core/src/main/java/com/arsdigita/bebop/page/PageTransformer.java
+++ b/ccm-core/src/main/java/com/arsdigita/bebop/page/PageTransformer.java
@@ -29,6 +29,7 @@ import com.arsdigita.templating.XSLParameterGenerator;
import com.arsdigita.templating.XSLTemplate;
import com.arsdigita.util.Assert;
import com.arsdigita.util.UncheckedWrapperException;
+import com.arsdigita.web.CCMDispatcherServlet;
import com.arsdigita.web.Debugger;
import com.arsdigita.web.TransformationDebugger;
import com.arsdigita.web.Web;
@@ -84,199 +85,199 @@ public class PageTransformer implements PresentationManager {
registerXSLParameterGenerator("contextPath",
new XSLParameterGenerator() {
- @Override
- public String generateValue(
+ @Override
+ public String generateValue(
HttpServletRequest request) {
- return request
+ return request
.getContextPath();
- }
+ }
- });
+ });
registerXSLParameterGenerator("root-context-prefix",
new XSLParameterGenerator() {
- @Override
- public String generateValue(
+ @Override
+ public String generateValue(
HttpServletRequest request) {
- return Web.getConfig()
- .getDispatcherContextPath();
- }
+ return CCMDispatcherServlet
+ .getContextPath();
+ }
- });
+ });
registerXSLParameterGenerator("context-prefix",
new XSLParameterGenerator() {
- @Override
- public String generateValue(
+ @Override
+ public String generateValue(
HttpServletRequest request) {
- return Web.getWebContext()
+ return Web.getWebContext()
.getRequestURL()
.getContextPath();
- }
+ }
- });
+ });
registerXSLParameterGenerator("internal-theme",
new XSLParameterGenerator() {
- @Override
- public String generateValue(
+ @Override
+ public String generateValue(
HttpServletRequest request) {
- return Web.getWebContext()
+ return Web.getWebContext()
.getRequestURL()
.getContextPath()
+ com.arsdigita.web.URL.INTERNAL_THEME_DIR;
- }
+ }
- });
+ });
registerXSLParameterGenerator("dispatcher-prefix",
new XSLParameterGenerator() {
- @Override
- public String generateValue(
+ @Override
+ public String generateValue(
HttpServletRequest request) {
- return com.arsdigita.web.URL
+ return com.arsdigita.web.URL
.getDispatcherPath();
- }
+ }
- });
+ });
registerXSLParameterGenerator("dcp-on-buttons",
new XSLParameterGenerator() {
- @Override
- public String generateValue(
+ @Override
+ public String generateValue(
HttpServletRequest request) {
- if (BebopConfig.getConfig()
+ if (BebopConfig.getConfig()
.getDcpOnButtons()) {
- return "true";
- } else {
- return null;
+ return "true";
+ } else {
+ return null;
+ }
+
}
- }
-
- });
+ });
registerXSLParameterGenerator("dcp-on-links",
new XSLParameterGenerator() {
- @Override
- public String generateValue(
+ @Override
+ public String generateValue(
HttpServletRequest request) {
- if (BebopConfig.getConfig()
+ if (BebopConfig.getConfig()
.getDcpOnLinks()) {
- return "true";
- } else {
- return null;
+ return "true";
+ } else {
+ return null;
+ }
+
}
- }
-
- });
+ });
registerXSLParameterGenerator("user-agent",
new XSLParameterGenerator() {
- @Override
- public String generateValue(
+ @Override
+ public String generateValue(
HttpServletRequest request) {
- return request.getHeader(
+ return request.getHeader(
"User-Agent");
- }
+ }
- });
+ });
registerXSLParameterGenerator("negotiated-language",
new XSLParameterGenerator() {
- @Override
- public String generateValue(
+ @Override
+ public String generateValue(
HttpServletRequest request) {
- return GlobalizationHelper
+ return GlobalizationHelper
.getNegotiatedLocale()
.getLanguage();
- }
+ }
- });
+ });
registerXSLParameterGenerator("selected-language",
new XSLParameterGenerator() {
- @Override
- public String generateValue(
+ @Override
+ public String generateValue(
HttpServletRequest request) {
- Locale selectedLocale
- = com.arsdigita.globalization.GlobalizationHelper.
- getSelectedLocale(request);
- return (selectedLocale != null)
- ? selectedLocale
+ Locale selectedLocale
+ = com.arsdigita.globalization.GlobalizationHelper
+ .getSelectedLocale(request);
+ return (selectedLocale != null)
+ ? selectedLocale
.toString() : "";
- }
+ }
- });
+ });
registerXSLParameterGenerator("request-scheme",
new XSLParameterGenerator() {
- @Override
- public String generateValue(
+ @Override
+ public String generateValue(
HttpServletRequest request) {
- return request.getScheme();
- }
+ return request.getScheme();
+ }
- });
+ });
registerXSLParameterGenerator("server-name",
new XSLParameterGenerator() {
- @Override
- public String generateValue(
+ @Override
+ public String generateValue(
HttpServletRequest request) {
- return request.getServerName();
- }
+ return request.getServerName();
+ }
- });
+ });
registerXSLParameterGenerator("server-port",
new XSLParameterGenerator() {
- @Override
- public String generateValue(
+ @Override
+ public String generateValue(
HttpServletRequest request) {
- return Integer.toString(
+ return Integer.toString(
request.getServerPort());
- }
+ }
- });
+ });
registerXSLParameterGenerator("host",
new XSLParameterGenerator() {
- @Override
- public String generateValue(
+ @Override
+ public String generateValue(
HttpServletRequest request) {
- if (request.getServerPort()
+ if (request.getServerPort()
== 80) {
- return String.format(
+ return String.format(
"%s://%s", request
.getScheme(), request
.getServerName());
- } else {
- return String.format(
+ } else {
+ return String.format(
"%s://%s:%d",
request.getScheme(),
request
.getServerName(),
request
.getServerPort());
+ }
}
- }
- });
+ });
s_log.debug("Static initalizer finished.");
}
@@ -343,7 +344,7 @@ public class PageTransformer implements PresentationManager {
try {
return new PrintWriter(new OutputStreamWriter(resp.
- getOutputStream(),
+ getOutputStream(),
charset));
} catch (IOException ex) {
throw new UncheckedWrapperException(ex);
@@ -372,11 +373,11 @@ public class PageTransformer implements PresentationManager {
* always be passed to XSLT, which is the value of
* req.getWebContextPath().
*
- * @param doc the Bebop page to serve
- * @param req the servlet request
- * @param resp the servlet response
+ * @param doc the Bebop page to serve
+ * @param req the servlet request
+ * @param resp the servlet response
* @param params a set of name-value pairs to pass as parameters to the
- * Transformer
+ * Transformer
*/
public void servePage(final Document doc,
final HttpServletRequest req,
@@ -393,7 +394,7 @@ public class PageTransformer implements PresentationManager {
try {
final String charset = Globalization
- .getDefaultCharset(DispatcherHelper.getNegotiatedLocale());
+ .getDefaultCharset(DispatcherHelper.getNegotiatedLocale());
final String output = req.getParameter("output");
s_log.info("output=" + output);
@@ -401,16 +402,16 @@ public class PageTransformer implements PresentationManager {
if (output == null) {
boolean fancyErrors
- = BebopConfig.getConfig().getFancyErrors()
+ = BebopConfig.getConfig().getFancyErrors()
|| Boolean.TRUE.equals(req.getAttribute(
- FANCY_ERRORS));
+ FANCY_ERRORS));
// Get the stylesheet transformer object corresponding to the
// current request.
final XSLTemplate template = Templating.getTemplate(
- req,
- fancyErrors,
- !Boolean.TRUE.equals(req.getAttribute(CACHE_XSL_NONE)));
+ req,
+ fancyErrors,
+ !Boolean.TRUE.equals(req.getAttribute(CACHE_XSL_NONE)));
final PrintWriter writer = getWriter(resp, "text/html", charset);
@@ -450,15 +451,15 @@ public class PageTransformer implements PresentationManager {
new StreamResult(writer));
} catch (TransformerException ex) {
throw new UncheckedWrapperException(
- "cannot transform document", ex);
+ "cannot transform document", ex);
}
// copy and paste from BasePresentationManager
if (KernelConfig.getConfig().isDebugEnabled()) {
Document origDoc = (Document) req.getAttribute(
- "com.arsdigita.xml.Document");
+ "com.arsdigita.xml.Document");
Debugger.addDebugger(new TransformationDebugger(template.
- getSource(), template.getDependents()));
+ getSource(), template.getDependents()));
writer.print(Debugger.getDebugging(req));
}
@@ -478,11 +479,11 @@ public class PageTransformer implements PresentationManager {
// current request.
template = Templating.getTemplate(req,
Boolean.TRUE.equals(req
- .getAttribute(
- PageTransformer.FANCY_ERRORS)),
+ .getAttribute(
+ PageTransformer.FANCY_ERRORS)),
!Boolean.TRUE.equals(req
- .getAttribute(
- PageTransformer.CACHE_XSL_NONE)));
+ .getAttribute(
+ PageTransformer.CACHE_XSL_NONE)));
endTransaction(req);
} finally {
}
@@ -490,7 +491,7 @@ public class PageTransformer implements PresentationManager {
try {
Date now = new Date();
SimpleDateFormat fmt = new SimpleDateFormat(
- "yyyy-MM-dd-HH-mm");
+ "yyyy-MM-dd-HH-mm");
String prefix = "waf-xsl-" + fmt.format(now);
final OutputStream os = resp.getOutputStream();
@@ -509,7 +510,7 @@ public class PageTransformer implements PresentationManager {
}
} else {
throw new IllegalStateException(output
- + " is an unknown output");
+ + " is an unknown output");
}
} finally {
}
@@ -576,8 +577,8 @@ public class PageTransformer implements PresentationManager {
public static String getXSLParameterValue(String name,
HttpServletRequest request) {
XSLParameterGenerator generator
- = (XSLParameterGenerator) s_XSLParameters
- .get(name);
+ = (XSLParameterGenerator) s_XSLParameters
+ .get(name);
if (generator != null) {
return generator.generateValue(request);
} else {
@@ -600,7 +601,7 @@ public class PageTransformer implements PresentationManager {
final Map.Entry entry = (Map.Entry) entries.next();
String value = ((XSLParameterGenerator) entry.getValue()).
- generateValue(request);
+ generateValue(request);
if (value == null) {
// XSL does not like nulls
value = "";
diff --git a/ccm-core/src/main/java/com/arsdigita/runtime/AbstractConfig.java b/ccm-core/src/main/java/com/arsdigita/runtime/AbstractConfig.java
deleted file mode 100644
index f83501cb2..000000000
--- a/ccm-core/src/main/java/com/arsdigita/runtime/AbstractConfig.java
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- * 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.runtime;
-
-import com.arsdigita.util.parameter.AbstractParameterContext;
-import com.arsdigita.util.parameter.ErrorList;
-import org.apache.log4j.Logger;
-
-/**
- * AbstractConfig is a base class for groups of customizable
- * configuration {@link com.arsdigita.util.parameter parameters}. A
- * CCM Developer wishing to add a new group of configuration
- * parameters to his application will extend this class and provide a
- * public noargs constructer that registers his parameters with the
- * superclass. For example:
- *
- *
- * package com.arsdigita.exampleApp;
- *
- * public final class ExampleConfig extends AbstractConfig {
- *
- * private Parameter m_string = new StringParameter
- * ("example.string", Parameter.OPTIONAL, "default");
- * private Parameter m_integer = new IntegerParameter
- * ("example.integer", Parameter.OPTIONAL, new Integer(0));
- * private Parameter m_boolean = new BooleanParameter
- * ("example.boolean", Parameter.OPTIONAL, Boolean.TRUE);
- *
- * public ExampleConfig() {
- * register(m_string);
- * register(m_integer);
- * register(m_boolean);
- * loadInfo();
- * }
- *
- * public String getString() {
- * return (String) get(m_string);
- * }
- *
- * public int getInteger() {
- * return ((Integer) get(m_integer)).intValue();
- * }
- *
- * public boolean getBoolean() {
- * return Boolean.TRUE.equals(get(m_boolean));
- * }
- *
- * }
- *
- *
- * When this pattern is followed, the resulting subclass of abstract
- * config may be used by developers writing java code to access the
- * values of customizable configuration parameters in a convenient and
- * type safe manner. In addition, the very same class is also usable
- * by the ccm configuration tools to allow customization and
- * validation of the new parameters.
- *
- * @author Justin Ross <jross@redhat.com>
- * @version $Id$
- */
-public abstract class AbstractConfig extends AbstractParameterContext {
-
- private static final Logger s_log = Logger.getLogger
- (AbstractConfig.class);
-
- /**
- * Default constructor for subclasses.
- */
- protected AbstractConfig() {}
-
- /**
- * Loads this AbstractConfig object with values from the default
- * configuration registry. Any errors encountered during
- * unmarshaling and loading of configuration values are added to
- * the errors ErrorList. This method should not be
- * called from the constructor of a config object since the ccm
- * configuration tools need to be able to construct empty config
- * objects.
- *
- * @param errors The ErrorList used to record errors during
- * unmarshaling and loading.
- *
- * @see ConfigRegistry
- */
- public final void load(ErrorList errors) {
- ConfigRegistry reg = new ConfigRegistry();
- reg.load(this, errors);
- }
-
- /**
- * Invokes the {@link #load(ErrorList)} method with a new and
- * empty ErrorList for accumulating errors, and returns that
- * ErrorList. This method can be used in combination with the
- * {@link ErrorList#check()} method to load and assert that this
- * configuration object is valid in one simple idiom. For example:
- *
- * - * - * @return Errors that may have been encountered during - * configuration loading. - * - * @see #load(ErrorList) - */ - public final ErrorList load() { - ErrorList errs = new ErrorList(); - load(errs); - return errs; - } - - /** - * @deprecated Use @{link #load()} instead. - */ - public final ErrorList load(final String resource) { - return load(); - } - - /** - * @deprecated Use @{link #load()} instead. - */ - public final ErrorList require(final String resource) { - return load(); - } -} diff --git a/ccm-core/src/main/java/com/arsdigita/runtime/ConfigError.java b/ccm-core/src/main/java/com/arsdigita/runtime/ConfigError.java deleted file mode 100644 index 5f98d6963..000000000 --- a/ccm-core/src/main/java/com/arsdigita/runtime/ConfigError.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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.runtime; - -import com.arsdigita.util.Assert; -import org.apache.log4j.Logger; - -/** - * Subject to change. - * - * An error to indicate invalid configurations. - * - * Usage: throw new ConfigError( "message" ); - * - * @author Justin Ross <jross@redhat.com> - */ -public class ConfigError extends Error { - - private static final long serialVersionUID = 5224480607138738741L; - - /** - * Constructs a new configuration error with the content - *- * ExampleConfig conf = new ExampleConfig(); - * conf.load().check(); - * ... - *
message.
- *
- * @param message A String describing what's wrong; it cannot
- * be null
- */
- public ConfigError(final String message) {
- super(message);
-
- Assert.exists(message, String.class);
- }
-
- /**
- * Constructs a new configuration error with a default message.
- */
- public ConfigError() {
- super("Configuration is invalid");
- }
-
-}
diff --git a/ccm-core/src/main/java/com/arsdigita/runtime/ConfigRegistry.java b/ccm-core/src/main/java/com/arsdigita/runtime/ConfigRegistry.java
deleted file mode 100644
index aa702e279..000000000
--- a/ccm-core/src/main/java/com/arsdigita/runtime/ConfigRegistry.java
+++ /dev/null
@@ -1,351 +0,0 @@
-/*
- * 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.runtime;
-
-import com.arsdigita.util.Classes;
-import com.arsdigita.util.JavaPropertyReader;
-import com.arsdigita.util.UncheckedWrapperException;
-import com.arsdigita.util.parameter.ErrorList;
-import com.arsdigita.util.parameter.ParameterContext;
-import com.arsdigita.util.parameter.ParameterReader;
-import com.arsdigita.xml.XML;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-
-import org.xml.sax.Attributes;
-import org.xml.sax.helpers.DefaultHandler;
-
-import org.apache.log4j.Logger;
-
-/**
- * The ConfigRegistry class maps between config classes (subclasses of
- * {@link com.arsdigita.runtime.AbstractConfig}), and a location used
- * for persisting the values in a config class.
- *
- * The ConfigRegistry also stores the set of configured packages for a
- * particular CCMResourceManager instance.
- * Additionally it stores a list of URLs for parent configurations that are
- * used for defaulting values not present in the local configuration.
- * This mapping is maintained and extended by CCMResourceManager developers through
- * the use of an XML configuration file placed in the src tree for a
- * particular package. If a particular package is configured, the
- * ConfigRegistry class will look in the classpath for a registry
- * configuration file named package-key.config, and parse the
- * file according to the following specification:
- *
- * - * <?xml version="1.0" encoding="utf-8"?> - * <registry> - * ... - * <config class="CLASSNAME" - * storage="FILENAME"/> - * ... - * </registry> - *
url, and use
- * loader when searching the classpath for registry
- * configuration files.
- *
- * @param url The base url for registry locations.
- * @param loader The ClassLoader to use for retrieving registry
- * configuration files.
- **/
- public ConfigRegistry(URL url, ClassLoader loader) {
- m_url = url;
- m_loader = loader;
- addContext(RegistryConfig.class, "registry.properties");
- initialize(m_url, new ErrorList());
- }
-
- /**
- * Convenience class which invokes {@link #ConfigRegistry(URL, ClassLoader)}
- * defaulting the loader to the current context class loader.
- *
- * @see Thread#getContextClassLoader()
- *
- * @param url The base url for registry locations.
- */
- public ConfigRegistry(URL url) {
- this(url, Thread.currentThread().getContextClassLoader());
- }
-
- /**
- * Convenience class which invokes {@link #ConfigRegistry(URL, ClassLoader)}
- * defaulting the URL to
- * new File(System.getProperty("ccm.conf")).toURL(). The value
- * of the ccm.conf system property may or may not include a trailing slash.
- *
- * @param loader The ClassLoader to use when searching for
- * registry configuration files.
- */
- public ConfigRegistry(ClassLoader loader) {
- this(CCMResourceManager.getConfigURL(), loader);
- }
-
- /**
- * Invokes {@link #ConfigRegistry(URL)} defaulting the URL to new
- * File(System.getProperty("ccm.conf")).toURL(). The value of the
- * ccm.conf system property may or may not include a trailing slash.
- */
- public ConfigRegistry() {
- this(CCMResourceManager.getConfigURL());
- }
-
- /**
- *
- * @param url Base url for registry location(s).
- * @param errs Errorlist
- */
- private void initialize(URL url, ErrorList errs) {
-
- ClassLoader ldr = new URLClassLoader(new URL[]{url}, null);
-
- RegistryConfig rc = new RegistryConfig();
- load(rc, errs, ldr);
-
- String[] packages = rc.getPackages();
- URL[] parents = rc.getParents();
-
- for (int i = 0; i < packages.length; i++) {
- if (!m_packages.contains(packages[i])) {
- initialize(packages[i]);
- }
- }
-
- for (int i = parents.length - 1; i >= 0; i--) {
- initialize(parents[i], errs);
- }
-
- m_loaders.add(ldr);
- }
-
- /**
- * This method is not supported API.
- */
- public final void initialize(String key) {
- s_log.debug(String.format("Initalizing for key '%s'", key));
- if (m_packages.contains(key)) {
- throw new IllegalArgumentException("already loaded: " + key);
- }
-
- InputStream is = m_loader.getResourceAsStream(key + ".config");
- if (is == null) {
- throw new UncheckedWrapperException(String.format("No .config for key '%s' found", key));
- }
- if (is != null) {
- try {
- XML.parse(is, new ConfigRegistryParser());
- m_packages.add(key);
- } finally {
- try {
- is.close();
- } catch (IOException e) {
- throw new UncheckedWrapperException(e);
- }
- }
- }
- }
-
- /**
- * Returns the list of configured packages for this ConfigRegistry.
- *
- * @return A list of package keys represented as Strings.
- **/
- public List getPackages() {
- return m_packages;
- }
-
- /**
- * Returns a list of config classes for this ConfigRegistry.
- *
- * @return A list of Class objects.
- **/
- public List getContexts() {
- return m_contexts;
- }
-
- /**
- * Returns the relative location used to store values for the
- * given config class.
- *
- * @param context a subclass of {@link
- * com.arsdigita.runtime.AbstractConfig}
- *
- * @return the relative storage location for context
- *
- * @throws IllegalArgumentException if this ConfigRegistry does
- * not contain a mapping for context
- **/
- public String getStorage(Class context) {
- if (!m_contexts.contains(context)) {
- throw new IllegalArgumentException("no such context: " + context
- + "; available contexts="
- + m_contexts
- + "; context->storage map: "
- + m_storage);
- }
- return (String) m_storage.get(context);
- }
-
- private void addContext(Class context, String storage) {
- s_log.debug(String.format("Adding context '%s', storage '%s'...",
- context.getName(), storage));
- m_contexts.add(context);
- m_storage.put(context, storage);
- }
-
- /**
- * Returns true if this ConfigRegistry contains a mapping for
- * context
- *
- * @param context a subclass of {@link
- * com.arsdigita.runtime.AbstractConfig}
- *
- * @return true if this ConfigRegistry contains a mapping for
- * context
- **/
- public boolean isConfigured(Class context) {
- return m_contexts.contains(context);
- }
-
- /**
- * Loads the given config object from the correct location based
- * on its class. Defaults all values based on the value of the
- * waf.config.parents parameter. Any errors
- * encountered during loading are reported in the given ErrorList.
- *
- * @param ctx the config object to load
- * @param errs used to accumulate errors during loading
- *
- * @throws IllegalArgumentException if this ConfigRegistry does
- * not contain a mapping for ctx.getClass()
- **/
- public void load(ParameterContext ctx, ErrorList errs) {
- for (Iterator it = m_loaders.iterator(); it.hasNext();) {
- ClassLoader ldr = (ClassLoader) it.next();
- load(ctx, errs, ldr);
- }
- }
-
- /**
- * Searches through this ConfigRegistry and its parents for the
- * given resource. If it is not found it is also searched for in
- * the classpath specified by the loader passed to this
- * ConfigRegistry on construction. This may be used to load
- * configuration information that is not stored in a config
- * object.
- *
- * @param resource the path to the resource
- *
- * @return an input stream containing the contents of the resource
- * or null if the resource is not found
- */
- public InputStream load(String resource) {
- for (int i = m_loaders.size() - 1; i >= 0; i--) {
- ClassLoader ldr = (ClassLoader) m_loaders.get(i);
- InputStream is = ldr.getResourceAsStream(resource);
- if (is != null) {
- return is;
- }
- }
-
- return m_loader.getResourceAsStream(resource);
- }
-
- private void load(ParameterContext ctx, ErrorList errs, ClassLoader ldr) {
- Properties props = getProperties(ldr, getStorage(ctx.getClass()));
- ParameterReader reader = new JavaPropertyReader(props);
- ctx.load(reader, errs);
- }
-
- private Properties getProperties(ClassLoader ldr, String resource) {
- Properties props = new Properties();
- InputStream is = ldr.getResourceAsStream(resource);
- if (is != null) {
- try {
- props.load(is);
- } catch (IOException e) {
- throw new UncheckedWrapperException(e);
- } finally {
- try {
- is.close();
- } catch (IOException e) {
- throw new UncheckedWrapperException(e);
- }
- }
- }
- return props;
- }
-
- private class ConfigRegistryParser extends DefaultHandler {
-
- @Override
- public void startElement(String uri, String localName, String qn,
- Attributes attrs) {
- if (localName.equals("config")) {
- String klass = attrs.getValue(uri, "class");
- String storage = attrs.getValue(uri, "storage");
- // XXX: Is there a better way to handle errors that
- // includes line number information?
- if ((klass == null) || (storage == null)) {
- throw new IllegalArgumentException(
- "class and storage attributes are required");
- }
-
- Class context = Classes.loadClass(klass);
- addContext(context, storage);
- }
- }
- }
-}
diff --git a/ccm-core/src/main/java/com/arsdigita/runtime/RegistryConfig.java b/ccm-core/src/main/java/com/arsdigita/runtime/RegistryConfig.java
deleted file mode 100644
index 2b6c14236..000000000
--- a/ccm-core/src/main/java/com/arsdigita/runtime/RegistryConfig.java
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- * 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.runtime;
-
-// import com.arsdigita.runtime.AbstractConfig;
-import com.arsdigita.util.StringUtils;
-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 java.net.MalformedURLException;
-import java.net.URL;
-
-
-/**
- * A config class used by the registry itself.
- *
- * Contains the parameters:
- * waf.config.packages: comma separated package-key list of installed packages
- * waf.config.parents :
- *
- * @author Rafael H. Schloming <rhs@mit.edu>
- * @version $Id$
- */
-public class RegistryConfig extends AbstractConfig {
-
- /**
- * Helper method to unmarshal parameter values.
- * @param str A String of comma separated values
- * @return StringArray of the values
- */
- private static String[] array(String str) {
- if (str == null) {
- return null;
- } else {
- return StringUtils.split(str, ',');
- }
- }
-
- /**
- * List of installed packages.
- *
- * Provided as a comma separated package-key list of installed packages.
- * The parameter overwrites the default marshal and unmarshal methods to
- * allow the String parameter to hold a list of values.
- *
- * TODO: Replace the type String parameter by StringArray parameter which
- * provides exactly the required functionality (doesn't it?).
- */
- private Parameter m_packages = new StringParameter
- ("waf.config.packages", Parameter.OPTIONAL, new String[0]) {
- @Override
- protected Object unmarshal(String value, ErrorList errs) {
- return array(value);
- }
-
- @Override
- protected String marshal(Object obj) {
- return StringUtils.join((String[]) obj, ',');
- }
- };
-
- /**
- * List of parameter values, purpose currently unkown.
- *
- * The parameter overwrites the default marshal and unmarshal methods to
- * allow the String parameter to hold a list of values.
- */
- private Parameter m_parents = new StringParameter
- ("waf.config.parents", Parameter.OPTIONAL, new URL[0]) {
- @Override
- protected Object unmarshal(String value, ErrorList errs) {
- String[] strs = array(value);
- URL[] result = new URL[strs.length];
- for (int i = 0; i < result.length; i++) {
- try {
- result[i] = new URL(strs[i]);
- } catch (MalformedURLException e) {
- errs.add(new ParameterError(this, e));
- }
- }
- if (!errs.isEmpty()) {
- return null;
- }
- return result;
- }
-
- protected String marshal(Object obj) {
- URL[] urls = (URL[]) obj;
- String[] strs = new String[urls.length];
- for (int i = 0; i < strs.length; i++) {
- strs[i] = urls[i].toExternalForm();
- }
- return StringUtils.join(strs, ',');
- }
- };
-
- /**
- * Constructs a new and empty config object.
- */
- public RegistryConfig() {
- register(m_packages);
- register(m_parents);
- }
-
- /**
- * Returns the value of the waf.config.packages parameter.
- *
- * @return the value of the waf.config.packages parameter
- */
- public String[] getPackages() {
- return (String[]) get(m_packages);
- }
-
- /**
- * Returns the value of the waf.config.parents parameter.
- *
- * @return the value of the waf.config.parents parameter
- */
- public URL[] getParents() {
- return (URL[]) get(m_parents);
- }
-
-}
diff --git a/ccm-core/src/main/java/com/arsdigita/templating/HostPatternGenerator.java b/ccm-core/src/main/java/com/arsdigita/templating/HostPatternGenerator.java
index aed3c1114..ab25c9d93 100755
--- a/ccm-core/src/main/java/com/arsdigita/templating/HostPatternGenerator.java
+++ b/ccm-core/src/main/java/com/arsdigita/templating/HostPatternGenerator.java
@@ -20,48 +20,53 @@ package com.arsdigita.templating;
import com.arsdigita.util.servlet.HttpHost;
import com.arsdigita.web.Web;
+import com.arsdigita.web.WebConfig;
import javax.servlet.http.HttpServletRequest;
import org.apache.log4j.Logger;
-
/**
- * Generates a set of patterns corresponding to the current
- * host name. (actually just retrieves the current hostname from configuration
- * file, StringArray returned is for sake of methods consistency)
+ * Generates a set of patterns corresponding to the current host name. (actually
+ * just retrieves the current hostname from configuration file, StringArray
+ * returned is for sake of methods consistency)
*/
public class HostPatternGenerator implements PatternGenerator {
- /** Internal logger instance to faciliate debugging. Enable logging output
- * by editing /WEB-INF/conf/log4j.properties int the runtime environment
- * and set com.arsdigita.templating.HostPatternGenerator=DEBUG
- * by uncommenting or adding the line. */
- private static final Logger s_log =
- Logger.getLogger(HostPatternGenerator.class);
+ /**
+ * Internal logger instance to faciliate debugging. Enable logging output by
+ * editing /WEB-INF/conf/log4j.properties int the runtime environment and
+ * set com.arsdigita.templating.HostPatternGenerator=DEBUG by uncommenting
+ * or adding the line.
+ */
+ private static final Logger s_log = Logger.getLogger(
+ HostPatternGenerator.class);
/**
- * Looks up the hostname from configuration and returns it as String.
- * The Return type is (unneccessarily) String[] due to the current API, but
+ * Looks up the hostname from configuration and returns it as String. The
+ * Return type is (unneccessarily) String[] due to the current API, but
* currently never returns more than just one value (one hostname:port).
- *
- * @param key placeholder from the pattern string, without surrounding
- * colons, constantly "host" here.
- * @param req current HttpServletRequest
- * @return Hostname (including port if any), retrieved from CCM
- * configuration
+ *
+ * @param key placeholder from the pattern string, without surrounding
+ * colons, constantly "host" here.
+ * @param req current HttpServletRequest
+ *
+ * @return Hostname (including port if any), retrieved from CCM
+ * configuration
*/
@Override
public String[] generateValues(String key,
HttpServletRequest req) {
- HttpHost host = Web.getConfig().getHost();
- String hostName = host.toString();
+ final HttpHost host = new HttpHost(WebConfig.getConfig().getHostName(),
+ WebConfig.getConfig().getHostPort());
+ final String hostName = host.toString();
if (s_log.isDebugEnabled()) {
- s_log.debug("Generating Values for key: " + key + " [" +
- "Hostname retrieved: >>" + hostName + "<<]");
+ s_log.debug("Generating Values for key: " + key + " ["
+ + "Hostname retrieved: >>" + hostName + "<<]");
}
- return new String[] { host.toString() };
+ return new String[]{host.toString()};
}
+
}
diff --git a/ccm-core/src/main/java/com/arsdigita/templating/Templating.java b/ccm-core/src/main/java/com/arsdigita/templating/Templating.java
index ca5473502..75f7109c0 100755
--- a/ccm-core/src/main/java/com/arsdigita/templating/Templating.java
+++ b/ccm-core/src/main/java/com/arsdigita/templating/Templating.java
@@ -25,6 +25,7 @@ import com.arsdigita.util.Exceptions;
import com.arsdigita.util.UncheckedWrapperException;
import com.arsdigita.util.servlet.HttpHost;
import com.arsdigita.web.Web;
+import com.arsdigita.web.WebConfig;
import com.arsdigita.xml.Document;
import com.arsdigita.xml.Element;
@@ -346,7 +347,9 @@ public class Templating {
* to a servlet which manages database retrieval.
*/
static URL transformURL(URL url) {
- HttpHost self = Web.getConfig().getHost();
+ final WebConfig webConfig = WebConfig.getConfig();
+ final HttpHost self = new HttpHost(webConfig.getHostName(),
+ webConfig.getHostPort());
/**
* Indicates whether url refers to a local resource inside the running
@@ -427,11 +430,9 @@ public class Templating {
}
} else // url is not the (local) running CCM host, no transformation
// is done
- {
- if (s_log.isDebugEnabled()) {
+ if (s_log.isDebugEnabled()) {
s_log.debug("URL " + url + " is not local");
}
- }
return url; // returns the original, unmodified url here
}
diff --git a/ccm-core/src/main/java/com/arsdigita/web/BaseApplicationServlet.java b/ccm-core/src/main/java/com/arsdigita/web/BaseApplicationServlet.java
index 8597c3a5e..a2eb2fad5 100644
--- a/ccm-core/src/main/java/com/arsdigita/web/BaseApplicationServlet.java
+++ b/ccm-core/src/main/java/com/arsdigita/web/BaseApplicationServlet.java
@@ -20,8 +20,8 @@ package com.arsdigita.web;
import org.apache.log4j.Logger;
import org.libreccm.cdi.utils.CdiUtil;
-import org.libreccm.web.CcmApplication;
import org.libreccm.web.ApplicationRepository;
+import org.libreccm.web.CcmApplication;
import java.io.IOException;
diff --git a/ccm-core/src/main/java/com/arsdigita/web/DefaultApplicationFileResolver.java b/ccm-core/src/main/java/com/arsdigita/web/DefaultApplicationFileResolver.java
index 042b586b3..9941daccd 100644
--- a/ccm-core/src/main/java/com/arsdigita/web/DefaultApplicationFileResolver.java
+++ b/ccm-core/src/main/java/com/arsdigita/web/DefaultApplicationFileResolver.java
@@ -18,13 +18,13 @@
*/
package com.arsdigita.web;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import javax.servlet.RequestDispatcher;
-
import org.apache.log4j.Logger;
import org.libreccm.web.CcmApplication;
+import javax.servlet.RequestDispatcher;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
/**
* The default implementation deals with templates files belonging to a specific
diff --git a/ccm-core/src/main/java/com/arsdigita/web/LegacyWebConfig.java b/ccm-core/src/main/java/com/arsdigita/web/LegacyWebConfig.java
deleted file mode 100644
index 40a48b876..000000000
--- a/ccm-core/src/main/java/com/arsdigita/web/LegacyWebConfig.java
+++ /dev/null
@@ -1,319 +0,0 @@
-/*
- * Copyright (C) 2015 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.web;
-
-import com.arsdigita.runtime.AbstractConfig;
-import com.arsdigita.util.parameter.BooleanParameter;
-import com.arsdigita.util.parameter.EnumerationParameter;
-import com.arsdigita.util.parameter.ErrorList;
-import com.arsdigita.util.parameter.Parameter;
-import com.arsdigita.util.parameter.ParameterError;
-import com.arsdigita.util.parameter.SingletonParameter;
-import com.arsdigita.util.parameter.StringArrayParameter;
-import com.arsdigita.util.parameter.StringParameter;
-import com.arsdigita.util.servlet.HttpHost;
-import com.arsdigita.util.servlet.HttpHostParameter;
-
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-
-/**
- * A record containing server-session scoped configuration properties.
- *
- * Accessors of this class may return null. Developers should take care to trap
- * null return values in their code.
- *
- * @see com.arsdigita.web.Web
- * @author Justin Ross <jross@redhat.com>
- * @author Jens Pelzetter
- */
-public class LegacyWebConfig extends AbstractConfig {
-
- private static final Logger LOGGER = LogManager.getLogger(LegacyWebConfig.class);
-
- private static LegacyWebConfig config;
-
- /**
- * Returns the singleton configuration record for the content section
- * environment.
- *
- * @return The CMSConfig record; it cannot be null
- */
- public static synchronized LegacyWebConfig getInstanceOf() {
- if (config == null) {
- config = new LegacyWebConfig();
- config.load();
- }
- return config;
- }
-
- // /////////////////////////////////////////////////////////////////////////
- // Configuration parameter section
- // /////////////////////////////////////////////////////////////////////////
- /**
- * Determines what HTTP scheme prefix is used by default to generate URLs
- * (either http od https)
- */
- private final Parameter m_scheme = new DefaultSchemeParameter(
- "waf.web.default_scheme",
- Parameter.REQUIRED, "http");
- /**
- * Sets the name and port that users of a site will see in URLs generated by
- * CCM for the site. This is a required parameter during installation, e.g.
- * example.com:80
- */
- private final Parameter m_server = new HttpHostParameter("waf.web.server");
- /**
- * Name and port that users of a site will see in secure URLs generated by
- * CCM for the site. As an example: example.com:443
- */
- private final Parameter m_secureServer = new HttpHostParameter(
- "waf.web.secure_server",
- Parameter.OPTIONAL, null);
- /**
- * The name of your website, for use in page footers for example. It's not
- * necessarily the URL but rather a title, e.g. "House of HTML". If not
- * specified set to the server's URL.
- */
- private final Parameter m_site = new StringParameter("waf.web.site_name",
- Parameter.OPTIONAL,
- null) {
-
- @Override
- public final Object getDefaultValue() {
- final HttpHost host = getServer();
- if (host == null) {
- return null;
- } else {
- return host.toString();
- }
- }
-
- };
- /**
- * Sets the name and port of the machine on which the CCM instance is
- * running. Used to fetch some resources by a local URL avoiding external
- * internet traffic (and delay). If not specified set to the servers's name
- * redirecting all traffic to external internet address.
- */
- private final Parameter m_host = new HttpHostParameter("waf.web.host",
- Parameter.OPTIONAL,
- null) {
-
- @Override
- public final Object getDefaultValue() {
- return getServer();
- }
-
- };
-
- /**
- * List of URLs which accessed by insecure (normal HTTP) connection produce
- * a redirect to a HTTPS equivalent. List is comma separated.
- */
- private final Parameter m_secureRequired = new StringArrayParameter(
- "waf.web.secure_required", Parameter.OPTIONAL, null);
- /**
- * List of URLs which accessed by secure (HTTPS) connection produce a
- * redirect to a HTTP equivalent. List is comma separated.
- */
- private final Parameter m_secureSwitchBack = new StringArrayParameter(
- "waf.web.secure_switchback", Parameter.OPTIONAL, null);
-
- /**
- * Dispatcher servlet path. It's the prefix to the main entry point for any
- * application request (CCMDispatcherServlet). By default /ccm
- */
- private final Parameter m_servlet = new StringParameter(
- "waf.web.dispatcher_servlet_path", Parameter.REQUIRED, "/ccm");
-
- /**
- * Specifies by name which implementation of ApplicationFileResolver is used
- * to dynamically resolve static files. By default
- * DefaultApplicationFileResolver() is used.
- */
- private final Parameter m_resolver = new SingletonParameter(
- "waf.web.application_file_resolver",
- Parameter.OPTIONAL,
- new DefaultApplicationFileResolver());
-
- private final Parameter m_deactivate_cache_host_notifications
- = new BooleanParameter(
- "waf.web.deactivate_cache_host_notifications",
- Parameter.OPTIONAL, Boolean.FALSE);
-
- private final Parameter m_dynamic_host_provider = new StringParameter(
- "waf.web.dynamic_host_provider",
- Parameter.OPTIONAL, "");
-
- /**
- * Constructor, but do NOT instantiate this class directly, use
- * getInstanceOf() instead. (Singleton pattern!)
- *
- */
- public LegacyWebConfig() {
-
- register(m_scheme);
- register(m_server);
- register(m_secureServer);
- register(m_site);
- register(m_host);
- register(m_secureRequired);
- register(m_secureSwitchBack);
- register(m_servlet);
- register(m_resolver);
- register(m_deactivate_cache_host_notifications);
- register(m_dynamic_host_provider);
-
- loadInfo();
- }
-
- public final String getDefaultScheme() {
- return (String) get(m_scheme);
- }
-
- public final HttpHost getServer() {
- return (HttpHost) get(m_server);
- }
-
- public final HttpHost getSecureServer() {
- return (HttpHost) get(m_secureServer);
- }
-
- public final boolean isSecureRequired(String uri) {
- String[] secured = (String[]) get(m_secureRequired);
- if (secured != null) {
- for (int i = 0, n = secured.length; i < n; i++) {
- if (uri.startsWith(secured[i])) {
- return true;
- }
- }
- }
- return false;
- }
-
- public final boolean isNonSecureSwitchRequired(String uri) {
- String[] switchBack = (String[]) get(m_secureSwitchBack);
- if (switchBack != null) {
- for (int i = 0, n = switchBack.length; i < n; i++) {
- if (uri.startsWith(switchBack[i])) {
- return true;
- }
- }
- }
- return false;
- }
-
- public final String getDispatcherServletPath() {
- return (String) get(m_servlet);
- }
-
- public final ApplicationFileResolver getApplicationFileResolver() {
- return (ApplicationFileResolver) get(m_resolver);
- }
-
- public final HttpHost getHost() {
- return (HttpHost) get(m_host);
- }
-
- final void setHost(final HttpHost host) {
- set(m_host, host);
- }
-
- public final String getSiteName() {
- return (String) get(m_site);
- }
-
- /**
- *
- * @return
- * @deprecated use Web.getContextPath() instead. The installation context
- * must no longer manually configured
- */
- // NO LONGER configured by configuration option but determined at runtime
- // by CCMDispatcherServlet itself.
- // // dispatcherContextPath option in old Initializer, set to ""
- // m_context = new StringParameter
- // ("waf.web.dispatcher_context_path", Parameter.REQUIRED, "");
- public final String getDispatcherContextPath() {
- // return (String) get(m_context);
- return CCMDispatcherServlet.getContextPath();
- }
-
-
- private static class DispatcherServletPathParameter
- extends StringParameter {
-
- DispatcherServletPathParameter(final String name) {
- super(name);
- }
-
- @Override
- protected void doValidate(final Object value, final ErrorList errors) {
- final String string = (String) value;
-
- if (string.endsWith("/")) {
- final ParameterError error = new ParameterError(this,
- "The value must not end in a '/'");
- errors.add(error);
- }
- }
-
- }
-
- private static class DefaultSchemeParameter extends EnumerationParameter {
-
- DefaultSchemeParameter(final String name,
- final int multiplicity,
- final Object defaalt) {
- super(name, multiplicity, defaalt);
-
- put("http", "http");
- put("https", "https");
- }
-
- }
-
- protected DynamicHostProvider dhProvider = null;
- protected boolean dhProviderInited = false;
-
- public final DynamicHostProvider getDynamicHostProvider() {
- if (dhProviderInited == false) {
- String classname = (String) get(m_dynamic_host_provider);
- if (classname != null) {
- try {
- Class klass = Class.forName(classname);
- dhProvider = (DynamicHostProvider) klass.newInstance();
- } catch (Exception e) {
- LOGGER.error(
- "Could not instantiate DynamicHostProvider using classname : "
- + classname, e);
- }
- }
- dhProviderInited = true;
- }
- return dhProvider;
- }
-
- public final boolean getDeactivateCacheHostNotifications() {
- return ((Boolean) get(m_deactivate_cache_host_notifications))
- .booleanValue();
- }
-
-}
diff --git a/ccm-core/src/main/java/com/arsdigita/web/LoginSignal.java b/ccm-core/src/main/java/com/arsdigita/web/LoginSignal.java
index cf716bc05..c1f5998ad 100644
--- a/ccm-core/src/main/java/com/arsdigita/web/LoginSignal.java
+++ b/ccm-core/src/main/java/com/arsdigita/web/LoginSignal.java
@@ -19,7 +19,6 @@
package com.arsdigita.web;
import javax.servlet.http.HttpServletRequest;
-import org.apache.log4j.Logger;
/**
*
diff --git a/ccm-core/src/main/java/com/arsdigita/web/URL.java b/ccm-core/src/main/java/com/arsdigita/web/URL.java
index f982fdc66..c0c92b1bc 100644
--- a/ccm-core/src/main/java/com/arsdigita/web/URL.java
+++ b/ccm-core/src/main/java/com/arsdigita/web/URL.java
@@ -612,11 +612,11 @@ public class URL {
* @return a URL to your server's root path
*/
public static final URL root() {
- final LegacyWebConfig config = Web.getConfig();
+ final WebConfig config = Web.getConfig();
URL url = new URL(config.getDefaultScheme(),
- config.getServer().getName(),
- config.getServer().getPort(),
+ config.getServerName(),
+ config.getServerPort(),
"",
"/",
null,
@@ -679,7 +679,7 @@ public class URL {
public static final URL there(final HttpServletRequest sreq,
final String path,
final ParameterMap params) {
- final LegacyWebConfig config = Web.getConfig();
+ final WebConfig config = Web.getConfig();
Assert.exists(sreq, "HttpServletRequest sreq");
Assert.exists(config, "WebConfig config");
@@ -693,7 +693,7 @@ public class URL {
return new URL(sreq.getScheme(),
host.getName(),
host.getPort(),
- config.getDispatcherContextPath(),
+ CCMDispatcherServlet.getContextPath(),
config.getDispatcherServletPath(),
path,
params);
@@ -715,9 +715,8 @@ public class URL {
public static final URL dynamicHostThere(final HttpServletRequest sreq,
final String path,
final ParameterMap params) {
- final LegacyWebConfig config = Web.getConfig();
+ final WebConfig config = Web.getConfig();
DynamicHostProvider provider = Web.getConfig().getDynamicHostProvider();
-
if (provider == null) {
return there(sreq, path, params);
}
@@ -734,7 +733,7 @@ public class URL {
return new URL(sreq.getScheme(),
provider.getName(),
provider.getPort(),
- config.getDispatcherContextPath(),
+ CCMDispatcherServlet.getContextPath(),
config.getDispatcherServletPath(),
path,
params);
@@ -755,7 +754,7 @@ public class URL {
*/
public static final URL there(final HttpServletRequest sreq,
final String path) {
- final LegacyWebConfig config = Web.getConfig();
+ final WebConfig config = Web.getConfig();
Assert.exists(sreq, "HttpServletRequest sreq");
Assert.exists(config, "WebConfig config");
@@ -765,7 +764,7 @@ public class URL {
return new URL(sreq.getScheme(),
host.getName(),
host.getPort(),
- config.getDispatcherContextPath(),
+ CCMDispatcherServlet.getContextPath(),
config.getDispatcherServletPath(),
path,
(ParameterMap) s_empty.get());
@@ -847,11 +846,11 @@ public class URL {
*/
public static final URL there(final String path,
final ParameterMap params) {
- final LegacyWebConfig config = Web.getConfig();
+ final WebConfig config = Web.getConfig();
return new URL(config.getDefaultScheme(),
- config.getServer().getName(),
- config.getServer().getPort(),
+ config.getServerName(),
+ config.getServerPort(),
"",
config.getDispatcherServletPath(),
path,
@@ -949,10 +948,10 @@ public class URL {
* @return
*/
public static String getDispatcherPath() {
- final LegacyWebConfig config = Web.getConfig();
+ final WebConfig config = Web.getConfig();
final HttpServletRequest req = Web.getRequest();
- final String context = config.getDispatcherContextPath();
+ final String context = CCMDispatcherServlet.getContextPath();
final String servlet = config.getDispatcherServletPath();
if (req == null) {
diff --git a/ccm-core/src/main/java/com/arsdigita/web/Web.java b/ccm-core/src/main/java/com/arsdigita/web/Web.java
index 5055ebaf9..7a54453ea 100644
--- a/ccm-core/src/main/java/com/arsdigita/web/Web.java
+++ b/ccm-core/src/main/java/com/arsdigita/web/Web.java
@@ -47,7 +47,7 @@ public class Web {
*/
private static final Logger s_log = Logger.getLogger(Web.class);
- private static final LegacyWebConfig s_config = LegacyWebConfig.getInstanceOf();
+ private static final WebConfig s_config = WebConfig.getConfig();
private static final ThreadLocal s_request = new InternalRequestLocal();
private static final ThreadLocal s_servletContext
@@ -90,9 +90,9 @@ public class Web {
/**
* Provide the configuration record for code in the web package.
*
- * @return A LegacyWebConfig configuration record; it cannot be null
+ * @return A WebConfig configuration record; it cannot be null
*/
- public static LegacyWebConfig getConfig() {
+ public static WebConfig getConfig() {
return s_config;
}
diff --git a/ccm-core/src/main/java/com/arsdigita/web/WebConfig.java b/ccm-core/src/main/java/com/arsdigita/web/WebConfig.java
index 415bc453f..a1235c60d 100644
--- a/ccm-core/src/main/java/com/arsdigita/web/WebConfig.java
+++ b/ccm-core/src/main/java/com/arsdigita/web/WebConfig.java
@@ -29,8 +29,6 @@ import java.lang.reflect.Method;
import java.util.HashSet;
import java.util.Set;
import java.util.StringJoiner;
-import java.util.logging.Level;
-import java.util.logging.Logger;
import javax.validation.ConstraintViolation;
import javax.validation.Validation;
@@ -74,7 +72,7 @@ public final class WebConfig {
private Boolean deactiveCacheHostNotifications = false;
@Setting
- private String dynamicHostProvider;
+ private String dynamicHostProviderClass;
public static WebConfig getConfig() {
final CdiUtil cdiUtil = new CdiUtil();
@@ -95,6 +93,14 @@ public final class WebConfig {
return server;
}
+ public String getServerName() {
+ return server.split(":")[0];
+ }
+
+ public Integer getServerPort() {
+ return Integer.parseInt(server.split(":")[1]);
+ }
+
public void setServer(
@Pattern(regexp = "[\\w-.]*:[0-9]{1,5}") final String server) {
final Method method;
@@ -122,6 +128,14 @@ public final class WebConfig {
return secureServer;
}
+ public String getSecureServerName() {
+ return secureServer.split(":")[0];
+ }
+
+ public Integer getSecureServerPort() {
+ return Integer.parseInt(secureServer.split(":")[1]);
+ }
+
public void setSecureServer(
@Pattern(regexp = "[\\w-.]*:[0-9]{1,5}") final String secureServer) {
final Method method;
@@ -157,9 +171,17 @@ public final class WebConfig {
return host;
}
+ public String getHostName() {
+ return host.split(":")[0];
+ }
+
+ public Integer getHostPort() {
+ return Integer.parseInt(host.split(":")[1]);
+ }
+
public void setHost(
@Pattern(regexp = "[\\w-.]*:[0-9]{1,5}") final String host) {
-
+
final Method method;
try {
method = getClass().getMethod("setHost", String.class);
@@ -243,12 +265,46 @@ public final class WebConfig {
this.deactiveCacheHostNotifications = deactiveCacheHostNotifications;
}
- public String getDynamicHostProvider() {
- return dynamicHostProvider;
+ public String getDynamicHostProviderClass() {
+ return dynamicHostProviderClass;
}
- public void setDynamicHostProvider(final String dynamicHostProvider) {
- this.dynamicHostProvider = dynamicHostProvider;
+ public DynamicHostProvider getDynamicHostProvider() {
+ try {
+ @SuppressWarnings("unchecked")
+ final Class