Browse Source

Meilleur utilisation saxophone

Loquicom 5 years ago
parent
commit
d0037c8837
1 changed files with 13 additions and 10 deletions
  1. 13 10
      src/coauth/parser/parser.js

+ 13 - 10
src/coauth/parser/parser.js

@@ -1,7 +1,6 @@
 const Saxophone = require('saxophone');
 const file = require('../../file');
 
-const ROOT_TAG = 'dblp';
 const TAGS = [
     'phdthesis',
     'mastersthesis',
@@ -30,6 +29,7 @@ const parser = class Parser {
         this.sax.on('tagopen', this._opentag);
         this.sax.on('tagclose', this._closetag);
         this.sax.on('text', this._text);
+        this.sax.on('finish', this._finish);
     }
 
     parse(callback = null) {
@@ -74,27 +74,24 @@ const parser = class Parser {
         throw err;
     }
 
-    _opentag(node) {
-        if (!instance._inTag && TAGS.indexOf(node.name) !== -1) {
+    _opentag(tag) {
+        if (!instance._inTag && TAGS.indexOf(tag.name) !== -1) {
             instance._inTag = true;
-            instance._tag = node.name;
+            instance._tag = tag.name;
             instance._auth = [];
-        } else if (!instance._isAuth && node.name === 'author') {
+        } else if (!instance._isAuth && tag.name === 'author') {
             instance._isAuth = true;
         }
     }
 
     _closetag(tag) {
-        tag = tag.name;
-        if (tag === ROOT_TAG && instance.callback !== null) {
-            instance.callback(instance.dest);
-        } else if (instance._inTag && instance._tag === tag) {
+        if (instance._inTag && instance._tag === tag.name) {
             instance._inTag = false;
             // On ne garde que les groupes d'auteurs
             if (instance._auth.length > 1) {
                 file.append(instance.dest, JSON.stringify(instance._auth) + '\n');
             }
-        } else if (instance._isAuth && tag === 'author') {
+        } else if (instance._isAuth && tag.name === 'author') {
             instance._isAuth = false;
         }
     }
@@ -105,6 +102,12 @@ const parser = class Parser {
         }
     }
 
+    _finish() {
+        if (instance.callback !== null) {
+            instance.callback(instance.dest);
+        }
+    }
+
 };
 
 module.exports.get = function () {