Example usage for java.util Properties putAll

List of usage examples for java.util Properties putAll

Introduction

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

Prototype

@Override
    public synchronized void putAll(Map<?, ?> t) 

Source Link

Usage

From source file:com.wavemaker.runtime.data.util.DataServiceUtils.java

public static Properties toHibernateConnectionProperties(Properties p) {
    Properties rtn = new Properties();
    rtn.putAll(p);
    for (Iterator<Map.Entry<Object, Object>> iter = p.entrySet().iterator(); iter.hasNext();) {
        Map.Entry<Object, Object> entry = iter.next();
        String name = (String) entry.getKey();
        String newName = null;//from   w  w  w  .j  a v a  2  s. co m
        if (name.endsWith(DataServiceConstants.DB_USERNAME)) {
            newName = DataServiceConstants.HIBERNATE_USER_PROPERTY;
        } else if (name.endsWith(DataServiceConstants.DB_PASS)) {
            newName = DataServiceConstants.HIBERNATE_PASS_PROPERTY;
        } else if (name.endsWith(DataServiceConstants.DB_DRIVER_CLASS_NAME)) {
            newName = DataServiceConstants.HIBERNATE_DRIVER_CLASS_NAME_PROPERTY;
        } else if (name.endsWith(DataServiceConstants.DB_URL)) {
            newName = DataServiceConstants.HIBERNATE_CONNECTION_URL_PROPERTY;
        } else if (name.endsWith(DataServiceConstants.DB_DIALECT)) {
            newName = DataServiceConstants.HIBERNATE_DIALECT_PROPERTY;
        }

        if (newName != null && rtn.getProperty(newName) == null) {
            rtn.setProperty(newName, (String) entry.getValue());
        }
    }

    return rtn;
}

From source file:org.esigate.DriverFactory.java

/**
 * Loads all instances according to default configuration file.
 *//*  w  ww  . j  av  a  2  s.  c  o  m*/
public static void configure() {
    InputStream inputStream = null;

    try {
        URL configUrl = getConfigUrl();

        if (configUrl == null) {
            throw new ConfigurationException(
                    "esigate.properties configuration file " + "was not found in the classpath");
        }

        inputStream = configUrl.openStream();

        Properties merged = new Properties();
        if (inputStream != null) {
            Properties props = new Properties();
            props.load(inputStream);
            merged.putAll(props);
        }

        configure(merged);
    } catch (IOException e) {
        throw new ConfigurationException("Error loading configuration", e);
    } finally {
        try {
            if (inputStream != null) {
                inputStream.close();
            }

        } catch (IOException e) {
            throw new ConfigurationException("failed to close stream", e);
        }
    }
}

From source file:com.wavemaker.runtime.data.util.DataServiceUtils.java

private static Properties loadDBProperties(String resourcename, String sep) {
    Tuple.Two<String, String> t = getBaseName(resourcename, sep);
    Properties base = SystemUtils.loadPropertiesFromResource(t.v1 + "." + t.v2);
    Properties rtn = SystemUtils.loadPropertiesFromResource(resourcename);
    rtn.putAll(base);
    return rtn;/* w w w.  j  a  va 2 s  .  c o m*/
}

From source file:com.baidu.cc.ConfigLoader.java

/**
 * create {@link ConfigLoader} instance.
 * /*from www . ja  va  2 s  . c o m*/
 * @param propertySupport {@link ConfigLoaderPropertySupport}
 * @return {@link ConfigLoader} instance.
 */
public static ConfigLoader createConfigLoader(ConfigLoaderPropertySupport propertySupport) {
    //create configservice 
    ExtConfigServerService service;
    service = createConfigService(propertySupport.getCcServerUrl(), propertySupport.getConnectionTimeout(),
            propertySupport.getReadTimeout());

    ConfigLoader configLoader = new ConfigLoader();
    configLoader.setCcVersionName(propertySupport.getCcVersionName());
    configLoader.setCcUser(propertySupport.getCcUser());
    configLoader.setCcPassword(propertySupport.getCcPassword());
    configLoader.setCallbackInteval(propertySupport.getCallbackInteval());

    configLoader.setConfigServerService(service);
    configLoader.init();

    //get configruation items from server
    Map<String, String> configItems = configLoader.getConfigItems();

    //add call back listener here
    configLoader.getCallables().put("cust_listener", propertySupport);

    //???
    Properties properties = new Properties();
    properties.putAll(configItems);
    configLoader.setVersionTag(configItems);

    propertySupport.propertiesLoad(configItems);

    if (propertySupport.isEnableUpdateCallback()) {
        configLoader.startListening(properties);
    }

    return configLoader;
}

From source file:org.escidoc.browser.elabsmodul.service.ELabsService.java

private static List<String[]> buildConfiguration(final List<Map<String, String>> list) {
    Preconditions.checkNotNull(list, "Config list is null");
    final List<String[]> result = new ArrayList<String[]>();

    if (list.isEmpty()) {
        LOG.error("There is not ConfigMap to process!");
        return null;
    }/*from w ww. j ava2 s .c  om*/

    for (final Map<String, String> map : list) {
        final Properties config = new Properties();
        config.putAll(map);

        if (!config.isEmpty()) {
            LOG.debug(config.toString());
            final ByteArrayOutputStream out = new ByteArrayOutputStream();
            try {
                config.storeToXML(out, "");
                LOG.debug("Configuration Properties XML \n" + out.toString());
            } catch (final IOException e) {
                LOG.error(e.getMessage());
            }
            result.add(new String[] { config.getProperty(ELabsServiceConstants.E_SYNC_DAEMON_ENDPOINT),
                    out.toString() });
        } else {
            LOG.error("Configuration is empty!");
        }
    }
    return result;
}

From source file:edu.umd.cs.eclipse.courseProjectManager.EclipseLaunchEventLog.java

static void postEventLogToServer(IProject project) {
    // Log to the course project manager log (visible to users).
    AutoCVSPlugin.getPlugin().getEventLog()
            .logMessage(new Date() + "\t" + "Collecting data for the Marmoset Project.");

    // Look up the EclipseLaunchEventLog for this project. This creates one
    // if it//from  w  ww.jav a  2  s .  c o  m
    // doesn't already exist.
    EclipseLaunchEventLog eclipseLaunchEventLog = EclipseLaunchEventLog.getLog(project);

    // NOTE: Don't try to upload if the user has disabled AutoCVS
    // or has shut off Eclipse launch event monitoring.
    IResource submitUserFile = project.findMember(AutoCVSPlugin.SUBMITUSER);

    // Don't log anything if we don't have a submitUser file,
    // autoCVS mode is disabled, or runlogging is disabled
    if (submitUserFile == null || !AutoCVSPlugin.hasAutoCVSNature(project)
            || !AutoCVSPlugin.hasAutoRunLogNature(project)) {
        return;
    }

    Debug.print("Trying to upload directly to the SubmitServer using a .submitUser file");

    // Find the .submitProject file.
    // This file will only exist for projects controlled by Marmoset.
    IResource submitProjectFile = project.findMember(AutoCVSPlugin.SUBMITPROJECT);
    if (submitProjectFile == null) {
        Debug.print("Can't find .submit file!");
        AutoCVSPlugin.getPlugin().getEventLog()
                .logMessage("project " + project.getName() + " does not contain a "
                        + AutoCVSPlugin.SUBMITPROJECT + " file.  This project is therefore probably not a "
                        + " Computer Science programming assignment that you checked out of CVS.  "
                        + " Thus you can ignore this message.");
        return;
    }

    try {
        Properties props = new Properties();
        FileInputStream fileInputStream = new FileInputStream(submitProjectFile.getRawLocation().toString());
        props.load(fileInputStream);
        fileInputStream.close();

        props.putAll(TurninProjectAction.getUserProperties(submitUserFile));
        Debug.print("Loaded the properties in the .submitUser file");

        // Nothing to report!
        if (eclipseLaunchEventLog.isEmpty())
            return;
        // Check for launch events that have been queued to the logfile.
        String allEvents = eclipseLaunchEventLog.getEvents();
        Debug.print("Grabbed queued events from logfile");

        Debug.print("Uploading!");

        uploadMessages(allEvents, props);

        // Now clear the .cpmLOG
        eclipseLaunchEventLog.clear();
    } catch (IOException e) {
        AutoCVSPlugin.getPlugin().getEventLog()
                .logError("Unable to post Eclipse launch events to the server: " + e.getMessage() + "\n"
                        + "This error is related to data gathering for the Marmoset project and should not "
                        + "affect your ability to work on your project.");
        Debug.print("Unable to log eclipse launch event to the server: " + e.toString());
        // e.printStackTrace();
    }
}

From source file:com.taobao.diamond.common.Constants.java

/** ?-D &gt; env &gt; diamond.properties  */
public static void init() {
    File diamondFile = new File(System.getProperty("user.home"), "diamond/ServerAddress");
    if (!diamondFile.exists()) {
        diamondFile.getParentFile().mkdirs();
        try (OutputStream out = new FileOutputStream(diamondFile)) {
            out.write("localhost".getBytes());
        } catch (IOException e) {
            throw new IllegalStateException(diamondFile.toString(), e);
        }/*ww  w  .j  av a 2  s  .  com*/
    }
    List<Field> fields = new ArrayList<>();
    for (Field field : Constants.class.getDeclaredFields()) {
        if (Modifier.isPublic(field.getModifiers()) && !Modifier.isFinal(field.getModifiers())) {
            fields.add(field);
        }
    }

    Properties props = new Properties();
    {
        ClassLoader cl = Thread.currentThread().getContextClassLoader();
        if (cl == null)
            cl = Constants.class.getClassLoader();
        try (InputStream in = cl.getResourceAsStream("diamond.properties")) {
            if (in != null)
                props.load(in);
        } catch (IOException e) {
            log.warn("load diamond.properties", e);
        }
    }
    props.putAll(System.getenv());
    props.putAll(System.getProperties());

    Map<String, Object> old = new HashMap<>();
    try {
        for (Field field : fields) {
            if (!props.containsKey(field.getName()))
                continue;
            old.put(field.getName(), field.get(Constants.class));

            String value = props.getProperty(field.getName());
            Class<?> clazz = field.getType();
            if (String.class.equals(clazz)) {
                field.set(Constraints.class, value);
            } else if (int.class.equals(clazz)) {
                if (value != null) {
                    field.set(Constraints.class, Integer.parseInt(value));
                }
            } else {
                throw new IllegalArgumentException(field + "  " + value + " ?");
            }
        }
    } catch (IllegalAccessException e) {
        throw new IllegalStateException(e);
    }

    setValue(old, "CONFIG_HTTP_URI_FILE", "HTTP_URI_FILE");
    setValue(old, "HTTP_URI_LOGIN", "HTTP_URI_FILE");
    setValue(old, "DAILY_DOMAINNAME", "DEFAULT_DOMAINNAME");
}

From source file:com.adobe.aem.demomachine.gui.AemDemoUtils.java

public static int[] getDemoAddons(File buildFile) {

    List<Integer> listIndices = new ArrayList<Integer>();

    Properties defaultProps = loadProperties(
            buildFile.getParentFile().getAbsolutePath() + File.separator + "build.properties");
    Properties personalProps = loadProperties(buildFile.getParentFile().getAbsolutePath() + File.separator
            + "conf" + File.separator + "build-personal.properties");

    @SuppressWarnings("serial")
    Properties sortedProps = new Properties() {
        @Override/*from w w  w  . jav  a 2  s .  co  m*/
        public synchronized Enumeration<Object> keys() {
            return Collections.enumeration(new TreeSet<Object>(super.keySet()));
        }
    };
    sortedProps.putAll(defaultProps);

    // Looping through all possible options
    Enumeration<?> e = sortedProps.keys();

    int currentIndice = 0;
    while (e.hasMoreElements()) {
        String key = (String) e.nextElement();
        if (key.startsWith("demo.addons.") & !(key.endsWith("help") || key.endsWith("label"))) {
            String value = sortedProps.getProperty(key);
            if (personalProps.containsKey(key)) {
                value = personalProps.getProperty(key);
            }
            if (value.equals("true")) {
                listIndices.add(currentIndice);
            }
            currentIndice = currentIndice + 1;
        }
    }
    int[] array = new int[listIndices.size()];
    for (int i = 0; i < listIndices.size(); i++)
        array[i] = listIndices.get(i);
    return array;

}

From source file:com.adobe.aem.demomachine.gui.AemDemoUtils.java

public static AemDemoProperty[] listDemoAddons(File buildFile) {

    List<AemDemoProperty> addons = new ArrayList<AemDemoProperty>();
    Properties defaultProps = loadProperties(
            buildFile.getParentFile().getAbsolutePath() + File.separator + "build.properties");

    @SuppressWarnings("serial")
    Properties sortedProps = new Properties() {
        @Override/*from w  ww  . j a  v a2  s . c o  m*/
        public synchronized Enumeration<Object> keys() {
            return Collections.enumeration(new TreeSet<Object>(super.keySet()));
        }
    };
    sortedProps.putAll(defaultProps);

    // Looping through all possible options
    Enumeration<?> e = sortedProps.keys();

    // List of paths to demo packages
    List<String[]> listPaths = Arrays.asList(AemDemoConstants.demoPaths);

    while (e.hasMoreElements()) {
        String key = (String) e.nextElement();
        if (key.startsWith("demo.addons.") & !(key.endsWith("help") || key.endsWith("label"))) {
            String newKey = key.substring(1 + key.lastIndexOf("."));

            // Check if downloads are required
            boolean downloadRequired = false;
            for (String[] path : listPaths) {
                if (path.length == 5 && path[4] != null && path[4].equals(newKey)) {
                    File pathFolder = new File(buildFile.getParentFile().getAbsolutePath()
                            + (path[1].length() > 0 ? (File.separator + path[1]) : ""));
                    if (!pathFolder.exists()) {
                        downloadRequired = true;
                    }
                }
            }
            addons.add(new AemDemoProperty(newKey,
                    sortedProps.getProperty(key + ".label") + (downloadRequired ? " (*)" : "")));
        }
    }

    AemDemoProperty[] aemPropertyArray = new AemDemoProperty[addons.size()];
    addons.toArray(aemPropertyArray);
    return aemPropertyArray;

}

From source file:com.turn.griffin.utils.GriffinConsumer.java

private static ConsumerConfig createConsumerConfig(String zkAddress, String groupId, Properties userProps) {
    Properties props = new Properties();
    props.put("zookeeper.connect", zkAddress);
    props.put("zookeeper.session.timeout.ms", "30000");
    props.put("zookeeper.connection.timeout.ms", "30000");
    props.put("zookeeper.sync.time.ms", "6000");

    props.put("group.id", groupId);

    props.put("auto.commit.enable", "true");
    props.put("auto.commit.interval.ms", "300000"); // 5 min
    props.put("rebalance.backoff.ms", "20000");

    /* Add user specified properties */
    /* Should be the last line to allow overriding any of the properties above */
    props.putAll(userProps);

    /* A hack to set the consumer offset to zero if the user specified smallest offset */
    if ("smallest".equals(props.get("auto.offset.reset"))) {
        ZkUtils.maybeDeletePath(zkAddress, new ZKGroupDirs(groupId).consumerGroupDir());
    }/*from   ww w  . j  a  v a2 s.c o  m*/
    return new ConsumerConfig(props);
}