Example usage for java.util Properties entrySet

List of usage examples for java.util Properties entrySet

Introduction

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

Prototype

@Override
    public Set<Map.Entry<Object, Object>> entrySet() 

Source Link

Usage

From source file:org.jahia.modules.external.modules.ModulesDataSource.java

private ExternalData enhanceData(String path, ExternalData data) {
    try {//  ww w .  ja va 2s . c  o  m
        ExtendedNodeType type = NodeTypeRegistry.getInstance().getNodeType(data.getType());
        if (type.isNodeType("jnt:moduleVersionFolder")) {
            String name = module.getName();
            String v = module.getVersion().toString();
            data.getProperties().put("j:title", new String[] { name + " (" + v + ")" });
        } else if (type.isNodeType(JNT_EDITABLE_FILE)) {
            Set<String> lazyProperties = data.getLazyProperties();
            if (lazyProperties == null) {
                lazyProperties = new HashSet<String>();
                data.setLazyProperties(lazyProperties);
            }
            String nodeTypeName = StringUtils
                    .replace(StringUtils.substringBetween(path, SRC_MAIN_RESOURCES, "/"), "_", ":");
            // add nodetype only if it is resolved
            if (nodeTypeName != null) {
                nodeTypeName = nodeTypeName.replace('-', '_');
                data.getProperties().put("nodeTypeName", new String[] { nodeTypeName });
            }
            lazyProperties.add(SOURCE_CODE);
            // set Properties
            if (type.isNodeType(Constants.JAHIAMIX_VIEWPROPERTIES)) {
                Properties properties = new SortedProperties();
                InputStream is = null;
                try {
                    is = getFile(StringUtils.substringBeforeLast(path, ".") + PROPERTIES_EXTENSION).getContent()
                            .getInputStream();
                    properties.load(is);
                    Map<String, String[]> dataProperties = new HashMap<String, String[]>();
                    for (Map.Entry<?, ?> property : properties.entrySet()) {
                        ExtendedPropertyDefinition propertyDefinition = type.getPropertyDefinitionsAsMap()
                                .get(property.getKey());
                        String[] values;
                        if (propertyDefinition != null && propertyDefinition.isMultiple()) {
                            values = StringUtils.split(((String) property.getValue()), ",");
                        } else {
                            values = new String[] { (String) property.getValue() };
                        }
                        dataProperties.put((String) property.getKey(), values);
                    }
                    data.getProperties().putAll(dataProperties);
                } catch (FileSystemException e) {
                    //no properties files, do nothing
                } catch (IOException e) {
                    logger.error("Cannot read property file", e);
                } finally {
                    IOUtils.closeQuietly(is);
                }
            }
        } else {
            String ext = StringUtils.substringAfterLast(path, ".");
            Map<?, ?> extensions = (Map<?, ?>) SpringContextSingleton.getBean("fileExtensionIcons");
            if ("img".equals(extensions.get(ext))) {
                InputStream is = null;
                try {
                    is = getFile(data.getPath()).getContent().getInputStream();
                    BufferedImage bimg = ImageIO.read(is);
                    if (bimg != null) {
                        data.setMixin(JMIX_IMAGE_LIST);
                        data.getProperties().put("j:height",
                                new String[] { Integer.toString(bimg.getHeight()) });
                        data.getProperties().put("j:width", new String[] { Integer.toString(bimg.getWidth()) });
                    }
                } catch (FileSystemException e) {
                    //no properties files, do nothing
                } catch (IOException e) {
                    logger.error("Cannot read property file", e);
                } catch (Exception e) {
                    logger.error("unable to enhance image " + data.getPath(), e);
                } finally {
                    if (is != null) {
                        IOUtils.closeQuietly(is);
                    }
                }
            }
        }
    } catch (NoSuchNodeTypeException e) {
        logger.error("Unknown type", e);
    }
    SourceControlManagement sourceControl = module.getSourceControl();
    if (sourceControl != null) {
        try {
            SourceControlManagement.Status status = getScmStatus(path);
            if (status != SourceControlManagement.Status.UNMODIFIED) {
                List<String> mixin = data.getMixin();
                if (mixin == null) {
                    mixin = new ArrayList<String>();
                }
                if (!mixin.contains("jmix:sourceControl")) {
                    mixin.add("jmix:sourceControl");
                }
                data.setMixin(mixin);
                data.getProperties().put("scmStatus", new String[] { status.name().toLowerCase() });
            }
        } catch (IOException e) {
            logger.error("Failed to get SCM status", e);
        }
    }
    return data;
}

From source file:com.sos.JSHelper.Options.JSOptionsClass.java

/**
 *
 * \brief LoadProperties/* w w  w.  j a va  2 s. com*/
 *
 * \details
 *
 * \return void
 *
 * @param pobjProp
 * @throws Exception
 */
public void LoadProperties(final Properties pobjProp) {
    @SuppressWarnings("unused")
    final String conMethodName = conClassName + "::LoadProperties";
    this.Settings();
    for (final Object element : pobjProp.entrySet()) {
        @SuppressWarnings("rawtypes")
        final Map.Entry mapItem = (Map.Entry) element;
        final String strMapKey = mapItem.getKey().toString();
        if (mapItem.getValue() != null) {
            final String strTemp = mapItem.getValue().toString();
            logger.debug("Property " + strMapKey + " = " + strTemp);
            if (strTemp != null && strTemp.length() > 0 && strTemp.equalsIgnoreCase(".") == false) {
                objSettings.put(strMapKey, strTemp);
            }
        }
    }
    // (hoffentlich) berschrieben von der erbenden Klasse
    try {
        setAllOptions(objSettings);
    } catch (Exception e) {
        throw new JobSchedulerException("setAllOptions returns an error:", e);
    }
    setAllCommonOptions(objSettings);
}

From source file:com.sos.JSHelper.Options.JSOptionsClass.java

/**
 *
 * \brief LoadProperties - Optionen aus Property-Datei laden
 *
 * \details// w  ww. j av a  2  s  .co  m
 * Ldt die Werte fr die Optionen aus einer Java-Properties-Datei.
 * Der Name der Datei ist als Parameter anzugeben.
 *
 * \return void
 *
 * @param pstrPropertiesFileName
 * @throws Exception
 */
@SuppressWarnings("unchecked")
public void LoadProperties(final String pstrPropertiesFileName) throws Exception {
    final String conMethodName = conClassName + "::LoadProperties ";
    final Properties objProp = new Properties();
    objProp.load(new FileInputStream(pstrPropertiesFileName));
    message(conMethodName + ": PropertyFile red. Name '" + pstrPropertiesFileName + "'.");
    this.Settings();
    for (final Object element : objProp.entrySet()) {
        final Map.Entry mapItem = (Map.Entry) element;
        final String strMapKey = mapItem.getKey().toString();
        if (mapItem.getValue() != null) {
            final String strTemp = mapItem.getValue().toString();
            if (strTemp != null && strTemp.length() > 0 && strTemp.equalsIgnoreCase(".") == false) {
                objSettings.put(strMapKey, strTemp);
            }
        }
    }
    // (hoffentlich) berschrieben von der erbenden Klasse
    message(conMethodName + ": Property-File loaded");
    setAllOptions(objSettings);
    setAllCommonOptions(objSettings);
    // return void;
}

From source file:mondrian.olap.Util.java

/**
 * Converts a {@link Properties} object to a string-to-string {@link Map}.
 *
 * @param properties Properties/* w w  w . j a  v  a 2  s . c om*/
 * @return String-to-string map
 */
public static Map<String, String> toMap(final Properties properties) {
    return new AbstractMap<String, String>() {
        @SuppressWarnings({ "unchecked" })
        public Set<Entry<String, String>> entrySet() {
            return (Set) properties.entrySet();
        }
    };
}

From source file:fr.cmoatoto.multishare.receiver.NanoHTTPDReceiver.java

/**
 * Override this to customize the server.
 * <p>//from ww  w  .j  a v a  2 s.c  om
 * 
 * (By default, this delegates to serveFile() and allows directory listing.)
 * 
 * @param uri
 *            Percent-decoded URI without parameters, for example "/index.cgi"
 * @param method
 *            "GET", "POST" etc.
 * @param parms
 *            Parsed, percent decoded parameters from URI and, in case of POST, data.
 * @param header
 *            Header entries, percent decoded
 * @param inetAddress
 * @return HTTP response, see class Response for details
 */
public Response serve(String uri, String method, Properties header, Properties parms, Properties files,
        InetAddress inetAddress) {
    myOut.println(method + " '" + uri + "' " + inetAddress.toString());

    Enumeration e = header.propertyNames();
    String element = null;
    myOut.println("URI: " + uri);
    String value = null;
    String mimeType = null;
    String extension = null;

    while (e.hasMoreElements()) {
        element = (String) e.nextElement();
        myOut.println("  HDR: '" + element + "' = '" + header.getProperty(element) + "'");
    }
    e = parms.propertyNames();
    while (e.hasMoreElements()) {
        element = (String) e.nextElement();

        myOut.println("  PRM: '" + element + "' = '" + parms.getProperty(element) + "'");
        if (element.equals("value")) {
            value = parms.getProperty(element);
            if (value.contains("http://remote_host:")) {
                value = value.replace("/remote_host", inetAddress.toString());
                myOut.println("  PRM REPLACED BY: '" + element + "' = '" + value + "'");
            }
        } else if (element.equals("mime")) {
            mimeType = parms.getProperty(element);
        } else if (element.equals("extension")) {
            extension = parms.getProperty(element);
        }

        if (value != null && mimeType != null) {
            if ("keyboard/key".equals(mimeType)) {
                try {
                    RemotedKeyboard.sendKeyEvent(mContext, Integer.parseInt(value));
                } catch (NumberFormatException e2) {
                    myOut.println(Log.getStackTraceString(e2));
                }
            } else {
                HttpServiceReceiver.show(mContext, value, mimeType, extension);
            }
        }
    }
    e = files.propertyNames();
    while (e.hasMoreElements()) {
        element = (String) e.nextElement();
        myOut.println("  UPLOADED: '" + value + "' = '" + files.getProperty(value) + "'");
    }

    final StringBuilder buf = new StringBuilder();
    for (Entry<Object, Object> kv : header.entrySet())
        buf.append(kv.getKey() + " : " + kv.getValue() + "\n");

    return new NanoHTTPDReceiver.Response(HTTP_OK, mimeType, uri);
}

From source file:br.com.ingenieux.mojo.beanstalk.env.DumpEnvironmentSettings.java

protected Object executeInternal() throws Exception {
    DescribeConfigurationOptionsResult configOptions = getService()
            .describeConfigurationOptions(new DescribeConfigurationOptionsRequest()
                    .withApplicationName(applicationName).withEnvironmentName(curEnv.getEnvironmentName()));

    for (ConfigurationOptionDescription o : configOptions.getOptions()) {
        String key = String.format("beanstalk.env.%s.%s", o.getNamespace().replace(":", "."), o.getName());

        for (Map.Entry<String, ConfigurationOptionSetting> entry : COMMON_PARAMETERS.entrySet()) {
            ConfigurationOptionSetting cos = entry.getValue();

            if (cos.getNamespace().equals(o.getNamespace()) && cos.getOptionName().equals(o.getName())) {
                key = entry.getKey();/*from   w  w  w.  j  a v  a2 s .  c  om*/
                break;
            }
        }

        defaultSettings.put(key, o);
    }

    DescribeConfigurationSettingsResult configurationSettings = getService()
            .describeConfigurationSettings(new DescribeConfigurationSettingsRequest()
                    .withApplicationName(applicationName).withEnvironmentName(curEnv.getEnvironmentName()));

    Properties newProperties = new Properties();

    if (configurationSettings.getConfigurationSettings().isEmpty()) {
        throw new IllegalStateException("No Configuration Settings received");
    }

    ConfigurationSettingsDescription configSettings = configurationSettings.getConfigurationSettings().get(0);

    Map<String, ConfigurationOptionSetting> keyMap = new LinkedHashMap<String, ConfigurationOptionSetting>();

    for (ConfigurationOptionSetting d : configSettings.getOptionSettings()) {
        String key = String.format("beanstalk.env.%s.%s", d.getNamespace().replaceAll(":", "."),
                d.getOptionName());
        String defaultValue = "";
        String outputKey = key;

        keyMap.put(key, d);

        for (Map.Entry<String, ConfigurationOptionSetting> cosEntry : COMMON_PARAMETERS.entrySet()) {
            ConfigurationOptionSetting v = cosEntry.getValue();

            boolean match = v.getNamespace().equals(d.getNamespace())
                    && v.getOptionName().equals(d.getOptionName());

            if (match) {
                outputKey = cosEntry.getKey();
                break;
            }
        }

        if (defaultSettings.containsKey(outputKey)) {
            defaultValue = StringUtils.defaultString(defaultSettings.get(outputKey).getDefaultValue());
        }

        String value = d.getValue();

        if (null == value || StringUtils.isBlank("" + value)) {
            continue;
        }

        if (!defaultValue.equals(value)) {
            if (!value.contains(curEnv.getEnvironmentId())) {
                getLog().info("Adding property " + key);

                if (changedOnly) {
                    String curValue = project.getProperties().getProperty(outputKey);

                    if (!value.equals(curValue)) {
                        newProperties.put(outputKey, value);
                    }
                } else {
                    newProperties.put(outputKey, value);
                }
            } else {
                getLog().info("Ignoring property " + outputKey + "(value=" + value
                        + ") due to containing references to the environment id");
            }

        } else {
            getLog().debug("Ignoring property " + key + " (defaulted)");
        }
    }

    if ("properties".equals(this.outputFileFormat)) {
        String comment = "elastic beanstalk environment properties for " + curEnv.getEnvironmentName();
        if (null != outputFile) {
            newProperties.store(new FileOutputStream(outputFile), comment);
        } else {
            newProperties.store(System.out, comment);
        }
    } else if ("yaml".equals(this.outputFileFormat)) {
        PrintStream printStream = System.out;

        if (null != outputFile) {
            printStream = new PrintStream(outputFile);
        }

        printStream.println("option_settings:");

        for (Map.Entry<Object, Object> e : newProperties.entrySet()) {
            ConfigurationOptionSetting c = keyMap.get("" + e.getKey());
            String value = "" + e.getValue();

            printStream.println("  - namespace: " + c.getNamespace());
            printStream.println("    option_name: " + c.getOptionName());
            printStream.println("    value: " + value);
        }

        printStream.close();
    }

    return null;
}

From source file:org.apache.geode.distributed.internal.DistributionConfigImpl.java

public void setApiProps(Properties apiProps) {
    if (apiProps != null) {
        setSource(apiProps, ConfigSource.api());
        this.modifiable = true;
        Iterator it = apiProps.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry me = (Map.Entry) it.next();
            String propName = (String) me.getKey();
            this.props.put(propName, me.getValue());
            if (specialPropName(propName)) {
                continue;
            }/*from w  ww  .  j a  v  a 2  s . c  o  m*/
            String propVal = (String) me.getValue();
            if (propVal != null) {
                this.setAttribute(propName, propVal.trim(), this.sourceMap.get(propName));
            }
        }
        // Make attributes read only
        this.modifiable = false;
    }
}

From source file:org.apache.geode.distributed.internal.DistributionConfigImpl.java

/**
 * Creates a new <code>DistributionConfigImpl</code> with the given non-default configuration
 * properties. See {@link org.apache.geode.distributed.DistributedSystem#connect} for a list of
 * exceptions that may be thrown.//www  .  j  a  va 2  s  .  com
 * 
 * @param nonDefault The configuration properties specified by the caller
 * @param ignoreGemFirePropsFile whether to skip loading distributed system properties from
 *        gemfire.properties file
 * @param isConnected whether to skip Validation for SSL properties and copy of ssl properties to
 *        other ssl properties. This parameter will be used till we provide support for ssl-*
 *        properties.
 *
 * @since GemFire 8.0
 */
public DistributionConfigImpl(Properties nonDefault, boolean ignoreGemFirePropsFile, boolean isConnected) {
    HashMap props = new HashMap();
    if (!ignoreGemFirePropsFile) {// For admin bug #40434
        props.putAll(loadPropertiesFromURL(DistributedSystem.getPropertyFileURL(), false));
    }
    props.putAll(loadPropertiesFromURL(DistributedSystem.getSecurityPropertiesFileURL(), true));

    // Now override values picked up from the file with values passed
    // in from the caller's code
    if (nonDefault != null) {
        props.putAll(nonDefault);
        setSource(nonDefault, ConfigSource.api());
    }
    // Now remove all user defined properties from props.
    for (Object entry : props.entrySet()) {
        Map.Entry<String, String> ent = (Map.Entry<String, String>) entry;
        if (((String) ent.getKey()).startsWith(USERDEFINED_PREFIX_NAME)) {
            userDefinedProps.put(ent.getKey(), ent.getValue());
        }
    }
    // Now override values picked up from the file or code with values
    // from the system properties.
    String[] attNames = getAttributeNames();

    // For gemfire.security-* properties, we will need to look at
    // all the system properties instead of looping through attNames
    Set attNameSet = new HashSet();
    for (int index = 0; index < attNames.length; ++index) {
        attNameSet.add(GEMFIRE_PREFIX + attNames[index]);
    }

    /* clone() is a synchronized method for Properties (actually in Hashtable) */
    Properties sysProps = (Properties) System.getProperties().clone();
    Iterator<?> sysPropsIter = sysProps.entrySet().iterator();
    while (sysPropsIter.hasNext()) {
        Map.Entry sysEntry = (Map.Entry) sysPropsIter.next();
        String sysName = (String) sysEntry.getKey();
        if (attNameSet.contains(sysName) || sysName.startsWith(GEMFIRE_PREFIX + SECURITY_PREFIX_NAME)
                || sysName.startsWith(GEMFIRE_PREFIX + SSL_SYSTEM_PROPS_NAME)) {
            String sysValue = (String) sysEntry.getValue();
            if (sysValue != null) {
                String attName = sysName.substring(GEMFIRE_PREFIX.length());
                props.put(attName, sysValue);
                this.sourceMap.put(attName, ConfigSource.sysprop());
            }
        }
    }
    sysProps.clear(); // clearing cloned SysProps

    final Properties overriddenDefaults = ProcessLauncherContext.getOverriddenDefaults();
    if (!overriddenDefaults.isEmpty()) {
        for (String key : overriddenDefaults.stringPropertyNames()) {
            // only apply the overridden default if it's not already specified in props
            final String property = key.substring(ProcessLauncherContext.OVERRIDDEN_DEFAULTS_PREFIX.length());
            if (!props.containsKey((property))) {
                props.put(property, overriddenDefaults.getProperty(key));
                this.sourceMap.put(property, ConfigSource.launcher());
            }
        }
    }

    initialize(props);

    if (securityPeerAuthInit != null && securityPeerAuthInit.length() > 0) {
        System.setProperty(SECURITY_SYSTEM_PREFIX + SECURITY_PEER_AUTH_INIT, securityPeerAuthInit);
    }
    if (securityPeerAuthenticator != null && securityPeerAuthenticator.length() > 0) {
        System.setProperty(SECURITY_SYSTEM_PREFIX + SECURITY_PEER_AUTHENTICATOR, securityPeerAuthenticator);
    }

    Iterator iter = security.entrySet().iterator();
    while (iter.hasNext()) {
        Map.Entry entry = (Map.Entry) iter.next();
        System.setProperty(SECURITY_SYSTEM_PREFIX + (String) entry.getKey(), (String) entry.getValue());
    }
    if (!isConnected) {
        copySSLPropsToServerSSLProps();
        copySSLPropsToJMXSSLProps();
        copyClusterSSLPropsToGatewaySSLProps();
        copySSLPropsToHTTPSSLProps();
    }

    // Make attributes writeable only
    this.modifiable = true;
    validateConfigurationProperties(props);
    validateSSLEnabledComponentsConfiguration();
    // Make attributes read only
    this.modifiable = false;

}

From source file:edu.uci.ics.asterix.aql.translator.AqlTranslator.java

private void handleCreateFeedPolicyStatement(AqlMetadataProvider metadataProvider, Statement stmt,
        IHyracksClientConnection hcc) throws Exception {
    MetadataTransactionContext mdTxnCtx = MetadataManager.INSTANCE.beginTransaction();
    metadataProvider.setMetadataTxnContext(mdTxnCtx);
    String dataverse;//  ww w .  j  a  va  2 s. c o  m
    String policy;
    FeedPolicy newPolicy = null;
    CreateFeedPolicyStatement cfps = (CreateFeedPolicyStatement) stmt;
    dataverse = getActiveDataverse(null);
    policy = cfps.getPolicyName();
    MetadataLockManager.INSTANCE.createFeedPolicyBegin(dataverse, dataverse + "." + policy);
    try {
        FeedPolicy feedPolicy = MetadataManager.INSTANCE.getFeedPolicy(metadataProvider.getMetadataTxnContext(),
                dataverse, policy);
        if (feedPolicy != null) {
            if (cfps.getIfNotExists()) {
                MetadataManager.INSTANCE.commitTransaction(mdTxnCtx);
                return;
            } else {
                throw new AlgebricksException("A policy with this name " + policy + " already exists.");
            }
        }
        boolean extendingExisting = cfps.getSourcePolicyName() != null;
        String description = cfps.getDescription() == null ? "" : cfps.getDescription();
        if (extendingExisting) {
            FeedPolicy sourceFeedPolicy = MetadataManager.INSTANCE.getFeedPolicy(
                    metadataProvider.getMetadataTxnContext(), dataverse, cfps.getSourcePolicyName());
            if (sourceFeedPolicy == null) {
                sourceFeedPolicy = MetadataManager.INSTANCE.getFeedPolicy(
                        metadataProvider.getMetadataTxnContext(), MetadataConstants.METADATA_DATAVERSE_NAME,
                        cfps.getSourcePolicyName());
                if (sourceFeedPolicy == null) {
                    throw new AlgebricksException("Unknown policy " + cfps.getSourcePolicyName());
                }
            }
            Map<String, String> policyProperties = sourceFeedPolicy.getProperties();
            policyProperties.putAll(cfps.getProperties());
            newPolicy = new FeedPolicy(dataverse, policy, description, policyProperties);
        } else {
            Properties prop = new Properties();
            try {
                InputStream stream = new FileInputStream(cfps.getSourcePolicyFile());
                prop.load(stream);
            } catch (Exception e) {
                throw new AlgebricksException("Unable to read policy file" + cfps.getSourcePolicyFile());
            }
            Map<String, String> policyProperties = new HashMap<String, String>();
            for (Entry<Object, Object> entry : prop.entrySet()) {
                policyProperties.put((String) entry.getKey(), (String) entry.getValue());
            }
            newPolicy = new FeedPolicy(dataverse, policy, description, policyProperties);
        }
        MetadataManager.INSTANCE.addFeedPolicy(mdTxnCtx, newPolicy);
        MetadataManager.INSTANCE.commitTransaction(mdTxnCtx);
    } catch (Exception e) {
        abort(e, e, mdTxnCtx);
        throw e;
    } finally {
        MetadataLockManager.INSTANCE.createFeedPolicyEnd(dataverse, dataverse + "." + policy);
    }
}

From source file:org.apache.asterix.app.translator.QueryTranslator.java

protected void handleCreateFeedPolicyStatement(AqlMetadataProvider metadataProvider, Statement stmt)
        throws AlgebricksException, HyracksDataException {
    String dataverse;//ww  w . j  av  a 2s .com
    String policy;
    FeedPolicyEntity newPolicy = null;
    MetadataTransactionContext mdTxnCtx = null;
    CreateFeedPolicyStatement cfps = (CreateFeedPolicyStatement) stmt;
    dataverse = getActiveDataverse(null);
    policy = cfps.getPolicyName();
    MetadataLockManager.INSTANCE.createFeedPolicyBegin(dataverse, dataverse + "." + policy);
    try {
        mdTxnCtx = MetadataManager.INSTANCE.beginTransaction();
        metadataProvider.setMetadataTxnContext(mdTxnCtx);
        FeedPolicyEntity feedPolicy = MetadataManager.INSTANCE
                .getFeedPolicy(metadataProvider.getMetadataTxnContext(), dataverse, policy);
        if (feedPolicy != null) {
            if (cfps.getIfNotExists()) {
                MetadataManager.INSTANCE.commitTransaction(mdTxnCtx);
                return;
            } else {
                throw new AlgebricksException("A policy with this name " + policy + " already exists.");
            }
        }
        boolean extendingExisting = cfps.getSourcePolicyName() != null;
        String description = cfps.getDescription() == null ? "" : cfps.getDescription();
        if (extendingExisting) {
            FeedPolicyEntity sourceFeedPolicy = MetadataManager.INSTANCE.getFeedPolicy(
                    metadataProvider.getMetadataTxnContext(), dataverse, cfps.getSourcePolicyName());
            if (sourceFeedPolicy == null) {
                sourceFeedPolicy = MetadataManager.INSTANCE.getFeedPolicy(
                        metadataProvider.getMetadataTxnContext(), MetadataConstants.METADATA_DATAVERSE_NAME,
                        cfps.getSourcePolicyName());
                if (sourceFeedPolicy == null) {
                    throw new AlgebricksException("Unknown policy " + cfps.getSourcePolicyName());
                }
            }
            Map<String, String> policyProperties = sourceFeedPolicy.getProperties();
            policyProperties.putAll(cfps.getProperties());
            newPolicy = new FeedPolicyEntity(dataverse, policy, description, policyProperties);
        } else {
            Properties prop = new Properties();
            try {
                InputStream stream = new FileInputStream(cfps.getSourcePolicyFile());
                prop.load(stream);
            } catch (Exception e) {
                throw new AlgebricksException("Unable to read policy file" + cfps.getSourcePolicyFile(), e);
            }
            Map<String, String> policyProperties = new HashMap<>();
            for (Entry<Object, Object> entry : prop.entrySet()) {
                policyProperties.put((String) entry.getKey(), (String) entry.getValue());
            }
            newPolicy = new FeedPolicyEntity(dataverse, policy, description, policyProperties);
        }
        MetadataManager.INSTANCE.addFeedPolicy(mdTxnCtx, newPolicy);
        MetadataManager.INSTANCE.commitTransaction(mdTxnCtx);
    } catch (RemoteException | ACIDException e) {
        abort(e, e, mdTxnCtx);
        throw new HyracksDataException(e);
    } finally {
        MetadataLockManager.INSTANCE.createFeedPolicyEnd(dataverse, dataverse + "." + policy);
    }
}