List of usage examples for org.apache.commons.lang StringUtils stripEnd
public static String stripEnd(String str, String stripChars)
Strips any of a set of characters from the end of a String.
From source file:com.adobe.acs.tools.tag_maker.tagdataconverters.impl.LowercaseWithDashesConverterImpl.java
@Override public final TagData convert(final String data) { String title = data;//from w w w. j av a 2 s .c o m String name = data; name = StringUtils.stripToEmpty(name); name = StringUtils.lowerCase(name); name = StringUtils.replace(name, "&", " and "); name = StringUtils.replace(name, "/", " or "); name = StringUtils.replace(name, "%", " percent "); name = name.replaceAll("[^a-z0-9-]+", "-"); name = StringUtils.stripEnd(name, "-"); name = StringUtils.stripStart(name, "-"); final TagData tagData = new TagData(name); tagData.setTitle(title); return tagData; }
From source file:com.gemstone.gemfire.management.internal.cli.parser.preprocessor.PreprocessorUtils.java
/** * /*from w w w .jav a2 s .c om*/ * This function will trim the given input string. It will not only remove the * spaces and tabs at the end but also compress multiple spaces and tabs to a * single space * * @param input * The input string on which the trim operation needs to be performed * @param retainLineSeparator * whether to retain the line separator. * * @return String */ public static TrimmedInput trim(final String input, final boolean retainLineSeparator) { if (input != null) { String inputCopy = input; StringBuffer output = new StringBuffer(); // First remove the trailing white spaces, we do not need those inputCopy = StringUtils.stripEnd(inputCopy, null); // As this parser is for optionParsing, we also need to remove // the trailing optionSpecifiers provided it has previous // options. Remove the trailing LONG_OPTION_SPECIFIERs // in a loop. It is necessary to check for previous options for // the case of non-mandatory arguments. // "^(.*)(\\s-+)$" - something that ends with a space followed by a series of hyphens. while (Pattern.matches("^(.*)(\\s-+)$", inputCopy)) { inputCopy = StringUtils.removeEnd(inputCopy, SyntaxConstants.SHORT_OPTION_SPECIFIER); // Again we need to trim the trailing white spaces // As we are in a loop inputCopy = StringUtils.stripEnd(inputCopy, null); } // Here we made use of the String class function trim to remove the // space and tabs if any at the // beginning and the end of the string int noOfSpacesRemoved = 0; { int length = inputCopy.length(); inputCopy = inputCopy.trim(); noOfSpacesRemoved += length - inputCopy.length(); } // Now we need to compress the multiple spaces and tabs to single space // and tabs but we also need to ignore the white spaces inside the // quotes and parentheses StringBuffer buffer = new StringBuffer(); boolean startWhiteSpace = false; for (int i = 0; i < inputCopy.length(); i++) { char ch = inputCopy.charAt(i); buffer.append(ch); if (PreprocessorUtils.isWhitespace(ch)) { if (PreprocessorUtils.isSyntaxValid(buffer.toString())) { if (startWhiteSpace) { noOfSpacesRemoved++; } else { startWhiteSpace = true; if (ch == '\n') { if (retainLineSeparator) { output.append("\n"); } } else { output.append(" "); } } buffer.delete(0, buffer.length()); } else { output.append(ch); } } else { startWhiteSpace = false; output.append(ch); } } return new TrimmedInput(output.toString(), noOfSpacesRemoved); } else { return null; } }
From source file:com.microfocus.application.automation.tools.octane.executor.scmmanager.SvnPluginHandler.java
@Override public void setScmRepositoryInJob(SCMRepository scmRepository, String scmRepositoryCredentialsId, FreeStyleProject proj, boolean executorJob) throws IOException { String relativeCheckOut;// w w w. j a v a2 s .c o m if (executorJob) { String url = StringUtils.stripEnd(scmRepository.getUrl(), "/").replaceAll("[<>:\"/\\|?*]", "_"); relativeCheckOut = "a\\..\\..\\..\\_test_sources\\" + url; } else { relativeCheckOut = "a" + File.separator + "..";//it doesn't has any affect on checkout folder. Without it, svn do checkout to folder of svn repository name //for example for URL https://myd-vm00812.hpeswlab.net/svn/uft_tests/ - tests will be cloned to "uft_tests" subfolder //adding a\.. will clone as is - Why we need it - subfolder is part of "package" reported to Octane } SubversionSCM svn = new SubversionSCM(scmRepository.getUrl(), scmRepositoryCredentialsId, relativeCheckOut); proj.setScm(svn); }
From source file:com.adobe.communities.ugc.migration.legacyProfileExport.SocialGraphExportServlet.java
protected void doGet(final SlingHttpServletRequest request, final SlingHttpServletResponse response) throws ServletException, IOException { final JSONWriter writer = new JSONWriter(response.getWriter()); writer.setTidy(true);//from ww w.ja v a 2 s .c om final SocialGraph graph = request.getResourceResolver().adaptTo(SocialGraph.class); final String path = StringUtils.stripEnd(request.getRequestParameter("path").getString(), "/"); final Resource userRoot = request.getResourceResolver().getResource(path); if (null == userRoot) { throw new ServletException("Cannot locate a valid resource at " + path); } final ValueMap vm = userRoot.adaptTo(ValueMap.class); if (!vm.get("jcr:primaryType").equals("rep:AuthorizableFolder")) { throw new ServletException("Cannot locate a valid resource at " + path); } //iterate over child resources to get user nodes try { writer.object(); exportSocialGraph(writer, userRoot, graph); writer.endObject(); } catch (final JSONException e) { throw new ServletException("Encountered a json exception while exporting social graph", e); } }
From source file:com.seer.datacruncher.datastreams.CreateXMLFromFlatFileFixedPosition.java
public DatastreamDTO createXMLFromFlatFileFixedPosition(DatastreamDTO dataStreamDTO) { String datastream = dataStreamDTO.getInput(); String fieldValue;// w ww . ja v a2 s .c om String fillChar; int beginIndex = 0; int endIndex = 0; int lenght = datastream.length(); List<SchemaFieldEntity> listSchemaFields = schemaFieldsDao.listSchemaFields(dataStreamDTO.getIdSchema()); List<String> listValues = new ArrayList<String>(); for (int cont = 0; cont < listSchemaFields.size(); cont++) { endIndex = beginIndex + Integer.parseInt(listSchemaFields.get(cont).getSize()); if (endIndex > lenght) { dataStreamDTO.setSuccess(false); dataStreamDTO.setMessage(I18n.getMessage("error.lenghtNotValid")); return dataStreamDTO; } fieldValue = datastream.substring(beginIndex, endIndex); beginIndex = endIndex; if (listSchemaFields.get(cont).getIdFieldType() != FieldType.date) { fillChar = listSchemaFields.get(cont).getFillChar(); if (listSchemaFields.get(cont).getIdAlign() == null || listSchemaFields.get(cont).getIdAlign() == 1) { fieldValue = StringUtils.stripEnd(fieldValue, fillChar); } else { fieldValue = StringUtils.stripStart(fieldValue, fillChar); } } fieldValue = fieldValue.replaceAll("&", "&"); listValues.add(fieldValue); } if (endIndex != lenght) { dataStreamDTO.setSuccess(false); dataStreamDTO.setMessage(I18n.getMessage("error.lenghtNotValid")); } else { StringBuffer stringBuffer = new StringBuffer(); stringBuffer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); stringBuffer.append("<" + Tag.TAG_ROOT + ">\n"); for (int cont = 0; cont < listSchemaFields.size(); cont++) { if (!listSchemaFields.get(cont).getNillable() || listValues.get(cont).length() > 0) { stringBuffer.append("\t<" + listSchemaFields.get(cont).getName() + ">" + listValues.get(cont) + "</" + listSchemaFields.get(cont).getName() + ">\n"); } } stringBuffer.append("</" + Tag.TAG_ROOT + ">\n"); dataStreamDTO.setSuccess(true); dataStreamDTO.setOutput(stringBuffer.toString()); } log.info(dataStreamDTO.getOutput()); return dataStreamDTO; }
From source file:gov.nih.nci.caarray.application.GenericDataServiceBean.java
/** * {@inheritDoc}// ww w . j a v a 2 s . c o m */ @Override public String getIncrementingCopyName(Class<?> entityClass, String fieldName, String name) { final String alphaPrefix = StringUtils.stripEnd(name, "0123456789"); final String numericSuffix = StringUtils.substringAfter(name, alphaPrefix); int maxSuffix = StringUtils.isEmpty(numericSuffix) ? 1 : Integer.parseInt(numericSuffix); final List<String> currentNames = this.searchDao.findValuesWithSamePrefix(entityClass, fieldName, alphaPrefix); for (final String currentName : currentNames) { final String suffix = StringUtils.substringAfter(currentName, alphaPrefix); if (!StringUtils.isNumeric(suffix) || StringUtils.isEmpty(suffix)) { continue; } maxSuffix = Math.max(maxSuffix, Integer.parseInt(suffix)); } return alphaPrefix + (maxSuffix + 1); }
From source file:com.adobe.communities.ugc.migration.legacyExport.ScoresExportServlet.java
protected void doGet(final SlingHttpServletRequest request, final SlingHttpServletResponse response) throws ServletException, IOException { final JSONWriter writer = new JSONWriter(response.getWriter()); writer.setTidy(true);/*w w w . jav a2 s . c o m*/ final String path = StringUtils.stripEnd(request.getRequestParameter("path").getString(), "/"); final Resource userRoot = request.getResourceResolver().getResource(path); if (null == userRoot) { throw new ServletException("Cannot locate a valid resource at " + path); } final ValueMap vm = userRoot.adaptTo(ValueMap.class); if (!vm.get("jcr:primaryType").equals("rep:AuthorizableFolder")) { throw new ServletException("Cannot locate a valid resource at " + path); } //iterate over child resources to get user nodes try { writer.object(); exportScores(writer, userRoot, request.getResourceResolver()); writer.endObject(); } catch (final JSONException e) { throw new ServletException("Encountered a json exception while exporting scores", e); } }
From source file:com.hpe.application.automation.tools.octane.executor.scmmanager.SvnPluginHandler.java
@Override public void setScmRepositoryInJob(SCMRepository scmRepository, String scmRepositoryCredentialsId, FreeStyleProject proj, boolean executorJob) throws IOException { String relativeCheckOut = null; if (executorJob) { String url = StringUtils.stripEnd(scmRepository.getUrl(), "/").replaceAll("[<>:\"/\\|?*]", "_"); relativeCheckOut = "a\\..\\..\\..\\_test_sources\\" + url; } else {/*from ww w . ja va 2 s.c o m*/ relativeCheckOut = "a" + File.separator + "..";//it doesn't has any affect on checkout folder. Without it, svn do checkout to folder of svn repository name //for example for URL https://myd-vm00812.hpeswlab.net/svn/uft_tests/ - tests will be cloned to "uft_tests" subfolder //adding a\.. will clone as is - Why we need it - subfolder is part of "package" reported to Octane } SubversionSCM svn = new SubversionSCM(scmRepository.getUrl(), scmRepositoryCredentialsId, relativeCheckOut); proj.setScm(svn); }
From source file:de.hybris.platform.addonsupport.config.SpelBeanFactory.java
@Override public void onApplicationEvent(final ContextRefreshedEvent event) { final ExpressionParser parser = new SpelExpressionParser(); final StandardEvaluationContext context = new StandardEvaluationContext(); context.setBeanResolver(new BeanFactoryResolver(applicationContext)); final String[] beanNames = applicationContext.getBeanNamesForType(AbstractConverter.class); for (final String beanName : beanNames) { final BeanDefinition def = beanFactory.getBeanDefinition(beanName); final PropertyValue pv = def.getPropertyValues().getPropertyValue("targetClass"); if (pv != null) { if (pv.getValue() instanceof TypedStringValue) { String expr = StringUtils.strip(((TypedStringValue) pv.getValue()).getValue()); if (expr.startsWith("#{")) { expr = StringUtils.replaceOnce(expr, "#{", "@"); expr = StringUtils.stripEnd(expr, "}"); final Object result = parser.parseExpression(expr).getValue(context); if (result != null) { try { applicationContext.getBean(beanName, AbstractConverter.class) .setTargetClass(ClassUtils.getClass(result.toString())); } catch (final ClassNotFoundException e) { LOG.error(beanName + " target class instantiation failed", e); }/* w w w. j a v a 2 s .c o m*/ } } } } } }
From source file:com.jivesoftware.jivesdk.server.endpoints.WebEndpoints.java
@GET @Path(ROOT_BY_NAME)/*from www .j ava 2 s . c om*/ @Produces(MediaType.TEXT_HTML) public Response getFile(@PathParam("name") String name, @QueryParam("vars") String vars) { try { if (name == null || name.trim().isEmpty()) { log.error("Request for invalid HTML resource"); return Response.status(Response.Status.BAD_REQUEST).build(); } Map<String, String> replacements = Maps.newHashMap(); replacements.put(HOST_SUFFIX, ""); if (!StringUtils.isEmpty(vars)) { String decodedVars = JiveSDKUtils.decodeBase64(vars); JsonNode replaceObj = new ObjectMapper().readTree(decodedVars); Iterator<Map.Entry<String, JsonNode>> it = replaceObj.getFields(); while (it.hasNext()) { Map.Entry<String, JsonNode> entry = it.next(); String key = entry.getKey(); String value = entry.getValue().asText(); if (key.startsWith(TEMPLATE_PREFIX) && key.endsWith(TEMPLATE_SUFFIX)) { replacements.put(key, value); } else { log.warn("Ignoring invalid HTML replacement-var: " + key + " -> " + value); } } } replacements.put(HOST_TEMPLATE, StringUtils.stripEnd(uriInfo.getBaseUri().toString(), "/")); replacements.put(TIME_TEMPLATE, String.valueOf(System.currentTimeMillis())); if (!verifyReplacementsAreValid(replacements)) { String entity = JiveSDKUtils.createHtmlMessage("Invalid HTML replacement-vars"); return Response.status(Response.Status.BAD_REQUEST).entity(entity).build(); } String contents = JiveSDKUtils.readFile(name); for (Map.Entry<String, String> entry : replacements.entrySet()) { contents = contents.replace(entry.getKey(), entry.getValue()); } return Response.ok(contents).build(); } catch (Throwable t) { log.error("Failed fetching HTML file: " + name, t); return Response.status(Response.Status.NOT_FOUND).build(); } }