| 1 | /* |
|---|
| 2 | * Copyright 2007-2008, 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 | import javax.xml.bind.JAXBElement; |
|---|
| 28 | import javax.xml.bind.JAXBException; |
|---|
| 29 | import javax.xml.bind.Unmarshaller; |
|---|
| 30 | |
|---|
| 31 | import org.docx4j.openpackaging.io.LoadFromZipFile; |
|---|
| 32 | import org.docx4j.openpackaging.io.SaveToZipFile; |
|---|
| 33 | import org.docx4j.openpackaging.packages.WordprocessingMLPackage; |
|---|
| 34 | import org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart; |
|---|
| 35 | import org.docx4j.wml.Body; |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | public class OpenAndSaveRoundTripTest extends AbstractSample { |
|---|
| 39 | |
|---|
| 40 | public static JAXBContext context = org.docx4j.jaxb.Context.jc; |
|---|
| 41 | |
|---|
| 42 | /** |
|---|
| 43 | * @param args |
|---|
| 44 | */ |
|---|
| 45 | public static void main(String[] args) throws Exception { |
|---|
| 46 | |
|---|
| 47 | try { |
|---|
| 48 | getInputFilePath(args); |
|---|
| 49 | } catch (IllegalArgumentException e) { |
|---|
| 50 | inputfilepath = System.getProperty("user.dir") + "/sample-docs/word/2010/2010-sample1.docx"; |
|---|
| 51 | } |
|---|
| 52 | System.out.println(inputfilepath); |
|---|
| 53 | |
|---|
| 54 | boolean save = true; |
|---|
| 55 | String outputfilepath = System.getProperty("user.dir") + "/OUT-roundtrip.docx"; |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | // Open a document from the file system |
|---|
| 59 | // 1. Load the Package |
|---|
| 60 | WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new java.io.File(inputfilepath)); |
|---|
| 61 | |
|---|
| 62 | // Save it |
|---|
| 63 | |
|---|
| 64 | if (save) { |
|---|
| 65 | SaveToZipFile saver = new SaveToZipFile(wordMLPackage); |
|---|
| 66 | saver.save(outputfilepath); |
|---|
| 67 | } |
|---|
| 68 | } |
|---|
| 69 | |
|---|
| 70 | |
|---|
| 71 | } |
|---|