Example usage for com.lowagie.text List ORDERED

List of usage examples for com.lowagie.text List ORDERED

Introduction

In this page you can find the example usage for com.lowagie.text List ORDERED.

Prototype

boolean ORDERED

To view the source code for com.lowagie.text List ORDERED.

Click Source Link

Document

a possible value for the numbered parameter

Usage

From source file:com.amphisoft.epub2pdf.content.XhtmlHandler.java

License:Open Source License

@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) {
    /*// w  w w.j a va 2s  . co  m
    if("ol".equals(qName) || "ul".equals(qName) || "li".equals(qName)) {
       System.err.print(qName + " ");
    }
     */
    currentSaxElemId = saxElemIdCounter;

    Map<String, String> attrMap = new HashMap<String, String>();
    // parse attributes
    for (int ai = 0; ai < attributes.getLength(); ai++) {
        attrMap.put(attributes.getQName(ai), attributes.getValue(ai));
    }
    String idAttr = attrMap.get("id");
    if (idAttr == null) {
        idAttr = "";
    }
    String className = attrMap.get("class");
    if (className == null) {
        className = "";
    }
    SaxElement sE = new SaxElement(qName, saxElemIdCounter++, className, idAttr, currentITextStyle);
    //printlnerr("startElement: " + sE.toString());
    saxElementStack.push(sE);

    try {
        if (attrMap.get("class") != null) {
            String[] elemClasses = attrMap.get("class").split(" ");

            for (String eClass : elemClasses) {

                StyleSpecText classTextStyles = styleMap.getTextStyleSpecFor(qName, eClass);
                if (classTextStyles != null) {
                    sE.applyTextStyles(classTextStyles);
                }

            }
        }
        if (attrMap.get("style") != null) {
            // TODO this needs more thought, and careful tracking of which tags are still open, etc.
            //String styleSource = attrMap.get("style");
            //CssStyleMap styleTagStyles = cssParser.getStylesFromStyleTag(styleSource);
            // ...
        }
        if (sE.textStyles == null) {
            try {
                int stackSize = saxElementStack.size();
                if (stackSize > 1) {
                    SaxElement enclosingElement = saxElementStack.elementAt(stackSize - 2);
                    StyleSpecText enclosingSST = enclosingElement.textStyles;
                    if (enclosingSST != null)
                        sE.applyTextStyles(enclosingSST);
                }
            } catch (Exception e) {
            }
        }

        StyleSpecText currentTextStyles = sE.textStyles;
        if (currentTextStyles != null) {
            if (currentTextStyles.isBold()) {
                currentITextStyle |= Font.BOLD;
            }
            if (currentTextStyles.isItalic()) {
                currentITextStyle |= Font.ITALIC;
            }
        }

        //System.err.println("PUSH -> " + saxElementStack);

        previousTag = currentTag;
        currentTag = qName;
        if (document.isOpen()) {
            if (XhtmlTags.NEWLINE.equals(qName)) {
                if (stack.size() > 0) {
                    TextElementArray currentTEA = (TextElementArray) stack.peek();
                    currentTEA.add(Chunk.NEWLINE);
                } else if (specialParagraph != null) {
                    specialParagraph.add(Chunk.NEWLINE);
                }
            }

            updateStack();

            String xmlElementId = attrMap.get("id");

            if (XhtmlTags.ANCHOR.equals(qName)) {
                //concession to nonconformists...
                if (xmlElementId == null) {
                    xmlElementId = attrMap.get("name");
                }
                Anchor anchor = textFactory.newAnchor();
                String ref = attrMap.get(XhtmlTags.REFERENCE);

                if (ref != null) {
                    int aNameStartIdx = ref.lastIndexOf("#") + 1;
                    ref = ref.substring(aNameStartIdx);
                    anchor.setReference(ref);
                }
                if (xmlElementId != null) {
                    anchor.setName(xmlElementId);
                }
                pushToStack(anchor);
            } else {
                if (xmlElementId != null) {
                    //flushStack();
                    Anchor dest = textFactory.newAnchor();
                    dest.setName(xmlElementId);
                    pushToStack(dest);
                    //flushStack();
                }
                for (int i = 0; i < 6; i++) {
                    if (XhtmlTags.H[i].equals(qName)) {
                        flushStack();
                        freshParagraph = true;
                        currentITextStyle |= Font.BOLD;
                        specialParagraph = textFactory.newHeadline(i + 1);
                        return;
                    }
                }
                if ("blockquote".equals(qName)) {
                    flushStack();
                    freshParagraph = true;
                    Paragraph p = textFactory.newParagraph();
                    p.setIndentationLeft(50);
                    p.setIndentationRight(20);
                    p.setAlignment(defaultAlignment);
                    pushToStack(p);
                } else if (XhtmlTags.PARAGRAPH.equals(qName)) {
                    flushStack();
                    freshParagraph = true;
                    Paragraph p = textFactory.newParagraph();
                    pushToStack(p);
                } else if (XhtmlTags.DIV.equals(qName)) {
                    if (stack.size() > 0 && stack.peek().getChunks().size() > 0) {
                        flushStack();
                    }
                    if (stack.size() == 0) {
                        Paragraph brandNewParagraph = textFactory.newParagraph();
                        pushToStack(brandNewParagraph);
                        freshParagraph = true;
                    }
                } else if (XhtmlTags.PRE.equals(qName)) {
                    flushStack();
                    freshParagraph = true;
                    Paragraph p = textFactory.newParagraphPre();
                    pushToStack(p);
                } else if (XhtmlTags.ORDEREDLIST.equals(qName)) {
                    flushStack();
                    List oList = new List(List.ORDERED, 10);
                    pushToStack(oList);
                } else if (XhtmlTags.UNORDEREDLIST.equals(qName)) {
                    flushStack();
                    List uList = new List(List.UNORDERED, 10);
                    pushToStack(uList);
                } else if (XhtmlTags.LISTITEM.equals(qName)) {
                    freshParagraph = true;
                    ListItem listItem = new ListItem();
                    pushToStack(listItem);
                } else if (XhtmlTags.IMAGE.equals(qName)) {
                    handleImage(attributes);
                } else if (qName != null && qName.endsWith("image")) {
                    handleSvgImage(attributes);
                } else if (XhtmlTags.LINK.equals(qName)) {
                    // if it's a stylesheet, parse it & update current-style
                    if ("stylesheet".equals(attrMap.get("rel")) && "text/css".equals(attrMap.get("type"))
                            && attrMap.get("href") != null) {
                        String cssHref = xhtmlDir.getAbsoluteFile().toURI().toString() + attrMap.get("href");
                        CssStyleMap stylesFromLink = cssParser.getStylesFromFileURI(cssHref);
                        if (stylesFromLink != null) {
                            styleMap.updateWith(stylesFromLink);
                        }
                    }
                } else if (XhtmlTags.STYLE.equals(qName)) {
                    inStyleTag = true;
                } else if (XhtmlTags.EM.equals(qName) || "I".equals(qName.toUpperCase())) {
                    currentITextStyle |= Font.ITALIC;
                } else if (XhtmlTags.STRONG.equals(currentTag) || "B".equals(qName.toUpperCase())) {
                    currentITextStyle |= Font.BOLD;
                }

            }

        } else if (XhtmlTags.BODY.equals(qName)) {
            document.open();
            freshParagraph = true;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    //printlnerr("leaving startElement " + localName + "; stack: " + stackStatus());
}

From source file:com.bibisco.export.ITextExporter.java

License:GNU General Public License

@Override
public void startOrderedList() {
    mList = new List(List.ORDERED);
    mList.setIndentationLeft(LIST_INDENTATION_LEFT);
    mList.setAlignindent(true);//from  www  .j  a va 2s.  c o m
    mList.setAutoindent(true);
}

From source file:questions.objects.NestingLists.java

public static void main(String[] args) throws IOException, DocumentException {
    Document document = new Document();
    PdfWriter.getInstance(document, new FileOutputStream(RESULT));
    document.open();//from  www .java 2  s  . c om
    List list1 = new List(List.ORDERED, 20);
    list1.add(new ListItem(new Chunk("Level 1 - Item 1")));
    list1.add(new ListItem(new Chunk("Level 1 - Item 2")));
    list1.add(new ListItem(new Chunk("Level 1 - Item 3")));

    List list2 = new List(List.ORDERED, 20);
    list2.add(new ListItem(new Chunk("Level 2 - Item 1")));
    list2.add(new ListItem(new Chunk("Level 2 - Item 2")));

    List list3 = new List(List.ORDERED, 20);
    list3.add(new ListItem(new Chunk("Level 3 - Item 1")));
    list3.add(new ListItem(new Chunk("Level 3 - Item 2")));
    list3.add(new ListItem(new Chunk("Level 3 - Item 3")));
    list3.add(new ListItem(new Chunk("Level 3 - Item 4")));
    list2.add(list3);

    list1.add(list2);
    list1.add(new ListItem(new Chunk("Level 1 - Item 4")));

    document.add(list1);
    document.close();
}