All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.rauberprojects.client.transclude.DefaultTranscluder Maven / Gradle / Ivy

There is a newer version: 1.0.3
Show newest version
package com.github.rauberprojects.client.transclude;

import com.github.rauberprojects.client.context.Context;
import com.github.rauberprojects.client.model.Data;
import com.github.rauberprojects.client.transclude.Transcluder;

import java.util.List;

/**
 * A transcluder that works according to the specification by checking the transclude value of the data element.
 *
 * Implementation note:
 * {@link Boolean#parseBoolean(String)} checks for null values and defaults to false if null is provided.
 * This behaviour is in-line with the specification.
 */
public class DefaultTranscluder implements Transcluder {

    @Override
    public Context transclude(Data data, Context oldContext, Context newContext) {

        final String transcludeValue = data.getTransclude();

        boolean shouldTransclude = Boolean.parseBoolean(transcludeValue);

        if (shouldTransclude) {

            final List newData = newContext.getUber().getData();
            data.setData(newData);

            return oldContext;
        } else {
            return newContext;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy