KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > calipso > reportgenerator > reportmanager > DefinitionTraslator


1 package com.calipso.reportgenerator.reportmanager;
2
3 import com.calipso.reportgenerator.reportdefinitions.*;
4
5 import java.util.Locale JavaDoc;
6 import java.util.Map JavaDoc;
7 import java.util.Hashtable JavaDoc;
8 import java.io.Serializable JavaDoc;
9
10 /**
11  * Traduce a los distintos lenguajes los string de las definiciones
12  */

13 public class DefinitionTraslator implements Serializable JavaDoc{
14   private ReportDefinition reportDefinition;
15   private ReportSourceDefinition reportSourceDefinition;
16   private ReportView reportView;
17   private Locale JavaDoc locale;
18   private Map JavaDoc localizationMap;
19
20   public DefinitionTraslator(ReportDefinition reportDefinition, Locale JavaDoc locale) {
21     this.reportDefinition = reportDefinition;
22     this.locale = locale;
23   }
24
25   public DefinitionTraslator(ReportSourceDefinition reportSourceDefinition, Locale JavaDoc locale) {
26     this.reportSourceDefinition = reportSourceDefinition;
27     this.locale = locale;
28   }
29
30   public DefinitionTraslator(ReportDefinition reportDefinition, String JavaDoc language, String JavaDoc country) {
31     this.reportDefinition = reportDefinition;
32     this.locale = new Locale JavaDoc(language,country);
33   }
34
35   public DefinitionTraslator(ReportSourceDefinition reportSourceDefinition, String JavaDoc language,String JavaDoc country) {
36     this.reportSourceDefinition = reportSourceDefinition;
37     this.locale = new Locale JavaDoc(language, country);
38   }
39
40   public String JavaDoc traslate(String JavaDoc 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 JavaDoc 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 JavaDoc getLocalizacionMap(ReportSourceDefinition reportSourceDefinition){
70     Localization localization = getLocalizationFromLocale(reportSourceDefinition.getLocalizations());
71     if (localization !=null){
72       return createMapLocazation(localization);
73     }
74     return null;
75   }
76
77   /**
78    * Crea un Map con la lista de los literales para las conversiones
79    * @param localization
80    * @return
81    */

82   private Map JavaDoc createMapLocazation(Localization localization) {
83     Map JavaDoc localeMap= new Hashtable JavaDoc();
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   /**Obtiene el localization para el locale corespondiente
91    *
92    * @param localizations
93    * @return
94    */

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 JavaDoc 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 JavaDoc language, String JavaDoc country) {
120     this.reportView = reportView;
121     this.reportDefinition = reportDefinition;
122     this.locale = new Locale JavaDoc(language,country);
123   }
124
125   public DefinitionTraslator(ReportView reportView, ReportDefinition reportDefinition, Locale JavaDoc locale) {
126     this.reportView = reportView;
127     this.reportDefinition = reportDefinition;
128     this.locale = locale;
129   }
130
131
132 }
133
Popular Tags