Example usage for java.util Properties get

List of usage examples for java.util Properties get

Introduction

In this page you can find the example usage for java.util Properties get.

Prototype

@Override
    public Object get(Object key) 

Source Link

Usage

From source file:net.bubble.common.utils.PropertiesUtil.java

@Override
protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess, Properties props)
        throws BeansException {
    contextProperties = new HashMap<String, String>();
    for (Object key : props.keySet()) {
        if (logger.isDebugEnabled()) {
            logger.debug("load property content: {}={}", String.valueOf(key), props.get(String.valueOf(key)));
        }//from  ww w.ja  v  a  2s  . com
        contextProperties.put(String.valueOf(key), String.valueOf(props.get(String.valueOf(key))));
    }
    super.processProperties(beanFactoryToProcess, props);
}

From source file:io.syndesis.maven.ExtractConnectorDescriptorsMojo.java

@SuppressWarnings("PMD.AvoidCatchingGenericException")
private String extractComponentJavaType(ClassLoader classLoader, String scheme) {
    try {/* w w w  .  j  av a 2s.  c o  m*/
        InputStream is = classLoader
                .getResourceAsStream("META-INF/services/org/apache/camel/component/" + scheme);
        if (is != null) {
            Properties props = new Properties();
            props.load(is);
            return (String) props.get("class");
        }
    } catch (Exception e) {
        getLog().warn("WARN: Error loading META-INF/services/org/apache/camel/component/" + scheme
                + " file due " + e.getMessage());
    }
    return null;
}

From source file:com.dc.tes.adapter.startup.remote.StartUpRemoteForRequest.java

private void startAdapter(Properties props) {
    String adapterName = props.getProperty("CHANNELNAME");

    IRequestAdapter adapterInstance = null;
    try {/*  w w w.  ja  va 2 s  .  co  m*/
        String clsName = "com.dc.tes.adapterlib." + (String) props.get("adapterPlugIn");
        adapterInstance = (IRequestAdapter) ConfigHelper.class.getClassLoader().loadClass(clsName)
                .newInstance();
        System.out.println("????" + clsName);

        // License
        m_props.setProperty("SIMTYPE", adapterInstance.AdapterType());

        m_adpterHelper = new DefaultRequestAdapterHelper(m_props, adapterInstance);

        // 
        byte[] config = m_adpterHelper.reg2TES();

        // ?
        if (adapterInstance.Init(new DefaultRequestAdapterEnvContext(config))) {
            m_adpterHelper.SetConfigProperty(adapterInstance.GetAdapterConfigProperties());
            System.out.println("??" + adapterName + "?Init?.");

            log.info("???" + adapterName + "?Init?.");
            log.error("???" + adapterName + "?Init?.");

            // ???
            m_adpterHelper.startServer();
        } else {
            m_adpterHelper.unReg2TES();
            // ?m_requestAdapterHelper.stopServer()

            System.out.println("???" + adapterName + "?Init.");
            log.error("???" + adapterName + "?Init.");
        }

    } catch (InstantiationException e) {
        log.error("?!?");
        System.out.println("?!?");
        // ?stopServer
    } catch (IllegalAccessException e) {
        log.error("?!?[" + e.getMessage() + "]");
        System.out.println("?!?[" + e.getMessage() + "]");
        // ?stopServer
    } catch (ClassNotFoundException e) {
        log.error("??!?[" + e.getMessage() + "]");
        System.out.println("??!?[" + e.getMessage() + "]");
        // ?stopServer
    } catch (ClosedByInterruptException e) {
        // ??
        shutdownAdapter();
        log.info("??" + adapterName + "");
        System.out.println("??" + adapterName + "");
    } catch (Exception e) {
        // ??
        shutdownAdapter();
        log.error("?" + adapterName + "?![" + e.getMessage() + "]");
        System.out.println("?" + adapterName + "?![" + e.getMessage() + "]");
    }

    System.out.println("??" + adapterName + "??.");
    log.info("??" + adapterName + "??.");
}

From source file:com.goodformobile.build.mobile.GenerateRAPCMojoTest.java

@Test
public void testIconIsInferredFromIconPNG() throws Exception {

    setPluginConfigFileName("com/goodformobile/build/mobile/generate-rapc-infer-icon-plugin-config.xml");
    AbstractRIMBuildMojo mojo = setupMojo();

    MavenProject project = getProject(mojo);
    project.getBuild().setOutputDirectory(
            getBasedir() + File.separator + "src/test/resources/projects/app-with-dependency/res");

    File buildDirectory = new File(getBasedir(), "target/test/unit/generate-rapc-mojo-basic-test/target");
    setupBuildDirectory(buildDirectory);
    project.getBuild().setDirectory(buildDirectory.getAbsolutePath());

    mojo.execute();/*from  w w  w .j a v a 2s. com*/

    File propertiesFile = new File(getBasedir(),
            "target/test/unit/generate-rapc-mojo-basic-test/target/rapc/maven_blackberry_plugin_test.rapc");
    assertTrue("Properties File not found.", propertiesFile.exists());
    Properties result = PropertyUtils.loadProperties(propertiesFile);
    assertNotNull(result);
    assertEquals(project.getName() + ",img/icon.png,", result.get("MIDlet-1"));
}

From source file:org.greencheek.utils.environment.propertyplaceholder.resolver.value.VariablePlaceholderValueResolver.java

public String resolvedPropertyValue(Properties properties, String key, boolean trimValues) {
    if (properties.get(key) == null)
        return null;
    return parseStringValue(properties.getProperty(key), new HashMap(properties), new HashSet<String>(),
            trimValues);// w w  w. java 2s . co m
}

From source file:net.sf.appstatus.web.StatusWebHandler.java

/**
 * Does the initialization work./*  w w  w  .j a v a2  s . c o m*/
 * <p>
 * Read configuration from /status-web-conf.properties
 * <p>
 * If you need to inject custom objects using these methods, please do it
 * before calling init.
 * <ul>
 * <li>{@link #setPages(Map)}</li>
 * <li>{@link #setAppStatus(AppStatus)}</li>
 * <li>{@link #setCssLocation(String)}</li>
 * </ul>
 */
public void init() {

    // init AppStatus
    if (appStatus == null) {
        // Use default instance if not set
        appStatus = AppStatusStatic.getInstance();
    }
    appStatus.init();
    InputStream is = null;

    // Load specific configuration
    try {
        is = Thread.currentThread().getContextClassLoader().getResourceAsStream(STATUS_WEB_CONF_PROPERTIES);

        if (is == null) {
            logger.warn("/status-web-conf.properties not found in classpath. Using default configuration");
        } else {
            Properties p = new Properties();
            p.load(is);

            if (allowIp == null) {
                allowIp = (String) p.get("ip.allow");
            }
        }
    } catch (Exception e) {
        logger.error("Error loading configuration from /status-web-conf.properties.", e);
    } finally {
        try {
            if (is != null) {
                is.close();
            }
        } catch (Exception e) {
            logger.warn(String.format("Error in close resource [%s]", STATUS_WEB_CONF_PROPERTIES), e);
        }
    }

    // Init css & js
    if (cssLocation == null) {
        cssLocation = "?resource=appstatus.css";
        Resources.addResource("appstatus.css", "/assets/css/appstatus.css", "text/css");
        Resources.addResource("bootstrap.js", "/assets/js/bootstrap.js", "application/javascript");
        Resources.addResource("jquery.js", "/assets/js/jquery-2.0.1.min.js", "application/javascript");
        Resources.addResource("glyphicons-halflings.png", "/assets/img/glyphicons-halflings.png", "image/png");
        Resources.addResource("glyphicons-halflings-white.png", "/assets/img/glyphicons-halflings-white.png",
                "image/png");
    }
}

From source file:com.cws.esolutions.core.utils.EmailUtils.java

/**
 * Processes and sends an email message as generated by the requesting
 * application. This method is utilized with a JNDI datasource.
 *
 * @param mailConfig - The {@link com.cws.esolutions.core.config.xml.MailConfig} to utilize
 * @param message - The email message/* w ww .j  ava  2s .  c  o  m*/
 * @param isWeb - <code>true</code> if this came from a container, <code>false</code> otherwise
 * @throws MessagingException {@link javax.mail.MessagingException} if an exception occurs sending the message
 */
public static final synchronized void sendEmailMessage(final MailConfig mailConfig, final EmailMessage message,
        final boolean isWeb) throws MessagingException {
    final String methodName = EmailUtils.CNAME
            + "#sendEmailMessage(final MailConfig mailConfig, final EmailMessage message, final boolean isWeb) throws MessagingException";

    Session mailSession = null;

    if (DEBUG) {
        DEBUGGER.debug(methodName);
        DEBUGGER.debug("Value: {}", mailConfig);
        DEBUGGER.debug("Value: {}", message);
        DEBUGGER.debug("Value: {}", isWeb);
    }

    SMTPAuthenticator smtpAuth = null;

    if (DEBUG) {
        DEBUGGER.debug("MailConfig: {}", mailConfig);
    }

    try {
        if (isWeb) {
            Context initContext = new InitialContext();
            Context envContext = (Context) initContext.lookup(EmailUtils.INIT_DS_CONTEXT);

            if (DEBUG) {
                DEBUGGER.debug("InitialContext: {}", initContext);
                DEBUGGER.debug("Context: {}", envContext);
            }

            if (envContext != null) {
                mailSession = (Session) envContext.lookup(mailConfig.getDataSourceName());
            }
        } else {
            Properties mailProps = new Properties();

            try {
                mailProps.load(
                        EmailUtils.class.getClassLoader().getResourceAsStream(mailConfig.getPropertyFile()));
            } catch (NullPointerException npx) {
                try {
                    mailProps.load(new FileInputStream(mailConfig.getPropertyFile()));
                } catch (IOException iox) {
                    throw new MessagingException(iox.getMessage(), iox);
                }
            } catch (IOException iox) {
                throw new MessagingException(iox.getMessage(), iox);
            }

            if (DEBUG) {
                DEBUGGER.debug("Properties: {}", mailProps);
            }

            if (StringUtils.equals((String) mailProps.get("mail.smtp.auth"), "true")) {
                smtpAuth = new SMTPAuthenticator();
                mailSession = Session.getDefaultInstance(mailProps, smtpAuth);
            } else {
                mailSession = Session.getDefaultInstance(mailProps);
            }
        }

        if (DEBUG) {
            DEBUGGER.debug("Session: {}", mailSession);
        }

        if (mailSession == null) {
            throw new MessagingException("Unable to configure email services");
        }

        mailSession.setDebug(DEBUG);
        MimeMessage mailMessage = new MimeMessage(mailSession);

        // Our emailList parameter should contain the following
        // items (in this order):
        // 0. Recipients
        // 1. From Address
        // 2. Generated-From (if blank, a default value is used)
        // 3. The message subject
        // 4. The message content
        // 5. The message id (optional)
        // We're only checking to ensure that the 'from' and 'to'
        // values aren't null - the rest is really optional.. if
        // the calling application sends a blank email, we aren't
        // handing it here.
        if (message.getMessageTo().size() != 0) {
            for (String to : message.getMessageTo()) {
                if (DEBUG) {
                    DEBUGGER.debug(to);
                }

                mailMessage.setRecipient(Message.RecipientType.TO, new InternetAddress(to));
            }

            mailMessage.setFrom(new InternetAddress(message.getEmailAddr().get(0)));
            mailMessage.setSubject(message.getMessageSubject());
            mailMessage.setContent(message.getMessageBody(), "text/html");

            if (message.isAlert()) {
                mailMessage.setHeader("Importance", "High");
            }

            Transport mailTransport = mailSession.getTransport("smtp");

            if (DEBUG) {
                DEBUGGER.debug("Transport: {}", mailTransport);
            }

            mailTransport.connect();

            if (mailTransport.isConnected()) {
                Transport.send(mailMessage);
            }
        }
    } catch (MessagingException mex) {
        throw new MessagingException(mex.getMessage(), mex);
    } catch (NamingException nx) {
        throw new MessagingException(nx.getMessage(), nx);
    }
}

From source file:io.cloudslang.lang.tools.build.ArgumentProcessorUtilsTest.java

@Test
public void testGetPropertiesFromFileThrowsException() throws URISyntaxException, IOException {
    InputStream fis = null;/*from   w  ww . j  a v a 2  s.c o  m*/
    Writer outputWriter = null;
    File tempRunConfigFile = null;
    try {
        fis = new FileInputStream(
                new File(getResource("lang/tools/build/builder_run_configuration.properties").toURI()));
        Path tempRunConfig = Files.createTempFile("temp_run_config", ".properties");

        tempRunConfigFile = tempRunConfig.toFile();
        outputWriter = new PrintWriter(new FileWriter(tempRunConfigFile));
        IOUtils.copy(fis, outputWriter);
        outputWriter.flush();

        String absolutePath = tempRunConfigFile.getAbsolutePath();
        Properties propertiesFromFile = getPropertiesFromFile(absolutePath);
        assertEquals("false", propertiesFromFile.get(TEST_COVERAGE));
        assertEquals("sequential", propertiesFromFile.get(TEST_SUITES_RUN_UNSPECIFIED));
        assertEquals("!default,vmware-local,xml-local,images", propertiesFromFile.get(TEST_SUITES_TO_RUN));
        assertEquals("images", propertiesFromFile.get(TEST_SUITES_SEQUENTIAL));
        assertEquals("xml-local,vmware-local", propertiesFromFile.get(TEST_SUITES_PARALLEL));
        assertEquals("8", propertiesFromFile.get(TEST_PARALLEL_THREAD_COUNT));
    } finally {
        IOUtils.closeQuietly(fis);
        IOUtils.closeQuietly(outputWriter);
        FileUtils.deleteQuietly(tempRunConfigFile);
    }
}

From source file:org.openspaces.esb.mule.eventcontainer.OpenSpacesMessageReceiver.java

/**
 * Extract the workManager setting from the URI. If the atrribute is missing sets
 * it to the default (<code>false</code>).
 *///from  ww w.  ja  va2s  .co m
private void initWritingAttributes(ImmutableEndpoint endpoint) {
    Properties params = endpoint.getEndpointURI().getParams();
    if (params != null) {
        try {
            String workManager = (String) params.get(ENDPOINT_PARAM_WORK_MANAGER);
            if (workManager != null) {
                this.workManager = Boolean.valueOf(workManager);
            }
        } catch (Exception e) {
            throw new MuleRuntimeException(
                    CoreMessages.failedToCreateConnectorFromUri(endpoint.getEndpointURI()), e);
        }
    }
}

From source file:de.uni_koeln.spinfo.maalr.configuration.Environment.java

public Environment() {
    version = "Unknown";
    configuration = Configuration.getInstance();
    configuration.getLemmaDescription().setDefaultEscaper(new Escaper() {

        @Override//  w w  w.ja v  a 2s . com
        public String escape(String text) {
            return SafeHtmlUtils.htmlEscape(text);
        }
    });
    /*
     * Load application properties, which contain build and version
     * number
     */
    Properties props = new Properties();
    try {
        props.load(getClass().getClassLoader().getResourceAsStream("application.properties"));
    } catch (IOException e) {
        logger.error("Failed to read application properties!", e);
    }
    version = (String) props.get("application.version");
    name = (String) props.getProperty("application.name");

    appProperties = new AppProperties();
    appProperties.setAppName(name);
    appProperties.setAppVersion(version);
    configuration.getLemmaDescription();
    luceneConfig = new LuceneConfiguration();
    luceneConfig.setBaseDirectory(configuration.getLuceneDir());
    logger.info("**********************************************************************************");
    logger.info("Initializing " + appProperties.getAppName() + " " + appProperties.getAppVersion());
    logger.info("**********************************************************************************");
}