Optics InfoBase site translator broken
I (erroneously) posted it to the translators forum.
http://forums.zotero.org/discussion/5129/optics-infobase-site-translator-broken/#Item_1
In short, the translator in the sync-preview is broken. Following is a patch that fixes it and adds PDF downloading and Abstract capturing.
Thank you for a wonderful software.
-- technion/zotero/translators/Optical Society of America.js 2009-01-04 17:56:18.000000000 +0200
+++ Optical Society of America.js 2009-01-06 16:40:18.000000000 +0200
@@ -48,14 +48,16 @@
articles = [url];
}
Zotero.Utilities.processDocuments(articles, function(newDoc) {
- var osalink = newDoc.evaluate('//div[@id="abstract"]/p/a[contains(text(), "opticsinfobase")]', newDoc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext().href;
+ var osalink = newDoc.evaluate('//div[@id="abstract-header"]/p/a[contains(text(), "opticsinfobase")]', newDoc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext().href;
+ var pdfpath = '//div[@id="abstract-header"]/p/a[contains(text(), "Full Text")]';
+ var pdflink = newDoc.evaluate(pdfpath, newDoc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext();
+ var abstractblock = newDoc.evaluate('//meta[@name="dc.description"]', newDoc, nsResolver, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
+ var doiblock = newDoc.evaluate('//meta[@name="dc.identifier"]', newDoc, nsResolver, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
+
Zotero.Utilities.HTTP.doGet(osalink, function(text) {
var action = text.match(/select\s+name=\"([^"]+)\"/)[1];
var id = text.match(/input\s+type=\"hidden\"\s+name=\"articles\"\s+value=\"([^"]+)\"/)[1];
- if (newDoc.evaluate('//p[*[contains(text(), "DOI")]]', newDoc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext()) {
- var doi = Zotero.Utilities.trimInternal(newDoc.evaluate('//p[*[contains(text(), "DOI")]]', newDoc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext().textContent);
- doi = doi.match(/doi:(.*)$/)[1];
- }
+
var get = 'http://' + host + '/custom_tags/IB_Download_Citations.cfm';
var post = 'articles=' + id + '&ArticleAction=save_endnote2&' + action + '=save_endnote2';
Zotero.Utilities.HTTP.doPost(get, post, function(text) {
@@ -69,8 +71,20 @@
} else {
pubName = item.publicationTitle;
}
- if (doi) item.DOI = doi;
+
+ if (doiblock) {
+ item.DOI = doiblock.getAttribute('content').match(/doi:(.*)$/)[1];
+ }
+
item.attachments = [{url:osalink, title:pubName + " Snapshot", mimeType:"text/html"}];
+ if (pdflink) {
+ item.attachments.push({url:pdflink.href, title:"OSA Journals PDF", mimeType:"application/pdf"});
+ }
+
+ if (abstractblock) {
+ item.abstractNote = abstractblock.getAttribute('content');
+ }
+
item.complete();
});
translator.translate();
http://forums.zotero.org/discussion/5129/optics-infobase-site-translator-broken/#Item_1
In short, the translator in the sync-preview is broken. Following is a patch that fixes it and adds PDF downloading and Abstract capturing.
Thank you for a wonderful software.
-- technion/zotero/translators/Optical Society of America.js 2009-01-04 17:56:18.000000000 +0200
+++ Optical Society of America.js 2009-01-06 16:40:18.000000000 +0200
@@ -48,14 +48,16 @@
articles = [url];
}
Zotero.Utilities.processDocuments(articles, function(newDoc) {
- var osalink = newDoc.evaluate('//div[@id="abstract"]/p/a[contains(text(), "opticsinfobase")]', newDoc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext().href;
+ var osalink = newDoc.evaluate('//div[@id="abstract-header"]/p/a[contains(text(), "opticsinfobase")]', newDoc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext().href;
+ var pdfpath = '//div[@id="abstract-header"]/p/a[contains(text(), "Full Text")]';
+ var pdflink = newDoc.evaluate(pdfpath, newDoc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext();
+ var abstractblock = newDoc.evaluate('//meta[@name="dc.description"]', newDoc, nsResolver, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
+ var doiblock = newDoc.evaluate('//meta[@name="dc.identifier"]', newDoc, nsResolver, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
+
Zotero.Utilities.HTTP.doGet(osalink, function(text) {
var action = text.match(/select\s+name=\"([^"]+)\"/)[1];
var id = text.match(/input\s+type=\"hidden\"\s+name=\"articles\"\s+value=\"([^"]+)\"/)[1];
- if (newDoc.evaluate('//p[*[contains(text(), "DOI")]]', newDoc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext()) {
- var doi = Zotero.Utilities.trimInternal(newDoc.evaluate('//p[*[contains(text(), "DOI")]]', newDoc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext().textContent);
- doi = doi.match(/doi:(.*)$/)[1];
- }
+
var get = 'http://' + host + '/custom_tags/IB_Download_Citations.cfm';
var post = 'articles=' + id + '&ArticleAction=save_endnote2&' + action + '=save_endnote2';
Zotero.Utilities.HTTP.doPost(get, post, function(text) {
@@ -69,8 +71,20 @@
} else {
pubName = item.publicationTitle;
}
- if (doi) item.DOI = doi;
+
+ if (doiblock) {
+ item.DOI = doiblock.getAttribute('content').match(/doi:(.*)$/)[1];
+ }
+
item.attachments = [{url:osalink, title:pubName + " Snapshot", mimeType:"text/html"}];
+ if (pdflink) {
+ item.attachments.push({url:pdflink.href, title:"OSA Journals PDF", mimeType:"application/pdf"});
+ }
+
+ if (abstractblock) {
+ item.abstractNote = abstractblock.getAttribute('content');
+ }
+
item.complete();
});
translator.translate();
Unfortunately the first bug has been found.
Some articles have an identifier that is not DOI.
Following is a corrected patch. Note that the patch is against the *vanilla* version of the translator, i.e., the one without my previous patch.
P.S.
Sean, I noted that you added me to the authors of the translator. I appreciate that a lot. Could you please use my real name instead of the username.
Thank you.
--- technion/zotero/translators/Optical Society of America.js 2009-01-04 17:56:18.000000000 +0200
+++ Optical Society of America.js 2009-01-06 19:44:05.000000000 +0200
@@ -48,14 +48,31 @@
articles = [url];
}
Zotero.Utilities.processDocuments(articles, function(newDoc) {
- var osalink = newDoc.evaluate('//div[@id="abstract"]/p/a[contains(text(), "opticsinfobase")]', newDoc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext().href;
+ var osalink = newDoc.evaluate('//div[@id="abstract-header"]/p/a[contains(text(), "opticsinfobase")]', newDoc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext().href;
+ var pdfpath = '//div[@id="abstract-header"]/p/a[contains(text(), "Full Text")]';
+ var pdflink = newDoc.evaluate(pdfpath, newDoc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext();
+ var abstractblock = newDoc.evaluate('//meta[@name="dc.description"]', newDoc, nsResolver, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
+ var identifierblock = newDoc.evaluate('//meta[@name="dc.identifier"]', newDoc, nsResolver, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
+
+ // if (pdflink)
+ // Zotero.debug("PDF found");
+ // else
+ // Zotero.debug("PDF not found");
+
+ // if (abstractblock)
+ // Zotero.debug("ABSTRACT found");
+ // else
+ // Zotero.debug("ABSTRACT not found");
+
+ // if (identifierblock)
+ // Zotero.debug("IDENTIFIER found");
+ // else
+ // Zotero.debug("ITENDITFIER not found");
+
Zotero.Utilities.HTTP.doGet(osalink, function(text) {
var action = text.match(/select\s+name=\"([^"]+)\"/)[1];
var id = text.match(/input\s+type=\"hidden\"\s+name=\"articles\"\s+value=\"([^"]+)\"/)[1];
- if (newDoc.evaluate('//p[*[contains(text(), "DOI")]]', newDoc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext()) {
- var doi = Zotero.Utilities.trimInternal(newDoc.evaluate('//p[*[contains(text(), "DOI")]]', newDoc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext().textContent);
- doi = doi.match(/doi:(.*)$/)[1];
- }
+
var get = 'http://' + host + '/custom_tags/IB_Download_Citations.cfm';
var post = 'articles=' + id + '&ArticleAction=save_endnote2&' + action + '=save_endnote2';
Zotero.Utilities.HTTP.doPost(get, post, function(text) {
@@ -69,8 +86,25 @@
} else {
pubName = item.publicationTitle;
}
- if (doi) item.DOI = doi;
+
+ if (identifierblock) {
+ //Zotero.debug("Adding DOI");
+ if (/doi:(.*)$/.test(identifierblock.getAttribute('content'))) {
+ item.DOI = RegExp.$1;
+ }
+ }
+
item.attachments = [{url:osalink, title:pubName + " Snapshot", mimeType:"text/html"}];
+ if (pdflink) {
+ //Zotero.debug("Adding PDF");
+ item.attachments.push({url:pdflink.href, title:"OSA Journals PDF", mimeType:"application/pdf"});
+ }
+
+ if (abstractblock) {
+ //Zotero.debug("Adding ABSTRACT");
+ item.abstractNote = abstractblock.getAttribute('content');
+ }
+
item.complete();
});
translator.translate();