poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ser...@apache.org
Subject svn commit: r1148959 - in /poi/trunk: src/documentation/content/xdocs/ src/scratchpad/src/org/apache/poi/hwpf/ src/scratchpad/src/org/apache/poi/hwpf/model/ src/scratchpad/src/org/apache/poi/hwpf/model/types/ src/scratchpad/src/org/apache/poi/hwpf/user...
Date Wed, 20 Jul 2011 22:32:01 GMT
Author: sergey
Date: Wed Jul 20 22:31:59 2011
New Revision: 1148959

URL: http://svn.apache.org/viewvc?rev=1148959&view=rev
Log:
initial support for endnotes and footnotes in HWPF

Added:
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/FootnoteReferenceDescriptor.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/NoteType.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/NotesTables.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/types/FRDAbstractType.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Notes.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/NotesImpl.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestNotesTables.java
    poi/trunk/src/types/definitions/frd_type.xml
    poi/trunk/test-data/document/endingnote.doc   (with props)
Modified:
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/FileInformationBlock.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/AllHWPFTests.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/converter/TestWordToHtmlConverter.java

Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=1148959&r1=1148958&r2=1148959&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Wed Jul 20 22:31:59 2011
@@ -34,11 +34,12 @@
 
     <changes>
         <release version="3.8-beta4" date="2011-??-??">
+           <action dev="poi-developers" type="add">Initial support for endnotes and
footnotes in HWPF</action>
            <action dev="poi-developers" type="fix">51470 - avoid exception when cloning
XSSF sheets with background images</action>
            <action dev="poi-developers" type="fix">51481 - Fixed autofilters in HSSF
to avoid warnings in Excel 2007</action>
            <action dev="poi-developers" type="fix">51533 - Avoid exception when changing
name of a sheet containing shared formulas</action>
            <action dev="poi-developers" type="add">Support for appending images to
existing drawings in HSSF</action>
-           <action dev="poi-developers" type="fix">Added initial support for bookmarks
in HWPF</action>
+           <action dev="poi-developers" type="add">Initial support for bookmarks in
HWPF</action>
            <action dev="poi-developers" type="fix">46250 - Fixed cloning worksheets
with images</action>
            <action dev="poi-developers" type="fix">51524 - PapBinTable constructor
is slow (regression)</action>
            <action dev="poi-developers" type="fix">51514 - allow HSSFObjectData to
work with both POIFS and NPOIFS</action>

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java?rev=1148959&r1=1148958&r2=1148959&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java Wed Jul 20 22:31:59
2011
@@ -36,6 +36,8 @@ import org.apache.poi.hwpf.model.FSPATab
 import org.apache.poi.hwpf.model.FieldsTables;
 import org.apache.poi.hwpf.model.FontTable;
 import org.apache.poi.hwpf.model.ListTables;
+import org.apache.poi.hwpf.model.NoteType;
+import org.apache.poi.hwpf.model.NotesTables;
 import org.apache.poi.hwpf.model.PAPBinTable;
 import org.apache.poi.hwpf.model.PicturesTable;
 import org.apache.poi.hwpf.model.RevisionMarkAuthorTable;
@@ -51,6 +53,8 @@ import org.apache.poi.hwpf.model.io.HWPF
 import org.apache.poi.hwpf.usermodel.Bookmarks;
 import org.apache.poi.hwpf.usermodel.BookmarksImpl;
 import org.apache.poi.hwpf.usermodel.HWPFList;
+import org.apache.poi.hwpf.usermodel.Notes;
+import org.apache.poi.hwpf.usermodel.NotesImpl;
 import org.apache.poi.hwpf.usermodel.Range;
 import org.apache.poi.poifs.common.POIFSConstants;
 import org.apache.poi.poifs.filesystem.DirectoryNode;
@@ -110,6 +114,18 @@ public final class HWPFDocument extends 
   /** Holds the bookmarks */
   protected Bookmarks _bookmarks;
 
+  /** Holds the ending notes tables */
+  protected NotesTables _endnotesTables = new NotesTables( NoteType.ENDNOTE );
+
+  /** Holds the footnotes */
+  protected Notes _endnotes = new NotesImpl( _endnotesTables );
+
+  /** Holds the footnotes tables */
+  protected NotesTables _footnotesTables = new NotesTables( NoteType.FOOTNOTE );
+
+  /** Holds the footnotes */
+  protected Notes _footnotes = new NotesImpl( _footnotesTables );
+
   /** Holds the fields PLCFs */
   protected FieldsTables _fieldsTables;
 
@@ -273,6 +289,12 @@ public final class HWPFDocument extends 
 
     _bookmarksTables = new BookmarksTables( _tableStream, _fib );
     _bookmarks = new BookmarksImpl( _bookmarksTables );
+
+    _endnotesTables = new NotesTables( NoteType.ENDNOTE, _tableStream, _fib );
+    _endnotes = new NotesImpl( _endnotesTables );
+    _footnotesTables = new NotesTables( NoteType.FOOTNOTE, _tableStream, _fib );
+    _footnotes = new NotesImpl( _footnotesTables );
+
     _fieldsTables = new FieldsTables(_tableStream, _fib);
   }
 
@@ -470,6 +492,22 @@ public final class HWPFDocument extends 
         return _bookmarks;
     }
 
+    /**
+     * @return user-friendly interface to access document endnotes
+     */
+    public Notes getEndnotes()
+    {
+        return _endnotes;
+    }
+
+    /**
+     * @return user-friendly interface to access document footnotes
+     */
+    public Notes getFootnotes()
+    {
+        return _footnotes;
+    }
+
   /**
    * @return FieldsTables object, that is able to extract fields descriptors from this document
    */
@@ -589,17 +627,75 @@ public final class HWPFDocument extends 
     _fib.setLcbPlcfbtePapx(tableStream.getOffset() - tableOffset);
     tableOffset = tableStream.getOffset();
 
+        /*
+         * plcfendRef (endnote reference position table) Written immediately
+         * after the previously recorded table if the document contains endnotes
+         * 
+         * plcfendTxt (endnote text position table) Written immediately after
+         * the plcfendRef if the document contains endnotes
+         * 
+         * Microsoft Office Word 97-2007 Binary File Format (.doc)
+         * Specification; Page 24 of 210
+         */
+        _endnotesTables.writeRef( _fib, tableStream );
+        _endnotesTables.writeTxt( _fib, tableStream );
+        tableOffset = tableStream.getOffset();
+
+    /*
+     * plcffld*** (table of field positions and statuses for annotation
+     * subdocument) Written immediately after the previously recorded table,
+     * if the ******* subdocument contains fields.
+     * 
+     * Microsoft Office Word 97-2007 Binary File Format (.doc)
+     * Specification; Page 24 of 210
+     */
+
+    if ( _fieldsTables != null )
+    {
+        _fieldsTables.write( _fib, tableStream );
+        tableOffset = tableStream.getOffset();
+    }
+
+        /*
+         * plcffndRef (footnote reference position table) Written immediately
+         * after the stsh if the document contains footnotes
+         * 
+         * plcffndTxt (footnote text position table) Written immediately after
+         * the plcffndRef if the document contains footnotes
+         * 
+         * Microsoft Office Word 97-2007 Binary File Format (.doc)
+         * Specification; Page 24 of 210
+         */
+        _footnotesTables.writeRef( _fib, tableStream );
+        _footnotesTables.writeTxt( _fib, tableStream );
+        tableOffset = tableStream.getOffset();
+
+        /*
+         * plcfsed (section table) Written immediately after the previously
+         * recorded table. Recorded in all Word documents
+         * 
+         * Microsoft Office Word 97-2007 Binary File Format (.doc)
+         * Specification; Page 25 of 210
+         */
+
     // write out the SectionTable.
     _fib.setFcPlcfsed(tableOffset);
     _st.writeTo(docSys, fcMin);
     _fib.setLcbPlcfsed(tableStream.getOffset() - tableOffset);
     tableOffset = tableStream.getOffset();
 
-        if ( _fieldsTables != null )
-        {
-            _fieldsTables.write( _fib, tableStream );
-            tableOffset = tableStream.getOffset();
-        }
+        /*
+         * plcflst (list formats) Written immediately after the end of the
+         * previously recorded, if there are any lists defined in the document.
+         * This begins with a short count of LSTF structures followed by those
+         * LSTF structures. This is immediately followed by the allocated data
+         * hanging off the LSTFs. This data consists of the array of LVLs for
+         * each LSTF. (Each LVL consists of an LVLF followed by two grpprls and
+         * an XST.)
+         * 
+         * Microsoft Office Word 97-2007 Binary File Format (.doc)
+         * Specification; Page 25 of 210
+         */
 
     // write out the list tables
     if (_lt != null)
@@ -607,7 +703,22 @@ public final class HWPFDocument extends 
       _fib.setFcPlcfLst(tableOffset);
       _lt.writeListDataTo(tableStream);
       _fib.setLcbPlcfLst(tableStream.getOffset() - tableOffset);
+    }
+
+    /*
+     * plflfo (more list formats) Written immediately after the end of the
+     * plcflst and its accompanying data, if there are any lists defined in
+     * the document. This consists first of a PL of LFO records, followed by
+     * the allocated data (if any) hanging off the LFOs. The allocated data
+     * consists of the array of LFOLVLFs for each LFO (and each LFOLVLF is
+     * immediately followed by some LVLs).
+     * 
+     * Microsoft Office Word 97-2007 Binary File Format (.doc)
+     * Specification; Page 26 of 210
+     */
 
+    if (_lt != null)
+    {
       _fib.setFcPlfLfo(tableStream.getOffset());
       _lt.writeListOverridesTo(tableStream);
       _fib.setLcbPlfLfo(tableStream.getOffset() - tableOffset);

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/FileInformationBlock.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/FileInformationBlock.java?rev=1148959&r1=1148958&r2=1148959&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/FileInformationBlock.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/FileInformationBlock.java Wed Jul
20 22:31:59 2011
@@ -85,6 +85,15 @@ public final class FileInformationBlock 
         knownFieldSet.add( Integer.valueOf( FIBFieldHandler.PLCFBKL ) );
         knownFieldSet.add( Integer.valueOf( FIBFieldHandler.STTBFBKMK ) );
 
+        // notes
+        for ( NoteType noteType : NoteType.values() )
+        {
+            knownFieldSet.add( Integer.valueOf( noteType
+                    .getFibDescriptorsFieldIndex() ) );
+            knownFieldSet.add( Integer.valueOf( noteType
+                    .getFibTextPositionsFieldIndex() ) );
+        }
+
         knownFieldSet.add( Integer.valueOf( FIBFieldHandler.STTBFFFN ) );
         knownFieldSet.add( Integer.valueOf( FIBFieldHandler.STTBFRMARK ) );
         knownFieldSet.add( Integer.valueOf( FIBFieldHandler.STTBSAVEDBY ) );
@@ -121,6 +130,24 @@ public final class FileInformationBlock 
             stringBuilder.append( getFieldsPlcfLength( part ) );
             stringBuilder.append( "\n" );
         }
+        stringBuilder.append( "\tNotes PLCF info:\n" );
+        for ( NoteType noteType : NoteType.values() )
+        {
+            stringBuilder.append( "\t\t" );
+            stringBuilder.append( noteType );
+            stringBuilder.append( ": descriptions starts " );
+            stringBuilder.append( getNotesDescriptorsOffset( noteType ) );
+            stringBuilder.append( " and have length of " );
+            stringBuilder.append( getNotesDescriptorsSize( noteType ) );
+            stringBuilder.append( " bytes\n" );
+            stringBuilder.append( "\t\t" );
+            stringBuilder.append( noteType );
+            stringBuilder.append( ": text positions starts " );
+            stringBuilder.append( getNotesTextPositionsOffset( noteType ) );
+            stringBuilder.append( " and have length of " );
+            stringBuilder.append( getNotesTextPositionsSize( noteType ) );
+            stringBuilder.append( " bytes\n" );
+        }
         try
         {
             stringBuilder.append( "\tJava reflection info:\n" );
@@ -842,7 +869,55 @@ public final class FileInformationBlock 
         return _fieldHandler.getFieldSize(FIBFieldHandler.DGGINFO);
     }
 
-    public void writeTo (byte[] mainStream, HWPFOutputStream tableStream)
+    public int getNotesDescriptorsOffset( NoteType noteType )
+    {
+        return _fieldHandler.getFieldOffset( noteType
+                .getFibDescriptorsFieldIndex() );
+    }
+
+    public void setNotesDescriptorsOffset( NoteType noteType, int offset )
+    {
+        _fieldHandler.setFieldOffset( noteType.getFibDescriptorsFieldIndex(),
+                offset );
+    }
+
+    public int getNotesDescriptorsSize( NoteType noteType )
+    {
+        return _fieldHandler.getFieldSize( noteType
+                .getFibDescriptorsFieldIndex() );
+    }
+
+    public void setNotesDescriptorsSize( NoteType noteType, int offset )
+    {
+        _fieldHandler.setFieldSize( noteType.getFibDescriptorsFieldIndex(),
+                offset );
+    }
+
+    public int getNotesTextPositionsOffset( NoteType noteType )
+    {
+        return _fieldHandler.getFieldOffset( noteType
+                .getFibTextPositionsFieldIndex() );
+    }
+
+    public void setNotesTextPositionsOffset( NoteType noteType, int offset )
+    {
+        _fieldHandler.setFieldOffset( noteType.getFibTextPositionsFieldIndex(),
+                offset );
+    }
+
+    public int getNotesTextPositionsSize( NoteType noteType )
+    {
+        return _fieldHandler.getFieldSize( noteType
+                .getFibTextPositionsFieldIndex() );
+    }
+
+    public void setNotesTextPositionsSize( NoteType noteType, int offset )
+    {
+        _fieldHandler.setFieldSize( noteType.getFibTextPositionsFieldIndex(),
+                offset );
+    }
+
+    public void writeTo( byte[] mainStream, HWPFOutputStream tableStream)
       throws IOException
     {
       //HWPFOutputStream mainDocument = sys.getStream("WordDocument");

Added: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/FootnoteReferenceDescriptor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/FootnoteReferenceDescriptor.java?rev=1148959&view=auto
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/FootnoteReferenceDescriptor.java
(added)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/FootnoteReferenceDescriptor.java
Wed Jul 20 22:31:59 2011
@@ -0,0 +1,83 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+package org.apache.poi.hwpf.model;
+
+import org.apache.poi.hwpf.model.types.FRDAbstractType;
+
+public final class FootnoteReferenceDescriptor extends FRDAbstractType
+        implements Cloneable
+{
+    public FootnoteReferenceDescriptor()
+    {
+    }
+
+    public FootnoteReferenceDescriptor( byte[] data, int offset )
+    {
+        fillFields( data, offset );
+    }
+
+    @Override
+    protected FootnoteReferenceDescriptor clone()
+    {
+        try
+        {
+            return (FootnoteReferenceDescriptor) super.clone();
+        }
+        catch ( CloneNotSupportedException e )
+        {
+            throw new RuntimeException( e );
+        }
+    }
+
+    @Override
+    public boolean equals( Object obj )
+    {
+        if ( this == obj )
+            return true;
+        if ( obj == null )
+            return false;
+        if ( getClass() != obj.getClass() )
+            return false;
+        FootnoteReferenceDescriptor other = (FootnoteReferenceDescriptor) obj;
+        if ( field_1_nAuto != other.field_1_nAuto )
+            return false;
+        return true;
+    }
+
+    @Override
+    public int hashCode()
+    {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + field_1_nAuto;
+        return result;
+    }
+
+    public boolean isEmpty()
+    {
+        return field_1_nAuto == 0;
+    }
+
+    @Override
+    public String toString()
+    {
+        if ( isEmpty() )
+            return "[FRD] EMPTY";
+
+        return super.toString();
+    }
+}

Added: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/NoteType.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/NoteType.java?rev=1148959&view=auto
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/NoteType.java (added)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/NoteType.java Wed Jul 20 22:31:59
2011
@@ -0,0 +1,51 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+/**
+ * Word document notes types (and their FIB field indices)
+ * 
+ * @author Sergey Vladimirov (vlsergey {at} gmail {doc} com)
+ */
+package org.apache.poi.hwpf.model;
+
+public enum NoteType {
+    /** Ending note */
+    ENDNOTE( FIBFieldHandler.PLCFENDREF, FIBFieldHandler.PLCFENDTXT ),
+
+    /** Footnote */
+    FOOTNOTE( FIBFieldHandler.PLCFFNDREF, FIBFieldHandler.PLCFFNDTXT );
+
+    private final int fibDescriptorsFieldIndex;
+    private final int fibTextPositionsFieldIndex;
+
+    private NoteType( int fibDescriptorsFieldIndex,
+            int fibTextPositionsFieldIndex )
+    {
+        this.fibDescriptorsFieldIndex = fibDescriptorsFieldIndex;
+        this.fibTextPositionsFieldIndex = fibTextPositionsFieldIndex;
+    }
+
+    public int getFibDescriptorsFieldIndex()
+    {
+        return fibDescriptorsFieldIndex;
+    }
+
+    public int getFibTextPositionsFieldIndex()
+    {
+        return fibTextPositionsFieldIndex;
+    }
+}

Added: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/NotesTables.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/NotesTables.java?rev=1148959&view=auto
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/NotesTables.java (added)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/NotesTables.java Wed Jul 20 22:31:59
2011
@@ -0,0 +1,118 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+package org.apache.poi.hwpf.model;
+
+import java.io.IOException;
+
+import org.apache.poi.hwpf.model.io.HWPFOutputStream;
+
+/**
+ * Holds information about document notes (footnotes or ending notes)
+ * 
+ * @author Sergey Vladimirov (vlsergey {at} gmail {doc} com)
+ */
+public class NotesTables
+{
+    private PlexOfCps descriptors = new PlexOfCps(
+            FootnoteReferenceDescriptor.getSize() );
+
+    private final NoteType noteType;
+
+    private PlexOfCps textPositions = new PlexOfCps( 0 );
+
+    public NotesTables( final NoteType noteType )
+    {
+        this.noteType = noteType;
+        textPositions
+                .addProperty( new GenericPropertyNode( 0, 1, new byte[0] ) );
+    }
+
+    public NotesTables( final NoteType noteType, byte[] tableStream,
+            FileInformationBlock fib )
+    {
+        this.noteType = noteType;
+        read( tableStream, fib );
+    }
+
+    public GenericPropertyNode getDescriptor( int index )
+    {
+        return descriptors.getProperty( index );
+    }
+
+    public int getDescriptorsCount()
+    {
+        return descriptors.length();
+    }
+
+    public GenericPropertyNode getTextPosition( int index )
+    {
+        return textPositions.getProperty( index );
+    }
+
+    private void read( byte[] tableStream, FileInformationBlock fib )
+    {
+        int referencesStart = fib.getNotesDescriptorsOffset( noteType );
+        int referencesLength = fib.getNotesDescriptorsSize( noteType );
+
+        if ( referencesStart != 0 && referencesLength != 0 )
+            this.descriptors = new PlexOfCps( tableStream, referencesStart,
+                    referencesLength, FootnoteReferenceDescriptor.getSize() );
+
+        int textPositionsStart = fib.getNotesTextPositionsOffset( noteType );
+        int textPositionsLength = fib.getNotesTextPositionsSize( noteType );
+
+        if ( textPositionsStart != 0 && textPositionsLength != 0 )
+            this.textPositions = new PlexOfCps( tableStream,
+                    textPositionsStart, textPositionsLength, 0 );
+    }
+
+    public void writeRef( FileInformationBlock fib, HWPFOutputStream tableStream )
+            throws IOException
+    {
+        if ( descriptors == null || descriptors.length() == 0 )
+        {
+            fib.setNotesDescriptorsOffset( noteType, 0 );
+            fib.setNotesDescriptorsSize( noteType, 0 );
+            return;
+        }
+
+        int start = tableStream.getOffset();
+        tableStream.write( descriptors.toByteArray() );
+        int end = tableStream.getOffset();
+
+        fib.setNotesDescriptorsOffset( noteType, start );
+        fib.setNotesDescriptorsSize( noteType, end - start );
+    }
+
+    public void writeTxt( FileInformationBlock fib, HWPFOutputStream tableStream )
+            throws IOException
+    {
+        if ( textPositions == null || textPositions.length() == 0 )
+        {
+            fib.setNotesTextPositionsOffset( noteType, 0 );
+            fib.setNotesTextPositionsSize( noteType, 0 );
+            return;
+        }
+
+        int start = tableStream.getOffset();
+        tableStream.write( textPositions.toByteArray() );
+        int end = tableStream.getOffset();
+
+        fib.setNotesTextPositionsOffset( noteType, start );
+        fib.setNotesTextPositionsSize( noteType, end - start );
+    }
+}

Added: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/types/FRDAbstractType.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/types/FRDAbstractType.java?rev=1148959&view=auto
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/types/FRDAbstractType.java (added)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/types/FRDAbstractType.java Wed
Jul 20 22:31:59 2011
@@ -0,0 +1,89 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+package org.apache.poi.hwpf.model.types;
+
+import org.apache.poi.util.LittleEndian;
+
+/**
+ * Footnote Reference Descriptor (FRD).
+ * <p>
+ * Class and fields descriptions are quoted from Microsoft Office Word 97-2007
+ * Binary File Format (.doc) Specification
+ * 
+ * NOTE: This source is automatically generated please do not modify this file.
+ * Either subclass or remove the record in src/types/definitions.
+ * 
+ * @author Sergey Vladimirov; according to Microsoft Office Word 97-2007 Binary
+ *         File Format (.doc) Specification
+ */
+public abstract class FRDAbstractType
+{
+
+    protected short field_1_nAuto;
+
+    protected FRDAbstractType()
+    {
+    }
+
+    protected void fillFields( byte[] data, int offset )
+    {
+        field_1_nAuto = LittleEndian.getShort( data, 0x0 + offset );
+    }
+
+    public void serialize( byte[] data, int offset )
+    {
+        LittleEndian.putShort( data, 0x0 + offset, field_1_nAuto );
+    }
+
+    /**
+     * Size of record
+     */
+    public static int getSize()
+    {
+        return 0 + 2;
+    }
+
+    public String toString()
+    {
+        StringBuilder builder = new StringBuilder();
+        builder.append( "[FRD]\n" );
+        builder.append( "    .nAuto                = " );
+        builder.append( " (" ).append( getNAuto() ).append( " )\n" );
+
+        builder.append( "[/FRD]\n" );
+        return builder.toString();
+    }
+
+    /**
+     * If > 0, the note is an automatically numbered note, otherwise it has a
+     * custom mark.
+     */
+    public short getNAuto()
+    {
+        return field_1_nAuto;
+    }
+
+    /**
+     * If > 0, the note is an automatically numbered note, otherwise it has a
+     * custom mark.
+     */
+    public void setNAuto( short field_1_nAuto )
+    {
+        this.field_1_nAuto = field_1_nAuto;
+    }
+
+} // END OF CLASS

Added: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Notes.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Notes.java?rev=1148959&view=auto
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Notes.java (added)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Notes.java Wed Jul 20 22:31:59
2011
@@ -0,0 +1,47 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+package org.apache.poi.hwpf.usermodel;
+
+/**
+ * User-friendly interface to access document notes information
+ * 
+ * @author Sergey Vladimirov (vlsergey {at} gmail {doc} com)
+ */
+public interface Notes
+{
+    /**
+     * Returns the location of note anchor in main textspace
+     */
+    int getNoteAnchorPosition( int index );
+
+    /**
+     * Returns count of notes in document
+     */
+    int getNotesCount();
+
+    /**
+     * Returns the end offset of the text corresponding to the reference within
+     * the footnote text address space
+     */
+    int getNoteTextEndOffset( int index );
+
+    /**
+     * Returns the start offset of the text corresponding to the reference
+     * within the footnote text address space
+     */
+    int getNoteTextStartOffset( int index );
+}

Added: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/NotesImpl.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/NotesImpl.java?rev=1148959&view=auto
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/NotesImpl.java (added)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/NotesImpl.java Wed Jul 20 22:31:59
2011
@@ -0,0 +1,54 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+package org.apache.poi.hwpf.usermodel;
+
+import org.apache.poi.hwpf.model.NotesTables;
+
+/**
+ * Default implementation of {@link Notes} interface
+ * 
+ * @author Sergey Vladimirov (vlsergey {at} gmail {doc} com)
+ */
+public class NotesImpl implements Notes
+{
+    private final NotesTables notesTables;
+
+    public NotesImpl( NotesTables notesTables )
+    {
+        this.notesTables = notesTables;
+    }
+
+    public int getNoteAnchorPosition( int index )
+    {
+        return notesTables.getDescriptor( index ).getStart();
+    }
+
+    public int getNotesCount()
+    {
+        return notesTables.getDescriptorsCount();
+    }
+
+    public int getNoteTextEndOffset( int index )
+    {
+        return notesTables.getTextPosition( index ).getEnd();
+    }
+
+    public int getNoteTextStartOffset( int index )
+    {
+        return notesTables.getTextPosition( index ).getStart();
+    }
+}

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/AllHWPFTests.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/AllHWPFTests.java?rev=1148959&r1=1148958&r2=1148959&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/AllHWPFTests.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/AllHWPFTests.java Wed Jul 20 22:31:59
2011
@@ -31,6 +31,7 @@ import org.apache.poi.hwpf.model.TestDoc
 import org.apache.poi.hwpf.model.TestFileInformationBlock;
 import org.apache.poi.hwpf.model.TestFontTable;
 import org.apache.poi.hwpf.model.TestListTables;
+import org.apache.poi.hwpf.model.TestNotesTables;
 import org.apache.poi.hwpf.model.TestPAPBinTable;
 import org.apache.poi.hwpf.model.TestPlexOfCps;
 import org.apache.poi.hwpf.model.TestRevisionMarkAuthorTable;
@@ -86,6 +87,7 @@ public final class AllHWPFTests
         suite.addTestSuite( TestFileInformationBlock.class );
         suite.addTestSuite( TestFontTable.class );
         suite.addTestSuite( TestListTables.class );
+        suite.addTestSuite( TestNotesTables.class );
         suite.addTestSuite( TestPAPBinTable.class );
         suite.addTestSuite( TestPlexOfCps.class );
         suite.addTestSuite( TestRevisionMarkAuthorTable.class );

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/converter/TestWordToHtmlConverter.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/converter/TestWordToHtmlConverter.java?rev=1148959&r1=1148958&r2=1148959&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/converter/TestWordToHtmlConverter.java
(original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/converter/TestWordToHtmlConverter.java
Wed Jul 20 22:31:59 2011
@@ -141,6 +141,15 @@ public class TestWordToHtmlConverter ext
         assertContains( result, substring );
     }
 
+    public void testEndnote() throws Exception
+    {
+        String result = getHtmlText( "endingnote.doc" );
+
+        assertContains( result, "<a href=\"#userref\">" );
+        assertContains( result, "<a name=\"userref\">" );
+        assertContains( result, "1" );
+    }
+
     public void testEquation() throws Exception
     {
         String result = getHtmlText( "equation.doc" );

Added: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestNotesTables.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestNotesTables.java?rev=1148959&view=auto
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestNotesTables.java (added)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestNotesTables.java Wed
Jul 20 22:31:59 2011
@@ -0,0 +1,45 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+package org.apache.poi.hwpf.model;
+
+import junit.framework.TestCase;
+
+import org.apache.poi.hwpf.HWPFDocument;
+import org.apache.poi.hwpf.HWPFTestDataSamples;
+import org.apache.poi.hwpf.usermodel.Notes;
+
+/**
+ * Test cases for {@link NotesTables} and default implementation of
+ * {@link Notes}
+ * 
+ * @author Sergey Vladimirov (vlsergey {at} gmail {dot} com)
+ */
+public class TestNotesTables extends TestCase
+{
+    public void test()
+    {
+        HWPFDocument doc = HWPFTestDataSamples
+                .openSampleFile( "endingnote.doc" );
+        Notes notes = doc.getEndnotes();
+
+        assertEquals( 1, notes.getNotesCount() );
+
+        assertEquals( 10, notes.getNoteAnchorPosition( 0 ) );
+        assertEquals( 0, notes.getNoteTextStartOffset( 0 ) );
+        assertEquals( 19, notes.getNoteTextEndOffset( 0 ) );
+    }
+}

Added: poi/trunk/src/types/definitions/frd_type.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/types/definitions/frd_type.xml?rev=1148959&view=auto
==============================================================================
--- poi/trunk/src/types/definitions/frd_type.xml (added)
+++ poi/trunk/src/types/definitions/frd_type.xml Wed Jul 20 22:31:59 2011
@@ -0,0 +1,33 @@
+<?xml version="1.0"?>
+<!--
+    ====================================================================
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements. See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License. You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+    ====================================================================
+-->
+<record fromfile="true" name="FRD" package="org.apache.poi.hwpf.model.types">
+    <suffix>AbstractType</suffix>
+    <extends>HDFType</extends>
+    <description>Footnote Reference Descriptor (FRD). &lt;p&gt;Class and fields
descriptions are
+        quoted from Microsoft Office Word 97-2007 Binary File Format (.doc) Specification
+    </description>
+    <author>Sergey Vladimirov; according to Microsoft Office Word 97-2007 Binary File
Format (.doc)
+        Specification
+    </author>
+    <fields>
+        <field type="short" size="2" name="nAuto"
+            description="If > 0, the note is an automatically numbered note, otherwise
it has a custom mark"/>
+    </fields>
+</record>

Added: poi/trunk/test-data/document/endingnote.doc
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/document/endingnote.doc?rev=1148959&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/test-data/document/endingnote.doc
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message