Differencer.java

package org.docascode.api.diff;

import org.apache.commons.io.FilenameUtils;
import org.docascode.api.core.errors.DocAsCodeException;
import org.docascode.api.event.Event;

import java.awt.*;
import java.io.IOException;

public class Differencer extends AbstractDifferencer{
    @Override
    public void diff() throws DocAsCodeException {
        AbstractDifferencer diff;
        String extension = FilenameUtils.getExtension(targetFile.getAbsolutePath());
        if (extension.equals("docx")) {
            diff = new DocxDifferencer();
        } else {
            Event e = new Event(this);
            e.setMessage(String.format(
                    "No Diff driver for %s.",
                    targetFile.getAbsolutePath()));
            fireEvent(e);
            return;
        }
        ((AbstractDifferencer) diff.addListener(this))
             .setBaseFile(this.baseFile)
             .setRevisedFile(this.revisedFile)
             .setTargetFile(this.targetFile)
             .setRevision(this.revision)
             .openAtEnd(openAtEnd)
             .diff();
        if (openAtEnd) {
            Desktop desktop;
            if (Desktop.isDesktopSupported()) {
                desktop = Desktop.getDesktop();
                try {
                    Event e = new Event(this);
                    e.setMessage(
                            String.format(
                                    "Opening '%s'.",
                                    targetFile));
                    e.setLevel(Event.Level.SUCESS);
                    fireEvent(e);
                    desktop.open(targetFile);
                } catch (IOException e) {
                    throw new DocAsCodeException(
                            String.format(
                                    "Unable to open file '%s",
                                    targetFile), e);
                }
            }
        }
    }
}