Example usage for org.springframework.util DefaultPropertiesPersister DefaultPropertiesPersister

List of usage examples for org.springframework.util DefaultPropertiesPersister DefaultPropertiesPersister

Introduction

In this page you can find the example usage for org.springframework.util DefaultPropertiesPersister DefaultPropertiesPersister.

Prototype

DefaultPropertiesPersister

Source Link

Usage

From source file:com.sfxie.extension.spring4.properties.PropertiesLoaderUtils.java

/**
 * Fill the given properties from the given EncodedResource,
 * potentially defining a specific encoding for the properties file.
 * @param props the Properties instance to load into
 * @param resource the resource to load from
 * @throws IOException in case of I/O errors
 *//*  ww w.j  a v a  2  s  .c om*/
public static void fillProperties(Properties props, EncodedResource resource) throws IOException {

    fillProperties(props, resource, new DefaultPropertiesPersister());
}

From source file:com.sfxie.extension.spring4.properties.SwitchPropertiesLoaderSupport.java

/**
 * Set the PropertiesPersister to use for parsing properties files.
 * The default is DefaultPropertiesPersister.
 * @see org.springframework.util.DefaultPropertiesPersister
 *//*  w  ww .  jav a2 s  .c  om*/
public void setPropertiesPersister(PropertiesPersister propertiesPersister) {
    this.propertiesPersister = (propertiesPersister != null ? propertiesPersister
            : new DefaultPropertiesPersister());
}

From source file:com.teasoft.teavote.controller.ElectionInfoController.java

@RequestMapping(value = "api/teavote/election-info", method = RequestMethod.POST)
@ResponseBody/*from   w  ww  . jav  a2 s .  c o  m*/
public JSONResponse saveElectionInfo(@RequestParam("logo") MultipartFile file,
        @RequestParam("commissioner") String commissioner, @RequestParam("orgName") String orgName,
        @RequestParam("electionDate") String electionDate, @RequestParam("startTime") String startTime,
        @RequestParam("endTime") String endTime, @RequestParam("pollingStation") String pollingStation,
        @RequestParam("startTimeInMillis") String startTimeInMillis,
        @RequestParam("endTimeInMillis") String endTimeInMillis, HttpServletRequest request) throws Exception {

    JSONResponse jSONResponse = new JSONResponse();
    //Candidate candidate = new Candidate();
    Map<String, String> errorMessages = new HashMap<>();

    if (!file.isEmpty()) {
        BufferedImage image = ImageIO.read(file.getInputStream());
        Integer width = image.getWidth();
        Integer height = image.getHeight();

        if (Math.abs(width - height) > MAX_IMAGE_DIM_DIFF) {
            errorMessages.put("image", "Invalid Image Dimension - Max abs(Width - height) must be 50 or less");
        } else {
            //Resize image
            BufferedImage originalImage = ImageIO.read(file.getInputStream());
            int type = originalImage.getType() == 0 ? BufferedImage.TYPE_INT_ARGB : originalImage.getType();

            BufferedImage resizeImagePng = resizeImage(originalImage, type);
            ConfigLocation configLocation = new ConfigLocation();
            //String rootPath = request.getSession().getServletContext().getRealPath("/");
            File serverFile = new File(configLocation.getConfigPath() + File.separator + "teavote-logo.jpg");

            switch (file.getContentType()) {
            case "image/png":
                ImageIO.write(resizeImagePng, "png", serverFile);
                break;
            case "image/jpeg":
                ImageIO.write(resizeImagePng, "jpg", serverFile);
                break;
            default:
                ImageIO.write(resizeImagePng, "png", serverFile);
                break;
            }
        }
    } else {
        //            errorMessages.put("image", "File Empty");
    }

    //Load properties
    Properties prop = appProp.getProperties();
    ConfigLocation configLocation = new ConfigLocation();
    prop.load(configLocation.getExternalProperties());

    prop.setProperty("teavote.orgName", orgName);
    prop.setProperty("teavote.commissioner", commissioner);
    prop.setProperty("teavote.electionDate", electionDate);
    prop.setProperty("teavote.startTime", startTime);
    prop.setProperty("teavote.endTime", endTime);
    prop.setProperty("teavote.pollingStation", pollingStation);
    prop.setProperty("teavote.startTimeInMillis", startTimeInMillis);
    prop.setProperty("teavote.endTimeInMillis", endTimeInMillis);

    File f = new File(configLocation.getConfigPath() + File.separator + "application.properties");
    OutputStream out = new FileOutputStream(f);
    DefaultPropertiesPersister p = new DefaultPropertiesPersister();
    p.store(prop, out, "Header Comment");

    if (errorMessages.isEmpty()) {
        return new JSONResponse(true, 0, null, Enums.JSONResponseMessage.SUCCESS.toString());
    }

    return new JSONResponse(false, 0, errorMessages, Enums.JSONResponseMessage.SERVER_ERROR.toString());
}

From source file:org.springframework.core.io.support.PropertiesLoaderSupport.java

/**
 * Set the PropertiesPersister to use for parsing properties files.
 * The default is DefaultPropertiesPersister.
 * @see org.springframework.util.DefaultPropertiesPersister
 *//*ww w. j  a  v  a 2s .c o  m*/
public void setPropertiesPersister(@Nullable PropertiesPersister propertiesPersister) {
    this.propertiesPersister = (propertiesPersister != null ? propertiesPersister
            : new DefaultPropertiesPersister());
}