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