Search in sources :

Example 1 with HPBFDocument

use of org.apache.poi.hpbf.HPBFDocument in project poi by apache.

the class TestEscherParts method testComplex.

@Test
public void testComplex() throws Exception {
    InputStream is = _samples.openResourceAsStream("SampleBrochure.pub");
    HPBFDocument doc1 = new HPBFDocument(is);
    is.close();
    EscherStm es = doc1.getEscherStm();
    EscherDelayStm eds = doc1.getEscherDelayStm();
    assertNotNull(es);
    assertNotNull(eds);
    assertEquals(30, es.getEscherRecords().length);
    assertEquals(19, eds.getEscherRecords().length);
    // TODO - check contents
    doc1.close();
    // Now do another complex file
    InputStream is2 = _samples.openResourceAsStream("SampleNewsletter.pub");
    HPBFDocument doc2 = new HPBFDocument(is2);
    is2.close();
    es = doc2.getEscherStm();
    eds = doc2.getEscherDelayStm();
    assertNotNull(es);
    assertNotNull(eds);
    assertEquals(51, es.getEscherRecords().length);
    assertEquals(92, eds.getEscherRecords().length);
    doc2.close();
}
Also used : InputStream(java.io.InputStream) HPBFDocument(org.apache.poi.hpbf.HPBFDocument) Test(org.junit.Test)

Example 2 with HPBFDocument

use of org.apache.poi.hpbf.HPBFDocument in project poi by apache.

the class TestQuillContents method testHyperlinkDifferentVersions.

@Test
public void testHyperlinkDifferentVersions() throws IOException {
    HPBFDocument doc;
    QuillContents qc;
    Type12 hlBitA;
    Type12 hlBitB;
    // Latest version
    doc = new HPBFDocument(_samples.openResourceAsStream("Sample.pub"));
    qc = doc.getQuillContents();
    hlBitA = (Type12) qc.getBits()[14];
    assertEquals(2, hlBitA.getNumberOfPLCs());
    assertEquals(2, hlBitA.getNumberOfHyperlinks());
    assertEquals(25, hlBitA.getTextStartAt(0));
    assertEquals(72, hlBitA.getTextStartAt(1));
    assertEquals(87, hlBitA.getAllTextEndAt());
    assertEquals("http://poi.apache.org/", hlBitA.getHyperlink(0));
    assertEquals("C:\\Documents and Settings\\Nick\\My Documents\\Booleans.xlsx", hlBitA.getHyperlink(1));
    hlBitB = (Type12) qc.getBits()[15];
    assertEquals(3, hlBitB.getNumberOfPLCs());
    assertEquals(3, hlBitB.getNumberOfHyperlinks());
    assertEquals(27, hlBitB.getTextStartAt(0));
    assertEquals(37, hlBitB.getTextStartAt(1));
    assertEquals(54, hlBitB.getTextStartAt(2));
    assertEquals(75, hlBitB.getAllTextEndAt());
    assertEquals("", hlBitB.getHyperlink(0));
    assertEquals("mailto:dev@poi.apache.org?subject=HPBF", hlBitB.getHyperlink(1));
    assertEquals("mailto:dev@poi.apache.org?subject=HPBF", hlBitB.getHyperlink(2));
    doc.close();
    // 2000 version
    doc = new HPBFDocument(_samples.openResourceAsStream("Sample2000.pub"));
    qc = doc.getQuillContents();
    hlBitA = (Type12) qc.getBits()[13];
    assertEquals(2, hlBitA.getNumberOfPLCs());
    assertEquals(2, hlBitA.getNumberOfHyperlinks());
    assertEquals(25, hlBitA.getTextStartAt(0));
    assertEquals(72, hlBitA.getTextStartAt(1));
    assertEquals(87, hlBitA.getAllTextEndAt());
    assertEquals("http://poi.apache.org/", hlBitA.getHyperlink(0));
    assertEquals("C:\\Documents and Settings\\Nick\\My Documents\\Booleans.xlsx", hlBitA.getHyperlink(1));
    hlBitB = (Type12) qc.getBits()[14];
    assertEquals(3, hlBitB.getNumberOfPLCs());
    assertEquals(3, hlBitB.getNumberOfHyperlinks());
    assertEquals(27, hlBitB.getTextStartAt(0));
    assertEquals(37, hlBitB.getTextStartAt(1));
    assertEquals(54, hlBitB.getTextStartAt(2));
    assertEquals(75, hlBitB.getAllTextEndAt());
    assertEquals("", hlBitB.getHyperlink(0));
    assertEquals("mailto:dev@poi.apache.org?subject=HPBF", hlBitB.getHyperlink(1));
    assertEquals("mailto:dev@poi.apache.org?subject=HPBF", hlBitB.getHyperlink(2));
    doc.close();
    // 98 version
    doc = new HPBFDocument(_samples.openResourceAsStream("Sample98.pub"));
    qc = doc.getQuillContents();
    hlBitA = (Type12) qc.getBits()[13];
    assertEquals(2, hlBitA.getNumberOfPLCs());
    assertEquals(2, hlBitA.getNumberOfHyperlinks());
    assertEquals(25, hlBitA.getTextStartAt(0));
    assertEquals(72, hlBitA.getTextStartAt(1));
    assertEquals(87, hlBitA.getAllTextEndAt());
    assertEquals("http://poi.apache.org/", hlBitA.getHyperlink(0));
    assertEquals("C:\\Documents and Settings\\Nick\\My Documents\\Booleans.xlsx", hlBitA.getHyperlink(1));
    hlBitB = (Type12) qc.getBits()[14];
    assertEquals(3, hlBitB.getNumberOfPLCs());
    assertEquals(3, hlBitB.getNumberOfHyperlinks());
    assertEquals(27, hlBitB.getTextStartAt(0));
    assertEquals(37, hlBitB.getTextStartAt(1));
    assertEquals(54, hlBitB.getTextStartAt(2));
    assertEquals(75, hlBitB.getAllTextEndAt());
    assertEquals("", hlBitB.getHyperlink(0));
    assertEquals("mailto:dev@poi.apache.org?subject=HPBF", hlBitB.getHyperlink(1));
    assertEquals("mailto:dev@poi.apache.org?subject=HPBF", hlBitB.getHyperlink(2));
    doc.close();
}
Also used : HPBFDocument(org.apache.poi.hpbf.HPBFDocument) Type12(org.apache.poi.hpbf.model.qcbits.QCPLCBit.Type12) Test(org.junit.Test)

Example 3 with HPBFDocument

use of org.apache.poi.hpbf.HPBFDocument in project poi by apache.

the class TestQuillContents method testSimpleHyperlink.

@Test
public void testSimpleHyperlink() throws IOException {
    HPBFDocument doc;
    QuillContents qc;
    Type12 hlBit;
    // Link at 10
    doc = new HPBFDocument(_samples.openResourceAsStream("LinkAt10.pub"));
    qc = doc.getQuillContents();
    hlBit = (Type12) qc.getBits()[12];
    assertEquals(1, hlBit.getNumberOfPLCs());
    assertEquals(1, hlBit.getNumberOfHyperlinks());
    assertEquals(10, hlBit.getTextStartAt(0));
    assertEquals(15, hlBit.getAllTextEndAt());
    assertEquals("http://poi.apache.org/", hlBit.getHyperlink(0));
    doc.close();
    // Longer link at 10
    doc = new HPBFDocument(_samples.openResourceAsStream("LinkAt10Longer.pub"));
    qc = doc.getQuillContents();
    hlBit = (Type12) qc.getBits()[12];
    assertEquals(1, hlBit.getNumberOfPLCs());
    assertEquals(1, hlBit.getNumberOfHyperlinks());
    assertEquals(10, hlBit.getTextStartAt(0));
    assertEquals(15, hlBit.getAllTextEndAt());
    assertEquals("http://poi.apache.org/hpbf/", hlBit.getHyperlink(0));
    doc.close();
    // Link at 20
    doc = new HPBFDocument(_samples.openResourceAsStream("LinkAt20.pub"));
    qc = doc.getQuillContents();
    hlBit = (Type12) qc.getBits()[12];
    assertEquals(1, hlBit.getNumberOfPLCs());
    assertEquals(1, hlBit.getNumberOfHyperlinks());
    assertEquals(20, hlBit.getTextStartAt(0));
    assertEquals(25, hlBit.getAllTextEndAt());
    assertEquals("http://poi.apache.org/", hlBit.getHyperlink(0));
    doc.close();
}
Also used : HPBFDocument(org.apache.poi.hpbf.HPBFDocument) Type12(org.apache.poi.hpbf.model.qcbits.QCPLCBit.Type12) Test(org.junit.Test)

Example 4 with HPBFDocument

use of org.apache.poi.hpbf.HPBFDocument in project poi by apache.

the class TestQuillContents method testText.

@Test
public void testText() throws IOException {
    HPBFDocument doc = new HPBFDocument(_samples.openResourceAsStream("Sample.pub"));
    QuillContents qc = doc.getQuillContents();
    assertEquals(20, qc.getBits().length);
    QCTextBit text = (QCTextBit) qc.getBits()[0];
    String t = text.getText();
    assertStartsWith(t, "This is some text on the first page");
    assertEndsWith(t, "Within doc to page 1\r");
    doc.close();
}
Also used : QCTextBit(org.apache.poi.hpbf.model.qcbits.QCTextBit) HPBFDocument(org.apache.poi.hpbf.HPBFDocument) Test(org.junit.Test)

Example 5 with HPBFDocument

use of org.apache.poi.hpbf.HPBFDocument in project poi by apache.

the class TestQuillContents method testBasics.

@Test
public void testBasics() throws IOException {
    HPBFDocument doc = new HPBFDocument(_samples.openResourceAsStream("Sample.pub"));
    QuillContents qc = doc.getQuillContents();
    assertEquals(20, qc.getBits().length);
    for (int i = 0; i < 19; i++) {
        assertNotNull(qc.getBits()[i]);
    }
    // Last one is blank
    assertNull(qc.getBits()[19]);
    // Should be text, then three STSHs
    assertEquals("TEXT", qc.getBits()[0].getThingType());
    assertEquals("TEXT", qc.getBits()[0].getBitType());
    assertEquals(0, qc.getBits()[0].getOptA());
    assertEquals("STSH", qc.getBits()[1].getThingType());
    assertEquals("STSH", qc.getBits()[1].getBitType());
    assertEquals(0, qc.getBits()[1].getOptA());
    assertEquals("STSH", qc.getBits()[2].getThingType());
    assertEquals("STSH", qc.getBits()[2].getBitType());
    assertEquals(1, qc.getBits()[2].getOptA());
    assertEquals("STSH", qc.getBits()[3].getThingType());
    assertEquals("STSH", qc.getBits()[3].getBitType());
    assertEquals(2, qc.getBits()[3].getOptA());
    doc.close();
}
Also used : HPBFDocument(org.apache.poi.hpbf.HPBFDocument) Test(org.junit.Test)

Aggregations

HPBFDocument (org.apache.poi.hpbf.HPBFDocument)15 Test (org.junit.Test)14 InputStream (java.io.InputStream)6 Type12 (org.apache.poi.hpbf.model.qcbits.QCPLCBit.Type12)5 Type4 (org.apache.poi.hpbf.model.qcbits.QCPLCBit.Type4)2 Type8 (org.apache.poi.hpbf.model.qcbits.QCPLCBit.Type8)2 Type0 (org.apache.poi.hpbf.model.qcbits.QCPLCBit.Type0)1 QCTextBit (org.apache.poi.hpbf.model.qcbits.QCTextBit)1 NPOIFSFileSystem (org.apache.poi.poifs.filesystem.NPOIFSFileSystem)1 POIFSFileSystem (org.apache.poi.poifs.filesystem.POIFSFileSystem)1