attrs.addAttribute("", "_indexed", "_indexed", "CDATA", indexedStr.toString());
}
String[] features = aFS.getFeatureNames();
for (int i = 0; i < features.length; i++) {
FeatureValue featVal = aFS.getFeatureValue(features[i]);
if (featVal instanceof PrimitiveValue) {
if (!"value".equals(features[i])) {
attrs.addAttribute("", features[i], features[i], "CDATA", featVal.toString());
} else {
contentValue = featVal.toString();
}
} else {
if (!"value".equals(features[i])) {
attrs.addAttribute("", "_ref_" + features[i], "_ref_" + features[i], "CDATA",
((ReferenceValue) featVal).getTargetId());
} else {
contentValue = ((ReferenceValue) featVal).getTargetId();
}
}
}
String xcasElementName = getXCasElementName(aFS);
mHandler.startElement("", xcasElementName, xcasElementName, attrs);
// encode array subelements
String[] arrayElems = null;
if (aFS instanceof PrimitiveArrayFS) {
arrayElems = ((PrimitiveArrayFS) aFS).toStringArray();
} else if (aFS instanceof ReferenceArrayFS) {
arrayElems = ((ReferenceArrayFS) aFS).getIdRefArray();
}
if (arrayElems != null) {
for (int j = 0; j < arrayElems.length; j++) {
mHandler.startElement("", "i", "i", new AttributesImpl());
if (arrayElems[j] != null) {
mHandler.characters(arrayElems[j].toCharArray(), 0, arrayElems[j].length());
}
mHandler.endElement("", "i", "i");
}
}
// encode "value" feature, if specified, as content
if (contentValue != null) {
mHandler.characters(contentValue.toCharArray(), 0, contentValue.length());
}
// encode annotation spanned text, if this FS has valid begin and end features
else if (mIncludeAnnotationSpannedText && aDocTextHolder.docText != null
&& aDocTextHolder.docText.length > 0) {
FeatureValue begin = aFS.getFeatureValue("begin");
FeatureValue end = aFS.getFeatureValue("end");
if (begin instanceof PrimitiveValue && end instanceof PrimitiveValue) {
int beginChar = ((PrimitiveValue) begin).toInt();
int endChar = ((PrimitiveValue) end).toInt();
if (beginChar >= 0 && endChar > beginChar && endChar <= aDocTextHolder.docText.length) {
// special case: do not include text of annotations spanning entire document