Class ResourceElementTypeHelper

java.lang.Object
org.ametys.cms.data.type.ResourceElementTypeHelper

public final class ResourceElementTypeHelper extends Object
Helper for resource type of elements stored in the repository
  • Field Details

  • Method Details

    • convertStringToBinary

      public static Binary convertStringToBinary(String value)
      Converts the given string to a Binary
      Parameters:
      value - the string to convert
      Returns:
      the converted Binary
    • convertByteArrayToBinary

      public static Binary convertByteArrayToBinary(byte[] value)
      Converts the given byte array to a Binary
      Parameters:
      value - the byte array to convert
      Returns:
      the converted Binary
    • singleBinaryToJSON

      public static Map<String,Object> singleBinaryToJSON(Binary binary, String binaryType, DataContext context)
      Convert the single binary into a JSON object
      Parameters:
      binary - the binary to convert
      binaryType - the type of the binary
      context - The context of the binary to convert
      Returns:
      The file as JSON
    • singleFileToJSON

      public static Map<String,Object> singleFileToJSON(File file, String fileType, String path, String fileURI)
      Convert the single file into a JSON object
      Parameters:
      file - the file to convert
      fileType - the type of the file
      path - the path of file (ex: data path for a binary or resource id for an explorer file)
      fileURI - uri of the file to give to the ResolveURIComponent
      Returns:
      The file as JSON
    • resourceFromXML

      public static void resourceFromXML(NamedResource resource, Element element, Optional<Object> additionalData, Context context)
      Sets the given resource's data using the given DOM element and additional data
      Parameters:
      resource - the resource
      element - the DOM element
      additionalData - additional data containing the input stream
      context - the Cocoon's context, used to retrieve mime types from file names if needed
    • binaryFromUpload

      public static Binary binaryFromUpload(Upload upload)
      Converts an uploaded file to a Binary.
      Parameters:
      upload - the uploaded file.
      Returns:
      the newly created Binary.
    • singleBinaryToSAX

      public static void singleBinaryToSAX(ContentHandler contentHandler, String tagName, Binary binary, String binaryType, DataContext context, AttributesImpl attributes) throws SAXException
      Generates SAX events for the given single binary
      Parameters:
      contentHandler - the ContentHandler that will receive the SAX events
      tagName - the tag name of the SAX event to generate.
      binary - the single file to SAX
      binaryType - the type of the file
      context - The context of the binary to convert
      attributes - the attributes for the SAX event to generate
      Throws:
      SAXException - if an error occurs during the SAX events generation
    • singleFileToSAX

      public static void singleFileToSAX(ContentHandler contentHandler, String tagName, File file, String fileType, String path, String fileURI, AttributesImpl attributes) throws SAXException
      Generates SAX events for the given single file
      Parameters:
      contentHandler - the ContentHandler that will receive the SAX events
      tagName - the tag name of the SAX event to generate.
      file - the single file to SAX
      fileType - the type of the file
      path - the path of file (ex: data path for a binary or resource id for an explorer file)
      fileURI - uri of the file
      attributes - the attributes for the SAX event to generate
      Throws:
      SAXException - if an error occurs during the SAX events generation
    • isResourceDataEmpty

      public static boolean isResourceDataEmpty(RepositoryData resourceData)
      Checks if the given resource data is empty. A resource data is considered as empty if it has no stream data
      Parameters:
      resourceData - the resource data to check
      Returns:
      true if the resource has is empty, false otherwise
    • readBinaryData

      public static Binary readBinaryData(RepositoryData binaryData)
      Read the binary from the given repository data
      Parameters:
      binaryData - the repository data containing the binary's data
      Returns:
      the read binary
    • readResourceData

      public static void readResourceData(RepositoryData resourceData, Resource resource)
      Read the resource from the given repository data
      Parameters:
      resourceData - the repository data containing the resource's data
      resource - the resource to read
    • emptyResourceData

      public static void emptyResourceData(ModifiableRepositoryData parentResourceData, String name, String nodeType)
      Empties the resource data with the given name. A resource data is considered as empty if it has no stream data
      Parameters:
      parentResourceData - the parent of the resource data to empty
      name - the name of the resource data
      nodeType - the node type of the resource data
    • writeSingleBinaryValue

      public static void writeSingleBinaryValue(ModifiableRepositoryData parentData, String name, Binary value)
      Write the resource in the given repository data
      Parameters:
      parentData - the repository data where to write the binary
      name - the name of the element to write
      value - the binary to write
    • writeResourceData

      public static void writeResourceData(ModifiableRepositoryData resourceData, Resource value)
      Write the resource in the given repository data
      Parameters:
      resourceData - the repository data where to write the resource's data
      value - the resource to write
    • compareSingleBinaries

      Compare the given single binaries and retrieves the changes as a stream of Triples. The Triple contains:
      • the general type of the change (added, modified or removed) as a DataChangeType,
      • some details about this change if possible (after or before for a date, more or less for a number, ...) as a DataChangeTypeDetail
      • The data concerned by this change if not the element itself (or an empty String)
      Parameters:
      binary1 - the 1st single binary
      binary2 - the 2nd single binary
      Returns:
      the changes between the two given single binaries as a stream of Triples. Retrieves an empty stream if there is no change
    • compareSingleRichTexts

      Compare the given single rich texts and retrieves the changes as a stream of Triples. The Triple contains:
      • the general type of the change (added, modified or removed) as a DataChangeType,
      • some details about this change if possible (after or before for a date, more or less for a number, ...) as a DataChangeTypeDetail
      • The data concerned by this change if not the element itself (or an empty String)
      Parameters:
      richText1 - the 1st single rich text
      richText2 - the 2nd single rich text
      Returns:
      the changes between the two given single rich texts as a stream of Triples. Retrieves an empty stream if there is no change
    • _compareSingleResourcesMetadata

      Compare the metadata of the given single resources and retrieves the changes as a stream of Triples. The Triples contain:
      • the general type of the change (added, modified or removed) as a DataChangeType,
      • some details about this change if possible (after or before for a date, more or less for a number, ...) as a DataChangeTypeDetail
      • The data concerned by this change if not the element itself (or an empty String)
      Parameters:
      resource1 - the 1st single resource
      resource2 - the 2nd single resource
      Returns:
      the changes between the metadata of the two given single resources as a stream of Triples. Retrieves an empty stream if there is no change
      Throws:
      IOException - if an error occurs while reading the resources' data
    • _compareSingleResourcesContent

      Compare the content of the given single resources and retrieves the changes as a stream of Triple. The Triples contain:
      • the general type of the change (added, modified or removed) as a DataChangeType,
      • some details about this change if possible (after or before for a date, more or less for a number, ...) as a DataChangeTypeDetail
      • The data concerned by this change if not the element itself (or an empty String)
      Parameters:
      resource1 - the 1st single resource
      resource2 - the 2nd single resource
      Returns:
      the changes between the content of the two given single resources as a stream of Triples. Retrieves an empty stream if there is no change
      Throws:
      IOException - if an error occurs while reading the resources' data
    • getStringValue

      public static String getStringValue(RepositoryData repositoryData, String name, String prefix)
      Retrieves the string value from the given repository data
      Parameters:
      repositoryData - the repository data containing the data to retrieve
      name - the name of the data to retrieve
      prefix - the prefix of the data to retrieve
      Returns:
      the string value
    • getStringValues

      public static String[] getStringValues(RepositoryData repositoryData, String name, String prefix)
      Retrieves the string values from the given repository data
      Parameters:
      repositoryData - the repository data containing the data to retrieve
      name - the name of the data to retrieve
      prefix - the prefix of the data to retrieve
      Returns:
      the string values
    • getRepositoryData

      public static <T extends RepositoryData> T getRepositoryData(T parentData, String dataTypeName, String name, String prefix)
      Retrieves the child repository data from the given repository data
      Type Parameters:
      T - Type of the repository data (modifiable or not)
      Parameters:
      parentData - the repository data containing the data to retrieve
      dataTypeName - the type of the data to retrieve
      name - the name of the data to retrieve
      prefix - the prefix of the data to retrieve
      Returns:
      the child repository data
    • getDateValue

      public static ZonedDateTime getDateValue(RepositoryData repositoryData, String name, String prefix)
      Retrieves the date value from the given repository data
      Parameters:
      repositoryData - the repository data containing data to retrieve
      prefix - the prefix of the data to retrieve
      name - the name of the data to retrieve
      Returns:
      the date value