1 | /******************************************************************************* | |
2 | * Copyhacked (H) 2012-2020. | |
3 | * This program and the accompanying materials | |
4 | * are made available under no term at all, use it like | |
5 | * you want, but share and discuss about it | |
6 | * every time possible with every body. | |
7 | * | |
8 | * Contributors: | |
9 | * ron190 at ymail dot com - initial implementation | |
10 | *******************************************************************************/ | |
11 | package com.jsql.view.swing.manager.util; | |
12 | ||
13 | import com.jsql.util.LogLevelUtil; | |
14 | import com.jsql.util.StringUtil; | |
15 | import com.jsql.util.bruter.ActionCoder; | |
16 | import com.jsql.view.swing.manager.ManagerCoder; | |
17 | import com.jsql.view.swing.util.UiUtil; | |
18 | import org.apache.commons.codec.DecoderException; | |
19 | import org.apache.commons.lang3.StringUtils; | |
20 | import org.apache.logging.log4j.LogManager; | |
21 | import org.apache.logging.log4j.Logger; | |
22 | ||
23 | import java.awt.event.ActionEvent; | |
24 | import java.awt.event.ActionListener; | |
25 | import java.io.IOException; | |
26 | import java.security.NoSuchAlgorithmException; | |
27 | import java.util.Arrays; | |
28 | import java.util.NoSuchElementException; | |
29 | ||
30 | /** | |
31 | * Action run when this.coderManager.encoding. | |
32 | */ | |
33 | public class CoderListener implements ActionListener { | |
34 | | |
35 | /** | |
36 | * Log4j logger sent to view. | |
37 | */ | |
38 | private static final Logger LOGGER = LogManager.getRootLogger(); | |
39 | | |
40 | private final ManagerCoder coderManager; | |
41 | | |
42 | public CoderListener(ManagerCoder coderManager) { | |
43 | this.coderManager = coderManager; | |
44 | } | |
45 | | |
46 | public void actionPerformed() { | |
47 |
1
1. actionPerformed : removed call to com/jsql/view/swing/manager/util/CoderListener::transform → NO_COVERAGE |
this.transform(this.coderManager.getMenuMethod().getText()); |
48 | } | |
49 | | |
50 | public void actionPerformed(String nameMethod) { | |
51 |
1
1. actionPerformed : removed call to com/jsql/view/swing/manager/util/CoderListener::transform → NO_COVERAGE |
this.transform(nameMethod); |
52 | } | |
53 | | |
54 | @Override | |
55 | public void actionPerformed(ActionEvent arg0) { | |
56 |
1
1. actionPerformed : removed call to com/jsql/view/swing/manager/util/CoderListener::transform → NO_COVERAGE |
this.transform(this.coderManager.getMenuMethod().getText()); |
57 | } | |
58 | | |
59 | private void transform(String labelMethodMenu) { | |
60 | ||
61 | String nameMethod = labelMethodMenu.replace("Hash to ", StringUtils.EMPTY); | |
62 | | |
63 | String result; | |
64 | String textInput = this.coderManager.getTextInput().getText(); | |
65 | | |
66 | try { | |
67 | if ( | |
68 |
1
1. transform : negated conditional → NO_COVERAGE |
StringUtils.isEmpty(textInput) |
69 |
1
1. transform : negated conditional → NO_COVERAGE |
&& !Arrays.asList("Md2", "Md4", "Md5", "Sha-1", "Sha-256", "Sha-384", "Sha-512", "Mysql").contains(nameMethod) |
70 | ) { | |
71 | result = "<span style=\"color:red;\">Empty string to convert</span>"; | |
72 | } else { | |
73 | | |
74 | result = ActionCoder.forName(nameMethod) | |
75 |
1
1. lambda$transform$0 : replaced return value with null for com/jsql/view/swing/manager/util/CoderListener::lambda$transform$0 → NO_COVERAGE |
.orElseThrow(() -> new NoSuchElementException("Unsupported encoding or decoding method")) |
76 | .run(textInput); | |
77 | | |
78 | // Prevent decoded HTML tags from result not rendered in Coder textPane | |
79 | result = StringUtil.fromHtml(result); | |
80 | } | |
81 | } catch ( | |
82 | IllegalArgumentException | |
83 | | NoSuchAlgorithmException | |
84 | | IOException | |
85 | | DecoderException e | |
86 | ) { | |
87 | | |
88 | result = String.format("<span style=\"color:red;\">Decoding failed: %s</span>", e.getMessage()); | |
89 | LOGGER.log(LogLevelUtil.IGNORE, e); | |
90 | } | |
91 | | |
92 |
1
1. transform : removed call to javax/swing/JTextPane::setText → NO_COVERAGE |
this.coderManager.getResult().setText( |
93 | String.format( | |
94 | "<html><span style=\"font-family:'%s'\">%s</span></html>", | |
95 | UiUtil.FONT_NAME_MONO_NON_ASIAN, | |
96 | result | |
97 | ) | |
98 | ); | |
99 | } | |
100 | } | |
Mutations | ||
47 |
1.1 |
|
51 |
1.1 |
|
56 |
1.1 |
|
68 |
1.1 |
|
69 |
1.1 |
|
75 |
1.1 |
|
92 |
1.1 |