eu.europa.ec.markt.dss.applet.SignatureValidationReportPanel.java Source code

Java tutorial

Introduction

Here is the source code for eu.europa.ec.markt.dss.applet.SignatureValidationReportPanel.java

Source

/*
 * DSS - Digital Signature Services
 *
 * Copyright (C) 2011 European Commission, Directorate-General Internal Market and Services (DG MARKT), B-1049 Bruxelles/Brussel
 *
 * Developed by: 2011 ARHS Developments S.A. (rue Nicolas Bov 2B, L-1253 Luxembourg) http://www.arhs-developments.com
 *
 * This file is part of the "DSS - Digital Signature Services" project.
 *
 * "DSS - Digital Signature Services" 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.
 *
 * DSS 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
 * "DSS - Digital Signature Services".  If not, see <http://www.gnu.org/licenses/>.
 */

package eu.europa.ec.markt.dss.applet;

import eu.europa.ec.markt.dss.applet.io.NativeHTTPDataLoader;
import eu.europa.ec.markt.dss.applet.io.RemoteAIACertificateSourceFactory;
import eu.europa.ec.markt.dss.applet.io.RemoteCRLSource;
import eu.europa.ec.markt.dss.applet.io.RemoteCertificateSource;
import eu.europa.ec.markt.dss.applet.io.RemoteOCSPSource;
import eu.europa.ec.markt.dss.applet.model.SignatureWizardModel;
import eu.europa.ec.markt.dss.applet.wizard.AbstractWizardPanel;
import eu.europa.ec.markt.dss.common.TooltipHelper;
import eu.europa.ec.markt.dss.report.PdfValidationReportService;
import eu.europa.ec.markt.dss.validation.TrustedListCertificateVerifier;
import eu.europa.ec.markt.dss.validation.report.ValidationReport;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.security.Security;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.swing.ToolTipManager;

import org.bouncycastle.jce.provider.BouncyCastleProvider;

/**
 * 
 * Display the validation report to the user.
 * 
 *
 * @version $Revision: 1867 $ - $Date: 2013-04-08 13:44:56 +0200 (Mon, 08 Apr 2013) $
 */

@SuppressWarnings("serial")
public class SignatureValidationReportPanel extends AbstractWizardPanel {

    private static final Logger LOG = Logger.getLogger(SignatureValidationReportPanel.class.getName());

    final private SignatureWizardModel model;

    private SignedDocumentTreeModel original;

    /** Creates new form SignatureValidationReport */
    public SignatureValidationReportPanel(SignatureWizardModel model) {

        Security.addProvider(new BouncyCastleProvider());

        initComponents();
        this.model = model;

        // ToolTipManager.sharedInstance().registerComponent(jTree1);
        TooltipHelper.registerComponentAtTooltipManager(jTree1);

        jTree1.setCellRenderer(new SignedDocumentTreeCellRenderer());
    }

    /**
     * This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The
     * content of this method is always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTree1 = new javax.swing.JTree();
        jButton1 = new javax.swing.JButton();

        setBackground(new java.awt.Color(255, 255, 255));

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11));
        java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("eu/europa/ec/markt/dss/applet/i18n"); // NOI18N
        jLabel1.setText(bundle.getString("SIGNATURE_REPORT")); // NOI18N

        jTree1.setCellRenderer(new SignedDocumentTreeCellRenderer());
        jTree1.setName("validation_tree"); // NOI18N
        jScrollPane1.setViewportView(jTree1);

        jButton1.setText("Save as PDF");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup().addContainerGap()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 380,
                                                Short.MAX_VALUE)
                                        .addGroup(layout.createSequentialGroup().addComponent(jLabel1)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                        187, Short.MAX_VALUE)
                                                .addComponent(jButton1)))
                                .addContainerGap()));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup().addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel1).addComponent(jButton1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 266, Short.MAX_VALUE)
                        .addContainerGap()));
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed

        try {
            ValidationReport report = original.getRoot().validateDocument();
            File tmp = File.createTempFile("validation", ".pdf");
            FileOutputStream output = new FileOutputStream(tmp);

            PdfValidationReportService service = new PdfValidationReportService();
            service.createReport(report, output);

            Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + tmp.toURI().toString());

            output.close();
        } catch (Exception e) {
            LOG.log(Level.SEVERE, "Error when creating PDF", e);
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    @Override
    public void aboutToDisplayPanel() throws IOException {

        RemoteOCSPSource ocspSource = new RemoteOCSPSource();
        ocspSource.setUrl(model.getServiceUrl() + "/ocsp");
        ocspSource.setDataLoader(new NativeHTTPDataLoader());

        RemoteCRLSource crlSource = new RemoteCRLSource();
        crlSource.setDataLoader(new NativeHTTPDataLoader());
        crlSource.setUrl(model.getServiceUrl() + "/crl");

        RemoteCertificateSource certificateSource = new RemoteCertificateSource();
        certificateSource.setDataLoader(new NativeHTTPDataLoader());
        certificateSource.setUrl(model.getServiceUrl() + "/certificate");

        RemoteAIACertificateSourceFactory certificateSourceFactory = new RemoteAIACertificateSourceFactory();

        TrustedListCertificateVerifier verifier = new TrustedListCertificateVerifier();
        verifier.setCrlSource(crlSource);
        verifier.setOcspSource(ocspSource);
        verifier.setTrustedListCertificatesSource(certificateSource);
        verifier.setAiaCertificateSourceFactory(certificateSourceFactory);

        original = new SignedDocumentTreeModel(model.getSignedFile(), model.getOriginalFile(), verifier);

        CachedTreeModel cached = new CachedTreeModel(original);
        jTree1.setModel(cached);

    }

    @Override
    public Object getNextPanelDescriptor() {
        return null;
    }

    @Override
    public Object getBackPanelDescriptor() {
        return SelectDocumentForVerificationPanel.ID;
    }

    @Override
    public Object getPanelDescriptorIdentifier() {
        return ID;
    }

    public static final String ID = "VALIDATION_REPORT";
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTree jTree1;
    // End of variables declaration//GEN-END:variables
}