forked from zotero/zotero-connectors
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_typeSchemaData.html
85 lines (76 loc) · 2.92 KB
/
build_typeSchemaData.html
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
78
79
80
81
82
83
84
85
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Build schemaData.js</title>
</head>
<body>
<p>This script builds schemaData.js, which contains Zotero schema information for the connector. It must be run from a Zotero SVN installation.</p>
<script type="text/javascript">
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
var Zotero = Components.classes["@zotero.org/Zotero;1"]
// Currently uses only nsISupports
//.getService(Components.interfaces.chnmIZoteroService).
.getService(Components.interfaces.nsISupports)
.wrappedJSObject;
// Create schema
var schema = {"itemTypes":{}, "creatorTypes":{}, "fields":{}};
var types = Zotero.ItemTypes.getTypes();
var fieldIDs = Zotero.DB.columnQuery("SELECT fieldID FROM fieldsCombined");
var baseMappedFields = Zotero.ItemFields.getBaseMappedFields();
for each(var fieldID in fieldIDs) {
var fieldObj = [/* name */Zotero.ItemFields.getName(fieldID)];
try {
fieldObj.push(/* localizedString */Zotero.getString("itemFields." + fieldObj.name));
} catch(e) {}
schema.fields[fieldID] = fieldObj;
}
// names, localizedStrings, creatorTypes, and fields for each item type
for each(var type in types) {
var fieldIDs = Zotero.ItemFields.getItemTypeFields(type.id);
var baseFields = {};
for each(var fieldID in fieldIDs) {
if(baseMappedFields.indexOf(fieldID) !== -1) {
baseFields[fieldID] = Zotero.ItemFields.getBaseIDFromTypeAndField(type.id, fieldID);
}
}
var icon = Zotero.ItemTypes.getImageSrc(type.name);
icon = icon.substr(icon.lastIndexOf("/")+1);
var creatorTypes = [creatorType.id for each(creatorType in Zotero.CreatorTypes.getTypesForItemType(type.id))];
var primaryCreatorType = Zotero.CreatorTypes.getPrimaryIDForType(type.id);
if(creatorTypes[0] != primaryCreatorType) {
creatorTypes.splice(creatorTypes.indexOf(primaryCreatorType), 1);
creatorTypes.unshift(primaryCreatorType);
}
schema.itemTypes[type.id] = [
/* name */type.name,
/* localizedString */Zotero.ItemTypes.getLocalizedString(type.name),
/* creatorTypes */creatorTypes,
/* fields */ fieldIDs,
/* baseFields */baseFields,
/* icon */icon
];
}
var types = Zotero.CreatorTypes.getTypes();
for each(var type in types) {
schema.creatorTypes[type.id] = [
/* name */type.name,
/* localizedString */Zotero.CreatorTypes.getLocalizedString(type.name)
];
}
// Write to file
var schemaFile = Zotero.getInstallDirectory();
schemaFile.append("chrome");
schemaFile.append("content");
schemaFile.append("zotero");
schemaFile.append("xpcom");
schemaFile.append("connector");
if(!schemaFile.exists()) {
document.write('<p>Failed: not an SVN installation.</p>');
} else {
schemaFile.append("typeSchemaData.js");
Zotero.File.putContents(schemaFile, "Zotero.Connector_Types.schema = "+JSON.stringify(schema));
document.write('<p>Wrote typeSchemaData.js successfully.</p>');
}
</script>
</body>
</html>