| 35 | private static final Json JSON = new Json(); |
| 36 | |
| 37 | public static Event<LogEntry> entryAdded() { |
| 38 | return new Event<>( |
| 39 | "log.entryAdded", |
| 40 | params -> { |
| 41 | String type = (String) params.get("type"); |
| 42 | |
| 43 | Optional<GenericLogEntry> genericLogEntry = Optional.empty(); |
| 44 | Optional<ConsoleLogEntry> consoleLogEntry = Optional.empty(); |
| 45 | Optional<JavascriptLogEntry> javascriptLogEntry = Optional.empty(); |
| 46 | |
| 47 | if (type != null) { |
| 48 | try (StringReader reader = new StringReader(JSON.toJson(params)); |
| 49 | JsonInput input = JSON.newInput(reader)) { |
| 50 | if ("console".equals(type)) { |
| 51 | consoleLogEntry = Optional.ofNullable(input.read(ConsoleLogEntry.class)); |
| 52 | } else if ("javascript".equals(type)) { |
| 53 | javascriptLogEntry = Optional.ofNullable(input.read(JavascriptLogEntry.class)); |
| 54 | } else { |
| 55 | genericLogEntry = Optional.ofNullable(input.read(GenericLogEntry.class)); |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | return new LogEntry(genericLogEntry, consoleLogEntry, javascriptLogEntry); |
| 61 | }); |
| 62 | } |
| 63 | } |