| 1 | /* |
|---|
| 2 | * Copyright 2010, Plutext Pty Ltd. |
|---|
| 3 | * |
|---|
| 4 | * This file is part of docx4j. |
|---|
| 5 | |
|---|
| 6 | docx4j is licensed under the Apache License, Version 2.0 (the "License"); |
|---|
| 7 | you may not use this file except in compliance with the License. |
|---|
| 8 | |
|---|
| 9 | You may obtain a copy of the License at |
|---|
| 10 | |
|---|
| 11 | http://www.apache.org/licenses/LICENSE-2.0 |
|---|
| 12 | |
|---|
| 13 | Unless required by applicable law or agreed to in writing, software |
|---|
| 14 | distributed under the License is distributed on an "AS IS" BASIS, |
|---|
| 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|---|
| 16 | See the License for the specific language governing permissions and |
|---|
| 17 | limitations under the License. |
|---|
| 18 | |
|---|
| 19 | */ |
|---|
| 20 | |
|---|
| 21 | package org.docx4j.samples; |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | import java.util.List; |
|---|
| 25 | |
|---|
| 26 | import javax.xml.bind.JAXBContext; |
|---|
| 27 | |
|---|
| 28 | import org.docx4j.model.structure.HeaderFooterPolicy; |
|---|
| 29 | import org.docx4j.model.structure.SectionWrapper; |
|---|
| 30 | import org.docx4j.openpackaging.packages.WordprocessingMLPackage; |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | /** |
|---|
| 34 | * This sample tells you how docx4j is interpreting headers/footers |
|---|
| 35 | * in your docx. |
|---|
| 36 | * |
|---|
| 37 | * It should match what you see when you look at the docx in Word |
|---|
| 38 | * (as opposed to the raw document.xml//sectPr content). |
|---|
| 39 | * |
|---|
| 40 | * @author jharrop |
|---|
| 41 | * |
|---|
| 42 | */ |
|---|
| 43 | public class HeaderFooterList extends AbstractSample { |
|---|
| 44 | |
|---|
| 45 | public static JAXBContext context = org.docx4j.jaxb.Context.jc; |
|---|
| 46 | |
|---|
| 47 | /** |
|---|
| 48 | * @param args |
|---|
| 49 | */ |
|---|
| 50 | public static void main(String[] args) throws Exception { |
|---|
| 51 | |
|---|
| 52 | try { |
|---|
| 53 | getInputFilePath(args); |
|---|
| 54 | } catch (IllegalArgumentException e) { |
|---|
| 55 | inputfilepath = System.getProperty("user.dir") |
|---|
| 56 | + "/sample-docs/test-docs/header-footer/Header-firstPage.docx"; |
|---|
| 57 | |
|---|
| 58 | // inputfilepath = System.getProperty("user.dir") |
|---|
| 59 | // + "/tmp/toc.docx"; |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage |
|---|
| 63 | .load(new java.io.File(inputfilepath)); |
|---|
| 64 | |
|---|
| 65 | List<SectionWrapper> sectionWrappers = wordMLPackage.getDocumentModel().getSections(); |
|---|
| 66 | |
|---|
| 67 | for (SectionWrapper sw : sectionWrappers) { |
|---|
| 68 | HeaderFooterPolicy hfp = sw.getHeaderFooterPolicy(); |
|---|
| 69 | |
|---|
| 70 | System.out.println("\n\nSECTION \n"); |
|---|
| 71 | |
|---|
| 72 | System.out.println("Headers:"); |
|---|
| 73 | if (hfp.getFirstHeader()!=null) System.out.println("-first"); |
|---|
| 74 | if (hfp.getDefaultHeader()!=null) System.out.println("-default"); |
|---|
| 75 | if (hfp.getEvenHeader()!=null) System.out.println("-even"); |
|---|
| 76 | |
|---|
| 77 | System.out.println("\nFooters:"); |
|---|
| 78 | if (hfp.getFirstFooter()!=null) System.out.println("-first"); |
|---|
| 79 | if (hfp.getDefaultFooter()!=null) System.out.println("-default"); |
|---|
| 80 | if (hfp.getEvenFooter()!=null) System.out.println("-even"); |
|---|
| 81 | |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | } |
|---|