/** * Convert a string to a JSON Object or JSON Array. */ @Functions.Expose(prefix = "osx", names = {"parseJson"}) public static Object parseJson(String text) { if ((text == null) || "".equals(text)) { return null; } try { if (text.startsWith("[")) { return new JSONArray(text); } else { return new JSONObject(text); } } catch (JSONException je) { throw new ELException(je); } }
/** Register functions for a single Method */ private void addMethod(Method m) { Expose annotation = m.getAnnotation(Expose.class); if (m.isAnnotationPresent(Expose.class)) { String prefix = annotation.prefix(); Map<String, Method> prefixMap = functions.get(prefix); if (prefixMap == null) { prefixMap = Maps.newHashMap(); functions.put(prefix, prefixMap); } for (String methodName : annotation.names()) { Method priorMethod = prefixMap.put(methodName, m); if (priorMethod != null) { throw new IllegalStateException( "Method " + prefix + ':' + methodName + " re-defined."); } } } }
/** * Convert a string to a JSON Object or JSON Array. */ @Functions.Expose(prefix = "osx", names = {"parseJson"}) public static Object parseJson(String text) { if ((text == null) || "".equals(text)) { return null; } try { if (text.startsWith("[")) { return new JSONArray(text); } else { return new JSONObject(text); } } catch (JSONException je) { throw new ELException(je); } }
/** * Convert a string to a JSON Object or JSON Array. */ @Functions.Expose(prefix = "osx", names = {"parseJson"}) public static Object parseJson(String text) { if ((text == null) || "".equals(text)) { return null; } try { if (text.startsWith("[")) { return new JSONArray(text); } else { return new JSONObject(text); } } catch (JSONException je) { throw new ELException(je); } }
/** Register functions for a single Method */ private void addMethod(Method m) { Expose annotation = m.getAnnotation(Expose.class); if (m.isAnnotationPresent(Expose.class)) { String prefix = annotation.prefix(); Map<String, Method> prefixMap = functions.get(prefix); if (prefixMap == null) { prefixMap = Maps.newHashMap(); functions.put(prefix, prefixMap); } for (String methodName : annotation.names()) { Method priorMethod = prefixMap.put(methodName, m); if (priorMethod != null) { throw new IllegalStateException( "Method " + prefix + ':' + methodName + " re-defined."); } } } }
/** * Convert a string to a JSON Object or JSON Array. */ @Functions.Expose(prefix = "osx", names = {"parseJson"}) public static Object parseJson(String text) { if ((text == null) || "".equals(text)) { return null; } try { if (text.startsWith("[")) { return new JSONArray(text); } else { return new JSONObject(text); } } catch (JSONException je) { throw new ELException(je); } }
/** * Decode a base-64 encoded string. */ @Functions.Expose(prefix = "osx", names = {"decodeBase64"}) public static String decodeBase64(String text) { if (text == null) { return null; } try { // TODO: allow a charset to be passed in? return new String(Base64.decodeBase64(text.getBytes("UTF-8")), "UTF-8"); } catch (UnsupportedEncodingException uee) { // UTF-8 will be supported everywhere throw new RuntimeException(uee); } }
/** Register functions for a single Method */ private void addMethod(Method m) { Expose annotation = m.getAnnotation(Expose.class); if (m.isAnnotationPresent(Expose.class)) { String prefix = annotation.prefix(); Map<String, Method> prefixMap = functions.get(prefix); if (prefixMap == null) { prefixMap = Maps.newHashMap(); functions.put(prefix, prefixMap); } for (String methodName : annotation.names()) { Method priorMethod = prefixMap.put(methodName, m); if (priorMethod != null) { throw new IllegalStateException( "Method " + prefix + ':' + methodName + " re-defined."); } } } }
/** Register functions for a single Method */ private void addMethod(Method m) { Expose annotation = m.getAnnotation(Expose.class); if (m.isAnnotationPresent(Expose.class)) { String prefix = annotation.prefix(); Map<String, Method> prefixMap = functions.get(prefix); if (prefixMap == null) { prefixMap = Maps.newHashMap(); functions.put(prefix, prefixMap); } for (String methodName : annotation.names()) { Method priorMethod = prefixMap.put(methodName, m); if (priorMethod != null) { throw new IllegalStateException( "Method " + prefix + ':' + methodName + " re-defined."); } } } }
/** Register functions for a single Method */ private void addMethod(Method m) { Expose annotation = m.getAnnotation(Expose.class); if (m.isAnnotationPresent(Expose.class)) { String prefix = annotation.prefix(); Map<String, Method> prefixMap = functions.get(prefix); if (prefixMap == null) { prefixMap = Maps.newHashMap(); functions.put(prefix, prefixMap); } for (String methodName : annotation.names()) { Method priorMethod = prefixMap.put(methodName, m); if (priorMethod != null) { throw new IllegalStateException( "Method " + prefix + ':' + methodName + " re-defined."); } } } }
/** * Convert a string to a JSON Object or JSON Array. */ @Functions.Expose(prefix = "osx", names = {"parseJson"}) public static Object parseJson(String text) { if ((text == null) || "".equals(text)) { return null; } try { if (text.startsWith("[")) { return new JSONArray(text); } else { return new JSONObject(text); } } catch (JSONException je) { throw new ELException(je); } }
/** * Decode a base-64 encoded string. */ @Functions.Expose(prefix = "osx", names = {"decodeBase64"}) public static String decodeBase64(String text) { if (text == null) { return null; } try { // TODO: allow a charset to be passed in? return new String(Base64.decodeBase64(text.getBytes("UTF-8")), "UTF-8"); } catch (UnsupportedEncodingException uee) { // UTF-8 will be supported everywhere throw new RuntimeException(uee); } }
/** * Form decode a string * @param text * @return */ @Functions.Expose(prefix = "osx", names = {"urlDecode"}) public static String formDecode(String text) { if (text == null) { return null; } return Utf8UrlCoder.decode(text); } }
/** * Unescape HTML entities in a string * @param text * @return */ @Functions.Expose(prefix = "os", names = {"htmlDecode"}) public static String htmlDecode(String text) { if (text == null) { return null; } return StringEscapeUtils.unescapeHtml4(text); } }
/** * Unescape HTML entities in a string * @param text * @return */ @Functions.Expose(prefix = "os", names = {"htmlDecode"}) public static String htmlDecode(String text) { if (text == null) { return null; } return StringEscapeUtils.unescapeHtml4(text); } }
/** * Non-static: shouldn't be exposed. */ @Functions.Expose(prefix="test", names={"goodbye"}) public String sayGoodbye() { return "goodbye"; } }
/** * Form decode a string * @param text * @return */ @Functions.Expose(prefix = "osx", names = {"urlDecode"}) public static String formDecode(String text) { if (text == null) { return null; } return Utf8UrlCoder.decode(text); } }
/** * Unescape HTML entities in a string * @param text * @return */ @Functions.Expose(prefix = "os", names = {"htmlDecode"}) public static String htmlDecode(String text) { if (text == null) { return null; } return StringEscapeUtils.unescapeHtml4(text); } }
/** * Form encode a string */ @Functions.Expose(prefix = "osx", names = {"urlEncode"}) public static String formEncode(String text) { if (text == null) { return null; } return Utf8UrlCoder.encode(text); }
/** * Static function, should be exposed under two names. */ @Functions.Expose(prefix="other", names={"bonjour"}) public static String sayHi2() { return "French hello"; }