Revision 26048 branches/v10/extensions/extI18n/src/org/gvsig/i18n/impl/I18nManagerImpl.java
I18nManagerImpl.java | ||
---|---|---|
32 | 32 |
import java.util.jar.*; |
33 | 33 |
import java.util.zip.ZipEntry; |
34 | 34 |
|
35 |
import org.gvsig.i18n.I18nManager; |
|
36 |
import org.gvsig.i18n.Messages; |
|
35 |
import org.gvsig.i18n.*; |
|
37 | 36 |
|
38 | 37 |
import com.iver.andami.Launcher; |
39 | 38 |
import com.iver.andami.PluginServices; |
40 | 39 |
import com.iver.andami.config.generate.AndamiConfig; |
40 |
import com.iver.utiles.StringUtilities; |
|
41 | 41 |
import com.iver.utiles.XMLEntity; |
42 | 42 |
|
43 | 43 |
/** |
... | ... | |
154 | 154 |
.toArray(new Locale[registeredLocales.size()]); |
155 | 155 |
} |
156 | 156 |
|
157 |
public void uninstallLocale(Locale locale) { |
|
157 |
public void uninstallLocale(Locale locale) throws I18nException {
|
|
158 | 158 |
if (getCurrentLocale().equals(locale) || isReferenceLocale(locale)) { |
159 |
// TODO: Exception |
|
160 |
// throw |
|
159 |
throw new UninstallLocaleException(locale); |
|
161 | 160 |
} |
162 | 161 |
|
163 | 162 |
if (registeredLocales.remove(locale)) { |
... | ... | |
248 | 247 |
config.setLocaleVariant(locale.getVariant()); |
249 | 248 |
} |
250 | 249 |
|
251 |
public Locale[] installLocales(File importFile) { |
|
250 |
public Locale[] installLocales(File importFile) throws I18nException {
|
|
252 | 251 |
List importLocales = new ArrayList(); |
253 | 252 |
|
254 | 253 |
try { |
... | ... | |
296 | 295 |
} |
297 | 296 |
} |
298 | 297 |
|
299 |
} catch (FileNotFoundException e) { |
|
300 |
// TODO Auto-generated catch block |
|
301 |
e.printStackTrace(); |
|
302 |
} catch (IOException e) { |
|
303 |
// TODO Auto-generated catch block |
|
304 |
e.printStackTrace(); |
|
298 |
} catch (Exception ex) { |
|
299 |
throw new InstallLocalesException(importFile, ex); |
|
305 | 300 |
} |
306 | 301 |
|
307 | 302 |
return (Locale[]) importLocales |
... | ... | |
309 | 304 |
} |
310 | 305 |
|
311 | 306 |
public void exportLocaleForUpdate(Locale locale, Locale referenceLocale, |
312 |
File exportFile) { |
|
307 |
File exportFile) throws I18nException {
|
|
313 | 308 |
Manifest manifest = new Manifest(); |
314 | 309 |
|
315 | 310 |
// First, add an entry for the locale to update |
... | ... | |
358 | 353 |
ps.close(); |
359 | 354 |
jaros.close(); |
360 | 355 |
fos.close(); |
361 |
} catch (IOException e) { |
|
362 |
// TODO Auto-generated catch block |
|
363 |
e.printStackTrace(); |
|
356 |
} catch (IOException ex) { |
|
357 |
throw new ExportLocaleException(locale, ex); |
|
364 | 358 |
} |
365 | 359 |
} |
366 | 360 |
|
367 | 361 |
public void exportLocaleForTranslation(Locale locale, |
368 |
Locale referenceLocale, File exportFile) { |
|
362 |
Locale referenceLocale, File exportFile) throws I18nException {
|
|
369 | 363 |
Manifest manifest = new Manifest(); |
370 | 364 |
|
371 | 365 |
// First, add an entry for the locale to update |
... | ... | |
412 | 406 |
// bos.close(); |
413 | 407 |
jaros.close(); |
414 | 408 |
fos.close(); |
415 |
} catch (IOException e) { |
|
416 |
// TODO Auto-generated catch block |
|
417 |
e.printStackTrace(); |
|
409 |
} catch (IOException ex) { |
|
410 |
throw new ExportLocaleException(locale, ex); |
|
418 | 411 |
} |
419 | 412 |
} |
420 | 413 |
|
... | ... | |
470 | 463 |
for (Iterator iterator = texts.entrySet().iterator(); iterator |
471 | 464 |
.hasNext();) { |
472 | 465 |
Entry entry = (Entry) iterator.next(); |
473 |
ps.print((String) entry.getKey()); |
|
466 |
String keyEncoded = escape((String) entry.getKey(), true); |
|
467 |
ps.print(keyEncoded); |
|
474 | 468 |
ps.print("="); |
475 | 469 |
if (withValue) { |
476 |
ps.println((String) entry.getValue()); |
|
470 |
String valueEncoded = escape((String) entry.getValue(), false); |
|
471 |
ps.println(valueEncoded); |
|
477 | 472 |
} |
478 | 473 |
else { |
479 | 474 |
ps.println(); |
... | ... | |
627 | 622 |
|
628 | 623 |
getI18nPersistence().addChild(localesEntity); |
629 | 624 |
} |
625 |
|
|
626 |
private String escape(String value, boolean replaceBlanks) { |
|
627 |
// First replace non printable characters |
|
628 |
if (replaceBlanks) { |
|
629 |
value = StringUtilities.replace(value, " ", "\\ "); |
|
630 |
} |
|
631 |
value = StringUtilities.replace(value, ":", "\\:"); |
|
632 |
value = StringUtilities.replace(value, "\n", "\\n"); |
|
633 |
value = StringUtilities.replace(value, "\t", "\\t"); |
|
634 |
value = StringUtilities.replace(value, "\b", "\\b"); |
|
635 |
value = StringUtilities.replace(value, "\f", "\\f"); |
|
636 |
value = StringUtilities.replace(value, "\r", "\\r"); |
|
637 |
// value = StringUtilities.replace(value, "\\", "\\\\"); |
|
638 |
value = StringUtilities.replace(value, "\'", "\\\'"); |
|
639 |
value = StringUtilities.replace(value, "\"", "\\\""); |
|
640 |
|
|
641 |
// Next, encode in raw-unicode-escape |
|
642 |
return toRawUnicodeEncoded(value); |
|
643 |
} |
|
644 |
|
|
645 |
private String toRawUnicodeEncoded(String value) { |
|
646 |
StringBuffer sb = new StringBuffer(); |
|
647 |
for (int i = 0; i < value.length(); i++) { |
|
648 |
char c = value.charAt(i); |
|
649 |
if (c <= 0x80) { |
|
650 |
sb.append(c); |
|
651 |
} |
|
652 |
else { |
|
653 |
sb.append("\\u"); |
|
654 |
String hexValue = Integer.toHexString((int) c); |
|
655 |
// Append 0 if the hex value has less than 4 digits |
|
656 |
for (int j = hexValue.length(); j < 4; j++) { |
|
657 |
sb.append('0'); |
|
658 |
} |
|
659 |
sb.append(hexValue); |
|
660 |
} |
|
661 |
} |
|
662 |
return sb.toString(); |
|
663 |
} |
|
630 | 664 |
} |
Also available in: Unified diff