Author: nbelaevski
Date: 2010-07-05 08:55:55 -0400 (Mon, 05 Jul 2010)
New Revision: 17716
Added:
root/core/trunk/api/src/main/java/org/richfaces/resource/Java2DUserResourceWrapper.java
root/core/trunk/api/src/main/java/org/richfaces/resource/UserResourceWrapper.java
root/core/trunk/impl/src/main/java/org/richfaces/resource/BaseResourceWrapper.java
root/core/trunk/impl/src/main/java/org/richfaces/resource/Java2DUserResourceWrapperImpl.java
root/core/trunk/impl/src/main/java/org/richfaces/resource/UserResourceWrapperImpl.java
Removed:
root/core/trunk/impl/src/main/java/org/richfaces/resource/Java2DUserResourceAdaptor.java
root/core/trunk/impl/src/main/java/org/richfaces/resource/UserResourceAdaptor.java
Modified:
root/core/trunk/impl/src/main/java/org/ajax4jsf/context/ContextInitParameters.java
root/core/trunk/impl/src/main/java/org/richfaces/resource/AbstractBaseResource.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/ResourceCodec.java
root/core/trunk/impl/src/main/java/org/richfaces/resource/ResourceHandlerImpl.java
root/core/trunk/impl/src/main/java/org/richfaces/util/Util.java
root/core/trunk/impl/src/test/java/org/richfaces/resource/AbstractBaseResourceTest.java
Log:
Resources fwk refactoring
Added:
root/core/trunk/api/src/main/java/org/richfaces/resource/Java2DUserResourceWrapper.java
===================================================================
---
root/core/trunk/api/src/main/java/org/richfaces/resource/Java2DUserResourceWrapper.java
(rev 0)
+++
root/core/trunk/api/src/main/java/org/richfaces/resource/Java2DUserResourceWrapper.java 2010-07-05
12:55:55 UTC (rev 17716)
@@ -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.resource;
+
+import javax.faces.FacesWrapper;
+
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public interface Java2DUserResourceWrapper extends FacesWrapper<Java2DUserResource>
{
+
+ public Java2DUserResource getWrapped();
+
+}
Added: root/core/trunk/api/src/main/java/org/richfaces/resource/UserResourceWrapper.java
===================================================================
--- root/core/trunk/api/src/main/java/org/richfaces/resource/UserResourceWrapper.java
(rev 0)
+++
root/core/trunk/api/src/main/java/org/richfaces/resource/UserResourceWrapper.java 2010-07-05
12:55:55 UTC (rev 17716)
@@ -0,0 +1,34 @@
+/*
+ * 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.FacesWrapper;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public interface UserResourceWrapper extends FacesWrapper<UserResource> {
+
+ public UserResource getWrapped();
+
+}
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-07-03
00:20:40 UTC (rev 17715)
+++
root/core/trunk/impl/src/main/java/org/ajax4jsf/context/ContextInitParameters.java 2010-07-05
12:55:55 UTC (rev 17716)
@@ -21,8 +21,6 @@
package org.ajax4jsf.context;
-import java.util.concurrent.ConcurrentMap;
-
import javax.el.ExpressionFactory;
import javax.el.ValueExpression;
import javax.faces.FacesException;
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-07-03
00:20:40 UTC (rev 17715)
+++
root/core/trunk/impl/src/main/java/org/richfaces/resource/AbstractBaseResource.java 2010-07-05
12:55:55 UTC (rev 17716)
@@ -158,9 +158,9 @@
String resourceName = getResourceName();
Object resourceData = Util.saveResourceState(context, this);
String resourceVersion = getResourceVersion();
- String resourceUri = resourceCodec.encodeResource(context, resourceName,
resourceData, resourceVersion);
+ String resourceUri = resourceCodec.encodeResourceRequestPath(context,
resourceName, resourceData, resourceVersion);
- resourceUri = Util.encodeResourceURL(context, resourceUri);
+ resourceUri = Util.encodeJSFURL(context, resourceUri);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(MessageFormat.format("Request path for {0} resource is:
{1}", String.valueOf(resourceName),
Added: root/core/trunk/impl/src/main/java/org/richfaces/resource/BaseResourceWrapper.java
===================================================================
--- root/core/trunk/impl/src/main/java/org/richfaces/resource/BaseResourceWrapper.java
(rev 0)
+++
root/core/trunk/impl/src/main/java/org/richfaces/resource/BaseResourceWrapper.java 2010-07-05
12:55:55 UTC (rev 17716)
@@ -0,0 +1,135 @@
+/*
+ * 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.util.Date;
+import java.util.Map;
+
+import javax.faces.FacesWrapper;
+import javax.faces.component.StateHolder;
+import javax.faces.context.FacesContext;
+
+import org.richfaces.util.Util;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public abstract class BaseResourceWrapper<T> extends AbstractCacheableResource
implements VersionedResource, StateHolder,
+ FacesWrapper<T> {
+
+ private T resourceObject;
+
+ public BaseResourceWrapper(T resourceObject) {
+ super();
+ this.resourceObject = resourceObject;
+ }
+
+ protected abstract Map<String, String> getWrappedResourceResponseHeaders();
+
+ @Override
+ public Map<String, String> getResponseHeaders() {
+ Map<String, String> headers = super.getResponseHeaders();
+
+ Map<String, String> userHeaders = getWrappedResourceResponseHeaders();
+ if (userHeaders != null) {
+ headers.putAll(userHeaders);
+ }
+
+ return headers;
+ }
+
+ public String getVersion() {
+ if (resourceObject instanceof VersionedResource) {
+ return ((VersionedResource) resourceObject).getVersion();
+ }
+
+ return null;
+ }
+
+ @Override
+ public boolean isCacheable(FacesContext context) {
+ if (resourceObject instanceof CacheableResource) {
+ return ((CacheableResource) resourceObject).isCacheable(context);
+ }
+
+ return false;
+ }
+
+ @Override
+ public Date getExpires(FacesContext context) {
+ if (resourceObject instanceof CacheableResource) {
+ return ((CacheableResource) resourceObject).getExpires(context);
+ }
+
+ return null;
+ }
+
+ @Override
+ public String getEntityTag(FacesContext context) {
+ if (resourceObject instanceof CacheableResource) {
+ return ((CacheableResource) resourceObject).getEntityTag(context);
+ }
+
+ return null;
+ }
+
+ @Override
+ public int getTimeToLive(FacesContext context) {
+ if (resourceObject instanceof CacheableResource) {
+ return ((CacheableResource) resourceObject).getTimeToLive(context);
+ }
+
+ return 0;
+ }
+
+ public boolean isTransient() {
+ if (resourceObject instanceof StateHolderResource) {
+ return ((StateHolderResource) resourceObject).isTransient();
+ }
+
+ if (resourceObject instanceof StateHolder) {
+ return ((StateHolder) resourceObject).isTransient();
+ }
+
+ return true;
+ }
+
+ public void setTransient(boolean newTransientValue) {
+ if (resourceObject instanceof StateHolder) {
+ ((StateHolder) resourceObject).setTransient(newTransientValue);
+ }
+ }
+
+ public Object saveState(FacesContext context) {
+ return Util.saveResourceState(context, resourceObject);
+ }
+
+ public void restoreState(FacesContext context, Object state) {
+ Util.restoreResourceState(context, resourceObject, state);
+ }
+
+ public T getWrapped() {
+ return resourceObject;
+ }
+
+}
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-07-03
00:20:40 UTC (rev 17715)
+++
root/core/trunk/impl/src/main/java/org/richfaces/resource/DefaultResourceCodec.java 2010-07-05
12:55:55 UTC (rev 17716)
@@ -94,7 +94,7 @@
return sb.toString();
}
- public String encodeResource(FacesContext context, String resourceName, Object
resourceData, String resourceVersion) {
+ public String encodeResourceRequestPath(FacesContext context, String resourceName,
Object resourceData, String resourceVersion) {
String encodedDataString = null;
boolean isBytesArray = false;
if (resourceData != null) {
@@ -110,6 +110,10 @@
+ encodeResource(context, resourceName, encodedDataString, isBytesArray,
resourceVersion);
}
+ public String encodeJSFMapping(FacesContext context, String resourcePath) {
+ return Util.encodeJSFURL(context, resourcePath);
+ }
+
public String getResourceKey(FacesContext context, String requestPath) {
Map<String, String> paramMap =
context.getExternalContext().getRequestParameterMap();
Deleted:
root/core/trunk/impl/src/main/java/org/richfaces/resource/Java2DUserResourceAdaptor.java
===================================================================
---
root/core/trunk/impl/src/main/java/org/richfaces/resource/Java2DUserResourceAdaptor.java 2010-07-03
00:20:40 UTC (rev 17715)
+++
root/core/trunk/impl/src/main/java/org/richfaces/resource/Java2DUserResourceAdaptor.java 2010-07-05
12:55:55 UTC (rev 17716)
@@ -1,163 +0,0 @@
-/*
- * 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();
- }
-
-}
Added:
root/core/trunk/impl/src/main/java/org/richfaces/resource/Java2DUserResourceWrapperImpl.java
===================================================================
---
root/core/trunk/impl/src/main/java/org/richfaces/resource/Java2DUserResourceWrapperImpl.java
(rev 0)
+++
root/core/trunk/impl/src/main/java/org/richfaces/resource/Java2DUserResourceWrapperImpl.java 2010-07-05
12:55:55 UTC (rev 17716)
@@ -0,0 +1,160 @@
+/*
+ * 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 Java2DUserResourceWrapperImpl extends
BaseResourceWrapper<Java2DUserResource>
+ implements Java2DUserResourceWrapper {
+
+ public Java2DUserResourceWrapperImpl(Java2DUserResource resourceObject) {
+ super(resourceObject);
+ }
+
+ public InputStream getInputStream() throws IOException {
+ Java2DUserResource j2DUserResource = getWrapped();
+ 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 getWrapped().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;
+ }
+ }
+
+ @Override
+ protected Map<String, String> getWrappedResourceResponseHeaders() {
+ return getWrapped().getResponseHeaders();
+ }
+
+ @Override
+ protected Date getLastModified(FacesContext context) {
+ return getWrapped().getLastModified();
+ }
+}
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-07-03
00:20:40 UTC (rev 17715)
+++
root/core/trunk/impl/src/main/java/org/richfaces/resource/LegacyResourceCodec.java 2010-07-05
12:55:55 UTC (rev 17716)
@@ -39,11 +39,15 @@
return Util.legacyDecodeResourceVersion(requestPath);
}
- public String encodeResource(FacesContext context, String resourceName, Object
resourceData, String resourceVersion) {
+ public String encodeResourceRequestPath(FacesContext context, String resourceName,
Object resourceData, String resourceVersion) {
return ResourceHandlerImpl.RICHFACES_RESOURCE_IDENTIFIER
+ Util.legacyEncodeResourceData(resourceName, resourceData,
resourceVersion);
}
+ public String encodeJSFMapping(FacesContext context, String resourcePath) {
+ return Util.encodeJSFURL(context, resourcePath);
+ }
+
public String getResourceKey(FacesContext context, String requestPath) {
return requestPath;
}
Modified: root/core/trunk/impl/src/main/java/org/richfaces/resource/ResourceCodec.java
===================================================================
---
root/core/trunk/impl/src/main/java/org/richfaces/resource/ResourceCodec.java 2010-07-03
00:20:40 UTC (rev 17715)
+++
root/core/trunk/impl/src/main/java/org/richfaces/resource/ResourceCodec.java 2010-07-05
12:55:55 UTC (rev 17716)
@@ -11,8 +11,10 @@
*/
public interface ResourceCodec {
- public String encodeResource(FacesContext context, String resourceName, Object
resourceData, String resourceVersion);
-
+ public String encodeResourceRequestPath(FacesContext context, String resourceName,
Object resourceData, String resourceVersion);
+
+ public String encodeJSFMapping(FacesContext context, String resourcePath);
+
public String decodeResourceName(FacesContext context, String requestPath);
public Object decodeResourceData(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-07-03
00:20:40 UTC (rev 17715)
+++
root/core/trunk/impl/src/main/java/org/richfaces/resource/ResourceHandlerImpl.java 2010-07-05
12:55:55 UTC (rev 17716)
@@ -44,8 +44,8 @@
import org.ajax4jsf.cache.Cache;
import org.richfaces.application.ServiceTracker;
import org.richfaces.log.RichfacesLogger;
+import org.richfaces.util.RequestStateManager.BooleanRequestStateVariable;
import org.richfaces.util.Util;
-import org.richfaces.util.RequestStateManager.BooleanRequestStateVariable;
import org.slf4j.Logger;
/**
@@ -415,11 +415,11 @@
if (Java2DUserResource.class.isAssignableFrom(loadedClass)) {
Java2DUserResource java2DUserResource = (Java2DUserResource)
loadedClass.newInstance();
wrappedResource = java2DUserResource;
- resource = new UserResourceAdaptor(new
Java2DUserResourceAdaptor(java2DUserResource), java2DUserResource);
+ resource = new
Java2DUserResourceWrapperImpl(java2DUserResource);
} else if (UserResource.class.isAssignableFrom(loadedClass)) {
UserResource userResource = (UserResource)
loadedClass.newInstance();
wrappedResource = userResource;
- resource = new UserResourceAdaptor(userResource, userResource);
+ resource = new UserResourceWrapperImpl(userResource);
} else {
Class<? extends Resource> resourceClass =
loadedClass.asSubclass(Resource.class);
resource = (Resource) resourceClass.newInstance();
Deleted:
root/core/trunk/impl/src/main/java/org/richfaces/resource/UserResourceAdaptor.java
===================================================================
---
root/core/trunk/impl/src/main/java/org/richfaces/resource/UserResourceAdaptor.java 2010-07-03
00:20:40 UTC (rev 17715)
+++
root/core/trunk/impl/src/main/java/org/richfaces/resource/UserResourceAdaptor.java 2010-07-05
12:55:55 UTC (rev 17716)
@@ -1,152 +0,0 @@
-/*
- * 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;
-
-import javax.faces.component.StateHolder;
-import javax.faces.context.FacesContext;
-
-import org.richfaces.util.Util;
-
-/**
- * @author Nick Belaevski
- *
- */
-public class UserResourceAdaptor extends AbstractCacheableResource implements
VersionedResource, StateHolder {
-
- 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();
- }
-
- if (wrappedResource instanceof StateHolder) {
- return ((StateHolder) wrappedResource).isTransient();
- }
-
- return true;
- }
-
- public void setTransient(boolean newTransientValue) {
- if (wrappedResource instanceof StateHolder) {
- ((StateHolder) wrappedResource).setTransient(newTransientValue);
- }
- }
-
- public Object saveState(FacesContext context) {
- return Util.saveResourceState(context, wrappedResource);
- }
-
- public void restoreState(FacesContext context, Object state) {
- Util.restoreResourceState(context, wrappedResource, state);
- }
-
-}
Added:
root/core/trunk/impl/src/main/java/org/richfaces/resource/UserResourceWrapperImpl.java
===================================================================
---
root/core/trunk/impl/src/main/java/org/richfaces/resource/UserResourceWrapperImpl.java
(rev 0)
+++
root/core/trunk/impl/src/main/java/org/richfaces/resource/UserResourceWrapperImpl.java 2010-07-05
12:55:55 UTC (rev 17716)
@@ -0,0 +1,66 @@
+/*
+ * 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;
+
+import javax.faces.context.FacesContext;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class UserResourceWrapperImpl extends BaseResourceWrapper<UserResource>
implements UserResourceWrapper {
+
+ public UserResourceWrapperImpl(UserResource resourceObject) {
+ super(resourceObject);
+ }
+
+ @Override
+ public InputStream getInputStream() throws IOException {
+ return getWrapped().getInputStream();
+ }
+
+ @Override
+ protected Map<String, String> getWrappedResourceResponseHeaders() {
+ return getWrapped().getResponseHeaders();
+ }
+
+ @Override
+ public String getContentType() {
+ return getWrapped().getContentType();
+ }
+
+ @Override
+ protected int getContentLength(FacesContext context) {
+ return getWrapped().getContentLength();
+ }
+
+ @Override
+ protected Date getLastModified(FacesContext context) {
+ return getWrapped().getLastModified();
+ }
+
+}
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-07-03 00:20:40
UTC (rev 17715)
+++ root/core/trunk/impl/src/main/java/org/richfaces/util/Util.java 2010-07-05 12:55:55
UTC (rev 17716)
@@ -379,7 +379,7 @@
return data;
}
- public static String encodeResourceURL(FacesContext context, String url) {
+ public static String encodeJSFURL(FacesContext context, String url) {
String mapping = Util.getMappingForRequest(context);
String resourcePath = url;
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-07-03
00:20:40 UTC (rev 17715)
+++
root/core/trunk/impl/src/test/java/org/richfaces/resource/AbstractBaseResourceTest.java 2010-07-05
12:55:55 UTC (rev 17716)
@@ -41,9 +41,9 @@
import org.easymock.EasyMock;
import org.jboss.test.faces.AbstractFacesTest;
import org.richfaces.application.ServiceTracker;
-import org.richfaces.jsr330.Module;
import org.richfaces.jsr330.InjectorConfig;
import org.richfaces.jsr330.InjectorImpl;
+import org.richfaces.jsr330.Module;
import org.richfaces.util.Util;
/**
@@ -132,13 +132,13 @@
String resourceState = "data";
final ResourceCodec resourceCodec = EasyMock.createMock(ResourceCodec.class);
- EasyMock.expect(resourceCodec.encodeResource(EasyMock.same(facesContext),
+
EasyMock.expect(resourceCodec.encodeResourceRequestPath(EasyMock.same(facesContext),
EasyMock.eq("org.richfaces.resource.MockStateAwareResource"),
EasyMock.aryEq(resourceState.getBytes()),
EasyMock.eq("4_0_alpha"))).andReturn("/rfRes/Resource0/4_0_alpha/data");
- EasyMock.expect(resourceCodec.encodeResource(EasyMock.same(facesContext),
+
EasyMock.expect(resourceCodec.encodeResourceRequestPath(EasyMock.same(facesContext),
EasyMock.eq("org.richfaces.resource.MockStateAwareResource"),
EasyMock.eq(null),
EasyMock.eq("4_0_alpha"))).andReturn("/rfRes/Resource1/4_0_alpha");
- EasyMock.expect(resourceCodec.encodeResource(EasyMock.same(facesContext),
+
EasyMock.expect(resourceCodec.encodeResourceRequestPath(EasyMock.same(facesContext),
EasyMock.eq("org.richfaces.resource.MockResource"),
EasyMock.eq(null),
EasyMock.eq("4_0_alpha"))).andReturn("/rfRes/Resource2/4_0_alpha");
EasyMock.replay(resourceCodec);