Class DataHolderHelper
- java.lang.Object
-
- org.ametys.plugins.repository.data.holder.impl.DataHolderHelper
-
public final class DataHolderHelper extends Object
Helper for implementations of data holder
-
-
Constructor Summary
Constructors Modifier Constructor Description private
DataHolderHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static <T> Map<String,T>
_findItemsByType(ModelItemContainer modelItemContainer, String type, ModelAwareDataHolder dataHolder, String prefix)
static void
copyTo(DataHolder source, ModifiableDataHolder destination)
Copies the sourceDataHolder
to the givenModifiableDataHolder
destination.static void
copyTo(DataHolder source, ModifiableDataHolder destination, String name)
Copy the data name of the sourceDataHolder
to the givenModifiableDataHolder
destination.static void
dataToSAX(ModelAwareDataHolder dataHolder, ContentHandler contentHandler, ViewItemContainer viewItemContainer, String prefix, Locale locale)
Generates SAX events for the data in the given view in the currentDataHolder
static <T> Map<String,T>
findItemsByType(ModelAwareDataHolder dataHolder, String type)
Find all data of the given type on aModelAwareDataHolder
, including in composite or repository entries.static RepeaterEntry
getRepeaterEntry(ModelAwareDataHolder dataHolder, String repeaterName, int entryPosition)
Retrieves the repeater entry at the given positionstatic Pair<String,Integer>
getRepeaterNameAndEntryPosition(String pathSegment)
Retrieves the pair of repeater name and entry position of the given path segment Returnnull
if the given path does not represent a repeater entrystatic boolean
hasRepeaterEntry(ModelAwareDataHolder dataHolder, String repeaterName, int entryPosition)
Checks if there is a repeater entry at the given positionstatic boolean
isRepeaterEntryPath(String path)
Test if the path is a repeater entry path (for example entries[1])
-
-
-
Constructor Detail
-
DataHolderHelper
private DataHolderHelper()
-
-
Method Detail
-
hasRepeaterEntry
public static boolean hasRepeaterEntry(ModelAwareDataHolder dataHolder, String repeaterName, int entryPosition) throws BadItemTypeException
Checks if there is a repeater entry at the given position- Parameters:
dataHolder
- data holder that contains the repeater entry. The data holder must be the direct parent of the repeaterrepeaterName
- the name of the repeaterentryPosition
- the position of the entry- Returns:
true
if there is an entry at the given position,false
otherwise- Throws:
BadItemTypeException
- if the value stored in the repository for the given repeater name is not a repeater
-
getRepeaterEntry
public static RepeaterEntry getRepeaterEntry(ModelAwareDataHolder dataHolder, String repeaterName, int entryPosition) throws BadItemTypeException
Retrieves the repeater entry at the given position- Parameters:
dataHolder
- data holder that contains the repeater entry. The data holder must be the direct parent of the repeaterrepeaterName
- the name of the repeaterentryPosition
- the position of the entry- Returns:
- the repeater entry
- Throws:
BadItemTypeException
- if the value stored in the repository for the given repeater name is not a repeater
-
isRepeaterEntryPath
public static boolean isRepeaterEntryPath(String path)
Test if the path is a repeater entry path (for example entries[1])- Parameters:
path
- the path representing the repeater entry- Returns:
- true if the pathSegment is a repeater entry path
-
getRepeaterNameAndEntryPosition
public static Pair<String,Integer> getRepeaterNameAndEntryPosition(String pathSegment)
Retrieves the pair of repeater name and entry position of the given path segment Returnnull
if the given path does not represent a repeater entry- Parameters:
pathSegment
- the path segment representing the repeater entry- Returns:
- the pair of repeater name and entry position
-
copyTo
public static void copyTo(DataHolder source, ModifiableDataHolder destination)
Copies the sourceDataHolder
to the givenModifiableDataHolder
destination.- Parameters:
source
- the sourceDataHolder
destination
- theModifiableDataHolder
destination
-
copyTo
public static void copyTo(DataHolder source, ModifiableDataHolder destination, String name)
Copy the data name of the sourceDataHolder
to the givenModifiableDataHolder
destination.- Parameters:
source
- the sourceDataHolder
destination
- theModifiableDataHolder
destinationname
- the name of the data
-
dataToSAX
public static void dataToSAX(ModelAwareDataHolder dataHolder, ContentHandler contentHandler, ViewItemContainer viewItemContainer, String prefix, Locale locale) throws SAXException, IOException, BadItemTypeException
Generates SAX events for the data in the given view in the currentDataHolder
- Parameters:
dataHolder
- theModelAwareDataHolder
to SAXcontentHandler
- theContentHandler
that will receive the SAX eventsviewItemContainer
- theViewItemContainer
containing referencing the model item for which generate SAX eventsprefix
- the path's prefix of the model items to SAX. Can benull
or empty if the model items in the view item container are at the rrot of the model.locale
- The locale to use for localized data, such asMultilingualString
. Can benull
to generate SAX events for all existingLocale
s.- Throws:
SAXException
- if an error occurs during the SAX events generationIOException
- if an error occurs while reading a value using the I/O APIBadItemTypeException
- if the saxed value's type does not matches the stored data
-
findItemsByType
public static <T> Map<String,T> findItemsByType(ModelAwareDataHolder dataHolder, String type)
Find all data of the given type on aModelAwareDataHolder
, including in composite or repository entries.- Type Parameters:
T
- the actual type of the requested data.- Parameters:
dataHolder
- the data holder.type
- the type identifier.- Returns:
- a Map with all data paths as keys and corresponding data as values.
-
_findItemsByType
private static <T> Map<String,T> _findItemsByType(ModelItemContainer modelItemContainer, String type, ModelAwareDataHolder dataHolder, String prefix)
-
-