diff --git a/src/org/atriasoft/ejson/Ejson.java b/src/org/atriasoft/ejson/Ejson.java index eb10903..b83ecfa 100644 --- a/src/org/atriasoft/ejson/Ejson.java +++ b/src/org/atriasoft/ejson/Ejson.java @@ -26,7 +26,7 @@ public class Ejson { SerializerJson.serialize(root, tmpp, 0); Log.info("Generated JSON : \n" + tmpp.toString()); } - + /** * Generate a string that contain the created XML * @@ -35,7 +35,7 @@ public class Ejson { public static void generate(final JsonNode root, final StringBuilder data) { SerializerJson.serialize(root, data, 1); } - + public static JsonNode parse(final String data) throws Exception, EjsonBuilderException, EjsonParserErrorMulti { final Builder builder = new BuilderGeneric(); final ParseJson parser = new ParseJson(builder); @@ -43,16 +43,21 @@ public class Ejson { property.setDisplayError(true); return (JsonNode) parser.parse(data, property); } - + public static JsonNode parse(final Uri data) throws Exception, EjsonBuilderException, EjsonParserErrorMulti { final Builder builder = new BuilderGeneric(); final ParseJson parser = new ParseJson(builder); final ParsingProperty property = new ParsingProperty(); property.setDisplayError(true); - Log.critical("not implemented..."); - return (JsonNode) parser.parse("", property); - } - - private Ejson() { + final byte[] elemData = Uri.getAllData(data); + if (elemData == null) { + Log.error("Can not read the Stream : " + data); + Log.displayBackTrace(); + return null; + } + final String dataToParse = new String(elemData); + return (JsonNode) parser.parse(dataToParse, property); } + + private Ejson() {} } diff --git a/src/org/atriasoft/ejson/internal/Log.java b/src/org/atriasoft/ejson/internal/Log.java index b911843..fdd8958 100644 --- a/src/org/atriasoft/ejson/internal/Log.java +++ b/src/org/atriasoft/ejson/internal/Log.java @@ -10,61 +10,72 @@ import io.scenarium.logger.Logger; public class Log { private static final String LIB_NAME = "ejson"; - private static final String LIB_NAME_DRAW = Logger.getDrawableName(LIB_NAME); - private static final boolean PRINT_CRITICAL = Logger.getNeedPrint(LIB_NAME, LogLevel.CRITICAL); - private static final boolean PRINT_ERROR = Logger.getNeedPrint(LIB_NAME, LogLevel.ERROR); - private static final boolean PRINT_WARNING = Logger.getNeedPrint(LIB_NAME, LogLevel.WARNING); - private static final boolean PRINT_INFO = Logger.getNeedPrint(LIB_NAME, LogLevel.INFO); - private static final boolean PRINT_DEBUG = Logger.getNeedPrint(LIB_NAME, LogLevel.DEBUG); - private static final boolean PRINT_VERBOSE = Logger.getNeedPrint(LIB_NAME, LogLevel.VERBOSE); - private static final boolean PRINT_TODO = Logger.getNeedPrint(LIB_NAME, LogLevel.TODO); - private static final boolean PRINT_PRINT = Logger.getNeedPrint(LIB_NAME, LogLevel.PRINT); + private static final String LIB_NAME_DRAW = Logger.getDrawableName(Log.LIB_NAME); + private static final boolean PRINT_CRITICAL = Logger.getNeedPrint(Log.LIB_NAME, LogLevel.CRITICAL); + private static final boolean PRINT_DEBUG = Logger.getNeedPrint(Log.LIB_NAME, LogLevel.DEBUG); + private static final boolean PRINT_ERROR = Logger.getNeedPrint(Log.LIB_NAME, LogLevel.ERROR); + private static final boolean PRINT_INFO = Logger.getNeedPrint(Log.LIB_NAME, LogLevel.INFO); + private static final boolean PRINT_PRINT = Logger.getNeedPrint(Log.LIB_NAME, LogLevel.PRINT); + private static final boolean PRINT_TODO = Logger.getNeedPrint(Log.LIB_NAME, LogLevel.TODO); + private static final boolean PRINT_VERBOSE = Logger.getNeedPrint(Log.LIB_NAME, LogLevel.VERBOSE); + private static final boolean PRINT_WARNING = Logger.getNeedPrint(Log.LIB_NAME, LogLevel.WARNING); public static void critical(final String data) { - if (PRINT_CRITICAL) { - Logger.critical(LIB_NAME_DRAW, data); + if (Log.PRINT_CRITICAL) { + Logger.critical(Log.LIB_NAME_DRAW, data); + } + } + + public static void critical(final String data, final Exception e) { + e.printStackTrace(); + if (Log.PRINT_CRITICAL) { + Logger.critical(Log.LIB_NAME_DRAW, data + " : " + e.getMessage()); } } public static void debug(final String data) { - if (PRINT_DEBUG) { - Logger.debug(LIB_NAME_DRAW, data); + if (Log.PRINT_DEBUG) { + Logger.debug(Log.LIB_NAME_DRAW, data); } } + public static void displayBackTrace() { + Logger.displayBackTrace(Log.LIB_NAME_DRAW); + } + public static void error(final String data) { - if (PRINT_ERROR) { - Logger.error(LIB_NAME_DRAW, data); + if (Log.PRINT_ERROR) { + Logger.error(Log.LIB_NAME_DRAW, data); } } public static void info(final String data) { - if (PRINT_INFO) { - Logger.info(LIB_NAME_DRAW, data); + if (Log.PRINT_INFO) { + Logger.info(Log.LIB_NAME_DRAW, data); } } public static void print(final String data) { - if (PRINT_PRINT) { - Logger.print(LIB_NAME_DRAW, data); + if (Log.PRINT_PRINT) { + Logger.print(Log.LIB_NAME_DRAW, data); } } public static void todo(final String data) { - if (PRINT_TODO) { - Logger.todo(LIB_NAME_DRAW, data); + if (Log.PRINT_TODO) { + Logger.todo(Log.LIB_NAME_DRAW, data); } } public static void verbose(final String data) { - if (PRINT_VERBOSE) { - Logger.verbose(LIB_NAME_DRAW, data); + if (Log.PRINT_VERBOSE) { + Logger.verbose(Log.LIB_NAME_DRAW, data); } } public static void warning(final String data) { - if (PRINT_WARNING) { - Logger.warning(LIB_NAME_DRAW, data); + if (Log.PRINT_WARNING) { + Logger.warning(Log.LIB_NAME_DRAW, data); } }