List of usage examples for java.util Properties keySet
@Override
public Set<Object> keySet()
From source file:de.tudarmstadt.ukp.dkpro.core.api.resources.ResourceObjectProviderBase.java
/** * Copy all properties that not already exist in target from source. *//*w w w.j a v a2 s. com*/ private void mergeProperties(Properties aTarget, Properties aSource) { for (Object key : aSource.keySet()) { if (!aTarget.containsKey(key)) { aTarget.put(key, aSource.get(key)); } } }
From source file:com.compomics.colims.client.controller.admin.FastaDbSaveUpdateController.java
@Override @PostConstruct//ww w . jav a 2 s.c om public void init() { //register to event bus eventBus.register(this); fastaDbSaveUpdatePanel = fastaDbManagementController.getFastaDbManagementDialog() .getFastaDbSaveUpdatePanel(); headerParseRuleAdditionDialog = new HeaderParseRuleAdditionDialog( fastaDbManagementController.getFastaDbManagementDialog(), true); taxonomyBindingList = ObservableCollections.observableList(new ArrayList<>()); taxonomyBindingList.add(TAXONOMY_CV_PARAM_NONE); taxonomyBindingList.addAll(cvParamService.findByCvParamByClass(TaxonomyCvParam.class)); //init binding bindingGroup = new BindingGroup(); JComboBoxBinding taxonomyComboBoxBinding = SwingBindings.createJComboBoxBinding( AutoBinding.UpdateStrategy.READ_WRITE, taxonomyBindingList, fastaDbSaveUpdatePanel.getTaxomomyComboBox()); bindingGroup.addBinding(taxonomyComboBoxBinding); headerParseRuleBindingList = ObservableCollections.observableList(new ArrayList<>()); try { config = PropertiesUtil.parsePropertiesFile("config/header-parse-rule.properties"); } catch (IOException | ConfigurationException ex) { java.util.logging.Logger.getLogger(FastaDbSaveUpdateController.class.getName()).log(Level.SEVERE, null, ex); } fillHeaderParseRuleComboBox(); JComboBoxBinding parseRuleComboBoxBinding = SwingBindings.createJComboBoxBinding( AutoBinding.UpdateStrategy.READ_WRITE, headerParseRuleBindingList, fastaDbSaveUpdatePanel.getHeaderParseRuleComboBox()); bindingGroup.addBinding(parseRuleComboBoxBinding); databaseBindingList = ObservableCollections.observableList(new ArrayList<>()); Properties allProperties = new Properties(); ClassLoader loader = Thread.currentThread().getContextClassLoader(); try { allProperties.load(loader.getResourceAsStream("config/embl-ebi-database.properties")); databaseSet = new TreeSet(allProperties.keySet()); } catch (IOException ex) { java.util.logging.Logger.getLogger(FastaDbSaveUpdateController.class.getName()).log(Level.SEVERE, null, ex); } fillDatabaseComboBox(); JComboBoxBinding databaseComboBoxBinding = SwingBindings.createJComboBoxBinding( AutoBinding.UpdateStrategy.READ_WRITE, databaseBindingList, fastaDbSaveUpdatePanel.getDatabaseComboBox()); bindingGroup.addBinding(databaseComboBoxBinding); bindingGroup.bind(); //init FASTA file selection //disable select multiple files fastaDbSaveUpdatePanel.getFastaFileChooser().setMultiSelectionEnabled(false); //set FASTA file filter fastaDbSaveUpdatePanel.getFastaFileChooser().setFileFilter(new FastaFileFilter()); //add listeners fastaDbSaveUpdatePanel.getBrowseTaxonomyButton().addActionListener(e -> { List<CvParam> cvParams = cvParamService.findByCvParamByClass(TaxonomyCvParam.class); //update the CV param list cvParamManagementController.updateDialog("FASTA DB taxonomy", TaxonomyCvParam.class, PRESELECTED_ONTOLOGY_NAMESPACES, cvParams); cvParamManagementController.showView(); }); fastaDbSaveUpdatePanel.getBrowseHeaderParseRuleButtton().addActionListener(l -> { headerParseRuleAdditionDialog.getParseRuleTextField().setText(""); headerParseRuleAdditionDialog.getDescriptionTextField().setText(""); GuiUtils.centerDialogOnComponent(fastaDbSaveUpdatePanel, headerParseRuleAdditionDialog); headerParseRuleAdditionDialog.setVisible(true); }); headerParseRuleAdditionDialog.getSaveParseRuleButton().addActionListener(l -> { try { config = PropertiesUtil.addProperty(config, headerParseRuleAdditionDialog.getDescriptionTextField().getText(), headerParseRuleAdditionDialog.getParseRuleTextField().getText()); } catch (ConfigurationException | IOException ex) { java.util.logging.Logger.getLogger(FastaDbSaveUpdateController.class.getName()).log(Level.SEVERE, null, ex); } fillHeaderParseRuleComboBox(); headerParseRuleAdditionDialog.dispose(); }); fastaDbSaveUpdatePanel.getBrowseFastaButton().addActionListener(e -> { //in response to the button click, show open dialog int returnVal = fastaDbSaveUpdatePanel.getFastaFileChooser().showOpenDialog(fastaDbSaveUpdatePanel); if (returnVal == JFileChooser.APPROVE_OPTION) { File fastaFile = fastaDbSaveUpdatePanel.getFastaFileChooser().getSelectedFile(); //show FASTA file name and path in textfields fastaDbSaveUpdatePanel.getFileNameTextField().setText(fastaFile.getName()); fastaDbSaveUpdatePanel.getFilePathTextField().setText(fastaFile.getAbsolutePath()); } }); fastaDbSaveUpdatePanel.getSaveOrUpdateButton().addActionListener(e -> { //validate FASTA DB updateFastaToEdit(); List<String> validationMessages = GuiUtils.validateEntity(fastaDbToEdit); if (validationMessages.isEmpty()) { if (fastaDbToEdit.getId() != null) { fastaDbToEdit = fastaDbService.merge(fastaDbToEdit); fastaDbManagementController.updateFastaDb(); } else { fastaDbService.persist(fastaDbToEdit); fastaDbManagementController.addFastaDb(fastaDbToEdit); } fastaDbSaveUpdatePanel.getNameTextField().setEnabled(false); fastaDbSaveUpdatePanel.getSaveOrUpdateButton().setText("update"); fastaDbSaveUpdatePanel.getFastaDbStateInfoLabel().setText(""); saveUpdate = true; MessageEvent messageEvent = new MessageEvent("Fasta DB store confirmation", "Fasta DB " + fastaDbToEdit.getName() + " was stored successfully!", JOptionPane.INFORMATION_MESSAGE); eventBus.post(messageEvent); fastaDbManagementController.showOverviewPanel(); } else { MessageEvent messageEvent = new MessageEvent("Validation failure", validationMessages, JOptionPane.WARNING_MESSAGE); eventBus.post(messageEvent); } }); fastaDbSaveUpdatePanel.getBackButton().addActionListener(e -> { if (!saveUpdate) { fastaDbManagementController.setSelectedFasta(-1); } saveUpdate = false; fastaDbManagementController.showOverviewPanel(); }); }
From source file:com.cyclopsgroup.waterview.servlet.WaterviewServlet.java
/** * Override method init in super class of MainServlet * * @see javax.servlet.Servlet#init(javax.servlet.ServletConfig) *//* w w w . ja v a 2s . c o m*/ public void init(ServletConfig config) throws ServletException { applicationBase = config.getInitParameter("application.base"); servletConfig = config; String basedir = config.getServletContext().getRealPath(""); Properties initProperties = new Properties(); initProperties.setProperty("basedir", basedir); initProperties.setProperty("plexus.home", basedir); Enumeration i = config.getInitParameterNames(); while (i.hasMoreElements()) { String key = (String) i.nextElement(); String value = config.getInitParameter(key); initProperties.setProperty(key, value); } try { container = new WaterviewPlexusContainer(); serviceManager = new ServiceManagerAdapter(container); for (Iterator j = initProperties.keySet().iterator(); j.hasNext();) { String initPropertyName = (String) j.next(); container.addContextValue(initPropertyName, initProperties.get(initPropertyName)); } container.addContextValue(Waterview.INIT_PROPERTIES, initProperties); container.initialize(); container.start(); } catch (Exception e) { container.getLogger().fatalError("Can not start container", e); } }
From source file:org.apache.lucene.benchmark.byTask.feeds.LineDocSourceTest.java
private void writeDocsToFile(BufferedWriter writer, boolean addHeader, Properties otherFields) throws IOException { if (addHeader) { writer.write(WriteLineDocTask.FIELDS_HEADER_INDICATOR); writer.write(WriteLineDocTask.SEP); writer.write(DocMaker.TITLE_FIELD); writer.write(WriteLineDocTask.SEP); writer.write(DocMaker.DATE_FIELD); writer.write(WriteLineDocTask.SEP); writer.write(DocMaker.BODY_FIELD); if (otherFields != null) { // additional field names in the header for (Object fn : otherFields.keySet()) { writer.write(WriteLineDocTask.SEP); writer.write(fn.toString()); }/*from w ww. j a v a 2s . co m*/ } writer.newLine(); } StringBuilder doc = new StringBuilder(); doc.append("title").append(WriteLineDocTask.SEP).append("date").append(WriteLineDocTask.SEP) .append(DocMaker.BODY_FIELD); if (otherFields != null) { // additional field values in the doc line for (Object fv : otherFields.values()) { doc.append(WriteLineDocTask.SEP).append(fv.toString()); } } writer.write(doc.toString()); writer.newLine(); }
From source file:com.intuit.tank.tools.debugger.ActionProducer.java
private static JComboBox getComboBox() { JComboBox cb = new JComboBox(); cb.setEditable(true);/*from ww w . j a v a2 s . c om*/ Properties props = new Properties(); File f = new File(DEBUGGER_PROPERTIES); InputStream in = null; try { if (f.exists()) { in = new FileInputStream(f); } if (in == null) { // load default in = ActionProducer.class.getClassLoader().getResourceAsStream(DEBUGGER_PROPERTIES); OutputStream out = new FileOutputStream(f); try { IOUtils.copy(in, out); } catch (Exception e) { LOG.error("Cannot write properties: " + e, e); } finally { IOUtils.closeQuietly(in); IOUtils.closeQuietly(out); } in = new FileInputStream(f); } props.load(in); for (Object o : props.keySet()) { String key = (String) o; if (key.startsWith(TS_INSTANCE_START)) { String name = key.substring(TS_INSTANCE_START.length()); String value = props.getProperty(key); cb.addItem(name + " (" + value + ")"); } } } catch (Exception e) { LOG.error("Cannot read properties: " + e, e); } finally { IOUtils.closeQuietly(in); } return cb; }
From source file:com.ecyrd.jspwiki.providers.WikiVersioningFileProvider.java
/** * Goes through the repository and decides which version is the newest one in that directory. * * @return Latest version number in the repository, or -1, if there is no page in the repository. *//* w ww. j a va 2s.co m*/ private int findLatestVersion(String page) { int version = -1; try { Properties props = getPageProperties(page); for (Iterator i = props.keySet().iterator(); i.hasNext();) { String key = (String) i.next(); if (key.endsWith(".author")) { int cutpoint = key.indexOf('.'); if (cutpoint > 0) { String pageNum = key.substring(0, cutpoint); try { int res = Integer.parseInt(pageNum); if (res > version) { version = res; } } catch (NumberFormatException e) { } // It's okay to skip these. } } } } catch (IOException e) { SilverTrace.error("wiki", "WikiVersioningFileProvider.findLatestVersion()", "wiki.EX_FIND_PAGE", e); } return version; }
From source file:ca.uhn.fhir.narrative.BaseThymeleafNarrativeGenerator.java
private void loadProperties(String propFileName) throws IOException { ourLog.debug("Loading narrative properties file: {}", propFileName); Properties file = new Properties(); InputStream resource = loadResource(propFileName); file.load(resource);//from w w w. ja va 2 s .c o m for (Object nextKeyObj : file.keySet()) { String nextKey = (String) nextKeyObj; if (nextKey.endsWith(".profile")) { String name = nextKey.substring(0, nextKey.indexOf(".profile")); if (isBlank(name)) { continue; } String narrativePropName = name + ".narrative"; String narrativeName = file.getProperty(narrativePropName); if (isBlank(narrativeName)) { throw new ConfigurationException( "Found property '" + nextKey + "' but no corresponding property '" + narrativePropName + "' in file " + propFileName); } if (StringUtils.isNotBlank(narrativeName)) { String narrative = IOUtils.toString(loadResource(narrativeName), Constants.CHARSET_UTF8); myNameToNarrativeTemplate.put(name, narrative); } } else if (nextKey.endsWith(".class")) { String name = nextKey.substring(0, nextKey.indexOf(".class")); if (isBlank(name)) { continue; } String className = file.getProperty(nextKey); Class<?> clazz; try { clazz = Class.forName(className); } catch (ClassNotFoundException e) { ourLog.debug("Unknown datatype class '{}' identified in narrative file {}", name, propFileName); clazz = null; } if (clazz != null) { myClassToName.put(clazz, name); } } else if (nextKey.endsWith(".narrative")) { String name = nextKey.substring(0, nextKey.indexOf(".narrative")); if (isBlank(name)) { continue; } String narrativePropName = name + ".narrative"; String narrativeName = file.getProperty(narrativePropName); if (StringUtils.isNotBlank(narrativeName)) { String narrative = IOUtils.toString(loadResource(narrativeName), Constants.CHARSET_UTF8); myNameToNarrativeTemplate.put(name, narrative); } continue; } else if (nextKey.endsWith(".title")) { ourLog.debug("Ignoring title property as narrative generator no longer generates titles: {}", nextKey); } else { throw new ConfigurationException("Invalid property name: " + nextKey); } } }
From source file:org.apache.blur.command.BaseCommandManager.java
@SuppressWarnings("unchecked") protected void loadCommandClasses(Enumeration<URL> enumeration, ClassLoader loader, BigInteger version) throws IOException { Properties properties = new Properties(); while (enumeration.hasMoreElements()) { URL url = enumeration.nextElement(); InputStream inputStream = url.openStream(); properties.load(inputStream);/* ww w . j a v a 2 s .c o m*/ inputStream.close(); } Set<Object> keySet = properties.keySet(); for (Object o : keySet) { String classNameToRegister = o.toString(); LOG.info("Loading class [{0}]", classNameToRegister); try { register((Class<? extends Command<?>>) loader.loadClass(classNameToRegister), version); } catch (ClassNotFoundException e) { throw new IOException(e); } } }
From source file:it.greenvulcano.gvesb.api.controller.GvConfigurationControllerRest.java
@GET @Path("/property") @Produces(MediaType.APPLICATION_JSON)/*from w w w.j a v a 2 s. c om*/ @RolesAllowed({ Authority.ADMINISTRATOR, Authority.MANAGER }) public Response getConfigProperties() { Response response = null; try { Properties configProperties = gvConfigurationManager.getXMLConfigProperties(); JSONObject configJson = new JSONObject(); configProperties.keySet().stream().map(Object::toString) .forEach(k -> configJson.put(k, configProperties.getProperty(k))); response = Response.ok(configJson.toString()).build(); } catch (FileNotFoundException e) { response = Response.status(Response.Status.NOT_FOUND).build(); } catch (Exception e) { LOG.error("Failed to retrieve XMLConfigProperties ", e); response = Response.status(Response.Status.SERVICE_UNAVAILABLE).build(); } return response; }
From source file:net.sf.mpaxs.spi.computeHost.Settings.java
private void addConfigFile(String path) { Properties prop = new Properties(); FileInputStream inputStream;/*from w w w . java2 s . c o m*/ try { inputStream = new FileInputStream(path); prop.load(inputStream); inputStream.close(); } catch (FileNotFoundException ex) { Logger.getLogger(Settings.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(Settings.class.getName()).log(Level.SEVERE, null, ex); } for (Object key : prop.keySet()) { String s = (String) key; config.setProperty(s, prop.getProperty(s)); } }