String whiteSpace = createIndentationString(indent);
SMNamespace namespace = annotationElement.getNamespace(
Annotation.URI_RDF_SYNTAX_NS, "rdf");
annotationElement.setIndentation(whiteSpace, indent, indentCount);
SMOutputElement rdfElement = annotationElement.addElement(namespace,
"RDF");
/*
* TODO: Check which name spaces are really required and add only those;
* particularly, if name spaces are missing and it is known from the
* kind of RDF annotation, which name spaces are needed, these should be
* added automatically here.
*/
Map<String, String> rdfNamespaces = annotation.getRDFAnnotationNamespaces();
for (String namespaceURI : rdfNamespaces.keySet()) {
if (!namespaceURI.equals(namespace.getURI())) {
writer.writeNamespace(rdfNamespaces.get(namespaceURI), namespaceURI);
}
}
// Checking if all the necessary namespaces are defined
// TODO: In fact, we could remove the rdfNamespaces map ?
if (rdfNamespaces.get(Annotation.URI_RDF_SYNTAX_NS) == null
|| rdfNamespaces.get(Annotation.URI_RDF_SYNTAX_NS).equals("xmlns"))
{
// writer.writeNamespace("rdf", Annotation.URI_RDF_SYNTAX_NS); // already registered previously
rdfNamespaces.put(Annotation.URI_RDF_SYNTAX_NS, "rdf");
}
if (annotation.isSetHistory() && annotation.getHistory().getCreatorCount() > 0)
{
if (rdfNamespaces.get(JSBML.URI_PURL_ELEMENTS) == null) {
writer.writeNamespace("dc", JSBML.URI_PURL_ELEMENTS);
rdfNamespaces.put(JSBML.URI_PURL_ELEMENTS, "dc");
}
if (rdfNamespaces.get(Creator.URI_RDF_VCARD_NS) == null) {
writer.writeNamespace("vCard", Creator.URI_RDF_VCARD_NS);
rdfNamespaces.put(Creator.URI_RDF_VCARD_NS, "vCard");
}
}
if (annotation.isSetHistory() && rdfNamespaces.get(JSBML.URI_PURL_TERMS) == null)
{
boolean isModelHistory = annotation.getParent() instanceof Model;
if (isModelHistory || (annotation.getHistory().isSetCreatedDate() || annotation.getHistory().isSetModifiedDate())) {
writer.writeNamespace("dcterms", JSBML.URI_PURL_TERMS);
rdfNamespaces.put(JSBML.URI_PURL_TERMS, "dcterms");
}
}
if (annotation.getCVTermCount() > 0)
{
if (rdfNamespaces.get(CVTerm.URI_BIOMODELS_NET_BIOLOGY_QUALIFIERS) == null) {
writer.writeNamespace("bqbiol", CVTerm.URI_BIOMODELS_NET_BIOLOGY_QUALIFIERS);
rdfNamespaces.put(CVTerm.URI_BIOMODELS_NET_BIOLOGY_QUALIFIERS, "bqbiol");
}
if (rdfNamespaces.get(CVTerm.URI_BIOMODELS_NET_MODEL_QUALIFIERS) == null) {
writer.writeNamespace("bqmodel", CVTerm.URI_BIOMODELS_NET_MODEL_QUALIFIERS);
rdfNamespaces.put(CVTerm.URI_BIOMODELS_NET_MODEL_QUALIFIERS, "bqmodel");
}
}
rdfElement.addCharacters("\n");
rdfElement.setIndentation(whiteSpace + createIndentationString(indentCount), indent + indentCount, indentCount);
SMOutputElement descriptionElement = rdfElement.addElement(namespace,
"Description");
descriptionElement.addAttribute(namespace, "about",
annotation.getAbout());
descriptionElement.addCharacters("\n");
if (annotation.isSetHistory()) {
writeHistory(annotation.getHistory(), rdfNamespaces, writer,
indent + 4);
}
if (annotation.getListOfCVTerms().size() > 0) {
writeCVTerms(annotation.getListOfCVTerms(), rdfNamespaces, writer,
indent + indentCount);
}
descriptionElement.setIndentation(whiteSpace + createIndentationString(indentCount), indent + indentCount, indentCount);
descriptionElement.addCharacters(whiteSpace + createIndentationString(indentCount));
annotationElement.setIndentation(whiteSpace, indent, indentCount);
rdfElement.addCharacters("\n");
rdfElement.addCharacters(whiteSpace);
annotationElement.addCharacters("\n");
}