mitreid-connect
公開メンバ関数 | 限定公開メンバ関数 | 非公開メンバ関数 | 非公開変数類 | 静的非公開変数類 | 全メンバ一覧
org.mitre.openid.connect.config.JsonMessageSource クラス
org.mitre.openid.connect.config.JsonMessageSource の継承関係図
Inheritance graph
org.mitre.openid.connect.config.JsonMessageSource 連携図
Collaboration graph

公開メンバ関数

Resource getBaseDirectory ()
 
void setBaseDirectory (Resource baseDirectory)
 

限定公開メンバ関数

MessageFormat resolveCode (String code, Locale locale)
 

非公開メンバ関数

String getValue (String code, List< JsonObject > langs)
 
String getValue (String code, JsonObject lang)
 
List< JsonObject > getLanguageMap (Locale locale)
 

非公開変数類

Resource baseDirectory
 
Locale fallbackLocale = new Locale("en")
 
Map< Locale, List< JsonObject > > languageMaps = new HashMap<>()
 
ConfigurationPropertiesBean config
 

静的非公開変数類

static final Logger logger = LoggerFactory.getLogger(JsonMessageSource.class)
 

詳解

著者
jricher

関数詳解

◆ getBaseDirectory()

Resource org.mitre.openid.connect.config.JsonMessageSource.getBaseDirectory ( )
inline
戻り値
the baseDirectory
199  {
200  return baseDirectory;
201  }
Resource baseDirectory
Definition: JsonMessageSource.java:51

◆ getLanguageMap()

List<JsonObject> org.mitre.openid.connect.config.JsonMessageSource.getLanguageMap ( Locale  locale)
inlineprivate
引数
locale
戻り値
159  {
160 
161  if (!languageMaps.containsKey(locale)) {
162  try {
163  List<JsonObject> set = new ArrayList<>();
164  for (String namespace : config.getLanguageNamespaces()) {
165  // full locale string, e.g. "en_US"
166  String filename = locale.getLanguage() + "_" + locale.getCountry() + File.separator + namespace + ".json";
167 
168  Resource r = getBaseDirectory().createRelative(filename);
169 
170  if (!r.exists()) {
171  // fallback to language only
172  logger.debug("Fallback locale to language only.");
173  filename = locale.getLanguage() + File.separator + namespace + ".json";
174  r = getBaseDirectory().createRelative(filename);
175  }
176 
177  logger.info("No locale loaded, trying to load from " + r);
178 
179  JsonParser parser = new JsonParser();
180  JsonObject obj = (JsonObject) parser.parse(new InputStreamReader(r.getInputStream(), "UTF-8"));
181 
182  set.add(obj);
183  }
184  languageMaps.put(locale, set);
185  } catch (JsonIOException | JsonSyntaxException | IOException e) {
186  logger.error("Unable to load locale", e);
187  }
188  }
189 
190  return languageMaps.get(locale);
191 
192 
193 
194  }
ConfigurationPropertiesBean config
Definition: JsonMessageSource.java:58
Map< Locale, List< JsonObject > > languageMaps
Definition: JsonMessageSource.java:55
static final Logger logger
Definition: JsonMessageSource.java:49
List< String > getLanguageNamespaces()
Definition: ConfigurationPropertiesBean.java:203
Resource getBaseDirectory()
Definition: JsonMessageSource.java:199

◆ getValue() [1/2]

String org.mitre.openid.connect.config.JsonMessageSource.getValue ( String  code,
List< JsonObject >  langs 
)
inlineprivate

Get a value from the set of maps, taking the first match in order

引数
code
langs
戻り値
89  {
90  if (langs == null || langs.isEmpty()) {
91  // no language maps, nothing to look up
92  return null;
93  }
94 
95  for (JsonObject lang : langs) {
96  String value = getValue(code, lang);
97  if (value != null) {
98  // short circuit out of here if we find a match, otherwise keep going through the list
99  return value;
100  }
101  }
102 
103  // if we didn't find anything return null
104  return null;
105  }
String getValue(String code, List< JsonObject > langs)
Definition: JsonMessageSource.java:89

◆ getValue() [2/2]

String org.mitre.openid.connect.config.JsonMessageSource.getValue ( String  code,
JsonObject  lang 
)
inlineprivate

Get a value from a single map

引数
code
locale
lang
戻り値
114  {
115 
116  // if there's no language map, nothing to look up
117  if (lang == null) {
118  return null;
119  }
120 
121  JsonElement e = lang;
122 
123  Iterable<String> parts = Splitter.on('.').split(code);
124  Iterator<String> it = parts.iterator();
125 
126  String value = null;
127 
128  while (it.hasNext()) {
129  String p = it.next();
130  if (e.isJsonObject()) {
131  JsonObject o = e.getAsJsonObject();
132  if (o.has(p)) {
133  e = o.get(p); // found the next level
134  if (!it.hasNext()) {
135  // we've reached a leaf, grab it
136  if (e.isJsonPrimitive()) {
137  value = e.getAsString();
138  }
139  }
140  } else {
141  // didn't find it, stop processing
142  break;
143  }
144  } else {
145  // didn't find it, stop processing
146  break;
147  }
148  }
149 
150 
151  return value;
152 
153  }

◆ resolveCode()

MessageFormat org.mitre.openid.connect.config.JsonMessageSource.resolveCode ( String  code,
Locale  locale 
)
inlineprotected
61  {
62 
63  List<JsonObject> langs = getLanguageMap(locale);
64 
65  String value = getValue(code, langs);
66 
67  if (value == null) {
68  // if we haven't found anything, try the default locale
70  value = getValue(code, langs);
71  }
72 
73  if (value == null) {
74  // if it's still null, return null
75  return null;
76  } else {
77  // otherwise format the message
78  return new MessageFormat(value, locale);
79  }
80 
81  }
Locale fallbackLocale
Definition: JsonMessageSource.java:53
List< JsonObject > getLanguageMap(Locale locale)
Definition: JsonMessageSource.java:159
String getValue(String code, List< JsonObject > langs)
Definition: JsonMessageSource.java:89

◆ setBaseDirectory()

void org.mitre.openid.connect.config.JsonMessageSource.setBaseDirectory ( Resource  baseDirectory)
inline
引数
baseDirectorythe baseDirectory to set
206  {
208  }
Resource baseDirectory
Definition: JsonMessageSource.java:51

メンバ詳解

◆ baseDirectory

Resource org.mitre.openid.connect.config.JsonMessageSource.baseDirectory
private

◆ config

ConfigurationPropertiesBean org.mitre.openid.connect.config.JsonMessageSource.config
private

◆ fallbackLocale

Locale org.mitre.openid.connect.config.JsonMessageSource.fallbackLocale = new Locale("en")
private

◆ languageMaps

Map<Locale, List<JsonObject> > org.mitre.openid.connect.config.JsonMessageSource.languageMaps = new HashMap<>()
private

◆ logger

final Logger org.mitre.openid.connect.config.JsonMessageSource.logger = LoggerFactory.getLogger(JsonMessageSource.class)
staticprivate

このクラス詳解は次のファイルから抽出されました: