<commit_before>/*
 *
 * Paros and its related class files.
 *
 * Paros is an HTTP/HTTPS proxy for assessing web application security.
 * Copyright (C) 2003-2004 Chinotec Technologies Company
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the Clarified Artistic License
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * Clarified Artistic License for more details.
 *
 * You should have received a copy of the Clarified Artistic License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

// ZAP: 2011/08/04 Changed to support new Features
// ZAP: 2011/08/04 Changed to support new interface
// ZAP: 2012/03/15 Changed so the display options can be modified dynamically.
// ZAP: 2012/07/02 Wraps no HttpMessage object, but more generalized Message.
// new map of supported message types; removed history list; removed unused
// methods.
// ZAP: 2012/07/16 Issue 326: Add response time and total length to manual request dialog 
// ZAP: 2012/07/31 Removed the instance variables followRedirect,
// useTrackingSessionState and httpSender. Removed the methods getHttpSender,
// getButtonFollowRedirect and getButtonUseTrackingSessionState and changed the
// methods windowClosing and setVisible.
// ZAP: 2012/08/01 Issue 332: added support for Modes

package org.parosproxy.paros.extension.manualrequest;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
import javax.swing.JTabbedPane;
import javax.swing.JToggleButton;
import javax.swing.JToolBar;

import org.parosproxy.paros.Constant;
import org.parosproxy.paros.control.Control;
import org.parosproxy.paros.control.Control.Mode;
import org.parosproxy.paros.extension.Extension;
import org.parosproxy.paros.extension.manualrequest.http.impl.HttpPanelSender;
import org.parosproxy.paros.extension.option.OptionsParamView;
import org.parosproxy.paros.model.Model;
import org.parosproxy.paros.network.HttpMessage;
import org.parosproxy.paros.view.AbstractFrame;
import org.parosproxy.paros.view.View;
import org.zaproxy.zap.extension.httppanel.HttpPanel;
import org.zaproxy.zap.extension.httppanel.HttpPanelRequest;
import org.zaproxy.zap.extension.httppanel.HttpPanelResponse;
import org.zaproxy.zap.extension.httppanel.Message;
import org.zaproxy.zap.extension.tab.Tab;



public class ManualRequestEditorDialog extends AbstractFrame implements Tab {
	private static final long serialVersionUID = 1L;

	// Window
	private JPanel panelWindow = null; // ZAP
//	private JPanel panelHeader = null;

	private HttpPanelRequest requestPanel = null;
	private HttpPanelResponse responsePanel = null;

//	private JComponent panelMain = null;
//	private JPanel panelContent = null;
	
	// ZAP: Removed the instance variables "JToggleButton followRedirect". and
	// "JToggleButton useTrackingSessionState".
	
	//private JComboBox comboChangeMethod = null;

	private JButton btnSend = null;
	
	// ZAP: Removed the instance variable "HttpSender httpSender".
	
	private boolean isSendEnabled = true;

	private Extension extension = null;
	
	// ZAP: Use more general class than HttpMessage
	private Message message = null;
	
	private String configurationKey;
	
	private RequestResponsePanel requestResponsePanel;

	// ZAP: introduced map of supported message types
    private Map<Class<? extends Message>, MessageSender> mapMessageSenders;

	private static JLabel labelTimeElapse = null;
	private static JLabel labelContentLength = null;
	private static JLabel labelTotalLength = null;
	private static JToolBar footerToolbar = null;
	
	
	public ManualRequestEditorDialog(Frame parent, boolean modal, boolean isSendEnabled, Extension extension, String configurationKey) throws HeadlessException {
		super();
		this.isSendEnabled = isSendEnabled;
		this.extension = extension;
		
		this.configurationKey = OptionsParamView.BASE_VIEW_KEY + "." + configurationKey + ".";
		
		this.setPreferredSize(new Dimension(700, 800));
		initialize();
        
        mapMessageSenders = new HashMap<>();
        mapMessageSenders.put(HttpMessage.class, new HttpPanelSender(getRequestPanel(), getResponsePanel()));
	}

	
	private void initialize() {
		
		requestResponsePanel = new RequestResponsePanel(configurationKey, getRequestPanel(), getResponsePanel());
		
		requestResponsePanel.addEndButton(getBtnSend());
		requestResponsePanel.addSeparator();

		requestResponsePanel.loadConfig();<commit_msg>Changed the class variables labelTimeElapse, labelContentLength, labelTotalLength and footerToolbar of the class ManualRequestEditorDialog to instance variables, as there may be more than one instance at the same time ("Manual Request Editor" and "Resend" dialogues).<commit_after>/*
 *
 * Paros and its related class files.
 *
 * Paros is an HTTP/HTTPS proxy for assessing web application security.
 * Copyright (C) 2003-2004 Chinotec Technologies Company
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the Clarified Artistic License
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * Clarified Artistic License for more details.
 *
 * You should have received a copy of the Clarified Artistic License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

// ZAP: 2011/08/04 Changed to support new Features
// ZAP: 2011/08/04 Changed to support new interface
// ZAP: 2012/03/15 Changed so the display options can be modified dynamically.
// ZAP: 2012/07/02 Wraps no HttpMessage object, but more generalized Message.
// new map of supported message types; removed history list; removed unused
// methods.
// ZAP: 2012/07/16 Issue 326: Add response time and total length to manual request dialog 
// ZAP: 2012/07/31 Removed the instance variables followRedirect,
// useTrackingSessionState and httpSender. Removed the methods getHttpSender,
// getButtonFollowRedirect and getButtonUseTrackingSessionState and changed the
// methods windowClosing and setVisible.
// ZAP: 2012/08/01 Issue 332: added support for Modes

package org.parosproxy.paros.extension.manualrequest;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
import javax.swing.JTabbedPane;
import javax.swing.JToggleButton;
import javax.swing.JToolBar;

import org.parosproxy.paros.Constant;
import org.parosproxy.paros.control.Control;
import org.parosproxy.paros.control.Control.Mode;
import org.parosproxy.paros.extension.Extension;
import org.parosproxy.paros.extension.manualrequest.http.impl.HttpPanelSender;
import org.parosproxy.paros.extension.option.OptionsParamView;
import org.parosproxy.paros.model.Model;
import org.parosproxy.paros.network.HttpMessage;
import org.parosproxy.paros.view.AbstractFrame;
import org.parosproxy.paros.view.View;
import org.zaproxy.zap.extension.httppanel.HttpPanel;
import org.zaproxy.zap.extension.httppanel.HttpPanelRequest;
import org.zaproxy.zap.extension.httppanel.HttpPanelResponse;
import org.zaproxy.zap.extension.httppanel.Message;
import org.zaproxy.zap.extension.tab.Tab;



public class ManualRequestEditorDialog extends AbstractFrame implements Tab {
	private static final long serialVersionUID = 1L;

	// Window
	private JPanel panelWindow = null; // ZAP
//	private JPanel panelHeader = null;

	private HttpPanelRequest requestPanel = null;
	private HttpPanelResponse responsePanel = null;

//	private JComponent panelMain = null;
//	private JPanel panelContent = null;
	
	// ZAP: Removed the instance variables "JToggleButton followRedirect". and
	// "JToggleButton useTrackingSessionState".
	
	//private JComboBox comboChangeMethod = null;

	private JButton btnSend = null;
	
	// ZAP: Removed the instance variable "HttpSender httpSender".
	
	private boolean isSendEnabled = true;

	private Extension extension = null;
	
	// ZAP: Use more general class than HttpMessage
	private Message message = null;
	
	private String configurationKey;
	
	private RequestResponsePanel requestResponsePanel;

	// ZAP: introduced map of supported message types
    private Map<Class<? extends Message>, MessageSender> mapMessageSenders;

	private JLabel labelTimeElapse = null;
	private JLabel labelContentLength = null;
	private JLabel labelTotalLength = null;
	private JToolBar footerToolbar = null;
	
	
	public ManualRequestEditorDialog(Frame parent, boolean modal, boolean isSendEnabled, Extension extension, String configurationKey) throws HeadlessException {
		super();
		this.isSendEnabled = isSendEnabled;
		this.extension = extension;
		
		this.configurationKey = OptionsParamView.BASE_VIEW_KEY + "." + configurationKey + ".";
		
		this.setPreferredSize(new Dimension(700, 800));
		initialize();
        
        mapMessageSenders = new HashMap<>();
        mapMessageSenders.put(HttpMessage.class, new HttpPanelSender(getRequestPanel(), getResponsePanel()));
	}

	
	private void initialize() {
		
		requestResponsePanel = new RequestResponsePanel(configurationKey, getRequestPanel(), getResponsePanel());
		
		requestResponsePanel.addEndButton(getBtnSend());
		requestResponsePanel.addSeparator();

		requestResponsePanel.loadConfig();
{'fraction_non_alphanumeric': 0.08102918586789555, 'fraction_numerical': 0.01747311827956989, 'mean_word_length': 4.881987577639752, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1376670', 'n_tokens_mistral': 3092, 'n_tokens_neox': 2838, 'n_words': 924}