Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
FeedReference |
|
| 2.5;2.5 |
1 | /* | |
2 | * Copyright 1999,2004 The Apache Software Foundation. | |
3 | * | |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | * you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at | |
7 | * | |
8 | * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | * | |
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 | ||
17 | package org.apache.commons.feedparser.locate; | |
18 | ||
19 | import java.util.regex.Pattern; | |
20 | ||
21 | /** | |
22 | * <p> | |
23 | * A FeedReference is used within the RSS/Atom location facility to pass back | |
24 | * metadata for feed discoveries. | |
25 | * | |
26 | * <p> | |
27 | * Right now we pass back the URL to the feeds as the `resource' parameter. The | |
28 | * media type (application/rss+xml, application/atom+xml, etc) as the type param | |
29 | * (which is optional). We also pass back the `title' back if its specified | |
30 | * within autodiscovery. This will be null if another discovery method is used. | |
31 | * | |
32 | * <p> Its important to realize that the media type is only given if we're 100% | |
33 | * certain of the value. If we have to use probe discovery or link discovery it | |
34 | * might not be possible to obtain the media type without antoher network | |
35 | * request (via HTTP headers). | |
36 | * | |
37 | * <p> Note that internally (within the ProbeLocator) we don't use absolute | |
38 | * resource URLs but use relative ones and use the media type as the default | |
39 | * media type. | |
40 | * | |
41 | * @author <a href="mailto:burton@apache.org">Kevin A. Burton</a> | |
42 | */ | |
43 | public class FeedReference { | |
44 | ||
45 | public static final String ATOM_MEDIA_TYPE = "application/atom+xml"; | |
46 | public static final String RSS_MEDIA_TYPE = "application/rss+xml"; | |
47 | public static final String XML_MEDIA_TYPE = "text/xml"; | |
48 | ||
49 | 0 | public static int METHOD_AUTO_DISCOVERY = 1; |
50 | 0 | public static int METHOD_PROBE_DISCOVERY = 2; |
51 | 0 | public static int METHOD_LINK_DISCOVERY = 4; |
52 | ||
53 | /** | |
54 | * The network addressable resource forfor this feed. | |
55 | */ | |
56 | 0 | public String resource = null; |
57 | ||
58 | /** | |
59 | * The media type of this feed. | |
60 | */ | |
61 | 0 | public String type = null; |
62 | ||
63 | /** | |
64 | * The title of the reference. Usually FOAF, RSS or Atom per auto-discovery | |
65 | * link. | |
66 | */ | |
67 | 0 | public String title = null; |
68 | ||
69 | /** | |
70 | * The method of discovery... | |
71 | */ | |
72 | 0 | public int method = 0; |
73 | ||
74 | 0 | protected Pattern schemePattern = Pattern.compile("^[^:/]*:/.*$"); |
75 | ||
76 | 0 | public FeedReference( String resource, String type ) { |
77 | 0 | this.resource = resource; |
78 | 0 | this.type = type; |
79 | 0 | } |
80 | ||
81 | public String toString() { | |
82 | 0 | return resource; |
83 | } | |
84 | ||
85 | public boolean equals(Object obj) { | |
86 | 0 | if (obj == null || (obj instanceof FeedReference) == false) |
87 | 0 | return false; |
88 | ||
89 | 0 | FeedReference compareMe = (FeedReference)obj; |
90 | ||
91 | 0 | if (resource.equals(compareMe.resource)) { |
92 | //ignore title and type when doing equality | |
93 | 0 | return true; |
94 | } | |
95 | ||
96 | 0 | return false; |
97 | } | |
98 | ||
99 | /** Determines if the resource given by this FeedReference is relative. | |
100 | * For example, the resource could be '/atom.xml', which is relative. | |
101 | * It could also be | |
102 | * "http://rss.groups.yahoo.com/group/talkinaboutarchitecture/rss". | |
103 | */ | |
104 | public boolean isRelative() { | |
105 | 0 | if (resource == null) |
106 | 0 | return true; |
107 | ||
108 | // look for a scheme:/ | |
109 | 0 | return !schemePattern.matcher(resource).matches(); |
110 | ||
111 | } | |
112 | ||
113 | } |