Esempio n. 1
0
 public void testNewlines() {
   assertEquals("", StringUtils.newlinesToXHTMLBreaks(null));
   assertEquals("", StringUtils.newlinesToXHTMLBreaks(""));
   assertEquals("\n<br />", StringUtils.newlinesToXHTMLBreaks("\n"));
   assertEquals("\n<br />", StringUtils.newlinesToXHTMLBreaks("\r"));
   assertEquals("\n<br />", StringUtils.newlinesToXHTMLBreaks("\r\n"));
   assertEquals("hello\n<br />world", StringUtils.newlinesToXHTMLBreaks("hello\nworld"));
   assertEquals("hello\n<br />world", StringUtils.newlinesToXHTMLBreaks("hello\rworld"));
   assertEquals("hello\n<br />world", StringUtils.newlinesToXHTMLBreaks("hello\r\nworld"));
 }
Esempio n. 2
0
  protected void doOutputField(Field field) {
    Format format = outputCellStart(field);
    // Style attribute courtesy of Brendon Price <*****@*****.**>
    out.print("<span style=\"");
    if (format.getFontFamilyName() != null)
      out.print("font-family: " + format.getFontFamilyName() + "; ");
    out.print("font-size: " + format.getSize() + "pt; ");
    outputColor(format.getColor());

    // Border code courtesy of Khadiyd Idris <*****@*****.**>
    Border b = field.getBorderOrDefault();
    String bcolor = "black";
    if (b.getColor() != null) {
      bcolor =
          "#"
              + Integer.toHexString(b.getColor().getRed())
              + Integer.toHexString(b.getColor().getGreen())
              + Integer.toHexString(b.getColor().getBlue());
    }

    if (b.getTop() != null)
      out.print("border-top: solid " + bcolor + " " + b.getTop().getThickness() + "pt; ");
    if (b.getLeft() != null)
      out.print("border-left: solid " + bcolor + " " + b.getLeft().getThickness() + "pt; ");
    if (b.getBottom() != null)
      out.print("border-bottom: solid " + bcolor + " " + b.getBottom().getThickness() + "pt; ");
    if (b.getRight() != null)
      out.print("border-right: solid " + bcolor + " " + b.getRight().getThickness() + "pt; ");

    out.print("\">");

    if (format.isBold()) out.print("<b>");
    if (format.isItalic()) out.print("<i>");
    if (format.isUnderline()) out.print("<u>");

    String str = field.toString();
    if (str == null || str.length() == 0) str = "&nbsp;";

    // Fix courtesy of Brendon Price <*****@*****.**>
    if ("&nbsp;".equals(str)) out.print(str);
    else out.print(StringUtils.newlinesToXHTMLBreaks(StringUtils.escapeHTML(str)));

    if (format.isUnderline()) out.print("</u>");
    if (format.isItalic()) out.print("</i>");
    if (format.isBold()) out.print("</b>");
    out.print("</span>");

    outputCellEnd();
  }