maven-doxia-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r366501 - in /maven/doxia/trunk: doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/inheritance/ doxia-decoration-model/src/test/java/org/apache/maven/doxia/site/decoration/inheritance/ doxia-decoration-model/src/te...
Date Fri, 06 Jan 2006 13:39:01 GMT
Author: brett
Date: Fri Jan  6 05:38:46 2006
New Revision: 366501

URL: http://svn.apache.org/viewcvs?rev=366501&view=rev
Log:
[MSITE-51] Add breadcrumbs

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
    maven/doxia/trunk/doxia-decoration-model/src/test/resources/merged.xml
    maven/doxia/trunk/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/DefaultSiteRenderer.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=366501&r1=366500&r2=366501&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 05:38:46 2006
@@ -27,7 +27,7 @@
 {
     String ROLE = DecorationModelInheritanceAssembler.class.getName();
 
-    void assembleModelInheritance( DecorationModel child, DecorationModel parent, String
childBaseUrl,
+    void assembleModelInheritance( String name, 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=366501&r1=366500&r2=366501&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 05:38:46 2006
@@ -40,8 +40,8 @@
 public class DefaultDecorationModelInheritanceAssembler
     implements DecorationModelInheritanceAssembler
 {
-    public void assembleModelInheritance( DecorationModel child, DecorationModel parent,
String childBaseUrl,
-                                          String parentBaseUrl )
+    public void assembleModelInheritance( String name, DecorationModel child, DecorationModel
parent,
+                                          String childBaseUrl, String parentBaseUrl )
     {
         String prefix = getParentPrefix( parentBaseUrl, childBaseUrl );
 
@@ -80,7 +80,7 @@
             child.setPoweredBy(
                 mergePoweredByLists( child.getPoweredBy(), parent.getPoweredBy(), prefix,
parentBaseUrl ) );
 
-            assembleBodyInheritance( child, parent, prefix, parentBaseUrl );
+            assembleBodyInheritance( name, childBaseUrl, child, parent, prefix, parentBaseUrl
);
 
             assembleCustomInheritance( child, parent );
         }
@@ -164,19 +164,25 @@
         }
     }
 
-    private void assembleBodyInheritance( DecorationModel child, DecorationModel parent,
String prefix, String baseUrl )
+    private void assembleBodyInheritance( String name, String childUrl, DecorationModel child,
DecorationModel parent,
+                                          String prefix, String baseUrl )
     {
         Body cBody = child.getBody();
         Body pBody = parent.getBody();
 
-        if ( cBody == null && pBody != null )
+        if ( cBody != null || pBody != null )
         {
-            cBody = new Body();
-            child.setBody( cBody );
-        }
+            if ( cBody == null )
+            {
+                cBody = new Body();
+                child.setBody( cBody );
+            }
+
+            if ( pBody == null )
+            {
+                pBody = new Body();
+            }
 
-        if ( pBody != null )
-        {
             if ( cBody.getHead() == null )
             {
                 cBody.setHead( pBody.getHead() );
@@ -187,6 +193,14 @@
             }
 
             cBody.setLinks( mergeLinkItemLists( cBody.getLinks(), pBody.getLinks(), prefix,
baseUrl ) );
+
+            if ( cBody.getBreadcrumbs().isEmpty() && !pBody.getBreadcrumbs().isEmpty()
)
+            {
+                LinkItem breadcrumb = new LinkItem();
+                breadcrumb.setName( name );
+                breadcrumb.setHref( childUrl );
+                cBody.getBreadcrumbs().add( breadcrumb );
+            }
             cBody.setBreadcrumbs(
                 mergeLinkItemLists( cBody.getBreadcrumbs(), pBody.getBreadcrumbs(), prefix,
baseUrl ) );
 
@@ -240,7 +254,14 @@
 
     private void resolveLinkItemPaths( LinkItem item, String prefix, String baseUrl )
     {
-        item.setHref( resolvePath( item.getHref(), prefix, baseUrl ) );
+        if ( item.getHref() != null )
+        {
+            item.setHref( resolvePath( item.getHref(), prefix, baseUrl ) );
+        }
+        else
+        {
+            item.setHref( "" );
+        }
     }
 
     private void resolveLogoPaths( Logo logo, String prefix, String baseUrl )
@@ -249,52 +270,58 @@
         resolveLinkItemPaths( logo, prefix, baseUrl );
     }
 
-    private List mergeLinkItemLists( List dominant, List recessive, String prefix, String
baseUrl )
+    private List mergeLinkItemLists( List childList, List parentList, String prefix, String
baseUrl )
     {
         List items = new ArrayList();
 
-        for ( Iterator it = dominant.iterator(); it.hasNext(); )
+        for ( Iterator it = parentList.iterator(); it.hasNext(); )
         {
             LinkItem item = (LinkItem) it.next();
 
-            items.add( item );
+            resolveLinkItemPaths( item, prefix, baseUrl );
+
+            if ( !items.contains( item ) )
+            {
+                items.add( item );
+            }
         }
 
-        for ( Iterator it = recessive.iterator(); it.hasNext(); )
+        for ( Iterator it = childList.iterator(); it.hasNext(); )
         {
             LinkItem item = (LinkItem) it.next();
 
             if ( !items.contains( item ) )
             {
                 items.add( item );
-
-                resolveLinkItemPaths( item, prefix, baseUrl );
             }
         }
 
         return items;
     }
 
-    private List mergePoweredByLists( List dominant, List recessive, String prefix, String
baseUrl )
+    private List mergePoweredByLists( List childList, List parentList, String prefix, String
baseUrl )
     {
         List logos = new ArrayList();
 
-        for ( Iterator it = dominant.iterator(); it.hasNext(); )
+        for ( Iterator it = parentList.iterator(); it.hasNext(); )
         {
             Logo logo = (Logo) it.next();
 
-            logos.add( logo );
+            if ( !logos.contains( logo ) )
+            {
+                logos.add( logo );
+            }
+
+            resolveLogoPaths( logo, prefix, baseUrl );
         }
 
-        for ( Iterator it = recessive.iterator(); it.hasNext(); )
+        for ( Iterator it = childList.iterator(); it.hasNext(); )
         {
             Logo logo = (Logo) it.next();
 
             if ( !logos.contains( logo ) )
             {
                 logos.add( logo );
-
-                resolveLogoPaths( logo, prefix, baseUrl );
             }
         }
 
@@ -319,7 +346,7 @@
         {
             prefix = getRelativePath( parentUrl, childUrl );
         }
-/*
+/* [MSITE-62] This is to test the ../ relative paths, which I am inclined not to use
         else
         {
             String[] parentSplit = splitUrl( parentUrl );
@@ -357,6 +384,7 @@
         return prefix;
     }
 
+/* [MSITE-62] This is to test the ../ relative paths, which I am inclined not to use
     private static String[] splitUrl( String url )
     {
         String[] retValue = null;
@@ -388,6 +416,7 @@
         }
         return retValue;
     }
+*/
 
     private static String getRelativePath( String childUrl, String parentUrl )
     {

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=366501&r1=366500&r2=366501&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 05:38:46 2006
@@ -17,6 +17,7 @@
  */
 
 import junit.framework.TestCase;
+import org.apache.maven.doxia.site.decoration.Body;
 import org.apache.maven.doxia.site.decoration.DecorationModel;
 import org.apache.maven.doxia.site.decoration.LinkItem;
 import org.apache.maven.doxia.site.decoration.Logo;
@@ -37,13 +38,15 @@
 {
     private DecorationModelInheritanceAssembler assembler = new DefaultDecorationModelInheritanceAssembler();
 
+    private static final String NAME = "Name";
+
     public void testInheritence()
         throws IOException, XmlPullParserException
     {
         DecorationModel childModel = readModel( "child.xml" );
         DecorationModel parentModel = readModel( "parent.xml" );
 
-        assembler.assembleModelInheritance( childModel, parentModel, "http://maven.apache.org/doxia",
+        assembler.assembleModelInheritance( NAME, childModel, parentModel, "http://maven.apache.org/doxia",
                                             "http://maven.apache.org" );
 
         DecorationModel mergedModel = readModel( "merged.xml" );
@@ -56,7 +59,7 @@
         // Test an empty model avoids NPEs
         DecorationModel childModel = readModel( "empty.xml" );
         DecorationModel parentModel = readModel( "empty.xml" );
-        assembler.assembleModelInheritance( childModel, parentModel, "http://maven.apache.org/doxia",
+        assembler.assembleModelInheritance( NAME, childModel, parentModel, "http://maven.apache.org/doxia",
                                             "http://maven.apache.org" );
 
         DecorationModel mergedModel = readModel( "empty.xml" );
@@ -68,7 +71,7 @@
     {
         DecorationModel parentModel = readModel( "external-urls.xml" );
         DecorationModel childModel = readModel( "empty.xml" );
-        assembler.assembleModelInheritance( childModel, parentModel, "http://maven.apache.org/doxia",
+        assembler.assembleModelInheritance( NAME, childModel, parentModel, "http://maven.apache.org/doxia",
                                             "http://maven.apache.org" );
 
         assertEquals( "check left banner href", "http://jakarta.apache.org/", childModel.getBannerLeft().getHref()
);
@@ -100,7 +103,7 @@
     {
         DecorationModel parentModel = readModel( "relative-urls.xml" );
         DecorationModel childModel = readModel( "empty.xml" );
-        assembler.assembleModelInheritance( childModel, parentModel, "http://maven.apache.org/doxia/",
+        assembler.assembleModelInheritance( NAME, childModel, parentModel, "http://maven.apache.org/doxia/",
                                             "http://maven.apache.org" );
 
         assertEquals( "check left banner href", "../banner/left", childModel.getBannerLeft().getHref()
);
@@ -129,7 +132,7 @@
     {
         DecorationModel parentModel = readModel( "subsite-urls.xml" );
         DecorationModel childModel = readModel( "empty.xml" );
-        assembler.assembleModelInheritance( childModel, parentModel, "http://maven.apache.org/doxia/",
+        assembler.assembleModelInheritance( NAME, childModel, parentModel, "http://maven.apache.org/doxia/",
                                             "http://maven.apache.org" );
 
         assertEquals( "check left banner href", "../banner/left", childModel.getBannerLeft().getHref()
);
@@ -158,7 +161,7 @@
     {
         DecorationModel parentModel = readModel( "relative-urls.xml" );
         DecorationModel childModel = readModel( "empty.xml" );
-        assembler.assembleModelInheritance( childModel, parentModel, "http://maven.apache.org/doxia/core",
+        assembler.assembleModelInheritance( NAME, childModel, parentModel, "http://maven.apache.org/doxia/core",
                                             "http://maven.apache.org" );
 
         assertEquals( "check left banner href", "../../banner/left", childModel.getBannerLeft().getHref()
);
@@ -188,7 +191,7 @@
     {
         DecorationModel parentModel = readModel( "relative-urls.xml" );
         DecorationModel childModel = readModel( "empty.xml" );
-        assembler.assembleModelInheritance( childModel, parentModel, "http://maven.apache.org/",
+        assembler.assembleModelInheritance( NAME, childModel, parentModel, "http://maven.apache.org/",
                                             "http://maven.apache.org/doxia/" );
 
         assertEquals( "check left banner href", "doxia/banner/left", childModel.getBannerLeft().getHref()
);
@@ -218,7 +221,7 @@
     {
         DecorationModel parentModel = readModel( "relative-urls.xml" );
         DecorationModel childModel = readModel( "empty.xml" );
-        assembler.assembleModelInheritance( childModel, parentModel, "http://maven.apache.org/",
+        assembler.assembleModelInheritance( NAME, childModel, parentModel, "http://maven.apache.org/",
                                             "http://maven.apache.org/doxia/core/" );
 
         assertEquals( "check left banner href", "doxia/core/banner/left", childModel.getBannerLeft().getHref()
);
@@ -249,7 +252,7 @@
     {
         DecorationModel parentModel = readModel( "relative-urls.xml" );
         DecorationModel childModel = readModel( "empty.xml" );
-        assembler.assembleModelInheritance( childModel, parentModel, "http://maven.apache.org",
+        assembler.assembleModelInheritance( NAME, childModel, parentModel, "http://maven.apache.org",
                                             "http://jakarta.apache.org" );
 
         assertEquals( "check left banner href", "http://jakarta.apache.org/banner/left",
@@ -281,7 +284,7 @@
         throws IOException, XmlPullParserException
     {
         DecorationModel childModel = readModel( "empty.xml" );
-        assembler.assembleModelInheritance( childModel, null, "http://maven.apache.org/doxia",
+        assembler.assembleModelInheritance( NAME, childModel, null, "http://maven.apache.org/doxia",
                                             "http://maven.apache.org" );
 
         DecorationModel mergedModel = readModel( "empty.xml" );
@@ -293,11 +296,11 @@
     {
         DecorationModel childModel = readModel( "fully-populated-child.xml" );
         DecorationModel parentModel = readModel( "fully-populated-child.xml" );
-        assembler.assembleModelInheritance( childModel, parentModel, "http://maven.apache.org/doxia",
-                                            "http://maven.apache.org" );
+        assembler.assembleModelInheritance( NAME, childModel, parentModel, "http://foo.apache.org/doxia",
+                                            "http://foo.apache.org" );
 
         DecorationModel mergedModel = readModel( "fully-populated-child.xml" );
-        assertEquals( "Check result", mergedModel, childModel );
+        assertEquals( "Check result", mergedModel.toString(), childModel.toString() );
     }
 
     public void testFullyPopulatedParentAndEmptyChild()
@@ -305,7 +308,7 @@
     {
         DecorationModel childModel = readModel( "empty.xml" );
         DecorationModel parentModel = readModel( "fully-populated-child.xml" );
-        assembler.assembleModelInheritance( childModel, parentModel, "http://maven.apache.org/doxia",
+        assembler.assembleModelInheritance( NAME, childModel, parentModel, "http://maven.apache.org/doxia",
                                             "http://maven.apache.org" );
 
         DecorationModel mergedModel = readModel( "fully-populated-merged.xml" );
@@ -345,7 +348,7 @@
         assertEquals( "Check result", resolvedModel, model );
     }
 
-/*
+/* [MSITE-62] This is to test the ../ relative paths, which I am inclined not to use
     public void testResolvingAllSiteChildUrls()
         throws IOException, XmlPullParserException
     {
@@ -389,6 +392,79 @@
 
         DecorationModel resolvedModel = readModel( "empty.xml" );
         assertEquals( "Check result", resolvedModel, model );
+    }
+
+    public void testDuplicateParentElements()
+    {
+        DecorationModel model = new DecorationModel();
+        model.setBody( new Body() );
+        model.getBody().addLink( createLinkItem( "Foo", "http://foo.apache.org" ) );
+        model.getBody().addLink( createLinkItem( "Foo", "http://foo.apache.org" ) );
+
+        model.addPoweredBy( createLogo( "Foo", "http://foo.apache.org", "http://foo.apache.org/foo.jpg"
) );
+        model.addPoweredBy( createLogo( "Foo", "http://foo.apache.org", "http://foo.apache.org/foo.jpg"
) );
+
+        DecorationModel child = new DecorationModel();
+        assembler.assembleModelInheritance( NAME, child, model, "http://maven.apache.org/doxia",
+                                            "http://maven.apache.org" );
+
+        assertEquals( "Check size", 1, child.getBody().getLinks().size() );
+        assertEquals( "Check item", createLinkItem( "Foo", "http://foo.apache.org" ),
+                      child.getBody().getLinks().get( 0 ) );
+
+        assertEquals( "Check size", 1, child.getPoweredBy().size() );
+        assertEquals( "Check item", createLogo( "Foo", "http://foo.apache.org", "http://foo.apache.org/foo.jpg"
),
+                      child.getPoweredBy().get( 0 ) );
+    }
+
+    public void testDuplicateChildElements()
+    {
+        DecorationModel model = new DecorationModel();
+        model.setBody( new Body() );
+        model.getBody().addLink( createLinkItem( "Foo", "http://foo.apache.org" ) );
+        model.getBody().addLink( createLinkItem( "Foo", "http://foo.apache.org" ) );
+
+        model.addPoweredBy( createLogo( "Foo", "http://foo.apache.org", "http://foo.apache.org/foo.jpg"
) );
+        model.addPoweredBy( createLogo( "Foo", "http://foo.apache.org", "http://foo.apache.org/foo.jpg"
) );
+
+        DecorationModel parent = new DecorationModel();
+        assembler.assembleModelInheritance( NAME, model, parent, "http://maven.apache.org/doxia",
+                                            "http://maven.apache.org" );
+
+        assertEquals( "Check size", 1, model.getBody().getLinks().size() );
+        assertEquals( "Check item", createLinkItem( "Foo", "http://foo.apache.org" ),
+                      model.getBody().getLinks().get( 0 ) );
+
+        assertEquals( "Check size", 1, model.getPoweredBy().size() );
+        assertEquals( "Check item", createLogo( "Foo", "http://foo.apache.org", "http://foo.apache.org/foo.jpg"
),
+                      model.getPoweredBy().get( 0 ) );
+    }
+
+    public void testBreadcrumbWithoutHref()
+    {
+        DecorationModel model = new DecorationModel();
+        model.setBody( new Body() );
+        model.getBody().addBreadcrumb( createLinkItem( "Foo", null ) );
+        assembler.resolvePaths( model, "http://foo.apache.org" );
+        assertEquals( "Check size", 1, model.getBody().getBreadcrumbs().size() );
+        assertEquals( "Check item", createLinkItem( "Foo", "" ), model.getBody().getBreadcrumbs().get(
0 ) );
+    }
+
+    private Logo createLogo( String name, String href, String img )
+    {
+        Logo logo = new Logo();
+        logo.setHref( href );
+        logo.setImg( img );
+        logo.setName( name );
+        return logo;
+    }
+
+    private static LinkItem createLinkItem( String name, String href )
+    {
+        LinkItem item = new LinkItem();
+        item.setName( name );
+        item.setHref( href );
+        return item;
     }
 
     private DecorationModel readModel( String name )

Modified: maven/doxia/trunk/doxia-decoration-model/src/test/resources/merged.xml
URL: http://svn.apache.org/viewcvs/maven/doxia/trunk/doxia-decoration-model/src/test/resources/merged.xml?rev=366501&r1=366500&r2=366501&view=diff
==============================================================================
--- maven/doxia/trunk/doxia-decoration-model/src/test/resources/merged.xml (original)
+++ maven/doxia/trunk/doxia-decoration-model/src/test/resources/merged.xml Fri Jan  6 05:38:46
2006
@@ -37,6 +37,7 @@
       <item name="Apache" href="http://www.apache.org/"/>
       <item name="Jakarta Commons" href="http://jakarta.apache.org/commons/"/>
       <item name="Sandbox" href="http://jakarta.apache.org/commons/sandbox/"/>
+      <item name="Name" href="http://maven.apache.org/doxia"/>
     </breadcrumbs>
     <links>
       <item name="Bouncy Castle" href="http://www.bouncycastle.org"/>

Modified: maven/doxia/trunk/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/DefaultSiteRenderer.java
URL: http://svn.apache.org/viewcvs/maven/doxia/trunk/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/DefaultSiteRenderer.java?rev=366501&r1=366500&r2=366501&view=diff
==============================================================================
--- maven/doxia/trunk/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/DefaultSiteRenderer.java
(original)
+++ maven/doxia/trunk/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/DefaultSiteRenderer.java
Fri Jan  6 05:38:46 2006
@@ -243,6 +243,7 @@
         context.put( "dateFormat", new SimpleDateFormat() );
 
         String currentFileName = PathTool.calculateLink( renderingContext.getOutputName(),
relativePath );
+        currentFileName = currentFileName.replace( '\\', '/' );
 
         context.put( "currentFileName", currentFileName );
 



Mime
View raw message