<commit_before>/*
 * TODO: several functions should not work unless we build a fresh item with a template
 * or parsed an item from the api with json content (things that depend on apiObj)
 * There should be a flag to note whether this is the case and throwing on attempts to
 * use these functions when it is not.
 */
Zotero.Item = function(entryEl){
    this.instance = "Zotero.Item";
    this.itemVersion = 0;
    this.itemKey = '';
    this.synced = false;
    this.apiObj = {};
    this.pristine = null;
    this.dataFields = {};
    this.childItemKeys = [];
    this.writeErrors = [];
    this.itemContentTypes = [];
    this.itemContentBlocks = {};
    this.notes = [];
    this.tagstrings = [];
    if(typeof entryEl != 'undefined'){
        this.parseXmlItem(entryEl);
    }
};

Zotero.Item.prototype = new Zotero.Entry();

Zotero.Item.prototype.dump = function(){
    var item = this;
    var dump = item.dumpEntry();
    var dumpProperties = [
        'apiObj',
        'pristine',
        'itemKey',
        'itemVersion',
        'synced',
        'creatorSummary',
        'year',
        'parentItemKey',
        'numChildren'
    ];
    for (var i = 0; i < dumpProperties.length; i++) {
        dump[dumpProperties[i]] = item[dumpProperties[i]];
    }
    //add tagstrings to dump for indexedDB searching purposes
    dump['tagstrings'] = item.tagstrings;
    return dump;
};

Zotero.Item.prototype.loadDump = function(dump){
    var item = this;
    item.loadDumpEntry(dump);
    var dumpProperties = [
        'apiObj',
        'pristine',
        'itemKey',
        'itemVersion',
        'synced',
        'creatorSummary',
        'year',
        'parentItemKey',
        'numChildren'
    ];
    for (var i = 0; i < dumpProperties.length; i++) {
        item[dumpProperties[i]] = dump[dumpProperties[i]];
    }
    //TODO: load secondary data structures
    item.numTags = item.apiObj.tags.length;
    item.initSecondaryData();

    return item;
};

Zotero.Item.prototype.parseXmlItem = function (iel) {
    var item = this;
    item.parseXmlEntry(iel);
    
    //parse entry metadata
    item.itemKey = iel.find("zapi\\:key, key").text();
    item.itemType = iel.find("zapi\\:itemType, itemType").text();
    item.creatorSummary = iel.find("zapi\\:creatorSummary, creatorSummary").text();
    item.year = iel.find("zapi\\:year, year").text();
    item.numChildren = parseInt(iel.find("zapi\\:numChildren, numChildren").text(), 10);
    item.numTags = parseInt(iel.find("zapi\\:numTags, numChildren").text(), 10);
    
    if(isNaN(item.numChildren)){
        item.numChildren = 0;
    }
    
    item.parentItemKey = false;
    
    //parse content block
    var contentEl = iel.children("content");<commit_msg>restore itemType to Item when loading dump<commit_after>/*
 * TODO: several functions should not work unless we build a fresh item with a template
 * or parsed an item from the api with json content (things that depend on apiObj)
 * There should be a flag to note whether this is the case and throwing on attempts to
 * use these functions when it is not.
 */
Zotero.Item = function(entryEl){
    this.instance = "Zotero.Item";
    this.itemVersion = 0;
    this.itemKey = '';
    this.synced = false;
    this.apiObj = {};
    this.pristine = null;
    this.dataFields = {};
    this.childItemKeys = [];
    this.writeErrors = [];
    this.itemContentTypes = [];
    this.itemContentBlocks = {};
    this.notes = [];
    this.tagstrings = [];
    if(typeof entryEl != 'undefined'){
        this.parseXmlItem(entryEl);
    }
};

Zotero.Item.prototype = new Zotero.Entry();

Zotero.Item.prototype.dump = function(){
    var item = this;
    var dump = item.dumpEntry();
    var dumpProperties = [
        'apiObj',
        'pristine',
        'itemKey',
        'itemVersion',
        'synced',
        'creatorSummary',
        'year',
        'parentItemKey',
        'numChildren'
    ];
    for (var i = 0; i < dumpProperties.length; i++) {
        dump[dumpProperties[i]] = item[dumpProperties[i]];
    }
    //add tagstrings to dump for indexedDB searching purposes
    dump['tagstrings'] = item.tagstrings;
    return dump;
};

Zotero.Item.prototype.loadDump = function(dump){
    var item = this;
    item.loadDumpEntry(dump);
    var dumpProperties = [
        'apiObj',
        'pristine',
        'itemKey',
        'itemVersion',
        'synced',
        'creatorSummary',
        'year',
        'parentItemKey',
        'numChildren'
    ];
    for (var i = 0; i < dumpProperties.length; i++) {
        item[dumpProperties[i]] = dump[dumpProperties[i]];
    }
    //TODO: load secondary data structures
    item.numTags = item.apiObj.tags.length;
    item.itemType = item.apiObj.itemType;
    item.initSecondaryData();

    return item;
};

Zotero.Item.prototype.parseXmlItem = function (iel) {
    var item = this;
    item.parseXmlEntry(iel);
    
    //parse entry metadata
    item.itemKey = iel.find("zapi\\:key, key").text();
    item.itemType = iel.find("zapi\\:itemType, itemType").text();
    item.creatorSummary = iel.find("zapi\\:creatorSummary, creatorSummary").text();
    item.year = iel.find("zapi\\:year, year").text();
    item.numChildren = parseInt(iel.find("zapi\\:numChildren, numChildren").text(), 10);
    item.numTags = parseInt(iel.find("zapi\\:numTags, numChildren").text(), 10);
    
    if(isNaN(item.numChildren)){
        item.numChildren = 0;
    }
    
    item.parentItemKey = false;
    
    //parse content block
    var contentEl = iel.children("content");
{'fraction_non_alphanumeric': 0.14203212416531313, 'fraction_numerical': 0.0028875654214040787, 'mean_word_length': 2.658085808580858, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6763621', 'n_tokens_mistral': 1753, 'n_tokens_neox': 1722, 'n_words': 403}