gluu
静的公開メンバ関数 | 静的公開変数類 | 静的非公開変数類 | 全メンバ一覧
org.xdi.oxauth.model.util.Util クラス
org.xdi.oxauth.model.util.Util 連携図
Collaboration graph

静的公開メンバ関数

static ObjectMapper createJsonMapper ()
 
static String asJsonSilently (Object p_object)
 
static String asPrettyJson (Object p_object) throws IOException
 
static String asJson (Object p_object) throws IOException
 
static byte [] getBytes (String p_str) throws UnsupportedEncodingException
 
static List< String > asList (JSONArray p_array) throws JSONException
 
static< T extends LdapEnum > List< T > asEnumList (JSONArray p_array, Class< T > clazz) throws JSONException, NoSuchMethodException, InvocationTargetException, IllegalAccessException
 
static void addToListIfHas (List< String > p_list, JSONObject jsonObj, String p_key) throws JSONException
 
static void addToJSONObjectIfNotNull (JSONObject p_jsonObject, String key, Object value) throws JSONException
 
static void addToJSONObjectIfNotNull (JSONObject p_jsonObject, String key, String[] value) throws JSONException
 
static String asString (List<? extends HasParamName > p_list)
 
static String listAsString (List< String > p_list)
 
static String mapAsString (Map< String, String > p_map) throws JSONException
 
static boolean allNotBlank (String... p_strings)
 
static List< String > splittedStringAsList (String p_string, String p_delimiter)
 
static List< String > jsonArrayStringAsList (String jsonString) throws JSONException
 
static JSONArray listToJsonArray (Collection< String > list)
 
static Map< String, String > jsonObjectArrayStringAsMap (String jsonString) throws JSONException
 
static< T > T firstItem (List< T > items)
 
static boolean isNullOrEmpty (String string)
 
static int parseIntSilently (String intString)
 

静的公開変数類

static final String UTF8_STRING_ENCODING = "UTF-8"
 

静的非公開変数類

static final Logger LOG = Logger.getLogger(Util.class)
 

詳解

著者
Yuriy Zabrovarnyy
Javier Rojas Blum
バージョン
July 18, 2017
著者
Gabin Dongmo 29/03/2013

関数詳解

◆ addToJSONObjectIfNotNull() [1/2]

static void org.xdi.oxauth.model.util.Util.addToJSONObjectIfNotNull ( JSONObject  p_jsonObject,
String  key,
Object  value 
) throws JSONException
inlinestatic
118  {
119  if (p_jsonObject != null && value != null && StringUtils.isNotBlank(key)) {
120  p_jsonObject.put(key, value);
121  }
122  }

◆ addToJSONObjectIfNotNull() [2/2]

static void org.xdi.oxauth.model.util.Util.addToJSONObjectIfNotNull ( JSONObject  p_jsonObject,
String  key,
String []  value 
) throws JSONException
inlinestatic
124  {
125  if (p_jsonObject != null && value != null && StringUtils.isNotBlank(key)) {
126  p_jsonObject.put(key, new JSONArray(Arrays.asList(value)));
127  }
128  }

◆ addToListIfHas()

static void org.xdi.oxauth.model.util.Util.addToListIfHas ( List< String >  p_list,
JSONObject  jsonObj,
String  p_key 
) throws JSONException
inlinestatic
109  {
110  if (jsonObj != null && org.apache.commons.lang.StringUtils.isNotBlank(p_key) && jsonObj.has(p_key)) {
111  JSONArray array = jsonObj.getJSONArray(p_key);
112  if (p_list != null && array != null) {
113  p_list.addAll(asList(array));
114  }
115  }
116  }
static List< String > asList(JSONArray p_array)
Definition: Util.java:81

◆ allNotBlank()

static boolean org.xdi.oxauth.model.util.Util.allNotBlank ( String...  p_strings)
inlinestatic
166  {
167  if (p_strings != null && p_strings.length > 0) {
168  for (String s : p_strings) {
169  if (org.apache.commons.lang.StringUtils.isBlank(s)) {
170  return false;
171  }
172  }
173  return true;
174  }
175  return false;
176  }

◆ asEnumList()

static <T extends LdapEnum> List<T> org.xdi.oxauth.model.util.Util.asEnumList ( JSONArray  p_array,
Class< T >  clazz 
) throws JSONException, NoSuchMethodException, InvocationTargetException, IllegalAccessException
inlinestatic
95  {
96  final List<T> result = new ArrayList<T>();
97  if (p_array != null) {
98  final int length = p_array.length();
99  if (length > 0) {
100  for (int i = 0; i < length; i++) {
101  Method method = clazz.getMethod("getByValue", String.class);
102  result.add((T) method.invoke(null, new Object[]{p_array.getString(i)}));
103  }
104  }
105  }
106  return result;
107  }

◆ asJson()

static String org.xdi.oxauth.model.util.Util.asJson ( Object  p_object) throws IOException
inlinestatic
72  {
73  final ObjectMapper mapper = createJsonMapper().configure(SerializationConfig.Feature.WRAP_ROOT_VALUE, false);
74  return mapper.writeValueAsString(p_object);
75  }
static ObjectMapper createJsonMapper()
Definition: Util.java:46

◆ asJsonSilently()

static String org.xdi.oxauth.model.util.Util.asJsonSilently ( Object  p_object)
inlinestatic
58  {
59  try {
60  return asJson(p_object);
61  } catch (IOException e) {
62  LOG.trace(e.getMessage(), e);
63  return "";
64  }
65  }
static final Logger LOG
Definition: Util.java:42
static String asJson(Object p_object)
Definition: Util.java:72

◆ asList()

static List<String> org.xdi.oxauth.model.util.Util.asList ( JSONArray  p_array) throws JSONException
inlinestatic
81  {
82  final List<String> result = new ArrayList<String>();
83  if (p_array != null) {
84  final int length = p_array.length();
85  if (length > 0) {
86  for (int i = 0; i < length; i++) {
87  result.add(p_array.getString(i));
88  }
89  }
90  }
91  return result;
92  }

◆ asPrettyJson()

static String org.xdi.oxauth.model.util.Util.asPrettyJson ( Object  p_object) throws IOException
inlinestatic
67  {
68  final ObjectMapper mapper = createJsonMapper().configure(SerializationConfig.Feature.WRAP_ROOT_VALUE, false);
69  return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(p_object);
70  }
static ObjectMapper createJsonMapper()
Definition: Util.java:46

◆ asString()

static String org.xdi.oxauth.model.util.Util.asString ( List<? extends HasParamName p_list)
inlinestatic
130  {
131  final StringBuilder sb = new StringBuilder();
132  if (p_list != null && !p_list.isEmpty()) {
133  for (HasParamName p : p_list) {
134  sb.append(" ").append(p.getParamName());
135  }
136  }
137  return sb.toString().trim();
138  }

◆ createJsonMapper()

static ObjectMapper org.xdi.oxauth.model.util.Util.createJsonMapper ( )
inlinestatic
46  {
47  final AnnotationIntrospector jaxb = new JaxbAnnotationIntrospector();
48  final AnnotationIntrospector jackson = new JacksonAnnotationIntrospector();
49 
50  final AnnotationIntrospector pair = new AnnotationIntrospector.Pair(jackson, jaxb);
51 
52  final ObjectMapper mapper = new ObjectMapper();
53  mapper.getDeserializationConfig().withAnnotationIntrospector(pair);
54  mapper.getSerializationConfig().withAnnotationIntrospector(pair);
55  return mapper;
56  }

◆ firstItem()

static <T> T org.xdi.oxauth.model.util.Util.firstItem ( List< T >  items)
inlinestatic
232  {
233  if (items == null) {
234  return null;
235  }
236 
237  Iterator<T> iterator = items.iterator();
238  if (iterator.hasNext()) {
239  return iterator.next();
240  }
241 
242  return null;
243  }

◆ getBytes()

static byte [] org.xdi.oxauth.model.util.Util.getBytes ( String  p_str) throws UnsupportedEncodingException
inlinestatic
77  {
78  return p_str.getBytes(UTF8_STRING_ENCODING);
79  }
static final String UTF8_STRING_ENCODING
Definition: Util.java:44

◆ isNullOrEmpty()

static boolean org.xdi.oxauth.model.util.Util.isNullOrEmpty ( String  string)
inlinestatic
245  {
246  return string == null || string.length() == 0;
247  }

◆ jsonArrayStringAsList()

static List<String> org.xdi.oxauth.model.util.Util.jsonArrayStringAsList ( String  jsonString) throws JSONException
inlinestatic
189  {
190  final List<String> result = new ArrayList<String>();
191  if (StringUtils.isNotBlank(jsonString)) {
192  JSONArray jsonArray = new JSONArray(jsonString);
193 
194  return asList(jsonArray);
195  }
196 
197  return result;
198  }
static List< String > asList(JSONArray p_array)
Definition: Util.java:81

◆ jsonObjectArrayStringAsMap()

static Map<String, String> org.xdi.oxauth.model.util.Util.jsonObjectArrayStringAsMap ( String  jsonString) throws JSONException
inlinestatic
引数
jsonString[{"CustomHeader1":"custom_header_value_1"},.....,{"CustomHeaderN":"custom_header_value_N"}]
戻り値
212  {
213  Map<String, String> result = new HashMap<String, String>();
214 
215  if (!isNullOrEmpty(jsonString)) {
216  JSONArray jsonArray = new JSONArray(jsonString);
217  for (int i = 0; i < jsonArray.length(); i++) {
218  JSONObject jsonObject = jsonArray.getJSONObject(i);
219 
220  Iterator<String> keysIter = jsonObject.keys();
221  while (keysIter.hasNext()) {
222  String key = keysIter.next();
223  String value = jsonObject.getString(key);
224  result.put(key, value);
225  }
226  }
227  }
228 
229  return result;
230  }
static boolean isNullOrEmpty(String string)
Definition: Util.java:245

◆ listAsString()

static String org.xdi.oxauth.model.util.Util.listAsString ( List< String >  p_list)
inlinestatic
140  {
141  StringBuilder param = new StringBuilder();
142  if (p_list != null && !p_list.isEmpty()) {
143  for (String item : p_list) {
144  param.append(" ").append(item);
145  }
146  }
147  return param.toString().trim();
148  }

◆ listToJsonArray()

static JSONArray org.xdi.oxauth.model.util.Util.listToJsonArray ( Collection< String >  list)
inlinestatic
200  {
201  if (list == null) {
202  return new JSONArray();
203  }
204 
205  return new JSONArray(list);
206  }

◆ mapAsString()

static String org.xdi.oxauth.model.util.Util.mapAsString ( Map< String, String >  p_map) throws JSONException
inlinestatic
150  {
151  if (p_map == null || p_map.size() == 0) {
152  return null;
153  }
154 
155  JSONArray jsonArray = new JSONArray();
156  for (String key : p_map.keySet()) {
157  JSONObject jsonObject = new JSONObject();
158  jsonObject.put(key, p_map.get(key));
159 
160  jsonArray.put(jsonObject);
161  }
162 
163  return jsonArray.toString();
164  }

◆ parseIntSilently()

static int org.xdi.oxauth.model.util.Util.parseIntSilently ( String  intString)
inlinestatic
249  {
250  try {
251  return Integer.parseInt(intString);
252  } catch (Exception e) {
253  return -1;
254  }
255  }

◆ splittedStringAsList()

static List<String> org.xdi.oxauth.model.util.Util.splittedStringAsList ( String  p_string,
String  p_delimiter 
)
inlinestatic
178  {
179  final List<String> result = new ArrayList<String>();
180  if (org.apache.commons.lang.StringUtils.isNotBlank(p_string) && org.apache.commons.lang.StringUtils.isNotEmpty(p_delimiter)) {
181  final String[] array = p_string.split(p_delimiter);
182  if (array != null && array.length > 0) {
183  result.addAll(Arrays.asList(array));
184  }
185  }
186  return result;
187  }

メンバ詳解

◆ LOG

final Logger org.xdi.oxauth.model.util.Util.LOG = Logger.getLogger(Util.class)
staticprivate

◆ UTF8_STRING_ENCODING

final String org.xdi.oxauth.model.util.Util.UTF8_STRING_ENCODING = "UTF-8"
static

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