List of usage examples for org.apache.commons.lang StringUtils left
public static String left(String str, int len)
Gets the leftmost len
characters of a String.
From source file:net.bible.android.device.ProgressNotificationManager.java
public void initialise() { Log.i(TAG, "Initializing"); workListener = new WorkListener() { @Override/* w w w .j a va 2 s .c om*/ public void workProgressed(WorkEvent ev) { final Progress prog = ev.getJob(); final int done = prog.getWork(); // updating notifications is really slow so we only update the notification manager every 5% if (prog.isFinished() || done % 5 == 0) { // compose a descriptive string showing job name and current section if relevant String status = StringUtils.left(prog.getJobName(), 50) + SharedConstants.LINE_SEPARATOR; if (!StringUtils.isEmpty(prog.getSectionName()) && !prog.getSectionName().equalsIgnoreCase(prog.getJobName())) { status += prog.getSectionName(); } // update notification view final Notification notification = findOrCreateNotification(prog); notification.contentView.setProgressBar(R.id.status_progress, 100, done, false); notification.contentView.setTextViewText(R.id.status_text, status); // this next line is REALLY slow and is the reason we only update the notification manager every 5% // inform the progress bar of updates in progress androidNotificationManager.notify(prog.hashCode(), notification); if (prog.isFinished()) { finished(prog); } } } @Override public void workStateChanged(WorkEvent ev) { Log.d(TAG, "WorkState changed"); // we don't care about these events } }; JobManager.addWorkListener(workListener); Log.d(TAG, "Finished Initializing"); }
From source file:com.haulmont.cuba.security.global.UserUtils.java
private static String parseParam(String param, String firstName, String lastName, String middleName) throws ParseException { if (param == null || param.length() == 0) throw new ParseException("Pattern error", 0); String last = StringUtils.substringAfter(param, "|"); String first = StringUtils.upperCase(StringUtils.substringBefore(param, "|")); if (first == null || first.length() == 0) throw new ParseException("Pattern error", 0); char type = first.charAt(0); boolean all = true; int length = 0; if (first.length() > 1) { char ch = first.charAt(1); switch (ch) { case 'F': case 'L': case 'M': if (first.length() != 2 || type != ch) throw new ParseException("Pattern error", 2); break; default:/*from w ww.j ava2 s . c o m*/ length = Integer.parseInt(first.substring(1, first.length())); break; } } else { all = false; length = 1; } switch (type) { case 'F': first = firstName; break; case 'L': first = lastName; break; case 'M': first = middleName; break; default: throw new ParseException("Pattern error", 0); } if (!all) { first = StringUtils.left(first, length); } return (first.length() > 0) ? first + last : ""; }
From source file:ai.grakn.graql.internal.pattern.VarImpl.java
@Override public String shortName() { return "$" + StringUtils.left(value, 3); }
From source file:net.bible.service.common.TitleSplitter.java
/** * Shorten camel case words uniformly e.g. StrongsRealGreek -> StReGr * Used to create short action bar text for document names * /*from w ww . j a v a2 s .c o m*/ * @param text Text to shorten * @param maxLength Max length of final string * @return Shortened text */ public String shorten(String text, int maxLength) { if (text == null) { return ""; } if (text.length() <= maxLength) { return text; } // take characters from the end of each part until required length obtained String[] parts = text.split("(?<=[a-z])(?=[A-Z0-9 ])"); int numParts = parts.length; if (numParts == 1) { return text.substring(0, maxLength); } // basicLength will be a bit short if the length of all parts is not going to be the same int basicSplitLength = maxLength / numParts; int remaining = maxLength % numParts; // add remaining to end parts because they are more specific int startToAddRemainingFrom = numParts - remaining; StringBuilder result = new StringBuilder(); for (int i = 0; i < parts.length; i++) { int partLen = basicSplitLength; if (i >= startToAddRemainingFrom) { partLen++; } result.append(StringUtils.left(parts[i], partLen)); } return result.toString(); }
From source file:com.openshift.internal.restclient.apis.TypeMetaFactory.java
@Override public Object stubKind(String kind, Optional<String> name, Optional<String> namespace) { if (StringUtils.isEmpty(kind)) { throw new OpenShiftException("Unable to stub a kind when the kind passed in is empty"); }/* w ww . j av a 2s.c o m*/ try { String version = ""; if (kind.contains(DELIMITER)) { int delimeter = kind.indexOf(DELIMITER); version = StringUtils.left(kind, delimeter); kind = StringUtils.right(kind, kind.length() - delimeter - DELIMITER.length()); } Map<String, String[]> properyKeyMap = ResourcePropertiesRegistry.getInstance().get(version, kind); ModelNode node = new ModelNode(); JBossDmrExtentions.set(node, properyKeyMap, APIVERSION, version); JBossDmrExtentions.set(node, properyKeyMap, KIND, kind); ITypeMeta instance = null; if (IMPL_MAP.containsKey(kind)) { Constructor<? extends ITypeMeta> constructor = IMPL_MAP.get(kind).getConstructor(ModelNode.class, Map.class); instance = constructor.newInstance(node, properyKeyMap); } else { instance = new TypeMeta(node, properyKeyMap); } if (name.isPresent() && instance instanceof INameSetable) { ((INameSetable) instance).setName(name.get()); } if (namespace.isPresent() && instance instanceof INamespaceSetable) { ((INamespaceSetable) instance).setNamespace(namespace.get()); } return instance; } catch (UnsupportedVersionException e) { throw e; } catch (Exception e) { throw new ResourceFactoryException(e, "Unable to stub instance from %s", kind); } }
From source file:info.magnolia.cms.security.HierarchicalUserManager.java
protected String getParentPath(String name) { final String lcName = name.toLowerCase(); if (lcName.length() < 3) { return "/" + getRealmName(); }/*w w w. j a va 2 s . co m*/ return "/" + getRealmName() + "/" + lcName.charAt(0) + "/" + StringUtils.left(lcName, 2); }
From source file:id.ac.idu.policy.PasswordEncoderImpl.java
@Override public boolean isPasswordValid(String encPass, String rawPass, Object token) { /*//from ww w . j a v a 2 s .c om * encPass -> Passwort aus UserDetais rawPass -> Passwort aus dem * Eingabefels token -> Ist null oder ein Md5Token und kommt aus * User.getToken() */ if (encPass == null) { /* * Passwort auf der DB ist null Da null nicht im Webformular * eingegeben werden kann, wird ein false geliefert. (vergleich ist * nicht notwendig!) */ return false; } if (token == null) { /* * Kein Token Verwenden. Einfach nur die Passwrter vergleichen. */ return encPass.equals(rawPass); } /* * Ab hier wird ein Token verwendet! Wenn man in Debugger wartet, kann * der eingegebene Token Ablaufen! */ if (rawPass.length() <= Md5Token.TOKEN_LENGTH) { /* * Passwort ist zu klein, um einen Token zu enthalten! */ return false; } /* * Passwort ohne Token ermitteln */ String newRawPass = StringUtils.left(rawPass, rawPass.length() - Md5Token.TOKEN_LENGTH); if (encPass.equals(newRawPass)) { /* * eingegebenes Token ermitteln */ String rawToken = StringUtils.right(rawPass, Md5Token.TOKEN_LENGTH); Md5Token md5Token = (Md5Token) token; /* * Token prfen */ return md5Token.isEqualsToken(rawToken); } return false; }
From source file:de.forsthaus.policy.PasswordEncoderImpl.java
@Override public boolean isPasswordValid(String encPass, String rawPass, Object token) { /*/*w ww . j a v a2 s . com*/ * encPass -> Passwort aus UserDetais rawPass -> Passwort aus dem * Eingabefels token -> Ist null oder ein Md5Token und kommt aus * User.getToken() */ if (encPass == null) { /* * Passwort auf der DB ist null Da null nicht im Webformular * eingegeben werden kann, wird ein false geliefert. (vergleich ist * nicht notwendig!) */ return false; } if (token == null) { /* * Kein Token Verwenden. Einfach nur die Passwrter vergleichen. */ return encPass.equals(rawPass); } /* * Ab hier wird ein Token verwendet! Wenn man in Debugger wartet, kann * der eingegebene Token Ablaufen! */ if (rawPass.length() <= Md5Token.TOKEN_LENGTH) { /* * Passwort ist zu klein, um einen Token zu enthalten! */ return false; } /* * Passwort ohne Token ermitteln */ String newRawPass = StringUtils.left(rawPass, rawPass.length() - Md5Token.TOKEN_LENGTH); if (encPass.equals(newRawPass)) { /* * eingegebenes Token ermitteln */ String rawToken = StringUtils.right(rawPass, Md5Token.TOKEN_LENGTH); Md5Token md5Token = (Md5Token) token; /* * Token prfen */ return md5Token.isEqualsToken(rawToken); } return false; }
From source file:com.alibaba.intl.bcds.goldroom.util.ImageUtilImpl.java
private String isbnTopath(String isbn, String separator) { StringBuilder sb = new StringBuilder(); sb.append(separator).append(StringUtils.left(isbn, 2)); sb.append(separator).append(StringUtils.mid(isbn, 2, 2)); sb.append(separator).append(StringUtils.mid(isbn, 4, 2)); sb.append(separator);// w w w. j a v a2 s. c o m return sb.toString(); }
From source file:com.welshare.web.InfoController.java
@RequestMapping("/contact/sendMessage") public String sendContactMessage(@Valid ContactMessage contactMessage, BindingResult binding, HttpServletRequest request) {/*from w ww. ja va2 s . c o m*/ if (!binding.hasErrors()) { contactMessage.setMessage(StringUtils.left(contactMessage.getMessage(), 1000)); contactMessage.setDateTime(new DateTime()); userService.save(contactMessage); WebUtils.addMessage(request, "contactMessageSent"); userService.notifyAdminUsers("New feedback received on welshare"); } return "info/contact"; }