* @throws CoreException
*/
public static void serialize(DotCorpus dotCorpus, OutputStream out) throws CoreException {
XMLSerializer xmlSerializer = new XMLSerializer(out, true);
ContentHandler xmlSerHandler = xmlSerializer.getContentHandler();
try {
xmlSerHandler.startDocument();
xmlSerHandler.startElement("", CONFIG_ELEMENT, CONFIG_ELEMENT, new AttributesImpl());
for (String corpusFolder : dotCorpus.getCorpusFolderNameList()) {
AttributesImpl corpusFolderAttributes = new AttributesImpl();
corpusFolderAttributes.addAttribute("", "",CORPUS_FOLDER_ATTRIBUTE, "", corpusFolder);
xmlSerHandler.startElement("", CORPUS_ELEMENT, CORPUS_ELEMENT, corpusFolderAttributes);
xmlSerHandler.endElement("", CORPUS_ELEMENT, CORPUS_ELEMENT);
}
for (AnnotationStyle style : dotCorpus.getAnnotationStyles()) {
AttributesImpl styleAttributes = new AttributesImpl();
styleAttributes
.addAttribute("", "", STYLE_TYPE_ATTRIBUTE, "", style.getAnnotation());
styleAttributes.addAttribute("", "", STYLE_STYLE_ATTRIBUTE, "", style.getStyle()
.name());
Color color = style.getColor();
Integer colorInt = new Color(color.getRed(), color.getGreen(), color.getBlue()).getRGB();
styleAttributes.addAttribute("", "", STYLE_COLOR_ATTRIBUTE, "", colorInt.toString());
styleAttributes.addAttribute("", "", STYLE_LAYER_ATTRIBUTE, "",
Integer.toString(style.getLayer()));
xmlSerHandler.startElement("", STYLE_ELEMENT, STYLE_ELEMENT, styleAttributes);
xmlSerHandler.endElement("", STYLE_ELEMENT, STYLE_ELEMENT);
}
if (dotCorpus.getTypeSystemFileName() != null) {
AttributesImpl typeSystemFileAttributes = new AttributesImpl();
typeSystemFileAttributes.addAttribute("", "", TYPESYTEM_FILE_ATTRIBUTE, "", dotCorpus
.getTypeSystemFileName());
xmlSerHandler.startElement("", TYPESYSTEM_ELEMENT, TYPESYSTEM_ELEMENT, typeSystemFileAttributes);
xmlSerHandler.endElement("", TYPESYSTEM_ELEMENT, TYPESYSTEM_ELEMENT);
}
for (String folder : dotCorpus.getCasProcessorFolderNames()) {
AttributesImpl taggerConfigAttributes = new AttributesImpl();
taggerConfigAttributes.addAttribute("", "", CAS_PROCESSOR_FOLDER_ATTRIBUTE, "", folder);
xmlSerHandler.startElement("", CAS_PROCESSOR_ELEMENT, CAS_PROCESSOR_ELEMENT, taggerConfigAttributes);
xmlSerHandler.endElement("", CAS_PROCESSOR_ELEMENT, CAS_PROCESSOR_ELEMENT);
}
if (dotCorpus.getEditorLineLengthHint() != DotCorpus.EDITOR_LINE_LENGTH_HINT_DEFAULT) {
AttributesImpl editorLineLengthHintAttributes = new AttributesImpl();
editorLineLengthHintAttributes.addAttribute("", "", EDITOR_LINE_LENGTH_ATTRIBUTE, "",
Integer.toString(dotCorpus.getEditorLineLengthHint()));
xmlSerHandler.startElement("", EDITOR_ELEMENT, EDITOR_ELEMENT, editorLineLengthHintAttributes);
xmlSerHandler.endElement("", EDITOR_ELEMENT, EDITOR_ELEMENT);
}
xmlSerHandler.endElement("", CONFIG_ELEMENT, CONFIG_ELEMENT);
xmlSerHandler.endDocument();
} catch (SAXException e) {
String message = (e.getMessage() != null ? e.getMessage() : "");
IStatus s = new Status(IStatus.ERROR, CasEditorPlugin.ID, IStatus.OK, message, e);
throw new CoreException(s);