Package org.webharvest.runtime.processors

Source Code of org.webharvest.runtime.processors.ExitProcessor

package org.webharvest.runtime.processors;

import org.webharvest.definition.ExitDef;
import org.webharvest.runtime.variables.Variable;
import org.webharvest.runtime.variables.EmptyVariable;
import org.webharvest.runtime.Scraper;
import org.webharvest.runtime.ScraperContext;
import org.webharvest.runtime.templaters.BaseTemplater;
import org.webharvest.utils.CommonUtil;

/**
* Exit processor.
*/
public class ExitProcessor extends BaseProcessor {

    private ExitDef exitDef;

    public ExitProcessor(ExitDef exitDef) {
        super(exitDef);
        this.exitDef = exitDef;
    }

    public Variable execute(Scraper scraper, ScraperContext context) {
        String condition = BaseTemplater.execute( exitDef.getCondition(), scraper.getScriptEngine());
        if ( condition == null || "".equals(condition) ) {
            condition = "true";
        }

        if (CommonUtil.isBooleanTrue(condition)) {
            String message = BaseTemplater.execute( exitDef.getMessage(), scraper.getScriptEngine());
            if (message == null) {
                message = "";
            }
            scraper.exitExecution(message);
            if ( scraper.getLogger().isInfoEnabled() ) {
                scraper.getLogger().info("Configuration exited: " + message);
            }
        }

        return new EmptyVariable();
    }

}
TOP

Related Classes of org.webharvest.runtime.processors.ExitProcessor

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.