Search in sources :

Example 1 with ListLevel

use of org.apache.poi.hwpf.model.ListLevel in project poi by apache.

the class HWPFList method setLevelParagraphProperties.

/**
     * Sets the paragraph properties for a particular level of the list.
     * 
     * @param level
     *            The level number.
     * @param pap
     *            The paragraph properties
     */
public void setLevelParagraphProperties(int level, ParagraphProperties pap) {
    ListLevel listLevel = _listData.getLevel(level);
    int styleIndex = _listData.getLevelStyle(level);
    ParagraphProperties base = _styleSheet.getParagraphStyle(styleIndex);
    byte[] grpprl = ParagraphSprmCompressor.compressParagraphProperty(pap, base);
    listLevel.setLevelProperties(grpprl);
}
Also used : ListLevel(org.apache.poi.hwpf.model.ListLevel)

Example 2 with ListLevel

use of org.apache.poi.hwpf.model.ListLevel in project poi by apache.

the class HWPFLister method dumpParagraphLevels.

protected void dumpParagraphLevels(ListTables listTables, ParagraphProperties paragraph) {
    if (paragraph.getIlfo() != 0) {
        final LFO lfo = listTables.getLfo(paragraph.getIlfo());
        System.out.println("PAP's LFO: " + lfo);
        final LFOData lfoData = listTables.getLfoData(paragraph.getIlfo());
        System.out.println("PAP's LFOData: " + lfoData);
        if (lfo != null) {
            final ListLevel listLevel = listTables.getLevel(lfo.getLsid(), paragraph.getIlvl());
            System.out.println("PAP's ListLevel: " + listLevel);
            if (listLevel.getGrpprlPapx() != null) {
                System.out.println("PAP's ListLevel PAPX:");
                dumpSprms(new SprmIterator(listLevel.getGrpprlPapx(), 0), "* ");
            }
            if (listLevel.getGrpprlPapx() != null) {
                System.out.println("PAP's ListLevel CHPX:");
                dumpSprms(new SprmIterator(listLevel.getGrpprlChpx(), 0), "* ");
            }
        }
    }
}
Also used : SprmIterator(org.apache.poi.hwpf.sprm.SprmIterator) LFO(org.apache.poi.hwpf.model.LFO) LFOData(org.apache.poi.hwpf.model.LFOData) ListLevel(org.apache.poi.hwpf.model.ListLevel)

Example 3 with ListLevel

use of org.apache.poi.hwpf.model.ListLevel in project poi by apache.

the class TestBug50075 method test.

public void test() {
    HWPFDocument doc = HWPFTestDataSamples.openSampleFile("Bug50075.doc");
    Range range = doc.getRange();
    assertEquals(1, range.numParagraphs());
    ListEntry entry = (ListEntry) range.getParagraph(0);
    LFO override = doc.getListTables().getLfo(entry.getIlfo());
    ListLevel level = doc.getListTables().getLevel(override.getLsid(), entry.getIlvl());
    // the bug reproduces, if this call fails with NullPointerException
    level.getNumberText();
}
Also used : HWPFDocument(org.apache.poi.hwpf.HWPFDocument) LFO(org.apache.poi.hwpf.model.LFO) ListLevel(org.apache.poi.hwpf.model.ListLevel)

Example 4 with ListLevel

use of org.apache.poi.hwpf.model.ListLevel in project poi by apache.

the class TestLists method testSpecificNumberedOrderedListFeatures.

public void testSpecificNumberedOrderedListFeatures() throws IOException {
    HWPFDocument doc = HWPFTestDataSamples.openSampleFile("Lists.doc");
    Range r = doc.getRange();
    //29 = OL 2.2.1
    for (int i = 26; i < 30; i++) {
        Paragraph p = r.getParagraph(i);
        assertTrue(p.isInList());
        HWPFList list = p.getList();
        ListLevel level = list.getLVL((char) p.getIlvl());
        assertFalse(level.isLegalNumbering());
        assertEquals(-1, level.getRestart());
    }
    Paragraph p = r.getParagraph(26);
    HWPFList list = p.getList();
    ListLevel level = list.getLVL((char) p.getIlvl());
    byte[] lvl = level.getLevelNumberingPlaceholderOffsets();
    assertEquals((byte) 1, lvl[0]);
    assertEquals((byte) 0, lvl[1]);
    p = r.getParagraph(27);
    list = p.getList();
    level = list.getLVL((char) p.getIlvl());
    lvl = level.getLevelNumberingPlaceholderOffsets();
    assertEquals((byte) 1, lvl[0]);
    assertEquals((byte) 3, lvl[1]);
    p = r.getParagraph(29);
    list = p.getList();
    level = list.getLVL((char) p.getIlvl());
    lvl = level.getLevelNumberingPlaceholderOffsets();
    assertEquals((byte) 1, lvl[0]);
    assertEquals((byte) 3, lvl[1]);
    assertEquals((byte) 5, lvl[2]);
}
Also used : HWPFDocument(org.apache.poi.hwpf.HWPFDocument) ListLevel(org.apache.poi.hwpf.model.ListLevel)

Example 5 with ListLevel

use of org.apache.poi.hwpf.model.ListLevel in project poi by apache.

the class Paragraph method newParagraph.

@Internal
public static Paragraph newParagraph(Range parent, PAPX papx) {
    HWPFDocumentCore doc = parent._doc;
    ListTables listTables = doc.getListTables();
    StyleSheet styleSheet = doc.getStyleSheet();
    ParagraphProperties properties = new ParagraphProperties();
    properties.setIstd(papx.getIstd());
    properties = newParagraph_applyStyleProperties(styleSheet, papx, properties);
    properties = ParagraphSprmUncompressor.uncompressPAP(properties, papx.getGrpprl(), 2);
    if (properties.getIlfo() != 0 && listTables != null) {
        LFO lfo = null;
        try {
            lfo = listTables.getLfo(properties.getIlfo());
        } catch (NoSuchElementException exc) {
            log.log(POILogger.WARN, "Paragraph refers to LFO #", properties.getIlfo(), " that does not exists");
        }
        if (lfo != null) {
            final ListLevel listLevel = listTables.getLevel(lfo.getLsid(), properties.getIlvl());
            if (listLevel != null && listLevel.getGrpprlPapx() != null) {
                properties = ParagraphSprmUncompressor.uncompressPAP(properties, listLevel.getGrpprlPapx(), 0);
                // reapply style and local PAPX properties
                properties = newParagraph_applyStyleProperties(styleSheet, papx, properties);
                properties = ParagraphSprmUncompressor.uncompressPAP(properties, papx.getGrpprl(), 2);
            }
        }
    }
    if (properties.getIlfo() > 0)
        return new ListEntry(papx, properties, parent);
    return new Paragraph(papx, properties, parent);
}
Also used : HWPFDocumentCore(org.apache.poi.hwpf.HWPFDocumentCore) StyleSheet(org.apache.poi.hwpf.model.StyleSheet) LFO(org.apache.poi.hwpf.model.LFO) ListTables(org.apache.poi.hwpf.model.ListTables) NoSuchElementException(java.util.NoSuchElementException) ListLevel(org.apache.poi.hwpf.model.ListLevel) Internal(org.apache.poi.util.Internal)

Aggregations

ListLevel (org.apache.poi.hwpf.model.ListLevel)7 LFO (org.apache.poi.hwpf.model.LFO)3 HWPFDocument (org.apache.poi.hwpf.HWPFDocument)2 NoSuchElementException (java.util.NoSuchElementException)1 HWPFDocumentCore (org.apache.poi.hwpf.HWPFDocumentCore)1 LFOData (org.apache.poi.hwpf.model.LFOData)1 ListFormatOverrideLevel (org.apache.poi.hwpf.model.ListFormatOverrideLevel)1 ListTables (org.apache.poi.hwpf.model.ListTables)1 StyleSheet (org.apache.poi.hwpf.model.StyleSheet)1 SprmIterator (org.apache.poi.hwpf.sprm.SprmIterator)1 Internal (org.apache.poi.util.Internal)1