JBoss Rich Faces SVN: r17592 - in root/core/trunk/impl/src: test/resources/javascript and 1 other directory.
by richfaces-svn-commits@lists.jboss.org
Author: pyaschenko
Date: 2010-06-10 10:17:06 -0400 (Thu, 10 Jun 2010)
New Revision: 17592
Modified:
root/core/trunk/impl/src/main/resources/META-INF/resources/richfaces-event.js
root/core/trunk/impl/src/test/resources/javascript/richfaces-event-qunit.js
Log:
Event API changes: refactoring, multiple binding was added to bindById method, used in autocomplete component
QUnit tests was fixed after the changes
Modified: root/core/trunk/impl/src/main/resources/META-INF/resources/richfaces-event.js
===================================================================
--- root/core/trunk/impl/src/main/resources/META-INF/resources/richfaces-event.js 2010-06-10 13:44:40 UTC (rev 17591)
+++ root/core/trunk/impl/src/main/resources/META-INF/resources/richfaces-event.js 2010-06-10 14:17:06 UTC (rev 17592)
@@ -2,6 +2,9 @@
* @author Pavel Yaschenko
*/
+// TODO: add support to bind multiple events using type param as an object with eventType,function pairs // see bindById method
+// TODO: update js docs
+
(function($, richfaces) {
/**
@@ -27,13 +30,27 @@
return element;
}
+ var getHandlerWrapper = function (component, fn) {
+ return f = function (e,d){
+ fn.call(component||this, e, this, d);
+ };
+ }
+
+ var getMultipleHandlerWrapper = function (object, component) {
+ var result = {};
+ for (var type in object) {
+ result[type] = getHandlerWrapper(component, object[type]);
+ }
+ return result;
+ }
+
$.extend(richfaces.Event, {
/**
* @constant
* @name RichFaces.Event.RICH_NAMESPACE
* @type string
* */
- RICH_NAMESPACE : "RICH:",
+ RICH_NAMESPACE : "RICH",
/**
* Attach an event handler to execute when the DOM is fully loaded.
@@ -65,12 +82,10 @@
* It is a context for an event handler
* @return {function} function that binded to the element's event
* */
- bind : function(selector, type, fn, data) {
+ bind : function(selector, type, fn, component, data) {
// type: namespace can be used, like onclick.rf.conponentName
- var f = function (e,d){
- e.data.fn.call(e.data.component||this, e, this, d);
- };
- getEventElement(selector).bind(type, {component: data, fn:fn}, f);
+ var f = getHandlerWrapper(component, fn);
+ getEventElement(selector).bind(type, data, f);
return f;
},
@@ -86,12 +101,15 @@
* It is a context for an event handler
* @return {function} function that binded to the element's event
* */
- bindById : function(id, type, fn, data) {
+ bindById : function(id, type, fn, component, data) {
// type: namespace can be used, like onclick.rf.conponentName
- var f = function (e,d){
- e.data.fn.call(e.data.component||this, e, this, d);
- };
- $(document.getElementById(id)).bind(type, {component: data, fn:fn}, f);
+ if (typeof type == "object") {
+ // in this case fn == component object
+ $(document.getElementById(id)).bind(getMultipleHandlerWrapper(type, fn), data);
+ } else {
+ var f = getHandlerWrapper(component, fn);
+ $(document.getElementById(id)).bind(type, data, f);
+ }
return f;
},
@@ -108,12 +126,10 @@
* It is a context for an event handler
* @return {function} function that binded to the element's event
* */
- bindOne: function(selector, type, fn, data) {
+ bindOne: function(selector, type, fn, component, data) {
// type: namespace can be used, like onclick.rf.conponentName
- var f = function (e,d){
- e.data.fn.call(e.data.component||this, e, this, d);
- };
- getEventElement(selector).one(type, {component: data, fn:fn}, f);
+ var f = getHandlerWrapper(component, fn);
+ getEventElement(selector).one(type, data, f);
return f;
},
@@ -130,12 +146,10 @@
* It is a context for an event handler
* @return {function} function that binded to the element's event
* */
- bindOneById: function(id, type, fn, data) {
+ bindOneById: function(id, type, fn, component, data) {
// type: namespace can be used, like onclick.rf.conponentName
- var f = function (e,d){
- e.data.fn.call(e.data.component||this, e, this, d);
- };
- $(document.getElementById(id)).one(type, {component: data, fn:fn}, f);
+ var f = getHandlerWrapper(component, fn);
+ $(document.getElementById(id)).one(type, data, f);
return f;
},
Modified: root/core/trunk/impl/src/test/resources/javascript/richfaces-event-qunit.js
===================================================================
--- root/core/trunk/impl/src/test/resources/javascript/richfaces-event-qunit.js 2010-06-10 13:44:40 UTC (rev 17591)
+++ root/core/trunk/impl/src/test/resources/javascript/richfaces-event-qunit.js 2010-06-10 14:17:06 UTC (rev 17592)
@@ -20,12 +20,10 @@
var domElement = element;
var callback = function (e, o, d) {
- expect(6);
+ expect(4);
equals(e.type, "click");
equals(o, element);
equals(d, testData2);
- equals(e.data.component, testData1);
- equals(typeof e.data.fn, "function");
equals(this, testData1);
};
return callback;
14 years, 7 months
JBoss Rich Faces SVN: r17591 - in root/core/trunk: impl/src/main/java/org/ajax4jsf/context and 8 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2010-06-10 09:44:40 -0400 (Thu, 10 Jun 2010)
New Revision: 17591
Added:
root/core/trunk/api/src/main/java/org/richfaces/resource/ImageType.java
root/core/trunk/api/src/main/java/org/richfaces/resource/Java2DUserResource.java
root/core/trunk/api/src/main/java/org/richfaces/resource/StateHolderResource.java
root/core/trunk/api/src/main/java/org/richfaces/resource/UserResource.java
root/core/trunk/impl/src/main/java/org/richfaces/resource/Java2DUserResourceAdaptor.java
root/core/trunk/impl/src/main/java/org/richfaces/resource/UserResourceAdaptor.java
Removed:
root/core/trunk/impl/src/main/java/org/ajax4jsf/util/NumericDataInputStream.java
root/core/trunk/impl/src/main/java/org/ajax4jsf/util/NumericDataOutputStream.java
root/core/trunk/impl/src/test/java/org/ajax4jsf/util/NumericStreamsTest.java
Modified:
root/core/trunk/api/src/main/java/org/richfaces/resource/CacheableResource.java
root/core/trunk/api/src/main/java/org/richfaces/resource/VersionedResource.java
root/core/trunk/impl/src/main/java/org/ajax4jsf/context/ContextInitParameters.java
root/core/trunk/impl/src/main/java/org/ajax4jsf/resource/Java2Dresource.java
root/core/trunk/impl/src/main/java/org/richfaces/renderkit/html/BaseGradient.java
root/core/trunk/impl/src/main/java/org/richfaces/renderkit/html/CustomizeableGradient.java
root/core/trunk/impl/src/main/java/org/richfaces/renderkit/html/images/BaseControlBackgroundImage.java
root/core/trunk/impl/src/main/java/org/richfaces/renderkit/html/images/CancelControlIcon.java
root/core/trunk/impl/src/main/java/org/richfaces/renderkit/html/images/OneColorBasedResource.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/CachedResourceImpl.java
root/core/trunk/impl/src/main/java/org/richfaces/resource/CompiledCSSResource.java
root/core/trunk/impl/src/main/java/org/richfaces/resource/ResourceHandlerImpl.java
root/core/trunk/impl/src/main/java/org/richfaces/resource/ResourceParameterELResolver.java
root/core/trunk/impl/src/main/java/org/richfaces/resource/TestResource2.java
root/core/trunk/impl/src/test/java/org/richfaces/resource/AbstractBaseResourceTest.java
root/core/trunk/impl/src/test/java/org/richfaces/resource/AbstractCacheableResourceTest.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/resources/resources/full.css
root/core/trunk/impl/src/test/resources/resources/importedEL.css
root/core/trunk/impl/src/test/resources/resources/resource.css
Log:
https://jira.jboss.org/browse/RF-8665
Modified: root/core/trunk/api/src/main/java/org/richfaces/resource/CacheableResource.java
===================================================================
--- root/core/trunk/api/src/main/java/org/richfaces/resource/CacheableResource.java 2010-06-10 00:30:15 UTC (rev 17590)
+++ root/core/trunk/api/src/main/java/org/richfaces/resource/CacheableResource.java 2010-06-10 13:44:40 UTC (rev 17591)
@@ -21,6 +21,8 @@
*/
package org.richfaces.resource;
+import java.util.Date;
+
import javax.faces.context.FacesContext;
/**
@@ -30,4 +32,10 @@
public interface CacheableResource {
public boolean isCacheable(FacesContext context);
+
+ public Date getExpires(FacesContext context);
+
+ public int getTimeToLive(FacesContext context);
+
+ public String getEntityTag(FacesContext context);
}
Added: root/core/trunk/api/src/main/java/org/richfaces/resource/ImageType.java
===================================================================
--- root/core/trunk/api/src/main/java/org/richfaces/resource/ImageType.java (rev 0)
+++ root/core/trunk/api/src/main/java/org/richfaces/resource/ImageType.java 2010-06-10 13:44:40 UTC (rev 17591)
@@ -0,0 +1,110 @@
+/*
+ * 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.awt.image.BufferedImage;
+import java.awt.image.IndexColorModel;
+
+public enum ImageType {
+ GIF("gif") {
+ @Override
+ public BufferedImage createImage(int width, int height) {
+ return createARGBImage(width, height);
+ }
+ },
+ PNG("png") {
+ @Override
+ public BufferedImage createImage(int width, int height) {
+ return createARGBImage(width, height);
+ }
+ },
+ PNG8("png") {
+ @Override
+ public BufferedImage createImage(int width, int height) {
+ return new BufferedImage(width, height, BufferedImage.TYPE_BYTE_INDEXED, SAFE_WEB_COLORS_MODEL);
+ }
+ },
+
+ // TODO - add common png8
+ JPEG("jpeg") {
+ @Override
+ public BufferedImage createImage(int width, int height) {
+ return new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
+ }
+ };
+
+ /**
+ * Default web safe colors color model
+ */
+ protected static final IndexColorModel SAFE_WEB_COLORS_MODEL;
+
+ // Build web safe 6x6x6 cube color model.
+ static {
+ byte[] webLevels = {
+ 0, 51, 102, (byte) 153, (byte) 204, (byte) 255
+ };
+ int colorsNumber = webLevels.length * webLevels.length * webLevels.length; /* 216 colors */
+ byte[] r = new byte[colorsNumber];
+ byte[] g = new byte[colorsNumber];
+ byte[] b = new byte[colorsNumber];
+
+ r[0] = 0;
+ g[0] = 0;
+ b[0] = 0;
+
+ for (int i = 0; i < webLevels.length; i++) {
+ for (int j = 0; j < webLevels.length; j++) {
+ for (int k = 0; k < webLevels.length; k++) {
+ int colorNum = i * webLevels.length * webLevels.length + j * webLevels.length + k;
+
+ r[colorNum] = webLevels[i];
+ g[colorNum] = webLevels[j];
+ b[colorNum] = webLevels[k];
+ }
+ }
+ }
+
+ SAFE_WEB_COLORS_MODEL = new IndexColorModel(8, colorsNumber, r, g, b, 0);
+ }
+
+ private String formatName;
+ private String mimeType;
+
+ private ImageType(String formatName) {
+ this.formatName = formatName;
+ this.mimeType = "image/" + formatName;
+ }
+
+ private static BufferedImage createARGBImage(int width, int height) {
+ return new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
+ }
+
+ public abstract BufferedImage createImage(int width, int height);
+
+ public String getFormatName() {
+ return formatName;
+ }
+
+ public String getMimeType() {
+ return mimeType;
+ }
+}
\ No newline at end of file
Added: root/core/trunk/api/src/main/java/org/richfaces/resource/Java2DUserResource.java
===================================================================
--- root/core/trunk/api/src/main/java/org/richfaces/resource/Java2DUserResource.java (rev 0)
+++ root/core/trunk/api/src/main/java/org/richfaces/resource/Java2DUserResource.java 2010-06-10 13:44:40 UTC (rev 17591)
@@ -0,0 +1,45 @@
+/*
+ * 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.awt.Dimension;
+import java.awt.Graphics2D;
+import java.util.Date;
+import java.util.Map;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public interface Java2DUserResource {
+
+ public Map<String, String> getResponseHeaders();
+
+ public Date getLastModified();
+
+ public ImageType getImageType();
+
+ public Dimension getDimension();
+
+ public void paint(Graphics2D graphics2D, Dimension dimension);
+
+}
Added: root/core/trunk/api/src/main/java/org/richfaces/resource/StateHolderResource.java
===================================================================
--- root/core/trunk/api/src/main/java/org/richfaces/resource/StateHolderResource.java (rev 0)
+++ root/core/trunk/api/src/main/java/org/richfaces/resource/StateHolderResource.java 2010-06-10 13:44:40 UTC (rev 17591)
@@ -0,0 +1,42 @@
+/*
+ * 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.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+
+import javax.faces.context.FacesContext;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public interface StateHolderResource {
+
+ public boolean isTransient();
+
+ public void writeState(FacesContext context, DataOutput dataOutput) throws IOException;
+
+ public void readState(FacesContext context, DataInput dataInput) throws IOException;
+
+}
Added: root/core/trunk/api/src/main/java/org/richfaces/resource/UserResource.java
===================================================================
--- root/core/trunk/api/src/main/java/org/richfaces/resource/UserResource.java (rev 0)
+++ root/core/trunk/api/src/main/java/org/richfaces/resource/UserResource.java 2010-06-10 13:44:40 UTC (rev 17591)
@@ -0,0 +1,45 @@
+/*
+ * 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.io.IOException;
+import java.io.InputStream;
+import java.util.Date;
+import java.util.Map;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public interface UserResource {
+
+ public Map<String, String> getResponseHeaders();
+
+ public Date getLastModified();
+
+ public InputStream getInputStream() throws IOException;
+
+ public String getContentType();
+
+ public int getContentLength();
+
+}
Modified: root/core/trunk/api/src/main/java/org/richfaces/resource/VersionedResource.java
===================================================================
--- root/core/trunk/api/src/main/java/org/richfaces/resource/VersionedResource.java 2010-06-10 00:30:15 UTC (rev 17590)
+++ root/core/trunk/api/src/main/java/org/richfaces/resource/VersionedResource.java 2010-06-10 13:44:40 UTC (rev 17591)
@@ -28,5 +28,7 @@
* @since 4.0
*/
public interface VersionedResource {
+
public String getVersion();
+
}
Modified: root/core/trunk/impl/src/main/java/org/ajax4jsf/context/ContextInitParameters.java
===================================================================
--- root/core/trunk/impl/src/main/java/org/ajax4jsf/context/ContextInitParameters.java 2010-06-10 00:30:15 UTC (rev 17590)
+++ root/core/trunk/impl/src/main/java/org/ajax4jsf/context/ContextInitParameters.java 2010-06-10 13:44:40 UTC (rev 17591)
@@ -40,6 +40,11 @@
* @author asmirnov
*/
public final class ContextInitParameters {
+ /**
+ *
+ */
+ private static final int DEFAULT_TTL = 60 * 60 * 24;
+
public static final String[] DATATABLE_USES_VIEW_LOCALE = {"org.richfaces.datatableUsesViewLocale"};
/**
@@ -51,6 +56,9 @@
public static final String STD_CONTROLS_SKINNING_CLASSES_PARAM = "org.richfaces.ENABLE_CONTROL_SKINNING_CLASSES";
public static final String[] QUEUE_ENABLED = {"org.richfaces.queue.enabled"};
+ //TODO - better name
+ public static final String[] RESOURCES_TTL = {"org.richfaces.RESOURCE_DEFAULT_TTL"};
+
private static final String INIT_PARAM_PREFIX = ContextInitParameters.class.getSimpleName() + ":";
private static final Object NULL = new Object() {
@@ -95,6 +103,10 @@
return getBooleanValue(paramValue, true);
}
+ public static int getResourcesTimeToLive(FacesContext context) {
+ return getInteger(context, RESOURCES_TTL, DEFAULT_TTL);
+ }
+
/**
* Method for determining STD_CONTROLS_SKINNING_CLASSES_PARAM parameter
*
@@ -106,11 +118,11 @@
return getBooleanValue(paramValue, false);
}
- static int getInteger(FacesContext context, String[] paramNames, int defaulValue) {
+ static int getInteger(FacesContext context, String[] paramNames, int defaultValue) {
String initParameter = getInitParameter(context, paramNames);
if (null == initParameter) {
- return defaulValue;
+ return defaultValue;
} else {
try {
return Integer.parseInt(initParameter);
@@ -120,21 +132,21 @@
}
}
- static String getString(FacesContext context, String[] paramNames, String defaulValue) {
+ static String getString(FacesContext context, String[] paramNames, String defaultValue) {
String initParameter = getInitParameter(context, paramNames);
if (null == initParameter) {
- return defaulValue;
+ return defaultValue;
} else {
return initParameter;
}
}
- static boolean getBoolean(FacesContext context, String[] paramNames, boolean defaulValue) {
+ static boolean getBoolean(FacesContext context, String[] paramNames, boolean defaultValue) {
String initParameter = getInitParameter(context, paramNames);
if (null == initParameter) {
- return defaulValue;
+ return defaultValue;
} else if ("true".equalsIgnoreCase(initParameter) || "yes".equalsIgnoreCase(initParameter)) {
return true;
} else if ("false".equalsIgnoreCase(initParameter) || "no".equalsIgnoreCase(initParameter)) {
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-10 00:30:15 UTC (rev 17590)
+++ root/core/trunk/impl/src/main/java/org/ajax4jsf/resource/Java2Dresource.java 2010-06-10 13:44:40 UTC (rev 17591)
@@ -25,21 +25,21 @@
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.DataInput;
+import java.io.DataOutput;
import java.io.IOException;
import java.io.InputStream;
-import javax.faces.component.StateHolder;
import javax.faces.context.FacesContext;
import javax.imageio.ImageIO;
import org.ajax4jsf.util.HtmlColor;
import org.ajax4jsf.util.HtmlDimensions;
-import org.ajax4jsf.util.NumericDataInputStream;
-import org.ajax4jsf.util.NumericDataOutputStream;
import org.richfaces.resource.AbstractCacheableResource;
+import org.richfaces.resource.ImageType;
+import org.richfaces.resource.StateHolderResource;
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 AbstractCacheableResource implements StateHolder {
+public abstract class Java2Dresource extends AbstractCacheableResource implements StateHolderResource {
private static final String SKIN_MARKER = "Skin.";
private ImageType imageType;
@@ -56,91 +56,6 @@
this.imageType = imageType;
}
- public static enum ImageType {
- GIF("gif") {
- @Override
- public BufferedImage createImage(int width, int height) {
- return createARGBImage(width, height);
- }
- },
- PNG("png") {
- @Override
- public BufferedImage createImage(int width, int height) {
- return createARGBImage(width, height);
- }
- },
- PNG8("png") {
- @Override
- public BufferedImage createImage(int width, int height) {
- return new BufferedImage(width, height, BufferedImage.TYPE_BYTE_INDEXED, SAFE_WEB_COLORS_MODEL);
- }
- },
-
- // TODO - add common png8
- JPEG("jpeg") {
- @Override
- public BufferedImage createImage(int width, int height) {
- return new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
- }
- };
-
- /**
- * Default web safe colors color model
- */
- protected static final IndexColorModel SAFE_WEB_COLORS_MODEL;
-
- // Build web safe 6x6x6 cube color model.
- static {
- byte[] webLevels = {
- 0, 51, 102, (byte) 153, (byte) 204, (byte) 255
- };
- int colorsNumber = webLevels.length * webLevels.length * webLevels.length; /* 216 colors */
- byte[] r = new byte[colorsNumber];
- byte[] g = new byte[colorsNumber];
- byte[] b = new byte[colorsNumber];
-
- r[0] = 0;
- g[0] = 0;
- b[0] = 0;
-
- for (int i = 0; i < webLevels.length; i++) {
- for (int j = 0; j < webLevels.length; j++) {
- for (int k = 0; k < webLevels.length; k++) {
- int colorNum = i * webLevels.length * webLevels.length + j * webLevels.length + k;
-
- r[colorNum] = webLevels[i];
- g[colorNum] = webLevels[j];
- b[colorNum] = webLevels[k];
- }
- }
- }
-
- SAFE_WEB_COLORS_MODEL = new IndexColorModel(8, colorsNumber, r, g, b, 0);
- }
-
- private String formatName;
- private String mimeType;
-
- private ImageType(String formatName) {
- this.formatName = formatName;
- this.mimeType = "image/" + formatName;
- }
-
- private static BufferedImage createARGBImage(int width, int height) {
- return new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
- }
-
- protected abstract BufferedImage createImage(int width, int height);
-
- protected String getFormatName() {
- return formatName;
- }
-
- protected String getMimeType() {
- return mimeType;
- }
- }
-
/**
* Primary calculation of image dimensions - used when HTML code is
* generated to render IMG's width and height Subclasses should override
@@ -208,32 +123,6 @@
return imageType.getMimeType();
}
- protected void writeState(FacesContext context, NumericDataOutputStream stream) {
- }
-
- protected void readState(FacesContext context, NumericDataInputStream stream) {
- }
-
- public boolean isTransient() {
- return false;
- }
-
- public void restoreState(FacesContext context, Object state) {
- readState(context, new NumericDataInputStream((byte[]) state));
- }
-
- public Object saveState(FacesContext context) {
- NumericDataOutputStream stream = new NumericDataOutputStream();
-
- writeState(context, stream);
-
- return stream.getBytes();
- }
-
- public void setTransient(boolean newTransientValue) {
- throw new UnsupportedOperationException();
- }
-
protected String getValueParameter(FacesContext context, String name) {
SkinFactory skinFactory = SkinFactory.getInstance();
@@ -291,4 +180,12 @@
return null;
}
}
+
+ public void readState(FacesContext context, DataInput dataInput) throws IOException {}
+
+ public void writeState(FacesContext context, DataOutput dataOutput) throws IOException {}
+
+ public boolean isTransient() {
+ return false;
+ }
}
Deleted: root/core/trunk/impl/src/main/java/org/ajax4jsf/util/NumericDataInputStream.java
===================================================================
--- root/core/trunk/impl/src/main/java/org/ajax4jsf/util/NumericDataInputStream.java 2010-06-10 00:30:15 UTC (rev 17590)
+++ root/core/trunk/impl/src/main/java/org/ajax4jsf/util/NumericDataInputStream.java 2010-06-10 13:44:40 UTC (rev 17591)
@@ -1,106 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * 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 org.ajax4jsf.util;
-
-import java.awt.*;
-import java.io.ByteArrayInputStream;
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-
-/**
- * Original idea by Igor Shabalov
- *
- * @author Nick Belaevski
- * @since 4.0
- */
-public class NumericDataInputStream {
- static final int BYTES_IN_INT = Integer.SIZE >> 3;
- static final int BYTES_IN_SHORT = Short.SIZE >> 3;
- static final int BYTES_IN_COLOR = BYTES_IN_INT - 1;
-
- // the size of maximum object in bytes that this stream can operate (int)
- static final int MAX_BYTES = BYTES_IN_INT;
- static final ByteOrder BUFFER_BYTES_ORDER = ByteOrder.LITTLE_ENDIAN;
- private byte[] bytes = new byte[MAX_BYTES];
- private ByteBuffer buffer = ByteBuffer.wrap(bytes).order(BUFFER_BYTES_ORDER);
- private ByteArrayInputStream byteArrayStream;
-
- public NumericDataInputStream(byte[] buf) {
- super();
- byteArrayStream = new ByteArrayInputStream(buf);
- }
-
- public NumericDataInputStream(byte[] buf, int offset, int length) {
- super();
- byteArrayStream = new ByteArrayInputStream(buf, offset, length);
- }
-
- public byte readByte() {
- int read = byteArrayStream.read();
-
- if (read >= 0) {
- return (byte) read;
- } else {
- throw new IllegalStateException("Data is invalid or corrupted");
- }
- }
-
- public short readShort() {
- int read = byteArrayStream.read(bytes, 0, BYTES_IN_SHORT);
-
- if (read == BYTES_IN_SHORT) {
- buffer.rewind();
-
- return buffer.asShortBuffer().get();
- } else {
- throw new IllegalStateException("Data is invalid or corrupted");
- }
- }
-
- public int readInt() {
- int read = byteArrayStream.read(bytes, 0, BYTES_IN_INT);
-
- if (read == BYTES_IN_INT) {
- buffer.rewind();
-
- return buffer.asIntBuffer().get();
- } else {
- throw new IllegalStateException("Data is invalid or corrupted");
- }
- }
-
- public int readIntColor() {
- int read = byteArrayStream.read(bytes, 0, BYTES_IN_COLOR);
-
- if (read == BYTES_IN_COLOR) {
- buffer.rewind();
-
- return buffer.asIntBuffer().get() & 0x00FFFFFF;
- } else {
- throw new IllegalStateException("Data is invalid or corrupted");
- }
- }
-
- public Color readColor() {
- return new Color(readIntColor());
- }
-}
Deleted: root/core/trunk/impl/src/main/java/org/ajax4jsf/util/NumericDataOutputStream.java
===================================================================
--- root/core/trunk/impl/src/main/java/org/ajax4jsf/util/NumericDataOutputStream.java 2010-06-10 00:30:15 UTC (rev 17590)
+++ root/core/trunk/impl/src/main/java/org/ajax4jsf/util/NumericDataOutputStream.java 2010-06-10 13:44:40 UTC (rev 17591)
@@ -1,82 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * 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 org.ajax4jsf.util;
-
-import static org.ajax4jsf.util.NumericDataInputStream.*;
-
-import java.awt.*;
-import java.io.ByteArrayOutputStream;
-import java.nio.ByteBuffer;
-
-/**
- * Original idea by Igor Shabalov
- *
- * @author Nick Belaevski
- * @since 4.0
- */
-public class NumericDataOutputStream {
- private ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
- private byte[] bytes = new byte[MAX_BYTES];
- private ByteBuffer buffer = ByteBuffer.wrap(bytes).order(BUFFER_BYTES_ORDER);
-
- public NumericDataOutputStream writeByte(byte value) {
- byteStream.write(value);
-
- return this;
- }
-
- public NumericDataOutputStream writeShort(short value) {
- buffer.rewind();
- buffer.asShortBuffer().put(value);
- byteStream.write(bytes, 0, BYTES_IN_SHORT);
-
- return this;
- }
-
- private void writeInteger(int value, int numBytes) {
- buffer.rewind();
- buffer.asIntBuffer().put(value);
- byteStream.write(bytes, 0, numBytes);
- }
-
- public NumericDataOutputStream writeInt(int value) {
- writeInteger(value, BYTES_IN_INT);
-
- return this;
- }
-
- public NumericDataOutputStream writeIntColor(int value) {
- writeInteger(value, BYTES_IN_COLOR);
-
- return this;
- }
-
- public NumericDataOutputStream writeColor(Color value) {
- writeIntColor(value.getRGB());
-
- return this;
- }
-
- public byte[] getBytes() {
- return byteStream.toByteArray();
- }
-}
Modified: root/core/trunk/impl/src/main/java/org/richfaces/renderkit/html/BaseGradient.java
===================================================================
--- root/core/trunk/impl/src/main/java/org/richfaces/renderkit/html/BaseGradient.java 2010-06-10 00:30:15 UTC (rev 17590)
+++ root/core/trunk/impl/src/main/java/org/richfaces/renderkit/html/BaseGradient.java 2010-06-10 13:44:40 UTC (rev 17591)
@@ -28,15 +28,17 @@
import java.awt.Shape;
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
import javax.faces.context.FacesContext;
import org.ajax4jsf.resource.Java2Dresource;
-import org.ajax4jsf.util.NumericDataInputStream;
-import org.ajax4jsf.util.NumericDataOutputStream;
import org.richfaces.renderkit.html.images.GradientType;
import org.richfaces.renderkit.html.images.GradientType.BiColor;
import org.richfaces.resource.DynamicResource;
+import org.richfaces.resource.ImageType;
import org.richfaces.skin.Skin;
/**
@@ -254,28 +256,20 @@
}
}
- @Override
- protected void readState(FacesContext context, NumericDataInputStream stream) {
- super.readState(context, stream);
-
- this.headerBackgroundColor = stream.readInt();
- this.headerGradientColor = stream.readInt();
- this.gradientType = GradientType.values()[stream.readByte()];
+ public void readState(FacesContext context, DataInput dataInput) throws IOException {
+ super.readState(context, dataInput);
+ this.headerBackgroundColor = dataInput.readInt();
+ this.headerGradientColor = dataInput.readInt();
+ this.gradientType = GradientType.values()[dataInput.readByte()];
}
-
+
@Override
- protected void writeState(FacesContext context,
- NumericDataOutputStream stream) {
- super.writeState(context, stream);
+ public void writeState(FacesContext context, DataOutput dataOutput) throws IOException {
+ super.writeState(context, dataOutput);
- stream.writeInt(this.headerBackgroundColor);
- stream.writeInt(this.headerGradientColor);
- stream.writeByte((byte) this.gradientType.ordinal());
+ dataOutput.writeInt(this.headerBackgroundColor);
+ dataOutput.writeInt(this.headerGradientColor);
+ dataOutput.writeByte((byte) this.gradientType.ordinal());
}
- public boolean isCacheable() {
- return true;
- }
-
-
}
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-10 00:30:15 UTC (rev 17590)
+++ root/core/trunk/impl/src/main/java/org/richfaces/renderkit/html/CustomizeableGradient.java 2010-06-10 13:44:40 UTC (rev 17591)
@@ -28,15 +28,18 @@
import java.awt.RenderingHints;
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
import javax.faces.context.FacesContext;
import org.ajax4jsf.resource.Java2Dresource;
-import org.ajax4jsf.util.NumericDataInputStream;
import org.richfaces.renderkit.html.images.GradientAlignment;
import org.richfaces.renderkit.html.images.GradientType;
import org.richfaces.renderkit.html.images.GradientType.BiColor;
import org.richfaces.resource.DynamicResource;
+import org.richfaces.resource.ImageType;
import org.richfaces.skin.Skin;
/**
@@ -168,24 +171,25 @@
}
@Override
- protected void readState(FacesContext context, NumericDataInputStream stream) {
- super.readState(context, stream);
+ public void readState(FacesContext context, DataInput dataInput) throws IOException {
+ super.readState(context, dataInput);
- this.baseColor = stream.readIntColor();
- this.gradientColor = stream.readIntColor();
- this.gradientHeight = stream.readInt();
- this.gradientAlignment = GradientAlignment.values()[stream.readByte()];
- this.gradientType = GradientType.values()[stream.readByte()];
+ this.baseColor = dataInput.readInt();
+ this.gradientColor = dataInput.readInt();
+ this.gradientHeight = dataInput.readInt();
+ this.gradientAlignment = GradientAlignment.values()[dataInput.readByte()];
+ this.gradientType = GradientType.values()[dataInput.readByte()];
}
+
@Override
- protected void writeState(FacesContext context, org.ajax4jsf.util.NumericDataOutputStream stream) {
- super.writeState(context, stream);
+ public void writeState(FacesContext context, DataOutput dataOutput) throws IOException {
+ super.writeState(context, dataOutput);
- stream.writeIntColor(this.baseColor);
- stream.writeIntColor(this.gradientColor);
- stream.writeInt(this.gradientHeight);
- stream.writeByte((byte) this.gradientAlignment.ordinal());
- stream.writeByte((byte) this.gradientType.ordinal());
+ dataOutput.writeInt(this.baseColor);
+ dataOutput.writeInt(this.gradientColor);
+ dataOutput.writeInt(this.gradientHeight);
+ dataOutput.writeByte((byte) this.gradientAlignment.ordinal());
+ dataOutput.writeByte((byte) this.gradientType.ordinal());
}
protected static String safeTrim(String s) {
Modified: root/core/trunk/impl/src/main/java/org/richfaces/renderkit/html/images/BaseControlBackgroundImage.java
===================================================================
--- root/core/trunk/impl/src/main/java/org/richfaces/renderkit/html/images/BaseControlBackgroundImage.java 2010-06-10 00:30:15 UTC (rev 17590)
+++ root/core/trunk/impl/src/main/java/org/richfaces/renderkit/html/images/BaseControlBackgroundImage.java 2010-06-10 13:44:40 UTC (rev 17591)
@@ -21,10 +21,12 @@
package org.richfaces.renderkit.html.images;
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+
import javax.faces.context.FacesContext;
-import org.ajax4jsf.util.NumericDataInputStream;
-import org.ajax4jsf.util.NumericDataOutputStream;
import org.richfaces.renderkit.html.BaseGradient;
import org.richfaces.skin.Skin;
@@ -50,31 +52,21 @@
}
@Override
- protected void writeState(FacesContext context,
- NumericDataOutputStream stream) {
+ public void writeState(FacesContext context,
+ DataOutput stream) throws IOException {
super.writeState(context, stream);
stream.writeInt(this.height);
}
@Override
- protected void readState(FacesContext context, NumericDataInputStream stream) {
+ public void readState(FacesContext context, DataInput stream) throws IOException {
super.readState(context, stream);
this.height = stream.readInt();
- }
- @Override
- public void restoreState(FacesContext context, Object state) {
- super.restoreState(context, state);
-
//TODO - create a special method?
this.gradientType = GradientType.PLAIN;
}
- @Override
- public Object saveState(FacesContext context) {
- return super.saveState(context);
- }
-
}
Modified: root/core/trunk/impl/src/main/java/org/richfaces/renderkit/html/images/CancelControlIcon.java
===================================================================
--- root/core/trunk/impl/src/main/java/org/richfaces/renderkit/html/images/CancelControlIcon.java 2010-06-10 00:30:15 UTC (rev 17590)
+++ root/core/trunk/impl/src/main/java/org/richfaces/renderkit/html/images/CancelControlIcon.java 2010-06-10 13:44:40 UTC (rev 17591)
@@ -25,13 +25,16 @@
import java.awt.GradientPaint;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
import javax.faces.context.FacesContext;
import org.ajax4jsf.resource.Java2Dresource;
import org.ajax4jsf.util.HtmlColor;
-import org.ajax4jsf.util.NumericDataInputStream;
import org.richfaces.resource.DynamicResource;
+import org.richfaces.resource.ImageType;
/**
* implementation of the default CANCEL icon renderer
@@ -59,18 +62,18 @@
}
@Override
- protected void readState(FacesContext context, NumericDataInputStream stream) {
+ public void readState(FacesContext context, DataInput stream) throws IOException {
super.readState(context, stream);
- this.iconColor = stream.readIntColor();
- this.iconBorderColor = stream.readIntColor();
+ this.iconColor = stream.readInt();
+ this.iconBorderColor = stream.readInt();
}
- protected void writeState(FacesContext context, org.ajax4jsf.util.NumericDataOutputStream stream) {
+ public void writeState(FacesContext context, DataOutput stream) throws IOException {
super.writeState(context, stream);
- stream.writeIntColor(this.iconColor);
- stream.writeIntColor(this.iconBorderColor);
+ stream.writeInt(this.iconColor);
+ stream.writeInt(this.iconBorderColor);
}
@Override
Modified: root/core/trunk/impl/src/main/java/org/richfaces/renderkit/html/images/OneColorBasedResource.java
===================================================================
--- root/core/trunk/impl/src/main/java/org/richfaces/renderkit/html/images/OneColorBasedResource.java 2010-06-10 00:30:15 UTC (rev 17590)
+++ root/core/trunk/impl/src/main/java/org/richfaces/renderkit/html/images/OneColorBasedResource.java 2010-06-10 13:44:40 UTC (rev 17591)
@@ -27,6 +27,7 @@
import org.ajax4jsf.resource.Java2Dresource;
import org.ajax4jsf.resource.ResourceContext;
import org.richfaces.resource.DynamicResource;
+import org.richfaces.resource.ImageType;
@DynamicResource
public abstract class OneColorBasedResource extends Java2Dresource {
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-10 00:30:15 UTC (rev 17590)
+++ root/core/trunk/impl/src/main/java/org/richfaces/resource/AbstractBaseResource.java 2010-06-10 13:44:40 UTC (rev 17591)
@@ -21,9 +21,8 @@
package org.richfaces.resource;
-import static org.richfaces.resource.ResourceUtils.millisToSecond;
-import static org.richfaces.resource.ResourceUtils.secondToMillis;
-
+import java.io.ByteArrayOutputStream;
+import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
@@ -38,10 +37,8 @@
import javax.faces.FacesException;
import javax.faces.application.Resource;
-import javax.faces.component.StateHolder;
import javax.faces.context.FacesContext;
-import org.ajax4jsf.resource.InternetResource;
import org.richfaces.application.ServiceTracker;
import org.richfaces.log.RichfacesLogger;
import org.richfaces.util.Util;
@@ -67,19 +64,6 @@
}
/**
- * <b>IMPORTANT:</b> this method returned TTL in RF 3.x, now it returns expiration time
- *
- * @return Returns the expired.
- */
- protected Date getExpires(FacesContext context) {
- return null;
- }
-
- protected int getTimeToLive(FacesContext context) {
- return 0;
- }
-
- /**
* TODO optimize/review?
*
* @return Returns the lastModified.
@@ -158,17 +142,7 @@
return classLoader;
}
- protected String getEntityTag(FacesContext context) {
- int contentLength = getContentLength(context);
- Date lastModified = getLastModified(context);
-
- if ((contentLength < 0) || (lastModified == null)) {
- return null;
- }
-
- return ResourceUtils.formatWeakTag(contentLength + "-" + lastModified.getTime());
- }
-
+ //TODO nick - review
private String getResourceVersion() {
if (this instanceof VersionedResource) {
return ((VersionedResource) this).getVersion();
@@ -186,11 +160,26 @@
String resourceName = getResourceName();
Object resourceData = null;
- if (this instanceof StateHolder) {
- StateHolder stateHolder = (StateHolder) this;
+ if (this instanceof StateHolderResource) {
+ StateHolderResource stateHolder = (StateHolderResource) this;
if (!stateHolder.isTransient()) {
- resourceData = stateHolder.saveState(context);
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ DataOutputStream oos = null;
+ try {
+ oos = new DataOutputStream(baos);
+ stateHolder.writeState(context, oos);
+ } catch (IOException e) {
+ throw new FacesException(e.getMessage(), e);
+ } finally {
+ try {
+ oos.close();
+ } catch (IOException e) {
+ LOGGER.debug(e.getMessage(), e);
+ }
+ }
+
+ resourceData = baos.toByteArray();
}
}
@@ -216,15 +205,16 @@
long getCurrentTime() {
return System.currentTimeMillis();
}
-
- private boolean canBeCached(FacesContext context) {
- if (this instanceof CacheableResource) {
- return ((CacheableResource) this).isCacheable(context);
- }
-
- return false;
+
+ protected void addNoCacheResponseHeaders(FacesContext facesContext, Map<String, String> headers) {
+ headers.put("Expires", "0");
+ headers.put("Cache-Control", "max-age=0, no-store, no-cache");
+ headers.put("Pragma", "no-cache");
}
+ protected void addCacheControlResponseHeaders(FacesContext facesContext, Map<String, String> headers) {
+ addNoCacheResponseHeaders(facesContext, headers);
+ }
@Override
public Map<String, String> getResponseHeaders() {
@@ -252,46 +242,10 @@
headers.put("Last-Modified", Util.formatHttpDate(lastModified));
}
- if (canBeCached(facesContext)) {
- long currentTime = getCurrentTime();
- String formattedExpireDate;
- long maxAge = getTimeToLive(facesContext);
-
- if (maxAge > 0) {
- formattedExpireDate = Util.formatHttpDate(currentTime + secondToMillis(maxAge));
- } else {
- Date expired = getExpires(facesContext);
-
- if (expired != null) {
- formattedExpireDate = Util.formatHttpDate(expired);
- maxAge = millisToSecond(expired.getTime() - currentTime);
- } else {
- maxAge = InternetResource.DEFAULT_TTL;
- formattedExpireDate = Util.formatHttpDate(currentTime + secondToMillis(maxAge));
- }
- }
-
- if (formattedExpireDate != null) {
- headers.put("Expires", formattedExpireDate);
- }
-
- if (maxAge > 0) {
- headers.put("Cache-Control", "max-age=" + maxAge);
- }
-
- String entityTag = getEntityTag(facesContext);
-
- if (entityTag != null) {
- headers.put("ETag", entityTag);
- }
- } else {
- headers.put("Expires", "0");
- headers.put("Cache-Control", "max-age=0, no-store, no-cache");
- headers.put("Pragma", "no-cache");
- }
-
headers.put("Date", Util.formatHttpDate(getCurrentTime()));
+ addCacheControlResponseHeaders(facesContext, headers);
+
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Created set of response headers");
@@ -342,20 +296,7 @@
@Override
public long getExpiration() {
- FacesContext facesContext = FacesContext.getCurrentInstance();
- long ttl = AbstractBaseResource.this.getTimeToLive(facesContext);
-
- if (ttl > 0) {
- return System.currentTimeMillis() + secondToMillis(ttl);
- }
-
- Date date = AbstractBaseResource.this.getExpires(facesContext);
-
- if (date != null) {
- return date.getTime();
- }
-
- return System.currentTimeMillis() + secondToMillis(InternetResource.DEFAULT_TTL);
+ return 0;
}
@Override
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-10 00:30:15 UTC (rev 17590)
+++ root/core/trunk/impl/src/main/java/org/richfaces/resource/AbstractCacheableResource.java 2010-06-10 13:44:40 UTC (rev 17591)
@@ -21,12 +21,16 @@
package org.richfaces.resource;
+import static org.richfaces.resource.ResourceUtils.millisToSecond;
+import static org.richfaces.resource.ResourceUtils.secondToMillis;
+
import java.util.Date;
import java.util.Map;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
+import org.ajax4jsf.context.ContextInitParameters;
import org.richfaces.log.RichfacesLogger;
import org.richfaces.util.Util;
import org.slf4j.Logger;
@@ -143,4 +147,67 @@
return false;
}
+
+ /**
+ * <b>IMPORTANT:</b> this method returned TTL in RF 3.x, now it returns expiration time
+ *
+ * @return Returns the expired.
+ */
+ public Date getExpires(FacesContext context) {
+ return null;
+ }
+
+ public int getTimeToLive(FacesContext context) {
+ return 0;
+ }
+
+ public String getEntityTag(FacesContext context) {
+ int contentLength = getContentLength(context);
+ Date lastModified = getLastModified(context);
+
+ if ((contentLength < 0) || (lastModified == null)) {
+ return null;
+ }
+
+ return ResourceUtils.formatWeakTag(contentLength + "-" + lastModified.getTime());
+ }
+
+ @Override
+ protected void addCacheControlResponseHeaders(FacesContext facesContext, Map<String, String> headers) {
+ if (isCacheable(facesContext)) {
+ long currentTime = getCurrentTime();
+ String formattedExpireDate;
+ long maxAge = getTimeToLive(facesContext);
+
+ if (maxAge > 0) {
+ formattedExpireDate = Util.formatHttpDate(currentTime + secondToMillis(maxAge));
+ } else {
+ Date expired = getExpires(facesContext);
+
+ if (expired != null) {
+ formattedExpireDate = Util.formatHttpDate(expired);
+ maxAge = millisToSecond(expired.getTime() - currentTime);
+ } else {
+ maxAge = ContextInitParameters.getResourcesTimeToLive(facesContext);
+ formattedExpireDate = Util.formatHttpDate(currentTime + secondToMillis(maxAge));
+ }
+ }
+
+ if (formattedExpireDate != null) {
+ headers.put("Expires", formattedExpireDate);
+ }
+
+ if (maxAge > 0) {
+ headers.put("Cache-Control", "max-age=" + maxAge);
+ }
+
+ String entityTag = getEntityTag(facesContext);
+
+ if (entityTag != null) {
+ headers.put("ETag", entityTag);
+ }
+ } else {
+ addNoCacheResponseHeaders(facesContext, headers);
+ }
+ }
}
Modified: root/core/trunk/impl/src/main/java/org/richfaces/resource/CachedResourceImpl.java
===================================================================
--- root/core/trunk/impl/src/main/java/org/richfaces/resource/CachedResourceImpl.java 2010-06-10 00:30:15 UTC (rev 17590)
+++ root/core/trunk/impl/src/main/java/org/richfaces/resource/CachedResourceImpl.java 2010-06-10 13:44:40 UTC (rev 17591)
@@ -204,7 +204,7 @@
}
@Override
- protected String getEntityTag(FacesContext context) {
+ public String getEntityTag(FacesContext context) {
return entityTag;
}
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-10 00:30:15 UTC (rev 17590)
+++ root/core/trunk/impl/src/main/java/org/richfaces/resource/CompiledCSSResource.java 2010-06-10 13:44:40 UTC (rev 17591)
@@ -22,15 +22,15 @@
package org.richfaces.resource;
import java.io.ByteArrayInputStream;
+import java.io.DataInput;
+import java.io.DataOutput;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
-import java.nio.ByteBuffer;
import java.text.MessageFormat;
import javax.faces.application.ProjectStage;
import javax.faces.application.Resource;
-import javax.faces.component.StateHolder;
import javax.faces.context.FacesContext;
import org.richfaces.log.RichfacesLogger;
@@ -49,7 +49,7 @@
/**
* @author amarkhel Class, that represented dynamic CSS resource.
*/
-public class CompiledCSSResource extends AbstractCacheableResource implements StateHolder {
+public class CompiledCSSResource extends AbstractCacheableResource implements StateHolderResource {
private static final String ECSS = ".ecss";
@@ -236,17 +236,11 @@
return false;
}
- public void restoreState(FacesContext context, Object state) {
+ public void readState(FacesContext context, DataInput dataInput) throws IOException {
//do nothing
}
- public Object saveState(FacesContext context) {
- ByteBuffer buffer = ByteBuffer.allocate(4);
- buffer.putInt(getSkinHashCode(context));
- return buffer.array();
+ public void writeState(FacesContext context, DataOutput dataOutput) throws IOException {
+ dataOutput.writeInt(getSkinHashCode(context));
}
-
- public void setTransient(boolean newTransientValue) {
- //do nothing
- }
}
\ No newline at end of file
Added: root/core/trunk/impl/src/main/java/org/richfaces/resource/Java2DUserResourceAdaptor.java
===================================================================
--- root/core/trunk/impl/src/main/java/org/richfaces/resource/Java2DUserResourceAdaptor.java (rev 0)
+++ root/core/trunk/impl/src/main/java/org/richfaces/resource/Java2DUserResourceAdaptor.java 2010-06-10 13:44:40 UTC (rev 17591)
@@ -0,0 +1,163 @@
+/*
+ * 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.awt.Dimension;
+import java.awt.Graphics2D;
+import java.awt.RenderingHints;
+import java.awt.image.BufferedImage;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Date;
+import java.util.Map;
+
+import javax.faces.context.FacesContext;
+import javax.imageio.ImageIO;
+
+import org.ajax4jsf.util.HtmlColor;
+import org.ajax4jsf.util.HtmlDimensions;
+import org.richfaces.skin.Skin;
+import org.richfaces.skin.SkinFactory;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class Java2DUserResourceAdaptor implements UserResource {
+
+ private Java2DUserResource j2DUserResource;
+
+ public Java2DUserResourceAdaptor(Java2DUserResource userResource) {
+ this.j2DUserResource = userResource;
+ }
+
+ public InputStream getInputStream() throws IOException {
+ Dimension dimension = j2DUserResource.getDimension();
+ int width = dimension.width;
+ int height = dimension.height;
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+ ImageType imageType = j2DUserResource.getImageType();
+
+ if ((width > 0) && (height > 0)) {
+ BufferedImage image = imageType.createImage(width, height);
+ Graphics2D g2d = image.createGraphics();
+
+ try {
+ g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+ g2d.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE);
+
+ g2d.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION,
+ RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
+ g2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
+ g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
+
+ j2DUserResource.paint(g2d, dimension);
+ } finally {
+ g2d.dispose();
+ }
+
+ try {
+ ImageIO.write(image, imageType.getFormatName(), baos);
+ } finally {
+ try {
+ baos.close();
+ } catch (IOException e) {
+
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+
+ return new ByteArrayInputStream(baos.toByteArray());
+ }
+
+ public String getContentType() {
+ return j2DUserResource.getImageType().getMimeType();
+ }
+
+ protected String getValueParameter(FacesContext context, String name) {
+ SkinFactory skinFactory = SkinFactory.getInstance();
+
+ Skin skin = skinFactory.getSkin(context);
+ String value = (String) skin.getParameter(context, name);
+
+ if (value == null || value.length() == 0) {
+ skin = skinFactory.getDefaultSkin(context);
+ value = (String) skin.getParameter(context, name);
+ }
+
+ return value;
+ }
+
+ protected Integer getColorValueParameter(FacesContext context, String name, boolean useDefault) {
+ Skin skin;
+ if (useDefault) {
+ skin = SkinFactory.getInstance().getDefaultSkin(context);
+ } else {
+ skin = SkinFactory.getInstance().getSkin(context);
+ }
+
+ return decodeColor((String) skin.getParameter(context, name));
+ }
+
+ protected Integer getHeight(FacesContext context, String heightParamName) {
+ SkinFactory skinFactory = SkinFactory.getInstance();
+ Skin skin = skinFactory.getSkin(context);
+
+ String height = (String) skin.getParameter(context, heightParamName);
+ if (height == null || height.length() == 0) {
+ skin = skinFactory.getDefaultSkin(context);
+ height = (String) skin.getParameter(context, heightParamName);
+ }
+
+ if (height != null && height.length() != 0) {
+ return Integer.valueOf(HtmlDimensions.decode(height).intValue());
+ } else {
+ return Integer.valueOf(16);
+ }
+ }
+
+ protected Integer decodeColor(String value) {
+ if (value != null && value.length() != 0) {
+ return Integer.valueOf(HtmlColor.decode(value).getRGB());
+ } else {
+ return null;
+ }
+ }
+
+ public int getContentLength() {
+ return -1;
+ }
+
+ public Date getLastModified() {
+ return j2DUserResource.getLastModified();
+ }
+
+ public Map<String, String> getResponseHeaders() {
+ return j2DUserResource.getResponseHeaders();
+ }
+
+}
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-10 00:30:15 UTC (rev 17590)
+++ root/core/trunk/impl/src/main/java/org/richfaces/resource/ResourceHandlerImpl.java 2010-06-10 13:44:40 UTC (rev 17591)
@@ -21,6 +21,8 @@
package org.richfaces.resource;
+import java.io.ByteArrayInputStream;
+import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -34,7 +36,7 @@
import javax.faces.application.ProjectStage;
import javax.faces.application.Resource;
import javax.faces.application.ResourceHandler;
-import javax.faces.component.StateHolder;
+import javax.faces.application.ResourceHandlerWrapper;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.imageio.ImageIO;
@@ -54,7 +56,7 @@
* @author Nick Belaevski
* @since 4.0
*/
-public class ResourceHandlerImpl extends ResourceHandler {
+public class ResourceHandlerImpl extends ResourceHandlerWrapper {
public static final String RICHFACES_RESOURCE_IDENTIFIER = "/rfRes/";
public static final String RESOURCE_CACHE_NAME = ResourceHandlerImpl.class.getName() + ":CACHE";
public static final String HANDLER_START_TIME_ATTRIBUTE = ResourceHandlerImpl.class.getName() + ":StartTime";
@@ -217,7 +219,7 @@
}
if (resource == null) {
- resource = createHandlerDependentResource(resourceName);
+ resource = createHandlerDependentResource(resourceName, null);
}
if (resource == null) {
@@ -249,8 +251,8 @@
}
}
- if (resource instanceof StateHolder) {
- StateHolder stateHolder = (StateHolder) resource;
+ if (resource instanceof StateHolderResource) {
+ StateHolderResource stateHolder = (StateHolderResource) resource;
Object decodedData = resourceCodec.decodeResourceData(context, resourcePath);
if (LOGGER.isDebugEnabled()) {
@@ -262,7 +264,19 @@
}
if (decodedData != null) {
- stateHolder.restoreState(context, decodedData);
+ DataInputStream dis = null;
+ try {
+ dis = new DataInputStream(new ByteArrayInputStream((byte[]) decodedData));
+ stateHolder.readState(context, dis);
+ } finally {
+ if (dis != null) {
+ try {
+ dis.close();
+ } catch (IOException e) {
+ LOGGER.debug(e.getMessage(), e);
+ }
+ }
+ }
} else {
// resource was transient and didn't store data
@@ -375,7 +389,7 @@
}
}
- protected void injectProperties(Resource resource, Map<String, String> parameters) {
+ protected void injectProperties(Object resource, Map<String, String> parameters) {
FacesContext facesContext = FacesContext.getCurrentInstance();
DependencyInjectionService diService = ServiceTracker.getService(facesContext, DependencyInjectionService.class);
@@ -394,7 +408,7 @@
* @param resourceName
* @return
*/
- protected Resource createHandlerDependentResource(String resourceName) {
+ protected Resource createHandlerDependentResource(String resourceName, Map<String, String> parameters) {
Resource resource = null;
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
@@ -402,11 +416,9 @@
try {
Class<?> loadedClass = Class.forName(resourceName, false, contextClassLoader);
- Class<? extends Resource> resourceClass = loadedClass.asSubclass(Resource.class);
-
boolean legitimateResource = false;
- DynamicResource annotation = resourceClass.getAnnotation(DynamicResource.class);
+ DynamicResource annotation = loadedClass.getAnnotation(DynamicResource.class);
legitimateResource = (annotation != null);
if (legitimateResource) {
LOGGER.debug(
@@ -434,7 +446,25 @@
}
if (legitimateResource) {
- resource = (Resource) resourceClass.newInstance();
+ Object wrappedResource;
+ if (Java2DUserResource.class.isAssignableFrom(loadedClass)) {
+ Java2DUserResource java2DUserResource = (Java2DUserResource) loadedClass.newInstance();
+ wrappedResource = java2DUserResource;
+ resource = new UserResourceAdaptor(new Java2DUserResourceAdaptor(java2DUserResource), java2DUserResource);
+ } else if (UserResource.class.isAssignableFrom(loadedClass)) {
+ UserResource userResource = (UserResource) loadedClass.newInstance();
+ wrappedResource = userResource;
+ resource = new UserResourceAdaptor(userResource, userResource);
+ } else {
+ Class<? extends Resource> resourceClass = loadedClass.asSubclass(Resource.class);
+ resource = (Resource) resourceClass.newInstance();
+ wrappedResource = resource;
+ }
+
+ if (parameters != null) {
+ injectProperties(wrappedResource, parameters);
+ }
+
resource.setResourceName(resourceName);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(MessageFormat.format("Successfully created instance of {0} resource",
@@ -462,7 +492,7 @@
result = new CompiledCSSResource(resourceName);
} else {
if ((resourceName != null) && ((libraryName == null) || (libraryName.length() == 0))) {
- result = createHandlerDependentResource(resourceName);
+ result = createHandlerDependentResource(resourceName, params);
}
if (result == null) {
@@ -470,10 +500,6 @@
}
}
- if (result != null) {
- injectProperties(result, params);
- }
-
return result;
}
@@ -508,4 +534,9 @@
public boolean libraryExists(String libraryName) {
return defaultHandler.libraryExists(libraryName);
}
+
+ @Override
+ public ResourceHandler getWrapped() {
+ return defaultHandler;
+ }
}
\ No newline at end of file
Modified: root/core/trunk/impl/src/main/java/org/richfaces/resource/ResourceParameterELResolver.java
===================================================================
--- root/core/trunk/impl/src/main/java/org/richfaces/resource/ResourceParameterELResolver.java 2010-06-10 00:30:15 UTC (rev 17590)
+++ root/core/trunk/impl/src/main/java/org/richfaces/resource/ResourceParameterELResolver.java 2010-06-10 13:44:40 UTC (rev 17591)
@@ -69,7 +69,9 @@
@Override
public void setValue(ELContext context, Object base, Object property, Object value) {
- throw new UnsupportedOperationException();
+ if (CONTEXT_ATTRIBUTE_NAME.equals(property) && base == null) {
+ 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-10 00:30:15 UTC (rev 17590)
+++ root/core/trunk/impl/src/main/java/org/richfaces/resource/TestResource2.java 2010-06-10 13:44:40 UTC (rev 17591)
@@ -25,13 +25,14 @@
import java.awt.Dimension;
import java.awt.GradientPaint;
import java.awt.Graphics2D;
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
import javax.faces.context.FacesContext;
import org.ajax4jsf.resource.Java2Dresource;
import org.ajax4jsf.util.HtmlColor;
-import org.ajax4jsf.util.NumericDataInputStream;
-import org.ajax4jsf.util.NumericDataOutputStream;
import org.richfaces.VersionBean;
import org.richfaces.skin.Skin;
import org.richfaces.skin.SkinFactory;
@@ -62,16 +63,15 @@
}
@Override
- protected void readState(FacesContext context, NumericDataInputStream stream) {
+ public void readState(FacesContext context, DataInput stream) throws IOException {
super.readState(context, stream);
- this.color = stream.readColor();
+ this.color = new Color(stream.readInt());
}
@Override
- protected void writeState(FacesContext context,
- NumericDataOutputStream stream) {
+ public void writeState(FacesContext context, DataOutput stream) throws IOException {
super.writeState(context, stream);
- stream.writeColor(this.color);
+ stream.writeInt(this.color.getRGB());
}
@Override
Added: root/core/trunk/impl/src/main/java/org/richfaces/resource/UserResourceAdaptor.java
===================================================================
--- root/core/trunk/impl/src/main/java/org/richfaces/resource/UserResourceAdaptor.java (rev 0)
+++ root/core/trunk/impl/src/main/java/org/richfaces/resource/UserResourceAdaptor.java 2010-06-10 13:44:40 UTC (rev 17591)
@@ -0,0 +1,145 @@
+/*
+ * 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.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Date;
+import java.util.Map;
+
+import javax.faces.context.FacesContext;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class UserResourceAdaptor extends AbstractCacheableResource implements VersionedResource, StateHolderResource {
+
+ private UserResource userResource;
+
+ private Object wrappedResource;
+
+ public UserResourceAdaptor(UserResource userResource, Object wrappedResource) {
+ super();
+ this.userResource = userResource;
+ this.wrappedResource = wrappedResource;
+ }
+
+ @Override
+ public InputStream getInputStream() throws IOException {
+ return userResource.getInputStream();
+ }
+
+ @Override
+ public Map<String, String> getResponseHeaders() {
+ Map<String, String> headers = super.getResponseHeaders();
+
+ Map<String, String> userHeaders = userResource.getResponseHeaders();
+ if (userHeaders != null) {
+ headers.putAll(userHeaders);
+ }
+
+ return headers;
+ }
+
+ @Override
+ public String getContentType() {
+ return userResource.getContentType();
+ }
+
+ @Override
+ protected int getContentLength(FacesContext context) {
+ return userResource.getContentLength();
+ }
+
+ @Override
+ protected Date getLastModified(FacesContext context) {
+ return userResource.getLastModified();
+ }
+
+ public String getVersion() {
+ if (wrappedResource instanceof VersionedResource) {
+ return ((VersionedResource) wrappedResource).getVersion();
+ }
+
+ return null;
+ }
+
+ @Override
+ public boolean isCacheable(FacesContext context) {
+ if (wrappedResource instanceof CacheableResource) {
+ return ((CacheableResource) wrappedResource).isCacheable(context);
+ }
+
+ return false;
+ }
+
+ @Override
+ public Date getExpires(FacesContext context) {
+ if (wrappedResource instanceof CacheableResource) {
+ return ((CacheableResource) wrappedResource).getExpires(context);
+ }
+
+ return null;
+ }
+
+ @Override
+ public String getEntityTag(FacesContext context) {
+ if (wrappedResource instanceof CacheableResource) {
+ return ((CacheableResource) wrappedResource).getEntityTag(context);
+ }
+
+ return null;
+ }
+
+ @Override
+ public int getTimeToLive(FacesContext context) {
+ if (wrappedResource instanceof CacheableResource) {
+ return ((CacheableResource) wrappedResource).getTimeToLive(context);
+ }
+
+ return 0;
+ }
+
+ public boolean isTransient() {
+ if (wrappedResource instanceof StateHolderResource) {
+ return ((StateHolderResource) wrappedResource).isTransient();
+ }
+
+ return true;
+ }
+
+ public void writeState(FacesContext context, DataOutput dataOutput) throws IOException {
+ if (wrappedResource instanceof StateHolderResource) {
+ ((StateHolderResource) wrappedResource).writeState(context, dataOutput);
+ }
+ }
+
+ public void readState(FacesContext context, DataInput dataInput) throws IOException {
+ if (wrappedResource instanceof StateHolderResource) {
+ ((StateHolderResource) wrappedResource).readState(context, dataInput);
+ }
+ }
+
+}
Deleted: root/core/trunk/impl/src/test/java/org/ajax4jsf/util/NumericStreamsTest.java
===================================================================
--- root/core/trunk/impl/src/test/java/org/ajax4jsf/util/NumericStreamsTest.java 2010-06-10 00:30:15 UTC (rev 17590)
+++ root/core/trunk/impl/src/test/java/org/ajax4jsf/util/NumericStreamsTest.java 2010-06-10 13:44:40 UTC (rev 17591)
@@ -1,74 +0,0 @@
-/**
- * License Agreement.
- *
- * JBoss RichFaces - Ajax4jsf Component Library
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * 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 org.ajax4jsf.util;
-
-import java.awt.Color;
-
-import junit.framework.TestCase;
-
-/**
- * @author Nick Belaevski
- * @since 4.0
- */
-public class NumericStreamsTest extends TestCase {
- public void testByte() throws Exception {
- byte[] bytes = new NumericDataOutputStream().writeByte((byte) 0xDF).writeByte((byte) 0x90).writeByte(
- (byte) 0xAA).getBytes();
- NumericDataInputStream inputStream = new NumericDataInputStream(bytes);
-
- assertEquals((byte) 0xDF, inputStream.readByte());
- assertEquals((byte) 0x90, inputStream.readByte());
- assertEquals((byte) 0xAA, inputStream.readByte());
- }
-
- public void testShort() throws Exception {
- byte[] bytes = new NumericDataOutputStream().writeShort((short) 0xA7DF).writeShort((short) 0xFE90).writeShort(
- (short) 0x34AA).getBytes();
- NumericDataInputStream inputStream = new NumericDataInputStream(bytes);
-
- assertEquals((short) 0xA7DF, inputStream.readShort());
- assertEquals((short) 0xFE90, inputStream.readShort());
- assertEquals((short) 0x34AA, inputStream.readShort());
- }
-
- public void testColor() throws Exception {
- byte[] bytes = new NumericDataOutputStream().writeColor(new Color(0xA7DFE0)).writeIntColor(0xE2349A).writeColor(
- new Color(0x4812F9)).getBytes();
- NumericDataInputStream inputStream = new NumericDataInputStream(bytes);
-
- assertEquals(0xA7DFE0, inputStream.readIntColor());
- assertEquals(new Color(0xE2349A), inputStream.readColor());
- assertEquals(0x4812F9, inputStream.readIntColor());
- }
-
- public void testInt() throws Exception {
- byte[] bytes =
- new NumericDataOutputStream().writeInt(0x12A7DFE0).writeInt(0x67E2349A).writeInt(0xBD4812F9).getBytes();
- NumericDataInputStream inputStream = new NumericDataInputStream(bytes);
-
- assertEquals(0x12A7DFE0, inputStream.readInt());
- assertEquals(0x67E2349A, inputStream.readInt());
- assertEquals(0xBD4812F9, inputStream.readInt());
- }
-}
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-10 00:30:15 UTC (rev 17590)
+++ root/core/trunk/impl/src/test/java/org/richfaces/resource/AbstractBaseResourceTest.java 2010-06-10 13:44:40 UTC (rev 17591)
@@ -24,6 +24,8 @@
package org.richfaces.resource;
import java.io.ByteArrayInputStream;
+import java.io.DataInput;
+import java.io.DataOutput;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
@@ -34,7 +36,6 @@
import java.util.Map;
import java.util.TimeZone;
-import javax.faces.component.StateHolder;
import javax.faces.context.FacesContext;
import org.easymock.EasyMock;
@@ -125,12 +126,12 @@
}
public void testGetRequestPath() throws Exception {
- Object resourceState = new Object();
+ String resourceState = "data";
ResourceCodec resourceCodec = EasyMock.createMock(ResourceCodec.class);
EasyMock.expect(resourceCodec.encodeResource(EasyMock.same(facesContext),
EasyMock.eq("org.richfaces.resource.MockStateAwareResource"),
- EasyMock.same(resourceState), EasyMock.eq("4_0_alpha"))).andReturn("/rfRes/Resource0/4_0_alpha/data");
+ EasyMock.aryEq(resourceState.getBytes()), 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("/rfRes/Resource1/4_0_alpha");
@@ -143,7 +144,7 @@
MockStateAwareResourceImpl stateAwareResourceImpl = new MockStateAwareResourceImpl();
stateAwareResourceImpl.setVersion("4_0_alpha");
- stateAwareResourceImpl.restoreState(facesContext, resourceState);
+ stateAwareResourceImpl.setState(resourceState);
assertEquals("org.richfaces.resource.MockStateAwareResource", stateAwareResourceImpl.getResourceName());
assertEquals("/rfRes/Resource0/4_0_alpha/data.jsf", stateAwareResourceImpl.getRequestPath());
stateAwareResourceImpl.setTransient(true);
@@ -191,7 +192,6 @@
assertEquals(130, urlConnection.getContentLength());
assertEquals("image/gif", urlConnection.getContentType());
assertEquals(lastModified.getTime(), urlConnection.getLastModified());
- assertEquals(expired.getTime(), urlConnection.getExpiration());
assertSame(stream, urlConnection.getInputStream());
assertSame(url, urlConnection.getURL());
@@ -202,7 +202,6 @@
assertEquals(-1, urlConnection2.getContentLength());
assertNull(urlConnection2.getContentType());
assertEquals(0, urlConnection2.getLastModified());
- assertTrue(urlConnection2.getExpiration() > 0);
}
public void testDefaults() throws Exception {
@@ -299,7 +298,7 @@
}
@Override
- protected Date getExpires(FacesContext context) {
+ public Date getExpires(FacesContext context) {
return expired;
}
@@ -308,7 +307,7 @@
}
@Override
- protected String getEntityTag(FacesContext context) {
+ public String getEntityTag(FacesContext context) {
return entityTag;
}
@@ -334,7 +333,7 @@
}
@Override
- protected int getTimeToLive(FacesContext context) {
+ public int getTimeToLive(FacesContext context) {
return ttl;
}
@@ -344,30 +343,37 @@
}
- private class MockStateAwareResourceImpl extends MockResourceImpl implements StateHolder {
- private boolean _transient = false;
- private Object resourceState;
+ private class MockStateAwareResourceImpl extends MockResourceImpl implements StateHolderResource {
+ private boolean _transient;
+
+ private String resourceState;
+
public MockStateAwareResourceImpl() {
super();
setResourceName("org.richfaces.resource.MockStateAwareResource");
}
+ public void setState(String resourceState) {
+ this.resourceState = resourceState;
+ }
+
+ public void setTransient(boolean transient1) {
+ _transient = transient1;
+ }
+
public boolean isTransient() {
return _transient;
}
- public void setTransient(boolean newTransientValue) {
- this._transient = newTransientValue;
+ public void readState(FacesContext context, DataInput dataInput) throws IOException {
+ resourceState = dataInput.readLine();
}
- public Object saveState(FacesContext context) {
- return resourceState;
+ public void writeState(FacesContext context, DataOutput objectOutput) throws IOException {
+ objectOutput.writeBytes(resourceState);
}
- public void restoreState(FacesContext context, Object state) {
- this.resourceState = state;
- }
}
Modified: root/core/trunk/impl/src/test/java/org/richfaces/resource/AbstractCacheableResourceTest.java
===================================================================
--- root/core/trunk/impl/src/test/java/org/richfaces/resource/AbstractCacheableResourceTest.java 2010-06-10 00:30:15 UTC (rev 17590)
+++ root/core/trunk/impl/src/test/java/org/richfaces/resource/AbstractCacheableResourceTest.java 2010-06-10 13:44:40 UTC (rev 17591)
@@ -276,7 +276,7 @@
}
@Override
- protected String getEntityTag(FacesContext context) {
+ public String getEntityTag(FacesContext context) {
return entityTag;
}
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-10 00:30:15 UTC (rev 17590)
+++ root/core/trunk/impl/src/test/java/org/richfaces/resource/CacheableResourceImpl.java 2010-06-10 13:44:40 UTC (rev 17591)
@@ -83,7 +83,7 @@
}
@Override
- protected Date getExpires(FacesContext context) {
+ public Date getExpires(FacesContext context) {
return ResourceHandlerImplTest.expires;
}
}
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-10 00:30:15 UTC (rev 17590)
+++ root/core/trunk/impl/src/test/java/org/richfaces/resource/ResourceHandlerImplTest.java 2010-06-10 13:44:40 UTC (rev 17591)
@@ -224,16 +224,16 @@
EasyMock.expect(mockedCodec.decodeResourceName(EasyMock.<FacesContext>notNull(),
EasyMock.eq("StateHolderResource"))).andReturn("org.richfaces.resource.StateHolderResourceImpl");
EasyMock.expect(mockedCodec.decodeResourceData(EasyMock.<FacesContext>notNull(),
- EasyMock.eq("StateHolderResource"))).andReturn("test text");
+ EasyMock.eq("StateHolderResource"))).andReturn("test text".getBytes());
EasyMock.expect(mockedCodec.decodeResourceVersion(EasyMock.<FacesContext>notNull(),
EasyMock.eq("StateHolderResource"))).andReturn(null);
EasyMock.expect(mockedCodec.getResourceKey(EasyMock.<FacesContext>notNull(),
- EasyMock.eq("StateHolderResource"))).andReturn("StateHolderResource.jsf?do=1");
+ EasyMock.eq("StateHolderResource"))).andReturn("StateHolderResource.jsf?db=1");
EasyMock.replay(mockedCodec);
ServiceTracker.setService(facesContext, ResourceCodec.class, mockedCodec);
WebRequestSettings settings =
- new WebRequestSettings(new URL("http://localhost/rfRes/StateHolderResource.jsf?do=1"));
+ new WebRequestSettings(new URL("http://localhost/rfRes/StateHolderResource.jsf?db=1"));
WebResponse resourceResponse = webClient.loadWebResponse(settings);
assertEquals(HttpServletResponse.SC_OK, resourceResponse.getStatusCode());
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-10 00:30:15 UTC (rev 17590)
+++ root/core/trunk/impl/src/test/java/org/richfaces/resource/StateHolderResourceImpl.java 2010-06-10 13:44:40 UTC (rev 17591)
@@ -24,12 +24,13 @@
package org.richfaces.resource;
import java.io.ByteArrayInputStream;
+import java.io.DataInput;
+import java.io.DataOutput;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import javax.faces.FacesException;
-import javax.faces.component.StateHolder;
import javax.faces.context.FacesContext;
/**
@@ -37,7 +38,7 @@
* @since 4.0
*/
@DynamicResource
-public class StateHolderResourceImpl extends AbstractCacheableResource implements StateHolder {
+public class StateHolderResourceImpl extends AbstractCacheableResource implements StateHolderResource {
private Object state = "";
@Override
@@ -64,4 +65,12 @@
public void setTransient(boolean newTransientValue) {
throw new UnsupportedOperationException();
}
+
+ public void readState(FacesContext context, DataInput dataInput) throws IOException {
+ state = dataInput.readLine();
+ }
+
+ public void writeState(FacesContext context, DataOutput dataOutput) throws IOException {
+ dataOutput.writeBytes(state.toString());
+ }
}
Modified: root/core/trunk/impl/src/test/resources/resources/full.css
===================================================================
--- root/core/trunk/impl/src/test/resources/resources/full.css 2010-06-10 00:30:15 UTC (rev 17590)
+++ root/core/trunk/impl/src/test/resources/resources/full.css 2010-06-10 13:44:40 UTC (rev 17591)
@@ -22,5 +22,5 @@
padding: 10px !important;
border: 1px solid green;
background-image: url(image.png);
- background: red url(/rfRes/org.richfaces.renderkit.html.images.ButtonBackgroundImage.jsf?db=eAF79urt!-Pnr!xn4mZgYAAAREsHMw__);
+ background: red url(/rfRes/org.richfaces.renderkit.html.images.ButtonBackgroundImage.jsf?db=eAH7!!bVs!9Xzh9nYmBg4AYARSUHMw__);
}
Modified: root/core/trunk/impl/src/test/resources/resources/importedEL.css
===================================================================
--- root/core/trunk/impl/src/test/resources/resources/importedEL.css 2010-06-10 00:30:15 UTC (rev 17590)
+++ root/core/trunk/impl/src/test/resources/resources/importedEL.css 2010-06-10 13:44:40 UTC (rev 17591)
@@ -22,5 +22,5 @@
padding: 10px !important;
border: 1px solid green;
background-image: url(image.png);
- background: red url(/rfRes/org.richfaces.renderkit.html.images.ButtonBackgroundImage.jsf?db=eAF79urt!-Pnr!xn4mZgYAAAREsHMw__);
+ background: red url(/rfRes/org.richfaces.renderkit.html.images.ButtonBackgroundImage.jsf?db=eAH7!!bVs!9Xzh9nYmBg4AYARSUHMw__);
}
\ No newline at end of file
Modified: root/core/trunk/impl/src/test/resources/resources/resource.css
===================================================================
--- root/core/trunk/impl/src/test/resources/resources/resource.css 2010-06-10 00:30:15 UTC (rev 17590)
+++ root/core/trunk/impl/src/test/resources/resources/resource.css 2010-06-10 13:44:40 UTC (rev 17591)
@@ -1,3 +1,3 @@
body {
- background: red url(/rfRes/org.richfaces.renderkit.html.images.ButtonBackgroundImage.jsf?db=eAF79urt!-Pnr!xn4mZgYAAAREsHMw__);
+ background: red url(/rfRes/org.richfaces.renderkit.html.images.ButtonBackgroundImage.jsf?db=eAH7!!bVs!9Xzh9nYmBg4AYARSUHMw__);
}
\ No newline at end of file
14 years, 7 months
JBoss Rich Faces SVN: r17590 - in root/core/branches/jsr-330: jsr330-impl and 11 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: alexsmirnov
Date: 2010-06-09 20:30:15 -0400 (Wed, 09 Jun 2010)
New Revision: 17590
Added:
root/core/branches/jsr-330/jsr330-impl/
root/core/branches/jsr-330/jsr330-impl/pom.xml
root/core/branches/jsr-330/jsr330-impl/src/
root/core/branches/jsr-330/jsr330-impl/src/main/
root/core/branches/jsr-330/jsr330-impl/src/main/java/
root/core/branches/jsr-330/jsr330-impl/src/main/java/org/
root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/
root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/
root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/Binding.java
root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/BindingModule.java
root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/DependencyException.java
root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/DependencyInjector.java
root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/DynamicBinding.java
root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/InjectorImpl.java
root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/ObjectFactory.java
root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/ProviderWrapper.java
root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/StaticBinding.java
root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/Target.java
root/core/branches/jsr-330/jsr330-impl/src/test/
root/core/branches/jsr-330/jsr330-impl/src/test/java/
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/InjectorTest.java
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/TestConstructorInjection.java
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/TestFieldInjection.java
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/TestInterface.java
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/TestMethodInjection.java
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/TestProviderInjection.java
Log:
add lightweight jsr-330 implementation
Property changes on: root/core/branches/jsr-330/jsr330-impl
___________________________________________________________________
Name: svn:ignore
+ target
.settings
.project
.classpath
.clover
Added: root/core/branches/jsr-330/jsr330-impl/pom.xml
===================================================================
--- root/core/branches/jsr-330/jsr330-impl/pom.xml (rev 0)
+++ root/core/branches/jsr-330/jsr330-impl/pom.xml 2010-06-10 00:30:15 UTC (rev 17590)
@@ -0,0 +1,43 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.richfaces</groupId>
+ <artifactId>jsr330-impl</artifactId>
+ <version>4.0.0-SNAPSHOT</version>
+ <packaging>jar</packaging>
+
+ <name>jsr330-impl</name>
+ <url>http://maven.apache.org</url>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <!-- http://maven.apache.org/plugins/maven-compiler-plugin/ -->
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.inject</groupId>
+ <artifactId>javax.inject</artifactId>
+ <version>1</version>
+ </dependency>
+ </dependencies>
+</project>
Added: root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/Binding.java
===================================================================
--- root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/Binding.java (rev 0)
+++ root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/Binding.java 2010-06-10 00:30:15 UTC (rev 17590)
@@ -0,0 +1,11 @@
+package org.richfaces.jsr330;
+
+import javax.inject.Provider;
+
+public interface Binding extends Provider {
+
+ public Object get();
+
+ void init(InjectorImpl injectorImpl);
+
+}
Added: root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/BindingModule.java
===================================================================
--- root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/BindingModule.java (rev 0)
+++ root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/BindingModule.java 2010-06-10 00:30:15 UTC (rev 17590)
@@ -0,0 +1,7 @@
+package org.richfaces.jsr330;
+
+public interface BindingModule {
+
+ public void configure(InjectorImpl injector);
+
+}
Added: root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/DependencyException.java
===================================================================
--- root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/DependencyException.java (rev 0)
+++ root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/DependencyException.java 2010-06-10 00:30:15 UTC (rev 17590)
@@ -0,0 +1,68 @@
+/*
+ * $Id$
+ *
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * 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 org.richfaces.jsr330;
+
+/**
+ * <p class="changed_added_4_0"></p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public class DependencyException extends RuntimeException {
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ */
+ public DependencyException() {
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param message
+ */
+ public DependencyException(String message) {
+ super(message);
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param cause
+ */
+ public DependencyException(Throwable cause) {
+ super(cause);
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param message
+ * @param cause
+ */
+ public DependencyException(String message, Throwable cause) {
+ super(message, cause);
+ // TODO Auto-generated constructor stub
+ }
+
+}
Added: root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/DependencyInjector.java
===================================================================
--- root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/DependencyInjector.java (rev 0)
+++ root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/DependencyInjector.java 2010-06-10 00:30:15 UTC (rev 17590)
@@ -0,0 +1,35 @@
+/*
+ * $Id$
+ *
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * 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 org.richfaces.jsr330;
+
+/**
+ * <p class="changed_added_4_0"></p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public interface DependencyInjector {
+
+ public <T> T create(Class<T> type);
+
+}
Added: root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/DynamicBinding.java
===================================================================
--- root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/DynamicBinding.java (rev 0)
+++ root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/DynamicBinding.java 2010-06-10 00:30:15 UTC (rev 17590)
@@ -0,0 +1,186 @@
+package org.richfaces.jsr330;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.inject.Inject;
+import javax.inject.Provider;
+import javax.inject.Singleton;
+
+public class DynamicBinding implements Binding, Provider {
+
+ private final Class<?> type;
+
+ private Constructor<?> constructor;
+
+ private List<Binding> constructorArguments;
+
+ private Map<Field, Binding> injectedFields;
+
+ private Map<Method, List<Binding>> injectedMethods;
+
+ private boolean singleton;
+
+ private volatile Object value;
+
+ public DynamicBinding(Class<?> type) {
+ this.type = type;
+ }
+
+ void findInjectorMethods(InjectorImpl injectorImpl) throws Exception {
+ injectedMethods = new HashMap<Method, List<Binding>>();
+ Method[] methods = this.type.getMethods();
+ for (Method method : methods) {
+ if (method.isAnnotationPresent(Inject.class)) {
+ Type[] parameterTypes = method.getGenericParameterTypes();
+ Annotation[][] parameterAnnotations = method.getParameterAnnotations();
+ injectedMethods.put(method, getParameterBindings(injectorImpl, parameterTypes, parameterAnnotations));
+ }
+ }
+ }
+
+ void findInjectedFields(InjectorImpl injectorImpl) throws Exception {
+ Field[] declaredFields = this.type.getDeclaredFields();
+ this.injectedFields = new HashMap<Field, Binding>();
+ for (Field field : declaredFields) {
+ if (field.isAnnotationPresent(Inject.class)) {
+ Type fieldType = field.getGenericType();
+ if (fieldType instanceof Class) {
+ Class<?> fieldClass = (Class<?>) fieldType;
+ this.injectedFields.put(field, injectorImpl.getBinding(Target.create(fieldClass, field
+ .getAnnotations())));
+ }
+ }
+ }
+ }
+
+ void findConstructor(InjectorImpl injectorImpl) throws Exception {
+ Constructor<?>[] constructors = this.type.getConstructors();
+ for (Constructor<?> constructor : constructors) {
+ if (constructor.isAnnotationPresent(Inject.class)) {
+ if (null != this.constructor) {
+ throw new DependencyException("More then one constructor have @Inject annotation " + this.type);
+ }
+ this.constructor = constructor;
+ Type[] parameterTypes = constructor.getGenericParameterTypes();
+ Annotation[][] parameterAnnotations = constructor.getParameterAnnotations();
+ this.constructorArguments = getParameterBindings(injectorImpl, parameterTypes, parameterAnnotations);
+ }
+ }
+ if (null == constructor) {
+ constructor = (Constructor<?>) this.type.getConstructor();
+ this.constructorArguments = Collections.emptyList();
+ }
+ }
+
+ List<Binding> getParameterBindings(InjectorImpl injectorImpl, Type[] parameterTypes,
+ Annotation[][] parameterAnnotations) {
+ List<Binding> arguments = new ArrayList<Binding>(parameterTypes.length);
+ int i = 0;
+ for (Type parameterType : parameterTypes) {
+ arguments.add(injectorImpl.getBinding(Target.create(parameterType, parameterAnnotations[i])));
+ i++;
+ }
+ return arguments;
+ }
+
+ public Object get() {
+ if (isSingleton()) {
+ if (null == value) {
+ synchronized (this) {
+ value = createInstance();
+ }
+ }
+ return value;
+ } else {
+ Object instance = createInstance();
+ return instance;
+ }
+ }
+
+ void invokeInjectionMethods(Object instance) throws Exception {
+ for (Method method : injectedMethods.keySet()) {
+ method.invoke(instance, getArgumentValues(injectedMethods.get(method)));
+ }
+
+ }
+
+ void injectFields(Object instance) throws Exception {
+ for (Field field : injectedFields.keySet()) {
+ boolean accessible = field.isAccessible();
+ if (!accessible) {
+ field.setAccessible(true);
+ }
+ field.set(instance, injectedFields.get(field).get());
+ if (!accessible) {
+ field.setAccessible(accessible);
+ }
+ }
+ }
+
+ Object createInstance() {
+ try {
+ Object[] arguments = getArgumentValues(this.constructorArguments);
+ Object instance = constructor.newInstance(arguments);
+ injectFields(instance);
+ invokeInjectionMethods(instance);
+ return instance;
+ } catch (Exception e) {
+ throw new DependencyException(e);
+ }
+ }
+
+ Object[] getArgumentValues(List<Binding> argumentBinding) {
+ Object[] arguments = new Object[argumentBinding.size()];
+ int i = 0;
+ for (Binding provider : argumentBinding) {
+ arguments[i++] = provider.get();
+ }
+ return arguments;
+ }
+
+ public void init(InjectorImpl injectorImpl) {
+ try {
+ findConstructor(injectorImpl);
+ findInjectedFields(injectorImpl);
+ findInjectorMethods(injectorImpl);
+ if (type.isAnnotationPresent(Singleton.class)) {
+ this.singleton = true;
+ }
+ } catch (Exception e) {
+ throw new DependencyException(e);
+ }
+ // TODO Auto-generated method stub
+
+ }
+
+ /**
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @return the singleton
+ */
+ public boolean isSingleton() {
+ return this.singleton;
+ }
+
+ /**
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @param singleton
+ * the singleton to set
+ */
+ public void setSingleton(boolean singleton) {
+ this.singleton = singleton;
+ }
+
+}
Added: root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/InjectorImpl.java
===================================================================
--- root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/InjectorImpl.java (rev 0)
+++ root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/InjectorImpl.java 2010-06-10 00:30:15 UTC (rev 17590)
@@ -0,0 +1,95 @@
+package org.richfaces.jsr330;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.inject.Provider;
+
+public class InjectorImpl implements DependencyInjector {
+
+
+ private final Map<Target,Binding> bindings = new HashMap<Target, Binding>();
+
+ @SuppressWarnings("unchecked")
+ public <T> T create(Class<T> type) {
+ Target target = Target.create(type);
+ return (T) getBinding(target).get();
+ }
+
+ public void init(BindingModule ... modules){
+ for (BindingModule bindingModule : modules) {
+ bindingModule.configure(this);
+ }
+ initProviders();
+ }
+
+ public void initSingletons() {
+ Collection<Binding> values = new ArrayList<Binding>(bindings.values());
+ for (Binding binding : values) {
+ if (binding instanceof DynamicBinding) {
+ DynamicBinding dynamicBinding = (DynamicBinding) binding;
+ if(dynamicBinding.isSingleton()){
+ dynamicBinding.get();
+ }
+ }
+ }
+ }
+
+ private void initProviders() {
+ Collection<Binding> values = new ArrayList<Binding>(bindings.values());
+ for (Binding binding : values) {
+ binding.init(this);
+ }
+
+ }
+
+ public Binding getBinding(Target type) {
+ if (bindings.containsKey(type)) {
+ return bindings.get(type);
+ } else if(type.isConcrete()){
+ // Concrete classes can be created without configuration.
+ Binding binding = registerImplementation(type, type.getRawType());
+ binding.init(this);
+ return binding;
+ } else {
+ throw new DependencyException("Type "+type+" has not been registered");
+ }
+ }
+
+ public Binding registerProvider(Target type, Provider<?> provider){
+ StaticBinding binding = new StaticBinding(provider);
+ registerProviderWrapper(type, binding);
+ return binding;
+ }
+
+ public Binding registerProvider(Target type, Class<? extends Provider<?>> provider){
+ DynamicBinding binding = new DynamicBinding(provider);
+ registerProviderWrapper(type, binding);
+ return binding;
+ }
+
+ private void registerProviderWrapper(Target type, Binding binding) {
+ bindings.put(type.toProvider(), binding);
+ ProviderWrapper wrapper = new ProviderWrapper(binding);
+ bindings.put(type, wrapper);
+ }
+
+ public Binding registerImplementation(Target type, Class<?> implementation){
+ DynamicBinding provider = new DynamicBinding(implementation);
+ registerImplementationProvider(type, provider);
+ return provider;
+ }
+
+ public Binding registerInstance(Target type, Object instance){
+ StaticBinding provider = new StaticBinding(instance);
+ registerImplementationProvider(type, provider);
+ return provider;
+ }
+
+ private void registerImplementationProvider(Target type, Binding provider) {
+ bindings.put(type, provider);
+ bindings.put(type.toProvider(), new StaticBinding(provider));
+ }
+}
Added: root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/ObjectFactory.java
===================================================================
--- root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/ObjectFactory.java (rev 0)
+++ root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/ObjectFactory.java 2010-06-10 00:30:15 UTC (rev 17590)
@@ -0,0 +1,40 @@
+package org.richfaces.jsr330;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Implementation independent factory for JSR-330 beans.
+ *
+ */
+public final class ObjectFactory {
+ /**
+ * <p class="changed_added_4_0">
+ * </p>
+ */
+ private static final Map<ClassLoader, DependencyInjector> INSTANCES =
+ new ConcurrentHashMap<ClassLoader, DependencyInjector>();
+
+ private ObjectFactory() {
+ }
+
+ public static <T> T create(Class<T> target) {
+ return getInjector().create(target);
+ }
+
+ private static DependencyInjector getInjector() {
+ return INSTANCES.get(getCurrentLoader());
+ }
+
+ private static ClassLoader getCurrentLoader() {
+ ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
+ if (null == contextClassLoader) {
+ contextClassLoader = ObjectFactory.class.getClassLoader();
+ }
+ return contextClassLoader;
+ }
+
+ public static void setInjector(DependencyInjector injector) {
+ INSTANCES.put(getCurrentLoader(), injector);
+ }
+}
Added: root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/ProviderWrapper.java
===================================================================
--- root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/ProviderWrapper.java (rev 0)
+++ root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/ProviderWrapper.java 2010-06-10 00:30:15 UTC (rev 17590)
@@ -0,0 +1,65 @@
+/*
+ * $Id$
+ *
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * 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 org.richfaces.jsr330;
+
+import javax.inject.Provider;
+
+/**
+ * <p class="changed_added_4_0"></p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public class ProviderWrapper implements Binding {
+
+ private final Binding binding;
+
+ public ProviderWrapper(Binding binding) {
+ this.binding = binding;
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.jsr330.Binding#get()
+ */
+ public Object get() {
+ // TODO Auto-generated method stub
+ return getProvider().get();
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.jsr330.Binding#getProvider()
+ */
+ private Provider<?> getProvider() {
+ // TODO Auto-generated method stub
+ return (Provider<?>) binding.get();
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.jsr330.Binding#init(org.richfaces.jsr330.InjectorImpl)
+ */
+ public void init(InjectorImpl injectorImpl) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
Added: root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/StaticBinding.java
===================================================================
--- root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/StaticBinding.java (rev 0)
+++ root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/StaticBinding.java 2010-06-10 00:30:15 UTC (rev 17590)
@@ -0,0 +1,48 @@
+/*
+ * $Id$
+ *
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * 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 org.richfaces.jsr330;
+
+
+/**
+ * <p class="changed_added_4_0"></p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public class StaticBinding implements Binding {
+
+ private final Object value;
+
+ public StaticBinding(Object value) {
+ this.value = value;
+ }
+
+ public Object get() {
+ return value;
+ }
+
+ public void init(InjectorImpl injectorImpl) {
+ // do nothing
+ }
+
+}
Added: root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/Target.java
===================================================================
--- root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/Target.java (rev 0)
+++ root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/Target.java 2010-06-10 00:30:15 UTC (rev 17590)
@@ -0,0 +1,170 @@
+/*
+ * $Id$
+ *
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * 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 org.richfaces.jsr330;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Modifier;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.Arrays;
+
+import javax.inject.Named;
+import javax.inject.Provider;
+
+/**
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public class Target {
+
+ private static final Class<?>[] EMPTY_TYPES = new Class<?>[]{};
+
+ private final String name;
+
+ private final Type type;
+
+ private Class<?> rawType;
+
+ private Type[] actualTypeArguments;
+
+ public Target(Type type) {
+ this(type,null);
+ }
+
+ public Target(Type type, String name) {
+ this.type = type;
+ this.name = name;
+ this.rawType = getRawClass(type);
+ this.actualTypeArguments = getActualTypeArguments(type);
+ }
+
+ public static Target create(Class<?> type, String name) {
+ return new Target(type, name);
+ }
+
+ public static Target create(Type type, Annotation... annotations) {
+ if (null != annotations) {
+ for (Annotation annotation : annotations) {
+ if (annotation instanceof Named) {
+ return new Target(type, ((Named) annotation).value());
+ }
+ }
+
+ }
+ return new Target(type);
+ }
+
+ public Target toProvider() {
+ Target target = new Target(type, name);
+ target.rawType = Provider.class;
+ target.actualTypeArguments = new Type[]{this.type};
+ return target;
+ }
+
+ public boolean isConcrete() {
+ return !Modifier.isAbstract((getRawType()).getModifiers());
+ }
+
+ public Class<?> getRawType(){
+ return rawType;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + Arrays.hashCode(this.actualTypeArguments);
+ result = prime * result + ((this.name == null) ? 0 : this.name.hashCode());
+ result = prime * result + ((this.rawType == null) ? 0 : this.rawType.hashCode());
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ Target other = (Target) obj;
+ if (!Arrays.equals(this.actualTypeArguments, other.actualTypeArguments)) {
+ return false;
+ }
+ if (this.name == null) {
+ if (other.name != null) {
+ return false;
+ }
+ } else if (!this.name.equals(other.name)) {
+ return false;
+ }
+ if (!this.rawType.equals(other.rawType)) {
+ return false;
+ }
+ return true;
+ }
+
+ public static Type[] getActualTypeArguments(Type type) {
+ if(type instanceof Class<?>){
+ return EMPTY_TYPES;
+ } else if(type instanceof ParameterizedType){
+ return ((ParameterizedType) type).getActualTypeArguments();
+ } else {
+ throw new DependencyException("Unknown type "+type);
+ }
+ }
+
+ public static Class<?> getRawClass(Type type){
+ if(type instanceof Class<?>){
+ return (Class<?>)type;
+ } else if(type instanceof ParameterizedType){
+ return getRawClass(((ParameterizedType) type).getRawType());
+ } else {
+ throw new DependencyException("Unknown type "+type);
+ }
+
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @return the actualTypeArguments
+ */
+ public Type[] getActualTypeArguments() {
+ return this.actualTypeArguments;
+ }
+
+
+}
Added: root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/InjectorTest.java
===================================================================
--- root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/InjectorTest.java (rev 0)
+++ root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/InjectorTest.java 2010-06-10 00:30:15 UTC (rev 17590)
@@ -0,0 +1,77 @@
+package org.richfaces.jsr330;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+
+public class InjectorTest {
+
+ @Test
+ public void injectConstructor() throws Exception {
+ InjectorImpl injector = new InjectorImpl();
+ injector.init(new BindingModule(){
+
+ public void configure(InjectorImpl injector) {
+ injector.registerImplementation(Target.create(TestInterface.class), TestConstructorInjection.class);
+ injector.registerInstance(Target.create(String.class, "foo"), "bar");
+ injector.registerInstance(Target.create(String.class, "bar"), "baz");
+ }
+
+ });
+ TestInterface testInterface = injector.create(TestInterface.class);
+ assertTrue(testInterface instanceof TestConstructorInjection);
+ assertEquals("bar",testInterface.hello());
+ }
+
+ @Test
+ public void injectField() throws Exception {
+ InjectorImpl injector = new InjectorImpl();
+ injector.init(new BindingModule(){
+
+ public void configure(InjectorImpl injector) {
+ injector.registerImplementation(Target.create(TestInterface.class), TestFieldInjection.class);
+ injector.registerInstance(Target.create(String.class, "foo"), "bar");
+ injector.registerInstance(Target.create(String.class, "bar"), "baz");
+ }
+
+ });
+ TestInterface testInterface = injector.create(TestInterface.class);
+ assertTrue(testInterface instanceof TestFieldInjection);
+ assertEquals("bar",testInterface.hello());
+ }
+
+ @Test
+ public void injectMethod() throws Exception {
+ InjectorImpl injector = new InjectorImpl();
+ injector.init(new BindingModule(){
+
+ public void configure(InjectorImpl injector) {
+ injector.registerImplementation(Target.create(TestInterface.class), TestMethodInjection.class);
+ injector.registerInstance(Target.create(String.class, "foo"), "bar");
+ injector.registerInstance(Target.create(String.class, "bar"), "baz");
+ }
+
+ });
+ TestInterface testInterface = injector.create(TestInterface.class);
+ assertTrue(testInterface instanceof TestMethodInjection);
+ assertEquals("bar",testInterface.hello());
+ }
+ @Test
+ public void injectProvider() throws Exception {
+ InjectorImpl injector = new InjectorImpl();
+ injector.init(new BindingModule(){
+
+ public void configure(InjectorImpl injector) {
+ injector.registerImplementation(Target.create(TestInterface.class), TestProviderInjection.class);
+ injector.registerInstance(Target.create(String.class, "foo"), "bar");
+ injector.registerInstance(Target.create(String.class, "bar"), "baz");
+ }
+
+ });
+ TestInterface testInterface = injector.create(TestInterface.class);
+ assertTrue(testInterface instanceof TestProviderInjection);
+ assertEquals("bar",testInterface.hello());
+ }
+
+}
Added: root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/TestConstructorInjection.java
===================================================================
--- root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/TestConstructorInjection.java (rev 0)
+++ root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/TestConstructorInjection.java 2010-06-10 00:30:15 UTC (rev 17590)
@@ -0,0 +1,47 @@
+/*
+ * $Id$
+ *
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * 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 org.richfaces.jsr330;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+
+/**
+ * <p class="changed_added_4_0"></p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public class TestConstructorInjection implements TestInterface {
+
+ final String param;
+
+ @Inject
+ public TestConstructorInjection( @Named("foo") String param) {
+ this.param = param;
+ }
+
+ public String hello() {
+ return param;
+ }
+
+}
Added: root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/TestFieldInjection.java
===================================================================
--- root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/TestFieldInjection.java (rev 0)
+++ root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/TestFieldInjection.java 2010-06-10 00:30:15 UTC (rev 17590)
@@ -0,0 +1,47 @@
+/*
+ * $Id$
+ *
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * 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 org.richfaces.jsr330;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+
+/**
+ * <p class="changed_added_4_0"></p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public class TestFieldInjection implements TestInterface {
+
+ @Inject
+ @Named("foo")
+ String param;
+
+ public TestFieldInjection( ) {
+ }
+
+ public String hello() {
+ return param;
+ }
+
+}
Added: root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/TestInterface.java
===================================================================
--- root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/TestInterface.java (rev 0)
+++ root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/TestInterface.java 2010-06-10 00:30:15 UTC (rev 17590)
@@ -0,0 +1,35 @@
+/*
+ * $Id$
+ *
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * 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 org.richfaces.jsr330;
+
+/**
+ * <p class="changed_added_4_0"></p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public interface TestInterface {
+
+ public String hello();
+
+}
Added: root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/TestMethodInjection.java
===================================================================
--- root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/TestMethodInjection.java (rev 0)
+++ root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/TestMethodInjection.java 2010-06-10 00:30:15 UTC (rev 17590)
@@ -0,0 +1,51 @@
+/*
+ * $Id$
+ *
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * 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 org.richfaces.jsr330;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+
+/**
+ * <p class="changed_added_4_0"></p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public class TestMethodInjection implements TestInterface {
+
+ String param;
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param param the param to set
+ */
+ @Inject
+ public void setParam( @Named("foo") String param) {
+ this.param = param;
+ }
+
+ public String hello() {
+ return param;
+ }
+
+}
Added: root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/TestProviderInjection.java
===================================================================
--- root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/TestProviderInjection.java (rev 0)
+++ root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/TestProviderInjection.java 2010-06-10 00:30:15 UTC (rev 17590)
@@ -0,0 +1,52 @@
+/*
+ * $Id$
+ *
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * 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 org.richfaces.jsr330;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Provider;
+
+/**
+ * <p class="changed_added_4_0"></p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public class TestProviderInjection implements TestInterface {
+
+ String param;
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param param the param to set
+ */
+ @Inject
+ public void setParam( @Named("foo") Provider<String> param) {
+ this.param = param.get();
+ }
+
+ public String hello() {
+ return param;
+ }
+
+}
14 years, 7 months
JBoss Rich Faces SVN: r17588 - root/core/branches.
by richfaces-svn-commits@lists.jboss.org
Author: alexsmirnov
Date: 2010-06-09 20:22:46 -0400 (Wed, 09 Jun 2010)
New Revision: 17588
Added:
root/core/branches/jsr-330/
Log:
create branch for jsr-330 experiment
Copied: root/core/branches/jsr-330 (from rev 17586, root/core/trunk)
14 years, 7 months
JBoss Rich Faces SVN: r17587 - root/cdk/trunk/plugins/commons/src/test/java/org/richfaces/cdk.
by richfaces-svn-commits@lists.jboss.org
Author: alexsmirnov
Date: 2010-06-09 20:14:16 -0400 (Wed, 09 Jun 2010)
New Revision: 17587
Modified:
root/cdk/trunk/plugins/commons/src/test/java/org/richfaces/cdk/CdkTestRunner.java
Log:
minor fix
Modified: root/cdk/trunk/plugins/commons/src/test/java/org/richfaces/cdk/CdkTestRunner.java
===================================================================
--- root/cdk/trunk/plugins/commons/src/test/java/org/richfaces/cdk/CdkTestRunner.java 2010-06-09 21:21:03 UTC (rev 17586)
+++ root/cdk/trunk/plugins/commons/src/test/java/org/richfaces/cdk/CdkTestRunner.java 2010-06-10 00:14:16 UTC (rev 17587)
@@ -123,12 +123,14 @@
FieldModule fields = new FieldModule(fieldValues);
Injector injector;
+ Object test = super.createTest();
if (Module.class.isAssignableFrom(testClass)) {
injector = Guice.createInjector(fields, (Module) testClass.newInstance());
} else {
injector = Guice.createInjector(fields);
}
- return injector.getInstance(testClass);
+ injector.injectMembers(test);
+ return test;
}
protected static final class FieldModule extends AbstractModule implements MockController {
14 years, 7 months
JBoss Rich Faces SVN: r17586 - root/core/branches/richfaces-core-4.0.0.Alpha2/impl/src/main/resources/META-INF/resources.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2010-06-09 17:21:03 -0400 (Wed, 09 Jun 2010)
New Revision: 17586
Modified:
root/core/branches/richfaces-core-4.0.0.Alpha2/impl/src/main/resources/META-INF/resources/richfaces.js
Log:
https://jira.jboss.org/browse/RF-8744
Modified: root/core/branches/richfaces-core-4.0.0.Alpha2/impl/src/main/resources/META-INF/resources/richfaces.js
===================================================================
--- root/core/branches/richfaces-core-4.0.0.Alpha2/impl/src/main/resources/META-INF/resources/richfaces.js 2010-06-09 21:18:20 UTC (rev 17585)
+++ root/core/branches/richfaces-core-4.0.0.Alpha2/impl/src/main/resources/META-INF/resources/richfaces.js 2010-06-09 21:21:03 UTC (rev 17586)
@@ -600,7 +600,7 @@
}
}
- if (!jQuery(sourceElt).is('input, select, textarea')) {
+ if (!jQuery(sourceElt).is(":input:not(:submit, :button, :image, :reset)")) {
parameters[sourceId] = sourceId;
}
14 years, 7 months
JBoss Rich Faces SVN: r17585 - root/core/trunk/impl/src/main/resources/META-INF/resources.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2010-06-09 17:18:20 -0400 (Wed, 09 Jun 2010)
New Revision: 17585
Modified:
root/core/trunk/impl/src/main/resources/META-INF/resources/richfaces.js
Log:
https://jira.jboss.org/browse/RF-8744
Modified: root/core/trunk/impl/src/main/resources/META-INF/resources/richfaces.js
===================================================================
--- root/core/trunk/impl/src/main/resources/META-INF/resources/richfaces.js 2010-06-09 17:40:12 UTC (rev 17584)
+++ root/core/trunk/impl/src/main/resources/META-INF/resources/richfaces.js 2010-06-09 21:18:20 UTC (rev 17585)
@@ -600,7 +600,7 @@
}
}
- if (!jQuery(sourceElt).is('input, select, textarea')) {
+ if (!jQuery(sourceElt).is(":input:not(:submit, :button, :image, :reset)")) {
parameters[sourceId] = sourceId;
}
14 years, 7 months
JBoss Rich Faces SVN: r17584 - in root: core/trunk/api/src/main/java/org/richfaces/resource and 8 other directories.
by richfaces-svn-commits@lists.jboss.org
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;
}
14 years, 7 months
JBoss Rich Faces SVN: r17583 - root/core/branches/richfaces-core-4.0.0.Alpha2/impl/src/main/resources/META-INF/resources.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2010-06-09 10:04:16 -0400 (Wed, 09 Jun 2010)
New Revision: 17583
Modified:
root/core/branches/richfaces-core-4.0.0.Alpha2/impl/src/main/resources/META-INF/resources/richfaces.js
Log:
https://jira.jboss.org/browse/RF-8744
Modified: root/core/branches/richfaces-core-4.0.0.Alpha2/impl/src/main/resources/META-INF/resources/richfaces.js
===================================================================
--- root/core/branches/richfaces-core-4.0.0.Alpha2/impl/src/main/resources/META-INF/resources/richfaces.js 2010-06-09 13:52:44 UTC (rev 17582)
+++ root/core/branches/richfaces-core-4.0.0.Alpha2/impl/src/main/resources/META-INF/resources/richfaces.js 2010-06-09 14:04:16 UTC (rev 17583)
@@ -560,6 +560,7 @@
richfaces.ajax = function(source, event, options) {
var sourceId = (typeof source == 'object' && source.id) ? source.id : source;
+ var sourceElt = (typeof source == 'object') ? source : document.getElementById(sourceId);
options = options || {};
@@ -599,7 +600,9 @@
}
}
- parameters[sourceId] = sourceId;
+ if (!jQuery(sourceElt).is('input, select, textarea')) {
+ parameters[sourceId] = sourceId;
+ }
if (eventHandlers) {
var eventsAdapter = richfaces.createJSFEventsAdapter(eventHandlers);
14 years, 7 months