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.txtweb.wikipedia.Wikipedia.java
@Override public void doGet(HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws ServletException { String txtWebMessageParam = httpRequest.getParameter(HTTP_PARAM_TXTWEB_MESSAGE); String pageParam = httpRequest.getParameter(HTTP_PARAM_PAGE); String paragraphNumberParam = httpRequest.getParameter(HTTP_PARAM_PARAGRAPH_NUMBER); String page = ""; if (pageParam != null && !pageParam.isEmpty()) { // If we know what page to display, then disregard the user's message // and simply display the page. page = pageParam;//from w w w. j ava2 s . c o m } else if (txtWebMessageParam != null && !txtWebMessageParam.isEmpty()) { txtWebMessageParam = StringUtils.strip(txtWebMessageParam); txtWebMessageParam = txtWebMessageParam.replaceAll("\\s+", " "); // Format the user's message to conform to wikipedia's URL naming conventions page = txtWebMessageParam; page = page.toLowerCase(); page = WordUtils.capitalize(page); page = page.replaceAll(" ", "_"); } else { // We don't know what page to display, and the user didn't send any message // Respond with a welcome message and instructions on how to use the service String response = getWelcomeMessage(); sendResponse(httpResponse, response); return; } int paragraphNumber = 1; if (paragraphNumberParam != null) { try { paragraphNumber = Integer.parseInt(paragraphNumberParam); } catch (NumberFormatException e) { // } } HttpClient httpclient = new DefaultHttpClient(); try { page = URLEncoder.encode(page, "UTF-8"); HttpGet httpGet = new HttpGet("http://en.wikipedia.org/wiki/" + page); HttpResponse Httpresponse = httpclient.execute(httpGet); String responseBody = EntityUtils.toString(Httpresponse.getEntity(), "UTF-8"); String responseWithoutInfoBoxes = removeInfoBoxes(responseBody); Source source = new Source(responseWithoutInfoBoxes); source.fullSequentialParse(); Element bodyContent = source.getElementById("bodyContent"); String response = ""; if (bodyContent != null) { response = parseHtmlNode(bodyContent, page, paragraphNumber); } if (!response.isEmpty()) { sendResponse(httpResponse, response); return; } } catch (MalformedURLException e) { // } catch (IOException e) { // } finally { httpclient.getConnectionManager().shutdown(); } if (pageParam != null && !pageParam.isEmpty()) { // Unknown error or no results. Respond with a nothing found message // and instructions on how to use the service. String response = getNothingFoundMessage(pageParam); sendResponse(httpResponse, response); return; } if (txtWebMessageParam != null && !txtWebMessageParam.isEmpty()) { // Unknown error or no results. Respond with a nothing found message // and instructions on how to use the service. String response = getNothingFoundMessage(txtWebMessageParam); sendResponse(httpResponse, response); return; } // Unknown error or no results. Respond with a welcome message // and instructions on how to use the service. String response = getWelcomeMessage(); sendResponse(httpResponse, response); return; }
From source file:com.neusoft.mid.clwapi.service.monitor.monitorServiceImpl.java
/** * ??./*from w w w .j av a 2s .c o m*/ * * @param token * ?. * @param vin * VIN. * @return ?. */ @Override public Response getRealTimeInfo(String token, String vin) { vin = StringUtils.strip(vin); String epid = context.getHttpHeaders().getHeaderString(UserInfoKey.ENTERPRISE_ID); logger.info("--?ID:" + epid + ",VIN:" + vin); if (CheckRequestParam.isEmpty(epid)) { logger.info("--?ID"); throw new ApplicationException(ErrorConstant.ERROR90000, Response.Status.INTERNAL_SERVER_ERROR); } logger.info("?"); RealTimeInfo car = monitorMapper.getRealInfobyVIN(epid, vin); if (CheckRequestParam.isEmpty(car)) { logger.info("--VIN" + vin + "?"); return Response.status(Response.Status.NO_CONTENT).header(HttpHeaders.CACHE_CONTROL, "no-store") .header("Pragma", "no-cache").build(); } logger.info("???ID"); car.setAlarmIDs(BusinessUtil.decodeAlarmStr(car.getAlarmStr())); car.setAlarmStr(null); logger.info("???"); String[] passengers = monitorMapper.getPassengersbyVIN(vin); if (!CheckRequestParam.isEmpty(passengers)) { car.setPassengers(passengers); } return Response.ok(JacksonUtils.toJsonRuntimeException(car)).header(HttpHeaders.CACHE_CONTROL, "no-store") .header("Pragma", "no-cache").build(); }
From source file:joshelser.as2015.parser.AmazonReviewParser.java
/** * Compute the next review from the reader. * // w w w . j av a2 s. co m * @return The next review or null if there is none */ AmazonReview getNextReview() { if (readerExhausted) { return null; } try { String line; AmazonReview nextReview = null; do { line = reader.readLine(); if (null == line) { readerExhausted = true; return nextReview; } // Empty line is message separator if (StringUtils.isBlank(line)) { // If we have a review return it if (null != nextReview) { return nextReview; } // otherwise, just try to read the next message } else { if (null == nextReview) { nextReview = new AmazonReview(); } int index = line.indexOf(':'); if (-1 == index) { throw new IllegalArgumentException("Cannot parse line '" + line + "'"); } String key = StringUtils.strip(line.substring(0, index)); String value = StringUtils.strip(line.substring(index + 1)); index = key.indexOf('/'); if (-1 == index) { throw new IllegalArgumentException("Cannot parse key '" + key + "'"); } AmazonReviewField field = new AmazonReviewField(key.substring(0, index), key.substring(index + 1)); nextReview.addReviewField(field, ByteBuffer.wrap(value.getBytes(StandardCharsets.UTF_8))); } } while (!readerExhausted); return nextReview; } catch (IOException e) { throw new RuntimeException("Failed to read file", e); } }
From source file:com.abiquo.server.core.appslibrary.TemplateDefinitionDto.java
public void setProductName(final String productName) { this.productName = StringUtils.strip(productName); }
From source file:com.haulmont.cuba.core.sys.jpql.Parser.java
private static void checkTreeForExceptions(String input, CommonTree tree) { TreeVisitor visitor = new TreeVisitor(); ErrorNodesFinder errorNodesFinder = new ErrorNodesFinder(); visitor.visit(tree, errorNodesFinder); List<ErrorRec> errors = errorNodesFinder.getErrorNodes().stream() .map(node -> new ErrorRec(node, "CommonErrorNode")).collect(Collectors.toList()); if (!errors.isEmpty()) { throw new JpqlSyntaxException( String.format("Errors found for input jpql:[%s]", StringUtils.strip(input)), errors); }//from ww w. j a va 2s. com }
From source file:com.neusoft.mid.clwapi.service.msg.MsgServiceImpl.java
/** * ?./* w ww. j ava 2 s . c o m*/ * * @param token * ?. * @param ttMsgInfo * ?. * @return ?. */ @Override public Response sendTtMsg(String token, String ttMsgInfo) { logger.info("???"); DiaoduInfo ttMsg = JacksonUtils.fromJsonRuntimeException(ttMsgInfo, DiaoduInfo.class); if (null == ttMsg || StringUtils.isEmpty(StringUtils.strip(ttMsg.getVins())) || StringUtils.isEmpty(StringUtils.strip(ttMsg.getMsg())) || StringUtils.isEmpty(StringUtils.strip(ttMsg.getType()))) { logger.info("??"); throw new ApplicationException(ErrorConstant.ERROR10001, Response.Status.BAD_REQUEST); } else { CoreMsgInfo msgInfo = new CoreMsgInfo(); msgInfo.setVin(ttMsg.getVins()); msgInfo.setType(parseTtmsgType(ttMsg.getType())); msgInfo.setMsg(ttMsg.getMsg()); msgInfo.setUserId(context.getHttpHeaders().getHeaderString(UserInfoKey.USR_ID)); // ????. msgSendThreadPool.executeSendMtMsgThread(msgInfo, msgMapper, sendDeliverMsgService); // ????. return Response.ok().header(HttpHeaders.CACHE_CONTROL, "no-store").header("Pragma", "no-cache").build(); } }
From source file:com.haulmont.cuba.core.global.QueryParserAstBased.java
private QueryTreeAnalyzer getQueryAnalyzer() { if (queryTreeAnalyzer == null) { queryTreeAnalyzer = new QueryTreeAnalyzer(); try {// ww w .j a va 2 s .c o m queryTreeAnalyzer.prepare(model, query); } catch (RecognitionException e) { throw new RuntimeException("Internal error while init queryTreeAnalyzer", 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<>(queryTreeAnalyzer.getInvalidIdVarNodes()); if (!errors.isEmpty()) { throw new JpqlSyntaxException(format("Errors found for input jpql:[%s]", StringUtils.strip(query)), errors); } } return queryTreeAnalyzer; }
From source file:com.github.rolecraftdev.command.CommandHelper.java
/** * Joins all of the arguments in the given {@link Arguments}, starting from * the specified start index. All arguments are separated from each other by * a single whitespace character.//from ww w. j a v a 2s .c om * * @param start the index to start joining arguments from * @param args the {@link Arguments} to retrieve the arguments from * @return a string of all arguments in the given {@link Arguments}, * starting at the specified start index * @since 0.0.5 */ public static String joinFrom(final int start, final Arguments args) { if (args.length() <= start) { return null; } final StringBuilder builder = new StringBuilder(); for (int i = start; i < args.length(); i++) { builder.append(args.getRaw(i)).append(" "); } // Use StringUtils#strip because String#trim also removes ASCII control // characters and not just unicode whitespace return StringUtils.strip(builder.toString()); }
From source file:edu.ku.brc.specify.tools.FixMetaTags.java
static public String getContents(File aFile) { //...checks on aFile are elided StringBuffer contents = new StringBuffer(); //System.out.println(aFile.getName()); //declared here only to make visible to finally clause BufferedReader input = null;/*w w w . ja v a2 s . c o m*/ try { String eol = System.getProperty("line.separator"); System.out.println("\n" + aFile.getName()); //use buffering //this implementation reads one line at a time //FileReader always assumes default encoding is OK! input = new BufferedReader(new FileReader(aFile)); String line = null; //not declared within while loop //boolean doIt = false; int cnt = 0; boolean doComment = true; boolean doClassDesc = true; while ((line = input.readLine()) != null) { cnt++; boolean addLine = true; if (doComment) { int inx = line.indexOf("<!--"); if (inx > -1) { do { line = input.readLine(); cnt++; } while (line.indexOf("-->") == -1); doComment = false; continue; } } if (doComment && line.indexOf("<class") > -1) { doComment = false; } if (doClassDesc) { int inx = line.indexOf("class-description"); if (inx > -1) { do { line = input.readLine(); cnt++; } while (line.indexOf("</meta>") == -1); contents.append(" <meta attribute=\"class-description\" inherit=\"false\"/>"); contents.append(eol); doClassDesc = false; continue; } } int ccInx = line.indexOf("class-code"); int inx = line.indexOf("<meta"); if (inx > -1 && ccInx == -1) { inx = line.indexOf("</meta>"); if (inx == -1) { String textLine = input.readLine(); cnt++; String endTag = null; if (textLine.indexOf("</meta>") == -1) { endTag = input.readLine(); cnt++; } if (endTag != null && endTag.indexOf("</meta>") == -1) { throw new RuntimeException("Assumption bad about end tab. line " + cnt); } contents.append(StringUtils.stripEnd(line, " ")); contents.append(StringUtils.strip(textLine)); if (endTag != null) { contents.append(StringUtils.strip(endTag)); } contents.append(eol); addLine = false; } } if (addLine) { contents.append(line); contents.append(System.getProperty("line.separator")); } } } catch (FileNotFoundException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } finally { try { if (input != null) { //flush and close both "input" and its underlying FileReader input.close(); } } catch (IOException ex) { ex.printStackTrace(); } } return contents.toString(); }
From source file:com.abiquo.server.core.appslibrary.TemplateDefinitionDto.java
public void setDescription(final String description) { this.description = StringUtils.strip(description); }