Author: ltheussl Date: Wed Jan 12 11:34:02 2011 New Revision: 1058083 URL: http://svn.apache.org/viewvc?rev=1058083&view=rev Log: [DOXIASITETOOLS-46, DOXIASITETOOLS-47] separate link resolution and inheritance assembly, fix path resolution issues with scp urls. Deprecate PathDescriptor and PathUtils which do not work correctly.
Added: maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/inheritance/URIPathDescriptor.java maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/test/java/org/apache/maven/doxia/site/decoration/inheritance/URIPathDescriptorTest.java maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/test/resources/fully-populated-unresolved.xml Modified: maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/inheritance/DefaultDecorationModelInheritanceAssembler.java maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/inheritance/PathDescriptor.java maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/inheritance/PathUtils.java maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/test/java/org/apache/maven/doxia/site/decoration/inheritance/DecorationModelInheritenceAssemblerTest.java Modified: maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/inheritance/DefaultDecorationModelInheritanceAssembler.java URL: http://svn.apache.org/viewvc/maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/inheritance/DefaultDecorationModelInheritanceAssembler.java?rev=1058083&r1=1058082&r2=1058083&view=diff ============================================================================== --- maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/inheritance/DefaultDecorationModelInheritanceAssembler.java (original) +++ maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/inheritance/DefaultDecorationModelInheritanceAssembler.java Wed Jan 12 11:34:02 2011 @@ -19,7 +19,8 @@ package org.apache.maven.doxia.site.deco * under the License. */ -import java.net.MalformedURLException; +import java.net.URISyntaxException; + import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -60,13 +61,13 @@ public class DefaultDecorationModelInher if ( child.getBannerLeft() == null && parent.getBannerLeft() != null ) { child.setBannerLeft( (Banner) parent.getBannerLeft().clone()); - resolveBannerPaths( child.getBannerLeft(), urlContainer ); + rebaseBannerPaths( child.getBannerLeft(), urlContainer ); } if ( child.getBannerRight() == null && parent.getBannerRight() != null) { child.setBannerRight( (Banner) parent.getBannerRight().clone()); - resolveBannerPaths( child.getBannerRight(), urlContainer ); + rebaseBannerPaths( child.getBannerRight(), urlContainer ); } if ( child.getPublishDate() == null && parent.getPublishDate() != null ) @@ -100,23 +101,21 @@ public class DefaultDecorationModelInher /** {...@inheritdoc} */ public void resolvePaths( final DecorationModel decoration, final String baseUrl ) { - URLContainer urlContainer = new URLContainer( null, baseUrl ); - if ( decoration.getBannerLeft() != null ) { - resolveBannerPaths( decoration.getBannerLeft(), urlContainer ); + relativizeBannerPaths( decoration.getBannerLeft(), baseUrl ); } if ( decoration.getBannerRight() != null ) { - resolveBannerPaths( decoration.getBannerRight(), urlContainer ); + relativizeBannerPaths( decoration.getBannerRight(), baseUrl ); } for ( Iterator i = decoration.getPoweredBy().iterator(); i.hasNext(); ) { Logo logo = (Logo) i.next(); - resolveLogoPaths( logo, urlContainer ); + relativizeLogoPaths( logo, baseUrl ); } if ( decoration.getBody() != null ) @@ -125,21 +124,21 @@ public class DefaultDecorationModelInher { LinkItem linkItem = (LinkItem) i.next(); - resolveLinkItemPaths( linkItem, urlContainer ); + relativizeLinkItemPaths( linkItem, baseUrl ); } for ( Iterator i = decoration.getBody().getBreadcrumbs().iterator(); i.hasNext(); ) { LinkItem linkItem = (LinkItem) i.next(); - resolveLinkItemPaths( linkItem, urlContainer ); + relativizeLinkItemPaths( linkItem, baseUrl ); } for ( Iterator i = decoration.getBody().getMenus().iterator(); i.hasNext(); ) { Menu menu = (Menu) i.next(); - resolveMenuPaths( menu.getItems(), urlContainer ); + relativizeMenuPaths( menu.getItems(), baseUrl ); } } } @@ -149,23 +148,36 @@ public class DefaultDecorationModelInher * to the oldBaseUrl, these are changed to the newBannerUrl. * * @param banner - * @param urlContainer + * @param baseUrl */ - private void resolveBannerPaths( final Banner banner, final URLContainer urlContainer ) + private void relativizeBannerPaths( final Banner banner, final String baseUrl ) { if ( banner != null ) { if ( StringUtils.isNotEmpty( banner.getHref() ) ) { - banner.setHref( convertPath( banner.getHref(), urlContainer ) ); + banner.setHref( relativizeLink( banner.getHref(), baseUrl ) ); } if ( StringUtils.isNotEmpty( banner.getSrc() ) ) { - banner.setSrc( convertPath( banner.getSrc(), urlContainer ) ); + banner.setSrc( relativizeLink( banner.getSrc(), baseUrl ) ); } } } + private void rebaseBannerPaths( final Banner banner, final URLContainer urlContainer ) + { + if ( banner.getHref() != null ) // it may be empty + { + banner.setHref( rebaseLink( banner.getHref(), urlContainer ) ); + } + + if ( banner.getSrc() != null ) + { + banner.setSrc( rebaseLink( banner.getSrc(), urlContainer ) ); + } + } + private void assembleCustomInheritance( final DecorationModel child, final DecorationModel parent ) { if ( child.getCustom() == null ) @@ -212,7 +224,7 @@ public class DefaultDecorationModelInher { LinkItem breadcrumb = new LinkItem(); breadcrumb.setName( name ); - breadcrumb.setHref( convertPath( urlContainer.getNewPath(), urlContainer ) ); + breadcrumb.setHref( "" ); cBody.getBreadcrumbs().add( breadcrumb ); } cBody.setBreadcrumbs( mergeLinkItemLists( cBody.getBreadcrumbs(), pBody.getBreadcrumbs(), urlContainer ) ); @@ -242,34 +254,44 @@ public class DefaultDecorationModelInher menus.add( topCounter, menu ); topCounter++; - resolveMenuPaths( menu.getItems(), urlContainer ); + rebaseMenuPaths( menu.getItems(), urlContainer ); } else if ( "bottom".equals( menu.getInherit() ) ) { menus.add( menu ); - resolveMenuPaths( menu.getItems(), urlContainer ); + rebaseMenuPaths( menu.getItems(), urlContainer ); } } return menus; } - private void resolveMenuPaths( final List items, final URLContainer urlContainer ) + private void relativizeMenuPaths( final List items, final String baseUrl ) { for ( Iterator i = items.iterator(); i.hasNext(); ) { MenuItem item = (MenuItem) i.next(); - resolveLinkItemPaths( item, urlContainer ); - resolveMenuPaths( item.getItems(), urlContainer ); + relativizeLinkItemPaths( item, baseUrl ); + relativizeMenuPaths( item.getItems(), baseUrl ); } } - private void resolveLinkItemPaths( final LinkItem item, final URLContainer urlContainer ) + private void rebaseMenuPaths( final List items, final URLContainer urlContainer ) + { + for ( Iterator i = items.iterator(); i.hasNext(); ) + { + MenuItem item = (MenuItem) i.next(); + rebaseLinkItemPaths( item, urlContainer ); + rebaseMenuPaths( item.getItems(), urlContainer ); + } + } + + private void relativizeLinkItemPaths( final LinkItem item, final String baseUrl ) { if ( StringUtils.isNotEmpty( item.getHref() ) ) { - String href = convertPath( item.getHref(), urlContainer ); + String href = relativizeLink( item.getHref(), baseUrl ); if ( StringUtils.isNotEmpty( href ) ) { item.setHref( href ); @@ -277,14 +299,25 @@ public class DefaultDecorationModelInher } else { - item.setHref( convertPath( "", urlContainer ) ); + item.setHref( relativizeLink( "", baseUrl ) ); } } - private void resolveLogoPaths( final Logo logo, final URLContainer urlContainer ) + private void rebaseLinkItemPaths( final LinkItem item, final URLContainer urlContainer ) + { + item.setHref( rebaseLink( item.getHref(), urlContainer ) ); + } + + private void relativizeLogoPaths( final Logo logo, final String baseUrl ) + { + logo.setImg( relativizeLink( logo.getImg(), baseUrl ) ); + relativizeLinkItemPaths( logo, baseUrl ); + } + + private void rebaseLogoPaths( final Logo logo, final URLContainer urlContainer ) { - logo.setImg( convertPath( logo.getImg(), urlContainer ) ); - resolveLinkItemPaths( logo, urlContainer ); + logo.setImg( rebaseLink( logo.getImg(), urlContainer ) ); + rebaseLinkItemPaths( logo, urlContainer ); } private List mergeLinkItemLists( final List childList, final List parentList, final URLContainer urlContainer ) @@ -295,7 +328,7 @@ public class DefaultDecorationModelInher { LinkItem item = (LinkItem) ( (LinkItem) it.next() ).clone(); - resolveLinkItemPaths( item, urlContainer ); + rebaseLinkItemPaths( item, urlContainer ); if ( !items.contains( item ) ) { @@ -329,7 +362,7 @@ public class DefaultDecorationModelInher logos.add( logo ); } - resolveLogoPaths( logo, urlContainer ); + rebaseLogoPaths( logo, urlContainer ); } for ( Iterator it = childList.iterator(); it.hasNext(); ) @@ -345,20 +378,48 @@ public class DefaultDecorationModelInher return logos; } - private String convertPath( final String relativePath, final URLContainer urlContainer ) + // rebase only affects relative links, a relative link wrt an old base gets translated, + // so it points to the same location as viewed from a new base + private String rebaseLink( final String link, final URLContainer urlContainer ) { + if ( link == null || urlContainer.getOldPath() == null ) + { + return link; + } + try { - PathDescriptor oldPathDescriptor = new PathDescriptor( urlContainer.getOldPath(), relativePath ); - PathDescriptor newPathDescriptor = new PathDescriptor( urlContainer.getNewPath(), "" ); + final URIPathDescriptor oldPath = new URIPathDescriptor( urlContainer.getOldPath(), link ); + + return oldPath.rebaseLink( urlContainer.getNewPath() ).toString(); + } + catch ( URISyntaxException ex ) + { + throw new RuntimeException( "Bad URI syntax of either: " + link + + ", and/or " + urlContainer.getOldPath() + + ", and/or " + urlContainer.getNewPath(), ex ); + } + } - PathDescriptor relativePathDescriptor = PathUtils.convertPath( oldPathDescriptor, newPathDescriptor ); + // relativize only affects absolute links, if the link has the same scheme, host and port + // as the base, it is made into a relative link as viewed from the base + private String relativizeLink( final String link, final String baseUri ) + { + if ( link == null || baseUri == null ) + { + return link; + } + + try + { + final URIPathDescriptor path = new URIPathDescriptor( baseUri, link ); - return relativePathDescriptor.getLocation(); + return path.relativizeLink().toString(); } - catch ( MalformedURLException mue ) + catch ( URISyntaxException ex ) { - throw new RuntimeException( "While converting Pathes:", mue ); + throw new RuntimeException( "Bad URI syntax of either: " + link + + ", and/or " + baseUri, ex ); } } Modified: maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/inheritance/PathDescriptor.java URL: http://svn.apache.org/viewvc/maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/inheritance/PathDescriptor.java?rev=1058083&r1=1058082&r2=1058083&view=diff ============================================================================== --- maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/inheritance/PathDescriptor.java (original) +++ maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/inheritance/PathDescriptor.java Wed Jan 12 11:34:02 2011 @@ -31,6 +31,7 @@ import org.codehaus.plexus.util.StringUt * anchor. * * @author <a href="mailto:henn...@apache.org">Henning P. Schmiedehausen</a> + * @deprecated use {...@link URIPathDescriptor} instead. * @version $Id$ */ Modified: maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/inheritance/PathUtils.java URL: http://svn.apache.org/viewvc/maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/inheritance/PathUtils.java?rev=1058083&r1=1058082&r2=1058083&view=diff ============================================================================== --- maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/inheritance/PathUtils.java (original) +++ maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/inheritance/PathUtils.java Wed Jan 12 11:34:02 2011 @@ -29,6 +29,7 @@ import org.codehaus.plexus.util.PathTool * * @author <a href="mailto:br...@apache.org">Brett Porter</a> * @author <a href="mailto:henn...@apache.org">Henning P. Schmiedehausen</a> + * @deprecated this only operates on deprecated classes, it is not used anymore. * @version $Id$ */ public abstract class PathUtils Added: maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/inheritance/URIPathDescriptor.java URL: http://svn.apache.org/viewvc/maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/inheritance/URIPathDescriptor.java?rev=1058083&view=auto ============================================================================== --- maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/inheritance/URIPathDescriptor.java (added) +++ maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/inheritance/URIPathDescriptor.java Wed Jan 12 11:34:02 2011 @@ -0,0 +1,222 @@ +package org.apache.maven.doxia.site.decoration.inheritance; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +import java.net.URI; +import java.net.URISyntaxException; + +import org.codehaus.plexus.util.PathTool; + +/** + * Describes a link that may be absolute or relative, and that is anchored to an absolute URI. + * + * @author ltheussl + * @since 1.1.5 + */ +public class URIPathDescriptor +{ + private final URI baseURI; + private final URI link; + + /** + * A URIPathDescriptor consists of a base URI and a link. + * Both arguments to this constructor have to be parsable to URIs. + * The baseURI parameter has to be absolute in the sense of {...@link URI#isAbsolute()}. + * + * @param baseURI The base URI. Has to be a valid absolute URI. + * In addition, the path of the URI should not have any file part, + * ie <code>http://maven.apache.org/</code> is valid, + * <code>http://maven.apache.org/index.html</code> is not. + * @param link the link. This may be a relative link or an absolute link. + * Note that URIs that start with a "/", ie don't specify a scheme, are considered relative. + * + * @throws URISyntaxException if either argument is not parsable as a URI, + * or if baseURI is not absolute. + */ + public URIPathDescriptor( final String baseURI, final String link ) + throws URISyntaxException + { + final String llink = link.startsWith( "/" ) ? link.substring( 1 ) : link; + final String bbase = baseURI.endsWith( "/" ) ? baseURI : baseURI + "/"; + + this.baseURI = new URI( bbase ).normalize(); + this.link = new URI( llink ).normalize(); + + if ( !this.baseURI.isAbsolute() ) + { + throw new URISyntaxException( baseURI, "Base must be an absolute URI!" ); + } + } + + /** + * Return the base of this URIPathDescriptor as a URI. + * + * @return the base URI. + */ + public URI getBaseURI() + { + return baseURI; + } + + /** + * Return the link of this URIPathDescriptor as a URI. + * + * @return the link URI. + */ + public URI getLink() + { + return link; + } + + /** + * Resolve the link to the base. + * This always returns an absolute URI. If link is absolute, link is returned. + * + * @return the resolved link. This is equivalent to calling + * {...@link #getBaseURI()}...@link URI#resolve(java.net.URI) resolve}( {...@link #getLink()} ). + */ + public URI resolveLink() + { + return baseURI.resolve( link ); + } + + /** + * Calculate the relative link with respect to the base. + * The original link is returned if either + * link is relative; + * or link and base do not share the {...@link #sameSite(java.net.URI) same site}. + * + * @return the link as a relative URI. + */ + public URI relativizeLink() + { + return relativizeLink( baseURI.toString(), link ); + } + + private static URI relativizeLink( final String base, final URI link ) + { + if ( !link.isAbsolute() ) + { + return link; + } + + final URI newBaseURI; + + try + { + newBaseURI = new URI( base ); + } + catch ( URISyntaxException ex ) + { + return link; + } + + if ( !sameSite( link, newBaseURI ) ) + { + return link; + } + + final String relativePath = PathTool.getRelativeFilePath( newBaseURI.getPath(), link.getPath() ); + + try + { + return new URI( relativePath ); + } + catch ( URISyntaxException ex ) + { + return link; + } + } + + /** + * Calculate the link as viewed from a different base. + * This returns the original link if link is absolute. + * This returns {...@link #resolveLink()} if + * newBase == null + * or newBase is not parsable as a URI. + * + * @param newBase the new base URI. Has to be parsable as a URI. + *. + * @return a new relative link. + */ + public URI rebaseLink( final String newBase ) + { + if ( link.isAbsolute() ) + { + return link; + } + + if ( newBase == null ) + { + return resolveLink(); + } + + final URI newBaseURI; + + try + { + newBaseURI = new URI( newBase ); + } + catch ( URISyntaxException ex ) + { + return resolveLink(); + } + + if ( !sameSite( newBaseURI ) ) + { + return resolveLink(); + } + + final String relativeBasePath = PathTool.getRelativeFilePath( newBaseURI.getPath(), baseURI.getPath() ); + + try + { + return new URI( relativeBasePath ).resolve( link ); + } + catch ( URISyntaxException ex ) + { + return resolveLink(); + } + } + + /** + * Check if this URIPathDescriptor lives on the same site as the given URI. + * + * @param uri a URI to compare with. + * + * @return true if {...@link #getBaseURI()} shares the same scheme, host and port with the given URI + * where null values are allowed. + */ + public boolean sameSite( final URI uri ) + { + return sameSite( this.baseURI, uri ); + } + + private static boolean sameSite( final URI baseURI, final URI newBaseURI ) + { + final boolean equalScheme = ( baseURI.getScheme() == null ? newBaseURI.getScheme() == null + : baseURI.getScheme().equals( newBaseURI.getScheme() ) ); + final boolean equalHost = ( baseURI.getHost() == null ? newBaseURI.getHost() == null + : baseURI.getHost().equals( newBaseURI.getHost() ) ); + final boolean equalPort = ( baseURI.getPort() == newBaseURI.getPort() ); + + return ( equalScheme && equalPort && equalHost ); + } +} Modified: maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/test/java/org/apache/maven/doxia/site/decoration/inheritance/DecorationModelInheritenceAssemblerTest.java URL: http://svn.apache.org/viewvc/maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/test/java/org/apache/maven/doxia/site/decoration/inheritance/DecorationModelInheritenceAssemblerTest.java?rev=1058083&r1=1058082&r2=1058083&view=diff ============================================================================== --- maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/test/java/org/apache/maven/doxia/site/decoration/inheritance/DecorationModelInheritenceAssemblerTest.java (original) +++ maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/test/java/org/apache/maven/doxia/site/decoration/inheritance/DecorationModelInheritenceAssemblerTest.java Wed Jan 12 11:34:02 2011 @@ -64,7 +64,7 @@ public class DecorationModelInheritenceA childModel = readModel( "child.xml" ); assembler.assembleModelInheritance( NAME, childModel, parentModel, "scp://people.apache.org/doxia", "scp://people.apache.org" ); - // FIXME! assertEquals( "Check scp result", mergedModel, childModel ); + assertEquals( "Check scp result", mergedModel, childModel ); assertEquals( "Modified parent!", readModel( "parent.xml" ), parentModel ); } @@ -150,7 +150,7 @@ public class DecorationModelInheritenceA childModel = readModel( "empty.xml" ); assembler.assembleModelInheritance( NAME, childModel, parentModel, "scp://people.apache.org/doxia", "scp://people.apache.org" ); - //FIXME! assertPathsResolvedForRelativeUrls( childModel ); + assertPathsResolvedForRelativeUrls( childModel ); assertEquals( "Modified parent!", readModel( "relative-urls.xml" ), parentModel ); } @@ -186,13 +186,16 @@ public class DecorationModelInheritenceA assembler.assembleModelInheritance( NAME, childModel, parentModel, "http://maven.apache.org/doxia/", "http://maven.apache.org" ); + assembler.resolvePaths( childModel, "http://maven.apache.org/doxia" ); + assertPathsResolvedForSubsiteUrls( childModel ); // same with scp url, DOXIASITETOOLS-47 childModel = readModel( "empty.xml" ); assembler.assembleModelInheritance( NAME, childModel, parentModel, "scp://people.apache.org/doxia", "scp://people.apache.org" ); - //FIXME! assertPathsResolvedForSubsiteUrls( childModel ); + assembler.resolvePaths( childModel, "http://maven.apache.org/doxia" ); + assertPathsResolvedForSubsiteUrls( childModel ); assertEquals( "Modified parent!", readModel( "subsite-urls.xml" ), parentModel ); } @@ -234,7 +237,7 @@ public class DecorationModelInheritenceA childModel = readModel( "empty.xml" ); assembler.assembleModelInheritance( NAME, childModel, parentModel, "scp://people.apache.org/doxia/core", "scp://people.apache.org" ); - //FIXME! assertPathsResolvedForRelativeUrlsDepthOfTwo( childModel ); + assertPathsResolvedForRelativeUrlsDepthOfTwo( childModel ); assertEquals( "Modified parent!", readModel( "relative-urls.xml" ), parentModel ); } @@ -277,7 +280,7 @@ public class DecorationModelInheritenceA childModel = readModel( "empty.xml" ); assembler.assembleModelInheritance( NAME, childModel, parentModel, "scp://people.apache.org/", "scp://people.apache.org/doxia/" ); - //FIXME! assertPathsResolvedForReverseRelativeUrls( childModel ); + assertPathsResolvedForReverseRelativeUrls( childModel ); assertEquals( "Modified parent!", readModel( "relative-urls.xml" ), parentModel ); } @@ -320,7 +323,7 @@ public class DecorationModelInheritenceA childModel = readModel( "empty.xml" ); assembler.assembleModelInheritance( NAME, childModel, parentModel, "scp://people.apache.org/", "scp://people.apache.org/doxia/core/" ); - //FIXME! assertPathsResolvedForReverseRelativeUrlsDepthOfTwo( childModel ); + assertPathsResolvedForReverseRelativeUrlsDepthOfTwo( childModel ); assertEquals( "Modified parent!", readModel( "relative-urls.xml" ), parentModel ); } @@ -363,8 +366,8 @@ public class DecorationModelInheritenceA // same with scp url, DOXIASITETOOLS-47 childModel = readModel( "empty.xml" ); assembler.assembleModelInheritance( NAME, childModel, parentModel, "scp://people.apache.org/", - "scp://jakarta.apache.org" ); - //FIXME! assertPathsResolvedForUnrelatedRelativeUrls( childModel ); + "http://jakarta.apache.org" ); + assertPathsResolvedForUnrelatedRelativeUrls( childModel ); assertEquals( "Modified parent!", readModel( "relative-urls.xml" ), parentModel ); } @@ -443,6 +446,11 @@ public class DecorationModelInheritenceA assembler.assembleModelInheritance( NAME, childModel, parentModel, "http://maven.apache.org/doxia", "http://maven.apache.org" ); + + DecorationModel unresolvedModel = readModel( "fully-populated-unresolved.xml" ); + assertEquals( "Check result", unresolvedModel, childModel ); + + assembler.resolvePaths( childModel, "http://maven.apache.org/doxia" ); DecorationModel mergedModel = readModel( "fully-populated-merged.xml" ); assertEquals( "Check result", mergedModel, childModel ); @@ -451,7 +459,8 @@ public class DecorationModelInheritenceA childModel = readModel( "empty.xml" ); assembler.assembleModelInheritance( NAME, childModel, parentModel, "scp://maven.apache.org/doxia", "scp://maven.apache.org" ); - // FIXME! assertEquals( "Check scp result", mergedModel, childModel ); + assembler.resolvePaths( childModel, "http://maven.apache.org/doxia" ); + assertEquals( "Check scp result", mergedModel, childModel ); assertEquals( "Modified parent!", readModel( "fully-populated-child.xml" ), parentModel ); } Added: maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/test/java/org/apache/maven/doxia/site/decoration/inheritance/URIPathDescriptorTest.java URL: http://svn.apache.org/viewvc/maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/test/java/org/apache/maven/doxia/site/decoration/inheritance/URIPathDescriptorTest.java?rev=1058083&view=auto ============================================================================== --- maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/test/java/org/apache/maven/doxia/site/decoration/inheritance/URIPathDescriptorTest.java (added) +++ maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/test/java/org/apache/maven/doxia/site/decoration/inheritance/URIPathDescriptorTest.java Wed Jan 12 11:34:02 2011 @@ -0,0 +1,95 @@ + +package org.apache.maven.doxia.site.decoration.inheritance; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +import junit.framework.TestCase; + +/** + * + * @author ltheussl + * @since 1.1.5 + */ +public class URIPathDescriptorTest + extends TestCase +{ + /** + * Test of resolveLink method, of class URIPathDescriptor. + * + * @throws Exception + */ + public void testResolveLink() + throws Exception + { + URIPathDescriptor oldPath = new URIPathDescriptor( "http://maven.apache.org/", "source" ); + assertEquals( "http://maven.apache.org/source", oldPath.resolveLink().toString() ); + + oldPath = new URIPathDescriptor( "http://maven.apache.org/", "source/" ); + assertEquals( "http://maven.apache.org/source/", oldPath.resolveLink().toString() ); + + oldPath = new URIPathDescriptor( "http://maven.apache.org/", "/source" ); + assertEquals( "http://maven.apache.org/source", oldPath.resolveLink().toString() ); + + oldPath = new URIPathDescriptor( "http://maven.apache.org", "source" ); + assertEquals( "http://maven.apache.org/source", oldPath.resolveLink().toString() ); + } + + /** + * Test of rebaseLink method, of class URIPathDescriptor. + * + * @throws Exception + */ + public void testRebaseLink() + throws Exception + { + URIPathDescriptor oldPath = new URIPathDescriptor( "http://maven.apache.org/", "source" ); + assertEquals( "../source", oldPath.rebaseLink( "http://maven.apache.org/doxia/" ).toString() ); + + oldPath = new URIPathDescriptor( "scp://people.apache.org/", "source" ); + assertEquals( "../source", oldPath.rebaseLink( "scp://people.apache.org/doxia" ).toString() ); + + oldPath = new URIPathDescriptor( "http://maven.apache.org/", "banner/left" ); + assertEquals( "../banner/left", oldPath.rebaseLink( "http://maven.apache.org/doxia/" ).toString() ); + + oldPath = new URIPathDescriptor( "http://jakarta.apache.org/", "banner/left" ); + assertEquals( "http://jakarta.apache.org/banner/left", oldPath.rebaseLink( "http://maven.apache.org/" ).toString() ); + } + + /** + * Test of relativizeLink method, of class URIPathDescriptor. + * + * @throws Exception + */ + public void testRelativizeLink() + throws Exception + { + URIPathDescriptor path = new URIPathDescriptor( "http://maven.apache.org/", "source" ); + assertEquals( "source", path.relativizeLink().toString() ); + + path = new URIPathDescriptor( "http://maven.apache.org/", "http://maven.apache.org/source" ); + assertEquals( "source", path.relativizeLink().toString() ); + + path = new URIPathDescriptor( "http://maven.apache.org/doxia/", "http://maven.apache.org/source/" ); + assertEquals( "../source/", path.relativizeLink().toString() ); + + path = new URIPathDescriptor( "http://maven.apache.org/doxia", "http://maven.apache.org/source" ); + assertEquals( "../source", path.relativizeLink().toString() ); + } +} Added: maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/test/resources/fully-populated-unresolved.xml URL: http://svn.apache.org/viewvc/maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/test/resources/fully-populated-unresolved.xml?rev=1058083&view=auto ============================================================================== --- maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/test/resources/fully-populated-unresolved.xml (added) +++ maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/test/resources/fully-populated-unresolved.xml Wed Jan 12 11:34:02 2011 @@ -0,0 +1,62 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you 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. +--> + +<project xmlns="http://maven.apache.org/DECORATION/1.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/DECORATION/1.0.0 file:../../../target/generated-site/xsd/decoration-1.0.0.xsd" + name="Empty"> + <bannerLeft> + <name>name</name> + <src>../src</src> + <href>../href</href> + </bannerLeft> + <bannerRight> + <name>name</name> + <src>../src</src> + <href>../href</href> + </bannerRight> + + <publishDate format="fmt" position="top"/> + <version position="right" /> + + <poweredBy> + <logo name="Maven" href="http://maven.apache.org" img="http://maven.apache.org/images/maven-feather.png"/> + </poweredBy> + + <skin> + <groupId>org.apache.maven.skins</groupId> + <artifactId>maven-default-skin</artifactId> + </skin> + + <body> + <head> + <meta name="blah" value="blah"/> + </head> + + <links> + <item name="Bouncy Castle" href="http://www.bouncycastle.org"/> + </links> + </body> + + <custom> + <junk>junk</junk> + </custom> +</project>