try {
// Create a Sofa using OLD APIs for now
SofaID_impl id = new SofaID_impl();
id.setSofaID("EnglishDocument");
Sofa es = new Sofa(jcas, id, "text");
// Initial View is #1!!!
assertTrue(2 == es.getSofaRef());
// Set the document text
es.setLocalSofaData("this beer is good");
// Test Multiple Sofas across XCAS serialization
String xcasFilename = "Sofa.xcas";
XCASSerializer ser = new XCASSerializer(cas.getTypeSystem());
OutputStream outputXCAS = new FileOutputStream(xcasFilename);
XMLSerializer xmlSer = new XMLSerializer(outputXCAS);
try {
ser.serialize(cas, xmlSer.getContentHandler());
outputXCAS.close();
} catch (IOException e) {
e.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
}
// Deserialize XCAS
cas.reset();
InputStream inputXCAS = new FileInputStream(xcasFilename);
try {
XCASDeserializer.deserialize(inputXCAS, cas, false);
inputXCAS.close();
} catch (SAXException e2) {
e2.printStackTrace();
} catch (IOException e2) {
e2.printStackTrace();
}
// Delete the generated file.
File xcasFile = new File(xcasFilename);
if (xcasFile.exists()) {
assertTrue(xcasFile.delete());
}
// Add a new Sofa
// id.setSofaID("GermanDocument");
// Sofa gs = new Sofa(jcas, id, "text");
JCas gerJcas = jcas.createView("GermanDocument");
Sofa gs = gerJcas.getSofa();
assertTrue(3 == gs.getSofaRef());
// Set the document text
// gs.setLocalSofaData("das bier ist gut");
gerJcas.setDocumentText("das bier ist gut");