1 package org.apache.maven.doxia.site.decoration;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.codehaus.plexus.util.StringUtils;
23 import org.codehaus.plexus.util.xml.Xpp3Dom;
24
25
26
27
28
29
30 public class DecorationUtils
31 {
32 public static boolean isLink( String href )
33 {
34 return StringUtils.isNotBlank( href )
35 && ( startsWithAnyIgnoreCase( href, "http:/", "https:/", "ftp:/", "mailto:", "file:/" )
36 || href.contains( "://" ) );
37 }
38
39 private static boolean startsWithIgnoreCase( String str, String prefix )
40 {
41 if ( str == null || prefix == null )
42 {
43 return ( str == null && prefix == null );
44 }
45 if ( prefix.length() > str.length() )
46 {
47 return false;
48 }
49 return str.regionMatches( true, 0, prefix, 0, prefix.length() );
50 }
51
52 public static boolean startsWithAnyIgnoreCase( String string, String... searchStrings )
53 {
54 for ( int i = 0; i < searchStrings.length; i++ )
55 {
56 String searchString = searchStrings[i];
57 if ( startsWithIgnoreCase( string, searchString ) )
58 {
59 return true;
60 }
61 }
62 return false;
63 }
64
65
66
67
68
69
70
71
72
73 public static Xpp3Dom getCustomChild( Xpp3Dom custom, String path )
74 {
75 String[] elements = path.split( "\\." );
76 for ( String element : elements )
77 {
78 if ( custom == null )
79 {
80 return null;
81 }
82 custom = custom.getChild( element );
83 }
84 return custom;
85 }
86
87
88
89
90
91
92
93
94
95 public static String getCustomValue( Xpp3Dom custom, String path )
96 {
97 custom = getCustomChild( custom, path );
98 return ( custom == null ) ? null : custom.getValue();
99 }
100
101
102
103
104
105
106
107
108
109
110 public static String getCustomValue( Xpp3Dom custom, String path, String defaultValue )
111 {
112 custom = getCustomChild( custom, path );
113 return ( custom == null ) ? defaultValue : custom.getValue();
114 }
115 }