List of usage examples for org.apache.commons.lang3 StringUtils chomp
public static String chomp(final String str)
Removes one newline from end of a String if it's there, otherwise leave it alone.
From source file:de.openali.odysseus.chart.factory.config.resolver.ChartTypeResolver.java
private String getUrl(final String url, final URL context) { if (StringUtils.isBlank(url)) return context.toString(); if (url.contains("#")) //$NON-NLS-1$ {// ww w.ja va2s. c o m final Pattern pattern = new Pattern("#.*"); //$NON-NLS-1$ if (pattern.matches(url)) return context.toString(); final RETokenizer tokenizer = new RETokenizer(pattern, url); return StringUtils.chomp(tokenizer.nextToken()); } return context.toString(); }
From source file:de.openali.odysseus.chart.factory.config.resolver.ChartTypeResolver.java
private String getAnchor(final String url) { if (Strings.isNullOrEmpty(url)) return null; final RETokenizer tokenizer = new RETokenizer(new Pattern(".*#"), url); //$NON-NLS-1$ return StringUtils.chomp(tokenizer.nextToken()); }
From source file:ch.cyberduck.core.ftp.FTPClient.java
@Override public String getModificationTime(final String file) throws IOException { final String status = super.getModificationTime(file); if (null == status) { throw new FTPException(this.getReplyCode(), this.getReplyString()); }/*from w w w. ja va2 s.c om*/ return StringUtils.chomp(status.substring(3).trim()); }
From source file:com.google.dart.engine.services.correction.MembersSorter.java
/** * Sorts all {@link Directive}s./* w w w . j av a 2 s . c o m*/ */ private void sortUnitDirectives() { List<DirectiveInfo> directives = Lists.newArrayList(); for (Directive directive : unit.getDirectives()) { if (!(directive instanceof UriBasedDirective)) { continue; } UriBasedDirective uriDirective = (UriBasedDirective) directive; String uriContent = uriDirective.getUri().getStringValue(); DirectivePriority kind = null; if (directive instanceof ImportDirective) { if (uriContent.startsWith("dart:")) { kind = DirectivePriority.DIRECTIVE_IMPORT_SDK; } else if (uriContent.startsWith("package:")) { kind = DirectivePriority.DIRECTIVE_IMPORT_PKG; } else { kind = DirectivePriority.DIRECTIVE_IMPORT_FILE; } } if (directive instanceof ExportDirective) { if (uriContent.startsWith("dart:")) { kind = DirectivePriority.DIRECTIVE_EXPORT_SDK; } else if (uriContent.startsWith("package:")) { kind = DirectivePriority.DIRECTIVE_EXPORT_PKG; } else { kind = DirectivePriority.DIRECTIVE_EXPORT_FILE; } } if (directive instanceof PartDirective) { kind = DirectivePriority.DIRECTIVE_PART; } if (kind != null) { int offset = directive.getOffset(); int length = directive.getLength(); String text = code.substring(offset, offset + length); directives.add(new DirectiveInfo(directive, kind, text)); } } // nothing to do if (directives.isEmpty()) { return; } int firstDirectiveOffset = directives.get(0).directive.getOffset(); int lastDirectiveEnd = directives.get(directives.size() - 1).directive.getEnd(); // do sort Collections.sort(directives); // append directives with grouping String directivesCode; { StringBuilder sb = new StringBuilder(); String endOfLine = getEndOfLine(); DirectivePriority currentPriority = null; for (DirectiveInfo directive : directives) { if (currentPriority != directive.priority) { if (sb.length() != 0) { sb.append(endOfLine); } currentPriority = directive.priority; } sb.append(directive.text); sb.append(endOfLine); } directivesCode = sb.toString(); directivesCode = StringUtils.chomp(directivesCode); } code = code.substring(0, firstDirectiveOffset) + directivesCode + code.substring(lastDirectiveEnd); }
From source file:com.globalsight.webservices.Ambassador4Falcon.java
private String getProjectDesc(Job p_job) { Project p = p_job.getL10nProfile().getProject(); String d = StringUtils.chomp(p.getDescription()); String desc = null;/* w w w . j a v a 2 s . c o m*/ if (d == null || d.length() == 0) desc = p.getName(); else desc = p.getName() + "-" + d; return desc; }
From source file:net.sourceforge.pmd.docs.RuleDocGenerator.java
/** * Searches for the source file of the given ruleset. This provides the information * for the "editme" link./* ww w .ja v a 2 s. co m*/ * * @param ruleset the ruleset to search for. * @return * @throws IOException */ private String getRuleSetSourceFilepath(RuleSet ruleset) throws IOException { final String rulesetFilename = FilenameUtils.normalize(StringUtils.chomp(ruleset.getFileName())); final List<Path> foundPathResult = new LinkedList<>(); Files.walkFileTree(root, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { String path = file.toString(); if (path.contains("src") && path.endsWith(rulesetFilename)) { foundPathResult.add(file); return FileVisitResult.TERMINATE; } return super.visitFile(file, attrs); } }); if (!foundPathResult.isEmpty()) { Path foundPath = foundPathResult.get(0); foundPath = root.relativize(foundPath); // Note: the path is normalized to unix path separators, so that the editme link // uses forward slashes return FilenameUtils.normalize(foundPath.toString(), true); } return StringUtils.chomp(ruleset.getFileName()); }
From source file:net.sourceforge.pmd.docs.RuleSetUtils.java
public static String getRuleSetFilename(String rulesetFileName) { return FilenameUtils.getBaseName(StringUtils.chomp(rulesetFileName)); }
From source file:net.sourceforge.pmd.docs.RuleSetUtils.java
public static String getRuleSetClasspath(RuleSet ruleset) { final String RESOURCES_PATH = "/resources/"; String filename = FilenameUtils.normalize(StringUtils.chomp(ruleset.getFileName()), true); int startIndex = filename.lastIndexOf(RESOURCES_PATH); if (startIndex > -1) { return filename.substring(startIndex + RESOURCES_PATH.length()); } else {//from ww w . ja v a2 s .co m return filename; } }
From source file:nz.co.fortytwo.signalk.processor.InputFilterProcessor.java
public void process(Exchange exchange) throws Exception { String msg = exchange.getIn().getBody(String.class); if (msg != null) { msg = msg.trim();/*from ww w .j a va 2s. c o m*/ // stomp messages are prefixed with 'ascii:' if (msg.startsWith("ascii:")) msg = msg.substring(6).trim(); msg = StringUtils.chomp(msg); boolean ok = false; if (msg.startsWith("!AIVDM")) { // AIS // !AIVDM,1,1,,B,15MwkRUOidG?GElEa<iQk1JV06Jd,0*6D exchange.getIn().setBody(msg); sendNmea(exchange); ok = true; } else if (msg.startsWith("$")) { // NMEA - good // System.out.println(msg); exchange.getIn().setBody(msg); if (logger.isDebugEnabled()) logger.debug(msg.toString()); sendNmea(exchange); ok = true; } else if (msg.startsWith("{") && msg.endsWith("}")) { Json json = Json.read(msg); // n2k if (json.has(SignalKConstants.pgn)) { exchange.getIn().setHeader(SignalKConstants.N2K_MESSAGE, msg); } // full or delta format if (exchange.getIn().getHeader(SignalKConstants.SIGNALK_FORMAT) == null) { if (json.has(SignalKConstants.CONTEXT)) { exchange.getIn().setHeader(SignalKConstants.SIGNALK_FORMAT, SignalKConstants.FORMAT_DELTA); } if (json.has(SignalKConstants.vessels) || json.has(SignalKConstants.resources)) { exchange.getIn().setHeader(SignalKConstants.SIGNALK_FORMAT, SignalKConstants.FORMAT_FULL); } } // compensate for MQTT and STOMP sessionid if (json.has(WebsocketConstants.CONNECTION_KEY)) { exchange.getIn().setHeader(WebsocketConstants.CONNECTION_KEY, json.at(WebsocketConstants.CONNECTION_KEY).asString()); } // deal with REPLY_TO Map<String, Object> headers = exchange.getIn().getHeaders(); if (headers != null && headers.containsKey(ConfigConstants.REPLY_TO)) { exchange.getIn().setHeader(ConfigConstants.DESTINATION, headers.get(ConfigConstants.REPLY_TO)); // headers.remove(Constants.REPLY_TO); } // for MQTT if (json.has(ConfigConstants.REPLY_TO)) { exchange.getIn().setHeader(ConfigConstants.DESTINATION, (json.at(ConfigConstants.REPLY_TO).asString())); } //if it has a config object, flag it as such if (json.has(SignalKConstants.CONFIG) || (json.has(SignalKConstants.CONTEXT) && StringUtils .startsWith(json.at(SignalKConstants.CONTEXT).toString(), SignalKConstants.CONFIG))) { exchange.getIn().setHeader(SignalKConstants.CONFIG_ACTION, SignalKConstants.CONFIG_ACTION_SAVE); } // json exchange.getIn().setBody(json); ok = true; } if (ok) { return; } // uh-oh log it, squash it exchange.getUnitOfWork().done(exchange); // System.out.println("Dropped invalid message:"+msg); logger.info("Dropped invalid message:" + msg); exchange.getIn().setBody(null); // throw new CamelExchangeException("Invalid msg", exchange); } }
From source file:org.benjp.services.mongodb.ChatServiceImpl.java
public void write(String message, String user, String room, String isSystem, String options) { DBCollection coll = db().getCollection(M_ROOM_PREFIX + room); message = StringUtils.chomp(message); message = message.replaceAll("&", "&"); message = message.replaceAll("<", "<"); message = message.replaceAll(">", ">"); message = message.replaceAll("\"", """); message = message.replaceAll("\n", "<br/>"); message = message.replaceAll("\\\\", "\"); message = message.replaceAll("\t", " "); BasicDBObject doc = new BasicDBObject(); doc.put("user", user); doc.put("message", message); doc.put("time", new Date()); doc.put("timestamp", System.currentTimeMillis()); doc.put("isSystem", isSystem); if (options != null) { options = options.replaceAll("<", "<"); options = options.replaceAll(">", ">"); options = options.replaceAll("'", "\""); // options = options.replaceAll("\"", """); // options = options.replaceAll("\\\\", "\"); doc.put("options", options); }/* ww w . ja v a2s. co m*/ coll.insert(doc); this.updateRoomTimestamp(room); }