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

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

Introduction

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

Prototype

public static String stripToEmpty(String str) 

Source Link

Document

Strips whitespace from the start and end of a String returning an empty String if null input.

Usage

From source file:com.opendesign.controller.ProductController.java

/**
 * ??() ?///from w w  w. j a  va  2  s.c om
 * 
 * @param product
 * @param request
 * @param saveType
 * @return
 * @throws Exception
 */
private JsonModelAndView saveProduct(DesignWorkVO product, MultipartHttpServletRequest request, int saveType)
        throws Exception {

    /*
     * ?? ? ?  
     */
    boolean isUpdate = saveType == SAVE_TYPE_UPDATE;

    Map<String, Object> resultMap = new HashMap<String, Object>();

    UserVO loginUser = CmnUtil.getLoginUser(request);
    if (loginUser == null || !StringUtil.isNotEmpty(loginUser.getSeq())) {
        resultMap.put("result", "100");
        return new JsonModelAndView(resultMap);
    }

    /*   ?  ? */
    if (isUpdate) {
        DesignWorkVO prevProduct = designerService.getDesignWork(product.getSeq());
        if (!loginUser.getSeq().equals(prevProduct.getMemberSeq())) {
            resultMap.put("result", "101");
            return new JsonModelAndView(resultMap);
        }
    }

    /*
     * ? ?
     */
    MultipartFile fileUrlFile = request.getFile("fileUrlFile");
    if (fileUrlFile != null) {
        String fileName = fileUrlFile.getOriginalFilename().toLowerCase();
        if (!(fileName.endsWith(".jpg") || fileName.endsWith(".png"))) {
            resultMap.put("result", "202");
            return new JsonModelAndView(resultMap);
        }

    } else {
        /* ?  ? . */
        if (!isUpdate) {
            resultMap.put("result", "201");
            return new JsonModelAndView(resultMap);
        }
    }

    /*
     * license
     */
    String license01 = request.getParameter("license01");
    String license02 = request.getParameter("license02");
    String license03 = request.getParameter("license03");
    String license = license01 + license02 + license03;
    product.setLicense(license);

    //??  ?///// 
    String stem = request.getParameter("origin");
    if (stem == null) {
        product.setOriginSeq("0");
    } else {
        product.setOriginSeq(stem);
    }
    //////////////////////////////

    /* 
     * ?? ?  "0"  
     */
    String point = request.getParameter("point");
    point = String.valueOf(CmnUtil.getIntValue(point)); //null--> 0 
    product.setPoint(point);

    /*
     * ? ?
     */
    List<MultipartFile> productFileList = new ArrayList<MultipartFile>();
    List<MultipartFile> openSourceFileList = new ArrayList<MultipartFile>();

    Iterator<String> iterator = request.getFileNames();
    while (iterator.hasNext()) {
        String fileNameKey = iterator.next();

        MultipartFile reqFile = request.getFile(fileNameKey);
        if (reqFile != null) {
            boolean existProuductFile = fileNameKey.startsWith("productFile");
            boolean existOpenSourceFile = fileNameKey.startsWith("openSourceFile");
            if (existProuductFile || existOpenSourceFile) {
                long fileSize = reqFile.getSize();
                if (fileSize > LIMIT_FILE_SIZE) {
                    resultMap.put("result", "203");
                    resultMap.put("fileName", reqFile.getOriginalFilename());
                    return new JsonModelAndView(resultMap);

                }

                if (existProuductFile) {
                    productFileList.add(reqFile);
                }

                if (existOpenSourceFile) {
                    openSourceFileList.add(reqFile);
                }
            }
        }
    }
    product.setMemberSeq(loginUser.getSeq());

    /*
     * ?? 
     */
    String fileUploadDir = CmnUtil.getFileUploadDir(request, FileUploadDomain.PRODUCT);
    File thumbFile = null;
    if (fileUrlFile != null) {
        String saveFileName = UUID.randomUUID().toString();
        thumbFile = CmnUtil.saveFile(fileUrlFile, fileUploadDir, saveFileName);

        String fileUploadDbPath = CmnUtil.getFileUploadDbPath(request, thumbFile);
        product.setThumbUri(fileUploadDbPath);
    }

    /*
     * ??() 
     */
    List<DesignPreviewImageVO> productList = new ArrayList<DesignPreviewImageVO>();
    List<String> productFilePaths = new ArrayList<>();

    for (MultipartFile aFile : productFileList) {
        String saveFileName = UUID.randomUUID().toString();
        File file = CmnUtil.saveFile(aFile, fileUploadDir, saveFileName);

        productFilePaths.add(file.getAbsolutePath());

        String fileUploadDbPath = CmnUtil.getFileUploadDbPath(request, file);

        DesignPreviewImageVO productFile = new DesignPreviewImageVO();
        productFile.setFilename(aFile.getOriginalFilename());
        productFile.setFileUri(fileUploadDbPath);

        productList.add(productFile);

    }
    product.setImageList(productList);

    /*
     *   
     */
    List<DesignWorkFileVO> openSourceList = new ArrayList<DesignWorkFileVO>();
    for (MultipartFile aFile : openSourceFileList) {
        String saveFileName = UUID.randomUUID().toString();
        File file = CmnUtil.saveFile(aFile, fileUploadDir, saveFileName);
        String fileUploadDbPath = CmnUtil.getFileUploadDbPath(request, file);

        //openSourceFile? ??? client?  .
        String filenameOpenSourceFile = StringUtils
                .stripToEmpty(request.getParameter("filename_" + aFile.getName()));

        DesignWorkFileVO openSourceFile = new DesignWorkFileVO();
        openSourceFile.setFilename(filenameOpenSourceFile);
        openSourceFile.setFileUri(fileUploadDbPath);

        openSourceList.add(openSourceFile);

    }
    product.setFileList(openSourceList);

    /*
     * ??/?   ?  ? ? 
     * ?? ? ?  ? ? ? 
     */
    String thumbFilePath = "";
    if (thumbFile != null) {
        thumbFilePath = thumbFile.getAbsolutePath();
    }
    ThumbnailManager.resizeNClone4DesignWork(thumbFilePath, productFilePaths);

    /*
     *  
     */
    String tag = request.getParameter("tag");
    if (StringUtil.isNotEmpty(tag)) {
        String[] tags = tag.split(",");

        int addIndex = 0;
        StringBuffer tagBuffer = new StringBuffer();
        for (String aTag : tags) {
            if (StringUtil.isNotEmpty(aTag)) {
                aTag = aTag.trim();
                tagBuffer.append(aTag);
                tagBuffer.append("|");
                addIndex++;
            }

            if (addIndex >= 5) {
                break;
            }
        }

        if (addIndex > 0) {
            tagBuffer.insert(0, "|");

            tag = tagBuffer.toString();
        }
    }
    product.setTags(tag);

    String currentDate = Day.getCurrentTimestamp().substring(0, 12);
    product.setRegisterTime(currentDate);
    product.setUpdateTime(currentDate);

    String[] categoryCodes = request.getParameterValues("categoryCodes");

    /*
     *  
     */
    if (isUpdate) {
        String[] removeProductSeqs = request.getParameterValues("removeProductSeq");
        String[] removeOpenSourceSeqs = request.getParameterValues("removeOpenSourceSeq");

        int projectSeq = service.updateProduct(product, categoryCodes, removeProductSeqs, removeOpenSourceSeqs);

    } else {
        int projectSeq = service.insertProduct(product, categoryCodes);

    }

    resultMap.put(RstConst.P_NAME, RstConst.V_SUCESS);
    return new JsonModelAndView(resultMap);

}

From source file:com.activecq.tools.auth.impl.PluggableAuthenticationHandlerImpl.java

/** OSGi Activate/Deactivate **/

protected void activate(ComponentContext componentContext) {
    Dictionary properties = componentContext.getProperties();

    enabled = PropertiesUtil.toBoolean(properties.get(PROP_ENABLED), DEFAULT_ENABLED);

    trustCredentials = PropertiesUtil.toString(properties.get(PROP_TRUST_CREDENTIALS),
            DEFAULT_TRUST_CREDENTIALS);/*from w w  w . jav a  2  s. c  o  m*/

    requestCredentialsRedirect = StringUtils.stripToEmpty(PropertiesUtil
            .toString(properties.get(PROP_REQUEST_CREDENTIALS_REDIRECT), DEFAULT_REQUEST_CREDENTIALS_REDIRECT));

    try {
        adminResourceResolver = resourceResolverFactory.getAdministrativeResourceResolver(null);
    } catch (LoginException ex) {
    }
}

From source file:gov.nih.nci.calims2.ui.generic.crud.CRUDTableDecorator.java

/**
 * Returns the json representation of the item commands.
 * /*w  w w  . j  ava2s  .  c om*/
 * @return the json representation of the item commands
 */
public String getItemCommands() {
    List<Map<String, Object>> commands = new ArrayList<Map<String, Object>>();
    for (Command itemCommand : table.getItemCommands()) {
        Map<String, Object> command = new HashMap<String, Object>();
        command.put("icon", itemCommand.getIconClass());
        command.put("url", itemCommand.getUrl());
        command.put("javascriptFunction", StringUtils.stripToEmpty(itemCommand.getJavascriptFunction()));
        String tooltip = messageSource
                .getMessage(config.getViewPrefix() + "list.command." + itemCommand.getName(), null, locale);
        command.put("tooltip", tooltip);
        commands.add(command);
    }
    return jsonSerializer.serializeCollection(commands);
}

From source file:gda.jython.translator.GeneralTranslator.java

static char nextPart(String string, int currentlocation) {
    String rightOfStart = StringUtils.stripToEmpty(StringUtils.substring(string, currentlocation));
    char nextPart = rightOfStart.charAt(0);
    return nextPart;
}

From source file:com.panet.imeta.job.entry.JobEntryBase.java

/**
 * ??--string/*from   w  ww  . jav  a  2 s  . co  m*/
 * 
 * @param parameter
 * @return
 */
public static String parameterToString(String[] parameter) {
    if (parameter != null && parameter.length > 0) {
        return StringUtils.stripToEmpty(parameter[0]);
    }
    return "";
}

From source file:gda.jython.translator.GeneralTranslator.java

static char previousPart(String string, int currentlocation) {
    String leftOfStart = StringUtils.stripToEmpty(StringUtils.substring(string, 0, currentlocation));
    char previousPart = leftOfStart.charAt(leftOfStart.length() - 1);
    return previousPart;
}

From source file:com.adobe.acs.tools.test_page_generator.impl.TestPageGeneratorServlet.java

private Object eval(final ScriptEngine scriptEngine, final Object value) {

    if (scriptEngine == null) {
        log.warn("ScriptEngine is null; cannot evaluate");
        return value;
    } else if (value instanceof String[]) {
        final List<String> scripts = new ArrayList<String>();
        final String[] values = (String[]) value;

        for (final String val : values) {
            scripts.add(String.valueOf(this.eval(scriptEngine, val)));
        }/* w w  w .  j  a  v  a2s .c  o m*/

        return scripts.toArray(new String[scripts.size()]);
    } else if (!(value instanceof String)) {
        return value;
    }

    final String stringValue = StringUtils.stripToEmpty((String) value);

    String script;
    if (StringUtils.startsWith(stringValue, "{{") && StringUtils.endsWith(stringValue, "}}")) {

        script = StringUtils.removeStart(stringValue, "{{");
        script = StringUtils.removeEnd(script, "}}");
        script = StringUtils.stripToEmpty(script);

        try {
            return scriptEngine.eval(script);
        } catch (ScriptException e) {
            log.error("Could not evaluation the test page property ecma [ {} ]", script);
        }
    }

    return value;
}

From source file:com.activecq.tools.errorpagehandler.impl.ErrorPageHandlerImpl.java

/**
 * Get configured error page extension//from  w w  w .  j a  va 2  s.  c om
 *
 * @return
 */
public String getErrorPageExtension() {
    return StringUtils.stripToEmpty(this.errorPageExtension);
}

From source file:com.activecq.tools.errorpagehandler.impl.ErrorPageHandlerImpl.java

/**
 * Add extension as configured via OSGi Component Property
 *
 * Defaults to .html/*from ww  w  .  ja v a  2s  .  c  o  m*/
 *
 * @param path
 * @return
 */
private String applyExtension(String path) {
    if (path == null) {
        return null;
    }

    String ext = getErrorPageExtension();
    if (StringUtils.isBlank(ext)) {
        return path;
    }

    return StringUtils.stripToEmpty(path).concat(".").concat(ext);
}

From source file:com.adobe.acs.commons.errorpagehandler.impl.ErrorPageHandlerImpl.java

/**
 * Check if this is an image request.//from w  ww. j a  v  a  2s .  c  o m
 *
 * @param request the current {@link SlingHttpServletRequest}
 * @return true if this request should deliver an image.
 */
private boolean isImageRequest(final SlingHttpServletRequest request) {
    if (StringUtils.isBlank(errorImagePath)) {
        log.warn("ACS AEM Commons error page handler enabled to handle error images, "
                + "but no error image path was provided.");
        return false;
    }

    final String extension = StringUtils
            .stripToEmpty(StringUtils.lowerCase(request.getRequestPathInfo().getExtension()));

    return ArrayUtils.contains(errorImageExtensions, extension);
}