maven-doxia-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r366471 - in /maven/doxia/trunk/doxia-decoration-model/src: main/java/org/apache/maven/doxia/site/decoration/inheritance/ test/java/org/apache/maven/doxia/site/decoration/inheritance/ test/resources/
Date Fri, 06 Jan 2006 10:40:32 GMT
Author: brett
Date: Fri Jan  6 02:40:18 2006
New Revision: 366471

URL: http://svn.apache.org/viewcvs?rev=366471&view=rev
Log:
[MSITE-62] improve relative path discovery and apply to whole descriptor

Added:
    maven/doxia/trunk/doxia-decoration-model/src/test/resources/relative-urls-resolved.xml
  (with props)
    maven/doxia/trunk/doxia-decoration-model/src/test/resources/subsite-relative-urls-resolved.xml
  (with props)
Modified:
    maven/doxia/trunk/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/inheritance/DecorationModelInheritanceAssembler.java
    maven/doxia/trunk/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/inheritance/DefaultDecorationModelInheritanceAssembler.java
    maven/doxia/trunk/doxia-decoration-model/src/test/java/org/apache/maven/doxia/site/decoration/inheritance/DecorationModelInheritenceAssemblerTest.java

Modified: maven/doxia/trunk/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/inheritance/DecorationModelInheritanceAssembler.java
URL: http://svn.apache.org/viewcvs/maven/doxia/trunk/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/inheritance/DecorationModelInheritanceAssembler.java?rev=366471&r1=366470&r2=366471&view=diff
==============================================================================
--- maven/doxia/trunk/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/inheritance/DecorationModelInheritanceAssembler.java
(original)
+++ maven/doxia/trunk/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/inheritance/DecorationModelInheritanceAssembler.java
Fri Jan  6 02:40:18 2006
@@ -29,4 +29,6 @@
 
     void assembleModelInheritance( DecorationModel child, DecorationModel parent, String
childBaseUrl,
                                    String parentBaseUrl );
+
+    void resolvePaths( DecorationModel decoration, String baseUrl );
 }

Modified: maven/doxia/trunk/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/inheritance/DefaultDecorationModelInheritanceAssembler.java
URL: http://svn.apache.org/viewcvs/maven/doxia/trunk/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/inheritance/DefaultDecorationModelInheritanceAssembler.java?rev=366471&r1=366470&r2=366471&view=diff
==============================================================================
--- maven/doxia/trunk/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/inheritance/DefaultDecorationModelInheritanceAssembler.java
(original)
+++ maven/doxia/trunk/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/inheritance/DefaultDecorationModelInheritanceAssembler.java
Fri Jan  6 02:40:18 2006
@@ -45,6 +45,11 @@
     {
         String prefix = getParentPrefix( parentBaseUrl, childBaseUrl );
 
+        if ( !prefix.endsWith( "/" ) )
+        {
+            prefix += "/";
+        }
+
         // cannot inherit from null parent.
         if ( parent != null )
         {
@@ -81,6 +86,52 @@
         }
     }
 
+    public void resolvePaths( DecorationModel decoration, String baseUrl )
+    {
+        String prefix = ".";
+
+        if ( decoration.getBannerLeft() != null )
+        {
+            resolveBannerPaths( decoration.getBannerLeft(), prefix, baseUrl );
+        }
+
+        if ( decoration.getBannerRight() != null )
+        {
+            resolveBannerPaths( decoration.getBannerRight(), prefix, baseUrl );
+        }
+
+        for ( Iterator i = decoration.getPoweredBy().iterator(); i.hasNext(); )
+        {
+            Logo logo = (Logo) i.next();
+
+            resolveLogoPaths( logo, prefix, baseUrl );
+        }
+
+        if ( decoration.getBody() != null )
+        {
+            for ( Iterator i = decoration.getBody().getLinks().iterator(); i.hasNext(); )
+            {
+                LinkItem linkItem = (LinkItem) i.next();
+
+                resolveLinkItemPaths( linkItem, prefix, baseUrl );
+            }
+
+            for ( Iterator i = decoration.getBody().getBreadcrumbs().iterator(); i.hasNext();
)
+            {
+                LinkItem linkItem = (LinkItem) i.next();
+
+                resolveLinkItemPaths( linkItem, prefix, baseUrl );
+            }
+
+            for ( Iterator i = decoration.getBody().getMenus().iterator(); i.hasNext(); )
+            {
+                Menu menu = (Menu) i.next();
+
+                resolveMenuPaths( menu.getItems(), prefix, baseUrl );
+            }
+        }
+    }
+
     private void resolveBannerPaths( Banner banner, String prefix, String baseUrl )
     {
         if ( banner != null )
@@ -92,11 +143,7 @@
 
     private String resolvePath( String href, String prefix, String baseUrl )
     {
-        String relativePath = href;
-        if ( relativePath.startsWith( baseUrl ) )
-        {
-            relativePath = relativePath.substring( baseUrl.length() );
-        }
+        String relativePath = getParentPrefix( href, baseUrl );
 
         if ( relativePath.startsWith( "/" ) )
         {
@@ -272,25 +319,87 @@
         {
             prefix = getRelativePath( parentUrl, childUrl );
         }
-
-        if ( !prefix.endsWith( "/" ) )
+        else
         {
-            prefix += "/";
+            String[] parentSplit = splitUrl( parentUrl );
+            String[] childSplit = splitUrl( childUrl );
+
+            if ( parentSplit != null && childSplit != null )
+            {
+                if ( parentSplit[0].equals( childSplit[0] ) && parentSplit[1].equals(
childSplit[1] ) )
+                {
+                    prefix = "";
+                    boolean mismatched = false;
+                    String parentPath = parentSplit[2].substring( 1 );
+                    String childPath = childSplit[2].substring( 1 );
+                    StringTokenizer tok = new StringTokenizer( childPath, "/" );
+                    while ( tok.hasMoreTokens() )
+                    {
+                        String part = tok.nextToken();
+
+                        if ( !mismatched && parentPath.startsWith( part ) )
+                        {
+                            parentPath = parentPath.substring( part.length() );
+                            if ( parentPath.startsWith( "/" ) )
+                            {
+                                parentPath = parentPath.substring( 1 );
+                            }
+                        }
+                        else
+                        {
+                            mismatched = true;
+                            if ( parentPath.length() > 0 )
+                            {
+                                prefix += "../";
+                            }
+                        }
+                    }
+                    prefix += parentPath;
+                }
+            }
         }
 
         return prefix;
     }
 
+    private static String[] splitUrl( String url )
+    {
+        String[] retValue = null;
+
+        int protocolIndex = url.indexOf( "://" );
+
+        if ( protocolIndex >= 0 )
+        {
+            String protocol = url.substring( 0, protocolIndex );
+
+            String host = url.substring( protocolIndex + 3 );
+
+            int pathIndex = host.indexOf( '/' );
+
+            if ( pathIndex >= 0 )
+            {
+                String path = host.substring( pathIndex );
+                host = host.substring( 0, pathIndex );
+                if ( host.length() == 0 && "file".equals( "protocol" ) )
+                {
+                    host = "localhost";
+                }
+
+                retValue = new String[3];
+                retValue[0] = protocol;
+                retValue[1] = host;
+                retValue[2] = path;
+            }
+        }
+        return retValue;
+    }
+
     private static String getRelativePath( String childUrl, String parentUrl )
     {
         String relative = childUrl.substring( parentUrl.length() );
         if ( relative.startsWith( "/" ) )
         {
             relative = relative.substring( 1 );
-        }
-        if ( !relative.endsWith( "/" ) )
-        {
-            relative += "/";
         }
         return relative;
     }

Modified: maven/doxia/trunk/doxia-decoration-model/src/test/java/org/apache/maven/doxia/site/decoration/inheritance/DecorationModelInheritenceAssemblerTest.java
URL: http://svn.apache.org/viewcvs/maven/doxia/trunk/doxia-decoration-model/src/test/java/org/apache/maven/doxia/site/decoration/inheritance/DecorationModelInheritenceAssemblerTest.java?rev=366471&r1=366470&r2=366471&view=diff
==============================================================================
--- maven/doxia/trunk/doxia-decoration-model/src/test/java/org/apache/maven/doxia/site/decoration/inheritance/DecorationModelInheritenceAssemblerTest.java
(original)
+++ maven/doxia/trunk/doxia-decoration-model/src/test/java/org/apache/maven/doxia/site/decoration/inheritance/DecorationModelInheritenceAssemblerTest.java
Fri Jan  6 02:40:18 2006
@@ -312,6 +312,50 @@
         assertEquals( "Check result", mergedModel, childModel );
     }
 
+    public void testResolvingAllExternalUrls()
+        throws IOException, XmlPullParserException
+    {
+        DecorationModel model = readModel( "external-urls.xml" );
+
+        assembler.resolvePaths( model, "http://foo.com/" );
+
+        DecorationModel resolvedModel = readModel( "external-urls.xml" );
+        assertEquals( "Check result", resolvedModel, model );
+    }
+
+    public void testResolvingAllRelativeUrls()
+        throws IOException, XmlPullParserException
+    {
+        DecorationModel model = readModel( "relative-urls.xml" );
+
+        assembler.resolvePaths( model, "http://foo.com/" );
+
+        DecorationModel resolvedModel = readModel( "relative-urls-resolved.xml" );
+        assertEquals( "Check result", resolvedModel, model );
+    }
+
+    public void testResolvingAllSiteUrls()
+        throws IOException, XmlPullParserException
+    {
+        DecorationModel model = readModel( "subsite-urls.xml" );
+
+        assembler.resolvePaths( model, "http://maven.apache.org/" );
+
+        DecorationModel resolvedModel = readModel( "relative-urls-resolved.xml" );
+        assertEquals( "Check result", resolvedModel, model );
+    }
+
+    public void testResolvingAllSiteChildUrls()
+        throws IOException, XmlPullParserException
+    {
+        DecorationModel model = readModel( "subsite-urls.xml" );
+
+        assembler.resolvePaths( model, "http://maven.apache.org/foo" );
+
+        DecorationModel resolvedModel = readModel( "subsite-relative-urls-resolved.xml" );
+        assertEquals( "Check result", resolvedModel, model );
+    }
+
     private DecorationModel readModel( String name )
         throws IOException, XmlPullParserException
     {

Added: maven/doxia/trunk/doxia-decoration-model/src/test/resources/relative-urls-resolved.xml
URL: http://svn.apache.org/viewcvs/maven/doxia/trunk/doxia-decoration-model/src/test/resources/relative-urls-resolved.xml?rev=366471&view=auto
==============================================================================
--- maven/doxia/trunk/doxia-decoration-model/src/test/resources/relative-urls-resolved.xml
(added)
+++ maven/doxia/trunk/doxia-decoration-model/src/test/resources/relative-urls-resolved.xml
Fri Jan  6 02:40:18 2006
@@ -0,0 +1,46 @@
+<!--
+  ~ Copyright 2004-2006 The Apache Software Foundation.
+  ~
+  ~ 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.
+  ~
+  -->
+
+<project name="Parent Name">
+  <bannerLeft>
+    <name>The Jakarta Project</name>
+    <src>images/jakarta-logo.gif</src>
+    <href>banner/left</href>
+  </bannerLeft>
+  <bannerRight>
+    <name>Jakarta Commons Sandbox</name>
+    <src>commons/images/logo.png</src>
+    <href>banner/right/</href>
+  </bannerRight>
+
+  <poweredBy>
+    <logo name="Tomcat" href="/tomcat" img="tomcat/logo.gif"/>
+  </poweredBy>
+
+  <body>
+    <breadcrumbs>
+      <item name="Apache" href="apache"/>
+    </breadcrumbs>
+
+    <links>
+      <item name="Bouncy Castle" href="bouncycastle/"/>
+    </links>
+
+    <menu name="Special" inherit="top">
+      <item name="Special" href="special/"/>
+    </menu>
+  </body>
+</project>

Propchange: maven/doxia/trunk/doxia-decoration-model/src/test/resources/relative-urls-resolved.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/doxia/trunk/doxia-decoration-model/src/test/resources/relative-urls-resolved.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/doxia/trunk/doxia-decoration-model/src/test/resources/subsite-relative-urls-resolved.xml
URL: http://svn.apache.org/viewcvs/maven/doxia/trunk/doxia-decoration-model/src/test/resources/subsite-relative-urls-resolved.xml?rev=366471&view=auto
==============================================================================
--- maven/doxia/trunk/doxia-decoration-model/src/test/resources/subsite-relative-urls-resolved.xml
(added)
+++ maven/doxia/trunk/doxia-decoration-model/src/test/resources/subsite-relative-urls-resolved.xml
Fri Jan  6 02:40:18 2006
@@ -0,0 +1,46 @@
+<!--
+  ~ Copyright 2004-2006 The Apache Software Foundation.
+  ~
+  ~ 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.
+  ~
+  -->
+
+<project name="Parent Name">
+  <bannerLeft>
+    <name>The Jakarta Project</name>
+    <src>../images/jakarta-logo.gif</src>
+    <href>../banner/left</href>
+  </bannerLeft>
+  <bannerRight>
+    <name>Jakarta Commons Sandbox</name>
+    <src>../commons/images/logo.png</src>
+    <href>../banner/right/</href>
+  </bannerRight>
+
+  <poweredBy>
+    <logo name="Tomcat" href="../tomcat" img="../tomcat/logo.gif"/>
+  </poweredBy>
+
+  <body>
+    <breadcrumbs>
+      <item name="Apache" href="../apache"/>
+    </breadcrumbs>
+
+    <links>
+      <item name="Bouncy Castle" href="../bouncycastle/"/>
+    </links>
+
+    <menu name="Special" inherit="top">
+      <item name="Special" href="../special/"/>
+    </menu>
+  </body>
+</project>

Propchange: maven/doxia/trunk/doxia-decoration-model/src/test/resources/subsite-relative-urls-resolved.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/doxia/trunk/doxia-decoration-model/src/test/resources/subsite-relative-urls-resolved.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision



Mime
View raw message