01: /*
02: * Copyright 2007 Hippo.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package nl.hippo.cms.brokenlinkchecker;
17:
18: /**
19: * <p>
20: * Utility class for classification of link URLs.
21: * </p>
22: */
23: public class LinkClassifier {
24: /**
25: * <p>
26: * The prefix for external links that point to insecure sites.
27: * </p>
28: */
29: static final String HTTP_PROTOCOL_PREFIX = "http://";
30:
31: /**
32: * <p>
33: * The prefix for external links that point to secure sites.
34: * </p>
35: */
36: static final String HTTPS_PROTOCOL_PREFIX = "https://";
37:
38: /**
39: * <p>
40: * The prefix for internal links.
41: * </p>
42: */
43: static final String INTERNAL_LINK_PREFIX = "/";
44:
45: /**
46: * <p>
47: * The only and private constructor to prevent instantiation of this
48: * class.
49: * </p>
50: */
51: private LinkClassifier() {
52: super ();
53: }
54:
55: /**
56: * <p>
57: * Determine if a link points to an insecure website.
58: * </p>
59: *
60: * @param link
61: * the link to check.
62: * @return <code>true</code> if the link points to an insecure
63: * website, <code>false</code> otherwise.
64: */
65: public static boolean isHttpLink(String link) {
66: return link.startsWith(HTTP_PROTOCOL_PREFIX);
67: }
68:
69: /**
70: * <p>
71: * Determine if a link points to a secure website.
72: * </p>
73: *
74: * @param link
75: * the link to check.
76: * @return <code>true</code> if the link points to a secure website,
77: * <code>false</code> otherwise.
78: */
79: public static boolean isHttpsLink(String link) {
80: return link.startsWith(HTTPS_PROTOCOL_PREFIX);
81: }
82:
83: /**
84: * <p>
85: * Determine if a link is a link internal to the site.
86: * </p>
87: *
88: * @param link
89: * the link to check.
90: * @return <code>true</code> if the link is internal to the site,
91: * <code>false</code> otherwise.
92: */
93: public static boolean isInternalLink(String link) {
94: return link.startsWith(INTERNAL_LINK_PREFIX);
95: }
96: }
|