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

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

Introduction

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

Prototype

public static String trim(String str) 

Source Link

Document

Removes control characters (char <= 32) from both ends of this String, handling null by returning null.

Usage

From source file:com.hangum.tadpole.summary.report.DailySummaryReportJOB.java

@Override
public void execute(JobExecutionContext arg0) throws JobExecutionException {
    logger.info("daily summary report");

    try {//from  ww  w.  jav  a2s.  c o  m
        // db  .
        List<UserDBDAO> listUserDB = TadpoleSystem_UserDBQuery.getDailySummaryReportDB();

        // ?  .
        for (UserDBDAO userDBDAO : listUserDB) {
            StringBuffer strMailContent = new StringBuffer();

            // (14.06.02) mysql ?   ? ?.
            if (PublicTadpoleDefine.YES_NO.YES.name().equals(userDBDAO.getIs_summary_report())) {
                if (userDBDAO.getDBDefine() == DBDefine.MYSQL_DEFAULT
                        || userDBDAO.getDBDefine() == DBDefine.MARIADB_DEFAULT) {

                    String strSummarySQl = MySQLSummaryReport.getSQL(userDBDAO.getDb());
                    String[] arrySQLS = StringUtils.split(strSummarySQl, ";");
                    for (String strSQL : arrySQLS) {
                        String strTitle = StringUtils.split(StringUtils.trim(strSQL),
                                PublicTadpoleDefine.LINE_SEPARATOR)[0];

                        String strResult = executSQL(userDBDAO, strTitle, strSQL);
                        strMailContent.append(strResult);
                    }

                    DailySummaryReport report = new DailySummaryReport();
                    String mailContent = report.makeFullSummaryReport(userDBDAO.getDisplay_name(),
                            strMailContent.toString());

                    //  .                  
                    Utils.sendEmail(userDBDAO.getUser_seq(), userDBDAO.getDisplay_name(), mailContent);

                    if (logger.isDebugEnabled())
                        logger.debug(mailContent);
                } // end mysql db
            } // if yes
        } // for (UserDBDAO userDBDAO

    } catch (Exception e) {
        logger.error("daily summary report", e);
    }
}

From source file:com.openteach.diamond.metadata.ServiceURL.java

/**
 * //from w  w  w. j av  a2s.  com
 */
@Override
public String toString() {
    return String.format("%s://%s:%d%s%s", protocol, host, port, serviceName,
            StringUtils.isBlank(query) ? "" : "?" + StringUtils.trim(query));
}

From source file:com.fengduo.bee.web.controller.account.UserController.java

/**
 * ??//from   w w w  .jav  a 2s.c o m
 * 
 * @return
 */
@RequestMapping(value = "/savepwd", method = RequestMethod.POST)
@ResponseBody
public JsonResult savepwd(String oldPassword, String password, String confirmPwd) {
    password = StringUtils.trim(password);
    confirmPwd = StringUtils.trim(confirmPwd);
    oldPassword = StringUtils.trim(oldPassword);

    if (StringUtils.isEmpty(password) || StringUtils.isEmpty(confirmPwd) || StringUtils.isEmpty(oldPassword)) {
        return JsonResultUtils.error("?!");
    }
    if (!StringUtils.equals(password, confirmPwd)) {
        return JsonResultUtils.error("??,?!");
    }
    if (!StringUtils.equals(oldPassword, getCurrentUser().getPasswordDesc())) {
        return JsonResultUtils.error("??!");
    }

    Long userId = getCurrentUserId();
    User userById = userService.getUserById(userId);
    if (null == userById) {
        return JsonResultUtils.error("");
    }
    userService.updateUserPwd(userId, password);
    // ??
    SecurityUtils.getSubject().logout();
    return JsonResultUtils.error("??");
}

From source file:com.adobe.acs.commons.images.transformers.impl.ScaleImageTransformerImpl.java

@Override
public final Layer transform(Layer layer, final ValueMap properties) {

    if (properties == null || properties.isEmpty()) {
        log.warn("Transform [ {} ] requires parameters.", TYPE);
        return layer;
    }//www.  j a va  2s .c o  m

    log.debug("Transforming with [ {} ]", TYPE);

    Double scale = properties.get(KEY_SCALE, 1D);
    String round = StringUtils.trim(properties.get(KEY_ROUND, String.class));

    if (scale == null) {
        log.warn("Could not derive a Double value for key [ {} ] from value [ {} ]", KEY_SCALE,
                properties.get(KEY_SCALE, String.class));
        scale = 1D;
    }

    if (scale != 1D) {

        int currentWidth = layer.getWidth();
        int currentHeight = layer.getHeight();

        double newWidth = scale * currentWidth;
        double newHeight = scale * currentHeight;

        if (StringUtils.equals(ROUND_UP, round)) {
            newWidth = (int) Math.ceil(newWidth);
            newHeight = (int) Math.ceil(newHeight);
        } else if (StringUtils.equals(ROUND_DOWN, round)) {
            newWidth = (int) Math.floor(newWidth);
            newHeight = (int) Math.floor(newHeight);
        } else {
            // "round"
            newWidth = (int) Math.round(newWidth);
            newHeight = (int) Math.round(newHeight);
        }

        // Invoke the ResizeImageTransformer with the new values

        final ValueMap params = new ValueMapDecorator(new HashMap<String, Object>());
        params.put(ResizeImageTransformerImpl.KEY_WIDTH, (int) newWidth);
        params.put(ResizeImageTransformerImpl.KEY_HEIGHT, (int) newHeight);

        layer = resizeImageTransformer.transform(layer, params);
    }

    return layer;
}

From source file:jp.ikedam.jenkins.plugins.updatesitesmanager.DescribedUpdateSite.java

/**
 * Constructor
 * 
 * @param id
 * @param url
 */
public DescribedUpdateSite(String id, String url) {
    super(StringUtils.trim(id), StringUtils.trim(url));
}

From source file:com.edgenius.wiki.render.handler.PageInfoHandler.java

public List<RenderPiece> handle(RenderContext renderContext, Map<String, String> values)
        throws RenderHandlerException {
    if (page == null) {
        throw new RenderHandlerException("Invalid content. {pageinfo} must inside a page.");
    }//  ww  w  .  j  ava 2  s  .c o m
    String type = StringUtils.trim(values.get(NameConstants.TYPE));
    if (StringUtils.isEmpty(type)
            || (!NameConstants.CREATOR.equals(type) && !NameConstants.MODIFIER.equals(type))) {
        log.warn("Unable to find valid type parameter from PageInfoMacro");
        throw new RenderHandlerException(
                "Type parameter is invalid, either creator or modifier. Sample {pageinfo:type=creator}");
    }

    User user = (NameConstants.CREATOR.equals(type)) ? page.getCreator() : page.getModifier();
    if (user == null) {
        //anonymous user
        user = userReadingService.getUser(-1);
    }
    Date date = (NameConstants.CREATOR.equals(type)) ? page.getCreatedDate() : page.getModifiedDate();

    String value = StringUtils.trimToEmpty(values.get("value"));

    List<RenderPiece> pieces = new ArrayList<RenderPiece>();
    pieces.add(new TextModel("<div class=\"macroPageinfo\" " + NameConstants.WAJAX + "=\""
            + RichTagUtil.buildWajaxAttributeString(this.getClass().getName(), values) + "\">"));

    StringBuffer buf = new StringBuffer();

    if (value.length() == 0 || "portrait".equals(value)) {
        String portraitUrl = UserUtil.getPortraitUrl(user.getPortrait());
        buf.append("<div class=\"portrait\">")
                .append(GwtUtils.getUserPortraitHTML(portraitUrl, user.getFullname(), -1)).append("</div>");
        pieces.add(new TextModel(buf.toString()));
    }

    if (value.length() == 0 || "name".equals(value)) {
        String msg = NameConstants.CREATOR.equals(type) ? messageService.getMessage("created.by")
                : messageService.getMessage("last.updated.by");
        pieces.add(new TextModel("<div class=\"name\">" + msg + " "));
        pieces.add(WikiUtil.createUserLinkModel(user));
        pieces.add(new TextModel("</div>"));
    }

    if ((value.length() == 0 || "date".equals(value)) && date != null) {
        buf = new StringBuffer();
        String showDate = DateUtil.toDisplayDateWithPrep(WikiUtil.getUser(), date, messageService);
        buf.append("<div class=\"date\">").append(showDate).append("</div>");
        pieces.add(new TextModel(buf.toString()));
    }

    if ("status".equals(value)) {
        buf = new StringBuffer();
        buf.append("<div class=\"status\">").append(user.getSetting().getStatus()).append("</div>");
        pieces.add(new TextModel(buf.toString()));
    }
    pieces.add(new TextModel("</div>"));

    return pieces;
}

From source file:com.edgenius.wiki.ext.tabs.TabMacro.java

public void execute(StringBuffer buffer, MacroParameter params) throws MalformedMacroException {
    String tabKey = params.getParam(Macro.GROUP_KEY);
    RenderContext context = params.getRenderContext();
    if (StringUtils.indexOf(tabKey, '-') == -1) {
        errorGroup(buffer, params, tabKey);
    } else {//from ww w .  j a va  2  s. c  o  m
        String[] keys = tabKey.split("-");
        if (keys.length != 2) {
            errorGroup(buffer, params, tabKey);
        } else {
            String grpKey = keys[0];
            String name = StringUtils.trim(params.getParam(NameConstants.NAME));
            if (StringUtils.isBlank(name)) {
                //default name
                name = DEFAULT_TAB_NAME;
            }
            //OK, save tabKey and tabName information into Global parameter, used by TabsHandler
            Map<String, Map<String, String>> tabsMap = (Map<String, Map<String, String>>) context
                    .getGlobalParam(TabsHandler.class.getName());
            if (tabsMap == null) {
                tabsMap = new HashMap<String, Map<String, String>>();
                context.putGlobalParam(TabsHandler.class.getName(), tabsMap);
            }
            Map<String, String> tabList = tabsMap.get(grpKey);
            if (tabList == null) {
                //ordered - so LinkedHashMap
                tabList = new LinkedHashMap<String, String>();
                tabsMap.put(grpKey, tabList);
            }
            tabList.put(tabKey, name);

            if (RenderContext.RENDER_TARGET_EXPORT.equals(context.getRenderTarget())
                    || RenderContext.RENDER_TARGET_PLAIN_VIEW.equals(context.getRenderTarget())) {
                //for print and export, tab name will be just before the content body
                buffer.append("<div class=\"macroTabName\">").append(name).append("</div>");
            }

            //use "tab-"+tabKey as div ID, so that TabsHanlder can process render tabs correctly.
            String content = params.getContent();
            buffer.append("<div class=\"macroTab\" id=\"tab-").append(tabKey).append("\" name=\"").append(name)
                    .append("\">").append(content).append("</div>");
        }
    }
}

From source file:com.siberhus.web.ckeditor.utils.PathUtils.java

/**
 * Remove or add slashes as indicated in rules
 * //from   w  w w. j  av a 2s .  c om
 * rules: space separated list of rules R- = remove slash on right R+ = add
 * slash on right L- = remove slash on left L+ = add slash on left
 */
public static String checkSlashes(String path, String rules, boolean isUrl) {
    String result = StringUtils.trim(path);
    if (StringUtils.isNotBlank(result)) {
        String rls[] = rules.split(" ");
        String separator = isUrl ? "/" : File.separator;
        for (String r : rls) {
            boolean isAdd = ("+".equals(String.valueOf(r.charAt(1))));
            if (isAdd) {
                if ("L".equals(StringUtils.upperCase(r.charAt(0) + ""))) {
                    // Add separator on left
                    if (!result.startsWith("/") && !result.startsWith("\\")) {
                        result = separator + result;
                    }
                } else {
                    // Add separator on right
                    if (!result.endsWith("/") && !result.endsWith("\\")) {
                        result = result + separator;
                    }
                }
            } else {
                if ("L".equals(StringUtils.upperCase(r.charAt(0) + ""))) {
                    // Remove separator on left
                    if (result.startsWith("/") || result.startsWith("\\")) {
                        result = result.substring(1);
                    }
                } else {
                    // Remove separator on right
                    if (result.endsWith("/") || result.endsWith("\\")) {
                        result = result.substring(0, result.length() - 1);
                    }
                }
            }
        }
    }
    return result;
}

From source file:com.bluexml.xforms.generator.forms.renderable.forms.RenderableActionField.java

public RenderableActionField(XFormsGenerator generationManager, ActionField formElement) {

    super();//  w  ww.  j a  va2 s.  co m
    /*
     * Ds un wrkflw, une transition de name "Relire" et de label
     * "Envoyer  la relecture" nous donne un id="transition/Relire". En
     * dehors d'un workflow, l'id du bouton est "Relire". Dans tous les cas,
     * "Envoyer  la relecture" est le texte affich sur le bouton.
     */
    ModelElement mel = formElement.getRef();
    if (mel != null) {
        mel = (ModelElement) generationManager.getFormGenerator().getRealObject(mel);
    }
    String actionName;
    String infixe;

    if ((mel != null) && (mel instanceof Transition)) { // this is a
        // workflow
        // transition button
        actionName = formElement.getId();
        infixe = MsgId.INT_ACT_CODE_WRKFLW_TRANSITION.getText();
    } else if (formElement.getId().equals(MsgId.INT_ACT_CODE_WRKFLW_SAVE.getText())) {
        actionName = "save"; // not used
        infixe = MsgId.INT_ACT_CODE_WRKFLW_SAVE.getText();
    } else { // this is a user-added action button
        actionName = StringUtils.trim(formElement.getAction_handler());
        infixe = MsgId.INT_ACT_CODE_EXECUTE.getText();
    }
    label = formElement.getLabel();
    // submission = new ModelElementSubmission(MsgId.INT_URI_SCHEME_WRITER +
    // infixe + "/"
    // + actionName, label, true, DEFAULT_VALIDATE_FIRST);
    String action = MsgId.INT_URI_SCHEME_WRITER + infixe + "?" + MsgId.INT_ACT_PARAM_EXEC_ACTION + "="
            + actionName;
    submission = new ModelElementSubmission(action, label, true, DEFAULT_VALIDATE_FIRST);
    RenderableSubmit button = new RenderableSubmit(submission, label, false);
    add(button);
}

From source file:com.smartitengineering.util.opensearch.impl.QueryImpl.java

public void setTitle(String title) {
    Utils.checkMaxLength(TITLE, TITLE_MAX_LEN, title);
    this.title = StringUtils.trim(title);
}