Package org.ametys.cms.data.type
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 Summary
Fields Modifier and Type Field Description static String
DATA_IDENTIFIER
Identifier of the data containing the resource's datastatic String
EMPTY_RESOURCE_IDENTIFIER
Identifier of the data to check to know if the resource is emptystatic String
ENCODING_IDENTIFIER
Encoding metadata identifierstatic String
FILENAME_IDENTIFIER
file name metadata identifierstatic String
HASH_IDENTIFIER
hash metadata identifierstatic String
LAST_MODIFICATION_DATE_IDENTIFIER
Last modification date metadata identifierstatic String
METADATA_PREFIX
Prefix to use for resource's metadatastatic String
MIME_TYPE_IDENTIFIER
Mime type metadata identifier
-
Constructor Summary
Constructors Modifier Constructor Description private
ResourceElementTypeHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description protected 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.private static String
_getBinaryURI(DataContext context)
private static Calendar
_getCalendarFromZonedDateTime(ZonedDateTime zonedDateTime)
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 datastatic Map<String,Object>
singleBinaryToJSON(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 binarystatic Map<String,Object>
singleFileToJSON(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 Detail
-
METADATA_PREFIX
public static final String METADATA_PREFIX
Prefix to use for resource's metadata- See Also:
- Constant Field Values
-
MIME_TYPE_IDENTIFIER
public static final String MIME_TYPE_IDENTIFIER
Mime type metadata identifier- See Also:
- Constant Field Values
-
ENCODING_IDENTIFIER
public static final String ENCODING_IDENTIFIER
Encoding metadata identifier- See Also:
- Constant Field Values
-
LAST_MODIFICATION_DATE_IDENTIFIER
public static final String LAST_MODIFICATION_DATE_IDENTIFIER
Last modification date metadata identifier- See Also:
- Constant Field Values
-
DATA_IDENTIFIER
public static final String DATA_IDENTIFIER
Identifier of the data containing the resource's data- See Also:
- Constant Field Values
-
HASH_IDENTIFIER
public static final String HASH_IDENTIFIER
hash metadata identifier- See Also:
- Constant Field Values
-
FILENAME_IDENTIFIER
public static final String FILENAME_IDENTIFIER
file name metadata identifier- See Also:
- Constant Field Values
-
EMPTY_RESOURCE_IDENTIFIER
public static final String EMPTY_RESOURCE_IDENTIFIER
Identifier of the data to check to know if the resource is empty- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ResourceElementTypeHelper
private ResourceElementTypeHelper()
-
-
Method Detail
-
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
public static Binary binaryFromUpload(Upload upload)
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
-
_getBinaryURI
private static String _getBinaryURI(DataContext context)
-
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
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 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
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 datavalue
- the resource to write
-
compareSingleBinaries
public static Stream<Triple<DataChangeType,DataChangeTypeDetail,String>> compareSingleBinaries(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,String>> compareSingleRichTexts(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,String>> _compareSingleResourcesMetadata(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,String>> _compareSingleResourcesContent(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
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 retrievename
- the name of the data to retrieveprefix
- 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 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
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 retrieveprefix
- the prefix of the data to retrievename
- the name of the data to retrieve- Returns:
- the date value
-
_getCalendarFromZonedDateTime
private static Calendar _getCalendarFromZonedDateTime(ZonedDateTime zonedDateTime)
-
-