[DEV] update some API ==> better normalisation

This commit is contained in:
Edouard DUPIN 2021-02-24 20:56:50 +01:00
parent b1ea27a01a
commit fce7d1d7ab
31 changed files with 330 additions and 272 deletions

View File

@ -1,6 +1,8 @@
/** Basic module interface.
*
* @author Edouard DUPIN */
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
open module org.atriasoft.exml {
exports org.atriasoft.exml;

View File

@ -1,33 +1,38 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package org.atriasoft.exml;
import org.atriasoft.exml.internal.Log;
import org.atriasoft.exml.internal.PositionParsing;
import org.atriasoft.exml.internal.Tools;
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
/**
* @brief Single attribute element
*/
public class Attribute extends Node {
public class Attribute {
protected FilePos m_pos; //!< position in the read file (null if the file is not parsed);
protected String m_value; //!< value of the node (for element this is the name, for text it is the inside text ...);
protected String m_name; //!< Name of the attribute
public Attribute() {
super("");
this.m_pos = null;
this.m_value = "";
this.m_name = "";
}
public Attribute(final Attribute _obj) {
super(_obj.m_value);
this.m_pos = _obj.getPos().clone();
this.m_pos = null;
this.m_value = _obj.m_value;
this.m_name = _obj.m_name;
}
public Attribute(final String _name) {
super("");
this.m_name = _name;
this.m_value = "";
}
/**
@ -36,19 +41,18 @@ public class Attribute extends Node {
* @param[in] _value Value of the attribute.
*/
public Attribute(final String _name, final String _value) {
super(_value);
this.m_name = _name;
this.m_value = _value;
}
@Override
public void clear() {
this.m_name = "";
};
this.m_value = "";
}
@Override
public Attribute clone() {
return new Attribute(this);
};
}
/**
* @brief get the current name of the Attribute
@ -58,12 +62,14 @@ public class Attribute extends Node {
return this.m_name;
};
@Override
public NodeType getType() {
return NodeType.attribute;
}
/**
* @brief get the current element Value.
* @return the reference of the string value.
*/
public String getValue() {
return this.m_value;
};
@Override
protected boolean iGenerate(final StringBuilder _data, final int _indent) {
_data.append(" ");
_data.append(this.m_name);
@ -71,18 +77,17 @@ public class Attribute extends Node {
_data.append(this.m_value);
_data.append("\"");
return true;
}
};
@Override
protected boolean iParse(final String _data, final PositionParsing _pos, final boolean _caseSensitive, final FilePos _filePos, final Document _doc) {
Log.verbose("start parse : 'attribute'");
this.m_pos.set(_filePos);
this.m_pos = _filePos.clone();
// search end of the comment :
int lastElementName = _pos.value;
for (int iii = _pos.value; iii < _data.length(); iii++) {
_filePos.check(_data.charAt(iii));
drawElementParsed(_data.charAt(iii), _filePos);
if (checkAvaillable(_data.charAt(iii), false) == true) {
Tools.drawElementParsed(_data.charAt(iii), _filePos);
if (Tools.checkAvaillable(_data.charAt(iii), false) == true) {
lastElementName = iii;
} else {
break;
@ -94,7 +99,7 @@ public class Attribute extends Node {
}
// count white space :
final FilePos tmpPos = new FilePos();
int white = countWhiteChar(_data, lastElementName + 1, tmpPos);
int white = Tools.countWhiteChar(_data, lastElementName + 1, tmpPos);
_filePos.add(tmpPos);
if (lastElementName + white + 1 >= _data.length()) {
_doc.createError(_data, lastElementName + white + 1, _filePos, " parse an xml end with an attribute parsing...");
@ -104,7 +109,7 @@ public class Attribute extends Node {
_doc.createError(_data, lastElementName + white + 1, _filePos, " error attribute parsing == > missing '=' ...");
return false;
}
white += countWhiteChar(_data, lastElementName + white + 2, tmpPos);
white += Tools.countWhiteChar(_data, lastElementName + white + 2, tmpPos);
_filePos.add(tmpPos);
if (lastElementName + white + 2 >= _data.length()) {
@ -120,7 +125,7 @@ public class Attribute extends Node {
_filePos.increment();
int lastAttributePos = lastElementName + white + 2;
for (int iii = lastElementName + white + 2; iii < _data.length(); iii++) {
drawElementParsed(_data.charAt(iii), _filePos);
Tools.drawElementParsed(_data.charAt(iii), _filePos);
if (_filePos.check(_data.charAt(iii)) == true) {
_doc.createError(_data, iii, _filePos, "unexpected '\\n' in an attribute parsing");
return false;
@ -140,7 +145,7 @@ public class Attribute extends Node {
}
int lastAttributePos = lastElementName + white + 3;
for (int iii = lastElementName + white + 3; iii < _data.length(); iii++) {
drawElementParsed(_data.charAt(iii), _filePos);
Tools.drawElementParsed(_data.charAt(iii), _filePos);
_filePos.check(_data.charAt(iii));
if ((_data.charAt(iii) != '"' && simpleQuoteCase == false) || (_data.charAt(iii) != '\'' && simpleQuoteCase == true)) { // '
lastAttributePos = iii + 1;
@ -163,4 +168,12 @@ public class Attribute extends Node {
public void setName(final String _name) {
this.m_name = _name;
}
/**
* @brief set the value of the node.
* @param[in] _value New value of the node.
*/
public final void setValue(final String _value) {
this.m_value = _value;
}
};

View File

@ -1,6 +1,6 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package org.atriasoft.exml;

View File

@ -1,12 +1,14 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package org.atriasoft.exml;
import org.atriasoft.exml.internal.Log;
import org.atriasoft.exml.internal.PositionParsing;
import org.atriasoft.exml.internal.Tools;
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
/**
* @brief Comment node: lt;!-- ... --gt;
*/
@ -35,12 +37,12 @@ public class Comment extends Node {
@Override
public NodeType getType() {
return NodeType.comment;
return NodeType.COMMENT;
}
@Override
public boolean iGenerate(final StringBuilder _data, final int _indent) {
addIndent(_data, _indent);
Tools.addIndent(_data, _indent);
_data.append("<!--");
_data.append(this.m_value);
_data.append("-->\n");
@ -52,11 +54,11 @@ public class Comment extends Node {
Log.verbose("start parse : 'comment'");
this.m_pos = _filePos;
final FilePos tmpPos = new FilePos();
final int white = countWhiteChar(_data, _pos.value, tmpPos);
final int white = Tools.countWhiteChar(_data, _pos.value, tmpPos);
_filePos.add(tmpPos);
// search end of the comment :
for (int iii = _pos.value + white; iii + 2 < _data.length(); iii++) {
drawElementParsed(_data.charAt(iii), _filePos);
Tools.drawElementParsed(_data.charAt(iii), _filePos);
if (_filePos.check(_data.charAt(iii)) == true) {
continue;
}
@ -65,7 +67,7 @@ public class Comment extends Node {
// search whitespace :
int newEnd = iii;
for (int jjj = iii - 1; jjj > _pos.value; jjj--) {
if (isWhiteChar(_data.charAt(jjj)) == true) {
if (Tools.isWhiteChar(_data.charAt(jjj)) == true) {
newEnd = jjj;
} else {
break;

View File

@ -1,12 +1,14 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package org.atriasoft.exml;
import org.atriasoft.exml.internal.Log;
import org.atriasoft.exml.internal.PositionParsing;
import org.atriasoft.exml.internal.Tools;
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
/**
* @brief Declaration node: lt;?XXXXXX ... gt;
*/
@ -37,12 +39,12 @@ public class Declaration extends AttributeList {
@Override
public NodeType getType() {
return NodeType.declaration;
return NodeType.DECLARATION;
};
@Override
protected boolean iGenerate(final StringBuilder _data, final int _indent) {
addIndent(_data, _indent);
Tools.addIndent(_data, _indent);
_data.append("<?");
_data.append(this.m_value);
super.iGenerate(_data, _indent);
@ -56,7 +58,7 @@ public class Declaration extends AttributeList {
this.m_pos = _filePos;
// search end of the comment :
for (int iii = _pos.value; iii + 1 < _data.length(); iii++) {
drawElementParsed(_data.charAt(iii), _filePos);
Tools.drawElementParsed(_data.charAt(iii), _filePos);
if (_filePos.check(_data.charAt(iii)) == true) {
continue;
}
@ -71,7 +73,7 @@ public class Declaration extends AttributeList {
_pos.value = iii + 1;
return true;
}
if (checkAvaillable(_data.charAt(iii), true) == true) {
if (Tools.checkAvaillable(_data.charAt(iii), true) == true) {
// we find an attibute == > create an element and parse it:
final Attribute attribute = new Attribute();
_pos.value = iii;

View File

@ -1,3 +1,8 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package org.atriasoft.exml;
import org.atriasoft.exml.internal.Log;

View File

@ -1,6 +1,13 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package org.atriasoft.exml;
import org.atriasoft.exml.internal.Log;
import org.atriasoft.exml.internal.PositionParsing;
import org.atriasoft.exml.internal.Tools;
/** @file
* @author Edouard DUPIN
@ -11,22 +18,6 @@ import org.atriasoft.exml.internal.Log;
* @brief Basic document element of a document
*/
public class Document extends Element {
private static String createPosPointer(final String _line, final int _pos) {
String out = "";
int iii;
for (iii = 0; iii < _pos && iii < _line.length(); iii++) {
if (_line.charAt(iii) == '\t') {
out += "\t";
} else {
out += " ";
}
}
for (; iii < _pos; iii++) {
out += " ";
}
out += "^";
return out;
}
private boolean m_caseSensitive; //!< check the case sensitive of the nodes and attribute
private boolean m_writeErrorWhenDetexted; //!< Request print error in parsing just when detected
@ -84,7 +75,7 @@ public class Document extends Element {
Log.error("No error detected ???");
return;
}
Log.error(this.m_filePos + " " + this.m_comment + "\n" + this.m_Line + "\n" + createPosPointer(this.m_Line, this.m_filePos.getCol()));
Log.error(this.m_filePos + " " + this.m_comment + "\n" + this.m_Line + "\n" + Tools.createPosPointer(this.m_Line, this.m_filePos.getCol()));
//Log.critical("detect error");
}
@ -205,7 +196,7 @@ public class Document extends Element {
@Override
public NodeType getType() {
return NodeType.document;
return NodeType.DOCUMENT;
}
@Override

View File

@ -1,3 +1,8 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package org.atriasoft.exml;
import java.util.ArrayList;
@ -6,6 +11,8 @@ import java.util.ListIterator;
import org.atriasoft.exml.exception.ExmlNodeDoesNotExist;
import org.atriasoft.exml.internal.Log;
import org.atriasoft.exml.internal.PositionParsing;
import org.atriasoft.exml.internal.Tools;
/** @file
* @author Edouard DUPIN
@ -53,10 +60,6 @@ public class Element extends AttributeList {
Log.error("Try to set an empty node");
return;
}
if (_node.getType() == NodeType.attribute) {
appendAttribute(_node.toAttribute());
return;
}
for (int iii = 0; iii < this.m_listSub.size(); iii++) {
if (this.m_listSub.get(iii) == _node) {
Log.error("Try to add a node that is already added before !!!");
@ -117,7 +120,7 @@ public class Element extends AttributeList {
*/
public Node getNode(final int _id) throws ExmlNodeDoesNotExist {
if (_id < 0 || _id >= this.m_listSub.size()) {
throw new ExmlNodeDoesNotExist("Node does not exist: " + _id + "/" + this.m_listAttribute.size());
throw new ExmlNodeDoesNotExist("Node does not exist: " + _id + "/" + this.m_listSub.size());
}
return this.m_listSub.get(_id);
}
@ -155,7 +158,7 @@ public class Element extends AttributeList {
public String getText() {
final StringBuilder res = new StringBuilder();
if (this.m_listSub.size() == 1) {
if (this.m_listSub.get(0).getType() == NodeType.text) {
if (this.m_listSub.get(0).getType() == NodeType.TEXT) {
res.append(this.m_listSub.get(0).getValue());
} else {
this.m_listSub.get(0).iGenerate(res, 0);
@ -172,30 +175,31 @@ public class Element extends AttributeList {
@Override
public NodeType getType() {
return NodeType.element;
return NodeType.ELEMENT;
}
/**
* @brief get the type of the element id.
* @param[in] _id Id of the element.
* @return the Current type of the element or typeUnknow.
* @throws ExmlNodeDoesNotExist The Node does not exist
*/
public NodeType getType(final int _id) {
public NodeType getType(final int _id) throws ExmlNodeDoesNotExist {
if (_id < 0 || _id >= this.m_listSub.size()) {
return NodeType.unknow;
throw new ExmlNodeDoesNotExist("Node does not exist: " + _id + "/" + this.m_listSub.size());
}
return this.m_listSub.get(_id).getType();
}
@Override
protected boolean iGenerate(final StringBuilder _data, final int _indent) {
addIndent(_data, _indent);
Tools.addIndent(_data, _indent);
_data.append("<");
_data.append(this.m_value);
super.iGenerate(_data, _indent);
if (this.m_listSub.size() > 0) {
if (this.m_listSub.size() == 1 && this.m_listSub.get(0) != null && this.m_listSub.get(0).getType() == NodeType.text && ((Text) this.m_listSub.get(0)).countLines() == 1) {
if (this.m_listSub.size() == 1 && this.m_listSub.get(0) != null && this.m_listSub.get(0).getType() == NodeType.TEXT && ((Text) this.m_listSub.get(0)).countLines() == 1) {
_data.append(">");
this.m_listSub.get(0).iGenerate(_data, 0);
Log.verbose(" generate : '" + _data + "'");
@ -206,7 +210,7 @@ public class Element extends AttributeList {
this.m_listSub.get(iii).iGenerate(_data, _indent + 1);
}
}
addIndent(_data, _indent);
Tools.addIndent(_data, _indent);
}
_data.append("</");
_data.append(this.m_value);
@ -225,7 +229,7 @@ public class Element extends AttributeList {
// find a normal node ...
for (int iii = _pos.value; iii < _data.length(); iii++) {
_filePos.check(_data.charAt(iii));
drawElementParsed(_data.charAt(iii), _filePos);
Tools.drawElementParsed(_data.charAt(iii), _filePos);
if (_data.charAt(iii) == '>') {
// we find the end ...
_pos.value = iii + 1;
@ -246,7 +250,7 @@ public class Element extends AttributeList {
_doc.createError(_data, _pos.value, _filePos, "Find / without > char ...");
return false;
}
if (checkAvaillable(_data.charAt(iii), true) == true) {
if (Tools.checkAvaillable(_data.charAt(iii), true) == true) {
// we find an attibute == > create an element and parse it:
final Attribute attribute = new Attribute();
_pos.value = iii;
@ -257,7 +261,7 @@ public class Element extends AttributeList {
this.m_listAttribute.add(attribute);
continue;
}
if (isWhiteChar(_data.charAt(iii)) == false) {
if (Tools.isWhiteChar(_data.charAt(iii)) == false) {
_doc.createError(_data, iii, _filePos, "Find an unknow element : '" + _data.charAt(iii) + "'");
return false;
}
@ -313,10 +317,10 @@ public class Element extends AttributeList {
//EXML_PARSE_ELEMENT(" start subParse ... " << _pos << " " << _filePos);
for (int iii = _pos.value; iii < _data.length(); iii++) {
_filePos.check(_data.charAt(iii));
drawElementParsed(_data.charAt(iii), _filePos);
Tools.drawElementParsed(_data.charAt(iii), _filePos);
final FilePos tmpPos = new FilePos();
if (_data.charAt(iii) == '<') {
final int white = countWhiteChar(_data, iii + 1, tmpPos);
final int white = Tools.countWhiteChar(_data, iii + 1, tmpPos);
if (iii + white + 1 >= _data.length()) {
_filePos.add(tmpPos);
_doc.createError(_data, _pos.value, _filePos, "End file with '<' char == > invalide XML");
@ -333,7 +337,7 @@ public class Element extends AttributeList {
if (_data.charAt(iii + white + 1) == '?') {
tmpPos.increment();
// TODO : white space ...
if (checkAvaillable(_data.charAt(iii + white + 2), true) == false) {
if (Tools.checkAvaillable(_data.charAt(iii + white + 2), true) == false) {
_doc.createError(_data, _pos.value, _filePos, "Find unavaillable name in the Declaration node...");
_pos.value = iii + white + 1;
return false;
@ -342,7 +346,7 @@ public class Element extends AttributeList {
int endPosName = iii + white + 1;
// generate element name ...
for (int jjj = iii + white + 2; jjj < _data.length(); jjj++) {
if (checkAvaillable(_data.charAt(jjj), false) == true) {
if (Tools.checkAvaillable(_data.charAt(jjj), false) == true) {
// we find the end ...
endPosName = jjj;
} else {
@ -426,7 +430,7 @@ public class Element extends AttributeList {
int endPosName = iii + white + 1;
// generate element name ...
for (int jjj = iii + white + 2; jjj < _data.length(); jjj++) {
if (checkAvaillable(_data.charAt(jjj), false) == true) {
if (Tools.checkAvaillable(_data.charAt(jjj), false) == true) {
// we find the end ...
endPosName = jjj;
} else {
@ -442,7 +446,7 @@ public class Element extends AttributeList {
// find end of node :
// find > element ...
for (int jjj = endPosName + 1; jjj < _data.length(); jjj++) {
drawElementParsed(_data.charAt(jjj), _filePos);
Tools.drawElementParsed(_data.charAt(jjj), _filePos);
if (tmpPos.check(_data.charAt(jjj)) == true) {
continue;
}
@ -467,13 +471,13 @@ public class Element extends AttributeList {
return false;
}
if (checkAvaillable(_data.charAt(iii + white + 1), true) == true) {
if (Tools.checkAvaillable(_data.charAt(iii + white + 1), true) == true) {
tmpPos.increment();
Log.debug("Generate node name : '" + _data.charAt(iii + 1) + "'");
int endPosName = iii + white + 1;
// generate element name ...
for (int jjj = iii + white + 2; jjj < _data.length(); jjj++) {
if (checkAvaillable(_data.charAt(jjj), false) == true) {
if (Tools.checkAvaillable(_data.charAt(jjj), false) == true) {
// we find the end ...
endPosName = jjj;
} else {

View File

@ -1,3 +1,8 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package org.atriasoft.exml;
/** @file

View File

@ -1,33 +1,25 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package org.atriasoft.exml;
import org.atriasoft.exml.internal.Log;
import org.atriasoft.exml.internal.PositionParsing;
/**
* @brief Basic main object of all xml elements.
*/
public abstract class Node {
protected class PositionParsing {
public int value = 0;
}
protected static boolean isWhiteChar(final Character _val) {
if (_val == ' ' || _val == '\t' || _val == '\n' || _val == '\r') {
return true;
}
return false;
}
protected FilePos m_pos; //!< position in the readed file == > not correct when the file is generated;
protected FilePos m_pos; //!< position in the read file (null if the file is not parsed)
protected String m_value; //!< value of the node (for element this is the name, for text it is the inside text ...);
/**
* @brief basic element of a xml structure
*/
public Node() {
this.m_pos = new FilePos(0, 0);
this.m_pos = null;
}
/**
@ -35,49 +27,16 @@ public abstract class Node {
* @param[in] _value value of the node
*/
public Node(final String _value) {
this.m_pos = new FilePos(0, 0);
this.m_pos = null;
this.m_value = _value;
}
/**
* @brief add indentation of the string input.
* @param[in,out] _data String where the indentation is done.
* @param[in] _indent Number of tab to add at the string.
*/
protected void addIndent(final StringBuilder _data, final int _indent) {
for (int iii = 0; iii < _indent; iii++) {
_data.append("\t");
}
}
/**
* @brief check if an element or attribute is availlable (not : !"#$%&'()*+,/;<=>?@[\]^`{|}~ \\n\\t\\r and for first char : not -.0123456789).
* @param[in] _val Value to check the conformity.
* @param[in] _firstChar True if the element check is the first char.
* @return true The value can be a part of attribute name
* @return false The value can NOT be a part of attribute name
*/
protected boolean checkAvaillable(final Character _val, final boolean _firstChar) {
if (_val == '!' || _val == '"' || _val == '#' || _val == '$' || _val == '%' || _val == '&' || _val == '\'' // '
|| _val == '(' || _val == ')' || _val == '*' || _val == '+' || _val == ',' || _val == '/' || _val == ';' || _val == '<' || _val == '=' || _val == '>' || _val == '?' || _val == '@'
|| _val == '[' || _val == '\\' || _val == ']' || _val == '^' || _val == '`' || _val == '{' || _val == '|' || _val == '}' || _val == '~' || _val == ' ' || _val == '\n' || _val == '\t'
|| _val == '\r') {
return false;
}
if (_firstChar == true) {
if (_val == '-' || _val == '.' || (_val >= '0' && _val <= '9')) {
return false;
}
}
return true;
}
/**
* @brief clear the Node
*/
public void clear() {
this.m_value = "";
this.m_pos.clear();
this.m_pos = null;
}
@Override
@ -85,43 +44,6 @@ public abstract class Node {
throw new CloneNotSupportedException("Can not clone an abstract class ...");
}
/**
* @brief count the number of white char in the string from the specify position (stop at the first element that is not a white char)
* @param[in] _data Data to parse.
* @param[in] _pos Start position in the string.
* @param[out] _filePos new poistion of te file to add.
* @return number of white element.
*/
protected int countWhiteChar(final String _data, final int _pos, final FilePos _filePos) {
_filePos.clear();
int white = 0;
for (int iii = _pos; iii < _data.length(); iii++) {
_filePos.check(_data.charAt(iii));
if (isWhiteChar(_data.charAt(iii)) == true) {
white++;
} else {
break;
}
}
_filePos.decrement();
return white;
}
/**
* @brief Display the cuurent element that is curently parse.
* @param[in] _val Char that is parsed.
* @param[in] _filePos Position of the char in the file.
*/
protected void drawElementParsed(final Character _val, final FilePos _filePos) {
if (_val == '\n') {
Log.debug(_filePos + " parse '\\n'");
} else if (_val == '\t') {
Log.debug(_filePos + " parse '\\t'");
} else {
Log.debug(_filePos + " parse '" + _val + "'");
}
}
/**
* @brief get the current position where the element is in the file
* @return The file position reference
@ -134,9 +56,7 @@ public abstract class Node {
* @brief get the node type.
* @return the type of the Node.
*/
NodeType getType() {
return NodeType.node;
}
public abstract NodeType getType();
/**
* @brief get the current element Value.
@ -152,9 +72,7 @@ public abstract class Node {
* @param[in] _indent current indentation of the file
* @return false if an error occured.
*/
protected boolean iGenerate(final StringBuilder _data, final int _indent) {
return true;
}
protected abstract boolean iGenerate(final StringBuilder _data, final int _indent);
/**
* @brief parse the Current node [pure VIRUAL]
@ -168,50 +86,42 @@ public abstract class Node {
protected abstract boolean iParse(String _data, PositionParsing _pos, boolean _caseSensitive, FilePos _filePos, Document _doc);
/**
* @brief check if the node is a exml::Attribute
* @return true if the node is a exml::Attribute
* @brief check if the node is a Comment
* @return true if the node is a Comment
*/
public boolean isAttribute() {
return this instanceof Attribute;
}
/**
* @brief check if the node is a exml::Comment
* @return true if the node is a exml::Comment
*/
public boolean isComment() {
public final boolean isComment() {
return this instanceof Comment;
}
/**
* @brief check if the node is a exml::Declaration
* @return true if the node is a exml::Declaration
* @brief check if the node is a Declaration
* @return true if the node is a Declaration
*/
public boolean isDeclaration() {
public final boolean isDeclaration() {
return this instanceof Declaration;
}
/**
* @brief check if the node is a exml::Document
* @return true if the node is a exml::Document
* @brief check if the node is a Document
* @return true if the node is a Document
*/
public boolean isDocument() {
public final boolean isDocument() {
return this instanceof Document;
}
/**
* @brief check if the node is a exml::Element
* @return true if the node is a exml::Element
* @brief check if the node is a Element
* @return true if the node is a Element
*/
public boolean isElement() {
public final boolean isElement() {
return this instanceof Element;
}
/**
* @brief check if the node is a exml::Text
* @return true if the node is a exml::Text
* @brief check if the node is a Text
* @return true if the node is a Text
*/
public boolean isText() {
public final boolean isText() {
return this instanceof Text;
}
@ -220,23 +130,15 @@ public abstract class Node {
* @param[in] _value New value of the node.
*/
public void setValue(final String _value) {
public final void setValue(final String _value) {
this.m_value = _value;
}
/**
* @brief Cast the element in a Attribute if it is possible.
* @return pointer on the class or null.
*/
public Attribute toAttribute() {
return (Attribute) this;
}
/**
* @brief Cast the element in a Comment if it is possible.
* @return pointer on the class or null.
*/
public Comment toComment() {
public final Comment toComment() {
return (Comment) this;
}
@ -244,7 +146,7 @@ public abstract class Node {
* @brief Cast the element in a Declaration if it is possible.
* @return pointer on the class or null.
*/
public Declaration toDeclaration() {
public final Declaration toDeclaration() {
return (Declaration) this;
}
@ -252,7 +154,7 @@ public abstract class Node {
* @brief Cast the element in a Document if it is possible.
* @return pointer on the class or null.
*/
public Document toDocument() {
public final Document toDocument() {
return (Document) this;
}
@ -260,7 +162,7 @@ public abstract class Node {
* @brief Cast the element in a Element if it is possible.
* @return pointer on the class or null.
*/
public Element toElement() {
public final Element toElement() {
return (Element) this;
}
@ -268,7 +170,7 @@ public abstract class Node {
* @brief Cast the element in a Text if it is possible.
* @return pointer on the class or null.
*/
public Text toText() {
public final Text toText() {
return (Text) this;
}

View File

@ -1,20 +1,17 @@
package org.atriasoft.exml;
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package org.atriasoft.exml;
/**
* @brief Type of the XML elements.
*/
public enum NodeType {
unknow, //!< might be an error ...
node, //!< might be an error ...
document, //!< all the file main access
declaration, //!< &lt;?xml ... ?&gt;
attribute, //!< the &lt;Element ATTRIBUTE="ATTRIBUTE_VALUE" /&gt;
element, //!< the &lt;XXX&gt; ... &lt;/XXX&gt;
comment, //!< comment node : &lt;!-- --&gt;
text, //!< &lt;XXX&gt; InsideText &lt;/XXX&gt;
DOCUMENT, //!< all the file main access
DECLARATION, //!< &lt;?xml ... ?&gt;
ELEMENT, //!< the &lt;XXX&gt; ... &lt;/XXX&gt;
COMMENT, //!< comment node : &lt;!-- --&gt;
TEXT, //!< &lt;XXX&gt; InsideText &lt;/XXX&gt;
}

View File

@ -1,11 +1,13 @@
package org.atriasoft.exml;
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package org.atriasoft.exml;
import org.atriasoft.exml.internal.Log;
import org.atriasoft.exml.internal.PositionParsing;
import org.atriasoft.exml.internal.Tools;
/**
* @brief Text node interface (internal data between two Marker: &lt;XXX&gt; ALL here &lt;/XXX&gt;
@ -68,8 +70,8 @@ public class Text extends Node {
}
@Override
NodeType getType() {
return NodeType.text;
public NodeType getType() {
return NodeType.TEXT;
};
@Override
@ -81,10 +83,10 @@ public class Text extends Node {
@Override
protected boolean iParse(final String _data, final PositionParsing _pos, final boolean _caseSensitive, final FilePos _filePos, final Document _doc) {
Log.verbose("start parse : 'text'");
this.m_pos = _filePos;
this.m_pos = _filePos.clone();
// search end of the comment :
for (int iii = _pos.value; iii < _data.length(); iii++) {
drawElementParsed(_data.charAt(iii), _filePos);
Tools.drawElementParsed(_data.charAt(iii), _filePos);
if (_filePos.check(_data.charAt(iii)) == true) {
continue;
}
@ -92,7 +94,7 @@ public class Text extends Node {
// search whitespace :
int newEnd = iii;
for (int jjj = iii - 1; jjj > _pos.value; --jjj) {
if (isWhiteChar(_data.charAt(jjj)) == true) {
if (Tools.isWhiteChar(_data.charAt(jjj)) == true) {
newEnd = jjj;
} else {
break;

View File

@ -1,6 +1,13 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package org.atriasoft.exml;
import org.atriasoft.exml.internal.Log;
import org.atriasoft.exml.internal.PositionParsing;
import org.atriasoft.exml.internal.Tools;
public class TextCDATA extends Text {
public TextCDATA() {
@ -22,10 +29,10 @@ public class TextCDATA extends Text {
@Override
protected boolean iParse(final String _data, final PositionParsing _pos, final boolean _caseSensitive, final FilePos _filePos, final Document _doc) {
Log.verbose("start parse : 'text::CDATA'");
this.m_pos = _filePos;
this.m_pos = _filePos.clone();
// search end of the comment :
for (int iii = _pos.value; iii + 2 < _data.length(); iii++) {
drawElementParsed(_data.charAt(iii), _filePos);
Tools.drawElementParsed(_data.charAt(iii), _filePos);
if (_filePos.check(_data.charAt(iii)) == true) {
continue;
}

View File

@ -1,3 +1,8 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package org.atriasoft.exml.exception;
public class ExmlAttributeDoesNotExist extends ExmlException {

View File

@ -1,3 +1,8 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package org.atriasoft.exml.exception;
public class ExmlException extends Exception {

View File

@ -1,3 +1,8 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package org.atriasoft.exml.exception;
public class ExmlNodeDoesNotExist extends ExmlException {

View File

@ -1,3 +1,8 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package org.atriasoft.exml.internal;
import io.scenarium.logger.LogLevel;

View File

@ -0,0 +1,6 @@
package org.atriasoft.exml.internal;
public class PositionParsing {
public int value = 0;
}

View File

@ -0,0 +1,101 @@
package org.atriasoft.exml.internal;
import org.atriasoft.exml.FilePos;
public class Tools {
/**
* @brief add indentation of the string input.
* @param[in,out] _data String where the indentation is done.
* @param[in] _indent Number of tab to add at the string.
*/
public static void addIndent(final StringBuilder _data, final int _indent) {
for (int iii = 0; iii < _indent; iii++) {
_data.append("\t");
}
}
/**
* @brief check if an element or attribute is availlable (not : !"#$%&'()*+,/;<=>?@[\]^`{|}~ \\n\\t\\r and for first char : not -.0123456789).
* @param[in] _val Value to check the conformity.
* @param[in] _firstChar True if the element check is the first char.
* @return true The value can be a part of attribute name
* @return false The value can NOT be a part of attribute name
*/
public static boolean checkAvaillable(final Character _val, final boolean _firstChar) {
if (_val == '!' || _val == '"' || _val == '#' || _val == '$' || _val == '%' || _val == '&' || _val == '\'' // '
|| _val == '(' || _val == ')' || _val == '*' || _val == '+' || _val == ',' || _val == '/' || _val == ';' || _val == '<' || _val == '=' || _val == '>' || _val == '?' || _val == '@'
|| _val == '[' || _val == '\\' || _val == ']' || _val == '^' || _val == '`' || _val == '{' || _val == '|' || _val == '}' || _val == '~' || _val == ' ' || _val == '\n' || _val == '\t'
|| _val == '\r') {
return false;
}
if (_firstChar == true) {
if (_val == '-' || _val == '.' || (_val >= '0' && _val <= '9')) {
return false;
}
}
return true;
}
/**
* @brief count the number of white char in the string from the specify position (stop at the first element that is not a white char)
* @param[in] _data Data to parse.
* @param[in] _pos Start position in the string.
* @param[out] _filePos new poistion of te file to add.
* @return number of white element.
*/
public static int countWhiteChar(final String _data, final int _pos, final FilePos _filePos) {
_filePos.clear();
int white = 0;
for (int iii = _pos; iii < _data.length(); iii++) {
_filePos.check(_data.charAt(iii));
if (Tools.isWhiteChar(_data.charAt(iii)) == true) {
white++;
} else {
break;
}
}
_filePos.decrement();
return white;
}
public static String createPosPointer(final String _line, final int _pos) {
String out = "";
int iii;
for (iii = 0; iii < _pos && iii < _line.length(); iii++) {
if (_line.charAt(iii) == '\t') {
out += "\t";
} else {
out += " ";
}
}
for (; iii < _pos; iii++) {
out += " ";
}
out += "^";
return out;
}
/**
* @brief Display the cuurent element that is curently parse.
* @param[in] _val Char that is parsed.
* @param[in] _filePos Position of the char in the file.
*/
public static void drawElementParsed(final Character _val, final FilePos _filePos) {
if (_val == '\n') {
Log.debug(_filePos + " parse '\\n'");
} else if (_val == '\t') {
Log.debug(_filePos + " parse '\\t'");
} else {
Log.debug(_filePos + " parse '" + _val + "'");
}
}
public static boolean isWhiteChar(final Character _val) {
if (_val == ' ' || _val == '\t' || _val == '\n' || _val == '\r') {
return true;
}
return false;
}
private Tools() {}
}

View File

@ -1,6 +1,6 @@
/** @file
* @author Edouard DUPIN
* @copyright 2014, Edouard DUPIN, all right reserved
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package test.atriasoft.exml;

View File

@ -1,13 +1,11 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package test.atriasoft.exml;
import org.junit.jupiter.api.BeforeAll;
/** @file
* @author Edouard DUPIN
* @copyright 2014, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
import org.junit.jupiter.api.Test;
public class ExmlTestAll {

View File

@ -8,7 +8,6 @@ package test.atriasoft.exml;
import org.atriasoft.exml.Attribute;
import org.atriasoft.exml.Document;
import org.atriasoft.exml.Element;
import org.atriasoft.exml.NodeType;
import org.atriasoft.exml.exception.ExmlAttributeDoesNotExist;
import org.atriasoft.exml.exception.ExmlNodeDoesNotExist;
import org.junit.jupiter.api.Assertions;
@ -34,13 +33,6 @@ public class ExmlTestAttribute {
myAttribute.clear();
}
@Test
public void create() {
final Attribute myAttribute = new Attribute("nameAttribute", "valueAttribute");
Assertions.assertEquals(myAttribute.getType(), NodeType.attribute);
}
@Test
public void createAssignement() {
final Attribute myAttribute = new Attribute("nameAttribute", "valueAttribute");

View File

@ -1,3 +1,8 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package test.atriasoft.exml;
import org.atriasoft.exml.Document;

View File

@ -1,6 +1,6 @@
/** @file
* @author Edouard DUPIN
* @copyright 2014, Edouard DUPIN, all right reserved
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package test.atriasoft.exml;
@ -21,7 +21,7 @@ public class ExmlTestComment {
@Test
public void create() {
final Comment myComment = new Comment("my Comment");
Assertions.assertEquals(myComment.getType(), NodeType.comment);
Assertions.assertEquals(myComment.getType(), NodeType.COMMENT);
}
@Test

View File

@ -1,6 +1,6 @@
/** @file
* @author Edouard DUPIN
* @copyright 2014, Edouard DUPIN, all right reserved
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package test.atriasoft.exml;
@ -21,7 +21,7 @@ public class ExmlTestDeclarationXML {
@Test
public void create() {
final DeclarationXML myDeclarationXML = new DeclarationXML("1.0", "UTF-8", true);
Assertions.assertEquals(myDeclarationXML.getType(), NodeType.declaration);
Assertions.assertEquals(myDeclarationXML.getType(), NodeType.DECLARATION);
try {
Assertions.assertEquals(myDeclarationXML.getAttribute("version"), "1.0");
Assertions.assertEquals(myDeclarationXML.getAttribute("encoding"), "UTF-8");

View File

@ -1,6 +1,6 @@
/** @file
* @author Edouard DUPIN
* @copyright 2014, Edouard DUPIN, all right reserved
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package test.atriasoft.exml;
@ -53,7 +53,7 @@ public class ExmlTestElement {
@Test
public void create() {
final Element myElement = new Element("NodeName");
Assertions.assertEquals(myElement.getType(), NodeType.element);
Assertions.assertEquals(myElement.getType(), NodeType.ELEMENT);
}
@Test
@ -109,7 +109,7 @@ public class ExmlTestElement {
@Test
public void getTypeId() {
final Element myElement = new Element("NodeName");
Assertions.assertEquals(NodeType.unknow, myElement.getType(1));
Assertions.assertEquals(NodeType.UNKNOWN, myElement.getType(1));
}
@Test

View File

@ -1,6 +1,6 @@
/** @file
* @author Edouard DUPIN
* @copyright 2014, Edouard DUPIN, all right reserved
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package test.atriasoft.exml;

View File

@ -1,6 +1,6 @@
/** @file
* @author Edouard DUPIN
* @copyright 2014, Edouard DUPIN, all right reserved
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package test.atriasoft.exml;

View File

@ -1,6 +1,6 @@
/** @file
* @author Edouard DUPIN
* @copyright 2014, Edouard DUPIN, all right reserved
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package test.atriasoft.exml;

View File

@ -1,9 +1,8 @@
/** @file
* @author Edouard DUPIN
* @copyright 2014, Edouard DUPIN, all right reserved
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package test.atriasoft.exml;
import org.junit.jupiter.api.BeforeAll;

View File

@ -1,3 +1,8 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package test.atriasoft.exml;
import io.scenarium.logger.LogLevel;