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:org.ops4j.pax.web.itest.base.TestConfiguration.java

public static Option paxCdiWithOwbBundles() {

    Properties props = new Properties();
    try {//w  w  w.j  a  v  a2  s .  c om
        props.load(TestConfiguration.class.getResourceAsStream("/systemPackages.properties"));
    } catch (IOException exc) {
        throw new Ops4jException(exc);
    }

    return composite(
            // do not treat javax.annotation as system package
            when(isEquinox()).useOptions(frameworkProperty("org.osgi.framework.system.packages")
                    .value(props.get("org.osgi.framework.system.packages"))),

            linkBundle("org.ops4j.pax.cdi.openwebbeans"),

            // there is a classloader conflict when adding this dep to the POM
            mavenBundle("org.ops4j.pax.cdi", "pax-cdi-undertow-openwebbeans", PAX_CDI_VERSION),

            mavenBundle("org.apache.openwebbeans", "openwebbeans-impl", "1.5.0"),
            mavenBundle("org.apache.openwebbeans", "openwebbeans-spi", "1.5.0"),
            mavenBundle("org.apache.openwebbeans", "openwebbeans-web", "1.5.0"),
            mavenBundle("org.apache.openwebbeans", "openwebbeans-el22", "1.5.0"),
            // needed by pax-cdi-web-openwebbeans
            mavenBundle("org.apache.geronimo.specs", "geronimo-jsp_2.2_spec", "1.2"),

            mavenBundle("org.apache.xbean", "xbean-asm5-shaded", "4.1"), //
            mavenBundle("org.apache.xbean", "xbean-finder-shaded", "4.1"), //
            //mavenBundle("org.slf4j", "jul-to-slf4j").versionAsInProject(),
            mavenBundle("org.apache.geronimo.specs", "geronimo-jta_1.1_spec", "1.1.1"),
            mavenBundle("javax.validation", "validation-api", "1.1.0.Final"),
            mavenBundle("javax.interceptor", "javax.interceptor-api", "1.2"),

            mavenBundle("javax.el", "javax.el-api", "3.0.0"));

}

From source file:podd.util.PoddWebappTestUtil.java

public static String getAdminProperty(String key) throws IOException {
    Properties adminProperties = new Properties();
    final URL url = getClassLoader().getResource("test.admin.properties");
    FileInputStream in = new FileInputStream(new File(url.getFile()));
    adminProperties.load(in);//w  ww .j a v a  2 s.  c  o m
    in.close();
    return adminProperties.get(key).toString();
}

From source file:com.cloudbees.sdk.Bees.java

/**
 * Parses the version number of SDK from the resource file that Maven produces.
 * <p/>//  w  ww  .j  av  a2s. c  om
 * To support running this from IDE and elsewhere, work gracefully if the version
 * is not available or not filtered.
 */
private static VersionNumber loadVersion() {
    Properties props = new Properties();
    InputStream in = Bees.class.getResourceAsStream("version.properties");
    if (in != null) {
        try {
            props.load(in);
        } catch (IOException e) {
            throw new Error(e);
        } finally {
            IOUtils.closeQuietly(in);
        }
    }
    Object v = props.get("version");
    if (v != null)
        try {
            return new VersionNumber(v.toString());
        } catch (Exception e) {
            // fall through
        }

    return new VersionNumber("0");
}

From source file:io.fabric8.forge.camel.commands.project.AbstractCamelProjectCommand.java

public static String extractComponentJavaType(Dependency dependency, String scheme) {
    try {/*w  w  w .  j ava2  s . c  om*/
        // is it a JAR file
        File file = dependency.getArtifact().getUnderlyingResourceObject();
        if (file != null && file.getName().toLowerCase().endsWith(".jar")) {
            URL url = new URL("file:" + file.getAbsolutePath());
            URLClassLoader child = new URLClassLoader(new URL[] { url });

            InputStream is = child
                    .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 (Throwable e) {
        // ignore
    }

    return null;
}

From source file:com.google.api.ads.adwords.awreporting.AwReporting.java

/**
 * Initialize the application context, adding the properties configuration file depending on the
 * specified path.//w  w w.  j ava 2s  . com
 *
 * @param propertiesPath the path to the file.
 * @param forceOnFileProcessor true if the processor will be created to run "on file"
 * @return the resource loaded from the properties file.
 * @throws IOException error opening the properties file.
 */
private static Properties initApplicationContextAndProperties(String propertiesPath,
        boolean forceOnFileProcessor) throws IOException {

    Resource resource = new ClassPathResource(propertiesPath);
    if (!resource.exists()) {
        resource = new FileSystemResource(propertiesPath);
    }
    LOGGER.trace("Innitializing Spring application context.");
    DynamicPropertyPlaceholderConfigurer.setDynamicResource(resource);
    Properties properties = PropertiesLoaderUtils.loadProperties(resource);

    // Selecting the XMLs to choose the Spring Beans to load.
    List<String> listOfClassPathXml = Lists.newArrayList();

    // Choose the DB type to use based properties file, default to MYSQL
    String dbType = (String) properties.get(AW_REPORT_MODEL_DB_TYPE);
    DataBaseType sqldbType = null;
    if (DataBaseType.MONGODB.name().equals(dbType)) {
        LOGGER.info("Using MONGO DB configuration properties.");
        listOfClassPathXml.add("classpath:aw-report-mongodb-beans.xml");
    } else {
        if (DataBaseType.MSSQL.name().equals(dbType)) {
            sqldbType = DataBaseType.MSSQL;
            LOGGER.info("Using MSSQL DB configuration properties.");
        } else {
            // default to MYSQL
            sqldbType = DataBaseType.MYSQL;
            LOGGER.info("Using MYSQL DB configuration properties.");
        }
        LOGGER.warn("Updating database schema, this could take a few minutes ...");
        listOfClassPathXml.add("classpath:aw-report-sql-beans.xml");
        LOGGER.warn("Done.");
    }

    // Choose the Processor type to use based properties file
    String processorType = (String) properties.get(AW_REPORT_PROCESSOR_TYPE);
    if (!forceOnFileProcessor && ProcessorType.ONMEMORY.name().equals(processorType)) {
        LOGGER.info("Using ONMEMORY Processor.");
        listOfClassPathXml.add("classpath:aw-report-processor-beans-onmemory.xml");
    } else {
        LOGGER.info("Using ONFILE Processor.");
        listOfClassPathXml.add("classpath:aw-report-processor-beans-onfile.xml");
    }

    appCtx = new ClassPathXmlApplicationContext();
    if (sqldbType != null) {
        appCtx.getEnvironment().setActiveProfiles(sqldbType.name());
    }

    appCtx.setConfigLocations(listOfClassPathXml.toArray(new String[listOfClassPathXml.size()]));
    appCtx.refresh();

    return properties;
}

From source file:com.esri.geoportal.commons.pdf.PdfUtils.java

/**
 * Generates a Dublin-Core XML string from the given PDF's metadata.
 * //from  ww  w  . java 2  s  .  c o m
 * @param pdfBytes the PDF file to parse
 * @param fileName the name of the PDF file. Used if the PDF metadata doesn't specify a title.
 * @param url the source location of the PDF file. Used to set the XML's "resource URL".
 * @param geometryServiceUrl url of a <a href="https://developers.arcgis.com/rest/services-reference/geometry-service.htm">geometry service</a> for reprojecting coordinates. 
 * 
 * @return Dublin-Core XML metadata
 */
public static byte[] generateMetadataXML(byte[] pdfBytes, String fileName, String url,
        String geometryServiceUrl) throws IOException {
    byte[] bytes = null;

    // Read in the PDF metadata.
    Properties metaProps = readMetadata(pdfBytes, fileName, geometryServiceUrl);

    // Build out the XML metadata
    if (metaProps != null) {
        Properties props = new Properties();
        props.put(WKAConstants.WKA_TITLE, metaProps.get(PdfUtils.PROP_TITLE));
        props.put(WKAConstants.WKA_DESCRIPTION, metaProps.get(PdfUtils.PROP_SUBJECT));
        props.put(WKAConstants.WKA_MODIFIED, metaProps.get(PdfUtils.PROP_MODIFICATION_DATE));
        props.put(WKAConstants.WKA_BBOX, metaProps.getOrDefault(PdfUtils.PROP_BBOX, DEFAULT_BBOX));
        props.put(WKAConstants.WKA_RESOURCE_URL, url);

        try {
            MapAttribute attr = AttributeUtils.fromProperties(props);
            Document document = new SimpleDcMetaBuilder().create(attr);
            bytes = XmlUtils.toString(document).getBytes("UTF-8");
        } catch (MetaException | TransformerException ex) {
            throw new IOException(ex);
        }
    }

    return bytes;
}

From source file:com.openideals.android.net.HttpManager.java

public static String doPost(String serviceEndpoint, Properties props) throws Exception {

    HttpClient httpClient = new DefaultHttpClient();

    HttpPost request = new HttpPost(serviceEndpoint);
    HttpResponse response = null;/*  ww  w.  jav a 2 s.co m*/
    HttpEntity entity = null;

    StringBuffer sbResponse = new StringBuffer();

    Enumeration<Object> enumProps = props.keys();
    String key, value = null;

    List<NameValuePair> nvps = new ArrayList<NameValuePair>();

    while (enumProps.hasMoreElements()) {
        key = (String) enumProps.nextElement();
        value = (String) props.get(key);
        nvps.add(new BasicNameValuePair(key, value));

        Log.i(TAG, "adding nvp:" + key + "=" + value);
    }

    UrlEncodedFormEntity uf = new UrlEncodedFormEntity(nvps, HTTP.UTF_8);

    Log.i(TAG, uf.toString());

    request.setEntity(uf);

    request.setHeader("Content-Type", POST_MIME_TYPE);

    Log.i(TAG, "http post request: " + request.toString());

    // Post, check and show the result (not really spectacular, but works):
    response = httpClient.execute(request);
    entity = response.getEntity();

    int status = response.getStatusLine().getStatusCode();

    // we assume that the response body contains the error message
    if (status != HttpStatus.SC_OK) {
        ByteArrayOutputStream ostream = new ByteArrayOutputStream();
        entity.writeTo(ostream);

        Log.e(TAG, " error status code=" + status);
        Log.e(TAG, ostream.toString());

        return null;
    } else {
        InputStream content = response.getEntity().getContent();
        // <consume response>

        BufferedReader reader = new BufferedReader(new InputStreamReader(content));
        String line;

        while ((line = reader.readLine()) != null)
            sbResponse.append(line);

        content.close(); // this will also close the connection

        return sbResponse.toString();
    }

}

From source file:info.guardianproject.net.http.HttpManager.java

public static String doPost(String serviceEndpoint, Properties props) throws Exception {

    DefaultHttpClient httpClient = new SocksHttpClient();

    HttpPost request = new HttpPost(serviceEndpoint);
    HttpResponse response = null;//  w  ww  .jav a2s . c om
    HttpEntity entity = null;

    StringBuffer sbResponse = new StringBuffer();

    Enumeration<Object> enumProps = props.keys();
    String key, value = null;

    List<NameValuePair> nvps = new ArrayList<NameValuePair>();

    while (enumProps.hasMoreElements()) {
        key = (String) enumProps.nextElement();
        value = (String) props.get(key);
        nvps.add(new BasicNameValuePair(key, value));

        Log.i(TAG, "adding nvp:" + key + "=" + value);
    }

    UrlEncodedFormEntity uf = new UrlEncodedFormEntity(nvps, HTTP.UTF_8);

    Log.i(TAG, uf.toString());

    request.setEntity(uf);

    request.setHeader("Content-Type", POST_MIME_TYPE);

    Log.i(TAG, "http post request: " + request.toString());

    // Post, check and show the result (not really spectacular, but works):
    response = httpClient.execute(request);
    entity = response.getEntity();

    int status = response.getStatusLine().getStatusCode();

    // we assume that the response body contains the error message
    if (status != HttpStatus.SC_OK) {
        ByteArrayOutputStream ostream = new ByteArrayOutputStream();
        entity.writeTo(ostream);

        Log.e(TAG, " error status code=" + status);
        Log.e(TAG, ostream.toString());

        return null;
    } else {
        InputStream content = response.getEntity().getContent();
        // <consume response>

        BufferedReader reader = new BufferedReader(new InputStreamReader(content));
        String line;

        while ((line = reader.readLine()) != null)
            sbResponse.append(line);

        content.close(); // this will also close the connection

        return sbResponse.toString();
    }

}

From source file:com.halseyburgund.rwframework.core.RWHttpManager.java

public static String uploadFile(String page, Properties properties, String fileParam, String file,
        int timeOutSec) throws Exception {
    if (D) {/*from ww  w. ja v a  2 s . c  o  m*/
        Log.d(TAG, "Starting upload of file: " + file, null);
    }

    // build GET-like page name that includes the RW operation
    Enumeration<Object> enumProps = properties.keys();
    StringBuilder uriBuilder = new StringBuilder(page).append('?');
    while (enumProps.hasMoreElements()) {
        String key = enumProps.nextElement().toString();
        String value = properties.get(key).toString();
        if ("operation".equals(key)) {
            uriBuilder.append(key);
            uriBuilder.append('=');
            uriBuilder.append(java.net.URLEncoder.encode(value));
            break;
        }
    }

    if (D) {
        Log.d(TAG, "GET request: " + uriBuilder.toString(), null);
    }

    HttpParams httpParams = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpParams, timeOutSec * 1000);
    HttpConnectionParams.setSoTimeout(httpParams, timeOutSec * 1000);

    HttpClient httpClient = new DefaultHttpClient(httpParams);
    HttpPost request = new HttpPost(uriBuilder.toString());
    RWMultipartEntity entity = new RWMultipartEntity();

    Iterator<Map.Entry<Object, Object>> i = properties.entrySet().iterator();
    while (i.hasNext()) {
        Map.Entry<Object, Object> entry = (Map.Entry<Object, Object>) i.next();
        String key = (String) entry.getKey();
        String val = (String) entry.getValue();
        entity.addPart(key, val);
        if (D) {
            Log.d(TAG, "Added StringBody multipart for: '" + key + "' = '" + val + "'", null);
        }
    }

    File upload = new File(file);
    entity.addPart(fileParam, upload);
    if (D) {
        String msg = "Added FileBody multipart for: '" + fileParam + "' =" + " <'" + upload.getAbsolutePath()
                + ", " + "size: " + upload.length() + " bytes >'";
        Log.d(TAG, msg, null);
    }

    request.setEntity(entity);

    if (D) {
        Log.d(TAG, "Sending HTTP request...", null);
    }

    HttpResponse response = httpClient.execute(request);

    int st = response.getStatusLine().getStatusCode();

    if (st == HttpStatus.SC_OK) {
        StringBuffer sbResponse = new StringBuffer();
        InputStream content = response.getEntity().getContent();
        BufferedReader reader = new BufferedReader(new InputStreamReader(content));
        String line;
        while ((line = reader.readLine()) != null) {
            sbResponse.append(line);
        }
        content.close(); // this will also close the connection

        if (D) {
            Log.d(TAG, "Upload successful (HTTP code: " + st + ")", null);
            Log.d(TAG, "Server response: " + sbResponse.toString(), null);
        }

        return sbResponse.toString();
    } else {
        ByteArrayOutputStream ostream = new ByteArrayOutputStream();
        entity.writeTo(ostream);
        Log.e(TAG, "Upload failed (http code: " + st + ")", null);
        Log.e(TAG, "Server response: " + ostream.toString(), null);
        throw new HttpException(String.valueOf(st));
    }
}

From source file:info.magnolia.importexport.DataTransporter.java

/**
 * Deprecated.//from www  .jav  a2  s  .co m
 * @param properties
 * @param repositoryName
 * @deprecated since 4.0 - use the PropertiesImportExport class instead.
 */
public static void importProperties(Properties properties, String repositoryName) {
    for (Iterator iter = properties.keySet().iterator(); iter.hasNext();) {
        String key = (String) iter.next();
        String value = (String) properties.get(key);

        String name = StringUtils.substringAfterLast(key, ".");
        String path = StringUtils.substringBeforeLast(key, ".").replace('.', '/');
        Content node = ContentUtil.getContent(repositoryName, path);
        if (node != null) {
            try {
                NodeDataUtil.getOrCreate(node, name).setValue(value);
                node.save();
            } catch (RepositoryException e) {
                log.error("can't set property " + key, e);
            }
        }
    }

}