Java Code Examples for java.util.Properties.isEmpty()

The following are Jave code examples for showing how to use isEmpty() of the java.util.Properties class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: parabuild-ci   File: WebuiUtils.java   Source Code and License Vote up 7 votes
public static String makeURLParameters(final Properties params) {
  final StringBuffer result = new StringBuffer(100);
  if (!params.isEmpty()) {
    boolean first = true;
    final Set set = params.entrySet();
    for (final Iterator i = set.iterator(); i.hasNext(); ) {
      final Map.Entry entry = (Map.Entry) i.next();
      if (first) {
        result.append('?');
        first = false;
      } else {
        result.append('&');
      }
      result.append((String) entry.getKey());
      result.append('=');
      result.append((String) entry.getValue());
    }
  }
  return result.toString();
}
 
Example 2
Project: incubator-servicecomb-java-chassis   File: Log4jUtils.java   Source Code and License Vote up 6 votes
public static void init(List<String> locationPatterns) throws Exception {
  if (inited) {
    return;
  }

  synchronized (LOCK) {
    if (inited) {
      return;
    }

    PropertiesLoader loader = new PropertiesLoader(locationPatterns);
    Properties properties = loader.load();
    if (properties.isEmpty()) {
      throw new Exception("can not find resource " + locationPatterns);
    }

    PropertyConfigurator.configure(properties);
    inited = true;

    // 如果最高优先级的文件是在磁盘上,且有写权限,则将merge的结果输出到该目录,方便维护时观察生效的参数
    outputFile(loader.getFoundResList(), properties);
  }
}
 
Example 3
Project: incubator-netbeans   File: XMLPropertiesConvertor.java   Source Code and License Vote up 6 votes
public void write(java.io.Writer w, Object inst) throws IOException {
    w.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"+XMLSettingsSupport.LINE_SEPARATOR); // NOI18N
    w.write("<!DOCTYPE properties PUBLIC \""); // NOI18N
    
    FileObject foEntity = Env.findEntityRegistration(providerFO);
    if (foEntity == null) foEntity = providerFO;
    Object publicId = foEntity.getAttribute(Env.EA_PUBLICID);
    if (publicId == null || !(publicId instanceof String)) {
        throw new IOException("missing or invalid attribute: " + //NOI18N
            Env.EA_PUBLICID + ", provider: " + foEntity); //NOI18N
    }
    
    w.write((String) publicId);
    w.write("\" \"http://www.netbeans.org/dtds/properties-1_0.dtd\">"+XMLSettingsSupport.LINE_SEPARATOR); // NOI18N
    w.write("<properties>"+XMLSettingsSupport.LINE_SEPARATOR); // NOI18N
    Properties p = getProperties(inst);
    if (p != null && !p.isEmpty()) writeProperties(w, p);
    w.write("</properties>"+XMLSettingsSupport.LINE_SEPARATOR); // NOI18N
}
 
Example 4
Project: Hydrograph   File: ExecutionTrackingUtils.java   Source Code and License Vote up 6 votes
/**
 * This function will load property file to initialize the parameters values.
 *
 */
public void loadPropertyFile(){
	try(FileInputStream stream = getExternalPropertyFilePath();
			InputStream inputStream = this.getClass().getResourceAsStream(getInternalPropertyFilePath());) {
		Properties properties = new Properties();
		
		if(stream != null){
			properties.load(stream);
		}else {
			
			properties.load(inputStream);
		}
		
		if (!properties.isEmpty()) {
			portNo = properties.getProperty(PORT_NO);
			host = properties.getProperty(LOCAL_URL);
			route = properties.getProperty(TRACKING_ROUTE);
			String frequency = properties.getProperty(STATUS_FREQUENCY);
			statusFrequency = Long.parseLong(frequency);
		}
	} catch (IOException exception) {
		logger.error("Failed to load properties file", exception);
	}
}
 
Example 5
Project: gemini.blueprint   File: ConfigPropertiesDefinitionParser.java   Source Code and License Vote up 6 votes
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
	// parse attributes using conventions
	super.doParse(element, parserContext, builder);

	// parse nested element (if any)
	Properties parsedProps = parserContext.getDelegate().parsePropsElement(element);
	if (!parsedProps.isEmpty()) {
		if (builder.getRawBeanDefinition().getPropertyValues().contains(PROPERTIES_PROP)) {
			parserContext.getReaderContext().error(
				"Property '" + PROPERTIES_PROP
						+ "' is defined more then once. Only one approach may be used per property.", element);

		}
		builder.addPropertyValue(PROPERTIES_PROP, parsedProps);
	}
}
 
Example 6
Project: incubator-netbeans   File: OQLSupport.java   Source Code and License Vote up 5 votes
public static void saveModel(OQLTreeModel model) {
    FileLock lock = null;
    try {
        Properties p = modelToProperties(model);
        if (!p.isEmpty()) ProfilerStorage.saveGlobalProperties(p, SAVED_OQL_QUERIES_FILENAME);
    } catch (Exception e) {
        ProfilerLogger.log(e);
    } finally {
        if (lock != null) lock.releaseLock();
    }
}
 
Example 7
Project: incubator-netbeans   File: ProfilerWindow.java   Source Code and License Vote up 5 votes
private void loadSessionSettings() {
    features = session.getFeatures();
    plugins = session.getPlugins();
    
    Properties p = new Properties();
    try {
        ProfilerStorage.loadProjectProperties(p, session.getProject(), "attach"); // NOI18N
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    }
    if (!p.isEmpty()) {
        attachSettings = new AttachSettings();
        attachSettings.load(p);
    }
}
 
Example 8
Project: monarch   File: CacheXmlGenerator.java   Source Code and License Vote up 5 votes
private void generate(final Properties props, String elementName) throws SAXException {
  if (props == null || props.isEmpty()) {
    return;
  }
  if (elementName != null) {
    handler.startElement("", elementName, elementName, EMPTY);
  }
  for (Iterator iter = props.entrySet().iterator(); iter.hasNext();) {
    Map.Entry entry = (Map.Entry) iter.next();
    String name = (String) entry.getKey();
    Object value = entry.getValue();

    AttributesImpl atts = new AttributesImpl();
    atts.addAttribute("", "", NAME, "", name);

    handler.startElement("", PARAMETER, PARAMETER, atts);

    if (value instanceof String) {
      generate((String) value);

    } else if (value instanceof Declarable) {
      generate((Declarable) value);

    } else {
      // Ignore it
    }

    handler.endElement("", PARAMETER, PARAMETER);

  }
  if (elementName != null) {
    handler.endElement("", elementName, elementName);
  }
}
 
Example 9
Project: phoenix.webui.framework   File: AutoModuleProxy.java   Source Code and License Vote up 5 votes
/**
 * 加载sessionStorage信息
 * @param accountNameValue
 * @return
 */
private boolean loadSessionStorage(String accountNameValue, Map<String, String> customMap)
{
    WebDriver webDriver = util.getEngine().getDriver();
    if(webDriver instanceof WebStorage)
    {
        WebStorage webStorage = (WebStorage) webDriver;
        SessionStorage sessionStorage = webStorage.getSessionStorage();

        Properties pro = new Properties();
        if(PathUtil.proLoad(pro, "sessionStorage." + accountNameValue))
        {
            if(pro.isEmpty())
            {
                return false;
            }
            
            pro.putAll(customMap);

            pro.stringPropertyNames().parallelStream().forEach((key) -> {
                sessionStorage.setItem(key, pro.getProperty(key));
            });

            return true;
        }
    }

    return false;
}
 
Example 10
Project: monarch   File: QueryTestUtils.java   Source Code and License Vote up 5 votes
public void createCache(Properties prop) {
  if (null != prop && !prop.isEmpty()) {
    cache = new CacheFactory(prop).create();
  } else {
    cache = new CacheFactory().set(MCAST_PORT, "0").create();
  }
}
 
Example 11
Project: lams   File: HbmBinder.java   Source Code and License Vote up 5 votes
private static void resolveAndBindTypeDef(SimpleValue simpleValue,
		Mappings mappings, String typeName, Properties parameters) {
	TypeDef typeDef = mappings.getTypeDef( typeName );
	if ( typeDef != null ) {
		typeName = typeDef.getTypeClass();
		// parameters on the property mapping should
		// override parameters in the typedef
		Properties allParameters = new Properties();
		allParameters.putAll( typeDef.getParameters() );
		allParameters.putAll( parameters );
		parameters = allParameters;
	}else if (typeName!=null && !mappings.isInSecondPass()){
		BasicType basicType=mappings.getTypeResolver().basic(typeName);
		if (basicType==null) {
			/*
			 * If the referenced typeName isn't a basic-type, it's probably a typedef defined 
			 * in a mapping file not read yet.
			 * It should be solved by deferring the resolution and binding of this type until 
			 * all mapping files are read - the second passes.
			 * Fixes issue HHH-7300
			 */
			SecondPass resolveUserTypeMappingSecondPass=new ResolveUserTypeMappingSecondPass(simpleValue,typeName,mappings,parameters);
			mappings.addSecondPass(resolveUserTypeMappingSecondPass);
		}
	}

	if ( !parameters.isEmpty() ) simpleValue.setTypeParameters( parameters );

	if ( typeName != null ) simpleValue.setTypeName( typeName );
}
 
Example 12
Project: oscm   File: Operation.java   Source Code and License Vote up 5 votes
public void setFromProperties(Properties properties) {
    if (!properties.isEmpty()) {
        setOperationId((String) properties
                .get(APPlatformController.KEY_OPERATION_ID));
        properties.remove(APPlatformController.KEY_OPERATION_ID);
        setUserId((String) properties
                .get(APPlatformController.KEY_OPERATION_USER_ID));
        properties.remove(APPlatformController.KEY_OPERATION_USER_ID);
        if (!properties.isEmpty()) {
            setParameters(convertPropertiesToXML(properties));
        }
    }
}
 
Example 13
Project: minie   File: Options.java   Source Code and License Vote up 5 votes
/** Load options from the configuration file*/
public void setOptions(InputStream optionsStream) throws IOException {
	Properties prop = new Properties();
	prop.load(optionsStream);
	
	// load the required options
	conservativeSVA = Boolean.parseBoolean(getProperty(prop, "conservativeSVA"));
	conservativeSVOA = Boolean.parseBoolean(getProperty(prop, "conservativeSVOA"));
	processCcAllVerbs = Boolean.parseBoolean(getProperty(prop, "processCcAllVerbs"));
	processCcNonVerbs = Boolean.parseBoolean(getProperty(prop, "processCcNonVerbs"));
	processAppositions = Boolean.parseBoolean(getProperty(prop, "processAppositions"));
	appositionVerb = getProperty(prop, "appositionVerb");
	processPossessives = Boolean.parseBoolean(getProperty(prop, "processPossessives"));
	possessiveVerb = getProperty(prop, "possessiveVerb");
	processPartmods = Boolean.parseBoolean(getProperty(prop, "processPartmods"));
	lemmatize = Boolean.parseBoolean(getProperty(prop, "lemmatize"));
	nary = Boolean.parseBoolean(getProperty(prop, "nary"));
	minOptionalArgs = Integer.parseInt(getProperty(prop, "minOptionalArgs"));
	maxOptionalArgs = Integer.parseInt(getProperty(prop, "maxOptionalArgs"));
	
	// get dictionaries
	dictCopular = getDictionary(prop, "dictCopular");
	dictExtCopular = getDictionary(prop, "dictExtCopular");
	dictNotExtCopular = getDictionary(prop, "dictNotExtCopular");
	dictComplexTransitive = getDictionary(prop, "dictComplexTransitive");
	dictAdverbsConj = getDictionary(prop, "dictAdverbsConj");
	dictAdverbsIgnore = getDictionary(prop, "dictAdverbsIgnore");
	dictAdverbsInclude = getDictionary(prop, "dictAdverbsInclude");
	
	// check for unused properties
	if (!prop.isEmpty()) {
		System.err.println( "Unknown option(s): " 
				+ Arrays.toString( prop.keySet().toArray() ));
	}
}
 
Example 14
Project: Banmanager   File: Property.java   Source Code and License Vote up 5 votes
/**
 * Converts a property file object into a JSONObject. The property file object is a table of name value pairs.
 * @param properties java.util.Properties
 * @return JSONObject
 * @throws JSONException
 */
public static JSONObject toJSONObject(Properties properties) throws JSONException {
    JSONObject jo = new JSONObject();
    if (properties != null && !properties.isEmpty()) {
        Enumeration enumProperties = properties.propertyNames();
        while(enumProperties.hasMoreElements()) {
            String name = (String)enumProperties.nextElement();
            jo.put(name, properties.getProperty(name));
        }
    }
    return jo;
}
 
Example 15
Project: lams   File: FreeMarkerConfigurationFactory.java   Source Code and License Vote up 4 votes
/**
 * 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
 */
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<TemplateLoader>(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;
}
 
Example 16
Project: azeroth   File: ResourceUtils.java   Source Code and License Vote up 4 votes
public synchronized static void merge(Properties properties) {
    if (properties == null || properties.isEmpty()) { return; }
    allProperties.putAll(properties);
}
 
Example 17
Project: rapidminer   File: TutorialGroup.java   Source Code and License Vote up 4 votes
/**
 * Loads the content of the zip file.
 */
private void load() throws IOException, RepositoryException {
	tutorials = new ArrayList<>();
	try (InputStream rawIn = getInputStream()) {
		NonClosingZipInputStream zip = new NonClosingZipInputStream(rawIn);
		try {
			ZipEntry entry;
			String localeFileName = getPropertyFileName();
			Properties defaultProps = new Properties();
			Properties localProps = new Properties();
			while ((entry = zip.getNextEntry()) != null) {
				if (entry.getName().replaceFirst("/", "").contains("/")) {
					// ignore second folder level and above
					continue;
				}
				String entryName = entry.getName();
				if (entry.isDirectory()) {
					if (path != null) {
						tutorials.add(new Tutorial(this, path, entryName));
					} else {
						tutorials.add(new Tutorial(this, entryName));
					}
				} else if (DEFAULT_PROPERTY_FILE.equals(entryName)) {
					defaultProps.load(zip);
				} else if (localeFileName.equals(entryName)) {
					localProps.load(zip);
				}
			}

			// load title and description from default props
			title = defaultProps.getProperty(KEY_GROUP_NAME, NO_TITLE);
			description = defaultProps.getProperty(KEY_GROUP_DESCRIPTION, NO_DESCRIPTION);

			// exchange titel and description by locale prop if available
			if (!localProps.isEmpty()) {
				title = localProps.getProperty(KEY_GROUP_NAME, title);
				description = localProps.getProperty(KEY_GROUP_DESCRIPTION, description);
			}

			if (title.isEmpty()) {
				title = NO_TITLE;
			}
			if (description.isEmpty()) {
				description = NO_DESCRIPTION;
			}
			Collections.sort(tutorials, TUTORIAL_COMPARATOR);
		} finally {
			zip.close(); // noop ; to avoid compile time warning about resource leak
			zip.close2();
		}
	}
}
 
Example 18
Project: wngn-jms-kafka   File: KafkaLog4jAppender.java   Source Code and License Vote up 4 votes
@Override
public void activateOptions() {
    // check for config parameter validity
    Properties props = new Properties();
    if (brokerList != null)
        props.put(BOOTSTRAP_SERVERS_CONFIG, brokerList);
    if (props.isEmpty())
        throw new ConfigException("The bootstrap servers property should be specified");
    if (topic == null)
        throw new ConfigException("Topic must be specified by the Kafka log4j appender");
    if (compressionType != null)
        props.put(COMPRESSION_TYPE_CONFIG, compressionType);
    if (requiredNumAcks != Integer.MAX_VALUE)
        props.put(ACKS_CONFIG, Integer.toString(requiredNumAcks));
    if (retries > 0)
        props.put(RETRIES_CONFIG, retries);
    if (securityProtocol != null) {
        props.put(SECURITY_PROTOCOL, securityProtocol);
    }
    if (securityProtocol != null && securityProtocol.contains("SSL") && sslTruststoreLocation != null &&
        sslTruststorePassword != null) {
        props.put(SSL_TRUSTSTORE_LOCATION, sslTruststoreLocation);
        props.put(SSL_TRUSTSTORE_PASSWORD, sslTruststorePassword);

        if (sslKeystoreType != null && sslKeystoreLocation != null &&
            sslKeystorePassword != null) {
            props.put(SSL_KEYSTORE_TYPE, sslKeystoreType);
            props.put(SSL_KEYSTORE_LOCATION, sslKeystoreLocation);
            props.put(SSL_KEYSTORE_PASSWORD, sslKeystorePassword);
        }
    }
    if (securityProtocol != null && securityProtocol.contains("SASL") && saslKerberosServiceName != null && clientJaasConfPath != null) {
        props.put(SASL_KERBEROS_SERVICE_NAME, saslKerberosServiceName);
        System.setProperty("java.security.auth.login.config", clientJaasConfPath);
        if (kerb5ConfPath != null) {
            System.setProperty("java.security.krb5.conf", kerb5ConfPath);
        }
    }

    props.put(KEY_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.ByteArraySerializer");
    props.put(VALUE_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.ByteArraySerializer");
    this.producer = getKafkaProducer(props);
    LogLog.debug("Kafka producer connected to " + brokerList);
    LogLog.debug("Logging for topic: " + topic);
}
 
Example 19
Project: dev-courses   File: JDBCConnection.java   Source Code and License Vote up 4 votes
/**
     * Sets the value of the connection's client info properties.  The
     * <code>Properties</code> object contains the names and values of the client info
     * properties to be set.  The set of client info properties contained in
     * the properties list replaces the current set of client info properties
     * on the connection.  If a property that is currently set on the
     * connection is not present in the properties list, that property is
     * cleared.  Specifying an empty properties list will clear all of the
     * properties on the connection.  See <code>setClientInfo (String, String)</code> for
     * more information.
     * <p>
     * If an error occurs in setting any of the client info properties, a
     * <code>SQLClientInfoException</code> is thrown. The <code>SQLClientInfoException</code>
     * contains information indicating which client info properties were not set.
     * The state of the client information is unknown because
     * some databases do not allow multiple client info properties to be set
     * atomically.  For those databases, one or more properties may have been
     * set before the error occurred.
     * <p>
     *
     * @param properties                the list of client info properties to set
     * <p>
     * @see java.sql.Connection#setClientInfo(String, String) setClientInfo(String, String)
     * @since JDK 1.6, HSQLDB 2.0
     * <p>
     * @throws SQLClientInfoException if the database server returns an error while
     *                  setting the clientInfo values on the database server or this method
     * is called on a closed connection
     * <p>
     */
//#ifdef JAVA6
    public void setClientInfo(
            Properties properties) throws SQLClientInfoException {

        if (!this.isClosed && (properties == null || properties.isEmpty())) {
            return;
        }

        SQLClientInfoException ex = new SQLClientInfoException();

        if (this.isClosed) {
            ex.initCause(JDBCUtil.connectionClosedException());
        } else {
            ex.initCause(JDBCUtil.notSupported());
        }

        throw ex;
    }
 
Example 20
Project: s-store   File: JDBCConnection.java   Source Code and License Vote up 4 votes
/**
     * Sets the value of the connection's client info properties.  The
     * <code>Properties</code> object contains the names and values of the client info
     * properties to be set.  The set of client info properties contained in
     * the properties list replaces the current set of client info properties
     * on the connection.  If a property that is currently set on the
     * connection is not present in the properties list, that property is
     * cleared.  Specifying an empty properties list will clear all of the
     * properties on the connection.  See <code>setClientInfo (String, String)</code> for
     * more information.
     * <p>
     * If an error occurs in setting any of the client info properties, a
     * <code>SQLClientInfoException</code> is thrown. The <code>SQLClientInfoException</code>
     * contains information indicating which client info properties were not set.
     * The state of the client information is unknown because
     * some databases do not allow multiple client info properties to be set
     * atomically.  For those databases, one or more properties may have been
     * set before the error occurred.
     * <p>
     *
     * @param properties                the list of client info properties to set
     * <p>
     * @see java.sql.Connection#setClientInfo(String, String) setClientInfo(String, String)
     * @since JDK 1.6, HSQLDB 1.9.0
     * <p>
     * @throws SQLClientInfoException if the database server returns an error while
     *                  setting the clientInfo values on the database server or this method
     * is called on a closed connection
     * <p>
     */
//#ifdef JAVA6
    public void setClientInfo(
            Properties properties) throws SQLClientInfoException {

        if (!this.isClosed && (properties == null || properties.isEmpty())) {
            return;
        }

        SQLClientInfoException ex = new SQLClientInfoException();

        if (this.isClosed) {
            ex.initCause(Util.connectionClosedException());
        } else {
            ex.initCause(Util.notSupported());
        }

        throw ex;
    }