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:org.jboss.bqt.client.xml.XMLQueryVisitationStrategy.java
/** * Consume an XML results File, produce results as JDOM and add results to the given parent. * <br>/*from w ww . j ava2 s . co m*/ * @param resultsFile the XML file object that is to be parsed * @param parent the parent Element to assign results to * @return the modified parent * @throws IOException * @exception JDOMException if there is an error consuming the message. */ public Element parseXMLResultsFile(File resultsFile, Element parent) throws IOException, JDOMException { SAXBuilder builder = SAXBuilderHelper.createSAXBuilder(false); Document resultsDocument = builder.build(resultsFile); List resultElements = resultsDocument.getRootElement().getChildren(TagNames.Elements.QUERY_RESULTS); Iterator iter = resultElements.iterator(); while (iter.hasNext()) { Element resultElement = (Element) iter.next(); if (resultElement.getChild(TagNames.Elements.SELECT) == null) { // We've got an exception Element exceptionElement = resultElement.getChild(TagNames.Elements.EXCEPTION); if (exceptionElement != null) { // --------------------------------- // Add the ExceptionType element ... // --------------------------------- Element typeElement = new Element(TagNames.Elements.EXCEPTION_TYPE); typeElement.setText(exceptionElement.getChild(TagNames.Elements.EXCEPTION_TYPE).getTextTrim()); parent.addContent(typeElement); // --------------------------- // Add the Message element ... // --------------------------- Element messageElement = new Element(TagNames.Elements.MESSAGE); String msg = exceptionElement.getChild(TagNames.Elements.MESSAGE).getTextTrim(); messageElement.setText(StringUtils.remove(msg, '\r')); parent.addContent(messageElement); // ------------------------- // Add the Class element ... // ------------------------- Element classElement = new Element(TagNames.Elements.CLASS); classElement.setText(exceptionElement.getChild(TagNames.Elements.CLASS).getTextTrim()); parent.addContent(classElement); } } else { // We've got results // ------------------------------- // Read the SELECT elements // ------------------------------- Element selectElement = resultElement.getChild(TagNames.Elements.SELECT); resultElement.removeChild(TagNames.Elements.SELECT); parent.addContent(selectElement); // ------------------------------- // Read the TABLE of data // ------------------------------- Element tableElement = resultElement.getChild(TagNames.Elements.TABLE); resultElement.removeChild(TagNames.Elements.TABLE); parent.addContent(tableElement); } } return parent; }
From source file:org.jboss.bqt.client.xml.XMLQueryVisitationStrategy.java
/** * Produce an XML message for an instance of the SQLException. * <br>// w w w . j av a 2 s .c om * @param object the instance for which the message is to be produced. * @param parent the XML element that is to be the parent of the produced XML message. * @return the root element of the XML segment that was produced. * @exception JDOMException if there is an error producing the message. */ private Element produceMsg(Throwable object, Element parent) throws JDOMException { Throwable exception = object; Element exceptionElement = null; // -------------------------------- // Create the Exception element ... // -------------------------------- exceptionElement = new Element(TagNames.Elements.EXCEPTION); // --------------------------------- // Add the ExceptionType element ... // --------------------------------- String className = exception.getClass().getName(); int index = className.lastIndexOf('.'); if (index != -1 && (++index) < className.length()) { className = className.substring(index); } Element typeElement = new Element(TagNames.Elements.EXCEPTION_TYPE); typeElement.setText(className); exceptionElement.addContent(typeElement); // --------------------------- // Add the Message element ... // --------------------------- Element messageElement = new Element(TagNames.Elements.MESSAGE); messageElement.setText(StringUtils.remove(ExceptionUtil.getExceptionMessage(exception), '\r')); exceptionElement.addContent(messageElement); // ------------------------- // Add the Class element ... // ------------------------- Element classElement = new Element(TagNames.Elements.CLASS); classElement.setText(exception.getClass().getName()); exceptionElement.addContent(classElement); if (parent != null) { exceptionElement = parent.addContent(exceptionElement); } return exceptionElement; }
From source file:org.jboss.windup.util.RecursiveZipMetaFactory.java
public RecursiveZipMetaFactory(File startLocation, Set<String> extensions) { UUID uuidKey = UUID.randomUUID(); safeExtractKey = "_" + StringUtils.substring(StringUtils.remove(uuidKey.toString(), "-"), 0, 6); this.startLocation = new File( startLocation.getAbsolutePath() + File.separator + "jboss_windup" + safeExtractKey); this.kae = extensions; }
From source file:org.jboss.windup.util.RecursiveZipMetaFactory.java
private ZipMetadata generateArchive(ZipMetadata parent, File entryOutput) { String relativePath = StringUtils.removeStart(entryOutput.getAbsolutePath(), this.startLocation.getAbsolutePath().toString()); if (LOG.isTraceEnabled()) { LOG.trace("RE Relative Path: " + relativePath); LOG.trace("SafeKey: " + safeExtractKey); }/* w w w . j a v a 2s .c o m*/ relativePath = StringUtils.replace(relativePath, "\\", "/"); relativePath = StringUtils.removeStart(relativePath, "/"); if (StringUtils.contains(relativePath, this.safeExtractKey)) { // all subarchives of the target archive will get copied to a location with the safeExtractKey. relativePath = StringUtils.remove(relativePath, this.safeExtractKey); } else { // otherwise, we know it is the original file... relativePath = StringUtils.substringAfterLast(relativePath, "/"); } String archiveName = relativePath; if (StringUtils.contains(archiveName, "/")) { archiveName = StringUtils.substringAfterLast(relativePath, "/"); } ZipMetadata archive = new ZipMetadata(); archive.setName(archiveName); archive.setFilePointer(entryOutput); archive.setRelativePath(relativePath); if (parent != null) { parent.getNestedArchives().add(archive); } archive.setArchiveMeta(parent); if (LOG.isTraceEnabled()) { LOG.trace("Created archive: " + archive.toString()); } return archive; }
From source file:org.jfrog.teamcity.agent.BaseBuildInfoExtractor.java
private void gatherBuildInfoParams(Map<String, String> allParamMap, Map propertyReceiver, final String propPrefix, final String... propTypes) { Map<String, String> filteredProperties = Maps.filterKeys(allParamMap, new Predicate<String>() { public boolean apply(String key) { if (StringUtils.isNotBlank(key)) { if (key.startsWith(propPrefix)) { return true; }/*from www. j av a 2 s . co m*/ for (String propType : propTypes) { if (key.startsWith(propType + propPrefix)) { return true; } } } return false; } }); filteredProperties = Maps.filterValues(filteredProperties, new Predicate<String>() { public boolean apply(String value) { return StringUtils.isNotBlank(value); } }); for (Map.Entry<String, String> entryToAdd : filteredProperties.entrySet()) { String key = entryToAdd.getKey(); for (String propType : propTypes) { key = StringUtils.remove(key, propType); } key = StringUtils.remove(key, propPrefix); propertyReceiver.put(key, entryToAdd.getValue()); } }
From source file:org.jfrog.teamcity.agent.util.ArtifactoryClientConfigurationBuilder.java
private static void gatherBuildInfoParams(Map<String, String> allParamMap, ArtifactoryClientConfiguration.PublisherHandler configuration, final String propPrefix, final String... propTypes) { Map<String, String> filteredProperties = Maps.filterKeys(allParamMap, new Predicate<String>() { public boolean apply(String key) { if (StringUtils.isNotBlank(key)) { if (key.startsWith(propPrefix)) { return true; }//from w w w . j av a 2 s. c o m for (String propType : propTypes) { if (key.startsWith(propType + propPrefix)) { return true; } } } return false; } }); filteredProperties = Maps.filterValues(filteredProperties, new Predicate<String>() { public boolean apply(String value) { return StringUtils.isNotBlank(value); } }); for (Map.Entry<String, String> entryToAdd : filteredProperties.entrySet()) { String key = entryToAdd.getKey(); for (String propType : propTypes) { key = StringUtils.remove(key, propType); } key = StringUtils.remove(key, propPrefix); configuration.addMatrixParam(key, entryToAdd.getValue()); } }
From source file:org.jfrog.teamcity.agent.util.PathHelper.java
public static String calculateTargetPath(File file, String relativePath, String targetPattern) { if (file == null) { throw new IllegalArgumentException("Cannot calculate a target path given a null file."); }//from w ww. j a va2s . c om if (relativePath == null) { throw new IllegalArgumentException("Cannot calculate a target path given a null relative path."); } if (StringUtils.isBlank(targetPattern)) { return relativePath; } StringBuilder artifactPathBuilder = new StringBuilder(); String[] targetTokens = targetPattern.split("/"); boolean addedRelativeParent = false; for (int i = 0; i < targetTokens.length; i++) { boolean lastToken = (i == (targetTokens.length - 1)); String targetToken = targetTokens[i]; if ("**".equals(targetToken)) { if (!lastToken) { String relativeParentPath = StringUtils.remove(relativePath, file.getName()); relativeParentPath = StringUtils.removeEnd(relativeParentPath, "/"); artifactPathBuilder.append(relativeParentPath); addedRelativeParent = true; } else { artifactPathBuilder.append(relativePath); } } else if (targetToken.startsWith("*.")) { String newFileName = FilenameUtils.removeExtension(file.getName()) + targetToken.substring(1); artifactPathBuilder.append(newFileName); } else if ("*".equals(targetToken)) { artifactPathBuilder.append(file.getName()); } else { if (StringUtils.isNotBlank(targetToken)) { artifactPathBuilder.append(targetToken); } if (lastToken) { if (artifactPathBuilder.length() > 0) { artifactPathBuilder.append("/"); } if (addedRelativeParent) { artifactPathBuilder.append(file.getName()); } else { artifactPathBuilder.append(relativePath); } } } if (!lastToken) { artifactPathBuilder.append("/"); } } return artifactPathBuilder.toString(); }
From source file:org.jnap.core.persistence.hibernate.DynaQueryBuilder.java
public Criteria build() throws QueryException { Matcher matcher = DYNA_QUERY_PATTERN.matcher(this.dynaQuery); if (!matcher.matches()) { throw new QueryException("The QueryMethod syntax is incorrect. It must start with 'findBy' " + ", findUniqueBy or 'countBy' expression followed by property expressions and operators.", this.dynaQuery); }// w w w .j a v a 2 s .c o m Criteria criteria = this.createCriteria(matcher.group(1).equals("countBy")); String dynaQueryExpression = matcher.group(2); // order by Matcher orderByMatcher = ORDER_BY_PATTERN.matcher(dynaQueryExpression); if (orderByMatcher.find()) { dynaQueryExpression = StringUtils.remove(dynaQueryExpression, orderByMatcher.group()); String orderByProperty = normalizePropertyName(orderByMatcher.group(3)); String orderByDirection = orderByMatcher.group(4); Order orderBy = "Desc".equals(orderByDirection) ? Order.desc(orderByProperty) : Order.asc(orderByProperty); criteria.addOrder(orderBy); } // split properties String[] properties = DYNA_QUERY_OPERATOR_PATTERN.split(dynaQueryExpression); if (properties.length == 0 || properties.length > 2) { throw new QueryException(format( "The QueryMethod syntax is incorrect. Dynamic queries must have " + "at least one property an no more than two (yours has {0}).\nYou can use one of " + "the following logical operators ({1}) and these expression operators ({2})", properties.length, LOGICAL_OPERATOR_AND + ", " + LOGICAL_OPERATOR_OR, StringUtils.join(EXPRESSION_OPERATORS, ", ")), this.dynaQuery); } Matcher logicalOperatorsMatcher = DYNA_QUERY_OPERATOR_PATTERN.matcher(dynaQueryExpression); String logicalOperator = logicalOperatorsMatcher.find() ? logicalOperatorsMatcher.group(1) : LOGICAL_OPERATOR_AND; Junction junction = LOGICAL_OPERATOR_OR.equals(logicalOperator) ? Restrictions.disjunction() : Restrictions.conjunction(); for (String property : properties) { junction.add(this.createCriterion(property)); } criteria.add(junction); return criteria; }
From source file:org.kuali.kfs.gl.batch.CollectorXmlInputFileType.java
/** * Builds the file name using the following construction: All collector files start with gl_idbilltrans_ append the chartorg * from the batch header append the username of the user who is uploading the file then the user supplied indentifier finally * the timestamp/* w w w . j a va2 s.c o m*/ * * @param user who uploaded the file * @param parsedFileContents represents collector batch object * @param userIdentifier user identifier for user who uploaded file * @return String returns file name using the convention mentioned in the description * * @see org.kuali.kfs.sys.batch.BatchInputFileType#getFileName(org.kuali.rice.kim.api.identity.Person, java.lang.Object, * java.lang.String) */ public String getFileName(String principalName, Object parsedFileContents, String userIdentifier) { // this implementation assumes that there is only one batch in the XML file CollectorBatch collectorBatch = ((List<CollectorBatch>) parsedFileContents).get(0); String fileName = "gl_collector_" + collectorBatch.getChartOfAccountsCode() + collectorBatch.getOrganizationCode(); fileName += "_" + 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:org.kuali.kfs.gl.batch.EnterpriseFeederFileSetType.java
/** * Return the file name based on information from user and file user identifier * //www . j a v a 2 s .c o m * @param user Person object representing user who uploaded file * @param fileUserIdentifer String representing user who uploaded file * @return String enterprise feeder formated file name string using information from user and file user identifier * @see org.kuali.kfs.sys.batch.BatchInputFileSetType#getFileName(java.lang.String, org.kuali.rice.kim.api.identity.Person, * java.lang.String) */ public String getFileName(String fileType, String principalName, String fileUserIdentifer, Date creationDate) { DateTimeService dateTimeService = SpringContext.getBean(DateTimeService.class); StringBuilder buf = new StringBuilder(); fileUserIdentifer = StringUtils.deleteWhitespace(fileUserIdentifer); fileUserIdentifer = StringUtils.remove(fileUserIdentifer, FILE_NAME_PART_DELIMITER); buf.append(FILE_NAME_PREFIX).append(FILE_NAME_PART_DELIMITER).append(principalName) .append(FILE_NAME_PART_DELIMITER).append(fileUserIdentifer).append(FILE_NAME_PART_DELIMITER) .append(dateTimeService.toDateTimeStringForFilename(creationDate)) .append(getFileExtension(fileType)); return buf.toString(); }