Class SpdxToolsHelper

java.lang.Object
org.spdx.tools.SpdxToolsHelper

public class SpdxToolsHelper extends Object
Static helper methods for the various tools
Author:
Gary O'Neall
  • Constructor Details

    • SpdxToolsHelper

      public SpdxToolsHelper()
  • Method Details

    • fileTypeToStore

      public static org.spdx.storage.ISerializableModelStore fileTypeToStore(SpdxToolsHelper.SerFileType fileType) throws org.spdx.core.InvalidSPDXAnalysisException
      Determine the appropriate in memory based model store which supports serialization for the fileType
      Parameters:
      fileType - file type for the store
      Returns:
      the appropriate in memory based model store which supports serialization for the fileType
      Throws:
      org.spdx.core.InvalidSPDXAnalysisException
    • fileToFileType

      public static SpdxToolsHelper.SerFileType fileToFileType(File file) throws InvalidFileNameException
      Determine the file type based on the file name and extension
      Parameters:
      file -
      Returns:
      the file type based on the file name and file extension
      Throws:
      InvalidFileNameException
    • strToFileType

      public static SpdxToolsHelper.SerFileType strToFileType(String str)
      Determine the file type based on the file extension or string
      Parameters:
      str -
      Returns:
      the file type based on the file extension or string
    • deserializeDocumentCompatV2

      public static org.spdx.library.model.v2.SpdxDocument deserializeDocumentCompatV2(File file) throws org.spdx.core.InvalidSPDXAnalysisException, IOException, InvalidFileNameException
      Deserializes an SPDX document from a file, compatible with SPDX version 2
      Parameters:
      file - file containing an SPDX document with the standard file extension for the serialization formats
      Returns:
      the SPDX document stored in the file
      Throws:
      org.spdx.core.InvalidSPDXAnalysisException
      IOException
      InvalidFileNameException
    • deserializeDocumentCompatV2

      public static org.spdx.library.model.v2.SpdxDocument deserializeDocumentCompatV2(File file, SpdxToolsHelper.SerFileType fileType) throws org.spdx.core.InvalidSPDXAnalysisException, IOException
      Deserializes an SPDX document from a file, compatible with SPDX version 2
      Parameters:
      file - file containing an SPDX document in one of the supported SerFileTypes
      fileType - serialization file type
      Returns:
      the SPDX document stored in the file
      Throws:
      org.spdx.core.InvalidSPDXAnalysisException
      IOException
    • deserializeDocumentCompat

      public static org.spdx.library.model.v3_0_1.core.SpdxDocument deserializeDocumentCompat(File file) throws org.spdx.core.InvalidSPDXAnalysisException, IOException, InvalidFileNameException
      Deserializes an SPDX document from a file
      Parameters:
      file - file containing an SPDX document with the standard file extension for the serialization formats
      Returns:
      the SPDX document stored in the file
      Throws:
      org.spdx.core.InvalidSPDXAnalysisException
      IOException
      InvalidFileNameException
    • deserializeDocument

      public static org.spdx.library.model.v3_0_1.core.SpdxDocument deserializeDocument(File file, SpdxToolsHelper.SerFileType fileType) throws org.spdx.core.InvalidSPDXAnalysisException, IOException
      Deserializes an SPDX document from a file
      Parameters:
      file - file containing an SPDX document in one of the supported SerFileTypes
      fileType - serialization file type
      Returns:
      the SPDX document stored in the file
      Throws:
      org.spdx.core.InvalidSPDXAnalysisException
      IOException
    • deserializeFile

      public static void deserializeFile(org.spdx.storage.ISerializableModelStore store, File file) throws FileNotFoundException, IOException, org.spdx.core.InvalidSPDXAnalysisException
      Reads SPDX data from a file and stores it in the store
      Parameters:
      store - Store where the SPDX data is to be stored
      file - File to read the store from
      Throws:
      FileNotFoundException - If the file is not found
      IOException - If there is an error reading the file
      org.spdx.core.InvalidSPDXAnalysisException - If there is a problem in the SPDX document structure
    • supportsV3

      public static boolean supportsV3(org.spdx.storage.ISerializableModelStore store)
      Is the store supporting SPDX version 3
      Parameters:
      store - model store
      Returns:
      true of the model store support SPDX spec version 3
    • supportsV2

      public static boolean supportsV2(org.spdx.storage.ISerializableModelStore store)
      Is the store supporting SPDX version 2
      Parameters:
      store - model store
      Returns:
      true of the model store support SPDX spec version 2
    • readDocumentFromFileV3

      public static org.spdx.library.model.v3_0_1.core.SpdxDocument readDocumentFromFileV3(org.spdx.storage.ISerializableModelStore store, File file) throws FileNotFoundException, IOException, org.spdx.core.InvalidSPDXAnalysisException
      Reads an SPDX Document from a file
      Parameters:
      store - Store where the document is to be stored
      file - File to read the store from
      Returns:
      SPDX Document from the store
      Throws:
      FileNotFoundException - If the file is not found
      IOException - If there is an error reading the file
      org.spdx.core.InvalidSPDXAnalysisException - If there is a problem in the SPDX document structure
    • readDocumentFromFile

      public static org.spdx.core.CoreModelObject readDocumentFromFile(org.spdx.storage.ISerializableModelStore store, File file) throws FileNotFoundException, IOException, org.spdx.core.InvalidSPDXAnalysisException
      Reads an SPDX Document from a file
      Parameters:
      store - Store where the document is to be stored
      file - File to read the store from
      Returns:
      SPDX Document from the store
      Throws:
      FileNotFoundException - If the file is not found
      IOException - If there is an error reading the file
      org.spdx.core.InvalidSPDXAnalysisException - If there is a problem in the SPDX document structure
    • readDocumentFromFileCompatV2

      public static org.spdx.library.model.v2.SpdxDocument readDocumentFromFileCompatV2(org.spdx.storage.ISerializableModelStore store, File file) throws FileNotFoundException, IOException, org.spdx.core.InvalidSPDXAnalysisException
      Reads an SPDX Document from a file, compatible with SPDX version 2
      Parameters:
      store - Store where the document is to be stored
      file - File to read the store from
      Returns:
      SPDX Document from the store
      Throws:
      FileNotFoundException - If the file is not found
      IOException - If there is an error reading the file
      org.spdx.core.InvalidSPDXAnalysisException - If there is a problem in the SPDX document structure
    • getDocFromStore

      public static org.spdx.library.model.v3_0_1.core.SpdxDocument getDocFromStore(org.spdx.storage.ISerializableModelStore store) throws org.spdx.core.InvalidSPDXAnalysisException
      Gets an SPDX document from the model store
      Parameters:
      store - model store
      Returns:
      returns a document if a single document is found in the model store
      Throws:
      org.spdx.core.InvalidSPDXAnalysisException
    • getDocFromStoreCompatV2

      public static org.spdx.library.model.v2.SpdxDocument getDocFromStoreCompatV2(org.spdx.storage.ISerializableModelStore store) throws org.spdx.core.InvalidSPDXAnalysisException
      Gets an SPDX document from the model store, compatible with SPDX version 2
      Parameters:
      store - model store
      Returns:
      returns a document if a single document is found in the model store
      Throws:
      org.spdx.core.InvalidSPDXAnalysisException
    • initialize

      public static void initialize()
      Initializes the model registry and default model stores