o MAVEN-276: Initial checkin. Product is functional, but not optimised for simplicity / performance

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@112940 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
bwalding 2003-02-16 23:05:23 +00:00
parent b97acf616b
commit e1e560c2da
12 changed files with 365 additions and 7 deletions

View File

@ -0,0 +1,174 @@
package org.apache.maven;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Maven" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Maven", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
import java.util.List;
import org.dom4j.Attribute;
import org.dom4j.Node;
import org.dom4j.tree.DefaultElement;
/**
* @author <a href="bwalding@jakarta.org">Ben Walding</a>
* @version $Id: NavBean.java,v 1.1 2003/02/16 23:03:02 bwalding Exp $
*/
public class NavBean
{
private String location;
private Node document;
public void setDocument(Object o)
{
document = (Node) o;
Node loc = document.selectSingleNode("//location");
if (loc != null)
location = loc.getStringValue();
}
private static String getAttribute(DefaultElement elem, String attribute, String defaultValue)
{
Attribute attr = elem.attribute(attribute);
if (attr == null)
return defaultValue;
return attr.getStringValue();
}
private static boolean getCollapseAttribute(DefaultElement elem)
{
return Boolean.valueOf(getAttribute(elem, "collapse", "false")).booleanValue();
}
private static String getHREFAttribute(DefaultElement elem)
{
return getAttribute(elem, "href", null);
}
/**
* Determines if the given node is collapsed. If a parent of this node is
* collapsed, this will give spurious results.
* @param o
* @return boolean
*/
public boolean isCollapsed(Object o)
{
//If we don't know where we are, collapse it - something outside of our knowledge
if (location == null)
return true;
if (!(o instanceof DefaultElement))
{
System.out.println(o.getClass().getName());
return false;
}
DefaultElement elem = (DefaultElement) o;
boolean collapsed = getCollapseAttribute(elem);
if (!collapsed)
return false;
if (isSelected(o))
return false;
String xpath = ".//item[@href='" + location + "']";
List l = elem.selectNodes(xpath);
if (l.size() != 0)
return false;
return true;
}
/**
* Determines if a given <code>item</code> node is the selected node
* @param o
* @return boolean
*/
public boolean isSelected(Object o)
{
if (location == null)
return false;
DefaultElement elem = (DefaultElement) o;
if (location.equals(getHREFAttribute(elem)))
return true;
return false;
}
/**
* Sets the location.
* @param location The location to set
*/
public void setLocation(String location)
{
this.location = location;
}
/**
* Find the first <code>item</code> with a given href
* @param href
* @return DefaultElement
*/
public DefaultElement getFirstNodeByHREF(String href)
{
String xpath = "//item[@href='" + href + "']";
return (DefaultElement) document.selectSingleNode(xpath);
}
}

View File

@ -10,8 +10,13 @@
xmlns:doc="doc"
xmlns="dummy" trim="false">
<jsl:template match="document" trim="false">
<x:doctype name="html"
<j:useBean var="navbean" class="org.apache.maven.NavBean"/>
<j:setProperties object="navbean"
document="${doc}"/>
${navbean.setDocument(doc)}
<x:doctype name="html"
publicId="-//CollabNet//DTD XHTML 1.0 Transitional//EN"
systemId="http://www.collabnet.com/dtds/collabnet_transitional_10.dtd"/>
@ -431,11 +436,22 @@
</jsl:template>
<jsl:template match="item" trim="false">
<x:set var="item" select="."/>
<j:set var="_name"><x:expr select="@name"/></j:set>
<j:set var="_link"><x:expr select="@href"/></j:set>
<div>
<j:set var="_name"><x:expr select="@name"/></j:set>
<j:set var="_link"><x:expr select="@href"/></j:set>
<small><doc:itemLink name="${_name}" link="${_link}"/></small>
<jsl:applyTemplates select="item"/>
<small>
<j:if test="${navbean.isSelected(item.get(0))}">
<b><doc:itemLink name="${_name}" link="${_link}"/></b>
</j:if>
<j:if test="${!navbean.isSelected(item.get(0))}">
<doc:itemLink name="${_name}" link="${_link}"/>
</j:if>
</small>
<j:if test="${!navbean.isCollapsed(item.get(0))}">
<jsl:applyTemplates select="item"/>
</j:if>
</div>
</jsl:template>

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<project name="Maven xdoc Plugin">
<title>Maven xdoc Plugin</title>
<body>
<links>
<item name="Maven" href="http://jakarta.apache.org/turbine/maven/"/>
</links>
<menu>
<item name="Alpha" href="/alpha/index.html">
<item name="Alpha One" href="/alpha/one/index.html"/>
<item name="Alpha Two" href="/alpha/two/index.html"/>
</item>
<item name="Beta" href="/beta/index.html" collapse="true">
<item name="Beta One" href="/beta/one/index.html" collapse="true"/>
<item name="Beta Two" href="/beta/two/index.html" collapse="true"/>
</item>
</menu>
</body>
</project>

View File

@ -0,0 +1,140 @@
package org.apache.maven;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Maven" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Maven", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
import java.io.File;
import java.io.FileInputStream;
import junit.framework.TestCase;
import org.dom4j.Document;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;
/**
* @author <a href="bwalding@jakarta.org">Ben Walding</a>
* @version $Id: NavBeanTest.java,v 1.1 2003/02/16 23:03:37 bwalding Exp $
*/
public class NavBeanTest extends TestCase
{
private File testResources;
public void setUp() {
testResources = new File(System.getProperty("basedir") + "/src/test-resources");
}
class Test
{
String href;
boolean collapsed;
public Test(String href, boolean collapsed)
{
this.href = href;
this.collapsed = collapsed;
}
}
private Test[] testAlpha =
{
new Test("/alpha/index.html", false),
new Test("/alpha/one/index.html", false),
new Test("/alpha/two/index.html", false),
new Test("/beta/index.html", true)};
private Test[] testBeta =
{
new Test("/alpha/index.html", false),
new Test("/alpha/one/index.html", false),
new Test("/alpha/two/index.html", false),
new Test("/beta/index.html", false),
new Test("/beta/one/index.html", true),
new Test("/beta/two/index.html", true)};
public void testAlpha() throws Exception
{
testGroup("/alpha/index.html", testAlpha);
}
public void testBeta() throws Exception
{
testGroup("/beta/index.html", testBeta);
}
protected Document getTestDocument() throws Exception
{
SAXReader reader = new SAXReader();
return reader.read(new FileInputStream(new File(testResources, "navigation.xml")));
}
public void testGroup(String location, Test[] tests) throws Exception
{
NavBean nb = new NavBean();
nb.setDocument(getTestDocument());
nb.setLocation(location);
for (int i = 0; i < tests.length; i++)
{
Test test = tests[i];
Node node = nb.getFirstNodeByHREF(test.href);
assertNotNull(node);
assertEquals(test.href + ".isCollapsed()", test.collapsed, nb.isCollapsed(node));
}
}
}

View File

@ -4,6 +4,7 @@
<properties>
<title>ALPHA</title>
<author email="bwalding@apache.org">Ben Walding</author>
<location>/alpha/index.html</location>
</properties>
<body>

View File

@ -4,6 +4,7 @@
<properties>
<title>ALPHA / ONE</title>
<author email="bwalding@apache.org">Ben Walding</author>
<location>/alpha/one/index.html</location>
</properties>
<body>

View File

@ -4,6 +4,7 @@
<properties>
<title>ALPHA / TWO</title>
<author email="bwalding@apache.org">Ben Walding</author>
<location>/alpha/two/index.html</location>
</properties>
<body>

View File

@ -4,6 +4,7 @@
<properties>
<title>BETA</title>
<author email="bwalding@apache.org">Ben Walding</author>
<location>/beta/index.html</location>
</properties>
<body>

View File

@ -4,6 +4,7 @@
<properties>
<title>BETA / ONE</title>
<author email="bwalding@apache.org">Ben Walding</author>
<location>/beta/one/index.html</location>
</properties>
<body>

View File

@ -4,6 +4,7 @@
<properties>
<title>BETA / TWO</title>
<author email="bwalding@apache.org">Ben Walding</author>
<location>/beta/two/index.html</location>
</properties>
<body>

View File

@ -4,6 +4,7 @@
<properties>
<title>ROOT</title>
<author email="bwalding@apache.org">Ben Walding</author>
<location>/index.html</location>
</properties>
<body>

View File

@ -12,7 +12,7 @@
<item name="Alpha One" href="/alpha/one/index.html"/>
<item name="Alpha Two" href="/alpha/two/index.html"/>
</item>
<item name="Beta" href="/beta/index.html" expanded="true">
<item name="Beta" href="/beta/index.html" collapse="true">
<item name="Beta One" href="/beta/one/index.html"/>
<item name="Beta Two" href="/beta/two/index.html"/>
</item>