diff --git a/deegree-core/deegree-core-commons/src/main/java/org/deegree/commons/i18n/Messages.java b/deegree-core/deegree-core-commons/src/main/java/org/deegree/commons/i18n/Messages.java new file mode 100644 index 0000000000..ab827e5498 --- /dev/null +++ b/deegree-core/deegree-core-commons/src/main/java/org/deegree/commons/i18n/Messages.java @@ -0,0 +1,84 @@ +//$HeadURL$ +/*---------------------------------------------------------------------------- + This file is part of deegree + Copyright (C) 2001-2014 by: + - Department of Geography, University of Bonn - + and + - lat/lon GmbH - + and + - Occam Labs UG (haftungsbeschränkt) - + and others + + This library is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation; either version 2.1 of the License, or (at your option) + any later version. + This library is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + You should have received a copy of the GNU Lesser General Public License + along with this library; if not, write to the Free Software Foundation, Inc., + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Contact information: + + e-mail: info@deegree.org + website: http://www.deegree.org/ +----------------------------------------------------------------------------*/ +package org.deegree.commons.i18n; + +import java.text.MessageFormat; +import java.util.Locale; +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +/** + * Responsible for the access to messages that are visible to the user. + *

+ * Messages are read from the properties file messages_LANG.properties (LANG is always a lowercased ISO 639 + * code), so internationalization is supported. If a certain property (or the property file) for the specific default + * language of the system is not found, the message is taken from messages_en.properties. + * + * @see Locale#getLanguage() + * + * @author Lyn Goltz + * @author last edited by: $Author$ + * + * @version $Revision$, $Date$ + */ +public class Messages { + + private static final ResourceBundle bundle = ResourceBundle.getBundle( "org.deegree.commons.i18n.messages" ); + + /** + * Returns the message assigned to the passed key. If no message is assigned, an error message will be returned that + * indicates the missing key. + * + * @see MessageFormat for conventions on string formatting and escape characters. + * + * @param key + * @param arguments + * @return the message assigned to the passed key + */ + public static String getMessage( String key, Object... arguments ) { + return getMessage( key, arguments ); + } + + /** + * Short version for lazy people. + * + * @param key + * @param arguments + * @return the same as #getMessage + */ + public static String get( String key, Object... arguments ) { + try { + if ( key != null ) + return MessageFormat.format( bundle.getString( key ), arguments ); + } catch ( MissingResourceException e ) { + } + return "$Message with key: " + key + " not found$"; + } + +} \ No newline at end of file diff --git a/deegree-core/deegree-core-commons/src/main/java/org/deegree/commons/tom/Reference.java b/deegree-core/deegree-core-commons/src/main/java/org/deegree/commons/tom/Reference.java index 1f1c8a8888..a79341f76b 100644 --- a/deegree-core/deegree-core-commons/src/main/java/org/deegree/commons/tom/Reference.java +++ b/deegree-core/deegree-core-commons/src/main/java/org/deegree/commons/tom/Reference.java @@ -36,6 +36,8 @@ package org.deegree.commons.tom; +import org.deegree.commons.i18n.Messages; + /** * Represents a lazy reference to an {@link Object}. * @@ -141,8 +143,8 @@ public synchronized T getReferencedObject() throw exception = e; } if ( object == null ) { - String msg = "Unable to resolve reference to '" + uri + "'."; - throw exception = new ReferenceResolvingException( msg ); + String mgs = Messages.get( "RESOLVING_FAILED", uri ); + throw exception = new ReferenceResolvingException( mgs ); } } return object; diff --git a/deegree-core/deegree-core-commons/src/main/resources/org/deegree/commons/i18n/messages.properties b/deegree-core/deegree-core-commons/src/main/resources/org/deegree/commons/i18n/messages.properties new file mode 100644 index 0000000000..3938b9c095 --- /dev/null +++ b/deegree-core/deegree-core-commons/src/main/resources/org/deegree/commons/i18n/messages.properties @@ -0,0 +1,33 @@ +/*---------------------------------------------------------------------------- + This file is part of deegree + Copyright (C) 2001-2014 by: + - Department of Geography, University of Bonn - + and + - lat/lon GmbH - + and + - Occam Labs UG (haftungsbeschränkt) - + and others + + This library is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation; either version 2.1 of the License, or (at your option) + any later version. + This library is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + You should have received a copy of the GNU Lesser General Public License + along with this library; if not, write to the Free Software Foundation, Inc., + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Contact information: + + e-mail: info@deegree.org + website: http://www.deegree.org/ +----------------------------------------------------------------------------*/ +# +# Default language message properties +# +# @see MessageFormat for conventions on string formatting and escape characters. +# +RESOLVING_FAILED=Unable to resolve reference to "{0}". \ No newline at end of file diff --git a/deegree-core/deegree-core-commons/src/main/resources/org/deegree/commons/i18n/messages_de.properties b/deegree-core/deegree-core-commons/src/main/resources/org/deegree/commons/i18n/messages_de.properties new file mode 100644 index 0000000000..bf96883bb7 --- /dev/null +++ b/deegree-core/deegree-core-commons/src/main/resources/org/deegree/commons/i18n/messages_de.properties @@ -0,0 +1,33 @@ +/*---------------------------------------------------------------------------- + This file is part of deegree + Copyright (C) 2001-2014 by: + - Department of Geography, University of Bonn - + and + - lat/lon GmbH - + and + - Occam Labs UG (haftungsbeschränkt) - + and others + + This library is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation; either version 2.1 of the License, or (at your option) + any later version. + This library is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + You should have received a copy of the GNU Lesser General Public License + along with this library; if not, write to the Free Software Foundation, Inc., + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Contact information: + + e-mail: info@deegree.org + website: http://www.deegree.org/ +----------------------------------------------------------------------------*/ +# +# German language message properties +# +# @see MessageFormat for conventions on string formatting and escape characters. +# +RESOLVING_FAILED=Referenz zu "{0}" konnte nicht aufgel\u00F6st werden. \ No newline at end of file diff --git a/deegree-core/deegree-core-commons/src/main/resources/org/deegree/commons/i18n/messages_en.properties b/deegree-core/deegree-core-commons/src/main/resources/org/deegree/commons/i18n/messages_en.properties new file mode 100644 index 0000000000..70c7bda7d0 --- /dev/null +++ b/deegree-core/deegree-core-commons/src/main/resources/org/deegree/commons/i18n/messages_en.properties @@ -0,0 +1,33 @@ +/*---------------------------------------------------------------------------- + This file is part of deegree + Copyright (C) 2001-2014 by: + - Department of Geography, University of Bonn - + and + - lat/lon GmbH - + and + - Occam Labs UG (haftungsbeschränkt) - + and others + + This library is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation; either version 2.1 of the License, or (at your option) + any later version. + This library is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + You should have received a copy of the GNU Lesser General Public License + along with this library; if not, write to the Free Software Foundation, Inc., + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Contact information: + + e-mail: info@deegree.org + website: http://www.deegree.org/ +----------------------------------------------------------------------------*/ +# +# English language message properties +# +# @see MessageFormat for conventions on string formatting and escape characters. +# +RESOLVING_FAILED=Unable to resolve reference to "{0}". \ No newline at end of file