/* === (DE)SERIALIZATION === */ /// <summary> Read the object from stream.</summary> //UPGRADE_TODO: Class 'java.io.DataInputStream' was converted to 'System.IO.BinaryReader' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioDataInputStream'" public virtual void readExternal(System.IO.BinaryReader dis, PrototypeFactory pf) { fallbackDefaultLocale = ExtUtil.readBool(dis); fallbackDefaultForm = ExtUtil.readBool(dis); localeResources =(OrderedMap < String, List< LocaleDataSource >>) ExtUtil.read(dis, new ExtWrapMap(String. }
//UPGRADE_TODO: Class 'java.io.DataInputStream' was converted to 'System.IO.BinaryReader' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioDataInputStream'" public override void readExternal(System.IO.BinaryReader in_Renamed, PrototypeFactory pf) { if (type != TYPE_SLOW_READ_ONLY) { System.Collections.IDictionary h; long size = ExtUtil.readNumeric(in_Renamed); switch (type) { case (TYPE_NORMAL): //UPGRADE_TODO: Class 'java.util.HashMap' was converted to 'System.Collections.Hashtable' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilHashMap'" h = new System.Collections.Hashtable((int)size); break; case (TYPE_ORDERED): h = new OrderedMap(); break; case (TYPE_SLOW_COMPACT): h = new Map((int)size); break; default: //UPGRADE_TODO: Class 'java.util.HashMap' was converted to 'System.Collections.Hashtable' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilHashMap'" h = new System.Collections.Hashtable((int)size); break; } for (int i = 0; i < size; i++) { System.Object key = ExtUtil.read(in_Renamed, keyType, pf); System.Object elem = ExtUtil.read(in_Renamed, dataType, pf); h[key] = elem; } val = h; } else { int size = ExtUtil.readInt(in_Renamed); System.Object[] k = new System.Object[size]; System.Object[] v = new System.Object[size]; for (int i = 0; i < size; i++) { k[i] = ExtUtil.read(in_Renamed, keyType, pf); v[i] = ExtUtil.read(in_Renamed, dataType, pf); } val = new Map(k, v); } }
/// <summary> Full constructor. /// /// </summary> /// <param name="fallbackDefaultLocale">If true, search the default locale when no translation for a particular text handle /// is found in the current locale. /// </param> /// <param name="fallbackDefaultForm">If true, search the default text form when no translation is available for the /// specified text form ('long', 'short', etc.). Note: form is specified by appending ';[form]' onto the text ID. /// </param> public Localizer(bool fallbackDefaultLocale, bool fallbackDefaultForm) { InitBlock(); stringTree = new PrefixTree(10); localeResources = new OrderedMap < String, List< LocaleDataSource >>(); currentLocaleData = new OrderedMap < String, PrefixTreeNode >(); locales = new List< String >(); defaultLocale = null; currentLocale = null; observers = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10)); this.fallbackDefaultLocale = fallbackDefaultLocale; this.fallbackDefaultForm = fallbackDefaultForm; }
private void parseAndAdd(OrderedMap locale, System.String line, int curline) { //trim whitespace. line = line.Trim(); //clear comments while (line.IndexOf("#") != -1) { line = line.Substring(0, (line.IndexOf("#")) - (0)); } if (line.IndexOf('=') == -1) { // TODO: Invalid line. Empty lines are fine, especially with comments, // but it might be hard to get all of those. if (line.Trim().Equals("")) { //Empty Line } else { System.Console.Out.WriteLine("Invalid line (#" + curline + ") read: " + line); } } else { //Check to see if there's anything after the '=' first. Otherwise there //might be some big problems. if (line.IndexOf('=') != line.Length - 1) { System.String value_Renamed = line.Substring(line.IndexOf('=') + 1, (line.Length) - (line.IndexOf('=') + 1)); locale.put(line.Substring(0, (line.IndexOf('=')) - (0)), value_Renamed); } else { System.Console.Out.WriteLine("Invalid line (#" + curline + ") read: '" + line + "'. No value follows the '='."); } } }
public TableLocaleSource(OrderedMap < String, String > localeData)
/*{ String -> String } */ public TableLocaleSource() { InitBlock(); localeData = new OrderedMap < String, String >(); }
//UPGRADE_TODO: Class 'java.io.DataInputStream' was converted to 'System.IO.BinaryReader' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioDataInputStream'" public virtual void readExternal(System.IO.BinaryReader in_Renamed, PrototypeFactory pf) { localeData =(OrderedMap < String, String >) ExtUtil.read(in, new ExtWrapMap(String. }
void loadTable(OrderedMap < String, PrefixTreeNode > destination, OrderedMap < String, String > source)
/// <summary> Constructs a body of local resources to be the set of Current Locale Data. /// /// After loading, the current locale data will contain definitions for each /// entry defined by the current locale resources, as well as definitions for any /// entry present in the fallback resources but not in those of the current locale. /// /// The procedure to accomplish this set is as follows, with overwritting occuring /// when a collision occurs: /// /// 1. Load all of the in memory definitions for the default locale if fallback is enabled /// 2. For each resource file for the default locale, load each definition if fallback is enabled /// 3. Load all of the in memory definitions for the current locale /// 4. For each resource file for the current locale, load each definition /// </summary> private void loadCurrentLocaleResources() { this.currentLocaleData = getLocaleData(currentLocale); }
private void InitBlock() { for(String key: source.keySet()) { destination.put(key, stringTree.addString(source.get_Renamed(key))); } if (locale == null || !this.locales.contains(locale)) { return null; } stringTree.clear(); //It's very important that any default locale contain the appropriate strings to localize the interface //for any possible language. As such, we'll keep around a table with only the default locale keys to //ensure that there are no localizations which are only present in another locale, which causes ugly //and difficult to trace errors. OrderedMap < String, Boolean > defaultLocaleKeys = new OrderedMap < String, Boolean >(); //This table will be loaded with the default values first (when applicable), and then with any //language specific translations overwriting the existing values. OrderedMap < String, PrefixTreeNode > data = new OrderedMap < String, PrefixTreeNode >(); // If there's a default locale, we load all of its elements into memory first, then allow // the current locale to overwrite any differences between the two. if (fallbackDefaultLocale && defaultLocale != null) { for (int i = 0; i < defaultResources.size(); ++i) { loadTable(data, ((LocaleDataSource) defaultResources.elementAt(i)).getLocalizedText()); } for(String key: data.keySet()) { defaultLocaleKeys.put(key, true); } } for (int i = 0; i < resources.size(); ++i) { loadTable(data, ((LocaleDataSource) resources.elementAt(i)).getLocalizedText()); } //Strings are now immutable stringTree.seal(); //If we're using a default locale, now we want to make sure that it has all of the keys //that the locale we want to use does. Otherwise, the app will crash when we switch to //a locale that doesn't contain the key. if (fallbackDefaultLocale && defaultLocale != null) { System.String missingKeys = ""; int keysmissing = 0; for(String key: data.keySet()) { if (!defaultLocaleKeys.containsKey(key)) { missingKeys += (key + ","); keysmissing++; } } if (keysmissing > 0) { //Is there a good way to localize these exceptions? throw new NoLocalizedTextException("Error loading locale " + locale + ". There were " + keysmissing + " keys which were contained in this locale, but were not " + "properly registered in the default Locale. Any keys which are added to a locale should always " + "be added to the default locale to ensure appropriate functioning.\n" + "The missing translations were for the keys: " + missingKeys, missingKeys, defaultLocale); } } return data; OrderedMap < String, PrefixTreeNode > mapping = getLocaleData(locale); if (mapping == null) throw new UnregisteredLocaleException("Attempted to access an undefined locale."); return mapping; currentLocale = (System.String) ExtUtil.read(dis, new ExtWrapNullable(typeof(System.String)), pf); Locale = currentLocale; }
/// <param name="resourceName">A path to a resource file provided in the current environment /// /// </param> /// <returns> a dictionary of key/value locale pairs from a file in the resource directory /// </returns> private OrderedMap loadLocaleResource(System.String resourceName) { //UPGRADE_ISSUE: Method 'java.lang.Class.getResourceAsStream' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javalangClassgetResourceAsStream_javalangString'" //UPGRADE_ISSUE: Class 'java.lang.System' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javalangSystem'" System.IO.Stream is_Renamed = typeof(System_Renamed).getResourceAsStream(resourceName); // TODO: This might very well fail. Best way to handle? OrderedMap locale = new OrderedMap(); int chunk = 100; System.IO.StreamReader isr; try { //UPGRADE_TODO: Constructor 'java.io.InputStreamReader.InputStreamReader' was converted to 'System.IO.StreamReader' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioInputStreamReaderInputStreamReader_javaioInputStream_javalangString'" isr = new System.IO.StreamReader(is_Renamed, System.Text.Encoding.GetEncoding("UTF-8")); } catch (System.Exception e) { throw new System.SystemException("Failed to load locale resource " + resourceName + ". Is it in the jar?"); } bool done = false; char[] cbuf = new char[chunk]; int offset = 0; int curline = 0; try { System.String line = ""; while (!done) { //UPGRADE_TODO: Method 'java.io.InputStreamReader.read' was converted to 'System.IO.StreamReader.Read' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioInputStreamReaderread_char[]_int_int'" int read = isr.Read(cbuf, offset, chunk - offset); if (read == -1) { done = true; if ((System.Object)line != (System.Object) "") { parseAndAdd(locale, line, curline); } break; } System.String stringchunk = new System.String(cbuf, offset, read); int index = 0; while (index != -1) { //UPGRADE_WARNING: Method 'java.lang.String.indexOf' was converted to 'System.String.IndexOf' which may throw an exception. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1101'" int nindex = stringchunk.IndexOf('\n', index); //UTF-8 often doesn't encode with newline, but with CR, so if we //didn't find one, we'll try that if (nindex == -1) { //UPGRADE_WARNING: Method 'java.lang.String.indexOf' was converted to 'System.String.IndexOf' which may throw an exception. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1101'" nindex = stringchunk.IndexOf('\r', index); } if (nindex == -1) { line += stringchunk.Substring(index); break; } else { line += stringchunk.Substring(index, (nindex) - (index)); //Newline. process our string and start the next one. curline++; parseAndAdd(locale, line, curline); line = ""; } index = nindex + 1; } } } catch (System.IO.IOException e) { // TODO Auto-generated catch block if (e is org.javarosa.core.io.StreamsUtil.DirectionalIOException) { ((org.javarosa.core.io.StreamsUtil.DirectionalIOException)e).printStackTrace(); } else { SupportClass.WriteStackTrace(e, Console.Error); } } finally { try { is_Renamed.Close(); } catch (System.IO.IOException e) { //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" System.Console.Out.WriteLine("Input Stream for resource file " + resourceURI + " failed to close. This will eat up your memory! Fix Problem! [" + e.Message + "]"); if (e is org.javarosa.core.io.StreamsUtil.DirectionalIOException) { ((org.javarosa.core.io.StreamsUtil.DirectionalIOException)e).printStackTrace(); } else { SupportClass.WriteStackTrace(e, Console.Error); } } } return(locale); }
private void InitBlock() { // TODO: This might very well fail. Best way to handle? OrderedMap <String, String> locale = new OrderedMap <String, String>(); int chunk = 100; System.IO.StreamReader isr; isr = new InputStreamReader(is_Renamed, "UTF-8"); bool done = false; char[] cbuf = new char[chunk]; int offset = 0; int curline = 0; System.String line = ""; while (!done) { //UPGRADE_TODO: Method 'java.io.InputStreamReader.read' was converted to 'System.IO.StreamReader.Read' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioInputStreamReaderread_char[]_int_int'" int read = isr.Read(cbuf, offset, chunk - offset); if (read == -1) { done = true; if ((System.Object)line != (System.Object) "") { parseAndAdd(locale, line, curline); } break; } System.String stringchunk = new System.String(cbuf, offset, read); int index = 0; while (index != -1) { //UPGRADE_WARNING: Method 'java.lang.String.indexOf' was converted to 'System.String.IndexOf' which may throw an exception. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1101'" int nindex = stringchunk.IndexOf('\n', index); //UTF-8 often doesn't encode with newline, but with CR, so if we //didn't find one, we'll try that if (nindex == -1) { //UPGRADE_WARNING: Method 'java.lang.String.indexOf' was converted to 'System.String.IndexOf' which may throw an exception. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1101'" nindex = stringchunk.IndexOf('\r', index); } if (nindex == -1) { line += stringchunk.Substring(index); break; } else { line += stringchunk.Substring(index, (nindex) - (index)); //Newline. process our string and start the next one. curline++; parseAndAdd(locale, line, curline); line = ""; } index = nindex + 1; } } is_Renamed.close(); return(locale); //trim whitespace. line = line.Trim(); //clear comments while (line.IndexOf("#") != -1) { line = line.Substring(0, (line.IndexOf("#")) - (0)); } if (line.IndexOf('=') == -1) { // TODO: Invalid line. Empty lines are fine, especially with comments, // but it might be hard to get all of those. if (line.Trim().Equals("")) { //Empty Line } else { System.Console.Out.WriteLine("Invalid line (#" + curline + ") read: " + line); } } else { //Check to see if there's anything after the '=' first. Otherwise there //might be some big problems. if (line.IndexOf('=') != line.Length - 1) { System.String value_Renamed = line.Substring(line.IndexOf('=') + 1, (line.Length) - (line.IndexOf('=') + 1)); locale.put(line.Substring(0, (line.IndexOf('=')) - (0)), value_Renamed); } else { System.Console.Out.WriteLine("Invalid line (#" + curline + ") read: '" + line + "'. No value follows the '='."); } } }
void parseAndAdd(OrderedMap <String, String> locale, String line, int curline)