//  ============================================================================
//
//  Copyright (C) 2006-2016 Talend Inc. - www.talend.com
//
//  This source code is available under agreement available at
//  https://github.com/Talend/data-prep/blob/master/LICENSE
//
//  You should have received a copy of the agreement
//  along with this program; if not, write to Talend SA
//  9 rue Pages 92150 Suresnes, France
//
//  ============================================================================

package org.talend.dataprep.transformation.api.action.metadata.text;

import java.util.EnumSet;
import java.util.Set;

import org.springframework.stereotype.Component;
import org.talend.dataprep.api.dataset.ColumnMetadata;
import org.talend.dataprep.api.dataset.DataSetRow;
import org.talend.dataprep.api.type.Type;
import org.talend.dataprep.transformation.api.action.context.ActionContext;
import org.talend.dataprep.transformation.api.action.metadata.category.ActionCategory;
import org.talend.dataprep.transformation.api.action.metadata.common.ActionMetadata;
import org.talend.dataprep.transformation.api.action.metadata.common.ColumnAction;

/**
 * Trim leading and trailing spaces.
 */
@Component(ActionMetadata.ACTION_BEAN_PREFIX + Trim.TRIM_ACTION_NAME)
public class Trim extends ActionMetadata implements ColumnAction {

    /**
     * The action name.
     */
    public static final String TRIM_ACTION_NAME = "trim"; //$NON-NLS-1$

    /**
     * @see ActionMetadata#getName()
     */
    @Override
    public String getName() {
        return TRIM_ACTION_NAME;
    }

    /**
     * @see ActionMetadata#getCategory()
     */
    @Override
    public String getCategory() {
        return ActionCategory.STRINGS.getDisplayName();
    }

    /**
     * @see ActionMetadata#acceptColumn(ColumnMetadata)
     */
    @Override
    public boolean acceptColumn(ColumnMetadata column) {
        return Type.STRING.equals(Type.get(column.getType()));
    }

    /**
     * @see ColumnAction#applyOnColumn(DataSetRow, ActionContext)
     */
    @Override
    public void applyOnColumn(DataSetRow row, ActionContext context) {
        final String columnId = context.getColumnId();
        final String toTrim = row.get(columnId);
        if (toTrim != null) {
            row.set(columnId, toTrim.trim());
        }
    }

    @Override
    public Set<Behavior> getBehavior() {
        return EnumSet.of(Behavior.VALUES_COLUMN);
    }
}

@@ -614,16 +614,92 @@
 il.Set;%0A
+import java.util.regex.Pattern;%0A%0Aimport org.apache.commons.lang.StringUtils;
 %0Aimport 
@@ -1516,16 +1516,79 @@
 NLS-1$%0A%0A
+    private static final String TRIM_PATTERN = %22trimPattern%22;%0A%0A
     /**%0A
@@ -2089,32 +2089,376 @@
 ype()));%0A    %7D%0A%0A
+    @Override%0A    public void compile(ActionContext actionContext) %7B%0A        super.compile(actionContext);%0A        if (actionContext.getActionStatus() == ActionContext.ActionStatus.OK) %7B%0A            final Pattern pattern = Pattern.compile(%22(%5E%5C%5Ch*)%7C(%5C%5Ch*$)%22);%0A            actionContext.get(TRIM_PATTERN, parameters -%3E pattern);%0A        %7D%0A    %7D%0A%0A
     /**%0A     * @
@@ -2758,38 +2758,149 @@
     
-row.set(columnId, toTrim.trim(
+final Pattern trimPattern = context.get(TRIM_PATTERN);%0A            row.set(columnId, trimPattern.matcher(toTrim).replaceAll(StringUtils.EMPTY
 ));%0A

Trim now removes non-breaking spaces.