Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
Javascript/CSS bundling and compressing tool for java web apps.
By using jawr resources are automatically bundled together and optionally minified and gzipped.
Jawr provides tag libraries to reference a generated bundle either by id or by using the name of any of its members.
/**
* Copyright 2007-2016 Jordi Hernández Sellés, Ibrahim Chaehoi, Matt Ruby
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/
package net.jawr.web.config;
import java.io.Serializable;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.servlet.ServletContext;
import net.jawr.web.JawrConstant;
import net.jawr.web.context.ThreadLocalJawrContext;
import net.jawr.web.exception.BundlingProcessException;
import net.jawr.web.resource.bundle.factory.util.ClassLoaderResourceUtils;
import net.jawr.web.resource.bundle.factory.util.PathNormalizer;
import net.jawr.web.resource.bundle.factory.util.RegexUtil;
import net.jawr.web.resource.bundle.generator.GeneratorRegistry;
import net.jawr.web.resource.bundle.generator.variant.css.CssSkinVariantResolver;
import net.jawr.web.resource.bundle.hashcode.BundleHashcodeGenerator;
import net.jawr.web.resource.bundle.hashcode.BundleStringHashcodeGenerator;
import net.jawr.web.resource.bundle.hashcode.MD5BundleHashcodeGenerator;
import net.jawr.web.resource.bundle.locale.DefaultLocaleResolver;
import net.jawr.web.resource.bundle.locale.LocaleResolver;
import net.jawr.web.resource.bundle.locale.LocaleVariantResolverWrapper;
import net.jawr.web.resource.bundle.renderer.CSSHTMLBundleLinkRenderer;
import net.jawr.web.resource.bundle.variant.VariantResolver;
import net.jawr.web.resource.bundle.variant.resolver.BrowserResolver;
import net.jawr.web.resource.bundle.variant.resolver.ConnectionTypeResolver;
import net.jawr.web.servlet.util.MIMETypesSupport;
import net.jawr.web.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* This class holds configuration details for Jawr in a given ServletContext.
*
* @author Jordi Hernández Sellés
* @author Ibrahim Chaehoi
* @author Matt Ruby
*/
public class JawrConfig implements Serializable {
/** The serial version UID */
private static final long serialVersionUID = -6243263853446050289L;
/** The logger */
private static final Logger LOGGER = LoggerFactory.getLogger(JawrConfig.class);
/** The unauthorized resource extensions */
private static final List UNAUTHORIZED_RESOURCE_EXTENSIONS = Arrays.asList("xml", "properties", "text");
/**
* The jawr property placeholder patten ex : ${my_property.id}
*/
public static final Pattern JAWR_PROPERY_PLACEHOLDER_PATTERN = Pattern.compile("\\$\\{([a-zA-Z0-9_\\.\\-]+)}");
/**
* The property name for the css link flavor
*/
public static final String JAWR_CSSLINKS_FLAVOR = "jawr.csslinks.flavor";
/**
* The property name for the locale resolver
*/
public static final String JAWR_LOCALE_RESOLVER = "jawr.locale.resolver";
/**
* The property name for the browser resolver
*/
public static final String JAWR_BROWSER_RESOLVER = "jawr.browser.resolver";
/**
* The property name for the css skin resolver
*/
public static final String JAWR_CSS_SKIN_RESOLVER = "jawr.css.skin.resolver";
/**
* The property name for the connection type resolver
*/
public static final String JAWR_CONNECTION_TYPE_SCHEME_RESOLVER = "jawr.url.connection.type.resolver";
/**
* The property name for the bundle hashcode generator
*/
public static final String JAWR_BUNDLE_HASHCODE_GENERATOR = "jawr.bundle.hashcode.generator";
/**
* The property name for the dwr mapping
*/
public static final String JAWR_DWR_MAPPING = "jawr.dwr.mapping";
/**
* The property name for the url context path used to override
*/
public static final String JAWR_URL_CONTEXTPATH_OVERRIDE = "jawr.url.contextpath.override";
/**
* The property name for the url context path used to override SSL path
*/
public static final String JAWR_URL_CONTEXTPATH_SSL_OVERRIDE = "jawr.url.contextpath.ssl.override";
/**
* The property name for the flag indicating if we should use or not the url
* context path override even in debug mode
*/
public static final String JAWR_USE_URL_CONTEXTPATH_OVERRIDE_IN_DEBUG_MODE = "jawr.url.contextpath.override.used.in.debug.mode";
/**
* The property name for the Gzip IE6 flag
*/
public static final String JAWR_GZIP_IE6_ON = "jawr.gzip.ie6.on";
/**
* The property name to force the CSS bundle in debug mode
*/
public static final String JAWR_DEBUG_IE_FORCE_CSS_BUNDLE = "jawr.debug.ie.force.css.bundle";
/**
* The property name for the charset name
*/
public static final String JAWR_CHARSET_NAME = "jawr.charset.name";
/**
* The property name for the Gzip flag
*/
public static final String JAWR_GZIP_ON = "jawr.gzip.on";
/**
* The property name for the debug override key
*/
public static final String JAWR_DEBUG_OVERRIDE_KEY = "jawr.debug.overrideKey";
/**
* The property name for the debug use random parameter
*/
public static final String JAWR_USE_RANDOM_PARAM = "jawr.debug.use.random.parameter";
/**
* The property name for the reload refresh key
*/
private static final String JAWR_CONFIG_RELOAD_REFRESH_KEY = "jawr.config.reload.refreshKey";
/**
* The property name for the Debug flag
*/
public static final String JAWR_DEBUG_ON = "jawr.debug.on";
/**
* The property name for the jawr working directory. By default it's
* jawrTemp in the application server working directory associated to the
* application.
*/
public static final String JAWR_WORKING_DIRECTORY = "jawr.working.directory";
/**
* The property name for the flag indicating if we should process the bundle
* at startup
*/
public static final String JAWR_USE_BUNDLE_MAPPING = "jawr.use.bundle.mapping";
/**
* The property name for the flag indicating if we should use "smart
* bundling".
*/
public static final String JAWR_USE_SMART_BUNDLING = "jawr.use.smart.bundling";
/**
* The property name for the flag indicating if we should use "generator
* cache".
*/
public static final String JAWR_USE_GENERATOR_CACHE = "jawr.use.generator.cache";
/**
* The property name for the debug mode system flag
*/
private static final String DEBUG_MODE_SYSTEM_FLAG = "net.jawr.debug.on";
/**
* The property name for the ClientSideHandlerGenerator class
*/
public static final String JAWR_JS_CLIENTSIDE_HANDLER = "jawr.js.clientside.handler.generator.class";
/**
* The property name for the JS Bundle link renderer
*/
public static final String JAWR_JS_BUNDLE_LINK_RENDERER_CLASS = "jawr.js.bundle.link.renderer.class";
/**
* The property name for the CSS Bundle link renderer
*/
public static final String JAWR_CSS_BUNDLE_LINK_RENDERER_CLASS = "jawr.css.bundle.link.renderer.class";
/**
* The property name for the CSS Bundle link renderer
*/
public static final String JAWR_IMG_RENDERER_CLASS = "jawr.img.bundle.link.renderer.class";
/**
* The property name for the flag indicating if the CSS image for the CSS
* retrieved from classpath must be also retrieved from classpath
*/
public static final String JAWR_CSS_CLASSPATH_HANDLE_IMAGE = "jawr.css.classpath.handle.image";
/**
* The property name for the name of the cookie used to store the CSS skin
*/
public static final String JAWR_CSS_SKIN_COOKIE = "jawr.css.skin.cookie";
/**
* The property name for the binary hash algorithm.
*/
public static final String JAWR_BINARY_HASH_ALGORITHM = "jawr.binary.hash.algorithm";
/**
* The property name for the binary resources.
*/
public static final String JAWR_BINARY_RESOURCES = "jawr.binary.resources";
/**
* The property name for the Jawr strict mode.
*/
public static final String JAWR_STRICT_MODE = "jawr.strict.mode";
/**
* The property name for the jawr servlet context reader class name
*/
public static final String JAWR_SERVLET_CTX_READER_CLASS = "jawr.servlet.context.reader.class";
/**
* The generator registry
*/
private GeneratorRegistry generatorRegistry;
/**
* The local resolver
*/
private LocaleResolver localeResolver;
/**
* The bundle hashcode generator
*/
private BundleHashcodeGenerator bundleHashcodeGenerator;
/**
* The servlet context
*/
private ServletContext context;
/**
* The root configuration properties
*/
private Properties configProperties;
/**
* Name of the charset to use to interpret and send resources. Defaults to
* UTF-8
*/
private String charsetName = "UTF-8";
/**
* The charset to use to interpret and send resources.
*/
private Charset resourceCharset;
/**
* Flag to switch on the strict mode. defaults to false. In strict mode,
* Jawr checks that the hashcode of the bundle requested is the right one or
* not.
*/
private boolean strictMode = false;
/**
* Flag to switch on the debug mode. defaults to false.
*/
private boolean debugModeOn = false;
/**
* Flag to switch on the debug use random parameter. defaults to true.
*/
private boolean debugUseRandomParam = true;
/**
* Key that may be passed in to override production mode
*/
private String debugOverrideKey = "";
/**
* Key that may be passed in to reload the bundles on the fly
*/
private String refreshKey = "";
/**
* Flag to switch on the gzipped resources mode. defaults to true.
*/
private boolean gzipResourcesModeOn = true;
/**
* Flag to switch on the gzipped resources mode for internet explorer 6.
* defaults to true.
*/
private boolean gzipResourcesForIESixOn = true;
/**
* Flag to switch on css resources bundle in debug mode. defaults to false.
*/
private boolean forceCssBundleInDebugForIEOn = false;
/**
* Flag which defines if we should process use information of bundle mapping at server startup.
* This is used to speed up server start up.
* defaults to true.
*/
private boolean useBundleMapping = true;
/**
* Flag which defines if we should use the smart bundling feature. defaults
* to true.
*/
private boolean useSmartBundling = true;
/**
* Flag which defines if we should use the generator cache feature. defaults
* to true.
*/
private boolean useGeneratorCache = true;
/**
* The delay after last event, this is used to to ensure that a batch
* modification is ended before starting the build
*/
private int delayAfterLastEvent = JawrConstant.DEFAULT_DELAY_AFTER_LAST_EVENT;
/**
* The jawr working directory path
*/
private String jawrWorkingDirectory;
/**
* Servlet mapping corresponding to this config. Defaults to an empty string
*/
private String servletMapping = "";
/**
* The type of resources handled by this config
*/
private String resourceType;
/**
* The allowed resource extensions
*/
private final List allowedExtensions = new ArrayList<>();
/**
* Override value to use instead of the context path of the application in
* generated urls. If null, contextPath is used. If blank, urls are
* generated to be relative.
*/
private String contextPathOverride;
/**
* Override value to use instead of the context path of the application in
* generated urls for SSL page. If null, contextPath is used. If blank, urls
* are generated to be relative.
*/
private String contextPathSslOverride;
/** The client side handler generator class name */
private String clientSideHandlerGeneratorClass;
/**
* The flag indicating that we should use the overridden context path even
* in debug mode. The default value is false.
*/
private boolean useContextPathOverrideInDebugMode = false;
/**
* Determines if the servlet, which provide CSS image for CSS define in the
* classpath should be used or not
*/
private boolean classpathCssHandleImage = false;
/**
* Defines the image resources definition.
*/
private String binaryResourcesDefinition;
/**
* Defines the image hash algorithm. By default the value is CRC32. There
* are only 2 algorithm available CRC32 and MD5.
*/
private String binaryHashAlgorithm = "CRC32";
/**
* Used to check if a configuration has not been outdated by a new one.
*/
private boolean valid = true;
/**
* Mapping path to the dwr servlet, in case it is integrated with jawr.
*/
private String dwrMapping;
/** The skin cookie name */
private String skinCookieName = JawrConstant.JAWR_SKIN;
/** The servletContext reader class name */
private String servletContextRsReaderClass;
/** The JS Bundle link renderer class name */
private String jsBundleLinkRenderClass;
/** The CSS Bundle link renderer class name */
private String cssBundleLinkRenderClass;
/** The Image renderer class name */
private String imgRenderClass;
/**
* Initialize configuration using params contained in the initialization
* properties file.
*
* @param resourceType
* the resource type
* @param props
* the properties
*/
public JawrConfig(final String resourceType, final Properties props) {
this(resourceType, props, null);
}
/**
* Initialize configuration using params contained in the initialization
* properties file.
*
* @param resourceType
* the resource type
* @param props
* the properties
* @param resolver
* the property resolver
*/
public JawrConfig(final String resourceType, final Properties props, ConfigPropertyResolver resolver) {
this.resourceType = resourceType;
this.configProperties = props;
if (resolver != null) {
for (Entry