<commit_before>/*
 * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
 *
 * WSO2 Inc. licenses this file to you 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.wso2.carbon.uuf.maven.model;

import java.util.Map;

/**
 * Bean class that represents the app's config file of an UUF App.
 *
 * @since 1.0.0
 */
public class AppConfig {

    private String theme;
    private String loginPageUri;
    private String loginRedirectUri;
    private Map<String, MenuItem[]> menus;
    private Map<String, String> errorPages;

    /**
     * Returns the theme name in this app's config.
     *
     * @return theme name in this app's config
     */
    public String getTheme() {
        return theme;
    }

    /**
     * Sets the theme name in this app's config.
     *
     * @param theme theme name to be set
     */
    public void setTheme(String theme) {
        this.theme = theme;
    }

    /**
     * Returns the login page URI in this app's config.
     *
     * @return URI of the login page in this app's config
     */
    public String getLoginPageUri() {
        return loginPageUri;
    }

    /**
     * Sets the login page URI in this app's config.
     *
     * @param loginPageUri URI of the login page to be set
     */
    public void setLoginPageUri(String loginPageUri) {
        this.loginPageUri = loginPageUri;
    }

    /**
     * Returns the login redirect URI in this app's config.
     *
     * @return URI of the login redirect page in this app's config
     */
    public String getLoginRedirectUri() {
        return loginRedirectUri;
    }

    /**
     * Sets the login redirect URI in this app's config.
     *
     * @param loginRedirectUri URI of the login redirect page in this app's config
     */
    public void setLoginRedirectUri(String loginRedirectUri) {
        this.loginRedirectUri = loginRedirectUri;
    }

    /**
     * Returns the menus in this app's config.
     *
     * @return menus in this app's config
     */
    public Map<String, MenuItem[]> getMenus() {
        return menus;
    }

    /**
     * Sets the menus in this app's config.
     *
     * @param menus menus to be set
     */
    public void setMenus(Map<String, MenuItem[]> menus) {
        this.menus = menus;
    }

    /**
     * Returns the error pages URIs in this app's config.
     *
     * @return URIs of error pages in this app's config
     */
    public Map<String, String> getErrorPages() {
        return errorPages;
    }

    /**
     * Sets the error pages URIs in this app's config.
     *
     * @param errorPages URIs of error pages to be set
     */
    public void setErrorPages(Map<String, String> errorPages) {
        this.errorPages = errorPages;
    }

    /**
     * Bean class that represents a menu item in the app's config file of an UUF Component.
     *
     * @since 1.0.0
     */
    public static class MenuItem {

        private String text;
        private String link;
        private String icon;<commit_msg>added more members to AppConfig class<commit_after>/*
 * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
 *
 * WSO2 Inc. licenses this file to you 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.wso2.carbon.uuf.maven.model;

import java.util.Map;
import java.util.regex.Pattern;

/**
 * Bean class that represents the app's config file of an UUF App.
 *
 * @since 1.0.0
 */
public class AppConfig {

    public static final Pattern HTTP_STATUS_CODES_PATTERN = Pattern.compile("[1-9][0-9][0-9]");

    private String contextPath;
    private String theme;
    private String loginPageUri;
    private Map<String, String> errorPages;
    private Map<String, MenuItem[]> menus;
    private SecurityConfig security;

    /**
     * Returns the client-side context path in this app's config.
     *
     * @return client-side context path in this app's config.
     */
    public String getContextPath() {
        return contextPath;
    }

    /**
     * Sets the client-side context path in this app's config.
     *
     * @param contextPath client-side context path to be set
     * @throws IllegalArgumentException if {@code contextPath} is empty or doesn't start with a '/'.
     */
    public void setContextPath(String contextPath) {
        if (contextPath == null) {
            return;
        }

        if (contextPath.isEmpty()) {
            throw new IllegalArgumentException("Value of 'contextPath' cannot be empty.");
        } else if (contextPath.charAt(0) != '/') {
            throw new IllegalArgumentException("Value of 'contextPath' must start with a '/'. Instead found '" +
                                                       contextPath.charAt(0) + "' at the beginning.");
        }
        this.contextPath = contextPath;
    }

    /**
     * Returns the theme name in this app's config.
     *
     * @return theme name in this app's config
     */
    public String getTheme() {
        return theme;
    }

    /**
     * Sets the theme name in this app's config.
     *
     * @param theme theme name to be set
     * @throws IllegalArgumentException if {@code theme} is an empty string
     */
    public void setTheme(String theme) {
        if (theme == null) {
            return;
        }

        if (theme.isEmpty()) {
            throw new IllegalArgumentException("Value of 'theme' cannot be empty.");
        }
        this.theme = theme;
    }

    /**
     * Returns the login page URI in this app's config.
     *
     * @return URI of the login page in this app's config
     */
    public String getLoginPageUri() {
        return loginPageUri;
    }

    /**
     * Sets the login page URI in this app's config.
     *
     * @param loginPageUri URI of the login page to be set
     * @throws IllegalArgumentException if {@code loginPageUri} is empty or doesn't start with a '/'.
     */
    public void setLoginPageUri(String loginPageUri) {
        if (loginPageUri == null) {
            return;
        }
        if (loginPageUri.isEmpty()) {
            throw new IllegalArgumentException("Value of 'loginPageUri' cannot be empty.");
        }
        if (loginPageUri.charAt(0) != '/') {
            throw new IllegalArgumentException("Value of 'loginPageUri' must start with a '/'. Instead found '" +
                                                       loginPageUri.charAt(0) + "' at the beginning.");
        }
        this.loginPageUri = loginPageUri;
    }

    /**
     * Returns the error pages URIs in this app's config.
     *
     * @return URIs of error pages in this app's config
     */
    public Map<String, String> getErrorPages() {
        return errorPages;
    }

    /**
     * Sets the error pages URIs in this app's config.
     *
     * @param errorPages URIs of error pages to be set
     * @throws IllegalArgumentException if an error page URI is empty or doesn't start with a '/'.
     */
    public void setErrorPages(Map<String, String> errorPages) {
        for (Map.Entry<String, String> entry : errorPages.entrySet()) {
            String httpStatusCode = entry.getKey();
            String errorPageUri = entry.getValue();

            if (!httpStatusCode.equals("default") && !HTTP_STATUS_CODES_PATTERN.matcher(httpStatusCode).matches()) {
                throw new IllegalArgumentException(
                        "HTTP status code must be between 100 and 999. Instead found '" + httpStatusCode +
                                "' for error page URI '" + errorPageUri + "'.");
            }

            if (errorPageUri.isEmpty()) {
                throw new IllegalArgumentException(
                        "Error page URI for HTTP status code '" + httpStatusCode + "' cannot be empty.");
            } else if (errorPageUri.charAt(0) != '/') {
                throw new IllegalArgumentException("Error page URI for HTTP status code '" + httpStatusCode +
                                                           "' must start with a '/'. Instead found '" +
                                                           errorPageUri.charAt(0) + "' at the beginning.");
            }
        }
        this.errorPages = errorPages;
    }

    /**
     * Returns the menus in this app's config.
     *
     * @return menus in this app's config
     */
    public Map<String, MenuItem[]> getMenus() {
        return menus;
    }

    /**
     * Sets the menus in this app's config.
     *
     * @param menus menus to be set
     */
    public void setMenus(Map<String, MenuItem[]> menus) {
        this.menus = menus;
    }

    /**
     * Returns the security related configurations in this app's config.
     *
     * @return security related configurations in this app's config
     */
    public SecurityConfig getSecurity() {
        return security;
    }

    /**
     * Sets the security related configurations in this app's config.
     *
     * @param security security configs to be set
     */
    public void setSecurity(SecurityConfig security) {
        this.security = security;
    }

    /**
     * Bean class that represents a menu item in the app's config file of an UUF Component.
     *
     * @since 1.0.0
     */
    public static class MenuItem {

        private String text;
        private String link;
        private String icon;
{'fraction_non_alphanumeric': 0.09205671004078461, 'fraction_numerical': 0.005243736647892795, 'mean_word_length': 2.0807657792402035, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 9, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6744159', 'n_tokens_mistral': 2825, 'n_tokens_neox': 2697, 'n_words': 1039}