Author: alexsmirnov
Date: 2010-06-14 12:48:35 -0400 (Mon, 14 Jun 2010)
New Revision: 17624
Added:
root/core/branches/jsr-330/api/src/main/java/org/richfaces/resource/ImageType.java
root/core/branches/jsr-330/api/src/main/java/org/richfaces/resource/Java2DUserResource.java
root/core/branches/jsr-330/api/src/main/java/org/richfaces/resource/StateHolderResource.java
root/core/branches/jsr-330/api/src/main/java/org/richfaces/resource/UserResource.java
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/resource/Java2DUserResourceAdaptor.java
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/resource/UserResourceAdaptor.java
Removed:
root/core/branches/jsr-330/impl/src/main/java/org/ajax4jsf/util/NumericDataInputStream.java
root/core/branches/jsr-330/impl/src/main/java/org/ajax4jsf/util/NumericDataOutputStream.java
root/core/branches/jsr-330/impl/src/test/java/org/ajax4jsf/util/NumericStreamsTest.java
Modified:
root/core/branches/jsr-330/
root/core/branches/jsr-330/api/src/main/java/org/richfaces/resource/CacheableResource.java
root/core/branches/jsr-330/api/src/main/java/org/richfaces/resource/VersionedResource.java
root/core/branches/jsr-330/impl/src/main/java/org/ajax4jsf/context/ContextInitParameters.java
root/core/branches/jsr-330/impl/src/main/java/org/ajax4jsf/resource/Java2Dresource.java
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/renderkit/html/BaseGradient.java
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/renderkit/html/CustomizeableGradient.java
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/renderkit/html/images/BaseControlBackgroundImage.java
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/renderkit/html/images/CancelControlIcon.java
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/renderkit/html/images/OneColorBasedResource.java
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/resource/AbstractBaseResource.java
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/resource/AbstractCacheableResource.java
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/resource/CachedResourceImpl.java
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/resource/CompiledCSSResource.java
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/resource/ResourceHandlerImpl.java
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/resource/ResourceParameterELResolver.java
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/resource/TestResource2.java
root/core/branches/jsr-330/impl/src/main/resources/META-INF/resources/richfaces-base-component.js
root/core/branches/jsr-330/impl/src/main/resources/META-INF/resources/richfaces-event.js
root/core/branches/jsr-330/impl/src/test/java/org/richfaces/resource/AbstractBaseResourceTest.java
root/core/branches/jsr-330/impl/src/test/java/org/richfaces/resource/AbstractCacheableResourceTest.java
root/core/branches/jsr-330/impl/src/test/java/org/richfaces/resource/CacheableResourceImpl.java
root/core/branches/jsr-330/impl/src/test/java/org/richfaces/resource/ResourceHandlerImplTest.java
root/core/branches/jsr-330/impl/src/test/java/org/richfaces/resource/StateHolderResourceImpl.java
root/core/branches/jsr-330/impl/src/test/resources/javascript/richfaces-event-qunit.js
root/core/branches/jsr-330/impl/src/test/resources/resources/full.css
root/core/branches/jsr-330/impl/src/test/resources/resources/importedEL.css
root/core/branches/jsr-330/impl/src/test/resources/resources/resource.css
Log:
Merged revisions 17591-17592,17594 via svnmerge from
https://svn.jboss.org/repos/richfaces/root/core/trunk
.......
r17591 | nbelaevski | 2010-06-10 06:44:40 -0700 (Thu, 10 Jun 2010) | 1 line
https://jira.jboss.org/browse/RF-8665
.......
r17592 | pyaschenko | 2010-06-10 07:17:06 -0700 (Thu, 10 Jun 2010) | 2 lines
Event API changes: refactoring, multiple binding was added to bindById method, used in
autocomplete component
QUnit tests was fixed after the changes
.......
r17594 | pyaschenko | 2010-06-10 07:21:37 -0700 (Thu, 10 Jun 2010) | 1 line
documentation comment added
.......
Property changes on: root/core/branches/jsr-330
___________________________________________________________________
Name: svnmerge-integrated
- /root/core/trunk:1-17586
+ /root/core/trunk:1-17598
Modified:
root/core/branches/jsr-330/api/src/main/java/org/richfaces/resource/CacheableResource.java
===================================================================
---
root/core/branches/jsr-330/api/src/main/java/org/richfaces/resource/CacheableResource.java 2010-06-13
17:38:26 UTC (rev 17623)
+++
root/core/branches/jsr-330/api/src/main/java/org/richfaces/resource/CacheableResource.java 2010-06-14
16:48:35 UTC (rev 17624)
@@ -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);
}
Copied: root/core/branches/jsr-330/api/src/main/java/org/richfaces/resource/ImageType.java
(from rev 17594, root/core/trunk/api/src/main/java/org/richfaces/resource/ImageType.java)
===================================================================
--- root/core/branches/jsr-330/api/src/main/java/org/richfaces/resource/ImageType.java
(rev 0)
+++
root/core/branches/jsr-330/api/src/main/java/org/richfaces/resource/ImageType.java 2010-06-14
16:48:35 UTC (rev 17624)
@@ -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
Copied:
root/core/branches/jsr-330/api/src/main/java/org/richfaces/resource/Java2DUserResource.java
(from rev 17594,
root/core/trunk/api/src/main/java/org/richfaces/resource/Java2DUserResource.java)
===================================================================
---
root/core/branches/jsr-330/api/src/main/java/org/richfaces/resource/Java2DUserResource.java
(rev 0)
+++
root/core/branches/jsr-330/api/src/main/java/org/richfaces/resource/Java2DUserResource.java 2010-06-14
16:48:35 UTC (rev 17624)
@@ -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);
+
+}
Copied:
root/core/branches/jsr-330/api/src/main/java/org/richfaces/resource/StateHolderResource.java
(from rev 17594,
root/core/trunk/api/src/main/java/org/richfaces/resource/StateHolderResource.java)
===================================================================
---
root/core/branches/jsr-330/api/src/main/java/org/richfaces/resource/StateHolderResource.java
(rev 0)
+++
root/core/branches/jsr-330/api/src/main/java/org/richfaces/resource/StateHolderResource.java 2010-06-14
16:48:35 UTC (rev 17624)
@@ -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;
+
+}
Copied:
root/core/branches/jsr-330/api/src/main/java/org/richfaces/resource/UserResource.java
(from rev 17594,
root/core/trunk/api/src/main/java/org/richfaces/resource/UserResource.java)
===================================================================
--- root/core/branches/jsr-330/api/src/main/java/org/richfaces/resource/UserResource.java
(rev 0)
+++
root/core/branches/jsr-330/api/src/main/java/org/richfaces/resource/UserResource.java 2010-06-14
16:48:35 UTC (rev 17624)
@@ -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/branches/jsr-330/api/src/main/java/org/richfaces/resource/VersionedResource.java
===================================================================
---
root/core/branches/jsr-330/api/src/main/java/org/richfaces/resource/VersionedResource.java 2010-06-13
17:38:26 UTC (rev 17623)
+++
root/core/branches/jsr-330/api/src/main/java/org/richfaces/resource/VersionedResource.java 2010-06-14
16:48:35 UTC (rev 17624)
@@ -28,5 +28,7 @@
* @since 4.0
*/
public interface VersionedResource {
+
public String getVersion();
+
}
Modified:
root/core/branches/jsr-330/impl/src/main/java/org/ajax4jsf/context/ContextInitParameters.java
===================================================================
---
root/core/branches/jsr-330/impl/src/main/java/org/ajax4jsf/context/ContextInitParameters.java 2010-06-13
17:38:26 UTC (rev 17623)
+++
root/core/branches/jsr-330/impl/src/main/java/org/ajax4jsf/context/ContextInitParameters.java 2010-06-14
16:48:35 UTC (rev 17624)
@@ -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/branches/jsr-330/impl/src/main/java/org/ajax4jsf/resource/Java2Dresource.java
===================================================================
---
root/core/branches/jsr-330/impl/src/main/java/org/ajax4jsf/resource/Java2Dresource.java 2010-06-13
17:38:26 UTC (rev 17623)
+++
root/core/branches/jsr-330/impl/src/main/java/org/ajax4jsf/resource/Java2Dresource.java 2010-06-14
16:48:35 UTC (rev 17624)
@@ -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/branches/jsr-330/impl/src/main/java/org/ajax4jsf/util/NumericDataInputStream.java
===================================================================
---
root/core/branches/jsr-330/impl/src/main/java/org/ajax4jsf/util/NumericDataInputStream.java 2010-06-13
17:38:26 UTC (rev 17623)
+++
root/core/branches/jsr-330/impl/src/main/java/org/ajax4jsf/util/NumericDataInputStream.java 2010-06-14
16:48:35 UTC (rev 17624)
@@ -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/branches/jsr-330/impl/src/main/java/org/ajax4jsf/util/NumericDataOutputStream.java
===================================================================
---
root/core/branches/jsr-330/impl/src/main/java/org/ajax4jsf/util/NumericDataOutputStream.java 2010-06-13
17:38:26 UTC (rev 17623)
+++
root/core/branches/jsr-330/impl/src/main/java/org/ajax4jsf/util/NumericDataOutputStream.java 2010-06-14
16:48:35 UTC (rev 17624)
@@ -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/branches/jsr-330/impl/src/main/java/org/richfaces/renderkit/html/BaseGradient.java
===================================================================
---
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/renderkit/html/BaseGradient.java 2010-06-13
17:38:26 UTC (rev 17623)
+++
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/renderkit/html/BaseGradient.java 2010-06-14
16:48:35 UTC (rev 17624)
@@ -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/branches/jsr-330/impl/src/main/java/org/richfaces/renderkit/html/CustomizeableGradient.java
===================================================================
---
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/renderkit/html/CustomizeableGradient.java 2010-06-13
17:38:26 UTC (rev 17623)
+++
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/renderkit/html/CustomizeableGradient.java 2010-06-14
16:48:35 UTC (rev 17624)
@@ -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/branches/jsr-330/impl/src/main/java/org/richfaces/renderkit/html/images/BaseControlBackgroundImage.java
===================================================================
---
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/renderkit/html/images/BaseControlBackgroundImage.java 2010-06-13
17:38:26 UTC (rev 17623)
+++
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/renderkit/html/images/BaseControlBackgroundImage.java 2010-06-14
16:48:35 UTC (rev 17624)
@@ -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/branches/jsr-330/impl/src/main/java/org/richfaces/renderkit/html/images/CancelControlIcon.java
===================================================================
---
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/renderkit/html/images/CancelControlIcon.java 2010-06-13
17:38:26 UTC (rev 17623)
+++
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/renderkit/html/images/CancelControlIcon.java 2010-06-14
16:48:35 UTC (rev 17624)
@@ -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/branches/jsr-330/impl/src/main/java/org/richfaces/renderkit/html/images/OneColorBasedResource.java
===================================================================
---
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/renderkit/html/images/OneColorBasedResource.java 2010-06-13
17:38:26 UTC (rev 17623)
+++
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/renderkit/html/images/OneColorBasedResource.java 2010-06-14
16:48:35 UTC (rev 17624)
@@ -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/branches/jsr-330/impl/src/main/java/org/richfaces/resource/AbstractBaseResource.java
===================================================================
---
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/resource/AbstractBaseResource.java 2010-06-13
17:38:26 UTC (rev 17623)
+++
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/resource/AbstractBaseResource.java 2010-06-14
16:48:35 UTC (rev 17624)
@@ -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/branches/jsr-330/impl/src/main/java/org/richfaces/resource/AbstractCacheableResource.java
===================================================================
---
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/resource/AbstractCacheableResource.java 2010-06-13
17:38:26 UTC (rev 17623)
+++
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/resource/AbstractCacheableResource.java 2010-06-14
16:48:35 UTC (rev 17624)
@@ -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/branches/jsr-330/impl/src/main/java/org/richfaces/resource/CachedResourceImpl.java
===================================================================
---
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/resource/CachedResourceImpl.java 2010-06-13
17:38:26 UTC (rev 17623)
+++
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/resource/CachedResourceImpl.java 2010-06-14
16:48:35 UTC (rev 17624)
@@ -204,7 +204,7 @@
}
@Override
- protected String getEntityTag(FacesContext context) {
+ public String getEntityTag(FacesContext context) {
return entityTag;
}
Modified:
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/resource/CompiledCSSResource.java
===================================================================
---
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/resource/CompiledCSSResource.java 2010-06-13
17:38:26 UTC (rev 17623)
+++
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/resource/CompiledCSSResource.java 2010-06-14
16:48:35 UTC (rev 17624)
@@ -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
Copied:
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/resource/Java2DUserResourceAdaptor.java
(from rev 17594,
root/core/trunk/impl/src/main/java/org/richfaces/resource/Java2DUserResourceAdaptor.java)
===================================================================
---
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/resource/Java2DUserResourceAdaptor.java
(rev 0)
+++
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/resource/Java2DUserResourceAdaptor.java 2010-06-14
16:48:35 UTC (rev 17624)
@@ -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/branches/jsr-330/impl/src/main/java/org/richfaces/resource/ResourceHandlerImpl.java
===================================================================
---
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/resource/ResourceHandlerImpl.java 2010-06-13
17:38:26 UTC (rev 17623)
+++
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/resource/ResourceHandlerImpl.java 2010-06-14
16:48:35 UTC (rev 17624)
@@ -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/branches/jsr-330/impl/src/main/java/org/richfaces/resource/ResourceParameterELResolver.java
===================================================================
---
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/resource/ResourceParameterELResolver.java 2010-06-13
17:38:26 UTC (rev 17623)
+++
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/resource/ResourceParameterELResolver.java 2010-06-14
16:48:35 UTC (rev 17624)
@@ -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/branches/jsr-330/impl/src/main/java/org/richfaces/resource/TestResource2.java
===================================================================
---
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/resource/TestResource2.java 2010-06-13
17:38:26 UTC (rev 17623)
+++
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/resource/TestResource2.java 2010-06-14
16:48:35 UTC (rev 17624)
@@ -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
Copied:
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/resource/UserResourceAdaptor.java
(from rev 17594,
root/core/trunk/impl/src/main/java/org/richfaces/resource/UserResourceAdaptor.java)
===================================================================
---
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/resource/UserResourceAdaptor.java
(rev 0)
+++
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/resource/UserResourceAdaptor.java 2010-06-14
16:48:35 UTC (rev 17624)
@@ -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);
+ }
+ }
+
+}
Modified:
root/core/branches/jsr-330/impl/src/main/resources/META-INF/resources/richfaces-base-component.js
===================================================================
---
root/core/branches/jsr-330/impl/src/main/resources/META-INF/resources/richfaces-base-component.js 2010-06-13
17:38:26 UTC (rev 17623)
+++
root/core/branches/jsr-330/impl/src/main/resources/META-INF/resources/richfaces-base-component.js 2010-06-14
16:48:35 UTC (rev 17624)
@@ -150,7 +150,8 @@
* @function
* @name RichFaces.BaseComponent#destroy
*
- * */
+ * */
+ // TODO: add to article
destroy: function() {
}
};
Modified:
root/core/branches/jsr-330/impl/src/main/resources/META-INF/resources/richfaces-event.js
===================================================================
---
root/core/branches/jsr-330/impl/src/main/resources/META-INF/resources/richfaces-event.js 2010-06-13
17:38:26 UTC (rev 17623)
+++
root/core/branches/jsr-330/impl/src/main/resources/META-INF/resources/richfaces-event.js 2010-06-14
16:48:35 UTC (rev 17624)
@@ -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;
},
Deleted:
root/core/branches/jsr-330/impl/src/test/java/org/ajax4jsf/util/NumericStreamsTest.java
===================================================================
---
root/core/branches/jsr-330/impl/src/test/java/org/ajax4jsf/util/NumericStreamsTest.java 2010-06-13
17:38:26 UTC (rev 17623)
+++
root/core/branches/jsr-330/impl/src/test/java/org/ajax4jsf/util/NumericStreamsTest.java 2010-06-14
16:48:35 UTC (rev 17624)
@@ -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/branches/jsr-330/impl/src/test/java/org/richfaces/resource/AbstractBaseResourceTest.java
===================================================================
---
root/core/branches/jsr-330/impl/src/test/java/org/richfaces/resource/AbstractBaseResourceTest.java 2010-06-13
17:38:26 UTC (rev 17623)
+++
root/core/branches/jsr-330/impl/src/test/java/org/richfaces/resource/AbstractBaseResourceTest.java 2010-06-14
16:48:35 UTC (rev 17624)
@@ -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/branches/jsr-330/impl/src/test/java/org/richfaces/resource/AbstractCacheableResourceTest.java
===================================================================
---
root/core/branches/jsr-330/impl/src/test/java/org/richfaces/resource/AbstractCacheableResourceTest.java 2010-06-13
17:38:26 UTC (rev 17623)
+++
root/core/branches/jsr-330/impl/src/test/java/org/richfaces/resource/AbstractCacheableResourceTest.java 2010-06-14
16:48:35 UTC (rev 17624)
@@ -276,7 +276,7 @@
}
@Override
- protected String getEntityTag(FacesContext context) {
+ public String getEntityTag(FacesContext context) {
return entityTag;
}
Modified:
root/core/branches/jsr-330/impl/src/test/java/org/richfaces/resource/CacheableResourceImpl.java
===================================================================
---
root/core/branches/jsr-330/impl/src/test/java/org/richfaces/resource/CacheableResourceImpl.java 2010-06-13
17:38:26 UTC (rev 17623)
+++
root/core/branches/jsr-330/impl/src/test/java/org/richfaces/resource/CacheableResourceImpl.java 2010-06-14
16:48:35 UTC (rev 17624)
@@ -83,7 +83,7 @@
}
@Override
- protected Date getExpires(FacesContext context) {
+ public Date getExpires(FacesContext context) {
return ResourceHandlerImplTest.expires;
}
}
Modified:
root/core/branches/jsr-330/impl/src/test/java/org/richfaces/resource/ResourceHandlerImplTest.java
===================================================================
---
root/core/branches/jsr-330/impl/src/test/java/org/richfaces/resource/ResourceHandlerImplTest.java 2010-06-13
17:38:26 UTC (rev 17623)
+++
root/core/branches/jsr-330/impl/src/test/java/org/richfaces/resource/ResourceHandlerImplTest.java 2010-06-14
16:48:35 UTC (rev 17624)
@@ -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/branches/jsr-330/impl/src/test/java/org/richfaces/resource/StateHolderResourceImpl.java
===================================================================
---
root/core/branches/jsr-330/impl/src/test/java/org/richfaces/resource/StateHolderResourceImpl.java 2010-06-13
17:38:26 UTC (rev 17623)
+++
root/core/branches/jsr-330/impl/src/test/java/org/richfaces/resource/StateHolderResourceImpl.java 2010-06-14
16:48:35 UTC (rev 17624)
@@ -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/branches/jsr-330/impl/src/test/resources/javascript/richfaces-event-qunit.js
===================================================================
---
root/core/branches/jsr-330/impl/src/test/resources/javascript/richfaces-event-qunit.js 2010-06-13
17:38:26 UTC (rev 17623)
+++
root/core/branches/jsr-330/impl/src/test/resources/javascript/richfaces-event-qunit.js 2010-06-14
16:48:35 UTC (rev 17624)
@@ -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;
Modified: root/core/branches/jsr-330/impl/src/test/resources/resources/full.css
===================================================================
--- root/core/branches/jsr-330/impl/src/test/resources/resources/full.css 2010-06-13
17:38:26 UTC (rev 17623)
+++ root/core/branches/jsr-330/impl/src/test/resources/resources/full.css 2010-06-14
16:48:35 UTC (rev 17624)
@@ -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/branches/jsr-330/impl/src/test/resources/resources/importedEL.css
===================================================================
--- root/core/branches/jsr-330/impl/src/test/resources/resources/importedEL.css 2010-06-13
17:38:26 UTC (rev 17623)
+++ root/core/branches/jsr-330/impl/src/test/resources/resources/importedEL.css 2010-06-14
16:48:35 UTC (rev 17624)
@@ -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/branches/jsr-330/impl/src/test/resources/resources/resource.css
===================================================================
--- root/core/branches/jsr-330/impl/src/test/resources/resources/resource.css 2010-06-13
17:38:26 UTC (rev 17623)
+++ root/core/branches/jsr-330/impl/src/test/resources/resources/resource.css 2010-06-14
16:48:35 UTC (rev 17624)
@@ -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