<commit_before>package gov.nasa.jpl.mgss.mbee.docgen.viewedit;

import gov.nasa.jpl.mbee.lib.Utils;

import java.awt.GridLayout;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Arrays;
import java.util.List;

import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScope;

public class ViewEditUtils {
	private static final String DEFAULT_EDITOR_CHOICE = "Community: http://docgen:8080/editor";
	private static String editorurl = null;
	private static String otherurl = "";
	private static String username = "admin";
	private static String password = "<PASSWORD>";
	private static String alf_ticket = "";
	private static boolean passwordSet = false;
	private static final List<String> servers = Arrays.asList("http://docgen.jpl.nasa.gov:8080/editor", 
															  "http://docgen.jpl.nasa.gov:8080/europa", 
															  "https://europaems:8443/alfresco/service",
															  "http://docgen.jpl.nasa.gov:8080/staging", 
															  "http://localhost:8080/editor",
															  "http://localhost:8080/view-repo/service",
															  "Other");
	private static final List<String> displays = Arrays.asList("Community: http://docgen:8080/editor",
															   "Europa: http://docgen:8080/europa",
															   "Europa Alfresco: https://europaems:8443/alfresco/service",
															   "Staging: http://docgen:8080/staging",
															   "Local-dev: http://localhost:8080/editor",
															   "Local-alfresco: http://localhost:8080/view-repo/service",
															   "Other");
	public static String getUrl() {
		String chosen = editorurl == null ? DEFAULT_EDITOR_CHOICE : editorurl;
		String url = Utils.getUserDropdownSelectionForString("Choose", "Choose View Editor Server", servers, displays, chosen);
		if (url == null) {
			return url;
		}
		editorurl = displays.get(servers.indexOf(url));
		if (url.equals("Other")) {
			String other = JOptionPane.showInputDialog("Enter the editor URL:", otherurl);
			if (other != null)
				otherurl = other;
			return other;
		}
		return url;
	}

	@Deprecated
	public static void setCredentials(HttpClient client) {
		setCredentials(client, "http://127.0.0.1:8080");
	}
	
	/**
	 * Sets credentials for the client based on the actual URL string
	 * @param client
	 * @param urlstring
	 */
	public static void setCredentials(HttpClient client, String urlstring) {
		try {
			URL url = new URL(urlstring);
			
			if (url.getProtocol().toLowerCase().equals("https") && !passwordSet) {
				// Pop up one time dialog for logging into Alfresco
				JPanel userPanel = new JPanel();<commit_msg>fixed ordering of europa view editor servers, remove deprecated function<commit_after>package gov.nasa.jpl.mgss.mbee.docgen.viewedit;

import gov.nasa.jpl.mbee.lib.Utils;

import java.awt.GridLayout;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Arrays;
import java.util.List;

import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScope;

public class ViewEditUtils {
	private static final String DEFAULT_EDITOR_CHOICE = "Community: http://docgen:8080/editor";
	private static String editorurl = null;
	private static String otherurl = "";
	private static String username = "admin";
	private static String password = "<PASSWORD>";
	private static String alf_ticket = "";
	private static boolean passwordSet = false;
	private static final List<String> servers = Arrays.asList("http://docgen.jpl.nasa.gov:8080/editor", 
															  "https://europaems:8443/alfresco/service",
															  "http://docgen.jpl.nasa.gov:8080/europa",   
															  "http://docgen.jpl.nasa.gov:8080/staging", 
															  "http://localhost:8080/editor",
															  "http://localhost:8080/view-repo/service",
															  "Other");
	private static final List<String> displays = Arrays.asList("Community: http://docgen:8080/editor",
			                          						   "Europa Alfresco: https://europaems:8443/alfresco/service",
			                          						   "Europa: http://docgen:8080/europa",											
															   "Staging: http://docgen:8080/staging",
															   "Local-dev: http://localhost:8080/editor",
															   "Local-alfresco: http://localhost:8080/view-repo/service",
															   "Other");
	public static String getUrl() {
		String chosen = editorurl == null ? DEFAULT_EDITOR_CHOICE : editorurl;
		String url = Utils.getUserDropdownSelectionForString("Choose", "Choose View Editor Server", servers, displays, chosen);
		if (url == null) {
			return url;
		}
		editorurl = displays.get(servers.indexOf(url));
		if (url.equals("Other")) {
			String other = JOptionPane.showInputDialog("Enter the editor URL:", otherurl);
			if (other != null)
				otherurl = other;
			return other;
		}
		return url;
	}
	
	/**
	 * Sets credentials for the client based on the actual URL string
	 * @param client
	 * @param urlstring
	 */
	public static void setCredentials(HttpClient client, String urlstring) {
		try {
			URL url = new URL(urlstring);
			
			if (url.getProtocol().toLowerCase().equals("https") && !passwordSet) {
				// Pop up one time dialog for logging into Alfresco
				JPanel userPanel = new JPanel();
{'fraction_non_alphanumeric': 0.12130075705437027, 'fraction_numerical': 0.01961459050240881, 'mean_word_length': 3.2679882525697503, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, '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': '2498653', 'n_tokens_mistral': 2226, 'n_tokens_neox': 1759, 'n_words': 394}