ChronoCtrl.java

package org.docascode.chrono;

import org.docascode.office.SubstituteCtrl;
import org.docascode.utils.DocAsCodeException;
import java.io.File;

public class ChronoCtrl {
    private ChronoModel chronoModel;

    public void add(String chrono, String input){
        this.chronoModel.add(chrono,input);
    }

    public void put(String chrono, String outputPath, String output){
        this.chronoModel.put(chrono,outputPath,output);
    }

    public void attach(String chrono, String classifier, String input){
        this.chronoModel.attach(chrono, classifier, input);
    }

    public File getFile(String chrono) throws DocAsCodeException {
        File file = new File(this.chronoModel.getInput(chrono));
        if (!file.exists()){
            throw new DocAsCodeException("File "+file.getAbsolutePath()+" cannot be found");
        }
        return file;
    }

    public String getOutput(String chrono, String outputPath) throws DocAsCodeException {
        final String substitute = SubstituteCtrl.substitute(this.chronoModel.getOutput(chrono, outputPath), getFile(chrono));
        return substitute;
    }

    public File getFile(String chrono, String classifier) throws DocAsCodeException {
        File file = new File(this.chronoModel.getInput(chrono,classifier));
        if (!file.exists()){
            throw new DocAsCodeException("File "+file.getAbsolutePath()+" cannot be found");
        }
        return file;
    }

    public String getOutput(String chrono, String classifier, String outputPath) throws DocAsCodeException {
        final String substitute = SubstituteCtrl.substitute(this.chronoModel.getOutput(chrono, classifier, outputPath), getFile(chrono,classifier));
        return substitute;
    }
}