List of usage examples for java.lang StringBuffer insert
@Override public StringBuffer insert(int offset, double d)
From source file:com.twelve.capital.external.feed.util.HttpImpl.java
@Override public String getCompleteURL(HttpServletRequest request) { StringBuffer sb = request.getRequestURL(); if (sb == null) { sb = new StringBuffer(); }/*from w w w. j a va 2s. c om*/ if (request.getQueryString() != null) { sb.append(StringPool.QUESTION); sb.append(request.getQueryString()); } String proxyPath = PortalUtil.getPathProxy(); if (Validator.isNotNull(proxyPath)) { int x = sb.indexOf(Http.PROTOCOL_DELIMITER) + Http.PROTOCOL_DELIMITER.length(); int y = sb.indexOf(StringPool.SLASH, x); sb.insert(y, proxyPath); } String completeURL = sb.toString(); if (request.isRequestedSessionIdFromURL()) { HttpSession session = request.getSession(); String sessionId = session.getId(); completeURL = PortalUtil.getURLWithSessionId(completeURL, sessionId); } if (_log.isWarnEnabled()) { if (completeURL.contains("?&")) { _log.warn("Invalid url " + completeURL); } } return completeURL; }
From source file:com.wm.framework.sh.dao.impl.BaseDaoImpl.java
protected String buildSortCondition(String prefix, List<SortCondition> sortConditions, boolean useSql, Class<?> entityClazz) { // StringBuilder builder = new StringBuilder(); StringBuffer order = new StringBuffer(); if (sortConditions != null && sortConditions.size() > 0) { for (SortCondition sort : sortConditions) { if (null == sort) { continue; }// w w w. j a v a2s . co m order.append(" "); if (prefix != null && !prefix.isEmpty()) { order.append(prefix); order.append("."); } if (useSql) { order.append(getColumnName(entityClazz, sort.getSortColumn())); } else { order.append(sort.getSortColumn()); } order.append(" "); order.append(sort.getSortOrder().toString()); if (sortConditions.indexOf(sort) != sortConditions.size() - 1) { order.append(","); } } if (!StringUtils.isEmpty(order.toString())) { order.insert(0, " order by"); } } return order.toString(); }
From source file:com.dearho.cs.subscriber.service.impl.SubscriberServiceImpl.java
@Override public Page querySubscriberConsumerMostByPage(Page page, Subscriber subscriber) { StringBuffer hql = new StringBuffer(); hql.append(/* w w w . java 2 s. c o m*/ "select a.subscriber_id as subscriber_id ,sum(a.amount) as sum_amount from acc_trade_record a ,sub_subscriber s where s.id=a.subscriber_id and a.type=" + Account.TYPE_ORDER); if (subscriber != null) { if (subscriber.getState() != null) { hql.append(" and s.state=" + subscriber.getState()); } if (subscriber.getEventState() != null) { hql.append(" and s.event_state=" + subscriber.getEventState()); } if (StringUtils.isNotEmpty(subscriber.getPhoneNo())) { hql.append(" and s.phone_no like '%" + subscriber.getPhoneNo() + "%'"); } if (StringUtils.isNotEmpty(subscriber.getSex())) { hql.append(" and sex = '" + subscriber.getSex() + "'"); } if (StringUtils.isNotEmpty(subscriber.getName())) { hql.append(" and name like '%" + subscriber.getName() + "%'"); } } hql.append(" group by a.subscriber_id "); hql.append(" order by sum(a.amount) desc "); hql.insert(0, "select b.subscriber_id ,sum_amount from ( "); hql.append(" )b"); page.setCountField("b.subscriber_id"); // page=subscriberDao.querySubscriberRechargeMostByPage(page, hql.toString()); return page; }
From source file:com.zimbra.cs.account.AttributeManagerUtil.java
private void listAttrs(PrintWriter pw, String[] inClass, String[] notInClass, String[] printFlags) throws ServiceException { if (inClass == null) usage("no class specified"); Set<String> attrsInClass = new HashSet<String>(); for (String c : inClass) { AttributeClass ac = AttributeClass.valueOf(c); SetUtil.union(attrsInClass, attrMgr.getAttrsInClass(ac)); }/*w w w .j a va2 s. com*/ Set<String> attrsNotInClass = new HashSet<String>(); if (notInClass != null) { for (String c : notInClass) { AttributeClass ac = AttributeClass.valueOf(c); SetUtil.union(attrsNotInClass, attrMgr.getAttrsInClass(ac)); } } attrsInClass = SetUtil.subtract(attrsInClass, attrsNotInClass); List<String> list = new ArrayList<String>(attrsInClass); Collections.sort(list); for (String a : list) { StringBuffer flags = new StringBuffer(); if (printFlags != null) { for (String f : printFlags) { AttributeFlag af = AttributeFlag.valueOf(f); if (attrMgr.hasFlag(af, a)) { if (flags.length() > 0) flags.append(", "); flags.append(af.name()); } } if (flags.length() > 0) { flags.insert(0, "(").append(")"); } } System.out.println(a + " " + flags); } }
From source file:org.owasp.jbrofuzz.core.net.MACAddrFuzzer.java
/** * <p>Return the next MAC Address element.</p> * //from ww w. j av a 2 s .c o m * @return String 00<->11<->22<->33<->44<->55 where * <-> could be any of the type specified by the * Separator enum. * * @author subere@uncon.org * @version 2.5 * @since 2.5 * */ public String next() { final StringBuffer output = new StringBuffer(17); long val = currentValue; // Perform division on a stack final Stack<Integer> stack = new Stack<Integer>(); while (val >= 16) { stack.push(Integer.valueOf((int) val % 16)); val = val / 16; } // Append the relevant empty positions with the first element // identified output.append(StringUtils.leftPad(Character.toString(hexCharArray[(int) val]), 12 - stack.size(), "0")); while (!stack.isEmpty()) { output.append(Character.toString(hexCharArray[stack.pop().intValue()])); } currentValue++; if (separator == Separator.NONE) { return output.toString(); } else { char delim; //Add the character delimeter switch (separator) { case HYPHEN: delim = '-'; break; case COLON: delim = ':'; break; case SPACE: delim = ' '; break; case UNDERSCORE: delim = '_'; break; default: delim = ':'; break; } for (int index = 2; index < 17; index += 3) { output.insert(index, delim); } } return output.toString(); }
From source file:org.jivesoftware.community.util.StringUtils.java
public static String wordWrap(String input, int width, Locale locale) { if (input == null) return ""; if (width < 5) return input; if (width >= input.length()) return input; if (locale == null) locale = JiveGlobals.getLocale(); StringBuffer buf = new StringBuffer(input); boolean endOfLine = false; int lineStart = 0; for (int i = 0; i < buf.length(); i++) { if (buf.charAt(i) == '\n') { lineStart = i + 1;/* w w w. ja v a2 s .c o m*/ endOfLine = true; } if (i <= (lineStart + width) - 1) continue; if (!endOfLine) { int limit = i - lineStart - 1; BreakIterator breaks = BreakIterator.getLineInstance(locale); breaks.setText(buf.substring(lineStart, i)); int end = breaks.last(); if (end == limit + 1 && !Character.isWhitespace(buf.charAt(lineStart + end))) end = breaks.preceding(end - 1); if (end != -1 && end == limit + 1) { buf.replace(lineStart + end, lineStart + end + 1, "\n"); lineStart += end; continue; } if (end != -1 && end != 0) { buf.insert(lineStart + end, '\n'); lineStart = lineStart + end + 1; } else { buf.insert(i, '\n'); lineStart = i + 1; } } else { buf.insert(i, '\n'); lineStart = i + 1; endOfLine = false; } } return buf.toString(); }
From source file:com.dearho.cs.subscriber.service.impl.SubscriberServiceImpl.java
@Override public Page querySubscriberOrderFirstByPage(Page page, Subscriber subscriber) { StringBuffer hql = new StringBuffer(); hql.append("select a.id from acc_trade_record a ,sub_subscriber s where s.id=a.subscriber_id and a.type=" + Account.TYPE_ORDER + " and (is_auto_clear is null or is_auto_clear !=1)"); if (subscriber != null) { if (subscriber.getState() != null) { hql.append(" and s.state=" + subscriber.getState()); }/* w ww .j ava2 s . c o m*/ if (subscriber.getEventState() != null) { hql.append(" and s.event_state=" + subscriber.getEventState()); } if (StringUtils.isNotEmpty(subscriber.getPhoneNo())) { hql.append(" and s.phone_no like '%" + subscriber.getPhoneNo() + "%'"); } if (StringUtils.isNotEmpty(subscriber.getSex())) { hql.append(" and sex = '" + subscriber.getSex() + "'"); } if (StringUtils.isNotEmpty(subscriber.getName())) { hql.append(" and name like '%" + subscriber.getName() + "%'"); } } hql.append(" group by a.subscriber_id having count(a.subscriber_id)=1 "); //hql.append(StringHelper.isEmpty(page.getOrderByString()) ? "" : page.getOrderByString()); hql.insert(0, "select b.id from ( "); hql.append(" )b"); page.setCountField("b.id"); page = subscriberDao.querySubscriberOrderFirstByPage(page, hql.toString()); return page; }
From source file:com.dearho.cs.subscriber.service.impl.SubscriberServiceImpl.java
@Override public Page querySubscriberRefundLatestLatestByPage(Page page, Subscriber subscriber) { StringBuffer hql = new StringBuffer(); hql.append(//from ww w . ja v a2s . co m "select a.id from acc_current_account a ,sub_subscriber s where s.id=a.subscriber_id and a.type=" + Account.TYPE_REFUND); if (subscriber != null) { if (subscriber.getState() != null) { hql.append(" and s.state=" + subscriber.getState()); } if (subscriber.getEventState() != null) { hql.append(" and s.event_state=" + subscriber.getEventState()); } if (StringUtils.isNotEmpty(subscriber.getPhoneNo())) { hql.append(" and s.phone_no like '%" + subscriber.getPhoneNo() + "%'"); } if (StringUtils.isNotEmpty(subscriber.getSex())) { hql.append(" and sex = '" + subscriber.getSex() + "'"); } if (StringUtils.isNotEmpty(subscriber.getName())) { hql.append(" and name like '%" + subscriber.getName() + "%'"); } } hql.append(" group by a.subscriber_id "); hql.append("order by a.create_time desc "); // hql.append(StringHelper.isEmpty(page.getOrderByString2()) ? "" : page.getOrderByString2()); hql.insert(0, "select b.id from ( "); hql.append(" )b"); page.setCountField("b.id"); // page=subscriberDao.querySubscriberRechargeLatestByPage(page, hql.toString()); return page; }
From source file:org.medici.bia.common.util.HtmlUtils.java
/** * /*from ww w.ja v a2 s . com*/ * @param text * @param searchWord * @return */ public static String highlightText(String text, String searchWord) { StringBuffer returnText = new StringBuffer(text); Integer indexWord = new Integer(0); List<String> exactWords = new ArrayList<String>(); String toSearch = searchWord; //MD: This code is to identify the words between double quotes while (toSearch.contains("\"")) { //First double quote int from = toSearch.indexOf('\"'); //Second double quote int to = toSearch.indexOf('\"', from + 1); //If there is the second double quote or not if (to != -1) { //Add the exact words to the list and remove them from the string exactWords.add(toSearch.substring(from + 1, to).toLowerCase()); toSearch = toSearch.substring(0, from) + toSearch.substring(to + 1, toSearch.length()); } else { toSearch = toSearch.replace("\"", " "); } } String[] words = StringUtils.split(searchWord.toLowerCase(), " "); if (exactWords.size() == 0) { for (String currentWord : words) { indexWord = returnText.toString().toLowerCase().indexOf(currentWord); while (indexWord != -1) { while (indexWord >= 0 && returnText.charAt(indexWord) != ' ') { indexWord--; } Integer beginWord = indexWord + 1; returnText.insert(beginWord, "<span class='highlighted'>"); Integer endWord = beginWord + 26; while (endWord < returnText.length() && returnText.charAt(endWord) != ' ') { endWord++; } returnText.insert(endWord, "</span>"); Integer nextWord = returnText.substring(endWord).toLowerCase().indexOf(currentWord); if (nextWord != -1) { indexWord = endWord + nextWord; } else { indexWord = nextWord; } } } } else { for (String currentWord : exactWords) { indexWord = returnText.toString().toLowerCase().indexOf(currentWord); while (indexWord != -1) { Integer beginWord = indexWord; returnText.insert(beginWord, "<span class='highlighted'>"); Integer endWord = beginWord + 26 + currentWord.length(); returnText.insert(endWord, "</span>"); Integer nextWord = returnText.substring(endWord).toLowerCase().indexOf(currentWord); if (nextWord != -1) { indexWord = endWord + nextWord; } else { indexWord = nextWord; } } } } return returnText.toString(); }
From source file:org.sakaiproject.messagebundle.impl.MessageBundleServiceImpl.java
public int getSearchCount(String searchQuery, String module, String baseName, String locale) { List<String> values = new ArrayList<String>(); List<BasicType> types = new ArrayList<BasicType>(); StringBuffer queryString = new StringBuffer(""); try {/*from w w w . j ava2s .com*/ if (StringUtils.isNotEmpty(searchQuery)) { queryString.append("(defaultValue like ? OR value like ? OR propertyName = ?)"); values.add("%" + searchQuery + "%"); values.add("%" + searchQuery + "%"); values.add(searchQuery); types.add(StandardBasicTypes.STRING); types.add(StandardBasicTypes.STRING); types.add(StandardBasicTypes.STRING); } if (StringUtils.isNotEmpty(module)) { if (queryString.length() > 0) { queryString.append(" AND "); } queryString.append("moduleName = ? "); values.add(module); types.add(StandardBasicTypes.STRING); } if (StringUtils.isNotEmpty(baseName)) { if (queryString.length() > 0) { queryString.append(" AND "); } queryString.append("baseName = ?"); values.add(baseName); types.add(StandardBasicTypes.STRING); } if (StringUtils.isNotEmpty(locale)) { if (queryString.length() > 0) { queryString.append(" AND "); } queryString.append("locale = ?"); values.add(locale); types.add(StandardBasicTypes.STRING); } if (queryString.length() > 0) { queryString.insert(0, "select count(*) from MessageBundleProperty where "); } else { queryString.insert(0, "select count(*) from MessageBundleProperty"); } Integer count = null; try { Query query = getSessionFactory().getCurrentSession().createQuery(queryString.toString()); query.setParameters(values.toArray(), (Type[]) types.toArray(new Type[types.size()])); count = (Integer) query.uniqueResult(); } catch (HibernateException e) { throw new RuntimeException(e.getMessage(), e); } return count.intValue(); } catch (Exception e) { logger.error("problem searching the message bundle data", e); } return 0; }