| 1 | docx4j has a three layered model of a docx file. |
|---|
| 2 | |
|---|
| 3 | The lowest level is org.docx4j.openpackaging, which represents the docx package, |
|---|
| 4 | and each of its constituent parts. |
|---|
| 5 | |
|---|
| 6 | Parts are generally subclasses of org.docx4j.openpackaging.parts.JaxbXmlPart |
|---|
| 7 | |
|---|
| 8 | A JaxbXmlPart has a content tree: |
|---|
| 9 | |
|---|
| 10 | public Object getJaxbElement() { |
|---|
| 11 | return jaxbElement; |
|---|
| 12 | } |
|---|
| 13 | |
|---|
| 14 | public void setJaxbElement(Object jaxbElement) { |
|---|
| 15 | this.jaxbElement = jaxbElement; |
|---|
| 16 | } |
|---|
| 17 | |
|---|
| 18 | The jaxb content tree is the second level of the three layered model. |
|---|
| 19 | |
|---|
| 20 | Most parts (including MainDocumentPart, styles, headers/footers, comments, endnotes/footnotes) |
|---|
| 21 | use org.docx4j.wml (WordprocessingML); wml references org.docx4j.dml (DrawingML) as necessary. |
|---|
| 22 | |
|---|
| 23 | The properties parts use org.docx4j.docProps. |
|---|
| 24 | |
|---|
| 25 | The highest level layer is this package (ie org.docx4j.model). |
|---|
| 26 | This package builds on the lower two layers and does/should include functionality relating to: |
|---|
| 27 | |
|---|
| 28 | - headers/footers |
|---|
| 29 | - list numbering |
|---|
| 30 | - images (TODO: refactor) |
|---|
| 31 | |
|---|
| 32 | Often the question is whether to put functionality into this package or into one of the |
|---|
| 33 | other two layers. |
|---|
| 34 | |
|---|
| 35 | Placing it in the jaxb layer (ie in org.docx4j.wml, org.docx4j.dml, or org.docx4j.docProps) |
|---|
| 36 | is to be avoided, since these classes are (largely) generated automatically from the |
|---|
| 37 | schemas. |
|---|
| 38 | |
|---|
| 39 | You can place the functionality in a particular part (ie in org.docx4j.openpackaging.parts.WordprocessingML) |
|---|
| 40 | if the functionality relates specifically to that part. So for example, the list numbering stuff could |
|---|
| 41 | have gone into the ListNumberingPart (and probably would have, but for the fact that it comprises |
|---|
| 42 | several different classes). |
|---|
| 43 | |
|---|
| 44 | However, functionality which applies to several parts (eg the header/footer stuff), is clearly better |
|---|
| 45 | placed here. |
|---|
| 46 | |
|---|
| 47 | In general, classes in the highest level will hold references to objects in the lower 2 levels, but |
|---|
| 48 | not vice versa. (Although since there is no central/core object on the highest level, it may be |
|---|
| 49 | convenient to store references to some of these in the package or MainDocumentPart). |
|---|
| 50 | |
|---|
| 51 | Aside: typically, when working with docx4j, you use the lowest level to create/open/save a package, |
|---|
| 52 | to add/remove parts, and to access the jaxb content tree for a particular part. You use the second and highest levels |
|---|
| 53 | to manipulate the document content. |
|---|
| 54 | |
|---|
| 55 | |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | |
|---|