use of org.omegat.util.xml.XMLBlock in project omegat by omegat-org.
the class PreferencesXML method readXmlPrefs.
static void readXmlPrefs(XMLStreamReader xml, List<String> keys, List<String> values) throws TranslationException {
XMLBlock blk;
List<XMLBlock> lst;
String pref;
String val;
// advance to omegat tag
if (xml.advanceToTag("omegat") == null) {
return;
}
// advance to project tag
if ((blk = xml.advanceToTag("preference")) == null) {
return;
}
String ver = blk.getAttribute("version");
if (ver != null && !ver.equals("1.0")) {
// unsupported preference file version - abort read
return;
}
lst = xml.closeBlock(blk);
if (lst == null) {
return;
}
for (int i = 0; i < lst.size(); i++) {
blk = lst.get(i);
if (blk.isClose()) {
continue;
}
if (!blk.isTag()) {
continue;
}
pref = blk.getTagName();
blk = lst.get(++i);
if (blk.isClose()) {
// allow empty string as a preference value
val = "";
} else {
val = blk.getText();
}
if (pref != null && val != null) {
// valid match - record these
keys.add(pref);
values.add(val);
}
}
}
use of org.omegat.util.xml.XMLBlock in project omegat by omegat-org.
the class XMLStreamReaderTest method testBadEntity.
@Test
public void testBadEntity() throws Exception {
try (XMLStreamReader xml = new XMLStreamReader()) {
xml.killEmptyBlocks();
XMLBlock blk;
xml.setStream(new File("test/data/xml/test-badDecimalEntity.xml"));
assertNotNull(xml.advanceToTag("root"));
assertNotNull(blk = xml.advanceToTag("body"));
try {
assertNotNull(xml.closeBlock(blk));
fail("XML parsing should fail on bad decimal entity");
} catch (TranslationException ex) {
}
xml.setStream(new File("test/data/xml/test-badHexEntity.xml"));
assertNotNull(xml.advanceToTag("root"));
assertNotNull(blk = xml.advanceToTag("body"));
try {
assertNotNull(xml.closeBlock(blk));
fail("XML parsing should fail on bad hex entity");
} catch (TranslationException ex) {
}
}
}
use of org.omegat.util.xml.XMLBlock in project omegat by omegat-org.
the class XMLStreamReaderTest method testLoadXML.
@Test
public void testLoadXML() throws Exception {
XMLStreamReader xml = new XMLStreamReader();
xml.killEmptyBlocks();
xml.setStream(new File("test/data/xml/test.xml"));
XMLBlock blk;
List<XMLBlock> lst;
assertNotNull(xml.advanceToTag("root"));
assertNotNull(blk = xml.advanceToTag("body"));
assertEquals("foo", blk.getAttribute("attr"));
assertNotNull(lst = xml.closeBlock(blk));
assertEquals(25, lst.size());
assertOpenTag(lst.get(0), "ascii");
assertText(lst.get(1), "bar");
assertCloseTag(lst.get(2), "ascii");
assertOpenTag(lst.get(3), "bmp");
// SNOWMAN
assertText(lst.get(4), "\u2603");
assertCloseTag(lst.get(5), "bmp");
assertOpenTag(lst.get(6), "dec");
// SNOWMAN
assertText(lst.get(7), "\u2603");
assertCloseTag(lst.get(8), "dec");
assertOpenTag(lst.get(9), "hex");
// SNOWMAN
assertText(lst.get(10), "\u2603");
assertCloseTag(lst.get(11), "hex");
assertOpenTag(lst.get(12), "astral");
// PLAYING CARD RED JOKER
assertText(lst.get(13), "\uD83C\uDCBF");
assertCloseTag(lst.get(14), "astral");
assertOpenTag(lst.get(15), "a-dec");
// PLAYING CARD RED JOKER
assertText(lst.get(16), "\uD83C\uDCBF");
assertCloseTag(lst.get(17), "a-dec");
assertOpenTag(lst.get(18), "a-hex");
// PLAYING CARD RED JOKER
assertText(lst.get(19), "\uD83C\uDCBF");
assertCloseTag(lst.get(20), "a-hex");
assertOpenTag(lst.get(21), "named");
assertText(lst.get(22), "&<>'\"");
assertCloseTag(lst.get(23), "named");
assertStandaloneTag(lst.get(24), "standalone");
xml.close();
}
Aggregations