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.liferay.portal.security.ldap.internal.exportimport.LDAPUserImporterImpl.java

protected void populateExpandoAttributes(ExpandoBridge expandoBridge, Map<String, String[]> expandoAttributes,
        Properties expandoMappings, Set<String> ldapUserIgnoreAttributes) {

    Map<String, Serializable> serializedExpandoAttributes = new HashMap<>();

    for (Map.Entry<String, String[]> expandoAttribute : expandoAttributes.entrySet()) {

        String name = expandoAttribute.getKey();

        if (!expandoBridge.hasAttribute(name)) {
            continue;
        }//ww  w.  j  a va2s .  c  o m

        if (expandoMappings.containsKey(name) && !ldapUserIgnoreAttributes.contains(name)) {

            int type = expandoBridge.getAttributeType(name);

            Serializable value = ExpandoConverterUtil.getAttributeFromStringArray(type,
                    expandoAttribute.getValue());

            serializedExpandoAttributes.put(name, value);
        }
    }

    if (serializedExpandoAttributes.isEmpty()) {
        return;
    }

    try {
        _expandoValueLocalService.addValues(expandoBridge.getCompanyId(), expandoBridge.getClassName(),
                ExpandoTableConstants.DEFAULT_TABLE_NAME, expandoBridge.getClassPK(),
                serializedExpandoAttributes);
    } catch (Exception e) {
        if (_log.isWarnEnabled()) {
            _log.warn("Unable to populate expando attributes");
        }

        if (_log.isDebugEnabled()) {
            _log.debug(e, e);
        }
    }
}

From source file:org.alfresco.reporting.processor.PropertyProcessor.java

/**
 * Validate if the unique sum of properties exists in the table definition.
 * Update the table definition if columns are not yet defined
 * @param props unique set of columns and their type
 * @throws Exception /*w ww  . ja va 2  s  . com*/
 */
public void setTableDefinition(final String tableName, Properties props) throws Exception {
    if (logger.isDebugEnabled())
        logger.debug("Enter setTableDefinition tableName=" + tableName + " with props=" + props);
    // get the existing table definition

    try {
        //props = reportingHelper.propertyKeyToLowerCase(props);   

        Properties tableDesc = dbhb.getTableDescription(tableName);

        if (logger.isDebugEnabled()) {
            propertyLogger("## Object properties", props);
            propertyLogger("## Table description", tableDesc);
        }

        // check if our properties are defined or not
        Enumeration<Object> keys = props.keys();
        while (keys.hasMoreElements()) {
            String key = (String) keys.nextElement();
            String type = props.getProperty(key, "-");
            // compare the key in lower-case. tableDesc contains lower case, 
            // key should too... Otherwise we happen to run into not-created issues against columns
            if (logger.isDebugEnabled())
                logger.debug("## COMPARE: key=" + key);
            if (tableDesc.containsKey(key /*.toLowerCase() */) || tableDesc.containsKey(key.toUpperCase()) || // Oracle sucks, Oracle sucks
                    tableDesc.containsKey(key.toLowerCase())) { // Oracle sucks, Oracle sucks
                // column exists... do nothing
                if (logger.isDebugEnabled())
                    logger.debug("DEFINITION Column " + key + " already exists.");
            } else {
                // column does NOT exist, accordingly.
                // if type is known, alter/extend the table 
                if (!"-".equals(type) && !"".equals(type)) {
                    if (logger.isDebugEnabled())
                        logger.debug("DEFINITION Adding column: " + key + "=" + type);
                    dbhb.extendTable(tableName, key, type);
                } else {
                    if (logger.isDebugEnabled())
                        logger.debug("DEFINITION Column " + key + " is empty. Type=" + type);
                }
            }
        } // end while
    } catch (Exception e) {
        logger.fatal("Exception setTableDefinition: " + e.getMessage());
        throw new Exception(e);
    }
    logger.debug("Exit setTableDefinition");
}

From source file:org.obiba.mica.search.queries.VariableQuery.java

@NotNull
@Override/*  w  w  w .j  av  a2 s.co m*/
protected Properties getAggregationsProperties(List<String> filter) {
    Properties properties = new Properties();
    if (mode != QueryMode.LIST && filter != null && !filter.isEmpty()) {
        List<Pattern> patterns = filter.stream().map(Pattern::compile).collect(Collectors.toList());

        getOpalTaxonomies().stream().filter(Taxonomy::hasVocabularies).forEach(taxonomy -> taxonomy
                .getVocabularies().stream().filter(Vocabulary::hasTerms).forEach(vocabulary -> {
                    String field = vocabulary.getAttributes().containsKey("field")
                            ? vocabulary.getAttributeValue("field")
                            : "attributes." + AttributeKey.getMapKey(vocabulary.getName(), taxonomy.getName())
                                    + "." + LanguageTag.UNDETERMINED;
                    if (patterns.isEmpty() || patterns.stream().anyMatch(p -> p.matcher(field).find()))
                        properties.put(field, "");
                }));

        taxonomyService.getVariableTaxonomy().getVocabularies().forEach(vocabulary -> {
            String field = vocabulary.getAttributes().containsKey("field")
                    ? vocabulary.getAttributeValue("field")
                    : vocabulary.getName().replace('-', '.');
            if (patterns.isEmpty() || patterns.stream().anyMatch(p -> p.matcher(field).matches()))
                properties.put(field, "");
        });
    }

    // required for the counts to work
    if (!properties.containsKey(JOIN_FIELD))
        properties.put(JOIN_FIELD, "");
    if (!properties.containsKey(DATASET_ID))
        properties.put(DATASET_ID, "");

    return properties;
}

From source file:org.alfresco.reporting.ReportLine.java

public void setLine(final String key, final String sqltype, String value, final Properties replacementTypes) {

    // An Oracle column can be varchar(30) at max....
    //      if (logger.isDebugEnabled()
    //         logger.debug("setLine: entry: key=" + key + ", type="+ sqltype + ", value=" + value);

    if ((value == null) || value.equalsIgnoreCase("null") || value.equalsIgnoreCase("~~null~~")
            || key.equals("isLatest")) {
        logger.debug("setLine *************** NULL ****************");
        return; // do not process null values, they potentially fail
        //value="~~NULL~~";
    }/* w  ww  .  ja v  a2  s.  co m*/
    if ((key != null) && (sqltype != null)) {
        String myKey = key; // .toLowerCase();
        String mySqltype = sqltype.trim();
        value = value.trim();

        // truncate the name if needed depending on DB provider
        myKey = reportingHelper.getTableColumnNameTruncated(myKey);

        // if Oracle, replace key "size" by key "docsize"
        // size is a reserved word in Oracle...
        if (Constants.VENDOR_ORACLE.equals(vendor)) {

            if (myKey.equalsIgnoreCase(Constants.COLUMN_SIZE)) {
                myKey = Constants.COLUMN_SIZE_ORACLE.toLowerCase();
            }
        }

        //         if (logger.isDebugEnabled()         
        //            logger.debug("setLine: stuff not null type="+ mySqltype + ", value=" + value);

        // validate if the current definition is overridden...
        if (replacementTypes.containsKey(myKey)) {
            mySqltype = replacementTypes.getProperty(myKey, "-").trim();
        }

        //         if (logger.isDebugEnabled() 
        //            logger.debug("setLine: after replacement, sqltype="+mySqltype);

        if (mySqltype.toUpperCase().startsWith("VARCHAR")) {
            try {
                if (logger.isDebugEnabled()) {
                    //                  logger.debug("setLine: Inside VARCHAR " + mySqltype  + ", " + mySqltype.indexOf("("));
                    //                  logger.debug("setLine: Inside VARCHAR " + mySqltype  + ", " + (mySqltype.length()-1));
                }
                int length = Integer
                        .parseInt(mySqltype.substring(mySqltype.indexOf("(") + 1, mySqltype.length() - 1));
                if (value.length() > length) {
                    value = value.substring(0, length - 2);
                } else {
                    //logger.debug("setLine: length is fine...");
                }
            } catch (Exception e) {
                e.printStackTrace();
                logger.fatal("Error in processing VARCHAR!!");
                logger.fatal(e.getMessage());
            }
        }
        types.setProperty(myKey, mySqltype);
        values.setProperty(myKey, value);
    }
    //      if (logger.isDebugEnabled()
    //         logger.debug("setLine: exit: Type=" + sqltype + ", value=" + value);
}

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

private void initGUI() {
    try {//  w ww. ja va2  s .  c  o  m
        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:fr.fastconnect.factory.tibco.bw.maven.packaging.ApplicationManagement.java

/**
 * <p>//from   w ww . j  av  a 2 s  .  c om
 * This will remove from the XML the default binding (with empty name
 * attribute) if it is not found in the properties.
 * </p>
 */
public void removeDefaultBindingIfNotExists(Properties properties) {
    List<Bw> bwServices = this.getBWServices();

    for (Bw bw : bwServices) {
        String path = "bw[" + bw.getName() + "]/bindings/binding[]/machine";

        List<Binding> bindings = bw.getBindings().getBinding();
        for (Iterator<Binding> iterator = bindings.iterator(); iterator.hasNext();) {
            Binding binding = (Binding) iterator.next();
            //            if (binding.getName().equals("") && properties.getString(path) == null) {
            if (binding.getName().equals("") && !properties.containsKey(path)) {
                iterator.remove();
            }
        }
    }

    List<Adapter> adapterServices = this.getAdapterServices();

    for (Adapter adapter : adapterServices) {
        String path = "adapter[" + adapter.getName() + "]/bindings/binding[]/machine";

        List<Binding> bindings = adapter.getBindings().getBinding();
        for (Iterator<Binding> iterator = bindings.iterator(); iterator.hasNext();) {
            Binding binding = (Binding) iterator.next();
            //            if (binding.getName().equals("") && properties.getString(path) == null) {
            if (binding.getName().equals("") && !properties.containsKey(path)) {
                iterator.remove();
            }
        }
    }
}

From source file:org.alfresco.reporting.action.executer.ReportContainerExecuter.java

private void processReport(final ReportTemplate report, final ReportingContainer reportingContainer,
        final ReportingRoot reportingRoot) {
    Properties keyValues = new Properties();

    if (logger.isDebugEnabled())
        logger.debug("enter processReport, report=" + report.getName());
    String targetPath = report.getTargetPath();
    Properties targetQueries = reportingRoot.getTargetQueries();

    // 1. Determine/get/create target Path
    // Lets see if there is a relative distribution by Site
    if (targetPath != null) {
        targetPath = targetPath.trim();//from ww  w. j ava2 s.  co  m
        if ((targetPath.indexOf("${") == 0) && (targetPath.indexOf("}") > -1)) {
            // 1a. it is a distribution by Site or other placeholder
            if (logger.isDebugEnabled())
                logger.debug("processReportable: it is a distribution by container");

            // get the target container query key
            String placeHolder = targetPath.substring(2, targetPath.indexOf("}"));
            String relativePath = targetPath.substring(targetPath.indexOf("}") + 1);

            relativePath = processDateElementsInPath(relativePath);

            if (logger.isDebugEnabled()) {
                logger.debug("  placeholder:   " + placeHolder);
                logger.debug("  relative path: " + relativePath);
            }

            if (placeHolder != null) {

                if (targetQueries.containsKey(placeHolder)) {
                    // execute Lucene query. For each result find node.
                    // For each node, append relative path
                    // get or create this path
                    // execute ReportExecuter against each of these end
                    // nodes (in proper output format)
                    if (logger.isDebugEnabled())
                        logger.debug("processReport: Processing with placeholder: " + placeHolder);
                    String placeHolderQuery = targetQueries.getProperty(placeHolder);
                    String searchLanguage = reportingHelper
                            .getSearchLanguage(reportingRoot.getRootQueryLanguage());

                    if (logger.isDebugEnabled())
                        logger.debug("processReport: query2=" + placeHolderQuery + "(" + searchLanguage + ")");

                    ResultSet placeHolderResults = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE,
                            searchLanguage, placeHolderQuery);

                    // cycle the resultset of containers
                    for (ResultSetRow placeHolderRow : placeHolderResults) {
                        final NodeRef targetRootRef = placeHolderRow.getChildAssocRef().getChildRef();

                        if (logger.isDebugEnabled())
                            logger.debug("Found targetRoot: "
                                    + nodeService.getProperty(targetRootRef, ContentModel.PROP_NAME));

                        // Introduce a storageNodeRef. This is used if you
                        // do a query against
                        // persons. The resulting report will be stored in
                        // the UserHome space.
                        // The value substitution will however be executed
                        // against the Person object.
                        NodeRef storageNodeRef = targetRootRef;
                        if (logger.isDebugEnabled())
                            logger.debug("processReport: storageNodeRef before=" + storageNodeRef);

                        try {
                            // if a Person object is found, replace it by
                            // its HomeFolder. For the best fun!
                            if (nodeService.getType(targetRootRef).equals(ContentModel.TYPE_PERSON)) {
                                if (logger.isDebugEnabled())
                                    logger.debug("processReport: The value=" + nodeService
                                            .getProperty(targetRootRef, ContentModel.PROP_HOMEFOLDER));

                                if (nodeService.getProperty(targetRootRef,
                                        ContentModel.PROP_HOMEFOLDER) != null) {
                                    if (logger.isDebugEnabled())
                                        logger.debug(
                                                "processReport: createGetRepositoryPath: SWAPPING Person for UserHome");
                                    storageNodeRef = (NodeRef) nodeService.getProperty(targetRootRef,
                                            ContentModel.PROP_HOMEFOLDER);
                                    if (logger.isDebugEnabled())
                                        logger.debug(
                                                "processReport: createGetRepositoryPath: storageNodeRef after swap="
                                                        + storageNodeRef);
                                } else {
                                    if (logger.isDebugEnabled())
                                        logger.debug(
                                                "processReport: createGetRepositoryPath: ow boy, no UserHome available for user "
                                                        + nodeService.getProperty(targetRootRef,
                                                                ContentModel.PROP_USERNAME));
                                    throw new ReportingException("No UserHome found for user " + nodeService
                                            .getProperty(targetRootRef, ContentModel.PROP_USERNAME));
                                }
                            } else {
                                if (logger.isDebugEnabled())
                                    logger.debug("createGetRepositoryPath: no SWAPPING");
                            }
                        } catch (ReportingException re) {
                            logger.fatal("processReport: User without a UserHome... Silent ignore");
                        }
                        if (logger.isDebugEnabled())
                            logger.debug(
                                    "processReport: processReportstorageNodeRef fully after=" + storageNodeRef);

                        // keyValues now contains the keys and the related
                        // short-form qnames
                        keyValues = report.getSubstitution();

                        if (logger.isDebugEnabled())
                            logger.debug("processReport: initial keyValues = " + keyValues);

                        // process of *replacing* the short-form qnames into
                        // actual
                        // node-property values
                        Enumeration keys = keyValues.keys();
                        while (keys.hasMoreElements()) {
                            final String key = (String) keys.nextElement();
                            final String value = keyValues.getProperty(key, "");
                            if (logger.isDebugEnabled())
                                logger.debug("Initial key=value; " + key + "=" + value);

                            if (value.contains(":") && !"".equals(value)) {
                                // system property
                                final QName property = reportingHelper.replaceShortQNameIntoLong(value);
                                if (logger.isDebugEnabled()) {
                                    logger.debug("processReport: QName=" + property);
                                    logger.debug("processReport: key=" + key + " value="
                                            + nodeService.getProperty(targetRootRef, property));
                                }

                                final String propertyValue = nodeService.getProperty(targetRootRef, property)
                                        .toString();
                                if (logger.isDebugEnabled())
                                    logger.debug("processReport: propertyValue=" + propertyValue);
                                keyValues.setProperty(key, propertyValue);
                            } else {
                                // ordinary property
                                keyValues.setProperty(key, value);
                                if (logger.isDebugEnabled())
                                    logger.debug("processReport: key=" + key + " value=" + value
                                            + " targetRootRef=" + targetRootRef);
                            } // end if/else
                        } // end while
                        if (logger.isDebugEnabled())
                            logger.debug("processReport: final keyValues = " + keyValues);

                        final NodeRef targetRef = createGetRepositoryPath(storageNodeRef, relativePath);
                        if (logger.isDebugEnabled()) {
                            logger.debug("processReport: Found full path: " + nodeService.getPath(targetRef));
                            logger.debug("processReport: keyValues = " + keyValues);
                        }
                        createExecuteReport(targetRef, report, keyValues);

                    } // end for ResultSetRow

                } else {
                    // we cannot deal with this unknown placeholder.
                    // silently let go?!
                    logger.warn("Cannot deal with placeholder: " + placeHolder);

                } // end if/else targetQueries.containsKey
            } // end if matcher.find

        } else {
            // 1b. it is a single fixed path. Start at companyhome, and find
            // your way in
            // NodeRef targetRef = createGetRepositoryPath(targetRootRef,
            // relativePath);

            // execute ReportExecuter against each of these end nodes (in
            // proper output format)

        }
    } // end if targetPath !=null

    if ((report.getTargetNode() != null) && (!"".equals(report.getTargetNode()))) {
        NodeRef newTarget = null;
        // create option to concatinate targetPath to targetNode
        if ((report.getTargetPath() != null) && (!"".equals(report.getTargetPath()))) {
            final String relativePath = processDateElementsInPath(report.getTargetPath());
            newTarget = createGetRepositoryPath(report.getTargetNode(), relativePath);
        } else {
            newTarget = report.getTargetNode();
        }
        if (logger.isDebugEnabled()) {
            logger.debug("executing fixed output path");
            logger.debug("  report    : " + report.getName());
            logger.debug("  targetNode: " + newTarget);
        }
        // keyValues now contains the keys and the related short-form qnames
        keyValues = report.getSubstitution();

        logger.debug("processReport: initial keyValues = " + keyValues);

        // process of replacing the short-form qnames into actual

        // node-property values
        Enumeration keys = keyValues.keys();
        while (keys.hasMoreElements()) {
            String key = (String) keys.nextElement();
            String value = keyValues.getProperty(key, "");

            // ordinary property
            keyValues.setProperty(key, value);
            logger.debug("processReport: key=" + key + " value=" + value);
        }
        logger.debug("processReport: final keyValues = " + keyValues);

        createExecuteReport(newTarget, report, keyValues);
    } // end if targetPath != null

    if (logger.isDebugEnabled())
        logger.debug("exit processReportable");
}

From source file:com.ibm.cics.ca1y.Emit.java

/**
 * Create a compiled pattern from the regex supplied in the properties, or a default.
 * /*from  w  w w.j a  v a  2  s  .  c  o m*/
 * @param props
 *            - the properties to find the regex in
 * @return compiled pattern
 */
private static Pattern getPattern(Properties props) {

    if (props.containsKey(TOKEN_REGEX)) {
        try {
            String regex = props.getProperty(TOKEN_REGEX);

            // Remove regex from properties to prevent it from being processed further
            props.remove(TOKEN_REGEX);

            return Pattern.compile(regex);

        } catch (Exception e) {
            logger.warning(messages.getString("InvalidRegex") + " " + TOKEN_REGEX_DEFAULT);
        }
    }

    return Pattern.compile(TOKEN_REGEX_DEFAULT);
}

From source file:dinistiq.Dinistiq.java

/**
 * Tries to resolve the value for a given placeholder.
 *
 * @param beanProperties properties of the beans to resolve the value for
 * @param dependencies global dependencies collector to store retrieved reference values as dependecy in
 * @param customer "customer" descriptor for logging who needed the value resolved
 * @param cls target class of the value/*from ww  w . ja  v  a2s. c o m*/
 * @param type target type of the value
 * @param name name of the placeholder
 * @return replaced value or original string
 * @throws Exception
 */
private Object getValue(Properties beanProperties, Map<String, Set<Object>> dependencies, String customer,
        Class<?> cls, Type type, final String name) throws Exception {
    ParameterizedType parameterizedType = (type instanceof ParameterizedType) ? (ParameterizedType) type : null;
    if ((name == null) && Collection.class.isAssignableFrom(cls)) {
        LOG.debug("getValue() collection: {}", type);
        if (parameterizedType != null) {
            Type collectionType = parameterizedType.getActualTypeArguments()[0];
            LOG.debug("getValue() inner type {}", collectionType);
            Collection<? extends Object> resultCollection = findBeans((Class<? extends Object>) collectionType);
            resultCollection = List.class.isAssignableFrom(cls) ? new ArrayList<>(resultCollection)
                    : resultCollection;
            if (dependencies != null) {
                dependencies.get(customer).addAll(resultCollection);
            } // if
            return resultCollection;
        } // if
    } // if
    Object bean = (name == null) ? findBean(cls)
            : (beanProperties.containsKey(name) ? getReferenceValue(beanProperties.getProperty(name))
                    : beans.get(name));
    if (Provider.class.equals(cls)) {
        final Dinistiq d = this;
        final Class<? extends Object> c = (Class<?>) parameterizedType.getActualTypeArguments()[0];
        LOG.info("getValue() Provider for {} :{}", name, c);
        bean = new Provider<Object>() {

            @Override
            public Object get() {
                return (name == null) ? d.findBean(c) : d.findBean(c, name);
            }

        };
        String beanName = "" + bean;
        if (dependencies != null) {
            dependencies.put(beanName, new HashSet<>());
        } // if
        beans.put(beanName, bean);
    } // if
    if (cls.isAssignableFrom(bean.getClass())) {
        if ((dependencies != null) && beans.containsValue(bean)) {
            dependencies.get(customer).add(bean);
        } // if
        return bean;
    } // if
    throw new Exception("for " + customer + ": no bean " + (name != null ? name + " :" : "of type ")
            + cls.getSimpleName() + " found.");
}

From source file:com.liferay.portal.security.ldap.internal.exportimport.LDAPUserImporterImpl.java

protected void updateLDAPUser(User ldapUser, Contact ldapContact, User user, Properties userMappings,
        Properties contactMappings, Set<String> ldapUserIgnoreAttributes) throws PortalException {

    Contact contact = user.getContact();

    for (String propertyName : _CONTACT_PROPERTY_NAMES) {
        String mappingPropertyName = propertyName;

        if (propertyName.equals("male")) {
            mappingPropertyName = ContactConverterKeys.GENDER;
        } else if (propertyName.equals("prefixId")) {
            mappingPropertyName = ContactConverterKeys.PREFIX;
        } else if (propertyName.equals("suffixId")) {
            mappingPropertyName = ContactConverterKeys.SUFFIX;
        }/*from www  .jav  a 2s .  c om*/

        if (!contactMappings.containsKey(mappingPropertyName)
                || ldapUserIgnoreAttributes.contains(propertyName)) {

            setProperty(ldapContact, contact, propertyName);
        }
    }

    for (String propertyName : _USER_PROPERTY_NAMES) {
        String mappingPropertyName = propertyName;

        if (propertyName.equals("portraitId")) {
            mappingPropertyName = UserConverterKeys.PORTRAIT;
        }

        if (!userMappings.containsKey(mappingPropertyName) || ldapUserIgnoreAttributes.contains(propertyName)) {

            setProperty(ldapUser, user, propertyName);
        }
    }
}