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

es.gob.afirma.standalone.crypto.CertificateInfo Maven / Gradle / Ivy

There is a newer version: 1.8.2
Show newest version
/* Copyright (C) 2011 [Gobierno de Espana]
 * This file is part of "Cliente @Firma".
 * "Cliente @Firma" is free software; you can redistribute it and/or modify it under the terms of:
 *   - the GNU General Public License as published by the Free Software Foundation;
 *     either version 2 of the License, or (at your option) any later version.
 *   - or The European Software License; either version 1.1 or (at your option) any later version.
 * You may contact the copyright holder at: [email protected]
 */

package es.gob.afirma.standalone.crypto;

import java.security.cert.X509Certificate;

import javax.swing.Icon;
import javax.swing.ImageIcon;

import es.gob.afirma.core.misc.AOUtil;
import es.gob.afirma.core.misc.Platform;
import es.gob.afirma.standalone.SimpleAfirmaMessages;

/** Información para la visualización y validación del certificado.
 * @author Carlos gamuci Millán */
public final class CertificateInfo {

    /** Icono ilustrativo del Certificado. */
    private final Icon icon;

    private final String iconTooltip;

    /** Texto descriptivo del certificado. */
    private String descriptionText;

    /** Construye el objeto con la información del certificado.
     * @param cert Certificado al cual se refierre la información
     * @param description Texto descriptivo del certificado.
     * @param i Icono para el certificado
     * @param iTooltip Tooltip para el icono del certificado */
    CertificateInfo(final X509Certificate cert,
    		        final String description,
    		        final Icon i,
    		        final String iTooltip) {

		final boolean isMac = Platform.OS.MACOSX.equals(Platform.getOS());
    	if (description == null || description.isEmpty()) {
        	if (cert == null) {
        		this.descriptionText = SimpleAfirmaMessages.getString("CertificateInfo.0"); //$NON-NLS-1$
        	}
        	else {
        		this.descriptionText =
    				"" + //$NON-NLS-1$
					(isMac ? "
" : "") + //$NON-NLS-1$ //$NON-NLS-2$ SimpleAfirmaMessages.getString("CertificateInfo.1") + //$NON-NLS-1$ ": " + //$NON-NLS-1$ (isMac ? "" : "") + //$NON-NLS-1$ //$NON-NLS-2$ AOUtil.getCN(cert) + (isMac ? "" : "") + //$NON-NLS-1$//$NON-NLS-2$ ". " + //$NON-NLS-1$ SimpleAfirmaMessages.getString("CertificateInfo.2") + //$NON-NLS-1$ ": " + //$NON-NLS-1$ "" + //$NON-NLS-1$ AOUtil.getCN(cert.getIssuerX500Principal().toString()) + "" + //$NON-NLS-1$ ""; //$NON-NLS-1$ } } else { this.descriptionText = "" + (isMac ? "
" : "") + "" + description + "" + ""; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ } if (i == null) { this.icon = new ImageIcon(this.getClass().getResource("/resources/default_cert_ico.png")); //$NON-NLS-1$ } else { this.icon = i; } if (iTooltip == null) { this.iconTooltip = SimpleAfirmaMessages.getString("CertificateInfo.3"); //$NON-NLS-1$ } else { this.iconTooltip = iTooltip; } } /** Obtiene el icono del certificado. * @return Icono del certificado. */ public Icon getIcon() { return this.icon; } /** Obtiene el texto del tooltip para el icono del certificado. * @return Texto del tooltip para el icono del certificado. */ public String getIconTooltip() { return this.iconTooltip; } /** Obtiene un texto descriptivo del certificado. * @return Descripción del certificado. */ public String getDescriptionText() { return this.descriptionText; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy