Example usage for org.apache.commons.configuration.plist XMLPropertyListConfiguration save

List of usage examples for org.apache.commons.configuration.plist XMLPropertyListConfiguration save

Introduction

In this page you can find the example usage for org.apache.commons.configuration.plist XMLPropertyListConfiguration save.

Prototype

public void save(Writer out) throws ConfigurationException 

Source Link

Usage

From source file:com.photon.phresco.impl.IPhoneApplicationProcessor.java

public void storeConfigObjAsPlist(Configuration keyValueObj, String plistPath) throws Exception {
    XMLPropertyListConfiguration plist = new XMLPropertyListConfiguration();
    Properties properties = keyValueObj.getProperties();
    Enumeration em = properties.keys();
    while (em.hasMoreElements()) {
        String str = (String) em.nextElement();
        plist.addProperty(str, properties.get(str));
    }//from w w  w . j  a v  a  2 s .  c  o  m
    plist.save(plistPath);

}

From source file:com.photon.phresco.impl.IPhoneApplicationProcessor.java

@Override
public void postConfiguration(ApplicationInfo appInfo, List<Configuration> configs) throws PhrescoException {

    try {//from ww w.  jav a  2 s.  c o  m
        String rootModulePath = "";
        String subModuleName = "";
        if (StringUtils.isNotEmpty(appInfo.getRootModule())) {
            rootModulePath = Utility.getProjectHome() + appInfo.getRootModule();
            subModuleName = appInfo.getAppDirName();
        } else {
            rootModulePath = Utility.getProjectHome() + appInfo.getAppDirName();
        }
        File phrescoPomFile = Utility.getPomFileLocation(rootModulePath, subModuleName);
        ProjectInfo projectInfo = Utility.getProjectInfo(rootModulePath, subModuleName);
        File sourceFolderLocation = Utility.getSourceFolderLocation(projectInfo, rootModulePath, subModuleName);
        String dotPhrescoFolderPath = Utility.getDotPhrescoFolderPath(rootModulePath, subModuleName);
        File ConfigFilePath = new File(
                dotPhrescoFolderPath + File.separator + Constants.CONFIGURATION_INFO_FILE);
        ConfigManager configManager = new ConfigManagerImpl(ConfigFilePath);
        List<Environment> environments = configManager.getEnvironments();
        for (Environment environment : environments) {
            String environmenName = "";
            Map<String, List<Properties>> values = new HashMap<String, List<Properties>>();
            String environmentName = environment.getName();
            File file = new File(sourceFolderLocation + getThirdPartyModuleFolder(phrescoPomFile)
                    + File.separator + environmentName);
            if (!file.exists()) {
                file.mkdir();
            }
            List<Configuration> configurations = environment.getConfigurations();
            if (CollectionUtils.isNotEmpty(configurations)) {
                String plistFile = file.getPath() + File.separator + ENVIRONMENT_PLIST;
                XMLPropertyListConfiguration plist = new XMLPropertyListConfiguration();
                for (Configuration configuration : configurations) {
                    if (configuration != null) {
                        String configType = configuration.getType();
                        environmenName = environment.getName();
                        Properties properties = configuration.getProperties();
                        properties.setProperty(NAME, configuration.getName());
                        if (values.containsKey(configType)) {
                            List<Properties> list = values.get(configType);
                            list.add(properties);
                            values.put(configType, list);
                        } else {
                            List<Properties> listProps = new ArrayList<Properties>();
                            listProps.add(properties);
                            values.put(configType, listProps);
                        }
                    }
                }
                plist.addProperty(environmenName, values);
                plist.save(plistFile);
            }
        }
    } catch (ConfigurationException e) {
        throw new PhrescoException(e);
    } catch (org.apache.commons.configuration.ConfigurationException e) {
        throw new PhrescoException(e);
    }
}

From source file:com.photon.phresco.impl.IPhonePhrescoApplicationProcessor.java

private void storeConfigObjAsPlist(List<Configuration> configuration, String destPlistFile)
        throws PhrescoException {
    //FIXME: this logic needs to be revisited and should be fixed with XMLPropertyListConfiguration classes.
    try {//from  w  ww  .  ja v a2s. c o  m
        XMLPropertyListConfiguration plist = new XMLPropertyListConfiguration();
        for (Configuration config : configuration) {
            if (FEATURES.equalsIgnoreCase(config.getType())) {
                String rootNode = "";
                HashMap<String, Object> valueMap = new HashMap();

                Properties properties = config.getProperties();
                Enumeration em = properties.keys();
                while (em.hasMoreElements()) {
                    HashMap<String, Object> tempMap = new HashMap();
                    String key = (String) em.nextElement();
                    String value = properties.getProperty(key);
                    String[] keySplited = key.split("\\.");
                    rootNode = keySplited[0];
                    int length = keySplited.length;
                    if (value != null && value instanceof String && value.toString().startsWith("[")
                            && value.toString().endsWith("]")) {

                        String arrayListvalue = value.toString().replace("[", "").replace("]", "");
                        String[] split = arrayListvalue.toString().split(",");
                        Map<String, Object> keyValuePair = new HashMap<String, Object>();
                        List<String> asList = new ArrayList<String>();
                        for (String string : split) {
                            asList.add(string.trim());
                        }
                        String rootKey = "";
                        String arrayListKey = "";
                        if (length == 3) {
                            rootKey = keySplited[1];
                            arrayListKey = keySplited[2];
                            keyValuePair.put(arrayListKey, asList);
                            if (!valueMap.isEmpty()) {
                                if (valueMap.containsKey(keySplited[1])) {
                                    HashMap<String, Object> object = (HashMap) valueMap.get(keySplited[1]);
                                    tempMap.put(arrayListKey, asList);

                                    for (Map.Entry<String, Object> entry : object.entrySet()) {
                                        tempMap.put(entry.getKey(), entry.getValue());
                                    }

                                    valueMap.put(rootKey, tempMap);
                                } else {
                                    valueMap.put(rootKey, keyValuePair);
                                }
                            } else {
                                valueMap.put(rootKey, keyValuePair);
                            }
                        } else if (length == 2) {
                            valueMap.put(keySplited[1], asList);
                        }
                    } else {
                        String arrayListKey = "";
                        if (length == 2) {
                            arrayListKey = keySplited[1];
                            valueMap.put(arrayListKey, value);
                        } else if (length == 3) {
                            HashMap localMap = new HashMap();
                            localMap.put(keySplited[2], value);
                            if (!valueMap.isEmpty()) {
                                if (valueMap.containsKey(keySplited[1])) {
                                    HashMap<String, Object> object = (HashMap) valueMap.get(keySplited[1]);
                                    tempMap.put(keySplited[2], value);

                                    for (Map.Entry<String, Object> entry : object.entrySet()) {
                                        tempMap.put(entry.getKey(), entry.getValue());
                                    }

                                    valueMap.put(keySplited[1], tempMap);
                                } else {
                                    valueMap.put(keySplited[1], localMap);
                                }
                            } else {
                                valueMap.put(keySplited[1], localMap);
                            }
                        }
                    }
                }
                plist.addProperty(rootNode, valueMap);
            }
        }
        plist.save(destPlistFile);
    } catch (ConfigurationException e) {
        throw new PhrescoException(e);
    }
}