AbstractManagerList.java

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;
12
13
import com.jsql.util.LogLevelUtil;
14
import com.jsql.view.swing.list.DnDList;
15
import com.jsql.view.swing.list.ItemList;
16
import com.jsql.view.swing.manager.util.JButtonStateful;
17
import com.jsql.view.swing.manager.util.StateButton;
18
import com.jsql.view.swing.scrollpane.LightScrollPane;
19
import com.jsql.view.swing.util.I18nViewUtil;
20
import com.jsql.view.swing.util.UiUtil;
21
import org.apache.commons.lang3.StringUtils;
22
import org.apache.logging.log4j.LogManager;
23
import org.apache.logging.log4j.Logger;
24
25
import javax.swing.*;
26
import java.awt.*;
27
import java.io.BufferedReader;
28
import java.io.IOException;
29
import java.io.InputStreamReader;
30
import java.nio.charset.StandardCharsets;
31
import java.util.ArrayList;
32
import java.util.List;
33
import java.util.Objects;
34
35
/**
36
 * Abstract manager containing a drag and drop list of item.
37
 */
38
public abstract class AbstractManagerList extends JPanel implements Manager {
39
    
40
    /**
41
     * Log4j logger sent to view.
42
     */
43
    private static final Logger LOGGER = LogManager.getRootLogger();
44
    
45
    protected final transient List<ItemList> itemsList = new ArrayList<>();
46
    
47
    protected DnDList listFile;
48
    
49
    protected final JPanel lastLine = new JPanel();
50
    
51
    /**
52
     * Contains the paths of webshell.
53
     */
54
    protected DnDList listPaths;
55
56
    /**
57
     * Starts the upload process.
58
     */
59
    protected JButtonStateful run;
60
61
    /**
62
     * Display the FILE privilege of current user.
63
     */
64
    protected JLabel privilege;
65
66
    /**
67
     * Text of the button that start the upload process.
68
     * Used to get back the default text after a search (defaultText->"Stop"->defaultText).
69
     */
70
    protected String defaultText;
71
72
    /**
73
     * A animated GIF displayed during processing.
74
     */
75
    protected final JLabel loader = new JLabel(UiUtil.ICON_LOADER_GIF);
76
    
77
    protected AbstractManagerList() {
78
        // Nothing
79
    }
80
    
81
    protected AbstractManagerList(String nameFile) {
82
        
83 1 1. <init> : removed call to com/jsql/view/swing/manager/AbstractManagerList::setLayout → NO_COVERAGE
        this.setLayout(new BorderLayout());
84
85
        try (
86
            var inputStream = UiUtil.class.getClassLoader().getResourceAsStream(nameFile);
87
            var inputStreamReader = new InputStreamReader(Objects.requireNonNull(inputStream), StandardCharsets.UTF_8);
88
            var reader = new BufferedReader(inputStreamReader)
89
        ) {
90
            String line;
91 1 1. <init> : negated conditional → NO_COVERAGE
            while ((line = reader.readLine()) != null) {
92
                this.itemsList.add(new ItemList(line));
93
            }
94
        } catch (IOException e) {
95
            LOGGER.log(LogLevelUtil.CONSOLE_JAVA, e, e);
96
        }
97
98
        this.listFile = new DnDList(this.itemsList);
99
100 1 1. <init> : removed call to com/jsql/view/swing/list/DnDList::setBorder → NO_COVERAGE
        this.listFile.setBorder(BorderFactory.createEmptyBorder(0, 0, LightScrollPane.THUMB_SIZE, 0));
101 1 1. <init> : removed call to com/jsql/view/swing/manager/AbstractManagerList::add → NO_COVERAGE
        this.add(new LightScrollPane(0, 0, 0, 0, this.listFile), BorderLayout.CENTER);
102
103 1 1. <init> : removed call to javax/swing/JPanel::setOpaque → NO_COVERAGE
        this.lastLine.setOpaque(false);
104 1 1. <init> : removed call to javax/swing/JPanel::setLayout → NO_COVERAGE
        this.lastLine.setLayout(new BoxLayout(this.lastLine, BoxLayout.X_AXIS));
105
106 1 1. <init> : removed call to javax/swing/JPanel::setBorder → NO_COVERAGE
        this.lastLine.setBorder(
107
            BorderFactory.createCompoundBorder(
108
                BorderFactory.createMatteBorder(0, 0, 0, 0, UiUtil.COLOR_COMPONENT_BORDER),
109
                BorderFactory.createEmptyBorder(1, 0, 1, 1)
110
            )
111
        );
112
    }
113
114
    /**
115
     * Add a new string to the list if it's not a duplicate.
116
     * @param element The string to add to the list
117
     */
118
    public void addToList(String element) {
119
        
120
        var isFound = false;
121
        DefaultListModel<ItemList> listModel = (DefaultListModel<ItemList>) this.listPaths.getModel();
122
        
123 2 1. addToList : changed conditional boundary → NO_COVERAGE
2. addToList : negated conditional → NO_COVERAGE
        for (var i = 0 ; i < listModel.size() ; i++) {
124 1 1. addToList : negated conditional → NO_COVERAGE
            if (listModel.get(i).toString().equals(element)) {
125
                isFound = true;
126
            }
127
        }
128
        
129 1 1. addToList : negated conditional → NO_COVERAGE
        if (!isFound) {
130
            
131
            var itemList = new ItemList(element);
132 1 1. addToList : removed call to javax/swing/DefaultListModel::addElement → NO_COVERAGE
            listModel.addElement(itemList);
133
        }
134
    }
135
    
136
    public void highlight(String url, String tag) {
137
        
138
        var itemLabel = String.format(" [%s]", tag);
139
        ListModel<ItemList> listModel = this.listPaths.getModel();
140
        
141 2 1. highlight : negated conditional → NO_COVERAGE
2. highlight : changed conditional boundary → NO_COVERAGE
        for (var i = 0 ; i < listModel.getSize() ; i++) {
142 1 1. highlight : negated conditional → NO_COVERAGE
            if (url.contains(listModel.getElementAt(i).getOriginalString())) {
143
                
144 1 1. highlight : removed call to com/jsql/view/swing/list/ItemList::setIsVulnerable → NO_COVERAGE
                listModel.getElementAt(i).setIsVulnerable(true);
145 1 1. highlight : removed call to com/jsql/view/swing/list/ItemList::setInternalString → NO_COVERAGE
                listModel.getElementAt(i).setInternalString(
146
                    listModel
147
                    .getElementAt(i)
148
                    .getInternalString()
149
                    .replace(itemLabel, StringUtils.EMPTY)
150
                    + itemLabel
151
                );
152
                
153 1 1. highlight : removed call to javax/swing/DefaultListModel::setElementAt → NO_COVERAGE
                ((DefaultListModel<ItemList>) listModel).setElementAt(listModel.getElementAt(i), i);
154
            }
155
        }
156
    }
157
    
158
    public void endProcess() {
159
        
160 1 1. endProcess : removed call to com/jsql/view/swing/manager/util/JButtonStateful::setText → NO_COVERAGE
        this.run.setText(I18nViewUtil.valueByKey(this.defaultText));
161 1 1. endProcess : removed call to com/jsql/view/swing/manager/AbstractManagerList::setButtonEnable → NO_COVERAGE
        this.setButtonEnable(true);
162 1 1. endProcess : removed call to javax/swing/JLabel::setVisible → NO_COVERAGE
        this.loader.setVisible(false);
163 1 1. endProcess : removed call to com/jsql/view/swing/manager/util/JButtonStateful::setState → NO_COVERAGE
        this.run.setState(StateButton.STARTABLE);
164
    }
165
166
    /**
167
     * Unselect every element of the list.
168
     */
169
    public void clearSelection() {
170 1 1. clearSelection : removed call to com/jsql/view/swing/list/DnDList::clearSelection → NO_COVERAGE
        this.listPaths.clearSelection();
171
    }
172
173
    /**
174
     * Enable or disable the button.
175
     * @param isEnable The new state of the button
176
     */
177
    public void setButtonEnable(boolean isEnable) {
178 1 1. setButtonEnable : removed call to com/jsql/view/swing/manager/util/JButtonStateful::setEnabled → NO_COVERAGE
        this.run.setEnabled(isEnable);
179
    }
180
181
    /**
182
     * Display another icon to the Privilege label.
183
     * @param icon The new icon
184
     */
185
    public void changePrivilegeIcon(Icon icon) {
186 1 1. changePrivilegeIcon : removed call to javax/swing/JLabel::setIcon → NO_COVERAGE
        this.privilege.setIcon(icon);
187
    }
188
    
189
    
190
    // Getter and setter
191
192
    public DnDList getListPaths() {
193 1 1. getListPaths : replaced return value with null for com/jsql/view/swing/manager/AbstractManagerList::getListPaths → NO_COVERAGE
        return this.listPaths;
194
    }
195
}

Mutations

83

1.1
Location : <init>
Killed by : none
removed call to com/jsql/view/swing/manager/AbstractManagerList::setLayout → NO_COVERAGE

91

1.1
Location : <init>
Killed by : none
negated conditional → NO_COVERAGE

100

1.1
Location : <init>
Killed by : none
removed call to com/jsql/view/swing/list/DnDList::setBorder → NO_COVERAGE

101

1.1
Location : <init>
Killed by : none
removed call to com/jsql/view/swing/manager/AbstractManagerList::add → NO_COVERAGE

103

1.1
Location : <init>
Killed by : none
removed call to javax/swing/JPanel::setOpaque → NO_COVERAGE

104

1.1
Location : <init>
Killed by : none
removed call to javax/swing/JPanel::setLayout → NO_COVERAGE

106

1.1
Location : <init>
Killed by : none
removed call to javax/swing/JPanel::setBorder → NO_COVERAGE

123

1.1
Location : addToList
Killed by : none
changed conditional boundary → NO_COVERAGE

2.2
Location : addToList
Killed by : none
negated conditional → NO_COVERAGE

124

1.1
Location : addToList
Killed by : none
negated conditional → NO_COVERAGE

129

1.1
Location : addToList
Killed by : none
negated conditional → NO_COVERAGE

132

1.1
Location : addToList
Killed by : none
removed call to javax/swing/DefaultListModel::addElement → NO_COVERAGE

141

1.1
Location : highlight
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : highlight
Killed by : none
changed conditional boundary → NO_COVERAGE

142

1.1
Location : highlight
Killed by : none
negated conditional → NO_COVERAGE

144

1.1
Location : highlight
Killed by : none
removed call to com/jsql/view/swing/list/ItemList::setIsVulnerable → NO_COVERAGE

145

1.1
Location : highlight
Killed by : none
removed call to com/jsql/view/swing/list/ItemList::setInternalString → NO_COVERAGE

153

1.1
Location : highlight
Killed by : none
removed call to javax/swing/DefaultListModel::setElementAt → NO_COVERAGE

160

1.1
Location : endProcess
Killed by : none
removed call to com/jsql/view/swing/manager/util/JButtonStateful::setText → NO_COVERAGE

161

1.1
Location : endProcess
Killed by : none
removed call to com/jsql/view/swing/manager/AbstractManagerList::setButtonEnable → NO_COVERAGE

162

1.1
Location : endProcess
Killed by : none
removed call to javax/swing/JLabel::setVisible → NO_COVERAGE

163

1.1
Location : endProcess
Killed by : none
removed call to com/jsql/view/swing/manager/util/JButtonStateful::setState → NO_COVERAGE

170

1.1
Location : clearSelection
Killed by : none
removed call to com/jsql/view/swing/list/DnDList::clearSelection → NO_COVERAGE

178

1.1
Location : setButtonEnable
Killed by : none
removed call to com/jsql/view/swing/manager/util/JButtonStateful::setEnabled → NO_COVERAGE

186

1.1
Location : changePrivilegeIcon
Killed by : none
removed call to javax/swing/JLabel::setIcon → NO_COVERAGE

193

1.1
Location : getListPaths
Killed by : none
replaced return value with null for com/jsql/view/swing/manager/AbstractManagerList::getListPaths → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.16.1