com.checkmarx.configprovider.resource.FileContentResource Maven / Gradle / Ivy
package com.checkmarx.configprovider.resource;
import com.checkmarx.configprovider.dto.interfaces.ConfigResource;
import com.checkmarx.configprovider.dto.ResourceType;
import com.typesafe.config.Config;
import lombok.Getter;
import javax.naming.ConfigurationException;
import java.util.Optional;
/**
* Contains String content of resources of type Yml or Json
*/
@Getter
public class FileContentResource extends AbstractFileResource implements ConfigResource {
private String content;
private String name;
/**
* @deprecated use {@link #FileContentResource(String, String, ResourceType)}
*/
@Deprecated
public FileContentResource(ResourceType type, String fileContent, String name) {
this(fileContent, name, type);
}
public FileContentResource(String fileContent, String name) {
this(fileContent, name, ResourceType.getTypeByNameOrExtention(name));
}
public FileContentResource(String fileContent, String name, ResourceType type) {
this.type = type;
this.content = fileContent;
this.name = name;
}
/**
* Converts file String content of type Yml or Json to Config object.
* Other types of files are not supported.
* @return Config object
* @throws ConfigurationException exception when the string content of the resource
* can not be converted to Config object
*/
@Override
public Config loadConfig() throws ConfigurationException {
if(ResourceType.YAML.equals(type)){
config = yamlToConfig(content, "");
}else if(ResourceType.JSON.equals(type)){
config = jsonToConfig(content);
}
return config;
}
@Override
public String getName() {
return Optional.ofNullable(name).orElse(type.name()) ;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy