/*
 * $Id: VKCAdditionalDocumentFormat.java,v 1.18 2005/03/21 20:21:08 marbobo Exp $
 *
 * Copyright (c) Siemens AG 2008 
 *           (c) Universität Paderborn 2008 
 * Licensed under EUPL 1.1. 
 *
 * $Log: VKCAdditionalDocumentFormat.java,v $
 * Revision 1.18  2005/03/21 20:21:08  marbobo
 * + DocSize auf Type Long umgestellt
 *
 * Revision 1.17  2004/10/08 13:58:38  koppy
 * getInputStream verbessert
 *
 * Revision 1.16  2004/03/10 13:04:46  bigmac
 * +toString()
 *
 * Revision 1.15  2003/12/10 14:42:59  koppy
 * Typ von archiveId geändert (Integer -->String)
 *
 * Revision 1.14  2003/11/30 13:05:04  koppy
 * + setInputStream()
 *
 * Revision 1.13  2003/11/29 22:16:05  koppy
 * Um einen Konstruktor erweitert
 *
 * Revision 1.12  2003/11/28 17:15:36  koppy
 * InputStream statt archiveId im constructor
 *
 * Revision 1.11  2003/11/12 16:12:56  jonyp
 * internalFlag set to 0 instead of "null" when the format is not internal
 *
 * Revision 1.10  2003/04/25 13:46:00  koppy
 * Setzen der docTypeId in setDocType(..)
 *
 * 
 * Revision 1.9  2003/03/17 00:42:54  koppy
 * + internalDocFormat-FLAG bei ADDITIONALDOCUMENTFORMATS
 *
 * Revision 1.8  2003/03/14 13:49:39  bigmac
 * *** empty log message ***
 *
 * Revision 1.7  2003/03/10 01:27:00  koppy
 * Anzeige/Speicherung zusätzlicher Formate eines Dokumentes
 *
 * Revision 1.6  2003/03/06 14:11:28  jonyp
 * get/set for ArchiveId
 *
 * Revision 1.5  2003/03/06 13:14:56  lawern
 * Kommentar ergaenzt
 *
 * Revision 1.4  2003/03/06 13:13:37  lawern
 * Felder kommentiert
 *
 * Revision 1.3  2003/03/06 13:07:11  lawern
 * docType auf docTypeId geaendert
 *
 */

package vkc.db.entities;

import java.io.InputStream;
import java.io.Serializable;

import vkc.server.archive.DataStoreException;
import vkc.util.VKCInputStream;
import vkc.view.WebShare;

/**
 * Klasse representiert ein zusätzliches Format
 * eines Dokumentes im VKC-System
 *
 */
public class VKCAdditionalDocumentFormat implements Serializable {
    /**
     * Datenbank-ID des aktuellen Objekts. Ist -1, wenn Objekt noch nicht in Datenbank eingetragen.
     */
    private Integer addDocFormatId = new Integer( -1 );

    /**
     * Datenbank-ID des verknüpften Dokuments
     */
    private Integer documentId;

    /**
     * Dokumententyp-ID aus der DB-Tabelle DOCUMENTTYPES
     */
    private Integer docTypeId;

    /**
     * 1, wenn Datei mit dem ZIP-Algorithmus komprimiert, ansonsten: 0
     */
    private Integer zipped;

    /**
     * Größe der Datei in Bytes
     */
    private Long docSize;

    /**
     * ArchiveID : Wo versteckt sich die Datei...
     */
    private String archiveId;

    /**
     * Der entsprechende Dokumenttyp
     */
    private VKCDocumentType docType;

    /** 1, wenn internes Format, sonst 0 */
    private Integer internalDocFormat = new Integer( 0 );
    
    
    private transient InputStream inputStream  = null;

    public VKCAdditionalDocumentFormat() {
    }

	/**
	 * Constructor
	 * @param is the VKCInputStream
	 * @param docTypeId
	 * @param zipped
	 */
	public VKCAdditionalDocumentFormat( VKCInputStream is, Integer docTypeId, Integer zipped ) {
		this( is, docTypeId, new Long( is.getLength() ), zipped );	
	}	
									   
	
	/**
	 * Constructor
	 * @param is some inputstream
	 * @param docTypeId
	 * @param docSize
	 * @param zipped
	 */
    public VKCAdditionalDocumentFormat( InputStream is, Integer docTypeId, Long docSize, Integer zipped ) {
        this.inputStream = is;
        this.docTypeId = docTypeId;
        this.zipped = zipped;
        this.docSize = docSize;

		if ( this.docTypeId.intValue() == vkc.converter.DocConverter.tdf ) {
		    this.internalDocFormat = new Integer( 1 );
		}
    }

    public void setDocumentId( Integer documentId ) {
        this.documentId = documentId;
    }

    public Integer getDocumentId() {
        return this.documentId;
    }

    public void setAddDocFormatId( Integer addDocFormatId ) {
        this.addDocFormatId = addDocFormatId;
    }

    public Integer getAddDocFormatId() {
        return this.addDocFormatId;
    }

    public void setDocTypeId( Integer docTypeId ) {
        this.docTypeId = docTypeId;
    }

    public Integer getDocTypeId() {
        return this.docTypeId;
    }

    public void setDocType( VKCDocumentType docType ) {
        this.docType = docType;
        this.docTypeId = docType.getDocTypeId();
    }

    public VKCDocumentType getDocType() {
        return this.docType;
    }

    public void setZipped( Integer zipped ) {
        this.zipped = zipped;
    }

    public Integer getZipped() {
        return this.zipped;
    }

    public void setDocSize( Long docSize ) {
        this.docSize = docSize;
    }

    public Long getDocSize() {
        return this.docSize;
    }

    public String getArchiveId() {
        return this.archiveId;
    }

    public void setArchiveId( String archiveId ) {
        this.archiveId = archiveId;
    }

    public Integer getInternalDocFormat() {
		return this.internalDocFormat;
    }

    public void setInternalDocFormat( Integer internalDocFormat ) {
		this.internalDocFormat = internalDocFormat;
    }

	public InputStream getInputStream() throws DataStoreException {
	    if ( inputStream == null ) {
	        inputStream = WebShare.archive.getInputStream( archiveId );
	    }
	    
	    return inputStream;
	}

	public void setInputStream( InputStream stream ) {
		inputStream = stream;
	}
	
	public String toString() {
		return 
			"Additional document format: docFormatId = " + addDocFormatId +
			", archiveId = " + archiveId +
			", internal = " + internalDocFormat +
			", docSize = " + docSize +
			", docTypeId = " + docTypeId;
	}
}