Author: nbelaevski
Date: 2010-06-09 13:40:12 -0400 (Wed, 09 Jun 2010)
New Revision: 17584
Added:
root/core/trunk/api/src/main/java/org/richfaces/application/DependencyInjectionService.java
root/core/trunk/api/src/main/java/org/richfaces/resource/CacheableResource.java
root/core/trunk/api/src/main/java/org/richfaces/resource/PostConstructResource.java
root/core/trunk/api/src/main/java/org/richfaces/resource/ResourceParameter.java
root/core/trunk/impl/src/main/java/org/richfaces/application/DependencyInjectionServiceImpl.java
root/core/trunk/impl/src/main/java/org/richfaces/resource/ResourceParameterELResolver.java
Modified:
root/core/trunk/impl/src/main/java/org/ajax4jsf/resource/Java2Dresource.java
root/core/trunk/impl/src/main/java/org/richfaces/application/InitializationListener.java
root/core/trunk/impl/src/main/java/org/richfaces/renderkit/html/CustomizeableGradient.java
root/core/trunk/impl/src/main/java/org/richfaces/resource/AbstractBaseResource.java
root/core/trunk/impl/src/main/java/org/richfaces/resource/AbstractCacheableResource.java
root/core/trunk/impl/src/main/java/org/richfaces/resource/CompiledCSSResource.java
root/core/trunk/impl/src/main/java/org/richfaces/resource/DefaultResourceCodec.java
root/core/trunk/impl/src/main/java/org/richfaces/resource/LegacyResourceCodec.java
root/core/trunk/impl/src/main/java/org/richfaces/resource/ResourceHandlerImpl.java
root/core/trunk/impl/src/main/java/org/richfaces/resource/TestResource2.java
root/core/trunk/impl/src/main/java/org/richfaces/util/Util.java
root/core/trunk/impl/src/main/resources/META-INF/resource-handler.faces-config.xml
root/core/trunk/impl/src/test/java/org/richfaces/resource/AbstractBaseResourceTest.java
root/core/trunk/impl/src/test/java/org/richfaces/resource/CacheableResourceImpl.java
root/core/trunk/impl/src/test/java/org/richfaces/resource/ResourceHandlerImplTest.java
root/core/trunk/impl/src/test/java/org/richfaces/resource/StateHolderResourceImpl.java
root/core/trunk/impl/src/test/java/org/richfaces/resource/VersionedResourceImpl.java
root/ui/core/trunk/ui/src/main/java/org/richfaces/resource/MediaOutputResource.java
root/ui/core/trunk/ui/src/main/java/org/richfaces/resource/PushResource.java
Log:
https://jira.jboss.org/browse/RF-8665
Added:
root/core/trunk/api/src/main/java/org/richfaces/application/DependencyInjectionService.java
===================================================================
---
root/core/trunk/api/src/main/java/org/richfaces/application/DependencyInjectionService.java
(rev 0)
+++
root/core/trunk/api/src/main/java/org/richfaces/application/DependencyInjectionService.java 2010-06-09
17:40:12 UTC (rev 17584)
@@ -0,0 +1,35 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This 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 software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.application;
+
+import javax.faces.context.FacesContext;
+
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public interface DependencyInjectionService {
+
+ public void inject(FacesContext context, Object bean);
+
+}
Added: root/core/trunk/api/src/main/java/org/richfaces/resource/CacheableResource.java
===================================================================
--- root/core/trunk/api/src/main/java/org/richfaces/resource/CacheableResource.java
(rev 0)
+++
root/core/trunk/api/src/main/java/org/richfaces/resource/CacheableResource.java 2010-06-09
17:40:12 UTC (rev 17584)
@@ -0,0 +1,33 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This 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 software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.resource;
+
+import javax.faces.context.FacesContext;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public interface CacheableResource {
+
+ public boolean isCacheable(FacesContext context);
+}
Added:
root/core/trunk/api/src/main/java/org/richfaces/resource/PostConstructResource.java
===================================================================
--- root/core/trunk/api/src/main/java/org/richfaces/resource/PostConstructResource.java
(rev 0)
+++
root/core/trunk/api/src/main/java/org/richfaces/resource/PostConstructResource.java 2010-06-09
17:40:12 UTC (rev 17584)
@@ -0,0 +1,37 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This 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 software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.resource;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+(a)Retention(RetentionPolicy.RUNTIME)
+(a)Target({ElementType.METHOD, ElementType.FIELD})
+public @interface PostConstructResource {
+
+}
Added: root/core/trunk/api/src/main/java/org/richfaces/resource/ResourceParameter.java
===================================================================
--- root/core/trunk/api/src/main/java/org/richfaces/resource/ResourceParameter.java
(rev 0)
+++
root/core/trunk/api/src/main/java/org/richfaces/resource/ResourceParameter.java 2010-06-09
17:40:12 UTC (rev 17584)
@@ -0,0 +1,40 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This 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 software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.resource;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * @author Nick Belaevski
+ */
+(a)Retention(RetentionPolicy.RUNTIME)
+(a)Target({ElementType.FIELD, ElementType.METHOD})
+public @interface ResourceParameter {
+
+ public String value();
+
+ public String defaultValue() default "";
+
+}
Modified: root/core/trunk/impl/src/main/java/org/ajax4jsf/resource/Java2Dresource.java
===================================================================
---
root/core/trunk/impl/src/main/java/org/ajax4jsf/resource/Java2Dresource.java 2010-06-09
14:04:16 UTC (rev 17583)
+++
root/core/trunk/impl/src/main/java/org/ajax4jsf/resource/Java2Dresource.java 2010-06-09
17:40:12 UTC (rev 17584)
@@ -23,13 +23,13 @@
import java.awt.Dimension;
import java.awt.Graphics2D;
+import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.awt.image.IndexColorModel;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.util.Map;
import javax.faces.component.StateHolder;
import javax.faces.context.FacesContext;
@@ -39,7 +39,7 @@
import org.ajax4jsf.util.HtmlDimensions;
import org.ajax4jsf.util.NumericDataInputStream;
import org.ajax4jsf.util.NumericDataOutputStream;
-import org.richfaces.resource.AbstractBaseResource;
+import org.richfaces.resource.AbstractCacheableResource;
import org.richfaces.skin.Skin;
import org.richfaces.skin.SkinFactory;
@@ -47,7 +47,7 @@
* @author shura (latest modification by $Author: alexsmirnov $)
* @version $Revision: 1.1.2.3 $ $Date: 2007/02/01 15:31:57 $
*/
-public abstract class Java2Dresource extends AbstractBaseResource implements StateHolder
{
+public abstract class Java2Dresource extends AbstractCacheableResource implements
StateHolder {
private static final String SKIN_MARKER = "Skin.";
private ImageType imageType;
@@ -56,10 +56,6 @@
this.imageType = imageType;
}
- public void populateParameters(Map<String, String> parameters){
-
- }
-
public static enum ImageType {
GIF("gif") {
@Override
@@ -161,8 +157,13 @@
* graphics to paint.
*/
protected void paint(Graphics2D graphics2D, Dimension dimension) {
+ graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
+ graphics2D.setRenderingHint(RenderingHints.KEY_DITHERING,
RenderingHints.VALUE_DITHER_ENABLE);
- // TODO Auto-generated method stub
+ graphics2D.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION,
+ RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
+ graphics2D.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING,
RenderingHints.VALUE_COLOR_RENDER_QUALITY);
+ graphics2D.setRenderingHint(RenderingHints.KEY_RENDERING,
RenderingHints.VALUE_RENDER_QUALITY);
}
/*
Added:
root/core/trunk/impl/src/main/java/org/richfaces/application/DependencyInjectionServiceImpl.java
===================================================================
---
root/core/trunk/impl/src/main/java/org/richfaces/application/DependencyInjectionServiceImpl.java
(rev 0)
+++
root/core/trunk/impl/src/main/java/org/richfaces/application/DependencyInjectionServiceImpl.java 2010-06-09
17:40:12 UTC (rev 17584)
@@ -0,0 +1,349 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This 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 software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.application;
+
+import java.beans.BeanInfo;
+import java.beans.IntrospectionException;
+import java.beans.Introspector;
+import java.beans.PropertyDescriptor;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.text.MessageFormat;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+import javax.el.ExpressionFactory;
+import javax.el.ValueExpression;
+import javax.faces.FacesException;
+import javax.faces.context.FacesContext;
+
+import org.richfaces.log.RichfacesLogger;
+import org.richfaces.resource.PostConstructResource;
+import org.richfaces.resource.ResourceParameter;
+import org.slf4j.Logger;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class DependencyInjectionServiceImpl implements DependencyInjectionService {
+
+ private static final Logger LOGGER = RichfacesLogger.APPLICATION.getLogger();
+
+ private abstract static class Injector<T extends Annotation> {
+
+ private PropertyDescriptor propertyDescriptor;
+
+ private T dependency;
+
+ public Injector(PropertyDescriptor propertyDescriptor, T dependency) {
+ super();
+ this.propertyDescriptor = propertyDescriptor;
+ this.dependency = dependency;
+ }
+
+ protected T getDependency() {
+ return dependency;
+ }
+
+ protected PropertyDescriptor getPropertyDescriptor() {
+ return propertyDescriptor;
+ }
+
+ protected abstract Object evaluateProperty(FacesContext context, Class<?>
propertyType);
+
+ public void inject(FacesContext context, Object bean) throws
IllegalArgumentException, IllegalAccessException,
+ InvocationTargetException {
+
+ Method writeMethod = propertyDescriptor.getWriteMethod();
+
+ if (writeMethod != null) {
+ writeMethod.invoke(bean, evaluateProperty(context,
propertyDescriptor.getPropertyType()));
+ } else {
+ throw new IllegalStateException(
+ MessageFormat.format("Write method for property {0} doesn't
exist", propertyDescriptor.getName()));
+ }
+ }
+
+ }
+
+ private static final class PropertyDependencyInjector extends
Injector<ResourceParameter> {
+
+ public PropertyDependencyInjector(PropertyDescriptor propertyDescriptor,
ResourceParameter dependency) {
+ super(propertyDescriptor, dependency);
+ }
+
+ private Object getExpressionValue(FacesContext context, String expressionString,
Class<?> expectedType) {
+ ExpressionFactory expressionFactory =
context.getApplication().getExpressionFactory();
+ ValueExpression expression =
expressionFactory.createValueExpression(context.getELContext(),
+ expressionString, expectedType);
+ return expression.getValue(context.getELContext());
+ }
+
+ protected Object evaluateProperty(FacesContext context, Class<?>
propertyType) {
+ Class<?> expectedType;
+ if (!propertyType.isPrimitive()) {
+ expectedType = Object.class;
+ } else {
+ expectedType = propertyType;
+ }
+
+ Object propertyValue = getExpressionValue(context, getDependency().value(),
expectedType);
+
+ if (propertyValue == null || "".equals(propertyValue)) {
+ String defaultValue = getDependency().defaultValue();
+ if (defaultValue != null && defaultValue.length() != 0) {
+ propertyValue = getExpressionValue(context, defaultValue,
expectedType);
+ }
+ }
+
+ if (!propertyType.isPrimitive() && propertyValue != null) {
+ propertyValue =
context.getApplication().getExpressionFactory().coerceToType(propertyValue,
propertyType);
+ }
+
+ return propertyValue;
+ }
+ }
+
+ private static final class IntrospectionData {
+
+ private Method postConstructMethod = null;
+
+ private Map<String, Injector<?>> injectorsMap = null;
+
+ public Map<String, Injector<?>> getInjectorsMap() {
+ if (injectorsMap != null) {
+ return injectorsMap;
+ }
+
+ return Collections.emptyMap();
+ }
+
+ public void addInjector(String propertyName, Injector<?> injector) {
+ if (injectorsMap == null) {
+ injectorsMap = new HashMap<String, Injector<?>>();
+ }
+
+ injectorsMap.put(propertyName, injector);
+ }
+
+ public Method getPostConstructMethod() {
+ return postConstructMethod;
+ }
+
+ public void setPostConstructMethod(Method postConstructMethod) {
+ this.postConstructMethod = postConstructMethod;
+ }
+ }
+
+ private ConcurrentMap<Class<?>, IntrospectionData> classesCache = new
ConcurrentHashMap<Class<?>, IntrospectionData>();
+
+ private void invokeMethod(Object bean, Method method) throws
IllegalArgumentException, IllegalAccessException,
+ InvocationTargetException {
+
+ if (method != null) {
+ method.setAccessible(true);
+ method.invoke(bean);
+ }
+ }
+
+ private boolean isUncheckedException(Class<?> type) {
+ // JLS 2nd edition - 11.2 Compile-Time Checking of Exceptions
+ return RuntimeException.class.isAssignableFrom(type) ||
Error.class.isAssignableFrom(type);
+ }
+
+ private void verifyPostConstructMethod(Method method) {
+ if (method.getParameterTypes().length != 0) {
+ throw new IllegalStateException(
+ MessageFormat.format("Post-construction method {0} has one or more
parameters", method.toString()));
+ }
+
+ if (!Void.TYPE.equals(method.getReturnType())) {
+ throw new IllegalStateException(
+ MessageFormat.format("Post-construction method {0} has incorrect
return type", method.toString()));
+ }
+
+ if ((method.getModifiers() & Modifier.STATIC) != 0) {
+ throw new IllegalStateException(
+ MessageFormat.format("Post-construction method {0} is static",
method.toString()));
+ }
+
+ Class<?>[] exceptionTypes = method.getExceptionTypes();
+ for (Class<?> exceptionType : exceptionTypes) {
+ if (isUncheckedException(exceptionType)) {
+ continue;
+ }
+
+ throw new IllegalStateException(
+ MessageFormat.format("Post-construction method {0} throws checked
exception", method.toString()));
+ }
+ }
+
+ private void inspectMethod(Method method, Class<? extends Annotation>
annotationClass,
+ IntrospectionData introspectionData) {
+
+ Annotation annotation = method.getAnnotation(annotationClass);
+ if (annotation != null) {
+ verifyPostConstructMethod(method);
+
+ if (introspectionData.getPostConstructMethod() != null) {
+ throw new IllegalStateException(
+ MessageFormat.format("There are two conflicting
post-construction methods: {0} and {1}",
+ method.toString(),
introspectionData.getPostConstructMethod().toString()));
+ }
+
+ introspectionData.setPostConstructMethod(method);
+ }
+ }
+
+ private void locatePostConstructMethods(Class<?> clazz, IntrospectionData
introspectionData) {
+ Method[] methods = clazz.getDeclaredMethods();
+ for (Method method : methods) {
+ inspectMethod(method, PostConstructResource.class, introspectionData);
+ }
+
+ Class<?> superclass = clazz.getSuperclass();
+ if (!Object.class.equals(superclass)) {
+ locatePostConstructMethods(superclass, introspectionData);
+ }
+ }
+
+ private void locateManagedPropertyFields(Class<?> clazz, Map<String,
ResourceParameter> fieldsMap) {
+ Field[] fields = clazz.getDeclaredFields();
+ for (Field field : fields) {
+ ResourceParameter dependency = field.getAnnotation(ResourceParameter.class);
+
+ if (dependency != null) {
+ String propertyName = field.getName();
+
+ if (!fieldsMap.containsKey(propertyName)) {
+ fieldsMap.put(propertyName, dependency);
+ }
+ }
+ }
+
+ Class<?> superclass = clazz.getSuperclass();
+ if (!Object.class.equals(superclass)) {
+ locateManagedPropertyFields(superclass, fieldsMap);
+ }
+ }
+
+ private <T extends Annotation> T getAnnotation(PropertyDescriptor descriptor,
Class<T> annotationClass) {
+ T annotation = null;
+
+ Method writeMethod = descriptor.getWriteMethod();
+ if (writeMethod != null) {
+ annotation = writeMethod.getAnnotation(annotationClass);
+ }
+
+ if (annotation == null) {
+ Method readMethod = descriptor.getReadMethod();
+ if (readMethod != null) {
+ annotation = readMethod.getAnnotation(annotationClass);
+ }
+ }
+
+ return annotation;
+ }
+
+ private void locateManagedPropertyDescriptors(Class<?> clazz, IntrospectionData
introspectionData,
+ Map<String, ResourceParameter> injectableFields) {
+
+ try {
+ BeanInfo beanInfo = Introspector.getBeanInfo(clazz);
+ if (beanInfo != null) {
+ PropertyDescriptor[] descriptors = beanInfo.getPropertyDescriptors();
+ if (descriptors != null) {
+ for (PropertyDescriptor descriptor : descriptors) {
+ String propertyName = descriptor.getName();
+
+ ResourceParameter dependency =
injectableFields.get(propertyName);
+
+ if (dependency == null) {
+ dependency = getAnnotation(descriptor,
ResourceParameter.class);
+ }
+
+ if (dependency != null) {
+ Injector<?> injector = new
PropertyDependencyInjector(descriptor, dependency);
+ introspectionData.addInjector(propertyName, injector);
+ }
+ }
+ }
+ }
+ } catch (IntrospectionException e) {
+ if (LOGGER.isDebugEnabled()) {
+ LOGGER.debug(e.getMessage(), e);
+ }
+ } finally {
+ Introspector.flushFromCaches(clazz);
+ }
+ }
+
+ protected IntrospectionData createIntrospectionData(Class<?> beanClass) {
+ IntrospectionData introspectionData = new IntrospectionData();
+
+ Map<String, ResourceParameter> injectableFields = new HashMap<String,
ResourceParameter>();
+ locateManagedPropertyFields(beanClass, injectableFields);
+
+ locateManagedPropertyDescriptors(beanClass, introspectionData,
injectableFields);
+
+ locatePostConstructMethods(beanClass, introspectionData);
+
+ return introspectionData;
+ }
+
+ public void inject(FacesContext context, Object bean) {
+ Class<?> beanClass = bean.getClass();
+
+ IntrospectionData introspectionData = classesCache.get(beanClass);
+ if (introspectionData == null) {
+ introspectionData = createIntrospectionData(beanClass);
+ classesCache.put(beanClass, introspectionData);
+ }
+
+ try {
+ Map<String, Injector<?>> injectorsMap =
introspectionData.getInjectorsMap();
+ if (!injectorsMap.isEmpty()) {
+ for (Injector<?> injector : injectorsMap.values()) {
+ injector.inject(context, bean);
+ }
+ }
+
+ Method postConstructMethod = introspectionData.getPostConstructMethod();
+ if (postConstructMethod != null) {
+ invokeMethod(bean, postConstructMethod);
+ }
+ } catch (IllegalArgumentException e) {
+ throw new FacesException(e.getMessage(), e);
+ } catch (IllegalAccessException e) {
+ throw new FacesException(e.getMessage(), e);
+ } catch (InvocationTargetException e) {
+ throw new FacesException(e.getMessage(), e);
+ }
+ }
+}
Modified:
root/core/trunk/impl/src/main/java/org/richfaces/application/InitializationListener.java
===================================================================
---
root/core/trunk/impl/src/main/java/org/richfaces/application/InitializationListener.java 2010-06-09
14:04:16 UTC (rev 17583)
+++
root/core/trunk/impl/src/main/java/org/richfaces/application/InitializationListener.java 2010-06-09
17:40:12 UTC (rev 17584)
@@ -41,6 +41,8 @@
import org.ajax4jsf.renderkit.AJAXDataSerializer;
import org.ajax4jsf.resource.util.URLToStreamHelper;
import org.richfaces.log.RichfacesLogger;
+import org.richfaces.resource.DefaultResourceCodec;
+import org.richfaces.resource.ResourceCodec;
import org.richfaces.skin.SkinFactory;
import org.richfaces.skin.SkinFactoryImpl;
import org.slf4j.Logger;
@@ -156,6 +158,13 @@
AJAXDataSerializer dataSerializer =
createServiceInstance(AJAXDataSerializer.class, AJAXDataSerializer.class);
ServiceTracker.setService(facesContext, AJAXDataSerializer.class,
dataSerializer);
+
+ DependencyInjectionService diService =
createServiceInstance(DependencyInjectionService.class,
+ DependencyInjectionServiceImpl.class);
+ ServiceTracker.setService(facesContext, DependencyInjectionService.class,
diService);
+
+ ResourceCodec resourceCodec = createServiceInstance(ResourceCodec.class,
DefaultResourceCodec.class);
+ ServiceTracker.setService(facesContext, ResourceCodec.class, resourceCodec);
}
protected void onStop() {
Modified:
root/core/trunk/impl/src/main/java/org/richfaces/renderkit/html/CustomizeableGradient.java
===================================================================
---
root/core/trunk/impl/src/main/java/org/richfaces/renderkit/html/CustomizeableGradient.java 2010-06-09
14:04:16 UTC (rev 17583)
+++
root/core/trunk/impl/src/main/java/org/richfaces/renderkit/html/CustomizeableGradient.java 2010-06-09
17:40:12 UTC (rev 17584)
@@ -28,7 +28,6 @@
import java.awt.RenderingHints;
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
-import java.util.Map;
import javax.faces.context.FacesContext;
@@ -69,17 +68,17 @@
}
}
- @Override
- public void populateParameters(Map<String, String> parameters){
- if(parameters.containsKey(GRADIENT_COLOR)){
- String gradientColorValue =
encodeSkinParameter(parameters.get(GRADIENT_COLOR));
- this.gradientColor = decodeColor(gradientColorValue);
- }
- if(parameters.containsKey(BASE_COLOR)){
- String baseColorValue = encodeSkinParameter(parameters.get(BASE_COLOR));
- this.baseColor = decodeColor(baseColorValue);
- }
- }
+// @Override
+// public void populateParameters(Map<String, String> parameters){
+// if(parameters.containsKey(GRADIENT_COLOR)){
+// String gradientColorValue =
encodeSkinParameter(parameters.get(GRADIENT_COLOR));
+// this.gradientColor = decodeColor(gradientColorValue);
+// }
+// if(parameters.containsKey(BASE_COLOR)){
+// String baseColorValue = encodeSkinParameter(parameters.get(BASE_COLOR));
+// this.baseColor = decodeColor(baseColorValue);
+// }
+// }
public Dimension getDimension() {
return dimension;
Modified:
root/core/trunk/impl/src/main/java/org/richfaces/resource/AbstractBaseResource.java
===================================================================
---
root/core/trunk/impl/src/main/java/org/richfaces/resource/AbstractBaseResource.java 2010-06-09
14:04:16 UTC (rev 17583)
+++
root/core/trunk/impl/src/main/java/org/richfaces/resource/AbstractBaseResource.java 2010-06-09
17:40:12 UTC (rev 17584)
@@ -37,6 +37,7 @@
import java.util.Map.Entry;
import javax.faces.FacesException;
+import javax.faces.application.Resource;
import javax.faces.component.StateHolder;
import javax.faces.context.FacesContext;
@@ -50,12 +51,10 @@
* @author Nick Belaevski
* @since 4.0
*/
-public abstract class AbstractBaseResource extends AbstractCacheableResource implements
VersionedResource {
+public abstract class AbstractBaseResource extends Resource {
public static final String URL_PROTOCOL = "jsfresource";
private static final Logger LOGGER = RichfacesLogger.RESOURCE.getLogger();
- private boolean cacheable = true;
private Date lastModified = null;
- private String version;
protected AbstractBaseResource() {
super();
@@ -85,7 +84,6 @@
*
* @return Returns the lastModified.
*/
- @Override
protected Date getLastModified(FacesContext context) {
if (lastModified == null) {
lastModified = getLastModifiedBySource();
@@ -160,19 +158,6 @@
return classLoader;
}
- /**
- * @return Returns the cacheable.
- */
- @Override
- public boolean isCacheable(FacesContext context) {
- return cacheable;
- }
-
- protected void setCacheable(boolean cacheable) {
- this.cacheable = cacheable;
- }
-
- @Override
protected String getEntityTag(FacesContext context) {
int contentLength = getContentLength(context);
Date lastModified = getLastModified(context);
@@ -184,12 +169,20 @@
return ResourceUtils.formatWeakTag(contentLength + "-" +
lastModified.getTime());
}
+ private String getResourceVersion() {
+ if (this instanceof VersionedResource) {
+ return ((VersionedResource) this).getVersion();
+ }
+
+ return null;
+ }
+
@Override
public String getRequestPath() {
// TODO - cache resource request path in request scope
FacesContext context = FacesContext.getCurrentInstance();
- ResourceCodec resourceCodec = ResourceHandlerImpl.getResourceCodec(context);
+ ResourceCodec resourceCodec = ServiceTracker.getService(context,
ResourceCodec.class);
String resourceName = getResourceName();
Object resourceData = null;
@@ -201,9 +194,8 @@
}
}
- String resourceVersion = getVersion();
- String resourceUri = ResourceHandlerImpl.RICHFACES_RESOURCE_IDENTIFIER
- + resourceCodec.encodeResource(context, resourceName, resourceData,
resourceVersion);
+ String resourceVersion = getResourceVersion();
+ String resourceUri = resourceCodec.encodeResource(context, resourceName,
resourceData, resourceVersion);
resourceUri = Util.encodeResourceURL(context, resourceUri);
@@ -215,14 +207,6 @@
return resourceUri;
}
- public String getVersion() {
- return version;
- }
-
- protected void setVersion(String version) {
- this.version = version;
- }
-
boolean isResourceRequest() {
FacesContext facesContext = FacesContext.getCurrentInstance();
@@ -233,6 +217,15 @@
return System.currentTimeMillis();
}
+ private boolean canBeCached(FacesContext context) {
+ if (this instanceof CacheableResource) {
+ return ((CacheableResource) this).isCacheable(context);
+ }
+
+ return false;
+ }
+
+
@Override
public Map<String, String> getResponseHeaders() {
Map<String, String> headers = new HashMap<String, String>();
@@ -259,7 +252,7 @@
headers.put("Last-Modified",
Util.formatHttpDate(lastModified));
}
- if (isCacheable(facesContext)) {
+ if (canBeCached(facesContext)) {
long currentTime = getCurrentTime();
String formattedExpireDate;
long maxAge = getTimeToLive(facesContext);
@@ -321,6 +314,11 @@
}
}
+ @Override
+ public boolean userAgentNeedsUpdate(FacesContext context) {
+ return true;
+ }
+
private class MyURLConnection extends URLConnection {
MyURLConnection(URL u) {
super(u);
@@ -384,4 +382,5 @@
return new MyURLConnection(u);
}
}
+
}
Modified:
root/core/trunk/impl/src/main/java/org/richfaces/resource/AbstractCacheableResource.java
===================================================================
---
root/core/trunk/impl/src/main/java/org/richfaces/resource/AbstractCacheableResource.java 2010-06-09
14:04:16 UTC (rev 17583)
+++
root/core/trunk/impl/src/main/java/org/richfaces/resource/AbstractCacheableResource.java 2010-06-09
17:40:12 UTC (rev 17584)
@@ -21,29 +21,30 @@
package org.richfaces.resource;
+import java.util.Date;
+import java.util.Map;
+
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+
import org.richfaces.log.RichfacesLogger;
import org.richfaces.util.Util;
import org.slf4j.Logger;
-import javax.faces.application.Resource;
-import javax.faces.context.ExternalContext;
-import javax.faces.context.FacesContext;
-import java.util.Date;
-import java.util.Map;
-
/**
* @author Nick Belaevski
* @since 4.0
*/
-public abstract class AbstractCacheableResource extends Resource {
+public abstract class AbstractCacheableResource extends AbstractBaseResource implements
CacheableResource {
+
private static final Logger LOGGER = RichfacesLogger.RESOURCE.getLogger();
- protected abstract Date getLastModified(FacesContext context);
-
- public abstract boolean isCacheable(FacesContext context);
-
- protected abstract String getEntityTag(FacesContext context);
-
+ private boolean cacheable = true;
+
+ public boolean isCacheable(FacesContext context) {
+ return cacheable;
+ }
+
// TODO add getExpired(FacesContext) for HTTP matching headers?
private static boolean isUserCopyActual(Date lastModified, Date modifiedCondition) {
@@ -97,6 +98,10 @@
return ResourceUtils.matchTag(resourceEntityTag, matchHeaderValue);
}
+ public void setCacheable(boolean cacheable) {
+ this.cacheable = cacheable;
+ }
+
@Override
public boolean userAgentNeedsUpdate(FacesContext context) {
if (!isCacheable(context)) {
Modified:
root/core/trunk/impl/src/main/java/org/richfaces/resource/CompiledCSSResource.java
===================================================================
---
root/core/trunk/impl/src/main/java/org/richfaces/resource/CompiledCSSResource.java 2010-06-09
14:04:16 UTC (rev 17583)
+++
root/core/trunk/impl/src/main/java/org/richfaces/resource/CompiledCSSResource.java 2010-06-09
17:40:12 UTC (rev 17584)
@@ -49,7 +49,7 @@
/**
* @author amarkhel Class, that represented dynamic CSS resource.
*/
-public class CompiledCSSResource extends AbstractBaseResource implements StateHolder {
+public class CompiledCSSResource extends AbstractCacheableResource implements StateHolder
{
private static final String ECSS = ".ecss";
Modified:
root/core/trunk/impl/src/main/java/org/richfaces/resource/DefaultResourceCodec.java
===================================================================
---
root/core/trunk/impl/src/main/java/org/richfaces/resource/DefaultResourceCodec.java 2010-06-09
14:04:16 UTC (rev 17583)
+++
root/core/trunk/impl/src/main/java/org/richfaces/resource/DefaultResourceCodec.java 2010-06-09
17:40:12 UTC (rev 17584)
@@ -27,7 +27,7 @@
import org.richfaces.util.Util;
-final class DefaultResourceCodec implements ResourceCodec {
+public final class DefaultResourceCodec implements ResourceCodec {
private static final String RESOURCE_VERSION_PARAM = "v";
@@ -35,11 +35,6 @@
private static final String RESOURCE_DATA_OBJECT_PARAM = "do";
- private static final ResourceCodec CODEC = new DefaultResourceCodec();
-
- private DefaultResourceCodec() {
- }
-
public String decodeResourceName(FacesContext context, String requestPath) {
return requestPath;
}
@@ -60,10 +55,6 @@
return null;
}
- public static ResourceCodec getInstance() {
- return CODEC;
- }
-
public String decodeResourceVersion(FacesContext context, String requestPath) {
return
context.getExternalContext().getRequestParameterMap().get(RESOURCE_VERSION_PARAM);
}
@@ -115,7 +106,8 @@
}
}
- return encodeResource(context, resourceName, encodedDataString, isBytesArray,
resourceVersion);
+ return ResourceHandlerImpl.RICHFACES_RESOURCE_IDENTIFIER
+ + encodeResource(context, resourceName, encodedDataString, isBytesArray,
resourceVersion);
}
public String getResourceKey(FacesContext context, String requestPath) {
Modified:
root/core/trunk/impl/src/main/java/org/richfaces/resource/LegacyResourceCodec.java
===================================================================
---
root/core/trunk/impl/src/main/java/org/richfaces/resource/LegacyResourceCodec.java 2010-06-09
14:04:16 UTC (rev 17583)
+++
root/core/trunk/impl/src/main/java/org/richfaces/resource/LegacyResourceCodec.java 2010-06-09
17:40:12 UTC (rev 17584)
@@ -25,13 +25,8 @@
import org.richfaces.util.Util;
-final class LegacyResourceCodec implements ResourceCodec {
+public final class LegacyResourceCodec implements ResourceCodec {
- private static final ResourceCodec CODEC = new LegacyResourceCodec();
-
- private LegacyResourceCodec() {
- }
-
public String decodeResourceName(FacesContext context, String requestPath) {
return Util.legacyDecodeResourceName(requestPath);
}
@@ -40,16 +35,13 @@
return Util.legacyDecodeResourceData(requestPath);
}
- public static ResourceCodec getInstance() {
- return CODEC;
- }
-
public String decodeResourceVersion(FacesContext context, String requestPath) {
return Util.legacyDecodeResourceVersion(requestPath);
}
public String encodeResource(FacesContext context, String resourceName, Object
resourceData, String resourceVersion) {
- return Util.legacyEncodeResourceData(resourceName, resourceData,
resourceVersion);
+ return ResourceHandlerImpl.RICHFACES_RESOURCE_IDENTIFIER
+ + Util.legacyEncodeResourceData(resourceName, resourceData,
resourceVersion);
}
public String getResourceKey(FacesContext context, String requestPath) {
Modified:
root/core/trunk/impl/src/main/java/org/richfaces/resource/ResourceHandlerImpl.java
===================================================================
---
root/core/trunk/impl/src/main/java/org/richfaces/resource/ResourceHandlerImpl.java 2010-06-09
14:04:16 UTC (rev 17583)
+++
root/core/trunk/impl/src/main/java/org/richfaces/resource/ResourceHandlerImpl.java 2010-06-09
17:40:12 UTC (rev 17584)
@@ -43,7 +43,7 @@
import org.ajax4jsf.cache.Cache;
import org.ajax4jsf.cache.CacheManager;
-import org.ajax4jsf.resource.Java2Dresource;
+import org.richfaces.application.DependencyInjectionService;
import org.richfaces.application.ServiceTracker;
import org.richfaces.log.RichfacesLogger;
import org.richfaces.util.Util;
@@ -99,21 +99,6 @@
cache = CacheManager.getInstance().getNewCache(RESOURCE_CACHE_NAME, envMap);
}
- protected static void setResourceCodec(ResourceCodec codec) {
- FacesContext facesContext = FacesContext.getCurrentInstance();
-
- ServiceTracker.setService(facesContext, ResourceCodec.class, codec);
- }
-
- public static ResourceCodec getResourceCodec(FacesContext context) {
- ResourceCodec resourceCodec = ServiceTracker.getService(context,
ResourceCodec.class);
- if (resourceCodec == null) {
- resourceCodec = DefaultResourceCodec.getInstance();
- }
-
- return resourceCodec;
- }
-
protected static String getResourcePathFromRequest(FacesContext context) {
String resourceName = Util.decodeResourceURL(context);
@@ -205,7 +190,7 @@
@Override
public void handleResourceRequest(FacesContext context) throws IOException {
if (isThisHandlerResourceRequest(context)) {
- ResourceCodec resourceCodec = ResourceHandlerImpl.getResourceCodec(context);
+ ResourceCodec resourceCodec = ServiceTracker.getService(context,
ResourceCodec.class);
String resourcePath = getResourcePathFromRequest(context);
@@ -232,8 +217,7 @@
}
if (resource == null) {
- resource = createHandlerDependentResource(resourceName,
- context.getExternalContext().getRequestParameterMap());
+ resource = createHandlerDependentResource(resourceName);
}
if (resource == null) {
@@ -391,14 +375,26 @@
}
}
+ protected void injectProperties(Resource resource, Map<String, String>
parameters) {
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ DependencyInjectionService diService = ServiceTracker.getService(facesContext,
DependencyInjectionService.class);
+
+ Map<Object, Object> attributes = facesContext.getAttributes();
+ try {
+ attributes.put(ResourceParameterELResolver.CONTEXT_ATTRIBUTE_NAME,
parameters);
+ diService.inject(facesContext, resource);
+ } finally {
+ attributes.remove(ResourceParameterELResolver.CONTEXT_ATTRIBUTE_NAME);
+ }
+ }
+
/**
* Should be called only if {@link #isResourceExists(String)} returns
<code>true</code>
*
* @param resourceName
- * @param params
* @return
*/
- protected Resource createHandlerDependentResource(String resourceName, Map<String,
String> params) {
+ protected Resource createHandlerDependentResource(String resourceName) {
Resource resource = null;
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
@@ -440,11 +436,6 @@
if (legitimateResource) {
resource = (Resource) resourceClass.newInstance();
resource.setResourceName(resourceName);
- if (resource instanceof Java2Dresource) {
- Java2Dresource dynamicResource = (Java2Dresource) resource;
- dynamicResource.populateParameters(params);
- resource = dynamicResource;
- }
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(MessageFormat.format("Successfully created
instance of {0} resource",
resourceName));
@@ -471,7 +462,7 @@
result = new CompiledCSSResource(resourceName);
} else {
if ((resourceName != null) && ((libraryName == null) ||
(libraryName.length() == 0))) {
- result = createHandlerDependentResource(resourceName, params);
+ result = createHandlerDependentResource(resourceName);
}
if (result == null) {
@@ -479,6 +470,10 @@
}
}
+ if (result != null) {
+ injectProperties(result, params);
+ }
+
return result;
}
Added:
root/core/trunk/impl/src/main/java/org/richfaces/resource/ResourceParameterELResolver.java
===================================================================
---
root/core/trunk/impl/src/main/java/org/richfaces/resource/ResourceParameterELResolver.java
(rev 0)
+++
root/core/trunk/impl/src/main/java/org/richfaces/resource/ResourceParameterELResolver.java 2010-06-09
17:40:12 UTC (rev 17584)
@@ -0,0 +1,75 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This 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 software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.resource;
+
+import java.beans.FeatureDescriptor;
+import java.util.Iterator;
+
+import javax.el.ELContext;
+import javax.el.ELResolver;
+import javax.faces.context.FacesContext;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class ResourceParameterELResolver extends ELResolver {
+
+ static final String CONTEXT_ATTRIBUTE_NAME = "rfResourceParam";
+
+ @Override
+ public Class<?> getCommonPropertyType(ELContext context, Object base) {
+ return String.class;
+ }
+
+ @Override
+ public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context,
Object base) {
+ return null;
+ }
+
+ @Override
+ public Class<?> getType(ELContext context, Object base, Object property) {
+ return null;
+ }
+
+ @Override
+ public Object getValue(ELContext context, Object base, Object property) {
+ if (CONTEXT_ATTRIBUTE_NAME.equals(property) && base == null) {
+ context.setPropertyResolved(true);
+ FacesContext facesContext = (FacesContext)
context.getContext(FacesContext.class);
+ return facesContext.getAttributes().get(CONTEXT_ATTRIBUTE_NAME);
+ }
+
+ return null;
+ }
+
+ @Override
+ public boolean isReadOnly(ELContext context, Object base, Object property) {
+ return true;
+ }
+
+ @Override
+ public void setValue(ELContext context, Object base, Object property, Object value)
{
+ throw new UnsupportedOperationException();
+ }
+
+}
Modified: root/core/trunk/impl/src/main/java/org/richfaces/resource/TestResource2.java
===================================================================
---
root/core/trunk/impl/src/main/java/org/richfaces/resource/TestResource2.java 2010-06-09
14:04:16 UTC (rev 17583)
+++
root/core/trunk/impl/src/main/java/org/richfaces/resource/TestResource2.java 2010-06-09
17:40:12 UTC (rev 17584)
@@ -37,7 +37,7 @@
import org.richfaces.skin.SkinFactory;
@DynamicResource
-public class TestResource2 extends Java2Dresource {
+public class TestResource2 extends Java2Dresource implements VersionedResource {
private static final int MASK_FOR_COLOR_WITHOUT_ALPHA_CHANNEL = 0x00FFFFFF;
@@ -83,7 +83,6 @@
return Integer.toHexString(color.getRGB() &
MASK_FOR_COLOR_WITHOUT_ALPHA_CHANNEL);
}
- @Override
public String getVersion() {
return VersionBean.VERSION.getResourceVersion();
}
Modified: root/core/trunk/impl/src/main/java/org/richfaces/util/Util.java
===================================================================
--- root/core/trunk/impl/src/main/java/org/richfaces/util/Util.java 2010-06-09 14:04:16
UTC (rev 17583)
+++ root/core/trunk/impl/src/main/java/org/richfaces/util/Util.java 2010-06-09 17:40:12
UTC (rev 17584)
@@ -61,6 +61,7 @@
import java.text.Format;
import java.text.ParseException;
import java.text.SimpleDateFormat;
+import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
@@ -403,11 +404,13 @@
}
public static Map<String, String> parseResourceParameters(String resourceName)
{
+ int queryPartIdx = resourceName.lastIndexOf(QUESTION_SIGN);
+ if (queryPartIdx == -1) {
+ return Collections.emptyMap();
+ }
+
Map<String, String> params = new HashMap<String, String>();
- if (!(resourceName.lastIndexOf(QUESTION_SIGN) != -1)) {
- return params;
- }
- resourceName = resourceName.substring(resourceName.lastIndexOf(QUESTION_SIGN) +
1);
+ resourceName = resourceName.substring(queryPartIdx + 1);
try {
if (resourceName.trim().length() > 0) {
String query = resourceName;
Modified:
root/core/trunk/impl/src/main/resources/META-INF/resource-handler.faces-config.xml
===================================================================
---
root/core/trunk/impl/src/main/resources/META-INF/resource-handler.faces-config.xml 2010-06-09
14:04:16 UTC (rev 17583)
+++
root/core/trunk/impl/src/main/resources/META-INF/resource-handler.faces-config.xml 2010-06-09
17:40:12 UTC (rev 17584)
@@ -5,5 +5,6 @@
<application>
<resource-handler>org.richfaces.resource.ResourceHandlerImpl</resource-handler>
+
<el-resolver>org.richfaces.resource.ResourceParameterELResolver</el-resolver>
</application>
</faces-config>
Modified:
root/core/trunk/impl/src/test/java/org/richfaces/resource/AbstractBaseResourceTest.java
===================================================================
---
root/core/trunk/impl/src/test/java/org/richfaces/resource/AbstractBaseResourceTest.java 2010-06-09
14:04:16 UTC (rev 17583)
+++
root/core/trunk/impl/src/test/java/org/richfaces/resource/AbstractBaseResourceTest.java 2010-06-09
17:40:12 UTC (rev 17584)
@@ -39,6 +39,7 @@
import org.easymock.EasyMock;
import org.jboss.test.faces.AbstractFacesTest;
+import org.richfaces.application.ServiceTracker;
import org.richfaces.util.Util;
/**
@@ -129,15 +130,15 @@
EasyMock.expect(resourceCodec.encodeResource(EasyMock.same(facesContext),
EasyMock.eq("org.richfaces.resource.MockStateAwareResource"),
- EasyMock.same(resourceState),
EasyMock.eq("4_0_alpha"))).andReturn("Resource0/4_0_alpha/data");
+ EasyMock.same(resourceState),
EasyMock.eq("4_0_alpha"))).andReturn("/rfRes/Resource0/4_0_alpha/data");
EasyMock.expect(resourceCodec.encodeResource(EasyMock.same(facesContext),
EasyMock.eq("org.richfaces.resource.MockStateAwareResource"),
- EasyMock.eq(null),
EasyMock.eq("4_0_alpha"))).andReturn("Resource1/4_0_alpha");
+ EasyMock.eq(null),
EasyMock.eq("4_0_alpha"))).andReturn("/rfRes/Resource1/4_0_alpha");
EasyMock.expect(resourceCodec.encodeResource(EasyMock.same(facesContext),
EasyMock.eq("org.richfaces.resource.MockResource"),
- EasyMock.eq(null),
EasyMock.eq("4_0_alpha"))).andReturn("Resource2/4_0_alpha");
+ EasyMock.eq(null),
EasyMock.eq("4_0_alpha"))).andReturn("/rfRes/Resource2/4_0_alpha");
EasyMock.replay(resourceCodec);
- ResourceHandlerImpl.setResourceCodec(resourceCodec);
+ ServiceTracker.setService(facesContext, ResourceCodec.class, resourceCodec);
MockStateAwareResourceImpl stateAwareResourceImpl = new
MockStateAwareResourceImpl();
@@ -211,7 +212,6 @@
assertEquals("org.richfaces.resource.ResourceImpl",
defaultResource.getResourceName());
assertEquals(-1, defaultResource.getContentLength(facesContext));
assertNull(defaultResource.getEntityTag(facesContext));
- assertNull(defaultResource.getVersion());
assertNull(defaultResource.getExpires(facesContext));
Date lastModified = defaultResource.getLastModified(facesContext);
@@ -248,7 +248,7 @@
assertFalse(actualResource.userAgentNeedsUpdate(facesContext));
}
- private class MockResourceImpl extends AbstractBaseResource {
+ private class MockResourceImpl extends AbstractCacheableResource implements
VersionedResource {
private int contentLength = -1;
private long currentTime;
private String entityTag;
@@ -273,11 +273,6 @@
return inputStream;
}
- /*
- * (non-Javadoc)
- * @see org.richfaces.resource.ResourceImpl#getVersion()
- */
- @Override
public String getVersion() {
return version;
}
@@ -376,7 +371,7 @@
}
- private class ResourceImpl extends AbstractBaseResource {
+ private class ResourceImpl extends AbstractCacheableResource {
public ResourceImpl() {
super();
setResourceName("org.richfaces.resource.ResourceImpl");
Modified:
root/core/trunk/impl/src/test/java/org/richfaces/resource/CacheableResourceImpl.java
===================================================================
---
root/core/trunk/impl/src/test/java/org/richfaces/resource/CacheableResourceImpl.java 2010-06-09
14:04:16 UTC (rev 17583)
+++
root/core/trunk/impl/src/test/java/org/richfaces/resource/CacheableResourceImpl.java 2010-06-09
17:40:12 UTC (rev 17584)
@@ -39,7 +39,7 @@
* @since 4.0
*/
@DynamicResource
-public class CacheableResourceImpl extends AbstractBaseResource {
+public class CacheableResourceImpl extends AbstractCacheableResource {
/*
* (non-Javadoc)
Modified:
root/core/trunk/impl/src/test/java/org/richfaces/resource/ResourceHandlerImplTest.java
===================================================================
---
root/core/trunk/impl/src/test/java/org/richfaces/resource/ResourceHandlerImplTest.java 2010-06-09
14:04:16 UTC (rev 17583)
+++
root/core/trunk/impl/src/test/java/org/richfaces/resource/ResourceHandlerImplTest.java 2010-06-09
17:40:12 UTC (rev 17584)
@@ -40,6 +40,7 @@
import org.easymock.classextension.EasyMock;
import org.jboss.test.faces.AbstractFacesTest;
import org.jboss.test.faces.htmlunit.LocalWebClient;
+import org.richfaces.application.ServiceTracker;
import org.richfaces.util.Util;
import com.gargoylesoftware.htmlunit.Cache;
@@ -229,7 +230,7 @@
EasyMock.expect(mockedCodec.getResourceKey(EasyMock.<FacesContext>notNull(),
EasyMock.eq("StateHolderResource"))).andReturn("StateHolderResource.jsf?do=1");
EasyMock.replay(mockedCodec);
- ResourceHandlerImpl.setResourceCodec(mockedCodec);
+ ServiceTracker.setService(facesContext, ResourceCodec.class, mockedCodec);
WebRequestSettings settings =
new WebRequestSettings(new
URL("http://localhost/rfRes/StateHolderResource.jsf?do=1"));
Modified:
root/core/trunk/impl/src/test/java/org/richfaces/resource/StateHolderResourceImpl.java
===================================================================
---
root/core/trunk/impl/src/test/java/org/richfaces/resource/StateHolderResourceImpl.java 2010-06-09
14:04:16 UTC (rev 17583)
+++
root/core/trunk/impl/src/test/java/org/richfaces/resource/StateHolderResourceImpl.java 2010-06-09
17:40:12 UTC (rev 17584)
@@ -37,7 +37,7 @@
* @since 4.0
*/
@DynamicResource
-public class StateHolderResourceImpl extends AbstractBaseResource implements StateHolder
{
+public class StateHolderResourceImpl extends AbstractCacheableResource implements
StateHolder {
private Object state = "";
@Override
Modified:
root/core/trunk/impl/src/test/java/org/richfaces/resource/VersionedResourceImpl.java
===================================================================
---
root/core/trunk/impl/src/test/java/org/richfaces/resource/VersionedResourceImpl.java 2010-06-09
14:04:16 UTC (rev 17583)
+++
root/core/trunk/impl/src/test/java/org/richfaces/resource/VersionedResourceImpl.java 2010-06-09
17:40:12 UTC (rev 17584)
@@ -28,8 +28,8 @@
* @since 4.0
*/
@DynamicResource
-public class VersionedResourceImpl extends EmptyStreamResource {
- @Override
+public class VersionedResourceImpl extends EmptyStreamResource implements
VersionedResource {
+
public String getVersion() {
return "1_0_2";
}
Modified:
root/ui/core/trunk/ui/src/main/java/org/richfaces/resource/MediaOutputResource.java
===================================================================
---
root/ui/core/trunk/ui/src/main/java/org/richfaces/resource/MediaOutputResource.java 2010-06-09
14:04:16 UTC (rev 17583)
+++
root/ui/core/trunk/ui/src/main/java/org/richfaces/resource/MediaOutputResource.java 2010-06-09
17:40:12 UTC (rev 17584)
@@ -40,7 +40,7 @@
* @author Nick Belaevski
* @since 4.0
*/
-public class MediaOutputResource extends AbstractBaseResource implements StateHolder {
+public class MediaOutputResource extends AbstractCacheableResource implements StateHolder
{
private MethodExpression contentProducer;
private ValueExpression expiresExpression;
Modified: root/ui/core/trunk/ui/src/main/java/org/richfaces/resource/PushResource.java
===================================================================
---
root/ui/core/trunk/ui/src/main/java/org/richfaces/resource/PushResource.java 2010-06-09
14:04:16 UTC (rev 17583)
+++
root/ui/core/trunk/ui/src/main/java/org/richfaces/resource/PushResource.java 2010-06-09
17:40:12 UTC (rev 17584)
@@ -40,11 +40,6 @@
public class PushResource extends AbstractBaseResource {
@Override
- public boolean isCacheable(FacesContext context) {
- return false;
- }
-
- @Override
public InputStream getInputStream() throws IOException {
return null;
}