diff options
author | Kurt Zenker <kz@openoffice.org> | 2007-05-11 08:11:19 +0000 |
---|---|---|
committer | Kurt Zenker <kz@openoffice.org> | 2007-05-11 08:11:19 +0000 |
commit | 012c8a6ffe39d331126beaca863f6769f0422393 (patch) | |
tree | 79429caaed3244194ef37201171f78ad4934397b /transex3 | |
parent | INTEGRATION: CWS gh13 (1.1.2); FILE ADDED (diff) | |
download | core-012c8a6ffe39d331126beaca863f6769f0422393.tar.gz core-012c8a6ffe39d331126beaca863f6769f0422393.zip |
INTEGRATION: CWS gh13 (1.1.2); FILE ADDED
2007/03/09 14:34:09 gh 1.1.2.1: original version by Christian Schmidt
Diffstat (limited to 'transex3')
-rwxr-xr-x | transex3/java/l10nconv/java/com/sun/star/tooling/languageResolver/LanguageResolver.java | 206 |
1 files changed, 206 insertions, 0 deletions
diff --git a/transex3/java/l10nconv/java/com/sun/star/tooling/languageResolver/LanguageResolver.java b/transex3/java/l10nconv/java/com/sun/star/tooling/languageResolver/LanguageResolver.java new file mode 100755 index 000000000000..9d4ef086ea42 --- /dev/null +++ b/transex3/java/l10nconv/java/com/sun/star/tooling/languageResolver/LanguageResolver.java @@ -0,0 +1,206 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: LanguageResolver.java,v $ + * + * $Revision: 1.2 $ + * + * last change: $Author: kz $ $Date: 2007-05-11 09:11:19 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * 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 + * + ************************************************************************/ +/* + * Created on 2005 + * by Christian Schmidt + */ +package com.sun.star.tooling.languageResolver; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.ListIterator; + +/** + * Translate language codes into another format + * between ISO, RFC3066 and numeric + * + * @author Christian Schmidt 2005 + * + */ +public class LanguageResolver { + private final static int ISO =2; + private final static int LANGID =0; + private final static int LANGNAME =1; + private final static int RFC3066 =3; + + ArrayList languages=new ArrayList(); + +// public static void main(String[] args){ +// try { +// LanguageResolver lr=new LanguageResolver(); +// } catch (IOException e) { +// // +// e.printStackTrace(); +// } +// } + + /** + * Create a new Instance of LanguageResolver + * + * @throws IOException + */ + public LanguageResolver() throws IOException{ + String lang = "com/sun/star/tooling/languageResolver/lang.map"; + ClassLoader cl = this.getClass().getClassLoader(); + InputStream in = cl.getResourceAsStream(lang); + BufferedReader languageTable= new BufferedReader(new InputStreamReader(in)); + + String line; + + while((line=(languageTable.readLine()))!=null){ + languages.add(line.split(",")); + } + } + /** + * Get the numeric value of the given ISO Language Code + * + * @param isoCode the ISO Language Code to find + * @return numeric value of the given isoCode + * @throws LanguageResolvingException if the Language ISO Code is not known + */ + public String getNrFromISO(String isoCode) throws LanguageResolvingException{ + if("".equals(isoCode)) return ""; + ListIterator iter=languages.listIterator(); + String[] line=new String[5]; + while(isoCode!="" && iter.hasNext()){ + line=(String[]) iter.next(); + if(line[ISO].equals(isoCode)) return line[LANGID]; + } + throw new LanguageResolvingException("Can not find ISO Code: "+isoCode ); + + } + + /** + * Get the ISO Language Code corresponding with the given Language ID + * + * @param ID the numeric language id to find + * @return the ISO Language Code corresponding with the given Language ID + * @throws LanguageResolvingException if the Language ID is not known + */ + public String getISOfromNr(String ID) throws LanguageResolvingException{ + if("".equals(ID)) return ""; + ListIterator iter=languages.listIterator(); + String[] line=new String[5]; + while(iter.hasNext()){ + line=(String[]) iter.next(); + if(line[LANGID].equals(ID)) return line[ISO]; + } + throw new LanguageResolvingException("Can not find Language Id: "+ID ); + } + + /** + * Get the RFC3066 value of the given ISO Language Code + * + * @param isoCode the ISO Language Code to find + * @return RFC3066 value of the given isoCode + * @throws LanguageResolvingException if the Language ISO Code is not known + */ + public String getRFCFromISO(String isoCode) throws LanguageResolvingException{ + if("".equals(isoCode)) return ""; + ListIterator iter=languages.listIterator(); + String[] line=new String[5]; + while(iter.hasNext()){ + line=(String[]) iter.next(); + if(line[ISO].equals(isoCode)) return line[RFC3066]; + } + throw new LanguageResolvingException("Can not find ISO Code: "+isoCode ); + } + + /** + * Get the ISO Language Code corresponding with the given RFC3066 code + * + * @param RFC RFC3066 language id to find + * @return the ISO Language Code corresponding with the given RFC3066 code + * @throws LanguageResolvingException if the RFC3066 code is not known + */ + public String getISOFromRFC(String RFC) throws LanguageResolvingException{ + if("".equals(RFC)) return ""; + ListIterator iter=languages.listIterator(); + String[] line=new String[5]; + while(iter.hasNext()){ + line=(String[]) iter.next(); + if(line[RFC3066].equals(RFC)) return line[ISO]; + } + throw new LanguageResolvingException("Can not find Language Id: "+RFC ); + } + + + /** + * This Exception is thrown if a Language Identfier is unknown + * + * @author Christian Schmidt 2005 + * + */ + public class LanguageResolvingException extends Exception { + + /** + * + */ + public LanguageResolvingException() { + super(); + // + } + + /** + * @param arg0 + */ + public LanguageResolvingException(String arg0) { + super(arg0); + // + } + + /** + * @param arg0 + * @param arg1 + */ + public LanguageResolvingException(String arg0, Throwable arg1) { + super(arg0, arg1); + // + } + + /** + * @param arg0 + */ + public LanguageResolvingException(Throwable arg0) { + super(arg0); + // + } + + } + +} |