Example usage for java.util Properties stringPropertyNames

List of usage examples for java.util Properties stringPropertyNames

Introduction

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

Prototype

public Set<String> stringPropertyNames() 

Source Link

Document

Returns an unmodifiable set of keys from this property list where the key and its corresponding value are strings, including distinct keys in the default property list if a key of the same name has not already been found from the main properties list.

Usage

From source file:gtu._work.ui.PropertyEditUI.java

private void initGUI() {
    try {//from  w  w w  .  java  2s . c om
        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        BorderLayout thisLayout = new BorderLayout();
        this.setTitle("PropertyEditUI");
        getContentPane().setLayout(thisLayout);
        {
            jMenuBar1 = new JMenuBar();
            setJMenuBar(jMenuBar1);
            {
                jMenu1 = new JMenu();
                jMenuBar1.add(jMenu1);
                jMenu1.setText("File");
                {
                    jMenuItem1 = new JMenuItem();
                    jMenu1.add(jMenuItem1);
                    jMenuItem1.setText("open directory");
                    jMenuItem1.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            File file = JCommonUtil._jFileChooser_selectDirectoryOnly();
                            loadCurrentFile(file);
                        }
                    });
                }
                {
                    openDirectoryAndChildren = new JMenuItem();
                    jMenu1.add(openDirectoryAndChildren);
                    openDirectoryAndChildren.setText("open directory and children");
                    openDirectoryAndChildren.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            System.out.println("openDirectoryAndChildren.actionPerformed, event=" + evt);
                            File file = JCommonUtil._jFileChooser_selectDirectoryOnly();
                            if (file == null) {
                                // file =
                                // PropertiesUtil.getJarCurrentPath(getClass());//XXX
                                file = new File("D:\\my_tool\\english");
                                JCommonUtil._jOptionPane_showMessageDialog_info("load C:\\L-CONFIG !");
                            }
                            DefaultListModel model = new DefaultListModel();
                            List<File> list = new ArrayList<File>();
                            FileUtil.searchFileMatchs(file, ".*\\.properties", list);
                            for (File f : list) {
                                File_ ff = new File_();
                                ff.file = f;
                                model.addElement(ff);
                            }
                            backupFileList = list;
                            fileList.setModel(model);
                        }
                    });
                }
                {
                    jMenuItem2 = new JMenuItem();
                    jMenu1.add(jMenuItem2);
                    jMenuItem2.setText("save");
                    jMenuItem2.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            System.out.println("jMenu3.actionPerformed, event=" + evt);
                            if (currentFile == null) {
                                return;
                            }
                            if (JCommonUtil._JOptionPane_showConfirmDialog_yesNoOption(
                                    "save to " + currentFile.getName(), "SAVE")) {
                                try {
                                    Properties prop = new Properties();
                                    // try {
                                    // prop.load(new
                                    // FileInputStream(currentFile));
                                    // } catch (Exception e) {
                                    // e.printStackTrace();
                                    // JCommonUtil.handleException(e);
                                    // return;
                                    // }
                                    loadModelToProperties(prop);
                                    prop.store(new FileOutputStream(currentFile), getTitle());
                                } catch (Exception e) {
                                    e.printStackTrace();
                                    JCommonUtil.handleException(e);
                                }
                            }
                        }
                    });
                }
                {
                    jMenuItem3 = new JMenuItem();
                    jMenu1.add(jMenuItem3);
                    jMenuItem3.setText("save to target");
                    jMenuItem3.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            File file = JFileChooserUtil.newInstance().selectFileOnly().showSaveDialog()
                                    .getApproveSelectedFile();
                            if (file == null) {
                                JCommonUtil._jOptionPane_showMessageDialog_error("file name is not correct!");
                                return;
                            }
                            if (!file.getName().contains(".properties")) {
                                file = new File(file.getParent(), file.getName() + ".properties");
                            }
                            try {
                                Properties prop = new Properties();
                                // try {
                                // prop.load(new
                                // FileInputStream(currentFile));
                                // } catch (Exception e) {
                                // e.printStackTrace();
                                // JCommonUtil.handleException(e);
                                // return;
                                // }
                                loadModelToProperties(prop);
                                prop.store(new FileOutputStream(file), getTitle());
                            } catch (Exception e) {
                                e.printStackTrace();
                                JCommonUtil.handleException(e);
                            }
                        }
                    });
                }
                {
                    jMenuItem4 = new JMenuItem();
                    jMenu1.add(jMenuItem4);
                    jMenuItem4.setText("save file(sorted)");
                    jMenuItem4.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            if (currentFile == null) {
                                return;
                            }
                            try {
                                BufferedReader reader = new BufferedReader(
                                        new InputStreamReader(new FileInputStream(currentFile)));
                                List<String> sortList = new ArrayList<String>();
                                for (String line = null; (line = reader.readLine()) != null;) {
                                    sortList.add(line);
                                }
                                reader.close();
                                Collections.sort(sortList);
                                StringBuilder sb = new StringBuilder();
                                for (String line : sortList) {
                                    sb.append(line + "\n");
                                }
                                FileUtil.saveToFile(currentFile, sb.toString(), "UTF8");
                            } catch (FileNotFoundException e) {
                                e.printStackTrace();
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                        }
                    });
                }
                {
                    jMenuItem5 = new JMenuItem();
                    jMenu1.add(jMenuItem5);
                    jMenuItem5.setText("");
                    jMenuItem5.addActionListener(new ActionListener() {
                        private void setMeaning(String meaning, int rowPos) {
                            propTable.getRowSorter().getModel().setValueAt(meaning, rowPos, 2);
                        }

                        private void setMeaningEn1(String english, int rowPos, List<String> errSb) {
                            EnglishTester_Diectory eng = new EnglishTester_Diectory();
                            try {
                                WordInfo wordInfo = eng.parseToWordInfo(english);
                                String meaning = getChs2Big5(wordInfo.getMeaning());
                                if (hasChinese(meaning)) {
                                    setMeaning(meaning, rowPos);
                                } else {
                                    setMeaningEn2(english, rowPos, errSb);
                                }
                            } catch (Exception e) {
                                errSb.add(english);
                                e.printStackTrace();
                            }
                        }

                        private void setMeaningEn2(String english, int rowPos, List<String> errSb) {
                            EnglishTester_Diectory2 eng2 = new EnglishTester_Diectory2();
                            try {
                                WordInfo2 wordInfo = eng2.parseToWordInfo(english);
                                String meaning = getChs2Big5(StringUtils.join(wordInfo.getMeaningList(), ";"));
                                setMeaning(meaning, rowPos);
                            } catch (Exception e) {
                                errSb.add(english);
                                e.printStackTrace();
                            }
                        }

                        private boolean hasChinese(String val) {
                            return new StringUtil_().getChineseWord(val, true).length() > 0;
                        }

                        private Properties loadFromMemoryBank() {
                            try {
                                Properties prop = new Properties();
                                File f1 = new File(
                                        "D:/gtu001_dropbox/Dropbox/Apps/gtu001_test/etc_config/EnglishSearchUI_MemoryBank.properties");
                                File f2 = new File(
                                        "e:/gtu001_dropbox/Dropbox/Apps/gtu001_test/etc_config/EnglishSearchUI_MemoryBank.properties");
                                for (File f : new File[] { f1, f2 }) {
                                    if (f.exists()) {
                                        HermannEbbinghaus_Memory memory = new HermannEbbinghaus_Memory();
                                        memory.init(f);
                                        List<MemData> memLst = memory.getAllMemData(true);
                                        for (MemData d : memLst) {
                                            prop.setProperty(d.getKey(), getChs2Big5(d.getRemark()));
                                        }
                                        break;
                                    }
                                }
                                return prop;
                            } catch (Exception ex) {
                                throw new RuntimeException(ex);
                            }
                        }

                        public void actionPerformed(ActionEvent evt) {
                            if (currentFile == null) {
                                return;
                            }

                            // Properties memoryProp = loadFromMemoryBank();
                            Properties memoryProp = new Properties();

                            List<String> errSb = new ArrayList<String>();
                            for (int row = 0; row < propTable.getModel().getRowCount(); row++) {
                                int rowPos = propTable.getRowSorter().convertRowIndexToModel(row);
                                String english = StringUtils.trimToEmpty(
                                        (String) propTable.getRowSorter().getModel().getValueAt(rowPos, 1))
                                        .toLowerCase();
                                String desc = (String) propTable.getRowSorter().getModel().getValueAt(rowPos,
                                        2);

                                if (memoryProp.containsKey(english)
                                        && StringUtils.isNotBlank(memoryProp.getProperty(english))) {
                                    setMeaning(memoryProp.getProperty(english), rowPos);
                                } else {
                                    if (StringUtils.isBlank(desc) || !hasChinese(desc)) {
                                        if (!english.contains(" ")) {
                                            setMeaningEn1(english, rowPos, errSb);
                                        } else {
                                            setMeaningEn2(english, rowPos, errSb);
                                        }
                                    }
                                }

                                if (StringUtils.trimToEmpty(desc).contains("?")) {
                                    setMeaning("", rowPos);
                                }
                            }
                            if (!errSb.isEmpty()) {
                                JCommonUtil._jOptionPane_showMessageDialog_error(":\n" + errSb);
                            }
                        }
                    });
                }

                {
                    JMenuItem jMenuItem6 = new JMenuItem();
                    jMenu1.add(jMenuItem6);
                    jMenuItem6.setText("");
                    jMenuItem6.addActionListener(new ActionListener() {
                        private void setMeaning(String meaning, int rowPos) {
                            propTable.getRowSorter().getModel().setValueAt(meaning, rowPos, 2);
                        }

                        public void actionPerformed(ActionEvent evt) {
                            for (int row = 0; row < propTable.getModel().getRowCount(); row++) {
                                int rowPos = propTable.getRowSorter().convertRowIndexToModel(row);
                                String english = StringUtils.trimToEmpty(
                                        (String) propTable.getRowSorter().getModel().getValueAt(rowPos, 1))
                                        .toLowerCase();
                                String desc = (String) propTable.getRowSorter().getModel().getValueAt(rowPos,
                                        2);

                                if (StringUtils.trimToEmpty(desc).contains("?")) {
                                    setMeaning("", rowPos);
                                }
                            }
                        }
                    });
                }
            }
        }
        {
            jTabbedPane1 = new JTabbedPane();
            getContentPane().add(jTabbedPane1, BorderLayout.CENTER);
            {
                jPanel2 = new JPanel();
                BorderLayout jPanel2Layout = new BorderLayout();
                jPanel2.setLayout(jPanel2Layout);
                jTabbedPane1.addTab("editor", null, jPanel2, null);
                {
                    jScrollPane1 = new JScrollPane();
                    jPanel2.add(jScrollPane1, BorderLayout.CENTER);
                    jScrollPane1.setPreferredSize(new java.awt.Dimension(550, 314));
                    {
                        TableModel propTableModel = new DefaultTableModel(
                                new String[][] { { "", "", "" }, { "", "", "" } },
                                new String[] { "index", "Key", "value" });
                        propTable = new JTable();
                        JTableUtil.defaultSetting_AutoResize(propTable);
                        jScrollPane1.setViewportView(propTable);
                        propTable.setModel(propTableModel);
                        propTable.addMouseListener(new MouseAdapter() {
                            public void mouseClicked(MouseEvent evt) {
                                JTableUtil xxxxxx = JTableUtil.newInstance(propTable);
                                int[] rows = xxxxxx.getSelectedRows();
                                for (int ii : rows) {
                                    System.out.println(xxxxxx.getModel().getValueAt(ii, 1));
                                }
                                JPopupMenuUtil.newInstance(propTable).applyEvent(evt)
                                        .addJMenuItem(JTableUtil.newInstance(propTable).getDefaultJMenuItems())
                                        .show();
                            }
                        });
                    }
                }
                {
                    queryText = new JTextField();
                    jPanel2.add(queryText, BorderLayout.NORTH);
                    queryText.getDocument()
                            .addDocumentListener(JCommonUtil.getDocumentListener(new HandleDocumentEvent() {

                                @Override
                                public void process(DocumentEvent event) {
                                    if (currentFile == null) {
                                        return;
                                    }
                                    Properties prop = new Properties();
                                    try {
                                        prop.load(new FileInputStream(currentFile));
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                        JCommonUtil.handleException(e);
                                        return;
                                    }
                                    loadPropertiesToModel(prop);
                                    String text = JCommonUtil.getDocumentText(event);
                                    Pattern pattern = null;
                                    try {
                                        pattern = Pattern.compile(text);
                                    } catch (Exception ex) {
                                    }

                                    DefaultTableModel model = JTableUtil.newInstance(propTable).getModel();
                                    for (int ii = 0; ii < model.getRowCount(); ii++) {
                                        String key = (String) model.getValueAt(ii, 1);
                                        String value = (String) model.getValueAt(ii, 2);
                                        if (key.contains(text)) {
                                            continue;
                                        }
                                        if (value.contains(text)) {
                                            continue;
                                        }
                                        if (pattern != null) {
                                            if (pattern.matcher(key).find()) {
                                                continue;
                                            }
                                            if (pattern.matcher(value).find()) {
                                                continue;
                                            }
                                        }
                                        model.removeRow(propTable.convertRowIndexToModel(ii));
                                        ii--;
                                    }
                                }
                            }));
                }
            }
            {
                jPanel3 = new JPanel();
                BorderLayout jPanel3Layout = new BorderLayout();
                jPanel3.setLayout(jPanel3Layout);
                jTabbedPane1.addTab("folder", null, jPanel3, null);
                {
                    jScrollPane2 = new JScrollPane();
                    jPanel3.add(jScrollPane2, BorderLayout.CENTER);
                    jScrollPane2.setPreferredSize(new java.awt.Dimension(550, 314));
                    {
                        fileList = new JList();
                        jScrollPane2.setViewportView(fileList);
                        fileList.addKeyListener(new KeyAdapter() {
                            public void keyPressed(KeyEvent evt) {
                                JListUtil.newInstance(fileList).defaultJListKeyPressed(evt);
                            }
                        });
                        fileList.addMouseListener(new MouseAdapter() {
                            public void mouseClicked(MouseEvent evt) {
                                final File_ file = JListUtil.getLeadSelectionObject(fileList);

                                if (evt.getButton() == MouseEvent.BUTTON1) {
                                    Properties prop = new Properties();
                                    currentFile = file.file;
                                    setTitle(currentFile.getName());
                                    try {
                                        prop.load(new FileInputStream(file.file));
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }
                                    loadPropertiesToModel(prop);
                                }

                                if (evt.getButton() == MouseEvent.BUTTON1 && evt.getClickCount() == 2) {
                                    try {
                                        Runtime.getRuntime().exec(String.format("cmd /c \"%s\"", file.file));
                                    } catch (IOException e1) {
                                        e1.printStackTrace();
                                    }
                                }

                                final File parent = file.file.getParentFile();
                                JMenuItem openTargetDir = new JMenuItem();
                                openTargetDir.setText("open : " + parent);
                                openTargetDir.addActionListener(new ActionListener() {
                                    @Override
                                    public void actionPerformed(ActionEvent e) {
                                        try {
                                            Desktop.getDesktop().open(parent);
                                        } catch (IOException e1) {
                                            JCommonUtil.handleException(e1);
                                        }
                                    }
                                });

                                JPopupMenuUtil.newInstance(fileList).addJMenuItem(openTargetDir).applyEvent(evt)
                                        .show();
                            }
                        });
                    }
                }
                {
                    fileQueryText = new JTextField();
                    jPanel3.add(fileQueryText, BorderLayout.NORTH);
                    fileQueryText.getDocument()
                            .addDocumentListener(JCommonUtil.getDocumentListener(new HandleDocumentEvent() {
                                @Override
                                public void process(DocumentEvent event) {
                                    String text = JCommonUtil.getDocumentText(event);
                                    DefaultListModel model = new DefaultListModel();
                                    for (File f : backupFileList) {
                                        if (f.getName().contains(text)) {
                                            File_ ff = new File_();
                                            ff.file = f;
                                            model.addElement(ff);
                                        }
                                    }
                                    fileList.setModel(model);
                                }
                            }));
                }
                {
                    contentQueryText = new JTextField();
                    jPanel3.add(contentQueryText, BorderLayout.SOUTH);
                    contentQueryText.addActionListener(new ActionListener() {

                        void addModel(File f, DefaultListModel model) {
                            File_ ff = new File_();
                            ff.file = f;
                            model.addElement(ff);
                        }

                        public void actionPerformed(ActionEvent evt) {
                            DefaultListModel model = new DefaultListModel();
                            String text = contentQueryText.getText();
                            if (StringUtils.isEmpty(contentQueryText.getText())) {
                                return;
                            }
                            Pattern pattern = Pattern.compile(text);
                            Properties pp = null;
                            for (File f : backupFileList) {
                                pp = new Properties();
                                try {
                                    pp.load(new FileInputStream(f));
                                    for (String key : pp.stringPropertyNames()) {
                                        if (key.isEmpty()) {
                                            continue;
                                        }
                                        if (pp.getProperty(key) == null || pp.getProperty(key).isEmpty()) {
                                            continue;
                                        }
                                        if (key.contains(text)) {
                                            addModel(f, model);
                                            break;
                                        }
                                        if (pp.getProperty(key).contains(text)) {
                                            addModel(f, model);
                                            break;
                                        }
                                        if (pattern.matcher(key).find()) {
                                            addModel(f, model);
                                            break;
                                        }
                                        if (pattern.matcher(pp.getProperty(key)).find()) {
                                            addModel(f, model);
                                            break;
                                        }
                                    }
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                            }
                            fileList.setModel(model);
                        }
                    });
                }
            }
        }
        JCommonUtil.setJFrameIcon(this, "resource/images/ico/english.ico");
        JCommonUtil.setJFrameCenter(this);
        pack();
        this.setSize(571, 408);

        loadCurrentFile(null);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.georchestra.security.Proxy.java

public void init() throws Exception {
    if (targets != null) {
        for (String url : targets.values()) {
            new URL(url); // test that it is a valid URL
        }//from   w w w  . ja v a 2 s .co  m
    }
    if (proxyPermissionsFile != null) {
        Closer closer = Closer.create();
        try {
            final ClassLoader classLoader = Proxy.class.getClassLoader();
            InputStream inStream = closer.register(classLoader.getResourceAsStream(proxyPermissionsFile));
            Map<String, Class<?>> aliases = Maps.newHashMap();
            aliases.put(Permissions.class.getSimpleName().toLowerCase(), Permissions.class);
            aliases.put(UriMatcher.class.getSimpleName().toLowerCase(), UriMatcher.class);
            XStreamMarshaller unmarshaller = new XStreamMarshaller();
            unmarshaller.setAliasesByType(aliases);
            setProxyPermissions((Permissions) unmarshaller.unmarshal(new StreamSource(inStream)));
        } finally {
            closer.close();
        }
    }
    // georchestra datadir autoconfiguration
    // dependency injection / properties setter() are made by Spring before
    // init() call
    if ((georchestraConfiguration != null) && (georchestraConfiguration.activated())) {
        logger.info("geOrchestra configuration detected, reconfiguration in progress ...");

        Properties pTargets = georchestraConfiguration.loadCustomPropertiesFile("targets-mapping");

        targets.clear();
        for (String target : pTargets.stringPropertyNames()) {
            targets.put(target, pTargets.getProperty(target));
        }
        logger.info("Done.");
    }
}

From source file:org.finra.dm.service.helper.DefaultSqsMessageBuilder.java

/**
 * Gets an incoming message value map from a message payload.
 *
 * @param payload the incoming message payload.
 * @param configurationValue the configuration value for the XPath expression properties.
 *
 * @return the incoming message value map.
 *///from   w w  w .j  a  v a2s. c om
private Map<String, Object> getIncomingMessageValueMap(String payload, ConfigurationValue configurationValue) {
    // This method is generic and could be placed in a generic helper, but since it's use is limited to only getting values from an incoming message
    // to produce an outgoing message, it is fine in this class.

    Properties xpathProperties;
    try {
        String xpathPropertiesString = configurationHelper.getProperty(configurationValue);
        xpathProperties = javaPropertiesHelper.getProperties(xpathPropertiesString);
    } catch (Exception e) {
        throw new IllegalStateException("Unable to load XPath properties from configuration with key '"
                + configurationValue.getKey() + "'", e);
    }

    // Create a map that will house keys that map to values retrieved from the incoming message via the XPath expressions.
    Map<String, Object> incomingMessageValuesMap = new HashMap<>();

    // Evaluate all the XPath expressions on the incoming message and store the results in the map.
    // If validation is desired, an XPath expression can be used to verify that the incoming message contains a valid path in the payload.
    // If no XPath expressions are used, then it is assumed that the message is valid and the message will be processed
    // with no incoming values.
    Document document;
    try {
        document = documentBuilder.parse(new InputSource(new StringReader(payload)));
    } catch (Exception e) {
        throw new IllegalArgumentException("Payload is not valid XML:\n" + payload, e);
    }

    for (String key : xpathProperties.stringPropertyNames()) {
        // Get the XPath expression.
        String xpathExpression = xpathProperties.getProperty(key);
        try {
            // Evaluate the expression and store the result in the map keyed by the XPath expression key.
            // A document is required here as opposed to an input source since an input source yields a bug when the input XML contains a namespace.
            incomingMessageValuesMap.put(key, xpath.evaluate(xpathExpression, document));
        } catch (Exception ex) {
            // If any XPath expressions couldn't be evaluated against the incoming payload, throw an exception.
            // If the caller is the incoming JMS processing logic, it will log a debug message because it doesn't know which message it is
            // processing. If this exception is thrown, it assumes the incoming message isn't the one it is processing and moves on to the next message
            // processing routine for a different incoming message.
            // If the XPath expression configured is incorrect (i.e. an internal server error), then the incoming JMS processing logic will eventually
            // find no successful handler and will log an error which can be looked into further. That debug message would then be useful.
            throw new IllegalStateException("XPath expression \"" + xpathExpression
                    + "\" could not be evaluated against payload \"" + payload + "\".", ex);
        }
    }

    return incomingMessageValuesMap;
}

From source file:net.nicholaswilliams.java.licensing.licensor.interfaces.cli.ConsoleLicenseGenerator.java

public Map<String, Long> getLicenseFeatures(Properties properties) {
    Map<String, Long> map = new HashMap<String, Long>();

    if (properties == null) {
        String featureName = this
                .promptForString("Optionally enter the name/key of a feature you want to add to "
                        + "this license (you can leave this blank): ");

        while (featureName != null) {
            long expiration = this
                    .parseDate(this.promptForString("Optionally enter an expiration date for feature ["
                            + featureName + "] (YYYY-MM-DD hh:mm:ss or blank): "));

            map.put(featureName, expiration);

            featureName = this.promptForString(
                    "Enter another feature to add to this license (you can leave " + "this blank): ");
        }//from w w w.  j a v  a  2  s . c  o  m
    } else {
        for (String key : properties.stringPropertyNames()) {
            if (key.startsWith(ConsoleLicenseGenerator.PROPERTY_LICENSE_FEATURE_PREFIX)) {
                String featureName = key.replace(ConsoleLicenseGenerator.PROPERTY_LICENSE_FEATURE_PREFIX, "");

                long expiration = this.parseDate(properties.getProperty(key));

                map.put(featureName, expiration);
            }
        }
    }

    return map;
}

From source file:org.apache.ambari.server.configuration.Configuration.java

public Map<String, String> getAmbariProperties() {

    Properties properties = readConfigFile();
    Map<String, String> ambariPropertiesMap = new HashMap<String, String>();

    for (String key : properties.stringPropertyNames()) {
        ambariPropertiesMap.put(key, properties.getProperty(key));
    }//from  w w  w .  j a v a2 s .co m
    return ambariPropertiesMap;
}

From source file:pl.project13.maven.git.GitCommitIdMojo.java

private void filterNot(Properties properties, @Nullable List<String> exclusions) {
    if (exclusions == null || exclusions.isEmpty()) {
        return;/* w  w  w. j  a  va 2s  .c  o  m*/
    }

    List<Predicate<CharSequence>> excludePredicates = Lists.transform(exclusions,
            new Function<String, Predicate<CharSequence>>() {
                @Override
                public Predicate<CharSequence> apply(String exclude) {
                    return Predicates.containsPattern(exclude);
                }
            });

    Predicate<CharSequence> shouldExclude = Predicates.alwaysFalse();
    for (Predicate<CharSequence> predicate : excludePredicates) {
        shouldExclude = Predicates.or(shouldExclude, predicate);
    }

    for (String key : properties.stringPropertyNames()) {
        if (shouldExclude.apply(key)) {
            log.debug("shouldExclude.apply({}) = {}", key, shouldExclude.apply(key));
            properties.remove(key);
        }
    }
}

From source file:pl.project13.maven.git.GitCommitIdMojo.java

private void filter(Properties properties, @Nullable List<String> inclusions) {
    if (inclusions == null || inclusions.isEmpty()) {
        return;/*from   w  w  w .j  a va2s.com*/
    }

    List<Predicate<CharSequence>> includePredicates = Lists.transform(inclusions,
            new Function<String, Predicate<CharSequence>>() {
                @Override
                public Predicate<CharSequence> apply(String exclude) {
                    return Predicates.containsPattern(exclude);
                }
            });

    Predicate<CharSequence> shouldInclude = Predicates.alwaysFalse();
    for (Predicate<CharSequence> predicate : includePredicates) {
        shouldInclude = Predicates.or(shouldInclude, predicate);
    }

    for (String key : properties.stringPropertyNames()) {
        if (!shouldInclude.apply(key)) {
            log.debug("!shouldInclude.apply({}) = {}", key, shouldInclude.apply(key));
            properties.remove(key);
        }
    }
}

From source file:org.apache.nifi.minifi.bootstrap.util.ConfigTransformerTest.java

@Test
public void testNifiPropertiesNoOverrides()
        throws IOException, ConfigurationChangeException, SchemaLoaderException {
    Properties pre216Properties = new Properties();
    try (InputStream pre216PropertiesStream = ConfigTransformerTest.class.getClassLoader()
            .getResourceAsStream("MINIFI-216/nifi.properties.before")) {
        pre216Properties.load(pre216PropertiesStream);
    }//  w ww .j av a 2 s  .c  o m
    pre216Properties.setProperty(ConfigTransformer.NIFI_VERSION_KEY, ConfigTransformer.NIFI_VERSION);

    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    try (InputStream configStream = ConfigTransformerTest.class.getClassLoader()
            .getResourceAsStream("MINIFI-216/config.yml")) {
        ConfigTransformer.writeNiFiProperties(SchemaLoader.loadConfigSchemaFromYaml(configStream),
                outputStream);
    }
    Properties properties = new Properties();
    properties.load(new ByteArrayInputStream(outputStream.toByteArray()));

    for (String name : pre216Properties.stringPropertyNames()) {
        assertEquals("Property key " + name + " doesn't match.", pre216Properties.getProperty(name),
                properties.getProperty(name));
    }
}

From source file:org.rhq.enterprise.server.core.CoreServer.java

public ProductInfo getProductInfo() {
    ClassLoader classLoader = this.getClass().getClassLoader();
    InputStream inputStream = classLoader.getResourceAsStream(PRODUCT_INFO_PROPERTIES_RESOURCE_PATH);
    if (inputStream != null) {
        Properties props = new Properties();
        try {/*from   ww  w  . j a v  a2 s. c o m*/
            try {
                props.load(inputStream);
            } finally {
                inputStream.close();
            }
        } catch (IOException e) {
            throw new IllegalStateException(
                    "Failed to load product info properties from class loader resource ["
                            + PRODUCT_INFO_PROPERTIES_RESOURCE_PATH + "].");
        }
        ProductInfo productInfo = new ProductInfo();
        // TODO: Using reflection below might be nicer.
        productInfo.setBuildNumber(props.getProperty("buildNumber"));
        productInfo.setFullName(props.getProperty("fullName"));
        productInfo.setHelpDocRoot(props.getProperty("helpDocRoot"));
        productInfo.setName(props.getProperty("name"));
        productInfo.setSalesEmail(props.getProperty("salesEmail"));
        productInfo.setShortName(props.getProperty("shortName"));
        productInfo.setSupportEmail(props.getProperty("supportEmail"));
        productInfo.setUrlDomain(props.getProperty("urlDomain"));
        productInfo.setUrl(props.getProperty("url"));
        productInfo.setVersion(props.getProperty("version"));

        HashMap<String, String> helpViewContent = new HashMap<String, String>();

        for (String propertyName : props.stringPropertyNames()) {
            if (propertyName.startsWith("view_help_section")) {
                helpViewContent.put(propertyName, props.getProperty(propertyName));
            }
        }

        productInfo.setHelpViewContent(helpViewContent);

        return productInfo;
    } else {
        throw new IllegalStateException(
                "Failed to find class loader resource [" + PRODUCT_INFO_PROPERTIES_RESOURCE_PATH + "].");
    }
}