List of usage examples for org.apache.commons.lang3 StringUtils substring
public static String substring(final String str, int start)
Gets a substring from the specified String avoiding exceptions.
A negative start position can be used to start n characters from the end of the String.
A null String will return null .
From source file:com.gargoylesoftware.htmlunit.javascript.host.Node.java
/** * Defines an event handler (or maybe any other object). * @param eventName the event name (e.g. "onclick") * @param value the property (<code>null</code> to reset it) */// w ww . j ava 2s .c o m protected void setEventHandlerProp(final String eventName, final Object value) { getEventListenersContainer().setEventHandlerProp(StringUtils.substring(eventName.toLowerCase(), 2), value); }
From source file:com.gargoylesoftware.htmlunit.javascript.host.Node.java
/** * Gets the property defined as event handler (not necessary a Function if something else has been set). * @param eventName the event name (e.g. "onclick") * @return the property//from www . ja v a 2 s .co m */ protected Object getEventHandlerProp(final String eventName) { if (eventListenersContainer_ == null) { return null; } return eventListenersContainer_.getEventHandlerProp(StringUtils.substring(eventName.toLowerCase(), 2)); }
From source file:com.gargoylesoftware.htmlunit.WebClientTest.java
/** * Test loading a file page with XML content. Regression test for bug 1113487. * * @throws Exception if something goes wrong *///w ww.j av a 2 s. c o m @Test public void loadFilePageXml() throws Exception { final String xmlContent = "<?xml version='1.0' encoding='UTF-8'?>\n" + "<dataset>\n" + "<table name=\"USER\">\n" + "<column>ID</column>\n" + "<row>\n" + "<value>116517</value>\n" + "</row>\n" + "</table>\n" + "</dataset>"; final File currentDirectory = new File((new File("")).getAbsolutePath()); final File tmpFile = File.createTempFile("test", ".xml", currentDirectory); tmpFile.deleteOnExit(); final String encoding = (new OutputStreamWriter(new ByteArrayOutputStream())).getEncoding(); FileUtils.writeStringToFile(tmpFile, xmlContent, encoding); final URL fileURL = new URL("file://" + tmpFile.getCanonicalPath()); final WebClient client = getWebClient(); final XmlPage page = (XmlPage) client.getPage(fileURL); assertEquals(xmlContent, page.getWebResponse().getContentAsString()); // "text/xml" or "application/xml", it doesn't matter assertEquals("/xml", StringUtils.substring(page.getWebResponse().getContentType(), -4)); assertEquals(200, page.getWebResponse().getStatusCode()); }
From source file:com.gp.cong.logisoft.bc.fcl.SedFilingBC.java
public void readRespResponseFile(InputStream is, String aesFilesFolder, String aesResponseFileName) throws Exception { List<String> contents = FileUtils.readLines(new File(aesFilesFolder + aesResponseFileName)); // Iterate the result to print each line of the file. String itn = ""; String shipmentNumber = ""; String status = ""; String exception = ""; if (null != contents && contents.size() > 0) { contents.remove(0);//from w w w.ja v a2 s .c o m } for (String line : contents) { if (null != line && line.length() > 0) { String key = StringUtils.substringBefore(line, " "); shipmentNumber = StringUtils.substringBefore(key, "-") + "-" + (StringUtils.substringAfterLast(key, "-").substring(0, 2)); status += StringUtils.substringAfterLast(line, key).trim() + " "; } } status = StringUtils.removeEnd(status, " "); if (CommonUtils.isNotEmpty(shipmentNumber)) { FclBlDAO fclBlDAO = new FclBlDAO(); String fileNo = shipmentNumber.contains("-") ? shipmentNumber.substring(0, shipmentNumber.indexOf("-")) : shipmentNumber; if (fileNo.length() > 6) { fileNo = fileNo.substring(2); } //String fileNo = shipmentNumber.contains("-") && shipmentNumber.length() > 2 ? shipmentNumber.substring(2, shipmentNumber.indexOf("-")) : shipmentNumber; FclBl fclBl = fclBlDAO.getFileNoObject(fileNo); LclFileNumber lclFileNumber = null; if (null == fclBl) { lclFileNumber = new LclFileNumberDAO().getByProperty("fileNumber", fileNo); } FclAESDetails fclAESDetails = new FclAESDetails(); SedFilingsDAO sedFilingsDAO = new SedFilingsDAO(); boolean hasAes = false; SedFilings sedFilings = sedFilingsDAO.findByTrnref(shipmentNumber.trim()); if (null != sedFilings) { sedFilings.setItn(itn); if (status.contains("SUCCESSFULLY PROCESSED")) { sedFilings.setStatus("P"); } else { sedFilings.setStatus("E"); } AesHistory aesHistory = new AesHistory(); if (null != fclBl) { aesHistory.setBolId(fclBl.getBol()); aesHistory.setFclBlNo(fclBl.getBolId()); for (Object object : fclBl.getFclAesDetails()) { FclAESDetails aes = (FclAESDetails) object; if (null != aes.getAesDetails() && aes.getAesDetails().equalsIgnoreCase(itn)) { hasAes = true; break; } } if (!hasAes && CommonUtils.isNotEmpty(itn)) { fclAESDetails.setAesDetails(itn); fclAESDetails.setFileNo(fileNo); fclAESDetails.setTrailerNoId(fclBl.getBol()); fclBl.getFclAesDetails().add(fclAESDetails); fclBlDAO.update(fclBl); } } else if (null != lclFileNumber) { //aesHistory.setBolId(lclFileNumber.getId()); aesHistory.setFclBlNo(lclFileNumber.getFileNumber()); } aesHistory.setFileNumber(shipmentNumber); aesHistory.setAesException(exception); aesHistory.setFileNo(fileNo); aesHistory.setItn(itn); aesHistory.setStatus(status); aesHistory.setProcessedDate(new Date()); byte[] bs = IOUtils.toByteArray(is); Blob blob = fclBlDAO.getSession().getLobHelper().createBlob(bs); aesHistory.setResponseFile(blob); new AesHistoryDAO().save(aesHistory); sedFilingsDAO.update(sedFilings); } } }
From source file:org.aliuge.crawler.extractor.selector.action.string.StringSubAction.java
/** * ???/*from w ww. j av a 2s .co m*/ */ @Override public String doAction(String content) { if (StringUtils.isNotBlank(content)) { if (StringUtils.isNotBlank(spos)) { this.pos = content.indexOf(spos) + spos.length(); } if (this.lenth == 0 && this.pos > 0) { content = StringUtils.substring(content, this.pos); } else if (this.lenth > 0 && this.pos >= 0) { content = StringUtils.substring(content, this.pos, this.pos + this.lenth); } return content; } return ""; }
From source file:org.apache.metron.common.stellar.shell.StellarShell.java
/** * Handles user interaction when executing a doc command. * @param expression The expression to execute. *//*from w w w .j a v a 2s . co m*/ private void handleDoc(String expression) { String functionName = StringUtils.substring(expression, 1); StreamSupport.stream(executor.getFunctionResolver().getFunctionInfo().spliterator(), false) .filter(info -> StringUtils.equals(functionName, info.getName())).map(info -> format(info)) .forEach(doc -> write(doc)); }
From source file:org.apache.metron.stellar.common.shell.specials.DocCommand.java
@Override public StellarResult execute(String command, StellarShellExecutor executor) { StellarResult result;/* ww w .j av a 2 s . co m*/ // expect ?functionName String functionName = StringUtils.substring(command, 1); // grab any docs for the given function Spliterator<StellarFunctionInfo> fnIterator = executor.getFunctionResolver().getFunctionInfo() .spliterator(); Optional<StellarFunctionInfo> functionInfo = StreamSupport.stream(fnIterator, false) .filter(info -> StringUtils.equals(functionName, info.getName())).findFirst(); if (functionInfo.isPresent()) { result = success(docFormat(functionInfo.get())); } else { result = error(String.format("No docs available for function '%s'", functionName)); } return result; }
From source file:org.apache.struts2.components.template.TemplateEngineManager.java
/** * <p>/*from w ww . j a v a2s . c o m*/ * Gets the TemplateEngine for the template name. If the template name has an extension (for instance foo.jsp), then * this extension will be used to look up the appropriate TemplateEngine. If it does not have an extension, it will * look for a Configuration setting "struts.ui.templateSuffix" for the extension, and if that is not set, it * will fall back to "ftl" as the default. * </p> * * @param template Template used to determine which TemplateEngine to return * @param templateTypeOverride Overrides the default template type * @return the engine. */ public TemplateEngine getTemplateEngine(Template template, String templateTypeOverride) { String templateType = DEFAULT_TEMPLATE_TYPE; String templateName = template.toString(); if (StringUtils.contains(templateName, ".")) { templateType = StringUtils.substring(templateName, StringUtils.indexOf(templateName, ".") + 1); } else if (StringUtils.isNotBlank(templateTypeOverride)) { templateType = templateTypeOverride; } else { String type = defaultTemplateType; if (type != null) { templateType = type; } } return templateEngines.get(templateType).create(); }
From source file:org.apache.struts2.util.RegexPatternMatcher.java
public RegexPatternMatcherExpression compilePattern(String data) { Map<Integer, String> params = new HashMap<Integer, String>(); Matcher matcher = PATTERN.matcher(data); int count = 0; while (matcher.find()) { String expression = matcher.group(1); //check if it is a regex int index = expression.indexOf(':'); if (index > 0) { String paramName = expression.substring(0, index); String regex = StringUtils.substring(expression, index + 1); if (StringUtils.isBlank(regex)) { throw new IllegalArgumentException("invalid expression [" + expression + "], named parameter regular exression " + "must be in the format {PARAM_NAME:REGEX}"); }/*from w w w . j a va2 s . com*/ params.put(++count, paramName); } else { params.put(++count, expression); } } //generate a new pattern used to match URIs //replace {X:B} by (B) String newPattern = data.replaceAll("(\\{[^\\}]*?:(.*?)\\})", "($2)"); //replace {X} by (.*?) newPattern = newPattern.replaceAll("(\\{.*?\\})", "(.*?)"); return new RegexPatternMatcherExpression(Pattern.compile(newPattern), params); }
From source file:org.asqatasun.ruleimplementation.link.AbstractDownloadableLinkRuleImplementation.java
/** * /*from ww w . j a v a 2s . co m*/ * @param uri * @return whether the current link has a proper extension (link.html) */ private boolean isLinkWithProperExtension(URI uri) { if (StringUtils.isNotBlank(uri.getQuery())) { return false; } String path = uri.getPath(); if (StringUtils.isBlank(path) || StringUtils.equals(path, SLASH_CHAR)) { return false; } int lastSlash = StringUtils.lastIndexOf(path, SLASH_CHAR); return StringUtils.substring(path, lastSlash).contains(POINT_CHAR); }