Java Code Examples for org.apache.commons.text.WordUtils#wrap()

The following examples show how to use org.apache.commons.text.WordUtils#wrap() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TxtTablePrinter.java    From openemm with GNU Affero General Public License v3.0 6 votes vote down vote up
private StringBuilder getRowsBlock(List<String> order, Map<String, ColumnDefinition> columnDefinitions, Row row) {
    List<String[]> textBlocks = new ArrayList<>();
    Map<String, String> columns = row.getColumns();
    int maxHeight = 0;
    for (String columnKey : order) {
        String columnText = columns.get(columnKey);
        String[] blockLines;
        if (StringUtils.isNotBlank(columnText)) {
            int columnWidth = columnDefinitions.get(columnKey).getWidth();
            String columnBlock = WordUtils.wrap(columnText, columnWidth, lineBreaker, true);
            blockLines = columnBlock.split("(" + lineBreaker + "|\r|\n)");
        } else {
            blockLines = new String[]{emptyValue};
        }
        textBlocks.add(blockLines);
        maxHeight = maxHeight < blockLines.length ? blockLines.length : maxHeight;
    }

    return appendTextBlocks(order, columnDefinitions, textBlocks, maxHeight);
}
 
Example 2
Source File: CsdbReleasesSD2IEC.java    From petscii-bbs with Mozilla Public License 2.0 6 votes vote down vote up
private void listPosts(String rssUrl) throws IOException, FeedException {
    cls();
    drawLogo();
    if (isEmpty(posts)) {
        waitOn();
        posts = getPosts(rssUrl, currentPage, pageSize);
        waitOff();
    }
    for (Map.Entry<Integer, ReleaseEntry> entry: posts.entrySet()) {
        int i = entry.getKey();
        ReleaseEntry post = entry.getValue();
        write(WHITE); print(i + "."); write(GREY3);
        final int iLen = 37-String.valueOf(i).length();
        String title = post.title + (isNotBlank(post.releasedBy) ? " (" + post.releasedBy+")" : EMPTY);
        String line = WordUtils.wrap(filterPrintable(HtmlUtils.htmlClean(title)), iLen, "\r", true);
        println(line.replaceAll("\r", "\r " + repeat(" ", 37-iLen)));
    }
    newline();
}
 
Example 3
Source File: CsdbReleases.java    From petscii-bbs with Mozilla Public License 2.0 6 votes vote down vote up
private void listPosts(String rssUrl) throws IOException, FeedException {
    cls();
    drawLogo();
    if (isEmpty(posts)) {
        waitOn();
        posts = getPosts(rssUrl, currentPage, pageSize);
        waitOff();
    }
    for (Map.Entry<Integer, ReleaseEntry> entry: posts.entrySet()) {
        int i = entry.getKey();
        ReleaseEntry post = entry.getValue();
        write(WHITE); print(i + "."); write(GREY3);
        final int iLen = 37-String.valueOf(i).length();
        String title = post.title + (isNotBlank(post.releasedBy) ? " (" + post.releasedBy+")" : EMPTY);
        String line = WordUtils.wrap(filterPrintable(HtmlUtils.htmlClean(title)), iLen, "\r", true);
        println(line.replaceAll("\r", "\r " + repeat(" ", 37-iLen)));
    }
    newline();
}
 
Example 4
Source File: GoogleBloggerProxy.java    From petscii-bbs with Mozilla Public License 2.0 6 votes vote down vote up
protected void listPosts() throws IOException {
    cls();
    drawLogo();
    if (posts == null) {
        waitOn();
        posts = getPosts();
        waitOff();
    }
    for (Map.Entry<Integer, Post> entry: posts.entrySet()) {
        int i = entry.getKey();
        Post post = entry.getValue();
        write(WHITE); print(i + "."); write(GREY3);
        final int iLen = 37-String.valueOf(i).length();
        String line = WordUtils.wrap(filterPrintable(HtmlUtils.htmlClean(post.getTitle())), iLen, "\r", true);
        println(line.replaceAll("\r", "\r " + repeat(" ", 37-iLen)));
    }
    newline();
}
 
Example 5
Source File: WordpressProxy.java    From petscii-bbs with Mozilla Public License 2.0 6 votes vote down vote up
protected void listPosts() throws Exception {
    cls();
    drawLogo();
    if (isEmpty(posts)) {
        waitOn();
        posts = getPosts(currentPage, pageSize);
        waitOff();
    }
    for (Map.Entry<Integer, Post> entry: posts.entrySet()) {
        int i = entry.getKey();
        Post post = entry.getValue();
        write(WHITE); print(i + "."); write(GREY3);
        final int iLen = 37-String.valueOf(i).length();
        String line = WordUtils.wrap(filterPrintable(HtmlUtils.htmlClean(post.title)), iLen, "\r", true);
        println(line.replaceAll("\r", "\r " + repeat(" ", 37-iLen)));
    }
    newline();
}
 
Example 6
Source File: InternetBrowser.java    From petscii-bbs with Mozilla Public License 2.0 5 votes vote down vote up
private void listLinks(Document webpage) throws Exception {
    clearForLinks();
    gotoXY(0,4);
    write(ORANGE);
    println("Links On Page:");
    println();

    List<Entry> entries = getAllLinks(webpage);

    if (isEmpty(entries)) {
        write(RED);
        println("Zero result page - press any key");
        flush();
        resetInput();
        readKey();
        return;
    }

    links = getLinksForPage(entries, __currentPage, __pageSize);

    for (Map.Entry<Integer, Entry> entry: links.entrySet()) {
        int i = entry.getKey();
        Entry post = entry.getValue();

        write(WHITE);
        print(i + ".");
        write(GREY3);

        final int iLen = 37 - String.valueOf(i).length(); //I'm guessing something to do with the row width

        String title = post.name;
        String line = WordUtils.wrap(filterPrintable(HtmlUtils.htmlClean(title)), iLen, "\r", true);

        println(line.replaceAll("\r", "\r " + repeat(" ", 37-iLen)));
    }
    newline();
}
 
Example 7
Source File: ArnoldC64.java    From petscii-bbs with Mozilla Public License 2.0 5 votes vote down vote up
private void listPosts(List<Entry> entries) {
    drawLogo();
    posts = getPosts(entries, currentPage, pageSize);
    for (Map.Entry<Integer, Entry> entry: posts.entrySet()) {
        int i = entry.getKey();
        Entry post = entry.getValue();
        write(WHITE); print(i + "."); write(GREY3);
        final int iLen = 37-String.valueOf(i).length();
        String title = post.name;
        String line = WordUtils.wrap(filterPrintable(HtmlUtils.htmlClean(title)), iLen, "\r", true);
        println(line.replaceAll("\r", "\r " + repeat(" ", 37-iLen)));
    }
    newline();
}
 
Example 8
Source File: AnsiParagraphBuilder.java    From halyard with Apache License 2.0 5 votes vote down vote up
@Override
public String toString() {
  StringBuilder bodyBuilder = new StringBuilder();

  for (AnsiSnippet snippet : snippets) {
    bodyBuilder.append(snippet.toString());
  }

  String body = bodyBuilder.toString();

  if (maxLineWidth < 0) {
    return body;
  }

  String[] lines = body.split("\n");

  StringBuilder lineBuilder = new StringBuilder();

  for (int i = 0; i < lines.length; i++) {
    String line = lines[i];

    line = WordUtils.wrap(line, maxLineWidth, "\n" + getIndent(), false);

    if (indentFirstLine) {
      line = getIndent() + line;
    }

    lineBuilder.append(line);

    if (i != lines.length - 1) {
      lineBuilder.append("\n");
    }
  }

  return lineBuilder.toString();
}
 
Example 9
Source File: PTextWord.java    From jphp with Apache License 2.0 5 votes vote down vote up
@Signature
public PTextWord wrap(Environment env, int lineLength,
                      @Optional("null") Memory newLineString,
                      @Optional("false") boolean wrapLongWords) {
    return new PTextWord(env, WordUtils.wrap(
            text, lineLength, newLineString.isNull() ? null : newLineString.toString(), wrapLongWords
    ));
}