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 2016/02/07 21:12:32 UTC
svn commit: r1729027 - in
/maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src:
main/java/org/apache/maven/doxia/site/decoration/ main/mdo/
test/java/org/apache/maven/doxia/site/decoration/
Author: hboutemy
Date: Sun Feb 7 20:12:32 2016
New Revision: 1729027
URL: http://svn.apache.org/viewvc?rev=1729027&view=rev
Log:
[DOXIASITETOOLS-150] added isLink(href) method for use in skins: $decoration.isLink($href)
Added:
maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/DecorationUtils.java (with props)
maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/test/java/org/apache/maven/doxia/site/decoration/DecorationUtilsTest.java (with props)
Modified:
maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/main/mdo/decoration.mdo
Added: maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/DecorationUtils.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/DecorationUtils.java?rev=1729027&view=auto
==============================================================================
--- maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/DecorationUtils.java (added)
+++ maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/DecorationUtils.java Sun Feb 7 20:12:32 2016
@@ -0,0 +1,63 @@
+package org.apache.maven.doxia.site.decoration;
+
+/*
+ * 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 org.codehaus.plexus.util.StringUtils;
+
+/**
+ * Decoration model utilities.
+ *
+ * @since 1.7
+ */
+public class DecorationUtils
+{
+ public static boolean isLink( String href )
+ {
+ return StringUtils.isNotBlank( href )
+ && ( startsWithAnyIgnoreCase( href, "http:/", "https:/", "ftp:/", "mailto:", "file:/" )
+ || href.contains( "://" ) );
+ }
+
+ private static boolean startsWithIgnoreCase( String str, String prefix )
+ {
+ if ( str == null || prefix == null )
+ {
+ return ( str == null && prefix == null );
+ }
+ if ( prefix.length() > str.length() )
+ {
+ return false;
+ }
+ return str.regionMatches( true, 0, prefix, 0, prefix.length() );
+ }
+
+ public static boolean startsWithAnyIgnoreCase( String string, String... searchStrings )
+ {
+ for ( int i = 0; i < searchStrings.length; i++ )
+ {
+ String searchString = searchStrings[i];
+ if ( startsWithIgnoreCase( string, searchString ) )
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+}
Propchange: maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/DecorationUtils.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/DecorationUtils.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/DecorationUtils.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/main/mdo/decoration.mdo
URL: http://svn.apache.org/viewvc/maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/main/mdo/decoration.mdo?rev=1729027&r1=1729026&r2=1729027&view=diff
==============================================================================
--- maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/main/mdo/decoration.mdo (original)
+++ maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/main/mdo/decoration.mdo Sun Feb 7 20:12:32 2016
@@ -271,6 +271,19 @@ under the License.
]]>
</code>
</codeSegment>
+ <codeSegment>
+ <version>1.7.0+</version>
+ <code>
+ /**
+ * @since 1.7
+ * @see DecorationUtils#isLink
+ */
+ public boolean isLink( String href )
+ {
+ return DecorationUtils.isLink( href );
+ }
+ </code>
+ </codeSegment>
</codeSegments>
</class>
Added: maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/test/java/org/apache/maven/doxia/site/decoration/DecorationUtilsTest.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/test/java/org/apache/maven/doxia/site/decoration/DecorationUtilsTest.java?rev=1729027&view=auto
==============================================================================
--- maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/test/java/org/apache/maven/doxia/site/decoration/DecorationUtilsTest.java (added)
+++ maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/test/java/org/apache/maven/doxia/site/decoration/DecorationUtilsTest.java Sun Feb 7 20:12:32 2016
@@ -0,0 +1,39 @@
+package org.apache.maven.doxia.site.decoration;
+
+/*
+ * 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;
+
+public class DecorationUtilsTest
+ extends TestCase
+{
+ public void testIsLink()
+ {
+ assertFalse( DecorationUtils.isLink( null ) );
+ assertFalse( DecorationUtils.isLink( "" ) );
+ assertFalse( DecorationUtils.isLink( " " ) );
+ assertTrue( DecorationUtils.isLink( "http://maven.apache.org/" ) );
+ assertTrue( DecorationUtils.isLink( "https://maven.apache.org/" ) );
+ assertTrue( DecorationUtils.isLink( "ftp://maven.apache.org/pub/" ) );
+ assertTrue( DecorationUtils.isLink( "file:///home" ) );
+ assertTrue( DecorationUtils.isLink( "mailto:toto@maven.org" ) );
+ assertTrue( DecorationUtils.isLink( "any-protocol://" ) );
+ }
+}
Propchange: maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/test/java/org/apache/maven/doxia/site/decoration/DecorationUtilsTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/test/java/org/apache/maven/doxia/site/decoration/DecorationUtilsTest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/test/java/org/apache/maven/doxia/site/decoration/DecorationUtilsTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain