|
| 1 | +/* |
| 2 | + * jPSXdec: PlayStation 1 Media Decoder/Converter in Java |
| 3 | + * Copyright (C) 2019 Michael Sabin |
| 4 | + * All rights reserved. |
| 5 | + * |
| 6 | + * Redistribution and use of the jPSXdec code or any derivative works are |
| 7 | + * permitted provided that the following conditions are met: |
| 8 | + * |
| 9 | + * * Redistributions may not be sold, nor may they be used in commercial |
| 10 | + * or revenue-generating business activities. |
| 11 | + * |
| 12 | + * * Redistributions that are modified from the original source must |
| 13 | + * include the complete source code, including the source code for all |
| 14 | + * components used by a binary built from the modified sources. However, as |
| 15 | + * a special exception, the source code distributed need not include |
| 16 | + * anything that is normally distributed (in either source or binary form) |
| 17 | + * with the major components (compiler, kernel, and so on) of the operating |
| 18 | + * system on which the executable runs, unless that component itself |
| 19 | + * accompanies the executable. |
| 20 | + * |
| 21 | + * * Redistributions must reproduce the above copyright notice, this list |
| 22 | + * of conditions and the following disclaimer in the documentation and/or |
| 23 | + * other materials provided with the distribution. |
| 24 | + * |
| 25 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS |
| 26 | + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
| 27 | + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
| 28 | + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER |
| 29 | + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 30 | + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 31 | + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 32 | + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 33 | + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 34 | + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 35 | + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 36 | + */ |
| 37 | + |
| 38 | +package jpsxdec.i18n; |
| 39 | + |
| 40 | +import java.text.MessageFormat; |
| 41 | +import java.util.logging.Level; |
| 42 | +import java.util.logging.LogRecord; |
| 43 | +import java.util.logging.Logger; |
| 44 | +import javax.annotation.CheckForNull; |
| 45 | +import javax.annotation.Nonnull; |
| 46 | + |
| 47 | +/** Development localized message. Replace with actual message before release. */ |
| 48 | +public class _PlaceholderMessage implements ILocalizedMessage { |
| 49 | + |
| 50 | + @Nonnull |
| 51 | + private final String _sMessage; |
| 52 | + @CheckForNull |
| 53 | + private final Object[] _aoArguments; |
| 54 | + |
| 55 | + public _PlaceholderMessage(@Nonnull String sMessage, Object ... aoArguments) { |
| 56 | + _sMessage = sMessage; |
| 57 | + _aoArguments = aoArguments; |
| 58 | + } |
| 59 | + |
| 60 | + public _PlaceholderMessage(@Nonnull String sMessage) { |
| 61 | + _sMessage = sMessage; |
| 62 | + _aoArguments = null; |
| 63 | + } |
| 64 | + |
| 65 | + public void logEnglish(@Nonnull Logger log, @Nonnull Level level) { |
| 66 | + logEnglish(log, level, null); |
| 67 | + } |
| 68 | + |
| 69 | + public void logEnglish(@Nonnull Logger log, @Nonnull Level level, @CheckForNull Throwable ex) { |
| 70 | + LogRecord lr = new LogRecord(level, _sMessage); |
| 71 | + lr.setLoggerName(log.getName()); |
| 72 | + if (_aoArguments != null) |
| 73 | + lr.setParameters(_aoArguments); |
| 74 | + if (ex != null) |
| 75 | + lr.setThrown(ex); |
| 76 | + log.log(lr); |
| 77 | + } |
| 78 | + |
| 79 | + public @Nonnull String getEnglishMessage() { |
| 80 | + if (_aoArguments == null) |
| 81 | + return _sMessage; |
| 82 | + else { |
| 83 | + Object[] aoArgCopy = new Object[_aoArguments.length]; |
| 84 | + for (int i = 0; i < _aoArguments.length; i++) { |
| 85 | + Object arg = _aoArguments[i]; |
| 86 | + if (arg instanceof ILocalizedMessage) |
| 87 | + aoArgCopy[i] = ((ILocalizedMessage)arg).getEnglishMessage(); // recursively get all the English |
| 88 | + else |
| 89 | + aoArgCopy[i] = arg; |
| 90 | + } |
| 91 | + |
| 92 | + return MessageFormat.format(_sMessage, aoArgCopy); |
| 93 | + } |
| 94 | + } |
| 95 | + |
| 96 | + public @Nonnull String getLocalizedMessage() { |
| 97 | + return getEnglishMessage(); |
| 98 | + } |
| 99 | + |
| 100 | + @Override |
| 101 | + public String toString() { |
| 102 | + return getLocalizedMessage(); |
| 103 | + } |
| 104 | + |
| 105 | + public boolean equalsIgnoreCase(@Nonnull String s) { |
| 106 | + return _sMessage.equalsIgnoreCase(s); |
| 107 | + } |
| 108 | + |
| 109 | +} |
0 commit comments