settings.setUpdateFields();
}
+ /**
+ * 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
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) {
--- /dev/null
+/* ====================================================================\r
+ Licensed to the Apache Software Foundation (ASF) under one or more\r
+ contributor license agreements. See the NOTICE file distributed with\r
+ this work for additional information regarding copyright ownership.\r
+ The ASF licenses this file to You under the Apache License, Version 2.0\r
+ (the "License"); you may not use this file except in compliance with\r
+ the License. You may obtain a copy of the License at\r
+\r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+==================================================================== */\r
+package org.apache.poi.xwpf.usermodel;\r
+\r
+import static org.junit.Assert.assertFalse;\r
+import static org.junit.Assert.assertTrue;\r
+\r
+import java.io.ByteArrayInputStream;\r
+import java.io.ByteArrayOutputStream;\r
+\r
+import org.apache.poi.xwpf.XWPFTestDataSamples;\r
+import org.junit.Test;\r
+\r
+public class TestChangeTracking {\r
+\r
+ @Test\r
+ public void detection() throws Exception {\r
+\r
+ XWPFDocument documentWithoutChangeTracking = XWPFTestDataSamples.openSampleDocument("bug56075-changeTracking_off.docx");\r
+ assertFalse(documentWithoutChangeTracking.isTrackRevisions());\r
+\r
+ XWPFDocument documentWithChangeTracking = XWPFTestDataSamples.openSampleDocument("bug56075-changeTracking_on.docx");\r
+ assertTrue(documentWithChangeTracking.isTrackRevisions());\r
+\r
+ }\r
+\r
+ @Test\r
+ public void activateChangeTracking() throws Exception {\r
+ XWPFDocument document = XWPFTestDataSamples.openSampleDocument("bug56075-changeTracking_off.docx");\r
+ assertFalse(document.isTrackRevisions());\r
+\r
+ document.setTrackRevisions(true);\r
+ \r
+ assertTrue(document.isTrackRevisions());\r
+ }\r
+\r
+ @Test\r
+ public void integration() throws Exception {\r
+ XWPFDocument doc = new XWPFDocument();\r
+\r
+ XWPFParagraph p1 = doc.createParagraph();\r
+\r
+ XWPFRun r1 = p1.createRun();\r
+ r1.setText("Lorem ipsum dolor sit amet.");\r
+ doc.setTrackRevisions(true);\r
+\r
+ ByteArrayOutputStream out = new ByteArrayOutputStream();\r
+ doc.write(out);\r
+\r
+ ByteArrayInputStream inputStream = new ByteArrayInputStream(out.toByteArray());\r
+ XWPFDocument document = new XWPFDocument(inputStream);\r
+ inputStream.close();\r
+\r
+ assertTrue(document.isTrackRevisions());\r
+ }\r
+\r
+}\r