All Downloads are FREE. Search and download functionalities are using the official Maven repository.

eu.europa.esig.dss.asic.common.ASiCContent Maven / Gradle / Ivy

There is a newer version: 6.0.d4j.2
Show newest version
/**
 * DSS - Digital Signature Services
 * Copyright (C) 2015 European Commission, provided under the CEF programme
 * 
 * This file is part of the "DSS - Digital Signature Services" project.
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */
package eu.europa.esig.dss.asic.common;

import eu.europa.esig.dss.enumerations.ASiCContainerType;
import eu.europa.esig.dss.model.DSSDocument;
import eu.europa.esig.dss.utils.Utils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Contains grouped documents representing an ASiC container's content
 *
 */
public class ASiCContent implements Serializable {

	private static final long serialVersionUID = -6871206656998856916L;

	/** The original ASiC container */
	private DSSDocument asicContainer;

	/** The container type */
	private ASiCContainerType containerType;

	/** The zip comment */
	private String zipComment;

	/** The mimetype document */
	private DSSDocument mimeTypeDocument;

	/** The list of originally signed documents embedded into the container */
	private List signedDocuments = new ArrayList<>();

	/** The list of signature documents embedded into the container */
	private List signatureDocuments = new ArrayList<>();

	/** The list of manifest documents embedded into the container */
	private List manifestDocuments = new ArrayList<>();

	/** The list of archive manifest documents embedded into the container (ASiC with CAdES) */
	private List archiveManifestDocuments = new ArrayList<>();

	/** The list of evidence record manifest documents embedded into the container */
	private List evidenceRecordManifestDocuments = new ArrayList<>();

	/** The list of timestamp documents embedded into the container (ASiC with CAdES) */
	private List timestampDocuments = new ArrayList<>();

	/** The list of evidence record documents embedded into the container */
	private List evidenceRecordDocuments = new ArrayList<>();

	/** The list of unsupported documents embedded into the container */
	private List unsupportedDocuments = new ArrayList<>();

	/** The list of folders embedded into the container */
	private List folders = new ArrayList<>();

	/** The list of "package.zip" documents (ASiC-S) */
	private List containerDocuments = new ArrayList<>();

	/**
	 * Default constructor instantiating object with null values and empty list of documents
	 */
	public ASiCContent() {
		// empty
	}

	/**
	 * Gets the original ASiC container
	 *
	 * @return {@link DSSDocument}
	 */
	public DSSDocument getAsicContainer() {
		return asicContainer;
	}

	/**
	 * Sets the original ASiC container
	 *
	 * @param asicContainer {@link DSSDocument}
	 */
	public void setAsicContainer(DSSDocument asicContainer) {
		this.asicContainer = asicContainer;
	}

	/**
	 * Gets the container type
	 *
	 * @return {@link ASiCContainerType}
	 */
	public ASiCContainerType getContainerType() {
		return containerType;
	}

	/**
	 * Sets the container type
	 *
	 * @param containerType {@link ASiCContainerType}
	 */
	public void setContainerType(ASiCContainerType containerType) {
		this.containerType = containerType;
	}

	/**
	 * Gets the zip comment
	 *
	 * @return {@link String} zip comment
	 */
	public String getZipComment() {
		return zipComment;
	}

	/**
	 * Sets the zip comment
	 *
	 * @param zipComment {@link String}
	 */
	public void setZipComment(String zipComment) {
		this.zipComment = zipComment;
	}

	/**
	 * Gets mimetype document
	 *
	 * @return {@link DSSDocument}
	 */
	public DSSDocument getMimeTypeDocument() {
		return mimeTypeDocument;
	}

	/**
	 * Sets mimetype document
	 *
	 * @param mimeTypeDocument {@link DSSDocument}
	 */
	public void setMimeTypeDocument(DSSDocument mimeTypeDocument) {
		this.mimeTypeDocument = mimeTypeDocument;
	}

	/**
	 * Gets signature documents
	 *
	 * @return a list of {@link DSSDocument}s
	 */
	public List getSignatureDocuments() {
		return signatureDocuments;
	}

	/**
	 * Sets signature documents
	 *
	 * @param signatureDocuments a list of {@link DSSDocument}s
	 */
	public void setSignatureDocuments(List signatureDocuments) {
		this.signatureDocuments = signatureDocuments;
	}

	/**
	 * Gets manifest documents
	 *
	 * @return a list of {@link DSSDocument}s
	 */
	public List getManifestDocuments() {
		return manifestDocuments;
	}

	/**
	 * Sets manifest documents
	 *
	 * @param manifestDocuments a list of {@link DSSDocument}s
	 */
	public void setManifestDocuments(List manifestDocuments) {
		this.manifestDocuments = manifestDocuments;
	}

	/**
	 * Gets archive manifest documents (ASiC with CAdES only)
	 *
	 * @return a list of {@link DSSDocument}s
	 */
	public List getArchiveManifestDocuments() {
		return archiveManifestDocuments;
	}

	/**
	 * Sets archive manifest documents (ASiC with CAdES only)
	 *
	 * @param archiveManifestDocuments a list of {@link DSSDocument}s
	 */
	public void setArchiveManifestDocuments(List archiveManifestDocuments) {
		this.archiveManifestDocuments = archiveManifestDocuments;
	}

	/**
	 * Gets evidence record manifest documents
	 *
	 * @return a list of {@link DSSDocument}s
	 */
	public List getEvidenceRecordManifestDocuments() {
		return evidenceRecordManifestDocuments;
	}

	/**
	 * Sets a list of evidence record manifest documents
	 *
	 * @param evidenceRecordManifestDocuments a list of {@link DSSDocument}s
	 */
	public void setEvidenceRecordManifestDocuments(List evidenceRecordManifestDocuments) {
		this.evidenceRecordManifestDocuments = evidenceRecordManifestDocuments;
	}

	/**
	 * Gets timestamp documents (ASiC with CAdES only)
	 *
	 * @return a list of {@link DSSDocument}s
	 */
	public List getTimestampDocuments() {
		return timestampDocuments;
	}

	/**
	 * Sets timestamp documents (ASiC with CAdES only)
	 *
	 * @param timestampDocuments a list of {@link DSSDocument}s
	 */
	public void setTimestampDocuments(List timestampDocuments) {
		this.timestampDocuments = timestampDocuments;
	}

	/**
	 * Gets evidence record documents
	 *
	 * @return a list of {@link DSSDocument}s
	 */
	public List getEvidenceRecordDocuments() {
		return evidenceRecordDocuments;
	}

	/**
	 * Sets a list of evidence record documents
	 *
	 * @param evidenceRecordDocuments a list of {@link DSSDocument}s
	 */
	public void setEvidenceRecordDocuments(List evidenceRecordDocuments) {
		this.evidenceRecordDocuments = evidenceRecordDocuments;
	}

	/**
	 * Gets signed documents
	 *
	 * @return a list of {@link DSSDocument}s
	 */
	public List getSignedDocuments() {
		return signedDocuments;
	}

	/**
	 * Sets signed documents
	 *
	 * @param signedDocuments a list of {@link DSSDocument}s
	 */
	public void setSignedDocuments(List signedDocuments) {
		this.signedDocuments = signedDocuments;
	}

	/**
	 * Gets unsupported documents
	 *
	 * @return a list of {@link DSSDocument}s
	 */
	public List getUnsupportedDocuments() {
		return unsupportedDocuments;
	}

	/**
	 * Sets unsupported documents
	 *
	 * @param unsupportedDocuments a list of {@link DSSDocument}s
	 */
	public void setUnsupportedDocuments(List unsupportedDocuments) {
		this.unsupportedDocuments = unsupportedDocuments;
	}

	/**
	 * Returns a list of folders present within the container
	 *
	 * @return a list of {@link DSSDocument}s
	 */
	public List getFolders() {
		return folders;
	}

	/**
	 * Sets a list of folders present within an archive
	 *
	 * @param folders a list of {@link DSSDocument}s
	 */
	public void setFolders(List folders) {
		this.folders = folders;
	}

	/**
	 * Gets "package.zip" documents
	 *
	 * @return a list of {@link DSSDocument}s
	 */
	public List getContainerDocuments() {
		return containerDocuments;
	}

	/**
	 * Sets package.zip" documents
	 *
	 * @param containerDocuments a list of {@link DSSDocument}s
	 */
	public void setContainerDocuments(List containerDocuments) {
		this.containerDocuments = containerDocuments;
	}

	/**
	 * This method returns a list of documents at the root level within the container
	 *
	 * @return a list of {@link DSSDocument}s
	 */
	public List getRootLevelSignedDocuments() {
		if (Utils.isCollectionEmpty(getSignedDocuments())) {
			return Collections.emptyList();
		}
		List rootLevelDocuments = new ArrayList<>();
		for (DSSDocument document : getSignedDocuments()) {
			if (document.getName() != null && !document.getName().contains("/") && !document.getName().contains("\\")) {
				rootLevelDocuments.add(document);
			}
		}
		return rootLevelDocuments;
	}
	
	/**
	 * Returns a list of all found manifest documents
	 * 
	 * @return list of {@link DSSDocument}s
	 */
	public List getAllManifestDocuments() {
		List allManifestsList = new ArrayList<>();
		allManifestsList.addAll(getManifestDocuments());
		allManifestsList.addAll(getArchiveManifestDocuments());
		allManifestsList.addAll(getEvidenceRecordManifestDocuments());
		return allManifestsList;
	}

	/**
	 * Gets all documents
	 *
	 * @return a list of {@link DSSDocument}s
	 */
	public List getAllDocuments() {
		List allDocuments = new ArrayList<>();
		// "mimetype" shall be the first file in the ASiC container;
		if (mimeTypeDocument != null) {
			allDocuments.add(mimeTypeDocument);
		}
		if (Utils.isCollectionNotEmpty(signedDocuments)) {
			allDocuments.addAll(signedDocuments);
		}
		if (Utils.isCollectionNotEmpty(signatureDocuments)) {
			allDocuments.addAll(signatureDocuments);
		}
		if (Utils.isCollectionNotEmpty(manifestDocuments)) {
			allDocuments.addAll(manifestDocuments);
		}
		if (Utils.isCollectionNotEmpty(archiveManifestDocuments)) {
			allDocuments.addAll(archiveManifestDocuments);
		}
		if (Utils.isCollectionNotEmpty(evidenceRecordManifestDocuments)) {
			allDocuments.addAll(evidenceRecordManifestDocuments);
		}
		if (Utils.isCollectionNotEmpty(timestampDocuments)) {
			allDocuments.addAll(timestampDocuments);
		}
		if (Utils.isCollectionNotEmpty(evidenceRecordDocuments)) {
			allDocuments.addAll(evidenceRecordDocuments);
		}
		if (Utils.isCollectionNotEmpty(unsupportedDocuments)) {
			allDocuments.addAll(unsupportedDocuments);
		}
		if (Utils.isCollectionNotEmpty(folders)) {
			allDocuments.addAll(folders);
		}

		return allDocuments;
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy