Debian Codegraph @

jte-jsp-converter/src/test/java/example/JteContext.java

raw
1 package example;
2
3 import gg.jte.Content;
4
5 import java.util.Collection;
6 import java.util.Map;
7
8 /**
9 * Dummy jte context, how you might use it in your project.
10 * Contains helper methods for a JSP migration
11 */
12 public class JteContext {
13 /**
14 * Taken from org.apache.el.parser.AstEmpty implementation
15 * @param obj the object to check for JSP like emptiness
16 */
17 public static boolean isEmpty(Object obj) {
18 if (obj == null) {
19 return true;
20 } else if (obj instanceof String string) {
21 return string.isEmpty();
22 } else if (obj instanceof Object[] objects) {
23 return objects.length == 0;
24 } else if (obj instanceof Collection<?> collection) {
25 return collection.isEmpty();
26 } else {
27 return obj instanceof Map<?, ?> m && m.isEmpty();
28 }
29 }
30
31 /**
32 * Dummy localization method. Usually {@link gg.jte.support.LocalizationSupport} in a thread local will help you implement this method.
33 * @param key the localization key
34 * @return a localized content
35 */
36 public static Content localize(String key) {
37 return null;
38 }
39
40 /**
41 * Dummy localization method. Usually {@link gg.jte.support.LocalizationSupport} in a thread local will help you implement this method.
42 * @param key the localization key
43 * @param params parameters for
44 */
45 public static Content localize(String key, Object ... params) {
46 return null;
47 }
48 }