List of usage examples for com.liferay.portal.kernel.util StringUtil replace
public static String replace(String s, String[] oldSubs, String[] newSubs)
From source file:au.com.permeance.liferay.portal.documentlibrary.util.DLFileNameNormalizerImpl.java
License:Open Source License
public String normalize(String fileName, char[] replaceChars) { if (Validator.isNull(fileName)) { return fileName; }/*from ww w .j a v a2 s . c om*/ fileName = GetterUtil.getString(fileName); fileName = fileName.toLowerCase(); fileName = Normalizer.normalizeToAscii(fileName); StringBuilder sb = null; int index = 0; for (int i = 0; i < fileName.length(); i++) { char c = fileName.charAt(i); if ((Arrays.binarySearch(_REPLACE_CHARS, c) >= 0) || ((replaceChars != null) && ArrayUtil.contains(replaceChars, c))) { if (sb == null) { sb = new StringBuilder(); } if (i > index) { sb.append(fileName.substring(index, i)); } sb.append(CharPool.DASH); // sb.append(CharPool.UNDERLINE); index = i + 1; } } if (sb != null) { if (index < fileName.length()) { sb.append(fileName.substring(index)); } fileName = sb.toString(); } while (fileName.indexOf(StringPool.DOUBLE_DASH) >= 0) { fileName = StringUtil.replace(fileName, StringPool.DOUBLE_DASH, StringPool.DASH); } return fileName; }
From source file:bean.CustomNotificationHandler.java
@Override protected String getBody(UserNotificationEvent userNotificationEvent, ServiceContext serviceContext) throws Exception { JSONObject jsonObject = JSONFactoryUtil.createJSONObject(userNotificationEvent.getPayload()); fullName = jsonObject.getString("fullName"); bodyText = jsonObject.getString("message"); body = StringUtil.replace(getBodyTemplate(), new String[] { "[$FULL_NAME$]", "[$BODY_TEXT$]" }, new String[] { fullName, bodyText }); return body;// w ww.ja v a2 s. c o m }
From source file:com.beorn.onlinepayment.service.persistence.PaymentMethodFinderImpl.java
License:Open Source License
public List<PaymentMethod> findBySellerId(long sellerId, Boolean configured, int start, int end, OrderByComparator obc) throws SystemException { Session session = null;// w ww . j ava 2 s. co m try { session = openSession(); String sql = CustomSQLUtil.get(FIND_BY_SELLERID); if (configured == null) { sql = StringUtil.replace(sql, "(Payment_PaymentPluginConfig.configured = ?) AND", ""); } CustomSQLUtil.replaceOrderBy(sql, obc); SQLQuery q = session.createSQLQuery(sql); q.addEntity("Payment_PaymentMethod", PaymentMethodImpl.class); QueryPos qPos = QueryPos.getInstance(q); qPos.add(sellerId); if (configured != null) qPos.add(configured); List<PaymentMethod> results = (List<PaymentMethod>) QueryUtil.list(q, getDialect(), start, end); return results; } catch (Exception e) { throw new SystemException(e); } finally { closeSession(session); } }
From source file:com.beorn.onlinepayment.service.persistence.PaymentMethodFinderImpl.java
License:Open Source License
public int countBySellerId(long sellerId, Boolean configured) throws SystemException { Session session = null;/* w w w . jav a 2 s .com*/ try { session = openSession(); String sql = CustomSQLUtil.get(COUNT_BY_SELLERID); if (configured == null) { sql = StringUtil.replace(sql, "(Payment_PaymentPluginConfig.configured = ?) AND", ""); } SQLQuery q = session.createSQLQuery(sql); q.addScalar(COUNT_COLUMN_NAME, Type.LONG); QueryPos qPos = QueryPos.getInstance(q); qPos.add(sellerId); if (configured != null) qPos.add(configured); Iterator<Long> itr = q.list().iterator(); if (itr.hasNext()) { Long count = itr.next(); if (count != null) { return count.intValue(); } } return 0; } catch (Exception e) { throw new SystemException(e); } finally { closeSession(session); } }
From source file:com.beorn.onlinepayment.service.persistence.PaymentPluginFinderImpl.java
License:Open Source License
public List<PaymentPlugin> findBySellerId(long sellerId, Boolean configured, int start, int end, OrderByComparator obc) throws SystemException { Session session = null;/*from ww w.java 2 s . c o m*/ try { session = openSession(); String sql = CustomSQLUtil.get(FIND_BY_SELLERID); if (configured == null) { sql = StringUtil.replace(sql, "(Payment_PaymentPlugin.configured = ?) AND", ""); sql = StringUtil.replace(sql, "(Payment_PaymentPluginConfig.configured = ?) AND", ""); } CustomSQLUtil.replaceOrderBy(sql, obc); SQLQuery q = session.createSQLQuery(sql); q.addEntity("Payment_PaymentPlugin", PaymentPluginImpl.class); QueryPos qPos = QueryPos.getInstance(q); qPos.add(sellerId); if (configured != null) { qPos.add(configured); qPos.add(configured); } List<PaymentPlugin> results = (List<PaymentPlugin>) QueryUtil.list(q, getDialect(), start, end); return results; } catch (Exception e) { throw new SystemException(e); } finally { closeSession(session); } }
From source file:com.beorn.onlinepayment.service.persistence.PaymentPluginFinderImpl.java
License:Open Source License
public int countBySellerId(long sellerId, Boolean configured) throws SystemException { Session session = null;//from w w w. j a va 2 s. c o m try { session = openSession(); String sql = CustomSQLUtil.get(COUNT_BY_SELLERID); if (configured == null) { sql = StringUtil.replace(sql, "(Payment_PaymentPlugin.configured = ?) AND", ""); sql = StringUtil.replace(sql, "(Payment_PaymentPluginConfig.configured = ?) AND", ""); } SQLQuery q = session.createSQLQuery(sql); q.addScalar(COUNT_COLUMN_NAME, Type.LONG); QueryPos qPos = QueryPos.getInstance(q); qPos.add(sellerId); if (configured != null) { qPos.add(configured); qPos.add(configured); } Iterator<Long> itr = q.list().iterator(); if (itr.hasNext()) { Long count = itr.next(); if (count != null) { return count.intValue(); } } return 0; } catch (Exception e) { throw new SystemException(e); } finally { closeSession(session); } }
From source file:com.beorn.onlinepayment.service.persistence.PaymentPluginFinderImpl.java
License:Open Source License
public List<PaymentPlugin> findByTransactionAndPaymentMethod(long transactionId, long paymentMethodId, Boolean configured, int start, int end, OrderByComparator obc) throws SystemException { Session session = null;/* w ww .j av a 2s . co m*/ try { session = openSession(); String sql = CustomSQLUtil.get(FIND_BY_TRANSACTIONID_AND_PAYMENTMETHODID); if (configured == null) { sql = StringUtil.replace(sql, "(Payment_PaymentPlugin.configured = ?) AND", ""); sql = StringUtil.replace(sql, "(Payment_PaymentPluginConfig.configured = ?) AND", ""); } CustomSQLUtil.replaceOrderBy(sql, obc); SQLQuery q = session.createSQLQuery(sql); q.addEntity("Payment_PaymentPlugin", PaymentPluginImpl.class); QueryPos qPos = QueryPos.getInstance(q); qPos.add(transactionId); qPos.add(paymentMethodId); if (configured != null) { qPos.add(configured); qPos.add(configured); } List<PaymentPlugin> results = (List<PaymentPlugin>) QueryUtil.list(q, getDialect(), start, end); return results; } catch (Exception e) { throw new SystemException(e); } finally { closeSession(session); } }
From source file:com.beorn.onlinepayment.service.persistence.PaymentPluginFinderImpl.java
License:Open Source License
public int countByTransactionAndPaymentMethod(long transactionId, long paymentMethodId, Boolean configured) throws SystemException { Session session = null;/*from ww w .ja v a 2 s . c o m*/ try { session = openSession(); String sql = CustomSQLUtil.get(COUNT_BY_TRANSACTIONID_AND_PAYMENTMETHODID); if (configured == null) { sql = StringUtil.replace(sql, "(Payment_PaymentPlugin.configured = ?) AND", ""); sql = StringUtil.replace(sql, "(Payment_PaymentPluginConfig.configured = ?) AND", ""); } SQLQuery q = session.createSQLQuery(sql); q.addScalar(COUNT_COLUMN_NAME, Type.LONG); QueryPos qPos = QueryPos.getInstance(q); qPos.add(transactionId); qPos.add(paymentMethodId); if (configured != null) { qPos.add(configured); qPos.add(configured); } Iterator<Long> itr = q.list().iterator(); if (itr.hasNext()) { Long count = itr.next(); if (count != null) { return count.intValue(); } } return 0; } catch (Exception e) { throw new SystemException(e); } finally { closeSession(session); } }
From source file:com.beorn.onlinepayment.service.persistence.RuleFinderImpl.java
License:Open Source License
public List<Rule> findByTransactionAndPaymentMethod(long transactionId, long paymentMethodId, Boolean configured, int start, int end, OrderByComparator obc) throws SystemException { Session session = null;//from w ww. ja va 2 s. co m try { session = openSession(); String sql = CustomSQLUtil.get(FIND_BY_TRANSACTIONID_AND_PAYMENTMETHODID); if (configured == null) { sql = StringUtil.replace(sql, "(Payment_PaymentPlugin.configured = ?) AND", ""); sql = StringUtil.replace(sql, "(Payment_PaymentPluginConfig.configured = ?) AND", ""); } CustomSQLUtil.replaceOrderBy(sql, obc); SQLQuery q = session.createSQLQuery(sql); q.addEntity("Payment_Rule", RuleImpl.class); QueryPos qPos = QueryPos.getInstance(q); qPos.add(transactionId); qPos.add(paymentMethodId); if (configured != null) { qPos.add(configured); qPos.add(configured); } List<Rule> results = (List<Rule>) QueryUtil.list(q, getDialect(), start, end); return results; } catch (Exception e) { throw new SystemException(e); } finally { closeSession(session); } }
From source file:com.cd.learning.hook.MBUtil.java
License:Open Source License
public static String replaceMessageBodyPaths(ThemeDisplay themeDisplay, String messageBody) { return StringUtil.replace(messageBody, new String[] { "@theme_images_path@", "href=\"/", "src=\"/" }, new String[] { themeDisplay.getPathThemeImages(), "href=\"" + themeDisplay.getURLPortal() + "/", "src=\"" + themeDisplay.getURLPortal() + "/" }); }