From 3e9924d0834e82e223864de8527dd6e7267b5dab Mon Sep 17 00:00:00 2001 From: Marco Zanon Date: Sun, 25 Mar 2012 13:07:49 +0000 Subject: [PATCH] Renamed the 'translation' package to 'text' (and its exceptions accordingly). --- .../{translation => text}/MTranslation.java | 28 ++++++++--------- .../MTranslationException.java | 6 ++-- .../MTranslationFileParsingTextException.java | 31 +++++++++++++++++++ ...TranslationValueNotFoundTextException.java | 31 +++++++++++++++++++ .../MFileParsingTranslationException.java | 31 ------------------- .../MValueNotFoundTranslationException.java | 31 ------------------- 6 files changed, 78 insertions(+), 80 deletions(-) rename src/java/com/marcozanon/macaco/{translation => text}/MTranslation.java (74%) rename src/java/com/marcozanon/macaco/{translation => text}/MTranslationException.java (78%) create mode 100644 src/java/com/marcozanon/macaco/text/MTranslationFileParsingTextException.java create mode 100644 src/java/com/marcozanon/macaco/text/MTranslationValueNotFoundTextException.java delete mode 100644 src/java/com/marcozanon/macaco/translation/MFileParsingTranslationException.java delete mode 100644 src/java/com/marcozanon/macaco/translation/MValueNotFoundTranslationException.java diff --git a/src/java/com/marcozanon/macaco/translation/MTranslation.java b/src/java/com/marcozanon/macaco/text/MTranslation.java similarity index 74% rename from src/java/com/marcozanon/macaco/translation/MTranslation.java rename to src/java/com/marcozanon/macaco/text/MTranslation.java index 9d6d47f..01c0889 100644 --- a/src/java/com/marcozanon/macaco/translation/MTranslation.java +++ b/src/java/com/marcozanon/macaco/text/MTranslation.java @@ -4,7 +4,7 @@ * Released under MIT license (see LICENSE for details). */ -package com.marcozanon.macaco.translation; +package com.marcozanon.macaco.text; import com.marcozanon.macaco.MInformation; import com.marcozanon.macaco.MObject; @@ -24,7 +24,7 @@ public class MTranslation extends MObject { /* */ - public MTranslation(String file, String language) throws MFileParsingTranslationException { + public MTranslation(String file, String language) throws MTranslationFileParsingTextException { super(); // if ((null == language) || ("".equals(language))) { @@ -47,7 +47,7 @@ public class MTranslation extends MObject { return this.messages; } - public void parseFile(String file) throws MFileParsingTranslationException { + public void parseFile(String file) throws MTranslationFileParsingTextException { if ((null == file) || ("".equals(file))) { throw new IllegalArgumentException("Invalid 'file': null or empty."); } @@ -57,7 +57,7 @@ public class MTranslation extends MObject { buffer = new LineNumberReader(new InputStreamReader(new FileInputStream(file), MInformation.TEXT_ENCODING)); } catch (FileNotFoundException exception) { - throw new MFileParsingTranslationException("Could not open file.", exception); + throw new MTranslationFileParsingTextException("Could not open file.", exception); } catch (UnsupportedEncodingException exception) { // cannot happen } @@ -69,7 +69,7 @@ public class MTranslation extends MObject { line = buffer.readLine(); } catch (IOException exception) { - throw new MFileParsingTranslationException("Could not read file.", exception); + throw new MTranslationFileParsingTextException("Could not read file.", exception); } if (null == line) { break; @@ -82,19 +82,19 @@ public class MTranslation extends MObject { else if (null == message) { message = line; if (this.getMessagesReference().containsKey(message)) { - throw new MFileParsingTranslationException(String.format("Invalid line: %s: duplicated message: %s.", buffer.getLineNumber(), message)); + throw new MTranslationFileParsingTextException(String.format("Invalid line: %s: duplicated message: %s.", buffer.getLineNumber(), message)); } this.getMessagesReference().put(message, new LinkedHashMap()); } else { int a = line.indexOf("="); if (-1 == a) { - throw new MFileParsingTranslationException(String.format("Invalid line: %s: string malformed: %s.", buffer.getLineNumber(), line)); + throw new MTranslationFileParsingTextException(String.format("Invalid line: %s: string malformed: %s.", buffer.getLineNumber(), line)); } String language = line.substring(0, a).trim(); String translation = line.substring(a + 1).trim(); if (this.getMessagesReference().get(message).containsKey(language)) { - throw new MFileParsingTranslationException(String.format("Invalid line: %s: duplicated translation for message: %s.", buffer.getLineNumber(), message)); + throw new MTranslationFileParsingTextException(String.format("Invalid line: %s: duplicated translation for message: %s.", buffer.getLineNumber(), message)); } this.getMessagesReference().get(message).put(language, translation); } @@ -104,7 +104,7 @@ public class MTranslation extends MObject { buffer.close(); } catch (IOException exception) { - throw new MFileParsingTranslationException("Could not close file.", exception); + throw new MTranslationFileParsingTextException("Could not close file.", exception); } } @@ -119,16 +119,16 @@ public class MTranslation extends MObject { try { translation = this.getTranslation(message, language, false); } - catch (MValueNotFoundTranslationException exception) { // cannot happen + catch (MTranslationValueNotFoundTextException exception) { // cannot happen } return translation; } - public String getStrictTranslation(String message, String language) throws MValueNotFoundTranslationException { + public String getStrictTranslation(String message, String language) throws MTranslationValueNotFoundTextException { return this.getTranslation(message, language, true); } - protected String getTranslation(String message, String language, boolean strictMode) throws MValueNotFoundTranslationException { + protected String getTranslation(String message, String language, boolean strictMode) throws MTranslationValueNotFoundTextException { if ((null == message) || ("".equals(message))) { throw new IllegalArgumentException("Invalid 'message': null or empty."); } @@ -138,7 +138,7 @@ public class MTranslation extends MObject { // if (!this.getMessagesReference().containsKey(message)) { if (strictMode) { - throw new MValueNotFoundTranslationException(String.format("Invalid 'message': %s: not available.", message)); + throw new MTranslationValueNotFoundTextException(String.format("Invalid 'message': %s: not available.", message)); } return message; } @@ -148,7 +148,7 @@ public class MTranslation extends MObject { LinkedHashMap messageTranslations = this.getMessagesReference().get(message); if (!messageTranslations.containsKey(language)) { if (strictMode) { - throw new MValueNotFoundTranslationException(String.format("Invalid 'language': %s: translation not available for message: %s.", language, message)); + throw new MTranslationValueNotFoundTextException(String.format("Invalid 'language': %s: translation not available for message: %s.", language, message)); } return message; } diff --git a/src/java/com/marcozanon/macaco/translation/MTranslationException.java b/src/java/com/marcozanon/macaco/text/MTranslationException.java similarity index 78% rename from src/java/com/marcozanon/macaco/translation/MTranslationException.java rename to src/java/com/marcozanon/macaco/text/MTranslationException.java index 0d31b03..14ee47d 100644 --- a/src/java/com/marcozanon/macaco/translation/MTranslationException.java +++ b/src/java/com/marcozanon/macaco/text/MTranslationException.java @@ -4,11 +4,9 @@ * Released under MIT license (see LICENSE for details). */ -package com.marcozanon.macaco.translation; +package com.marcozanon.macaco.text; -import com.marcozanon.macaco.MException; - -public abstract class MTranslationException extends MException { +public abstract class MTranslationException extends MTextException { private static final long serialVersionUID = 0L; diff --git a/src/java/com/marcozanon/macaco/text/MTranslationFileParsingTextException.java b/src/java/com/marcozanon/macaco/text/MTranslationFileParsingTextException.java new file mode 100644 index 0000000..5289e75 --- /dev/null +++ b/src/java/com/marcozanon/macaco/text/MTranslationFileParsingTextException.java @@ -0,0 +1,31 @@ +/** + * Macaco + * Copyright (c) 2009-2012 Marco Zanon . + * Released under MIT license (see LICENSE for details). + */ + +package com.marcozanon.macaco.text; + +public class MTranslationFileParsingTextException extends MTranslationException { + + private static final long serialVersionUID = 0L; + + /* */ + + public MTranslationFileParsingTextException() { + super(); + } + + public MTranslationFileParsingTextException(String message) { + super(message); + } + + public MTranslationFileParsingTextException(Throwable error) { + super(error); + } + + public MTranslationFileParsingTextException(String message, Throwable error) { + super(message, error); + } + +} diff --git a/src/java/com/marcozanon/macaco/text/MTranslationValueNotFoundTextException.java b/src/java/com/marcozanon/macaco/text/MTranslationValueNotFoundTextException.java new file mode 100644 index 0000000..0236c50 --- /dev/null +++ b/src/java/com/marcozanon/macaco/text/MTranslationValueNotFoundTextException.java @@ -0,0 +1,31 @@ +/** + * Macaco + * Copyright (c) 2009-2012 Marco Zanon . + * Released under MIT license (see LICENSE for details). + */ + +package com.marcozanon.macaco.text; + +public class MTranslationValueNotFoundTextException extends MTranslationException { + + private static final long serialVersionUID = 0L; + + /* */ + + public MTranslationValueNotFoundTextException() { + super(); + } + + public MTranslationValueNotFoundTextException(String message) { + super(message); + } + + public MTranslationValueNotFoundTextException(Throwable error) { + super(error); + } + + public MTranslationValueNotFoundTextException(String message, Throwable error) { + super(message, error); + } + +} diff --git a/src/java/com/marcozanon/macaco/translation/MFileParsingTranslationException.java b/src/java/com/marcozanon/macaco/translation/MFileParsingTranslationException.java deleted file mode 100644 index 9ff3e99..0000000 --- a/src/java/com/marcozanon/macaco/translation/MFileParsingTranslationException.java +++ /dev/null @@ -1,31 +0,0 @@ -/** - * Macaco - * Copyright (c) 2009-2012 Marco Zanon . - * Released under MIT license (see LICENSE for details). - */ - -package com.marcozanon.macaco.translation; - -public class MFileParsingTranslationException extends MTranslationException { - - private static final long serialVersionUID = 0L; - - /* */ - - public MFileParsingTranslationException() { - super(); - } - - public MFileParsingTranslationException(String message) { - super(message); - } - - public MFileParsingTranslationException(Throwable error) { - super(error); - } - - public MFileParsingTranslationException(String message, Throwable error) { - super(message, error); - } - -} diff --git a/src/java/com/marcozanon/macaco/translation/MValueNotFoundTranslationException.java b/src/java/com/marcozanon/macaco/translation/MValueNotFoundTranslationException.java deleted file mode 100644 index eb572d7..0000000 --- a/src/java/com/marcozanon/macaco/translation/MValueNotFoundTranslationException.java +++ /dev/null @@ -1,31 +0,0 @@ -/** - * Macaco - * Copyright (c) 2009-2012 Marco Zanon . - * Released under MIT license (see LICENSE for details). - */ - -package com.marcozanon.macaco.translation; - -public class MValueNotFoundTranslationException extends MTranslationException { - - private static final long serialVersionUID = 0L; - - /* */ - - public MValueNotFoundTranslationException() { - super(); - } - - public MValueNotFoundTranslationException(String message) { - super(message); - } - - public MValueNotFoundTranslationException(Throwable error) { - super(error); - } - - public MValueNotFoundTranslationException(String message, Throwable error) { - super(message, error); - } - -} -- 2.30.2