org.digidoc4j.ddoc.c14n.TinyXMLParser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ddoc4j Show documentation
Show all versions of ddoc4j Show documentation
DDoc4J is Java Library for validating DDOC documents. It's not recommended to use it directly but rather through DigiDoc4J's API.
The newest version!
package org.digidoc4j.ddoc.c14n;
import org.digidoc4j.ddoc.c14n.common.StringImplementation;
import java.util.Stack;
public class TinyXMLParser {
public TinyXMLParser()
{
}
public void Fail(TinyXMLParser_Fragment f, String reason) throws 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, 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("