Merge "Fix preview diff on first change"
diff --git a/BUCK b/BUCK
index 25b0467..df1e8a6 100644
--- a/BUCK
+++ b/BUCK
@@ -2,11 +2,14 @@
 
 MODULE = 'com.googlesource.gerrit.plugins.xdocs.XDocs'
 
-ASCIIDOCTOR = '//lib/asciidoctor:asciidoc_lib' if STANDALONE_MODE \
-  else '//plugins/x-docs/lib/asciidoctor:asciidoc_lib'
-
-DAISYDIFF = '//lib/daisydiff:daisydiff_lib' if STANDALONE_MODE \
-  else '//plugins/x-docs/lib/daisydiff:daisydiff_lib'
+if STANDALONE_MODE:
+  ASCIIDOCTOR = '//lib/asciidoctor:asciidoc_lib'
+  DAISYDIFF = '//lib/daisydiff:daisydiff_lib'
+  DOCX4J = '//lib/docx4j:docx4j_lib'
+else:
+  ASCIIDOCTOR = '//plugins/x-docs/lib/asciidoctor:asciidoc_lib'
+  DAISYDIFF = '//plugins/x-docs/lib/daisydiff:daisydiff_lib'
+  DOCX4J = '//plugins/x-docs/lib/docx4j:docx4j_lib'
 
 gerrit_plugin(
   name = 'x-docs',
@@ -24,6 +27,7 @@
   deps = [
     ASCIIDOCTOR,
     DAISYDIFF,
+    DOCX4J,
   ],
 )
 
diff --git a/lib/antlr/BUCK b/lib/antlr/BUCK
new file mode 100644
index 0000000..f437234
--- /dev/null
+++ b/lib/antlr/BUCK
@@ -0,0 +1,38 @@
+include_defs('//bucklets/maven_jar.bucklet')
+
+VERSION = '3.2'
+
+java_library(
+  name = 'antlr_lib',
+  deps = [
+    ':antlr',
+  ],
+  visibility = ['PUBLIC'],
+)
+
+maven_jar(
+  name = 'antlr',
+  id = 'org.antlr:antlr:' + VERSION,
+  sha1 = '6b0acabea7bb3da058200a77178057e47e25cb69',
+  license = 'antlr',
+  deps = [
+    ':antlr-runtime',
+    ':stringtemplate',
+  ],
+)
+
+maven_jar(
+  name = 'antlr-runtime',
+  id = 'org.antlr:antlr-runtime:' + VERSION,
+  sha1 = '31c746001016c6226bd7356c9f87a6a084ce3715',
+  license = 'antlr',
+)
+
+maven_jar(
+  name = 'stringtemplate',
+  id = 'org.antlr:stringtemplate:' + VERSION,
+  sha1 = '6fe2e3bb57daebd1555494818909f9664376dd6c',
+  license = 'antlr',
+  attach_source = False,
+)
+
diff --git a/lib/avalon-framework/BUCK b/lib/avalon-framework/BUCK
new file mode 100644
index 0000000..467405e
--- /dev/null
+++ b/lib/avalon-framework/BUCK
@@ -0,0 +1,29 @@
+include_defs('//bucklets/maven_jar.bucklet')
+
+VERSION = '4.3.1'
+
+java_library(
+  name = 'avalon-framework_lib',
+  exported_deps = [
+    ':avalon-framework-api',
+    ':avalon-framework-impl',
+  ],
+  visibility = ['PUBLIC'],
+)
+
+maven_jar(
+  name = 'avalon-framework-api',
+  id = 'org.apache.avalon.framework:avalon-framework-api:' + VERSION,
+  sha1 = '2dacadeb49bc14420990b1f28897d46f96e2181d',
+  src_sha1 = '5c04230666be057c5a3ad1558575fc9a886fc1b6',
+  license = 'Apache2.0',
+)
+
+maven_jar(
+  name = 'avalon-framework-impl',
+  id = 'org.apache.avalon.framework:avalon-framework-impl:' + VERSION,
+  sha1 = '2d5f5a07fd14513ce6d7a7bfaff69419c26dbd0b',
+  src_sha1 = '09f779f9b35461a7767a54bc835d21bd2a97ad6e',
+  license = 'Apache2.0',
+)
+
diff --git a/lib/commons/BUCK b/lib/commons/BUCK
new file mode 100644
index 0000000..ba42a1f
--- /dev/null
+++ b/lib/commons/BUCK
@@ -0,0 +1,41 @@
+include_defs('//bucklets/maven_jar.bucklet')
+
+java_library(
+  name = 'commons_lib',
+  deps = [
+    ':codec',
+    ':io',
+    ':lang',
+  ],
+  visibility = ['PUBLIC'],
+)
+
+EXCLUDE = [
+  'META-INF/LICENSE.txt',
+  'META-INF/NOTICE.txt'
+]
+
+maven_jar(
+  name = 'codec',
+  id = 'commons-codec:commons-codec:1.4',
+  sha1 = '4216af16d38465bbab0f3dff8efa14204f7a399a',
+  license = 'Apache2.0',
+  exclude = EXCLUDE,
+)
+
+maven_jar(
+  name = 'io',
+  id = 'commons-io:commons-io:1.4',
+  sha1 = 'a8762d07e76cfde2395257a5da47ba7c1dbd3dce',
+  license = 'Apache2.0',
+  exclude = EXCLUDE,
+)
+
+maven_jar(
+  name = 'lang',
+  id = 'commons-lang:commons-lang:2.5',
+  sha1 = 'b0236b252e86419eef20c31a44579d2aee2f0a69',
+  license = 'Apache2.0',
+  exclude = EXCLUDE,
+)
+
diff --git a/lib/docx4j/BUCK b/lib/docx4j/BUCK
new file mode 100644
index 0000000..b9c84bb
--- /dev/null
+++ b/lib/docx4j/BUCK
@@ -0,0 +1,90 @@
+include_defs('//bucklets/gerrit_plugin.bucklet')
+include_defs('//bucklets/maven_jar.bucklet')
+
+if STANDALONE_MODE:
+  ANTLR  = '//lib/antlr:antlr_lib'
+  AVALON_FRAMEWORK = '//lib/avalon-framework:avalon-framework_lib'
+  COMMONS = '//lib/commons:commons_lib'
+  POI = '//lib/poi:poi_lib'
+  PLUTEXT = '//lib/plutext:plutext_lib'
+  XALAN = '//lib/xalan:xalan_lib'
+  XMLGRAPHICS = '//lib/xmlgraphics:xmlgraphics_lib'
+else:
+  ANTLR = '//plugins/x-docs/lib/antlr:antlr_lib'
+  AVALON_FRAMEWORK = '//plugins/x-docs/lib/avalon-framework:avalon-framework_lib'
+  COMMONS = '//plugins/x-docs/lib/commons:commons_lib'
+  POI = '//plugins/x-docs/lib/poi:poi_lib'
+  PLUTEXT = '//plugins/x-docs/lib/plutext:plutext_lib'
+  XALAN = '//plugins/x-docs/lib/xalan:xalan_lib'
+  XMLGRAPHICS = '//plugins/x-docs/lib/xmlgraphics:xmlgraphics_lib'
+
+java_library(
+  name = 'docx4j_lib',
+  deps = [
+    ANTLR,
+    COMMONS,
+    ':guava',
+  ],
+  exported_deps = [
+    AVALON_FRAMEWORK,
+    POI,
+    PLUTEXT,
+    XALAN,
+    XMLGRAPHICS,
+    ':docx4j',
+    ':mbassador',
+    ':slf4j-api',
+    ':wmf2svg',
+    ':xml-apis',
+  ],
+  visibility = ['PUBLIC'],
+)
+
+maven_jar(
+  name = 'docx4j',
+  id = 'org.docx4j:docx4j:3.2.1',
+  sha1 = '35b2ef9f7eb12efe9708b986ecf6e86cfd77a162',
+  src_sha1 = '49702b88080bc22f6cfa58aadbf5422bcd904094',
+  license = 'Apache2.0',
+)
+
+maven_jar(
+  name = 'guava',
+  id = 'com.google.guava:guava:18.0',
+  sha1 = 'cce0823396aa693798f8882e64213b1772032b09',
+  license = 'Apache2.0',
+  attach_source = False,
+)
+
+maven_jar(
+  name = 'mbassador',
+  id = 'net.engio:mbassador:1.2.0',
+  sha1 = '7aa2c6f172cc8c59983c5255faa45a16a41e173b',
+  src_sha1 = 'd10cdaf71bfcb2002ab904a9d475e60c70c9b6bf',
+  license = 'mbassador',
+)
+
+maven_jar(
+  name = 'slf4j-api',
+  id = 'org.slf4j:slf4j-api:1.7.7',
+  sha1 = '2b8019b6249bb05d81d3a3094e468753e2b21311',
+  src_sha1 = '0acd62e31cc314266e73eebed0b6dd7ea974a0ed',
+  license = 'slf4j',
+)
+
+maven_jar(
+  name = 'wmf2svg',
+  id = 'net.arnx:wmf2svg:0.9.7',
+  sha1 = '88a871f85a0e765c960af88ccc5a9a0e00384cd8',
+  src_sha1 = '6948f9616032bd857c5173b204042889527a3bf3',
+  license = 'Apache2.0',
+)
+
+maven_jar(
+  name = 'xml-apis',
+  id = 'xml-apis:xml-apis:1.3.04',
+  sha1 = '90b215f48fe42776c8c7f6e3509ec54e84fd65ef',
+  src_sha1 = 'd89105ccbe3fd823865330fd964233baf2b53e88',
+  license = 'Apache2.0',
+)
+
diff --git a/lib/docx4j/LICENSE-mbassador b/lib/docx4j/LICENSE-mbassador
new file mode 100644
index 0000000..f8986b8
--- /dev/null
+++ b/lib/docx4j/LICENSE-mbassador
@@ -0,0 +1,13 @@
+MIT License
+
+Copyright (c) 2012 Benjamin Diedrichsen
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
+to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
+and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/lib/docx4j/LICENSE-slf4j b/lib/docx4j/LICENSE-slf4j
new file mode 100644
index 0000000..ff563ee
--- /dev/null
+++ b/lib/docx4j/LICENSE-slf4j
@@ -0,0 +1,22 @@
+Copyright (c) 2004-2013 QOS.ch
+All rights reserved.
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
diff --git a/lib/plutext/BUCK b/lib/plutext/BUCK
new file mode 100644
index 0000000..39da881
--- /dev/null
+++ b/lib/plutext/BUCK
@@ -0,0 +1,37 @@
+include_defs('//bucklets/maven_jar.bucklet')
+
+VERSION = '4.3.1'
+
+java_library(
+  name = 'plutext_lib',
+  exported_deps = [
+    ':jaxb-svg11',
+    ':jaxb-xmldsig-core',
+    ':jaxb-xslfo',
+  ],
+  visibility = ['PUBLIC'],
+)
+
+maven_jar(
+  name = 'jaxb-svg11',
+  id = 'org.plutext:jaxb-svg11:1.0.2',
+  sha1 = '3c0cd54d5691f5b5f8c60ed0c06353ff1db424e1',
+  src_sha1 = 'd2ecea2f14168d693bf68326ebea2ebfc6144114',
+  license = 'Apache2.0',
+)
+
+maven_jar(
+  name = 'jaxb-xmldsig-core',
+  id = 'org.plutext:jaxb-xmldsig-core:1.0.0',
+  sha1 = '57514aa2f72111cfbc0a532ce88782735370e1e5',
+  src_sha1 = 'a41559be6a94177daf0813f63d6ec81b11b3c0d3',
+  license = 'Apache2.0',
+)
+
+maven_jar(
+  name = 'jaxb-xslfo',
+  id = 'org.plutext:jaxb-xslfo:1.0.1',
+  sha1 = '85441209652b216f61160445b399f5bc97e370c6',
+  src_sha1 = 'b81e98b51687771f8a0b12406ea142a6e5dc6539',
+  license = 'Apache2.0',
+)
diff --git a/lib/poi/BUCK b/lib/poi/BUCK
new file mode 100644
index 0000000..1ce3b08
--- /dev/null
+++ b/lib/poi/BUCK
@@ -0,0 +1,29 @@
+include_defs('//bucklets/maven_jar.bucklet')
+
+VERSION = '3.10.1'
+
+java_library(
+  name = 'poi_lib',
+  exported_deps = [
+    ':poi',
+    ':poi-scratchpad',
+  ],
+  visibility = ['PUBLIC'],
+)
+
+maven_jar(
+  name = 'poi',
+  id = 'org.apache.poi:poi:' + VERSION,
+  sha1 = '95174823e13aa828cb715b542e647e56096ffcb2',
+  src_sha1 = 'dcbcab74270ee3f68da61ef13c6f0858fb532e52',
+  license = 'Apache2.0',
+)
+
+maven_jar(
+  name = 'poi-scratchpad',
+  id = 'org.apache.poi:poi-scratchpad:' + VERSION,
+  sha1 = 'f40da8984b7a9bdf81270d7ecd2639548361fccd',
+  src_sha1 = '88df5b9afa00070902f9bb100c554dba289afc7a',
+  license = 'Apache2.0',
+)
+
diff --git a/lib/xalan/BUCK b/lib/xalan/BUCK
new file mode 100644
index 0000000..0eaa213
--- /dev/null
+++ b/lib/xalan/BUCK
@@ -0,0 +1,29 @@
+include_defs('//bucklets/maven_jar.bucklet')
+
+VERSION = '2.7.2'
+
+java_library(
+  name = 'xalan_lib',
+  exported_deps = [
+    ':xalan',
+    ':serializer',
+  ],
+  visibility = ['PUBLIC'],
+)
+
+maven_jar(
+  name = 'xalan',
+  id = 'xalan:xalan:' + VERSION,
+  sha1 = 'd55d3f02a56ec4c25695fe67e1334ff8c2ecea23',
+  src_sha1 = 'fe9c3d37a49238fac9d4d6c4f5bbd8c334da787a',
+  license = 'Apache2.0',
+)
+
+maven_jar(
+  name = 'serializer',
+  id = 'xalan:serializer:' + VERSION,
+  sha1 = '24247f3bb052ee068971393bdb83e04512bb1c3c',
+  src_sha1 = 'fe9c3d37a49238fac9d4d6c4f5bbd8c334da787a',
+  license = 'Apache2.0',
+)
+
diff --git a/lib/xmlgraphics/BUCK b/lib/xmlgraphics/BUCK
new file mode 100644
index 0000000..b408e90
--- /dev/null
+++ b/lib/xmlgraphics/BUCK
@@ -0,0 +1,173 @@
+include_defs('//bucklets/maven_jar.bucklet')
+
+BATIK_VERSION = '1.7'
+
+java_library(
+  name = 'xmlgraphics_lib',
+  exported_deps = [
+    ':batik-anim',
+    ':batik-awt-util',
+    ':batik-bridge',
+    ':batik-css',
+    ':batik-dom',
+    ':batik-ext',
+    ':batik-extension',
+    ':batik-gvt',
+    ':batik-js',
+    ':batik-parser',
+    ':batik-script',
+    ':batik-svg-dom',
+    ':batik-svggen',
+    ':batik-transcoder',
+    ':batik-util',
+    ':batik-xml',
+    ':fop',
+    ':xmlgraphics-commons',
+  ],
+  visibility = ['PUBLIC'],
+)
+
+maven_jar(
+  name = 'batik-anim',
+  id = 'org.apache.xmlgraphics:batik-anim:' + BATIK_VERSION,
+  sha1 = 'a45dd2ff8e4ecd56a4fc64dc668b53bee90bf601',
+  license = 'Apache2.0',
+  attach_source = False,
+)
+
+maven_jar(
+  name = 'batik-awt-util',
+  id = 'org.apache.xmlgraphics:batik-awt-util:' + BATIK_VERSION,
+  sha1 = '67605a29d49bf33f3c1d7832f490b0a007e7a6e2',
+  license = 'Apache2.0',
+  attach_source = False,
+)
+
+maven_jar(
+  name = 'batik-bridge',
+  id = 'org.apache.xmlgraphics:batik-bridge:' + BATIK_VERSION,
+  sha1 = '8e0cde3830e0f17704cd392b0a09b13944987a51',
+  license = 'Apache2.0',
+  attach_source = False,
+)
+
+maven_jar(
+  name = 'batik-css',
+  id = 'org.apache.xmlgraphics:batik-css:' + BATIK_VERSION,
+  sha1 = 'e6bb5c85753331534593f33fb9236acb41a0ab79',
+  license = 'Apache2.0',
+  attach_source = False,
+)
+
+maven_jar(
+  name = 'batik-dom',
+  id = 'org.apache.xmlgraphics:batik-dom:' + BATIK_VERSION,
+  sha1 = '710d559bd1df52581b57b75a99ed5fd2e2918bb7',
+  license = 'Apache2.0',
+  attach_source = False,
+)
+
+maven_jar(
+  name = 'batik-ext',
+  id = 'org.apache.xmlgraphics:batik-ext:' + BATIK_VERSION,
+  sha1 = '4784302b44a0336166fef6153a5e3d73e861aecc',
+  license = 'Apache2.0',
+  attach_source = False,
+)
+
+maven_jar(
+  name = 'batik-extension',
+  id = 'org.apache.xmlgraphics:batik-extension:' + BATIK_VERSION,
+  sha1 = '8e810d9ce0499beca541e3b1a144557cf06f8b19',
+  license = 'Apache2.0',
+  attach_source = False,
+)
+
+maven_jar(
+  name = 'batik-gvt',
+  id = 'org.apache.xmlgraphics:batik-gvt:' + BATIK_VERSION,
+  sha1 = '03d315e60d72c761c52946b4acaa4b86239ef938',
+  license = 'Apache2.0',
+  attach_source = False,
+)
+
+maven_jar(
+  name = 'batik-js',
+  id = 'org.apache.xmlgraphics:batik-js:' + BATIK_VERSION,
+  sha1 = '688eb1bf13b7a54491fcb3405068fc5092589884',
+  license = 'Apache2.0',
+  attach_source = False,
+)
+
+maven_jar(
+  name = 'batik-parser',
+  id = 'org.apache.xmlgraphics:batik-parser:' + BATIK_VERSION,
+  sha1 = '5d756cc4f6bf891793e6c7590773859c33a8609f',
+  license = 'Apache2.0',
+  attach_source = False,
+)
+
+maven_jar(
+  name = 'batik-script',
+  id = 'org.apache.xmlgraphics:batik-script:' + BATIK_VERSION,
+  sha1 = '4ea7906724bfefc1fca3e5b28229a458523e1fbf',
+  license = 'Apache2.0',
+  attach_source = False,
+)
+
+maven_jar(
+  name = 'batik-svg-dom',
+  id = 'org.apache.xmlgraphics:batik-svg-dom:' + BATIK_VERSION,
+  sha1 = '5b3b1fea480fabbd3e0c44540af25b9fda0587ae',
+  license = 'Apache2.0',
+  attach_source = False,
+)
+
+maven_jar(
+  name = 'batik-svggen',
+  id = 'org.apache.xmlgraphics:batik-svggen:' + BATIK_VERSION,
+  sha1 = 'baa58d0f5bfd2a28142e222cee126eb71bd0a938',
+  license = 'Apache2.0',
+  attach_source = False,
+)
+
+maven_jar(
+  name = 'batik-transcoder',
+  id = 'org.apache.xmlgraphics:batik-transcoder:' + BATIK_VERSION,
+  sha1 = 'aa2eb6300cb50bbb9dbf52daf7d625aa0df1d930',
+  license = 'Apache2.0',
+  attach_source = False,
+)
+
+maven_jar(
+  name = 'batik-util',
+  id = 'org.apache.xmlgraphics:batik-util:' + BATIK_VERSION,
+  sha1 = '5c4dd0dd9a86a2fba2c6ea26fb62b32b21b2a61e',
+  license = 'Apache2.0',
+  attach_source = False,
+)
+
+maven_jar(
+  name = 'batik-xml',
+  id = 'org.apache.xmlgraphics:batik-xml:' + BATIK_VERSION,
+  sha1 = '17e3da8bd9d4a131350a7835f5cc0d93ba199c89',
+  license = 'Apache2.0',
+  attach_source = False,
+)
+
+maven_jar(
+  name = 'fop',
+  id = 'org.apache.xmlgraphics:fop:1.1',
+  sha1 = '95978100a6cde324078947a2d476cf2f207a7e5a',
+  license = 'Apache2.0',
+  attach_source = False,
+)
+
+maven_jar(
+  name = 'xmlgraphics-commons',
+  id = 'org.apache.xmlgraphics:xmlgraphics-commons:1.5',
+  sha1 = '7fb5c2b2c18f0e87fbe9bded16429a5d7cc2dc2b',
+  license = 'Apache2.0',
+  attach_source = False,
+)
+
diff --git a/pom.xml b/pom.xml
index 7a08bdf..bfb6513 100644
--- a/pom.xml
+++ b/pom.xml
@@ -125,16 +125,221 @@
       <version>2.6.1</version>
       <scope>provided</scope>
     </dependency>
+
     <dependency>
       <groupId>org.asciidoctor</groupId>
       <artifactId>asciidoctorj</artifactId>
       <version>1.5.1</version>
     </dependency>
+
     <dependency>
       <groupId>org.outerj.daisy</groupId>
       <artifactId>daisydiff</artifactId>
       <version>1.1</version>
     </dependency>
+
+    <dependency>
+      <groupId>org.docx4j</groupId>
+      <artifactId>docx4j</artifactId>
+      <version>3.2.1</version>
+    </dependency>
+    <dependency>
+      <groupId>org.antlr</groupId>
+      <artifactId>antlr</artifactId>
+      <version>3.2</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.antlr</groupId>
+      <artifactId>antlr-runtime</artifactId>
+      <version>3.2</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.antlr</groupId>
+      <artifactId>stringtemplate</artifactId>
+      <version>3.2</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.avalon.framework</groupId>
+      <artifactId>avalon-framework-api</artifactId>
+      <version>4.3.1</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.avalon.framework</groupId>
+      <artifactId>avalon-framework-impl</artifactId>
+      <version>4.3.1</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.xmlgraphics</groupId>
+      <artifactId>batik-anim</artifactId>
+      <version>1.7</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.xmlgraphics</groupId>
+      <artifactId>batik-awt-util</artifactId>
+      <version>1.7</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.xmlgraphics</groupId>
+      <artifactId>batik-bridge</artifactId>
+      <version>1.7</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.xmlgraphics</groupId>
+      <artifactId>batik-css</artifactId>
+      <version>1.7</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.xmlgraphics</groupId>
+      <artifactId>batik-dom</artifactId>
+      <version>1.7</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.xmlgraphics</groupId>
+      <artifactId>batik-ext</artifactId>
+      <version>1.7</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.xmlgraphics</groupId>
+      <artifactId>batik-extension</artifactId>
+      <version>1.7</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.xmlgraphics</groupId>
+      <artifactId>batik-gvt</artifactId>
+      <version>1.7</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.xmlgraphics</groupId>
+      <artifactId>batik-js</artifactId>
+      <version>1.7</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.xmlgraphics</groupId>
+      <artifactId>batik-parser</artifactId>
+      <version>1.7</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.xmlgraphics</groupId>
+      <artifactId>batik-script</artifactId>
+      <version>1.7</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.xmlgraphics</groupId>
+      <artifactId>batik-svg-dom</artifactId>
+      <version>1.7</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.xmlgraphics</groupId>
+      <artifactId>batik-svggen</artifactId>
+      <version>1.7</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.xmlgraphics</groupId>
+      <artifactId>batik-transcoder</artifactId>
+      <version>1.7</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.xmlgraphics</groupId>
+      <artifactId>batik-util</artifactId>
+      <version>1.7</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.xmlgraphics</groupId>
+      <artifactId>batik-xml</artifactId>
+      <version>1.7</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.xmlgraphics</groupId>
+      <artifactId>fop</artifactId>
+      <version>1.1</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.xmlgraphics</groupId>
+      <artifactId>xmlgraphics-commons</artifactId>
+      <version>1.5</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.poi</groupId>
+      <artifactId>poi</artifactId>
+      <version>3.10.1</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.poi</groupId>
+      <artifactId>poi-scratchpad</artifactId>
+      <version>3.10.1</version>
+    </dependency>
+    <dependency>
+      <groupId>commons-codec</groupId>
+      <artifactId>commons-codec</artifactId>
+      <version>1.4</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>commons-io</groupId>
+      <artifactId>commons-io</artifactId>
+      <version>1.4</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>commons-lang</groupId>
+      <artifactId>commons-lang</artifactId>
+      <version>2.5</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>com.google.guava</groupId>
+      <artifactId>guava</artifactId>
+      <version>18.0</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.plutext</groupId>
+      <artifactId>jaxb-svg11</artifactId>
+      <version>1.0.2</version>
+    </dependency>
+    <dependency>
+      <groupId>org.plutext</groupId>
+      <artifactId>jaxb-xmldsig-core</artifactId>
+      <version>1.0.0</version>
+    </dependency>
+    <dependency>
+      <groupId>org.plutext</groupId>
+      <artifactId>jaxb-xslfo</artifactId>
+      <version>1.0.1</version>
+    </dependency>
+    <dependency>
+      <groupId>net.engio</groupId>
+      <artifactId>mbassador</artifactId>
+      <version>1.2.0</version>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-api</artifactId>
+      <version>1.7.7</version>
+    </dependency>
+    <dependency>
+      <groupId>net.arnx</groupId>
+      <artifactId>wmf2svg</artifactId>
+      <version>0.9.7</version>
+    </dependency>
+    <dependency>
+      <groupId>xalan</groupId>
+      <artifactId>xalan</artifactId>
+      <version>2.7.2</version>
+    </dependency>
+    <dependency>
+      <groupId>xalan</groupId>
+      <artifactId>serializer</artifactId>
+      <version>2.7.2</version>
+    </dependency>
+    <dependency>
+      <groupId>xml-apis</groupId>
+      <artifactId>xml-apis</artifactId>
+      <version>1.3.04</version>
+    </dependency>
   </dependencies>
 
   <repositories>
diff --git a/src/main/java/com/googlesource/gerrit/plugins/xdocs/Module.java b/src/main/java/com/googlesource/gerrit/plugins/xdocs/Module.java
index 7ca2d9a..3f73760 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/xdocs/Module.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/xdocs/Module.java
@@ -31,6 +31,7 @@
 import com.googlesource.gerrit.plugins.xdocs.client.SideBySideDiffPreviewWebLink;
 import com.googlesource.gerrit.plugins.xdocs.client.UnifiedDiffPreviewWebLink;
 import com.googlesource.gerrit.plugins.xdocs.formatter.AsciidoctorFormatter;
+import com.googlesource.gerrit.plugins.xdocs.formatter.DocxFormatter;
 import com.googlesource.gerrit.plugins.xdocs.formatter.Formatter;
 import com.googlesource.gerrit.plugins.xdocs.formatter.MarkdownFormatter;
 import com.googlesource.gerrit.plugins.xdocs.formatter.PlainTextFormatter;
@@ -56,6 +57,9 @@
         .annotatedWith(Exports.named(AsciidoctorFormatter.NAME))
         .to(AsciidoctorFormatter.class);
     bind(Formatter.class)
+        .annotatedWith(Exports.named(DocxFormatter.NAME))
+        .to(DocxFormatter.class);
+    bind(Formatter.class)
         .annotatedWith(Exports.named(MarkdownFormatter.NAME))
         .to(MarkdownFormatter.class);
     bind(Formatter.class)
diff --git a/src/main/java/com/googlesource/gerrit/plugins/xdocs/XDocGlobalConfig.java b/src/main/java/com/googlesource/gerrit/plugins/xdocs/XDocGlobalConfig.java
index 1f86e69..41e3a67 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/xdocs/XDocGlobalConfig.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/xdocs/XDocGlobalConfig.java
@@ -15,6 +15,7 @@
 package com.googlesource.gerrit.plugins.xdocs;
 
 import com.googlesource.gerrit.plugins.xdocs.formatter.AsciidoctorFormatter;
+import com.googlesource.gerrit.plugins.xdocs.formatter.DocxFormatter;
 import com.googlesource.gerrit.plugins.xdocs.formatter.MarkdownFormatter;
 import com.googlesource.gerrit.plugins.xdocs.formatter.PlainTextFormatter;
 import com.googlesource.gerrit.plugins.xdocs.formatter.ZipFormatter;
@@ -48,6 +49,8 @@
 
   static void initialize(Config cfg) {
     cfg.setString(SECTION_FORMATTER, AsciidoctorFormatter.NAME, KEY_EXT, "adoc");
+    cfg.setStringList(SECTION_FORMATTER, DocxFormatter.NAME, KEY_EXT,
+        Arrays.asList("docx", "pptx", "xlsx"));
     cfg.setString(SECTION_FORMATTER, MarkdownFormatter.NAME, KEY_MIME_TYPE,
         "text/x-markdown");
     cfg.setString(SECTION_FORMATTER, PlainTextFormatter.NAME, KEY_MIME_TYPE,
diff --git a/src/main/java/com/googlesource/gerrit/plugins/xdocs/formatter/DocxFormatter.java b/src/main/java/com/googlesource/gerrit/plugins/xdocs/formatter/DocxFormatter.java
new file mode 100644
index 0000000..f9eb83a
--- /dev/null
+++ b/src/main/java/com/googlesource/gerrit/plugins/xdocs/formatter/DocxFormatter.java
@@ -0,0 +1,68 @@
+// Copyright (C) 2014 The Android Open Source Project
+//
+// Licensed 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 com.googlesource.gerrit.plugins.xdocs.formatter;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+
+import com.google.inject.Inject;
+
+import com.googlesource.gerrit.plugins.xdocs.ConfigSection;
+
+import org.docx4j.Docx4J;
+import org.docx4j.Docx4jProperties;
+import org.docx4j.convert.out.HTMLSettings;
+import org.docx4j.openpackaging.exceptions.Docx4JException;
+import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+public class DocxFormatter implements StreamFormatter {
+  public static final String NAME = "DOCX";
+
+  private final FormatterUtil util;
+
+  @Inject
+  DocxFormatter(FormatterUtil formatterUtil) {
+    this.util = formatterUtil;
+  }
+
+  @Override
+  public String format(String projectName, String revision, ConfigSection cfg,
+      InputStream raw) throws IOException {
+    // Docx4J tries to load some resources dynamically. This fails if the Gerrit
+    // core classloader is used since it doesn't see the resources that are
+    // contained in the plugin jar. To make the resource loading work we
+    // must set a context classloader on the current thread.
+    ClassLoader loader = Thread.currentThread().getContextClassLoader();
+    try {
+      Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
+      WordprocessingMLPackage p = Docx4J.load(raw);
+      HTMLSettings htmlSettings = Docx4J.createHTMLSettings();
+      htmlSettings.setWmlPackage(p);
+      Docx4jProperties.setProperty("docx4j.Convert.Out.HTML.OutputMethodXML", true);
+      try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
+        Docx4J.toHTML(htmlSettings, out, Docx4J.FLAG_EXPORT_PREFER_XSL);
+        String html = out.toString(UTF_8.name());
+        return util.applyCss(html, NAME, projectName);
+      }
+    } catch (Docx4JException e) {
+      throw new IOException(e);
+    } finally {
+      Thread.currentThread().setContextClassLoader(loader);
+    }
+  }
+}
diff --git a/src/main/resources/Documentation/about.md b/src/main/resources/Documentation/about.md
index 7477b6e..5039d46 100644
--- a/src/main/resources/Documentation/about.md
+++ b/src/main/resources/Documentation/about.md
@@ -67,6 +67,15 @@
     </td>
   </tr>
   <tr>
+    <td><tt>DocxFormatter</tt></td>
+    <td><tt>DOCX</tt></td>
+    <td>Formatter for <tt>.docx</tt>, <tt>.pptx</tt> and <tt>.xlsx</tt> files.</td>
+    <td><a href="../../../Documentation/licenses.html#Apache2_0">Apache2.0</a><br/></td>
+    <td>
+      <a href="http://www.docx4java.org/trac/docx4j">http://www.docx4java.org/trac/docx4j</a></br>
+    </td>
+  </tr>
+  <tr>
     <td><tt>MarkdownFormatter</tt></td>
     <td><tt>MARKDOWN</tt></td>
     <td>Formatter for documentation that is written in
diff --git a/src/main/resources/Documentation/config.md b/src/main/resources/Documentation/config.md
index 2b12b55..5184c96 100644
--- a/src/main/resources/Documentation/config.md
+++ b/src/main/resources/Documentation/config.md
@@ -96,7 +96,8 @@
 	Overrides the [global configuration of `inheritCss`](#formatterInheritCss)
 	for this formatter.
 
-	Supported for the following formatters: `ASCIIDOCTOR`, `MARKDOWN`, `ZIP`
+	Supported for the following formatters: `ASCIIDOCTOR`, `DOCX`,
+	`MARKDOWN`, `ZIP`
 
 	Default: `true` (CSS is inherited)
 
@@ -111,7 +112,8 @@
 	Overrides the [global configuration of `cssTheme`](#formatterCssTheme)
 	for this formatter.
 
-	Supported for the following formatters: `ASCIIDOCTOR`, `MARKDOWN`, `ZIP`
+	Supported for the following formatters: `ASCIIDOCTOR`, `DOCX`,
+	`MARKDOWN`, `ZIP`
 
 	By default not set.
 
@@ -136,6 +138,7 @@
 provided in the `refs/meta/config` branch of the project:
 
 * `ASCIIDOCTOR`: `@PLUGIN@/asciidoctor.css`
+* `DOCX`: `@PLUGIN@/docx.css`
 * `MARKDOWN`: `@PLUGIN@/markdown.css`
 * `ZIP`: `@PLUGIN@/zip.css`
 
@@ -155,6 +158,10 @@
 ```
   [formatter "ASCIIDOCTOR"]
     ext = adoc
+  [formatter "DOCX"]
+    ext = docx
+    ext = pptx
+    ext = xlsx
   [formatter "MARKDOWN"]
     mimeType = text/x-markdown
   [formatter "PLAIN_TEXT"]
@@ -168,6 +175,7 @@
 Supported formatters:
 
 * `ASCIIDOCTOR`
+* `DOCX`
 * `MARKDOWN`
 * `PLAIN_TEXT`
 * `ZIP`
@@ -249,7 +257,8 @@
 
 	Can be overridden on [project-level](#inheritCss).
 
-	Supported for the following formatters: `ASCIIDOCTOR`, `MARKDOWN`, `ZIP`
+	Supported for the following formatters: `ASCIIDOCTOR`, `DOCX`,
+	`MARKDOWN`, `ZIP`
 
 	Default: `true` (CSS is inherited)
 
@@ -262,7 +271,8 @@
 
 	Can be overridden on [project-level](#cssTheme).
 
-	Supported for the following formatters: `ASCIIDOCTOR`, `MARKDOWN`, `ZIP`
+	Supported for the following formatters: `ASCIIDOCTOR`, `DOCX`,
+	`MARKDOWN`, `ZIP`
 
 	By default not set.
 
@@ -300,5 +310,6 @@
 providing CSS files in `<review-site>/data/@PLUGIN@/css/`:
 
 * `ASCIIDOCTOR`: `asciidoctor.css`
+* `DOCX`: `docx.css`
 * `MARKDOWN`: `markdown.css`
 * `ZIP`: `zip.css`
diff --git a/src/main/resources/com/googlesource/gerrit/plugins/xdocs/formatter/docx.css b/src/main/resources/com/googlesource/gerrit/plugins/xdocs/formatter/docx.css
new file mode 100644
index 0000000..f657db5
--- /dev/null
+++ b/src/main/resources/com/googlesource/gerrit/plugins/xdocs/formatter/docx.css
@@ -0,0 +1,38 @@
+/* Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed 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.
+ */
+
+html,
+body,
+div,
+span,
+h1, h2, h3, h4, h5, h6,
+p,
+a,
+img,
+ol, ul, li,
+table,
+caption,
+tbody,
+tfoot,
+thead,
+tr, th, td {
+  margin: 0;
+  padding: 0;
+  border: 0;
+}
+
+body {
+  line-height: 1;
+}