From 8981bb4a75c94cac6fd068f2990168ea6e23ba40 Mon Sep 17 00:00:00 2001 From: Matt Burton Date: Tue, 28 Jul 2009 23:19:36 +0000 Subject: [PATCH] Created a translator for Defense Technical Information Center --- translators/DTIC.js | 126 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 translators/DTIC.js diff --git a/translators/DTIC.js b/translators/DTIC.js new file mode 100644 index 000000000..4b0205264 --- /dev/null +++ b/translators/DTIC.js @@ -0,0 +1,126 @@ +{ + "translatorID":"99be9976-2ff9-40df-96e8-82edfa79d9f3", + "translatorType":4, + "label":"Defense Technical Information Center", + "creator":"Matt Burton", + "target":"http://oai\\.dtic\\.mil/oai/", + "minVersion":"1.0.0b3.r1", + "maxVersion":"", + "priority":100, + "inRepository":true, + "lastUpdated":"2009-07-28 18:10:00" +} + +function detectWeb(doc, url) { + if(doc.title.indexOf("DTIC OAI Index for") != -1) { + return "multiple"; + } else if (url.indexOf("verb=getRecord") != -1){ + return "report"; + } +} + +function doWeb(doc, url) { + var namespace = doc.documentElement.namespaceURI; + var nsResolver = namespace ? function(prefix) { + if (prefix == 'x') return namespace; else return null; + } : null; + + var newURIs = new Array(); + + if(detectWeb(doc,url) == "multiple"){ + var links = doc.evaluate("//a/@href", doc, nsResolver, XPathResult.Abstract, null); + var titles = doc.evaluate("//a/preceding::text()[1]", doc, nsResolver, XPathResult.Abstract, null); + var items = new Object(); + var link, title; + while( link = links.iterateNext(), title = titles.iterateNext()){ + items[link.textContent.replace(/&metadataPrefix=html/, "&metadataPrefix=oai_dc")] = title.textContent; + } + items = Zotero.selectItems(items); + if(!items) { + return true; + } + for (url in items) { + newURIs.push(url); + Zotero.debug(url); + } + } else { + newURIs.push(url.replace(/&metadataPrefix=html/, "&metadataPrefix=oai_dc")) + } + + // ripped the arXiv.org code, hence the funny var names. + Zotero.Utilities.HTTP.doGet(newURIs, function(text) { + var newItem = new Zotero.Item("report"); + // remove header + text = text.replace(/]*>/, "").replace(/<\?xml[^>]*\?>/, ""); + // fix non-compliant XML tags (colons) + text = text.replace(/]*>/, "").replace(/<\/OAI-PMH[^>]*>/, ""); + text = "" + text + ""; + var xml = new XML(text); + var title; + var citation = xml.GetRecord.record.metadata.oai_dc_dc; + var test = xml..responseDate.text().toString(); + + if (citation.dc_title.length()){ + title = Zotero.Utilities.trimInternal(citation.dc_title.text().toString()); + newItem.title = title; + } + Zotero.debug("article title: " + title); + var type = ""; + if(citation.dc_creator.length()) { + var authors = citation.dc_creator; + for(var j=0; j