protected Properties getProperties(
      ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws Exception {

    Properties properties = new Properties();

    ThemeDisplay themeDisplay = (ThemeDisplay) resourceRequest.getAttribute(WebKeys.THEME_DISPLAY);

    Map<String, ConfigurationModel> configurationModels =
        _configurationModelRetriever.getConfigurationModels(themeDisplay.getLanguageId());

    String factoryPid = ParamUtil.getString(resourceRequest, "factoryPid");
    String pid = ParamUtil.getString(resourceRequest, "pid");

    ConfigurationModel configurationModel = configurationModels.get(pid);

    if ((configurationModel == null) && Validator.isNotNull(factoryPid)) {
      configurationModel = configurationModels.get(factoryPid);
    }

    if (configurationModel == null) {
      return properties;
    }

    Configuration configuration = _configurationModelRetriever.getConfiguration(pid);

    if (configuration == null) {
      return properties;
    }

    ExtendedAttributeDefinition[] attributeDefinitions =
        configurationModel.getAttributeDefinitions(ConfigurationModel.ALL);

    for (AttributeDefinition attributeDefinition : attributeDefinitions) {
      String[] values = AttributeDefinitionUtil.getProperty(attributeDefinition, configuration);

      String value = null;

      // See http://goo.gl/JhYK7g

      if (values.length == 1) {
        value = values[0];
      } else if (values.length > 1) {
        value = StringUtil.merge(values, "\n");
      }

      properties.setProperty(attributeDefinition.getID(), value);
    }

    return properties;
  }