/*
 * This file (PdfGeneratorFromStream.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.02.01 19:47
 */

package hu.astrid.printxml.generator;

import hu.astrid.printxml.exception.PatientPrintException;

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

/**
 * Can generate PDF from Stream
 * @author inagy
 */
public class PdfGeneratorFromStream extends PdfGenerator<InputStream> {

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

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

    @Override
    public InputStream getAsStream(InputStream input)
            throws PatientPrintException {
        try {
            return getAsURI(input).toURL().openStream();
        } catch (PatientPrintException ex) {
            throw ex;
        } catch (Exception e) {
            throw new PatientPrintException(e);
        }
    }

    @Override
    public URI getAsURI(InputStream input) throws PatientPrintException {
        try {
            PdfGeneratorFromDocument pdfGenFromDoc = new PdfGeneratorFromDocument();
            pdfGenFromDoc.setResourceName(getResourceName());
            pdfGenFromDoc.setTargetFile(this.getTargetFile());
            return pdfGenFromDoc.getAsURI(createDocument(input));
        } catch (PatientPrintException ex) {
            throw ex;
        } catch (Exception e) {
            throw new PatientPrintException(e);
        }
    }
}
