-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenuMap.js
More file actions
77 lines (70 loc) · 3.3 KB
/
Copy pathMenuMap.js
File metadata and controls
77 lines (70 loc) · 3.3 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
import { DOMParser } from '@xmldom/xmldom'
import * as xpath from 'xpath'
import zIndexes from './Z3950Indexes.json' with { type: 'json' };
const sruNamespaces = {
"srw": "http://www.loc.gov/zing/srw/",
"explain": "http://explain.z3950.org/dtd/2.0/",
"ns": "http://explain.z3950.org/dtd/2.1/"
}
const defaultIndexes = [
{name:"Keyword",code:"keyword",relators:["all","="]},
{name:"Title",code:"title",relators:["all","=","=="]},
{name:"Author",code:"author",relators:["all","=","=="]},
{name:"Subject",code:"subject",relators:["all","="]},
{name:"ISBN",code:"isbn",relators:["="]},
{name:"ISSN",code:"issn",relators:["="]},
{name:"Publication Date",code:"date",relators:["=",">",">=","<","<="]},
{name:"Language",code:"lang",relators:["="]},
{name:"Record #",code:"recno",relators:["="]},
{name:"Raw Query",code:"raw",relators:["="]}
]
export class MenuMap {
menuMap = {}
constructor(catalogList) {
Object.entries(catalogList).forEach(async ([catkey,catalogInfo]) => {
this.menuMap[catkey] = {}
if(Object.hasOwn(catalogInfo,'indexes')) {
this.menuMap[catkey] = {"primary": catalogInfo.indexes}
} else {
this.menuMap[catkey] = {"primary": defaultIndexes}
}
if(catalogInfo.type == "z3950") {
if(Object.hasOwn(zIndexes,catkey)) {
this.menuMap[catkey].secondary = zIndexes[catkey]
}
} else if(catalogInfo.type == "almasru") {
const explainResponse = await fetch(catalogInfo.baseurl + "?version=1.2&operation=explain")
const explainText = await explainResponse.text()
const parser = new DOMParser()
const explainXML = parser.parseFromString(explainText, "text/xml");
const selectWithNs = xpath.useNamespaces(sruNamespaces)
var secondaryIndexes = []
var indexes = selectWithNs('//explain:index', explainXML)
indexes.forEach(ind => {
const name = selectWithNs('.//ns:title/text()',ind)[0].nodeValue
const prefix = selectWithNs('.//explain:map/explain:name/@set',ind)[0].nodeValue
const code = selectWithNs('.//explain:map/explain:name/text()',ind)[0].nodeValue
const relators = selectWithNs('.//explain:configInfo/explain:supports',ind)
const relatorList = relators.map(rel => {
var textValue = selectWithNs('.//text()',rel)
if(textValue.length > 0) {
return textValue[0].nodeValue
} else {
return "empty"
}
})
secondaryIndexes.push({"name":name,"code":`${prefix}.${code}`,"relators":relatorList})
})
this.menuMap[catkey].secondary = secondaryIndexes
}
if(Object.hasOwn(catalogInfo,"resultFields")) {
this.menuMap[catkey].resultFields = catalogInfo.resultFields
} else {
this.menuMap[catkey].resultFields = []
}
})
}
getJSON() {
return JSON.stringify(this.menuMap,null,2)
}
}