List of usage examples for org.apache.commons.lang3 StringUtils indexOf
public static int indexOf(final CharSequence seq, final CharSequence searchSeq)
Finds the first index within a CharSequence, handling null .
From source file:com.moviejukebox.reader.MovieNFOReader.java
/** * Find the position of the string or return the maximum * * @param nfoText/*from w ww . java 2 s .co m*/ * @param xmlType * @return */ private static int findPosition(final String nfoText, final String xmlType) { int pos = StringUtils.indexOf(nfoText, XML_START + xmlType); return (pos == -1 ? Integer.MAX_VALUE : pos); }
From source file:com.sinosoft.one.data.jade.statement.SelectQuerier.java
private String parseCountSql(String sql) { // sql = StringUtils.lowerCase(sql); int end = StringUtils.indexOf(sql.toLowerCase(), "from"); String s = StringUtils.substring(sql, end); return "select count(1) " + s; }
From source file:com.quancheng.saluki.registry.consul.ConsulRegistry.java
private GrpcURL buildURL(ConsulService service) { try {/*from www . j a v a 2 s. c om*/ for (String tag : service.getTags()) { if (StringUtils.indexOf(tag, Constants.PROVIDERS_CATEGORY) != -1) { String toUrlPath = StringUtils.substringAfter(tag, Constants.PROVIDERS_CATEGORY); GrpcURL salukiUrl = GrpcURL.valueOf(GrpcURL.decode(toUrlPath)); return salukiUrl; } } } catch (Exception e) { log.error("convert consul service to url fail! service:" + service, e); } return null; }
From source file:com.brianscottrussell.gameoflife.GameGrid.java
/** * given the grid input String, parses the row count if this is a valid input String * * Sample of expected format of input String where rowCount = 4: * 4 8/*from w w w .ja v a 2 s . c om*/ ......../n ....*.../n ...**.../n ........ * * @param input String * @return int as the row count * @throws InvalidGameGridInputException */ private int parseRowCountFromInputString(String input) throws InvalidGameGridInputException { try { // get the character(s), before the 1st space as the rowCount return Integer.valueOf(StringUtils.substring(input, 0, StringUtils.indexOf(input, ' '))); } catch (NumberFormatException e) { throw new InvalidGameGridInputException(e.getClass().getSimpleName() + ": " + e.getMessage()); } }
From source file:com.brianscottrussell.gameoflife.GameGrid.java
/** * given the grid input String, parses the column count if this is a valid input String * * Sample of expected format of input String where columnCount = 8: * 4 8/*from ww w .j a v a2 s. c o m*/ ......../n ....*.../n ...**.../n ........ * * @param input String * @return int as the column count * @throws InvalidGameGridInputException */ private int parseColumnCountFromInputString(String input) throws InvalidGameGridInputException { try { // get the character(s), before the 1st carriage return as the rowCount return Integer.valueOf(StringUtils.substring(input, StringUtils.indexOf(input, ' ') + 1, StringUtils.indexOf(input, GameOfLife.LF))); } catch (NumberFormatException e) { throw new InvalidGameGridInputException(e.getClass().getSimpleName() + ": " + e.getMessage()); } }
From source file:de.micromata.tpsb.doc.ParserContext.java
private String removeGenerics(String type) { // Generics enthalten? if (StringUtils.indexOf(type, "<") > 0) { type = StringUtils.substringBefore(type, "<"); }/*from w w w.j a v a 2s . co m*/ return type; }
From source file:com.xpn.xwiki.web.UploadAction.java
/** * Extract the corresponding attachment name for a given file field. It can either be specified in a separate form * input field, or it is extracted from the original filename. * // w w w. j av a 2 s . co m * @param fieldName the target file field * @param fileupload the {@link FileUploadPlugin} holding the form data * @param context the current request context * @return a valid attachment name * @throws XWikiException if the form data cannot be accessed, or if the specified filename is invalid */ protected String getFileName(String fieldName, FileUploadPlugin fileupload, XWikiContext context) throws XWikiException { String filenameField = FILENAME_FIELD_NAME + fieldName.substring(FILE_FIELD_NAME.length()); String filename = null; // Try to use the name provided by the user filename = fileupload.getFileItemAsString(filenameField, context); if (!StringUtils.isBlank(filename)) { // TODO These should be supported, the URL should just contain escapes. if (filename.indexOf("/") != -1 || filename.indexOf("\\") != -1 || filename.indexOf(";") != -1) { throw new XWikiException(XWikiException.MODULE_XWIKI_APP, XWikiException.ERROR_XWIKI_APP_INVALID_CHARS, "Invalid filename: " + filename); } } if (StringUtils.isBlank(filename)) { // Try to get the actual filename on the client String fname = fileupload.getFileName(fieldName, context); if (StringUtils.indexOf(fname, "/") >= 0) { fname = StringUtils.substringAfterLast(fname, "/"); } if (StringUtils.indexOf(fname, "\\") >= 0) { fname = StringUtils.substringAfterLast(fname, "\\"); } filename = fname; } // Sometimes spaces are replaced with '+' by the browser. filename = filename.replaceAll("\\+", " "); if (StringUtils.isBlank(filename)) { // The file field was left empty, ignore this return null; } // Issues fixed by the clearName : // 1) Attaching images with a name containing special characters generates bugs // (image are not displayed), XWIKI-2090. // 2) Attached files that we can't delete or link in the Wiki pages, XWIKI-2087. filename = context.getWiki().clearName(filename, false, true, context); return filename; }
From source file:de.micromata.genome.junittools.wicket.WicketTestBuilder.java
@Deprecated public T _validateLastRenderedResponseOccurrenceOfStringABeforeStringB(String stringA, String stringB) { String lastResponse = _getLastResponseAsString(); int posA = StringUtils.indexOf(lastResponse, stringA); int posB = StringUtils.indexOf(lastResponse, stringB); validateNotEquals(-1, posA);/*ww w . j a v a 2s .c o m*/ validateNotEquals(-1, posB); validateTrue(posA < posB, "String A must occurr before String B"); return (T) this; }
From source file:com.mirth.connect.connectors.smtp.SmtpDispatcher.java
@Override public Response send(ConnectorProperties connectorProperties, ConnectorMessage connectorMessage) { SmtpDispatcherProperties smtpDispatcherProperties = (SmtpDispatcherProperties) connectorProperties; String responseData = null;/*from w w w . ja v a 2 s.com*/ String responseError = null; String responseStatusMessage = null; Status responseStatus = Status.QUEUED; String info = "From: " + smtpDispatcherProperties.getFrom() + " To: " + smtpDispatcherProperties.getTo() + " SMTP Info: " + smtpDispatcherProperties.getSmtpHost() + ":" + smtpDispatcherProperties.getSmtpPort(); eventController.dispatchEvent(new ConnectionStatusEvent(getChannelId(), getMetaDataId(), getDestinationName(), ConnectionStatusEventType.WRITING, info)); try { Email email = null; if (smtpDispatcherProperties.isHtml()) { email = new HtmlEmail(); } else { email = new MultiPartEmail(); } email.setCharset(charsetEncoding); email.setHostName(smtpDispatcherProperties.getSmtpHost()); try { email.setSmtpPort(Integer.parseInt(smtpDispatcherProperties.getSmtpPort())); } catch (NumberFormatException e) { // Don't set if the value is invalid } try { int timeout = Integer.parseInt(smtpDispatcherProperties.getTimeout()); email.setSocketTimeout(timeout); email.setSocketConnectionTimeout(timeout); } catch (NumberFormatException e) { // Don't set if the value is invalid } // This has to be set before the authenticator because a session shouldn't be created yet configuration.configureEncryption(connectorProperties, email); if (smtpDispatcherProperties.isAuthentication()) { email.setAuthentication(smtpDispatcherProperties.getUsername(), smtpDispatcherProperties.getPassword()); } Properties mailProperties = email.getMailSession().getProperties(); // These have to be set after the authenticator, so that a new mail session isn't created configuration.configureMailProperties(mailProperties); if (smtpDispatcherProperties.isOverrideLocalBinding()) { mailProperties.setProperty("mail.smtp.localaddress", smtpDispatcherProperties.getLocalAddress()); mailProperties.setProperty("mail.smtp.localport", smtpDispatcherProperties.getLocalPort()); } /* * NOTE: There seems to be a bug when calling setTo with a List (throws a * java.lang.ArrayStoreException), so we are using addTo instead. */ for (String to : StringUtils.split(smtpDispatcherProperties.getTo(), ",")) { email.addTo(to); } // Currently unused for (String cc : StringUtils.split(smtpDispatcherProperties.getCc(), ",")) { email.addCc(cc); } // Currently unused for (String bcc : StringUtils.split(smtpDispatcherProperties.getBcc(), ",")) { email.addBcc(bcc); } // Currently unused for (String replyTo : StringUtils.split(smtpDispatcherProperties.getReplyTo(), ",")) { email.addReplyTo(replyTo); } for (Entry<String, String> header : smtpDispatcherProperties.getHeaders().entrySet()) { email.addHeader(header.getKey(), header.getValue()); } email.setFrom(smtpDispatcherProperties.getFrom()); email.setSubject(smtpDispatcherProperties.getSubject()); AttachmentHandlerProvider attachmentHandlerProvider = getAttachmentHandlerProvider(); String body = attachmentHandlerProvider.reAttachMessage(smtpDispatcherProperties.getBody(), connectorMessage); if (StringUtils.isNotEmpty(body)) { if (smtpDispatcherProperties.isHtml()) { ((HtmlEmail) email).setHtmlMsg(body); } else { email.setMsg(body); } } /* * If the MIME type for the attachment is missing, we display a warning and set the * content anyway. If the MIME type is of type "text" or "application/xml", then we add * the content. If it is anything else, we assume it should be Base64 decoded first. */ for (Attachment attachment : smtpDispatcherProperties.getAttachments()) { String name = attachment.getName(); String mimeType = attachment.getMimeType(); String content = attachment.getContent(); byte[] bytes; if (StringUtils.indexOf(mimeType, "/") < 0) { logger.warn("valid MIME type is missing for email attachment: \"" + name + "\", using default of text/plain"); attachment.setMimeType("text/plain"); bytes = attachmentHandlerProvider.reAttachMessage(content, connectorMessage, charsetEncoding, false); } else if ("application/xml".equalsIgnoreCase(mimeType) || StringUtils.startsWith(mimeType, "text/")) { logger.debug("text or XML MIME type detected for attachment \"" + name + "\""); bytes = attachmentHandlerProvider.reAttachMessage(content, connectorMessage, charsetEncoding, false); } else { logger.debug("binary MIME type detected for attachment \"" + name + "\", performing Base64 decoding"); bytes = attachmentHandlerProvider.reAttachMessage(content, connectorMessage, null, true); } ((MultiPartEmail) email).attach(new ByteArrayDataSource(bytes, mimeType), name, null); } /* * From the Commons Email JavaDoc: send returns * "the message id of the underlying MimeMessage". */ responseData = email.send(); responseStatus = Status.SENT; responseStatusMessage = "Email sent successfully."; } catch (Exception e) { eventController.dispatchEvent(new ErrorEvent(getChannelId(), getMetaDataId(), connectorMessage.getMessageId(), ErrorEventType.DESTINATION_CONNECTOR, getDestinationName(), connectorProperties.getName(), "Error sending email message", e)); responseStatusMessage = ErrorMessageBuilder.buildErrorResponse("Error sending email message", e); responseError = ErrorMessageBuilder.buildErrorMessage(connectorProperties.getName(), "Error sending email message", e); // TODO: Exception handling // connector.handleException(new Exception(e)); } finally { eventController.dispatchEvent(new ConnectionStatusEvent(getChannelId(), getMetaDataId(), getDestinationName(), ConnectionStatusEventType.IDLE)); } return new Response(responseStatus, responseData, responseStatusMessage, responseError); }
From source file:com.nridge.ds.solr.SolrDS.java
/** * Returns the base Solr URL associated with the standalone/cloud search cluster. * * @param anIncludeCollection Should the collection name be included * * @return Base URL string.//from w w w.j a v a 2s . co m * * @throws DSException Data source exception. */ public String getBaseURL(boolean anIncludeCollection) throws DSException { String baseSolrURL; initialize(); if ((anIncludeCollection) && (StringUtils.isNotEmpty(mCollectionName))) { if (StringUtils.contains(mBaseSolrURL, mCollectionName)) baseSolrURL = mBaseSolrURL; else baseSolrURL = String.format("%s/%s", mBaseSolrURL, mCollectionName); } else { int solrOffset = StringUtils.indexOf(mBaseSolrURL, "solr"); if (solrOffset > 5) baseSolrURL = mBaseSolrURL.substring(0, solrOffset + 4); else baseSolrURL = mBaseSolrURL; } return baseSolrURL; }