xades4j.production.QualifyingPropertiesProcessor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of xades4j Show documentation
Show all versions of xades4j Show documentation
The XAdES4j library is an high-level, configurable and extensible Java implementation of XML Advanced
Electronic Signatures (XAdES 1.3.2 and 1.4.1). It enables producing, verifying and extending signatures in the
main XAdES forms: XAdES-BES, XAdES-EPES, XAdES-T and XAdES-C. Also, extended forms are supported through the
enrichment of an existing signature.
/*
* XAdES4j - A Java library for generation and verification of XAdES signatures.
* Copyright (C) 2010 Luis Goncalves.
*
* XAdES4j 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 3 of the License, or any later version.
*
* XAdES4j 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 XAdES4j. If not, see .
*/
package xades4j.production;
import xades4j.properties.UnsignedProperties;
import xades4j.properties.SignedProperties;
import xades4j.properties.QualifyingProperties;
import xades4j.properties.DataObjectDesc;
import xades4j.properties.UnsignedDataObjectProperty;
import xades4j.properties.UnsignedSignatureProperty;
import xades4j.properties.SignedSignatureProperty;
import xades4j.properties.SignedDataObjectProperty;
import xades4j.providers.DataObjectPropertiesProvider;
import xades4j.providers.SignaturePropertiesProvider;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
/**
* Helper class that gathers the qualifying properties from the different providers
* and data object desriptions.
* @author Luís
*/
class QualifyingPropertiesProcessor
{
private final SignaturePropertiesProvider sigPropsProvider;
private final DataObjectPropertiesProvider dataObjPropsProvider;
public QualifyingPropertiesProcessor(
SignaturePropertiesProvider sigPropsProvider,
DataObjectPropertiesProvider dataObjPropsProvider)
{
this.sigPropsProvider = sigPropsProvider;
this.dataObjPropsProvider = dataObjPropsProvider;
}
QualifyingProperties getQualifyingProperties(
SignedDataObjects dataObjs,
Collection formatSpecificSignedSigProps,
Collection formatSpecificUnsignedSigProps)
{
/* **** Signature properties **** */
// Collect the signature properties from the provider.
SignaturePropertiesCollectorImpl signaturePropsCollector = new SignaturePropertiesCollectorImpl();
sigPropsProvider.provideProperties(signaturePropsCollector);
Collection collectedSignedSigProps = signaturePropsCollector.getSignedSigProps();
Collection signedSigProps = new ArrayList(
collectedSignedSigProps.size() + formatSpecificSignedSigProps.size());
signedSigProps.addAll(collectedSignedSigProps);
signedSigProps.addAll(formatSpecificSignedSigProps);
Collection collectedUnsignedSigProps = signaturePropsCollector.getUnsignedSigProps();
Collection unsignedSigProps = new ArrayList(
collectedUnsignedSigProps.size() + formatSpecificUnsignedSigProps.size());
unsignedSigProps.addAll(collectedUnsignedSigProps);
unsignedSigProps.addAll(formatSpecificUnsignedSigProps);
/* **** Data objects properties **** */
Collection dataObjsInfo = dataObjs.getDataObjectsDescs();
// The containers for all the specified signed data object properties. Since
// some properties can be applied to multiple data objects, we need to rule
// out repeated references (a Set is used).
Set signedDataObjProps = new HashSet(dataObjsInfo.size());
Set unsignedDataObjProps = new HashSet(0);
// Add the global data object properties.
signedDataObjProps.addAll(dataObjs.getSignedDataObjsProperties());
unsignedDataObjProps.addAll(dataObjs.getUnsignedDataObjsProperties());
// Add the properties specified for each data object.
for (DataObjectDesc dataObjInfo : dataObjsInfo)
{
// If no properties were specified allow the provider to add them.
if (!dataObjInfo.hasProperties())
this.dataObjPropsProvider.provideProperties(dataObjInfo);
signedDataObjProps.addAll(dataObjInfo.getSignedDataObjProps());
unsignedDataObjProps.addAll(dataObjInfo.getUnsignedDataObjProps());
}
/* **** */
return new QualifyingProperties(
new SignedProperties(signedSigProps, signedDataObjProps),
new UnsignedProperties(unsignedSigProps, unsignedDataObjProps));
}
}