Package org.spdx.rdfparser
Class SpdxDocumentContainer
java.lang.Object
org.spdx.rdfparser.SpdxDocumentContainer
- All Implemented Interfaces:
IModelContainer,SpdxRdfConstants
public class SpdxDocumentContainer extends Object implements IModelContainer, SpdxRdfConstants
This class contains the SPDX Document and provides some of the basic
RDF model support. This class also manages the SpdxRef, ExtractedLicenseInfos,
and LicenseRefs.
Separating the container aspects of the SpdxDocument into this separate
class allows for the SpdxDocument to follow the rdfparser.model pattern.
- Author:
- Gary O'Neall
-
Field Summary
Fields Modifier and Type Field Description static StringCURRENT_IMPLEMENTATION_VERSIONstatic StringCURRENT_SPDX_VERSIONprotected intnextLicenseRefKeeps tract of the next license reference number when generating the license ID's for non-standard licensesstatic StringONE_DOT_ONE_SPDX_VERSIONstatic StringONE_DOT_TWO_SPDX_VERSIONstatic StringONE_DOT_ZERO_SPDX_VERSIONstatic StringPOINT_EIGHT_SPDX_VERSIONstatic StringPOINT_NINE_SPDX_VERSIONstatic StringTWO_POINT_ONE_VERSIONstatic StringTWO_POINT_TWO_VERSIONstatic StringTWO_POINT_ZERO_VERSIONFields inherited from interface org.spdx.rdfparser.SpdxRdfConstants
ALGORITHM_SHA1, CLASS_ANNOTATION, CLASS_CROSS_REF, CLASS_DOAP_PROJECT, CLASS_EXTERNAL_DOC_REF, CLASS_OR_LATER_OPERATOR, CLASS_POINTER_BYTE_OFFSET_POINTER, CLASS_POINTER_LINE_CHAR_POINTER, CLASS_POINTER_START_END_POINTER, CLASS_RELATIONSHIP, CLASS_SPDX_ANY_LICENSE_INFO, CLASS_SPDX_CHECKSUM, CLASS_SPDX_CONJUNCTIVE_LICENSE_SET, CLASS_SPDX_CREATION_INFO, CLASS_SPDX_DISJUNCTIVE_LICENSE_SET, CLASS_SPDX_DOCUMENT, CLASS_SPDX_ELEMENT, CLASS_SPDX_EXTERNAL_REFERENCE, CLASS_SPDX_EXTRACTED_LICENSING_INFO, CLASS_SPDX_FILE, CLASS_SPDX_ITEM, CLASS_SPDX_LICENSE, CLASS_SPDX_LICENSE_EXCEPTION, CLASS_SPDX_NOASSERTION_ELEMENT, CLASS_SPDX_NONE_ELEMENT, CLASS_SPDX_PACKAGE, CLASS_SPDX_REFERENCE_TYPE, CLASS_SPDX_REVIEW, CLASS_SPDX_SIMPLE_LICENSE_INFO, CLASS_SPDX_SNIPPET, CLASS_SPDX_VERIFICATIONCODE, CLASS_WITH_EXCEPTION_OPERATOR, CREATOR_PREFIX_ORGANIZATION, CREATOR_PREFIX_PERSON, CREATOR_PREFIX_TOOL, DOAP_NAMESPACE, EXTERNAL_DOC_REF_PATTERN, EXTERNAL_DOC_REF_PRENUM, EXTERNAL_ELEMENT_REF_PATTERN, FILE_TYPE_ARCHIVE, FILE_TYPE_BINARY, FILE_TYPE_OTHER, FILE_TYPE_SOURCE, LICENSE_ID_PATTERN, LICENSE_ID_PATTERN_NUMERIC, LICENSEXML_ATTRIBUTE_ALT_MATCH, LICENSEXML_ATTRIBUTE_ALT_NAME, LICENSEXML_ATTRIBUTE_DEPRECATED, LICENSEXML_ATTRIBUTE_DEPRECATED_VERSION, LICENSEXML_ATTRIBUTE_FSF_LIBRE, LICENSEXML_ATTRIBUTE_ID, LICENSEXML_ATTRIBUTE_LIST_VERSION_ADDED, LICENSEXML_ATTRIBUTE_NAME, LICENSEXML_ATTRIBUTE_OSI_APPROVED, LICENSEXML_ELEMENT_ALT, LICENSEXML_ELEMENT_BREAK, LICENSEXML_ELEMENT_BULLET, LICENSEXML_ELEMENT_COPYRIGHT_TEXT, LICENSEXML_ELEMENT_CROSS_REF, LICENSEXML_ELEMENT_CROSS_REFS, LICENSEXML_ELEMENT_EXCEPTION, LICENSEXML_ELEMENT_ITEM, LICENSEXML_ELEMENT_LICENSE, LICENSEXML_ELEMENT_LICENSE_COLLECTION, LICENSEXML_ELEMENT_LIST, LICENSEXML_ELEMENT_NOTES, LICENSEXML_ELEMENT_OPTIONAL, LICENSEXML_ELEMENT_PARAGRAPH, LICENSEXML_ELEMENT_STANDARD_LICENSE_HEADER, LICENSEXML_ELEMENT_TEXT, LICENSEXML_ELEMENT_TITLE_TEXT, LICENSEXML_URI, NOASSERTION_VALUE, NON_STD_LICENSE_ID_PRENUM, NONE_VALUE, OWL_NAMESPACE, PROP_ANNOTATION, PROP_ANNOTATION_DATE, PROP_ANNOTATION_TYPE, PROP_ANNOTATOR, PROP_ATTRIBUTION_TEXT, PROP_CHECKSUM_ALGORITHM, PROP_CHECKSUM_ALGORITHM_SHA1, PROP_CHECKSUM_VALUE, PROP_COPYRIGHT_TEXT, PROP_CREATION_CREATED, PROP_CREATION_CREATOR, PROP_CROSS_REF_IS_LIVE, PROP_CROSS_REF_IS_VALID, PROP_CROSS_REF_MATCH, PROP_CROSS_REF_ORDER, PROP_CROSS_REF_TIMESTAMP, PROP_CROSS_REF_URL, PROP_CROSS_REF_WAYBACK_LINK, PROP_EXAMPLE, PROP_EXCEPTION_TEMPLATE, PROP_EXCEPTION_TEXT, PROP_EXTERNAL_DOC_CHECKSUM, PROP_EXTERNAL_DOC_ID, PROP_EXTERNAL_REF, PROP_EXTERNAL_SPDX_DOCUMENT, PROP_EXTRACTED_TEXT, PROP_FILE_ARTIFACTOF, PROP_FILE_CHECKSUM, PROP_FILE_CONTRIBUTOR, PROP_FILE_COPYRIGHT, PROP_FILE_FILE_DEPENDENCY, PROP_FILE_LIC_COMMENTS, PROP_FILE_LICENSE, PROP_FILE_NAME, PROP_FILE_NOTICE, PROP_FILE_SEEN_LICENSE, PROP_FILE_TYPE, PROP_FILE_TYPE_ARCHIVE, PROP_FILE_TYPE_BINARY, PROP_FILE_TYPE_OTHER, PROP_FILE_TYPE_SOURCE, PROP_LIC_COMMENTS, PROP_LIC_ID_DEPRECATED, PROP_LICENSE_CONCLUDED, PROP_LICENSE_DECLARED, PROP_LICENSE_EXCEPTION, PROP_LICENSE_EXCEPTION_ID, PROP_LICENSE_ID, PROP_LICENSE_INFO_FROM_SNIPPETS, PROP_LICENSE_LIST_VERSION, PROP_LICENSE_NAME, PROP_LICENSE_SET_MEMEBER, PROP_LICENSE_TEXT, PROP_NAME, PROP_OWL_SAME_AS, PROP_PACKAGE_CHECKSUM, PROP_PACKAGE_CONCLUDED_LICENSE, PROP_PACKAGE_DECLARED_COPYRIGHT, PROP_PACKAGE_DECLARED_LICENSE, PROP_PACKAGE_DECLARED_NAME, PROP_PACKAGE_DESCRIPTION, PROP_PACKAGE_DOWNLOAD_URL, PROP_PACKAGE_FILE, PROP_PACKAGE_FILE_NAME, PROP_PACKAGE_FILES_ANALYZED, PROP_PACKAGE_LICENSE_COMMENT, PROP_PACKAGE_LICENSE_INFO_FROM_FILES, PROP_PACKAGE_ORIGINATOR, PROP_PACKAGE_SHORT_DESC, PROP_PACKAGE_SOURCE_INFO, PROP_PACKAGE_SUPPLIER, PROP_PACKAGE_VERIFICATION_CODE, PROP_PACKAGE_VERSION_INFO, PROP_POINTER_END_POINTER, PROP_POINTER_LINE_NUMBER, PROP_POINTER_OFFSET, PROP_POINTER_REFERENCE, PROP_POINTER_START_POINTER, PROP_PROJECT_HOMEPAGE, PROP_PROJECT_NAME, PROP_REFERENCE_CATEGORY, PROP_REFERENCE_LOCATOR, PROP_REFERENCE_TYPE, PROP_RELATED_SPDX_ELEMENT, PROP_RELATIONSHIP, PROP_RELATIONSHIP_TYPE, PROP_REVIEW_DATE, PROP_REVIEW_REVIEWER, PROP_SNIPPET_FROM_FILE, PROP_SNIPPET_RANGE, PROP_SPDX_CREATION_INFO, PROP_SPDX_DATA_LICENSE, PROP_SPDX_EXTERNAL_DOC_REF, PROP_SPDX_EXTRACTED_LICENSES, PROP_SPDX_FILE_REFERENCE, PROP_SPDX_PACKAGE, PROP_SPDX_REVIEWED_BY, PROP_SPDX_VERSION, PROP_STD_LICENSE_FSF_LIBRE, PROP_STD_LICENSE_HEADER_TEMPLATE, PROP_STD_LICENSE_HEADER_VERSION_1, PROP_STD_LICENSE_NAME, PROP_STD_LICENSE_NAME_VERSION_1, PROP_STD_LICENSE_NOTES_VERSION_1, PROP_STD_LICENSE_NOTICE, PROP_STD_LICENSE_OSI_APPROVED, PROP_STD_LICENSE_OSI_APPROVED_VERSION_1, PROP_STD_LICENSE_TEMPLATE, PROP_STD_LICENSE_TEMPLATE_VERSION_1, PROP_STD_LICENSE_URL_VERSION_1, PROP_VALUE_NOASSERTION, PROP_VALUE_NONE, PROP_VERIFICATIONCODE_IGNORED_FILES, PROP_VERIFICATIONCODE_VALUE, RDF_NAMESPACE, RDF_POINTER_NAMESPACE, RDF_PROP_RESOURCE, RDF_PROP_TYPE, RDFS_NAMESPACE, RDFS_PROP_COMMENT, RDFS_PROP_LABEL, RDFS_PROP_SEE_ALSO, SPDX_DATA_LICENSE_ID, SPDX_DATA_LICENSE_ID_VERSION_1_0, SPDX_DATE_FORMAT, SPDX_DOCUMENT_ID, SPDX_ELEMENT_REF_PATTERN, SPDX_ELEMENT_REF_PRENUM, SPDX_LISTED_REFERENCE_TYPES_PREFIX, SPDX_NAMESPACE, SPDX_VERSION_PATTERN, STANDARD_LICENSE_URL, TERM_ELEMENT_NOASSERTION, TERM_ELEMENT_NONE, TERM_LICENSE_NOASSERTION, TERM_LICENSE_NONE, URI_VALUE_NOASSERTION, URI_VALUE_NONE -
Constructor Summary
Constructors Constructor Description SpdxDocumentContainer(String uri)Creates a new empty SPDX Document with the current SPDX document version.SpdxDocumentContainer(String uri, String spdxVersion)Creates a new empty SPDX Document.SpdxDocumentContainer(org.apache.jena.rdf.model.Model model)Construct an SpdxDocumentContainer from an existing model which already contain an SPDX Document -
Method Summary
Modifier and Type Method Description booleanaddCheckNodeObject(org.apache.jena.graph.Node node, IRdfModel nodeObject)Add a node object to the container.voidaddElement(SpdxElement element)Add an SPDX element directly to the model without connecting it to any propertiesvoidaddExtractedLicenseInfos(ExtractedLicenseInfo license)ExtractedLicenseInfoaddNewExtractedLicenseInfo(String licenseText)Adds a new non-standard license containing the text provided.voidaddNewExtractedLicenseInfo(ExtractedLicenseInfo license)Adds the license as a new ExtractedLicenseInfovoidaddSpdxElementRef(String elementRef)Notifies the model container that a new element ref is in use.org.apache.jena.rdf.model.ResourcecreateResource(org.apache.jena.rdf.model.Resource duplicate, String uri, org.apache.jena.rdf.model.Resource type, IRdfModel nodeObject)Create a resource in the modelStringdocumentNamespaceToId(String externalNamespace)Translate an external document namespace URI to an external document IDStringexternalDocumentIdToNamespace(String docId)Translate an external document ID to the external document's namespacebooleanextractedLicenseExists(String id)List<SpdxElement>findAllElements()Returns all elements in the containsList<SpdxFile>findAllFiles()List<SpdxPackage>findAllPackages()List<SpdxSnippet>findAllSnippets()SpdxElementfindElementById(String id)Find an element within the container by the SPDX Identifier.static StringformNonStandardLicenseID(int idNum)static StringformSpdxElementRef(int refNum)StringgetDocumentNamespace()static intgetElementRefNumber(String elementReference)Parses out the reference number for an SPDX element referenceExternalDocumentRef[]getExternalDocumentRefs()ExtractedLicenseInfogetExtractedLicense(String id)ExtractedLicenseInfo[]getExtractedLicenseInfos()voidgetExtractedLicenseInfosFromModel()Get Update the extrated license infos from the model and resynchronize it with the license cache.SpdxFile[]getFileReferences()get all file references contained within the containerintgetLicenseRefNum(String licenseID)Parses a license ID and return the integer representing the ID number (e.g.org.apache.jena.rdf.model.ModelgetModel()StringgetNextLicenseRef()StringgetNextSpdxElementRef()SpdxDocumentgetSpdxDocument()voidinitializeNextLicenseRef()Initialize the next license reference and the cache of extracted license infosvoidsetExternalDocumentRefs(ExternalDocumentRef[] externalDocumentRefs)voidsetExtractedLicenseInfos(ExtractedLicenseInfo[] extractedLicenseInfos)booleanspdxElementRefExists(String elementRef)Returns true if the element reference already exists in the modelStringverifySpdxVersion(String spdxVersion)
-
Field Details
-
POINT_EIGHT_SPDX_VERSION
- See Also:
- Constant Field Values
-
POINT_NINE_SPDX_VERSION
- See Also:
- Constant Field Values
-
ONE_DOT_ZERO_SPDX_VERSION
- See Also:
- Constant Field Values
-
ONE_DOT_ONE_SPDX_VERSION
- See Also:
- Constant Field Values
-
ONE_DOT_TWO_SPDX_VERSION
- See Also:
- Constant Field Values
-
TWO_POINT_ZERO_VERSION
- See Also:
- Constant Field Values
-
TWO_POINT_ONE_VERSION
- See Also:
- Constant Field Values
-
TWO_POINT_TWO_VERSION
- See Also:
- Constant Field Values
-
CURRENT_SPDX_VERSION
- See Also:
- Constant Field Values
-
CURRENT_IMPLEMENTATION_VERSION
- See Also:
- Constant Field Values
-
nextLicenseRef
protected int nextLicenseRefKeeps tract of the next license reference number when generating the license ID's for non-standard licenses
-
-
Constructor Details
-
SpdxDocumentContainer
public SpdxDocumentContainer(org.apache.jena.rdf.model.Model model) throws InvalidSPDXAnalysisExceptionConstruct an SpdxDocumentContainer from an existing model which already contain an SPDX Document- Parameters:
model-- Throws:
InvalidSPDXAnalysisException
-
SpdxDocumentContainer
Creates a new empty SPDX Document with the current SPDX document version. Note: Follow-up calls MUST be made to add the required properties for this to be a valid SPDX document- Parameters:
uri- URI for the SPDX Document- Throws:
InvalidSPDXAnalysisException
-
SpdxDocumentContainer
Creates a new empty SPDX Document. Note: Follow-up calls MUST be made to add the required properties for this to be a valid SPDX document- Parameters:
uri- URI for the SPDX DocumentspdxVersion- The version of SPDX analysis to create (impacts the data license for some versions)- Throws:
InvalidSPDXAnalysisException
-
-
Method Details
-
getModel
public org.apache.jena.rdf.model.Model getModel()- Specified by:
getModelin interfaceIModelContainer- Returns:
- the RDF model
-
getDocumentNamespace
- Specified by:
getDocumentNamespacein interfaceIModelContainer- Returns:
- Namespace for document
-
getElementRefNumber
Parses out the reference number for an SPDX element reference- Parameters:
elementReference- Element reference to parse- Returns:
- element reference or -1 if the element reference is not valid
-
findElementById
Find an element within the container by the SPDX Identifier. Returns null if the element does not exist in the container.- Parameters:
id-- Returns:
- Throws:
InvalidSPDXAnalysisException
-
verifySpdxVersion
-
getSpdxDocument
- Returns:
-
getNextSpdxElementRef
- Specified by:
getNextSpdxElementRefin interfaceIModelContainer- Returns:
- return the next available SPDX element reference.
-
formSpdxElementRef
-
spdxElementRefExists
Description copied from interface:IModelContainerReturns true if the element reference already exists in the model- Specified by:
spdxElementRefExistsin interfaceIModelContainer- Returns:
-
addSpdxElementRef
Description copied from interface:IModelContainerNotifies the model container that a new element ref is in use. This must be called for all new element references to prevent duplication of elements.- Specified by:
addSpdxElementRefin interfaceIModelContainer- Throws:
InvalidSPDXAnalysisException
-
initializeNextLicenseRef
Initialize the next license reference and the cache of extracted license infos- Throws:
InvalidSPDXAnalysisException
-
getNextLicenseRef
- Returns:
- next available license ID for an ExtractedLicenseInfo
-
getLicenseRefNum
Parses a license ID and return the integer representing the ID number (e.g. N in LicenseRef-N) Note that in SPDX 1.2, non-numeric license IDs are allowed. This method will throw a NonNumericException if a non numeric license ID passed as a licenseID parameter- Parameters:
licenseID-- Returns:
- Throws:
NonNumericLicenseIdException- If the non-standard license ID is not of the form LicenseRef-NN
-
formNonStandardLicenseID
-
addNewExtractedLicenseInfo
public ExtractedLicenseInfo addNewExtractedLicenseInfo(String licenseText) throws InvalidSPDXAnalysisExceptionAdds a new non-standard license containing the text provided. Forms the license ID from the next License ID available- Parameters:
licenseText-- Returns:
- the newly created NonStandardLicense
- Throws:
InvalidSPDXAnalysisException
-
addNewExtractedLicenseInfo
public void addNewExtractedLicenseInfo(ExtractedLicenseInfo license) throws InvalidSPDXAnalysisExceptionAdds the license as a new ExtractedLicenseInfo- Parameters:
license-- Throws:
InvalidSPDXAnalysisException
-
extractedLicenseExists
- Parameters:
id-- Returns:
- true if the license ID is already in the model as an extracted license info
- Throws:
InvalidSPDXAnalysisException
-
getExtractedLicense
- Parameters:
id-- Returns:
- true if the license ID is already in the model as an extracted license info
- Throws:
InvalidSPDXAnalysisException
-
getExtractedLicenseInfosFromModel
Get Update the extrated license infos from the model and resynchronize it with the license cache.- Throws:
InvalidSPDXAnalysisException
-
getExtractedLicenseInfos
- Returns:
-
setExtractedLicenseInfos
public void setExtractedLicenseInfos(ExtractedLicenseInfo[] extractedLicenseInfos) throws InvalidSPDXAnalysisException- Parameters:
extractedLicenseInfos-- Throws:
InvalidSPDXAnalysisException
-
addExtractedLicenseInfos
public void addExtractedLicenseInfos(ExtractedLicenseInfo license) throws InvalidSPDXAnalysisException- Parameters:
license-- Throws:
InvalidSPDXAnalysisException
-
getFileReferences
get all file references contained within the container- Returns:
- Throws:
InvalidSPDXAnalysisException
-
documentNamespaceToId
Description copied from interface:IModelContainerTranslate an external document namespace URI to an external document ID- Specified by:
documentNamespaceToIdin interfaceIModelContainer- Returns:
-
externalDocumentIdToNamespace
Description copied from interface:IModelContainerTranslate an external document ID to the external document's namespace- Specified by:
externalDocumentIdToNamespacein interfaceIModelContainer- Returns:
-
getExternalDocumentRefs
- Returns:
- external document refs
-
setExternalDocumentRefs
public void setExternalDocumentRefs(ExternalDocumentRef[] externalDocumentRefs) throws InvalidSPDXAnalysisException- Parameters:
externalDocumentRefs-- Throws:
InvalidSPDXAnalysisException
-
findAllPackages
- Throws:
InvalidSPDXAnalysisException
-
findAllFiles
- Throws:
InvalidSPDXAnalysisException
-
addElement
Add an SPDX element directly to the model without connecting it to any properties- Parameters:
element-- Throws:
InvalidSPDXAnalysisException
-
findAllElements
Returns all elements in the contains- Returns:
- Throws:
InvalidSPDXAnalysisException
-
createResource
public org.apache.jena.rdf.model.Resource createResource(org.apache.jena.rdf.model.Resource duplicate, String uri, org.apache.jena.rdf.model.Resource type, IRdfModel nodeObject)Description copied from interface:IModelContainerCreate a resource in the model- Specified by:
createResourcein interfaceIModelContainer- Parameters:
duplicate- A duplicate resource who's node and resource should be returneduri- If not null, the URI for the resource - if null, an anonomous resource will be usedtype- Type of the resourcenodeObject- the object representing this node- Returns:
-
addCheckNodeObject
Description copied from interface:IModelContainerAdd a node object to the container. This is for containers which keep track of which object are related to which nodes- Specified by:
addCheckNodeObjectin interfaceIModelContainer- Returns:
- true if there are multiple objects for this node
-
findAllSnippets
- Returns:
- all snippets in the document container
- Throws:
InvalidSPDXAnalysisException
-