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 privateDataHolderHelper()
-
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 voidcopyTo(DataHolder source, ModifiableDataHolder destination)Copies the sourceDataHolderto the givenModifiableDataHolderdestination.static voidcopyTo(DataHolder source, ModifiableDataHolder destination, String name)Copy the data name of the sourceDataHolderto the givenModifiableDataHolderdestination.static voiddataToSAX(ModelAwareDataHolder dataHolder, ContentHandler contentHandler, ViewItemContainer viewItemContainer, String prefix, Locale locale)Generates SAX events for the data in the given view in the currentDataHolderstatic <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 RepeaterEntrygetRepeaterEntry(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 Returnnullif the given path does not represent a repeater entrystatic booleanhasRepeaterEntry(ModelAwareDataHolder dataHolder, String repeaterName, int entryPosition)Checks if there is a repeater entry at the given positionstatic booleanisRepeaterEntryPath(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:
trueif there is an entry at the given position,falseotherwise- 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 Returnnullif 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 sourceDataHolderto the givenModifiableDataHolderdestination.- Parameters:
source- the sourceDataHolderdestination- theModifiableDataHolderdestination
-
copyTo
public static void copyTo(DataHolder source, ModifiableDataHolder destination, String name)
Copy the data name of the sourceDataHolderto the givenModifiableDataHolderdestination.- Parameters:
source- the sourceDataHolderdestination- theModifiableDataHolderdestinationname- 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- theModelAwareDataHolderto SAXcontentHandler- theContentHandlerthat will receive the SAX eventsviewItemContainer- theViewItemContainercontaining referencing the model item for which generate SAX eventsprefix- the path's prefix of the model items to SAX. Can benullor 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 benullto generate SAX events for all existingLocales.- 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)
-
-