[DEV] update log interface

This commit is contained in:
Edouard DUPIN 2022-04-01 00:58:05 +02:00
parent 1201bf804a
commit 25f149357b
2 changed files with 105 additions and 105 deletions

View File

@ -73,6 +73,36 @@ public class Exml {
// 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 {
final Builder builder = new BuilderGeneric();
final ParseXml parser = new ParseXml(builder);
@ -81,7 +111,6 @@ public class Exml {
return (XmlElement) parser.parse(data, property);
}
@SuppressWarnings("unchecked")
public static <T> T[] parse(final String data, final Class<T> classType, final String rootNodeName) throws ExmlException, ExmlParserErrorMulti {
Builder builder;
@ -103,44 +132,6 @@ public class Exml {
throw ex;
}
}
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
@ -148,7 +139,7 @@ public class Exml {
* @param _uri URI of the xml
* @return false : An error occured
* @return true : Parsing is OK
* @throws ExmlException
* @throws ExmlException
*/
/*
* public boolean load( Uri _uri){ // Start loading the XML :
@ -160,7 +151,7 @@ public class Exml {
* the file: fileIo->close(); // parse the data: boolean ret =
* parse(tmpDataUnicode); //Display(); return ret; }
*/
public static XmlElement parse(final Uri data) throws ExmlException {
final Builder builder = new BuilderGeneric();
final ParseXml parser = new ParseXml(builder);
@ -169,31 +160,43 @@ public class Exml {
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 (XmlElement) parser.parse(dataToParse, property);
}
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 (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
public static <T> T parseOne(final Path path, final Class<T> classType, final String rootNodeName) throws ExmlException, ExmlParserErrorMulti {
final 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 (elemData == null) {
Log.error("Can not read the Stream : " + data);
Log.displayBackTrace();
return null;
if (elements.length > 1) {
throw new ExmlBuilderException("Error in parsing the file, More than One node find ...");
}
final String dataToParse = new String(elemData);
return (XmlElement) parser.parse(dataToParse, property);
return elements[0];
}
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,24 +207,19 @@ public class Exml {
* @return true : Parsing is OK
*/
public static void store(final Uri uri, final Object root, final String rootNodeName) throws ExmlException, IOException {
StringBuilder builder = new StringBuilder();
Exml.generate(root, rootNodeName, builder);
final StringBuilder builder = new StringBuilder();
Exml.generate(root, rootNodeName, builder);
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)
* == false) { Log.error("Error while creating the XML: " + _uri); return false;
* } auto fileIo = uri::get(_uri); if (fileIo == null) {
* Log.error("Can not create the uri: " + _uri); return false; } if
* (fileIo->open(io::OpenMode::Write) == false) {
* Log.error("Can not open (r) the file : " + _uri); return false; }
* fileIo->writeAll(createData); fileIo->close(); return true; }
*/
/*
* public boolean store( Uri _uri){ String createData; if (generate(createData)
* == false) { Log.error("Error while creating the XML: " + _uri); return false;
* } auto fileIo = uri::get(_uri); if (fileIo == null) {
* Log.error("Can not create the uri: " + _uri); return false; } if
* (fileIo->open(io::OpenMode::Write) == false) {
* Log.error("Can not open (r) the file : " + _uri); return false; }
* fileIo->writeAll(createData); fileIo->close(); return true; }
*/
private Exml() {}
}

View File

@ -9,7 +9,7 @@ import io.scenarium.logger.LogLevel;
import io.scenarium.logger.Logger;
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_DRAW = Logger.getDrawableName(Log.LIB_NAME);
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_WARNING = Logger.getNeedPrint(Log.LIB_NAME, LogLevel.WARNING);
public static void critical(final String data) {
if (Log.PRINT_CRITICAL || Log.FORCE) {
Logger.critical(Log.LIB_NAME_DRAW, data);
public static void critical(final Exception e, final String data) {
e.printStackTrace();
if (PRINT_CRITICAL || FORCE_ALL) {
Logger.critical(LIB_NAME_DRAW, data + " : " + e.getMessage());
}
}
public static void debug(final String data) {
if (Log.PRINT_DEBUG || Log.FORCE) {
Logger.debug(Log.LIB_NAME_DRAW, data);
public static void critical(final String data, final Object... objects) {
if (PRINT_CRITICAL || FORCE_ALL) {
Logger.critical(LIB_NAME_DRAW, data, objects);
}
}
public static void displayBackTrace() {
// TODO Auto-generated method stub
}
public static void error(final String data) {
if (Log.PRINT_ERROR || Log.FORCE) {
Logger.error(Log.LIB_NAME_DRAW, data);
public static void debug(final String data, final Object... objects) {
if (PRINT_DEBUG || FORCE_ALL) {
Logger.debug(LIB_NAME_DRAW, data, objects);
}
}
public static void info(final String data) {
if (Log.PRINT_INFO || Log.FORCE) {
Logger.info(Log.LIB_NAME_DRAW, data);
public static void error(final String data, final Object... objects) {
if (PRINT_ERROR || FORCE_ALL) {
Logger.error(LIB_NAME_DRAW, data, objects);
}
}
public static void print(final String data) {
if (Log.PRINT_PRINT || Log.FORCE) {
Logger.print(Log.LIB_NAME_DRAW, data);
public static void info(final String data, final Object... objects) {
if (PRINT_INFO || FORCE_ALL) {
Logger.info(LIB_NAME_DRAW, data, objects);
}
}
public static void todo(final String data) {
if (Log.PRINT_TODO || Log.FORCE) {
Logger.todo(Log.LIB_NAME_DRAW, data);
public static void print(final String data, final Object... objects) {
if (PRINT_PRINT || FORCE_ALL) {
Logger.print(LIB_NAME_DRAW, data, objects);
}
}
public static void verbose(final String data) {
if (Log.PRINT_VERBOSE || Log.FORCE) {
Logger.verbose(Log.LIB_NAME_DRAW, data);
public static void todo(final String data, final Object... objects) {
if (PRINT_TODO || FORCE_ALL) {
Logger.todo(LIB_NAME_DRAW, data, objects);
}
}
public static void warning(final String data) {
if (Log.PRINT_WARNING || Log.FORCE) {
Logger.warning(Log.LIB_NAME_DRAW, data);
public static void verbose(final String data, final Object... objects) {
if (PRINT_VERBOSE || FORCE_ALL) {
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);
}
}