Class CollectionValueTranslator

    • Constructor Detail

      • CollectionValueTranslator

        public CollectionValueTranslator​(CollectionType targetType,
                                         AbstractValueTranslator elementTranslator)
        Instantiates a new collection translator instance for collections of type targetType translatable by elementTranslator.
        Parameters:
        targetType - type of collection elements
        elementTranslator - translator for translating elements of collection
      • CollectionValueTranslator

        public CollectionValueTranslator​(CollectionType targetType,
                                         AbstractValueTranslator elementTranslator,
                                         char delimiter)
        Not public constructors for testing purposes. Additionally to the regular constructor, you can specify the delimiters to use for item separation.
        Parameters:
        targetType - type of collection elements
        elementTranslator - translator for translating elements of collection
        delimiter - delimiter to use for element separation
    • Method Detail

      • importValue

        public java.lang.Object importValue​(java.lang.String valueExpr,
                                            Item forItem)
                                     throws JaloInvalidParameterException
        Description copied from class: AbstractValueTranslator
        Translates a tokenized csv value for import usage. This means that the result object must be a instance of the expected attribute type.
        Specified by:
        importValue in class AbstractValueTranslator
        Parameters:
        valueExpr - expression to translate
        forItem - the target item in case it already exist, null otherwise (for partOf attributes!)
        Returns:
        Object translated value
        Throws:
        JaloInvalidParameterException - value can not be translated with this translator or is invalid
      • processItem

        protected boolean processItem​(java.lang.String token,
                                      Item forItem,
                                      java.util.Collection col,
                                      boolean append,
                                      boolean allowNull)
        Translates given token to an value (item attribute) and adds or removes it to given list.
        Parameters:
        token - string representation of one value
        forItem - existing item if exist (can be null)
        col - existing collection for adding/removing (non null)
        append - add (true) or remove (false) attribute to/from existing collection?
        allowNull - if the string is translated to null, do you want to ignore it?
        Returns:
        true, if an attribute was added/removed to the collection, false otherwise
      • processItems

        protected void processItems​(java.util.List<java.lang.String> expressions,
                                    Item forItem,
                                    java.util.BitSet doAppendSet,
                                    java.util.Collection coll,
                                    boolean allowNull)
        Processes all expressions at once. This applies to item expressions only!

        Internally this method calls ItemExpressionTranslator.convertAllToJalo(Item, List, List) to perform a single query fetching *all* items at once to avoid database roundtrip.

        Parameters:
        expressions -
        forItem -
        doAppendSet -
        coll -
        allowNull -
      • getElementTranslator

        public AbstractValueTranslator getElementTranslator()
        Returns the used translator for an single element of collection.
        Returns:
        used translator
      • isEmpty

        protected boolean isEmpty​(java.lang.String collStr)
        Checks if given expression is empty.
        Parameters:
        collStr - collection expression to check
        Returns:
        true if expression is empty (null or length of 0), false otherwise
      • joinAndEscape

        protected java.lang.String joinAndEscape​(java.util.List strings)
        Concats collection element strings into one string delimited by the configured delimiter. If needed the element strings are escaped in case they contain delimiter or other special characters.

        As default this simply calls CSVUtils.joinAndEscape(List, char[], char, boolean).

        Parameters:
        strings - the collection element strings
        Returns:
        the complete cell string
      • splitAndUnescape

        protected java.util.List<java.lang.String> splitAndUnescape​(java.lang.String valueExpr)
        Used for tokenizing the cell string into several collection element tokens. Also this method does unescaping in case the collection element tokens contain escaped delimiters or other special characters.

        As default this calls simply CSVUtils.splitAndUnescape(String, char[], boolean).

        Parameters:
        valueExpr - the cell value
        Returns:
        the list of element tokens
      • getCollectionValueDelimiter

        protected char getCollectionValueDelimiter()
        Returns the used element delimiter in collections for defined descriptor.
        Returns:
        used element delimiter
      • isDelimiter

        @Deprecated
        protected final boolean isDelimiter​(java.lang.String collStr,
                                            int pos,
                                            char character)
        Deprecated.
        since ages - not needed any more - to hook in tokenizing overridesplitAndUnescape(String) instead!