List of usage examples for java.util Properties isEmpty
@Override public boolean isEmpty()
From source file:org.sakaiproject.search.tool.SearchBeanImpl.java
protected Properties extractPropertiesFromTool() { Placement placement = toolManager.getCurrentPlacement(); Properties props = placement.getPlacementConfig(); if (props.isEmpty()) props = placement.getConfig();/* www .j a v a 2s .co m*/ return props; }
From source file:org.traccar.web.server.model.DataServiceImpl.java
@Override public HashMap<String, String> getCustomLayers() { String fileName = "/WEB-INF/custom.properties"; HashMap<String, String> map = new HashMap<String, String>(); Properties customLayerFile = new Properties(); try {/* ww w .jav a 2 s.c o m*/ customLayerFile.load(super.getServletContext().getResourceAsStream(fileName)); if (!customLayerFile.isEmpty()) { Iterator<Entry<Object, Object>> layers = customLayerFile.entrySet().iterator(); while (layers.hasNext()) { Entry e = layers.next(); String layerName = e.getKey().toString(); String layerUrl = e.getValue().toString(); map.put(layerName, layerUrl); } } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return map; }
From source file:org.wso2.carbon.ui.valve.XSSValve.java
private void buildScriptPatterns() { patternList = new ArrayList<Pattern>(Arrays.asList(patterns)); if (patterPath != null && !patterPath.isEmpty()) { InputStream inStream = null; File xssPatternConfigFile = new File(patterPath); Properties properties = new Properties(); if (xssPatternConfigFile.exists()) { try { inStream = new FileInputStream(xssPatternConfigFile); properties.load(inStream); } catch (FileNotFoundException e) { log.error("Can not load xssPatternConfig properties file ", e); } catch (IOException e) { log.error("Can not load xssPatternConfigFile properties file ", e); } finally { if (inStream != null) { try { inStream.close(); } catch (IOException e) { log.error("Error while closing stream ", e); }//from w ww .j av a 2 s. c o m } } } if (!properties.isEmpty()) { for (String key : properties.stringPropertyNames()) { String value = properties.getProperty(key); patternList.add(Pattern.compile(value, Pattern.CASE_INSENSITIVE)); } } } }
From source file:solidstack.reflect.Dumper.java
public void dumpTo(Object o, DumpWriter out) { try {/*from www . j ava 2 s .c o m*/ if (o == null) { out.append("<null>"); return; } Class<?> cls = o.getClass(); if (cls == String.class) { out.append("\"").append(((String) o).replace("\\", "\\\\").replace("\n", "\\n").replace("\r", "\\r") .replace("\t", "\\t").replace("\"", "\\\"")).append("\""); return; } if (o instanceof CharSequence) { out.append("(").append(o.getClass().getName()).append(")"); dumpTo(o.toString(), out); return; } if (cls == char[].class) { out.append("(char[])"); dumpTo(String.valueOf((char[]) o), out); return; } if (cls == byte[].class) { out.append("byte[").append(Integer.toString(((byte[]) o).length)).append("]"); return; } if (cls == Class.class) { out.append(((Class<?>) o).getCanonicalName()).append(".class"); return; } if (cls == File.class) { out.append("File( \"").append(((File) o).getPath()).append("\" )"); return; } if (cls == AtomicInteger.class) { out.append("AtomicInteger( ").append(Integer.toString(((AtomicInteger) o).get())).append(" )"); return; } if (cls == AtomicLong.class) { out.append("AtomicLong( ").append(Long.toString(((AtomicLong) o).get())).append(" )"); return; } if (o instanceof ClassLoader) { out.append(o.getClass().getCanonicalName()); return; } if (cls == java.lang.Short.class || cls == java.lang.Long.class || cls == java.lang.Integer.class || cls == java.lang.Float.class || cls == java.lang.Byte.class || cls == java.lang.Character.class || cls == java.lang.Double.class || cls == java.lang.Boolean.class || cls == BigInteger.class || cls == BigDecimal.class) { out.append("(").append(cls.getSimpleName()).append(")").append(o.toString()); return; } String className = cls.getCanonicalName(); if (className == null) className = cls.getName(); out.append(className); if (this.skip.contains(className) || o instanceof java.lang.Thread) { out.append(" (skipped)"); return; } Integer id = this.visited.get(o); if (id == null) { id = ++this.id; this.visited.put(o, id); if (!this.hideIds) out.append(" <id=" + id + ">"); } else { out.append(" <refid=" + id + ">"); return; } if (cls.isArray()) { if (Array.getLength(o) == 0) out.append(" []"); else { out.newlineOrSpace().append("[").newlineOrSpace().indent().setFirst(); int rowCount = Array.getLength(o); for (int i = 0; i < rowCount; i++) { out.comma(); dumpTo(Array.get(o, i), out); } out.newlineOrSpace().unIndent().append("]"); } } else if (o instanceof Collection && !this.overriddenCollection.contains(className)) { Collection<?> list = (Collection<?>) o; if (list.isEmpty()) out.append(" []"); else { out.newlineOrSpace().append("[").newlineOrSpace().indent().setFirst(); for (Object value : list) { out.comma(); dumpTo(value, out); } out.newlineOrSpace().unIndent().append("]"); } } else if (o instanceof Properties && !this.overriddenCollection.contains(className)) // Properties is a Map, so it must come before the Map { Field def = cls.getDeclaredField("defaults"); if (!def.isAccessible()) def.setAccessible(true); Properties defaults = (Properties) def.get(o); Hashtable<?, ?> map = (Hashtable<?, ?>) o; out.newlineOrSpace().append("[").newlineOrSpace().indent().setFirst(); for (Map.Entry<?, ?> entry : map.entrySet()) { out.comma(); dumpTo(entry.getKey(), out); out.append(": "); dumpTo(entry.getValue(), out); } if (defaults != null && !defaults.isEmpty()) { out.comma().append("defaults: "); dumpTo(defaults, out); } out.newlineOrSpace().unIndent().append("]"); } else if (o instanceof Map && !this.overriddenCollection.contains(className)) { Map<?, ?> map = (Map<?, ?>) o; if (map.isEmpty()) out.append(" []"); else { out.newlineOrSpace().append("[").newlineOrSpace().indent().setFirst(); for (Map.Entry<?, ?> entry : map.entrySet()) { out.comma(); dumpTo(entry.getKey(), out); out.append(": "); dumpTo(entry.getValue(), out); } out.newlineOrSpace().unIndent().append("]"); } } else if (o instanceof Method) { out.newlineOrSpace().append("{").newlineOrSpace().indent().setFirst(); Field field = cls.getDeclaredField("clazz"); if (!field.isAccessible()) field.setAccessible(true); out.comma().append("clazz").append(": "); dumpTo(field.get(o), out); field = cls.getDeclaredField("name"); if (!field.isAccessible()) field.setAccessible(true); out.comma().append("name").append(": "); dumpTo(field.get(o), out); field = cls.getDeclaredField("parameterTypes"); if (!field.isAccessible()) field.setAccessible(true); out.comma().append("parameterTypes").append(": "); dumpTo(field.get(o), out); field = cls.getDeclaredField("returnType"); if (!field.isAccessible()) field.setAccessible(true); out.comma().append("returnType").append(": "); dumpTo(field.get(o), out); out.newlineOrSpace().unIndent().append("}"); } else { ArrayList<Field> fields = new ArrayList<Field>(); while (cls != Object.class) { Field[] fs = cls.getDeclaredFields(); for (Field field : fs) fields.add(field); cls = cls.getSuperclass(); } Collections.sort(fields, new Comparator<Field>() { public int compare(Field left, Field right) { return left.getName().compareTo(right.getName()); } }); if (fields.isEmpty()) out.append(" {}"); else { out.newlineOrSpace().append("{").newlineOrSpace().indent().setFirst(); for (Field field : fields) if ((field.getModifiers() & Modifier.STATIC) == 0) if (!this.hideTransients || (field.getModifiers() & Modifier.TRANSIENT) == 0) { out.comma().append(field.getName()).append(": "); if (!field.isAccessible()) field.setAccessible(true); if (field.getType().isPrimitive()) if (field.getType() == boolean.class) // TODO More? out.append(field.get(o).toString()); else out.append("(").append(field.getType().getName()).append(")") .append(field.get(o).toString()); else dumpTo(field.get(o), out); } out.newlineOrSpace().unIndent().append("}"); } } } catch (IOException e) { throw new FatalIOException(e); } catch (Exception e) { dumpTo(e.toString(), out); } }
From source file:org.springframework.ui.freemarker.FreeMarkerConfigurationFactory.java
/** * Prepare the FreeMarker Configuration and return it. * @return the FreeMarker Configuration object * @throws IOException if the config file wasn't found * @throws TemplateException on FreeMarker initialization failure *//*from ww w .j av a 2s .c o m*/ public Configuration createConfiguration() throws IOException, TemplateException { Configuration config = newConfiguration(); Properties props = new Properties(); // Load config file if specified. if (this.configLocation != null) { if (logger.isInfoEnabled()) { logger.info("Loading FreeMarker configuration from " + this.configLocation); } PropertiesLoaderUtils.fillProperties(props, this.configLocation); } // Merge local properties if specified. if (this.freemarkerSettings != null) { props.putAll(this.freemarkerSettings); } // FreeMarker will only accept known keys in its setSettings and // setAllSharedVariables methods. if (!props.isEmpty()) { config.setSettings(props); } if (!CollectionUtils.isEmpty(this.freemarkerVariables)) { config.setAllSharedVariables(new SimpleHash(this.freemarkerVariables, config.getObjectWrapper())); } if (this.defaultEncoding != null) { config.setDefaultEncoding(this.defaultEncoding); } List<TemplateLoader> templateLoaders = new LinkedList<>(this.templateLoaders); // Register template loaders that are supposed to kick in early. if (this.preTemplateLoaders != null) { templateLoaders.addAll(this.preTemplateLoaders); } // Register default template loaders. if (this.templateLoaderPaths != null) { for (String path : this.templateLoaderPaths) { templateLoaders.add(getTemplateLoaderForPath(path)); } } postProcessTemplateLoaders(templateLoaders); // Register template loaders that are supposed to kick in late. if (this.postTemplateLoaders != null) { templateLoaders.addAll(this.postTemplateLoaders); } TemplateLoader loader = getAggregateTemplateLoader(templateLoaders); if (loader != null) { config.setTemplateLoader(loader); } postProcessConfiguration(config); return config; }
From source file:org.codehaus.tycho.eclipsepackaging.ProductExportMojo.java
/** * Root files are files that must be packaged with an Eclipse install but are not features or plug-ins. These files * are added to the root or to a specified sub folder of the build. * /*from ww w. j a v a2 s. c o m*/ * <pre> * root= * root.<confi>= * root.folder.<subfolder>= * root.<config>.folder.<subfolder>= * </pre> * * Not supported are the properties root.permissions and root.link. * * @see http://help.eclipse.org/ganymede/index.jsp?topic=/org.eclipse.pde.doc.user/tasks/pde_rootfiles.htm * * @throws MojoExecutionException */ private void includeRootFiles(TargetEnvironment environment, File target) throws MojoExecutionException { Properties properties = project.getProperties(); String generatedBuildProperties = properties.getProperty("generatedBuildProperties"); getLog().debug("includeRootFiles from " + generatedBuildProperties); if (generatedBuildProperties != null) { Properties rootProperties = new Properties(); try { rootProperties.load(new FileInputStream(new File(project.getBasedir(), generatedBuildProperties))); if (!rootProperties.isEmpty()) { String config = getConfig(environment); String root = "root"; String rootConfig = "root." + config; String rootFolder = "root.folder."; String rootConfigFolder = "root." + config + ".folder."; Set<Entry<Object, Object>> entrySet = rootProperties.entrySet(); for (Iterator iterator = entrySet.iterator(); iterator.hasNext();) { Entry<String, String> entry = (Entry<String, String>) iterator.next(); String key = entry.getKey().trim(); // root= if (root.equals(key)) { handleRootEntry(target, entry.getValue(), null); } // root.xxx= else if (rootConfig.equals(key)) { handleRootEntry(target, entry.getValue(), null); } // root.folder.yyy= else if (key.startsWith(rootFolder)) { String subFolder = entry.getKey().substring((rootFolder.length())); handleRootEntry(target, entry.getValue(), subFolder); } // root.xxx.folder.yyy= else if (key.startsWith(rootConfigFolder)) { String subFolder = entry.getKey().substring((rootConfigFolder.length())); handleRootEntry(target, entry.getValue(), subFolder); } else { getLog().debug("ignoring property " + entry.getKey() + "=" + entry.getValue()); } } } } catch (FileNotFoundException e) { throw new MojoExecutionException("Error including root files for product", e); } catch (IOException e) { throw new MojoExecutionException("Error including root files for product", e); } } }
From source file:org.apache.ivory.workflow.engine.OozieWorkflowEngine.java
@Override public void reRun(String cluster, String jobId, Properties props) throws IvoryException { OozieClient client = OozieClientFactory.get(cluster); try {/* w w w. j av a2 s. com*/ WorkflowJob jobInfo = client.getJobInfo(jobId); Properties jobprops = OozieUtils.toProperties(jobInfo.getConf()); if (props == null || props.isEmpty()) jobprops.put(OozieClient.RERUN_FAIL_NODES, "false"); else for (Entry<Object, Object> entry : props.entrySet()) { jobprops.put(entry.getKey(), entry.getValue()); } jobprops.remove(OozieClient.COORDINATOR_APP_PATH); jobprops.remove(OozieClient.BUNDLE_APP_PATH); client.reRun(jobId, jobprops); assertStatus(cluster, jobId, WorkflowJob.Status.RUNNING); LOG.info("Rerun job " + jobId + " on cluster " + cluster); } catch (Exception e) { LOG.error("Unable to rerun workflows", e); throw new IvoryException(e); } }
From source file:org.compass.gps.device.hibernate.embedded.CompassEventListener.java
private CompassHolder initCompassHolder(Configuration cfg) { Properties compassProperties = new Properties(); //noinspection unchecked Properties props = cfg.getProperties(); for (Map.Entry entry : props.entrySet()) { String key = (String) entry.getKey(); if (key.startsWith(COMPASS_PREFIX)) { compassProperties.put(entry.getKey(), entry.getValue()); }//w w w .ja va 2 s .c om if (key.startsWith(COMPASS_GPS_INDEX_PREFIX)) { compassProperties.put(entry.getKey(), entry.getValue()); } } if (compassProperties.isEmpty()) { if (log.isDebugEnabled()) { log.debug("No Compass properties defined, disabling Compass"); } return null; } if (compassProperties.getProperty(CompassEnvironment.CONNECTION) == null) { if (log.isDebugEnabled()) { log.debug("No Compass [" + CompassEnvironment.CONNECTION + "] property defined, disabling Compass"); } return null; } processCollections = compassProperties.getProperty(COMPASS_PROCESS_COLLECTIONS, "true") .equalsIgnoreCase("true"); CompassConfiguration compassConfiguration = CompassConfigurationFactory.newConfiguration(); CompassSettings settings = compassConfiguration.getSettings(); settings.addSettings(compassProperties); String configLocation = (String) compassProperties.get(COMPASS_CONFIG_LOCATION); if (configLocation != null) { compassConfiguration.configure(configLocation); } boolean atleastOneClassAdded = false; for (Iterator it = cfg.getClassMappings(); it.hasNext();) { PersistentClass clazz = (PersistentClass) it.next(); Class<?> mappedClass = clazz.getMappedClass(); for (Iterator propIt = clazz.getPropertyIterator(); propIt.hasNext();) { Property prop = (Property) propIt.next(); Value value = prop.getValue(); if (value instanceof Component) { Component component = (Component) value; try { atleastOneClassAdded |= compassConfiguration.tryAddClass( ClassUtils.forName(component.getComponentClassName(), settings.getClassLoader())); } catch (ClassNotFoundException e) { log.warn("Failed to load component class [" + component.getComponentClassName() + "]", e); } } } Value idValue = clazz.getIdentifierProperty().getValue(); if (idValue instanceof Component) { Component component = (Component) idValue; try { atleastOneClassAdded |= compassConfiguration.tryAddClass( ClassUtils.forName(component.getComponentClassName(), settings.getClassLoader())); } catch (ClassNotFoundException e) { log.warn("Failed to load component class [" + component.getComponentClassName() + "]", e); } } atleastOneClassAdded |= compassConfiguration.tryAddClass(mappedClass); } if (!atleastOneClassAdded) { if (log.isDebugEnabled()) { log.debug("No searchable class mappings found in Hibernate class mappings, disabling Compass"); } return null; } CompassHolder compassHolder = new CompassHolder(); compassHolder.compassProperties = compassProperties; compassHolder.commitBeforeCompletion = settings .getSettingAsBoolean(CompassEnvironment.Transaction.COMMIT_BEFORE_COMPLETION, false); String transactionFactory = (String) compassProperties.get(CompassEnvironment.Transaction.FACTORY); if (transactionFactory == null) { String hibernateTransactionStrategy = cfg.getProperty(Environment.TRANSACTION_STRATEGY); if (CMTTransactionFactory.class.getName().equals(hibernateTransactionStrategy) || JTATransactionFactory.class.getName().equals(hibernateTransactionStrategy)) { // hibernate is configured with JTA, automatically configure Compass to use its JTASync (by default) compassHolder.hibernateControlledTransaction = false; compassConfiguration.setSetting(CompassEnvironment.Transaction.FACTORY, JTASyncTransactionFactory.class.getName()); } else { // Hibernate JDBC transaction manager, let Compass use the local transaction manager compassHolder.hibernateControlledTransaction = true; // if the settings is configured to use local transaciton, disable thread bound setting since // we are using Hibernate to managed transaction scope (using the transaction to holder map) and not thread locals if (settings .getSetting(CompassEnvironment.Transaction.DISABLE_THREAD_BOUND_LOCAL_TRANSATION) == null) { settings.setBooleanSetting(CompassEnvironment.Transaction.DISABLE_THREAD_BOUND_LOCAL_TRANSATION, true); } } } else if (LocalTransactionFactory.class.getName().equals(transactionFactory)) { compassHolder.hibernateControlledTransaction = true; // if the settings is configured to use local transaciton, disable thread bound setting since // we are using Hibernate to managed transaction scope (using the transaction to holder map) and not thread locals if (settings.getSetting(CompassEnvironment.Transaction.DISABLE_THREAD_BOUND_LOCAL_TRANSATION) == null) { settings.setBooleanSetting(CompassEnvironment.Transaction.DISABLE_THREAD_BOUND_LOCAL_TRANSATION, true); } } else { // Hibernate is not controlling the transaction (using JTA Sync or XA), don't commit/rollback // with Hibernate transaction listeners compassHolder.hibernateControlledTransaction = false; } compassHolder.indexSettings = new Properties(); for (Map.Entry entry : compassProperties.entrySet()) { String key = (String) entry.getKey(); if (key.startsWith(COMPASS_GPS_INDEX_PREFIX)) { compassHolder.indexSettings.put(key.substring(COMPASS_GPS_INDEX_PREFIX.length()), entry.getValue()); } } String mirrorFilterClass = compassHolder.compassProperties.getProperty(COMPASS_MIRROR_FILTER); if (mirrorFilterClass != null) { try { compassHolder.mirrorFilter = (HibernateMirrorFilter) ClassUtils .forName(mirrorFilterClass, compassConfiguration.getSettings().getClassLoader()) .newInstance(); } catch (Exception e) { throw new CompassException("Failed to create mirror filter [" + mirrorFilterClass + "]", e); } } compassHolder.compass = compassConfiguration.buildCompass(); return compassHolder; }
From source file:gov.nih.nci.cabig.caaers.tools.mail.CaaersJavaMailSender.java
/** * We will check the configuration, and populate the propertes in the JavaMailSenderImpl bean. *///from w w w . j ava 2 s .c o m public void afterPropertiesSet() throws Exception { Properties properties = new Properties(); boolean hasUsername = StringUtils.isNotBlank(getUsername()); boolean hasPassword = StringUtils.isNotBlank(getPassword()); boolean isSSL = configuration.get(Configuration.SMTP_SSL_ENABLED) != null && configuration.get(Configuration.SMTP_SSL_ENABLED); Integer optedTimeout = configuration.get(Configuration.SMTP_TIMEOUT); Integer actualTimeout = optedTimeout == null ? 4000 : optedTimeout; String baseMailPropertyName = "mail.smtp."; if (isSSL) { baseMailPropertyName = "mail.smtps."; properties.setProperty(baseMailPropertyName + "starttls.enable", "true"); } properties.setProperty(baseMailPropertyName + "timeout", actualTimeout.toString()); if (hasUsername || hasPassword) { properties.setProperty(baseMailPropertyName + "auth", "true"); } if (logger.isDebugEnabled()) { properties.put(baseMailPropertyName + "debug", "true"); } if (!properties.isEmpty()) { setJavaMailProperties(properties); } if (logger.isDebugEnabled()) { logger.debug("Mail properties : " + String.valueOf(properties)); logger.debug("Mail host : " + String.valueOf(getHost())); logger.debug("Mail username : " + String.valueOf(getUsername())); logger.debug("Mail password : " + String.valueOf(getPassword())); logger.debug("Mail port : " + String.valueOf(getPort())); logger.debug("Mail protocol : " + String.valueOf(getProtocol())); } }