Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ChangesFeedParser |
|
| 3.0;3 |
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; | |
18 | ||
19 | import java.util.Iterator; | |
20 | import java.util.List; | |
21 | ||
22 | import org.jaxen.jdom.JDOMXPath; | |
23 | import org.jdom.Element; | |
24 | ||
25 | /** | |
26 | * Handles parsing Blogger.com changes.xml files. | |
27 | * | |
28 | * @author <a href="mailto:burton@apache.org">Kevin A. Burton (burtonator)</a> | |
29 | * @version $Id: ChangesFeedParser.java 373614 2006-01-30 22:31:21Z mvdb $ | |
30 | */ | |
31 | 0 | public class ChangesFeedParser { |
32 | ||
33 | /** | |
34 | * Parse this feed. | |
35 | * | |
36 | * | |
37 | */ | |
38 | public static void parse( FeedParserListener listener, | |
39 | org.jdom.Document doc ) throws FeedParserException { | |
40 | ||
41 | try { | |
42 | ||
43 | 0 | FeedParserState state = new FeedParserState(); |
44 | ||
45 | 0 | FeedVersion v = new FeedVersion(); |
46 | 0 | v.isChanges = true; |
47 | 0 | listener.onFeedVersion( v ); |
48 | ||
49 | 0 | listener.init(); |
50 | ||
51 | 0 | FeedDirectoryParserListener fdpl = (FeedDirectoryParserListener)listener; |
52 | ||
53 | //this should be the root directory. | |
54 | 0 | JDOMXPath xpath = new JDOMXPath( "/weblogUpdates/weblog" ); |
55 | 0 | List list = xpath.selectNodes( doc ); |
56 | ||
57 | 0 | Iterator i = list.iterator(); |
58 | 0 | while ( i.hasNext() ) { |
59 | ||
60 | 0 | Element child = (Element)i.next(); |
61 | 0 | onWeblog( fdpl, state, child ); |
62 | ||
63 | 0 | } |
64 | ||
65 | 0 | listener.finished(); |
66 | ||
67 | 0 | } catch ( Throwable t ) { throw new FeedParserException( t ); } |
68 | ||
69 | 0 | } |
70 | ||
71 | private static void onWeblog( FeedDirectoryParserListener listener, | |
72 | FeedParserState state, | |
73 | Element current ) throws Exception { | |
74 | ||
75 | 0 | String weblog = current.getAttributeValue( "url" ); |
76 | 0 | String description = current.getAttributeValue( "name" ); |
77 | 0 | String title = description; |
78 | 0 | String feed = null; |
79 | ||
80 | 0 | if ( weblog == null ) |
81 | 0 | weblog = feed; |
82 | ||
83 | 0 | listener.onItem( state, title, weblog, description, feed ); |
84 | ||
85 | 0 | } |
86 | ||
87 | } | |
88 |