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.edgenius.wiki.ext.textnut.BPListParaserHandler.java

public void endElement(String uri, String localName, String qName) throws SAXException {
    if (qName.equals("key")) {
        String content = StringUtils.trim(characters.toString());
        if ("WebMainResource".equals(content)) {
            mainResource = 1;/*from  w  w w. ja v  a  2 s .co  m*/
        } else if ("WebSubresources".equals(content)) {
            mainResource = 2;
        } else if ("WebResourceURL".equals(content)) {
            tagFlag = 2;
        } else if ("WebResourceData".equals(content)) {
            tagFlag = 5;
        } else {
            //other
            tagFlag = 0;
        }
        return;
    }
    if (qName.equals("string")) {
        if (tagFlag == 2) {
            url = StringUtils.trim(characters.toString());
        }
    }

    if (tagFlag == 5 && qName.equals("data")) {
        File file = new File(fileCacheDir, FileUtil.getFileName(url));
        //Attachments
        if (url != null) {
            try {
                if (mainResource == 1) {
                    //HTML
                    url = NutParser.MAIN_RESOURCE_URL;
                }
                FileUtils.writeByteArrayToFile(file,
                        Base64.decodeBase64(characters.toString().trim().getBytes()));
                //cache to return map
                files.put(url, file);
            } catch (IOException e) {
                log.error("Unable to write attachment for BPList", e);
            }
        } else {
            log.error("Null URL for file resource in BPList");
        }
    }

}

From source file:de.iteratec.iteraplan.model.attribute.EnumAV.java

public void setName(String name) {
    this.name = StringUtils.trim(StringUtil.removeIllegalXMLChars(name));
    this.value = this.name;
}

From source file:com.hangum.tadpole.application.start.dialog.login.OTPLoginDialog.java

@Override
protected void okPressed() {
    String strOTPCode = StringUtils.trim(textOTPCode.getText());
    if (!NumberUtils.isNumber(strOTPCode)) {
        textOTPCode.setFocus();/*from   w ww .  java  2  s  .  c o  m*/
        MessageDialog.openWarning(getShell(), Messages.get().Warning, Messages.get().OTPLoginDialog_3); //$NON-NLS-1$
        return;
    }

    setIntOTPCode(NumberUtils.toInt(strOTPCode));

    super.okPressed();
}

From source file:gemlite.core.webapp.tools.DataModelController.java

@RequestMapping(value = "/model", method = RequestMethod.POST)
@ResponseBody/* w ww  . jav  a  2 s .co  m*/
public ModelAndView model(HttpServletRequest request, ModelAndView modelAndView) {
    modelAndView = new ModelAndView("tools/data_model");
    String driver = StringUtils.trim((String) request.getParameter("driver"));
    String url = StringUtils.trim((String) request.getParameter("url"));
    String user = StringUtils.trim((String) request.getParameter("user"));
    String pwd = StringUtils.trim((String) request.getParameter("pwd"));
    String name = StringUtils.trim((String) request.getParameter("name"));
    String inputSchema = StringUtils.trim((String) request.getParameter("inputSchema"));
    String includes = StringUtils.trim((String) request.getParameter("includes"));
    String excludes = StringUtils.trim((String) request.getParameter("excludes"));
    String packageName = StringUtils.trim((String) request.getParameter("packageName"));
    String directory = StringUtils.trim((String) request.getParameter("directory"));

    DataModelConf conf = new DataModelConf(driver, url, user, pwd, name, inputSchema, includes, excludes,
            packageName, directory);
    try {
        HashMap<String, String> map = getValueMap(conf);
        modelAndView.addAllObjects(map);
        command.webExecute(driver, url, user, pwd, name, inputSchema, includes, excludes, packageName,
                directory);
        DataModelService service = JpaContext.getService(DataModelService.class);
        service.deleteAll();
        service.save(conf);
        modelAndView.addObject("msg", "Successed!");
    } catch (Exception e) {
        modelAndView.addObject("msg", "Failed! Please check the configuration. " + e);
    }

    return modelAndView;
}

From source file:hudson.plugins.sonar.template.SonarPomGenerator.java

private static SimpleTemplate generateSrcDirsPluginTemplate(List<String> srcDirs)
        throws IOException, InterruptedException {
    SimpleTemplate srcTemplate = new SimpleTemplate("hudson/plugins/sonar/sonar-multi-sources.template");
    StringBuffer sourcesXml = new StringBuffer();
    for (int i = 1; i < srcDirs.size(); i++) {
        sourcesXml.append("<source><![CDATA[").append(StringUtils.trim(srcDirs.get(i)))
                .append("]]></source>\n");
    }//from  w ww  .  j  av a 2  s. c o m
    srcTemplate.setAttribute("sources", sourcesXml.toString());
    return srcTemplate;
}

From source file:com.qualitesys.sonarqcr4pblplugin.pbl.QcrQcrXmlParser.java

@Override
protected String messageFor(SMInputCursor measureCursor) throws XMLStreamException {
    //    System.out.println("php QcrQcrXmlParser messageFor "
    //            +" measureCursor "+measureCursor.toString()
    //            );
    return StringUtils.trim(measureCursor.collectDescendantText());
}

From source file:com.thoughtworks.go.config.ArtifactPlan.java

public void setDest(String dest) {
    this.dest = StringUtils.trim(dest);
}

From source file:com.edgenius.wiki.render.impl.LinkReplacerFilter.java

@Override
public void replace(StringBuffer buffer, MatchResult result, RenderContext context) {
    LinkModel link = getLinkModel(result, context.getCurrentRegion());
    LinkReplacer replacer = (LinkReplacer) context.getGlobalParam(LinkReplacer.class.getName());

    if (replacer.getType() == WikiConstants.AUTO_FIX_COPY_LINK) {
        //change spaceUname: append @spaceUname after link
        if (StringUtils.isBlank(link.getSpaceUname())
                || StringUtils.equals(link.getSpaceUname(), replacer.getFromSpaceUname())) {
            buffer.append(getLink(replacer.getFromSpaceUname(), link));
            return;
        }/*from w  w  w  . j  av a  2  s . c  om*/
    } else if (replacer.getType() == WikiConstants.AUTO_FIX_TITLE_CHANGE_LINK) {
        //change pageTitle: change old title to new one

        //link has not assign space, then from(content's space) must be same with the space of updated title page 
        if (((StringUtils.isBlank(link.getSpaceUname())
                && StringUtils.equalsIgnoreCase(replacer.getFromSpaceUname(), replacer.getToSpaceUname()))
                //if assigned space, then it must be same with the space of updated title page
                || StringUtils.equalsIgnoreCase(link.getSpaceUname(), replacer.getToSpaceUname()))
                //title must be same
                && StringUtils.equalsIgnoreCase(StringUtils.trim(link.getLink()),
                        StringUtils.trim(replacer.getOldTitle()))) {
            link.setLink(replacer.getNewTitle());
            buffer.append(getLink(null, link));
            return;
        }
    }

    String body;
    //append original text if no change
    if (context.getCurrentRegion() != null) {
        body = context.getCurrentRegion().getBody();
    } else {
        body = result.group(0);
    }

    buffer.append(body);

}

From source file:com.hangum.tadpole.login.core.otp.GoogleOTPLoginDialog.java

@Override
protected void okPressed() {
    String strOTPCode = StringUtils.trim(textOTPCode.getText());
    if (!NumberUtils.isNumber(strOTPCode)) {
        textOTPCode.setFocus();//from  ww w. ja  v  a2s  .  c  om
        MessageDialog.openWarning(getShell(), CommonMessages.get().Warning, Messages.get().OTPLoginDialog_3); //$NON-NLS-1$
        return;
    }

    setIntOTPCode(NumberUtils.toInt(strOTPCode));

    super.okPressed();
}

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

public List<RenderPiece> handle(RenderContext renderContext, Map<String, String> values)
        throws RenderHandlerException {

    Map<String, Map<String, String>> tabsMap = (Map<String, Map<String, String>>) renderContext
            .getGlobalParam(TabsHandler.class.getName());
    if (tabsMap == null || tabsMap.size() == 0) {
        //No valid tab found for tabs
        return null;
    }// w ww  . jav  a 2 s  . co  m

    String grpKey = values.get(Macro.GROUP_KEY);

    //tabKey and tabName - see TabMacro.java
    Map<String, String> tabList = tabsMap.get(grpKey);
    if (tabList == null || tabList.size() == 0) {
        //No valid tab found for tabs
        return null;
    }

    try {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("tabsID", grpKey);
        String sel = StringUtils.trim(values.get("select"));
        if (!StringUtils.isBlank(sel)) {
            int idx = 0;
            for (Entry<String, String> entry : tabList.entrySet()) {
                if (StringUtils.equalsIgnoreCase(entry.getValue(), sel)) {
                    map.put("selectTab", idx);
                    break;
                }
                idx++;
            }
        }
        map.put("tabMap", tabList);
        return Arrays
                .asList((RenderPiece) new TextModel(pluginService.renderMacro("tabs", map, renderContext)));
    } catch (PluginRenderException e) {
        log.error("Unable to render Tab plugin", e);
        throw new RenderHandlerException("Tabs can't be rendered.");
    }

}