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:org.kalypso.commons.runtime.LogStatusWrapper.java
/** * @return an IStatus representation of this result. *///from w ww. j av a 2 s . c o m public IStatus toStatus() { if (!hasMessages()) return Status.OK_STATUS; // the ErrorDialog cannot show a message which is too long: the dialog's // height would be bigger than the user's monitor. That's why we truncate // the summary string here. If the user wants to see more, he can have // a look at the log file using the 'details' button in the ErrorDialog final String truncatedSummary = StringUtils.left(m_summary, 512); // '\r' verschwinden lassen, da sonst der Status-Dialog zuviele Umbrche generiert final String msg = truncatedSummary.replace('\r', ' ') + "...\n" //$NON-NLS-1$ + Messages.getString("org.kalypso.commons.runtime.LogStatusWrapper.5") //$NON-NLS-1$ + m_logFile.toString(); return new LogStatus(IStatus.WARNING, KalypsoCommonsPlugin.getID(), 0, msg, null, m_logFile, m_charsetName); }
From source file:org.kawanfw.commons.api.server.DefaultCommonsConfigurator.java
/** * The default algorithm to use for computing token * /* w w w. j av a2 s.co m*/ * @param username * the client side username * @param secretForAuthToken * the secret to add * @return <code>SHA-1(username + {@link #addSecretForAuthToken()})</code> * first 20 hexadecimal characters. * * @throws Exception if any Exception occurs */ public static String defaultComputeAuthToken(String username, String secretForAuthToken) throws Exception { // Add more secret info very hard to find for an external hacker StringBuilder tokenBuilder = new StringBuilder(); tokenBuilder.append(username); if (secretForAuthToken != null) { tokenBuilder.append(secretForAuthToken); } Sha1 hashcode = new Sha1(); String token = hashcode.getHexHash((tokenBuilder.toString()).getBytes()); token = StringUtils.left(token, 20); return token; }
From source file:org.kawanfw.file.api.client.RemoteSession.java
/** * Creates an Awake FILE session with a proxy and protocol parameters. * //from w ww . ja v a 2s . c om * @param url * the URL of the path to the {@code ServerFileManager} Servlet * @param username * the username for authentication on the Awake Server (may be * null for <code>call()</code> * @param password * the user password for authentication on the Awake Server (may * be null) * @param proxy * the proxy to use, may be null for direct access * @param passwordAuthentication * the proxy credentials, null if no proxy or if the proxy does * not require authentication * @param sessionParameters * the session parameters to use (may be null) * * @throws MalformedURLException * if the url is malformed * @throws UnknownHostException * if host URL (http://www.acme.org) does not exists or no * Internet Connection. * @throws ConnectException * if the Host is correct but the {@code ServerFileManager} * Servlet is not reachable * (http://www.acme.org/ServerFileManager) and access failed * with a status != OK (200). (If the host is incorrect, or is * impossible to connect to - Tomcat down - the * {@code ConnectException} will be the sub exception * {@code HttpHostConnectException}.) * @throws SocketException * if network failure during transmission * @throws InvalidLoginException * the username or password is invalid * @throws SecurityException * Scheme is required to be https (SSL/TLS) * @throws RemoteException * an exception has been thrown on the server side. This traps * an Awake product failure and should not happen. * @throws IOException * for all other IO / Network / System Error */ public RemoteSession(String url, String username, char[] password, Proxy proxy, PasswordAuthentication passwordAuthentication, SessionParameters sessionParameters) throws MalformedURLException, UnknownHostException, ConnectException, SocketException, InvalidLoginException, RemoteException, SecurityException, IOException { if (url == null) { throw new MalformedURLException("url is null!"); } @SuppressWarnings("unused") URL asUrl = new URL(url); // Try to raise a MalformedURLException; this.username = username; this.url = url; this.proxy = proxy; this.passwordAuthentication = passwordAuthentication; this.sessionParameters = sessionParameters; // username & password may be null: for call() if (username == null) { return; } // Launch the Servlet httpTransfer = HttpTransferUtil.HttpTransferFactory(url, proxy, passwordAuthentication, sessionParameters); // TestReload if SSL required by host if (this.url.toLowerCase().startsWith("http://") && isForceHttps()) { throw new SecurityException( Tag.PRODUCT_SECURITY + " Remote Host requires a SSL url that starts with \"https\" scheme"); } String passwordStr = new String(password); // Prepare the request parameters List<SimpleNameValuePair> requestParams = new Vector<SimpleNameValuePair>(); requestParams.add(new SimpleNameValuePair(Parameter.TEST_CRYPTO, Parameter.TEST_CRYPTO)); requestParams.add(new SimpleNameValuePair(Parameter.ACTION, Action.LOGIN_ACTION)); requestParams.add(new SimpleNameValuePair(Parameter.USERNAME, username)); requestParams.add(new SimpleNameValuePair(Parameter.PASSWORD, passwordStr)); httpTransfer.send(requestParams); // If everything is OK, we have in our protocol a response that // 1) starts with "OK". 2) Is followed by the Authentication Token // else: response starts with "INVALID_LOGIN_OR_PASSWORD". String receive = httpTransfer.recv(); debug("receive: " + receive); if (receive.startsWith(ReturnCode.INVALID_LOGIN_OR_PASSWORD)) { throw new InvalidLoginException("Invalid username or password."); } else if (receive.startsWith(ReturnCode.OK)) { // OK! We are logged in & and correctly authenticated // Keep in static memory the Authentication Token for next api // commands (First 20 chars) String theToken = receive.substring(ReturnCode.OK.length() + 1); authenticationToken = StringUtils.left(theToken, Parameter.TOKEN_LEFT_SIZE); } else { this.username = null; // Should never happen throw new InvalidLoginException(Tag.PRODUCT_PRODUCT_FAIL + " Please contact support."); } }
From source file:org.noroomattheinn.utils.MailGun.java
public boolean send(String to, String message) { final int SubjectLength = 30; String subject = StringUtils.left(message, SubjectLength); if (message.length() > SubjectLength) { subject = subject + "..."; }//from w w w . j a va 2 s . com return send(to, subject, message); }
From source file:org.openestate.io.idx.IdxFormat.java
public static String printString(String value, int maxLength) { value = StringUtils.trimToNull(value); if (maxLength < 1) return value; else if (maxLength < 4) return StringUtils.left(value, maxLength); else/* ww w.j a v a 2 s .c o m*/ return StringUtils.abbreviate(value, maxLength); }
From source file:org.opensingular.flow.core.ProcessInstance.java
/** * Altera a descrio desta instncia de processo. * <p>//w w w. j a v a 2s. c om * A descrio ser truncada para um tamanho mximo de 250 caracteres. * </p> * * @param descricao a nova descrio. */ public final void setDescription(String descricao) { getInternalEntity().setDescription(StringUtils.left(descricao, 250)); }
From source file:org.pepstock.jem.node.JobLogManager.java
/** * Prints steps information after the end of execution of each step. * /*from w w w . java 2 s .c om*/ * @param job job instance * @param step step ended */ public static void printStepResult(Job job, Step step) { // JOBNAME STEPNAME RC CPU (ms) I/O (counts) MEMORY (mb) " // 1234567890123456 1234567890123456 1234 1234567890 1234567890123456 // 1234567890123456 // Sigar sigar = new Sigar(); SigarProxy proxy = SigarProxyCache.newInstance(sigar, 0); StringBuilder sb = new StringBuilder(); if (step == null) { sb.append(StringUtils.rightPad("[init]", 24)); sb.append(' ').append(StringUtils.rightPad("-", 4)); } else { // if name of step more than 24 chars // cut the name adding "..." as to be continued if (step.getName().length() > 24) { sb.append(StringUtils.rightPad(StringUtils.left(step.getName(), 21), 24, ".")); } else { sb.append(StringUtils.rightPad(step.getName(), 24)); } sb.append(' ').append(StringUtils.rightPad(String.valueOf(step.getReturnCode()), 4)); } // parse process id because the form is pid@hostname String pid = job.getProcessId(); String id = pid.substring(0, pid.indexOf('@')); // extract, using SIGAR, CPU consumed by step, N/A otherwise try { // calculate cpu used on the step. // Sigar gives total amount of cpu of process so a difference with // previous one is mandatory long cpu = proxy.getProcCpu(id).getTotal() - PREVIOUS_CPU; sb.append(' ').append(StringUtils.rightPad(String.valueOf(cpu), 10)); // saved for next step PREVIOUS_CPU = cpu; } catch (SigarException e) { // debug LogAppl.getInstance().debug(e.getMessage(), e); sb.append(' ').append(StringUtils.rightPad("N/A", 10)); } // extract, using SIGAR, memory currently used by step, N/A otherwise try { sb.append(' ') .append(StringUtils.rightPad(String.valueOf(proxy.getProcMem(id).getResident() / 1024), 10)); } catch (SigarException e) { // debug LogAppl.getInstance().debug(e.getMessage(), e); sb.append(' ').append(StringUtils.rightPad("N/A", 10)); } Main.getOutputSystem().writeJobLog(job, sb.toString()); sigar.close(); SigarProxyCache.clear(proxy); }
From source file:org.sakaiproject.gradebookng.business.LetterGradeComparator.java
@Override public int compare(final String o1, final String o2) { if (o1.toLowerCase().charAt(0) == o2.toLowerCase().charAt(0)) { // only take the first 2 chars, to cater for GradePointsMapping as well final String s1 = StringUtils.trim(StringUtils.left(o1, 2)); final String s2 = StringUtils.trim(StringUtils.left(o2, 2)); if (s1.length() == 2 && s2.length() == 2) { if (s1.charAt(1) == '+') { return -1; // SAK-30094 } else { return 1; }/*from w w w . j a va2 s . co m*/ } if (s1.length() == 1 && s2.length() == 2) { if (o2.charAt(1) == '+') { return 1; // SAK-30094 } else { return -1; } } if (s1.length() == 2 && s2.length() == 1) { if (s1.charAt(1) == '+') { return -1; // SAK-30094 } else { return 1; } } return 0; } else { return o1.toLowerCase().compareTo(o2.toLowerCase()); } }
From source file:org.springframework.cassandra.core.cql.generator.AbstractKeyspaceOperationCqlGeneratorTest.java
public String randomKeyspaceName() { String name = getClass().getSimpleName() + "_" + UUID.randomUUID().toString().replace("-", ""); return StringUtils.left(name, 47).toLowerCase(); }
From source file:org.talend.dataquality.semantic.validator.impl.SedolValidator.java
@Override public boolean isValid(String str) { if (str == null || str.length() != 7) { return false; }/* w ww . j a v a 2 s .c om*/ String sedolStr = StringUtils.left(str, 6); // Extract the checksum digit. int checksum = -1; try { String csStr = StringUtils.right(str, 1); checksum = Integer.valueOf(csStr); } catch (NumberFormatException e) { throw new RuntimeException("Invalid checksum digit. ", e); } int checksumFromSedol = getSedolCheckDigit(sedolStr); return checksum == checksumFromSedol; }