[DEV] update log interface
This commit is contained in:
parent
1201bf804a
commit
25f149357b
@ -73,6 +73,36 @@ public class Exml {
|
|||||||
// return iGenerate(_data, 0);
|
// return iGenerate(_data, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static XmlElement parse(final Path data) throws ExmlException, ExmlParserErrorMulti {
|
||||||
|
final Builder builder = new BuilderGeneric();
|
||||||
|
final ParseXml parser = new ParseXml(builder);
|
||||||
|
final ParsingProperty property = new ParsingProperty();
|
||||||
|
property.setDisplayError(true);
|
||||||
|
byte[] elemData = null;
|
||||||
|
try {
|
||||||
|
elemData = Files.readAllBytes(data);
|
||||||
|
} catch (final IOException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
if (elemData == null) {
|
||||||
|
Log.error("Can not read the Stream : " + data);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
final String dataToParse = new String(elemData);
|
||||||
|
return (XmlElement) parser.parse(dataToParse, property);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> T[] parse(final Path path, final Class<T> classType, final String rootNodeName) throws ExmlException, ExmlParserErrorMulti {
|
||||||
|
String content = null;
|
||||||
|
try {
|
||||||
|
content = Exml.readFile(path, StandardCharsets.UTF_8);
|
||||||
|
} catch (final IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return Exml.parse(content, classType, rootNodeName);
|
||||||
|
}
|
||||||
|
|
||||||
public static XmlElement parse(final String data) throws ExmlException, ExmlParserErrorMulti {
|
public static XmlElement parse(final String data) throws ExmlException, ExmlParserErrorMulti {
|
||||||
final Builder builder = new BuilderGeneric();
|
final Builder builder = new BuilderGeneric();
|
||||||
final ParseXml parser = new ParseXml(builder);
|
final ParseXml parser = new ParseXml(builder);
|
||||||
@ -81,7 +111,6 @@ public class Exml {
|
|||||||
return (XmlElement) parser.parse(data, property);
|
return (XmlElement) parser.parse(data, property);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static <T> T[] parse(final String data, final Class<T> classType, final String rootNodeName) throws ExmlException, ExmlParserErrorMulti {
|
public static <T> T[] parse(final String data, final Class<T> classType, final String rootNodeName) throws ExmlException, ExmlParserErrorMulti {
|
||||||
Builder builder;
|
Builder builder;
|
||||||
@ -104,44 +133,6 @@ public class Exml {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> T parseOne(final String data, final Class<T> classType, final String rootNodeName) throws ExmlException, ExmlParserErrorMulti {
|
|
||||||
T[] elements = Exml.parse(data, classType, rootNodeName);
|
|
||||||
if (elements == null || elements.length == 0 ) {
|
|
||||||
throw new ExmlBuilderException("Error in parsing the file, no node find ...");
|
|
||||||
}
|
|
||||||
if (elements.length > 1 ) {
|
|
||||||
throw new ExmlBuilderException("Error in parsing the file, More than One node find ...");
|
|
||||||
}
|
|
||||||
return elements[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String readFile(final Path path, final Charset encoding) throws IOException
|
|
||||||
{
|
|
||||||
byte[] encoded = Files.readAllBytes(path);
|
|
||||||
return new String(encoded, encoding);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T> T[] parse(final Path path, final Class<T> classType, final String rootNodeName) throws ExmlException, ExmlParserErrorMulti {
|
|
||||||
String content = null;
|
|
||||||
try {
|
|
||||||
content = Exml.readFile(path, StandardCharsets.UTF_8);
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return Exml.parse(content, classType, rootNodeName);
|
|
||||||
}
|
|
||||||
public static <T> T parseOne(final Path path, final Class<T> classType, final String rootNodeName) throws ExmlException, ExmlParserErrorMulti {
|
|
||||||
T[] elements = Exml.parse(path, classType, rootNodeName);
|
|
||||||
if (elements == null || elements.length == 0 ) {
|
|
||||||
throw new ExmlBuilderException("Error in parsing the file, no node find ...");
|
|
||||||
}
|
|
||||||
if (elements.length > 1 ) {
|
|
||||||
throw new ExmlBuilderException("Error in parsing the file, More than One node find ...");
|
|
||||||
}
|
|
||||||
return elements[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load the file that might contain the xml
|
* Load the file that might contain the xml
|
||||||
*
|
*
|
||||||
@ -169,31 +160,43 @@ public class Exml {
|
|||||||
final byte[] elemData = Uri.getAllData(data);
|
final byte[] elemData = Uri.getAllData(data);
|
||||||
if (elemData == null) {
|
if (elemData == null) {
|
||||||
Log.error("Can not read the Stream : " + data);
|
Log.error("Can not read the Stream : " + data);
|
||||||
Log.displayBackTrace();
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
final String dataToParse = new String(elemData);
|
final String dataToParse = new String(elemData);
|
||||||
return (XmlElement) parser.parse(dataToParse, property);
|
return (XmlElement) parser.parse(dataToParse, property);
|
||||||
}
|
}
|
||||||
public static XmlElement parse(final Path data) throws ExmlException, ExmlParserErrorMulti {
|
|
||||||
final Builder builder = new BuilderGeneric();
|
public static <T> T parseOne(final Path path, final Class<T> classType, final String rootNodeName) throws ExmlException, ExmlParserErrorMulti {
|
||||||
final ParseXml parser = new ParseXml(builder);
|
final T[] elements = Exml.parse(path, classType, rootNodeName);
|
||||||
final ParsingProperty property = new ParsingProperty();
|
if (elements == null || elements.length == 0) {
|
||||||
property.setDisplayError(true);
|
throw new ExmlBuilderException("Error in parsing the file, no node find ...");
|
||||||
byte[] elemData = null;
|
|
||||||
try {
|
|
||||||
elemData = Files.readAllBytes(data);
|
|
||||||
} catch (IOException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
if (elemData == null) {
|
if (elements.length > 1) {
|
||||||
Log.error("Can not read the Stream : " + data);
|
throw new ExmlBuilderException("Error in parsing the file, More than One node find ...");
|
||||||
Log.displayBackTrace();
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
final String dataToParse = new String(elemData);
|
return elements[0];
|
||||||
return (XmlElement) parser.parse(dataToParse, property);
|
}
|
||||||
|
|
||||||
|
public static <T> T parseOne(final String data, final Class<T> classType, final String rootNodeName) throws ExmlException, ExmlParserErrorMulti {
|
||||||
|
final T[] elements = Exml.parse(data, classType, rootNodeName);
|
||||||
|
if (elements == null || elements.length == 0) {
|
||||||
|
throw new ExmlBuilderException("Error in parsing the file, no node find ...");
|
||||||
|
}
|
||||||
|
if (elements.length > 1) {
|
||||||
|
throw new ExmlBuilderException("Error in parsing the file, More than One node find ...");
|
||||||
|
}
|
||||||
|
return elements[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String readFile(final Path path, final Charset encoding) throws IOException {
|
||||||
|
final byte[] encoded = Files.readAllBytes(path);
|
||||||
|
return new String(encoded, encoding);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void store(final Path path, final Object root, final String rootNodeName) throws ExmlException, IOException {
|
||||||
|
final StringBuilder builder = new StringBuilder();
|
||||||
|
Exml.generate(root, rootNodeName, builder);
|
||||||
|
Files.writeString(path, builder.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -204,16 +207,11 @@ public class Exml {
|
|||||||
* @return true : Parsing is OK
|
* @return true : Parsing is OK
|
||||||
*/
|
*/
|
||||||
public static void store(final Uri uri, final Object root, final String rootNodeName) throws ExmlException, IOException {
|
public static void store(final Uri uri, final Object root, final String rootNodeName) throws ExmlException, IOException {
|
||||||
StringBuilder builder = new StringBuilder();
|
final StringBuilder builder = new StringBuilder();
|
||||||
Exml.generate(root, rootNodeName, builder);
|
Exml.generate(root, rootNodeName, builder);
|
||||||
Uri.writeAll(uri, builder.toString());
|
Uri.writeAll(uri, builder.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void store(final Path path, final Object root, final String rootNodeName) throws ExmlException, IOException {
|
|
||||||
StringBuilder builder = new StringBuilder();
|
|
||||||
Exml.generate(root, rootNodeName, builder);
|
|
||||||
Files.writeString(path, builder.toString());
|
|
||||||
}
|
|
||||||
/*
|
/*
|
||||||
* public boolean store( Uri _uri){ String createData; if (generate(createData)
|
* public boolean store( Uri _uri){ String createData; if (generate(createData)
|
||||||
* == false) { Log.error("Error while creating the XML: " + _uri); return false;
|
* == false) { Log.error("Error while creating the XML: " + _uri); return false;
|
||||||
|
@ -9,7 +9,7 @@ import io.scenarium.logger.LogLevel;
|
|||||||
import io.scenarium.logger.Logger;
|
import io.scenarium.logger.Logger;
|
||||||
|
|
||||||
public class Log {
|
public class Log {
|
||||||
private static final boolean FORCE = false;
|
private static final boolean FORCE_ALL = false;
|
||||||
private static final String LIB_NAME = "exml";
|
private static final String LIB_NAME = "exml";
|
||||||
private static final String LIB_NAME_DRAW = Logger.getDrawableName(Log.LIB_NAME);
|
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_CRITICAL = Logger.getNeedPrint(Log.LIB_NAME, LogLevel.CRITICAL);
|
||||||
@ -21,56 +21,58 @@ public class Log {
|
|||||||
private static final boolean PRINT_VERBOSE = Logger.getNeedPrint(Log.LIB_NAME, LogLevel.VERBOSE);
|
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);
|
private static final boolean PRINT_WARNING = Logger.getNeedPrint(Log.LIB_NAME, LogLevel.WARNING);
|
||||||
|
|
||||||
public static void critical(final String data) {
|
public static void critical(final Exception e, final String data) {
|
||||||
if (Log.PRINT_CRITICAL || Log.FORCE) {
|
e.printStackTrace();
|
||||||
Logger.critical(Log.LIB_NAME_DRAW, data);
|
if (PRINT_CRITICAL || FORCE_ALL) {
|
||||||
|
Logger.critical(LIB_NAME_DRAW, data + " : " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void debug(final String data) {
|
public static void critical(final String data, final Object... objects) {
|
||||||
if (Log.PRINT_DEBUG || Log.FORCE) {
|
if (PRINT_CRITICAL || FORCE_ALL) {
|
||||||
Logger.debug(Log.LIB_NAME_DRAW, data);
|
Logger.critical(LIB_NAME_DRAW, data, objects);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void displayBackTrace() {
|
public static void debug(final String data, final Object... objects) {
|
||||||
// TODO Auto-generated method stub
|
if (PRINT_DEBUG || FORCE_ALL) {
|
||||||
|
Logger.debug(LIB_NAME_DRAW, data, objects);
|
||||||
}
|
|
||||||
|
|
||||||
public static void error(final String data) {
|
|
||||||
if (Log.PRINT_ERROR || Log.FORCE) {
|
|
||||||
Logger.error(Log.LIB_NAME_DRAW, data);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void info(final String data) {
|
public static void error(final String data, final Object... objects) {
|
||||||
if (Log.PRINT_INFO || Log.FORCE) {
|
if (PRINT_ERROR || FORCE_ALL) {
|
||||||
Logger.info(Log.LIB_NAME_DRAW, data);
|
Logger.error(LIB_NAME_DRAW, data, objects);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void print(final String data) {
|
public static void info(final String data, final Object... objects) {
|
||||||
if (Log.PRINT_PRINT || Log.FORCE) {
|
if (PRINT_INFO || FORCE_ALL) {
|
||||||
Logger.print(Log.LIB_NAME_DRAW, data);
|
Logger.info(LIB_NAME_DRAW, data, objects);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void todo(final String data) {
|
public static void print(final String data, final Object... objects) {
|
||||||
if (Log.PRINT_TODO || Log.FORCE) {
|
if (PRINT_PRINT || FORCE_ALL) {
|
||||||
Logger.todo(Log.LIB_NAME_DRAW, data);
|
Logger.print(LIB_NAME_DRAW, data, objects);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void verbose(final String data) {
|
public static void todo(final String data, final Object... objects) {
|
||||||
if (Log.PRINT_VERBOSE || Log.FORCE) {
|
if (PRINT_TODO || FORCE_ALL) {
|
||||||
Logger.verbose(Log.LIB_NAME_DRAW, data);
|
Logger.todo(LIB_NAME_DRAW, data, objects);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void warning(final String data) {
|
public static void verbose(final String data, final Object... objects) {
|
||||||
if (Log.PRINT_WARNING || Log.FORCE) {
|
if (PRINT_VERBOSE || FORCE_ALL) {
|
||||||
Logger.warning(Log.LIB_NAME_DRAW, data);
|
Logger.verbose(LIB_NAME_DRAW, data, objects);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void warning(final String data, final Object... objects) {
|
||||||
|
if (PRINT_WARNING || FORCE_ALL) {
|
||||||
|
Logger.warning(LIB_NAME_DRAW, data, objects);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user