ee.sk.digidoc.c14n.TinyXMLParser Maven / Gradle / Ivy
package ee.sk.digidoc.c14n;
import ee.sk.digidoc.c14n.TinyXMLParser_CData;
import ee.sk.digidoc.c14n.TinyXMLParser_Comment;
import ee.sk.digidoc.c14n.TinyXMLParser_Document;
import ee.sk.digidoc.c14n.TinyXMLParser_Element;
import ee.sk.digidoc.c14n.TinyXMLParser_Fragment;
import ee.sk.digidoc.c14n.TinyXMLParser_Handler;
import ee.sk.digidoc.c14n.TinyXMLParser_NestedElement;
import ee.sk.digidoc.c14n.TinyXMLParser_Tag;
import ee.sk.digidoc.c14n.TinyXMLParser_TextNode;
import java.util.Stack;
import ee.sk.digidoc.c14n.common.StringImplementation;
public class TinyXMLParser
{
public TinyXMLParser()
{
}
public void Fail(TinyXMLParser_Fragment f, String reason) throws java.lang.RuntimeException
{
Object[] objectArray0;
objectArray0 = new Object[]
{
"Error line ",
new Integer(f.get_TextPosition().get_Line()),
", column ",
new Integer(f.get_TextPosition().get_Column()),
" - ",
reason
};
throw new java.lang.RuntimeException(StringImplementation.Concat(objectArray0));
}
public void Parse(TinyXMLParser_Handler h, byte[] data)
{
TinyXMLParser_Document doc;
Stack a;
TinyXMLParser_Fragment f;
TinyXMLParser_Element current;
TinyXMLParser_NestedElement nested;
TinyXMLParser_Tag def;
TinyXMLParser_Comment comment;
TinyXMLParser_Element n;
TinyXMLParser_CData u;
TinyXMLParser_TextNode ux;
try
{
doc = new TinyXMLParser_Document();
doc.ParseHandler = h;
a = new Stack();
h.startDocument();
f = TinyXMLParser_Fragment.Of(data, (int)0);
if(f == null) return;
f.OwnerDocument = doc;
f.SplitMarkup();
current = null;
while (!(f == null))
{
if (f.get_IsMarkup())
{
if (f.get_Item(""))
{
h.endElement(n);
}
else
{
if (!(current == null))
{
a.push(current);
}
else
{
if (!(doc.DocumentElement == null))
{
this.Fail(f, "document element already defined");
}
doc.DocumentElement = n;
}
current = n;
}
continue;
}
if (f.get_Item(""))
{
if ((current == null))
{
this.Fail(f, "tag is not open");
}
current.End = TinyXMLParser_Tag.Of(f);
if (!current.get_IsValid())
{
this.Fail(f, "tags dont match : "+ current.get_NameOfBeginTagFragment().get_DataString()+ " vs "+ current.get_NameOfEndTagFragment().get_DataString());
}
f = current.End.End.get_Next();
h.endElement(current);
if ((a.size() == 0))
{
current = null;
}
else
{
current = ((TinyXMLParser_Element)a.pop());
}
continue;
}
if (f.get_Item("