package cz.hobrasoft.pdfmu.sign;

import com.itextpdf.text.pdf.PdfSignatureAppearance;
import com.itextpdf.text.pdf.PdfStamper;
import cz.hobrasoft.pdfmu.ArgsConfiguration;
import java.util.Calendar;
import net.sourceforge.argparse4j.inf.Namespace;

/**
 *
 * @author <a href="mailto:filip.bartek@hobrasoft.cz">Filip Bartek</a>
 */
class SignatureAppearanceParameters implements ArgsConfiguration {

    public String reason = null;
    public String location = null;
    public String name = null;
    public String contact = null;
    public Calendar signDate = null;
    public int certificationLevel = PdfSignatureAppearance.NOT_CERTIFIED;

    @Override
    public void setFromNamespace(Namespace namespace) {
        reason = namespace.getString("reason");
        location = namespace.getString("location");
        name = namespace.getString("name");
        contact = namespace.getString("contact");
        // TODO?: Expose `signDate`
        // TODO?: Expose `certificationLevel`
    }

    public void configureSignatureAppearance(PdfSignatureAppearance sap) {
        assert sap != null;
        // Configure signature metadata
        if (reason != null) {
            System.err.println(String.format("Reason: %s", reason));
            sap.setReason(reason);
        }
        if (location != null) {
            System.err.println(String.format("Location: %s", location));
            sap.setLocation(location);
        }
        if (name != null) {
            // `setVisibleSignature(null)` crashes
            System.err.println(String.format("Name: %s", name));
            sap.setVisibleSignature(name);
        }
        if (contact != null) {
            System.err.println(String.format("Contact: %s", contact));
            sap.setContact(contact);
        }
        if (signDate != null) {
            // `setSignDate(null)` crashes
            System.err.println(String.format("Date: %s", signDate));
            sap.setSignDate(signDate);
        }
        sap.setCertificationLevel(certificationLevel);
    }

    public PdfSignatureAppearance getSignatureAppearance(PdfStamper stp) {
        assert stp != null;
        // Initialize the signature appearance
        PdfSignatureAppearance sap = stp.getSignatureAppearance();
        configureSignatureAppearance(sap);
        return sap;
    }

}

@@ -812,52 +812,8 @@
 %22);%0A
-        name = namespace.getString(%22name%22);%0A
     
@@ -1392,205 +1392,8 @@
   %7D%0A
-        if (name != null) %7B%0A            // %60setVisibleSignature(null)%60 crashes%0A            System.err.println(String.format(%22Name: %25s%22, name));%0A            sap.setVisibleSignature(name);%0A        %7D%0A
     

Remove `name` member (not useful)