List of usage examples for org.apache.commons.lang StringUtils remove
public static String remove(String str, char remove)
Removes all occurrences of a character from within the source string.
From source file:com.jnj.b2b.storefront.controllers.misc.StoreSessionController.java
protected String getReturnRedirectUrlForUrlEncoding(final HttpServletRequest request, final String old, final String current) { final String originalReferer = (String) request.getSession() .getAttribute(StorefrontFilter.ORIGINAL_REFERER); if (StringUtils.isNotBlank(originalReferer)) { return REDIRECT_PREFIX + StringUtils.replace(originalReferer, "/" + old + "/", "/" + current + "/"); }/*from w w w . j a va2 s . c om*/ String referer = StringUtils.remove(request.getRequestURL().toString(), request.getServletPath()); if (!StringUtils.endsWith(referer, "/")) { referer = referer + "/"; } if (referer != null && !referer.isEmpty() && StringUtils.contains(referer, "/" + old)) { return REDIRECT_PREFIX + StringUtils.replace(referer, "/" + old, "/" + current); } return REDIRECT_PREFIX + referer; }
From source file:fitnesse.wiki.PageData.java
public void setContent(String content) { this.content = StringUtils.remove(content, '\r'); }
From source file:net.sf.profiler4j.console.util.export.FilenameGenerator.java
/** * Checks to see, if the given pattern is correct syntactically, i.e. if the pattern makes sense. * <p>// w w w . j av a 2s .c o m * See the class comment for a specification of what constitutes a valid pattern. * <p> * A pattern for which this method returns {@code true} may still be unusable, e.g. if the target directory * is write-protected. * * @param pattern The pattern. * @return {@code true}, if the pattern is syntactically correct, {@code false} otherwise. */ public boolean isValidPattern(String pattern) { if (StringUtils.isBlank(pattern)) return false; // It may not contain more than one placeholder for a running-number in the file name. String name = extractFileName(pattern); if (1 < StringUtils.countMatches(name, PLACEHOLDER__RUNNING_NUMBER)) return false; // With placeholders removed, the pattern must constitute a valid filename in the current system. // To check this, we simply try to create the file. String pattern_without_placeholders = StringUtils.remove(pattern, "%i"); if (!isPossibleToCreateFile(pattern_without_placeholders)) { return false; } return true; }
From source file:net.sourceforge.jaulp.xsl.transform.XsltTransformerUtilsTest.java
@Test public void testGetTransformerFile() throws TransformerConfigurationException, TransformerFactoryConfigurationError, TransformerException, IOException { final File resDestDir = PathFinder.getSrcTestResourcesDir(); String[] dirsAndFilename = { "net", "sourceforge", "jaulp", "xsl", "transform", "birthdates.xml" }; File xmlFile = PathFinder.getRelativePathTo(resDestDir, Arrays.asList(dirsAndFilename)); File xsltFile = PathFinder.getRelativePathTo(resDestDir, "\\.", "net.sourceforge.jaulp.xsl.transform", "functions.xsl"); File outputFile = PathFinder.getRelativePathTo(resDestDir, "\\.", "net.sourceforge.jaulp.xsl.transform", "output.xml"); XsltTransformerUtils.transform(xmlFile, xsltFile, new FileOutputStream(outputFile)); String actual = ReadFileUtils.readFromFile(outputFile); actual = StringUtils.remove(actual, '\r'); actual = StringUtils.remove(actual, '\n'); expected = StringUtils.remove(expected, '\r'); expected = StringUtils.remove(expected, '\n'); AssertJUnit.assertTrue("", expected.equals(actual)); }
From source file:ch.algotrader.esper.SpringServiceResolver.java
@Override public void resolve(final EPStatement statement, final String subscriberExpression) { if (StringUtils.isBlank(subscriberExpression)) { throw new IllegalArgumentException("Subscriber is empty"); }/*www.j a va 2s. c o m*/ PropertyPlaceholderHelper placeholderHelper = new PropertyPlaceholderHelper("${", "}", ",", false); String s = placeholderHelper.replacePlaceholders(subscriberExpression, name -> { if (name.equalsIgnoreCase("strategyName")) { return this.strategyName; } else { return this.configParams.getString(name, "null"); } }); final Matcher matcher = SUBSCRIBER_NOTATION.matcher(s); if (matcher.matches()) { // New subscriber notation final String beanName = matcher.group(1); final String beanMethod = matcher.group(3); Object bean = this.applicationContext.getBean(beanName); try { statement.setSubscriber(bean, beanMethod); } catch (EPSubscriberException ex) { throw new SubscriberResolutionException("Subscriber expression '" + subscriberExpression + "' could not be resolved to a service method", ex); } } else { // Assuming to be a fully qualified class name otherwise try { Class<?> cl = Class.forName(s); statement.setSubscriber(cl.newInstance()); } catch (Exception e) { // Old notation for backward compatibility String serviceName = StringUtils.substringBeforeLast(s, "."); if (serviceName.contains(".")) { serviceName = StringUtils.remove(StringUtils.remove( StringUtils.uncapitalize(StringUtils.substringAfterLast(serviceName, ".")), "Base"), "Impl"); } String beanMethod = StringUtils.substringAfterLast(s, "."); Object bean = this.applicationContext.getBean(serviceName); statement.setSubscriber(bean, beanMethod); } } }
From source file:edu.cornell.kfs.fp.batch.ProcurementCardFlatInputFileType.java
/** * No additional information is added to procurement card batch files. * /*from w w w. j av a 2 s . c om*/ * @see org.kuali.kfs.sys.batch.BatchInputFileType#getFileName(org.kuali.rice.kim.bo.Person, java.lang.Object, * java.lang.String) */ public String getFileName(String principalName, Object parsedFileContents, String userIdentifier) { String fileName = "pcdo_" + principalName; if (StringUtils.isNotBlank(userIdentifier)) { fileName += "_" + userIdentifier; } fileName += "_" + dateTimeService.toDateTimeStringForFilename(dateTimeService.getCurrentDate()); // remove spaces in filename fileName = StringUtils.remove(fileName, " "); return fileName; }
From source file:net.birelian.liquibase.converter.mojo.XmlToYamlConverterMojo.java
/** * Create a file//from w w w. ja v a 2 s . c o m * * @param originalFileName The original file name * @return The file * @throws ApplicationException If any */ private File createFile(String originalFileName) throws ApplicationException { // Remove the original extension String fileName = StringUtils.remove(originalFileName, "." + sourceFormat); File file = new File(targetDir + PATH_SEPARATOR + fileName + "." + targetFormat); // Create file if it doesn't exist if (!file.exists()) { try { boolean created = file.createNewFile(); if (!created) { throw new ApplicationException("Unable to create file " + file.getName()); } } catch (IOException e) { throw new ApplicationException("Unable to create file " + fileName, e); } } return file; }
From source file:com.akrema.stringeval.StringEvaluator.java
/** * {@inheritDoc}/*from w w w . ja v a 2 s .c o m*/ */ @Override public ArrayList<Argument> getArguments(String expr, int beginindex, int endindex) throws ParseExpressionException, InputStringException { ArrayList<Argument> args = new ArrayList<Argument>(); this.argString = expr.substring(beginindex, endindex); String argsource; this.argString = StringUtils.remove(this.argString, StringCONST.LEFT_PARENTHESE); this.argString = StringUtils.remove(this.argString, StringCONST.RIGHT_PARENTHESE); String[] tocken = this.argString.split(StringCONST.DELM); this.argString = this.argString.trim(); if (tocken.length > 3) { throw new InputStringException("missing arguments ,the number of argument must be between" + "1 and 3"); } if (!tocken[0].startsWith(String.valueOf(StringCONST.SINGLE_QUOTE))) { throw new ParseExpressionException(" invalid String Source "); } tocken[0] = StringUtils.remove(tocken[0], StringCONST.SINGLE_QUOTE); argsource = tocken[0].trim(); args.add(new Argument(0, StringCONST.TYPE_STRING, argsource)); int tokenindex = 1; while (tokenindex < tocken.length) { String arg = tocken[tokenindex]; arg = arg.trim(); if (arg.startsWith("\'")) arg = StringUtils.remove(arg, StringCONST.SINGLE_QUOTE); arg = arg.trim(); switch (ExprUtils.getTypeArgs(arg)) { case 0: args.add(new Argument(tokenindex, StringCONST.TYPE_CHAR, arg)); break; case 1: args.add(new Argument(tokenindex, StringCONST.TYPE_INTEGER, arg)); break; case 2: args.add(new Argument(tokenindex, StringCONST.TYPE_STRING, arg)); break; default: break; } tokenindex++; } return args; }
From source file:gov.nih.nci.caxchange.transcend.CaXchangeRequestService.java
/** * This method is used process the message * //from w w w . j a va2 s .c o m * @param parameters - parameters * @return ResponseMessage */ @WebResult(name = "responseMessage", targetNamespace = "http://caXchange.nci.nih.gov/caxchangerequest", partName = "parameters") @WebMethod public gov.nih.nci.caxchange.messaging.ResponseMessage processRequest( @WebParam(partName = "parameters", name = "message", targetNamespace = "http://caXchange.nci.nih.gov/caxchangerequest") Message parameters) { LOG.debug("Executing operation processRequest"); final Long caXchangeId = Calendar.getInstance().getTimeInMillis(); // setting this value as String, but inside the app is expecting a long value parameters.getMetadata().setCaXchangeIdentifier(String.valueOf(caXchangeId)); final gov.nih.nci.caxchange.messaging.ResponseMessage respMessage = new ResponseMessage(); final ResponseMetadata rm = new ResponseMetadata(); rm.setExternalIdentifier(parameters.getMetadata().getExternalIdentifier()); rm.setCaXchangeIdentifier(parameters.getMetadata().getCaXchangeIdentifier()); respMessage.setResponseMetadata(rm); try { final String reqstr = getCaXchangeRequestxml(parameters); if (StringUtils.isEmpty(reqstr)) { final ErrorDetails errorDetails = new ErrorDetails(); errorDetails.setErrorCode(String.valueOf(IntegrationError._1050)); errorDetails.setErrorDescription(IntegrationError._1050.getMessage((Object) null)); final Response response = new Response(); response.setCaXchangeError(errorDetails); response.setResponseStatus(Statuses.FAILURE); respMessage.setResponse(response); return respMessage; } String mcResponse = webServiceMessageReceiver.processData(reqstr); if (LOG.isDebugEnabled()) { LOG.debug("CaXchangeRequestService..MC RESPONSE:" + mcResponse); } if (StringUtils.isEmpty(mcResponse)) { throw new JAXBException("No proper response from iHub"); } if ((mcResponse.indexOf("Error") > -1 || mcResponse.indexOf("Exception") > -1 || mcResponse.indexOf("ERROR") > -1 || mcResponse.indexOf("error") > -1)) { mcResponse = StringUtils.remove(mcResponse, "SUCCESS:"); mcResponse = StringUtils.remove(mcResponse, "FAILURE:"); final Response response = new Response(); response.setCaXchangeError(getErrorDetailsFromCaXchangeError(mcResponse)); response.setResponseStatus(Statuses.FAILURE); respMessage.setResponse(response); return respMessage; } final Response response = new Response(); response.setResponseStatus(Statuses.SUCCESS); response.getTargetResponse().add(prepareTargetResponse(parameters)); respMessage.setResponse(response); return respMessage; } catch (JAXBException ex) { return getJAXBExceptionResponseMessage(respMessage, ex); } }
From source file:com.theserverlabs.maven.utplsq.SureFireReport.java
/** * Converts test results into a Surefire xml test tags * /* w ww . ja va2 s.c o m*/ * @param status * @param dc a decoded utplsql description * @param testResult populated with failures and latest success/failure count * @throws SplitterException */ protected void addTestResults(String status, DescContainer dc, TestResults tr) throws SplitterException { // work out if the test was a success or failure // (only statuses possible in utPLSQL) if ("SUCCESS".equals(status)) { tr.incSuccessCounter(); } else { tr.incFailureCounter(); } // generate the XML for each test executed and add it to a // string buffer that we'll later write to a file tr.getTestXML().append("\n <testcase classname=\"" + dc.getProcedureName() + "\" "); // Remove Quotes to make text more readable tr.getTestXML().append("name=\"" + StringEscapeUtils.escapeXml(dc.getTestName()) + "\" "); tr.getTestXML().append("time=\"" + dc.getDuration() + "\""); tr.getTestXML().append(">"); if ("FAILURE".equals(status)) { tr.getTestXML().append("\n <failure type=\"" + dc.getType() + "\""); tr.getTestXML().append(" message=\""); String resultsMinusQuotes = StringUtils.remove(dc.getResults(), '"'); tr.getTestXML().append(StringEscapeUtils.escapeXml(resultsMinusQuotes)); tr.getTestXML().append("\"/>\n "); tr.getFailureDescriptions() .add(dc.getProcedureName() + "\n" + dc.getTestName() + "\n" + dc.getResults()); } tr.getTestXML().append("</testcase>"); }