forked from google/gdata-java-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVerificationMethod.java
More file actions
212 lines (186 loc) · 5.68 KB
/
Copy pathVerificationMethod.java
File metadata and controls
212 lines (186 loc) · 5.68 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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/* Copyright (c) 2008 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.gdata.data.webmastertools;
import com.google.gdata.data.AbstractExtension;
import com.google.gdata.data.AttributeGenerator;
import com.google.gdata.data.AttributeHelper;
import com.google.gdata.data.ExtensionDescription;
import com.google.gdata.util.ParseException;
/**
* GData schema extension describing a node specifying verification method. The
* verification method specifies a type of verification (HTML meta tag or file
* verification), verification value to be used by web site owner for the given
* type, and whether the given verification method is currently in use.
*
* Example:
* <pre class="code">
* <wt:verification-method type="METATAG" in-use="false">
* SOMEVALUE
* </wt:verification-method>
* </pre>
*
*
*/
@ExtensionDescription.Default(
nsAlias = Namespaces.WT_ALIAS,
nsUri = Namespaces.WT,
localName = VerificationMethod.METHOD_NODE)
public class VerificationMethod extends AbstractExtension {
/** Enumerates supported verification method types. */
public enum MethodType { METATAG, HTMLPAGE }
/** Verification method type. */
private MethodType methodType;
/** Specifies whether the method is currently in use. */
private boolean inUse;
/** Specifies the file content for HTML file verification. */
private String fileContent;
/**
* Specifies verification value which is interpreted accordingly to
* verification type. For instance for HTML file verification, the value
* specifies the file name that must be used by web site owner.
*/
private String value;
/** XML element names used by this class. */
public static final String METHOD_NODE = "verification-method";
private static final String METHODTYPE = "type";
private static final String INUSE = "in-use";
private static final String FILECONTENT = "file-content";
/**
* Checks whether specified node name matches node name for the verification
* method.
*
* @param nodeName is node name to check against.
* @return {@code true} if the name matches or {@code false} otherwise.
*/
public static boolean matchesNode(String nodeName) {
return nodeName.equals(METHOD_NODE);
}
/**
* Constructs {@link AbstractExtension} to represent verification method node.
*/
public VerificationMethod() {
super(Namespaces.WT_NAMESPACE, METHOD_NODE);
this.methodType = MethodType.METATAG;
this.inUse = false;
this.fileContent = "";
this.value = "";
}
/**
* Compares {@link VerificationMethod} objects based on the verification
* method type, value, file-content and in-use flag.
*/
@Override
public boolean equals(Object rhs) {
if (!sameClassAs(rhs)) {
return false;
}
VerificationMethod r = (VerificationMethod) rhs;
if (!methodType.equals(r.methodType)) {
return false;
}
if (inUse != r.inUse) {
return false;
}
if (!fileContent.equals(r.fileContent)) {
return false;
}
if (!value.equals(r.value)) {
return false;
}
return true;
}
/**
* Returns hash code which is based on the method type.
*/
@Override
public int hashCode() {
return methodType.hashCode();
}
/**
* Set verification method type.
*/
public void setMethodType(MethodType method) {
methodType = method;
}
/**
* Get verification method type.
*/
public MethodType getMethodType() {
return methodType;
}
/**
* Mark this method as the verification method that is currently in use.
*/
public void setInUse(boolean inUse) {
this.inUse = inUse;
}
/**
* Returns verification method that is currently in use.
*/
public boolean getInUse() {
return inUse;
}
/**
* Sets file content for HTML file verification.
*/
public void setFileContent(String fileContent) {
this.fileContent = fileContent;
}
/**
* Returns file content for HTML file verification.
*/
public String getFileContent() {
return fileContent;
}
/**
* Sets verification method value. The value is a string that is interpreted
* according to the method type.
*/
public void setValue(String v) {
value = v;
}
/**
* Get verification method value. The value is a string that is interpreted
* according to the method type.
*/
public String getValue() {
return value;
}
/**
* Overrides base class method to output attributes defined by this class.
*/
@Override
protected void putAttributes(AttributeGenerator generator) {
generator.put(METHODTYPE, methodType.toString().toLowerCase());
generator.put(INUSE, inUse);
generator.put(FILECONTENT, fileContent);
generator.setContent(value);
}
/**
* Overrides base class method to parse attributes specific to this class.
*/
@Override
protected void consumeAttributes(AttributeHelper helper)
throws ParseException {
methodType = helper.consumeEnum(
METHODTYPE, true, MethodType.class, MethodType.METATAG);
inUse = helper.consumeBoolean(INUSE, true);
fileContent = helper.consume(FILECONTENT, false);
String content = helper.consumeContent(false);
if (content != null) {
value = content;
}
}
}