DataPolice.java |
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 private DataPolice() { 39 } 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 if (!reporting) { 53 return; 54 } 55 StringBuilder buf = new StringBuilder(); 56 BookMetaData bmd = book.getBookMetaData(); 57 if (bmd != null) { 58 buf.append(bmd.getInitials()); 59 } 60 if (bmd != null && key != null) { 61 buf.append(':'); 62 } 63 if (key != null) { 64 buf.append(key.getOsisID()); 65 } 66 buf.append(": "); 67 buf.append(message); 68 LOGGER.info(buf.toString()); 69 } 70 71 /** 72 * @return Returns whether to report found problems. 73 */ 74 public static synchronized boolean isReporting() { 75 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 DataPolice.reporting = reporting; 84 } 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 private static final Logger LOGGER = LoggerFactory.getLogger(DataPolice.class); 95 } 96