Search in sources :

Example 1 with Type12

use of org.apache.poi.hpbf.model.qcbits.QCPLCBit.Type12 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 2 with Type12

use of org.apache.poi.hpbf.model.qcbits.QCPLCBit.Type12 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 3 with Type12

use of org.apache.poi.hpbf.model.qcbits.QCPLCBit.Type12 in project poi by apache.

the class PublisherTextExtractor method getText.

public String getText() {
    StringBuffer text = new StringBuffer();
    // Get the text from the Quill Contents
    QCBit[] bits = doc.getQuillContents().getBits();
    for (int i = 0; i < bits.length; i++) {
        if (bits[i] != null && bits[i] instanceof QCTextBit) {
            QCTextBit t = (QCTextBit) bits[i];
            text.append(t.getText().replace('\r', '\n'));
        }
    }
    //  how to tie that together.
    if (hyperlinksByDefault) {
        for (int i = 0; i < bits.length; i++) {
            if (bits[i] != null && bits[i] instanceof Type12) {
                Type12 hyperlinks = (Type12) bits[i];
                for (int j = 0; j < hyperlinks.getNumberOfHyperlinks(); j++) {
                    text.append("<");
                    text.append(hyperlinks.getHyperlink(j));
                    text.append(">\n");
                }
            }
        }
    }
    return text.toString();
}
Also used : QCTextBit(org.apache.poi.hpbf.model.qcbits.QCTextBit) QCBit(org.apache.poi.hpbf.model.qcbits.QCBit) Type12(org.apache.poi.hpbf.model.qcbits.QCPLCBit.Type12)

Example 4 with Type12

use of org.apache.poi.hpbf.model.qcbits.QCPLCBit.Type12 in project poi by apache.

the class TestQuillContents method testComplexPLC.

@SuppressWarnings("unused")
@Test
public void testComplexPLC() throws IOException {
    HPBFDocument doc = new HPBFDocument(_samples.openResourceAsStream("Sample.pub"));
    QuillContents qc = doc.getQuillContents();
    assertEquals(20, qc.getBits().length);
    assertTrue(qc.getBits()[10] instanceof Type4);
    assertTrue(qc.getBits()[11] instanceof Type4);
    assertTrue(qc.getBits()[13] instanceof Type0);
    assertTrue(qc.getBits()[14] instanceof Type12);
    assertTrue(qc.getBits()[15] instanceof Type12);
    assertTrue(qc.getBits()[16] instanceof Type8);
    Type4 plc10 = (Type4) qc.getBits()[10];
    Type4 plc11 = (Type4) qc.getBits()[11];
    Type0 plc13 = (Type0) qc.getBits()[13];
    Type12 plc14 = (Type12) qc.getBits()[14];
    Type12 plc15 = (Type12) qc.getBits()[15];
    Type8 plc16 = (Type8) qc.getBits()[16];
    assertEquals(1, plc10.getNumberOfPLCs());
    assertEquals(4, plc10.getPreData().length);
    assertEquals(1, plc10.getPlcValA().length);
    assertEquals(1, plc10.getPlcValB().length);
    assertEquals(0, plc10.getPreData()[0]);
    assertEquals(0, plc10.getPreData()[1]);
    assertEquals(0, plc10.getPreData()[2]);
    assertEquals(0, plc10.getPreData()[3]);
    assertEquals(0x5d0, plc10.getPlcValA()[0]);
    assertEquals(0x800, plc10.getPlcValB()[0]);
    assertEquals(2, plc11.getNumberOfPLCs());
    assertEquals(4, plc11.getPreData().length);
    assertEquals(2, plc11.getPlcValA().length);
    assertEquals(2, plc11.getPlcValB().length);
    assertEquals(0, plc11.getPreData()[0]);
    assertEquals(0, plc11.getPreData()[1]);
    assertEquals(0, plc11.getPreData()[2]);
    assertEquals(0, plc11.getPreData()[3]);
    assertEquals(0x53a, plc11.getPlcValA()[0]);
    assertEquals(0x5d0, plc11.getPlcValB()[0]);
    assertEquals(0xa00, plc11.getPlcValA()[1]);
    assertEquals(0xc00, plc11.getPlcValB()[1]);
    assertEquals(5, plc13.getNumberOfPLCs());
    assertEquals(4, plc13.getPreData().length);
    assertEquals(5, plc13.getPlcValA().length);
    assertEquals(5, plc13.getPlcValB().length);
    assertEquals(0xff00, plc13.getPreData()[0]);
    assertEquals(0, plc13.getPreData()[1]);
    assertEquals(0xf, plc13.getPreData()[2]);
    assertEquals(0, plc13.getPreData()[3]);
    assertEquals(0x19, plc13.getPlcValA()[0]);
    assertEquals(0x00, plc13.getPlcValB()[0]);
    assertEquals(0x27, plc13.getPlcValA()[1]);
    assertEquals(0x00, plc13.getPlcValB()[1]);
    assertEquals(0x36, plc13.getPlcValA()[2]);
    assertEquals(0x00, plc13.getPlcValB()[2]);
    assertEquals(0x42, plc13.getPlcValA()[3]);
    assertEquals(0x00, plc13.getPlcValB()[3]);
    assertEquals(0x50, plc13.getPlcValA()[4]);
    assertEquals(0x00, plc13.getPlcValB()[4]);
    // TODO - test the type 12s
    assertEquals(6, plc16.getNumberOfPLCs());
    assertEquals(7, plc16.getPreData().length);
    assertEquals(6, plc16.getPlcValA().length);
    assertEquals(6, plc16.getPlcValB().length);
    assertEquals(0xff, plc16.getPreData()[0]);
    assertEquals(0, plc16.getPreData()[1]);
    assertEquals(0x56, plc16.getPreData()[2]);
    assertEquals(0, plc16.getPreData()[3]);
    assertEquals(0x62, plc16.getPreData()[4]);
    assertEquals(0, plc16.getPreData()[5]);
    assertEquals(0x3e, plc16.getPreData()[6]);
    assertEquals(0x500000, plc16.getPlcValA()[0]);
    assertEquals(0x570000, plc16.getPlcValB()[0]);
    assertEquals(0x4b0000, plc16.getPlcValA()[1]);
    assertEquals(0x000000, plc16.getPlcValB()[1]);
    assertEquals(0x0a0000, plc16.getPlcValA()[2]);
    assertEquals(0x22000000, plc16.getPlcValB()[2]);
    assertEquals(0x000005, plc16.getPlcValA()[3]);
    assertEquals(0x000004, plc16.getPlcValB()[3]);
    assertEquals(0x000004, plc16.getPlcValA()[4]);
    assertEquals(0x000004, plc16.getPlcValB()[4]);
    assertEquals(0x000004, plc16.getPlcValA()[5]);
    assertEquals(0x000004, plc16.getPlcValB()[5]);
    doc.close();
}
Also used : Type4(org.apache.poi.hpbf.model.qcbits.QCPLCBit.Type4) Type8(org.apache.poi.hpbf.model.qcbits.QCPLCBit.Type8) HPBFDocument(org.apache.poi.hpbf.HPBFDocument) Type0(org.apache.poi.hpbf.model.qcbits.QCPLCBit.Type0) Type12(org.apache.poi.hpbf.model.qcbits.QCPLCBit.Type12) Test(org.junit.Test)

Example 5 with Type12

use of org.apache.poi.hpbf.model.qcbits.QCPLCBit.Type12 in project poi by apache.

the class TestQuillContents method testManyHyperlinks.

@Test
public void testManyHyperlinks() 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();
}
Also used : HPBFDocument(org.apache.poi.hpbf.HPBFDocument) Type12(org.apache.poi.hpbf.model.qcbits.QCPLCBit.Type12) Test(org.junit.Test)

Aggregations

Type12 (org.apache.poi.hpbf.model.qcbits.QCPLCBit.Type12)6 HPBFDocument (org.apache.poi.hpbf.HPBFDocument)5 Test (org.junit.Test)5 QCBit (org.apache.poi.hpbf.model.qcbits.QCBit)1 Type0 (org.apache.poi.hpbf.model.qcbits.QCPLCBit.Type0)1 Type4 (org.apache.poi.hpbf.model.qcbits.QCPLCBit.Type4)1 Type8 (org.apache.poi.hpbf.model.qcbits.QCPLCBit.Type8)1 QCTextBit (org.apache.poi.hpbf.model.qcbits.QCTextBit)1