Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions core/src/org/sbml/jsbml/xml/RDFConstants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* ----------------------------------------------------------------------------
* This file is part of JSBML. Please visit <http://sbml.org/Software/JSBML>
* for the latest version of JSBML and more information about SBML.
*
* Copyright (C) 2009-2022 jointly by the following organizations:
* 1. The University of Tuebingen, Germany
* 2. EMBL European Bioinformatics Institute (EBML-EBI), Hinxton, UK
* 3. The California Institute of Technology, Pasadena, CA, USA
* 4. The University of California, San Diego, La Jolla, CA, USA
* 5. The Babraham Institute, Cambridge, UK
* * This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online as <http://sbml.org/Software/JSBML/License>.
* ----------------------------------------------------------------------------
*/

package org.sbml.jsbml.xml;

/**
* Centralized constants for RDF and XHTML keywords used in SBML annotations.
* * @author Deepak Yadav
* @since 1.7
*/
public final class RDFConstants {

/** The RDF namespace prefix. */
public static final String PREFIX_RDF = "rdf";

/** The Dublin Core namespace prefix. */
public static final String PREFIX_DC = "dc";

/** The Dublin Core Terms namespace prefix. */
public static final String PREFIX_DCTERMS = "dcterms";

/** The vCard namespace prefix. */
public static final String PREFIX_VCARD = "vCard";

/** The Biology Qualifiers namespace prefix. */
public static final String PREFIX_BQBIOL = "bqbiol";

/** The Model Qualifiers namespace prefix. */
public static final String PREFIX_BQMODEL = "bqmodel";

/** The RDF 'RDF' element name. */
public static final String RDF = "RDF";

/** The RDF 'Description' element name. */
public static final String DESCRIPTION = "Description";

/** The RDF 'Bag' element name. */
public static final String BAG = "Bag";

/** The RDF 'li' element name. */
public static final String LI = "li";

/** The RDF 'about' attribute name. */
public static final String ABOUT = "about";

/** The RDF 'resource' attribute name. */
public static final String RESOURCE = "resource";

/** The RDF 'parseType' attribute name. */
public static final String PARSE_TYPE = "parseType";

/** Private constructor to prevent instantiation. */
private RDFConstants() {
}
}
25 changes: 13 additions & 12 deletions core/src/org/sbml/jsbml/xml/parsers/SBMLRDFAnnotationParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.sbml.jsbml.xml.XMLAttributes;
import org.sbml.jsbml.xml.XMLNode;
import org.sbml.jsbml.xml.XMLTriple;
import org.sbml.jsbml.xml.RDFConstants;
import org.sbml.jsbml.xml.parsers.SBMLRDFAnnotationParser.NODE_COLOR;
import org.w3c.util.DateParser;
import org.w3c.util.InvalidDateException;
Expand Down Expand Up @@ -169,7 +170,7 @@ private NODE_COLOR isValidRDF(XMLNode annotationXMLNode) {
return NODE_COLOR.WHITE;
}

XMLNode rdfNode = annotationXMLNode.getChildElement("RDF", Annotation.URI_RDF_SYNTAX_NS);
XMLNode rdfNode = annotationXMLNode.getChildElement(RDFConstants.RDF, Annotation.URI_RDF_SYNTAX_NS);

return isValidRDFDescription(rdfNode);
}
Expand All @@ -189,7 +190,7 @@ private NODE_COLOR isValidRDFDescription(XMLNode rdfNode) {
}

NODE_COLOR rdfNodeColor = null;
List<XMLNode> descriptionNodes = rdfNode.getChildElements("Description", Annotation.URI_RDF_SYNTAX_NS);
List<XMLNode> descriptionNodes = rdfNode.getChildElements(RDFConstants.DESCRIPTION, Annotation.URI_RDF_SYNTAX_NS);

if (descriptionNodes == null || descriptionNodes.size() == 0) {
rdfNodeColor = NODE_COLOR.WHITE;
Expand Down Expand Up @@ -274,10 +275,10 @@ private NODE_COLOR isValidCreator(XMLNode creatorNode) {

// dc:creator->rdf:Bag->rdf:li*->VCard:stuff*
NODE_COLOR wholeColor = NODE_COLOR.GREEN;
XMLNode bagNode = creatorNode.getChildElement("Bag", Annotation.URI_RDF_SYNTAX_NS);
XMLNode bagNode = creatorNode.getChildElement(RDFConstants.BAG, Annotation.URI_RDF_SYNTAX_NS);

if (bagNode != null) {
List<XMLNode> liNodes = bagNode.getChildElements("li", Annotation.URI_RDF_SYNTAX_NS);
List<XMLNode> liNodes = bagNode.getChildElements(RDFConstants.LI, Annotation.URI_RDF_SYNTAX_NS);

if (liNodes != null && liNodes.size() > 0) {

Expand Down Expand Up @@ -509,7 +510,7 @@ private void readSBMLRDF(SBase contextObject)
readRDFURIs(contextObject, descriptionNode);
readRDFHistory(contextObject, descriptionNode);

contextObject.getAnnotation().setAbout(descriptionNode.getAttrValue("about", Annotation.URI_RDF_SYNTAX_NS));
contextObject.getAnnotation().setAbout(descriptionNode.getAttrValue(RDFConstants.ABOUT, Annotation.URI_RDF_SYNTAX_NS));

descriptionNode.removeAttr("about", Annotation.URI_RDF_SYNTAX_NS);
boolean removed = removeXmlNodeIfEmpty(descriptionNode);
Expand All @@ -520,9 +521,9 @@ private void readSBMLRDF(SBase contextObject)

if (nbChildElements > 0 || nbAttributes > 0) {
// removing the usual namespace declarations if the node is empty
rdfNode.removeNamespace("rdf");
rdfNode.removeNamespace("dc");
rdfNode.removeNamespace("dcterms");
rdfNode.removeNamespace(RDFConstants.PREFIX_RDF);
rdfNode.removeNamespace(RDFConstants.PREFIX_DC);
rdfNode.removeNamespace(RDFConstants.PREFIX_DCTERMS);
rdfNode.removeNamespace("vcard");
rdfNode.removeNamespace("vCard");
rdfNode.removeNamespace("bqbiol");
Expand Down Expand Up @@ -1268,7 +1269,7 @@ private XMLNode writeSBMLRDF(SBase contextObject, XMLNode annotationXMLNode)
annotationXMLNode = new XMLNode(new XMLTriple("annotation"), new XMLAttributes());
}

XMLNode rdfNode = getOrCreate(annotationXMLNode, "RDF", Annotation.URI_RDF_SYNTAX_NS, "rdf");
XMLNode rdfNode = getOrCreate(annotationXMLNode, RDFConstants.RDF, Annotation.URI_RDF_SYNTAX_NS, RDFConstants.PREFIX_RDF);
rdfNode.addNamespace(Annotation.URI_RDF_SYNTAX_NS, "rdf");

// writing only the needed namespaces
Expand All @@ -1279,7 +1280,7 @@ private XMLNode writeSBMLRDF(SBase contextObject, XMLNode annotationXMLNode)
if (contextObject.isSetHistory() &&
(contextObject.getHistory().isSetCreatedDate() || contextObject.getHistory().isSetModifiedDate()))
{
rdfNode.addNamespace(JSBML.URI_PURL_TERMS, "dcterms");
rdfNode.addNamespace(JSBML.URI_PURL_TERMS, RDFConstants.PREFIX_DCTERMS);
}
if (contextObject.getCVTermCount() > 0) {
boolean needBqModel = false;
Expand Down Expand Up @@ -1307,7 +1308,7 @@ private XMLNode writeSBMLRDF(SBase contextObject, XMLNode annotationXMLNode)

// check if the rdf:about value is correct
checkAbout(contextObject);
descriptionNode.addAttr("about", contextObject.getAnnotation().getAbout(), Annotation.URI_RDF_SYNTAX_NS, "rdf");
descriptionNode.addAttr(RDFConstants.ABOUT, contextObject.getAnnotation().getAbout(), Annotation.URI_RDF_SYNTAX_NS, RDFConstants.PREFIX_RDF);

writeHistory(contextObject, descriptionNode);
writeURIs(contextObject, descriptionNode);
Expand Down Expand Up @@ -1932,4 +1933,4 @@ private void writeCVTerm(CVTerm cvterm, XMLNode parentNode,
writeURIs(cvterm, bagNode);
}

}
}