Examples of HWPFDocument


Examples of org.apache.poi.hwpf.HWPFDocument

  /**
   * Test (more "confirm" than test) that we have the general structure that we expect to have.
   */
  public void testDocStructure() throws Exception {

    HWPFDocument daDoc = new HWPFDocument(new FileInputStream(illustrativeDocFile));

    Range range = daDoc.getRange();
    assertEquals(414, range.text().length());

    assertEquals(1, range.numSections());
    Section section = range.getSection(0);
    assertEquals(414, section.text().length());
View Full Code Here

Examples of org.apache.poi.hwpf.HWPFDocument

  /**
   * Test that we can replace text in our Range with Unicode text.
   */
  public void testRangeReplacementOne() throws Exception {

    HWPFDocument daDoc = new HWPFDocument(new FileInputStream(illustrativeDocFile));

    Range range = daDoc.getRange();
    assertEquals(1, range.numSections());

    Section section = range.getSection(0);
    assertEquals(5, section.numParagraphs());

View Full Code Here

Examples of org.apache.poi.hwpf.HWPFDocument

  /**
   * Test that we can replace text in our Range with Unicode text.
   */
  public void testRangeReplacementAll() throws Exception {

    HWPFDocument daDoc = new HWPFDocument(new FileInputStream(illustrativeDocFile));

    Range range = daDoc.getRange();
    assertEquals(1, range.numSections());

    Section section = range.getSection(0);
    assertEquals(5, section.numParagraphs());

View Full Code Here

Examples of org.apache.poi.hwpf.HWPFDocument

    protected void setUp() throws Exception {
    String dirname = System.getProperty("HWPF.testdata.path");

    String filename = dirname + "/test2.doc";
    doc = new HWPFDocument(new FileInputStream(filename));
    }
View Full Code Here

Examples of org.apache.poi.hwpf.HWPFDocument

     *  embeded word documents
     * @throws Exception
     */
    public void testExtractFromEmbeded() throws Exception {
      POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(filename3));
      HWPFDocument doc;
      WordExtractor extractor3;

      DirectoryNode dirA = (DirectoryNode)
      fs.getRoot().getEntry("MBD0000A3B7");
      DirectoryNode dirB = (DirectoryNode)
        fs.getRoot().getEntry("MBD0000A3B2");

      // Should have WordDocument and 1Table
      assertNotNull(dirA.getEntry("1Table"));
      assertNotNull(dirA.getEntry("WordDocument"));

      assertNotNull(dirB.getEntry("1Table"));
      assertNotNull(dirB.getEntry("WordDocument"));

      // Check each in turn
      doc = new HWPFDocument(dirA, fs);
      extractor3 = new WordExtractor(doc);

      assertNotNull(extractor3.getText());
      assertTrue(extractor3.getText().length() > 20);
      assertEquals("I am a sample document\r\nNot much on me\r\nI am document 1\r\n",
          extractor3.getText());
      assertEquals("Sample Doc 1", extractor3.getSummaryInformation().getTitle());
      assertEquals("Sample Test", extractor3.getSummaryInformation().getSubject());


      doc = new HWPFDocument(dirB, fs);
      extractor3 = new WordExtractor(doc);

      assertNotNull(extractor3.getText());
      assertTrue(extractor3.getText().length() > 20);
      assertEquals("I am another sample document\r\nNot much on me\r\nI am document 2\r\n",
View Full Code Here

Examples of org.apache.poi.hwpf.HWPFDocument

      assertEquals("Another Sample Test", extractor3.getSummaryInformation().getSubject());
    }

    public void testWithHeader() throws Exception {
      // Non-unicode
      HWPFDocument doc = new HWPFDocument(
          new FileInputStream(filename4)
      );
      extractor = new WordExtractor(doc);

      assertEquals(
          "First header column!\tMid header Right header!\n",
          extractor.getHeaderText()
      );

      String text = extractor.getText();
      assertTrue(
          text.indexOf("First header column!") > -1
      );


      // Unicode
      doc = new HWPFDocument(
          new FileInputStream(filename5)
      );
      extractor = new WordExtractor(doc);

      assertEquals(
View Full Code Here

Examples of org.apache.poi.hwpf.HWPFDocument

      );
    }

    public void testWithFooter() throws Exception {
      // Non-unicode
      HWPFDocument doc = new HWPFDocument(
          new FileInputStream(filename4)
      );
      extractor = new WordExtractor(doc);

      assertEquals(
          "Footer Left\tFooter Middle Footer Right\n",
          extractor.getFooterText()
      );

      String text = extractor.getText();
      assertTrue(
          text.indexOf("Footer Left") > -1
      );


      // Unicode
      doc = new HWPFDocument(
          new FileInputStream(filename5)
      );
      extractor = new WordExtractor(doc);

      assertEquals(
View Full Code Here

Examples of org.apache.poi.hwpf.HWPFDocument

  /**
   * Check that we do the positions correctly when
   *  working with pure-ascii
   */
  public void testAsciiParts() throws Exception {
    HWPFDocument doc = new HWPFDocument(
        new FileInputStream(new File(dirname, "ThreeColHeadFoot.doc"))
    );
    TextPieceTable tbl = doc.getTextTable();

    // All ascii, so stored in one big lump
    assertEquals(1, tbl.getTextPieces().size());
    TextPiece tp = (TextPiece)tbl.getTextPieces().get(0);

    assertEquals(0, tp.getStart());
    assertEquals(339, tp.getEnd());
    assertEquals(339, tp.characterLength());
    assertEquals(339, tp.bytesLength());
    assertTrue(tp.getStringBuffer().toString().startsWith("This is a sample word document"));


    // Save and re-load
    HWPFDocument docB = saveAndReload(doc);
    tbl = docB.getTextTable();

    assertEquals(1, tbl.getTextPieces().size());
    tp = (TextPiece)tbl.getTextPieces().get(0);

    assertEquals(0, tp.getStart());
View Full Code Here

Examples of org.apache.poi.hwpf.HWPFDocument

  /**
   * Check that we do the positions correctly when
   *  working with a mix ascii, unicode file
   */
  public void testUnicodeParts() throws Exception {
    HWPFDocument doc = new HWPFDocument(
        new FileInputStream(new File(dirname, "HeaderFooterUnicode.doc"))
    );
    TextPieceTable tbl = doc.getTextTable();

    // In three bits, split every 512 bytes
    assertEquals(3, tbl.getTextPieces().size());
    TextPiece tpA = (TextPiece)tbl.getTextPieces().get(0);
    TextPiece tpB = (TextPiece)tbl.getTextPieces().get(1);
    TextPiece tpC = (TextPiece)tbl.getTextPieces().get(2);

    assertTrue(tpA.isUnicode());
    assertTrue(tpB.isUnicode());
    assertTrue(tpC.isUnicode());

    assertEquals(256, tpA.characterLength());
    assertEquals(256, tpB.characterLength());
    assertEquals(19, tpC.characterLength());

    assertEquals(512, tpA.bytesLength());
    assertEquals(512, tpB.bytesLength());
    assertEquals(38, tpC.bytesLength());

    assertEquals(0, tpA.getStart());
    assertEquals(256, tpA.getEnd());
    assertEquals(256, tpB.getStart());
    assertEquals(512, tpB.getEnd());
    assertEquals(512, tpC.getStart());
    assertEquals(531, tpC.getEnd());


    // Save and re-load
    HWPFDocument docB = saveAndReload(doc);
    tbl = docB.getTextTable();

    assertEquals(3, tbl.getTextPieces().size());
    tpA = (TextPiece)tbl.getTextPieces().get(0);
    tpB = (TextPiece)tbl.getTextPieces().get(1);
    tpC = (TextPiece)tbl.getTextPieces().get(2);
View Full Code Here

Examples of org.apache.poi.hwpf.HWPFDocument

  protected HWPFDocument saveAndReload(HWPFDocument doc) throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    doc.write(baos);

    return new HWPFDocument(
        new ByteArrayInputStream(baos.toByteArray())
    );
  }
View Full Code Here
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.