Author: julien_viet
Date: 2010-04-01 10:24:25 -0400 (Thu, 01 Apr 2010)
New Revision: 2455
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/CompositeResourceResolver.java
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/MainResourceResolver.java
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/ResourceResolver.java
Log:
GTNPORTAL-1016 : Fix resource resolver error handling
GTNPORTAL-1017 : Avoid to create a String from a StringBuffer for providing a Reader as it
is possible to do that
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/CompositeResourceResolver.java
===================================================================
---
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/CompositeResourceResolver.java 2010-04-01
13:26:53 UTC (rev 2454)
+++
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/CompositeResourceResolver.java 2010-04-01
14:24:25 UTC (rev 2455)
@@ -19,8 +19,11 @@
package org.exoplatform.portal.resource;
+import org.apache.commons.io.input.CharSequenceReader;
+import org.gatein.common.logging.Logger;
+import org.gatein.common.logging.LoggerFactory;
+
import java.io.Reader;
-import java.io.StringReader;
import java.util.Map;
/**
@@ -38,18 +41,31 @@
*/
private final String portalContainerName;
+ /** . */
+ private final String prefix;
+
+ /** . */
+ private final Logger log = LoggerFactory.getLogger(CompositeResourceResolver.class);
+
public CompositeResourceResolver(String portalContainerName, Map<SkinKey,
SkinConfig> skins)
{
this.portalContainerName = portalContainerName;
this.skins = skins;
+ this.prefix = "/" + portalContainerName + "/resource/";
}
public Resource resolve(String path)
{
- if (path.startsWith("/" + portalContainerName + "/resource/")
&& path.endsWith(".css"))
+ if (path == null)
{
- final StringBuffer sb = new StringBuffer();
- String encoded = path.substring(("/" + portalContainerName +
"/resource/").length());
+ throw new NullPointerException("No null path is accepted");
+ }
+
+ //
+ if (path.startsWith(prefix) && path.endsWith(".css"))
+ {
+ final StringBuilder sb = new StringBuilder();
+ String encoded = path.substring(prefix.length());
String blah[] = encoded.split("/");
int len = (blah.length >> 1) << 1;
for (int i = 0; i < len; i += 2)
@@ -68,12 +84,16 @@
@Override
public Reader read()
{
- return new StringReader(sb.toString());
+ return new CharSequenceReader(sb);
}
};
}
else
{
+ if (log.isDebugEnabled())
+ {
+ log.debug("Could not resolve path value");
+ }
return null;
}
}
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/MainResourceResolver.java
===================================================================
---
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/MainResourceResolver.java 2010-04-01
13:26:53 UTC (rev 2454)
+++
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/MainResourceResolver.java 2010-04-01
14:24:25 UTC (rev 2455)
@@ -19,6 +19,9 @@
package org.exoplatform.portal.resource;
+import org.gatein.common.logging.Logger;
+import org.gatein.common.logging.LoggerFactory;
+
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;
@@ -32,12 +35,18 @@
class MainResourceResolver implements ResourceResolver
{
+ /** . */
final Map<String, SimpleResourceContext> contexts;
+ /** . */
final CopyOnWriteArrayList<ResourceResolver> resolvers;
+ /** . */
final Map<SkinKey, SkinConfig> skins;
+ /** . */
+ private final Logger log = LoggerFactory.getLogger(MainResourceResolver.class);
+
public MainResourceResolver(String portalContainerName, Map<SkinKey, SkinConfig>
skins)
{
this.skins = skins;
@@ -62,6 +71,12 @@
public Resource resolve(String path)
{
+ if (path == null)
+ {
+ throw new NullPointerException("No null path is accepted");
+ }
+
+ //
for (ResourceResolver resolver : resolvers)
{
Resource res = resolver.resolve(path);
@@ -75,6 +90,16 @@
int i1 = path.indexOf("/", 2);
String targetedContextPath = path.substring(0, i1);
SimpleResourceContext context = contexts.get(targetedContextPath);
- return context.getResource(path.substring(i1));
+
+ //
+ if (context == null)
+ {
+ log.warn("Could not resolve " + targetedContextPath + " resource
for path " + path);
+ return null;
+ }
+ else
+ {
+ return context.getResource(path.substring(i1));
+ }
}
}
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/ResourceResolver.java
===================================================================
---
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/ResourceResolver.java 2010-04-01
13:26:53 UTC (rev 2454)
+++
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/ResourceResolver.java 2010-04-01
14:24:25 UTC (rev 2455)
@@ -29,11 +29,13 @@
{
/**
- * Returns a reader for the provided path or null if the resource cannot be resolved.
+ * Returns a {@link org.exoplatform.portal.resource.Resource} for the provided path or
null if the resource cannot be resolved.
*
* @param path the path
- * @return a reader
+ * @return a reader
+ * @throws NullPointerException if the path argument is null
+ * @throws IllegalStateException when
*/
- Resource resolve(String path);
+ Resource resolve(String path) throws NullPointerException;
}
Show replies by date