Warnings

Warnings – Usage of warnings when using Structures_BibTex

Overview

The class Structures_BibTex introduces a system to collect warnings that may happen during parsing. Warnings are things in the BibTex source which are not correct but do not cause the parser to fail. One example would be a double cite entry. These warnings should help to improve the quality of your BibTex code. Whether warnings are generated or not is controlled by the option validate. Per default warnings are generated. If you want to not generate warnings you should use the setOption() method like this.

Switching off creation of warnings

<?php
require_once 'Structures/BibTex.php';
$bibtex = new Structures_BibTex();
$bibtex->setOption('validate'false);
?>

Usage

The warnings are stored in an array called warnings which is public accessible. To check is a warning exists you can use the method hasWarning(). This method returns true if there are warnings and false otherwise.

Checking for warnings

<?php
require_once 'Structures/BibTex.php';
$bibtex = new Structures_BibTex();
$ret    $bibtex->loadFile('foo.bib');
if (
PEAR::isError($ret)) {
    die(
$ret->getMessage());
}
$bibtex->parse();
if (
$bibtex->hasWarning()) {
    print 
'There are warnings!<br />';
}
?>

Every warning itself is hash table with the following keys:

  • warning - Type of the warning

  • entry - The line that caused the warning

  • wholeentry - The whole entry in which the warning occurred

To print every warning with type and line that caused the warning you could do something like this:

Checking for warnings

<?php
require_once 'Structures/BibTex.php';
$bibtex = new Structures_BibTex();
$ret    $bibtex->loadFile('foo.bib');
if (
PEAR::isError($ret)) {
    die(
$ret->getMessage());
}
$bibtex->parse();
if (
$bibtex->hasWarning()) {
    foreach (
$bibtex->warnings as $warning) {
        echo 
'Warning: '.$warning['warning'].'<br />';
        echo 
'Line: '.$warning['entry'].'<hr />';
    }
}
?>

Finally if you want to clear all warnings you can use the method clearWarnings().

Types of Warnings

The following Warnings are known:

  • WARNING_MISSING_END_BRACE - This warning is generated when the end brace in an entry is missing. Take this warning seriously!

  • WARNING_AT_IN_BRACES - A Value is delimited by Braces. Then inside a @ is not allowed.

  • WARNING_ESCAPED_DOUBLE_QUOTE_INSIDE_DOUBLE_QUOTES - A Value is delimited by double quotes. Then inside no escaped double quote is allowed.

  • WARNING_UNBALANCED_AMOUNT_OF_BRACES - The amount of braces inside a value is not equal (opening and closing). The parses fails if in the complete entry this amount is not correct. But if only on an entry it is not correct then this is only a warning. As a matter of fact of the parser does not fail but there is an unbalanced amount of braces in an entry this warning has to be generated something times two.

  • WARNING_MULTIPLE_ENTRIES - Every entry is identified by a unique string. This warning is created if there are at least two entries with the same identification.

  • WARNING_LINE_WAS_NOT_CONVERTED - This warning is created if during exporting (for example in RTF or HTML) one entry was ignored because of no matching data in the entry. At least one of the following entries have to exist in the entry to get converted: title, journal, year or authors.

  • STRING_ENTRY_NOT_YET_SUPPORTED - BibTex defines some special entry types, String is one of them and is used to define abbreviations. This is not yet supported by Structres_BibTex.

  • PREAMBLE_ENTRY_NOT_YET_SUPPORTED - BibTex defines some special entry types, Preamble is one of them and is used to define formatted code. This is not yet supported by Structres_BibTex.

  • WARNING_NOT_ALLOWED_ENTRY_TYPE - BibTex allows to define own types. This warning is genereated when a type was detected which is not part of the standard types. The allowed or standard type are defined in the class variable allowedTypes as array.

Introduction to Structures_BibTex (Previous) Possibility to export the data using Structures_BibTex (Next)
Last updated: Sun, 19 Dec 2010 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report or add a note.
View this page in:

User Notes:

There are no user contributed notes for this page.