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

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

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

import net.sf.jpluck.plucker.Paragraph;

public class HorizontalRuleHandler extends EmptyTagHandler {
    public void start(HTMLSerializer ser, StyledElement elem) {
        String s = elem.getAttributes().getValue("width");
        int width = 100;
        boolean relative = true;
        if (s != null) {
            s = s.trim();
            relative = (s.charAt(s.length() - 1) == '%');
            if (relative) {
                s = s.substring(0, s.length() - 1);

            }
            try {
                width = Integer.parseInt(s);
            } catch (NumberFormatException e) {
                // Assume defaults in case of error
                relative = true;
            }
        }
        s = elem.getAttributes().getValue("size");
        int height = 2;
        try {
            height = Integer.parseInt(s);
        } catch (NumberFormatException e) {
        }

        Paragraph p = ser.addParagraph();
        p.setSpacing(4);
        String align = elem.getAttributes().getValue("align");
        if (align==null) {
            align="center";
        }
        if (align.equalsIgnoreCase("center")) {
            p.addAlignCenter();
        } else if (align.equalsIgnoreCase("right")) {
            p.addAlignRight();
        }
        if (relative) {
            if (width > 100) {
                width = 100;
            }
            p.addHorizontalRuleRelative(width, height);
        } else {
            if (width > 160) {
                width = 160;
            }
            p.addHorizontalRuleAbsolute(width, height);
        }
        ser.addParagraph(4);
    }
}
TOP

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

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.