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 @@ ...@@ -20,6 +20,12 @@
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.openecard.addons</groupId>
<artifactId>tr03112</artifactId>
<version>${project.version}</version>
</dependency>
<dependency> <dependency>
<groupId>org.bitbucket.b_c</groupId> <groupId>org.bitbucket.b_c</groupId>
<artifactId>jose4j</artifactId> <artifactId>jose4j</artifactId>
......
...@@ -20,6 +20,8 @@ import org.openecard.addon.bind.HeaderEntry; ...@@ -20,6 +20,8 @@ import org.openecard.addon.bind.HeaderEntry;
import org.openecard.addon.bind.Headers; import org.openecard.addon.bind.Headers;
import org.openecard.addon.bind.RequestBody; import org.openecard.addon.bind.RequestBody;
import org.openecard.addons.reqesidta.ReqesidtaProperties; import org.openecard.addons.reqesidta.ReqesidtaProperties;
import org.openecard.binding.tctoken.TR03112Keys;
import org.openecard.common.DynamicContext;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -59,6 +61,8 @@ public class SignRequest { ...@@ -59,6 +61,8 @@ public class SignRequest {
throw new InvalidHashException("Hash algorithm %s is not allowed by the system."); 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); return new SignRequest(hashAlg, sigAlg, ssaUri, doc);
} }
......
...@@ -22,12 +22,16 @@ ...@@ -22,12 +22,16 @@
package org.openecard.sal.protocol.eac.gui; 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.common.I18n;
import org.openecard.gui.definition.Document;
import org.openecard.gui.definition.InputInfoUnit; import org.openecard.gui.definition.InputInfoUnit;
import org.openecard.sal.protocol.eac.anytype.PACEMarkerType; import org.openecard.sal.protocol.eac.anytype.PACEMarkerType;
import org.openecard.gui.definition.PasswordField; import org.openecard.gui.definition.PasswordField;
import org.openecard.gui.definition.Step; import org.openecard.gui.definition.Step;
import org.openecard.gui.definition.Text; 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.EACData;
import org.openecard.sal.protocol.eac.anytype.PasswordID; import org.openecard.sal.protocol.eac.anytype.PasswordID;
...@@ -81,6 +85,16 @@ public final class PINStep extends Step { ...@@ -81,6 +85,16 @@ public final class PINStep extends Step {
transactionInfoField.setText(LANG_EAC.translationForKey(TRANSACTION_INFO, transactionInfo)); transactionInfoField.setText(LANG_EAC.translationForKey(TRANSACTION_INFO, transactionInfo));
getInputInfoUnits().add(transactionInfoField); 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; this.status = status;
// create step elements // create step elements
......
...@@ -41,6 +41,7 @@ public final class ToggleText extends IDTrait implements InputInfoUnit { ...@@ -41,6 +41,7 @@ public final class ToggleText extends IDTrait implements InputInfoUnit {
private String title; private String title;
private Document document; private Document document;
private boolean collapsed; private boolean collapsed;
private boolean external;
/** /**
...@@ -134,6 +135,25 @@ public final class ToggleText extends IDTrait implements InputInfoUnit { ...@@ -134,6 +135,25 @@ public final class ToggleText extends IDTrait implements InputInfoUnit {
return document; 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 @Override
public InfoUnitElementType type() { public InfoUnitElementType type() {
......
...@@ -90,13 +90,15 @@ public class ToggleText implements StepComponent { ...@@ -90,13 +90,15 @@ public class ToggleText implements StepComponent {
private Component text; private Component text;
private File tmpDir; private File tmpDir;
private final boolean isExternal;
/** /**
* Creates a new ToggleText. * Creates a new ToggleText.
* *
* @param toggleText * @param toggleText
*/ */
public ToggleText(org.openecard.gui.definition.ToggleText 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 { ...@@ -106,7 +108,7 @@ public class ToggleText implements StepComponent {
* @param contentText Text of the content * @param contentText Text of the content
*/ */
public ToggleText(String buttonText, String contentText) { 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 { ...@@ -117,7 +119,7 @@ public class ToggleText implements StepComponent {
* @param collapsed Indicates whether the {@code contentText} is displayed or not. * @param collapsed Indicates whether the {@code contentText} is displayed or not.
*/ */
public ToggleText(String buttonText, String contentText, boolean collapsed) { 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 { ...@@ -126,8 +128,10 @@ public class ToggleText implements StepComponent {
* @param buttonText Text of the button * @param buttonText Text of the button
* @param content {@link Document} representing the content of the instance. * @param content {@link Document} representing the content of the instance.
* @param collapsed Collapsed (content is visible or not) * @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); initComponents(buttonText, content);
initLayout(); initLayout();
loadUIDefaults(); loadUIDefaults();
...@@ -155,18 +159,21 @@ public class ToggleText implements StepComponent { ...@@ -155,18 +159,21 @@ public class ToggleText implements StepComponent {
createJTextArea(new String(content.getValue(), Charset.forName("UTF-8"))); createJTextArea(new String(content.getValue(), Charset.forName("UTF-8")));
break; break;
case "application/pdf": case "application/pdf":
createPdfComponent(content.getValue()); if (isExternal) {
// try { try {
// createTmpDir(); createTmpDir();
// String pdfFile = createTmpPdf(content.getValue()); String pdfFile = createTmpPdf(content.getValue());
// createStartPdfViewButton(pdfFile); createStartPdfViewButton(pdfFile);
// } catch (FileNotFoundException | SecurityException ex) { } catch (FileNotFoundException | SecurityException ex) {
// LOG.error("Failed to access the tmp pdf file.", ex); LOG.error("Failed to access the tmp pdf file.", ex);
// createJTextArea(LANG.translationForKey("pdf.creation.failed")); createJTextArea(LANG.translationForKey("pdf.creation.failed"));
// } catch (IOException ex) { } catch (IOException ex) {
// LOG.error("Failed to create the tmp pdf file.", ex); LOG.error("Failed to create the tmp pdf file.", ex);
// createJTextArea(LANG.translationForKey("pdf.creation.failed")); createJTextArea(LANG.translationForKey("pdf.creation.failed"));
// } }
} else {
createPdfComponent(content.getValue());
}
break; break;
default: default:
LOG.warn("Unsupported usage of content of type " + mimeType + " in " + ToggleText.class.getName()); LOG.warn("Unsupported usage of content of type " + mimeType + " in " + ToggleText.class.getName());
......
Supports Markdown
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