source: trunk/docx4j/src/main/java/org/docx4j/samples/OpenAndSaveRoundTripTest.java @ 1592

Revision 1592, 2.0 KB checked in by jharrop, 11 months ago (diff)

OpenAndSaveRoundTripTest? extends AbstractSample?

Line 
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
21package org.docx4j.samples;
22
23
24import java.util.List;
25
26import javax.xml.bind.JAXBContext;
27import javax.xml.bind.JAXBElement;
28import javax.xml.bind.JAXBException;
29import javax.xml.bind.Unmarshaller;
30
31import org.docx4j.openpackaging.io.LoadFromZipFile;
32import org.docx4j.openpackaging.io.SaveToZipFile;
33import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
34import org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart;
35import org.docx4j.wml.Body;
36
37
38public 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}
Note: See TracBrowser for help on using the repository browser.