From e06f8556d684ccaadbde70d2d90642fbcc068745 Mon Sep 17 00:00:00 2001 From: dyrpsf Date: Sat, 14 Mar 2026 10:06:11 +0530 Subject: [PATCH] Centralize RDF and XHTML keywords into RDFConstants (#288) --- core/src/org/sbml/jsbml/xml/RDFConstants.java | 71 +++++++++++++++++++ .../xml/parsers/SBMLRDFAnnotationParser.java | 25 +++---- 2 files changed, 84 insertions(+), 12 deletions(-) create mode 100644 core/src/org/sbml/jsbml/xml/RDFConstants.java diff --git a/core/src/org/sbml/jsbml/xml/RDFConstants.java b/core/src/org/sbml/jsbml/xml/RDFConstants.java new file mode 100644 index 000000000..c123982ee --- /dev/null +++ b/core/src/org/sbml/jsbml/xml/RDFConstants.java @@ -0,0 +1,71 @@ +/* + * ---------------------------------------------------------------------------- + * This file is part of JSBML. Please visit + * 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 . + * ---------------------------------------------------------------------------- + */ + +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() { + } +} \ No newline at end of file diff --git a/core/src/org/sbml/jsbml/xml/parsers/SBMLRDFAnnotationParser.java b/core/src/org/sbml/jsbml/xml/parsers/SBMLRDFAnnotationParser.java index b274ea575..173a19648 100644 --- a/core/src/org/sbml/jsbml/xml/parsers/SBMLRDFAnnotationParser.java +++ b/core/src/org/sbml/jsbml/xml/parsers/SBMLRDFAnnotationParser.java @@ -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; @@ -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); } @@ -189,7 +190,7 @@ private NODE_COLOR isValidRDFDescription(XMLNode rdfNode) { } NODE_COLOR rdfNodeColor = null; - List descriptionNodes = rdfNode.getChildElements("Description", Annotation.URI_RDF_SYNTAX_NS); + List descriptionNodes = rdfNode.getChildElements(RDFConstants.DESCRIPTION, Annotation.URI_RDF_SYNTAX_NS); if (descriptionNodes == null || descriptionNodes.size() == 0) { rdfNodeColor = NODE_COLOR.WHITE; @@ -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 liNodes = bagNode.getChildElements("li", Annotation.URI_RDF_SYNTAX_NS); + List liNodes = bagNode.getChildElements(RDFConstants.LI, Annotation.URI_RDF_SYNTAX_NS); if (liNodes != null && liNodes.size() > 0) { @@ -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); @@ -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"); @@ -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 @@ -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; @@ -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); @@ -1932,4 +1933,4 @@ private void writeCVTerm(CVTerm cvterm, XMLNode parentNode, writeURIs(cvterm, bagNode); } -} +} \ No newline at end of file