1
|
|
|
module.exports = function(GedcomX){ |
2
|
|
|
|
3
|
|
|
var utils = require('../utils'), |
4
|
|
|
AtomCommon = require('./AtomCommon'); |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* An individual atom feed entry. |
8
|
|
|
* |
9
|
|
|
* @constructor |
10
|
|
|
* @param {Object} [json] |
|
|
|
|
11
|
|
|
*/ |
12
|
|
|
var AtomEntry = function(json){ |
13
|
|
|
|
14
|
|
|
// Protect against forgetting the new keyword when calling the constructor |
15
|
|
|
if(!(this instanceof AtomEntry)){ |
16
|
|
|
return new AtomEntry(json); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
// If the given object is already an instance then just return it. DON'T copy it. |
20
|
|
|
if(AtomEntry.isInstance(json)){ |
21
|
|
|
return json; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
this.init(json); |
|
|
|
|
25
|
|
|
}; |
26
|
|
|
|
27
|
|
|
AtomEntry.prototype = Object.create(AtomCommon.prototype); |
28
|
|
|
|
29
|
|
|
AtomEntry._gedxClass = AtomEntry.prototype._gedxClass = 'GedcomX.AtomEntry'; |
30
|
|
|
|
31
|
|
|
AtomEntry.jsonProps = [ |
32
|
|
|
'authors', |
33
|
|
|
'contributors', |
34
|
|
|
'categories', |
35
|
|
|
'generator', |
36
|
|
|
'icon', |
37
|
|
|
'id', |
38
|
|
|
'links', |
39
|
|
|
'logo', |
40
|
|
|
'rights', |
41
|
|
|
'subtitle', |
42
|
|
|
'title', |
43
|
|
|
'updated', |
44
|
|
|
'content', |
45
|
|
|
'confidence', |
46
|
|
|
'published', |
47
|
|
|
'source', |
48
|
|
|
'summary', |
49
|
|
|
'score' |
50
|
|
|
]; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Check whether the given object is an instance of this class. |
54
|
|
|
* |
55
|
|
|
* @param {Object} obj |
56
|
|
|
* @returns {Boolean} |
57
|
|
|
*/ |
58
|
|
|
AtomEntry.isInstance = function(obj){ |
59
|
|
|
return utils.isInstance(obj, this._gedxClass); |
60
|
|
|
}; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Initialize from JSON |
64
|
|
|
* |
65
|
|
|
* @param {Object} |
|
|
|
|
66
|
|
|
* @return {AtomEntry} this |
67
|
|
|
*/ |
68
|
|
|
AtomEntry.prototype.init = function(json){ |
69
|
|
|
|
70
|
|
|
AtomCommon.prototype.init.call(this, json); |
71
|
|
|
|
72
|
|
|
if(json){ |
73
|
|
|
this.setAuthors(json.authors); |
74
|
|
|
this.setContributors(json.contributors); |
75
|
|
|
this.setCategories(json.categories); |
76
|
|
|
this.setGenerator(json.generator); |
77
|
|
|
this.setIcon(json.icon); |
78
|
|
|
this.setId(json.id); |
79
|
|
|
this.setLinks(json.links); |
80
|
|
|
this.setLogo(json.logo); |
81
|
|
|
this.setRights(json.rights); |
82
|
|
|
this.setSubtitle(json.subtitle); |
83
|
|
|
this.setTitle(json.title); |
84
|
|
|
this.setUpdated(json.updated); |
85
|
|
|
this.setContent(json.content); |
86
|
|
|
this.setConfidence(json.confidence); |
87
|
|
|
this.setPublished(json.published); |
88
|
|
|
this.setSource(json.source); |
89
|
|
|
this.setSummary(json.summary); |
90
|
|
|
this.setScore(json.score); |
91
|
|
|
} |
92
|
|
|
return this; |
93
|
|
|
}; |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Set the authors |
97
|
|
|
* |
98
|
|
|
* @param {AtomPerson[]} authors |
99
|
|
|
* @return {AtomEntry} this |
100
|
|
|
*/ |
101
|
|
|
AtomEntry.prototype.setAuthors = function(authors){ |
102
|
|
|
return this._setArray(authors, 'authors', 'addAuthor'); |
103
|
|
|
}; |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Add an author |
107
|
|
|
* |
108
|
|
|
* @param {AtomPerson} author |
109
|
|
|
* @return {AtomEntry} this |
110
|
|
|
*/ |
111
|
|
|
AtomEntry.prototype.addAuthor = function(author){ |
112
|
|
|
return this._arrayPush(author, 'authors', GedcomX.AtomPerson); |
113
|
|
|
}; |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Get the authors |
117
|
|
|
* |
118
|
|
|
* @return {AtomPerson[]} authors |
119
|
|
|
*/ |
120
|
|
|
AtomEntry.prototype.getAuthors = function(){ |
121
|
|
|
return this.authors || []; |
122
|
|
|
}; |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Set the contributors |
126
|
|
|
* |
127
|
|
|
* @param {AtomPerson[]} contributors |
128
|
|
|
* @return {AtomEntry} this |
129
|
|
|
*/ |
130
|
|
|
AtomEntry.prototype.setContributors = function(contributors){ |
131
|
|
|
return this._setArray(contributors, 'contributors', 'addContributor'); |
132
|
|
|
}; |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* Add a contributor |
136
|
|
|
* |
137
|
|
|
* @param {AtomPerson} contributor |
138
|
|
|
* @return {AtomEntry} this |
139
|
|
|
*/ |
140
|
|
|
AtomEntry.prototype.addContributor = function(contributor){ |
141
|
|
|
return this._arrayPush(contributor, 'contributors', GedcomX.AtomPerson); |
142
|
|
|
}; |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* Get the contributors |
146
|
|
|
* |
147
|
|
|
* @return {AtomPerson[]} contributors |
148
|
|
|
*/ |
149
|
|
|
AtomEntry.prototype.getContributors = function(){ |
150
|
|
|
return this.contributors || []; |
151
|
|
|
}; |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* Set the categories |
155
|
|
|
* |
156
|
|
|
* @param {AtomCategory[]} categories |
157
|
|
|
* @return {AtomEntry} this |
158
|
|
|
*/ |
159
|
|
|
AtomEntry.prototype.setCategories = function(categories){ |
160
|
|
|
return this._setArray(categories, 'categories', 'addCategory'); |
161
|
|
|
}; |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* Add a category |
165
|
|
|
* |
166
|
|
|
* @param {AtomCategory} category |
167
|
|
|
* @return {AtomEntry} this |
168
|
|
|
*/ |
169
|
|
|
AtomEntry.prototype.addCategory = function(category){ |
170
|
|
|
return this._arrayPush(category, 'categories', GedcomX.AtomCategory); |
171
|
|
|
}; |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* Get the categories |
175
|
|
|
* |
176
|
|
|
* @return {AtomCategory[]} categories |
177
|
|
|
*/ |
178
|
|
|
AtomEntry.prototype.getCategories = function(){ |
179
|
|
|
return this.categories || []; |
180
|
|
|
}; |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* Set the generator |
184
|
|
|
* |
185
|
|
|
* @param {AtomGenerator} generator |
186
|
|
|
* @return {AtomEntry} |
187
|
|
|
*/ |
188
|
|
|
AtomEntry.prototype.setGenerator = function(generator){ |
189
|
|
|
if(generator){ |
190
|
|
|
this.generator = GedcomX.AtomGenerator(generator); |
191
|
|
|
} |
192
|
|
|
return this; |
193
|
|
|
}; |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* Get the generator |
197
|
|
|
* |
198
|
|
|
* @return {AtomGenerator} generator |
199
|
|
|
*/ |
200
|
|
|
AtomEntry.prototype.getGenerator = function(){ |
201
|
|
|
return this.generator; |
202
|
|
|
}; |
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* Set the icon |
206
|
|
|
* |
207
|
|
|
* @param {String} icon |
208
|
|
|
* @return {AtomEntry} |
209
|
|
|
*/ |
210
|
|
|
AtomEntry.prototype.setIcon = function(icon){ |
211
|
|
|
this.icon = icon; |
212
|
|
|
return this; |
213
|
|
|
}; |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* Get the icon |
217
|
|
|
* |
218
|
|
|
* @return {String} icon |
219
|
|
|
*/ |
220
|
|
|
AtomEntry.prototype.getIcon = function(){ |
221
|
|
|
return this.icon; |
222
|
|
|
}; |
223
|
|
|
|
224
|
|
|
/** |
225
|
|
|
* Set the id |
226
|
|
|
* |
227
|
|
|
* @param {String} id |
228
|
|
|
* @return {AtomEntry} |
229
|
|
|
*/ |
230
|
|
|
AtomEntry.prototype.setId = function(id){ |
231
|
|
|
this.id = id; |
232
|
|
|
return this; |
233
|
|
|
}; |
234
|
|
|
|
235
|
|
|
/** |
236
|
|
|
* Get the id |
237
|
|
|
* |
238
|
|
|
* @return {String} id |
239
|
|
|
*/ |
240
|
|
|
AtomEntry.prototype.getId = function(){ |
241
|
|
|
return this.id; |
242
|
|
|
}; |
243
|
|
|
|
244
|
|
|
/** |
245
|
|
|
* Set the links |
246
|
|
|
* |
247
|
|
|
* @param {Links} links |
248
|
|
|
* @return {AtomEntry} this |
249
|
|
|
*/ |
250
|
|
|
AtomEntry.prototype.setLinks = function(links){ |
251
|
|
|
if(links){ |
252
|
|
|
this.links = GedcomX.Links(links); |
253
|
|
|
} |
254
|
|
|
return this; |
255
|
|
|
}; |
256
|
|
|
|
257
|
|
|
/** |
258
|
|
|
* Add a link |
259
|
|
|
* |
260
|
|
|
* @param {Link} link |
261
|
|
|
* @return {AtomEntry} this |
262
|
|
|
*/ |
263
|
|
|
AtomEntry.prototype.addLink = function(link){ |
264
|
|
|
if(link){ |
265
|
|
|
if(!this.links){ |
266
|
|
|
this.links = GedcomX.Links(); |
267
|
|
|
} |
268
|
|
|
this.links.addLink(link); |
269
|
|
|
} |
270
|
|
|
return this; |
271
|
|
|
}; |
272
|
|
|
|
273
|
|
|
/** |
274
|
|
|
* Get the links |
275
|
|
|
* |
276
|
|
|
* @return {Link[]} |
277
|
|
|
*/ |
278
|
|
|
AtomEntry.prototype.getLinks = function(){ |
279
|
|
|
return this.links ? this.links.getLinks() : []; |
280
|
|
|
}; |
281
|
|
|
|
282
|
|
|
/** |
283
|
|
|
* Get a link |
284
|
|
|
* |
285
|
|
|
* @param {String} rel |
286
|
|
|
* @return {Links} |
287
|
|
|
*/ |
288
|
|
|
AtomEntry.prototype.getLink = function(rel){ |
289
|
|
|
if(this.links){ |
|
|
|
|
290
|
|
|
return this.links.getLink(rel); |
291
|
|
|
} |
292
|
|
|
}; |
293
|
|
|
|
294
|
|
|
/** |
295
|
|
|
* Set the logo |
296
|
|
|
* |
297
|
|
|
* @param {String} logo |
298
|
|
|
* @return {AtomEntry} |
299
|
|
|
*/ |
300
|
|
|
AtomEntry.prototype.setLogo = function(logo){ |
301
|
|
|
this.logo = logo; |
302
|
|
|
return this; |
303
|
|
|
}; |
304
|
|
|
|
305
|
|
|
/** |
306
|
|
|
* Get the logo |
307
|
|
|
* |
308
|
|
|
* @return {String} logo |
309
|
|
|
*/ |
310
|
|
|
AtomEntry.prototype.getLogo = function(){ |
311
|
|
|
return this.logo; |
312
|
|
|
}; |
313
|
|
|
|
314
|
|
|
/** |
315
|
|
|
* Set the rights |
316
|
|
|
* |
317
|
|
|
* @param {String} rights |
318
|
|
|
* @return {AtomEntry} |
319
|
|
|
*/ |
320
|
|
|
AtomEntry.prototype.setRights = function(rights){ |
321
|
|
|
this.rights = rights; |
322
|
|
|
return this; |
323
|
|
|
}; |
324
|
|
|
|
325
|
|
|
/** |
326
|
|
|
* Get the rights |
327
|
|
|
* |
328
|
|
|
* @return {String} rights |
329
|
|
|
*/ |
330
|
|
|
AtomEntry.prototype.getRights = function(){ |
331
|
|
|
return this.rights; |
332
|
|
|
}; |
333
|
|
|
|
334
|
|
|
/** |
335
|
|
|
* Set the subtitle |
336
|
|
|
* |
337
|
|
|
* @param {String} subtitle |
338
|
|
|
* @return {AtomEntry} |
339
|
|
|
*/ |
340
|
|
|
AtomEntry.prototype.setSubtitle = function(subtitle){ |
341
|
|
|
this.subtitle = subtitle; |
342
|
|
|
return this; |
343
|
|
|
}; |
344
|
|
|
|
345
|
|
|
/** |
346
|
|
|
* Get the subtitle |
347
|
|
|
* |
348
|
|
|
* @return {String} subtitle |
349
|
|
|
*/ |
350
|
|
|
AtomEntry.prototype.getSubtitle = function(){ |
351
|
|
|
return this.subtitle; |
352
|
|
|
}; |
353
|
|
|
|
354
|
|
|
/** |
355
|
|
|
* Set the title |
356
|
|
|
* |
357
|
|
|
* @param {String} title |
358
|
|
|
* @return {AtomEntry} |
359
|
|
|
*/ |
360
|
|
|
AtomEntry.prototype.setTitle = function(title){ |
361
|
|
|
this.title = title; |
362
|
|
|
return this; |
363
|
|
|
}; |
364
|
|
|
|
365
|
|
|
/** |
366
|
|
|
* Get the title |
367
|
|
|
* |
368
|
|
|
* @return {String} title |
369
|
|
|
*/ |
370
|
|
|
AtomEntry.prototype.getTitle = function(){ |
371
|
|
|
return this.title; |
372
|
|
|
}; |
373
|
|
|
|
374
|
|
|
/** |
375
|
|
|
* Get the updated timestamp |
376
|
|
|
* |
377
|
|
|
* @returns {Date} updated |
378
|
|
|
*/ |
379
|
|
|
AtomEntry.prototype.getUpdated = function(){ |
380
|
|
|
return this.updated; |
381
|
|
|
}; |
382
|
|
|
|
383
|
|
|
/** |
384
|
|
|
* Set the updated timestamp |
385
|
|
|
* |
386
|
|
|
* @param {Date|Number} date Integer timestamp (milliseconds since epoch) or JavaScript Date instance |
387
|
|
|
* @returns {AtomEntry} this |
388
|
|
|
*/ |
389
|
|
|
AtomEntry.prototype.setUpdated = function(date){ |
390
|
|
|
if(date){ |
391
|
|
|
this.updated = new Date(date); |
392
|
|
|
} |
393
|
|
|
return this; |
394
|
|
|
}; |
395
|
|
|
|
396
|
|
|
/** |
397
|
|
|
* Set the content |
398
|
|
|
* |
399
|
|
|
* @param {AtomContent} content |
400
|
|
|
* @return {AtomEntry} this |
401
|
|
|
*/ |
402
|
|
|
AtomEntry.prototype.setContent = function(content){ |
403
|
|
|
if(content){ |
404
|
|
|
this.content = GedcomX.AtomContent(content); |
405
|
|
|
} |
406
|
|
|
return this; |
407
|
|
|
}; |
408
|
|
|
|
409
|
|
|
/** |
410
|
|
|
* Get the content |
411
|
|
|
* |
412
|
|
|
* @return {AtomContent} content |
413
|
|
|
*/ |
414
|
|
|
AtomEntry.prototype.getContent = function(){ |
415
|
|
|
return this.content; |
416
|
|
|
}; |
417
|
|
|
|
418
|
|
|
/** |
419
|
|
|
* Set the confidence |
420
|
|
|
* |
421
|
|
|
* @param {Integer} confidence |
422
|
|
|
* @return {AtomEntry} this |
423
|
|
|
*/ |
424
|
|
|
AtomEntry.prototype.setConfidence = function(confidence){ |
425
|
|
|
this.confidence = confidence; |
426
|
|
|
return this; |
427
|
|
|
}; |
428
|
|
|
|
429
|
|
|
/** |
430
|
|
|
* Get the confidence |
431
|
|
|
* |
432
|
|
|
* @return {Integer} confidence |
433
|
|
|
*/ |
434
|
|
|
AtomEntry.prototype.getConfidence = function(){ |
435
|
|
|
return this.confidence; |
436
|
|
|
}; |
437
|
|
|
|
438
|
|
|
/** |
439
|
|
|
* Get the published timestamp |
440
|
|
|
* |
441
|
|
|
* @returns {Date} published |
442
|
|
|
*/ |
443
|
|
|
AtomEntry.prototype.getPublished = function(){ |
444
|
|
|
return this.published; |
445
|
|
|
}; |
446
|
|
|
|
447
|
|
|
/** |
448
|
|
|
* Set the published timestamp |
449
|
|
|
* |
450
|
|
|
* @param {Date|Number} date Integer timestamp (milliseconds since epoch) or JavaScript Date instance |
451
|
|
|
* @returns {AtomEntry} this |
452
|
|
|
*/ |
453
|
|
|
AtomEntry.prototype.setPublished = function(date){ |
454
|
|
|
if(date){ |
455
|
|
|
this.published = new Date(date); |
456
|
|
|
} |
457
|
|
|
return this; |
458
|
|
|
}; |
459
|
|
|
|
460
|
|
|
/** |
461
|
|
|
* Set the source |
462
|
|
|
* |
463
|
|
|
* @param {AtomSource} source |
464
|
|
|
* @return {AtomEntry} this |
465
|
|
|
*/ |
466
|
|
|
AtomEntry.prototype.setSource = function(source){ |
467
|
|
|
if(source){ |
468
|
|
|
this.source = GedcomX.AtomSource(source); |
469
|
|
|
} |
470
|
|
|
return this; |
471
|
|
|
}; |
472
|
|
|
|
473
|
|
|
/** |
474
|
|
|
* Get the source |
475
|
|
|
* |
476
|
|
|
* @return {AtomSource} source |
477
|
|
|
*/ |
478
|
|
|
AtomEntry.prototype.getSource = function(){ |
479
|
|
|
return this.source; |
480
|
|
|
}; |
481
|
|
|
|
482
|
|
|
/** |
483
|
|
|
* Set the summary |
484
|
|
|
* |
485
|
|
|
* @param {String} summary |
486
|
|
|
* @return {AtomEntry} this |
487
|
|
|
*/ |
488
|
|
|
AtomEntry.prototype.setSummary = function(summary){ |
489
|
|
|
this.summary = summary; |
490
|
|
|
return this; |
491
|
|
|
}; |
492
|
|
|
|
493
|
|
|
/** |
494
|
|
|
* Get the summary |
495
|
|
|
* |
496
|
|
|
* @return {String} summary |
497
|
|
|
*/ |
498
|
|
|
AtomEntry.prototype.getSummary = function(){ |
499
|
|
|
return this.summary; |
500
|
|
|
}; |
501
|
|
|
|
502
|
|
|
/** |
503
|
|
|
* Set the score |
504
|
|
|
* |
505
|
|
|
* @param {Number} score |
506
|
|
|
* @return {AtomEntry} this |
507
|
|
|
*/ |
508
|
|
|
AtomEntry.prototype.setScore = function(score){ |
509
|
|
|
this.score = score; |
510
|
|
|
return this; |
511
|
|
|
}; |
512
|
|
|
|
513
|
|
|
/** |
514
|
|
|
* Get the score |
515
|
|
|
* |
516
|
|
|
* @return {Number} score |
517
|
|
|
*/ |
518
|
|
|
AtomEntry.prototype.getScore = function(){ |
519
|
|
|
return this.score; |
520
|
|
|
}; |
521
|
|
|
|
522
|
|
|
/** |
523
|
|
|
* Export the object as JSON |
524
|
|
|
* |
525
|
|
|
* @return {Object} JSON object |
526
|
|
|
*/ |
527
|
|
|
AtomEntry.prototype.toJSON = function(){ |
528
|
|
|
return this._toJSON(AtomCommon, AtomEntry.jsonProps); |
529
|
|
|
}; |
530
|
|
|
|
531
|
|
|
GedcomX.AtomEntry = AtomEntry; |
532
|
|
|
|
533
|
|
|
}; |