closes #1043, store EndNote® styles as binary blobs

closes #1046, Provide some indicator of whether style is originally from EndNote
will require that you re-import previously imported styles
This commit is contained in:
Simon Kornblith 2008-06-22 17:16:43 +00:00
parent 4525afddc5
commit ef2ff0a884
6 changed files with 61 additions and 37 deletions

View file

@ -938,15 +938,23 @@ function refreshStylesList(cslID) {
var treerow = document.createElement('treerow');
var titleCell = document.createElement('treecell');
var updatedCell = document.createElement('treecell');
var cslCell = document.createElement('treecell');
var updatedDate = Zotero.Date.formatDate(Zotero.Date.strToDate(styleData[i].updated), true);
treeitem.setAttribute('id', 'zotero-csl-'+styleData[i].cslID);
titleCell.setAttribute('label', styleData[i].title);
updatedCell.setAttribute('label', updatedDate);
// if not EN
if(styleData[i].cslID.length < Zotero.ENConverter.uriPrefix.length ||
styleData[i].cslID.substr(0, Zotero.ENConverter.uriPrefix.length) != Zotero.ENConverter.uriPrefix) {
cslCell.setAttribute('src', 'chrome://zotero/skin/tick.png');
Zotero.debug("ISCSL");
}
treerow.appendChild(titleCell);
treerow.appendChild(updatedCell);
treerow.appendChild(cslCell);
treeitem.appendChild(treerow);
treechildren.appendChild(treeitem);
@ -988,21 +996,11 @@ function addStyle() {
// read the rest of the bytes in the file
read += bStream.readBytes(file.fileSize-6);
// get fallback name and modification date
var fallbackName = file.leafName;
fallbackName = fallbackName.replace(/\.ens$/i, "");
// get name and modification date
var name = file.leafName.replace(/\.ens$/i, "");
var date = new Date(file.lastModifiedTime);
Zotero.debug(file.lastModifiedTime);
Zotero.debug(date);
try {
var enConverter = new Zotero.ENConverter(read, date, fallbackName);
var xml = enConverter.parse();
} catch(e) {
styleImportError();
throw e;
}
var cslID = Zotero.Cite.installStyle(xml.toXMLString());
var cslID = Zotero.Cite.installStyle(read, false, date, name);
} else {
// This _should_ get the right charset for us automatically
var fileURI = Components.classes["@mozilla.org/network/protocol;1?name=file"]
@ -1018,6 +1016,7 @@ function addStyle() {
styleImportError();
throw e;
}
var cslID = Zotero.Cite.installStyle(req.responseText);
}
}

View file

@ -338,6 +338,7 @@ To add a new preference:
<treecols>
<treecol id="styleManager-title" label="&zotero.preferences.styles.styleManager.title;" flex="3"/>
<treecol id="styleManager-updated" label="&zotero.preferences.styles.styleManager.updated;" flex="1"/>
<treecol id="styleManager-csl" label="&zotero.preferences.styles.styleManager.csl;"/>
</treecols>
<treechildren id="styleManager-rows"/>
</tree>

View file

@ -76,6 +76,11 @@ Zotero.Cite = new function() {
if(csl.indexOf("<defaults") != -1) {
_lastCSL = new Zotero.CSL.Compat(csl);
} else {
if(csl.substr(0, 6) == "\x00\x08\xFF\x00\x00\x00") {
// EN style
var enConverter = new Zotero.ENConverter(csl);
csl = enConverter.parse();
}
_lastCSL = new Zotero.CSL(csl);
}
@ -96,12 +101,20 @@ Zotero.Cite = new function() {
/**
* installs a style
**/
function installStyle(cslString, loadURI) {
function installStyle(cslString, loadURI, date, name) {
var error = false;
try {
var xml = new XML(Zotero.CSL.Global.cleanXML(cslString));
if(cslString.substr(0, 6) == "\x00\x08\xFF\x00\x00\x00") {
// EN style
var enConverter = new Zotero.ENConverter(cslString, date, name);
var xml = enConverter.parse();
} else {
// CSL
var xml = new XML(Zotero.CSL.Global.cleanXML(cslString));
}
}
catch (e) {
var error = true;
error = true;
Components.utils.reportError(e);
}
@ -309,7 +322,11 @@ Zotero.Cite.MIMEHandler.StreamListener.prototype.onStopRequest = function(channe
Zotero.CSL = function(csl) {
default xml namespace = "http://purl.org/net/xbiblio/csl"; with ({});
this._csl = new XML(Zotero.CSL.Global.cleanXML(csl));
if(typeof csl != "XML") {
this._csl = new XML(Zotero.CSL.Global.cleanXML(csl));
} else {
this._csl = CSL;
}
// initialize CSL
Zotero.CSL.Global.init();

View file

@ -35,6 +35,9 @@ Zotero.ENConverter = function(styleData, date, fileTitle) {
}
}
// The URI prefix for EN styles
Zotero.ENConverter.uriPrefix = "http://zotero.org/styles/en-converted/";
/**
* Mappings for item types
*
@ -201,31 +204,35 @@ Zotero.ENConverter.seriesCodes = ["\x01", "\x09", "\x0A", "\x0B", "\x15", "\x1D"
**/
Zotero.ENConverter.prototype.parseInfo = function() {
default xml namespace = "http://purl.org/net/xbiblio/csl"; with({});
var guid = "";
for(var i=0; i<16; i++) {
var bite = Math.floor(Math.random() * 255);
if(i == 4 || i == 6 || i == 8 || i == 10) {
guid += "-";
// version
if(i == 6) bite = bite & 0x0f | 0x40;
// variant
if(i == 8) bite = bite & 0x3f | 0x80;
}
var str = bite.toString(16);
guid += str.length == 1 ? '0' + str : str;
}
this.xml.info.id = "urn:uuid:"+guid;
if(this.fileTitle) {
var title = this.fileTitle;
} else {
var title = this.convertFromUTF16(this.findField(this.fields, "\x10")[0].data.replace("\xFB", "", "g"));
if(!title) title = "Untitled Style";
}
if(!title) {
var title = "Untitled Style";
var identifier = "";
for(var i=0; i<16; i++) {
var bite = Math.floor(Math.random() * 255);
if(i == 4 || i == 6 || i == 8 || i == 10) {
identifier += "-";
// version
if(i == 6) bite = bite & 0x0f | 0x40;
// variant
if(i == 8) bite = bite & 0x3f | 0x80;
}
var str = bite.toString(16);
identifier += str.length == 1 ? '0' + str : str;
}
} else {
var identifier = encodeURIComponent(title);
}
this.xml.info.title = title;
this.xml.info.id = Zotero.ENConverter.uriPrefix+identifier;
if(this.date) {
var date = this.date;
@ -1369,6 +1376,5 @@ Zotero.ENConverter.prototype.parse = function() {
this.parseCitation();
this.parseBibliography();
Zotero.debug(this.xml);
return this.xml;
}

View file

@ -64,6 +64,7 @@
<!ENTITY zotero.preferences.styles.styleManager "Style Manager">
<!ENTITY zotero.preferences.styles.styleManager.title "Title">
<!ENTITY zotero.preferences.styles.styleManager.updated "Updated">
<!ENTITY zotero.preferences.styles.styleManager.csl "CSL">
<!ENTITY zotero.preferences.export.getAdditionalStyles "Get additional styles...">
<!ENTITY zotero.preferences.prefpane.keys "Shortcut Keys">

Binary file not shown.

After

Width:  |  Height:  |  Size: 537 B