List of usage examples for org.apache.commons.lang3 StringUtils stripEnd
public static String stripEnd(final String str, final String stripChars)
Strips any of a set of characters from the end of a String.
A null input String returns null .
From source file:info.magnolia.security.app.dialog.action.SaveRoleDialogAction.java
private String stripWildcardsFromPath(String path) { path = StringUtils.stripEnd(path, "/*"); if (StringUtils.isBlank(path)) { path = "/"; }//from ww w . j a v a2 s.c o m return path; }
From source file:com.adobe.cq.dialogconversion.impl.rules.NodeBasedRewriteRule.java
/** * Replaces the value of a mapped property with a value from the original tree. * * @param root the root node of the original tree * @param property the (potentially) mapped property in the replacement copy tree * @return the mapped property if there was a successful mapping, null otherwise *//*w w w . j a va2 s . c om*/ private Property mapProperty(Node root, Property property) throws RepositoryException { if (property.getType() != PropertyType.STRING) { // a mapped property must be of type string return null; } // array containing the expressions: ${<path>} Value[] values; if (property.isMultiple()) { values = property.getValues(); } else { values = new Value[1]; values[0] = property.getValue(); } boolean deleteProperty = false; for (Value value : values) { Matcher matcher = MAPPED_PATTERN.matcher(value.getString()); if (matcher.matches()) { // this is a mapped property, we will delete it if the mapped destination // property doesn't exist deleteProperty = true; String path = matcher.group(2); // unwrap quoted property paths path = StringUtils.removeStart(StringUtils.stripEnd(path, "\'"), "\'"); if (root.hasProperty(path)) { // replace property by mapped value in the original tree Property originalProperty = root.getProperty(path); String name = property.getName(); Node parent = property.getParent(); property.remove(); Property newProperty = JcrUtil.copy(originalProperty, parent, name); // negate boolean properties if negation character has been set String negate = matcher.group(1); if ("!".equals(negate) && originalProperty.getType() == PropertyType.BOOLEAN) { newProperty.setValue(!newProperty.getBoolean()); } // the mapping was successful deleteProperty = false; break; } else { String defaultValue = matcher.group(4); if (defaultValue != null) { if (property.isMultiple()) { // the property is multiple in the replacement, // recreate it so we can set the property to the default String name = property.getName(); Node parent = property.getParent(); property.remove(); parent.setProperty(name, defaultValue); } else { property.setValue(defaultValue); } deleteProperty = false; break; } } } } if (deleteProperty) { // mapped destination does not exist, we don't include the property in replacement tree property.remove(); return null; } return property; }
From source file:com.google.dart.java2dart.engine.MainAnalysisServer.java
/** * Removes trailing spaces from the given Dart source. *//*from w w w. java 2 s . c o m*/ private static String removeTrailingWhitespaces(String source) { String[] lines = StringUtils.splitPreserveAllTokens(source, '\n'); for (int i = 0; i < lines.length; i++) { lines[i] = StringUtils.stripEnd(lines[i], null); } return StringUtils.join(lines, "\n"); }
From source file:de.aschoerk.javaconv.RustDumpVisitor.java
@Override public void visit(final FieldAccessExpr n, final Object arg) { printJavaComment(n.getComment(), arg); int mark = printer.push(); n.getScope().accept(this, arg); String scope = printer.getMark(mark); printer.drop();/*from w w w . j a v a 2 s . c o m*/ int i = StringUtils.lastIndexOfAny(StringUtils.stripEnd(scope, " "), "\n", "\t", " ", "."); String accessed = i <= 0 ? scope : scope.substring(i + 1); if (Character.isUpperCase(accessed.charAt(0)) && accessed.length() > 1 && Character.isLowerCase(accessed.charAt(1))) { printer.print("::"); } else { printer.print("."); } printer.print(replaceLengthAtEnd(n.getField())); }
From source file:com.sonicle.webtop.mail.Service.java
private void outputFolders(MailAccount account, Folder parent, Folder folders[], boolean level1, boolean favorites, ArrayList<JsFolder> jsFolders) throws Exception { boolean hasPrefix = !StringUtils.isBlank(account.getFolderPrefix()); String prefixMatch = StringUtils.stripEnd(account.getFolderPrefix(), account.getFolderSeparator() + ""); ArrayList<Folder> postPrefixList = new ArrayList<Folder>(); ArrayList<Folder> afolders; if (!favorites) afolders = sortFolders(account, folders); else {/*ww w . j a v a 2 s. c o m*/ afolders = new ArrayList<Folder>(); for (Folder f : folders) { if (f != null) { afolders.add(f); } } } //If Shared Folders, sort on description if (parent != null && account.isSharedFolder(parent.getFullName())) { if (!account.hasDifferentDefaultFolder() || !account.isDefaultFolder(parent.getFullName())) { String ss = mprofile.getSharedSort(); if (ss.equals("D")) { Collections.sort(afolders, account.getDescriptionFolderComparator()); } else if (ss.equals("U")) { Collections.sort(afolders, account.getWebTopUserFolderComparator()); } } } //If at level 1, look for the prefix folder in the list Folder prefixFolder = null; if (level1) { for (Folder f : afolders) { if (f.getFullName().equals(prefixMatch)) { prefixFolder = f; break; } } //remove it and use it later if (prefixFolder != null) afolders.remove(prefixFolder); } //now scan and output folders for (Folder f : afolders) { String foldername = f.getFullName(); //in case of moved root, check not to duplicate root elsewhere if (account.hasDifferentDefaultFolder()) { if (account.isDovecot()) { if (account.isDefaultFolder(foldername)) continue; } else { //skip default folder under shared if (account.isDefaultFolder(foldername) && parent != null && !parent.getFullName().equals(foldername)) continue; } } //skip hidden if (us.isFolderHidden(foldername)) continue; FolderCache mc = account.getFolderCache(foldername); if (mc == null && parent != null) { //continue; //System.out.println("foldername="+foldername+" parentname="+parent.getFullName()); FolderCache fcparent = account.getFolderCache(parent.getFullName()); mc = account.addSingleFoldersCache(fcparent, f); } //String shortfoldername=getShortFolderName(foldername); IMAPFolder imapf = (IMAPFolder) f; String atts[] = imapf.getAttributes(); boolean leaf = true; boolean noinferiors = false; if (account.hasDifferentDefaultFolder() && account.isDefaultFolder(foldername)) { } else if (!favorites) { for (String att : atts) { if (att.equals("\\HasChildren")) { if (!level1 || !foldername.equals(account.getInboxFolderFullName())) leaf = false; } else if (att.equals("\\Noinferiors")) noinferiors = true; } if (noinferiors) leaf = true; } //boolean leaf=isLeaf((IMAPFolder)f); //logger.debug("folder {} isleaf={}, level1={}",f.getFullName(),leaf,level1); //if (leaf) { // if (!level1 || !foldername.equals("INBOX")) leaf=false; //} if (!favorites && prefixFolder != null && !foldername.equals("INBOX") && !foldername.startsWith(account.getFolderPrefix())) { postPrefixList.add(f); } else { /* String iconCls = "wtmail-icon-imap-folder-xs"; int unread = 0; boolean hasUnread = false; boolean nounread = false; if (mc.isSharedFolder()) { iconCls = "wtmail-icon-shared-folder-xs"; nounread = true; } else if (mc.isInbox()) { iconCls = "wtmail-icon-inbox-folder-xs"; } else if (mc.isSent()) { iconCls = "wtmail-icon-sent-folder-xs"; nounread = true; } else if (mc.isDrafts()) { iconCls = "wtmail-icon-drafts-folder-xs"; nounread = true; } else if (mc.isTrash()) { iconCls = "wtmail-icon-trash-folder-xs"; nounread = true; } else if (mc.isArchive()) { iconCls = "wtmail-icon-archive-folder-xs"; nounread = true; } else if (mc.isSpam()) { iconCls = "wtmail-icon-spam-folder-xs"; nounread = true; } else if (mc.isDms()) { iconCls = "wtmail-icon-dms-folder-xs"; } else if (mc.isSharedInbox()) { iconCls = "wtmail-icon-inbox-folder-xs"; } if (!nounread) { unread = mc.getUnreadMessagesCount(); hasUnread = mc.hasUnreadChildren(); } String text = mc.getDescription(); String group = us.getMessageListGroup(foldername); if (group == null) { group = ""; } String ss = "{id:'" + StringEscapeUtils.escapeEcmaScript(foldername) + "',text:'" + StringEscapeUtils.escapeEcmaScript(description) + "',folder:'" + StringEscapeUtils.escapeEcmaScript(text) + "',leaf:" + leaf + ",iconCls: '" + iconCls + "',unread:" + unread + ",hasUnread:" + hasUnread + ",group: '"+group+"'"; boolean isSharedToSomeone=false; try { isSharedToSomeone=mc.isSharedToSomeone(); } catch(Exception exc) { } if (isSharedToSomeone) ss+=",isSharedToSomeone: true"; if (mc.isSharedFolder()) ss+=",isSharedRoot: true"; if (account.isUnderSharedFolder(foldername)) ss+=",isUnderShared: true"; if (mc.isInbox()) { ss += ",isInbox: true"; } if (mc.isSent()) { ss += ",isSent: true"; } if (account.isUnderSentFolder(mc.getFolderName())) { ss += ",isUnderSent: true"; } if (mc.isDrafts()) { ss += ",isDrafts: true"; } if (mc.isTrash()) { ss += ",isTrash: true"; } if (mc.isArchive()) { ss += ",isArchive: true"; } if (mc.isSpam()) { ss += ",isSpam: true"; } if (mc.isScanForcedOff()) { ss += ", scanOff: true"; } else if (mc.isScanForcedOn()) { ss += ", scanOn: true"; } else if (mc.isScanEnabled()) { ss += ", scanEnabled: true"; } boolean canRename=true; if (mc.isInbox() || mc.isSpecial() || mc.isSharedFolder() || (mc.getParent()!=null && mc.getParent().isSharedFolder())) canRename=false; ss += ", canRename: "+canRename; ss += ", account: '"+account.getId()+"'"; ss += "},"; out.print(ss); */ jsFolders.add(createJsFolder(mc, leaf)); } } //if we have a prefix folder output remaining folders if (!favorites && prefixFolder != null) { for (Folder ff : prefixFolder.list()) postPrefixList.add(ff); ArrayList<Folder> sortedFolders = sortFolders(account, postPrefixList.toArray(new Folder[postPrefixList.size()])); outputFolders(account, prefixFolder, sortedFolders.toArray(new Folder[sortedFolders.size()]), false, false, jsFolders); } }
From source file:net.sourceforge.pmd.docs.RuleDocGenerator.java
private static String stripIndentation(String description) { if (description == null || description.isEmpty()) { return ""; }/*from w w w . j a v a 2 s. c o m*/ String stripped = StringUtils.stripStart(description, "\n\r"); stripped = StringUtils.stripEnd(stripped, "\n\r "); int indentation = 0; int strLen = stripped.length(); while (Character.isWhitespace(stripped.charAt(indentation)) && indentation < strLen) { indentation++; } String[] lines = stripped.split("\\n"); String prefix = StringUtils.repeat(' ', indentation); StringBuilder result = new StringBuilder(stripped.length()); if (StringUtils.isNotEmpty(prefix)) { for (int i = 0; i < lines.length; i++) { String line = lines[i]; if (i > 0) { result.append(StringUtils.LF); } result.append(StringUtils.removeStart(line, prefix)); } } else { result.append(stripped); } return result.toString(); }
From source file:org.apache.falcon.entity.FeedHelper.java
public static String normalizePartitionExpression(String part1, String part2) { String partExp = StringUtils.stripToEmpty(part1) + "/" + StringUtils.stripToEmpty(part2); partExp = partExp.replaceAll("//+", "/"); partExp = StringUtils.stripStart(partExp, "/"); partExp = StringUtils.stripEnd(partExp, "/"); return partExp; }
From source file:org.apache.falcon.oozie.feed.FeedReplicationCoordinatorBuilder.java
private String getPathsWithPartitions(Cluster srcCluster, Cluster trgCluster) throws FalconException { String srcPart = FeedHelper//from w w w. j a v a2 s.co m .normalizePartitionExpression(FeedHelper.getCluster(entity, srcCluster.getName()).getPartition()); srcPart = FeedHelper.evaluateClusterExp(srcCluster, srcPart); String targetPart = FeedHelper .normalizePartitionExpression(FeedHelper.getCluster(entity, trgCluster.getName()).getPartition()); targetPart = FeedHelper.evaluateClusterExp(trgCluster, targetPart); StringBuilder pathsWithPartitions = new StringBuilder(); pathsWithPartitions.append("${coord:dataIn('input')}/") .append(FeedHelper.normalizePartitionExpression(srcPart, targetPart)); String parts = pathsWithPartitions.toString().replaceAll("//+", "/"); parts = StringUtils.stripEnd(parts, "/"); return parts; }
From source file:org.apache.falcon.oozie.feed.OozieFeedWorkflowBuilderTest.java
private String getPathsWithPartitions(Cluster sourceCluster, Cluster targetCluster, Feed aFeed) throws FalconException { String srcPart = FeedHelper// ww w . j a va2 s . co m .normalizePartitionExpression(FeedHelper.getCluster(aFeed, sourceCluster.getName()).getPartition()); srcPart = FeedHelper.evaluateClusterExp(sourceCluster, srcPart); String targetPart = FeedHelper .normalizePartitionExpression(FeedHelper.getCluster(aFeed, targetCluster.getName()).getPartition()); targetPart = FeedHelper.evaluateClusterExp(targetCluster, targetPart); String pathsWithPartitions = "${coord:dataIn('input')}/" + FeedHelper.normalizePartitionExpression(srcPart, targetPart); String parts = pathsWithPartitions.replaceAll("//+", "/"); parts = StringUtils.stripEnd(parts, "/"); return parts; }
From source file:org.apache.streams.util.schema.SchemaStoreImpl.java
@Override public Schema create(Schema parent, String path) { if (path.equals("#")) { return parent; } else {/* w ww . j a v a2s . c o m*/ path = StringUtils.stripEnd(path, "#?&/"); URI id = (parent != null && parent.getId() != null) ? parent.getId().resolve(path) : URI.create(path); if (this.selfReferenceWithoutParentFile(parent, path)) { this.schemas.put(id, new Schema(id, this.fragmentResolver.resolve(parent.getParentContent(), path), parent, false)); return this.schemas.get(id); } else { return this.create(id); } } }