List of usage examples for org.apache.commons.lang3 StringUtils left
public static String left(final String str, final int len)
Gets the leftmost len characters of a String.
If len characters are not available, or the String is null , the String will be returned without an exception.
From source file:com.sql.EMail.java
/** * Inserts email message into email table. * * @param eml EmailMessageModel/*ww w. ja va2s . com*/ * @return Integer - generated key of the email */ public static int InsertEmail(EmailMessageModel eml) { Connection conn = null; PreparedStatement ps = null; try { conn = DBConnection.connectToDB(); String sql = "INSERT INTO EMail (" + "section, " + "emailFrom, " + "emailTo, " + "emailSubject, " + "sentDate, " + "receivedDate, " + "emailCC, " + "emailBCC, " + "emailBody, " + "emailBodyFileName, " + "readyToFile " + ") VALUES (" + "?, " //1 + "?, " //2 + "?, " //3 + "?, " //4 + "?, " //5 + "?, " //6 + "?, " //7 + "?, " //8 + "?, " //9 + "?, " //10 + "0)"; // Ready to File False ps = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); ps.setString(1, StringUtils.left(eml.getSection(), 4)); ps.setString(2, StringUtils.left(eml.getEmailFrom(), 200)); ps.setString(3, eml.getEmailTo()); ps.setString(4, eml.getEmailSubject()); ps.setTimestamp(5, eml.getSentDate()); ps.setTimestamp(6, eml.getReceivedDate()); ps.setString(7, eml.getEmailCC()); ps.setString(8, eml.getEmailBCC()); ps.setString(9, eml.getEmailBody()); ps.setString(10, eml.getEmailBodyFileName()); ps.executeUpdate(); ResultSet newRow = ps.getGeneratedKeys(); if (newRow.next()) { return newRow.getInt(1); } } catch (SQLException ex) { ExceptionHandler.Handle(ex); } finally { DbUtils.closeQuietly(conn); DbUtils.closeQuietly(ps); } return 0; }
From source file:com.thoughtworks.go.server.util.WebUtils.java
public String limit(String code, int limit) { if (code == null) { return ""; }//from w w w. java2 s . c om String lefted = StringUtils.left(code, limit); if (code.length() > limit) { lefted = lefted + "..."; } return lefted; }
From source file:com.sql.Audit.java
/** * Adds an entry to the audit table/*from w w w . j a va2s . c o m*/ * @param action performed action to be stored */ public static void addAuditEntry(String action) { Connection conn = null; PreparedStatement ps = null; try { conn = DBConnection.connectToDB(); String sql = "INSERT INTO Audit VALUES" + "(?,?,?)"; ps = conn.prepareStatement(sql); ps.setTimestamp(1, new Timestamp(System.currentTimeMillis())); ps.setInt(2, 0); ps.setString(3, action == null ? "MISSING ACTION" : StringUtils.left(action, 255)); ps.executeUpdate(); } catch (SQLException ex) { if (ex.getCause() instanceof SQLServerException) { addAuditEntry(action); } } finally { DbUtils.closeQuietly(conn); DbUtils.closeQuietly(ps); } }
From source file:kenh.expl.functions.Left.java
public String process(String str, int len) { return StringUtils.left(str, len); }
From source file:com.francetelecom.clara.cloud.techmodel.cf.services.userprovided.ServiceNameBuilder.java
public String build() { return StringUtils.left(value, MAX_NAME_LENTGH); }
From source file:com.github.steveash.jg2p.seq.LeadingTrailingFeature.java
@Override public Instance pipe(Instance carrier) { TokenSequence ts = (TokenSequence) carrier.getData(); if (ts.size() >= 2) { Token first = ts.get(0);//from w w w . j a v a2s . c om Token last = ts.get(ts.size() - 1); String firstShape = TokenSeqUtil.convertShape(StringUtils.left(first.getText(), 1)); String lastShape = TokenSeqUtil.convertShape(StringUtils.right(last.getText(), 1)); first.setFeatureValue("FIRST", 1.0); if (isNotBlank(firstShape)) { first.setFeatureValue("FIRST-" + firstShape, 1.0); } last.setFeatureValue("LAST", 1.0); if (isNotBlank(lastShape)) { last.setFeatureValue("LAST-" + lastShape, 1.0); } } return carrier; }
From source file:com.github.steveash.jg2p.seq.SurroundingTokenFeature.java
@Override public Instance pipe(Instance carrier) { TokenSequence ts = (TokenSequence) carrier.getData(); for (int i = 1; i < ts.size() - 1; i++) { Token a = ts.get(i - 1);/*from ww w . j a v a2s . c om*/ Token t = ts.get(i); Token z = ts.get(i + 1); String before = StringUtils.right(a.getText(), 1); String after = StringUtils.left(z.getText(), 1); if (isNotBlank(before) && isNotBlank(after)) { String f = prefix + xform(before) + "^" + xform(t.getText()) + "^" + xform(after); t.setFeatureValue(f, 1.0); } } return carrier; }
From source file:com.francetelecom.clara.cloud.commons.FqdnHelper.java
/** * Sanitize a subpart of the uri so that it does not contain separators we use in domains. * e.g. when trying to construct "c-{conflictid}-{webGuiLabel}-{envLabel}-{appRelease}{appVersion}-{paasInstance}.{cfSubDomain]" * this method can be called on each individual part such as "webGuiLabel" so that they don't use * dots or dashes and get truncated to the appropriate length by trimming extra chars at beginning. * @param uriPart a part of the fqdn (e.g. "webguilabel") *///from ww w . j ava2 s. c o m public static String sanitizeAndTruncatePart(String uriPart, int maxLength) { String sanitizedString = FILTERED_CHARS_IN_NAMES.removeFrom(uriPart); sanitizedString = Ascii.toLowerCase(sanitizedString); sanitizedString = InternetDomainNameCleaner.getFixedPart(sanitizedString, false); if (sanitizedString.length() > maxLength) { sanitizedString = StringUtils.left(sanitizedString, maxLength); } sanitizedString = InternetDomainNameCleaner.getFixedPart(sanitizedString, false); return sanitizedString; }
From source file:com.sangupta.shire.site.SiteBackup.java
/** * Method to restore the _site.backup folder that we took in this very session. *///from ww w. j ava2 s.c om private void restoreSiteBackup() { if (backupFolder != null) { // build up the name of the original folder String path = backupFolder.getAbsolutePath(); path = StringUtils.left(path, path.length() - BACKUP_FOLDER_EXTENSION.length()); File original = new File(path); // delete the currently made site folder if (original.exists()) { FileUtils.deleteQuietly(original); } // restore the backup try { FileUtils.moveDirectory(backupFolder, original); } catch (IOException e) { System.out.println("Unable to restore the original site backup."); e.printStackTrace(); } } }
From source file:com.sonicle.webtop.core.bol.OSysLog.java
@Override public void setSwName(String swName) { super.setSwName(StringUtils.left(swName, 50)); }