forked from google/gdata-java-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMetadataEntryExtension.java
More file actions
185 lines (166 loc) · 5.6 KB
/
Copy pathMetadataEntryExtension.java
File metadata and controls
185 lines (166 loc) · 5.6 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/* Copyright (c) 2006 Google 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.google.api.gbase.client;
import com.google.gdata.data.BaseEntry;
import com.google.gdata.data.PubControl;
/**
* Handle gm: attributes found in histogram and item types feeds.
*
* This object should be accessed using
* {@link com.google.api.gbase.client.GoogleBaseEntry#getGoogleBaseMetadata()}.
*
* The metadata can contain <em>either</em>:
* <ul>
* <li>histogram metadata ({@link #getAttributeHistogram()})
* <li>item type description metadata ({@link #getItemTypeDescription()})
* <li>statistics {@link #getStats()}
* </ul>
* Only one of them can be defined. Which one it is depends on the
* type of entry/feed that has been read. See also the javadoc for
* {@link GoogleBaseEntry}.
*/
public class MetadataEntryExtension {
private final BaseEntry<?> owner;
/**
* Item type description information, if it is set.
*
* If it is not set, this means that either this extension
* has not been initialized yet or that this is not an
* itemtype entry.
*/
private final ItemTypeDescription itemType;
/**
* Creates a MetadataEntryExtension and link it to a
* {@link BaseEntry} (usually a {@link GoogleBaseEntry}).
*
* @param owner entry this object is linked to
*/
public MetadataEntryExtension(BaseEntry<?> owner) {
this.owner = owner;
this.itemType = new ItemTypeDescription(owner);
}
/**
* Gets attribute histogram information.
*
* @return attribute histogram information fond in the feed
* @exception IllegalStateException if the feed was not an
* histogram feed.
*/
public AttributeHistogram getAttributeHistogram() {
AttributeHistogram histogram = owner.getExtension(AttributeHistogram.class);
if (histogram == null) {
throw new IllegalStateException("Not a histogram feed entry.");
}
return histogram;
}
/** Gets statistics, if available. */
public Stats getStats() {
return owner.getExtension(Stats.class);
}
/**
* Checks whether anything has been defined in this extension.
*
* @return true if there is metadata about locale, histograms or
* item types in this object
*/
public boolean isEmpty() {
return hasAttributeHistogram() || hasItemTypeDescription() || hasStats();
}
/**
* Checks whether statistics information is available in the current entry.
*
* @return true if a call to {@link #getStats()} would return a Stats
* object
*/
public boolean hasStats() {
return owner.getExtension(Stats.class) != null;
}
/**
* Checks whether an attribute histogram is available in the current
* entry.
*
* @return true if a call to {@link #getAttributeHistogram()} would work
*/
public boolean hasAttributeHistogram() {
return owner.getExtension(AttributeHistogram.class) != null;
}
/**
* Gets the {@link ItemTypeDescription} associated with this extension.
*
* @return item type description
* @exception IllegalStateException if no item type description could
* be found in the entry (only item type feeds have item type description
* information)
*/
public ItemTypeDescription getItemTypeDescription() {
if (!hasItemTypeDescription()) {
throw new IllegalStateException("Not an item-type entry.");
}
return itemType;
}
/**
* Checks whether item type description is available in the current entry.
*
* @return true if a call to {@link #getItemTypeDescription()} would work
*/
public boolean hasItemTypeDescription() {
return itemType.getName() != null;
}
/**
* Checks whether the entry contains the {@code gm:disapproved} tag, marking
* it as a disapproved item.
*
* @return {@code true} if the {@code gm:disapproved} tag is present in the
* {@code app:control} section, {@code false} otherwise.
*/
public boolean hasGmDisapproved() {
return owner.getPubControl() != null
&& owner.getPubControl().getExtension(GmDisapproved.class) != null;
}
/**
* Returns the publishing priority for the entry or {@code null} if
* the entry doesn't contain this information.
*
* @return the value for the {@code publishing_priority} parameter,
* or {@code null} if this information is not available.
*/
public GmPublishingPriority.Value getGmPublishingPriority() {
PubControl pubControl = owner.getPubControl();
if (pubControl == null) {
return null;
}
GmPublishingPriority priority = pubControl.getExtension(
GmPublishingPriority.class);
if (priority == null) {
return null;
}
return priority.getValue();
}
/**
* Sets the publishing priority for the entry.
*
* @param value the value for the publish priority
*/
public void setGmPublishingPriority(GmPublishingPriority.Value value) {
GmPublishingPriority priority = new GmPublishingPriority();
priority.setValue(value);
PubControl pubControl = owner.getPubControl();
if (pubControl == null) {
pubControl = new PubControl();
owner.setPubControl(pubControl);
}
pubControl.setExtension(priority);
}
}