Package net.sf.jpluck.plucker.parsing.html

Source Code of net.sf.jpluck.plucker.parsing.html.TableCellHandler

package net.sf.jpluck.plucker.parsing.html;

import net.sf.jpluck.plucker.Paragraph;
import net.sf.jpluck.plucker.TableCell;
import net.sf.jpluck.plucker.functions.Align;
import net.sf.jpluck.plucker.parsing.Element;


public class TableCellHandler implements TagHandler, Alignable {
    public void start(HTMLSerializer ser, StyledElement elem) {
        if (ser.isParseTables()) {
            TableCell cell = ser.addCell();
            if (cell != null) {
                String align = elem.getAttributes().getValue("align");
                int alignment = Align.LEFT;
                if (align != null) {
                    align = align.toLowerCase();
                    if (align.equals("right")) {
                        cell.setAlignment(Align.RIGHT);
                    } else if (align.equals("center") || align.equals("middle")) {
                        cell.setAlignment(Align.CENTER);
                    } else if (align.equals("justify")) {
                      cell.setAlignment(Align.JUSTIFY);
                    }
                }
                try {
                  int rowspan = Integer.parseInt(elem.getAttributes().getValue("rowspan"));
                  cell.setRowSpan(rowspan);
                }
                catch (NumberFormatException e) {
                }
        try {
          int colspan = Integer.parseInt(elem.getAttributes().getValue("colspan"));
          cell.setColumnSpan(colspan);
        }
        catch (NumberFormatException e) {
        }
            }
        } else {
            Paragraph p = ser.addParagraph();
            Element table = elem.getAncestor("table");
            if ((table != null) && (elem.getSiblings().length > 0)) {
                try {
                    int border = Integer.parseInt(table.getAttributes().getValue("border"));

                    if (border > 0) {
                        if (elem.getQName().equals("tr")) {
                            border = border * 2;
                        }

                        p.addHorizontalRuleRelative(100, border);
                        p = ser.addParagraph();
                    }
                } catch (Exception e) {
                }
            }
      if (elem.getQName().equals("th")) {
        Style style = new Style();
        style.setBold(true);
        elem.setStyle(style);
      }
        }
    }

    public void end(HTMLSerializer ser, StyledElement elem) {
        ser.addParagraph();
    }
}
TOP

Related Classes of net.sf.jpluck.plucker.parsing.html.TableCellHandler

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.