This repository was archived by the owner on Jul 20, 2024. It is now read-only.
forked from splunk/splunk-sdk-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAtomFeed.java
More file actions
115 lines (99 loc) · 3.38 KB
/
AtomFeed.java
File metadata and controls
115 lines (99 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
* Copyright 2012 Splunk, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"): you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package com.splunk;
import java.io.InputStream;
import java.util.*;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamConstants;
/**
* The {@code AtomFeed} class represents an Atom feed.
*/
public class AtomFeed extends AtomObject {
/** The list of Atom entries contained in this {@code AtomFeed} object. */
public ArrayList<AtomEntry> entries = new ArrayList<AtomEntry>();
/** The value of the Atom feed's {@code <itemsPerPage>} element. */
public String itemsPerPage = null;
/** The value of the Atom feed's {@code <startIndex>} element. */
public String startIndex = null;
/** The value of the Atom feed's {@code <totalResults>} element. */
public String totalResults = null;
/**
* Creates a new {@code AtomFeed} instance.
*
* @return A new {@code AtomFeed} instance.
*/
static AtomFeed create() {
return new AtomFeed();
}
/**
* Creates a new {@code AtomFeed} instance based on the given stream.
*
* @param input The input stream.
* @return An {@code AtomFeed} instance representing the parsed stream.
*/
public static AtomFeed parseStream(InputStream input) {
XMLStreamReader reader = createReader(input);
AtomFeed result = AtomFeed.parse(reader);
try {
reader.close();
}
catch (XMLStreamException e) {
throw new RuntimeException(e.getMessage(), e);
}
return result;
}
/**
* Creates a new {@code AtomFeed} instance based on a given XML element.
*
* @param input The XML stream.
* @return An {@code AtomFeed} instance representing the parsed element.
* @throws RuntimeException The runtime exception if a parse error occurs.
*/
static AtomFeed parse(XMLStreamReader input) {
AtomFeed feed = AtomFeed.create();
feed.load(input, "feed");
return feed;
}
/**
* Initializes the current instance from a given XML element.
*
* @param reader The XML reader.
*/
@Override void init(XMLStreamReader reader) {
assert reader.isStartElement();
String name = reader.getLocalName();
if (name.equals("entry")) {
AtomEntry entry = AtomEntry.parse(reader);
this.entries.add(entry);
}
else if (name.equals("messages")) {
parseEnd(reader);
}
else if (name.equals("totalResults")) {
this.totalResults = parseText(reader);
}
else if (name.equals("itemsPerPage")) {
this.itemsPerPage = parseText(reader);
}
else if (name.equals("startIndex")) {
this.startIndex = parseText(reader);
}
else {
super.init(reader);
}
}
}