/*
 * $Id: DocumentViewSettings.java,v 1.6 2005/09/04 18:03:56 marbobo Exp $
 *
 * Copyright (c) Siemens AG 2008 
 *           (c) Universität Paderborn 2008 
 * Licensed under EUPL 1.1. 
 *
 * $Log: DocumentViewSettings.java,v $
 * Revision 1.6  2005/09/04 18:03:56  marbobo
 * + Neues Metadaten-Attribute (Erstellungsdatum) für Dokumente hinzugefügt
 *
 * Revision 1.5  2004/11/09 14:35:42  marbobo
 * + Umstellung von authorId auf publisherId
 * + Hinzufügen von AuthorName für Dokumente
 * + Nötwendige Änderungen betreffend AuthorName und PublisherId
 *
 * Revision 1.4  2004/07/20 08:51:21  jonyp
 * added copyright info + cvs log
 *
 *
 */

package vkc.view.bean;

import java.io.Serializable;
import java.util.HashMap;

import vkc.db.serializer.VKCDocumentViewFieldSerializer;
import vkc.exception.DBException;

public final class DocumentViewSettings implements Serializable {
	private boolean fileName = false;
	private boolean fileFormat = false;
	private boolean fileSize = false;
	private boolean classType = false;
	private boolean statusType = false;
	private boolean versionNo = false;
	private boolean versionLabel = false;
	private boolean versionDescr = false;
	private boolean creationDate = false;
	private boolean expires = false;
	private boolean published = false;
	private boolean author = false;
	private boolean publisher = false;
	private boolean accessCount = false;
	private boolean lastAccessed = false;
	private boolean keywords = false;
	private boolean description = false;
	private boolean additionalFormats = false;
	private boolean dynaAttributes = false;
	private boolean addAttributes = false; 

	public boolean isAccessCount() {
		return accessCount;
	}

	public boolean isAccessCountORLastAccessed() {
		return isAccessCount() || isLastAccessed();
	}

	public boolean isAddAttributes() {
		return addAttributes;
	}

	public boolean isAdditionalFormats() {
		return additionalFormats;
	}

	public boolean isAuthor() {
		return author;
	}

	public boolean isClassType() {
		return classType;
	}

	public boolean isClassTypeORFileSize() {
		return isClassType() || isFileSize();
	}

	public boolean isDescription() {
		return description;
	}

	public boolean isDynaAttributes() {
		return dynaAttributes;
	}

	public boolean isCreationDate() {
		return creationDate;
	}
	
	public boolean isCreationDateORPublisher() {
		return isCreationDate() || isPublisher();
	}

	public boolean isExpires() {
		return expires;
	}

	public boolean isFileFormat() {
		return fileFormat;
	}

	public boolean isFileName() {
		return fileName;
	}

	public boolean isFileNameORFileFormat() {
		return isFileName() || isFileFormat();
	}

	public boolean isFileSize() {
		return fileSize;
	}

	public boolean isKeywords() {
		return keywords;
	}

	public boolean isLastAccessed() {
		return lastAccessed;
	}

	public boolean isPublished() {
		return published;
	}

	public boolean isPublishedORAuthor() {
		return isPublished() || isAuthor();
	}

	public boolean isPublisher() {
		return publisher;
	}

	public boolean isStatusType() {
		return statusType;
	}

	public boolean isVersionDescr() {
		return versionDescr;
	}

	public boolean isVersionLabel() {
		return versionLabel;
	}

	public boolean isVersionNo() {
		return versionNo;
	}

	public boolean isVersionDescrORExpires() {
		return isVersionDescr() || isExpires();
	}

	public boolean isVersionNoORVersionLabel() {
		return isVersionNo() || isVersionLabel();
	}

	public void setAccessCount(boolean b) {
		accessCount = b;
	}

	public void setAddAttributes(boolean b) {
		addAttributes = b;
	}

	public void setAdditionalFormats(boolean b) {
		additionalFormats = b;
	}

	public void setAuthor(boolean b) {
		author = b;
	}

	public void setDescription(boolean b) {
		description = b;
	}

	public void setDynaAttributes(boolean b) {
		dynaAttributes = b;
	}

	public void setCreationDate(boolean b) {
		creationDate = b;
	}

	public void setExpires(boolean b) {
		expires = b;
	}

	public void setKeywords(boolean b) {
		keywords = b;
	}

	public void setLastAccessed(boolean b) {
		lastAccessed = b;
	}

	public void setPublished(boolean b) {
		published = b;
	}

	public void setPublisher(boolean b) {
		publisher = b;
	}

	public void setVersionDescr(boolean b) {
		versionDescr = b;
	}

	public void setVersionLabel(boolean b) {
		versionLabel = b;
	}

	public void setVersionNo(boolean b) {
		versionNo = b;
	}
	
	public HashMap getDocumentViewFields() throws DBException {
		HashMap fields = VKCDocumentViewFieldSerializer.getAllDocumentViewFields();
		HashMap elements = new HashMap();

		if (isFileName()) {
			elements.put("fileName", fields.get("fileName"));
		}

		if (isFileFormat()) {
			elements.put("fileFormat", fields.get("fileFormat"));
		}

		if (isFileSize()) {
			elements.put("fileSize", fields.get("fileSize"));
		}

		if (isClassType()) {
			elements.put("classType", fields.get("classType"));
		}

		if (isStatusType()) {
			elements.put("statusType", fields.get("statusType"));
		}

		if (isVersionNo()) {
			elements.put("versionNo", fields.get("versionNo"));
		}

		if (isVersionLabel()) {
			elements.put("versionLabel", fields.get("versionLabel"));
		}

		if (isVersionDescr()) {
			elements.put("versionDescr", fields.get("versionDescr"));
		}

		if (isExpires()) {
			elements.put("expires", fields.get("expires"));
		}

		if (isPublished()) {
			elements.put("published", fields.get("published"));
		}

		if (isAuthor()) {
			elements.put("author", fields.get("author"));
		}

		if (isCreationDate()) {
			elements.put("creationDate", fields.get("creationDate"));
		}

		if (isPublisher()) {
			elements.put("publisher", fields.get("publisher"));
		}

		if (isAccessCount()) {
			elements.put("accessCount", fields.get("accessCount"));
		}

		if (isLastAccessed()) {
			elements.put("lastAccessed", fields.get("lastAccessed"));
		}

		if (isKeywords()) {
			elements.put("keywords", fields.get("keywords"));
		}

		if (isDescription()) {
			elements.put("description", fields.get("description"));
		}

		if (isAdditionalFormats()) {
			elements.put("additionalFormats", fields.get("additionalFormats"));
		}

		if (isDynaAttributes()) {
			elements.put("dynaAttributes", fields.get("dynaAttributes"));
		}

		if (isAddAttributes()) {
			elements.put("addAttributes", fields.get("addAttributes"));
		}

		return elements;
	}

	public void setDocViewElements( HashMap elements ) throws DBException {
		if (elements.isEmpty()) {
			elements = VKCDocumentViewFieldSerializer.getAllDefaultDocumentViewFields();
		}
		
		if (elements.containsKey("fileName")) {
			setFileName(true);
		}

		if (elements.containsKey("fileFormat")) {
			setFileFormat(true);
		}

		if (elements.containsKey("fileSize")) {
			setFileSize(true);
		}

		if (elements.containsKey("classType")) {
			setClassType(true);
		}

		if (elements.containsKey("statusType")) {
			setStatusType(true);
		}

		if (elements.containsKey("versionNo")) {
			setVersionNo(true);
		}

		if (elements.containsKey("versionLabel")) {
			setVersionLabel(true);
		}

		if (elements.containsKey("versionDescr")) {
			setVersionDescr(true);
		}

		if (elements.containsKey("expires")) {
			setExpires(true);
		}

		if (elements.containsKey("published")) {
			setPublished(true);
		}

		if (elements.containsKey("author")) {
			setAuthor(true);
		}

		if (elements.containsKey("creationDate")) {
			setCreationDate(true);
		}

		if (elements.containsKey("publisher")) {
			setPublisher(true);
		}

		if (elements.containsKey("accessCount")) {
			setAccessCount(true);
		}

		if (elements.containsKey("lastAccessed")) {
			setLastAccessed(true);
		}

		if (elements.containsKey("keywords")) {
			setKeywords(true);
		}

		if (elements.containsKey("description")) {
			setDescription(true);
		}

		if (elements.containsKey("additionalFormats")) {
			setAdditionalFormats(true);
		}

		if (elements.containsKey("dynaAttributes")) {
			setDynaAttributes(true);
		}

		if (elements.containsKey("addAttributes")) {
			setAddAttributes(true);
		}
	}

	public DocumentViewSettings getFullviewDocumentViewSettings() {
		DocumentViewSettings view = new DocumentViewSettings();
		
		view.setFileName(true);
		view.setFileFormat(true);
		view.setFileSize(true);
		view.setClassType(true);
		view.setStatusType(true);
		view.setVersionNo(true);
		view.setVersionLabel(true);
		view.setVersionDescr(true);
		view.setExpires(true);
		view.setPublished(true);
		view.setAuthor(true);
		view.setCreationDate(true);
		view.setPublisher(true);
		view.setAccessCount(true);
		view.setLastAccessed(true);
		view.setKeywords(true);
		view.setDescription(true);
		view.setAdditionalFormats(true);
		view.setDynaAttributes(true);
		view.setAddAttributes(true);
		
		return view;
	}

	public DocumentViewSettings getDefaultviewDocumentViewSettings() throws DBException {
		DocumentViewSettings view = new DocumentViewSettings();
		
		HashMap	elements = VKCDocumentViewFieldSerializer.getAllDefaultDocumentViewFields();
		
		if (elements.containsKey("fileName")) {
			view.setFileName(true);
		} else {
			view.setFileName(false);
		}

		if (elements.containsKey("fileFormat")) {
			view.setFileFormat(true);
		} else {
			view.setFileFormat(false);
		}

		if (elements.containsKey("fileSize")) {
			view.setFileSize(true);
		} else {
			view.setFileSize(false);
		}

		if (elements.containsKey("classType")) {
			view.setClassType(true);
		} else {
			view.setClassType(false);
		}

		if (elements.containsKey("statusType")) {
			view.setStatusType(true);
		} else {
			view.setStatusType(false);
		}

		if (elements.containsKey("versionNo")) {
			view.setVersionNo(true);
		} else {
			view.setVersionNo(false);
		}

		if (elements.containsKey("versionLabel")) {
			view.setVersionLabel(true);
		} else {
			view.setVersionLabel(false);
		}

		if (elements.containsKey("versionDescr")) {
			view.setVersionDescr(true);
		} else {
			view.setVersionDescr(false);
		}

		if (elements.containsKey("expires")) {
			view.setExpires(true);
		} else {
			view.setExpires(false);
		}

		if (elements.containsKey("published")) {
			view.setPublished(true);
		} else {
			view.setPublished(false);
		}

		if (elements.containsKey("author")) {
			view.setAuthor(true);
		} else {
			view.setAuthor(false);
		}

		if (elements.containsKey("creationDate")) {
			view.setCreationDate(true);
		} else {
			view.setCreationDate(false);
		}

		if (elements.containsKey("publisher")) {
			view.setPublisher(true);
		} else {
			view.setPublisher(false);
		}

		if (elements.containsKey("accessCount")) {
			view.setAccessCount(true);
		} else {
			view.setAccessCount(false);
		}

		if (elements.containsKey("lastAccessed")) {
			view.setLastAccessed(true);
		} else {
			view.setLastAccessed(false);
		}

		if (elements.containsKey("keywords")) {
			view.setKeywords(true);
		} else {
			view.setKeywords(false);
		}

		if (elements.containsKey("description")) {
			view.setDescription(true);
		} else {
			view.setDescription(false);
		}

		if (elements.containsKey("additionalFormats")) {
			view.setAdditionalFormats(true);
		} else {
			view.setAdditionalFormats(false);
		}

		if (elements.containsKey("dynaAttributes")) {
			view.setDynaAttributes(true);
		} else {
			view.setDynaAttributes(false);
		}

		if (elements.containsKey("addAttributes")) {
			view.setAddAttributes(true);
		} else {
			view.setAddAttributes(false);
		}
		
		return view;
	}
	
	public boolean isDefaultViewSetting() throws DBException {
		HashMap	elements = VKCDocumentViewFieldSerializer.getAllDefaultDocumentViewFields();
		
		if (!elements.containsKey("fileName")) {
			if (isFileName()) {
				return false;
			}
		}

		if (!elements.containsKey("fileFormat")) {
			if (isFileFormat()) {
				return false;
			}
		}

		if (!elements.containsKey("fileSize")) {
			if (isFileSize()) {
				return false;
			}
		}

		if (!elements.containsKey("classType")) {
			if (isClassType()) {
				return false;
			}
		}

		if (!elements.containsKey("statusType")) {
			if (isStatusType()) {
				return false;
			}
		}

		if (!elements.containsKey("versionNo")) {
			if (isVersionNo()) {
				return false;
			}
		}

		if (!elements.containsKey("versionLabel")) {
			if (isVersionLabel()) {
				return false;
			}
		}

		if (!elements.containsKey("versionDescr")) {
			if (isVersionDescr()) {
				return false;
			}
		}

		if (!elements.containsKey("expires")) {
			if (isExpires()) {
				return false;
			}
		}

		if (!elements.containsKey("published")) {
			if (isPublished()) {
				return false;
			}
		}

		if (!elements.containsKey("author")) {
			if (isAuthor()) {
				return false;
			}
		}

		if (!elements.containsKey("creationDate")) {
			if (isCreationDate()) {
				return false;
			}
		}

		if (!elements.containsKey("publisher")) {
			if (isPublisher()) {
				return false;
			}
		}

		if (!elements.containsKey("accessCount")) {
			if (isAccessCount()) {
				return false;
			}
		}

		if (!elements.containsKey("lastAccessed")) {
			if (isLastAccessed()) {
				return false;
			}
		}

		if (!elements.containsKey("keywords")) {
			if (isKeywords()) {
				return false;
			}
		}

		if (!elements.containsKey("description")) {
			if (isDescription()) {
				return false;
			}
		}

		if (!elements.containsKey("additionalFormats")) {
			if (isAdditionalFormats()) {
				return false;
			}
		}

		if (!elements.containsKey("dynaAttributes")) {
			if (isDynaAttributes()) {
				return false;
			}
		}

		if (!elements.containsKey("addAttributes")) {
			if (isAddAttributes()) {
				return false;
			}
		}

		return true;
	}

	public void setClassType(boolean b) {
		classType = b;
	}

	public void setFileFormat(boolean b) {
		fileFormat = b;
	}

	public void setFileName(boolean b) {
		fileName = b;
	}

	public void setFileSize(boolean b) {
		fileSize = b;
	}

	public void setStatusType(boolean b) {
		statusType = b;
	}
}