Example usage for java.util Properties containsKey

List of usage examples for java.util Properties containsKey

Introduction

In this page you can find the example usage for java.util Properties containsKey.

Prototype

@Override
    public boolean containsKey(Object key) 

Source Link

Usage

From source file:com.capgemini.archaius.spring.SpringPropertiesLoadingTest.java

/**
 * Of course this works as we're just testing Spring - instead we need to document that you can't do this any more
 * as it will ignore Archaius changes./*w  w  w. ja  va  2  s.c o m*/
 * 
 * @throws Exception
 */
@Test
public void springPropertiesAreLoadedFromSingleFileAndAccessedViaPropertiesLoadersUtils() throws Exception {

    Resource resource = new ClassPathResource("properties/system.properties");
    Properties props = PropertiesLoaderUtils.loadProperties(resource);

    assertThat(props.containsKey(propertyKey), is(true));
}

From source file:com.idega.util.FileLocalizer.java

public static void readFile(File fileToRead, Properties props) {
    BufferedReader in = null;/*from   w w w . j  a v  a 2 s . c o m*/
    try {
        if (fileToRead.isFile()) {
            in = new BufferedReader(new FileReader(fileToRead));
            String input = in.readLine();
            StringTokenizer st;
            String a, b;
            while (input != null) {
                int index = input.indexOf(stringToFind);
                if (index > -1) {
                    int i1 = input.indexOf("(", index);
                    int i2 = input.indexOf(")", index);
                    if (i2 > -1) {
                        a = input.substring(i1 + 2, i2 - 1);
                        b = "";
                        st = new StringTokenizer(a, "\",");
                        if (st.hasMoreTokens()) {
                            a = st.nextToken();
                            if (st.hasMoreTokens()) {
                                b = st.nextToken();
                            }
                            if (!props.containsKey(a)) {
                                props.setProperty(a, b);

                                // System.err.println(a+"="+b);
                            }
                        }
                    }
                }
                input = in.readLine();
            } // while ends
        } else {
            return;
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    } finally {
        IOUtils.closeQuietly(in);
    }
}

From source file:org.apache.metron.management.KafkaFunctions.java

/**
 * Determines how Kafka messages should be rendered for the user.
 *
 * @param properties The properties./*from   ww  w .j a  v a 2 s.co  m*/
 * @return How the Kafka messages should be rendered.
 */
private static String getMessageView(Properties properties) {
    // defaults to the simple view
    String messageView = MESSAGE_VIEW_SIMPLE;

    if (properties.containsKey(MESSAGE_VIEW_PROPERTY)) {
        messageView = ConversionUtils.convert(properties.get(MESSAGE_VIEW_PROPERTY), String.class);
    }

    return messageView;
}

From source file:com.mozilla.bagheera.consumer.KafkaConsumer.java

/**
 * Create a KafkaConsumer from the given command-line options
 * @param cmd//  w  ww. jav a2 s  .  c  o  m
 * @return
 */
public static KafkaConsumer fromOptions(CommandLine cmd) {
    Properties props = new Properties();
    String propsFilePath = cmd.getOptionValue("properties");
    BufferedReader reader = null;
    try {
        reader = new BufferedReader(new InputStreamReader(new FileInputStream(propsFilePath)));
        props.load(reader);
        props.setProperty("groupid", cmd.getOptionValue("groupid"));
    } catch (FileNotFoundException e) {
        LOG.error("Could not find properties file", e);
    } catch (IOException e) {
        LOG.error("Error reading properties file", e);
    } finally {
        if (reader != null) {
            try {
                reader.close();
            } catch (IOException e) {
                LOG.error("Error closing properties file", e);
            }
        }
    }

    int numThreads = props.containsKey("consumer.threads")
            ? Integer.parseInt(props.getProperty("consumer.threads"))
            : DEFAULT_NUM_THREADS;
    // if numthreads specified on command-line then override
    if (cmd.hasOption("numthreads")) {
        numThreads = Integer.parseInt(cmd.getOptionValue("numthreads"));
    }

    // construct consumer
    KafkaConsumer consumer = new KafkaConsumer(cmd.getOptionValue("topic"), props, numThreads);

    // setup validation pipeline if we need to
    if (cmd.hasOption("validatejson")) {
        ValidationPipeline vp = new ValidationPipeline();
        vp.addFirst(new JsonValidator());
        consumer.setValidationPipeline(vp);
    }

    return consumer;
}

From source file:com.th.frame.core.message.impl.AbstractPropertiesMessage.java

protected String getMessageValue(String key) {
    if (null == key || "".equals(key))
        return "";
    Properties _prop = getDefaultProperties();
    return _prop.containsKey(key) ? _prop.getProperty(key) : "";
}

From source file:org.apache.pig.test.RegisteredJarVisibilityLoader.java

@Override
public void setLocation(String location, Job job) throws IOException {
    UDFContext udfContext = UDFContext.getUDFContext();
    Properties properties = udfContext.getUDFProperties(RegisteredJarVisibilityLoader.class);

    if (!properties.containsKey(REGISTERED_JAR_VISIBILITY_SCHEMA)) {
        LOG.info("Storing " + RegisteredJarVisibilitySchema.class.getName() + " in UDFContext.");
        properties.put(REGISTERED_JAR_VISIBILITY_SCHEMA, new RegisteredJarVisibilitySchema());
        LOG.info("Stored " + RegisteredJarVisibilitySchema.class.getName() + " in UDFContext.");
    } else {//w ww  . j  a va2 s. c om
        LOG.info("Retrieving " + REGISTERED_JAR_VISIBILITY_SCHEMA + " from UDFContext.");
        RegisteredJarVisibilitySchema registeredJarVisibilitySchema = (RegisteredJarVisibilitySchema) properties
                .get(REGISTERED_JAR_VISIBILITY_SCHEMA);
        LOG.info("Retrieved " + REGISTERED_JAR_VISIBILITY_SCHEMA + " from UDFContext.");
    }

    super.setLocation(location, job);
}

From source file:com.capgemini.archaius.spring.jdbc.SpringPropertiesLoadingFromJdbcAndPropertiesFileTest.java

/**
 * Of course this works as we're just testing Spring - instead we need to
 * document that you can't do this any more as it will ignore Archaius
 * changes.//w w w. j ava2s .c  o  m
 *
 * @throws Exception
 */
@Test
public void springPropertiesAreLoadedFromSingleFileAndAccessedViaPropertiesLoadersUtils() throws Exception {

    Resource resource = new ClassPathResource("properties/archaiusSystem.properties");
    Properties props = PropertiesLoaderUtils.loadProperties(resource);

    assertThat(props.containsKey(propertyKey), is(true));
}

From source file:com.piusvelte.taplock.server.TapLockServer.java

private static void initialize() {
    (new File(APP_PATH)).mkdir();
    if (OS == OS_WIN)
        Security.addProvider(new BouncyCastleProvider());
    System.out.println("APP_PATH: " + APP_PATH);
    try {// w w  w . j a  v  a2 s. c  om
        sLogFileHandler = new FileHandler(sLog);
    } catch (SecurityException e) {
        writeLog("sLogFileHandler init: " + e.getMessage());
    } catch (IOException e) {
        writeLog("sLogFileHandler init: " + e.getMessage());
    }

    File propertiesFile = new File(sProperties);
    if (!propertiesFile.exists()) {
        try {
            propertiesFile.createNewFile();
        } catch (IOException e) {
            writeLog("propertiesFile.createNewFile: " + e.getMessage());
        }
    }

    Properties prop = new Properties();

    try {
        prop.load(new FileInputStream(sProperties));
        if (prop.isEmpty()) {
            prop.setProperty(sPassphraseKey, sPassphrase);
            prop.setProperty(sDisplaySystemTrayKey, Boolean.toString(sDisplaySystemTray));
            prop.setProperty(sDebuggingKey, Boolean.toString(sDebugging));
            prop.store(new FileOutputStream(sProperties), null);
        } else {
            if (prop.containsKey(sPassphraseKey))
                sPassphrase = prop.getProperty(sPassphraseKey);
            else
                prop.setProperty(sPassphraseKey, sPassphrase);
            if (prop.containsKey(sDisplaySystemTrayKey))
                sDisplaySystemTray = Boolean.parseBoolean(prop.getProperty(sDisplaySystemTrayKey));
            else
                prop.setProperty(sDisplaySystemTrayKey, Boolean.toString(sDisplaySystemTray));
            if (prop.containsKey(sDebuggingKey))
                sDebugging = Boolean.parseBoolean(prop.getProperty(sDebuggingKey));
            else
                prop.setProperty(sDebuggingKey, Boolean.toString(sDebugging));
        }
    } catch (FileNotFoundException e) {
        writeLog("prop load: " + e.getMessage());
    } catch (IOException e) {
        writeLog("prop load: " + e.getMessage());
    }

    if (sLogFileHandler != null) {
        sLogger = Logger.getLogger("TapLock");
        sLogger.setUseParentHandlers(false);
        sLogger.addHandler(sLogFileHandler);
        SimpleFormatter sf = new SimpleFormatter();
        sLogFileHandler.setFormatter(sf);
        writeLog("service starting");
    }

    if (sDisplaySystemTray && SystemTray.isSupported()) {
        final SystemTray systemTray = SystemTray.getSystemTray();
        Image trayIconImg = Toolkit.getDefaultToolkit()
                .getImage(TapLockServer.class.getResource("/systemtrayicon.png"));
        final TrayIcon trayIcon = new TrayIcon(trayIconImg, "Tap Lock");
        trayIcon.setImageAutoSize(true);
        PopupMenu popupMenu = new PopupMenu();
        MenuItem aboutItem = new MenuItem("About");
        CheckboxMenuItem toggleSystemTrayIcon = new CheckboxMenuItem("Display Icon in System Tray");
        toggleSystemTrayIcon.setState(sDisplaySystemTray);
        CheckboxMenuItem toggleDebugging = new CheckboxMenuItem("Debugging");
        toggleDebugging.setState(sDebugging);
        MenuItem shutdownItem = new MenuItem("Shutdown Tap Lock Server");
        popupMenu.add(aboutItem);
        popupMenu.add(toggleSystemTrayIcon);
        if (OS == OS_WIN) {
            MenuItem setPasswordItem = new MenuItem("Set password");
            popupMenu.add(setPasswordItem);
            setPasswordItem.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    JPanel panel = new JPanel();
                    JLabel label = new JLabel("Enter your Windows account password:");
                    JPasswordField passField = new JPasswordField(32);
                    panel.add(label);
                    panel.add(passField);
                    String[] options = new String[] { "OK", "Cancel" };
                    int option = JOptionPane.showOptionDialog(null, panel, "Tap Lock", JOptionPane.NO_OPTION,
                            JOptionPane.PLAIN_MESSAGE, null, options, options[0]);
                    if (option == 0) {
                        String password = encryptString(new String(passField.getPassword()));
                        if (password != null) {
                            Properties prop = new Properties();
                            try {
                                prop.load(new FileInputStream(sProperties));
                                prop.setProperty(sPasswordKey, password);
                                prop.store(new FileOutputStream(sProperties), null);
                            } catch (FileNotFoundException e1) {
                                writeLog("prop load: " + e1.getMessage());
                            } catch (IOException e1) {
                                writeLog("prop load: " + e1.getMessage());
                            }
                        }
                    }
                }
            });
        }
        popupMenu.add(toggleDebugging);
        popupMenu.add(shutdownItem);
        trayIcon.setPopupMenu(popupMenu);
        try {
            systemTray.add(trayIcon);
        } catch (AWTException e) {
            writeLog("systemTray.add: " + e.getMessage());
        }
        aboutItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String newline = System.getProperty("line.separator");
                newline += newline;
                JOptionPane.showMessageDialog(null, "Tap Lock" + newline + "Copyright (c) 2012 Bryan Emmanuel"
                        + newline
                        + "This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version."
                        + newline
                        + "This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details."
                        + newline
                        + "You should have received a copy of the GNU General Public License along with this program.  If not, see <http://www.gnu.org/licenses/>."
                        + newline + "Bryan Emmanuel piusvelte@gmail.com");
            }
        });
        toggleSystemTrayIcon.addItemListener(new ItemListener() {
            @Override
            public void itemStateChanged(ItemEvent e) {
                setTrayIconDisplay(e.getStateChange() == ItemEvent.SELECTED);
                if (!sDisplaySystemTray)
                    systemTray.remove(trayIcon);
            }
        });
        toggleDebugging.addItemListener(new ItemListener() {
            @Override
            public void itemStateChanged(ItemEvent e) {
                setDebugging(e.getStateChange() == ItemEvent.SELECTED);
            }
        });
        shutdownItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                shutdown();
            }
        });
    }
    synchronized (sConnectionThreadLock) {
        (sConnectionThread = new ConnectionThread()).start();
    }
}

From source file:edu.tamu.tcat.db.core.AbstractDataSourceFactory.java

protected int getMaxActiveConnections(Properties parameters) {
    if (parameters.containsKey(MAX_ACTIVE_CONNECTIONS))
        return Integer.parseInt(parameters.getProperty(MAX_ACTIVE_CONNECTIONS));
    return 5;/*from   w  ww  .j a v a  2  s.co  m*/
}

From source file:edu.tamu.tcat.db.core.AbstractDataSourceFactory.java

protected int getMaxIdleConnections(Properties parameters) {
    if (parameters.containsKey(MAX_IDLE_CONNECTIONS))
        return Integer.parseInt(parameters.getProperty(MAX_IDLE_CONNECTIONS));
    return 5;/*from  w ww. j  av  a2 s .com*/
}