Skip to content

Commit 4666e89

Browse files
committed
remove namespace declarations from attributes
1 parent fbd3f45 commit 4666e89

File tree

3 files changed

+61
-62
lines changed

3 files changed

+61
-62
lines changed

src/main/java/org/openarchives/resourcesync/ResourceSyncDocument.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,14 @@ protected void populateDocument(Element element)
120120
if (mdElement != null)
121121
{
122122
// - capability
123-
String capability = mdElement.getAttributeValue("capability", ResourceSync.NS_RS);
123+
String capability = mdElement.getAttributeValue("capability");
124124
if (!"".equals(capability))
125125
{
126126
this.capability = capability;
127127
}
128128

129129
// - modified
130-
String modified = mdElement.getAttributeValue("modified", ResourceSync.NS_ATOM);
130+
String modified = mdElement.getAttributeValue("modified");
131131
if (modified != null && !"".equals(modified))
132132
{
133133
Date lastMod = ResourceSync.DATE_FORMAT.parse(modified);
@@ -139,8 +139,8 @@ protected void populateDocument(Element element)
139139
List<Element> lns = element.getChildren("ln", ResourceSync.NS_RS);
140140
for (Element ln : lns)
141141
{
142-
String rel = ln.getAttributeValue("rel", ResourceSync.NS_ATOM);
143-
String href = ln.getAttributeValue("href", ResourceSync.NS_ATOM);
142+
String rel = ln.getAttributeValue("rel");
143+
String href = ln.getAttributeValue("href");
144144
if (rel != null && !"".equals(rel) && href != null && !"".equals(href))
145145
{
146146
this.addLn(rel, href);
@@ -156,24 +156,23 @@ protected void populateDocument(Element element)
156156
public Element getElement()
157157
{
158158
Element root = new Element(this.root, ResourceSync.NS_SITEMAP);
159-
root.addNamespaceDeclaration(ResourceSync.NS_ATOM);
160159
root.addNamespaceDeclaration(ResourceSync.NS_RS);
161160

162161
// set the capability of the document in the rs:md
163162
Element md = new Element("md", ResourceSync.NS_RS);
164-
md.setAttribute("capability", this.capability, ResourceSync.NS_RS);
163+
md.setAttribute("capability", this.capability);
165164
if (this.lastModified != null)
166165
{
167-
md.setAttribute("modified", ResourceSync.DATE_FORMAT.format(this.lastModified), ResourceSync.NS_ATOM);
166+
md.setAttribute("modified", ResourceSync.DATE_FORMAT.format(this.lastModified));
168167
}
169168
root.addContent(md);
170169

171170
// serialise the rs:ln elements
172171
for (ResourceSyncLn ln : this.lns)
173172
{
174173
Element lnEl = new Element("ln", ResourceSync.NS_RS);
175-
lnEl.setAttribute("rel", ln.getRel(), ResourceSync.NS_ATOM);
176-
lnEl.setAttribute("href", ln.getHref(), ResourceSync.NS_ATOM);
174+
lnEl.setAttribute("rel", ln.getRel());
175+
lnEl.setAttribute("href", ln.getHref());
177176
root.addContent(lnEl);
178177
}
179178

src/main/java/org/openarchives/resourcesync/ResourceSyncEntry.java

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -195,50 +195,50 @@ public void populateObject(Element element)
195195
if (mdElement != null)
196196
{
197197
// - capability
198-
String capability = mdElement.getAttributeValue("capability", ResourceSync.NS_RS);
198+
String capability = mdElement.getAttributeValue("capability");
199199
if (capability != null && !"".equals(capability))
200200
{
201201
this.setCapability(capability);
202202
}
203203

204204
// - change
205-
String change = mdElement.getAttributeValue("change", ResourceSync.NS_RS);
205+
String change = mdElement.getAttributeValue("change");
206206
if (change != null && !"".equals(change))
207207
{
208208
this.setChange(change);
209209
}
210210

211211
// - hash
212-
String hashAttr = mdElement.getAttributeValue("hash", ResourceSync.NS_ATOM);
212+
String hashAttr = mdElement.getAttributeValue("hash");
213213
if (hashAttr != null && !"".equals(hashAttr))
214214
{
215215
this.addHashesFromAttr(hashAttr);
216216
}
217217

218218
// - length
219-
String length = mdElement.getAttributeValue("length", ResourceSync.NS_ATOM);
219+
String length = mdElement.getAttributeValue("length");
220220
if (length != null && !"".equals(length))
221221
{
222222
long l = Long.parseLong(length);
223223
this.setLength(l);
224224
}
225225

226226
// - path
227-
String path = mdElement.getAttributeValue("path", ResourceSync.NS_RS);
227+
String path = mdElement.getAttributeValue("path");
228228
if (path != null && !"".equals(path))
229229
{
230230
this.setPath(path);
231231
}
232232

233233
// - type
234-
String type = mdElement.getAttributeValue("type", ResourceSync.NS_ATOM);
234+
String type = mdElement.getAttributeValue("type");
235235
if (type != null && !"".equals(type))
236236
{
237237
this.setType(type);
238238
}
239239

240240
// -encoding
241-
String encoding = mdElement.getAttributeValue("encoding"); // FIXME: namespace?
241+
String encoding = mdElement.getAttributeValue("encoding");
242242
if (encoding != null && !"".equals(encoding))
243243
{
244244
this.setEncoding(encoding);
@@ -249,14 +249,14 @@ public void populateObject(Element element)
249249
List<Element> lns = element.getChildren("ln", ResourceSync.NS_RS);
250250
for (Element ln : lns)
251251
{
252-
String rel = ln.getAttributeValue("rel", ResourceSync.NS_ATOM);
253-
String href = ln.getAttributeValue("href", ResourceSync.NS_ATOM);
252+
String rel = ln.getAttributeValue("rel");
253+
String href = ln.getAttributeValue("href");
254254
if (rel != null && !"".equals(rel) && href != null && !"".equals(href))
255255
{
256256
ResourceSyncLn link = this.addLn(rel, href);
257257

258258
// hash
259-
String lnHashAttr = ln.getAttributeValue("hash", ResourceSync.NS_ATOM);
259+
String lnHashAttr = ln.getAttributeValue("hash");
260260
if (lnHashAttr != null && !"".equals(lnHashAttr))
261261
{
262262
Map<String, String> hashMap = this.getHashesFromAttr(lnHashAttr);
@@ -267,44 +267,44 @@ public void populateObject(Element element)
267267
}
268268

269269
// length
270-
String lnLength = ln.getAttributeValue("length", ResourceSync.NS_ATOM);
270+
String lnLength = ln.getAttributeValue("length");
271271
if (lnLength != null && !"".equals(length))
272272
{
273273
long lnl = Long.parseLong(lnLength);
274274
link.setLength(lnl);
275275
}
276276

277277
// modified
278-
String modified = ln.getAttributeValue("modified", ResourceSync.NS_ATOM);
278+
String modified = ln.getAttributeValue("modified");
279279
if (modified != null && !"".equals(modified))
280280
{
281281
Date modDate = ResourceSync.DATE_FORMAT.parse(modified);
282282
link.setModified(modDate);
283283
}
284284

285285
// path
286-
String lnPath = ln.getAttributeValue("path", ResourceSync.NS_RS);
286+
String lnPath = ln.getAttributeValue("path");
287287
if (lnPath != null && !"".equals(lnPath))
288288
{
289289
link.setPath(lnPath);
290290
}
291291

292292
// pri
293-
String pri = ln.getAttributeValue("pri"); // FIXME: namespace?
293+
String pri = ln.getAttributeValue("pri");
294294
if (pri != null && !"".equals(pri))
295295
{
296296
link.setPri(Integer.parseInt(pri));
297297
}
298298

299299
// type
300-
String lnType = ln.getAttributeValue("type", ResourceSync.NS_ATOM);
300+
String lnType = ln.getAttributeValue("type");
301301
if (lnType != null && !"".equals(lnType))
302302
{
303303
link.setType(lnType);
304304
}
305305

306306
// encoding
307-
String lnEncoding = ln.getAttributeValue("encoding"); // FIXME: namespace?
307+
String lnEncoding = ln.getAttributeValue("encoding");
308308
if (lnEncoding != null && !"".equals(lnEncoding))
309309
{
310310
link.setEncoding(lnEncoding);
@@ -343,38 +343,38 @@ public Element getElement()
343343
boolean trip = false;
344344
if (this.capability != null)
345345
{
346-
md.setAttribute("capability", this.capability, ResourceSync.NS_RS);
346+
md.setAttribute("capability", this.capability);
347347
trip = true;
348348
}
349349
if (this.change != null)
350350
{
351-
md.setAttribute("change", this.change, ResourceSync.NS_RS);
351+
md.setAttribute("change", this.change);
352352
trip = true;
353353
}
354354
String hashAttr = this.getHashAttr(this.hashes);
355355
if (!"".equals(hashAttr))
356356
{
357-
md.setAttribute("hash", hashAttr, ResourceSync.NS_ATOM);
357+
md.setAttribute("hash", hashAttr);
358358
trip = true;
359359
}
360360
if (this.length > -1)
361361
{
362-
md.setAttribute("length", Long.toString(this.length), ResourceSync.NS_ATOM);
362+
md.setAttribute("length", Long.toString(this.length));
363363
trip = true;
364364
}
365365
if (this.path != null)
366366
{
367-
md.setAttribute("path", this.path, ResourceSync.NS_RS);
367+
md.setAttribute("path", this.path);
368368
trip = true;
369369
}
370370
if (this.type != null)
371371
{
372-
md.setAttribute("type", this.type, ResourceSync.NS_ATOM);
372+
md.setAttribute("type", this.type);
373373
trip = true;
374374
}
375375
if (this.encoding != null)
376376
{
377-
md.setAttribute("encoding", this.encoding); // FIXME: namespace? This comes from the HTTP spec
377+
md.setAttribute("encoding", this.encoding);
378378
trip = true;
379379
}
380380
if (trip)
@@ -390,47 +390,47 @@ public Element getElement()
390390
String lnHash = this.getHashAttr(ln.getHashes());
391391
if (!"".equals(lnHash))
392392
{
393-
link.setAttribute("hash", lnHash, ResourceSync.NS_ATOM);
393+
link.setAttribute("hash", lnHash);
394394
trip = true;
395395
}
396396
if (ln.getHref() != null)
397397
{
398-
link.setAttribute("href", ln.getHref(), ResourceSync.NS_ATOM);
398+
link.setAttribute("href", ln.getHref());
399399
trip = true;
400400
}
401401
if (ln.getLength() > -1)
402402
{
403-
link.setAttribute("length", Long.toString(ln.getLength()), ResourceSync.NS_ATOM);
403+
link.setAttribute("length", Long.toString(ln.getLength()));
404404
trip = true;
405405
}
406406
if (ln.getModified() != null)
407407
{
408-
link.setAttribute("modified", ResourceSync.DATE_FORMAT.format(ln.getModified()), ResourceSync.NS_ATOM);
408+
link.setAttribute("modified", ResourceSync.DATE_FORMAT.format(ln.getModified()));
409409
trip = true;
410410
}
411411
if (ln.getPath() != null)
412412
{
413-
link.setAttribute("path", ln.getPath(), ResourceSync.NS_RS);
413+
link.setAttribute("path", ln.getPath());
414414
trip = true;
415415
}
416416
if (ln.getRel() != null)
417417
{
418-
link.setAttribute("rel", ln.getRel(), ResourceSync.NS_ATOM);
418+
link.setAttribute("rel", ln.getRel());
419419
trip = true;
420420
}
421421
if (ln.getPri() > 0)
422422
{
423-
link.setAttribute("pri", Integer.toString(ln.getPri())); // FIXME: namespace?
423+
link.setAttribute("pri", Integer.toString(ln.getPri()));
424424
trip = true;
425425
}
426426
if (ln.getType() != null)
427427
{
428-
link.setAttribute("type", ln.getType(), ResourceSync.NS_ATOM);
428+
link.setAttribute("type", ln.getType());
429429
trip = true;
430430
}
431431
if (ln.getEncoding() != null)
432432
{
433-
link.setAttribute("encoding", ln.getEncoding()); // FIXME: namespace?
433+
link.setAttribute("encoding", ln.getEncoding());
434434
trip = true;
435435
}
436436
if (trip)

src/test/java/org/openarchives/resourcesync/test/TestBaseClasses.java

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -174,25 +174,25 @@ public void resourceSyncEntry()
174174

175175
Element md = element.getChild("md", ResourceSync.NS_RS);
176176

177-
String cap = md.getAttributeValue("capability", ResourceSync.NS_RS);
177+
String cap = md.getAttributeValue("capability");
178178
assert cap.equals(ResourceSync.CAPABILITY_RESOURCELIST);
179179

180-
String change = md.getAttributeValue("change", ResourceSync.NS_RS);
180+
String change = md.getAttributeValue("change");
181181
assert change.equals(ResourceSync.CHANGE_CREATED);
182182

183-
String length = md.getAttributeValue("length", ResourceSync.NS_ATOM);
183+
String length = md.getAttributeValue("length");
184184
assert length.equals("987");
185185

186-
String path = md.getAttributeValue("path", ResourceSync.NS_RS);
186+
String path = md.getAttributeValue("path");
187187
assert path.equals("/path/to/file");
188188

189-
String type = md.getAttributeValue("type", ResourceSync.NS_ATOM);
189+
String type = md.getAttributeValue("type");
190190
assert type.equals("application/pdf");
191191

192192
String encoding = md.getAttributeValue("encoding");
193193
assert encoding.equals("utf-8");
194194

195-
String hashAttr = md.getAttributeValue("hash", ResourceSync.NS_ATOM);
195+
String hashAttr = md.getAttributeValue("hash");
196196
String[] hashParts = hashAttr.split(" ");
197197
assert hashParts.length == 2;
198198
seenMd5 = false;
@@ -220,19 +220,19 @@ public void resourceSyncEntry()
220220
collection = false;
221221
for (Element linkEl : linkEls)
222222
{
223-
if (linkEl.getAttributeValue("href", ResourceSync.NS_ATOM).equals("http://describes"))
223+
if (linkEl.getAttributeValue("href").equals("http://describes"))
224224
{
225-
assert linkEl.getAttributeValue("rel", ResourceSync.NS_ATOM).equals(ResourceSync.REL_DESCRIBES);
226-
assert linkEl.getAttributeValue("type", ResourceSync.NS_ATOM).equals("text/html");
227-
assert linkEl.getAttributeValue("length", ResourceSync.NS_ATOM).equals("543");
225+
assert linkEl.getAttributeValue("rel").equals(ResourceSync.REL_DESCRIBES);
226+
assert linkEl.getAttributeValue("type").equals("text/html");
227+
assert linkEl.getAttributeValue("length").equals("543");
228228
describes = true;
229229
}
230-
if (linkEl.getAttributeValue("href", ResourceSync.NS_ATOM).equals("http://other.collection/"))
230+
if (linkEl.getAttributeValue("href").equals("http://other.collection/"))
231231
{
232-
assert linkEl.getAttributeValue("rel", ResourceSync.NS_ATOM).equals(ResourceSync.REL_COLLECTION);
232+
assert linkEl.getAttributeValue("rel").equals(ResourceSync.REL_COLLECTION);
233233
other_collection = true;
234234
}
235-
if (linkEl.getAttributeValue("href", ResourceSync.NS_ATOM).equals("http://collection"))
235+
if (linkEl.getAttributeValue("href").equals("http://collection"))
236236
{
237237
collection = true;
238238
}
@@ -317,10 +317,10 @@ public void resourceSyncDocument()
317317

318318
Element md = element.getChild("md", ResourceSync.NS_RS);
319319

320-
String cap = md.getAttributeValue("capability", ResourceSync.NS_RS);
320+
String cap = md.getAttributeValue("capability");
321321
assert cap.equals(ResourceSync.CAPABILITY_CHANGEDUMP);
322322

323-
String mod = md.getAttributeValue("modified", ResourceSync.NS_ATOM);
323+
String mod = md.getAttributeValue("modified");
324324
assert mod.equals(nowStr);
325325

326326
List<Element> linkEls = element.getChildren("ln", ResourceSync.NS_RS);
@@ -329,14 +329,14 @@ public void resourceSyncDocument()
329329
desc = false;
330330
for (Element link : linkEls)
331331
{
332-
if (link.getAttributeValue("rel", ResourceSync.NS_ATOM).equals(ResourceSync.REL_DESCRIBED_BY))
332+
if (link.getAttributeValue("rel").equals(ResourceSync.REL_DESCRIBED_BY))
333333
{
334-
assert link.getAttributeValue("href", ResourceSync.NS_ATOM).equals("http://describedby");
334+
assert link.getAttributeValue("href").equals("http://describedby");
335335
descby = true;
336336
}
337-
if (link.getAttributeValue("rel", ResourceSync.NS_ATOM).equals(ResourceSync.REL_DESCRIBES))
337+
if (link.getAttributeValue("rel").equals(ResourceSync.REL_DESCRIBES))
338338
{
339-
assert link.getAttributeValue("href", ResourceSync.NS_ATOM).equals("http://describes");
339+
assert link.getAttributeValue("href").equals("http://describes");
340340
desc = true;
341341
}
342342
}
@@ -352,13 +352,13 @@ public void resourceSyncDocument()
352352
if (entry.getChild("loc", ResourceSync.NS_SITEMAP).getText().equals("http://entry1"))
353353
{
354354
Element m = entry.getChild("md", ResourceSync.NS_RS);
355-
assert m.getAttributeValue("type", ResourceSync.NS_ATOM).equals("text/xml");
355+
assert m.getAttributeValue("type").equals("text/xml");
356356
saw1 = true;
357357
}
358358
if (entry.getChild("loc", ResourceSync.NS_SITEMAP).getText().equals("http://entry2"))
359359
{
360360
Element m = entry.getChild("md", ResourceSync.NS_RS);
361-
assert m.getAttributeValue("change", ResourceSync.NS_RS).equals(ResourceSync.CHANGE_UPDATED);
361+
assert m.getAttributeValue("change").equals(ResourceSync.CHANGE_UPDATED);
362362
saw2 = true;
363363
}
364364
}

0 commit comments

Comments
 (0)