poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kiwiwi...@apache.org
Subject svn commit: r1577010 - in /poi: site/src/documentation/content/xdocs/ trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/ trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/ trunk/test-data/document/
Date Thu, 13 Mar 2014 00:16:57 GMT
Author: kiwiwings
Date: Thu Mar 13 00:16:56 2014
New Revision: 1577010

URL: http://svn.apache.org/r1577010
Log:
Bug 56075 - Add Change Tracking support to XWPF 

Added:
    poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestChangeTracking.java
    poi/trunk/test-data/document/bug56075-changeTracking_off.docx   (with props)
    poi/trunk/test-data/document/bug56075-changeTracking_on.docx   (with props)
Modified:
    poi/site/src/documentation/content/xdocs/status.xml
    poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java
    poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSettings.java

Modified: poi/site/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/site/src/documentation/content/xdocs/status.xml?rev=1577010&r1=1577009&r2=1577010&view=diff
==============================================================================
--- poi/site/src/documentation/content/xdocs/status.xml (original)
+++ poi/site/src/documentation/content/xdocs/status.xml Thu Mar 13 00:16:56 2014
@@ -37,6 +37,7 @@
     </devs>
 
     <release version="3.11-beta1" date="2014-??-??">
+        <action dev="PD" type="add" fixes-bug="56075">Add Change Tracking support to
XWPF</action>
         <action dev="PD" type="add" fixes-bug="56077">Add password hash function to
HWPF</action>
         <action dev="PD" type="add" fixes-bug="56076">Add document protection with
password support to XWPF</action>
         <action dev="PD" type="fix" fixes-bug="55026">Support OOXML ContentTypes which
include parameters</action>

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java?rev=1577010&r1=1577009&r2=1577010&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java Thu Mar 13 00:16:56
2014
@@ -1158,6 +1158,24 @@ public class XWPFDocument extends POIXML
     }
     
     /**
+      * 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

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSettings.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSettings.java?rev=1577010&r1=1577009&r2=1577010&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSettings.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSettings.java Thu Mar 13 00:16:56
2014
@@ -326,6 +326,32 @@ public class XWPFSettings extends POIXML
         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) {

Added: poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestChangeTracking.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestChangeTracking.java?rev=1577010&view=auto
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestChangeTracking.java (added)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestChangeTracking.java Thu
Mar 13 00:16:56 2014
@@ -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());
+    }
+
+}

Added: poi/trunk/test-data/document/bug56075-changeTracking_off.docx
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/document/bug56075-changeTracking_off.docx?rev=1577010&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/test-data/document/bug56075-changeTracking_off.docx
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: poi/trunk/test-data/document/bug56075-changeTracking_on.docx
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/document/bug56075-changeTracking_on.docx?rev=1577010&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/test-data/document/bug56075-changeTracking_on.docx
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message