diff options
-rw-r--r-- | src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java | 18 | ||||
-rw-r--r-- | src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSettings.java | 26 | ||||
-rw-r--r-- | src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestChangeTracking.java | 71 | ||||
-rw-r--r-- | test-data/document/bug56075-changeTracking_off.docx | bin | 0 -> 12617 bytes | |||
-rw-r--r-- | test-data/document/bug56075-changeTracking_on.docx | bin | 0 -> 12606 bytes |
5 files changed, 115 insertions, 0 deletions
diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java index 65952cbae9..5badf3a671 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java @@ -1158,6 +1158,24 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody { } /** + * Check if revision tracking is turned on. + * + * @return <code>true</code> if revision tracking is turned on + */ + public boolean isTrackRevisions() { + return settings.isTrackRevisions(); + } + + /** + * Enable or disable revision tracking. + * + * @param <code>true</code> to turn on revision tracking, <code>false</code> to turn off revision tracking + */ + public void setTrackRevisions(boolean enable) { + settings.setTrackRevisions(enable); + } + + /** * inserts an existing XWPFTable to the arrays bodyElements and tables * @param pos * @param table diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSettings.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSettings.java index dab349a274..43041bb0c6 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSettings.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSettings.java @@ -326,6 +326,32 @@ public class XWPFSettings extends POIXMLDocumentPart { return ctSettings.isSetUpdateFields() && ctSettings.getUpdateFields().getVal() == STOnOff.TRUE; } + /** + * Check if revision tracking is turned on. + * + * @return <code>true</code> if revision tracking is turned on + */ + public boolean isTrackRevisions() { + return ctSettings.isSetTrackRevisions(); + } + + /** + * Enable or disable revision tracking. + * + * @param <code>true</code> to turn on revision tracking, <code>false</code> to turn off revision tracking + */ + public void setTrackRevisions(boolean enable) { + if(enable) { + if(!ctSettings.isSetTrackRevisions()) { + ctSettings.addNewTrackRevisions(); + } + } else { + if(ctSettings.isSetTrackRevisions()) { + ctSettings.unsetTrackRevisions(); + } + } + } + @Override protected void commit() throws IOException { if (ctSettings == null) { diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestChangeTracking.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestChangeTracking.java new file mode 100644 index 0000000000..d3e4758e1f --- /dev/null +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestChangeTracking.java @@ -0,0 +1,71 @@ +/* ====================================================================
+ 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.xwpf.usermodel;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+
+import org.apache.poi.xwpf.XWPFTestDataSamples;
+import org.junit.Test;
+
+public class TestChangeTracking {
+
+ @Test
+ public void detection() throws Exception {
+
+ XWPFDocument documentWithoutChangeTracking = XWPFTestDataSamples.openSampleDocument("bug56075-changeTracking_off.docx");
+ assertFalse(documentWithoutChangeTracking.isTrackRevisions());
+
+ XWPFDocument documentWithChangeTracking = XWPFTestDataSamples.openSampleDocument("bug56075-changeTracking_on.docx");
+ assertTrue(documentWithChangeTracking.isTrackRevisions());
+
+ }
+
+ @Test
+ public void activateChangeTracking() throws Exception {
+ XWPFDocument document = XWPFTestDataSamples.openSampleDocument("bug56075-changeTracking_off.docx");
+ assertFalse(document.isTrackRevisions());
+
+ document.setTrackRevisions(true);
+
+ assertTrue(document.isTrackRevisions());
+ }
+
+ @Test
+ public void integration() throws Exception {
+ XWPFDocument doc = new XWPFDocument();
+
+ XWPFParagraph p1 = doc.createParagraph();
+
+ XWPFRun r1 = p1.createRun();
+ r1.setText("Lorem ipsum dolor sit amet.");
+ doc.setTrackRevisions(true);
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ doc.write(out);
+
+ ByteArrayInputStream inputStream = new ByteArrayInputStream(out.toByteArray());
+ XWPFDocument document = new XWPFDocument(inputStream);
+ inputStream.close();
+
+ assertTrue(document.isTrackRevisions());
+ }
+
+}
diff --git a/test-data/document/bug56075-changeTracking_off.docx b/test-data/document/bug56075-changeTracking_off.docx Binary files differnew file mode 100644 index 0000000000..a92202d22e --- /dev/null +++ b/test-data/document/bug56075-changeTracking_off.docx diff --git a/test-data/document/bug56075-changeTracking_on.docx b/test-data/document/bug56075-changeTracking_on.docx Binary files differnew file mode 100644 index 0000000000..401af507f7 --- /dev/null +++ b/test-data/document/bug56075-changeTracking_on.docx |