All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.zaproxy.zap.extension.keyboard.KeyboardParam Maven / Gradle / Ivy

Go to download

The Zed Attack Proxy (ZAP) is an easy to use integrated penetration testing tool for finding vulnerabilities in web applications. It is designed to be used by people with a wide range of security experience and as such is ideal for developers and functional testers who are new to penetration testing. ZAP provides automated scanners as well as a set of tools that allow you to find security vulnerabilities manually.

There is a newer version: 2.15.0
Show newest version
/*
 * Zed Attack Proxy (ZAP) and its related class files.
 *
 * ZAP is an HTTP/HTTPS proxy for assessing web application security.
 *
 * Copyright 2014 The ZAP Development Team
 *
 * 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.zaproxy.zap.extension.keyboard;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import javax.swing.KeyStroke;
import org.apache.commons.configuration.ConversionException;
import org.apache.commons.configuration.HierarchicalConfiguration;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.parosproxy.paros.common.AbstractParam;

public class KeyboardParam extends AbstractParam {

    private static final Logger logger = LogManager.getLogger(KeyboardParam.class);

    private static final String KEYBOARD_BASE_KEY = "keyboard";

    private static final String ALL_SHORTCUTS_KEY = KEYBOARD_BASE_KEY + ".shortcuts";

    private static final String MENU_ITEM_KEY = "menu";
    private static final String KEYCODE_KEY = "keycode";
    private static final String MODIFIERS_KEY = "modifiers";

    private Map map = null;

    public KeyboardParam() {}

    @Override
    protected void parse() {
        try {
            List fields =
                    ((HierarchicalConfiguration) getConfig()).configurationsAt(ALL_SHORTCUTS_KEY);
            map = new HashMap<>(fields.size());
            for (HierarchicalConfiguration sub : fields) {
                String name = sub.getString(MENU_ITEM_KEY, "");
                if (name.length() > 0) {
                    map.put(
                            name,
                            KeyStroke.getKeyStroke(
                                    sub.getInt(KEYCODE_KEY, 0),
                                    sub.getInt(MODIFIERS_KEY, 0),
                                    false));
                }
            }
        } catch (ConversionException e) {
            logger.error("Error while loading keyboard shortcuts {}", e.getMessage(), e);
        }
    }

    public KeyStroke getShortcut(String i18nKey) {
        return map.get(i18nKey);
    }

    public void setShortcut(String i18nKey, KeyStroke keyStroke) {
        map.put(i18nKey, keyStroke);
    }

    protected void setConfigs() {
        ((HierarchicalConfiguration) getConfig()).clearTree(ALL_SHORTCUTS_KEY);

        int i = 0;
        for (Entry entry : map.entrySet()) {
            String elementBaseKey = ALL_SHORTCUTS_KEY + "(" + i + ").";
            getConfig().setProperty(elementBaseKey + MENU_ITEM_KEY, entry.getKey());
            if (entry.getValue() != null) {
                getConfig()
                        .setProperty(elementBaseKey + KEYCODE_KEY, entry.getValue().getKeyCode());
                getConfig()
                        .setProperty(
                                elementBaseKey + MODIFIERS_KEY, entry.getValue().getModifiers());
            } else {
                getConfig().setProperty(elementBaseKey + KEYCODE_KEY, 0);
                getConfig().setProperty(elementBaseKey + MODIFIERS_KEY, 0);
            }
            i++;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy