1 package com.calipso.reportgenerator.reportmanager; 2 3 import com.calipso.reportgenerator.reportdefinitions.*; 4 5 import java.util.Locale ; 6 import java.util.Map ; 7 import java.util.Hashtable ; 8 import java.io.Serializable ; 9 10 13 public class DefinitionTraslator implements Serializable { 14 private ReportDefinition reportDefinition; 15 private ReportSourceDefinition reportSourceDefinition; 16 private ReportView reportView; 17 private Locale locale; 18 private Map localizationMap; 19 20 public DefinitionTraslator(ReportDefinition reportDefinition, Locale locale) { 21 this.reportDefinition = reportDefinition; 22 this.locale = locale; 23 } 24 25 public DefinitionTraslator(ReportSourceDefinition reportSourceDefinition, Locale locale) { 26 this.reportSourceDefinition = reportSourceDefinition; 27 this.locale = locale; 28 } 29 30 public DefinitionTraslator(ReportDefinition reportDefinition, String language, String country) { 31 this.reportDefinition = reportDefinition; 32 this.locale = new Locale (language,country); 33 } 34 35 public DefinitionTraslator(ReportSourceDefinition reportSourceDefinition, String language,String country) { 36 this.reportSourceDefinition = reportSourceDefinition; 37 this.locale = new Locale (language, country); 38 } 39 40 public String traslate(String value){ 41 if (isMultilanguage() && (localizationMap != null) && (value != null ) && localizationMap.containsKey(value)){ 42 return localizationMap.get(value).toString(); 43 } else { 44 return value; 45 } 46 } 47 48 private boolean isMultilanguage() { 49 if (reportView != null){ 50 return reportDefinition.getMultilanguage(); 51 } else if (reportDefinition != null){ 52 return reportDefinition.getMultilanguage(); 53 } else if (reportSourceDefinition != null){ 54 return reportSourceDefinition.getMultilanguage(); 55 } 56 return false; 57 } 58 59 private Map getLocalizacionMap() { 60 if (localizationMap == null ){ 61 Localization localization = getLocalizationFromLocale(reportDefinition.getLocalizations()); 62 if (localization !=null){ 63 localizationMap = createMapLocazation(localization); 64 } 65 } 66 return localizationMap; 67 } 68 69 private Map getLocalizacionMap(ReportSourceDefinition reportSourceDefinition){ 70 Localization localization = getLocalizationFromLocale(reportSourceDefinition.getLocalizations()); 71 if (localization !=null){ 72 return createMapLocazation(localization); 73 } 74 return null; 75 } 76 77 82 private Map createMapLocazation(Localization localization) { 83 Map localeMap= new Hashtable (); 84 for (int i=0;i<localization.getLiteralsCount();i++){ 85 localeMap.put(localization.getLiterals()[i].getCode(),localization.getLiterals()[i].getValue()); 86 } 87 return localeMap; 88 } 89 90 95 private Localization getLocalizationFromLocale(Localizations localizations) { 96 Localization localization; 97 if (localizations != null){ 98 for (int i=0;i<localizations.getLocalizationCount();i++){ 99 localization = localizations.getLocalization()[i]; 100 if (localization.getLocale().equalsIgnoreCase(locale.toString())){ 101 return localization; 102 }; 103 } 104 } 105 return null; 106 } 107 108 public String getDescription(){ 109 if (reportView != null){ 110 return traslate(reportView.getId()); 111 }else if (reportDefinition != null){ 112 return traslate(reportDefinition.getDescription()); 113 } else if (reportSourceDefinition != null){ 114 return traslate(reportSourceDefinition.getId()); 115 } 116 return ""; 117 } 118 119 public DefinitionTraslator(ReportView reportView, ReportDefinition reportDefinition, String language, String country) { 120 this.reportView = reportView; 121 this.reportDefinition = reportDefinition; 122 this.locale = new Locale (language,country); 123 } 124 125 public DefinitionTraslator(ReportView reportView, ReportDefinition reportDefinition, Locale locale) { 126 this.reportView = reportView; 127 this.reportDefinition = reportDefinition; 128 this.locale = locale; 129 } 130 131 132 } 133 | Popular Tags |