Commit ee769fe9 authored by Rene Lottes's avatar Rene Lottes
Browse files

Let the user open the PDF in external viewer,

parent c05c7e26
......@@ -20,6 +20,12 @@
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.openecard.addons</groupId>
<artifactId>tr03112</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.bitbucket.b_c</groupId>
<artifactId>jose4j</artifactId>
......
......@@ -20,6 +20,8 @@ import org.openecard.addon.bind.HeaderEntry;
import org.openecard.addon.bind.Headers;
import org.openecard.addon.bind.RequestBody;
import org.openecard.addons.reqesidta.ReqesidtaProperties;
import org.openecard.binding.tctoken.TR03112Keys;
import org.openecard.common.DynamicContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -59,6 +61,8 @@ public class SignRequest {
throw new InvalidHashException("Hash algorithm %s is not allowed by the system.");
}
DynamicContext dynCtx = DynamicContext.getInstance(TR03112Keys.INSTANCE_KEY);
dynCtx.put("PDF_DOCUMENT", doc);
return new SignRequest(hashAlg, sigAlg, ssaUri, doc);
}
......
......@@ -22,12 +22,16 @@
package org.openecard.sal.protocol.eac.gui;
import org.openecard.binding.tctoken.TR03112Keys;
import org.openecard.common.DynamicContext;
import org.openecard.common.I18n;
import org.openecard.gui.definition.Document;
import org.openecard.gui.definition.InputInfoUnit;
import org.openecard.sal.protocol.eac.anytype.PACEMarkerType;
import org.openecard.gui.definition.PasswordField;
import org.openecard.gui.definition.Step;
import org.openecard.gui.definition.Text;
import org.openecard.gui.definition.ToggleText;
import org.openecard.sal.protocol.eac.EACData;
import org.openecard.sal.protocol.eac.anytype.PasswordID;
......@@ -81,6 +85,16 @@ public final class PINStep extends Step {
transactionInfoField.setText(LANG_EAC.translationForKey(TRANSACTION_INFO, transactionInfo));
getInputInfoUnits().add(transactionInfoField);
}
DynamicContext dynCtx = DynamicContext.getInstance(TR03112Keys.INSTANCE_KEY);
byte[] doc = (byte[]) dynCtx.get("PDF_DOCUMENT");
if (doc != null) {
ToggleText toggleText = new ToggleText();
toggleText.setDocument(new Document("application/pdf", doc));
toggleText.setCollapsed(false);
toggleText.setExternal(true);
toggleText.setTitle("PDF");
getInputInfoUnits().add(toggleText);
}
this.status = status;
// create step elements
......
......@@ -41,6 +41,7 @@ public final class ToggleText extends IDTrait implements InputInfoUnit {
private String title;
private Document document;
private boolean collapsed;
private boolean external;
/**
......@@ -134,6 +135,25 @@ public final class ToggleText extends IDTrait implements InputInfoUnit {
return document;
}
/**
* Gets whether the text should open in external viewer or not.
*
* @return
*/
public boolean isExternal() {
return external;
}
/**
* Sets whether the PDF should open in external viewer or not.
* This only works for 'application/pdf' document
*
* @param external to set if the PDF should open in external viewer
*/
public void setExternal(boolean external) {
this.external = external;
}
@Override
public InfoUnitElementType type() {
......
......@@ -90,13 +90,15 @@ public class ToggleText implements StepComponent {
private Component text;
private File tmpDir;
private final boolean isExternal;
/**
* Creates a new ToggleText.
*
* @param toggleText
*/
public ToggleText(org.openecard.gui.definition.ToggleText toggleText) {
this(toggleText.getTitle(), toggleText.getDocument(), toggleText.isCollapsed());
this(toggleText.getTitle(), toggleText.getDocument(), toggleText.isCollapsed(), toggleText.isExternal());
}
/**
......@@ -106,7 +108,7 @@ public class ToggleText implements StepComponent {
* @param contentText Text of the content
*/
public ToggleText(String buttonText, String contentText) {
this(buttonText, new Document("text/plain", contentText.getBytes(Charset.forName("UTF-8"))), false);
this(buttonText, new Document("text/plain", contentText.getBytes(Charset.forName("UTF-8"))), false, false);
}
/**
......@@ -117,7 +119,7 @@ public class ToggleText implements StepComponent {
* @param collapsed Indicates whether the {@code contentText} is displayed or not.
*/
public ToggleText(String buttonText, String contentText, boolean collapsed) {
this(buttonText, new Document("text/plain", contentText.getBytes(Charset.forName("UTF-8"))), collapsed);
this(buttonText, new Document("text/plain", contentText.getBytes(Charset.forName("UTF-8"))), collapsed, false);
}
/**
......@@ -126,8 +128,10 @@ public class ToggleText implements StepComponent {
* @param buttonText Text of the button
* @param content {@link Document} representing the content of the instance.
* @param collapsed Collapsed (content is visible or not)
* @param isExternal Sets whether the PDF should open in external viewer or not.
*/
public ToggleText(String buttonText, Document content, boolean collapsed) {
public ToggleText(String buttonText, Document content, boolean collapsed, boolean isExternal) {
this.isExternal = isExternal;
initComponents(buttonText, content);
initLayout();
loadUIDefaults();
......@@ -155,18 +159,21 @@ public class ToggleText implements StepComponent {
createJTextArea(new String(content.getValue(), Charset.forName("UTF-8")));
break;
case "application/pdf":
createPdfComponent(content.getValue());
// try {
// createTmpDir();
// String pdfFile = createTmpPdf(content.getValue());
// createStartPdfViewButton(pdfFile);
// } catch (FileNotFoundException | SecurityException ex) {
// LOG.error("Failed to access the tmp pdf file.", ex);
// createJTextArea(LANG.translationForKey("pdf.creation.failed"));
// } catch (IOException ex) {
// LOG.error("Failed to create the tmp pdf file.", ex);
// createJTextArea(LANG.translationForKey("pdf.creation.failed"));
// }
if (isExternal) {
try {
createTmpDir();
String pdfFile = createTmpPdf(content.getValue());
createStartPdfViewButton(pdfFile);
} catch (FileNotFoundException | SecurityException ex) {
LOG.error("Failed to access the tmp pdf file.", ex);
createJTextArea(LANG.translationForKey("pdf.creation.failed"));
} catch (IOException ex) {
LOG.error("Failed to create the tmp pdf file.", ex);
createJTextArea(LANG.translationForKey("pdf.creation.failed"));
}
} else {
createPdfComponent(content.getValue());
}
break;
default:
LOG.warn("Unsupported usage of content of type " + mimeType + " in " + ToggleText.class.getName());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment