[Jsptest-svn-commits] SF.net SVN: jsptest: [200] trunk
Status: Alpha
Brought to you by:
lkoskela
|
From: <lko...@us...> - 2008-04-04 12:53:13
|
Revision: 200
http://jsptest.svn.sourceforge.net/jsptest/?rev=200&view=rev
Author: lkoskela
Date: 2008-04-04 05:53:08 -0700 (Fri, 04 Apr 2008)
Log Message:
-----------
Refactored TLD location mapping into a separate class. Fixed ClasspathTldLocator.
Modified Paths:
--------------
trunk/jsptest-acceptance/jsptest-acceptance-jsp21/pom.xml
trunk/jsptest-jsp20/src/main/java/net/sf/jsptest/compiler/jsp20/mock/taglibs/ClasspathTldLocator.java
trunk/jsptest-jsp20/src/main/java/net/sf/jsptest/compiler/jsp20/mock/taglibs/MockTldLocationsCache.java
Added Paths:
-----------
trunk/jsptest-jsp20/src/main/java/net/sf/jsptest/compiler/jsp20/mock/taglibs/TldUriMappings.java
trunk/jsptest-jsp20/src/test/java/net/sf/jsptest/compiler/jsp20/mock/
trunk/jsptest-jsp20/src/test/java/net/sf/jsptest/compiler/jsp20/mock/taglibs/
trunk/jsptest-jsp20/src/test/java/net/sf/jsptest/compiler/jsp20/mock/taglibs/TestClasspathTldLocator.java
trunk/jsptest-jsp20/src/test/resources/META-INF/
trunk/jsptest-jsp20/src/test/resources/META-INF/MANIFEST.MF
trunk/jsptest-jsp20/src/test/resources/META-INF/exists.tld
Removed Paths:
-------------
trunk/jsptest-jsp20/src/main/java/net/sf/jsptest/compiler/jsp20/mock/MockTldLocationsCache.java
Modified: trunk/jsptest-acceptance/jsptest-acceptance-jsp21/pom.xml
===================================================================
--- trunk/jsptest-acceptance/jsptest-acceptance-jsp21/pom.xml 2008-04-04 07:01:10 UTC (rev 199)
+++ trunk/jsptest-acceptance/jsptest-acceptance-jsp21/pom.xml 2008-04-04 12:53:08 UTC (rev 200)
@@ -7,7 +7,7 @@
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>jsptest-acceptance-jsp21</artifactId>
- <version>0.13-SNAPSHOT</version>
+ <version>0.14-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Acceptance tests for the JspTest variant for the JSP 2.1 specification.</name>
<description />
Deleted: trunk/jsptest-jsp20/src/main/java/net/sf/jsptest/compiler/jsp20/mock/MockTldLocationsCache.java
===================================================================
--- trunk/jsptest-jsp20/src/main/java/net/sf/jsptest/compiler/jsp20/mock/MockTldLocationsCache.java 2008-04-04 07:01:10 UTC (rev 199)
+++ trunk/jsptest-jsp20/src/main/java/net/sf/jsptest/compiler/jsp20/mock/MockTldLocationsCache.java 2008-04-04 12:53:08 UTC (rev 200)
@@ -1,72 +0,0 @@
-/*
- * Copyright 2007 Lasse Koskela.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package net.sf.jsptest.compiler.jsp20.mock;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.servlet.ServletContext;
-
-import org.apache.jasper.JasperException;
-import org.apache.jasper.compiler.TldLocationsCache;
-
-/**
- * @author Lasse Koskela
- */
-public class MockTldLocationsCache extends TldLocationsCache {
- private Map standardTlds = new HashMap() {
- {
- put("http://java.sun.com/jstl/core", "/WEB-INF/c.tld");
- put("http://java.sun.com/jstl/sql", "/WEB-INF/sql.tld");
- put("http://java.sun.com/jstl/xml", "/WEB-INF/x.tld");
- put("http://java.sun.com/jstl/functions",
- "/WEB-INF/fn.tld");
- put("http://java.sun.com/jstl/fmt", "/WEB-INF/fmt.tld");
- put("http://java.sun.com/jsp/jstl/core", "/WEB-INF/c.tld");
- put("http://java.sun.com/jsp/jstl/sql",
- "/WEB-INF/sql.tld");
- put("http://java.sun.com/jsp/jstl/xml", "/WEB-INF/x.tld");
- put("http://java.sun.com/jsp/jstl/functions",
- "/WEB-INF/fn.tld");
- put("http://java.sun.com/jsp/jstl/fmt",
- "/WEB-INF/fmt.tld");
- }
- };
-
- private TldLocationsCache realCache;
-
- public MockTldLocationsCache(TldLocationsCache delegate,
- ServletContext ctx) {
- this(delegate, ctx, true);
- }
-
- public MockTldLocationsCache(TldLocationsCache delegate,
- ServletContext ctx, boolean redeployMode) {
- super(ctx, redeployMode);
- this.realCache = delegate;
- }
-
- public String[] getLocation(String uri) throws JasperException {
- // TODO: Optimize. This call to getLocation(String) can take a full second.
- String[] location = realCache.getLocation(uri);
- if (location == null && standardTlds.containsKey(uri)) {
- location = new String[] { (String) standardTlds.get(uri),
- null };
- }
- return location;
- }
-}
Modified: trunk/jsptest-jsp20/src/main/java/net/sf/jsptest/compiler/jsp20/mock/taglibs/ClasspathTldLocator.java
===================================================================
--- trunk/jsptest-jsp20/src/main/java/net/sf/jsptest/compiler/jsp20/mock/taglibs/ClasspathTldLocator.java 2008-04-04 07:01:10 UTC (rev 199)
+++ trunk/jsptest-jsp20/src/main/java/net/sf/jsptest/compiler/jsp20/mock/taglibs/ClasspathTldLocator.java 2008-04-04 12:53:08 UTC (rev 200)
@@ -20,16 +20,16 @@
public class ClasspathTldLocator implements TldLocator {
- public TldLocation find(String filename) {
- try {
- String pathInsideArchive = "META-INF/" + filename;
- URL resource = getClass().getResource(pathInsideArchive);
- if (resource != null) {
- return TldLocation.foundFromClassPath(resource,
- pathInsideArchive);
- }
- } catch (Exception ignored) {
- }
- return TldLocation.notFound();
- }
+ public TldLocation find(String filename) {
+ try {
+ String pathInsideArchive = "/META-INF/" + filename;
+ URL resource = getClass().getResource(pathInsideArchive);
+ if (resource != null) {
+ return TldLocation.foundFromClassPath(resource,
+ pathInsideArchive);
+ }
+ } catch (Exception ignored) {
+ }
+ return TldLocation.notFound();
+ }
}
\ No newline at end of file
Modified: trunk/jsptest-jsp20/src/main/java/net/sf/jsptest/compiler/jsp20/mock/taglibs/MockTldLocationsCache.java
===================================================================
--- trunk/jsptest-jsp20/src/main/java/net/sf/jsptest/compiler/jsp20/mock/taglibs/MockTldLocationsCache.java 2008-04-04 07:01:10 UTC (rev 199)
+++ trunk/jsptest-jsp20/src/main/java/net/sf/jsptest/compiler/jsp20/mock/taglibs/MockTldLocationsCache.java 2008-04-04 12:53:08 UTC (rev 200)
@@ -16,8 +16,8 @@
package net.sf.jsptest.compiler.jsp20.mock.taglibs;
-import java.util.HashMap;
-import java.util.Map;
+import java.util.Iterator;
+import java.util.List;
import javax.servlet.ServletContext;
@@ -29,58 +29,46 @@
*/
public class MockTldLocationsCache extends TldLocationsCache {
- private Map standardTlds = new HashMap() {
- {
- put("http://java.sun.com/jstl/core", "c.tld");
- put("http://java.sun.com/jstl/sql", "sql.tld");
- put("http://java.sun.com/jstl/xml", "x.tld");
- put("http://java.sun.com/jstl/fmt", "fmt.tld");
- put("http://java.sun.com/jstl/functions", "fn.tld");
+ private TldUriMappings standardTlds;
- put("http://java.sun.com/jstl/core-rt", "c-rt.tld");
- put("http://java.sun.com/jstl/sql-rt", "sql-rt.tld");
- put("http://java.sun.com/jstl/xml-rt", "x-rt.tld");
- put("http://java.sun.com/jstl/fmt-rt", "fmt-rt.tld");
- put("http://java.sun.com/jstl/functions-rt", "fn-rt.tld");
+ private TldLocationsCache realCache;
- put("http://java.sun.com/jsp/jstl/core", "c.tld");
- put("http://java.sun.com/jsp/jstl/sql", "sql.tld");
- put("http://java.sun.com/jsp/jstl/xml", "x.tld");
- put("http://java.sun.com/jsp/jstl/fmt", "fmt.tld");
- put("http://java.sun.com/jsp/jstl/functions", "fn.tld");
- }
- };
+ private String webRoot;
- private TldLocationsCache realCache;
+ private TldLocator[] locators;
- private String webRoot;
+ public MockTldLocationsCache(TldLocationsCache delegate,
+ ServletContext ctx) {
+ this(delegate, ctx, true);
+ }
- private TldLocator[] locators;
+ public MockTldLocationsCache(TldLocationsCache delegate,
+ ServletContext ctx, boolean redeployMode) {
+ super(ctx, redeployMode);
+ realCache = delegate;
+ webRoot = ctx.getRealPath("/");
+ standardTlds = new TldUriMappings();
+ locators = new TldLocator[] {
+ new WebInfLibTldLocator(webRoot),
+ new ExplodedTldLocator(webRoot),
+ new ClasspathTldLocator() };
+ }
- public MockTldLocationsCache(TldLocationsCache delegate, ServletContext ctx) {
- this(delegate, ctx, true);
- }
-
- public MockTldLocationsCache(TldLocationsCache delegate,
- ServletContext ctx, boolean redeployMode) {
- super(ctx, redeployMode);
- realCache = delegate;
- webRoot = ctx.getRealPath("/");
- locators = new TldLocator[] { new WebInfLibTldLocator(webRoot),
- new ExplodedTldLocator(webRoot), new ClasspathTldLocator() };
- }
-
- public String[] getLocation(String uri) throws JasperException {
- // TODO: Optimize. Call to getLocation(String) can take a full second.
- if (standardTlds.containsKey(uri)) {
- String tldFileName = (String) standardTlds.get(uri);
- for (int i = 0; i < locators.length; i++) {
- TldLocation location = locators[i].find(tldFileName);
- if (location.wasFound()) {
- return location.toArray();
- }
- }
- }
- return realCache.getLocation(uri);
- }
+ public String[] getLocation(String uri) throws JasperException {
+ // TODO: Optimize. Call to getLocation(String) can take a full second.
+ if (standardTlds.contains(uri)) {
+ List tldFileNames = (List) standardTlds.get(uri);
+ for (Iterator it = tldFileNames.iterator(); it.hasNext();) {
+ String tldFileName = (String) it.next();
+ for (int i = 0; i < locators.length; i++) {
+ TldLocation location = locators[i]
+ .find(tldFileName);
+ if (location.wasFound()) {
+ return location.toArray();
+ }
+ }
+ }
+ }
+ return realCache.getLocation(uri);
+ }
}
Added: trunk/jsptest-jsp20/src/main/java/net/sf/jsptest/compiler/jsp20/mock/taglibs/TldUriMappings.java
===================================================================
--- trunk/jsptest-jsp20/src/main/java/net/sf/jsptest/compiler/jsp20/mock/taglibs/TldUriMappings.java (rev 0)
+++ trunk/jsptest-jsp20/src/main/java/net/sf/jsptest/compiler/jsp20/mock/taglibs/TldUriMappings.java 2008-04-04 12:53:08 UTC (rev 200)
@@ -0,0 +1,59 @@
+package net.sf.jsptest.compiler.jsp20.mock.taglibs;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class TldUriMappings {
+
+ private static final Map standardTlds = new HashMap();
+
+ static {
+ initialize();
+ }
+
+ private static void initialize() {
+ map("http://java.sun.com/jstl/core", "c.tld");
+ map("http://java.sun.com/jstl/sql", "sql.tld");
+ map("http://java.sun.com/jstl/xml", "x.tld");
+ map("http://java.sun.com/jstl/fmt", "fmt.tld");
+ map("http://java.sun.com/jstl/functions", "fn.tld");
+
+ map("http://java.sun.com/jsp/jstl/core", "c.tld");
+ map("http://java.sun.com/jsp/jstl/sql", "sql.tld");
+ map("http://java.sun.com/jsp/jstl/xml", "x.tld");
+ map("http://java.sun.com/jsp/jstl/fmt", "fmt.tld");
+ map("http://java.sun.com/jsp/jstl/functions", "fn.tld");
+
+ map("http://java.sun.com/jstl/core-rt", "c-rt.tld");
+ map("http://java.sun.com/jstl/sql-rt", "sql-rt.tld");
+ map("http://java.sun.com/jstl/xml-rt", "x-rt.tld");
+ map("http://java.sun.com/jstl/fmt-rt", "fmt-rt.tld");
+ map("http://java.sun.com/jstl/functions-rt", "fn-rt.tld");
+
+ map("http://java.sun.com/jstl/core-rt", "c-1_0-rt.tld");
+ map("http://java.sun.com/jstl/sql-rt", "sql-1_0-rt.tld");
+ map("http://java.sun.com/jstl/xml-rt", "x-1_0-rt.tld");
+ map("http://java.sun.com/jstl/fmt-rt", "fmt-1_0-rt.tld");
+ map("http://java.sun.com/jstl/functions-rt", "fn-1_0-rt.tld");
+ }
+
+ private static void map(String uri, String filename) {
+ List filenames = (List) standardTlds.get(uri);
+ if (filenames == null) {
+ filenames = new ArrayList();
+ }
+ filenames.add(filename);
+ standardTlds.put(uri, filenames);
+ }
+
+ public boolean contains(String uri) {
+ return standardTlds.containsKey(uri);
+ }
+
+ public List get(String uri) {
+ return (List) standardTlds.get(uri);
+ }
+
+}
Added: trunk/jsptest-jsp20/src/test/java/net/sf/jsptest/compiler/jsp20/mock/taglibs/TestClasspathTldLocator.java
===================================================================
--- trunk/jsptest-jsp20/src/test/java/net/sf/jsptest/compiler/jsp20/mock/taglibs/TestClasspathTldLocator.java (rev 0)
+++ trunk/jsptest-jsp20/src/test/java/net/sf/jsptest/compiler/jsp20/mock/taglibs/TestClasspathTldLocator.java 2008-04-04 12:53:08 UTC (rev 200)
@@ -0,0 +1,22 @@
+package net.sf.jsptest.compiler.jsp20.mock.taglibs;
+
+import junit.framework.TestCase;
+
+public class TestClasspathTldLocator extends TestCase {
+
+ private ClasspathTldLocator locator;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ locator = new ClasspathTldLocator();
+ }
+
+ public void testTldFilesAreFoundFromClasspath() throws Exception {
+ assertTrue(locator.find("exists.tld").wasFound());
+ }
+
+ public void testMissingFilesAreReportedAsNotFound()
+ throws Exception {
+ assertFalse(locator.find("nosuchfile.tld").wasFound());
+ }
+}
Added: trunk/jsptest-jsp20/src/test/resources/META-INF/MANIFEST.MF
===================================================================
--- trunk/jsptest-jsp20/src/test/resources/META-INF/MANIFEST.MF (rev 0)
+++ trunk/jsptest-jsp20/src/test/resources/META-INF/MANIFEST.MF 2008-04-04 12:53:08 UTC (rev 200)
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Created-By: 1.5.0_13 (Apple Computer, Inc.)
+
Added: trunk/jsptest-jsp20/src/test/resources/META-INF/exists.tld
===================================================================
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|