com.adobe.cq.social.scf.HttpStatusTextProvider Maven / Gradle / Ivy
/*************************************************************************
*
* ADOBE CONFIDENTIAL
* __________________
*
* Copyright 2015 Adobe Systems Incorporated
* All Rights Reserved.
*
* NOTICE: All information contained herein is, and remains
* the property of Adobe Systems Incorporated and its suppliers,
* if any. The intellectual and technical concepts contained
* herein are proprietary to Adobe Systems Incorporated and its
* suppliers and are protected by trade secret or copyright law.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from Adobe Systems Incorporated.
**************************************************************************/
package com.adobe.cq.social.scf;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
public class HttpStatusTextProvider {
public static Map statusMap = null;
private static void init() {
if (statusMap != null) {
return;
}
final Map map = new HashMap();
final Field[] field = HttpServletResponse.class.getDeclaredFields();
for (final Field f : field) {
if (f.isSynthetic()) {
continue;
}
final int mods = f.getModifiers();
if (!Modifier.isPublic(mods)) {
continue;
}
if (!Modifier.isFinal(mods)) {
continue;
}
if (!Modifier.isStatic(mods)) {
continue;
}
if (f.getType() == int.class && f.getName().startsWith("SC_")) {
final String name = f.getName().replace("SC_", "").replace("_", " ");
try {
map.put(f.getInt(null), name);
} catch (final IllegalArgumentException e) {
// not possible.
} catch (final IllegalAccessException e) {
// not possible.
}
}
}
statusMap = map;
}
public static String getStatusText(final int statusCode) {
init();
final String result = statusMap.get(statusCode);
if (result != null) {
return result;
}
return "UNKOWN";
}
}