2009-10-07 18:28:56 +00:00
|
|
|
{
|
|
|
|
"translatorID":"58ab2618-4a25-4b9b-83a7-80cd0259f896",
|
|
|
|
"translatorType":4,
|
|
|
|
"label":"Gallica",
|
|
|
|
"creator":"Sylvain Machefert",
|
|
|
|
"target":"^http://gallica\\.bnf\\.fr",
|
|
|
|
"minVersion":"1.0.0b3.r1",
|
|
|
|
"maxVersion":"",
|
|
|
|
"priority":100,
|
|
|
|
"inRepository":true,
|
2010-03-29 15:01:48 +00:00
|
|
|
"lastUpdated":"2010-02-20 10:40:00"
|
2009-10-07 18:28:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function detectWeb(doc, url) {
|
2010-03-29 15:01:48 +00:00
|
|
|
var namespace = doc.documentElement.namespaceURI;
|
|
|
|
var nsResolver = namespace ? function(prefix) {
|
|
|
|
if (prefix == 'x') return namespace; else return null;
|
|
|
|
} : null;
|
|
|
|
|
|
|
|
var indexSearch = url.toString().indexOf('http://gallica.bnf.fr/Search');
|
|
|
|
var indexArk = url.toString().indexOf('http://gallica.bnf.fr/ark:');
|
|
|
|
var indexSNE = url.toString().indexOf('http://gallica.bnf.fr/VisuSNE');
|
|
|
|
|
|
|
|
if (indexSearch == 0)
|
|
|
|
{
|
|
|
|
var errorXpath = '//div[@class="errorMessage"]';
|
|
|
|
if (elt = doc.evaluate(errorXpath, doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext()) {
|
|
|
|
// We are on a search page result but it can be an empty result page.
|
|
|
|
// Nothing to return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return "multiple";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (indexArk == 0)
|
|
|
|
{
|
|
|
|
var iconxpath = '//div[@class="contenu1"]/img';
|
|
|
|
if (elt = doc.evaluate(iconxpath, doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext())
|
|
|
|
{
|
|
|
|
var icon = elt.getAttribute('src');
|
|
|
|
return getDoctypeGallica(icon);
|
|
|
|
}
|
|
|
|
|
|
|
|
// For some biblio, the icon picture is located in another div ...
|
|
|
|
var iconxpath = '//div[@class="titrePeriodiqueGauche"]/img';
|
|
|
|
if (elt = doc.evaluate(iconxpath, doc, nsResolver,
|
|
|
|
XPathResult.ANY_TYPE, null).iterateNext())
|
|
|
|
{
|
|
|
|
var icon = elt.getAttribute('src');
|
|
|
|
return getDoctypeGallica(icon);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (indexSNE == 0)
|
|
|
|
{
|
|
|
|
return "book";
|
|
|
|
}
|
2009-10-07 18:28:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This function takes the name of the icon, and returns the Zotero item name
|
|
|
|
function getDoctypeGallica(img)
|
|
|
|
{
|
|
|
|
var iconname = img.substring(img.lastIndexOf('/') + 1);
|
|
|
|
|
2010-03-29 15:01:48 +00:00
|
|
|
if (iconname =='livre_a.png')
|
2009-10-07 18:28:56 +00:00
|
|
|
{
|
|
|
|
return "book";
|
|
|
|
}
|
2010-03-29 15:01:48 +00:00
|
|
|
else if (iconname == 'carte.png')
|
2009-10-07 18:28:56 +00:00
|
|
|
{
|
|
|
|
return "map";
|
|
|
|
}
|
2010-03-29 15:01:48 +00:00
|
|
|
else if (iconname == 'images.png')
|
2009-10-07 18:28:56 +00:00
|
|
|
{
|
|
|
|
return "artwork";
|
|
|
|
}
|
2010-03-29 15:01:48 +00:00
|
|
|
else if (iconname == 'docsonore.png')
|
|
|
|
{
|
|
|
|
return "audioRecording";
|
|
|
|
}
|
|
|
|
else if (iconname == 'musiquenotee.png')
|
|
|
|
{
|
|
|
|
// This icon is for Sheet music type. But no Zotero type matches
|
|
|
|
// as of today (2010-02)
|
|
|
|
return "book";
|
|
|
|
}
|
|
|
|
else if ( (iconname == 'picto_type_document1.png') || (iconname == 'perio_vol_ocr.png') )
|
2009-10-07 18:28:56 +00:00
|
|
|
{
|
|
|
|
return "book";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Zotero.debug("Undefined icon : " + iconname);
|
|
|
|
return "book";
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function doWeb(doc, url) {
|
|
|
|
var namespace = doc.documentElement.namespaceURI;
|
|
|
|
var nsResolver = namespace ? function(prefix) {
|
|
|
|
if (prefix == 'x') return namespace; else return null;
|
|
|
|
} : null;
|
|
|
|
|
|
|
|
if (detectWeb(doc, url) == "multiple")
|
|
|
|
{
|
|
|
|
var availableItems = new Array();
|
2010-03-29 15:01:48 +00:00
|
|
|
var xpath = '//div[@class="resultats_line"]';
|
2009-10-07 18:28:56 +00:00
|
|
|
|
|
|
|
var elmts = doc.evaluate(xpath, doc, nsResolver, XPathResult.ANY_TYPE, null);
|
|
|
|
var elmt = elmts.iterateNext();
|
|
|
|
|
|
|
|
var itemsId = new Array();
|
|
|
|
|
2010-03-29 15:01:48 +00:00
|
|
|
var i = 1;
|
2009-10-07 18:28:56 +00:00
|
|
|
do {
|
2010-03-29 15:01:48 +00:00
|
|
|
var id = doc.evaluate('div[@class="resultat_id"]', elmt, nsResolver, XPathResult.ANY_TYPE, null).iterateNext().textContent;
|
|
|
|
var this_result = doc.evaluate('div[@class="resultat_desc"]/div[@class="titre"]/a', elmt, nsResolver, XPathResult.ANY_TYPE, null).iterateNext();
|
|
|
|
availableItems[i] = Zotero.Utilities.cleanTags(this_result.getAttribute('title'));
|
2009-10-07 18:28:56 +00:00
|
|
|
|
|
|
|
i++;
|
|
|
|
} while (elmt = elmts.iterateNext());
|
2010-03-29 15:01:48 +00:00
|
|
|
|
2009-10-07 18:28:56 +00:00
|
|
|
var items = Zotero.selectItems(availableItems);
|
|
|
|
|
|
|
|
for (var i in items) {
|
|
|
|
// All informations are available on search result page. We don't need to query
|
|
|
|
// every subpage with scrape. We'are going to call the special Gallica scrape function
|
2010-03-29 15:01:48 +00:00
|
|
|
// This function (scrapeGallica) is reused in scrape.
|
|
|
|
var fullpath = '//div[@class="resultats_line"][' + i + ']';
|
|
|
|
|
|
|
|
var item_element = doc.evaluate(fullpath, doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext();
|
|
|
|
if (item_element != undefined)
|
|
|
|
{
|
|
|
|
var detail = doc.evaluate('.//div[@class="notice"]', item_element, nsResolver, XPathResult.ANY_TYPE, null).iterateNext();
|
|
|
|
|
2010-10-03 18:54:39 +00:00
|
|
|
var iconType = doc.evaluate('.//span[@class="picto"]/img', item_element, nsResolver, XPathResult.ANY_TYPE, null).iterateNext();
|
2010-03-29 15:01:48 +00:00
|
|
|
var docType = getDoctypeGallica(iconType.getAttribute('src'));
|
|
|
|
|
|
|
|
var docUrl = doc.evaluate('.//div[@class="liens"]/a', item_element, nsResolver, XPathResult.ANY_TYPE, null).iterateNext();
|
|
|
|
docUrl = docUrl.getAttribute("href");
|
|
|
|
|
|
|
|
scrapeGallica(doc, nsResolver, detail, docType, docUrl);
|
|
|
|
}
|
2009-10-07 18:28:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var docType = detectWeb(doc, url);
|
2010-03-29 15:01:48 +00:00
|
|
|
var xpath = '//div[@class="notice"]';
|
2009-10-07 18:28:56 +00:00
|
|
|
var detail = doc.evaluate(xpath, doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext();
|
2010-03-29 15:01:48 +00:00
|
|
|
scrapeGallica(doc, nsResolver, detail, docType, "");
|
2009-10-07 18:28:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-29 15:01:48 +00:00
|
|
|
function scrapeGallica(doc, nsResolver, div, type, direct_url)
|
2009-10-07 18:28:56 +00:00
|
|
|
{
|
|
|
|
var item = new Zotero.Item;
|
|
|
|
item.itemType = type;
|
|
|
|
|
|
|
|
var elmts = doc.evaluate('p', div, nsResolver, XPathResult.ANY_TYPE, null);
|
|
|
|
|
|
|
|
var elmt = elmts.iterateNext();
|
|
|
|
|
|
|
|
do {
|
|
|
|
var text = Zotero.Utilities.trimInternal(elmt.textContent);
|
|
|
|
var contenu = '';
|
|
|
|
if (contenu = text.split(/^(Titre|Title|Título) : /)[2])
|
|
|
|
{
|
|
|
|
item.title = Zotero.Utilities.trimInternal(contenu);
|
|
|
|
}
|
|
|
|
else if ( contenu = text.split(/^(Auteur|Author|Autor) : /)[2])
|
|
|
|
{
|
|
|
|
contenu = contenu.replace(/(See only the results matching this author|Ne voir que les résultats de cet auteur)/, '');
|
|
|
|
if (type == 'artwork')
|
|
|
|
{
|
|
|
|
item.creators.push(Zotero.Utilities.cleanAuthor(contenu, "artist", true));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
item.creators.push(Zotero.Utilities.cleanAuthor(contenu, "author", true));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( contenu = text.split(/^(Publisher|Éditeur|Editor) : /)[2])
|
|
|
|
{
|
|
|
|
item.publisher = Zotero.Utilities.trimInternal(contenu);
|
|
|
|
}
|
|
|
|
else if ( contenu = text.split(/^(Date of publication|Date d'édition|Data de publicação|Fecha de publicación) : /)[2])
|
|
|
|
{
|
|
|
|
item.date = Zotero.Utilities.trimInternal(contenu);
|
|
|
|
}
|
|
|
|
else if ( contenu = text.split(/^(Contributeur|Contributor|Contribuidor) : /)[2])
|
|
|
|
{
|
|
|
|
item.creators.push(Zotero.Utilities.cleanAuthor(contenu, "contributor", true));
|
|
|
|
}
|
|
|
|
else if ( contenu = text.split(/^(Language|Langue|Língua|Idioma) : /)[2])
|
|
|
|
{
|
|
|
|
item.language = Zotero.Utilities.trimInternal(contenu);
|
|
|
|
}
|
|
|
|
else if ( contenu = text.split(/^(Format|Formato) : /)[2])
|
|
|
|
{
|
|
|
|
// This field contains : application/pdf for example.
|
|
|
|
}
|
|
|
|
else if ( contenu = text.split(/^(Copyright|Droits|Direitos) : /)[2])
|
|
|
|
{
|
|
|
|
item.rights = Zotero.Utilities.trimInternal(contenu);
|
|
|
|
}
|
|
|
|
else if (contenu = text.split(/^(Identifier|Identifiant|Senha) : /)[2])
|
|
|
|
{
|
|
|
|
var temp = '';
|
|
|
|
if (temp = contenu.split(/^ISSN /)[1])
|
|
|
|
{
|
|
|
|
item.ISSN = temp;
|
|
|
|
}
|
|
|
|
else if (contenu.match(/^http:\/\//))
|
|
|
|
{
|
|
|
|
// If identifier starts with http it is the url of the document
|
|
|
|
item.url = contenu;
|
|
|
|
}
|
|
|
|
else if (contenu.match(/^ark:/))
|
|
|
|
{
|
|
|
|
item.url = "http://gallica.bnf.fr/" + contenu;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (contenu = text.split(/^(Description|Descrição) : /)[2])
|
|
|
|
{
|
|
|
|
var temp = '';
|
|
|
|
if (temp = contenu.split(/^Variante\(s\) de titre : /)[1])
|
|
|
|
{
|
|
|
|
// Alternative title : no field in zotero ?
|
|
|
|
// Zotero.debug("Titre : " + temp);
|
|
|
|
}
|
|
|
|
else if (temp = contenu.split(/^Collection : /)[1])
|
|
|
|
{
|
|
|
|
item.collection = temp;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Zotero.debug(contenu);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (contenu = text.split(/^(Sujet|Assunto|Tema|Subject) : /)[2])
|
|
|
|
{
|
|
|
|
|
|
|
|
var tagList = contenu.split(/; ?/);
|
|
|
|
for (var tag in tagList)
|
|
|
|
{
|
|
|
|
item.tags.push(Zotero.Utilities.trimInternal(tagList[tag]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} while (elmt = elmts.iterateNext());
|
2010-03-29 15:01:48 +00:00
|
|
|
|
2009-10-07 18:28:56 +00:00
|
|
|
if ( (item.url == "") || (item.url == undefined) )
|
|
|
|
{
|
2010-03-29 15:01:48 +00:00
|
|
|
if (direct_url != "")
|
|
|
|
{
|
|
|
|
item.url = "http://gallica.bnf.fr" + direct_url;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
item.url = doc.location.href;
|
|
|
|
}
|
2009-10-07 18:28:56 +00:00
|
|
|
}
|
|
|
|
item.complete();
|
|
|
|
}
|