Example usage for java.lang StringBuilder insert

List of usage examples for java.lang StringBuilder insert

Introduction

In this page you can find the example usage for java.lang StringBuilder insert.

Prototype

@Override
public StringBuilder insert(int offset, double d) 

Source Link

Usage

From source file:com.irccloud.android.ColorFormatter.java

public static String irc_to_html(String msg) {
    if (msg == null)
        return "";

    int pos = 0;//w  ww  . ja  va2s.  c  om
    boolean bold = false, underline = false, italics = false;
    String fg = "", bg = "";
    StringBuilder builder = new StringBuilder(msg);
    builder.insert(0, "<irc>");

    while (pos < builder.length()) {
        if (builder.charAt(pos) == 2) { //Bold
            String html = "";
            if (bold) {
                html += "</b>";
                if (fg.length() > 0) {
                    html += "</font>";
                }
                if (bg.length() > 0) {
                    html += "</_bg" + bg + ">";
                }
                if (italics)
                    html += "</i>";
                if (underline)
                    html += "</u>";
                if (fg.length() > 0) {
                    html += "<font color=\"#" + fg + "\">";
                }
                if (bg.length() > 0) {
                    html += "<_bg" + bg + ">";
                }
                if (italics)
                    html += "<i>";
                if (underline)
                    html += "<u>";
            } else {
                html += "<b>";
            }
            bold = !bold;
            builder.deleteCharAt(pos);
            builder.insert(pos, html);
        } else if (builder.charAt(pos) == 22 || builder.charAt(pos) == 29) { //Italics
            String html = "";
            if (italics) {
                html += "</i>";
                if (fg.length() > 0) {
                    html += "</font>";
                }
                if (bg.length() > 0) {
                    html += "</_bg" + bg + ">";
                }
                if (bold)
                    html += "</b>";
                if (underline)
                    html += "</u>";
                if (fg.length() > 0) {
                    html += "<font color=\"#" + fg + "\">";
                }
                if (bg.length() > 0) {
                    html += "<_bg" + bg + ">";
                }
                if (bold)
                    html += "<b>";
                if (underline)
                    html += "<u>";
            } else {
                html += "<i>";
            }
            italics = !italics;
            builder.deleteCharAt(pos);
            builder.insert(pos, html);
        } else if (builder.charAt(pos) == 31) { //Underline
            String html = "";
            if (underline) {
                html += "</u>";
                if (fg.length() > 0) {
                    html += "</font>";
                }
                if (bg.length() > 0) {
                    html += "</_bg" + bg + ">";
                }
                if (bold)
                    html += "</b>";
                if (italics)
                    html += "</i>";
                if (fg.length() > 0) {
                    html += "<font color=\"#" + fg + "\">";
                }
                if (bg.length() > 0) {
                    html += "<_bg" + bg + ">";
                }
                if (bold)
                    html += "<b>";
                if (italics)
                    html += "<i>";
            } else {
                html += "<u>";
            }
            underline = !underline;
            builder.deleteCharAt(pos);
            builder.insert(pos, html);
        } else if (builder.charAt(pos) == 15) { //Formatting clear
            String html = "";
            if (fg.length() > 0) {
                html += "</font>";
                fg = "";
            }
            if (bg.length() > 0) {
                html += "</_bg" + bg + ">";
                bg = "";
            }
            if (bold) {
                html += "</b>";
                bold = false;
            }
            if (underline) {
                html += "</u>";
                underline = false;
            }
            if (italics) {
                html += "</i>";
                italics = false;
            }
            builder.deleteCharAt(pos);
            if (html.length() > 0)
                builder.insert(pos, html);
        } else if (builder.charAt(pos) == 3 || builder.charAt(pos) == 4) { //Color
            boolean rgb = (builder.charAt(pos) == 4);
            int count = 0;
            String new_fg = "", new_bg = "";
            builder.deleteCharAt(pos);
            if (pos < builder.length()) {
                while (pos + count < builder.length()
                        && ((builder.charAt(pos + count) >= '0' && builder.charAt(pos + count) <= '9') || rgb
                                && ((builder.charAt(pos + count) >= 'a' && builder.charAt(pos + count) <= 'f')
                                        || (builder.charAt(pos + count) >= 'A'
                                                && builder.charAt(pos + count) <= 'F')))) {
                    if ((++count == 2 && !rgb) || count == 6)
                        break;
                }
                if (count > 0) {
                    if (count < 3 && !rgb) {
                        try {
                            int col = Integer.parseInt(builder.substring(pos, pos + count));
                            if (col > 15) {
                                count--;
                                col /= 10;
                            }
                            new_fg = COLOR_MAP[col];
                        } catch (NumberFormatException e) {
                            new_fg = builder.substring(pos, pos + count);
                        }
                    } else
                        new_fg = builder.substring(pos, pos + count);
                    builder.delete(pos, pos + count);
                }
                if (pos < builder.length() && builder.charAt(pos) == ',') {
                    builder.deleteCharAt(pos);
                    if (new_fg.length() == 0)
                        new_fg = "clear";
                    new_bg = "clear";
                    count = 0;
                    while (pos + count < builder.length()
                            && ((builder.charAt(pos + count) >= '0' && builder.charAt(pos + count) <= '9')
                                    || rgb && ((builder.charAt(pos + count) >= 'a'
                                            && builder.charAt(pos + count) <= 'f')
                                            || (builder.charAt(pos + count) >= 'A'
                                                    && builder.charAt(pos + count) <= 'F')))) {
                        if ((++count == 2 && !rgb) || count == 6)
                            break;
                    }
                    if (count > 0) {
                        if (count < 3 && !rgb) {
                            try {
                                int col = Integer.parseInt(builder.substring(pos, pos + count));
                                if (col > 15) {
                                    count--;
                                    col /= 10;
                                }
                                new_bg = COLOR_MAP[col];
                            } catch (NumberFormatException e) {
                                new_bg = builder.substring(pos, pos + count);
                            }
                        } else
                            new_bg = builder.substring(pos, pos + count);
                        builder.delete(pos, pos + count);
                    } else {
                        builder.insert(pos, ",");
                    }
                }
                String html = "";
                if (new_fg.length() == 0 && new_bg.length() == 0) {
                    new_fg = "clear";
                    new_bg = "clear";
                }
                if (new_fg.length() > 0 && fg.length() > 0) {
                    html += "</font>";
                }
                if (new_bg.length() > 0 && bg.length() > 0) {
                    html += "</_bg" + bg + ">";
                }
                if (new_bg.length() > 0) {
                    if (new_bg.equals("clear")) {
                        bg = "";
                    } else {
                        bg = "";
                        if (new_bg.length() == 6) {
                            bg = new_bg;
                        } else if (new_bg.length() == 3) {
                            bg += new_bg.charAt(0);
                            bg += new_bg.charAt(0);
                            bg += new_bg.charAt(1);
                            bg += new_bg.charAt(1);
                            bg += new_bg.charAt(2);
                            bg += new_bg.charAt(2);
                        } else {
                            bg = "ffffff";
                        }
                        if (bg.length() > 0)
                            html += "<_bg" + bg + ">";
                    }
                }
                if (new_fg.length() > 0) {
                    if (new_fg.equals("clear")) {
                        fg = "";
                    } else {
                        fg = "";
                        if (new_fg.length() == 6) {
                            fg = new_fg;
                        } else if (new_fg.length() == 3) {
                            fg += new_fg.charAt(0);
                            fg += new_fg.charAt(0);
                            fg += new_fg.charAt(1);
                            fg += new_fg.charAt(1);
                            fg += new_fg.charAt(2);
                            fg += new_fg.charAt(2);
                        } else {
                            fg = "000000";
                        }
                    }
                    if (ColorScheme.getInstance().theme != null && bg.length() == 0) {
                        if (ColorScheme.getInstance().isDarkTheme && DARK_FG_SUBSTITUTIONS.containsKey(fg))
                            fg = DARK_FG_SUBSTITUTIONS.get(fg);
                        if (Integer.toHexString(ColorScheme.getInstance().contentBackgroundColor)
                                .equalsIgnoreCase("ff" + fg)) {
                            int red = Integer.parseInt(fg.substring(0, 1), 16);
                            int blue = Integer.parseInt(fg.substring(2, 3), 16);
                            int green = Integer.parseInt(fg.substring(4, 5), 16);

                            red += 0x22;
                            if (red > 0xFF)
                                red = 0xFF;
                            green += 0x22;
                            if (green > 0xFF)
                                green = 0xFF;
                            blue += 0x22;
                            if (blue > 0xFF)
                                blue = 0xFF;

                            fg = String.format("%02x%02x%02x", red, green, blue);
                        }
                    }
                    if (fg.length() > 0)
                        html += "<font color=\"#" + fg + "\">";
                }
                builder.insert(pos, html);
            }
        } else {
            pos++;
        }
    }
    if (fg.length() > 0) {
        builder.append("</font>");
    }
    if (bg.length() > 0) {
        builder.append("</_bg").append(bg).append(">");
    }
    if (bold)
        builder.append("</b>");
    if (underline)
        builder.append("</u>");
    if (italics)
        builder.append("</i>");

    builder.append("</irc>");
    return builder.toString();
}

From source file:com.evolveum.polygon.scim.StandardScimHandlingStrategy.java

public void handleInvalidStatus(String errorPitch, String responseString, String situation, int statusCode)
        throws ParseException, IOException {

    String error = ErrorHandler.onNoSuccess(responseString, statusCode, situation);
    StringBuilder errorString = new StringBuilder(errorPitch).append(error);
    switch (statusCode) {
    case 400:/*w w w . j a va 2s.  c  o m*/
        handleBadRequest(error);
        break;
    case 401:
        errorString.insert(0, "Unauthorized ");
        throw new InvalidCredentialException(errorString.toString());
    case 404:
        LOGGER.warn("Resource not found or resource was already deleted");
        break;
    case 409:
        errorString.insert(0, "Conflict ");
        throw new AlreadyExistsException(errorString.toString());
    case 500:
        errorString.insert(0, "Provider server error ");
        throw new ConnectorException(errorString.toString());
    default:
        LOGGER.warn(error);
        break;
    }
}

From source file:GIST.IzbirkomExtractor.StreetNameNormalizer.java

/**
 * //from ww  w.jav  a2s. co  m
 * @param streetName street name to be normalized
 * @return normalized street name
 */
public ArrayList<String> normalize(String streetName) {

    /**
     * Array for street name variations.
     */
    ArrayList<String> variations = new ArrayList<String>();

    /* expand abbreviated street type, extract street type, and extract it from the street name */
    Matcher m = streetTypeAbbrList.getExpansionsPattern()
            .matcher(streetTypeAbbrList.expandAbbreviations(streetName.toLowerCase()));

    String streetType;
    String streetNoType;
    if (!m.find()) {
        logger.warning("No street type in " + streetName);
        streetType = "";
        streetNoType = streetName;
    } else {
        streetType = m.group(1);
        streetNoType = m.replaceFirst(" ");
    }
    streetNoType = streetNoType.replaceAll("\\s+", " ")
            .trim(); /* this is to fix case when street type is in the middle */
    streetNoType = WordUtils.capitalizeFully(streetNoType).replaceAll("\\b\\b",
            ""); /* capitalize word parts but avoid 
                   capitalizing single  */

    /* replacement from abbreviated street name parts */

    /* permute street type place in the street name */
    for (String streetNameVar : streetNamePartList.createAllExpansions(streetNoType)) {

        String[] streetNameParts = streetNameVar.split("\\s+");

        /* check each if each street name part is an ordinal */
        ArrayList<Ordinal> ordinals = new ArrayList<Ordinal>(streetNameParts.length);
        int ordinalCount = 0;
        for (int i = 0; i < streetNameParts.length; i++) {
            Ordinal o = ordinalFactory.parse(streetNameParts[i]);
            ordinals.add(o);
            if (o != null)
                ordinalCount++;
        }

        /* permute all parts of the street name except for street type */
        for (FischerKrause fk = new FischerKrause(streetNameParts.length); fk.hasNext();) {
            int idx[] = fk.next();

            StringBuilder sb = new StringBuilder();
            StringBuilder sb_regex = new StringBuilder(); /* StringBuilder for queries with regex */
            for (int i = 0; i < idx.length; i++) {
                sb.append(streetNameParts[idx[i]]);

                if (ordinals.get(idx[i]) != null)
                    sb_regex.append(ordinals.get(idx[i]).getSQLRegex());
                else
                    sb_regex.append(streetNameParts[idx[i]]);

                if (i == idx.length - 1)
                    continue; /* avoid adding space at the end of the string */

                sb.append(' ');
                sb_regex.append(' ');
            }

            /* permutation of the words without street types */
            variations.add(sb.toString() + ' ' + streetType);
            variations.add(streetType + ' ' + sb.toString());

            /* permutation for regexped form of the street name with ordinals regexps */
            if (ordinalCount > 0 && !sb.toString().contains(
                    "(")) { /* make sure that streetname itself does not contain regex-like symbols (typically resulting from parse errors) */
                variations.add("^" + sb_regex.toString() + ' ' + streetType + '$');
                variations.add("^" + streetType + ' ' + sb_regex.toString() + '$');

                /* if the street name starts with an ordinal add permutations with the street type after the 1st ordinal */
                if (ordinals.get(idx[0]) != null && streetNameParts.length > 1) {
                    variations
                            .add(sb.insert(streetNameParts[idx[0]].length() + 1, streetType + ' ').toString());
                    variations.add("^"
                            + sb_regex.insert(ordinals.get(idx[0]).getSQLRegex().length() + 1, streetType + ' ')
                                    .toString()
                            + '$');
                }
            }
        }
    }

    return variations;
}

From source file:com.servoy.j2db.util.Utils.java

public static String longToHexString(long n, int digits) {
    StringBuilder buffer = new StringBuilder(Long.toHexString(n));
    if (buffer.length() > digits)
        return buffer.substring(buffer.length() - digits);
    while (buffer.length() < digits)
        buffer.insert(0, '0');
    return buffer.toString();
}

From source file:net.ymate.framework.core.taglib.bootstrap.PageTag.java

@Override
protected StringBuilder __doTagContent(StringBuilder tagContent, StringBuilder bodyContent) {
    lang = StringUtils.defaultIfBlank(lang, "en");
    charset = StringUtils.defaultIfBlank(charset, "utf-8");
    viewport = StringUtils.defaultIfBlank(viewport, "width=device-width, initial-scale=1");
    ///*from   w w  w  .  ja  v a2s .  c o m*/
    StringBuilder _tmpSB = new StringBuilder("<!DOCTYPE html>");
    _tmpSB.append("<!--[if IE 8]> <html lang=\"").append(lang).append("\" class=\"ie8 no-js\"> <![endif]-->");
    _tmpSB.append("<!--[if IE 9]> <html lang=\"").append(lang).append("\" class=\"ie9 no-js\"> <![endif]-->");
    _tmpSB.append("<!--[if !IE]><!-->");
    _tmpSB.append("<html lang=\"").append(lang).append("\" class=\"no-js\">");
    _tmpSB.append("<!--<![endif]-->");
    _tmpSB.append("<head>");
    _tmpSB.append("<meta charset=\"").append(charset).append("\">");
    _tmpSB.append("<title>").append(StringUtils.trimToEmpty(title)).append("</title>");
    _tmpSB.append("<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">");
    _tmpSB.append("<meta name=\"viewport\" content=\"").append(viewport).append("\">");
    if (StringUtils.isNotBlank(keywords)) {
        _tmpSB.append("<meta name=\"keywords\" content=\"").append(keywords).append("\">");
    }
    if (StringUtils.isNotBlank(description)) {
        _tmpSB.append("<meta name=\"description\" content=\"").append(description).append("\">");
    }
    if (StringUtils.isNotBlank(author)) {
        _tmpSB.append("<meta name=\"author\" content=\"").append(author).append("\">");
    }
    if (StringUtils.isNotBlank(headerBody)) {
        _tmpSB.append(headerBody);
    }
    _tmpSB.append("</head>");
    //
    return super.__doTagContent(tagContent.insert(0, _tmpSB), bodyContent).append("</html>");
}

From source file:com.gargoylesoftware.htmlunit.CodeStyleTest.java

/**
 * Converts the given alerts definition to an array of expressions.
 *//*from   w  w  w. j av a  2  s. co  m*/
private static List<String> alertsToList(final String string) {
    final List<String> list = new ArrayList<>();
    if ("\"\"".equals(string)) {
        list.add(string);
    } else {
        final StringBuilder currentToken = new StringBuilder();

        boolean insideString = true;
        boolean startsWithBraces = false;
        for (final String token : string.split("(?<!\\\\)\"")) {
            insideString = !insideString;
            if (currentToken.length() != 0) {
                currentToken.append('"');
            } else {
                startsWithBraces = token.toString().contains("{");
            }

            if (!insideString && token.startsWith(",") && !startsWithBraces) {
                list.add(currentToken.toString());
                currentToken.setLength(0);
                startsWithBraces = token.toString().contains("{");
            }

            if (!insideString && token.contains("}")) {
                final int curlyIndex = token.indexOf('}') + 1;
                currentToken.append(token.substring(0, curlyIndex));
                list.add(currentToken.toString());
                currentToken.setLength(0);
                currentToken.append(token.substring(curlyIndex));
            } else {
                if (!insideString && token.contains(",") && !startsWithBraces) {
                    final String[] expressions = token.split(",");
                    currentToken.append(expressions[0]);
                    if (currentToken.length() != 0) {
                        list.add(currentToken.toString());
                    }
                    for (int i = 1; i < expressions.length - 1; i++) {
                        list.add(',' + expressions[i]);
                    }
                    currentToken.setLength(0);
                    currentToken.append(',' + expressions[expressions.length - 1]);
                } else {
                    currentToken.append(token);
                }
            }
        }
        if (currentToken.length() != 0) {
            if (!currentToken.toString().contains("\"")) {
                currentToken.insert(0, '"');
            }
            int totalQuotes = 0;
            for (int i = 0; i < currentToken.length(); i++) {
                if (currentToken.charAt(i) == '"' && (i == 0 || currentToken.charAt(i - 1) != '\\')) {
                    totalQuotes++;
                }
            }
            if (totalQuotes % 2 != 0) {
                currentToken.append('"');
            }

            list.add(currentToken.toString());
        }
    }
    return list;
}

From source file:com.sfs.whichdoctor.webservice.RotationServiceImpl.java

/**
 * Get a list of relevant rotations for a person for the specified year.
 *
 * @param PEOsysids the PEOsysids/*from   w w w . j av a 2  s. c  o  m*/
 * @param year the year
 * @param program the program
 * @param training_site_country_code the training_site_country_code
 * @param state the state
 * @param primary_site the primary_site
 * @param training_site the training_site
 * @param division the division
 * @param keyword the keyword
 * @param incl_prep the incl_prep
 * @param incl_non_prep the incl_non_prep
 * @return the rotations by year
 */
public String getRotationsByYear(final int year, final String program, final String training_site_country_code,
        final String state, final String primary_site, final String training_site, final String division,
        final String keyword, final int incl_prep, final int incl_non_prep) {

    StringBuilder results = new StringBuilder();

    if (this.getAllowedAddress()) {

        Calendar periodFrom = Calendar.getInstance();
        Calendar periodTo = Calendar.getInstance();

        periodFrom.set(year, 1, 1, 0, 0);
        periodTo.set(year, 12, 31, 23, 59);

        List<Integer> identifiers = findPeople(year, program, training_site_country_code, state, primary_site,
                training_site, division, keyword, incl_prep, incl_non_prep);

        for (int identifier : identifiers) {

            PersonsRotations pr = loadRotations(identifier, periodFrom, periodTo);

            results.append(this.rotationXmlOutput.getSecondGenRotations(pr.getRotations(), identifier,
                    pr.getDivision(), pr.getCurrentRotations()));
        }
    }

    if (results.length() > 0) {
        results.insert(0, "<trainees>");
        results.append("</trainees>");
    } else {
        results.append("<trainees />");
    }

    return results.toString();
}

From source file:models.Group.java

/**
  * //from w w  w  . jav  a2 s.c o  m
  * 
  * @param page 1
  * @param pageSize ??
  * @param industryId Id?
  * @param privacy ???
  * @param skillTag ?
  * @param groupName ???
  * @param memberUserId ?Id?
  * @param isOwner ????
  * @param orderBy ??????SQL
  * @param isDesc ???
  * @return Page
 */
public static Page<Group> queryByPage(int page, int pageSize, Long industryId, GroupPriv privacy,
        String skillTag, String groupName, List<Type> typeList, Long memberUserId, Boolean isOwner,
        String orderBy, Boolean isDesc) {
    StringBuilder hql = new StringBuilder();
    Map<String, Object> paramMap = new HashMap<>();
    hql.append("from Group g ");
    if (memberUserId != null) {
        hql.append(" left join g.groupmembers gm where gm.userId = :memberUserId ");
        paramMap.put("memberUserId", memberUserId);
    } else {
        hql.append(" where 1 = 1");
    }
    if (memberUserId != null && isOwner != null) {
        hql.append(" and ((g.owner.userId ").append(isOwner ? " = " : " <> ")
                .append(" :ownerUserId and g.type = :hasOwnerType) or g.type <> :hasOwnerType) ");
        paramMap.put("hasOwnerType", Type.NORMAL);
        paramMap.put("ownerUserId", memberUserId);
    }
    if (CollectionUtils.isNotEmpty(typeList)) {
        hql.append(" and g.type in (:typeList) ");
        paramMap.put("typeList", typeList);
    }
    if (null != industryId) {
        hql.append(" and g.industry.id = :industryId ");
        paramMap.put("industryId", industryId);
    }
    if (null != privacy) {
        hql.append(" and g.groupPriv = :privacy ");
        paramMap.put("privacy", privacy);
    }
    if (StringUtils.isNotBlank(skillTag)) {
        hql.append(" and g.tags like :skillTag ");
        paramMap.put("skillTag", "%" + skillTag + "%");
    }
    if (StringUtils.isNotBlank(groupName)) {
        hql.append(" and g.groupName like :groupName ");
        paramMap.put("groupName", "%" + groupName + "%");
    }

    String countHql = "select count(g.id) " + hql.toString();

    // order
    if (StringUtils.isNotBlank(orderBy)) {
        hql.append(" order by g.");
        hql.append(orderBy);
        hql.append(BooleanUtils.isFalse(isDesc) ? " asc " : " desc ");
    } else {
        hql.append(" order by countMem desc, id desc");
    }
    hql.insert(0, "select g ");

    TypedQuery<Group> listTypedQuery = JPA.em().createQuery(hql.toString(), Group.class)
            .setFirstResult((page - 1) * pageSize).setMaxResults(pageSize);
    TypedQuery<Long> countTypedQuery = JPA.em().createQuery(countHql, Long.class);
    for (Entry<String, Object> e : paramMap.entrySet()) {
        listTypedQuery.setParameter(e.getKey(), e.getValue());
        countTypedQuery.setParameter(e.getKey(), e.getValue());
    }

    List<Group> resultList = listTypedQuery.getResultList();
    Long count = countTypedQuery.getSingleResult();

    return new Page<Group>(Constants.SUCESS, count, resultList);
}

From source file:com.funtl.framework.smoke.core.commons.persistence.Page.java

/**
 * ?//  w w w.  j a v  a  2 s.  c  o m
 * <div class="page">${page}</div>
 */
@Override
public String toString() {

    StringBuilder sb = new StringBuilder();
    // ??????
    if (UserAgentUtils.isMobileOrTablet(request)) {
        sb.append("<li class=\"disabled\"><a style=\"height:44px;\" href=\"javascript:\">? ");
        sb.append(
                "<input class=\"pagination-panel-input form-control input-sm input-inline input-mini\" type=\"text\" value=\""
                        + pageNo
                        + "\" onkeypress=\"var e=window.event||this;var c=e.keyCode||e.which;if(c==13)");
        sb.append(funcName + "(this.value," + pageSize + ",'" + funcParam
                + "');\" onclick=\"this.select();\"/> / ");
        sb.append(
                "<input class=\"pagination-panel-input form-control input-sm input-inline input-mini\" type=\"text\" value=\""
                        + pageSize
                        + "\" onkeypress=\"var e=window.event||this;var c=e.keyCode||e.which;if(c==13)");
        sb.append(funcName + "(" + pageNo + ",this.value,'" + funcParam
                + "');\" onclick=\"this.select();\"/> ?");
        sb.append(" " + count + " ?" + (message != null ? message : "") + "</a></li>\n");

        sb.insert(0, "<ul class=\"pagination\" style=\"visibility: visible; margin-top:20px;\">\n")
                .append("</ul>\n");

        sb.append("<div style=\"clear:both;\"></div>");

        return sb.toString();
    }

    if (pageNo == first) {// 
        sb.append(
                "<li class=\"prev disabled\"><a style=\"height:44px; padding-top:11px;\" href=\"javascript:\" title=\"\"><i class=\"fa fa-angle-left\"></i></a></li>\n");
    } else {
        sb.append(
                "<li class=\"prev\"><a style=\"height:44px; padding-top:11px;\" href=\"javascript:\" onclick=\""
                        + funcName + "(" + prev + "," + pageSize + ",'" + funcParam
                        + "');\" title=\"\"><i class=\"fa fa-angle-left\"></i></a></li>\n");
    }

    int begin = pageNo - (length / 2);

    if (begin < first) {
        begin = first;
    }

    int end = begin + length - 1;

    if (end >= last) {
        end = last;
        begin = end - length + 1;
        if (begin < first) {
            begin = first;
        }
    }

    if (begin > first) {
        int i = 0;
        for (i = first; i < first + slider && i < begin; i++) {
            sb.append("<li><a style=\"height:44px; padding-top:11px;\" href=\"javascript:\" onclick=\""
                    + funcName + "(" + i + "," + pageSize + ",'" + funcParam + "');\">" + (i + 1 - first)
                    + "</a></li>\n");
        }
        if (i < begin) {
            sb.append(
                    "<li class=\"disabled\"><a style=\"height:44px; padding-top:11px;\" href=\"javascript:\">...</a></li>\n");
        }
    }

    for (int i = begin; i <= end; i++) {
        if (i == pageNo) {
            sb.append("<li class=\"active\"><a style=\"height:44px; padding-top:11px;\" href=\"javascript:\">"
                    + (i + 1 - first) + "</a></li>\n");
        } else {
            sb.append("<li><a style=\"height:44px; padding-top:11px;\" href=\"javascript:\" onclick=\""
                    + funcName + "(" + i + "," + pageSize + ",'" + funcParam + "');\">" + (i + 1 - first)
                    + "</a></li>\n");
        }
    }

    if (last - end > slider) {
        sb.append(
                "<li class=\"disabled\"><a style=\"height:44px; padding-top:11px;\" href=\"javascript:\">...</a></li>\n");
        end = last - slider;
    }

    for (int i = end + 1; i <= last; i++) {
        sb.append("<li><a style=\"height:44px; padding-top:11px;\" href=\"javascript:\" onclick=\"" + funcName
                + "(" + i + "," + pageSize + ",'" + funcParam + "');\">" + (i + 1 - first) + "</a></li>\n");
    }

    if (pageNo == last) {
        sb.append(
                "<li class=\"next disabled\"><a style=\"height:44px; padding-top:11px;\" href=\"javascript:\" title=\"\"><i class=\"fa fa-angle-right\"></i></a></li>\n");
    } else {
        sb.append(
                "<li class=\"next\"><a style=\"height:44px; padding-top:11px;\" href=\"javascript:\" onclick=\""
                        + funcName + "(" + next + "," + pageSize + ",'" + funcParam
                        + "');\" title=\"\">" + "<i class=\"fa fa-angle-right\"></i></a></li>\n");
    }

    sb.append("<li class=\"disabled\"><a style=\"height:44px;\" href=\"javascript:\">? ");
    sb.append(
            "<input class=\"pagination-panel-input form-control input-sm input-inline input-mini\" type=\"text\" value=\""
                    + pageNo + "\" onkeypress=\"var e=window.event||this;var c=e.keyCode||e.which;if(c==13)");
    sb.append(
            funcName + "(this.value," + pageSize + ",'" + funcParam + "');\" onclick=\"this.select();\"/> / ");
    sb.append(
            "<input class=\"pagination-panel-input form-control input-sm input-inline input-mini\" type=\"text\" value=\""
                    + pageSize + "\" onkeypress=\"var e=window.event||this;var c=e.keyCode||e.which;if(c==13)");
    sb.append(funcName + "(" + pageNo + ",this.value,'" + funcParam
            + "');\" onclick=\"this.select();\"/> ?");
    sb.append(" " + count + " ?" + (message != null ? message : "") + "</a></li>\n");

    sb.insert(0, "<ul class=\"pagination\" style=\"visibility: visible; margin-top:20px;\">\n")
            .append("</ul>\n");

    sb.append("<div style=\"clear:both;\"></div>");

    //      sb.insert(0,"<div class=\"page\">\n").append("</div>\n");

    return sb.toString();
}

From source file:com.evolveum.polygon.scim.StandardScimHandlingStrategy.java

@Override
public void delete(Uid uid, String resourceEndPoint, ScimConnectorConfiguration conf) {

    ServiceAccessManager accessManager = new ServiceAccessManager(conf);

    Header authHeader = accessManager.getAuthHeader();
    String scimBaseUri = accessManager.getBaseUri();

    if (authHeader == null || scimBaseUri.isEmpty()) {

        throw new ConnectorException(
                "The data needed for authorization of request to the provider was not found.");
    }/*from  ww  w .  j av  a  2  s .c  om*/

    HttpClient httpClient = initHttpClient(conf);

    String uri = new StringBuilder(scimBaseUri).append(SLASH).append(resourceEndPoint).append(SLASH)
            .append(uid.getUidValue()).toString();

    LOGGER.info("The uri for the delete request: {0}", uri);
    HttpDelete httpDelete = buildHttpDelete(uri, authHeader);

    try (CloseableHttpResponse response = (CloseableHttpResponse) httpClient.execute(httpDelete)) {
        int statusCode = response.getStatusLine().getStatusCode();

        if (statusCode == 204 || statusCode == 200) {
            LOGGER.info("Deletion of resource was succesfull");
        } else {

            String responseString;
            HttpEntity entity = response.getEntity();

            if (entity != null) {
                responseString = EntityUtils.toString(entity);
            } else {
                responseString = "";
            }

            handleInvalidStatus("while deleting resource. ", responseString, "deleting object", statusCode);
        }

    } catch (ClientProtocolException e) {
        LOGGER.error(
                "An protocol exception has occurred while in the process of deleting a resource object. Possible mismatch in the interpretation of the HTTP specification: {0}",
                e.getLocalizedMessage());
        LOGGER.info(
                "An protocol exception has occurred while in the process of deleting a resource object. Possible mismatch in the interpretation of the HTTP specification: {0}",
                e);
        throw new ConnectionFailedException(
                "An protocol exception has occurred while in the process of deleting a resource object. Possible mismatch in the interpretation of the HTTP specification.",
                e);
    } catch (IOException e) {

        StringBuilder errorBuilder = new StringBuilder(
                "An error has occurred while processing the http response. Occurrence in the process of deleting a resource object with the Uid:  ");

        errorBuilder.append(uid.toString());

        if ((e instanceof SocketTimeoutException || e instanceof NoRouteToHostException)) {

            errorBuilder.insert(0, "Connection timed out. ");

            throw new OperationTimeoutException(errorBuilder.toString(), e);
        } else {

            LOGGER.error(
                    "An error has occurred while processing the http response. Occurrence in the process of deleting a resource object: : {0}",
                    e.getLocalizedMessage());
            LOGGER.info(
                    "An error has occurred while processing the http response. Occurrence in the process of deleting a resource object: : {0}",
                    e);

            throw new ConnectorIOException(errorBuilder.toString(), e);
        }
    }
}