[DEV] load from java generic PAth
This commit is contained in:
parent
8a32b34593
commit
2e6f7c3a5f
@ -6,7 +6,14 @@
|
|||||||
|
|
||||||
package org.atriasoft.exml;
|
package org.atriasoft.exml;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Array;
|
import java.lang.reflect.Array;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.atriasoft.etk.Uri;
|
import org.atriasoft.etk.Uri;
|
||||||
@ -81,6 +88,22 @@ public class Exml {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
private static String readFile(Path path, 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 ExmlBuilderException, ExmlParserErrorMulti {
|
||||||
|
String content = null;
|
||||||
|
try {
|
||||||
|
content = readFile(path, StandardCharsets.UTF_8);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return parse(content, classType, rootNodeName);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load the file that might contain the xml
|
* Load the file that might contain the xml
|
||||||
@ -99,7 +122,7 @@ public class Exml {
|
|||||||
* the file: fileIo->close(); // parse the data: boolean ret =
|
* the file: fileIo->close(); // parse the data: boolean ret =
|
||||||
* parse(tmpDataUnicode); //Display(); return ret; }
|
* parse(tmpDataUnicode); //Display(); return ret; }
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public static XmlElement parse(final Uri data) throws ExmlBuilderException, ExmlParserErrorMulti {
|
public static XmlElement parse(final Uri data) throws ExmlBuilderException, ExmlParserErrorMulti {
|
||||||
final Builder builder = new BuilderGeneric();
|
final Builder builder = new BuilderGeneric();
|
||||||
final ParseXml parser = new ParseXml(builder);
|
final ParseXml parser = new ParseXml(builder);
|
||||||
@ -114,6 +137,26 @@ public class Exml {
|
|||||||
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 ExmlBuilderException, 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();
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store the Xml in the file
|
* Store the Xml in the file
|
||||||
|
@ -44,7 +44,7 @@ public abstract class XmlNode {
|
|||||||
public abstract XmlNodeType getType();
|
public abstract XmlNodeType getType();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the current element Value.
|
* Get the current element Value (value in the XML tag <VALUE ... > </VALUE>.
|
||||||
* @return the reference of the string value.
|
* @return the reference of the string value.
|
||||||
*/
|
*/
|
||||||
public String getValue() {
|
public String getValue() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user