List of usage examples for java.lang StringBuffer insert
@Override public StringBuffer insert(int offset, double d)
From source file:org.apache.felix.webconsole.internal.core.BundlesServlet.java
private void collectImport(JSONArray array, String name, Version version, boolean optional, ExportedPackage export) {// w w w.jav a2 s.c o m StringBuffer importBuff = new StringBuffer(); boolean bootDel = isBootDelegated(name); String marker = null; importBuff.append(name); importBuff.append(",version=").append(version); importBuff.append(" from "); if (export != null) { importBuff.append(getBundleDescriptor(export.getExportingBundle())); if (bootDel) { importBuff.append(" -- It will be overwritten by Boot Delegation"); marker = "INFO"; } } else { importBuff.append(" -- It is unable to be resolved"); marker = "ERROR"; if (optional) { importBuff.append(" that is not required"); } if (bootDel) { importBuff.append(" and overwritten by Boot Delegation"); } } if (marker != null) { importBuff.insert(0, ": "); importBuff.insert(0, marker); } array.put(importBuff); }
From source file:org.sakaiproject.messagebundle.impl.MessageBundleServiceImpl.java
@SuppressWarnings("unchecked") public List<MessageBundleProperty> search(String searchQuery, String module, String baseName, String locale) { List<String> values = new ArrayList<String>(); StringBuffer queryString = new StringBuffer(""); try {//from w w w . j a v a2 s .com if (StringUtils.isNotEmpty(searchQuery)) { queryString.append("(defaultValue like ? OR value like ? OR propertyName = ?)"); values.add("%" + searchQuery + "%"); values.add("%" + searchQuery + "%"); values.add(searchQuery); } if (StringUtils.isNotEmpty(module)) { if (queryString.length() > 0) { queryString.append(" AND "); } queryString.append("moduleName = ? "); values.add(module); } if (StringUtils.isNotEmpty(baseName)) { if (queryString.length() > 0) { queryString.append(" AND "); } queryString.append("baseName = ?"); values.add(baseName); } if (StringUtils.isNotEmpty(locale)) { if (queryString.length() > 0) { queryString.append(" AND "); } queryString.append("locale = ?"); values.add(locale); } if (queryString.length() > 0) { queryString.insert(0, "from MessageBundleProperty where "); } else { queryString.insert(0, "from MessageBundleProperty"); } return (List<MessageBundleProperty>) getHibernateTemplate().find(queryString.toString(), values.toArray()); } catch (Exception e) { logger.error("problem searching the message bundle data", e); } return new ArrayList<MessageBundleProperty>(); }
From source file:net.yacy.http.servlets.YaCyDefaultServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String pathInfo;// ww w . j av a 2s . co m Enumeration<String> reqRanges = null; boolean included = request.getAttribute(RequestDispatcher.INCLUDE_REQUEST_URI) != null; if (included) { pathInfo = (String) request.getAttribute(RequestDispatcher.INCLUDE_PATH_INFO); if (pathInfo == null) { pathInfo = request.getPathInfo(); } } else { pathInfo = request.getPathInfo(); // Is this a Range request? reqRanges = request.getHeaders(HeaderFramework.RANGE); if (!hasDefinedRange(reqRanges)) { reqRanges = null; } } String pathInContext = pathInfo == null ? "/" : pathInfo; // this is the path of the resource in _resourceBase (= path within htroot respective htDocs) boolean endsWithSlash = pathInContext.endsWith(URIUtil.SLASH); // Find the resource Resource resource = null; try { // Look for a class resource boolean hasClass = false; if (reqRanges == null && !endsWithSlash) { final int p = pathInContext.lastIndexOf('.'); if (p >= 0) { String pathofClass = pathInContext.substring(0, p) + ".class"; Resource classresource = _resourceBase.addPath(pathofClass); // Does a class resource exist? if (classresource != null && classresource.exists() && !classresource.isDirectory()) { hasClass = true; } } } // find resource resource = getResource(pathInContext); if (!hasClass && (resource == null || !resource.exists()) && !pathInContext.contains("..")) { // try to get this in the alternative htDocsPath resource = Resource.newResource(new File(_htDocsPath, pathInContext)); } if (ConcurrentLog.isFine("FILEHANDLER")) { ConcurrentLog.fine("FILEHANDLER", "YaCyDefaultServlet: uri=" + request.getRequestURI() + " resource=" + resource); } // Handle resource if (!hasClass && (resource == null || !resource.exists())) { if (included) { throw new FileNotFoundException("!" + pathInContext); } response.sendError(HttpServletResponse.SC_NOT_FOUND); } else if (!resource.isDirectory()) { if (endsWithSlash && pathInContext.length() > 1) { String q = request.getQueryString(); pathInContext = pathInContext.substring(0, pathInContext.length() - 1); if (q != null && q.length() != 0) { pathInContext += "?" + q; } response.sendRedirect(response .encodeRedirectURL(URIUtil.addPaths(_servletContext.getContextPath(), pathInContext))); } else { if (hasClass) { // this is a YaCy servlet, handle the template handleTemplate(pathInfo, request, response); } else { if (included || passConditionalHeaders(request, response, resource)) { sendData(request, response, included, resource, reqRanges); } } } } else { // resource is directory String welcome; if (!endsWithSlash) { StringBuffer buf = request.getRequestURL(); synchronized (buf) { int param = buf.lastIndexOf(";"); if (param < 0) { buf.append('/'); } else { buf.insert(param, '/'); } String q = request.getQueryString(); if (q != null && q.length() != 0) { buf.append('?'); buf.append(q); } response.setContentLength(0); response.sendRedirect(response.encodeRedirectURL(buf.toString())); } } // else look for a welcome file else if (null != (welcome = getWelcomeFile(pathInContext))) { ConcurrentLog.fine("FILEHANDLER", "welcome={}" + welcome); // Forward to the index RequestDispatcher dispatcher = request.getRequestDispatcher(welcome); if (dispatcher != null) { if (included) { dispatcher.include(request, response); } else { dispatcher.forward(request, response); } } } else { if (included || passConditionalHeaders(request, response, resource)) { sendDirectory(request, response, resource, pathInContext); } } } } catch (IllegalArgumentException e) { ConcurrentLog.logException(e); if (!response.isCommitted()) { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage()); } } finally { if (resource != null) { resource.close(); } } }
From source file:com.dearho.cs.subscriber.service.impl.SubscriberServiceImpl.java
@Override public Page querySubscriberOrderLatestByPage(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()); }//from www . j av a 2s . 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.getName())) { hql.append(" and s.name=" + subscriber.getName()); } } hql.append(" group by a.subscriber_id "); hql.append(" order by a.trade_time desc"); 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 querySubscriberOrderLongestByPage(Page page, Subscriber subscriber) { StringBuffer hql = new StringBuffer(); hql.append(/*from ww w . ja va 2s. c o m*/ "select a.member_id as subscriber_id ,sum(orders_duration) as sumOrderTime from ord_orders a , sub_subscriber s where s.id=a.member_id and (a.state=2 or a.state=0) "); 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.getName())) { hql.append(" and s.name=" + subscriber.getName()); } } hql.append(" group by a.member_id "); hql.append(" order by sum(orders_duration) desc "); hql.insert(0, "select b.subscriber_id ,sumOrderTime from ( "); hql.append(" )b"); page.setCountField("b.subscriber_id"); // page=subscriberDao.querySubscriberRechargeMostByPage(page, hql.toString()); return page; }
From source file:com.sfs.whichdoctor.beans.BulkEmailBean.java
/** * Gets the contact message./* www. j a v a2 s .c o m*/ * * @param preferences the preferences * * @return the contact message */ private String getContactMessage(final PreferencesBean preferences) { final StringBuffer address = new StringBuffer(); final StringBuffer contact = new StringBuffer(); if (preferences != null) { if (StringUtils.isNotBlank(preferences.getOption("system", "companyname"))) { address.append(preferences.getOption("system", "companyname")); } if (StringUtils.isNotBlank(preferences.getOption("contact", "physical"))) { if (address.length() > 0) { address.append("<br />"); } address.append(preferences.getOption("contact", "physical")); } if (StringUtils.isNotBlank(preferences.getOption("contact", "postal"))) { if (address.length() > 0) { address.append("<br />"); } address.append(preferences.getOption("contact", "postal")); } if (address.length() > 0) { address.insert(0, "<p>"); address.append("</p>"); } if (StringUtils.isNotBlank(preferences.getOption("contact", "telephone"))) { contact.append("<span style=\"padding-right: 30px;\">"); contact.append(preferences.getOption("contact", "telephone")); contact.append("</span>"); } if (StringUtils.isNotBlank(preferences.getOption("contact", "fax"))) { contact.append("<span style=\"padding-right: 30px;\">"); contact.append(preferences.getOption("contact", "fax")); contact.append("</span>"); } if (StringUtils.isNotBlank(preferences.getOption("contact", "web"))) { contact.append("<span>"); contact.append(preferences.getOption("contact", "web")); contact.append("</span>"); } if (contact.length() > 0) { contact.insert(0, "<p>"); contact.append("</p>"); } } return address.toString() + contact.toString(); }
From source file:org.jlibrary.client.export.freemarker.FreemarkerExporter.java
/** * Returns a relative location URL based in the passed node path. Each item * in the returned location URL has a link to that item. * //from w w w.j a v a 2s.c om * @param node Node * * @return String Relative location URL */ public String getLocationURL(Node node) { boolean isDirectory = node.isDirectory(); String location = node.getPath(); StringBuffer buffer = new StringBuffer(); String[] parts = StringUtils.split(location, "/"); if (parts.length == 0) return ""; int k = parts.length - 1; Node n = (Node) node; while ((n != null) && (k >= 0)) { if (k == parts.length - 1) { if (!n.isDocument()) { parts[k] = n.getName(); } } else { parts[k] = n.getName(); } n = EntityRegistry.getInstance().getNode(n.getParent(), n.getRepository()); k--; } String nodeHtmlName = ""; if (parts.length > 1) { nodeHtmlName = parts[parts.length - 1]; if (node.isDocument()) { if (!((Document) node).getTypecode().equals(Types.HTML_DOCUMENT)) { nodeHtmlName += ".html"; } parts[parts.length - 1] = node.getName(); } } for (int i = parts.length - 2; i >= 0; i--) { StringBuffer buffer2 = new StringBuffer(); buffer2.append("/<A href=\""); int dots = parts.length - i - 2; if (node.isDirectory()) { dots++; } if (dots == 0) { buffer2.append("./"); } else { for (int j = 0; j < dots; j++) { buffer2.append("../"); } } buffer2.append("index.html\">" + parts[i] + "</A>"); buffer.insert(0, buffer2.toString()); } if (isDirectory) { buffer.append("/<A href=\"./index.html\">" + parts[parts.length - 1] + "</A>"); } else { buffer.append("/<A href=\"" + nodeHtmlName + "\">" + parts[parts.length - 1] + "</A>"); } return buffer.toString(); }
From source file:com.dearho.cs.subscriber.service.impl.SubscriberServiceImpl.java
@Override public Page querySubscriberOrderMostByPage(Page page, Subscriber subscriber) { StringBuffer hql = new StringBuffer(); hql.append(//from w w w . j av a 2 s. c o m "select a.subscriber_id as subscriber_id, count(*) as allOrder 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.getName())) { hql.append(" and s.name=" + subscriber.getName()); } } hql.append(" group by a.subscriber_id "); hql.append(" order by count(*) desc "); hql.insert(0, "select b.subscriber_id ,allOrder from ( "); hql.append(" )b"); page.setCountField("b.subscriber_id"); page = subscriberDao.querySubscriberOrderMostByPage(page, hql.toString()); return page; }
From source file:org.zkoss.poi.ss.format.CellNumberFormatter.java
private void writeInteger(StringBuffer result, StringBuffer output, List<Special> numSpecials, Set<StringMod> mods, boolean showCommas, boolean fraction) {//20100924, henrichen@zkoss.org: fraction has special treatment about zero //20100914, henrichen@zkoss.org: repect the current locale final char comma = Formatters.getGroupingSeparator(locale); final String commaStr = "" + comma; final String dot = "" + Formatters.getDecimalSeparator(locale); int pos = result.indexOf(dot) - 1; if (pos < 0) { if (exponent != null && numSpecials == integerSpecials) pos = result.indexOf("E") - 1; else//from ww w . j a v a 2 s .c o m pos = result.length() - 1; } int strip; for (strip = 0; strip < pos; strip++) { char resultCh = result.charAt(strip); if (resultCh != '0' && resultCh != comma) break; } //20100924, henrichen@zkoss.org: handle all zero case final char posCh = !fraction && strip == pos && pos >= 0 ? result.charAt(pos) : '\000'; final boolean allZeros = posCh == '0' || posCh == comma; ListIterator<Special> it = numSpecials.listIterator(numSpecials.size()); boolean followWithComma = false; Special lastOutputIntegerDigit = null; int digit = 0; while (it.hasPrevious()) { char resultCh; if (pos >= 0) resultCh = result.charAt(pos); else { // If result is shorter than field, pretend there are leading zeros resultCh = '0'; } Special s = it.previous(); followWithComma = showCommas && digit > 0 && digit % 3 == 0; boolean zeroStrip = false; if (resultCh != '0' || s.ch == '0' || s.ch == '?' || pos >= strip) { zeroStrip = s.ch == '?' && (pos < strip || allZeros); //20100924, henrichen@zkoss.org: handle all zero case output.setCharAt(s.pos, (zeroStrip ? ' ' : resultCh)); lastOutputIntegerDigit = s; } if (followWithComma) { //20100914, henrichen@zkoss.org: repect the current locale //mods.add(insertMod(s, zeroStrip ? " " : ",", StringMod.AFTER)); mods.add(insertMod(s, zeroStrip ? " " : commaStr, StringMod.AFTER)); followWithComma = false; } digit++; --pos; } StringBuffer extraLeadingDigits = new StringBuffer(); if (pos >= 0) { // We ran out of places to put digits before we ran out of digits; put this aside so we can add it later ++pos; // pos was decremented at the end of the loop above when the iterator was at its end extraLeadingDigits = new StringBuffer(result.substring(0, pos)); if (showCommas) { while (pos > 0) { if (digit > 0 && digit % 3 == 0) //20100914, henrichen@zkoss.org: repect the current locale //extraLeadingDigits.insert(pos, ','); extraLeadingDigits.insert(pos, comma); digit++; --pos; } } mods.add(insertMod(lastOutputIntegerDigit, extraLeadingDigits, StringMod.BEFORE)); } }
From source file:com.sfs.whichdoctor.isb.publisher.PersonIsbXmlWriter.java
/** * Builds the membership role map./*from www . ja va 2 s .co m*/ * * @param person the person * @return the map */ private Map<String, String> buildMembershipRoleMap(final PersonBean person) { Map<String, String> roleMap = new HashMap<String, String>(); Collection<MembershipBean> memberships = new ArrayList<MembershipBean>(); if (person != null && person.getMembershipDetails() != null) { memberships = person.getMembershipDetails(); } String prefix = ""; for (MembershipBean role : memberships) { final String roleClass = role.getMembershipClass(); final String roleType = role.getMembershipType(); StringBuffer roleDN = new StringBuffer(); if (StringUtils.equalsIgnoreCase(roleClass, "RACP") && StringUtils.isBlank(roleType)) { // The default membership type ObjectTypeBean div = role.getObjectTypeField("Division"); ObjectTypeBean type = role.getObjectTypeField("Membership Type"); if (type != null && StringUtils.isNotBlank(type.getLdapMapping(1))) { roleDN.append(type.getLdapMapping(1)); } if (div != null && StringUtils.isNotBlank(div.getLdapMapping(1))) { prefix = div.getLdapMapping(1); } if (StringUtils.isNotBlank(roleDN.toString()) && StringUtils.isNotBlank(prefix)) { roleDN.insert(0, ","); roleDN.insert(0, prefix); } } if (StringUtils.equalsIgnoreCase(roleClass, "RACP") && StringUtils.endsWithIgnoreCase(roleType, "Affiliation")) { ObjectTypeBean type = role.getObjectTypeField("Affiliation"); if (type != null && StringUtils.isNotBlank(type.getLdapMapping(1))) { roleDN.append(type.getLdapMapping(1)); } } if (StringUtils.isNotBlank(roleDN.toString())) { roleMap.put(String.valueOf(role.getGUID()), roleDN.toString().trim()); } } // Process the training status to see if it has a mapping if (person != null && StringUtils.isNotBlank(person.getTrainingStatusMapping())) { StringBuffer roleDN = new StringBuffer(); roleDN.append(person.getTrainingStatusMapping()); if (StringUtils.isNotBlank(prefix)) { roleDN.insert(0, ","); roleDN.insert(0, prefix); } roleMap.put(String.valueOf(person.getGUID()), roleDN.toString().trim()); } return roleMap; }