/*
 * This file (PdfGeneratorFromDocument.java) is part of DebGen-ReportPrintLib  developed by ASTRID Research.
 * All rights reserved. Reproduction, modification, use or disclosure
 * to third parties without express authority is forbidden.
 *
 *  Copyright ASTRID Research, Hungary, 2010.
 *
 *  ASTRID Research
 *  Headquaters: Csapó utca 42. Debrecen H-4029 HUNGARY
 *  Phone: +36-52-533-173        Fax: +36-52-533-174
 *  Web: http://www.astrid.hu    E-mail: info@astrid.hu
 *
 * Project name: DEBGEN-Biobank-Project.
 * File last modified at 2010.01.06 20:12
 */

package hu.astrid.printxml.generator;

import hu.astrid.printxml.exception.PatientPrintException;
import org.w3c.dom.Document;

import java.io.FileInputStream;
import java.io.InputStream;
import java.net.URI;
import java.util.Locale;

/**
 * Can generate PDF from DOM Document
 * @author inagy
 */
public class PdfGeneratorFromDocument extends PdfGenerator<Document> {

    /**
     * Default Constructor
     */
    public PdfGeneratorFromDocument() {
        super();
    }

    /**
     * Creates a new PdfGeneratorFromDocument instance, and sets the locale of the PDF document
     * @param locale The locale of the PDF
     */
    public PdfGeneratorFromDocument(Locale locale) {
        super(locale);
    }

    @Override
    public InputStream getAsStream(Document document) throws PatientPrintException {
        try {
            return new FileInputStream(generatePdf(document));
        } catch (PatientPrintException ex) {
            throw ex;
        } catch (Exception e) {
            e.printStackTrace();
            throw new PatientPrintException(e);
        }
    }

    @Override
    public URI getAsURI(Document document) throws PatientPrintException {
        try {
            return generatePdfAsFile(document).toURI();
        } catch (PatientPrintException ex) {
            throw ex;
        } catch (Exception e) {
            throw new PatientPrintException(e);
        }
    }
}
