| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| DataPolice |
|
| 2.5;2.5 |
| 1 | /** | |
| 2 | * Distribution License: | |
| 3 | * JSword is free software; you can redistribute it and/or modify it under | |
| 4 | * the terms of the GNU Lesser General Public License, version 2.1 or later | |
| 5 | * as published by the Free Software Foundation. This program is distributed | |
| 6 | * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even | |
| 7 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
| 8 | * See the GNU Lesser General Public License for more details. | |
| 9 | * | |
| 10 | * The License is available on the internet at: | |
| 11 | * http://www.gnu.org/copyleft/lgpl.html | |
| 12 | * or by writing to: | |
| 13 | * Free Software Foundation, Inc. | |
| 14 | * 59 Temple Place - Suite 330 | |
| 15 | * Boston, MA 02111-1307, USA | |
| 16 | * | |
| 17 | * © CrossWire Bible Society, 2005 - 2016 | |
| 18 | * | |
| 19 | */ | |
| 20 | package org.crosswire.jsword.book; | |
| 21 | ||
| 22 | import org.crosswire.jsword.passage.Key; | |
| 23 | import org.slf4j.Logger; | |
| 24 | import org.slf4j.LoggerFactory; | |
| 25 | ||
| 26 | /** | |
| 27 | * When we can't convert some source data then the user doesn't really care and | |
| 28 | * just wants it to work, but it would be good to have some way to get the | |
| 29 | * problems fixed, so as a start point we report them through this class. | |
| 30 | * | |
| 31 | * @see gnu.lgpl.License The GNU Lesser General Public License for details. | |
| 32 | * @author Joe Walker | |
| 33 | */ | |
| 34 | public final class DataPolice { | |
| 35 | /** | |
| 36 | * Prevent instantiation | |
| 37 | */ | |
| 38 | 0 | private DataPolice() { |
| 39 | 0 | } |
| 40 | ||
| 41 | /** | |
| 42 | * Report a message against the current book and key. | |
| 43 | * | |
| 44 | * @param book | |
| 45 | * the book against which to report | |
| 46 | * @param key | |
| 47 | * the key against which to report | |
| 48 | * @param message | |
| 49 | * the police report. | |
| 50 | */ | |
| 51 | public static void report(Book book, Key key, String message) { | |
| 52 | 0 | if (!reporting) { |
| 53 | 0 | return; |
| 54 | } | |
| 55 | 0 | StringBuilder buf = new StringBuilder(); |
| 56 | 0 | BookMetaData bmd = book.getBookMetaData(); |
| 57 | 0 | if (bmd != null) { |
| 58 | 0 | buf.append(bmd.getInitials()); |
| 59 | } | |
| 60 | 0 | if (bmd != null && key != null) { |
| 61 | 0 | buf.append(':'); |
| 62 | } | |
| 63 | 0 | if (key != null) { |
| 64 | 0 | buf.append(key.getOsisID()); |
| 65 | } | |
| 66 | 0 | buf.append(": "); |
| 67 | 0 | buf.append(message); |
| 68 | 0 | LOGGER.info(buf.toString()); |
| 69 | 0 | } |
| 70 | ||
| 71 | /** | |
| 72 | * @return Returns whether to report found problems. | |
| 73 | */ | |
| 74 | public static synchronized boolean isReporting() { | |
| 75 | 0 | return reporting; |
| 76 | } | |
| 77 | ||
| 78 | /** | |
| 79 | * @param reporting | |
| 80 | * Turn on reporting of found problems | |
| 81 | */ | |
| 82 | public static synchronized void setReporting(boolean reporting) { | |
| 83 | 0 | DataPolice.reporting = reporting; |
| 84 | 0 | } |
| 85 | ||
| 86 | /** | |
| 87 | * Whether to report problems or not. By default, reporting is off. | |
| 88 | */ | |
| 89 | private static boolean reporting; | |
| 90 | ||
| 91 | /** | |
| 92 | * The log stream | |
| 93 | */ | |
| 94 | 0 | private static final Logger LOGGER = LoggerFactory.getLogger(DataPolice.class); |
| 95 | } |