Example usage for java.util Properties setProperty

List of usage examples for java.util Properties setProperty

Introduction

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

Prototype

public synchronized Object setProperty(String key, String value) 

Source Link

Document

Calls the Hashtable method put .

Usage

From source file:it.geosolutions.geobatch.imagemosaic.ImageMosaicProperties.java

/**
 * If the indexer file do not exists, build the indexer using the passed configuration and
 * return the corresponding properties object
 * /*from  ww w .  j  ava  2 s .  c o m*/
 * @note: here we suppose that elevation are stored as double
 * @note: for a list of available SPI refer to:<br>
 *        geotools/trunk/modules/plugin/imagemosaic/src/main/resources/META-INF/services/org.
 *        geotools.gce.imagemosaic.properties.PropertiesCollectorSPI
 * 
 * @param indexer
 * @param configuration
 * @return 
 * @throws NullPointerException 
 * @throws IOException 
 */
protected static Properties buildIndexer(File indexer, ImageMosaicConfiguration configuration)
        throws NullPointerException, IOException {
    // ////
    // INDEXER
    // ////
    if (!indexer.exists()) {

        FileWriter outFile = null;
        PrintWriter out = null;
        try {
            indexer.createNewFile();

            if (!indexer.canWrite()) {
                final String message = "Unable to write on indexer.properties file at URL: "
                        + indexer.getAbsolutePath();
                if (LOGGER.isErrorEnabled())
                    LOGGER.error(message);
                throw new IOException(message);
            }

            outFile = new FileWriter(indexer);
            out = new PrintWriter(outFile);

            File baseDir = indexer.getParentFile();

            // Write text to file
            // setting caching of file to false

            // create a private copy and fix inconsistencies in it
            configuration = configuration.clone();
            ConfigUtil.sanitize(configuration);

            // create regex files
            for (DomainAttribute domainAttr : configuration.getDomainAttributes()) {
                final File regexFile = new File(baseDir, domainAttr.getAttribName() + "regex.properties");
                ImageMosaicProperties.createRegexFile(regexFile, domainAttr.getRegEx());

                if (domainAttr.getEndRangeAttribName() != null) {
                    final File endRangeRegexFile = new File(baseDir,
                            domainAttr.getEndRangeAttribName() + "regex.properties");
                    ImageMosaicProperties.createRegexFile(endRangeRegexFile, domainAttr.getEndRangeRegEx());
                }
            }

            StringBuilder indexerSB = createIndexer(configuration);
            out.append(indexerSB);

            //                out.println(org.geotools.gce.imagemosaic.Utils.Prop.CACHING+"=false");
            //
            //                // create indexer
            //                DomainAttribute timeAttr = ConfigUtil.getTimeAttribute(configuration);
            //                DomainAttribute elevAttr = ConfigUtil.getElevationAttribute(configuration);
            //
            //                if(timeAttr != null) {
            //                    out.println(org.geotools.gce.imagemosaic.Utils.Prop.TIME_ATTRIBUTE+"="+getAttribDeclaration(timeAttr));
            //                }
            //                if(elevAttr != null) {
            //                    out.println(org.geotools.gce.imagemosaic.Utils.Prop.ELEVATION_ATTRIBUTE+"="+getAttribDeclaration(elevAttr));
            //                }
            //
            //                List<DomainAttribute> customAttribs = ConfigUtil.getCustomDimensions(configuration);
            //                if( ! customAttribs.isEmpty() ) {
            //                    out.println("AdditionalDomainAttributes");
            //                    String sep="=";
            //                    for (DomainAttribute customAttr : customAttribs) {
            //                        out.print(sep);
            //                        sep=",";
            //                        out.print(getDimensionDeclaration(customAttr));
            //                    }
            //                    out.println();
            //                }
            //
            //                out.print("Schema=*the_geom:Polygon,location:String");
            //                for (DomainAttribute attr : configuration.getDomainAttributes()) {
            //                    TYPE type = attr.getType();
            //                    printSchemaField(out, attr.getAttribName(), type);
            //                    if(attr.getEndRangeAttribName() != null)
            //                        printSchemaField(out, attr.getEndRangeAttribName(), type);
            //                }
            //                out.println();
            //
            //                String sep="";
            //                out.print("PropertyCollectors=");
            //                for (DomainAttribute attr : configuration.getDomainAttributes()) {
            //                    TYPE type = attr.getType();
            //                    out.print(sep);
            //                    sep=";";
            //                    printCollectorField(out, attr.getAttribName(), type);
            //                    if(attr.getEndRangeAttribName() != null)
            //                        printCollectorField(out, attr.getEndRangeAttribName(), type);
            //                }
            //                out.println();

        } catch (IOException e) {
            if (LOGGER.isErrorEnabled())
                LOGGER.error("Error occurred while writing indexer.properties file at URL: "
                        + indexer.getAbsolutePath(), e);
            return null;
        } finally {
            if (out != null) {
                out.flush();
                IOUtils.closeQuietly(out);
            }
            out = null;
            if (outFile != null) {
                IOUtils.closeQuietly(outFile);
            }
            outFile = null;
        }
        return getPropertyFile(indexer);
    } else {
        // file -> indexer.properties
        /**
         * get the Caching property and set it to false
         */
        Properties indexerProps = getPropertyFile(indexer);
        String caching = indexerProps.getProperty(CACHING_KEY);
        if (caching != null) {
            if (caching.equals("true")) {
                indexerProps.setProperty(CACHING_KEY, "false");
            }
        } else {
            if (LOGGER.isWarnEnabled())
                LOGGER.warn("Unable to get the " + CACHING_KEY + " property into the "
                        + indexer.getAbsolutePath() + " file.");
        }

        return indexerProps;
    }
}

From source file:com.dragoniade.encrypt.EncryptionHelper.java

public static void encrypt(Properties p, String seedKey, String key) {
    String value = p.getProperty(key);
    String seed = p.getProperty(seedKey, seedKey);

    String encrypted;// w w  w .  ja v a  2  s .  c  o  m
    try {
        Cipher cipher = getEncrypter(seed);
        byte[] result = cipher.doFinal(value.getBytes("UTF-16"));
        encrypted = cipher.getAlgorithm() + "{" + Base64.encode(result) + "}";
    } catch (Exception e) {
        try {
            encrypted = "{" + Base64.encode(value.getBytes("UTF-16")) + "}";
        } catch (Exception e2) {
            encrypted = "{" + Base64.encode(value.getBytes()) + "}";
        }
    }

    p.setProperty(key, encrypted);
}

From source file:com.ontotext.s4.service.S4ServiceClient.java

private static Properties readCredentials(Parameters params) {
    Properties props = new Properties();

    if (params.getValue("apikey") != null) {
        if (params.getValue("secret") == null) {
            printUsageAndTerminate("API key secret not provided");
        }/*from  ww w .  ja  va2s.  c  o m*/
        props.setProperty("apikey", params.getValue("apikey"));
        props.setProperty("secret", params.getValue("secret"));
        return props;
    }
    String credsFile = "s4credentials.properties";
    if (params.getValue("creds") != null) {
        credsFile = params.getValue("creds");
    }
    if (new File(credsFile).exists()) {
        try {
            props.load(new FileInputStream(credsFile));
        } catch (IOException ex) {
            printUsageAndTerminate("Error reading credentials file: " + ex.getMessage());
        }
    } else {
        InputStream inStr = Thread.currentThread().getContextClassLoader().getResourceAsStream(credsFile);
        if (inStr != null) {
            try {
                props.load(inStr);
            } catch (IOException ioe) {
                printUsageAndTerminate("Error reading credentials file: " + ioe.getMessage());
            }
        }
    }
    return props;
}

From source file:com.virtualparadigm.packman.processor.JPackageManagerBU.java

public static boolean configure(File tempDir, Configuration configuration) {
    logger.info("PackageManager::configure()");
    boolean status = true;
    if (tempDir != null && configuration != null && !configuration.isEmpty()) {
        VelocityEngine velocityEngine = new VelocityEngine();
        Properties vProps = new Properties();
        vProps.setProperty("resource.loader", "string");
        vProps.setProperty("string.resource.loader.class",
                "org.apache.velocity.runtime.resource.loader.StringResourceLoader");
        velocityEngine.init(vProps);//from  w  ww .j  a  v  a 2s.  co  m
        Template template = null;
        VelocityContext velocityContext = JPackageManagerBU.createVelocityContext(configuration);
        StringResourceRepository stringResourceRepository = StringResourceLoader.getRepository();
        String templateContent = null;
        StringWriter stringWriter = null;
        long lastModified;

        Collection<File> patchFiles = FileUtils.listFiles(
                new File(tempDir.getAbsolutePath() + "/" + JPackageManagerBU.PATCH_DIR_NAME + "/"
                        + JPackageManagerBU.PATCH_FILES_DIR_NAME),
                TEMPLATE_SUFFIX_FILE_FILTER, DirectoryFileFilter.DIRECTORY);

        if (patchFiles != null) {
            for (File pfile : patchFiles) {
                logger.debug("  processing patch fileset file: " + pfile.getAbsolutePath());
                try {
                    lastModified = pfile.lastModified();
                    templateContent = FileUtils.readFileToString(pfile);
                    templateContent = templateContent.replaceAll("(\\$)(\\{)([^\\}]*)(\\:)([^\\}]*)(\\})",
                            "#$2$3$4$5$6");

                    stringResourceRepository.putStringResource(JPackageManagerBU.CURRENT_TEMPLATE_NAME,
                            templateContent);
                    stringWriter = new StringWriter();
                    template = velocityEngine.getTemplate(JPackageManagerBU.CURRENT_TEMPLATE_NAME);
                    template.merge(velocityContext, stringWriter);

                    templateContent = stringWriter.toString();
                    templateContent = templateContent.replaceAll("(#)(\\{)([^\\}]*)(\\:)([^\\}]*)(\\})",
                            "\\$$2$3$4$5$6");

                    FileUtils.writeStringToFile(pfile, templateContent);
                    pfile.setLastModified(lastModified);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }

        Collection<File> scriptFiles = FileUtils.listFiles(
                new File(tempDir.getAbsolutePath() + "/" + JPackageManagerBU.AUTORUN_DIR_NAME),
                TEMPLATE_SUFFIX_FILE_FILTER, DirectoryFileFilter.DIRECTORY);

        if (scriptFiles != null) {
            for (File scriptfile : scriptFiles) {
                logger.debug("  processing script file: " + scriptfile.getAbsolutePath());
                try {
                    lastModified = scriptfile.lastModified();
                    templateContent = FileUtils.readFileToString(scriptfile);
                    templateContent = templateContent.replaceAll("(\\$)(\\{)([^\\}]*)(\\:)([^\\}]*)(\\})",
                            "#$2$3$4$5$6");

                    stringResourceRepository.putStringResource(JPackageManagerBU.CURRENT_TEMPLATE_NAME,
                            templateContent);
                    stringWriter = new StringWriter();
                    template = velocityEngine.getTemplate(JPackageManagerBU.CURRENT_TEMPLATE_NAME);
                    template.merge(velocityContext, stringWriter);

                    templateContent = stringWriter.toString();
                    templateContent = templateContent.replaceAll("(#)(\\{)([^\\}]*)(\\:)([^\\}]*)(\\})",
                            "\\$$2$3$4$5$6");

                    FileUtils.writeStringToFile(scriptfile, templateContent);
                    scriptfile.setLastModified(lastModified);

                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }
    return status;
}

From source file:de.tudarmstadt.ukp.dkpro.tc.crfsuite.CRFSuiteOutcomeIDReport.java

protected static Properties generateProperties(HashMap<String, Integer> aMapping, List<String> predictions,
        List<String> testFeatures) throws Exception {
    Properties props = new Properties();

    int maxLines = predictions.size();

    for (int idx = 1; idx < maxLines; idx++) {
        String entry = predictions.get(idx);
        String[] split = entry.split("\t");
        if (split.length != 2) {
            continue;
        }//from w ww .j av a  2s.co m
        String featureEntry = testFeatures.get(idx - 1);
        String id = extractTCId(featureEntry);
        int numGold = aMapping.get(split[0]);
        int numPred = aMapping.get(split[1]);
        String propEntry = numPred + SEPARATOR_CHAR + numGold;
        props.setProperty(id, propEntry);
    }

    return props;
}

From source file:org.apache.directory.fortress.core.rest.RestUtils.java

/**
 * @param inProps//  ww  w.  j  a  va  2  s .co m
 * @return Properties
 */
public static Properties getProperties(Props inProps) {
    Properties properties = null;
    List<Props.Entry> props = inProps.getEntry();
    if (props.size() > 0) {
        properties = new Properties();
        //int size = props.size();
        for (Props.Entry entry : props) {
            String key = entry.getKey();
            String val = entry.getValue();
            properties.setProperty(key, val);
        }
    }
    return properties;
}

From source file:davmail.Settings.java

/**
 * Get all properties that are in the specified scope, that is, that start with '&lt;scope&gt;.'.
 *
 * @param scope     start of property name
 * @return properties/*from w w w .  j av  a  2  s.com*/
 */
public static synchronized Properties getSubProperties(String scope) {
    final String keyStart;
    if (scope == null || scope.length() == 0) {
        keyStart = "";
    } else if (scope.endsWith(".")) {
        keyStart = scope;
    } else {
        keyStart = scope + '.';
    }
    Properties result = new Properties();
    for (Map.Entry entry : SETTINGS.entrySet()) {
        String key = (String) entry.getKey();
        if (key.startsWith(keyStart)) {
            String value = (String) entry.getValue();
            result.setProperty(key.substring(keyStart.length()), value);
        }
    }
    return result;
}

From source file:com.splicemachine.orc.OrcTester.java

private static Properties createTableProperties(String name, String type) {
    Properties orderTableProperties = new Properties();
    orderTableProperties.setProperty("columns", name);
    orderTableProperties.setProperty("columns.types", type);
    return orderTableProperties;
}

From source file:net.paoding.analysis.knife.PaodingMaker.java

private static void postPropertiesLoaded(Properties p) {
    if ("done".equals(p.getProperty("paoding.analysis.postPropertiesLoaded"))) {
        return;//from ww w.j ava 2  s.  c o  m
    }
    setDicHomeProperties(p);
    p.setProperty("paoding.analysis.postPropertiesLoaded", "done");
}

From source file:io.fabric8.maven.proxy.impl.MavenProxyServletSupportTest.java

private static void addPom(JarOutputStream jas, String groupId, String artifactId, String version)
        throws Exception {
    Properties properties = new Properties();
    properties.setProperty("groupId", groupId);
    properties.setProperty("artifactId", artifactId);
    properties.setProperty("version", version);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    properties.store(baos, null);//from  ww  w .ja v  a2s. c  om
    addEntry(jas, String.format("META-INF/maven/%s/%s/%s/pom.properties", groupId, artifactId, version),
            baos.toByteArray());
}