Skip to content

Commit bfeed3c

Browse files
committed
add null checks to parse routine
1 parent 71e3f75 commit bfeed3c

File tree

2 files changed

+52
-46
lines changed

2 files changed

+52
-46
lines changed

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

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -117,19 +117,22 @@ protected void populateDocument(Element element)
117117
// metadata element
118118
Element mdElement = element.getChild("md", ResourceSync.NS_RS);
119119

120-
// - capability
121-
String capability = mdElement.getAttributeValue("capability", ResourceSync.NS_RS);
122-
if (!"".equals(capability))
120+
if (mdElement != null)
123121
{
124-
this.capability = capability;
125-
}
122+
// - capability
123+
String capability = mdElement.getAttributeValue("capability", ResourceSync.NS_RS);
124+
if (!"".equals(capability))
125+
{
126+
this.capability = capability;
127+
}
126128

127-
// - modified
128-
String modified = mdElement.getAttributeValue("modified", ResourceSync.NS_ATOM);
129-
if (modified != null && !"".equals(modified))
130-
{
131-
Date lastMod = ResourceSync.DATE_FORMAT.parse(modified);
132-
this.setLastModified(lastMod);
129+
// - modified
130+
String modified = mdElement.getAttributeValue("modified", ResourceSync.NS_ATOM);
131+
if (modified != null && !"".equals(modified))
132+
{
133+
Date lastMod = ResourceSync.DATE_FORMAT.parse(modified);
134+
this.setLastModified(lastMod);
135+
}
133136
}
134137

135138
// rs:ln elements

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

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -181,47 +181,50 @@ public void populateObject(Element element)
181181
// the metadata element
182182
Element mdElement = element.getChild("md", ResourceSync.NS_RS);
183183

184-
// - capability
185-
String capability = mdElement.getAttributeValue("capability", ResourceSync.NS_RS);
186-
if (capability != null && !"".equals(capability))
184+
if (mdElement != null)
187185
{
188-
this.setCapability(capability);
189-
}
186+
// - capability
187+
String capability = mdElement.getAttributeValue("capability", ResourceSync.NS_RS);
188+
if (capability != null && !"".equals(capability))
189+
{
190+
this.setCapability(capability);
191+
}
190192

191-
// - change
192-
String change = mdElement.getAttributeValue("change", ResourceSync.NS_RS);
193-
if (change != null && !"".equals(change))
194-
{
195-
this.setChange(change);
196-
}
193+
// - change
194+
String change = mdElement.getAttributeValue("change", ResourceSync.NS_RS);
195+
if (change != null && !"".equals(change))
196+
{
197+
this.setChange(change);
198+
}
197199

198-
// - hash
199-
String hashAttr = mdElement.getAttributeValue("hash", ResourceSync.NS_ATOM);
200-
if (hashAttr != null && !"".equals(hashAttr))
201-
{
202-
this.addHashesFromAttr(hashAttr);
203-
}
200+
// - hash
201+
String hashAttr = mdElement.getAttributeValue("hash", ResourceSync.NS_ATOM);
202+
if (hashAttr != null && !"".equals(hashAttr))
203+
{
204+
this.addHashesFromAttr(hashAttr);
205+
}
204206

205-
// - length
206-
String length = mdElement.getAttributeValue("length", ResourceSync.NS_ATOM);
207-
if (length != null && !"".equals(length))
208-
{
209-
long l = Long.parseLong(length);
210-
this.setLength(l);
211-
}
207+
// - length
208+
String length = mdElement.getAttributeValue("length", ResourceSync.NS_ATOM);
209+
if (length != null && !"".equals(length))
210+
{
211+
long l = Long.parseLong(length);
212+
this.setLength(l);
213+
}
212214

213-
// - path
214-
String path = mdElement.getAttributeValue("path", ResourceSync.NS_RS);
215-
if (path != null && !"".equals(path))
216-
{
217-
this.setPath(path);
218-
}
215+
// - path
216+
String path = mdElement.getAttributeValue("path", ResourceSync.NS_RS);
217+
if (path != null && !"".equals(path))
218+
{
219+
this.setPath(path);
220+
}
219221

220-
// - type
221-
String type = mdElement.getAttributeValue("type", ResourceSync.NS_ATOM);
222-
if (type != null && !"".equals(type))
223-
{
224-
this.setType(type);
222+
// - type
223+
String type = mdElement.getAttributeValue("type", ResourceSync.NS_ATOM);
224+
if (type != null && !"".equals(type))
225+
{
226+
this.setType(type);
227+
}
225228
}
226229

227230
// all the rs:ln elements

0 commit comments

Comments
 (0)