@natlibfi/ekirjasto-opds-feed-parser 0.0.0-post.147 → 0.0.0-post.148
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/src/accessibility.d.ts +12 -0
- package/lib/src/accessibility.js +16 -0
- package/lib/src/accessibility_parser.d.ts +8 -0
- package/lib/src/accessibility_parser.js +71 -0
- package/lib/src/conformance.d.ts +6 -0
- package/lib/src/conformance.js +9 -0
- package/lib/src/conformance_parser.d.ts +7 -0
- package/lib/src/conformance_parser.js +53 -0
- package/lib/src/entry_parser.js +4 -0
- package/lib/src/opds_entry.d.ts +2 -0
- package/lib/src/ways_of_reading.d.ts +6 -0
- package/lib/src/ways_of_reading.js +9 -0
- package/lib/src/ways_of_reading_parser.d.ts +7 -0
- package/lib/src/ways_of_reading_parser.js +59 -0
- package/package.json +1 -1
- package/test/accessibility_parser_test.ts +450 -0
- package/test/files/accessibility.xml +13 -0
- package/test/files/acquisition.xml +10 -0
- package/test/files/entry.xml +10 -0
- package/test/opds_parser_test.ts +6 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import Conformance from "./conformance";
|
|
2
|
+
import WaysOfReading from "./ways_of_reading";
|
|
3
|
+
export default class Accessibility {
|
|
4
|
+
conformance?: Conformance;
|
|
5
|
+
waysOfReading?: WaysOfReading;
|
|
6
|
+
constructor(args?: {
|
|
7
|
+
conformance?: Conformance;
|
|
8
|
+
waysOfReading?: WaysOfReading;
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
export interface AccessibilityArgs extends Accessibility {
|
|
12
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
// Define the Accessibility class
|
|
4
|
+
var Accessibility = /** @class */ (function () {
|
|
5
|
+
// This constructor is used when
|
|
6
|
+
// we are initializing a new Accessibility object
|
|
7
|
+
// with the given parameters
|
|
8
|
+
function Accessibility(args) {
|
|
9
|
+
if (args) {
|
|
10
|
+
this.conformance = args.conformance;
|
|
11
|
+
this.waysOfReading = args.waysOfReading;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return Accessibility;
|
|
15
|
+
}());
|
|
16
|
+
exports.default = Accessibility;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import Accessibility from "./accessibility";
|
|
2
|
+
import Xml2jsOutputParser from "./xml2js_output_parser";
|
|
3
|
+
export default class AccessibilityParser extends Xml2jsOutputParser<Accessibility> {
|
|
4
|
+
parse(tag: any): Accessibility;
|
|
5
|
+
private parseConformance;
|
|
6
|
+
private parseWaysOfReading;
|
|
7
|
+
private createAccessibility;
|
|
8
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
var accessibility_1 = require("./accessibility");
|
|
19
|
+
var conformance_parser_1 = require("./conformance_parser");
|
|
20
|
+
var ways_of_reading_parser_1 = require("./ways_of_reading_parser");
|
|
21
|
+
var xml2js_output_parser_1 = require("./xml2js_output_parser");
|
|
22
|
+
// AccessibilityParser class extends Xml2jsOutputParser
|
|
23
|
+
// to handle parsing of accessibility data
|
|
24
|
+
var AccessibilityParser = /** @class */ (function (_super) {
|
|
25
|
+
__extends(AccessibilityParser, _super);
|
|
26
|
+
function AccessibilityParser() {
|
|
27
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
28
|
+
}
|
|
29
|
+
// function parse is given a tag as parameter
|
|
30
|
+
// (it should be the XML element <accessibility>)
|
|
31
|
+
// and extracts accessibility details from it.
|
|
32
|
+
AccessibilityParser.prototype.parse = function (tag) {
|
|
33
|
+
var conformance = this.parseConformance(tag);
|
|
34
|
+
var waysOfReading = this.parseWaysOfReading(tag);
|
|
35
|
+
return this.createAccessibility(conformance, waysOfReading);
|
|
36
|
+
};
|
|
37
|
+
// helper function to parse the 'conformance' subtag
|
|
38
|
+
AccessibilityParser.prototype.parseConformance = function (tag) {
|
|
39
|
+
// first create instance of the ConformanceParser
|
|
40
|
+
// and define the subtag's name from <conformance>
|
|
41
|
+
var subtagName = "conformance";
|
|
42
|
+
var subtagParser = new conformance_parser_1.default(this.prefixes);
|
|
43
|
+
// then extract conformance metadata from XML using the parser
|
|
44
|
+
return this.parseSubtag(tag, subtagName, subtagParser);
|
|
45
|
+
};
|
|
46
|
+
// helper function to parse the 'waysOfReading' subtag
|
|
47
|
+
AccessibilityParser.prototype.parseWaysOfReading = function (tag) {
|
|
48
|
+
// first create a instance of the WaysOfReadingParser
|
|
49
|
+
// and define the subtag's name from <waysOfReading>
|
|
50
|
+
var subtagName = "waysOfReading";
|
|
51
|
+
var subtagParser = new ways_of_reading_parser_1.default(this.prefixes);
|
|
52
|
+
// then extract ways of reading metadata from XML using the parser
|
|
53
|
+
return this.parseSubtag(tag, subtagName, subtagParser);
|
|
54
|
+
};
|
|
55
|
+
// helper function that creates an Accessibility instance
|
|
56
|
+
// from the parsed data given as parameter
|
|
57
|
+
AccessibilityParser.prototype.createAccessibility = function (conformance, waysOfReading) {
|
|
58
|
+
// create an AccessibilityArgs object
|
|
59
|
+
// that holds the extracted data
|
|
60
|
+
var accessibilityArgs = {
|
|
61
|
+
conformance: conformance,
|
|
62
|
+
waysOfReading: waysOfReading,
|
|
63
|
+
};
|
|
64
|
+
// return a new Accessibility instance
|
|
65
|
+
// that is created using accessibilityArgs
|
|
66
|
+
// (there's a constructor init method for this)
|
|
67
|
+
return new accessibility_1.default(accessibilityArgs);
|
|
68
|
+
};
|
|
69
|
+
return AccessibilityParser;
|
|
70
|
+
}(xml2js_output_parser_1.default));
|
|
71
|
+
exports.default = AccessibilityParser;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import Conformance from "./conformance";
|
|
2
|
+
import Xml2jsOutputParser from "./xml2js_output_parser";
|
|
3
|
+
export default class ConformanceParser extends Xml2jsOutputParser<Conformance> {
|
|
4
|
+
parse(tag: any): Conformance;
|
|
5
|
+
private extractConformsTo;
|
|
6
|
+
private createConformance;
|
|
7
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
var conformance_1 = require("./conformance");
|
|
19
|
+
var xml2js_output_parser_1 = require("./xml2js_output_parser");
|
|
20
|
+
// this class extends Xml2jsOutputParser
|
|
21
|
+
// to handle parsing of conformance accessibility data
|
|
22
|
+
var ConformanceParser = /** @class */ (function (_super) {
|
|
23
|
+
__extends(ConformanceParser, _super);
|
|
24
|
+
function ConformanceParser() {
|
|
25
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
26
|
+
}
|
|
27
|
+
// parse function gets a tag <conformance>
|
|
28
|
+
// and extracts Conformance data from it
|
|
29
|
+
ConformanceParser.prototype.parse = function (tag) {
|
|
30
|
+
// extract the 'conformsTo' value from the tag
|
|
31
|
+
// using the helper function.
|
|
32
|
+
var conformsTo = this.extractConformsTo(tag);
|
|
33
|
+
// return new Conformance instance
|
|
34
|
+
return this.createConformance(conformsTo);
|
|
35
|
+
};
|
|
36
|
+
// helper function to extract the 'conformsTo' value from the tag
|
|
37
|
+
ConformanceParser.prototype.extractConformsTo = function (tag) {
|
|
38
|
+
// Use the existing method to parse the subtag content
|
|
39
|
+
return this.parseSubtagContent(tag, "conformsTo");
|
|
40
|
+
};
|
|
41
|
+
// helper function to create a Conformance instance
|
|
42
|
+
// from the extracted conformsTo element
|
|
43
|
+
ConformanceParser.prototype.createConformance = function (conformsTo) {
|
|
44
|
+
// create a ConformanceArgs object
|
|
45
|
+
// to hold the extracted data
|
|
46
|
+
var conformanceArgs = { conformsTo: conformsTo };
|
|
47
|
+
// return a new Conformance instance
|
|
48
|
+
// using the collected arguments
|
|
49
|
+
return new conformance_1.default(conformanceArgs);
|
|
50
|
+
};
|
|
51
|
+
return ConformanceParser;
|
|
52
|
+
}(xml2js_output_parser_1.default));
|
|
53
|
+
exports.default = ConformanceParser;
|
package/lib/src/entry_parser.js
CHANGED
|
@@ -15,6 +15,7 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
15
15
|
};
|
|
16
16
|
})();
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
var accessibility_parser_1 = require("./accessibility_parser");
|
|
18
19
|
var opds_entry_1 = require("./opds_entry");
|
|
19
20
|
var partial_opds_entry_1 = require("./partial_opds_entry");
|
|
20
21
|
var complete_entry_link_1 = require("./complete_entry_link");
|
|
@@ -36,6 +37,8 @@ var EntryParser = /** @class */ (function (_super) {
|
|
|
36
37
|
var dcPrefix = this.prefixes[namespace_parser_1.default.DC_URI];
|
|
37
38
|
var schemaPrefix = this.prefixes[namespace_parser_1.default.SCHEMA_URI];
|
|
38
39
|
var id = this.parseSubtagContent(entry, atomPrefix + "id");
|
|
40
|
+
var accessibilityParser = new accessibility_parser_1.default(this.prefixes);
|
|
41
|
+
var accessibility = this.parseSubtag(entry, atomPrefix + "accessibility", accessibilityParser);
|
|
39
42
|
var updated = this.parseSubtagContent(entry, atomPrefix + "updated");
|
|
40
43
|
var title = this.parseSubtagContent(entry, atomPrefix + "title");
|
|
41
44
|
var contributorParser = new contributor_parser_1.default(this.prefixes);
|
|
@@ -83,6 +86,7 @@ var EntryParser = /** @class */ (function (_super) {
|
|
|
83
86
|
}
|
|
84
87
|
return new entryClass({
|
|
85
88
|
id: id,
|
|
89
|
+
accessibility: accessibility,
|
|
86
90
|
updated: updated,
|
|
87
91
|
title: title,
|
|
88
92
|
authors: authors,
|
package/lib/src/opds_entry.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import Accessibility from "./accessibility";
|
|
1
2
|
import OPDSLink from "./opds_link";
|
|
2
3
|
import Contributor from "./contributor";
|
|
3
4
|
import Series from "./series";
|
|
@@ -5,6 +6,7 @@ import Category from "./category";
|
|
|
5
6
|
import Summary from "./summary";
|
|
6
7
|
export default class OPDSEntry {
|
|
7
8
|
id: string;
|
|
9
|
+
accessibility: Accessibility;
|
|
8
10
|
updated: string;
|
|
9
11
|
title: string;
|
|
10
12
|
authors: Array<Contributor>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import WaysOfReading from "./ways_of_reading";
|
|
2
|
+
import Xml2jsOutputParser from "./xml2js_output_parser";
|
|
3
|
+
export default class WaysOfReadingParser extends Xml2jsOutputParser<WaysOfReading> {
|
|
4
|
+
parse(tag: any): WaysOfReading;
|
|
5
|
+
private extractFeatures;
|
|
6
|
+
private createWaysOfReading;
|
|
7
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
var ways_of_reading_1 = require("./ways_of_reading");
|
|
19
|
+
var xml2js_output_parser_1 = require("./xml2js_output_parser");
|
|
20
|
+
// this class extends Xml2jsOutputParser
|
|
21
|
+
// to handle parsing of ways of reading accessibility data
|
|
22
|
+
var WaysOfReadingParser = /** @class */ (function (_super) {
|
|
23
|
+
__extends(WaysOfReadingParser, _super);
|
|
24
|
+
function WaysOfReadingParser() {
|
|
25
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
26
|
+
}
|
|
27
|
+
// parse function gets a tag <waysOfReading>
|
|
28
|
+
// and extracts Conformance information from it.
|
|
29
|
+
WaysOfReadingParser.prototype.parse = function (tag) {
|
|
30
|
+
// extract an array of features
|
|
31
|
+
// from the 'feature' subtags in the tag
|
|
32
|
+
var featuresArray = this.extractFeatures(tag["feature"]);
|
|
33
|
+
// return new WaysOfReading instance
|
|
34
|
+
return this.createWaysOfReading(featuresArray);
|
|
35
|
+
};
|
|
36
|
+
// helper function to extract features from the 'feature' subtags
|
|
37
|
+
WaysOfReadingParser.prototype.extractFeatures = function (featureSubtags) {
|
|
38
|
+
// first check that featureSubtags is defined and is an array
|
|
39
|
+
if (!featureSubtags || !Array.isArray(featureSubtags)) {
|
|
40
|
+
return [];
|
|
41
|
+
}
|
|
42
|
+
// then extract the feature element contents from subtags,
|
|
43
|
+
// mapping each subtag to its content
|
|
44
|
+
return featureSubtags.map(function (subtag) { return subtag["_"]; });
|
|
45
|
+
};
|
|
46
|
+
// helper function to create a WaysOfReading instance
|
|
47
|
+
// from the extracted feature elements
|
|
48
|
+
WaysOfReadingParser.prototype.createWaysOfReading = function (features) {
|
|
49
|
+
// create a WaysOfReadingArgs object
|
|
50
|
+
// to hold the extracted data
|
|
51
|
+
var waysOfReadingArgs = { features: features };
|
|
52
|
+
// return a new WaysOfReading instance
|
|
53
|
+
// using the collected arguments
|
|
54
|
+
// (there's a constructor init method for this)
|
|
55
|
+
return new ways_of_reading_1.default(waysOfReadingArgs);
|
|
56
|
+
};
|
|
57
|
+
return WaysOfReadingParser;
|
|
58
|
+
}(xml2js_output_parser_1.default));
|
|
59
|
+
exports.default = WaysOfReadingParser;
|
package/package.json
CHANGED
|
@@ -0,0 +1,450 @@
|
|
|
1
|
+
import AccessibilityParser from "../src/accessibility_parser";
|
|
2
|
+
import chai = require("chai");
|
|
3
|
+
import ConformanceParser from "../src/conformance_parser";
|
|
4
|
+
import fs = require("fs");
|
|
5
|
+
import OPDSParser, { OPDSEntry, OPDSFeed } from "../src";
|
|
6
|
+
import PrefixMap from "../src/prefix_map";
|
|
7
|
+
import WaysOfReadingParser from "../src/ways_of_reading_parser";
|
|
8
|
+
|
|
9
|
+
let expect = chai.expect;
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
// OPDS entry parsing test for accessibility
|
|
13
|
+
|
|
14
|
+
describe("EntryParser, AccessibilityParser, ConformanceParser and WaysOfReadingParser", () => {
|
|
15
|
+
let opdsParser: OPDSParser;
|
|
16
|
+
|
|
17
|
+
beforeEach(() => {
|
|
18
|
+
opdsParser = new OPDSParser();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
describe("#parse", () => {
|
|
22
|
+
|
|
23
|
+
it("extract accessibility attribute from <accessibility>", (done) => {
|
|
24
|
+
fs.readFile("test/files/accessibility.xml", "utf8", (error, data) => {
|
|
25
|
+
if (error) {
|
|
26
|
+
done(error);
|
|
27
|
+
} else {
|
|
28
|
+
let promise: Promise<OPDSFeed | OPDSEntry> = opdsParser.parse(data);
|
|
29
|
+
promise.then((entry: OPDSEntry) => {
|
|
30
|
+
expect(entry.title).to.equals("Accessibility XML test");
|
|
31
|
+
expect(entry.accessibility).to.be.an("object");
|
|
32
|
+
expect(entry.accessibility).to.have.property("waysOfReading");
|
|
33
|
+
expect(entry.accessibility.waysOfReading).to.have.property("features").that.is.an("array").that.has.lengthOf(3);
|
|
34
|
+
expect(entry.accessibility.waysOfReading.features).to.include.members([
|
|
35
|
+
"Appearance can be modified",
|
|
36
|
+
"Has alternative text",
|
|
37
|
+
"Not fully readable in read aloud or dynamic braille"
|
|
38
|
+
]);
|
|
39
|
+
expect(entry.accessibility).to.have.property("conformance");
|
|
40
|
+
expect(entry.accessibility.conformance).to.have.property("conformsTo", "This publication meets accepted accessibility standards");
|
|
41
|
+
}).then(done, done);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
// Accessibility parsing tests
|
|
52
|
+
|
|
53
|
+
describe("AccessibilityParser", () => {
|
|
54
|
+
let accessibilityParser: AccessibilityParser;
|
|
55
|
+
|
|
56
|
+
beforeEach(() => {
|
|
57
|
+
let prefixes: PrefixMap = {};
|
|
58
|
+
accessibilityParser = new AccessibilityParser(prefixes);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe("#parse", () => {
|
|
62
|
+
|
|
63
|
+
it("extracts conformance attribute", () => {
|
|
64
|
+
|
|
65
|
+
const accessibilityTag = {
|
|
66
|
+
"conformance": [{
|
|
67
|
+
"conformsTo": [
|
|
68
|
+
{"_": "This publication meets accepted accessibility standards"}
|
|
69
|
+
]
|
|
70
|
+
}],
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const result = accessibilityParser.parse(accessibilityTag);
|
|
74
|
+
|
|
75
|
+
expect(result).to.be.an("object");
|
|
76
|
+
expect(result).to.have.property("conformance");
|
|
77
|
+
expect(result.conformance).to.have.property("conformsTo", "This publication meets accepted accessibility standards");
|
|
78
|
+
expect(result).to.have.property("waysOfReading");
|
|
79
|
+
expect(result.waysOfReading).to.be.null;
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("extracts ways of reading attribute", () => {
|
|
83
|
+
|
|
84
|
+
const accessibilityTag = {
|
|
85
|
+
"waysOfReading": [{
|
|
86
|
+
"feature": [
|
|
87
|
+
{"_": "Appearance can be modified"},
|
|
88
|
+
{"_": "Has alternative text"},
|
|
89
|
+
{"_": "Not fully readable in read aloud or dynamic braille"}
|
|
90
|
+
]
|
|
91
|
+
}],
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const result = accessibilityParser.parse(accessibilityTag);
|
|
95
|
+
|
|
96
|
+
expect(result).to.be.an("object");
|
|
97
|
+
expect(result).to.have.property("waysOfReading");
|
|
98
|
+
expect(result.waysOfReading).to.have.property("features").that.is.an("array").that.has.lengthOf(3);
|
|
99
|
+
expect(result.waysOfReading.features).to.include.members([
|
|
100
|
+
"Appearance can be modified",
|
|
101
|
+
"Has alternative text",
|
|
102
|
+
"Not fully readable in read aloud or dynamic braille"
|
|
103
|
+
]);
|
|
104
|
+
expect(result).to.have.property("conformance");
|
|
105
|
+
expect(result.conformance).to.be.null;
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it("extracts conformance and ways of reading attributes", () => {
|
|
109
|
+
|
|
110
|
+
const accessibilityTag = {
|
|
111
|
+
"conformance": [{
|
|
112
|
+
"conformsTo": [
|
|
113
|
+
{"_": "This publication meets accepted accessibility standards"}
|
|
114
|
+
]
|
|
115
|
+
}],
|
|
116
|
+
"waysOfReading": [{
|
|
117
|
+
"feature": [
|
|
118
|
+
{"_": "Appearance can be modified"},
|
|
119
|
+
{"_": "Has alternative text"},
|
|
120
|
+
{"_": "Not fully readable in read aloud or dynamic braille"}
|
|
121
|
+
]
|
|
122
|
+
}]
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
const result = accessibilityParser.parse(accessibilityTag);
|
|
126
|
+
|
|
127
|
+
expect(result).to.be.an("object");
|
|
128
|
+
expect(result).to.have.property("conformance");
|
|
129
|
+
expect(result.conformance).to.have.property("conformsTo", "This publication meets accepted accessibility standards");
|
|
130
|
+
expect(result).to.have.property("waysOfReading");
|
|
131
|
+
expect(result.waysOfReading).to.have.property("features").that.is.an("array").that.has.lengthOf(3);
|
|
132
|
+
expect(result.waysOfReading.features).to.include.members([
|
|
133
|
+
"Appearance can be modified",
|
|
134
|
+
"Has alternative text",
|
|
135
|
+
"Not fully readable in read aloud or dynamic braille"
|
|
136
|
+
]);
|
|
137
|
+
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it("extracts only conformance and ways of reading attributes", () => {
|
|
141
|
+
|
|
142
|
+
const accessibilityTag = {
|
|
143
|
+
"conformance": [{
|
|
144
|
+
"conformsTo": [
|
|
145
|
+
{"_": "This publication meets accepted accessibility standards"}
|
|
146
|
+
]
|
|
147
|
+
}],
|
|
148
|
+
"waysOfReading": [{
|
|
149
|
+
"feature": [
|
|
150
|
+
{"_": "Appearance can be modified"},
|
|
151
|
+
{"_": "Has alternative text"},
|
|
152
|
+
{"_": "Not fully readable in read aloud or dynamic braille"}
|
|
153
|
+
]
|
|
154
|
+
}],
|
|
155
|
+
"hazards": [{
|
|
156
|
+
"feature": [
|
|
157
|
+
{"_": "Sounds"},
|
|
158
|
+
{"_": "Motion simulation"},
|
|
159
|
+
{"_": "Flashing content"}
|
|
160
|
+
]
|
|
161
|
+
}]
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
const result = accessibilityParser.parse(accessibilityTag);
|
|
165
|
+
|
|
166
|
+
expect(result).to.be.an("object");
|
|
167
|
+
expect(result).to.have.property("conformance");
|
|
168
|
+
expect(result.conformance).to.have.property("conformsTo", "This publication meets accepted accessibility standards");
|
|
169
|
+
expect(result).to.have.property("waysOfReading");
|
|
170
|
+
expect(result.waysOfReading).to.have.property("features").that.is.an("array").that.has.lengthOf(3);
|
|
171
|
+
expect(result.waysOfReading.features).to.include.members([
|
|
172
|
+
"Appearance can be modified",
|
|
173
|
+
"Has alternative text",
|
|
174
|
+
"Not fully readable in read aloud or dynamic braille"
|
|
175
|
+
]);
|
|
176
|
+
expect(result).not.to.have.property("hazards");
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it("extracts conformance and ways of reading attributes if available", () => {
|
|
180
|
+
|
|
181
|
+
const accessibilityTag = {};
|
|
182
|
+
|
|
183
|
+
const result = accessibilityParser.parse(accessibilityTag);
|
|
184
|
+
|
|
185
|
+
expect(result).to.be.an("object");
|
|
186
|
+
expect(result).to.have.property("conformance");
|
|
187
|
+
expect(result).to.have.property("waysOfReading");
|
|
188
|
+
expect(result.conformance).to.be.null;
|
|
189
|
+
expect(result.waysOfReading).to.be.null;
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
it("extracts only conformance and ways of reading from accessibility if available", () => {
|
|
193
|
+
|
|
194
|
+
const accessibilityTag = {
|
|
195
|
+
"hazards": [{
|
|
196
|
+
"feature": [
|
|
197
|
+
{"_": "Sounds"},
|
|
198
|
+
{"_": "Motion simulation"},
|
|
199
|
+
{"_": "Flashing content"}
|
|
200
|
+
]
|
|
201
|
+
}]
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
const result = accessibilityParser.parse(accessibilityTag);
|
|
205
|
+
|
|
206
|
+
expect(result).to.be.an("object");
|
|
207
|
+
expect(Object.keys(result)).to.have.lengthOf(2);
|
|
208
|
+
expect(result).to.have.property("conformance");
|
|
209
|
+
expect(result).to.have.property("waysOfReading");
|
|
210
|
+
expect(result).not.to.have.property("hazards");
|
|
211
|
+
expect(result.conformance).to.be.null;
|
|
212
|
+
expect(result.waysOfReading).to.be.null;
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
// Conformance parsing tests
|
|
221
|
+
|
|
222
|
+
describe("ConformanceParser", () => {
|
|
223
|
+
let conformanceParser: ConformanceParser;
|
|
224
|
+
|
|
225
|
+
beforeEach(() => {
|
|
226
|
+
let prefixes: PrefixMap = {};
|
|
227
|
+
conformanceParser = new ConformanceParser(prefixes);
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
describe("#parse", () => {
|
|
231
|
+
|
|
232
|
+
it("extracts conformsTo attribute", () => {
|
|
233
|
+
|
|
234
|
+
const conformanceTag = {
|
|
235
|
+
"conformsTo": [
|
|
236
|
+
{
|
|
237
|
+
"_": "This publication meets accepted accessibility standards"
|
|
238
|
+
}
|
|
239
|
+
]
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
const result = conformanceParser.parse(conformanceTag);
|
|
243
|
+
|
|
244
|
+
expect(result).to.be.an("object");
|
|
245
|
+
expect(result).to.have.property("conformsTo", "This publication meets accepted accessibility standards");
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
it("extracts conformsTo attribute including empty strings", () => {
|
|
249
|
+
|
|
250
|
+
const conformanceTag = {
|
|
251
|
+
"conformsTo": [
|
|
252
|
+
{
|
|
253
|
+
"_": ""
|
|
254
|
+
}
|
|
255
|
+
]
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
const result = conformanceParser.parse(conformanceTag);
|
|
259
|
+
|
|
260
|
+
expect(result).to.be.an("object");
|
|
261
|
+
expect(result).to.have.property("conformsTo", "");
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
it("extracts only conformsTo attribute", () => {
|
|
265
|
+
|
|
266
|
+
const conformanceTag = {
|
|
267
|
+
"conformsTo": [
|
|
268
|
+
{
|
|
269
|
+
"_": "This publication meets accepted accessibility standards"
|
|
270
|
+
}
|
|
271
|
+
],
|
|
272
|
+
"certifier": [
|
|
273
|
+
{
|
|
274
|
+
"_": "The publication was certified by Certifier"
|
|
275
|
+
}
|
|
276
|
+
]
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
const result = conformanceParser.parse(conformanceTag);
|
|
280
|
+
|
|
281
|
+
expect(result).to.be.an("object");
|
|
282
|
+
expect(Object.keys(result)).to.have.lengthOf(1);
|
|
283
|
+
expect(result).to.have.property("conformsTo", "This publication meets accepted accessibility standards");
|
|
284
|
+
expect(result).not.to.have.property("certifier");
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
it("extracts conformsTo attribute if available", () => {
|
|
288
|
+
|
|
289
|
+
const conformanceTag = {};
|
|
290
|
+
|
|
291
|
+
const result = conformanceParser.parse(conformanceTag);
|
|
292
|
+
|
|
293
|
+
expect(result).to.be.an("object");
|
|
294
|
+
expect(result.conformsTo).to.be.undefined;
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
it("extracts only conformsTo attribute if available", () => {
|
|
298
|
+
|
|
299
|
+
const conformanceTag = {
|
|
300
|
+
"certifier": [
|
|
301
|
+
{
|
|
302
|
+
"_": "The publication was certified by Certifier"
|
|
303
|
+
}
|
|
304
|
+
]
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
const result = conformanceParser.parse(conformanceTag);
|
|
308
|
+
|
|
309
|
+
expect(result).to.be.an("object");
|
|
310
|
+
expect(Object.keys(result)).to.have.lengthOf(1);
|
|
311
|
+
expect(result).to.have.property("conformsTo");
|
|
312
|
+
expect(result.conformsTo).to.be.undefined;
|
|
313
|
+
expect(result).not.to.have.property("certifier");
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
});
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
// Ways of reading parsing tests
|
|
321
|
+
|
|
322
|
+
describe("WaysOfReadingParser", () => {
|
|
323
|
+
let waysOfReadingParser: WaysOfReadingParser;
|
|
324
|
+
|
|
325
|
+
beforeEach(() => {
|
|
326
|
+
let prefixes: PrefixMap = {};
|
|
327
|
+
waysOfReadingParser = new WaysOfReadingParser(prefixes);
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
describe("#parse", () => {
|
|
331
|
+
|
|
332
|
+
it("extracts waysOfReading attribute", () => {
|
|
333
|
+
|
|
334
|
+
const waysOfReadingTag = {
|
|
335
|
+
"feature": [
|
|
336
|
+
{
|
|
337
|
+
"_": "Appearance can be modified"
|
|
338
|
+
},
|
|
339
|
+
{
|
|
340
|
+
"_": "Has alternative text"
|
|
341
|
+
},
|
|
342
|
+
{
|
|
343
|
+
"_": "Not fully readable in read aloud or dynamic braille"
|
|
344
|
+
}
|
|
345
|
+
]
|
|
346
|
+
};
|
|
347
|
+
|
|
348
|
+
const result = waysOfReadingParser.parse(waysOfReadingTag);
|
|
349
|
+
|
|
350
|
+
expect(result).to.be.an("object");
|
|
351
|
+
expect(result).to.have.property("features").that.is.an("array").that.has.lengthOf(3);
|
|
352
|
+
expect(result.features).to.include.members([
|
|
353
|
+
"Appearance can be modified",
|
|
354
|
+
"Has alternative text",
|
|
355
|
+
"Not fully readable in read aloud or dynamic braille"
|
|
356
|
+
]);
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
it("extracts waysOfReading attribute including empty strings", () => {
|
|
360
|
+
|
|
361
|
+
const waysOfReadingTag = {
|
|
362
|
+
"feature": [
|
|
363
|
+
{
|
|
364
|
+
"_": "Appearance can be modified"
|
|
365
|
+
},
|
|
366
|
+
{
|
|
367
|
+
"_": ""
|
|
368
|
+
},
|
|
369
|
+
{
|
|
370
|
+
"_": "Not fully readable in read aloud or dynamic braille"
|
|
371
|
+
}
|
|
372
|
+
]
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
const result = waysOfReadingParser.parse(waysOfReadingTag);
|
|
376
|
+
|
|
377
|
+
expect(result).to.be.an("object");
|
|
378
|
+
expect(result).to.have.property("features").that.is.an("array").that.has.lengthOf(3);
|
|
379
|
+
expect(result.features).to.include.members([
|
|
380
|
+
"Appearance can be modified",
|
|
381
|
+
"",
|
|
382
|
+
"Not fully readable in read aloud or dynamic braille"
|
|
383
|
+
]);
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
it("extracts only waysOfReading attribute", () => {
|
|
387
|
+
|
|
388
|
+
const waysOfReadingTag = {
|
|
389
|
+
"feature": [
|
|
390
|
+
{
|
|
391
|
+
"_": "Appearance can be modified"
|
|
392
|
+
},
|
|
393
|
+
{
|
|
394
|
+
"_": "Has alternative text"
|
|
395
|
+
},
|
|
396
|
+
{
|
|
397
|
+
"_": "Not fully readable in read aloud or dynamic braille"
|
|
398
|
+
}
|
|
399
|
+
],
|
|
400
|
+
"additionalAccessibilityInformation": [
|
|
401
|
+
{
|
|
402
|
+
"_": "High contrast between foreground text and background"
|
|
403
|
+
}
|
|
404
|
+
]
|
|
405
|
+
};
|
|
406
|
+
|
|
407
|
+
const result = waysOfReadingParser.parse(waysOfReadingTag);
|
|
408
|
+
|
|
409
|
+
expect(result).to.be.an("object");
|
|
410
|
+
expect(Object.keys(result)).to.have.lengthOf(1);
|
|
411
|
+
expect(result).to.have.property("features").that.is.an("array").that.has.lengthOf(3);
|
|
412
|
+
expect(result.features).to.include.members([
|
|
413
|
+
"Appearance can be modified",
|
|
414
|
+
"Has alternative text",
|
|
415
|
+
"Not fully readable in read aloud or dynamic braille"
|
|
416
|
+
]);
|
|
417
|
+
expect(result).not.to.have.property("additionalAccessibilityInformation");
|
|
418
|
+
});
|
|
419
|
+
|
|
420
|
+
it("extracts waysOfReading attribute if available", () => {
|
|
421
|
+
|
|
422
|
+
const waysOfReadingTag = {};
|
|
423
|
+
|
|
424
|
+
const result = waysOfReadingParser.parse(waysOfReadingTag);
|
|
425
|
+
|
|
426
|
+
expect(result).to.be.an("object");
|
|
427
|
+
expect(result).to.have.property("features").that.is.an("array").that.has.lengthOf(0);
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
it("extracts only waysOfReading attribute if available", () => {
|
|
431
|
+
|
|
432
|
+
const waysOfReadingTag = {
|
|
433
|
+
"additionalAccessibilityInformation": [
|
|
434
|
+
{
|
|
435
|
+
"_": "High contrast between foreground text and background"
|
|
436
|
+
}
|
|
437
|
+
]
|
|
438
|
+
};
|
|
439
|
+
|
|
440
|
+
const result = waysOfReadingParser.parse(waysOfReadingTag);
|
|
441
|
+
|
|
442
|
+
expect(result).to.be.an("object");
|
|
443
|
+
expect(Object.keys(result)).to.have.lengthOf(1);
|
|
444
|
+
expect(result).to.have.property("features").that.is.an("array").that.has.lengthOf(0);
|
|
445
|
+
expect(result).not.to.have.property("additionalAccessibilityInformation");
|
|
446
|
+
});
|
|
447
|
+
|
|
448
|
+
});
|
|
449
|
+
|
|
450
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<entry xmlns:bibframe="http://bibframe.org/vocab/" xmlns:simplified="http://librarysimplified.org/terms/" xmlns:app="http://www.w3.org/2007/app" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:opds="http://opds-spec.org/2010/catalog" xmlns:schema="http://schema.org/" xmlns="http://www.w3.org/2005/Atom" schema:additionalType="http://schema.org/Book">
|
|
2
|
+
<title>Accessibility XML test</title>
|
|
3
|
+
<accessibility>
|
|
4
|
+
<waysOfReading>
|
|
5
|
+
<feature>Appearance can be modified</feature>
|
|
6
|
+
<feature>Has alternative text</feature>
|
|
7
|
+
<feature>Not fully readable in read aloud or dynamic braille</feature>
|
|
8
|
+
</waysOfReading>
|
|
9
|
+
<conformance>
|
|
10
|
+
<conformsTo>This publication meets accepted accessibility standards</conformsTo>
|
|
11
|
+
</conformance>
|
|
12
|
+
</accessibility>
|
|
13
|
+
</entry>
|
|
@@ -17,6 +17,16 @@
|
|
|
17
17
|
<author>
|
|
18
18
|
<name>Jane Austen</name>
|
|
19
19
|
</author>
|
|
20
|
+
<accessibility>
|
|
21
|
+
<waysOfReading>
|
|
22
|
+
<feature>Appearance can be modified</feature>
|
|
23
|
+
<feature>Has alternative text</feature>
|
|
24
|
+
<feature>Not fully readable in read aloud or dynamic braille</feature>
|
|
25
|
+
</waysOfReading>
|
|
26
|
+
<conformance>
|
|
27
|
+
<conformsTo>This publication meets accepted accessibility standards</conformsTo>
|
|
28
|
+
</conformance>
|
|
29
|
+
</accessibility>
|
|
20
30
|
<published>2006-12-28T20:00:54Z</published>
|
|
21
31
|
<updated>2012-10-12T17:43:18Z</updated>
|
|
22
32
|
<dcterms:language>en</dcterms:language>
|
package/test/files/entry.xml
CHANGED
|
@@ -3,6 +3,16 @@
|
|
|
3
3
|
<title>The Frances Hodgson Burnett Megapack</title>
|
|
4
4
|
<bibframe:distribution bibframe:ProviderName="Overdrive"/>
|
|
5
5
|
<author><name>Frances Hodgson Burnett</name></author>
|
|
6
|
+
<accessibility>
|
|
7
|
+
<waysOfReading>
|
|
8
|
+
<feature>Appearance can be modified</feature>
|
|
9
|
+
<feature>Has alternative text</feature>
|
|
10
|
+
<feature>Not fully readable in read aloud or dynamic braille</feature>
|
|
11
|
+
</waysOfReading>
|
|
12
|
+
<conformance>
|
|
13
|
+
<conformsTo>This publication meets accepted accessibility standards</conformsTo>
|
|
14
|
+
</conformance>
|
|
15
|
+
</accessibility>
|
|
6
16
|
<summary type="html"><p>The Frances Hodgson Burnett Megapack collects 40 classic works by the author of <i>Little Lord Fauntleroy, A Little Princess</i>, and <i>The Secret Garden</i>. Almost 5,000 pages of great reading!<p>THE SECRET GARDEN<p>LITTLE LORD FAUNTLEROY<p>A LITTLE PRINCESS<p>THE LOST PRINCE<p>A LADY OF QUALITY<p>HIS GRACE OF OSMONDE<p>THE LAND OF THE BLUE FLOWER<p>THE LITTLE HUNCHBACK ZIA<p>LITTLE SAINT ELIZABETH<p>THE STORY OF PRINCE FAIRYFOOT<p>THE PROUD LITTLE GRAIN OF WHEAT<p>BEHIND THE WHITE BRICK<p>LODUSKY<p>MÈRE GIRAUDS LITTLE DAUGHTER<p>"LE MONSIEUR DE LA PETITE DAME"<p>MY ROBIN<p>ONE DAY AT ARLE<p>THE PRETTY SISTER OF JOSÉ<p>RACKETTY-PACKETTY HOUSE<p>SARA CREWE<p>SETH<p>THE SHUTTLE<p>SURLY TIM<p>THAT LASS O' LOWRIE'S<p>THEO<p>T. TEMBAROM<p>VAGABONDIA<p>THE WHITE PEOPLE<p>LOUISIANA<p>THE GOOD WOLF<p>BARTY CRUSOE AND HIS MAN SATURDAY<p>THE COZY LION<p>THE DAWN OF A TOMORROW<p>EMILY FOX-SETON<p>ESMERALDA<p>A FAIR BARBARIAN<p>THE HEAD OF THE HOUSE OF COOMBE<p>ROBIN<p>IN CONNECTION WITH THE DE WILLOUGHBY CLAIM<p>IN THE CLOSED ROOM<p>If you enjoy this volume, don't forget to search your favorite ebook store for "Wildside Megapack" to see the 100+ entries in this best-selling series, including volumes of science fiction, fantasy, mystery, westerns, classics, young adult books, and much, much more! (Sort by publication date to see the most recent entries.)</summary>
|
|
7
17
|
<updated>2016-01-08T21:38:19Z</updated>
|
|
8
18
|
<simplified:pwid>500010e3-884f-58d1-2cca-b56429de23fb</simplified:pwid>
|
package/test/opds_parser_test.ts
CHANGED
|
@@ -106,6 +106,8 @@ describe("OPDSParser", () => {
|
|
|
106
106
|
expect(result.entries[0].categories.length).to.equals(2);
|
|
107
107
|
expect(result.entries[0].categories[0].term).to.equals("FBFIC000000");
|
|
108
108
|
expect(result.entries[0].categories[0].label).to.equals("Fiction");
|
|
109
|
+
expect(result.entries[0].accessibility.waysOfReading.features).to.contain("Appearance can be modified");
|
|
110
|
+
expect(result.entries[0].accessibility.conformance.conformsTo).to.equals("This publication meets accepted accessibility standards");
|
|
109
111
|
|
|
110
112
|
expect(result.entries[0].links.length).to.equals(4);
|
|
111
113
|
expect(result.entries[0].links[0]).to.be.an.instanceof(OPDSAcquisitionLink);
|
|
@@ -139,6 +141,10 @@ describe("OPDSParser", () => {
|
|
|
139
141
|
|
|
140
142
|
expect(result.categories.length).to.equals(4);
|
|
141
143
|
expect(result.language).to.equals("en");
|
|
144
|
+
|
|
145
|
+
expect(result.accessibility.waysOfReading.features).to.contain("Appearance can be modified");
|
|
146
|
+
expect(result.accessibility.conformance.conformsTo).to.equals("This publication meets accepted accessibility standards");
|
|
147
|
+
|
|
142
148
|
}).then(done, done);
|
|
143
149
|
}
|
|
144
150
|
});
|