Package org.ametys.cms.data.type
Class ResourceElementTypeHelper
java.lang.Object
org.ametys.cms.data.type.ResourceElementTypeHelper
Helper for resource type of elements stored in the repository
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Identifier of the data containing the resource's datastatic final String
Identifier of the data to check to know if the resource is emptystatic final String
Encoding metadata identifierstatic final String
file name metadata identifierstatic final String
hash metadata identifierstatic final String
Last modification date metadata identifierstatic final String
Prefix to use for resource's metadatastatic final String
Mime type metadata identifier -
Method Summary
Modifier and TypeMethodDescriptionprotected static Stream<Triple<DataChangeType,
DataChangeTypeDetail, String>> _compareSingleResourcesContent
(Resource resource1, Resource resource2) Compare the content of the given single resources and retrieves the changes as a stream ofTriple
.protected static Stream<Triple<DataChangeType,
DataChangeTypeDetail, String>> _compareSingleResourcesMetadata
(Resource resource1, Resource resource2) Compare the metadata of the given single resources and retrieves the changes as a stream ofTriple
s.static Binary
binaryFromUpload
(Upload upload) Converts an uploaded file to aBinary
.static Stream<Triple<DataChangeType,
DataChangeTypeDetail, String>> compareSingleBinaries
(Binary binary1, Binary binary2) Compare the given single binaries and retrieves the changes as a stream ofTriple
s.static Stream<Triple<DataChangeType,
DataChangeTypeDetail, String>> compareSingleRichTexts
(RichText richText1, RichText richText2) Compare the given single rich texts and retrieves the changes as a stream ofTriple
s.static void
emptyResourceData
(ModifiableRepositoryData parentResourceData, String name, String nodeType) Empties the resource data with the given name.static ZonedDateTime
getDateValue
(RepositoryData repositoryData, String name, String prefix) Retrieves the date value from the given repository datastatic <T extends RepositoryData>
TgetRepositoryData
(T parentData, String dataTypeName, String name, String prefix) Retrieves the child repository data from the given repository datastatic String
getStringValue
(RepositoryData repositoryData, String name, String prefix) Retrieves the string value from the given repository datastatic String[]
getStringValues
(RepositoryData repositoryData, String name, String prefix) Retrieves the string values from the given repository datastatic boolean
isResourceDataEmpty
(RepositoryData resourceData) Checks if the given resource data is empty.static Binary
readBinaryData
(RepositoryData binaryData) Read the binary from the given repository datastatic void
readResourceData
(RepositoryData resourceData, Resource resource) Read the resource from the given repository datastatic void
resourceFromXML
(NamedResource resource, Element element, Optional<Object> additionalData, Context context) Sets the given resource's data using the given DOM element and additional datasingleBinaryToJSON
(Binary binary, String binaryType, DataContext context) Convert the single binary into a JSON objectstatic void
singleBinaryToSAX
(ContentHandler contentHandler, String tagName, Binary binary, String binaryType, DataContext context, AttributesImpl attributes) Generates SAX events for the given single binarysingleFileToJSON
(File file, String fileType, String path, String fileURI) Convert the single file into a JSON objectstatic void
singleFileToSAX
(ContentHandler contentHandler, String tagName, File file, String fileType, String path, String fileURI, AttributesImpl attributes) Generates SAX events for the given single filestatic void
writeResourceData
(ModifiableRepositoryData resourceData, Resource value) Write the resource in the given repository datastatic void
writeSingleBinaryValue
(ModifiableRepositoryData parentData, String name, Binary value) Write the resource in the given repository data
-
Field Details
-
METADATA_PREFIX
Prefix to use for resource's metadata- See Also:
-
MIME_TYPE_IDENTIFIER
Mime type metadata identifier- See Also:
-
ENCODING_IDENTIFIER
Encoding metadata identifier- See Also:
-
LAST_MODIFICATION_DATE_IDENTIFIER
Last modification date metadata identifier- See Also:
-
DATA_IDENTIFIER
Identifier of the data containing the resource's data- See Also:
-
HASH_IDENTIFIER
hash metadata identifier- See Also:
-
FILENAME_IDENTIFIER
file name metadata identifier- See Also:
-
EMPTY_RESOURCE_IDENTIFIER
Identifier of the data to check to know if the resource is empty- See Also:
-
-
Method Details
-
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 convertbinaryType
- the type of the binarycontext
- 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 convertfileType
- the type of the filepath
- 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 theResolveURIComponent
- Returns:
- The file as JSON
-
resourceFromXML
public static void resourceFromXML(NamedResource resource, Element element, Optional<Object> additionalData, Context context) throws TransformerException, IOException Sets the given resource's data using the given DOM element and additional data- Parameters:
resource
- the resourceelement
- the DOM elementadditionalData
- additional data containing the input streamcontext
- the Cocoon's context, used to retrieve mime types from file names if needed- Throws:
TransformerException
- if an error occurs while parsing the DOM nodeIOException
- if an error occurs reading the resource's input stream
-
binaryFromUpload
Converts an uploaded file to aBinary
.- 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
- theContentHandler
that will receive the SAX eventstagName
- the tag name of the SAX event to generate.binary
- the single file to SAXbinaryType
- the type of the filecontext
- The context of the binary to convertattributes
- 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
- theContentHandler
that will receive the SAX eventstagName
- the tag name of the SAX event to generate.file
- the single file to SAXfileType
- the type of the filepath
- the path of file (ex: data path for a binary or resource id for an explorer file)fileURI
- uri of the fileattributes
- the attributes for the SAX event to generate- Throws:
SAXException
- if an error occurs during the SAX events generation
-
isResourceDataEmpty
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
Read the binary from the given repository data- Parameters:
binaryData
- the repository data containing the binary's data- Returns:
- the read binary
-
readResourceData
Read the resource from the given repository data- Parameters:
resourceData
- the repository data containing the resource's dataresource
- 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 emptyname
- the name of the resource datanodeType
- 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 binaryname
- the name of the element to writevalue
- the binary to write
-
writeResourceData
Write the resource in the given repository data- Parameters:
resourceData
- the repository data where to write the resource's datavalue
- the resource to write
-
compareSingleBinaries
public static Stream<Triple<DataChangeType,DataChangeTypeDetail, compareSingleBinariesString>> (Binary binary1, Binary binary2) throws IOException Compare the given single binaries and retrieves the changes as a stream ofTriple
s. TheTriple
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 binarybinary2
- the 2nd single binary- Returns:
- the changes between the two given single binaries as a stream of
Triple
s. Retrieves an empty stream if there is no change - Throws:
IOException
- if an error occurs while reading the binaries' data
- the general type of the change (added, modified or removed) as a
-
compareSingleRichTexts
public static Stream<Triple<DataChangeType,DataChangeTypeDetail, compareSingleRichTextsString>> (RichText richText1, RichText richText2) throws IOException Compare the given single rich texts and retrieves the changes as a stream ofTriple
s. TheTriple
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 textrichText2
- the 2nd single rich text- Returns:
- the changes between the two given single rich texts as a stream of
Triple
s. Retrieves an empty stream if there is no change - Throws:
IOException
- if an error occurs while reading the rich texts' data
- the general type of the change (added, modified or removed) as a
-
_compareSingleResourcesMetadata
protected static Stream<Triple<DataChangeType,DataChangeTypeDetail, _compareSingleResourcesMetadataString>> (Resource resource1, Resource resource2) throws IOException Compare the metadata of the given single resources and retrieves the changes as a stream ofTriple
s. TheTriple
s 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 resourceresource2
- the 2nd single resource- Returns:
- the changes between the metadata of the two given single resources as a stream of
Triple
s. Retrieves an empty stream if there is no change - Throws:
IOException
- if an error occurs while reading the resources' data
- the general type of the change (added, modified or removed) as a
-
_compareSingleResourcesContent
protected static Stream<Triple<DataChangeType,DataChangeTypeDetail, _compareSingleResourcesContentString>> (Resource resource1, Resource resource2) throws IOException Compare the content of the given single resources and retrieves the changes as a stream ofTriple
. TheTriple
s 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 resourceresource2
- the 2nd single resource- Returns:
- the changes between the content of the two given single resources as a stream of
Triple
s. Retrieves an empty stream if there is no change - Throws:
IOException
- if an error occurs while reading the resources' data
- the general type of the change (added, modified or removed) as a
-
getStringValue
Retrieves the string value from the given repository data- Parameters:
repositoryData
- the repository data containing the data to retrievename
- the name of the data to retrieveprefix
- the prefix of the data to retrieve- Returns:
- the string value
-
getStringValues
Retrieves the string values from the given repository data- Parameters:
repositoryData
- the repository data containing the data to retrievename
- the name of the data to retrieveprefix
- 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 retrievedataTypeName
- the type of the data to retrievename
- the name of the data to retrieveprefix
- the prefix of the data to retrieve- Returns:
- the child repository data
-
getDateValue
Retrieves the date value from the given repository data- Parameters:
repositoryData
- the repository data containing data to retrieveprefix
- the prefix of the data to retrievename
- the name of the data to retrieve- Returns:
- the date value
-