public void processCas(CAS aCAS) throws ResourceProcessException {
JCas jcas;
try {
jcas = aCAS.getJCas();
} catch (CASException e) {
throw new ResourceProcessException(e);
}
// retrieve the filename of the input file from the CAS
File outFile = null;
boolean hasDefaultView = false;
if (mTEXT) {
// get the default View if it exists
try {
jcas = aCAS.getView(CAS.NAME_DEFAULT_SOFA).getJCas();
hasDefaultView = true;
FSIterator it = jcas.getAnnotationIndex(SourceDocumentInformation.type).iterator();
if (it.hasNext()) {
// get the output file name from the annotation in the CAS ...
// ... note this is a little flakey if processing an XCAS file,
// which could have such an annotation with a different name than the input XCAS file!
// So we don't do this if XCAS output is specified.
SourceDocumentInformation fileLoc = (SourceDocumentInformation) it.next();
File inFile;
inFile = new File(new URL(fileLoc.getUri()).getPath());
outFile = new File(mOutputDir, inFile.getName());
}
} catch (CASRuntimeException e) {
// default Sofa name does not exist, use default processing below
} catch (CASException e) {
// invalid something (??), use default processing below
} catch (MalformedURLException e1) {
// invalid URL, use default processing below
}
}
if (outFile == null) {
// default processing, create a name for the output file
outFile = new File(mOutputDir, "doc" + mDocNum++);
}
// convert CAS to xml format and write to output file in UTF-8
FileOutputStream outStream = null;
try {
outStream = new FileOutputStream(outFile);
if (hasDefaultView) {
String xmlAnnotations = cas2xml.generateXML(aCAS);
outStream.write(xmlAnnotations.getBytes("UTF-8"));
} else {
XMLSerializer xmlSer = new XMLSerializer(outStream, false);
if (mXCAS.equalsIgnoreCase("xcas")) {
XCASSerializer ser = new XCASSerializer(aCAS.getTypeSystem());
ser.serialize(aCAS, xmlSer.getContentHandler());
}
else {
XmiCasSerializer ser = new XmiCasSerializer(aCAS.getTypeSystem());
ser.serialize(aCAS, xmlSer.getContentHandler());
}
}
} catch (CASException e) {
throw new ResourceProcessException(e);
} catch (IOException e) {
throw new ResourceProcessException(e);
} catch (SAXException e) {
throw new ResourceProcessException(e);
} finally {
if (outStream != null) {
try {
outStream.close();
} catch (IOException e) {