Ticket #705: proquest_translator.2.sql

File proquest_translator.2.sql, 5.5 KB (added by akusuma, 9 years ago)

Working Proquest Translator. Needs to be commited.

Line 
1REPLACE INTO translators VALUES ('a77690cf-c5d1-8fc4-110f-d1fc765dcf88', '1.0.0b3.r1', '', '2007-08-31 11:34:38', '1', '100', '4', 'ProQuest', 'Simon Kornblith', '^https?://proquest\.umi\.com/', 
2'function detectWeb(doc, url) {
3        var namespace = doc.documentElement.namespaceURI;
4        var nsResolver = namespace ? function(prefix) {
5                if (prefix == ''x'') return namespace; else return null;
6        } : null;
7               
8        if(doc.evaluate(''//img[substring(@src, string-length(@src)-32) = "/images/common/logo_proquest.gif" or substring(@src, string-length(@src)-38) = "/images/common/logo_proquest_small.gif"]'',
9                        doc, nsResolver, XPathResult.ANY_TYPE, null)) {   
10                if(doc.title == "Results") {
11                        return "multiple";
12                } else {
13                        return "magazineArticle";
14                }
15        }
16}
17
18//^https?://[^/]+/pqdweb\?((?:.*\&)?did=.*&Fmt=[0-9]|(?:.*\&)Fmt=[0-9].*&did=|(?:.*\&)searchInterface=)', 
19'function parseRIS(uris) {
20       
21       
22        Zotero.Utilities.HTTP.doGet(uris, function(text, xmlhttp, url){
23                // load translator for RIS
24
25                if(url.match("exportFormat=1")=="exportFormat=1") {
26                       
27                       
28                        var translator = Zotero.loadTranslator("import");
29                        translator.setTranslator("32d59d2d-b65a-4da4-b0a3-bdd3cfb979e7");
30                        translator.setString(text);
31
32                        //Set Handler fixes anomaly in Proquest RIS format. Properly formats author name as [last name], [first name]
33                        translator.setHandler("itemDone", function(obj, item) {
34                                var cre = new Array();
35                                cre = item.creators;
36                                for each(var e in cre) {
37       
38                                        if(!e[''firstName'']) {
39                                                //check if there is a first name, if not, take the first word in the last name
40                                                var names = e[''lastName''].split(" ");
41                                                e[''firstName'']=names[0];
42                                                e[''lastName'']="";
43                                                for(var i = 1; i<names.length; i++) {
44                                                        e[''lastName'']+=names[i];
45                                                }
46                                        }
47                                }
48
49                                item.complete();
50                        });
51               
52                        translator.translate();
53                        Zotero.done();
54                }
55               
56        }, function() {});
57        Zotero.wait();
58}
59
60function doWeb(doc, url) {
61       
62        var namespace = doc.documentElement.namespaceURI;
63        var nsResolver = namespace ? function(prefix) {
64                if (prefix == ''x'') return namespace; else return null;
65        } : null;
66       
67       
68        if(doc.evaluate(''//img[substring(@src, string-length(@src)-32) = "/images/common/logo_proquest.gif" or substring(@src, string-length(@src)-38) = "/images/common/logo_proquest_small.gif"]'',
69                                doc, nsResolver, XPathResult.ANY_TYPE, null)) {
70                        if(doc.title == "Results") {
71                               
72                                //Get Client ID
73                                var xpath = ''//a'';
74                                var data= doc.evaluate(xpath, doc, nsResolver, XPathResult.ANY_TYPE, null);
75                                var aitem;
76                                var clientID;
77                                while(aitem = data.iterateNext()) {
78                                        clientID=aitem.href;
79                                        if(clientID.indexOf("clientId")!=-1) {
80                                                clientID = clientID.substr(clientID.indexOf("clientId")+9,clientID.length);
81                                                break;
82                                        }
83                                }               
84                               
85                                var multXpath = ''//input[@name="chk"][@type="checkbox"]'';
86                                var titleXpath = ''//a[@class="bold"]'';
87                                var mInfos = doc.evaluate(multXpath, doc, nsResolver, XPathResult.ANY_TYPE, null);
88                                var titleElmts = doc.evaluate(titleXpath, doc, nsResolver, XPathResult.ANY_TYPE, null);
89                                var titleElmt;
90                                var mInfo;
91                                mInfo = mInfos.iterateNext();
92                                titleElmt = titleElmts.iterateNext();
93
94                                var items = new Array();
95
96                                do {
97                                        //Get item ID
98                                       
99                                        var str= mInfo.value;
100                                        str= str.replace("retrieveGroup", "sid");
101                                        var url = "http://proquest.umi.com/pqdweb?RQT=530&markedListInfo="+str+"1";
102                                        items[url] = Zotero.Utilities.cleanString(titleElmt.textContent);
103
104                                } while((mInfo = mInfos.iterateNext()) && (titleElmt = titleElmts.iterateNext()));
105
106                                items = Zotero.selectItems(items);
107                                if(!items) return true;
108
109                               
110                                //Array of URLs for the doGet
111                                var uris = new Array();
112                               
113                                //Clear Basket
114                                uris.push("http://proquest.umi.com/pqdweb?RQT=531&clientId="+clientID);
115                                uris.push("http://proquest.umi.com/pqdweb?RQT=532&clientId="+clientID);
116                               
117                                //Add URLS to the basket
118                                for(var bibcode in items) {
119                                        uris.push(bibcode);
120                                }
121                                       
122                                //Export basket as a RIS file
123                                uris.push("http://proquest.umi.com/pqdweb?RQT=532&clientId="+clientID);
124                                uris.push("http://proquest.umi.com/pqdweb?RQT=562&MRR=M&clientId="+clientID);
125                                uris.push("http://proquest.umi.com/pqdweb?RQT=562&exportFormat=1&clientId="+clientID);
126                               
127                                parseRIS(uris);
128                               
129                        } else {
130
131                                //Get Client ID
132                                var xpath = ''//a'';
133                                var data= doc.evaluate(xpath, doc, nsResolver, XPathResult.ANY_TYPE, null);
134                                var aitem;
135                                var clientID;
136                                while(aitem = data.iterateNext()) {
137                                        clientID=aitem.href;
138                                        if(clientID.indexOf("clientId")!=-1) {
139                                                clientID = clientID.substr(clientID.indexOf("clientId")+9,clientID.length);
140                                                break;
141                                        }
142                                }               
143                               
144                                //Get item ID
145                                var xpath = ''//input[@name="marked"][@type="checkbox"]'';
146                                var str= doc.evaluate(xpath, doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext().value;
147                                str= str.replace("retrieveGroup", "sid");
148                               
149                                //Array of URLs for the doGet
150                                var uris = new Array();
151                               
152                                //Clear Basket
153                                uris.push("http://proquest.umi.com/pqdweb?RQT=531&clientId="+clientID);
154                                uris.push("http://proquest.umi.com/pqdweb?RQT=532&clientId="+clientID);
155                               
156                                //Create URL to add item to basket
157                                url = "http://proquest.umi.com/pqdweb?RQT=530&markedListInfo="+str+"1";
158                                Zotero.debug("RIS URL: "+url);
159                               
160                                uris.push(url);
161                                       
162                                //Export basket as a RIS file
163                                uris.push("http://proquest.umi.com/pqdweb?RQT=532&clientId="+clientID);
164                                uris.push("http://proquest.umi.com/pqdweb?RQT=562&MRR=M&clientId="+clientID);
165                                uris.push("http://proquest.umi.com/pqdweb?RQT=562&exportFormat=1&clientId="+clientID);
166                               
167                                parseRIS(uris);
168                               
169                        }
170                }
171
172}');