summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/PrivacyNoticeWindow.java
blob: eed17d3406e3a64ba41475fb073bcefd760f9bf1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package org.openslx.dozmod.gui.window;

import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import javax.xml.bind.DatatypeConverter;

import org.apache.commons.io.IOUtils;
import org.apache.log4j.Logger;
import org.openslx.dozmod.Config;
import org.openslx.dozmod.gui.helper.UiFeedback;
import org.openslx.dozmod.util.ResourceLoader;

/**
 * Window for showing the privacy notice.
 */
@SuppressWarnings("serial")
public class PrivacyNoticeWindow extends GenericNoticeWindow implements UiFeedback {

	private final static Logger LOGGER = Logger.getLogger(PrivacyNoticeWindow.class);

	final PrivacyNoticeWindow me = this;

	private static String PRIVACY_NOTICE_MD5 = null;
	private static String PRIVACY_NOTICE_CONTENT = null;

	static {
		try (InputStream noticeStream = ResourceLoader.getStream("/txt/privacy_notice")) {
			MessageDigest md = MessageDigest.getInstance("MD5");
			byte[] content = IOUtils.toByteArray(noticeStream);
			md.update(content);
			byte[] md5 = md.digest();
			PRIVACY_NOTICE_CONTENT = new String(content, StandardCharsets.UTF_8);
			PRIVACY_NOTICE_MD5 = DatatypeConverter.printHexBinary(md5);
		} catch (IOException | NoSuchAlgorithmException e) {
			LOGGER.error("Failed to get hash of privacy_notice: ", e);
		}
	}

	public PrivacyNoticeWindow(Frame modalParent) {
		super(modalParent, shouldBeShown());

		// Set the actual text
		setNoticeText(PRIVACY_NOTICE_CONTENT);

		// function for continue button
		btnContinue.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				// save the agreement to config
				Config.setPrivacyAgreement(PRIVACY_NOTICE_MD5);
				me.dispose();
			}
		});
	}

	public static boolean shouldBeShown() {
		return !Config.getPrivacyAgreement().equals(PRIVACY_NOTICE_MD5);
	}

	public static void open(Frame modalParent) {
		new PrivacyNoticeWindow(modalParent).setVisible(true);
	}

}