List of usage examples for org.apache.commons.lang StringUtils substring
public static String substring(String str, int start, int end)
Gets a substring from the specified String avoiding exceptions.
From source file:com.prowidesoftware.swift.model.field.SwiftParseUtils.java
/** * Returns the numeric starting substring of the value. * The split is made when the first alpha character (not number or comma) is found. * For example:<br />/* w w w . jav a 2 s. c o m*/ * 2345,33ABCD will be return 2345,33<br /> * If the value does not contain any numeric or comma character <code>null</code> is returned. * * @param value * @return s */ public static String getNumericPrefix(final String value) { if (value != null && value.length() > 0) { int i = 0; while (i < value.length() && (StringUtils.isNumeric("" + value.charAt(i)) || StringUtils.equals("" + value.charAt(i), ","))) { i++; } if (i > 0) { return StringUtils.substring(value, 0, i); } } return null; }
From source file:it.geosolutions.geoserver.sira.security.config.ExpressionTest.java
@Test public void testRuleAccessFilterECQLEvaluated() throws CQLException { final String xml = "<Rule>" + " <roles>ADMIN</roles>" + " <workspace>*</workspace>" + " <layer>*</layer>" + " <accessMode>READ</accessMode>" + " <filter>\"sira:attivita/sira:Attivita/@gml:id\" = 'attivita.#{new java.util.Random().nextInt(9) + 1}'</filter>" + " <hiddenAttributes />" + "</Rule>"; final Rule r = (Rule) this.xstream.fromXML(xml); assertTrue(r.isValid());/* www. j a v a 2s . c om*/ assertEquals(0, r.priority); assertEquals("ADMIN", r.roles); assertEquals(Rule.ANY, r.workspace); assertEquals(Rule.ANY, r.layer); assertEquals(AccessMode.READ.name(), r.accessMode); final AccessMode accessMode = this.expressionRuleEngine.evaluateAccessMode(r); assertThat(accessMode, is(AccessMode.READ)); assertEquals( "\"sira:attivita/sira:Attivita/@gml:id\" = 'attivita.#{new java.util.Random().nextInt(9) + 1}'", r.filter); final Filter filter = this.expressionRuleEngine.evaluateFilter(r); final String lastFilterChar = StringUtils.substring(filter.toString(), -3, -2); try { final Integer attivitaId = Integer.valueOf(lastFilterChar); assertThat(attivitaId, is(both(greaterThanOrEqualTo(0)).and(lessThanOrEqualTo(9)))); } catch (NumberFormatException e) { fail("Exception not expected"); } assertEquals(CatalogMode.HIDE, r.catalogMode); assertTrue(r.hiddenAttributes != null); assertEquals(0, r.hiddenAttributes.defaultAttributes.size()); }
From source file:com.sfs.whichdoctor.dao.PaymentDAOImpl.java
/** * Process a credit card payment./* w w w . j a v a 2s . c om*/ * * @param cardNumber the card number * @param cardHolder the card holder * @param expiryMonth the expiry month * @param expiryYear the expiry year * @param securityCode the security code * @param totalValue the total value * @param description the description * @param purchaseComment the purchase comment * @return the string[] where: * string[0] = success/error, * string[1] = transaction reference, * string[2] = error message, * string[3] = extended error log */ public final String[] processCreditCardPayment(final String cardNumber, final String cardHolder, final int expiryMonth, final int expiryYear, final int securityCode, final double totalValue, final String description, final String purchaseComment) { String success = "", reference = "", message = "", logMessage = ""; /* Perform a web service call using XFire libraries */ try { Client client = new Client(new URL(this.paymentUrl)); dataLogger.debug("Processing payment"); Object[] result = client.invoke("process", new Object[] { accessId, secret, cardNumber, cardHolder, expiryMonth, expiryYear, securityCode, totalValue, 0, "", description, purchaseComment }); dataLogger.info("Payment processing complete. Results Object[]: " + result); String resultString = (String) result[0]; StringTokenizer st = new StringTokenizer(resultString, ","); int i = 0; while (st.hasMoreTokens()) { String token = st.nextToken(); if (StringUtils.startsWith(token, "'")) { token = StringUtils.substring(token, 1, token.length()); } if (StringUtils.endsWith(token, "'")) { token = StringUtils.substring(token, 0, token.length() - 1); } switch (i) { case 0: success = token; break; case 1: reference = token; break; case 2: message = token; break; case 3: logMessage = token; break; } i++; } dataLogger.info("Payment result: " + success + ", reference: " + reference + ", message: " + message); } catch (Exception e) { dataLogger.error("Error performing payment process web service lookup: " + e.getMessage(), e); } return new String[] { success, reference, message, logMessage }; }
From source file:gov.nih.nci.cabig.caaers.web.admin.EditUserController.java
/** * Builds a Map containing <Study Coordinating Center Identifier> <String to display>. This Map is used in the UI. * @param command/*from w w w .jav a2 s. c o m*/ */ private void populateStudyMap(UserCommand command) { StudyQuery query = null; StringBuilder displayValue = null; for (SuiteRoleMembership srM : command.getRoleMemberships()) { if (srM.getRole().isScoped()) { if (srM.getRole().isSiteScoped() && srM.getRole().isStudyScoped()) { if (!srM.isAllStudies()) { for (String studyIdentifier : srM.getStudyIdentifiers()) { if (!command.getStudyMap().containsKey(studyIdentifier)) { query = new StudyQuery(); query.filterByIdentifierValueExactMatch(studyIdentifier); List<Study> studies = studyRepository.find(query); if (studies.isEmpty()) { command.getStudyMap().put(studyIdentifier, studyIdentifier); } else { displayValue = new StringBuilder(); Study study = studies.get(0); displayValue.append("(").append(study.getCoordinatingCenterIdentifierValue()) .append(") "); String suffix = ""; String studyTitle = study.getShortTitle(); int end = studyTitle.length(); if (end > 30) { end = 30; suffix = "..."; } studyTitle = StringUtils.substring(studyTitle, 0, end); studyTitle = studyTitle + suffix; displayValue.append(studyTitle); command.getStudyMap().put(studyIdentifier, displayValue.toString()); } } } } } } } }
From source file:com.snaplogic.snaps.uniteller.BaseService.java
private String getCamelCaseForMethod(String resourceType) { return new StringBuilder().append(StringUtils.substring(resourceType, 0, 1).toLowerCase()) .append(StringUtils.substring(resourceType, 1)).toString(); }
From source file:gda.jython.translator.GeneralTranslator.java
static char previousPart(String string, int currentlocation) { String leftOfStart = StringUtils.stripToEmpty(StringUtils.substring(string, 0, currentlocation)); char previousPart = leftOfStart.charAt(leftOfStart.length() - 1); return previousPart; }
From source file:it.geosolutions.geoserver.sira.security.config.ExpressionTest.java
@Test public void testRuleAccessFilterECQLEvaluatedWithRootObject() throws CQLException { final String xml = "<Rule>" + " <roles>ADMIN</roles>" + " <workspace>*</workspace>" + " <layer>*</layer>" + " <accessMode>READ</accessMode>" + " <filter>\"sira:attivita/sira:Attivita/@gml:id\" = 'attivita.#{[\'value\']}'</filter>" + " <hiddenAttributes />" + "</Rule>"; final Rule r = (Rule) this.xstream.fromXML(xml); @SuppressWarnings("serial") final Map<String, Object> rootObject = new HashMap<String, Object>() { {// ww w .j a va 2s .c o m // ...a little reminder of how far the development of this project has been taken by "you-know-what";-) this.put("value", 20161231); } }; this.expressionRuleEngine.setRootObject(rootObject); assertTrue(r.isValid()); assertEquals(0, r.priority); assertEquals("ADMIN", r.roles); assertEquals(Rule.ANY, r.workspace); assertEquals(Rule.ANY, r.layer); assertEquals(AccessMode.READ.name(), r.accessMode); final AccessMode accessMode = this.expressionRuleEngine.evaluateAccessMode(r); assertThat(accessMode, is(AccessMode.READ)); assertEquals("\"sira:attivita/sira:Attivita/@gml:id\" = 'attivita.#{[\'value\']}'", r.filter); final Filter filter = this.expressionRuleEngine.evaluateFilter(r); final String lastFilterChar = StringUtils.substring(filter.toString(), -10, -2); try { final Integer attivitaId = Integer.valueOf(lastFilterChar); assertThat(attivitaId, is(rootObject.get("value"))); } catch (NumberFormatException e) { fail("Exception not expected"); } assertEquals(CatalogMode.HIDE, r.catalogMode); assertTrue(r.hiddenAttributes != null); assertEquals(0, r.hiddenAttributes.defaultAttributes.size()); }
From source file:com.baidu.cc.spring.ConfigCenterPropertyPlaceholderConfigurer.java
/** * log out loaded properties.<br>// ww w . j a v a 2 s . co m * For safety consider all value will print out only include partial string. * example a result "key=jdbcpassword" will finally print out as "key=jdbcpa..." * * @param props properties to log out */ protected void doLogLoadedProperties(Properties props) { Iterator<Entry<Object, Object>> iterator = props.entrySet().iterator(); StringBuilder logContent = new StringBuilder(); logContent.append("Loaded property list:\n"); while (iterator.hasNext()) { Entry<Object, Object> next = iterator.next(); logContent.append(next.getKey()).append("="); String value = String.valueOf(next.getValue()); if (value == null) { logContent.append("\n"); continue; } int length = value.length(); if (length < 2) { logContent.append("..."); } else { int sub = length / 2; logContent.append(StringUtils.substring(value, 0, sub)); logContent.append("..."); } logContent.append("\n"); } LOGGER.info(logContent); }
From source file:com.ning.killbill.zuora.zuora.ZuoraApi.java
private String getFirstName(com.ning.billing.account.api.Account account) { final Integer firstNameLength = Objects.firstNonNull(account.getFirstNameLength(), 0); return StringUtils.defaultIfEmpty(StringUtils.substring(account.getName(), 0, firstNameLength), ""); }
From source file:com.prowidesoftware.swift.model.SwiftMessageUtils.java
/** * Creates a sequence and all it's containing parents. * This method is mainly useful for writing test cases. Instead of writing: * <pre><code>//from w ww .ja va2s. c o m * MT535.SequenceB.newInstance( * MT535.SequenceB1b.newInstance( * MT535.SequenceB1b.newInstance( * MT535.SequenceB1b1.newInstance( * tags * ) * ) * ) * ); * </code></pre> * This method is the same with a much cleaner code literature: * <pre><code> * SwiftMessageUtils.createSequenceWithParents(MT535.class, "B1b1", tags); * </code></pre> * * <em>Note:</em><br> * Using * <pre><code> * SwiftMessageUtils.createSequenceWithParents(MT535.class, "B", tags); * </code></pre> * Is virtually the same as: * <pre><code> * MT535.SequenceB.newInstance(tags); * </code></pre> * * @param mt the MT class for which the sequence is to be created * @param sequenceName name of the sequence * @param tags the content to put in the sequence * @return the SwiftTagListBlock containing all parent sequences, the sequence requested and the contents * @since 7.8 */ public static final SwiftTagListBlock createSubsequenceWithParents(final Class<? extends AbstractMT> mt, final String sequenceName, final Tag... tags) { log.finer("Create sequence " + sequenceName); final SwiftTagListBlock result = new SwiftTagListBlock(); result.append(tags); for (int i = sequenceName.length(); i >= 1; i--) { final String sn = StringUtils.substring(sequenceName, 0, i); final SwiftTagListBlock newresult = createSequenceSingle(mt, sn, result.asTagArray()); log.finer(sn + " => " + newresult); result.setTags(newresult.getTags()); } return result; }