keycloak
静的公開メンバ関数 | 静的公開変数類 | 静的非公開メンバ関数 | 静的非公開変数類 | 全メンバ一覧
org.keycloak.common.util.StringPropertyReplacer クラス
org.keycloak.common.util.StringPropertyReplacer 連携図
Collaboration graph

静的公開メンバ関数

static String replaceProperties (final String string)
 
static String replaceProperties (final String string, final Properties props)
 

静的公開変数類

static final String NEWLINE = System.getProperty("line.separator", "\n")
 

静的非公開メンバ関数

static String resolveCompositeKey (String key, Properties props)
 

静的非公開変数類

static final String FILE_SEPARATOR = File.separator
 
static final String PATH_SEPARATOR = File.pathSeparator
 
static final String FILE_SEPARATOR_ALIAS = "/"
 
static final String PATH_SEPARATOR_ALIAS = ":"
 
static final int NORMAL = 0
 
static final int SEEN_DOLLAR = 1
 
static final int IN_BRACKET = 2
 

詳解

A utility class for replacing properties in strings.

著者
Jason Dillon
Scott Stark
Claudio Vesco
Adrian Brock
Dimitris Andreadis
バージョン
Revision
2898

関数詳解

◆ replaceProperties() [1/2]

static String org.keycloak.common.util.StringPropertyReplacer.replaceProperties ( final String  string)
inlinestatic

Go through the input string and replace any occurance of ${p} with the System.getProperty(p) value. If there is no such property p defined, then the ${p} reference will remain unchanged.

If the property reference is of the form ${p:v} and there is no such property p, then the default value v will be returned.

If the property reference is of the form ${p1,p2} or ${p1,p2:v} then the primary and the secondary properties will be tried in turn, before returning either the unchanged input, or the default value.

The property ${/} is replaced with System.getProperty("file.separator") value and the property ${:} is replaced with System.getProperty("path.separator").

引数
string- the string with possible ${} references
戻り値
the input string with all property references replaced if any. If there are no valid references the input string will be returned.
74  {
75  return replaceProperties(string, null);
76  }
static String replaceProperties(final String string)
Definition: StringPropertyReplacer.java:73

◆ replaceProperties() [2/2]

static String org.keycloak.common.util.StringPropertyReplacer.replaceProperties ( final String  string,
final Properties  props 
)
inlinestatic

Go through the input string and replace any occurance of ${p} with the props.getProperty(p) value. If there is no such property p defined, then the ${p} reference will remain unchanged.

If the property reference is of the form ${p:v} and there is no such property p, then the default value v will be returned.

If the property reference is of the form ${p1,p2} or ${p1,p2:v} then the primary and the secondary properties will be tried in turn, before returning either the unchanged input, or the default value.

The property ${/} is replaced with System.getProperty("file.separator") value and the property ${:} is replaced with System.getProperty("path.separator").

引数
string- the string with possible ${} references
props- the source for ${x} property ref values, null means use System.getProperty()
戻り値
the input string with all property references replaced if any. If there are no valid references the input string will be returned.
99  {
100  final char[] chars = string.toCharArray();
101  StringBuilder buffer = new StringBuilder();
102  boolean properties = false;
103  int state = NORMAL;
104  int start = 0;
105  for (int i = 0; i < chars.length; ++i)
106  {
107  char c = chars[i];
108 
109  // Dollar sign outside brackets
110  if (c == '$' && state != IN_BRACKET)
111  state = SEEN_DOLLAR;
112 
113  // Open bracket immediatley after dollar
114  else if (c == '{' && state == SEEN_DOLLAR)
115  {
116  buffer.append(string.substring(start, i - 1));
117  state = IN_BRACKET;
118  start = i - 1;
119  }
120 
121  // No open bracket after dollar
122  else if (state == SEEN_DOLLAR)
123  state = NORMAL;
124 
125  // Closed bracket after open bracket
126  else if (c == '}' && state == IN_BRACKET)
127  {
128  // No content
129  if (start + 2 == i)
130  {
131  buffer.append("${}"); // REVIEW: Correct?
132  }
133  else // Collect the system property
134  {
135  String value = null;
136 
137  String key = string.substring(start + 2, i);
138 
139  // check for alias
140  if (FILE_SEPARATOR_ALIAS.equals(key))
141  {
142  value = FILE_SEPARATOR;
143  }
144  else if (PATH_SEPARATOR_ALIAS.equals(key))
145  {
146  value = PATH_SEPARATOR;
147  }
148  else
149  {
150  // check from the properties
151  if (props != null)
152  value = props.getProperty(key);
153  else
154  value = System.getProperty(key);
155 
156  if (value == null)
157  {
158  // Check for a default value ${key:default}
159  int colon = key.indexOf(':');
160  if (colon > 0)
161  {
162  String realKey = key.substring(0, colon);
163  if (props != null)
164  value = props.getProperty(realKey);
165  else
166  value = System.getProperty(realKey);
167 
168  if (value == null)
169  {
170  // Check for a composite key, "key1,key2"
171  value = resolveCompositeKey(realKey, props);
172 
173  // Not a composite key either, use the specified default
174  if (value == null)
175  value = key.substring(colon+1);
176  }
177  }
178  else
179  {
180  // No default, check for a composite key, "key1,key2"
181  value = resolveCompositeKey(key, props);
182  }
183  }
184  }
185 
186  if (value != null)
187  {
188  properties = true;
189  buffer.append(value);
190  }
191  else
192  {
193  buffer.append("${");
194  buffer.append(key);
195  buffer.append('}');
196  }
197 
198  }
199  start = i + 1;
200  state = NORMAL;
201  }
202  }
203 
204  // No properties
205  if (!properties)
206  return string;
207 
208  // Collect the trailing characters
209  if (start != chars.length)
210  buffer.append(string.substring(start, chars.length));
211 
212  // Done
213  return buffer.toString();
214  }
static final String FILE_SEPARATOR
Definition: StringPropertyReplacer.java:38
static final String PATH_SEPARATOR
Definition: StringPropertyReplacer.java:41
static final String PATH_SEPARATOR_ALIAS
Definition: StringPropertyReplacer.java:47
static String resolveCompositeKey(String key, Properties props)
Definition: StringPropertyReplacer.java:227
static final int IN_BRACKET
Definition: StringPropertyReplacer.java:52
static final int NORMAL
Definition: StringPropertyReplacer.java:50
static final String FILE_SEPARATOR_ALIAS
Definition: StringPropertyReplacer.java:44
static final int SEEN_DOLLAR
Definition: StringPropertyReplacer.java:51

◆ resolveCompositeKey()

static String org.keycloak.common.util.StringPropertyReplacer.resolveCompositeKey ( String  key,
Properties  props 
)
inlinestaticprivate

Try to resolve a "key" from the provided properties by checking if it is actually a "key1,key2", in which case try first "key1", then "key2". If all fails, return null.

It also accepts "key1," and ",key2".

引数
keythe key to resolve
propsthe properties to use
戻り値
the resolved key or null
228  {
229  String value = null;
230 
231  // Look for the comma
232  int comma = key.indexOf(',');
233  if (comma > -1)
234  {
235  // If we have a first part, try resolve it
236  if (comma > 0)
237  {
238  // Check the first part
239  String key1 = key.substring(0, comma);
240  if (props != null)
241  value = props.getProperty(key1);
242  else
243  value = System.getProperty(key1);
244  }
245  // Check the second part, if there is one and first lookup failed
246  if (value == null && comma < key.length() - 1)
247  {
248  String key2 = key.substring(comma + 1);
249  if (props != null)
250  value = props.getProperty(key2);
251  else
252  value = System.getProperty(key2);
253  }
254  }
255  // Return whatever we've found or null
256  return value;
257  }

メンバ詳解

◆ FILE_SEPARATOR

final String org.keycloak.common.util.StringPropertyReplacer.FILE_SEPARATOR = File.separator
staticprivate

File separator value

◆ FILE_SEPARATOR_ALIAS

final String org.keycloak.common.util.StringPropertyReplacer.FILE_SEPARATOR_ALIAS = "/"
staticprivate

File separator alias

◆ IN_BRACKET

final int org.keycloak.common.util.StringPropertyReplacer.IN_BRACKET = 2
staticprivate

◆ NEWLINE

final String org.keycloak.common.util.StringPropertyReplacer.NEWLINE = System.getProperty("line.separator", "\n")
static

New line string constant

◆ NORMAL

final int org.keycloak.common.util.StringPropertyReplacer.NORMAL = 0
staticprivate

◆ PATH_SEPARATOR

final String org.keycloak.common.util.StringPropertyReplacer.PATH_SEPARATOR = File.pathSeparator
staticprivate

Path separator value

◆ PATH_SEPARATOR_ALIAS

final String org.keycloak.common.util.StringPropertyReplacer.PATH_SEPARATOR_ALIAS = ":"
staticprivate

Path separator alias

◆ SEEN_DOLLAR

final int org.keycloak.common.util.StringPropertyReplacer.SEEN_DOLLAR = 1
staticprivate

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