| 1 | package com.jsql.view.swing.panel.consoles; | |
| 2 | ||
| 3 | import com.jsql.model.bean.util.HttpHeader; | |
| 4 | import com.jsql.model.injection.vendor.model.VendorYaml; | |
| 5 | import com.jsql.util.I18nUtil; | |
| 6 | import com.jsql.util.LogLevelUtil; | |
| 7 | import com.jsql.util.StringUtil; | |
| 8 | import com.jsql.view.swing.panel.util.HTMLEditorKitTextPaneWrap; | |
| 9 | import com.jsql.view.swing.tab.TabbedPaneWheeled; | |
| 10 | import com.jsql.view.swing.text.JPopupTextComponent; | |
| 11 | import com.jsql.view.swing.text.JTextPanePlaceholder; | |
| 12 | import com.jsql.view.swing.text.SyntaxTextArea; | |
| 13 | import com.jsql.view.swing.util.I18nViewUtil; | |
| 14 | import com.jsql.view.swing.util.MediatorHelper; | |
| 15 | import com.jsql.view.swing.util.UiUtil; | |
| 16 | import org.apache.commons.lang3.StringUtils; | |
| 17 | import org.apache.logging.log4j.LogManager; | |
| 18 | import org.apache.logging.log4j.Logger; | |
| 19 | import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea; | |
| 20 | import org.fife.ui.rsyntaxtextarea.SyntaxConstants; | |
| 21 | import org.fife.ui.rtextarea.RTextScrollPane; | |
| 22 | import org.jsoup.Jsoup; | |
| 23 | import org.jsoup.safety.Safelist; | |
| 24 | ||
| 25 | import javax.swing.*; | |
| 26 | import javax.swing.text.DefaultCaret; | |
| 27 | import java.awt.*; | |
| 28 | import java.awt.event.FocusAdapter; | |
| 29 | import java.awt.event.FocusEvent; | |
| 30 | import java.util.AbstractMap.SimpleEntry; | |
| 31 | import java.util.Arrays; | |
| 32 | import java.util.Map; | |
| 33 | import java.util.stream.Stream; | |
| 34 | ||
| 35 | public class TabbedPaneNetworkTab extends TabbedPaneWheeled { | |
| 36 | | |
| 37 | private static final Logger LOGGER = LogManager.getRootLogger(); | |
| 38 | ||
| 39 | private final RSyntaxTextArea textAreaUrl = new SyntaxTextArea(I18nUtil.valueByKey("NETWORK_LINE_PLACEHOLDER_URL")); | |
| 40 | private final RSyntaxTextArea textAreaResponse = new SyntaxTextArea(I18nUtil.valueByKey("NETWORK_LINE_PLACEHOLDER_RESPONSE")); | |
| 41 | private final RSyntaxTextArea textAreaSource = new SyntaxTextArea(I18nUtil.valueByKey("NETWORK_LINE_PLACEHOLDER_SOURCE")); | |
| 42 | private final JTextPane textPanePreview = new JPopupTextComponent<>(new JTextPanePlaceholder(I18nUtil.valueByKey("NETWORK_LINE_PLACEHOLDER_PREVIEW")){ | |
| 43 | @Override | |
| 44 | public boolean isEditable() { | |
| 45 |
1
1. isEditable : replaced boolean return with true for com/jsql/view/swing/panel/consoles/TabbedPaneNetworkTab$1::isEditable → NO_COVERAGE |
return false; |
| 46 | } | |
| 47 | }).getProxy(); | |
| 48 | private final RSyntaxTextArea textAreaHeader = new SyntaxTextArea(I18nUtil.valueByKey("NETWORK_LINE_PLACEHOLDER_HEADERS")); | |
| 49 | private final RSyntaxTextArea textAreaRequest = new SyntaxTextArea(I18nUtil.valueByKey("NETWORK_LINE_PLACEHOLDER_REQUEST")); | |
| 50 | private final JCheckBox checkBoxDecode = new JCheckBox("Decode", MediatorHelper.model().getMediatorUtils().getPreferencesUtil().isUrlDecodeNetworkTab()); | |
| 51 | ||
| 52 | public TabbedPaneNetworkTab() { | |
| 53 |
1
1. <init> : removed call to com/jsql/view/swing/panel/consoles/TabbedPaneNetworkTab::setName → NO_COVERAGE |
this.setName("tabNetwork"); |
| 54 | var panelDecode = new JPanel(new BorderLayout()); | |
| 55 |
1
1. <init> : removed call to javax/swing/JPanel::add → NO_COVERAGE |
panelDecode.add(this.checkBoxDecode, BorderLayout.LINE_END); // reduce to minimum size as checkbox expands by the label |
| 56 |
1
1. <init> : removed call to com/jsql/view/swing/panel/consoles/TabbedPaneNetworkTab::putClientProperty → NO_COVERAGE |
this.putClientProperty("JTabbedPane.trailingComponent", panelDecode); |
| 57 | ||
| 58 |
1
1. <init> : removed call to com/jsql/view/swing/util/I18nViewUtil::addComponentForKey → NO_COVERAGE |
I18nViewUtil.addComponentForKey("NETWORK_LINE_PLACEHOLDER_URL", this.textAreaUrl); |
| 59 |
1
1. <init> : removed call to com/jsql/view/swing/util/I18nViewUtil::addComponentForKey → NO_COVERAGE |
I18nViewUtil.addComponentForKey("NETWORK_LINE_PLACEHOLDER_RESPONSE", this.textAreaResponse); |
| 60 |
1
1. <init> : removed call to com/jsql/view/swing/util/I18nViewUtil::addComponentForKey → NO_COVERAGE |
I18nViewUtil.addComponentForKey("NETWORK_LINE_PLACEHOLDER_SOURCE", this.textAreaSource); |
| 61 |
1
1. <init> : removed call to com/jsql/view/swing/util/I18nViewUtil::addComponentForKey → NO_COVERAGE |
I18nViewUtil.addComponentForKey("NETWORK_LINE_PLACEHOLDER_PREVIEW", this.textPanePreview); |
| 62 |
1
1. <init> : removed call to com/jsql/view/swing/util/I18nViewUtil::addComponentForKey → NO_COVERAGE |
I18nViewUtil.addComponentForKey("NETWORK_LINE_PLACEHOLDER_HEADERS", this.textAreaHeader); |
| 63 |
1
1. <init> : removed call to com/jsql/view/swing/util/I18nViewUtil::addComponentForKey → NO_COVERAGE |
I18nViewUtil.addComponentForKey("NETWORK_LINE_PLACEHOLDER_REQUEST", this.textAreaRequest); |
| 64 | Stream.of( | |
| 65 | new SimpleEntry<>("NETWORK_TAB_URL_LABEL", this.textAreaUrl), | |
| 66 | new SimpleEntry<>("NETWORK_TAB_HEADERS_LABEL", this.textAreaHeader), | |
| 67 | new SimpleEntry<>("NETWORK_TAB_PARAMS_LABEL", this.textAreaRequest), | |
| 68 | new SimpleEntry<>("NETWORK_TAB_RESPONSE_LABEL", this.textAreaResponse), | |
| 69 | new SimpleEntry<>("NETWORK_TAB_SOURCE_LABEL", this.textAreaSource), | |
| 70 | new SimpleEntry<>("NETWORK_TAB_PREVIEW_LABEL", this.textPanePreview) | |
| 71 | ) | |
| 72 |
1
1. <init> : removed call to java/util/stream/Stream::forEach → NO_COVERAGE |
.forEach(entry -> { |
| 73 |
1
1. lambda$new$0 : removed call to com/jsql/view/swing/panel/consoles/TabbedPaneNetworkTab::addTab → NO_COVERAGE |
this.addTab( |
| 74 | I18nUtil.valueByKey(entry.getKey()), | |
| 75 |
1
1. lambda$new$0 : negated conditional → NO_COVERAGE |
entry.getValue() == this.textAreaSource |
| 76 | ? new RTextScrollPane(entry.getValue(), false) | |
| 77 | : new JScrollPane(entry.getValue()) | |
| 78 | ); | |
| 79 | var label = new JLabel(I18nUtil.valueByKey(entry.getKey())); | |
| 80 |
1
1. lambda$new$0 : removed call to javax/swing/JLabel::setName → NO_COVERAGE |
label.setName("label"+ entry.getKey()); |
| 81 |
1
1. lambda$new$0 : removed call to com/jsql/view/swing/panel/consoles/TabbedPaneNetworkTab::setTabComponentAt → NO_COVERAGE |
this.setTabComponentAt( |
| 82 | this.indexOfTab(I18nUtil.valueByKey(entry.getKey())), | |
| 83 | label | |
| 84 | ); | |
| 85 |
1
1. lambda$new$0 : removed call to com/jsql/view/swing/util/I18nViewUtil::addComponentForKey → NO_COVERAGE |
I18nViewUtil.addComponentForKey(entry.getKey(), label); |
| 86 | ||
| 87 |
1
1. lambda$new$0 : removed call to javax/swing/text/JTextComponent::setName → NO_COVERAGE |
entry.getValue().setName("text"+ entry.getKey()); |
| 88 | ||
| 89 | DefaultCaret caret = (DefaultCaret) entry.getValue().getCaret(); | |
| 90 |
1
1. lambda$new$0 : removed call to javax/swing/text/DefaultCaret::setUpdatePolicy → NO_COVERAGE |
caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE); |
| 91 | }); | |
| 92 | ||
| 93 |
1
1. <init> : removed call to java/util/List::forEach → NO_COVERAGE |
Arrays.asList(this.textAreaUrl, this.textAreaHeader, this.textAreaRequest, this.textAreaResponse, this.textAreaSource).forEach(entry -> { |
| 94 |
1
1. lambda$new$1 : removed call to org/fife/ui/rsyntaxtextarea/RSyntaxTextArea::setEditable → NO_COVERAGE |
entry.setEditable(false); |
| 95 |
1
1. lambda$new$1 : removed call to org/fife/ui/rsyntaxtextarea/RSyntaxTextArea::setLineWrap → NO_COVERAGE |
entry.setLineWrap(true); |
| 96 | }); | |
| 97 |
1
1. <init> : removed call to org/fife/ui/rsyntaxtextarea/RSyntaxTextArea::setSyntaxEditingStyle → NO_COVERAGE |
this.textAreaResponse.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_HTML); |
| 98 |
1
1. <init> : removed call to org/fife/ui/rsyntaxtextarea/RSyntaxTextArea::setSyntaxEditingStyle → NO_COVERAGE |
this.textAreaSource.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_HTML); |
| 99 |
1
1. <init> : removed call to org/fife/ui/rsyntaxtextarea/RSyntaxTextArea::setHighlightSecondaryLanguages → NO_COVERAGE |
this.textAreaSource.setHighlightSecondaryLanguages(true); |
| 100 |
1
1. <init> : removed call to com/jsql/view/swing/panel/consoles/TabbedPaneNetworkTab::applyTheme → NO_COVERAGE |
this.applyTheme(); |
| 101 | | |
| 102 |
1
1. <init> : removed call to javax/swing/JTextPane::setEditorKit → NO_COVERAGE |
this.textPanePreview.setEditorKit(new HTMLEditorKitTextPaneWrap()); |
| 103 |
1
1. <init> : removed call to javax/swing/JTextPane::setContentType → NO_COVERAGE |
this.textPanePreview.setContentType("text/html"); |
| 104 |
1
1. <init> : removed call to javax/swing/JTextPane::setEditable → NO_COVERAGE |
this.textPanePreview.setEditable(false); |
| 105 |
1
1. <init> : removed call to javax/swing/text/Caret::setBlinkRate → NO_COVERAGE |
this.textPanePreview.getCaret().setBlinkRate(0); |
| 106 |
1
1. <init> : removed call to javax/swing/JTextPane::addFocusListener → NO_COVERAGE |
this.textPanePreview.addFocusListener(new FocusAdapter() { |
| 107 | @Override | |
| 108 | public void focusGained(FocusEvent focusEvent) { | |
| 109 |
1
1. focusGained : removed call to javax/swing/text/Caret::setVisible → NO_COVERAGE |
TabbedPaneNetworkTab.this.textPanePreview.getCaret().setVisible(true); |
| 110 |
1
1. focusGained : removed call to javax/swing/text/Caret::setSelectionVisible → NO_COVERAGE |
TabbedPaneNetworkTab.this.textPanePreview.getCaret().setSelectionVisible(true); |
| 111 | } | |
| 112 | }); | |
| 113 | } | |
| 114 | | |
| 115 | public void changeTextNetwork(HttpHeader networkData) { | |
| 116 |
1
1. changeTextNetwork : removed call to org/fife/ui/rsyntaxtextarea/RSyntaxTextArea::setText → NO_COVERAGE |
this.textAreaRequest.setText(this.getDecodedValue(this.checkBoxDecode.isSelected(), networkData.getPost())); |
| 117 |
1
1. changeTextNetwork : removed call to org/fife/ui/rsyntaxtextarea/RSyntaxTextArea::setText → NO_COVERAGE |
this.textAreaUrl.setText(this.getDecodedValue(this.checkBoxDecode.isSelected(), networkData.getUrl())); |
| 118 |
1
1. changeTextNetwork : removed call to com/jsql/view/swing/panel/consoles/TabbedPaneNetworkTab::updateTextArea → NO_COVERAGE |
this.updateTextArea(this.textAreaHeader, networkData.getHeader()); |
| 119 |
1
1. changeTextNetwork : removed call to com/jsql/view/swing/panel/consoles/TabbedPaneNetworkTab::updateTextArea → NO_COVERAGE |
this.updateTextArea(this.textAreaResponse, networkData.getResponse()); |
| 120 | ||
| 121 | // Fix #53736: ArrayIndexOutOfBoundsException on setText() | |
| 122 | // Fix #54573: NullPointerException on setText() | |
| 123 | try { | |
| 124 |
1
1. changeTextNetwork : removed call to org/fife/ui/rsyntaxtextarea/RSyntaxTextArea::setText → NO_COVERAGE |
this.textAreaSource.setText( |
| 125 | StringUtil.detectUtf8(networkData.getSource()) | |
| 126 | .replaceAll(VendorYaml.CALIBRATOR_SQL +"{5,}", VendorYaml.CALIBRATOR_SQL +"*") | |
| 127 | .trim() | |
| 128 | ); | |
| 129 | } catch (ArrayIndexOutOfBoundsException | NullPointerException e) { | |
| 130 | LOGGER.log(LogLevelUtil.CONSOLE_JAVA, e, e); | |
| 131 | } | |
| 132 | | |
| 133 | this.textPanePreview.getEditorKit().createDefaultDocument(); // Reset EditorKit to disable previous document effect | |
| 134 | // Proxy is used by jsoup to display <img> tags | |
| 135 | // Previous test for 2xx Success and 3xx Redirection was Header only, now get the HTML content | |
| 136 | // Fix #35352: EmptyStackException on setText() | |
| 137 | // Fix #39841: RuntimeException on setText() | |
| 138 | // Fix #42523: ExceptionInInitializerError on clean() | |
| 139 | try { | |
| 140 |
1
1. changeTextNetwork : removed call to javax/swing/JTextPane::setText → NO_COVERAGE |
this.textPanePreview.setText( |
| 141 | Jsoup.clean( | |
| 142 | String.format( | |
| 143 | "<html>%s</html>", | |
| 144 | StringUtil.detectUtf8(networkData.getSource()) | |
| 145 | ) | |
| 146 | .replaceAll("<img[^>]*>",StringUtils.EMPTY) // avoid loading external resources | |
| 147 | .replaceAll("<input[^>]*type=\"?hidden\"?.*>", StringUtils.EMPTY) | |
| 148 | .replaceAll( | |
| 149 | "<input[^>]*type=\"?(submit|button)\"?.*>", | |
| 150 | "<div style=\"background-color:#eeeeee;text-align:center;border:1px solid black;width:100px;\">button</div>" | |
| 151 | ) | |
| 152 | .replaceAll( | |
| 153 | "<input[^>]*>", | |
| 154 | "<div style=\"text-align:center;border:1px solid black;width:100px;\">input</div>" | |
| 155 | ), | |
| 156 | Safelist.relaxed().addTags("center", "div", "span").addAttributes(":all", "style") | |
| 157 | ) | |
| 158 | ); | |
| 159 | } catch (Exception | ExceptionInInitializerError e) { | |
| 160 | LOGGER.log(LogLevelUtil.CONSOLE_JAVA, e, e); | |
| 161 | } | |
| 162 | } | |
| 163 | ||
| 164 | private void updateTextArea(JTextArea textArea, Map<String, String> httpData) { | |
| 165 |
1
1. updateTextArea : removed call to javax/swing/JTextArea::setText → NO_COVERAGE |
textArea.setText(StringUtils.EMPTY); |
| 166 |
1
1. updateTextArea : negated conditional → NO_COVERAGE |
if (httpData != null) { |
| 167 |
1
1. updateTextArea : removed call to java/util/Map::forEach → NO_COVERAGE |
httpData.forEach((key, value) -> { |
| 168 | String decodedValue = this.getDecodedValue(this.checkBoxDecode.isSelected(), value); | |
| 169 |
1
1. lambda$updateTextArea$2 : removed call to javax/swing/JTextArea::append → NO_COVERAGE |
textArea.append(key + ": " + decodedValue + "\n"); |
| 170 | }); | |
| 171 | } | |
| 172 | } | |
| 173 | ||
| 174 | private String getDecodedValue(boolean isSelected, String value) { | |
| 175 | // Fix #96095: IllegalArgumentException on URLDecoder.decode() | |
| 176 | try { | |
| 177 |
2
1. getDecodedValue : replaced return value with "" for com/jsql/view/swing/panel/consoles/TabbedPaneNetworkTab::getDecodedValue → NO_COVERAGE 2. getDecodedValue : negated conditional → NO_COVERAGE |
return isSelected ? StringUtil.fromUrl(value) : value; |
| 178 | } catch (IllegalArgumentException e) { | |
| 179 | LOGGER.log(LogLevelUtil.CONSOLE_JAVA, "Decoding failure: {}", e.getMessage()); | |
| 180 |
1
1. getDecodedValue : replaced return value with "" for com/jsql/view/swing/panel/consoles/TabbedPaneNetworkTab::getDecodedValue → NO_COVERAGE |
return value; |
| 181 | } | |
| 182 | } | |
| 183 | ||
| 184 | public void reset() { | |
| 185 |
1
1. reset : removed call to org/fife/ui/rsyntaxtextarea/RSyntaxTextArea::setText → NO_COVERAGE |
this.textAreaUrl.setText(StringUtils.EMPTY); |
| 186 |
1
1. reset : removed call to org/fife/ui/rsyntaxtextarea/RSyntaxTextArea::setText → NO_COVERAGE |
this.textAreaHeader.setText(StringUtils.EMPTY); |
| 187 |
1
1. reset : removed call to org/fife/ui/rsyntaxtextarea/RSyntaxTextArea::setText → NO_COVERAGE |
this.textAreaRequest.setText(StringUtils.EMPTY); |
| 188 |
1
1. reset : removed call to org/fife/ui/rsyntaxtextarea/RSyntaxTextArea::setText → NO_COVERAGE |
this.textAreaResponse.setText(StringUtils.EMPTY); |
| 189 | | |
| 190 | // Fix #54572: NullPointerException on setText() | |
| 191 | try { | |
| 192 |
1
1. reset : removed call to org/fife/ui/rsyntaxtextarea/RSyntaxTextArea::setText → NO_COVERAGE |
this.textAreaSource.setText(StringUtils.EMPTY); |
| 193 | } catch (NullPointerException e) { | |
| 194 | LOGGER.log(LogLevelUtil.CONSOLE_JAVA, e, e); | |
| 195 | } | |
| 196 | | |
| 197 | // Fix #41879: ArrayIndexOutOfBoundsException on setText() | |
| 198 | try { | |
| 199 |
1
1. reset : removed call to javax/swing/JTextPane::setText → NO_COVERAGE |
this.textPanePreview.setText(StringUtils.EMPTY); |
| 200 | } catch (ArrayIndexOutOfBoundsException e) { | |
| 201 | LOGGER.log(LogLevelUtil.CONSOLE_JAVA, e, e); | |
| 202 | } | |
| 203 | } | |
| 204 | ||
| 205 | public void applyTheme() { | |
| 206 | Arrays.asList( | |
| 207 | this.textAreaUrl, this.textAreaHeader, this.textAreaRequest, this.textAreaResponse, this.textAreaSource | |
| 208 |
1
1. applyTheme : removed call to java/util/List::forEach → NO_COVERAGE |
).forEach(UiUtil::applySyntaxTheme); |
| 209 | } | |
| 210 | ||
| 211 | public JCheckBox getCheckBoxDecode() { | |
| 212 |
1
1. getCheckBoxDecode : replaced return value with null for com/jsql/view/swing/panel/consoles/TabbedPaneNetworkTab::getCheckBoxDecode → NO_COVERAGE |
return this.checkBoxDecode; |
| 213 | } | |
| 214 | } | |
Mutations | ||
| 45 |
1.1 |
|
| 53 |
1.1 |
|
| 55 |
1.1 |
|
| 56 |
1.1 |
|
| 58 |
1.1 |
|
| 59 |
1.1 |
|
| 60 |
1.1 |
|
| 61 |
1.1 |
|
| 62 |
1.1 |
|
| 63 |
1.1 |
|
| 72 |
1.1 |
|
| 73 |
1.1 |
|
| 75 |
1.1 |
|
| 80 |
1.1 |
|
| 81 |
1.1 |
|
| 85 |
1.1 |
|
| 87 |
1.1 |
|
| 90 |
1.1 |
|
| 93 |
1.1 |
|
| 94 |
1.1 |
|
| 95 |
1.1 |
|
| 97 |
1.1 |
|
| 98 |
1.1 |
|
| 99 |
1.1 |
|
| 100 |
1.1 |
|
| 102 |
1.1 |
|
| 103 |
1.1 |
|
| 104 |
1.1 |
|
| 105 |
1.1 |
|
| 106 |
1.1 |
|
| 109 |
1.1 |
|
| 110 |
1.1 |
|
| 116 |
1.1 |
|
| 117 |
1.1 |
|
| 118 |
1.1 |
|
| 119 |
1.1 |
|
| 124 |
1.1 |
|
| 140 |
1.1 |
|
| 165 |
1.1 |
|
| 166 |
1.1 |
|
| 167 |
1.1 |
|
| 169 |
1.1 |
|
| 177 |
1.1 2.2 |
|
| 180 |
1.1 |
|
| 185 |
1.1 |
|
| 186 |
1.1 |
|
| 187 |
1.1 |
|
| 188 |
1.1 |
|
| 192 |
1.1 |
|
| 199 |
1.1 |
|
| 208 |
1.1 |
|
| 212 |
1.1 |