List of usage examples for org.apache.commons.lang StringUtils strip
public static String strip(String str)
Strips whitespace from the start and end of a String.
From source file:com.github.jillesvangurp.osm2geojson.OsmBlobIterable.java
@Override public Iterator<String> iterator() { final Iterator<String> it = lineIterable.iterator(); return new Iterator<String>() { String next = null;/*from w ww . java2s . c om*/ StringBuilder buf = new StringBuilder(); @Override public boolean hasNext() { if (next != null) { return true; } else { String line; while (it.hasNext() && next == null) { line = it.next(); if (line.length() > 0) { String stripped = StringUtils.strip(line); if (stripped.startsWith("<node")) { buf.delete(0, buf.length()); buf.append(line); if (!fastEndsWith(stripped, "/>")) { while (!fastEndsWith(StringUtils.strip(line), "</node>")) { line = it.next(); buf.append(line); } } next = StringUtils.strip(buf.toString()); } else if (stripped.startsWith("<way")) { buf.delete(0, buf.length()); buf.append(line); if (!fastEndsWith(line, "/>")) { while (!fastEndsWith(StringUtils.strip(line), "</way>")) { line = it.next(); buf.append(line); } } next = StringUtils.strip(buf.toString()); } else if (stripped.startsWith("<relation")) { buf.delete(0, buf.length()); buf.append(line); if (!fastEndsWith(line, "/>")) { while (!fastEndsWith(StringUtils.strip(line), "</relation>")) { line = it.next(); buf.append(line); } } next = StringUtils.strip(buf.toString()); } } } return next != null; } } @Override public String next() { if (hasNext()) { String result = next; next = null; return result; } else { throw new NoSuchElementException(); } } @Override public void remove() { throw new UnsupportedOperationException("Remove is not supported"); } }; }
From source file:com.abiquo.server.core.appslibrary.TemplateDefinitionDto.java
public void setProductVendor(final String productVendor) { this.productVendor = StringUtils.strip(productVendor); }
From source file:com.neusoft.mid.clwapi.service.alarm.AlarmServiceImpl.java
/** * ???//from w w w. j av a 2 s .co m * * @param token * token * @param body * ? * @return */ @Override public Object getAlarmList(String token, String body) { logger.info("???"); String organizationId = context.getHttpHeaders().getHeaderString(UserInfoKey.ORGANIZATION_ID); // ?? AlarmRequ iAlarmRequ = JacksonUtils.fromJsonRuntimeException(body, AlarmRequ.class); // ?? iAlarmRequ.setEndTime(StringUtils.strip(iAlarmRequ.getEndTime())); iAlarmRequ.setStartTime(StringUtils.strip(iAlarmRequ.getStartTime())); iAlarmRequ.setNum(StringUtils.strip(iAlarmRequ.getNum())); iAlarmRequ.setOperat(StringUtils.strip(iAlarmRequ.getOperat())); iAlarmRequ.setOrganizationId(organizationId); // ?? logger.info("??"); if (StringUtils.isEmpty(iAlarmRequ.getOperat()) || StringUtils.isEmpty(iAlarmRequ.getNum()) || StringUtils.isEmpty(iAlarmRequ.getType())) { logger.error("??"); throw new ApplicationException(ErrorConstant.ERROR10001, Response.Status.BAD_REQUEST); } else if (StringUtils.isEmpty(iAlarmRequ.getStartTime()) || StringUtils.isEmpty(iAlarmRequ.getEndTime())) { logger.error("????"); throw new ApplicationException(ErrorConstant.ERROR10002, Response.Status.BAD_REQUEST); } else if (HttpConstant.TIME_ZERO.equals(iAlarmRequ.getStartTime()) && HttpConstant.TIME_ZERO.equals(iAlarmRequ.getEndTime())) { logger.error("?????0"); throw new ApplicationException(ErrorConstant.ERROR10002, Response.Status.BAD_REQUEST); } else if (HttpConstant.TIME_24_HOURS_AGO.equalsIgnoreCase(iAlarmRequ.getStartTime()) && !HttpConstant.TIME_ZERO.equals(iAlarmRequ.getEndTime())) { logger.error( "??-hh24????0"); throw new ApplicationException(ErrorConstant.ERROR10002, Response.Status.BAD_REQUEST); } else if (!StringUtils.isNumeric(iAlarmRequ.getNum())) { logger.error("??num?"); throw new ApplicationException(ErrorConstant.ERROR10002, Response.Status.BAD_REQUEST); } else if (!StringUtils.isEmpty(iAlarmRequ.getPage()) && !StringUtils.isNumeric(iAlarmRequ.getPage())) { logger.error("??page?"); throw new ApplicationException(ErrorConstant.ERROR10002, Response.Status.BAD_REQUEST); } // page?0 iAlarmRequ.setPage(StringUtils.isEmpty(iAlarmRequ.getPage()) ? HttpConstant.ZERO : iAlarmRequ.getPage()); // ??? int page = Integer.valueOf(iAlarmRequ.getPage()); int num = Integer.valueOf(iAlarmRequ.getNum()); // ???? if (page < 0) { logger.error("??page?0"); throw new ApplicationException(ErrorConstant.ERROR10002, Response.Status.BAD_REQUEST); } // ? // if (iAlarmRequ.getOperat().equals(HttpConstant.ALARMPORT_OPERATE_UNTREATED)) { iAlarmRequ.setOperat(HttpConstant.ALARMPORT_OPERATE_UNTREATED_DB); } else if (iAlarmRequ.getOperat().equals(HttpConstant.ALARMPORT_OPERATE_TREATED)) { iAlarmRequ.setOperat(HttpConstant.ALARMPORT_OPERATE_TREATED_DB); } else if (iAlarmRequ.getOperat().equals(HttpConstant.ALARMPORT_OPERATE_ALL)) { iAlarmRequ.setOperat(HttpConstant.ALARMPORT_OPERATE_ALL_DB); } else { logger.error("???operat?0?1?2"); throw new ApplicationException(ErrorConstant.ERROR10002, Response.Status.BAD_REQUEST); } if (iAlarmRequ.getType().equals(HttpConstant.ALARMPORT_TYPE_OVERSPEED)) { iAlarmRequ.setSpeedFlag(true); iAlarmRequ.setOverLoadFlag(null); } else if (iAlarmRequ.getType().equals(HttpConstant.ALARMPORT_TYPE_OVERLOAD)) { iAlarmRequ.setSpeedFlag(null); iAlarmRequ.setOverLoadFlag(true); } else if (iAlarmRequ.getType().equals(HttpConstant.ALARMPORT_TYPE_ALL)) { iAlarmRequ.setSpeedFlag(null); iAlarmRequ.setOverLoadFlag(null); } else { logger.error("???type?0?1?2"); throw new ApplicationException(ErrorConstant.ERROR10002, Response.Status.BAD_REQUEST); } // ???? if (!HttpConstant.TIME_ZERO.equals(iAlarmRequ.getStartTime()) && !HttpConstant.TIME_24_HOURS_AGO.equalsIgnoreCase(iAlarmRequ.getStartTime())) { try { TimeUtil.parseStringToDate(iAlarmRequ.getStartTime(), HttpConstant.TIME_FORMAT); } catch (ParseException e) { logger.error("????" + e.getMessage()); throw new ApplicationException(ErrorConstant.ERROR10002, Response.Status.BAD_REQUEST); } } if (!HttpConstant.TIME_ZERO.equals(iAlarmRequ.getEndTime())) { try { TimeUtil.parseStringToDate(iAlarmRequ.getEndTime(), HttpConstant.TIME_FORMAT); } catch (ParseException e) { logger.error("?????" + e.getMessage()); throw new ApplicationException(ErrorConstant.ERROR10002, Response.Status.BAD_REQUEST); } } logger.info("???"); // ? if (HttpConstant.TIME_ZERO.equals(iAlarmRequ.getStartTime())) { iAlarmRequ.setStartTime(null); } else if (HttpConstant.TIME_24_HOURS_AGO.equalsIgnoreCase(iAlarmRequ.getStartTime())) { Date dBTime = iCommonMapper.getDBTime(); Date oneDayAgo = TimeUtil.get24Ago(dBTime); String startTime = TimeUtil.formatDateToString(oneDayAgo, HttpConstant.TIME_FORMAT); iAlarmRequ.setStartTime(startTime); } if (HttpConstant.TIME_ZERO.equals(iAlarmRequ.getEndTime())) { iAlarmRequ.setEndTime(null); } iAlarmRequ.setEnId(context.getHttpHeaders().getHeaderString(UserInfoKey.ENTERPRISE_ID)); // ? if (page != 0) { iAlarmRequ.setStartRow(String.valueOf(page * num - num)); iAlarmRequ.setEndRow(String.valueOf(page * num)); } else if (num != 0) { iAlarmRequ.setStartRow(HttpConstant.ZERO); iAlarmRequ.setEndRow(String.valueOf(num)); } else { iAlarmRequ.setStartRow(null); iAlarmRequ.setEndRow(null); } logger.info("????"); // ? List<AlarmInfo> temp = iAlarmMapper.getAlarmList(iAlarmRequ); logger.info("??"); // if (temp == null || temp.size() == 0) { logger.info("??"); return Response.noContent().build(); } logger.info("??"); if (logger.isDebugEnabled()) { logger.debug("List size:" + temp.size()); Iterator<AlarmInfo> it = temp.iterator(); while (it.hasNext()) { logger.debug(it.next().toString()); } } // List<AlarmInfo> content = new ArrayList<AlarmInfo>(); Iterator<AlarmInfo> it = temp.iterator(); while (it.hasNext()) { AlarmInfo a = it.next(); if (!StringUtils.isEmpty(a.getSpeeding())) { a.setAlarmCont(a.getSpeeding()); } else if (!StringUtils.isEmpty(a.getPhotoId())) { a.setAlarmCont(a.getPhotoId()); } else { a.setAlarmCont(null); } content.add(a); } // AlarmResp iAlarmResp = new AlarmResp(); iAlarmResp.setContent(content); logger.info("????"); return JacksonUtils.toJsonRuntimeException(iAlarmResp); }
From source file:de.hybris.platform.addonsupport.config.SpelBeanFactory.java
@Override public void onApplicationEvent(final ContextRefreshedEvent event) { final ExpressionParser parser = new SpelExpressionParser(); final StandardEvaluationContext context = new StandardEvaluationContext(); context.setBeanResolver(new BeanFactoryResolver(applicationContext)); final String[] beanNames = applicationContext.getBeanNamesForType(AbstractConverter.class); for (final String beanName : beanNames) { final BeanDefinition def = beanFactory.getBeanDefinition(beanName); final PropertyValue pv = def.getPropertyValues().getPropertyValue("targetClass"); if (pv != null) { if (pv.getValue() instanceof TypedStringValue) { String expr = StringUtils.strip(((TypedStringValue) pv.getValue()).getValue()); if (expr.startsWith("#{")) { expr = StringUtils.replaceOnce(expr, "#{", "@"); expr = StringUtils.stripEnd(expr, "}"); final Object result = parser.parseExpression(expr).getValue(context); if (result != null) { try { applicationContext.getBean(beanName, AbstractConverter.class) .setTargetClass(ClassUtils.getClass(result.toString())); } catch (final ClassNotFoundException e) { LOG.error(beanName + " target class instantiation failed", e); }/*w w w . j av a 2 s . c o m*/ } } } } } }
From source file:gr.seab.r2rml.entities.sql.SelectQuery.java
public ArrayList<SelectField> createSelectFields(String q) { ArrayList<SelectField> results = new ArrayList<SelectField>(); int start = q.toUpperCase().indexOf("SELECT") + 7; int end = q.toUpperCase().indexOf("FROM"); List<String> fields = splitFields(q.substring(start, end)); List<String> processedFields = new ArrayList<String>(); for (int i = 0; i < fields.size(); i++) { String strippedFieldName = StringUtils.strip(fields.get(i)); if (createSelectFieldTable(strippedFieldName) != null) { processedFields.add(strippedFieldName); }/* ww w. j av a 2s . com*/ } for (String field : processedFields) { SelectField f = new SelectField(); f.setName(field.trim()); f.setTable(createSelectFieldTable(field.trim())); f.setAlias(createAlias(field).trim()); log.info("Adding field with: name '" + f.getName() + "', table '" + f.getTable().getName() + "', alias '" + f.getAlias() + "'"); results.add(f); } return results; }
From source file:br.com.nordestefomento.jrimum.bopepo.campolivre.CampoLivreFactory.java
/** * Devolve um CampoLivre de acordo a partir de uma String. * /*from w w w . j av a2 s.c o m*/ * @param strCampoLivre * * @return Uma referncia para um ICampoLivre. * * @throws NullPointerException * @throws IllegalArgumentException */ public static CampoLivre create(String strCampoLivre) { CampoLivre campoLivre = null; ObjectUtil.checkNotNull(strCampoLivre); StringUtil.checkNotBlank(strCampoLivre, "O Campo Livre no deve ser vazio!"); strCampoLivre = StringUtils.strip(strCampoLivre); if (strCampoLivre.length() == CampoLivre.STRING_LENGTH) { if (StringUtils.remove(strCampoLivre, ' ').length() == CampoLivre.STRING_LENGTH) { if (StringUtils.isNumeric(strCampoLivre)) { campoLivre = new CampoLivre() { private static final long serialVersionUID = -7592488081807235080L; Field<String> campo = new Field<String>(StringUtils.EMPTY, STRING_LENGTH, Filler.ZERO_LEFT); public void read(String str) { campo.read(str); } public String write() { return campo.write(); } }; campoLivre.read(strCampoLivre); } else { IllegalArgumentException e = new IllegalArgumentException( "O Campo Livre [ " + strCampoLivre + " ] deve ser uma String numrica!"); log.error(StringUtils.EMPTY, e); throw e; } } else { IllegalArgumentException e = new IllegalArgumentException( "O Campo Livre [ " + strCampoLivre + " ] no deve conter espaos em branco!"); log.error(StringUtils.EMPTY, e); throw e; } } else { IllegalArgumentException e = new IllegalArgumentException("O tamanho do Campo Livre [ " + strCampoLivre + " ] deve ser igual a 25 e no [" + strCampoLivre.length() + "]!"); log.error(StringUtils.EMPTY, e); throw e; } return campoLivre; }
From source file:br.com.nordestefomento.jrimum.bopepo.campolivre.guia.CampoLivreFactory.java
/** * Devolve um CampoLivre de acordo a partir de uma String. * // w w w. ja va2s . c o m * @param strCampoLivre * * @return Uma referncia para um CampoLivre. * * @throws NullPointerException * @throws IllegalArgumentException */ public static CampoLivre create(String strCampoLivre, TipoSeguimento tipoSeguimento) { CampoLivre campoLivre = null; final Integer tamanhoCorreto = CampoLivreUtil.getTamanhoCorreto(tipoSeguimento); ObjectUtil.checkNotNull(strCampoLivre); StringUtil.checkNotBlank(strCampoLivre, "O Campo Livre no deve ser vazio!"); strCampoLivre = StringUtils.strip(strCampoLivre); if (CampoLivreUtil.tamanhoEstaCorreto(strCampoLivre, tipoSeguimento)) { if (CampoLivreUtil.naoExisteEspacoEmBranco(strCampoLivre, tipoSeguimento)) { if (StringUtils.isNumeric(strCampoLivre)) { campoLivre = new CampoLivre() { private static final long serialVersionUID = -7592488081807235080L; Field<String> campo = new Field<String>(StringUtils.EMPTY, tamanhoCorreto, Filler.ZERO_LEFT); public void read(String str) { campo.read(str); } public String write() { return campo.write(); } }; campoLivre.read(strCampoLivre); } else { IllegalArgumentException e = new IllegalArgumentException( "O Campo Livre [ " + strCampoLivre + " ] deve ser uma String numrica!"); log.error(StringUtils.EMPTY, e); throw e; } } else { IllegalArgumentException e = new IllegalArgumentException( "O Campo Livre [ " + strCampoLivre + " ] no deve conter espaos em branco!"); log.error(StringUtils.EMPTY, e); throw e; } } else { IllegalArgumentException e = new IllegalArgumentException("O tamanho do Campo Livre [ " + strCampoLivre + " ] deve ser igual a " + tamanhoCorreto + " e no [" + strCampoLivre.length() + "]!"); log.error(StringUtils.EMPTY, e); throw e; } return campoLivre; }
From source file:com.neusoft.mid.clwapi.service.photo.PhotoServiceImpl.java
/** * ??API//from w w w. j av a 2 s . c o m * * @param token * token * @param body * ? * @return */ @Override public Object getPhotoList(String token, String body) { logger.info("???"); String organizationId = context.getHttpHeaders().getHeaderString(UserInfoKey.ORGANIZATION_ID); // ?? PhotoRequ iPhotoRequ = JacksonUtils.fromJsonRuntimeException(body, PhotoRequ.class); // ?? iPhotoRequ.setEndTime(StringUtils.strip(iPhotoRequ.getEndTime())); iPhotoRequ.setStartTime(StringUtils.strip(iPhotoRequ.getStartTime())); iPhotoRequ.setNum(StringUtils.strip(iPhotoRequ.getNum())); iPhotoRequ.setType(StringUtils.strip(iPhotoRequ.getType())); iPhotoRequ.setPage(StringUtils.strip(iPhotoRequ.getPage())); iPhotoRequ.setOrganizationId(organizationId); // ?? logger.info("??"); if (StringUtils.isEmpty(iPhotoRequ.getType()) || StringUtils.isEmpty(iPhotoRequ.getNum()) || StringUtils.isEmpty(iPhotoRequ.getPage())) { logger.error("??"); throw new ApplicationException(ErrorConstant.ERROR10001, Response.Status.BAD_REQUEST); } else if (StringUtils.isEmpty(iPhotoRequ.getStartTime()) || StringUtils.isEmpty(iPhotoRequ.getEndTime())) { logger.error("????"); throw new ApplicationException(ErrorConstant.ERROR10002, Response.Status.BAD_REQUEST); } else if (!iPhotoRequ.getType().equals(HttpConstant.PHOTOPORT_TYPE_ORDER) && !iPhotoRequ.getType().equals(HttpConstant.PHOTOPORT_TYPE_ALL)) { logger.error("??type?1?2"); throw new ApplicationException(ErrorConstant.ERROR10002, Response.Status.BAD_REQUEST); } else if (!StringUtils.isNumeric(iPhotoRequ.getNum())) { logger.error("??num?"); throw new ApplicationException(ErrorConstant.ERROR10002, Response.Status.BAD_REQUEST); } else if (!StringUtils.isNumeric(iPhotoRequ.getPage())) { logger.error("??page?"); throw new ApplicationException(ErrorConstant.ERROR10002, Response.Status.BAD_REQUEST); } // ??? if (!HttpConstant.TIME_ZERO.equals(iPhotoRequ.getStartTime())) { try { TimeUtil.parseStringToDate(iPhotoRequ.getStartTime(), HttpConstant.TIME_FORMAT); } catch (ParseException e) { logger.error("???????", e); throw new ApplicationException(ErrorConstant.ERROR10002, Response.Status.BAD_REQUEST); } } else { iPhotoRequ.setStartTime(null); } if (!HttpConstant.TIME_ZERO.equals(iPhotoRequ.getEndTime())) { try { TimeUtil.parseStringToDate(iPhotoRequ.getEndTime(), HttpConstant.TIME_FORMAT); } catch (ParseException e) { logger.error("????????", e); throw new ApplicationException(ErrorConstant.ERROR10002, Response.Status.BAD_REQUEST); } } else { iPhotoRequ.setEndTime(null); } // ????? int page = Integer.valueOf(iPhotoRequ.getPage()); int num = Integer.valueOf(iPhotoRequ.getNum()); // ???? if (page <= 0) { logger.error("??page?0"); throw new ApplicationException(ErrorConstant.ERROR10002, Response.Status.BAD_REQUEST); } logger.info("???"); // ? iPhotoRequ.setVin(StringUtils.isEmpty(iPhotoRequ.getVin()) ? null : iPhotoRequ.getVin()); iPhotoRequ.setOrgaId(StringUtils.isEmpty(iPhotoRequ.getOrgaId()) ? null : iPhotoRequ.getOrgaId()); // ?? // IDEN_ID iPhotoRequ.setUsrId(context.getHttpHeaders().getHeaderString(UserInfoKey.USR_ID)); iPhotoRequ.setEnId(context.getHttpHeaders().getHeaderString(UserInfoKey.ENTERPRISE_ID)); // ? iPhotoRequ.setStartRow(String.valueOf(page * num - num)); iPhotoRequ.setEndRow(String.valueOf(page * num)); // 2type??sql iPhotoRequ.setType( iPhotoRequ.getType().equals(HttpConstant.PHOTOPORT_TYPE_ALL) ? null : iPhotoRequ.getType()); logger.info("?"); logger.debug("?"); logger.debug(iPhotoRequ.toString()); // ? List<PhotoInfo> imgs = iPhotoMapper.getPhotoList(iPhotoRequ); logger.info("??"); logger.debug("imgs=" + (imgs == null ? "NULL" : imgs.size())); if (imgs == null || imgs.size() == 0) { logger.info("?"); return Response.noContent().build(); } logger.debug("?"); if (logger.isDebugEnabled()) { Iterator<PhotoInfo> it = imgs.iterator(); while (it.hasNext()) { PhotoInfo temp = it.next(); logger.debug(temp.toString()); } } // PhotoResp iPhotoResp = new PhotoResp(); iPhotoResp.setImgs(imgs); logger.info("???"); return JacksonUtils.toJsonRuntimeException(iPhotoResp); }
From source file:com.haulmont.cuba.core.sys.jpql.transform.QueryTransformerAstBased.java
private QueryTreeTransformer getQueryTransformer() { if (queryTreeTransformer == null) { queryTreeTransformer = new QueryTreeTransformer(); try {//from w w w . j a v a 2 s . c o m queryTreeTransformer.prepare(model, query); } catch (RecognitionException e) { throw new RuntimeException("Internal error while init queryTreeTransformer", e); } catch (JPA2RecognitionException e) { throw new JpqlSyntaxException( format("Errors found for input jpql:[%s]\n%s", StringUtils.strip(query), e.getMessage())); } List<ErrorRec> errors = new ArrayList<>(queryTreeTransformer.getInvalidIdVarNodes()); if (!errors.isEmpty()) { throw new JpqlSyntaxException( String.format("Errors found for input jpql:[%s]", StringUtils.strip(query)), errors); } } return queryTreeTransformer; }
From source file:com.microsoft.alm.plugin.external.commands.CommandTest.java
/** * This test makes sure that output from a command is flushed before the completion event is fired. * * @throws Exception/* w w w . j a v a 2s .c o m*/ */ @Test public void testRaceCondition() throws Exception { // Fake the tool location so this works on any machine PowerMockito.mockStatic(TfTool.class); when(TfTool.getValidLocation()).thenReturn("/path/tf_home"); Process proc = Mockito.mock(Process.class); PowerMockito.mockStatic(ProcessHelper.class); when(ProcessHelper.startProcess(anyString(), anyList())).thenReturn(proc); when(proc.getErrorStream()).thenReturn(new InputStream() { @Override public int read() throws IOException { return -1; } }); when(proc.getInputStream()).thenReturn(new InputStream() { private String result = "12345"; private int index = 0; @Override public int read() throws IOException { try { Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } if (index < result.length()) { return result.charAt(index++); } else { return -1; } } }); when(proc.waitFor()).thenAnswer(new Answer<Integer>() { @Override public Integer answer(InvocationOnMock invocation) throws Throwable { return 0; } }); when(proc.exitValue()).thenReturn(0); final MyCommand cmd = new MyCommand(null); final String output = cmd.runSynchronously(); Assert.assertEquals("12345", StringUtils.strip(output)); }