Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhanced ReferenceResolvingException to be multilingual #725

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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.
* <p>
* Messages are read from the properties file <code>messages_LANG.properties</code> (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 <code>messages_en.properties</code>.
*
* @see Locale#getLanguage()
*
* @author <a href="mailto:goltz@lat-lon.de">Lyn Goltz</a>
* @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$";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@

package org.deegree.commons.tom;

import org.deegree.commons.i18n.Messages;

/**
* Represents a lazy reference to an {@link Object}.
*
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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}".
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
@@ -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}".