Package pdfrobot

Source Code of pdfrobot.PdfRobotApplication

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package pdfrobot;

import java.awt.SystemTray;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Timer;
import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
import javax.swing.UnsupportedLookAndFeelException;
import pdfrobot.engine.parser.PdfFileParser;
import pdfrobot.engine.parser.PdfFileRule;
import pdfrobot.engine.parser.SerializedFileRules;
import pdfrobot.engine.robot.PdfRobotScheduledJob;
import pdfrobot.gui.GuiManager;
import pdfrobot.logging.LogRecordBuffer;
import pdfrobot.settings.ApplicationSettings;

/**
*
* @author hedsttor
*/
public class PdfRobotApplication implements Application {

    Timer executionTimer;
    String osName;
    String osVer;
    boolean systemTraySupported;

    public PdfRobotApplication() {
    }

    private int run() throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException {
        osName = System.getProperty("os.name");
        osVer = System.getProperty("os.version");
        systemTraySupported = SystemTray.isSupported();      
        GuiManager.getInstance().startGui(this);
        Logger.getLogger(PdfRobotApplication.class.getName()).log(Level.INFO, "Starting application. Checking for quarentine folder...");
        File quarentineFolder = new File("Quarentined");
        if(quarentineFolder.exists() && quarentineFolder.isDirectory()) {
            Logger.getLogger(PdfRobotApplication.class.getName()).log(Level.INFO, "Quarentine folder ok... ");
        }
        else {
            Logger.getLogger(PdfRobotApplication.class.getName()).log(Level.INFO, "Quarentine folder does not exist. Creating it... ");
            quarentineFolder.mkdir();
            Logger.getLogger(PdfRobotApplication.class.getName()).log(Level.INFO, "Quarentine folder created. ");
        }
        return 0;
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        try {
            LogManager.getLogManager().readConfiguration(File.class.getResourceAsStream("/config/logconf.cfg"));
        } catch (IOException ex) {
            Logger.getLogger(PdfRobotApplication.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SecurityException ex) {
            Logger.getLogger(PdfRobotApplication.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            new PdfRobotApplication().run();
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(PdfRobotApplication.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            Logger.getLogger(PdfRobotApplication.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            Logger.getLogger(PdfRobotApplication.class.getName()).log(Level.SEVERE, null, ex);
        } catch (UnsupportedLookAndFeelException ex) {
            Logger.getLogger(PdfRobotApplication.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public List<PdfFileRule> getFileRules() {
        //return new PdfFileRules().getRules();
        return new SerializedFileRules().getRules();
    }

    public String extractTextFromPdf(File selectedFile) {
        String text = "";
        try {
            text = new PdfFileParser().parsePdf(selectedFile);
        } catch (IOException ex) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "IOException extracting text.", ex);
        }
        return text;
    }

    public boolean savePdfRule(PdfFileRule rule) throws RuleAlreadyExistsException {
        //return new PdfFileRules().saveRule(line, pattern, folder);
        return new SerializedFileRules().saveRule(rule);
    }

    public void startTimer(long intervalInSeconds) {
        executionTimer = new Timer("pdfRobotTimer");
        executionTimer.schedule(new PdfRobotScheduledJob(), 0, intervalInSeconds * 1000);
    }

    public void stopTimer() {
        executionTimer.cancel();
    }

    public void saveRules(List<PdfFileRule> ruleModel) {
        new SerializedFileRules().saveRules(ruleModel);
    }

    public void saveStartDirectory(File startDirectory) {
        ApplicationSettings.getInstance().getFileSettings().setStartDirectory(startDirectory);
    }

    public File getStartDirectory() {
        return ApplicationSettings.getInstance().getFileSettings().getStartDirectory();
    }

    public LogRecord[] getRecords(int numberOfRecords) {
        return LogRecordBuffer.getInstance().get(numberOfRecords);
    }
}
TOP

Related Classes of pdfrobot.PdfRobotApplication

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.