[Jsptest-svn-commits] SF.net SVN: jsptest: [193] trunk
Status: Alpha
Brought to you by:
lkoskela
From: <lko...@us...> - 2008-04-02 15:43:37
|
Revision: 193 http://jsptest.svn.sourceforge.net/jsptest/?rev=193&view=rev Author: lkoskela Date: 2008-04-02 08:43:33 -0700 (Wed, 02 Apr 2008) Log Message: ----------- Refactored TLD location stuff from MockEmbeddedServletOptions into a strategy type of design supporting 'tld files in WEB-INF', 'tld files in WEB-INF/lib' and 'tld files in a .jar file somewhere in classpath'. Renamed MockEmbeddedServletOptions to MockOptions. Modified Paths: -------------- trunk/jsptest-jsp20/src/main/java/net/sf/jsptest/compiler/jsp20/JasperCompiler.java Added Paths: ----------- trunk/jsptest-acceptance/jsptest-acceptance-jsp20/src/test/java/net/sf/jsptest/acceptance/jsp/TaglibsDefinedInJarFileTest.java trunk/jsptest-acceptance/jsptest-acceptance-jsp20/src/test/resources/websrc2/ trunk/jsptest-acceptance/jsptest-acceptance-jsp20/src/test/resources/websrc2/WEB-INF/ trunk/jsptest-acceptance/jsptest-acceptance-jsp20/src/test/resources/websrc2/WEB-INF/custom-taglib.tld trunk/jsptest-acceptance/jsptest-acceptance-jsp20/src/test/resources/websrc2/WEB-INF/lib/ trunk/jsptest-acceptance/jsptest-acceptance-jsp20/src/test/resources/websrc2/WEB-INF/lib/tlds.jar trunk/jsptest-acceptance/jsptest-acceptance-jsp20/src/test/resources/websrc2/WEB-INF/web.xml trunk/jsptest-acceptance/jsptest-acceptance-jsp20/src/test/resources/websrc2/custom-taglib.jsp trunk/jsptest-acceptance/jsptest-acceptance-jsp20/src/test/resources/websrc2/index.jsp trunk/jsptest-acceptance/jsptest-acceptance-jsp20/src/test/resources/websrc2/standard-taglibs.jsp trunk/jsptest-jsp20/src/main/java/net/sf/jsptest/compiler/jsp20/mock/MockOptions.java trunk/jsptest-jsp20/src/main/java/net/sf/jsptest/compiler/jsp20/mock/taglibs/ 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/ExplodedTldLocator.java trunk/jsptest-jsp20/src/main/java/net/sf/jsptest/compiler/jsp20/mock/taglibs/MockTagInfo.java 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/TldLocation.java trunk/jsptest-jsp20/src/main/java/net/sf/jsptest/compiler/jsp20/mock/taglibs/TldLocator.java trunk/jsptest-jsp20/src/main/java/net/sf/jsptest/compiler/jsp20/mock/taglibs/WebInfLibTldLocator.java Removed Paths: ------------- trunk/jsptest-jsp20/src/main/java/net/sf/jsptest/compiler/jsp20/mock/MockEmbeddedServletOptions.java Added: trunk/jsptest-acceptance/jsptest-acceptance-jsp20/src/test/java/net/sf/jsptest/acceptance/jsp/TaglibsDefinedInJarFileTest.java =================================================================== --- trunk/jsptest-acceptance/jsptest-acceptance-jsp20/src/test/java/net/sf/jsptest/acceptance/jsp/TaglibsDefinedInJarFileTest.java (rev 0) +++ trunk/jsptest-acceptance/jsptest-acceptance-jsp20/src/test/java/net/sf/jsptest/acceptance/jsp/TaglibsDefinedInJarFileTest.java 2008-04-02 15:43:33 UTC (rev 193) @@ -0,0 +1,36 @@ +/* + * 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.acceptance.jsp; + +import net.sf.jsptest.JspTestCase; + +/** + * @author Lasse Koskela + */ +public class TaglibsDefinedInJarFileTest extends JspTestCase { + + protected String getWebRoot() { + return "src/test/resources/websrc2"; + } + + public void testStandardTaglibsWork() throws Exception { + get("/standard-taglibs.jsp"); + for (int i = 1; i <= 10; i++) { + output().shouldContain("loop-" + i); + } + } +} Added: trunk/jsptest-acceptance/jsptest-acceptance-jsp20/src/test/resources/websrc2/WEB-INF/custom-taglib.tld =================================================================== --- trunk/jsptest-acceptance/jsptest-acceptance-jsp20/src/test/resources/websrc2/WEB-INF/custom-taglib.tld (rev 0) +++ trunk/jsptest-acceptance/jsptest-acceptance-jsp20/src/test/resources/websrc2/WEB-INF/custom-taglib.tld 2008-04-02 15:43:33 UTC (rev 193) @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="ISO-8859-1" ?> +<!DOCTYPE taglib + PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN" + "http://java.sun.com/j2ee/dtd/web-jsptaglibrary_1_2.dtd"> + +<taglib> + + <tlib-version>1.0</tlib-version> + <jsp-version>1.2</jsp-version> + <short-name>custom-taglib</short-name> + <uri>http://jsptest.sf.net/taglib</uri> + <description>taglib example</description> + + <tag> + <name>date</name> + <tag-class>net.sf.jsptest.acceptance.jsp.CustomTag</tag-class> + <body-content>TAGDEPENDENT</body-content> + <description>Render request information</description> + <attribute> + <name>tz</name> + <required>false</required> + </attribute> + </tag> + +</taglib> Added: trunk/jsptest-acceptance/jsptest-acceptance-jsp20/src/test/resources/websrc2/WEB-INF/lib/tlds.jar =================================================================== (Binary files differ) Property changes on: trunk/jsptest-acceptance/jsptest-acceptance-jsp20/src/test/resources/websrc2/WEB-INF/lib/tlds.jar ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/jsptest-acceptance/jsptest-acceptance-jsp20/src/test/resources/websrc2/WEB-INF/web.xml =================================================================== --- trunk/jsptest-acceptance/jsptest-acceptance-jsp20/src/test/resources/websrc2/WEB-INF/web.xml (rev 0) +++ trunk/jsptest-acceptance/jsptest-acceptance-jsp20/src/test/resources/websrc2/WEB-INF/web.xml 2008-04-02 15:43:33 UTC (rev 193) @@ -0,0 +1,129 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<web-app xmlns="http://java.sun.com/xml/ns/j2ee" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" + version="2.4"> + +<!-- + <context-param> + <param-name>javax.faces.CONFIG_FILES</param-name> + <param-value> + /WEB-INF/faces-config.xml + </param-value> + <description> + Comma separated list of URIs of (additional) faces config files. + (e.g. /WEB-INF/my-config.xml) + See JSF 1.0 PRD2, 10.3.2 + </description> + </context-param> + + <context-param> + <param-name>javax.faces.STATE_SAVING_METHOD</param-name> + <param-value>client</param-value> + <description> + State saving method: "client" or "server" (= default) + See JSF Specification 2.5.2 + </description> + </context-param> + + <context-param> + <param-name>org.apache.myfaces.ALLOW_JAVASCRIPT</param-name> + <param-value>true</param-value> + <description> + This parameter tells MyFaces if javascript code should be allowed in the + rendered HTML output. + If javascript is allowed, command_link anchors will have javascript code + that submits the corresponding form. + If javascript is not allowed, the state saving info and nested parameters + will be added as url parameters. + Default: "true" + </description> + </context-param> + + <context-param> + <param-name>org.apache.myfaces.PRETTY_HTML</param-name> + <param-value>true</param-value> + <description> + If true, rendered HTML code will be formatted, so that it is "human readable". + i.e. additional line separators and whitespace will be written, that do not + influence the HTML code. + Default: "true" + </description> + </context-param> + + <context-param> + <param-name>org.apache.myfaces.DETECT_JAVASCRIPT</param-name> + <param-value>false</param-value> + </context-param> + + <context-param> + <param-name>org.apache.myfaces.AUTO_SCROLL</param-name> + <param-value>true</param-value> + <description> + If true, a javascript function will be rendered that is able to restore the + former vertical scroll on every request. Convenient feature if you have pages + with long lists and you do not want the browser page to always jump to the top + if you trigger a link or button action that stays on the same page. + Default: "false" + </description> + </context-param> + + <listener> + <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class> + </listener> + + <servlet> + <servlet-name>Faces Servlet</servlet-name> + <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> + <load-on-startup>1</load-on-startup> + </servlet> + + <servlet-mapping> + <servlet-name>Faces Servlet</servlet-name> + <url-pattern>*.faces</url-pattern> + </servlet-mapping> +--> + + <!-- Welcome files --> + <welcome-file-list> + <welcome-file>index.jsp</welcome-file> + </welcome-file-list> + + <!-- standard taglibs --> + <taglib> + <taglib-uri>http://java.sun.com/jstl/fmt</taglib-uri> + <taglib-location>/WEB-INF/fmt.tld</taglib-location> + </taglib> + + <taglib> + <taglib-uri>http://java.sun.com/jstl/fmt-rt</taglib-uri> + <taglib-location>/WEB-INF/fmt-rt.tld</taglib-location> + </taglib> + + <taglib> + <taglib-uri>http://java.sun.com/jstl/core</taglib-uri> + <taglib-location>/WEB-INF/c.tld</taglib-location> + </taglib> + + <taglib> + <taglib-uri>http://java.sun.com/jstl/core-rt</taglib-uri> + <taglib-location>/WEB-INF/c-rt.tld</taglib-location> + </taglib> + + <taglib> + <taglib-uri>http://java.sun.com/jstl/x</taglib-uri> + <taglib-location>/WEB-INF/x.tld</taglib-location> + </taglib> + + <taglib> + <taglib-uri>http://java.sun.com/jstl/x-rt</taglib-uri> + <taglib-location>/WEB-INF/x-rt.tld</taglib-location> + </taglib> + + <!-- custom taglibs --> + <taglib> + <taglib-uri>http://jsptest.sf.net/taglib</taglib-uri> + <taglib-location>/WEB-INF/custom-taglib.tld</taglib-location> + </taglib> + +</web-app> \ No newline at end of file Added: trunk/jsptest-acceptance/jsptest-acceptance-jsp20/src/test/resources/websrc2/custom-taglib.jsp =================================================================== --- trunk/jsptest-acceptance/jsptest-acceptance-jsp20/src/test/resources/websrc2/custom-taglib.jsp (rev 0) +++ trunk/jsptest-acceptance/jsptest-acceptance-jsp20/src/test/resources/websrc2/custom-taglib.jsp 2008-04-02 15:43:33 UTC (rev 193) @@ -0,0 +1,16 @@ +<%@ page language="Java" %> +<%@ taglib uri="http://jsptest.sf.net/taglib" prefix="custom" %> +<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %> +<html> + <body> + + <small><custom:date tz="GMT">EEE, dd/MMM/yyyy HH:mm:ss ZZZ</custom:date> ==></small> + <custom:date tz="GMT">EEE, dd/MMM/yyyy HH:mm:ss ZZZ</custom:date> + <br/> + + <small><custom:date tz="EST">EEE, dd-MMM-yyyy HH:mm:ss ZZZ</custom:date> ==></small> + <custom:date tz="EST">EEE, dd-MMM-yyyy HH:mm:ss ZZZ</custom:date> + <br/> + + </body> +</html> Added: trunk/jsptest-acceptance/jsptest-acceptance-jsp20/src/test/resources/websrc2/index.jsp =================================================================== --- trunk/jsptest-acceptance/jsptest-acceptance-jsp20/src/test/resources/websrc2/index.jsp (rev 0) +++ trunk/jsptest-acceptance/jsptest-acceptance-jsp20/src/test/resources/websrc2/index.jsp 2008-04-02 15:43:33 UTC (rev 193) @@ -0,0 +1,3 @@ +<%@ page language="Java" %> +Hello <%= "from" %> Jasper +The time is <%= new java.util.Date().toString() %> \ No newline at end of file Added: trunk/jsptest-acceptance/jsptest-acceptance-jsp20/src/test/resources/websrc2/standard-taglibs.jsp =================================================================== --- trunk/jsptest-acceptance/jsptest-acceptance-jsp20/src/test/resources/websrc2/standard-taglibs.jsp (rev 0) +++ trunk/jsptest-acceptance/jsptest-acceptance-jsp20/src/test/resources/websrc2/standard-taglibs.jsp 2008-04-02 15:43:33 UTC (rev 193) @@ -0,0 +1,5 @@ +<%@ page language="Java" %> +<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core-rt" %> +<c:forEach var="i" begin="1" end="10"> + <c:out value="loop"/>-<c:out value="${i}" /> +</c:forEach> \ No newline at end of file Modified: trunk/jsptest-jsp20/src/main/java/net/sf/jsptest/compiler/jsp20/JasperCompiler.java =================================================================== --- trunk/jsptest-jsp20/src/main/java/net/sf/jsptest/compiler/jsp20/JasperCompiler.java 2008-03-09 18:55:16 UTC (rev 192) +++ trunk/jsptest-jsp20/src/main/java/net/sf/jsptest/compiler/jsp20/JasperCompiler.java 2008-04-02 15:43:33 UTC (rev 193) @@ -35,7 +35,7 @@ import net.sf.jsptest.compiler.java.CommandLineJavac; import net.sf.jsptest.compiler.java.JavaCompiler; import net.sf.jsptest.compiler.java.SunJavaC; -import net.sf.jsptest.compiler.jsp20.mock.MockEmbeddedServletOptions; +import net.sf.jsptest.compiler.jsp20.mock.MockOptions; import net.sf.jsptest.compiler.jsp20.mock.MockServletConfig; import net.sf.jsptest.compiler.jsp20.mock.MockTagInfo; import net.sf.jsptest.utils.Path; @@ -270,8 +270,7 @@ private Options createOptions(ServletContext ctx, ServletConfig cfg, JspCompilationInfo info) { Options options = new EmbeddedServletOptions(cfg, ctx); - return new MockEmbeddedServletOptions(options, ctx, info - .getTaglibs()); + return new MockOptions(options, ctx, info.getTaglibs()); } private void resolveJavaSourceFile(JspCompilationInfo info) { Deleted: trunk/jsptest-jsp20/src/main/java/net/sf/jsptest/compiler/jsp20/mock/MockEmbeddedServletOptions.java =================================================================== --- trunk/jsptest-jsp20/src/main/java/net/sf/jsptest/compiler/jsp20/mock/MockEmbeddedServletOptions.java 2008-03-09 18:55:16 UTC (rev 192) +++ trunk/jsptest-jsp20/src/main/java/net/sf/jsptest/compiler/jsp20/mock/MockEmbeddedServletOptions.java 2008-04-02 15:43:33 UTC (rev 193) @@ -1,157 +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.io.File; -import java.util.Map; - -import javax.servlet.ServletContext; - -import org.apache.jasper.Options; -import org.apache.jasper.compiler.JspConfig; -import org.apache.jasper.compiler.MockTagPluginManager; -import org.apache.jasper.compiler.TagPluginManager; -import org.apache.jasper.compiler.TldLocationsCache; - -/** - * @author Lasse Koskela - */ -public class MockEmbeddedServletOptions implements Options { - - private Options options; - - private ServletContext servletContext; - - private Map taglibs; - - public MockEmbeddedServletOptions(Options options, - ServletContext context, Map taglibs) { - this.options = options; - this.servletContext = context; - this.taglibs = taglibs; - } - - public boolean getErrorOnUseBeanInvalidClassAttribute() { - return options.getErrorOnUseBeanInvalidClassAttribute(); - } - - public boolean getKeepGenerated() { - return options.getKeepGenerated(); - } - - public boolean isPoolingEnabled() { - return options.isPoolingEnabled(); - } - - public boolean getMappedFile() { - return options.getMappedFile(); - } - - public boolean getSendErrorToClient() { - return options.getSendErrorToClient(); - } - - public boolean getClassDebugInfo() { - return options.getClassDebugInfo(); - } - - public int getCheckInterval() { - return options.getCheckInterval(); - } - - public boolean getDevelopment() { - return options.getDevelopment(); - } - - public boolean isSmapSuppressed() { - return true; // options.isSmapSuppressed(); - } - - public boolean isSmapDumped() { - return false; // options.isSmapDumped(); - } - - public boolean getTrimSpaces() { - return options.getTrimSpaces(); - } - - public String getIeClassId() { - return options.getIeClassId(); - } - - public File getScratchDir() { - return options.getScratchDir(); - } - - public String getClassPath() { - return options.getClassPath(); - } - - public String getCompiler() { - return options.getCompiler(); - } - - public String getCompilerTargetVM() { - return options.getCompilerTargetVM(); - } - - public String getCompilerSourceVM() { - return options.getCompilerSourceVM(); - } - - public TldLocationsCache getTldLocationsCache() { - TldLocationsCache realCache = options.getTldLocationsCache(); - return new MockTldLocationsCache(realCache, servletContext); - } - - public String getJavaEncoding() { - return options.getJavaEncoding(); - } - - public boolean getFork() { - return options.getFork(); - } - - public JspConfig getJspConfig() { - return options.getJspConfig(); - } - - public boolean isXpoweredBy() { - return options.isXpoweredBy(); - } - - public TagPluginManager getTagPluginManager() { - return new MockTagPluginManager(servletContext, options - .getTagPluginManager(), taglibs); - } - - public boolean genStringAsCharArray() { - return options.genStringAsCharArray(); - } - - public int getModificationTestInterval() { - return options.getModificationTestInterval(); - } - - public boolean isCaching() { - return options.isCaching(); - } - - public Map getCache() { - return options.getCache(); - } -} \ No newline at end of file Added: trunk/jsptest-jsp20/src/main/java/net/sf/jsptest/compiler/jsp20/mock/MockOptions.java =================================================================== --- trunk/jsptest-jsp20/src/main/java/net/sf/jsptest/compiler/jsp20/mock/MockOptions.java (rev 0) +++ trunk/jsptest-jsp20/src/main/java/net/sf/jsptest/compiler/jsp20/mock/MockOptions.java 2008-04-02 15:43:33 UTC (rev 193) @@ -0,0 +1,159 @@ +/* + * 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.io.File; +import java.util.Map; + +import javax.servlet.ServletContext; + +import net.sf.jsptest.compiler.jsp20.mock.taglibs.MockTldLocationsCache; + +import org.apache.jasper.Options; +import org.apache.jasper.compiler.JspConfig; +import org.apache.jasper.compiler.MockTagPluginManager; +import org.apache.jasper.compiler.TagPluginManager; +import org.apache.jasper.compiler.TldLocationsCache; + +/** + * @author Lasse Koskela + */ +public class MockOptions implements Options { + + private Options options; + + private ServletContext servletContext; + + private Map taglibs; + + public MockOptions(Options options, + ServletContext context, Map taglibs) { + this.options = options; + this.servletContext = context; + this.taglibs = taglibs; + } + + public boolean getErrorOnUseBeanInvalidClassAttribute() { + return options.getErrorOnUseBeanInvalidClassAttribute(); + } + + public boolean getKeepGenerated() { + return options.getKeepGenerated(); + } + + public boolean isPoolingEnabled() { + return options.isPoolingEnabled(); + } + + public boolean getMappedFile() { + return options.getMappedFile(); + } + + public boolean getSendErrorToClient() { + return options.getSendErrorToClient(); + } + + public boolean getClassDebugInfo() { + return options.getClassDebugInfo(); + } + + public int getCheckInterval() { + return options.getCheckInterval(); + } + + public boolean getDevelopment() { + return options.getDevelopment(); + } + + public boolean isSmapSuppressed() { + return true; // options.isSmapSuppressed(); + } + + public boolean isSmapDumped() { + return false; // options.isSmapDumped(); + } + + public boolean getTrimSpaces() { + return options.getTrimSpaces(); + } + + public String getIeClassId() { + return options.getIeClassId(); + } + + public File getScratchDir() { + return options.getScratchDir(); + } + + public String getClassPath() { + return options.getClassPath(); + } + + public String getCompiler() { + return options.getCompiler(); + } + + public String getCompilerTargetVM() { + return options.getCompilerTargetVM(); + } + + public String getCompilerSourceVM() { + return options.getCompilerSourceVM(); + } + + public TldLocationsCache getTldLocationsCache() { + TldLocationsCache realCache = options.getTldLocationsCache(); + return new MockTldLocationsCache(realCache, servletContext); + } + + public String getJavaEncoding() { + return options.getJavaEncoding(); + } + + public boolean getFork() { + return options.getFork(); + } + + public JspConfig getJspConfig() { + return options.getJspConfig(); + } + + public boolean isXpoweredBy() { + return options.isXpoweredBy(); + } + + public TagPluginManager getTagPluginManager() { + return new MockTagPluginManager(servletContext, options + .getTagPluginManager(), taglibs); + } + + public boolean genStringAsCharArray() { + return options.genStringAsCharArray(); + } + + public int getModificationTestInterval() { + return options.getModificationTestInterval(); + } + + public boolean isCaching() { + return options.isCaching(); + } + + public Map getCache() { + return options.getCache(); + } +} \ No newline at end of file Added: 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 (rev 0) +++ trunk/jsptest-jsp20/src/main/java/net/sf/jsptest/compiler/jsp20/mock/taglibs/ClasspathTldLocator.java 2008-04-02 15:43:33 UTC (rev 193) @@ -0,0 +1,35 @@ +/* + * 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.taglibs; + +import java.net.URL; + +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(); + } +} \ No newline at end of file Added: trunk/jsptest-jsp20/src/main/java/net/sf/jsptest/compiler/jsp20/mock/taglibs/ExplodedTldLocator.java =================================================================== --- trunk/jsptest-jsp20/src/main/java/net/sf/jsptest/compiler/jsp20/mock/taglibs/ExplodedTldLocator.java (rev 0) +++ trunk/jsptest-jsp20/src/main/java/net/sf/jsptest/compiler/jsp20/mock/taglibs/ExplodedTldLocator.java 2008-04-02 15:43:33 UTC (rev 193) @@ -0,0 +1,36 @@ +/* + * 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.taglibs; + +import java.io.File; + +public class ExplodedTldLocator implements TldLocator { + + private final String webRoot; + + public ExplodedTldLocator(String webRoot) { + this.webRoot = webRoot; + } + + public TldLocation find(String filename) { + File webInf = new File(webRoot, "WEB-INF"); + if (new File(webInf, filename).exists()) { + return TldLocation.foundFromWebInf(filename); + } + return TldLocation.notFound(); + } +} \ No newline at end of file Added: trunk/jsptest-jsp20/src/main/java/net/sf/jsptest/compiler/jsp20/mock/taglibs/MockTagInfo.java =================================================================== --- trunk/jsptest-jsp20/src/main/java/net/sf/jsptest/compiler/jsp20/mock/taglibs/MockTagInfo.java (rev 0) +++ trunk/jsptest-jsp20/src/main/java/net/sf/jsptest/compiler/jsp20/mock/taglibs/MockTagInfo.java 2008-04-02 15:43:33 UTC (rev 193) @@ -0,0 +1,38 @@ +/* + * 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.taglibs; + +import javax.servlet.jsp.tagext.TagInfo; + +/** + * @author Lasse Koskela + */ +public class MockTagInfo extends TagInfo { + + public MockTagInfo() { + super("", "", "", "", null, null, null); + } + + public String getTagClassName() { + try { + throw new RuntimeException("MockTagInfo being asked for getTagClassName()"); + } catch (RuntimeException e) { + e.printStackTrace(System.out); + } + return super.getTagClassName(); + } +} Added: 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 (rev 0) +++ trunk/jsptest-jsp20/src/main/java/net/sf/jsptest/compiler/jsp20/mock/taglibs/MockTldLocationsCache.java 2008-04-02 15:43:33 UTC (rev 193) @@ -0,0 +1,86 @@ +/* + * 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.taglibs; + +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", "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"); + + 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"); + + 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 TldLocationsCache realCache; + + private String webRoot; + + private TldLocator[] locators; + + 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); + } +} Added: trunk/jsptest-jsp20/src/main/java/net/sf/jsptest/compiler/jsp20/mock/taglibs/TldLocation.java =================================================================== --- trunk/jsptest-jsp20/src/main/java/net/sf/jsptest/compiler/jsp20/mock/taglibs/TldLocation.java (rev 0) +++ trunk/jsptest-jsp20/src/main/java/net/sf/jsptest/compiler/jsp20/mock/taglibs/TldLocation.java 2008-04-02 15:43:33 UTC (rev 193) @@ -0,0 +1,89 @@ +/* + * 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.taglibs; + +import java.io.File; +import java.net.MalformedURLException; +import java.net.URL; + +public class TldLocation { + + private final boolean wasFound; + + protected TldLocation(boolean wasFound) { + this.wasFound = wasFound; + } + + /** + * Indicates whether the location was found or not. + * + * @return true if the TLD was found, false if it wasn't. + */ + public boolean wasFound() { + return wasFound; + } + + /** + * <p> + * Formats the location of the TLD into the array format used by + * <tt>TldLocationsCache</tt>, i.e. an array in one of these formats: + * </p> + * <p> { "/WEB-INF/foo.tld", null } for exploded TLD files<br/> { + * "file://url/to/taglibs.jar", "META-INF/foo.tld } for TLD files found in + * archives + * </p> + */ + public String[] toArray() { + return null; + } + + public static TldLocation notFound() { + return new TldLocation(false); + } + + public static TldLocation foundFromWebInf(final String filename) { + return new TldLocation(true) { + public String[] toArray() { + return new String[] { "/WEB-INF/" + filename, null }; + } + }; + } + + public static TldLocation foundFromArchive(final File archive, + final String archiveEntry) { + return new TldLocation(true) { + public String[] toArray() { + try { + String pathToArchive = archive.toURL().toExternalForm(); + return new String[] { pathToArchive, archiveEntry }; + } catch (MalformedURLException e) { + throw new RuntimeException(e); + } + } + }; + } + + public static TldLocation foundFromClassPath(final URL archive, + final String pathInsideArchive) { + return new TldLocation(true) { + public String[] toArray() { + String pathToArchive = archive.toExternalForm(); + return new String[] { pathToArchive, pathInsideArchive }; + } + }; + } +} Added: trunk/jsptest-jsp20/src/main/java/net/sf/jsptest/compiler/jsp20/mock/taglibs/TldLocator.java =================================================================== --- trunk/jsptest-jsp20/src/main/java/net/sf/jsptest/compiler/jsp20/mock/taglibs/TldLocator.java (rev 0) +++ trunk/jsptest-jsp20/src/main/java/net/sf/jsptest/compiler/jsp20/mock/taglibs/TldLocator.java 2008-04-02 15:43:33 UTC (rev 193) @@ -0,0 +1,29 @@ +/* + * 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.taglibs; + +public interface TldLocator { + + /** + * Attempts to find the given TLD file. + * + * @param filename + * The name of the TLD file, e.g. "sql-rt.tld". + * @return <tt>TldLocation</tt> representing the result of the search. + */ + TldLocation find(String filename); +} Added: trunk/jsptest-jsp20/src/main/java/net/sf/jsptest/compiler/jsp20/mock/taglibs/WebInfLibTldLocator.java =================================================================== --- trunk/jsptest-jsp20/src/main/java/net/sf/jsptest/compiler/jsp20/mock/taglibs/WebInfLibTldLocator.java (rev 0) +++ trunk/jsptest-jsp20/src/main/java/net/sf/jsptest/compiler/jsp20/mock/taglibs/WebInfLibTldLocator.java 2008-04-02 15:43:33 UTC (rev 193) @@ -0,0 +1,65 @@ +/* + * 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.taglibs; + +import java.io.File; +import java.io.FilenameFilter; +import java.io.IOException; +import java.util.jar.JarEntry; +import java.util.jar.JarFile; + +public class WebInfLibTldLocator implements TldLocator { + + private final String webRoot; + + public WebInfLibTldLocator(String webRoot) { + this.webRoot = webRoot; + } + + public TldLocation find(String filename) { + File webInfLib = new File(new File(webRoot, "WEB-INF"), "lib"); + if (webInfLib.exists()) { + File[] archives = findArchivesFrom(webInfLib); + return findTldFromArchives(filename, archives); + } else { + return TldLocation.notFound(); + } + } + + private TldLocation findTldFromArchives(String filename, File[] archives) { + for (int i = 0; i < archives.length; i++) { + try { + JarFile archive = new JarFile(archives[i]); + JarEntry entry = archive.getJarEntry("META-INF/" + filename); + if (entry != null) { + return TldLocation.foundFromArchive(archives[i], + "META-INF/" + filename); + } + } catch (IOException ignored) { + } + } + return TldLocation.notFound(); + } + + private File[] findArchivesFrom(File dir) { + return dir.listFiles(new FilenameFilter() { + public boolean accept(File directory, String name) { + return name.endsWith(".jar"); + } + }); + } +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |