List of usage examples for org.apache.commons.lang StringUtils chomp
public static String chomp(String str, String separator)
Removes separator
from the end of str
if it's there, otherwise leave it alone.
From source file:com.googlecode.fascinator.portal.process.EmailNotifier.java
public String getCollectionValues(JsonSimple emailConfig, JsonSimple tfPackage, String varField) { String formattedCollectionValues = ""; JSONArray subKeys = emailConfig.getArray("collections", varField, "subKeys"); String tfPackageField = emailConfig.getString("", "collections", varField, "payloadKey"); if (StringUtils.isNotBlank(tfPackageField) && subKeys instanceof JSONArray) { List<JsonObject> jsonList = new StorageDataUtil().getJavaList(tfPackage, tfPackageField); log.debug("Collating collection values for email template..."); JSONArray fieldSeparators = emailConfig.getArray("collections", varField, "fieldSeparators"); String recordSeparator = emailConfig.getString(IOUtils.LINE_SEPARATOR, "collections", varField, "recordSeparator"); String nextDelimiter = " "; for (JsonObject collectionRow : jsonList) { if (fieldSeparators instanceof JSONArray && fieldSeparators.size() > 0) { // if no more delimiters, continue to use the last one specified Object nextFieldSeparator = fieldSeparators.remove(0); if (nextFieldSeparator instanceof String) { nextDelimiter = (String) nextFieldSeparator; } else { log.warn("Unable to retrieve String value from fieldSeparator: " + fieldSeparators.toString()); }//w w w .ja v a 2 s .com } List<String> collectionValuesList = new ArrayList<String>(); for (Object requiredKey : subKeys) { Object rawKeyValue = collectionRow.get(requiredKey); if (rawKeyValue instanceof String) { String keyValue = StringUtils.trim((String) rawKeyValue); if (StringUtils.isNotBlank(keyValue)) { collectionValuesList.add(keyValue); } else if (!isVariableNameHiddenIfEmpty) { collectionValuesList.add("$" + requiredKey); } else { log.info("blank variable name will be hidden: " + keyValue); } } else { log.warn("No string value returned from: " + requiredKey); } } formattedCollectionValues += StringUtils.join(collectionValuesList, nextDelimiter) + recordSeparator; } formattedCollectionValues = StringUtils.chomp(formattedCollectionValues, recordSeparator); log.debug("email formatted collection values: " + formattedCollectionValues); } return formattedCollectionValues; }
From source file:com.google.gdt.eclipse.designer.actions.deploy.DeployModuleAction.java
/** * Creates build.xml file in same folder as module. *//* www .j ava2 s .c o m*/ private void createBuildScript(DeployDialog deployDialog) throws Exception { String moduleId = m_selectedModule.getId(); // IProject project = m_selectedModule.getProject(); IFolder targetFolder = m_selectedModule.getModuleFolder(); // prepare script String script = getScriptTemplate(); // apply template values script = StringUtils.replace(script, "##GWT_HOME##", Utils.getGWTLocation(project)); script = StringUtils.replace(script, "##PROJECT_ROOT##", project.getLocation().toOSString()); script = StringUtils.replace(script, "##MODULE_ID##", moduleId); script = StringUtils.replace(script, "##WAR_NAME##", deployDialog.getWarName()); script = StringUtils.replace(script, "##DEPLOY_DIR##", deployDialog.getServerPath()); script = StringUtils.replace(script, "##COMPILER_STYLE##", deployDialog.getCompilerStyle()); script = StringUtils.replace(script, "##COMPILER_MAX_MEMORY##", deployDialog.getCompilerMaxMemory()); // set class path elements { String classpathElements = ""; String[] classpath = getGWTProjectClasspath(project); for (int i = 0; i < classpath.length; i++) { String element = classpath[i].replace('\\', '/'); classpathElements += "\t\t\t\t<pathelement location=\"" + element + "\" />"; if (i != classpath.length - 1) { classpathElements += "\n"; } } script = StringUtils.replace(script, "##CLASS_PATH_ELEMENTS##", classpathElements); } // set servlets { final StringBuffer buffer = new StringBuffer(); ModuleVisitor.accept(m_selectedModule, new ModuleVisitor() { @Override public void endVisitModule(ModuleElement module) { List<ServletElement> servletElements = module.getServletElements(); for (ServletElement servletElement : servletElements) { String servletName = servletElement.getClassName(); { buffer.append("\t<servlet>\n"); buffer.append("\t\t<servlet-name>" + servletName + "</servlet-name>\n"); buffer.append( "\t\t<servlet-class>" + servletElement.getClassName() + "</servlet-class>\n"); buffer.append("\t</servlet>\n"); } { buffer.append("\t<servlet-mapping>\n"); buffer.append("\t\t<servlet-name>" + servletName + "</servlet-name>\n"); buffer.append("\t\t<url-pattern>" + servletElement.getPath() + "</url-pattern>\n"); buffer.append("\t</servlet-mapping>\n"); } } } }); // apply sevlets script = StringUtils.replace(script, "##SERVLETS##", buffer.toString()); } // create/copy jar's { String targetModulePath = WebUtils.getWebFolderName(project); String jarsScript = prepareJars(project, targetModulePath, true); jarsScript = StringUtils.chomp(jarsScript, "\n"); script = StringUtils.replace(script, "<!--##PROJECT_AND_REQUIRED_JARS##-->", jarsScript); } // create build.xml IFile buildFile = targetFolder.getFile("build.xml"); ByteArrayInputStream source = new ByteArrayInputStream(script.getBytes()); if (buildFile.exists()) { buildFile.setContents(source, true, true, null); } else { buildFile.create(source, true, null); } }
From source file:com.linkedin.pinot.broker.broker.helix.HelixBrokerStarter.java
private String getZkAddressForBroker(String zkServers, String helixClusterName) { List tokens = new ArrayList<String>(); for (String token : zkServers.split(",")) { tokens.add(StringUtil.join("/", StringUtils.chomp(token, "/"), helixClusterName, PROPERTY_STORE)); }//from w w w. j a va2 s. c o m return StringUtils.join(tokens, ","); }
From source file:com.google.gdt.eclipse.designer.core.model.widgets.CoordinatesTest.java
/** * For string like <code>"left 10px, top 20 px"</code> returns * //from w w w.ja v a 2s .co m * <pre> * border-left 10px; * border-top 20px; * </pre> */ private static String getSidesStyle(String stylesString, String styleName) { String styles = ""; String[] stylesParts = StringUtils.split(stylesString, ','); for (String stylePart : stylesParts) { stylePart = stylePart.trim(); styles += "\t"; if (stylePart.startsWith("top") || stylePart.startsWith("right") || stylePart.startsWith("bottom") || stylePart.startsWith("left")) { String side = StringUtils.substringBefore(stylePart, " "); String withoutSide = StringUtils.substringAfter(stylePart, " "); styles += styleName + "-" + side + ": " + withoutSide; } else { styles += styleName + ": " + stylePart; } styles += ";\n"; } styles = StringUtils.chomp(styles, "\n"); return styles; }
From source file:com.egt.ejb.toolkit.ToolKitUtils.java
public static String getCodigoFuncionAlterno(String codigoFuncion, String codigoDominio) { String alterno = StringUtils.trimToEmpty(codigoFuncion).toLowerCase(); String dominio = StringUtils.trimToEmpty(codigoDominio).toLowerCase(); alterno = StringUtils.removeStart(alterno, dominio); alterno = StringUtils.chomp(alterno, dominio); alterno = alterno.replace("_" + dominio + "_", "_"); alterno = StringUtils.removeStart(alterno, "_"); alterno = StringUtils.chomp(alterno, "_"); alterno = dominio + "_" + alterno; return alterno; }
From source file:com.egt.ejb.toolkit.ToolKitUtils.java
public static String getCodigoArchivoInforme(String codigoFuncion, String codigoDominio) { String alterno = StringUtils.trimToEmpty(codigoFuncion).toLowerCase(); String dominio = StringUtils.trimToEmpty(codigoDominio).toLowerCase(); alterno = StringUtils.removeStart(alterno, "emitir_"); alterno = StringUtils.removeStart(alterno, "informar_"); alterno = StringUtils.removeStart(alterno, "exportar_"); alterno = StringUtils.removeStart(alterno, dominio); alterno = StringUtils.chomp(alterno, dominio); alterno = alterno.replace("_" + dominio + "_", "_"); alterno = StringUtils.removeStart(alterno, "_"); alterno = StringUtils.chomp(alterno, "_"); alterno = dominio + "_" + alterno; return alterno; }
From source file:com.ning.metrics.collector.util.F5PoolMemberControl.java
private String toString(CommonIPPortDefinition[][] membersDefinitions) { String res = ""; for (CommonIPPortDefinition[] memberDefinitions : membersDefinitions) { for (CommonIPPortDefinition memberDefinition : memberDefinitions) { res = String.format("%s%s,", res, toString(memberDefinition)); }//from www. j a v a2s . c o m } return StringUtils.chomp(res, ","); }
From source file:edu.ku.brc.specify.config.LatLonConverter.java
public static BigDecimal convertDDDDStrToDDDDBD(final String str) { String withoutDegSign = StringUtils.chomp(str, ""); //above doesn't always work for Windows/Mac so try again... withoutDegSign = StringUtils.chomp(withoutDegSign, ""); //apparently need to do this on mac withoutDegSign = StringUtils.remove(withoutDegSign, UNICODE_DEGREE); String val = StringUtils.replace(StringUtils.replace(withoutDegSign, decimalSep, ""), "-", ""); return StringUtils.isNumeric(val) ? parseDoubleToBigDecimal(withoutDegSign) : null; }
From source file:edu.ku.brc.util.LatLonConverter.java
/** * Converts Decmal Degrees to BigDecimal. * @param bd the DigDecimal to be converted. * @return a BigDecimal/*from w ww . j a v a 2 s. c o m*/ */ public static BigDecimal convertDDDDStrToDDDDBD(final String str) { String withoutDegSign = StringUtils.chomp(str, ""); //above doesn't always work for Windows/Mac so try again... withoutDegSign = StringUtils.chomp(withoutDegSign, ""); //apparently need to do this on mac withoutDegSign = StringUtils.remove(withoutDegSign, UNICODE_DEGREE); String val = StringUtils.replace(StringUtils.replace(withoutDegSign, decimalSep, ""), "-", ""); return StringUtils.isNumeric(val) ? UIHelper.parseDoubleToBigDecimal(withoutDegSign) : null; }
From source file:net.unit8.maven.plugins.handlebars.PrecompileMojo.java
private File getOutputFile(File directory) throws IOException { if (preserveHierarchy) { String relativePath = sourceDirectory.toURI().relativize(directory.toURI()).getPath(); File outputBaseDir = new File(outputDirectory, relativePath); if (!outputBaseDir.exists()) { FileUtils.forceMkdir(outputBaseDir); }//from ww w. ja v a 2s. c o m return new File(outputBaseDir, directory.getName() + ".js"); } else { String relativePath = sourceDirectory.toURI().relativize(directory.toURI()).getPath(); String name = StringUtils.chomp(relativePath, "/").replace('/', '-'); if (StringUtils.isEmpty(name)) name = "index"; return new File(outputDirectory, name + ".js"); } }