<commit_before>/*
Copyright 2007-2011 WebDriver committers

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package org.openqa.grid.web.utils;

import com.google.common.collect.Maps;
import org.openqa.grid.common.RegistrationRequest;
import org.openqa.grid.web.Hub;
import org.openqa.selenium.Platform;

import java.util.Map;

/**
 * Utilities for dealing with browser names.
 */
public class BrowserNameUtils {
    public static String lookupGrid1Environment(String browserString) {
        String translatedBrowserString = Hub.getGrid1Mapping().get(browserString);

        return (translatedBrowserString == null) ? browserString : translatedBrowserString;
    }

    public static Map<String, Object> parseGrid2Environment(String environment) {
        Map<String, Object> ret = Maps.newHashMap();

        String[] details = environment.split(" ");
        if (details.length == 1) {
            // simple browser string
            ret.put(RegistrationRequest.BROWSER, details[0]);
        } else {
            // more complex. Only case handled so far = X on Y
            // where X is the browser string, Y the OS
            ret.put(RegistrationRequest.BROWSER, details[0]);
            if (details.length==3){
                ret.put(RegistrationRequest.PLATFORM, Platform.extractFromSysProperty(details[2]));
            }
        }

        return ret;
    }

    public static String consoleIconName(String browserString) {
        String ret = browserString;

        // Take care of any Grid 1.0 named environment translation.
        if (browserString.charAt(0) != '*') {
            browserString = lookupGrid1Environment(browserString);
        }

        // Map browser environments to icon names.
        if (browserString.contains("iexplore") || browserString.startsWith("*iehta")) {
			ret = "internet explorer";
		} else if (browserString.contains("firefox") || browserString.startsWith("*chrome")) {
			ret = "firefox";
		} else if (browserString.startsWith("*safari")) {
			ret = "safari";
		} else if (browserString.startsWith("*googlechrome")) {
            ret = "chrome";
        }

        return ret;
    }
}<commit_msg>FrancoisReynaud: addign a helper method to get the browser icons for the grid consoles.<commit_after>/*
Copyright 2007-2011 WebDriver committers

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
 */

package org.openqa.grid.web.utils;

import static org.openqa.grid.common.RegistrationRequest.BROWSER;

import com.google.common.collect.Maps;
import org.openqa.grid.common.RegistrationRequest;
import org.openqa.grid.web.Hub;
import org.openqa.selenium.Platform;

import java.util.Map;

/**
 * Utilities for dealing with browser names.
 */
public class BrowserNameUtils {
	public static String lookupGrid1Environment(String browserString) {
		String translatedBrowserString = Hub.getGrid1Mapping().get(browserString);

		return (translatedBrowserString == null) ? browserString : translatedBrowserString;
	}

	public static Map<String, Object> parseGrid2Environment(String environment) {
		Map<String, Object> ret = Maps.newHashMap();

		String[] details = environment.split(" ");
		if (details.length == 1) {
			// simple browser string
			ret.put(RegistrationRequest.BROWSER, details[0]);
		} else {
			// more complex. Only case handled so far = X on Y
			// where X is the browser string, Y the OS
			ret.put(RegistrationRequest.BROWSER, details[0]);
			if (details.length == 3) {
				ret.put(RegistrationRequest.PLATFORM, Platform.extractFromSysProperty(details[2]));
			}
		}

		return ret;
	}

	public static String consoleIconName(String browserString) {
		String ret = browserString;

		// Take care of any Grid 1.0 named environment translation.
		if (browserString.charAt(0) != '*') {
			browserString = lookupGrid1Environment(browserString);
		}

		// Map browser environments to icon names.
		if (browserString.contains("iexplore") || browserString.startsWith("*iehta")) {
			ret = "internet explorer";
		} else if (browserString.contains("firefox") || browserString.startsWith("*chrome")) {
			ret = "firefox";
		} else if (browserString.startsWith("*safari")) {
			ret = "safari";
		} else if (browserString.startsWith("*googlechrome")) {
			ret = "chrome";
		}

		return ret;
	}

	public static String getConsoleIconPath(String browserString) {
		String name = consoleIconName(browserString);
		return "/grid/resources/images/" + name + ".png";
	}

}
{'fraction_non_alphanumeric': 0.10346110904354298, 'fraction_numerical': 0.00893189430591738, 'mean_word_length': 3.6456352636127916, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7486749', 'n_tokens_mistral': 1580, 'n_tokens_neox': 1460, 'n_words': 463}