You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by hb...@apache.org on 2017/12/21 12:10:43 UTC
[maven-doxia-sitetools] branch master updated: [DOXIASITETOOLS-185]
added helpers to traverse custom skin parameters
This is an automated email from the ASF dual-hosted git repository.
hboutemy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-doxia-sitetools.git
The following commit(s) were added to refs/heads/master by this push:
new e10a843 [DOXIASITETOOLS-185] added helpers to traverse custom skin parameters
e10a843 is described below
commit e10a843bce0f2620caaf808cddae584c11a90461
Author: Hervé Boutemy <hb...@apache.org>
AuthorDate: Thu Dec 21 13:10:42 2017 +0100
[DOXIASITETOOLS-185] added helpers to traverse custom skin parameters
---
.../doxia/site/decoration/DecorationUtils.java | 52 ++++++++++++++++++++++
doxia-decoration-model/src/main/mdo/decoration.mdo | 34 +++++++++++++-
.../doxia/site/decoration/DecorationUtilsTest.java | 25 +++++++++++
3 files changed, 110 insertions(+), 1 deletion(-)
diff --git a/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/DecorationUtils.java b/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/DecorationUtils.java
index 5afb2fc..20dd732 100644
--- a/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/DecorationUtils.java
+++ b/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/DecorationUtils.java
@@ -20,6 +20,7 @@ package org.apache.maven.doxia.site.decoration;
*/
import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.plexus.util.xml.Xpp3Dom;
/**
* Decoration model utilities.
@@ -60,4 +61,55 @@ public class DecorationUtils
}
return false;
}
+
+ /**
+ * Helper to get decoration custom DOM element by simply specifying a dotted path.
+ *
+ * @param custom the custom DOM element
+ * @param path the dotted path to the child
+ * @return <code>null</code> if any element in the path does not exist
+ * @since 1.8
+ */
+ public static Xpp3Dom getCustomChild( Xpp3Dom custom, String path )
+ {
+ String[] elements = path.split( "\\." );
+ for ( String element : elements )
+ {
+ if ( custom == null )
+ {
+ return null;
+ }
+ custom = custom.getChild( element );
+ }
+ return custom;
+ }
+
+ /**
+ * Helper to get decoration custom DOM element value by simply specifying a dotted path.
+ *
+ * @param custom the custom DOM element
+ * @param path the dotted path to the child
+ * @return the element value or <code>null</code> if any element in the path does not exist
+ * @since 1.8
+ */
+ public static String getCustomValue( Xpp3Dom custom, String path )
+ {
+ custom = getCustomChild( custom, path );
+ return ( custom == null ) ? null : custom.getValue();
+ }
+
+ /**
+ * Helper to get decoration custom DOM element value by simply specifying a dotted path.
+ *
+ * @param custom the custom DOM element
+ * @param path the dotted path to the child
+ * @param defaultValue default value
+ * @return the element value or the default value if any element in the path does not exist
+ * @since 1.8
+ */
+ public static String getCustomValue( Xpp3Dom custom, String path, String defaultValue )
+ {
+ custom = getCustomChild( custom, path );
+ return ( custom == null ) ? defaultValue : custom.getValue();
+ }
}
diff --git a/doxia-decoration-model/src/main/mdo/decoration.mdo b/doxia-decoration-model/src/main/mdo/decoration.mdo
index cac9616..ee867e4 100644
--- a/doxia-decoration-model/src/main/mdo/decoration.mdo
+++ b/doxia-decoration-model/src/main/mdo/decoration.mdo
@@ -25,7 +25,8 @@ under the License.
<id>decoration</id>
<name>Decoration</name>
<description><![CDATA[
- <p>This is a reference for the site decoration descriptor used in Doxia Sitetools, also known as <code>site.xml</code>.</p>
+ <p>This is a reference for the site decoration descriptor used in Doxia Sitetools, also known as <code>site.xml</code>:
+ it is used to configure a site template (aka skin).</p>
<p>An XSD is available at:</p>
<ul>
<!-- There is no property filtering in Modello, this has to be updated manually. See DOXIASITETOOLS-98. -->
@@ -293,6 +294,37 @@ under the License.
}
</code>
</codeSegment>
+ <codeSegment>
+ <version>1.8.0+</version>
+ <code>
+ /**
+ * @since 1.8
+ * @see DecorationUtils#getCustomChild
+ */
+ public Object getCustomChild( String path )
+ {
+ return DecorationUtils.getCustomChild( (org.codehaus.plexus.util.xml.Xpp3Dom) custom, path );
+ }
+
+ /**
+ * @since 1.8
+ * @see DecorationUtils#getCustomValue
+ */
+ public String getCustomValue( String path )
+ {
+ return DecorationUtils.getCustomValue( (org.codehaus.plexus.util.xml.Xpp3Dom) custom, path );
+ }
+
+ /**
+ * @since 1.8
+ * @see DecorationUtils#getCustomValue
+ */
+ public String getCustomValue( String path, String defaultValue )
+ {
+ return DecorationUtils.getCustomValue( (org.codehaus.plexus.util.xml.Xpp3Dom) custom, path, defaultValue );
+ }
+ </code>
+ </codeSegment>
</codeSegments>
</class>
diff --git a/doxia-decoration-model/src/test/java/org/apache/maven/doxia/site/decoration/DecorationUtilsTest.java b/doxia-decoration-model/src/test/java/org/apache/maven/doxia/site/decoration/DecorationUtilsTest.java
index 58be1ca..35e2389 100644
--- a/doxia-decoration-model/src/test/java/org/apache/maven/doxia/site/decoration/DecorationUtilsTest.java
+++ b/doxia-decoration-model/src/test/java/org/apache/maven/doxia/site/decoration/DecorationUtilsTest.java
@@ -1,5 +1,7 @@
package org.apache.maven.doxia.site.decoration;
+import org.codehaus.plexus.util.xml.Xpp3Dom;
+
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -36,4 +38,27 @@ public class DecorationUtilsTest
assertTrue( DecorationUtils.isLink( "mailto:toto@maven.org" ) );
assertTrue( DecorationUtils.isLink( "any-protocol://" ) );
}
+
+ public void testGetCustomChild()
+ {
+ Xpp3Dom dom = new Xpp3Dom( "root" );
+ Xpp3Dom level1 = new Xpp3Dom( "level1" );
+ dom.addChild( level1 );
+ Xpp3Dom level2 = new Xpp3Dom( "level2" );
+ level2.setValue( "value" );
+ level1.addChild( level2 );
+
+ assertEquals( level1, DecorationUtils.getCustomChild( dom, "level1" ) );
+ assertEquals( level2, DecorationUtils.getCustomChild( dom, "level1.level2" ) );
+ assertNull( DecorationUtils.getCustomChild( dom, "no.level2" ) );
+ assertNull( DecorationUtils.getCustomChild( dom, "level1.no" ) );
+
+ assertEquals( "value", DecorationUtils.getCustomValue( dom, "level1.level2" ) );
+ assertNull( DecorationUtils.getCustomValue( dom, "no.level2" ) );
+ assertNull( DecorationUtils.getCustomValue( dom, "level1.no" ) );
+
+ assertEquals( "value", DecorationUtils.getCustomValue( dom, "level1.level2", "default" ) );
+ assertEquals( "default", DecorationUtils.getCustomValue( dom, "no.level2", "default" ) );
+ assertEquals( "default", DecorationUtils.getCustomValue( dom, "level1.no", "default" ) );
+ }
}
--
To stop receiving notification emails like this one, please contact
['"commits@maven.apache.org" <co...@maven.apache.org>'].