Example usage for org.apache.commons.configuration DataConfiguration getString

List of usage examples for org.apache.commons.configuration DataConfiguration getString

Introduction

In this page you can find the example usage for org.apache.commons.configuration DataConfiguration getString.

Prototype

public String getString(String key, String defaultValue) 

Source Link

Usage

From source file:org.davidmason.zayf.config.ConfigLoader.java

private List<ServerInfo> findServerInfoByPrefixes(DataConfiguration serverConfig, List<String> prefixes) {
    List<ServerInfo> servers = new ArrayList<ServerInfo>();
    for (String prefix : prefixes) {
        String urlKey = prefix + URL_KEY_SUFFIX;
        String userNameKey = prefix + USER_NAME_SUFFIX;
        String apiKeyKey = prefix + API_KEY_SUFFIX;
        ServerInfo server = new ServerInfo(prefix, serverConfig.getURL(urlKey, null),
                serverConfig.getString(userNameKey, null), serverConfig.getString(apiKeyKey, null));
        servers.add(server);//  ww  w .  j a va 2s  .  c o  m
    }
    return servers;
}

From source file:org.davidmason.zayf.rest.ServerProxyImpl.java

private List<ServerInfo> getServerList(DataConfiguration serverConfig) {
    List<String> prefixes = new ArrayList<String>();
    Iterator<String> iter = serverConfig.getKeys();
    // TODO log.debug
    System.out.print("Keys: ");
    while (iter.hasNext()) {
        String key = iter.next();
        // TODO log.debug
        System.out.print(key + " ");
        if (key.endsWith(urlKeySuffix)) {
            String prefix = key.substring(0, key.length() - urlKeySuffix.length());
            if (!prefix.isEmpty()) {
                prefixes.add(prefix);/*from  w w w. ja v  a  2s .  co m*/
            }
        }
    }
    // TODO log.debug
    System.out.println();

    List<ServerInfo> servers = new ArrayList<ServerInfo>();
    for (String prefix : prefixes) {
        String urlKey = prefix + urlKeySuffix;
        String userNameKey = prefix + userNameSuffix;
        String apiKeyKey = prefix + apiKeyKeySuffix;
        // TODO log.debug
        System.out.println("urlKey: " + urlKey + " userNameKey: " + userNameKey + " apiKeyKey: " + apiKeyKey);
        ServerInfo server = new ServerInfo(prefix, serverConfig.getURL(urlKey, null),
                serverConfig.getString(userNameKey, null), serverConfig.getString(apiKeyKey, null));
        servers.add(server);
    }

    return servers;
}

From source file:pl.otros.logview.exceptionshandler.ShowErrorDialogExceptionHandler.java

protected JComponent createDialogView() {
    JPanel jPanel = new JPanel(new MigLayout());
    JLabel label = new JLabel("Do you want to send error report?");
    label.setFont(label.getFont().deriveFont(Font.BOLD));
    jPanel.add(label, "span 4, wrap, center");
    jPanel.add(new JLabel("Comment:"));
    commentTextArea = new JTextArea(10, 30);
    commentTextArea.setWrapStyleWord(true);
    commentTextArea.setLineWrap(true);/*from   w ww . j  a  v  a2s  .  com*/
    JScrollPane jScrollPane = new JScrollPane(commentTextArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    jPanel.add(jScrollPane, "span 3, wrap");
    jPanel.add(new JLabel("Email (optional):"));
    emailTextField = new JTextField(30);
    jPanel.add(emailTextField, "span 3, wrap");

    jPanel.add(new JSeparator(), "span 4, wrap, grow");
    checkBoxUseProxy = new JCheckBox("Use HTTP proxy");
    proxyTf = new JTextField();
    proxyPortModel = new SpinnerNumberModel(80, 1, 256 * 256 - 1, 1);
    proxyUser = new JTextField();
    proxyPasswordField = new JPasswordField();
    proxySpinner = new JSpinner(proxyPortModel);

    jPanel.add(checkBoxUseProxy, "wrap");
    labelProxyHost = new JLabel("Proxy address");
    jPanel.add(labelProxyHost);
    jPanel.add(proxyTf, "wrap, span 3, grow");
    labelProxyPort = new JLabel("Proxy port");
    jPanel.add(labelProxyPort);
    jPanel.add(proxySpinner, "wrap");
    labelProxyUser = new JLabel("User");
    jPanel.add(labelProxyUser);
    jPanel.add(proxyUser, "grow");
    labelProxyPassword = new JLabel("Password");
    jPanel.add(labelProxyPassword);
    jPanel.add(proxyPasswordField, "grow");

    checkBoxUseProxy.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            setProxyEnabled(checkBoxUseProxy.isSelected());
        }
    });
    DataConfiguration c = otrosApplication.getConfiguration();
    proxyTf.setText(c.getString(ConfKeys.HTTP_PROXY_HOST, ""));
    proxyUser.setText(c.getString(ConfKeys.HTTP_PROXY_USER, ""));
    proxyPortModel.setValue(Integer.valueOf(c.getInt(ConfKeys.HTTP_PROXY_PORT, 80)));
    boolean useProxy = c.getBoolean(ConfKeys.HTTP_PROXY_USE, false);
    checkBoxUseProxy.setSelected(useProxy);
    setProxyEnabled(useProxy);

    return jPanel;
}

From source file:pl.otros.logview.gui.actions.ChekForNewVersionOnStartupAction.java

@Override
protected void handleNewVersionIsAvailable(final String current, String running) {
    LOGGER.info(String.format("Running version is %s, current is %s", running, current));
    DataConfiguration configuration = getOtrosApplication().getConfiguration();
    String doNotNotifyThisVersion = configuration
            .getString(ConfKeys.VERSION_CHECK_SKIP_NOTIFICATION_FOR_VERSION, "2000-01-01");
    if (current != null && doNotNotifyThisVersion.compareTo(current) > 0) {
        return;//  ww  w  .j a v a  2s  .c  o  m
    }
    JPanel message = new JPanel(new GridLayout(4, 1, 4, 4));
    message.add(new JLabel(String.format("New version %s is available", current)));
    JButton button = new JButton("Open download page");
    button.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                Desktop.getDesktop()
                        .browse(new URI("https://sourceforge.net/projects/otroslogviewer/files/?source=app"));
            } catch (Exception e1) {
                String msg = "Can't open browser with download page: " + e1.getMessage();
                LOGGER.severe(msg);
                getOtrosApplication().getStatusObserver().updateStatus(msg, StatusObserver.LEVEL_ERROR);
            }
        }
    });
    message.add(button);

    final JCheckBox chboxDoNotNotifyMeAboutVersion = new JCheckBox("Do not notify me about version " + current);
    message.add(chboxDoNotNotifyMeAboutVersion);
    final JCheckBox chboxDoNotCheckVersionOnStart = new JCheckBox("Do not check for new version on startup");
    message.add(chboxDoNotCheckVersionOnStart);

    final JDialog dialog = new JDialog((Frame) null, "New version is available");
    dialog.getContentPane().setLayout(new BorderLayout(5, 5));
    dialog.getContentPane().add(message);

    JPanel jp = new JPanel(new FlowLayout(FlowLayout.CENTER));
    jp.add(new JButton(new AbstractAction("Ok") {

        /**
         * 
         */
        private static final long serialVersionUID = 7930093775785431184L;

        @Override
        public void actionPerformed(ActionEvent e) {
            dialog.setVisible(false);
            dialog.dispose();
            if (chboxDoNotNotifyMeAboutVersion.isSelected()) {
                LOGGER.fine("Disabling new version notificiation for " + current);
                getOtrosApplication().getConfiguration()
                        .setProperty(ConfKeys.VERSION_CHECK_SKIP_NOTIFICATION_FOR_VERSION, current);
            }
            if (chboxDoNotCheckVersionOnStart.isSelected()) {
                LOGGER.fine("Disabling new version check on start");
                getOtrosApplication().getConfiguration().setProperty(ConfKeys.VERSION_CHECK_ON_STARTUP, false);
            }
        }
    }));
    dialog.getContentPane().add(jp, BorderLayout.SOUTH);
    dialog.pack();
    dialog.setResizable(false);
    GuiUtils.centerOnScreen(dialog);
    dialog.setVisible(true);

}

From source file:pl.otros.logview.gui.message.pattern.StyleProperties.java

public static boolean isStyleForGroupDeclared(int group, DataConfiguration styleConfig) {
    String groupSuffix = "." + group;
    if (group <= 0) {
        groupSuffix = "";
    }//from w  ww  .j  a  v a  2s.  c  o  m
    StringBuilder sb = new StringBuilder();
    sb.append(styleConfig.getString(PROP_FONT_FAMILY + groupSuffix, ""));
    sb.append(styleConfig.getString(PROP_FONT_SIZE + groupSuffix, ""));
    sb.append(styleConfig.getString(PROP_FONT_BOLD + groupSuffix, ""));
    sb.append(styleConfig.getString(PROP_FONT_ITALIC + groupSuffix, ""));
    sb.append(styleConfig.getString(PROP_FONT_UNDERLINE + groupSuffix, ""));
    sb.append(styleConfig.getString(PROP_BACKGROUND + groupSuffix, ""));
    sb.append(styleConfig.getString(PROP_FOREGROUND + groupSuffix, ""));

    return sb.toString().trim().length() > 0;

}

From source file:pl.otros.logview.gui.message.pattern.StyleProperties.java

public static Style getStyle(StyleContext styleContext, DataConfiguration styleConfig, String styleName,
        int group) {
    Style style = styleContext.addStyle(styleName, styleContext.getStyle(StyleContext.DEFAULT_STYLE));

    String groupSuffix = "." + group;
    if (group <= 0) {
        groupSuffix = "";
    }//w ww  .  j  av  a 2  s  .c om

    String fontFamily = styleConfig.getString(PROP_FONT_FAMILY + groupSuffix, "");
    if (fontFamily.trim().length() > 0) {
        StyleConstants.setFontFamily(style, styleConfig.getString(PROP_FONT_FAMILY + groupSuffix));
    }

    if (styleConfig.getString(PROP_FONT_SIZE + groupSuffix, "").trim().length() > 0) {
        StyleConstants.setFontSize(style, styleConfig.getInt(PROP_FONT_SIZE + groupSuffix));
    }

    if (styleConfig.getString(PROP_FONT_BOLD + groupSuffix, "").trim().length() > 0) {
        StyleConstants.setBold(style, styleConfig.getBoolean(PROP_FONT_BOLD + groupSuffix));
    }

    if (styleConfig.getString(PROP_FONT_ITALIC + groupSuffix, "").trim().length() > 0) {
        StyleConstants.setItalic(style, styleConfig.getBoolean(PROP_FONT_ITALIC + groupSuffix));
    }

    if (styleConfig.getString(PROP_FONT_UNDERLINE + groupSuffix, "").trim().length() > 0) {
        StyleConstants.setUnderline(style, styleConfig.getBoolean(PROP_FONT_UNDERLINE + groupSuffix));
    }

    if (styleConfig.getString(PROP_BACKGROUND + groupSuffix, "").trim().length() > 0) {
        StyleConstants.setBackground(style, styleConfig.getColor(PROP_BACKGROUND + groupSuffix));
    }

    if (styleConfig.getString(PROP_FOREGROUND + groupSuffix, "").trim().length() > 0) {
        StyleConstants.setForeground(style, styleConfig.getColor(PROP_FOREGROUND + groupSuffix));
    }
    return style;
}