Converts a map of properties from server format to client format.<p>

@param cms the CmsObject to use for VFS operations
@param props the map of properties
@param propConfig the property configuration

@return the converted property map
180165
public static Map<String, String> convertPropertiesToClientFormat(
        CmsObject cms,
        Map<String, String> props,
        Map<String, CmsXmlContentProperty> propConfig) {

        return convertProperties(cms, props, propConfig, true);
    }
853174
public static Properties format(Config config) {
        Properties properties = new Properties();
        writeConfig("", config, properties);
        return properties;
    }
656331
public CmsFormatterConfiguration getFormatters(CmsObject cms, CmsResource res) {

        if (CmsResourceTypeFunctionConfig.isFunction(res)) {

            CmsFormatterConfigurationCacheState formatters = getCachedFormatters();
            I_CmsFormatterBean function = formatters.getFormatters().get(res.getStructureId());
            if (function != null) {
                return CmsFormatterConfiguration.create(cms, Collections.singletonList(function));
            } else {
                if ((!res.getStructureId().isNullUUID())
                    && cms.existsResource(res.getStructureId(), CmsResourceFilter.IGNORE_EXPIRATION)) {
                    // usually if it's just been created, but not added to the configuration cache yet
                    CmsFormatterBeanParser parser = new CmsFormatterBeanParser(cms, new HashMap<>());
                    try {
                        function = parser.parse(
                            CmsXmlContentFactory.unmarshal(cms, cms.readFile(res)),
                            res.getRootPath(),
                            "" + res.getStructureId());
                        return CmsFormatterConfiguration.create(cms, Collections.singletonList(function));
                    } catch (Exception e) {
                        LOG.warn(e.getLocalizedMessage(), e);
                        return CmsFormatterConfiguration.EMPTY_CONFIGURATION;
                    }

                } else {
                    // if a new function has been dragged on the page, it doesn't exist in the VFS yet, so we need a different
                    // instance as a replacement
                    CmsResource defaultFormatter = CmsFunctionRenderer.getDefaultFunctionInstance(cms);
                    if (defaultFormatter != null) {
                        I_CmsFormatterBean defaultFormatterBean = formatters.getFormatters().get(
                            defaultFormatter.getStructureId());
                        return CmsFormatterConfiguration.create(cms, Collections.singletonList(defaultFormatterBean));
                    } else {
                        LOG.warn("Could not read default formatter for functions.");
                        return CmsFormatterConfiguration.EMPTY_CONFIGURATION;
                    }
                }
            }
        } else {
            try {
                int resTypeId = res.getTypeId();
                return getFormatters(
                    cms,
                    OpenCms.getResourceManager().getResourceType(resTypeId),
                    getFormattersFromSchema(cms, res));
            } catch (CmsLoaderException e) {
                LOG.warn(e.getLocalizedMessage(), e);
                return CmsFormatterConfiguration.EMPTY_CONFIGURATION;
            }
        }
    }
449304
public void setProperties(List<Property> props) {
    this.proplist = props;
    this.properties = new HashMap(props.size());
    for (Property prop : props)
      properties.put(prop.getName(), prop);

    // analyze properties to find lookup set
    findLookupProperties();
  }

  /**
   * The set of properties Duke records can have, and their associated
   * cleaners, comparators, and probabilities.
   */
  public List<Property> getProperties() {
    return proplist;
  }

  /**
   * The properties which are used to identify records, rather than
   * compare them.
   */
  public Collection<Property> getIdentityProperties() {
    Collection<Property> ids = new ArrayList();
    for (Property p : getProperties())
      if (p.isIdProperty())
        ids.add(p);
    return ids;
  }

  /**
   * Returns the property with the given name, or null if there is no
   * such property.
   */
  public Property getPropertyByName(String name) {
    return properties.get(name);
  }

  /**
   * Returns the properties Duke queries for in the Lucene index. This
   * is a subset of getProperties(), and is computed based on the
   * probabilities and the threshold.
   */
  public Collection<Property> getLookupProperties() {
    return lookups;
  }

  /**
   * Validates the configuration to verify that it makes sense.
   * Rejects configurations that will fail during runtime.
   */
  public void validate() {
    // verify that we do have properties
    if (properties == null || properties.isEmpty())
      throw new DukeConfigException("Configuration has no properties at all");

    // check if max prob is below threshold
    // this code duplicates code in findLookupProperties(), but prefer
    // that to creating an attribute
    double prob = 0.5;
    for (Property prop : properties.values()) {
      if (prop.getHighProbability() == 0.0)
        // if the probability is zero we ignore the property entirely
        continue;

      prob = Utils.computeBayes(prob, prop.getHighProbability());
    }
    if (prob < threshold)
      throw new DukeConfigException("Maximum possible probability is " + prob +
                                 ", which is below threshold (" + threshold +
                                 "), which means no duplicates will ever " +
                                 "be found");

    // check that we have at least one ID property
    if (getIdentityProperties().isEmpty())
      throw new DukeConfigException("No ID properties.");

    // check that we only have one ID property
    if (getIdentityProperties().size() > 1)
      throw new DukeConfigException("Can only have one ID property.");
  }

  private void findLookupProperties() {
    List<Property> candidates = new ArrayList();
    for (Property prop : properties.values())
      // leave out properties that are either not used for comparisons,
      // or which have lookup turned off explicitly
      if (!prop.isIdProperty() &&
          !prop.isIgnoreProperty() &&
          prop.getLookupBehaviour() != Property.Lookup.FALSE &&
          prop.getHighProbability() != 0.0)
        candidates.add(prop);


    // sort them, lowest high prob to highest high prob
    Collections.sort(candidates, new HighComparator());

    // run over and find all those needed to get above the threshold
    int last = -1;
    double prob = 0.5;
    for (int ix = 0; ix < candidates.size(); ix++) {
      Property prop = candidates.get(ix);
      prob = Utils.computeBayes(prob, prop.getHighProbability());
      if (prob >= threshold) {
        last = ix;
        break;
      }
    }

    if (last == -1)
      lookups = new ArrayList();
    else
      lookups = new ArrayList(candidates.subList(0, last + 1));


    // need to also add TRUE and REQUIRED
    for (Property p : proplist) {
      if (p.getLookupBehaviour() != Property.Lookup.TRUE &&
          p.getLookupBehaviour() != Property.Lookup.REQUIRED)
        continue;

      if (lookups.contains(p))
        continue;

      lookups.add(p);
    }
  }

  private static class HighComparator implements java.util.Comparator<Property> {
    public int compare(Property p1, Property p2) {
      if (p1.getHighProbability() < p2.getHighProbability())
        return 1;
      else if (p1.getHighProbability() == p2.getHighProbability())
        return 0;
      else
        return -1;
    }
  }

  public Configuration copy() {
    ConfigurationImpl copy = new ConfigurationImpl();
    for (DataSource src : datasources)
      copy.addDataSource(0, src);
    for (DataSource src : group1)
      copy.addDataSource(1, src);
    for (DataSource src : group2)
      copy.addDataSource(2, src);

    copy.setThreshold(threshold);
    copy.setMaybeThreshold(thresholdMaybe);
    copy.addDatabase(database1);
    if (database2 != null)
      copy.addDatabase(database2);

    List<Property> newprops = new ArrayList();
    for (Property p : proplist)
      newprops.add(p.copy());
    copy.setProperties(newprops);

    return copy;
  }


  @Override
  public List<Comparator> getCustomComparators() {
	return this.customComparators;
  }

  @Override
  public void addCustomComparator(Comparator comparator) {
	this.customComparators.add(comparator);
  }
}
1352380
protected Reader doCreateScript(Properties props) {
		BundleStringJsonifier bsj = new BundleStringJsonifier(props, addQuoteToMessageKey);
		String script = template.toString();
		String messages = bsj.serializeBundles().toString();
		script = script.replaceFirst("@namespace", RegexUtil.adaptReplacementToMatcher(namespace));
		script = script.replaceFirst("@messages", RegexUtil.adaptReplacementToMatcher(messages));

		return new StringReader(script);
	}
1157690
public Map<String, String> getParameters(CmsObject cms) {

        Map<String, String> result = new LinkedHashMap<String, String>(m_parameters);
        if (cms != null) {
            String userParamsStr = (String)(cms.getRequestContext().getCurrentUser().getAdditionalInfo().get(
                "ADE_PARAMS"));
            if (userParamsStr != null) {
                Map<String, String> userParams = CmsStringUtil.splitAsMap(userParamsStr, "|", ":");
                result.putAll(userParams);
            }
        }
        return result;
    }
1296336
private Map<String, String> getContentsByContainerName(
        CmsContainerElementBean element,
        Collection<CmsContainer> containers) {

        CmsFormatterConfiguration configs = getFormatterConfiguration(element.getResource());
        Map<String, String> result = new HashMap<String, String>();
        for (CmsContainer container : containers) {
            String content = getContentByContainer(element, container, configs);
            if (content != null) {
                content = removeScriptTags(content);
            }
            result.put(container.getName(), content);
        }
        return result;
    }
710465
private CmsClientSitemapEntry toClientEntry(CmsJspNavElement navElement, boolean isRoot) throws CmsException {

        CmsResource entryPage = null;
        CmsObject cms = getCmsObject();
        CmsClientSitemapEntry clientEntry = new CmsClientSitemapEntry();
        CmsResource entryFolder = null;

        CmsResource ownResource = navElement.getResource();
        clientEntry.setResourceState(ownResource.getState());
        CmsResource defaultFileResource = null;
        if (ownResource.isFolder() && !navElement.isNavigationLevel()) {
            defaultFileResource = cms.readDefaultFile(ownResource, CmsResourceFilter.ONLY_VISIBLE_NO_DELETED);
        }

        Map<String, CmsClientProperty> ownProps = getClientProperties(cms, ownResource, false);

        Map<String, CmsClientProperty> defaultFileProps = null;
        if (defaultFileResource != null) {
            defaultFileProps = getClientProperties(cms, defaultFileResource, false);
            clientEntry.setDefaultFileId(defaultFileResource.getStructureId());
            clientEntry.setDefaultFileType(
                OpenCms.getResourceManager().getResourceType(defaultFileResource.getTypeId()).getTypeName());
            clientEntry.setDefaultFileReleased(defaultFileResource.isReleasedAndNotExpired(System.currentTimeMillis()));
        } else {
            defaultFileProps = new HashMap<String, CmsClientProperty>();
        }
        boolean isDefault = isDefaultFile(ownResource);
        clientEntry.setId(ownResource.getStructureId());
        clientEntry.setResourceTypeId(ownResource.getTypeId());
        clientEntry.setFolderDefaultPage(isDefault);
        if (navElement.getResource().isFolder()) {
            entryFolder = navElement.getResource();
            entryPage = defaultFileResource;
            clientEntry.setName(entryFolder.getName());
            if (entryPage == null) {
                entryPage = entryFolder;
            }
            if (!isRoot && isSubSitemap(navElement)) {
                clientEntry.setEntryType(EntryType.subSitemap);
                clientEntry.setDefaultFileType(null);
            } else if (navElement.isNavigationLevel()) {
                clientEntry.setEntryType(EntryType.navigationLevel);
            }
            CmsLock folderLock = cms.getLock(entryFolder);
            clientEntry.setHasForeignFolderLock(
                !folderLock.isUnlocked() && !folderLock.isOwnedBy(cms.getRequestContext().getCurrentUser()));
            if (!cms.getRequestContext().getCurrentProject().isOnlineProject()) {
                List<CmsResource> blockingChildren = cms.getBlockingLockedResources(entryFolder);
                clientEntry.setBlockingLockedChildren((blockingChildren != null) && !blockingChildren.isEmpty());
            }
        } else {
            entryPage = navElement.getResource();
            clientEntry.setName(entryPage.getName());
            if (isRedirectType(entryPage.getTypeId())) {
                clientEntry.setEntryType(EntryType.redirect);
                CmsFile file = getCmsObject().readFile(entryPage);
                I_CmsXmlDocument content = CmsXmlContentFactory.unmarshal(getCmsObject(), file);
                I_CmsXmlContentValue linkValue = content.getValue(
                    REDIRECT_LINK_TARGET_XPATH,
                    getCmsObject().getRequestContext().getLocale());
                String link = linkValue != null
                ? linkValue.getStringValue(getCmsObject())
                : Messages.get().getBundle(getWorkplaceLocale()).key(Messages.GUI_REDIRECT_SUB_LEVEL_0);
                clientEntry.setRedirectTarget(link);
            } else {
                clientEntry.setEntryType(EntryType.leaf);
            }
        }
        if (entryPage.isFile()) {
            List<CmsAlias> aliases = OpenCms.getAliasManager().getAliasesForStructureId(
                getCmsObject(),
                entryPage.getStructureId());
            if (!aliases.isEmpty()) {
                List<String> aliasList = new ArrayList<String>();
                for (CmsAlias alias : aliases) {
                    String aliasPath = alias.getAliasPath();
                    aliasList.add(aliasPath);
                }
                clientEntry.setAliases(aliasList);
            }
        }
        long dateExpired = navElement.getResource().getDateExpired();
        if (dateExpired != CmsResource.DATE_EXPIRED_DEFAULT) {
            clientEntry.setDateExpired(
                CmsDateUtil.getDate(new Date(dateExpired), DateFormat.SHORT, getWorkplaceLocale()));
        }
        long dateReleased = navElement.getResource().getDateReleased();
        if (dateReleased != CmsResource.DATE_RELEASED_DEFAULT) {
            clientEntry.setDateReleased(
                CmsDateUtil.getDate(new Date(dateReleased), DateFormat.SHORT, getWorkplaceLocale()));
        }
        clientEntry.setResleasedAndNotExpired(
            navElement.getResource().isReleasedAndNotExpired(System.currentTimeMillis()));
        String path = cms.getSitePath(entryPage);
        clientEntry.setVfsPath(path);
        clientEntry.setOwnProperties(ownProps);
        clientEntry.setDefaultFileProperties(defaultFileProps);
        clientEntry.setSitePath(entryFolder != null ? cms.getSitePath(entryFolder) : path);
        clientEntry.setLock(generateClientLock(entryPage));
        clientEntry.setInNavigation(isRoot || navElement.isInNavigation());
        String type = OpenCms.getResourceManager().getResourceType(ownResource).getTypeName();
        clientEntry.setResourceTypeName(type);
        clientEntry.setVfsModeIcon(CmsIconUtil.getIconClasses(type, ownResource.getName(), false));

        if (!clientEntry.isSubSitemapType()) {
            if (clientEntry.isNavigationLevelType()) {
                clientEntry.setNavModeIcon(CmsIconUtil.ICON_NAV_LEVEL_BIG);
            } else if (defaultFileResource != null) {
                clientEntry.setNavModeIcon(
                    CmsIconUtil.getIconClasses(clientEntry.getDefaultFileType(), defaultFileResource.getName(), false));
            }
        }
        clientEntry.setPermissionInfo(OpenCms.getADEManager().getPermissionInfo(cms, ownResource, null));
        return clientEntry;
    }
995314
public static Map<String, CmsXmlContentProperty> resolveMacrosInProperties(
        Map<String, CmsXmlContentProperty> properties,
        I_CmsMacroResolver resolver) {

        Map<String, CmsXmlContentProperty> result = new LinkedHashMap<String, CmsXmlContentProperty>();
        for (Map.Entry<String, CmsXmlContentProperty> entry : properties.entrySet()) {
            String key = entry.getKey();
            CmsXmlContentProperty prop = entry.getValue();
            result.put(key, resolveMacrosInProperty(prop, resolver));
        }
        return result;
    }
248069
private String convertPropertyToFieldValue(CmsProperty prop) {

        if (prop == null) {
            return "";
        }
        return "" + Boolean.valueOf(prop.getValue());
    }
1109308
private void cmisProperties( CmisObject object,
                                 DocumentWriter writer ) {
        // convert properties
        List<Property<?>> list = object.getProperties();
        for (Property<?> property : list) {
            String pname = properties.findJcrName(property.getId());
            if (pname != null) {
                writer.addProperty(pname, properties.jcrValues(property));
            }
        }
    }
1103005
public Map<String, CmsXmlContentProperty> getSettingConfig(String containerName) {

        CmsFormatterConfig formatterConfig = getFormatterConfig(containerName);
        return formatterConfig != null
        ? formatterConfig.getSettingConfig()
        : Collections.<String, CmsXmlContentProperty> emptyMap();
    }
351146
public static void updateWysiwygConfig(
        Map<String, CmsXmlContentProperty> propertyConfig,
        CmsObject cms,
        CmsResource resource) {

        Map<String, CmsXmlContentProperty> wysiwygUpdates = Maps.newHashMap();
        String wysiwygConfig = null;
        for (Map.Entry<String, CmsXmlContentProperty> entry : propertyConfig.entrySet()) {
            CmsXmlContentProperty prop = entry.getValue();
            if (prop.getWidget().equals("wysiwyg")) {
                if (wysiwygConfig == null) {
                    String configStr = "";
                    try {
                        String filePath = OpenCms.getSystemInfo().getConfigFilePath(cms, "wysiwyg/property-widget");
                        String configFromVfs = (String)CmsVfsMemoryObjectCache.getVfsMemoryObjectCache().loadVfsObject(
                            cms,
                            filePath,
                            new Transformer() {

                                public Object transform(Object rootPath) {

                                    try {
                                        CmsFile file = cms.readFile(
                                            (String)rootPath,
                                            CmsResourceFilter.IGNORE_EXPIRATION);
                                        return new String(file.getContents(), "UTF-8");
                                    } catch (Exception e) {
                                        return "";
                                    }
                                }
                            });
                        configStr = configFromVfs;
                    } catch (Exception e) {
                        LOG.error(e.getLocalizedMessage(), e);
                    }

                    CmsHtmlWidgetOption opt = new CmsHtmlWidgetOption(configStr);
                    Locale locale = resource != null
                    ? OpenCms.getLocaleManager().getDefaultLocale(cms, resource)
                    : Locale.ENGLISH;
                    String json = CmsHtmlWidget.getJSONConfiguration(opt, cms, resource, locale).toString();
                    List<String> nums = Lists.newArrayList();
                    try {
                        for (byte b : json.getBytes("UTF-8")) {
                            nums.add("" + b);
                        }
                    } catch (UnsupportedEncodingException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    wysiwygConfig = "v:" + CmsStringUtil.listAsString(nums, ",");
                }
                CmsXmlContentProperty prop2 = prop.withConfig(wysiwygConfig);
                wysiwygUpdates.put(entry.getKey(), prop2);
            }
        }
        propertyConfig.putAll(wysiwygUpdates);
    }
145781
private void parseProperty(I_CmsXmlContentLocation field) {

        CmsPropertyConfig propConfig = parseProperty(m_cms, field);
        m_propertyConfigs.add(propConfig);
    }
1374013
public static Map<String, String> fromProperties(final Properties props) {
		Map<String, String> propMap = new HashMap<String, String>();
		
		for (Enumeration<?> e = props.propertyNames(); e.hasMoreElements();) {
			String key = (String) e.nextElement();
			propMap.put(key, props.getProperty(key));
		}
				
		return Collections.unmodifiableMap(propMap);
	}
761725
public Properties processProps(Map<String, Object> props, String elementNameRef) {
        final Properties properties = new Properties();
        String pid = (String) props.get(elementNameRef);

        if (pid == null) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(tc, "pid null");
            }
        } else {
            ConfigurationAdmin configAdmin = configAdminRef.getServiceWithException();
            Configuration config = null;
            try {
                // We do not want to create a missing pid, only find one that we were told exists
                Configuration[] configList = configAdmin.listConfigurations(FilterUtils.createPropertyFilter("service.pid", pid));
                if (configList != null && configList.length > 0) {
                    //bind the config to this bundle so no one else can steal it
                    config = configAdmin.getConfiguration(pid, configAdminRef.getReference().getBundle().getLocation());
                }
            } catch (Exception e) {
                //do nothing
            }
            if (config != null) {
                // Just get the first one (there should only ever be one.. )
                Dictionary<String, ?> cProps = config.getProperties();
                Enumeration<String> keys = cProps.keys();
                while (keys.hasMoreElements()) {
                    String key = keys.nextElement();
                    if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                        Tr.debug(tc, "found key: " + key);
                    }
                    // Skip certain keys
                    if (key.startsWith(".")
                            || key.startsWith("config.")
                            || key.startsWith("service.")
                            || key.equals("id")) {
                        continue;
                    }
                    Object value = cProps.get(key);
                    if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                        Tr.debug(tc, "key: " + key + " value: " + value);
                    }
                    // For scope to claims map generate String array from comma delimited string
                    value = getValue(value);
                    properties.put(key, value);
                }
            }
        }
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, elementNameRef + ": " + properties.toString());
        }
        return properties;
    }
19932
protected Map<String, CmsXmlContentProperty> getDefaultPropertiesForType(String typeName) {

        Map<String, CmsXmlContentProperty> propertyConfig = new LinkedHashMap<String, CmsXmlContentProperty>();
        CmsExplorerTypeSettings explorerType = OpenCms.getWorkplaceManager().getExplorerTypeSetting(typeName);
        if (explorerType != null) {
            List<String> defaultProps = explorerType.getProperties();
            for (String propName : defaultProps) {
                CmsXmlContentProperty property = new CmsXmlContentProperty(
                    propName,
                    "string",
                    "string",
                    "",
                    "",
                    "",
                    "",
                    null,
                    "",
                    "",
                    "false");
                propertyConfig.put(propName, property);
            }
        }
        return propertyConfig;
    }