List of usage examples for java.util Properties containsKey
@Override public boolean containsKey(Object key)
From source file:com.github.horrorho.liquiddonkey.settings.commandline.CommandLineConfigFactory.java
public Config fromArgs(String[] args) { logger.trace("<< fromArgs() < {}", (Object) args); try {// w w w.j a v a2 s . co m PropertiesFactory factory = PropertiesFactory.create(); // Fallback defaults Properties properties = factory.fromDefaults(); // Jar defaults try { String resource = properties.get(Property.PROPERTIES_JAR.name()).toString(); IOSupplier<InputStream> supplier = () -> this.getClass().getResourceAsStream(resource); properties = factory.fromInputStream(properties, supplier); } catch (IOException ex) { logger.warn("-- fromArgs() > exception: ", ex); } // Command line args CommandLineOptions commandLineOptions = CommandLineOptions.from(properties); properties = CommandLinePropertiesFactory.create().from(properties, commandLineOptions, args); if (properties.containsKey(Property.COMMAND_LINE_HELP.name())) { HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.setOptionComparator(null); helpFormatter.printHelp(properties.getProperty(Property.APP_NAME.name()) + " [OPTION]... (<token> | <appleid> <password>) ", commandLineOptions.options()); return null; } if (properties.containsKey(Property.COMMAND_LINE_VERSION.name())) { System.out.println(properties.getProperty(Property.PROJECT_VERSION.name())); return null; } // Build config Config config = Config.from(properties); logger.trace(">> fromArgs() > {}", config); return config; } catch (ParseException | IllegalArgumentException | IllegalStateException ex) { logger.trace("-- fromArgs() > exception: ", ex); System.out.println(ex.getLocalizedMessage()); System.out.println("Try '--help' for more information."); return null; } }
From source file:com.twinsoft.convertigo.eclipse.ConvertigoPlugin.java
public static void configureDeployConfiguration() { // The embedded Tomcat has been created, so all engine paths have been computed. deploymentConfigurationManager = new DeploymentConfigurationManager(); try {// w ww. ja v a 2 s . c o m deploymentConfigurationManager.load(); } catch (Exception e) { logException(e, "Unable to load deployment configurations"); } try { Properties properties = decodePsc(); for (int i = 1; i < Integer.MAX_VALUE; i++) { if (i > 1 && !properties.containsKey(DeploymentKey.adminUser.key(i))) { break; } if (!"".equals(DeploymentKey.server.value(properties, i))) { deploymentConfigurationManager.add(new DeploymentConfigurationReadOnly( DeploymentKey.server.value(properties, i), DeploymentKey.adminUser.value(properties, i), DeploymentKey.adminPassword.value(properties, i), Boolean.parseBoolean(DeploymentKey.sslHttps.value(properties, i)), Boolean.parseBoolean(DeploymentKey.sslTrustCert.value(properties, i)), Boolean.parseBoolean(DeploymentKey.assembleXsl.value(properties, i)))); } } } catch (Exception e) { logException(e, "Unable to load deployment configurations from PSC"); } }
From source file:com.virtualparadigm.packman.processor.JPackageManagerOld.java
public static Properties validate(File tempDir) { logger.info("PackageManager::validate()"); // INVALID (return empty properties) IF: // package.properties not found // package properties does not contain name and version // found installed version greater than package to be installed Properties packageProperties = new Properties(); InputStream packagePropInputStream = null; try {// w ww . j av a 2 s . co m packagePropInputStream = new FileInputStream( new File(tempDir.getAbsolutePath() + "/" + JPackageManagerOld.METADATA_DIR_NAME + "/" + JPackageManagerOld.PACKAGE_PROPERTIES_FILE_NAME)); packageProperties.load(packagePropInputStream); logger.info(" loaded package properties."); } catch (IOException ioe) { logger.error("", ioe); } finally { if (packagePropInputStream != null) { try { packagePropInputStream.close(); } catch (Exception e) { logger.error("", e); } } } if (packageProperties.containsKey(JPackageManagerOld.PACKAGE_NAME_KEY) && packageProperties.containsKey(JPackageManagerOld.PACKAGE_VERSION_KEY)) { VersionNumber installedVersionNumber = null; Package installPackage = JPackageManagerOld .findInstalledPackage(packageProperties.getProperty(PACKAGE_NAME_KEY)); if (installPackage == null) { installedVersionNumber = new VersionNumber("0"); } else { installedVersionNumber = installPackage.getVersionNumber(); } if (installedVersionNumber.compareTo(new VersionNumber( packageProperties.getProperty(JPackageManagerOld.PACKAGE_VERSION_KEY))) >= 0) { logger.info(" installed version is more recent."); //installed version greater than or equal to package to install packageProperties = null; } } else { logger.info(" could not find package.name or package.version values for new package."); //return null to signify error/invalid packageProperties = null; } return packageProperties; }
From source file:info.magnolia.jcr.util.PropertiesImportExport.java
/** * Each property or node in the stream has to be separated by the \n. *///from www . ja v a 2s.c om public void createNodes(Node root, InputStream propertiesStream) throws IOException, RepositoryException { Properties properties = new OrderedProperties(); properties.load(propertiesStream); properties = keysToInnerFormat(properties); for (Object o : properties.keySet()) { String key = (String) o; String valueStr = properties.getProperty(key); String propertyName = StringUtils.substringAfterLast(key, "."); String path = StringUtils.substringBeforeLast(key, "."); String type = null; if (propertyName.equals("@type")) { type = valueStr; } else if (properties.containsKey(path + ".@type")) { type = properties.getProperty(path + ".@type"); } type = StringUtils.defaultIfEmpty(type, NodeTypes.ContentNode.NAME); Node c = NodeUtil.createPath(root, path, type); populateNode(c, propertyName, valueStr); } }
From source file:com.piusvelte.taplock.server.ConnectionThread.java
@SuppressWarnings("unchecked") @Override/* w w w. j av a2 s . co m*/ public void run() { TapLockServer.writeLog("ConnectionThread started"); // retrieve the local Bluetooth device object // setup the server to listen for connection try { local = LocalDevice.getLocalDevice(); local.setDiscoverable(DiscoveryAgent.GIAC); // String url = "btspp://localhost:" + mRemoteAuthServerUUID.toString() + ";master=false;encrypt=false;authenticate=false;name=" + sSPD; String url = "btspp://localhost:" + sTapLockUUID.toString() + ";name=" + sSPD; notifier = (StreamConnectionNotifier) Connector.open(url); } catch (Exception e) { // no bluetooth present TapLockServer.writeLog("notifier init: " + e.getMessage()); TapLockServer.shutdown(); return; } JSONParser jsonParser = new JSONParser(); while (notifier != null) { TapLockServer.writeLog("waiting for connection..."); try { btConnection = notifier.acceptAndOpen(); } catch (IOException e) { TapLockServer.writeLog("notifier.acceptAndOpen: " + e.getMessage()); btConnection = null; } if (btConnection != null) { TapLockServer.writeLog("new connection..."); try { btInStream = btConnection.openInputStream(); btOutStream = btConnection.openOutputStream(); } catch (IOException e) { TapLockServer.writeLog("inStream and outStream open: " + e.getMessage()); } if ((btInStream != null) && (btOutStream != null)) { // send the challenge String challenge = Long.toString(System.currentTimeMillis()); TapLockServer.writeLog("init challenge: " + challenge); JSONObject responseJObj = new JSONObject(); responseJObj.put(TapLockServer.PARAM_CHALLENGE, challenge); String responseStr = responseJObj.toJSONString(); try { btOutStream.write(responseStr.getBytes()); } catch (IOException e) { TapLockServer.writeLog("outStream.write: " + e.getMessage()); } // prepare to receive data byte[] btBuffer = new byte[1024]; int btReadBytes = -1; try { btReadBytes = btInStream.read(btBuffer); } catch (IOException e) { TapLockServer.writeLog("inStream.read: " + e.getMessage()); } while (btReadBytes != -1) { responseJObj.clear(); String requestStr = new String(btBuffer, 0, btReadBytes); TapLockServer.writeLog("request: " + requestStr); JSONObject requestJObj = null; try { requestJObj = (JSONObject) jsonParser.parse(requestStr); } catch (ParseException e) { TapLockServer.writeLog("jsonParser.parse: " + e.getMessage()); } if (requestJObj != null) { if ((requestJObj != null) && requestJObj.containsKey(TapLockServer.PARAM_ACTION) && requestJObj.containsKey(TapLockServer.PARAM_HMAC)) { String requestAction = (String) requestJObj.get(TapLockServer.PARAM_ACTION); TapLockServer.writeLog("action: " + requestAction); String requestPassphrase = (String) requestJObj.get(TapLockServer.PARAM_PASSPHRASE); if (requestPassphrase == null) requestPassphrase = ""; String requestHMAC = (String) requestJObj.get(TapLockServer.PARAM_HMAC); String validHMAC = null; try { validHMAC = TapLockServer.getHashString(challenge + TapLockServer.sPassphrase + requestAction + requestPassphrase); } catch (NoSuchAlgorithmException e) { TapLockServer.writeLog("getHashString: " + e.getMessage()); } catch (UnsupportedEncodingException e) { TapLockServer.writeLog("getHashString: " + e.getMessage()); } if (requestHMAC.equals(validHMAC)) { if (TapLockServer.ACTION_PASSPHRASE.equals(requestAction)) TapLockServer.setPassphrase(requestPassphrase); else { if (TapLockServer.OS == TapLockServer.OS_WIN) { if (TapLockServer.ACTION_LOCK.equals(requestAction)) runCommand("rundll32.exe user32.dll, LockWorkStation"); else { // either unlock or toggle String password = ""; Properties prop = new Properties(); try { prop.load(new FileInputStream(TapLockServer.sProperties)); if (prop.containsKey(TapLockServer.sPasswordKey)) password = TapLockServer.decryptString( prop.getProperty(TapLockServer.sPasswordKey)); } catch (FileNotFoundException e) { TapLockServer.writeLog("prop load: " + e.getMessage()); } catch (IOException e) { TapLockServer.writeLog("prop load: " + e.getMessage()); } Socket cpSocket = null; try { cpSocket = new Socket(TapLockServer.S_LOCALHOST, TapLockServer.SERVER_PORT); } catch (UnknownHostException e) { TapLockServer.writeLog("socket: " + e.getMessage()); } catch (IOException e) { TapLockServer.writeLog("socket: " + e.getMessage()); } if (cpSocket != null) { InputStream cpInStream = null; OutputStream cpOutStream = null; try { cpInStream = cpSocket.getInputStream(); cpOutStream = cpSocket.getOutputStream(); } catch (IOException e) { TapLockServer.writeLog("in/out stream: " + e.getMessage()); } if ((cpInStream != null) && (cpOutStream != null)) { // get the version byte[] cpBuffer = new byte[1]; int cpReadBytes = -1; try { cpReadBytes = cpInStream.read(cpBuffer); } catch (IOException e) { TapLockServer .writeLog("instream read: " + e.getMessage()); } if (cpReadBytes != -1) { TapLockServer.writeLog("credential provider version: " + new String(cpBuffer, 0, cpReadBytes)); // pack the credentials byte[] usernameBytes = System.getProperty("user.name") .getBytes(Charset.forName("UTF-8")); byte[] passwordBytes = password .getBytes(Charset.forName("UTF-8")); byte[] credentialsBuf = new byte[TapLockServer.S_CREDBUF]; for (int i = 0, l = usernameBytes.length; (i < l) && (i < TapLockServer.S_USERBUF); i++) credentialsBuf[i] = usernameBytes[i]; for (int i = 0, l = passwordBytes.length; (i < l) && (i < TapLockServer.S_PASSBUF); i++) credentialsBuf[i + TapLockServer.S_USERBUF] = passwordBytes[i]; try { cpOutStream.write(credentialsBuf); } catch (IOException e) { TapLockServer.writeLog( "cpOutStream write: " + e.getMessage()); } cpReadBytes = -1; try { cpReadBytes = cpInStream.read(credentialsBuf); } catch (IOException e) { TapLockServer.writeLog( "cpInStream read: " + e.getMessage()); } // the socket should return "0" if no errors if (cpReadBytes != -1) { String cpResult = new String(credentialsBuf, 0, cpReadBytes); TapLockServer.writeLog( "credential provider result: " + cpResult); if (!TapLockServer.CREDENTIAL_PROVIDER_SUCCESS .equals(cpResult)) responseJObj.put(TapLockServer.PARAM_ERROR, "Authentication error, is the Windows password set in Tap Lock Server?"); } try { cpOutStream.close(); } catch (IOException e) { TapLockServer.writeLog( "output close: " + e.getMessage()); } try { cpInStream.close(); } catch (IOException e) { TapLockServer .writeLog("in close: " + e.getMessage()); } try { cpSocket.close(); } catch (IOException e) { TapLockServer.writeLog( "socket close: " + e.getMessage()); } } } } else runCommand("rundll32.exe user32.dll, LockWorkStation"); } } else if (TapLockServer.OS == TapLockServer.OS_NIX) { if (TapLockServer.ACTION_TOGGLE.equals(requestAction)) requestAction = TapLockServer.getToggleAction(); String command = null; if (TapLockServer.ACTION_LOCK.equals(requestAction)) command = "gnome-screensaver-command -a"; else if (TapLockServer.ACTION_UNLOCK.equals(requestAction)) command = "gnome-screensaver-command -d"; if (command != null) runCommand(command); } } } else { TapLockServer.writeLog("authentication failed"); responseJObj.put(TapLockServer.PARAM_ERROR, "authentication failed"); } } else { TapLockServer.writeLog("invalid request"); responseJObj.put(TapLockServer.PARAM_ERROR, "invalid request"); } } else { TapLockServer.writeLog("failed to parse request"); responseJObj.put(TapLockServer.PARAM_ERROR, "failed to parse request"); } // send the new challenge challenge = Long.toString(System.currentTimeMillis()); TapLockServer.writeLog("next challenge: " + challenge); responseJObj.put(TapLockServer.PARAM_CHALLENGE, challenge); responseStr = responseJObj.toJSONString(); try { btOutStream.write(responseStr.getBytes()); } catch (IOException e) { TapLockServer.writeLog("outStream.write: " + e.getMessage()); } try { btReadBytes = btInStream.read(btBuffer); } catch (IOException e) { TapLockServer.writeLog("inStream.read: " + e.getMessage()); } } if (btInStream != null) { try { btInStream.close(); } catch (IOException e) { TapLockServer.writeLog("inStream.close: " + e.getMessage()); } } if (btOutStream != null) { try { btOutStream.close(); } catch (IOException e) { TapLockServer.writeLog("outStream.close: " + e.getMessage()); } } } if (btConnection != null) { try { btConnection.close(); } catch (IOException e) { TapLockServer.writeLog("connection.close: " + e.getMessage()); } btConnection = null; } } } }
From source file:io.warp10.script.WarpScriptLib.java
public static void registerExtensions() { Properties props = WarpConfig.getProperties(); if (null == props) { return;/* www . j av a 2s . co m*/ } // // Extract the list of extensions // Set<String> ext = new LinkedHashSet<String>(); if (props.containsKey(Configuration.CONFIG_WARPSCRIPT_EXTENSIONS)) { String[] extensions = props.getProperty(Configuration.CONFIG_WARPSCRIPT_EXTENSIONS).split(","); for (String extension : extensions) { ext.add(extension.trim()); } } for (Object key : props.keySet()) { if (!key.toString().startsWith(Configuration.CONFIG_WARPSCRIPT_EXTENSION_PREFIX)) { continue; } ext.add(props.get(key).toString().trim()); } // Sort the extensions List<String> sortedext = new ArrayList<String>(ext); sortedext.sort(null); boolean failedExt = false; // // Determine the possible jar from which WarpScriptLib was loaded // String wsljar = null; URL wslurl = WarpScriptLib.class .getResource('/' + WarpScriptLib.class.getCanonicalName().replace('.', '/') + ".class"); if (null != wslurl && "jar".equals(wslurl.getProtocol())) { wsljar = wslurl.toString().replaceAll("!/.*", "").replaceAll("jar:file:", ""); } for (String extension : sortedext) { // If the extension name contains '#', remove everything up to the last '#', this was used as a sorting prefix if (extension.contains("#")) { extension = extension.replaceAll("^.*#", ""); } try { // // Locate the class using the current class loader // URL url = WarpScriptLib.class.getResource('/' + extension.replace('.', '/') + ".class"); if (null == url) { LOG.error("Unable to load extension '" + extension + "', make sure it is in the class path."); failedExt = true; continue; } Class cls = null; // // If the class was located in a jar, load it using a specific class loader // so we can have fat jars with specific deps, unless the jar is the same as // the one from which WarpScriptLib was loaded, in which case we use the same // class loader. // if ("jar".equals(url.getProtocol())) { String jarfile = url.toString().replaceAll("!/.*", "").replaceAll("jar:file:", ""); ClassLoader cl = WarpScriptLib.class.getClassLoader(); // If the jar differs from that from which WarpScriptLib was loaded, create a dedicated class loader if (!jarfile.equals(wsljar)) { cl = new WarpClassLoader(jarfile, WarpScriptLib.class.getClassLoader()); } cls = Class.forName(extension, true, cl); } else { cls = Class.forName(extension, true, WarpScriptLib.class.getClassLoader()); } //Class cls = Class.forName(extension); WarpScriptExtension wse = (WarpScriptExtension) cls.newInstance(); wse.register(); System.out.println("LOADED extension '" + extension + "'"); } catch (Exception e) { throw new RuntimeException(e); } } if (failedExt) { throw new RuntimeException("Some WarpScript extensions could not be loaded, aborting."); } }
From source file:com.ellychou.todo.rest.service.SpringContextJerseyTest.java
private String getProperty(String propertyName) { if (forcedPropertyMap.containsKey(propertyName)) { return forcedPropertyMap.get(propertyName); }// w ww . j a va2 s.c o m final Properties systemProperties = AccessController.doPrivileged(PropertiesHelper.getSystemProperties()); if (systemProperties.containsKey(propertyName)) { return systemProperties.getProperty(propertyName); } if (propertyMap.containsKey(propertyName)) { return propertyMap.get(propertyName); } return null; }
From source file:eu.planets_project.tb.impl.data.util.DataHandlerImpl.java
private String getInputFileIndexEntryName(File localFileRef) { if ((localFileRef != null) && (localFileRef.canRead())) { try {/*w w w. j av a2 s . c o m*/ //get the index where a mapping of stored file name - original name is stored Properties props = this.getInputDirIndex(); //fileName corresponds to a random number if (props.containsKey(localFileRef.getName())) { //return the corresponding name from the index return props.getProperty(localFileRef.getName()); } } catch (IOException e) { // TODO Auto-generated catch block log.debug("index file name for " + localFileRef.getName() + " was not found"); } } //else if no name was found return the physical file name return localFileRef.getName(); }
From source file:eu.planets_project.tb.impl.data.util.DataHandlerImpl.java
private String getOutputFileIndexEntryName(File localFileRef) { if ((localFileRef != null) && (localFileRef.canRead())) { try {/*w w w. j a v a 2 s . c o m*/ //get the index where a mapping of stored file name - original name is stored Properties props = this.getOutputDirIndex(); //fileName corresponds to a random number if (props.containsKey(localFileRef.getName())) { //return the corresponding name from the index return props.getProperty(localFileRef.getName()); } } catch (IOException e) { // TODO Auto-generated catch block log.debug("index file name for " + localFileRef.getName() + " was not found"); } } //else if no name was found return the physical file name return localFileRef.getName(); }
From source file:org.apache.stratos.python.cartridge.agent.integration.tests.PythonAgentIntegrationTest.java
/** * Setup method for test method testPythonCartridgeAgent *///w ww .ja v a 2 s . c o m protected void setup(int timeout) throws Exception { messageBrokers = new HashMap<>(); distributionName = integrationProperties.getProperty(DISTRIBUTION_NAME); cepPort = Integer.parseInt(integrationProperties.getProperty(CEP_PORT)); cepSSLPort = Integer.parseInt(integrationProperties.getProperty(CEP_SSL_PORT)); Properties jndiProperties = new Properties(); jndiProperties.load(new FileInputStream( new File(System.getProperty("jndi.properties.dir") + PATH_SEP + "jndi.properties"))); if (!jndiProperties.containsKey(ACTIVEMQ_AMQP_BIND_PORTS) || !jndiProperties.containsKey(ACTIVEMQ_MQTT_BIND_PORTS)) { amqpBindPorts = integrationProperties.getProperty(ACTIVEMQ_AMQP_BIND_PORTS).split(","); mqttBindPorts = integrationProperties.getProperty(ACTIVEMQ_MQTT_BIND_PORTS).split(","); } else { amqpBindPorts = jndiProperties.getProperty(ACTIVEMQ_AMQP_BIND_PORTS).split(","); mqttBindPorts = jndiProperties.getProperty(ACTIVEMQ_MQTT_BIND_PORTS).split(","); } if (amqpBindPorts.length != mqttBindPorts.length) { throw new RuntimeException( "The number of AMQP ports and MQTT ports should be equal in integration-test.properties."); } // start ActiveMQ test server for (int i = 0; i < amqpBindPorts.length; i++) { log.info("Starting ActiveMQ instance with AMQP: " + amqpBindPorts[i] + ", MQTT: " + mqttBindPorts[i]); startActiveMQInstance(Integer.parseInt(amqpBindPorts[i]), Integer.parseInt(mqttBindPorts[i]), true); } //ExecutorService executorService = StratosThreadPool.getExecutorService // ("TEST_THREAD_POOL"); topologyEventReceiver = TopologyEventReceiver.getInstance(); // topologyEventReceiver.setExecutorService(executorService); // topologyEventReceiver.execute(); instanceStatusEventReceiver = InstanceStatusEventReceiver.getInstance(); // instanceStatusEventReceiver.setExecutorService(executorService); // instanceStatusEventReceiver.execute(); instanceStatusEventReceiver.addEventListener(new InstanceStartedEventListener() { @Override protected void onEvent(Event event) { log.info("Instance started event received"); instanceStarted = true; } }); instanceStatusEventReceiver.addEventListener(new InstanceActivatedEventListener() { @Override protected void onEvent(Event event) { log.info("Instance activated event received"); instanceActivated = true; } }); initializerEventReceiver = InitializerEventReceiver.getInstance(); this.eventReceiverInitialized = true; // Start CEP Thrift test server thriftTestServer = new ThriftTestServer(); File file = new File( getResourcesPath() + PATH_SEP + "common" + PATH_SEP + "stratos-health-stream-def.json"); FileInputStream fis = new FileInputStream(file); String str = IOUtils.toString(fis, "UTF-8"); if (str.equals("")) { log.warn("Stream definition of health stat stream is empty. Thrift server will not function properly"); } thriftTestServer.addStreamDefinition(str, -1234); // start with non-ssl port; test server will automatically bind to ssl port thriftTestServer.start(cepPort); log.info("Started Thrift server with stream definition: " + str); agentPath = setupPythonAgent(); log.info("Python agent working directory name: " + PYTHON_AGENT_DIR_NAME); log.info("Starting python cartridge agent..."); this.outputStream = executeCommand("python " + agentPath + PATH_SEP + "agent.py", timeout); }