List of usage examples for org.apache.commons.lang StringUtils substringBefore
public static String substringBefore(String str, String separator)
Gets the substring before the first occurrence of a separator.
From source file:info.magnolia.module.delta.BootstrapConditionally.java
private static String determineRepository(String filename) { return StringUtils.substringBefore(cleanupFilename(filename), "."); }
From source file:cec.easyshop.storefront.filters.CustomerLocationRestorationFilter.java
protected UserLocationData decipherUserLocationData(final String customerLocationString) { final UserLocationData userLocationData = new UserLocationData(); final String searchTerm = StringUtils.substringBefore(customerLocationString, CustomerLocationCookieGenerator.LOCATION_SEPARATOR); final String latitudeAndLongitude = StringUtils.substringAfter(customerLocationString, CustomerLocationCookieGenerator.LOCATION_SEPARATOR); if (StringUtils.isNotEmpty(latitudeAndLongitude)) { final GeoPoint geoPoint = new GeoPoint(); geoPoint.setLatitude(Double.parseDouble(StringUtils.substringBefore(latitudeAndLongitude, CustomerLocationCookieGenerator.LATITUDE_LONGITUDE_SEPARATOR))); geoPoint.setLongitude(Double.parseDouble(StringUtils.substringAfter(latitudeAndLongitude, CustomerLocationCookieGenerator.LATITUDE_LONGITUDE_SEPARATOR))); userLocationData.setPoint(geoPoint); }/*from ww w .j av a2s . c o m*/ userLocationData.setSearchTerm(searchTerm); return userLocationData; }
From source file:com.opengamma.bbg.referencedata.MockReferenceDataProvider.java
@Override protected ReferenceDataProviderGetResult doBulkGet(ReferenceDataProviderGetRequest request) { if (_expectedFields.size() > 0) { for (String field : _expectedFields) { assertTrue(request.getFields().contains(field)); }//from ww w.java2 s .c o m } ReferenceDataProviderGetResult result = new ReferenceDataProviderGetResult(); for (String identifier : request.getIdentifiers()) { if (_mockDataMap.containsKey(identifier)) { // known security ReferenceData refData = new ReferenceData(identifier); MutableFudgeMsg msg = OpenGammaFudgeContext.getInstance().newMessage(); Multimap<String, String> fieldMap = _mockDataMap.get(identifier); if (fieldMap != null) { // security actually has data for (String field : request.getFields()) { Collection<String> values = fieldMap.get(field); assertTrue("Field not found: " + field + " in " + fieldMap.keySet(), values.size() > 0); assertNotNull(values); for (String value : values) { if (value != null) { if (value.contains("=")) { MutableFudgeMsg submsg = OpenGammaFudgeContext.getInstance().newMessage(); submsg.add(StringUtils.substringBefore(value, "="), StringUtils.substringAfter(value, "=")); msg.add(field, submsg); } else { msg.add(field, value); } } } } } refData.setFieldValues(msg); result.addReferenceData(refData); } else { // security wasn't marked as known fail("Security not found: " + identifier + " in " + _mockDataMap.keySet()); } } return result; }
From source file:com.abssh.util.PropertyFilter.java
/** * @param filterName// w w w . j ava 2s.c o m * ,???. eg. LIKES_NAME_OR_LOGIN_NAME * @param value * . */ @SuppressWarnings("unchecked") public PropertyFilter(final String filterName, final Object value) { String matchTypeStr = StringUtils.substringBefore(filterName, "_"); String matchTypeCode = StringUtils.substring(matchTypeStr, 0, matchTypeStr.length() - 1); String propertyTypeCode = StringUtils.substring(matchTypeStr, matchTypeStr.length() - 1, matchTypeStr.length()); try { matchType = Enum.valueOf(MatchType.class, matchTypeCode); } catch (RuntimeException e) { throw new IllegalArgumentException( "filter??" + filterName + ",.", e); } try { propertyType = Enum.valueOf(PropertyType.class, propertyTypeCode).getValue(); } catch (RuntimeException e) { throw new IllegalArgumentException( "filter??" + filterName + ",.", e); } String propertyNameStr = StringUtils.substringAfter(filterName, "_"); propertyNames = propertyNameStr.split(PropertyFilter.OR_SEPARATOR); Assert.isTrue(propertyNames.length > 0, "filter??" + filterName + ",??."); // entity property. if (value != null && (value.getClass().isArray() || Collection.class.isInstance(value) || value.toString().split(",").length > 1)) { // IN ? Object[] vObjects = null; if (value.getClass().isArray()) { vObjects = (Object[]) value; } else if (Collection.class.isInstance(value)) { vObjects = ((Collection) value).toArray(); } else { vObjects = value.toString().split(","); } this.propertyValue = new Object[vObjects.length]; for (int i = 0; i < vObjects.length; i++) { propertyValue[i] = ReflectionUtils.convertValue(vObjects[i], propertyType); } } else { Object tObject = ReflectionUtils.convertValue(value, propertyType); if (tObject != null && matchType == MatchType.LE && propertyType.getName().equals("java.util.Date")) { // LED ??tObject2010-08-13 00:00:00 // ?2010-08-13 23:59:59 Date leDate = (Date) tObject; Calendar c = GregorianCalendar.getInstance(); c.setTime(leDate); c.set(Calendar.HOUR_OF_DAY, 23); c.set(Calendar.MINUTE, 59); c.set(Calendar.SECOND, 59); tObject = c.getTime(); } else if (tObject != null && matchType == MatchType.LEN && propertyType.getName().equals("java.util.Date")) { // LED ??tObject2010-08-13 00:00:00 // ?2010-08-13 23:59:59 // Date leDate = (Date) tObject; // Calendar c = GregorianCalendar.getInstance(); // c.setTime(leDate); // tObject = c.getTime(); } else if (tObject != null && matchType == MatchType.LIKE) { tObject = ((String) tObject).replace("%", "\\%").replace("_", "\\_"); } this.propertyValue = new Object[] { tObject }; } }
From source file:de.hybris.platform.chinesepaymentaddon.controllers.pages.ChineseOrderConfirmationController.java
@Override protected String processOrderCode(final String orderCode, final Model model, final HttpServletRequest request) throws CMSItemNotFoundException { final OrderData orderDetails = orderFacade.getOrderDetailsForCode(orderCode); if (orderDetails.isGuestCustomer() && !StringUtils.substringBefore(orderDetails.getUser().getUid(), "|") .equals(getSessionService().getAttribute(WebConstants.ANONYMOUS_CHECKOUT_GUID))) { return getCheckoutRedirectUrl(); }/*from w w w . j a va 2 s . c o m*/ if (orderDetails.getEntries() != null && !orderDetails.getEntries().isEmpty()) { for (final OrderEntryData entry : orderDetails.getEntries()) { final String productCode = entry.getProduct().getCode(); final ProductData product = productFacade.getProductForCodeAndOptions(productCode, Arrays.asList(ProductOption.BASIC, ProductOption.PRICE, ProductOption.CATEGORIES)); entry.setProduct(product); } } model.addAttribute("orderCode", orderCode); model.addAttribute("orderData", orderDetails); model.addAttribute("allItems", orderDetails.getEntries()); model.addAttribute("deliveryAddress", orderDetails.getDeliveryAddress()); model.addAttribute("deliveryMode", orderDetails.getDeliveryMode()); model.addAttribute("paymentInfo", orderDetails.getPaymentInfo()); model.addAttribute("pageType", PageType.ORDERCONFIRMATION.name()); final String uid; if (orderDetails.isGuestCustomer() && !model.containsAttribute("guestRegisterForm")) { final GuestRegisterForm guestRegisterForm = new GuestRegisterForm(); guestRegisterForm.setOrderCode(orderDetails.getGuid()); uid = StringUtils.substringAfter(orderDetails.getUser().getUid(), "|"); guestRegisterForm.setUid(uid); model.addAttribute(guestRegisterForm); } else { uid = orderDetails.getUser().getUid(); } model.addAttribute("email", uid); final String continueUrl = (String) getSessionService().getAttribute(WebConstants.CONTINUE_URL); model.addAttribute(CONTINUE_URL_KEY, (continueUrl != null && !continueUrl.isEmpty()) ? continueUrl : ROOT); final AbstractPageModel cmsPage = getContentPageForLabelOrId(CHECKOUT_ORDER_CONFIRMATION_CMS_PAGE_LABEL); storeCmsPageInModel(model, cmsPage); setUpMetaDataForContentPage(model, getContentPageForLabelOrId(CHECKOUT_ORDER_CONFIRMATION_CMS_PAGE_LABEL)); model.addAttribute(ThirdPartyConstants.SeoRobots.META_ROBOTS, ThirdPartyConstants.SeoRobots.NOINDEX_NOFOLLOW); if (ResponsiveUtils.isResponsive()) { return getViewForPage(model); } return ControllerConstants.Views.Pages.Checkout.CheckoutConfirmationPage; }
From source file:gov.guilin.controller.admin.StatisticsController.java
/** * //from w w w . j a v a 2 s.co m */ @RequestMapping(value = "/setting", method = RequestMethod.POST) public String setting(@RequestParam(defaultValue = "false") Boolean isEnabled, RedirectAttributes redirectAttributes) { Setting setting = SettingUtils.get(); if (isEnabled) { if (StringUtils.isEmpty(setting.getCnzzSiteId()) || StringUtils.isEmpty(setting.getCnzzPassword())) { try { String createAccountUrl = "http://intf.cnzz.com/user/companion/guilin.php?domain=" + setting.getSiteUrl() + "&key=" + DigestUtils.md5Hex(setting.getSiteUrl() + "Lfg4uP0H"); URLConnection urlConnection = new URL(createAccountUrl).openConnection(); BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream())); String line = null; while ((line = in.readLine()) != null) { if (line.contains("@")) { break; } } if (line != null) { setting.setCnzzSiteId(StringUtils.substringBefore(line, "@")); setting.setCnzzPassword(StringUtils.substringAfter(line, "@")); } } catch (IOException e) { e.printStackTrace(); } } } setting.setIsCnzzEnabled(isEnabled); SettingUtils.set(setting); cacheService.clear(); addFlashMessage(redirectAttributes, SUCCESS_MESSAGE); return "redirect:setting.jhtml"; }
From source file:com.bstek.dorado.view.resolver.VelocityInterceptorDirective.java
@SuppressWarnings("rawtypes") protected void intercept(InternalContextAdapter contextAdapter, Writer writer, Node node) throws Exception { int paramNum = node.jjtGetNumChildren(); if (paramNum == 0) { throw new IllegalArgumentException("No interceptor name defined in #interceptor."); }/*from w w w .j a va2s . c o m*/ String interceptorName = (String) node.jjtGetChild(0).value(contextAdapter); if (StringUtils.isEmpty(interceptorName)) { throw new IllegalArgumentException("The interceptor name defined in #interceptor can not be empty."); } if (interceptorName.indexOf('#') <= 0) { throw new IllegalArgumentException("Invalid interceptor name [" + interceptorName + "]."); } String beanName = StringUtils.substringBefore(interceptorName, "#"); String methodName = StringUtils.substringAfter(interceptorName, "#"); if (StringUtils.isEmpty(methodName)) { throw new IllegalArgumentException("Invalid interceptor name [" + interceptorName + "]."); } if (paramNum > 2) { throw new IllegalArgumentException("Too more arguments defined in #interceptor."); } Map parameterMap = null; if (paramNum == 2) { parameterMap = (Map) node.jjtGetChild(1).value(contextAdapter); } Object bean = BeanFactoryUtils.getBean(beanName); Method[] methods = MethodAutoMatchingUtils.getMethodsByName(bean.getClass(), methodName); if (methods.length == 0) { throw new IllegalArgumentException("No method found for [" + interceptorName + "]."); } else if (methods.length > 1) { throw new IllegalArgumentException("More than one method found for [" + interceptorName + "]."); } Method method = methods[0]; View view = (View) contextAdapter.get("view"); Class<?>[] parameterTypes = method.getParameterTypes(); String[] parameterNames = MethodAutoMatchingUtils.getParameterNames(method); Object[] parameters = new Object[parameterTypes.length]; int i = 0; for (Class<?> parameterType : parameterTypes) { if (Writer.class.isAssignableFrom(parameterType)) { /* Writer */ parameters[i] = writer; } else if (Context.class.isAssignableFrom(parameterType)) { /* Velocity Context */ parameters[i] = contextAdapter; } else if (ViewElement.class.isAssignableFrom(parameterType)) { /* Component or View */ String parameterName = parameterNames[i]; if ("view".equals(parameterName)) { parameters[i] = view; } else { parameters[i] = view.getViewElement(parameterName); } } else if (parameterMap != null) { /* from ParameterMap */ String parameterName = parameterNames[i]; parameters[i] = parameterMap.get(parameterName); } i++; } method.invoke(bean, parameters); }
From source file:net.osxx.controller.admin.StatisticsController.java
/** * /*from w w w.j av a2 s . co m*/ */ @RequestMapping(value = "/setting", method = RequestMethod.POST) public String setting(@RequestParam(defaultValue = "false") Boolean isEnabled, RedirectAttributes redirectAttributes) { Setting setting = SettingUtils.get(); if (isEnabled) { if (StringUtils.isEmpty(setting.getCnzzSiteId()) || StringUtils.isEmpty(setting.getCnzzPassword())) { try { String createAccountUrl = "http://intf.cnzz.com/user/companion/osxx.php?domain=" + setting.getSiteUrl() + "&key=" + DigestUtils.md5Hex(setting.getSiteUrl() + "Lfg4uP0H"); URLConnection urlConnection = new URL(createAccountUrl).openConnection(); BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream())); String line = null; while ((line = in.readLine()) != null) { if (line.contains("@")) { break; } } if (line != null) { setting.setCnzzSiteId(StringUtils.substringBefore(line, "@")); setting.setCnzzPassword(StringUtils.substringAfter(line, "@")); } } catch (IOException e) { e.printStackTrace(); } } } setting.setIsCnzzEnabled(isEnabled); SettingUtils.set(setting); cacheService.clear(); addFlashMessage(redirectAttributes, SUCCESS_MESSAGE); return "redirect:setting.jhtml"; }
From source file:net.shopxx.controller.admin.StatisticsController.java
/** * //w w w . j a v a2s.co m */ @RequestMapping(value = "/setting", method = RequestMethod.POST) public String setting(@RequestParam(defaultValue = "false") Boolean isEnabled, RedirectAttributes redirectAttributes) { Setting setting = SettingUtils.get(); if (isEnabled) { if (StringUtils.isEmpty(setting.getCnzzSiteId()) || StringUtils.isEmpty(setting.getCnzzPassword())) { try { String createAccountUrl = "http://intf.cnzz.com/user/companion/shopxx.php?domain=" + setting.getSiteUrl() + "&key=" + DigestUtils.md5Hex(setting.getSiteUrl() + "Lfg4uP0H"); URLConnection urlConnection = new URL(createAccountUrl).openConnection(); BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream())); String line = null; while ((line = in.readLine()) != null) { if (line.contains("@")) { break; } } if (line != null) { setting.setCnzzSiteId(StringUtils.substringBefore(line, "@")); setting.setCnzzPassword(StringUtils.substringAfter(line, "@")); } } catch (IOException e) { e.printStackTrace(); } } } setting.setIsCnzzEnabled(isEnabled); SettingUtils.set(setting); cacheService.clear(); addFlashMessage(redirectAttributes, SUCCESS_MESSAGE); return "redirect:setting.jhtml"; }
From source file:eu.annocultor.converters.europeana.EuropeanaLabelExtractor.java
boolean extractDfgCoverage(List<String> extracted, String label) { if (precheckisDfgCoverage(label)) { if (StringUtils.capitalize(label).equals(label)) { String countryAbbreviated = StringUtils.substringBefore(label, " "); extracted.add(countryAbbreviated); String countrySpelled = StringUtils.substringAfter(label, " "); if (!StringUtils.isEmpty(countrySpelled)) { extracted.add(countrySpelled); return true; }/*from w w w. jav a 2 s .c om*/ } } return false; }