This is an automated email from the ASF dual-hosted git repository. dashorst pushed a commit to branch archive/wicket-1.1.x in repository https://gitbox.apache.org/repos/asf/wicket.git
commit cdf1dd2442b448613b045b558813a472850de8ae Author: Juegen Donnerstag <[email protected]> AuthorDate: Tue Nov 1 10:22:13 2005 +0000 backported autolink NPE fix git-svn-id: https://svn.apache.org/repos/asf/incubator/wicket/branches/WICKET_1_1@457984 13f79535-47bb-0310-9956-ffa450edef68 --- wicket/src/java/wicket/AutoLinkResolver.java | 125 +++++++++++---------- .../html/link/AutolinkPageExpectedResult_4.html | 14 +++ .../wicket/markup/html/link/AutolinkPage_4.html | 14 +++ .../wicket/markup/html/link/AutolinkPage_4.java | 41 +++++++ .../test/wicket/markup/html/link/AutolinkTest.java | 9 ++ wicket/xdocs/changes.xml | 3 + 6 files changed, 144 insertions(+), 62 deletions(-) diff --git a/wicket/src/java/wicket/AutoLinkResolver.java b/wicket/src/java/wicket/AutoLinkResolver.java index b306d173a5..e787a0e7ff 100644 --- a/wicket/src/java/wicket/AutoLinkResolver.java +++ b/wicket/src/java/wicket/AutoLinkResolver.java @@ -160,77 +160,78 @@ public final class AutoLinkResolver implements IComponentResolver { extension = infoPath.substring(pos + 1); infoPath = infoPath.substring(0, pos); - } - - // HTML hrefs are handled first - if (supportedPageExtensions.containsKey(extension.toLowerCase())) - { - // Obviously a href like href="myPkg.MyLabel.html" will do as well. - // Wicket will not throw an exception. It accepts it. - infoPath = Strings.replaceAll(infoPath, "/", "."); - final ApplicationSettings appSettings = page.getApplicationSettings(); - final IClassResolver defaultClassResolver = appSettings.getDefaultClassResolver(); - - final String className; - if (!infoPath.startsWith(".")) - { - // Href is relative. Resolve the url given relative to the - // current page - className = Packages.extractPackageName(page.getClass()) + "." + infoPath; - } - else - { - // href is absolute. If class with the same absolute path - // exists, use it. Else don't change the href. - className = infoPath.substring(1); - } - - try - { - final Class clazz = defaultClassResolver.resolveClass(className); - return new AutolinkBookmarkablePageLink(autoId, clazz, pageParameters); - } - catch (WicketRuntimeException ex) - { - // fall through - } - } - // It is not "*.html". Create a static resource reference - else - { - if (infoPath.startsWith("/") || infoPath.startsWith("\\")) - { - // href is absolute. Don't change it at all. - } - else + // HTML hrefs are handled first + if (supportedPageExtensions.containsKey(extension.toLowerCase())) { - // Href is relative. Create a resource reference pointing at - // this file - - // <wicket:head> components are handled differently. We can not - // use the container, because it is the container the header - // has been added to (e.g. the Page). What we need however, is - // the component (e.g. a Panel) which contributed it. - Component relevantContainer = container; - while ((relevantContainer instanceof IComponentResolver) - && !(relevantContainer instanceof IComponentResolverMarker)) + // Obviously a href like href="myPkg.MyLabel.html" will do as well. + // Wicket will not throw an exception. It accepts it. + infoPath = Strings.replaceAll(infoPath, "/", "."); + + final ApplicationSettings appSettings = page.getApplicationSettings(); + final IClassResolver defaultClassResolver = appSettings.getDefaultClassResolver(); + + final String className; + if (!infoPath.startsWith(".")) { - relevantContainer = relevantContainer.getParent(); + // Href is relative. Resolve the url given relative to the + // current page + className = Packages.extractPackageName(page.getClass()) + "." + infoPath; } - + else + { + // href is absolute. If class with the same absolute path + // exists, use it. Else don't change the href. + className = infoPath.substring(1); + } + try { - // Create the component implementing the link - return new CssLink(autoId, relevantContainer.getClass(), href); + final Class clazz = defaultClassResolver.resolveClass(className); + return new AutolinkBookmarkablePageLink(autoId, clazz, pageParameters); } catch (WicketRuntimeException ex) { - // Provided the resource does not exist, assume the user did - // deliberately not point it to a page or resource. The href - // might still point to a valid homepage outside of wicket. - log.info("Did not find autolink resource: " + href - + "; Assume it is a valid external URL"); + log.info("Did not find corresponding java class: " + className); + // fall through + } + } + // It is not "*.html". Create a static resource reference + else + { + if (infoPath.startsWith("/") || infoPath.startsWith("\\")) + { + // href is absolute. Don't change it at all. + } + else + { + // Href is relative. Create a resource reference pointing at + // this file + + // <wicket:head> components are handled differently. We can not + // use the container, because it is the container the header + // has been added to (e.g. the Page). What we need however, is + // the component (e.g. a Panel) which contributed it. + Component relevantContainer = container; + while ((relevantContainer instanceof IComponentResolver) + && !(relevantContainer instanceof IComponentResolverMarker)) + { + relevantContainer = relevantContainer.getParent(); + } + + try + { + // Create the component implementing the link + return new CssLink(autoId, relevantContainer.getClass(), href); + } + catch (WicketRuntimeException ex) + { + // Provided the resource does not exist, assume the user did + // deliberately not point it to a page or resource. The href + // might still point to a valid homepage outside of wicket. + log.info("Did not find autolink resource: " + href + + "; Assume it is a valid external URL"); + } } } } diff --git a/wicket/src/test/wicket/markup/html/link/AutolinkPageExpectedResult_4.html b/wicket/src/test/wicket/markup/html/link/AutolinkPageExpectedResult_4.html new file mode 100644 index 0000000000..297ba3abe2 --- /dev/null +++ b/wicket/src/test/wicket/markup/html/link/AutolinkPageExpectedResult_4.html @@ -0,0 +1,14 @@ +<html xmlns:wicket> +<body> +<wicket:link autolink="true"> + <!-- File/page does not exist => Do not change href at all --> + <a href="PageDoesNotExist.html">Home</a> + <!-- Reference an internal target => Do not change href at all --> + <a href="#link1">Link 1</a> + <!-- Not sure what it should do, but it is obviously valid => Do not change href at all --> + <a href="">Link 1</a> + <!-- Not supported yet: Reference an internal target on an existing page --> + <a href="SamePage.html#link1">Link 1</a> +</wicket:link> +</body> +</html> diff --git a/wicket/src/test/wicket/markup/html/link/AutolinkPage_4.html b/wicket/src/test/wicket/markup/html/link/AutolinkPage_4.html new file mode 100644 index 0000000000..0127b353c4 --- /dev/null +++ b/wicket/src/test/wicket/markup/html/link/AutolinkPage_4.html @@ -0,0 +1,14 @@ +<html xmlns:wicket> +<body> +<wicket:link autolink=true> + <!-- File/page does not exist => Do not change href at all --> + <a href="PageDoesNotExist.html">Home</a> + <!-- Reference an internal target => Do not change href at all --> + <a href="#link1">Link 1</a> + <!-- Not sure what it should do, but it is obviously valid => Do not change href at all --> + <a href="">Link 1</a> + <!-- Not supported yet: Reference an internal target on an existing page --> + <a href="SamePage.html#link1">Link 1</a> +</wicket:link> +</body> +</html> diff --git a/wicket/src/test/wicket/markup/html/link/AutolinkPage_4.java b/wicket/src/test/wicket/markup/html/link/AutolinkPage_4.java new file mode 100644 index 0000000000..ce87975437 --- /dev/null +++ b/wicket/src/test/wicket/markup/html/link/AutolinkPage_4.java @@ -0,0 +1,41 @@ +/* + * $Id$ + * $Revision$ + * $Date$ + * + * ==================================================================== + * 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 wicket.markup.html.link; + +import wicket.PageParameters; +import wicket.markup.html.WebPage; + + +/** + * Mock page for testing. + * + * @author Chris Turner + */ +public class AutolinkPage_4 extends WebPage +{ + private static final long serialVersionUID = 1L; + + /** + * Construct. + * @param parameters + */ + public AutolinkPage_4(final PageParameters parameters) + { + } +} diff --git a/wicket/src/test/wicket/markup/html/link/AutolinkTest.java b/wicket/src/test/wicket/markup/html/link/AutolinkTest.java index aa012cb932..c489be2858 100644 --- a/wicket/src/test/wicket/markup/html/link/AutolinkTest.java +++ b/wicket/src/test/wicket/markup/html/link/AutolinkTest.java @@ -70,4 +70,13 @@ public class AutolinkTest extends WicketTestCase application.getSettings().setAutomaticLinking(true); executeTest(AutolinkPage_3.class, "AutolinkPageExpectedResult_3.html"); } + + /** + * @throws Exception + */ + public void testRenderHomePage_4() throws Exception + { + application.getSettings().setAutomaticLinking(true); + executeTest(AutolinkPage_4.class, "AutolinkPageExpectedResult_4.html"); + } } diff --git a/wicket/xdocs/changes.xml b/wicket/xdocs/changes.xml index b8f531e2b2..dab4f4b5b6 100644 --- a/wicket/xdocs/changes.xml +++ b/wicket/xdocs/changes.xml @@ -10,6 +10,9 @@ <body> <release version="1.2-alpha1" date="tbd" description="Wicket CVS HEAD development"> </release> + <release version="1.1.1" date="tbd" description="Wicket 1.1.1"> + <action type="fix" dev="Juergen Donnerstag">Fixed autolink NPE problem</action> + </release> <release version="1.1" date="2005-10-30" description="Wicket 1.1 final"> <action type="fix" dev="Juergen Donnerstag" issue="1339686" due-to="Janne Hietamäki">fixed: Invalid Panel markup throws weird exception</action> <action type="delete" dev="Jonathan Locke">Removed experimental code: page sets.</action>
