/*
 * This file (PdfGeneratorFromURI.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:46
 */

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 URI
 *
 * @author inagy
 */
public class PdfGeneratorFromURI extends PdfGenerator<URI> {


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

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

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

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