com.sazneo.export.formatter.Main.java Source code

Java tutorial

Introduction

Here is the source code for com.sazneo.export.formatter.Main.java

Source

/*
 * Copyright 2012 Sazneo.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.sazneo.export.formatter;

import com.sazneo.export.file.FileProcessor;
import com.sazneo.export.formatter.html.HtmlFormatter;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.MessageFormat;

/**
 * Main entry point for application
 */
public class Main {

    public static void main(String... args) {

        Log logger = LogFactory.getLog(Main.class);

        if (args.length != 3) {
            logger.error("Usage: java Main <stylesheet> <export xml file> <output dir>");
            System.exit(1);
        }

        String styleSheetPath = args[0];
        File styleSheet = new File(styleSheetPath);

        String exportXmlPath = args[1];
        File exportXml = new File(exportXmlPath);

        String outPutDirPath = args[2];
        File outputDir = new File(outPutDirPath);
        if (!outputDir.exists()) {
            outputDir.mkdirs();
        }

        try {
            File outputFile = new File(outputDir, "export.html");
            FileOutputStream outputStream = new FileOutputStream(outputFile);
            HtmlFormatter formatter = new HtmlFormatter(styleSheet, exportXml, outputStream);
            formatter.transform();
            FileProcessor fileProcessor = new FileProcessor(exportXml, outputDir);
            fileProcessor.process();

        } catch (IOException e) {
            logger.error(MessageFormat.format("Failed to create export.html at {0}:\n {1}", outPutDirPath, e));
        }
    }
}