Author: nbelaevski
Date: 2010-07-05 18:37:01 -0400 (Mon, 05 Jul 2010)
New Revision: 17725
Removed:
root/core/trunk/impl/src/main/java/org/richfaces/resource/LegacyResourceCodec.java
Modified:
root/core/trunk/api/src/main/java/org/richfaces/resource/ResourceCodec.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/test/java/org/richfaces/resource/AbstractBaseResourceTest.java
Log:
Added libraryName support for dynamic resources
Modified: root/core/trunk/api/src/main/java/org/richfaces/resource/ResourceCodec.java
===================================================================
--- root/core/trunk/api/src/main/java/org/richfaces/resource/ResourceCodec.java 2010-07-05
18:38:30 UTC (rev 17724)
+++ root/core/trunk/api/src/main/java/org/richfaces/resource/ResourceCodec.java 2010-07-05
22:37:01 UTC (rev 17725)
@@ -11,12 +11,15 @@
*/
public interface ResourceCodec {
- public String encodeResourceRequestPath(FacesContext context, String resourceName,
Object resourceData, String resourceVersion);
+ public String encodeResourceRequestPath(FacesContext context, String libraryName,
String resourceName,
+ Object resourceData, String resourceVersion);
public String encodeJSFMapping(FacesContext context, String resourcePath);
public String decodeResourceName(FacesContext context, String requestPath);
+ public String decodeLibraryName(FacesContext context, String requestPath);
+
public Object decodeResourceData(FacesContext context, String requestPath);
public String decodeResourceVersion(FacesContext context, String requestPath);
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-05
18:38:30 UTC (rev 17724)
+++
root/core/trunk/impl/src/main/java/org/richfaces/resource/AbstractBaseResource.java 2010-07-05
22:37:01 UTC (rev 17725)
@@ -155,10 +155,12 @@
// TODO - cache resource request path in request scope
FacesContext context = FacesContext.getCurrentInstance();
ResourceCodec resourceCodec = ServiceTracker.getService(context,
ResourceCodec.class);
+ String libraryName = getLibraryName();
String resourceName = getResourceName();
Object resourceData = Util.saveResourceState(context, this);
String resourceVersion = getResourceVersion();
- String resourceUri = resourceCodec.encodeResourceRequestPath(context,
resourceName, resourceData, resourceVersion);
+ String resourceUri = resourceCodec.encodeResourceRequestPath(context,
libraryName, resourceName,
+ resourceData, resourceVersion);
resourceUri = Util.encodeJSFURL(context, resourceUri);
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-05
18:38:30 UTC (rev 17724)
+++
root/core/trunk/impl/src/main/java/org/richfaces/resource/DefaultResourceCodec.java 2010-07-05
22:37:01 UTC (rev 17725)
@@ -35,10 +35,17 @@
private static final String RESOURCE_DATA_OBJECT_PARAM = "do";
+ private static final String LIBRARY_NAME_PARAM = "ln";
+
public String decodeResourceName(FacesContext context, String requestPath) {
return requestPath;
}
+ public String decodeLibraryName(FacesContext context, String requestPath) {
+ Map<String, String> paramMap =
context.getExternalContext().getRequestParameterMap();
+ return paramMap.get(LIBRARY_NAME_PARAM);
+ }
+
public Object decodeResourceData(FacesContext context, String requestPath) {
Map<String, String> paramMap =
context.getExternalContext().getRequestParameterMap();
@@ -59,8 +66,8 @@
return
context.getExternalContext().getRequestParameterMap().get(RESOURCE_VERSION_PARAM);
}
- private String encodeResource(FacesContext context, String resourceName, String
encodedResourceData,
- boolean dataIsBytesArray, String resourceVersion) {
+ private String encodeResource(FacesContext context, String libraryName, String
resourceName,
+ String encodedResourceData, boolean dataIsBytesArray, String resourceVersion) {
boolean parameterAppended = false;
@@ -94,7 +101,7 @@
return sb.toString();
}
- public String encodeResourceRequestPath(FacesContext context, String resourceName,
Object resourceData, String resourceVersion) {
+ public String encodeResourceRequestPath(FacesContext context, String libraryName,
String resourceName, Object resourceData, String resourceVersion) {
String encodedDataString = null;
boolean isBytesArray = false;
if (resourceData != null) {
@@ -107,7 +114,7 @@
}
return ResourceHandlerImpl.RICHFACES_RESOURCE_IDENTIFIER
- + encodeResource(context, resourceName, encodedDataString, isBytesArray,
resourceVersion);
+ + encodeResource(context, libraryName, resourceName, encodedDataString,
isBytesArray, resourceVersion);
}
public String encodeJSFMapping(FacesContext context, String resourcePath) {
@@ -126,7 +133,8 @@
String resourceVersionString = paramMap.get(RESOURCE_VERSION_PARAM);
- return encodeResource(context, decodeResourceName(context, requestPath),
+ return encodeResource(context, decodeLibraryName(context, requestPath),
+ decodeResourceName(context, requestPath),
resourceDataString, isBytesArray, resourceVersionString);
}
}
Deleted:
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-05
18:38:30 UTC (rev 17724)
+++
root/core/trunk/impl/src/main/java/org/richfaces/resource/LegacyResourceCodec.java 2010-07-05
22:37:01 UTC (rev 17725)
@@ -1,55 +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.richfaces.resource;
-
-import javax.faces.context.FacesContext;
-
-import org.richfaces.util.Util;
-
-public final class LegacyResourceCodec implements ResourceCodec {
-
- public String decodeResourceName(FacesContext context, String requestPath) {
- return Util.legacyDecodeResourceName(requestPath);
- }
-
- public Object decodeResourceData(FacesContext context, String requestPath) {
- return Util.legacyDecodeResourceData(requestPath);
- }
-
- public String decodeResourceVersion(FacesContext context, String requestPath) {
- return Util.legacyDecodeResourceVersion(requestPath);
- }
-
- 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/test/java/org/richfaces/resource/AbstractBaseResourceTest.java
===================================================================
---
root/core/trunk/impl/src/test/java/org/richfaces/resource/AbstractBaseResourceTest.java 2010-07-05
18:38:30 UTC (rev 17724)
+++
root/core/trunk/impl/src/test/java/org/richfaces/resource/AbstractBaseResourceTest.java 2010-07-05
22:37:01 UTC (rev 17725)
@@ -133,12 +133,15 @@
final ResourceCodec resourceCodec = EasyMock.createMock(ResourceCodec.class);
EasyMock.expect(resourceCodec.encodeResourceRequestPath(EasyMock.same(facesContext),
+ EasyMock.eq("custom.library"),
EasyMock.eq("org.richfaces.resource.MockStateAwareResource"),
- EasyMock.aryEq(resourceState.getBytes()),
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?l=custom.library");
EasyMock.expect(resourceCodec.encodeResourceRequestPath(EasyMock.same(facesContext),
+ EasyMock.eq("custom.library"),
EasyMock.eq("org.richfaces.resource.MockStateAwareResource"),
- EasyMock.eq(null),
EasyMock.eq("4_0_alpha"))).andReturn("/rfRes/Resource1/4_0_alpha");
+ EasyMock.eq(null),
EasyMock.eq("4_0_alpha"))).andReturn("/rfRes/Resource1/4_0_alpha?l=custom.library");
EasyMock.expect(resourceCodec.encodeResourceRequestPath(EasyMock.same(facesContext),
+ EasyMock.<String>isNull(),
EasyMock.eq("org.richfaces.resource.MockResource"),
EasyMock.eq(null),
EasyMock.eq("4_0_alpha"))).andReturn("/rfRes/Resource2/4_0_alpha");
EasyMock.replay(resourceCodec);
@@ -153,13 +156,13 @@
ServiceTracker.setInjector(injector);
MockStateAwareResourceImpl stateAwareResourceImpl = new
MockStateAwareResourceImpl();
-
+ stateAwareResourceImpl.setLibraryName("custom.library");
stateAwareResourceImpl.setVersion("4_0_alpha");
stateAwareResourceImpl.setState(resourceState);
assertEquals("org.richfaces.resource.MockStateAwareResource",
stateAwareResourceImpl.getResourceName());
- assertEquals("/rfRes/Resource0/4_0_alpha/data.jsf",
stateAwareResourceImpl.getRequestPath());
+ assertEquals("/rfRes/Resource0/4_0_alpha/data.jsf?l=custom.library",
stateAwareResourceImpl.getRequestPath());
stateAwareResourceImpl.setTransient(true);
- assertEquals("/rfRes/Resource1/4_0_alpha.jsf",
stateAwareResourceImpl.getRequestPath());
+ assertEquals("/rfRes/Resource1/4_0_alpha.jsf?l=custom.library",
stateAwareResourceImpl.getRequestPath());
MockResourceImpl resourceImpl = new MockResourceImpl();