Example usage for org.apache.commons.lang StringUtils substringAfterLast

List of usage examples for org.apache.commons.lang StringUtils substringAfterLast

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils substringAfterLast.

Prototype

public static String substringAfterLast(String str, String separator) 

Source Link

Document

Gets the substring after the last occurrence of a separator.

Usage

From source file:org.ednovo.gooru.application.converter.GooruImageUtil.java

public boolean resizeImageByDimensions(String srcFilePath, String targetFolderPath, String filenamePrefix,
        String dimensions, String resourceGooruOid, String sessionToken, String thumbnail) {
    try {//from w  w  w . j  a v  a 2s . c  o m
        logger.debug(" src : {} /= target : {}", srcFilePath, targetFolderPath);
        String[] imageDimensions = dimensions.split(",");
        if (filenamePrefix == null) {
            filenamePrefix = StringUtils.substringAfterLast(srcFilePath, "/");
            if (filenamePrefix.contains(".")) {
                filenamePrefix = StringUtils.substringBeforeLast(filenamePrefix, ".");
            }
        }

        for (String dimension : imageDimensions) {
            String[] xy = dimension.split(X);
            int width = Integer.valueOf(xy[0]);
            int height = Integer.valueOf(xy[1]);
            resizeImageByDimensions(srcFilePath, width, height,
                    targetFolderPath + filenamePrefix + "-" + dimension + "." + getFileExtenstion(srcFilePath));
        }

        try {
            HttpClient client = new HttpClient();
            HttpMethod method = new PutMethod("http://" + propertyMap.get(SERVER_PATH) + "/"
                    + propertyMap.get(REST_END_POINT) + "/media/resource/thumbnail?sessionToken=" + sessionToken
                    + "&resourceGooruOid=" + resourceGooruOid + "&thumbnail=" + thumbnail);
            client.executeMethod(method);
        } catch (Exception ex) {
            logger.error("something went wrong while making rest api call", ex);
        }

        return true;
    } catch (Exception ex) {
        logger.error("Multiple scaling of image failed for src : " + srcFilePath + " : ", ex);
        return false;
    }
}

From source file:org.ednovo.gooru.application.converter.GooruImageUtil.java

public static String getFileExtenstion(String filePath) {

    return StringUtils.substringAfterLast(filePath, ".");

}

From source file:org.ednovo.gooru.application.converter.GooruImageUtil.java

public static String getFileName(String filePath) {
    return StringUtils.substringAfterLast(filePath, "/");
}

From source file:org.ednovo.gooru.application.util.GooruImageUtil.java

public static String getFileExtenstion(String filePath) {
    if (filePath != null) {
        if (filePath.contains("?")) {
            filePath = StringUtils.substringBefore(filePath, "?");
        }//from  ww  w . j  ava2  s  .co  m
        return StringUtils.substringAfterLast(filePath, ".");
    } else {
        return null;
    }
}

From source file:org.ednovo.gooru.application.util.GooruImageUtil.java

public static String getFileName(String filePath) {
    if (filePath != null) {
        if (filePath.contains("?")) {
            filePath = StringUtils.substringBefore(filePath, "?");
        }/*  w w w  .  j  av  a2  s. c  o  m*/
        return StringUtils.substringAfterLast(filePath, "/");
    } else {
        return null;
    }
}

From source file:org.ednovo.gooru.application.util.GooruImageUtil.java

public static String getFileNamePrefix(String filePath) {
    if (filePath != null) {
        if (filePath.contains("/")) {
            filePath = StringUtils.substringAfterLast(filePath, "/");
        }//from   ww w . j a  v a 2s. c om
        if (filePath.contains("?")) {
            filePath = StringUtils.substringBefore(filePath, "?");
        }
        return StringUtils.substringBeforeLast(filePath, ".");
    } else {
        return null;
    }

}

From source file:org.ednovo.gooru.application.util.GooruImageUtil.java

public static String moveImage(String srcFilePath, String destFolderPath, String fileNamePrefix)
        throws IOException {
    File srcFile = new File(srcFilePath);
    String fileExtension = StringUtils.substringAfterLast(srcFilePath, ".");
    File destFile = new File(destFolderPath + fileNamePrefix + "." + fileExtension);
    try {//w w w .j  a va  2  s. c  o m
        if (destFile.exists() && srcFile.exists()) {
            destFile.delete();
        }
        FileUtils.moveFile(srcFile, destFile);
    } catch (IOException exception) {
        LOGGER.error("Move File Failed:" + exception);
        throw exception;
    }
    return destFile.getAbsolutePath();
}

From source file:org.ednovo.gooru.application.util.GooruImageUtil.java

public static String copyImage(String srcFilePath, String destFolderPath, String fileNamePrefix)
        throws IOException {
    File srcFile = new File(srcFilePath);
    String fileExtension = StringUtils.substringAfterLast(srcFilePath, ".");
    File destFile = new File(destFolderPath + fileNamePrefix + "." + fileExtension);
    try {//from w w  w .  j av a  2  s  .  c o m
        if (destFile.exists() && srcFile.exists()) {
            destFile.delete();
        }
        FileUtils.copyFile(srcFile, destFile);
    } catch (IOException exception) {
        LOGGER.error("copy File Failed:" + exception);
        throw exception;
    }
    return destFile.getAbsolutePath();
}

From source file:org.ednovo.gooru.controllers.api.ResourceRestController.java

@AuthorizeOperations(operations = { GooruOperationConstants.OPERATION_RESOURCE_UPDATE })
@Transactional(readOnly = false, propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
@RequestMapping(method = RequestMethod.POST, value = "/resource/{gooruContentId}/thumbnail")
public ModelAndView updateResourceThumbnail(HttpServletRequest request,
        @PathVariable(GOORU_CONTENT_ID) String gooruContentId,
        @RequestParam(value = UPLOAD_FILENAME) String fileName,
        @RequestParam(value = SESSIONTOKEN, required = false) String sessionToken, HttpServletResponse response)
        throws Exception {
    request.setAttribute(PREDICATE, RES_UPDATE_THUMBNAIL);
    Map<String, Object> formField = RequestUtil.getMultipartItems(request);

    boolean isHasSlash = StringUtils.contains(fileName, '\\');

    if (isHasSlash) {
        fileName = StringUtils.substringAfterLast(fileName, Character.toString('\\'));
    }//  w  ww  .j a v  a 2s.  com

    Resource resource = resourceService.updateResourceThumbnail(gooruContentId, fileName, formField);

    ModelAndView jsonmodel = new ModelAndView(REST_MODEL);
    jsonmodel.addObject(MODEL, resource.getFolder() + "/" + fileName);
    return jsonmodel;
}

From source file:org.ednovo.gooru.converter.service.ConversionServiceImpl.java

public List<String> resizeImageByDimensions(String srcFilePath, String targetFolderPath, String filenamePrefix,
        String dimensions, String resourceGooruOid, String sessionToken, String thumbnail, String apiEndPoint) {
    String imagePath = null;/*from w  w w  . j  a v  a2  s . com*/
    List<String> list = new ArrayList<String>();
    try {
        logger.debug(" src : {} /= target : {}", srcFilePath, targetFolderPath);
        String[] imageDimensions = dimensions.split(",");
        if (filenamePrefix == null) {
            filenamePrefix = StringUtils.substringAfterLast(srcFilePath, "/");
            if (filenamePrefix.contains(".")) {
                filenamePrefix = StringUtils.substringBeforeLast(filenamePrefix, ".");
            }
        }

        for (String dimension : imageDimensions) {
            String[] xy = dimension.split(X);
            int width = Integer.valueOf(xy[0]);
            int height = Integer.valueOf(xy[1]);
            imagePath = resizeImageByDimensions(srcFilePath, width, height,
                    targetFolderPath + filenamePrefix + "-" + dimension + "." + getFileExtenstion(srcFilePath));

            list.add(imagePath);
        }

        try {
            JSONObject json = new JSONObject();
            json.put(RESOURCE_GOORU_OID, resourceGooruOid);
            json.put(THUMBNAIL, thumbnail);
            JSONObject jsonAlias = new JSONObject();
            jsonAlias.put(MEDIA, json);
            String jsonString = jsonAlias.toString();
            StringRequestEntity requestEntity = new StringRequestEntity(jsonString, APP_JSON, "UTF-8");
            HttpClient client = new HttpClient();
            PutMethod postmethod = new PutMethod(
                    apiEndPoint + "/media/resource/thumbnail?sessionToken=" + sessionToken);
            postmethod.setRequestEntity(requestEntity);
            client.executeMethod(postmethod);
        } catch (Exception ex) {
            logger.error("rest api call failed!", ex.getMessage());
        }

    } catch (Exception ex) {
        logger.error("Multiple scaling of image failed for src : " + srcFilePath + " : ", ex);
    }

    return list;
}