<commit_before>package com.gallatinsystems.framework.dataexport.applet;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Map;
import java.util.Map.Entry;

import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;


/**
 * applet wrapper for data import utilities
 * 
 * @author <NAME>
 * 
 */
public class DataImportAppletImpl extends JApplet {

	private static final long serialVersionUID = -545153291195490725L;
	private static final String IMPORT_TYPE_PARAM = "importType";	
	private static final String FACTORY_PARAM = "factoryClass";
	private static final String SERVER_BASE_OVERRIDE_PARAM = "serverOverride";
	private DataImportExportFactory dataImporterFactory;
	private JLabel statusLabel;

	public void init() {
		statusLabel = new JLabel();
		getContentPane().add(statusLabel);
		String type = getParameter(IMPORT_TYPE_PARAM);	
		String factoryClass = getParameter(FACTORY_PARAM);
		String serverBase = getParameter(SERVER_BASE_OVERRIDE_PARAM);
		if(serverBase == null || serverBase.trim().length()==0){
			serverBase = getCodeBase().toString();
		}
		if (factoryClass != null) {
			try {
				dataImporterFactory = (DataImportExportFactory) Class.forName(
						factoryClass).newInstance();
			} catch (Exception e) {
				System.err.println("Could not instantiate factory: "
						+ factoryClass);
				e.printStackTrace(System.err);
			}
		}else{
			System.err.println("Factory must be specified");
		}
		doImport(type, serverBase);
	}

	public void doImport(String type, String serverBase) {
		JFileChooser chooser = new JFileChooser();

		chooser.showOpenDialog(this);
		if (chooser.getSelectedFile() != null) {
			DataImporter importer = dataImporterFactory.getImporter(type);
			statusLabel.setText("Validating...");
			Map<Integer, String> errorMap = importer.validate(chooser
					.getSelectedFile());
			if (errorMap.size() == 0) {
				if (serverBase.trim().endsWith("/")) {
					serverBase = serverBase.trim().substring(0,
							serverBase.lastIndexOf("/"));
				}
				importer.executeImport(chooser.getSelectedFile(), serverBase);
				statusLabel.setText("Import Complete");
			} else {
				statusLabel.setText("Vailidation Failed");
				StringBuilder builder = new StringBuilder();
				builder.append("The survey has the following errors:\n");
				for (Entry<Integer, String> entry : errorMap.entrySet()) {
					builder.append("Row ").append(entry.getKey()).append(": ")
							.append(entry.getValue()).append("\n\n");
				}
				final JDialog dia = new JDialog();
				dia.setTitle("Validation Failure");
				final JTextPane text = new JTextPane();
				final JScrollPane scroller = new JScrollPane(text);
				text.setEditable(false);
				text.setText(builder.toString());
				dia.getContentPane().setLayout(new BorderLayout());
				dia.getContentPane().add(scroller, BorderLayout.CENTER);
				dia.setSize(400, 400);
				JButton okButton = new JButton("Ok");
				okButton.addActionListener(new ActionListener() {

					@Override
					public void actionPerformed(ActionEvent e) {
						dia.setVisible(false);
						text.setText("");						
					}
				});
				dia.getContentPane().add(okButton, BorderLayout.SOUTH);
				dia.setVisible(true);
			}

		}
<commit_msg>added documentation to base importer applet<commit_after>package com.gallatinsystems.framework.dataexport.applet;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Map;
import java.util.Map.Entry;

import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;

/**
 * applet wrapper for data import utilities
 * 
 * @author <NAME>
 * 
 */
public class DataImportAppletImpl extends JApplet {

	private static final long serialVersionUID = -545153291195490725L;
	private static final String IMPORT_TYPE_PARAM = "importType";
	private static final String FACTORY_PARAM = "factoryClass";
	private static final String SERVER_BASE_OVERRIDE_PARAM = "serverOverride";
	private DataImportExportFactory dataImporterFactory;
	private JLabel statusLabel;

	/**
	 * initializes the applet by reading in the configuration parameters
	 * configured in the Applet tag. This applet expects to be passed the
	 * following:
	 * <ul>
	 * <li>factoryClass - fully qualified class name of a
	 * DataImportExportFactory instance</li>
	 * <li>importType - the type of importer to run. This value will be passed
	 * to the importer factory</li>
	 * <li>serverOverride (optional) - server base to use for remote api calls.
	 * This is only used for testing or for calling a server other than the one
	 * hosting the html page that loaded the applet</li>
	 * </ul>
	 */
	public void init() {
		statusLabel = new JLabel();
		getContentPane().add(statusLabel);
		String type = getParameter(IMPORT_TYPE_PARAM);
		String factoryClass = getParameter(FACTORY_PARAM);
		String serverBase = getParameter(SERVER_BASE_OVERRIDE_PARAM);
		if (serverBase == null || serverBase.trim().length() == 0) {
			serverBase = getCodeBase().toString();
		}
		if (factoryClass != null) {
			try {
				dataImporterFactory = (DataImportExportFactory) Class.forName(
						factoryClass).newInstance();
			} catch (Exception e) {
				System.err.println("Could not instantiate factory: "
						+ factoryClass);
				e.printStackTrace(System.err);
			}
		} else {
			System.err.println("Factory must be specified");
		}
		doImport(type, serverBase);
	}

	/**
	 * exectues the import. This will launch a fileChooser dialog box and allow
	 * the user to specify a file for import. Once a file has been chosen, the
	 * file will be passed to the dataImporter returned by the factory and the
	 * executeImport method will be called on the DataImporter instance.
	 * 
	 * @param type
	 * @param serverBase
	 */
	public void doImport(String type, String serverBase) {
		JFileChooser chooser = new JFileChooser();

		chooser.showOpenDialog(this);
		if (chooser.getSelectedFile() != null) {
			DataImporter importer = dataImporterFactory.getImporter(type);
			statusLabel.setText("Validating...");
			Map<Integer, String> errorMap = importer.validate(chooser
					.getSelectedFile());
			if (errorMap.size() == 0) {
				if (serverBase.trim().endsWith("/")) {
					serverBase = serverBase.trim().substring(0,
							serverBase.lastIndexOf("/"));
				}
				importer.executeImport(chooser.getSelectedFile(), serverBase);
				statusLabel.setText("Import Complete");
			} else {
				statusLabel.setText("Vailidation Failed");
				StringBuilder builder = new StringBuilder();
				builder.append("The survey has the following errors:\n");
				for (Entry<Integer, String> entry : errorMap.entrySet()) {
					builder.append("Row ").append(entry.getKey()).append(": ")
							.append(entry.getValue()).append("\n\n");
				}
				final JDialog dia = new JDialog();
				dia.setTitle("Validation Failure");
				final JTextPane text = new JTextPane();
				final JScrollPane scroller = new JScrollPane(text);
				text.setEditable(false);
				text.setText(builder.toString());
				dia.getContentPane().setLayout(new BorderLayout());
				dia.getContentPane().add(scroller, BorderLayout.CENTER);
				dia.setSize(400, 400);
				JButton okButton = new JButton("Ok");
				okButton.addActionListener(new ActionListener() {

					@Override
					public void actionPerformed(ActionEvent e) {
						dia.setVisible(false);
						text.setText("");
					}
				});
				dia.getContentPane().add(okButton, BorderLayout.SOUTH);
				dia.setVisible(true);
			}

		}

{'fraction_non_alphanumeric': 0.11825192802056556, 'fraction_numerical': 0.006940874035989717, 'mean_word_length': 4.20120320855615, 'pattern_counts': {'":': 2, '<': 17, '<?xml version=': 0, '>': 17, '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': '6544459', 'n_tokens_mistral': 2733, 'n_tokens_neox': 2272, 'n_words': 564}