merge trunk

git-svn-id: https://svn.apache.org/repos/asf/poi/branches/hemf@1840324 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andreas Beeker 2018-09-07 21:26:56 +00:00
commit 24f14e2494
19 changed files with 336 additions and 255 deletions

View File

@ -91,9 +91,9 @@ subprojects {
// See https://github.com/melix/japicmp-gradle-plugin // See https://github.com/melix/japicmp-gradle-plugin
apply plugin: 'me.champeau.gradle.japicmp' apply plugin: 'me.champeau.gradle.japicmp'
version = '4.0.0-SNAPSHOT' version = '4.0.1-SNAPSHOT'
ext { ext {
japicmpversion = '3.17' japicmpversion = '4.0.0'
} }
tasks.withType(JavaCompile) { tasks.withType(JavaCompile) {

131
build.xml
View File

@ -42,7 +42,7 @@ under the License.
<description>The Apache POI project Ant build.</description> <description>The Apache POI project Ant build.</description>
<property name="version.id" value="4.0.1-beta1"/> <property name="version.id" value="4.0.1-SNAPSHOT"/>
<property name="release.rc" value="RC1"/> <property name="release.rc" value="RC1"/>
<property environment="env"/> <property environment="env"/>
@ -552,7 +552,6 @@ under the License.
<scriptdef name="release_tag" language="javascript"> <scriptdef name="release_tag" language="javascript">
var rel = ("REL_"+project.getProperty("version.id")).toUpperCase().replace(/\W/g,"_"); var rel = ("REL_"+project.getProperty("version.id")).toUpperCase().replace(/\W/g,"_");
if (rel.search(/BETA/) == -1) rel += "_FINAL";
project.setProperty("RELEASE_TAG", rel); project.setProperty("RELEASE_TAG", rel);
</scriptdef> </scriptdef>
<release_tag/> <release_tag/>
@ -2545,7 +2544,6 @@ under the License.
<scriptdef name="getnextrel" language="javascript"> <scriptdef name="getnextrel" language="javascript">
var relCurr = new String(project.getProperty("version.id")); var relCurr = new String(project.getProperty("version.id"));
var relNext = relCurr.replace(/[0-9]+$/, function(lastNum){ return new String(new Number(lastNum)+1); }); var relNext = relCurr.replace(/[0-9]+$/, function(lastNum){ return new String(new Number(lastNum)+1); });
if (relNext.search(/beta/i) == -1) relNext += "-beta1";
project.setProperty("rel_next", relNext); project.setProperty("rel_next", relNext);
</scriptdef> </scriptdef>
<getnextrel/> <getnextrel/>
@ -2591,7 +2589,7 @@ under the License.
message="tag r${svn_version2} as ${version.id}"/> message="tag r${svn_version2} as ${version.id}"/>
</svn> </svn>
<!-- update build.xml to the next beta version --> <!-- update build.xml to the next snapshot version -->
<antcall target="-update-build.xml"> <antcall target="-update-build.xml">
<param name="version_id" value="${rel_next}"/> <param name="version_id" value="${rel_next}"/>
</antcall> </antcall>
@ -2605,7 +2603,7 @@ under the License.
</fileset> </fileset>
</replaceregexp> </replaceregexp>
<!-- unpin documentation and commit next beta version --> <!-- unpin documentation and commit next snapshot version -->
<svn refid="svn.settings"> <svn refid="svn.settings">
<update dir="." recurse="true"/> <update dir="." recurse="true"/>
<propset path="src" name="svn:externals" value="documentation https://svn.apache.org/repos/asf/poi/site/src/documentation"/> <propset path="src" name="svn:externals" value="documentation https://svn.apache.org/repos/asf/poi/site/src/documentation"/>
@ -2656,6 +2654,45 @@ under the License.
</svn> </svn>
</target> </target>
<target name="release-finish" description="write the dist to the release candidate repo - needs Java7+">
<!--svn refid="svn.settings">
<update dir="." recurse="true"/>
</svn-->
<local name="rel_prev"/>
<local name="file_date"/>
<local name="file_date_iso"/>
<tstamp>
<!-- usually overwritten by a command line argument -->
<!-- for convience this is kept in the same format as in the release-prep call -->
<format property="file_date" pattern="yyyyMMdd" locale="US"/>
</tstamp>
<scriptdef name="getnextrel" language="javascript">
var relPrev = new String(project.getProperty("version.id"))
.replace(/([0-9]+)[^0-9]*$/, function(all,lastNum){ return new String(new Number(lastNum)-1); });
project.setProperty("rel_prev", relPrev);
var fileDateIso = new String(project.getProperty("file_date"))
.replace(/([0-9]{4})([0-9]{2})([0-9]{2})/, "$1-$2-$3");
project.setProperty("file_date_iso", fileDateIso);
</scriptdef>
<getnextrel/>
<replaceregexp file="build.gradle" match="( +version += +)'[^']+'" replace="\1'${version.id}'"/>
<replaceregexp file="build.gradle" match="(japicmpversion += +)'[^']+'" replace="\1'${rel_prev}'"/>
<replaceregexp file="src/examples/groovy/build.gradle" match="( *compile 'org.apache.poi:[^0-9]+)([0-9.]+)'" replace="\1${rel_prev}'" byline="true"/>
<replaceregexp file="src/examples/scala/build.sbt" match='( *org.apache.poi.* ")[0-9.]+(.+)' replace="\1${rel_prev}\2" byline="true"/>
<replaceregexp file="osgi/build.xml" match='(name="version.id" value=")[^"]+' replace="\1${version.id}"/>
<replaceregexp file="doap_POI.rdf" match="&lt;release&gt;" replace="&lt;release&gt;&#10; &lt;Version&gt;&#10; &lt;name&gt;Apache POI ${rel_prev}&lt;/name&gt;&#10; &lt;created&gt;${file_date_iso}&lt;/created&gt;&#10; &lt;revision&gt;${rel_prev}&lt;/revision&gt;&#10; &lt;/Version&gt;&#10; &lt;/release&gt;&#10; &lt;release&gt;"/>
<replaceregexp match="(&lt;version&gt;)[^&lt;]+" replace="\1${version.id}">
<fileset dir="sonar" includes="**/pom.xml"/>
</replaceregexp>
</target>
<target name="-update-build.xml"> <target name="-update-build.xml">
<replaceregexp byline="true"> <replaceregexp byline="true">
<regexp pattern="(&lt;property name=&quot;version.id&quot; value=&quot;)[^&quot;]+(&quot;/>)"/> <regexp pattern="(&lt;property name=&quot;version.id&quot; value=&quot;)[^&quot;]+(&quot;/>)"/>
@ -2758,21 +2795,15 @@ under the License.
<format property="rel_date" pattern="dd MMMM yyyy" locale="US"/> <format property="rel_date" pattern="dd MMMM yyyy" locale="US"/>
<format property="file_date" pattern="yyyyMMdd" locale="US"/> <format property="file_date" pattern="yyyyMMdd" locale="US"/>
</tstamp> </tstamp>
<!-- TODO: change reltype (dev/release), depending on BETA / FINAL --> <property name="baseurl" value="https://www.apache.org/dist/poi/release"/>
<property name="reltype" value="dev"/>
<property name="baseurl" value="https://www.apache.org/dist/poi/${reltype}"/>
<loadChecksum property="bin-tar-md5" url="${baseurl}/bin/poi-bin-${version.id}-${file_date}.tar.gz.md5"/> <loadChecksum property="bin-tar-sha256" url="${baseurl}/bin/poi-bin-${version.id}-${file_date}.tar.gz.sha256"/>
<loadChecksum property="bin-tar-sha1" url="${baseurl}/bin/poi-bin-${version.id}-${file_date}.tar.gz.sha1"/>
<loadChecksum property="bin-tar-sha512" url="${baseurl}/bin/poi-bin-${version.id}-${file_date}.tar.gz.sha512"/> <loadChecksum property="bin-tar-sha512" url="${baseurl}/bin/poi-bin-${version.id}-${file_date}.tar.gz.sha512"/>
<loadChecksum property="bin-zip-md5" url="${baseurl}/bin/poi-bin-${version.id}-${file_date}.zip.md5"/> <loadChecksum property="bin-zip-sha256" url="${baseurl}/bin/poi-bin-${version.id}-${file_date}.zip.sha256"/>
<loadChecksum property="bin-zip-sha1" url="${baseurl}/bin/poi-bin-${version.id}-${file_date}.zip.sha1"/>
<loadChecksum property="bin-zip-sha512" url="${baseurl}/bin/poi-bin-${version.id}-${file_date}.zip.sha512"/> <loadChecksum property="bin-zip-sha512" url="${baseurl}/bin/poi-bin-${version.id}-${file_date}.zip.sha512"/>
<loadChecksum property="src-tar-md5" url="${baseurl}/src/poi-src-${version.id}-${file_date}.tar.gz.md5"/> <loadChecksum property="src-tar-sha256" url="${baseurl}/src/poi-src-${version.id}-${file_date}.tar.gz.sha256"/>
<loadChecksum property="src-tar-sha1" url="${baseurl}/src/poi-src-${version.id}-${file_date}.tar.gz.sha1"/>
<loadChecksum property="src-tar-sha512" url="${baseurl}/src/poi-src-${version.id}-${file_date}.tar.gz.sha512"/> <loadChecksum property="src-tar-sha512" url="${baseurl}/src/poi-src-${version.id}-${file_date}.tar.gz.sha512"/>
<loadChecksum property="src-zip-md5" url="${baseurl}/src/poi-src-${version.id}-${file_date}.zip.md5"/> <loadChecksum property="src-zip-sha256" url="${baseurl}/src/poi-src-${version.id}-${file_date}.zip.sha256"/>
<loadChecksum property="src-zip-sha1" url="${baseurl}/src/poi-src-${version.id}-${file_date}.zip.sha1"/>
<loadChecksum property="src-zip-sha512" url="${baseurl}/src/poi-src-${version.id}-${file_date}.zip.sha512"/> <loadChecksum property="src-zip-sha512" url="${baseurl}/src/poi-src-${version.id}-${file_date}.zip.sha512"/>
<loadFilesize property="bin-tar-size" url="${baseurl}/bin/poi-bin-${version.id}-${file_date}.tar.gz"/> <loadFilesize property="bin-tar-size" url="${baseurl}/bin/poi-bin-${version.id}-${file_date}.tar.gz"/>
@ -2785,69 +2816,57 @@ under the License.
<p>The Apache POI team is pleased to announce the release of ${version.id}. <p>The Apache POI team is pleased to announce the release of ${version.id}.
Featured are a handful of new areas of functionality and numerous bug fixes.</p> Featured are a handful of new areas of functionality and numerous bug fixes.</p>
<p>A summary of changes is available in the <p>A summary of changes is available in the
<link href="https://www.apache.org/dyn/closer.lua/poi/dev/RELEASE-NOTES-${version.id}.txt">Release Notes</link>. <a href="https://www.apache.org/dyn/closer.lua/poi/dev/RELEASE-NOTES-${version.id}.txt">Release Notes</a>.
A full list of changes is available in the <link href="changes.html">change log</link>. A full list of changes is available in the <a href="site:changes">change log</a>.
People interested should also follow the <link href="mailinglists.html">dev list</link> People interested should also follow the <a href="site:mailinglists">dev list</a>
to track progress.</p> to track progress.</p>
<p> <p>
The POI source release as well as the pre-built binary deployment packages are listed below. The POI source release as well as the pre-built binary deployment packages are listed below.
Pre-built versions of all <link href="overview.html#components">POI components</link> Pre-built versions of all <a href="site:components">POI components</a>
are available in the central Maven repository under Group ID "org.apache.poi" and Version are available in the central Maven repository under Group ID "org.apache.poi" and Version
"${version.id}". "${version.id}".
</p> </p>
<section id="POI-${version.id}-bin"><title>Binary Distribution</title> <section id="POI-${version.id}-bin"><title>Binary Distribution</title>
<ul> <ul>
<li><link href="https://www.apache.org/dyn/closer.lua/poi/${reltype}/bin/poi-bin-${version.id}-${file_date}.tar.gz">poi-bin-${version.id}-${file_date}.tar.gz</link> <li><a href="https://www.apache.org/dyn/closer.lua/poi/release/bin/poi-bin-${version.id}-${file_date}.tar.gz">poi-bin-${version.id}-${file_date}.tar.gz</a>
(${bin-tar-size} MB, <link href="https://www.apache.org/dist/poi/${reltype}/bin/poi-bin-${version.id}-${file_date}.tar.gz.asc">signature (.asc)</link>) (${bin-tar-size} MB, <a href="https://www.apache.org/dist/poi/release/bin/poi-bin-${version.id}-${file_date}.tar.gz.asc">signature (.asc)</a>)
<br/> <br/>
MD5 checksum: <link href="https://www.apache.org/dist/poi/${reltype}/bin/poi-bin-${version.id}-${file_date}.tar.gz.md5"> SHA256 checksum: <a href="https://www.apache.org/dist/poi/release/bin/poi-bin-${version.id}-${file_date}.tar.gz.sha256">
${bin-tar-md5}</link> ${bin-tar-sha256}</a>
<br/> <br/>
SHA1 checksum: <link href="https://www.apache.org/dist/poi/${reltype}/bin/poi-bin-${version.id}-${file_date}.tar.gz.sha1"> SHA512 checksum: <a href="https://www.apache.org/dist/poi/release/bin/poi-bin-${version.id}-${file_date}.tar.gz.sha512">
${bin-tar-sha1}</link> ${bin-tar-sha512}</a>
<br/>
SHA512 checksum: <link href="https://www.apache.org/dist/poi/${reltype}/bin/poi-bin-${version.id}-${file_date}.tar.gz.sha512">
${bin-tar-sha512}</link>
</li> </li>
<li><link href="https://www.apache.org/dyn/closer.lua/poi/${reltype}/bin/poi-bin-${version.id}-${file_date}.zip">poi-bin-${version.id}-${file_date}.zip</link> <li><a href="https://www.apache.org/dyn/closer.lua/poi/release/bin/poi-bin-${version.id}-${file_date}.zip">poi-bin-${version.id}-${file_date}.zip</a>
(${bin-zip-size} MB, <link href="https://www.apache.org/dist/poi/${reltype}/bin/poi-bin-${version.id}-${file_date}.zip.asc">signature (.asc)</link>) (${bin-zip-size} MB, <a href="https://www.apache.org/dist/poi/release/bin/poi-bin-${version.id}-${file_date}.zip.asc">signature (.asc)</a>)
<br/> <br/>
MD5 checksum: <link href="https://www.apache.org/dist/poi/${reltype}/bin/poi-bin-${version.id}-${file_date}.zip.md5"> SHA256 checksum: <a href="https://www.apache.org/dist/poi/release/bin/poi-bin-${version.id}-${file_date}.zip.sha256">
${bin-zip-md5}</link> ${bin-zip-sha256}</a>
<br/> <br/>
SHA1 checksum: <link href="https://www.apache.org/dist/poi/${reltype}/bin/poi-bin-${version.id}-${file_date}.zip.sha1"> SHA512 checksum: <a href="https://www.apache.org/dist/poi/release/bin/poi-bin-${version.id}-${file_date}.zip.sha512">
${bin-zip-sha1}</link> ${bin-zip-sha512}</a>
<br/>
SHA512 checksum: <link href="https://www.apache.org/dist/poi/${reltype}/bin/poi-bin-${version.id}-${file_date}.zip.sha512">
${bin-zip-sha512}</link>
</li> </li>
</ul> </ul>
</section> </section>
<section id="POI-${version.id}-src"><title>Source Distribution</title> <section id="POI-${version.id}-src"><title>Source Distribution</title>
<ul> <ul>
<li><link href="https://www.apache.org/dyn/closer.lua/poi/${reltype}/src/poi-src-${version.id}-${file_date}.tar.gz">poi-src-${version.id}-${file_date}.tar.gz</link> <li><a href="https://www.apache.org/dyn/closer.lua/poi/release/src/poi-src-${version.id}-${file_date}.tar.gz">poi-src-${version.id}-${file_date}.tar.gz</a>
(${src-tar-size} MB, <link href="https://www.apache.org/dist/poi/${reltype}/src/poi-src-${version.id}-${file_date}.tar.gz.asc">signature (.asc)</link>) (${src-tar-size} MB, <a href="https://www.apache.org/dist/poi/release/src/poi-src-${version.id}-${file_date}.tar.gz.asc">signature (.asc)</a>)
<br/> <br/>
MD5 checksum: <link href="https://www.apache.org/dist/poi/${reltype}/src/poi-src-${version.id}-${file_date}.tar.gz.md5"> SHA256 checksum: <a href="https://www.apache.org/dist/poi/release/src/poi-src-${version.id}-${file_date}.tar.gz.sha256">
${src-tar-md5}</link> ${src-tar-sha256}</a>
<br/> <br/>
SHA1 checksum: <link href="https://www.apache.org/dist/poi/${reltype}/src/poi-src-${version.id}-${file_date}.tar.gz.sha1"> SHA512 checksum: <a href="https://www.apache.org/dist/poi/release/src/poi-src-${version.id}-${file_date}.tar.gz.sha512">
${src-tar-sha1}</link> ${src-tar-sha512}</a>
<br/>
SHA512 checksum: <link href="https://www.apache.org/dist/poi/${reltype}/src/poi-src-${version.id}-${file_date}.tar.gz.sha512">
${src-tar-sha512}</link>
</li> </li>
<li><link href="https://www.apache.org/dyn/closer.lua/poi/${reltype}/src/poi-src-${version.id}-${file_date}.zip">poi-src-${version.id}-${file_date}.zip</link> <li><a href="https://www.apache.org/dyn/closer.lua/poi/release/src/poi-src-${version.id}-${file_date}.zip">poi-src-${version.id}-${file_date}.zip</a>
(${src-zip-size} MB, <link href="https://www.apache.org/dist/poi/${reltype}/src/poi-src-${version.id}-${file_date}.zip.asc">signature (.asc)</link>) (${src-zip-size} MB, <a href="https://www.apache.org/dist/poi/release/src/poi-src-${version.id}-${file_date}.zip.asc">signature (.asc)</a>)
<br/> <br/>
MD5 checksum: <link href="https://www.apache.org/dist/poi/${reltype}/src/poi-src-${version.id}-${file_date}.zip.md5"> SHA256 checksum: <a href="https://www.apache.org/dist/poi/release/src/poi-src-${version.id}-${file_date}.zip.sha256">
${src-zip-md5}</link> ${src-zip-sha256}</a>
<br/> <br/>
SHA1 checksum: <link href="https://www.apache.org/dist/poi/${reltype}/src/poi-src-${version.id}-${file_date}.zip.sha1"> SHA512 checksum: <a href="https://www.apache.org/dist/poi/release/src/poi-src-${version.id}-${file_date}.zip.sha512">
${src-zip-sha1}</link> ${src-zip-sha512}</a>
<br/>
SHA512 checksum: <link href="https://www.apache.org/dist/poi/${reltype}/src/poi-src-${version.id}-${file_date}.zip.sha512">
${src-zip-sha512}</link>
</li> </li>
</ul> </ul>
</section> </section>

View File

@ -35,6 +35,13 @@
<programming-language>Java</programming-language> <programming-language>Java</programming-language>
<category rdf:resource="https://projects.apache.org/category/content" /> <category rdf:resource="https://projects.apache.org/category/content" />
<category rdf:resource="https://projects.apache.org/category/library" /> <category rdf:resource="https://projects.apache.org/category/library" />
<release>
<Version>
<name>Apache POI 4.0.0</name>
<created>2018-09-07</created>
<revision>4.0.0</revision>
</Version>
</release>
<release> <release>
<Version> <Version>
<name>Apache POI 3.17</name> <name>Apache POI 3.17</name>

View File

@ -11,7 +11,7 @@ H H * * 0
''' '''
def xercesUrl = 'http://repo1.maven.org/maven2/xerces/xercesImpl/2.6.1/xercesImpl-2.6.1.jar' def xercesUrl = 'http://repo1.maven.org/maven2/xerces/xercesImpl/2.6.1/xercesImpl-2.6.1.jar'
def xercesLib = 'compile-lib/xercesImpl-2.6.1.jar' def xercesLib = './xercesImpl-2.6.1.jar'
def poijobs = [ def poijobs = [
[ name: 'POI-DSL-1.8', trigger: 'H */12 * * *' [ name: 'POI-DSL-1.8', trigger: 'H */12 * * *'
@ -88,7 +88,7 @@ def poijobs = [
disabled: true, skipcigame: true disabled: true, skipcigame: true
], ],
[ name: 'POI-DSL-old-Xerces', trigger: triggerSundays, [ name: 'POI-DSL-old-Xerces', trigger: triggerSundays,
shell: "mkdir -p compile-lib && test -f ${xercesLib} || wget -O ${xercesLib} ${xercesUrl}\n", shell: "test -f ${xercesLib} || wget -O ${xercesLib} ${xercesUrl}\n",
// the property triggers using Xerces as XML Parser and previously showed some exception that can occur // the property triggers using Xerces as XML Parser and previously showed some exception that can occur
properties: ["-Dadditionaljar=${xercesLib}"] properties: ["-Dadditionaljar=${xercesLib}"]
], ],

View File

@ -26,7 +26,7 @@ under the License.
<!-- TODO Import these from the parent build file --> <!-- TODO Import these from the parent build file -->
<property name="repository.m2" value="http://repo1.maven.org"/> <property name="repository.m2" value="http://repo1.maven.org"/>
<property name="version.id" value="4.0.0-SNAPSHOT"/> <property name="version.id" value="4.0.1-SNAPSHOT"/>
<property name="dist.dir" value="build/dist"/> <property name="dist.dir" value="build/dist"/>
<!-- jars in the /lib directory, see the fetch-bundle-jars target--> <!-- jars in the /lib directory, see the fetch-bundle-jars target-->

View File

@ -6,7 +6,7 @@
<parent> <parent>
<groupId>org.apache.poi</groupId> <groupId>org.apache.poi</groupId>
<artifactId>poi-parent</artifactId> <artifactId>poi-parent</artifactId>
<version>4.0.1-beta1-SNAPSHOT</version> <version>4.0.1-SNAPSHOT</version>
</parent> </parent>
<artifactId>poi-examples</artifactId> <artifactId>poi-examples</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>

View File

@ -6,7 +6,7 @@
<parent> <parent>
<groupId>org.apache.poi</groupId> <groupId>org.apache.poi</groupId>
<artifactId>poi-parent</artifactId> <artifactId>poi-parent</artifactId>
<version>4.0.1-beta1-SNAPSHOT</version> <version>4.0.1-SNAPSHOT</version>
</parent> </parent>
<artifactId>poi-excelant</artifactId> <artifactId>poi-excelant</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>

View File

@ -6,7 +6,7 @@
<parent> <parent>
<groupId>org.apache.poi</groupId> <groupId>org.apache.poi</groupId>
<artifactId>poi-parent</artifactId> <artifactId>poi-parent</artifactId>
<version>4.0.1-beta1-SNAPSHOT</version> <version>4.0.1-SNAPSHOT</version>
</parent> </parent>
<artifactId>poi-main</artifactId> <artifactId>poi-main</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>

View File

@ -6,7 +6,7 @@
<parent> <parent>
<groupId>org.apache.poi</groupId> <groupId>org.apache.poi</groupId>
<artifactId>poi-parent</artifactId> <artifactId>poi-parent</artifactId>
<version>4.0.1-beta1-SNAPSHOT</version> <version>4.0.1-SNAPSHOT</version>
<relativePath>..</relativePath> <relativePath>..</relativePath>
</parent> </parent>
<artifactId>poi-ooxml-schema-encryption</artifactId> <artifactId>poi-ooxml-schema-encryption</artifactId>

View File

@ -6,7 +6,7 @@
<parent> <parent>
<groupId>org.apache.poi</groupId> <groupId>org.apache.poi</groupId>
<artifactId>poi-parent</artifactId> <artifactId>poi-parent</artifactId>
<version>4.0.1-beta1-SNAPSHOT</version> <version>4.0.1-SNAPSHOT</version>
<relativePath>..</relativePath> <relativePath>..</relativePath>
</parent> </parent>
<artifactId>poi-ooxml-schema-security</artifactId> <artifactId>poi-ooxml-schema-security</artifactId>

View File

@ -6,7 +6,7 @@
<parent> <parent>
<groupId>org.apache.poi</groupId> <groupId>org.apache.poi</groupId>
<artifactId>poi-parent</artifactId> <artifactId>poi-parent</artifactId>
<version>4.0.1-beta1-SNAPSHOT</version> <version>4.0.1-SNAPSHOT</version>
<relativePath>..</relativePath> <relativePath>..</relativePath>
</parent> </parent>
<artifactId>poi-ooxml-schema</artifactId> <artifactId>poi-ooxml-schema</artifactId>

View File

@ -6,7 +6,7 @@
<parent> <parent>
<groupId>org.apache.poi</groupId> <groupId>org.apache.poi</groupId>
<artifactId>poi-parent</artifactId> <artifactId>poi-parent</artifactId>
<version>4.0.1-beta1-SNAPSHOT</version> <version>4.0.1-SNAPSHOT</version>
</parent> </parent>
<artifactId>poi-ooxml</artifactId> <artifactId>poi-ooxml</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>

View File

@ -4,7 +4,7 @@
<groupId>org.apache.poi</groupId> <groupId>org.apache.poi</groupId>
<artifactId>poi-parent</artifactId> <artifactId>poi-parent</artifactId>
<packaging>pom</packaging> <packaging>pom</packaging>
<version>4.0.1-beta1-SNAPSHOT</version> <version>4.0.1-SNAPSHOT</version>
<name>Apache POI - the Java API for Microsoft Documents</name> <name>Apache POI - the Java API for Microsoft Documents</name>
<description>Maven build of Apache POI for Sonar checks</description> <description>Maven build of Apache POI for Sonar checks</description>
<url>http://poi.apache.org/</url> <url>http://poi.apache.org/</url>

View File

@ -6,7 +6,7 @@
<parent> <parent>
<groupId>org.apache.poi</groupId> <groupId>org.apache.poi</groupId>
<artifactId>poi-parent</artifactId> <artifactId>poi-parent</artifactId>
<version>4.0.1-beta1-SNAPSHOT</version> <version>4.0.1-SNAPSHOT</version>
</parent> </parent>
<artifactId>poi-scratchpad</artifactId> <artifactId>poi-scratchpad</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>

View File

@ -23,8 +23,8 @@ repositories {
} }
dependencies { dependencies {
compile 'org.codehaus.groovy:groovy-all:2.4.13' compile 'org.codehaus.groovy:groovy-all:2.4.13'
compile 'org.apache.poi:poi:3.17' compile 'org.apache.poi:poi:4.0.0'
compile 'org.apache.poi:poi-ooxml:3.17' compile 'org.apache.poi:poi-ooxml:4.0.0'
} }
// Our files are in the current directory // Our files are in the current directory

View File

@ -17,7 +17,7 @@
// Add the POI core and OOXML support dependencies into your build.sbt // Add the POI core and OOXML support dependencies into your build.sbt
libraryDependencies ++= Seq( libraryDependencies ++= Seq(
"org.apache.poi" % "poi" % "3.17", "org.apache.poi" % "poi" % "4.0.0",
"org.apache.poi" % "poi-ooxml" % "3.17", "org.apache.poi" % "poi-ooxml" % "4.0.0",
"org.apache.poi" % "poi-ooxml-schemas" "3.17", "org.apache.poi" % "poi-ooxml-schemas" "4.0.0",
) )

View File

@ -20,6 +20,7 @@ package org.apache.poi.ooxml.util;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.concurrent.TimeUnit;
import javax.xml.XMLConstants; import javax.xml.XMLConstants;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
@ -38,6 +39,7 @@ import org.xml.sax.SAXParseException;
public final class DocumentHelper { public final class DocumentHelper {
private static POILogger logger = POILogFactory.getLogger(DocumentHelper.class); private static POILogger logger = POILogFactory.getLogger(DocumentHelper.class);
private static long lastLog;
private DocumentHelper() {} private DocumentHelper() {}
@ -102,19 +104,19 @@ public final class DocumentHelper {
//this doesn't appear to work, and we still need to limit //this doesn't appear to work, and we still need to limit
//entity expansions to 1 in trySetXercesSecurityManager //entity expansions to 1 in trySetXercesSecurityManager
documentBuilderFactory.setExpandEntityReferences(false); documentBuilderFactory.setExpandEntityReferences(false);
trySetSAXFeature(documentBuilderFactory, XMLConstants.FEATURE_SECURE_PROCESSING, true); trySetFeature(documentBuilderFactory, XMLConstants.FEATURE_SECURE_PROCESSING, true);
trySetSAXFeature(documentBuilderFactory, POIXMLConstants.FEATURE_LOAD_DTD_GRAMMAR, false); trySetFeature(documentBuilderFactory, POIXMLConstants.FEATURE_LOAD_DTD_GRAMMAR, false);
trySetSAXFeature(documentBuilderFactory, POIXMLConstants.FEATURE_LOAD_EXTERNAL_DTD, false); trySetFeature(documentBuilderFactory, POIXMLConstants.FEATURE_LOAD_EXTERNAL_DTD, false);
trySetXercesSecurityManager(documentBuilderFactory); trySetXercesSecurityManager(documentBuilderFactory);
} }
private static void trySetSAXFeature(DocumentBuilderFactory dbf, String feature, boolean enabled) { private static void trySetFeature(DocumentBuilderFactory dbf, String feature, boolean enabled) {
try { try {
dbf.setFeature(feature, enabled); dbf.setFeature(feature, enabled);
} catch (Exception e) { } catch (Exception e) {
logger.log(POILogger.WARN, "SAX Feature unsupported", feature, e); logger.log(POILogger.WARN, "DocumentBuilderFactory Feature unsupported", feature, e);
} catch (AbstractMethodError ame) { } catch (AbstractMethodError ame) {
logger.log(POILogger.WARN, "Cannot set SAX feature because outdated XML parser in classpath", feature, ame); logger.log(POILogger.WARN, "Cannot set DocumentBuilderFactory feature because outdated XML parser in classpath", feature, ame);
} }
} }
@ -134,13 +136,23 @@ public final class DocumentHelper {
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
// continue without log, this is expected in some setups // continue without log, this is expected in some setups
} catch (Throwable e) { // NOSONAR - also catch things like NoClassDefError here } catch (Throwable e) { // NOSONAR - also catch things like NoClassDefError here
logger.log(POILogger.WARN, "SAX Security Manager could not be setup", e); if(System.currentTimeMillis() > lastLog + TimeUnit.MINUTES.toMillis(5)) {
logger.log(POILogger.WARN, "DocumentBuilderFactory Security Manager could not be setup [log suppressed for 5 minutes]", e);
lastLog = System.currentTimeMillis();
}
} }
} }
// separate old version of Xerces not found => use the builtin way of setting the property // separate old version of Xerces not found => use the builtin way of setting the property
// Note: when entity_expansion_limit==0, there is no limit! // Note: when entity_expansion_limit==0, there is no limit!
dbf.setAttribute(POIXMLConstants.PROPERTY_ENTITY_EXPANSION_LIMIT, 1); try {
dbf.setAttribute(POIXMLConstants.PROPERTY_ENTITY_EXPANSION_LIMIT, 1);
} catch (Throwable e) {
if(System.currentTimeMillis() > lastLog + TimeUnit.MINUTES.toMillis(5)) {
logger.log(POILogger.WARN, "DocumentBuilderFactory Entity Expansion Limit could not be setup [log suppressed for 5 minutes]", e);
lastLog = System.currentTimeMillis();
}
}
} }
/** /**

View File

@ -101,40 +101,44 @@ public final class XSSFDrawing extends POIXMLDocumentPart implements Drawing<XSS
/** /**
* Construct a SpreadsheetML drawing from a package part * Construct a SpreadsheetML drawing from a package part
* *
* @param part the package part holding the drawing data, * @param part
* the content type must be <code>application/vnd.openxmlformats-officedocument.drawing+xml</code> * the package part holding the drawing data, the content type
* must be
* <code>application/vnd.openxmlformats-officedocument.drawing+xml</code>
* *
* @since POI 3.14-Beta1 * @since POI 3.14-Beta1
*/ */
public XSSFDrawing(PackagePart part) throws IOException, XmlException { public XSSFDrawing(PackagePart part) throws IOException, XmlException {
super(part); super(part);
XmlOptions options = new XmlOptions(DEFAULT_XML_OPTIONS); XmlOptions options = new XmlOptions(DEFAULT_XML_OPTIONS);
//Removing root element // Removing root element
options.setLoadReplaceDocumentElement(null); options.setLoadReplaceDocumentElement(null);
InputStream is = part.getInputStream(); InputStream is = part.getInputStream();
try { try {
drawing = CTDrawing.Factory.parse(is,options); drawing = CTDrawing.Factory.parse(is, options);
} finally { } finally {
is.close(); is.close();
} }
} }
/** /**
* Construct a new CTDrawing bean. By default, it's just an empty placeholder for drawing objects * Construct a new CTDrawing bean. By default, it's just an empty
* placeholder for drawing objects
* *
* @return a new CTDrawing bean * @return a new CTDrawing bean
*/ */
private static CTDrawing newDrawing(){ private static CTDrawing newDrawing() {
return CTDrawing.Factory.newInstance(); return CTDrawing.Factory.newInstance();
} }
/** /**
* Return the underlying CTDrawing bean, the root element of the SpreadsheetML Drawing part. * Return the underlying CTDrawing bean, the root element of the
* SpreadsheetML Drawing part.
* *
* @return the underlying CTDrawing bean * @return the underlying CTDrawing bean
*/ */
@Internal @Internal
public CTDrawing getCTDrawing(){ public CTDrawing getCTDrawing() {
return drawing; return drawing;
} }
@ -143,14 +147,13 @@ public final class XSSFDrawing extends POIXMLDocumentPart implements Drawing<XSS
XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS); XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
/* /*
Saved drawings must have the following namespaces set: * Saved drawings must have the following namespaces set: <xdr:wsDr
<xdr:wsDr * xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"
xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" * xmlns:xdr=
xmlns:xdr="http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing"> * "http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing">
*/ */
xmlOptions.setSaveSyntheticDocumentElement( xmlOptions
new QName(CTDrawing.type.getName().getNamespaceURI(), "wsDr", "xdr") .setSaveSyntheticDocumentElement(new QName(CTDrawing.type.getName().getNamespaceURI(), "wsDr", "xdr"));
);
PackagePart part = getPackagePart(); PackagePart part = getPackagePart();
OutputStream out = part.getOutputStream(); OutputStream out = part.getOutputStream();
@ -158,20 +161,20 @@ public final class XSSFDrawing extends POIXMLDocumentPart implements Drawing<XSS
out.close(); out.close();
} }
@Override @Override
public XSSFClientAnchor createAnchor(int dx1, int dy1, int dx2, int dy2, public XSSFClientAnchor createAnchor(int dx1, int dy1, int dx2, int dy2, int col1, int row1, int col2, int row2) {
int col1, int row1, int col2, int row2) { return new XSSFClientAnchor(dx1, dy1, dx2, dy2, col1, row1, col2, row2);
return new XSSFClientAnchor(dx1, dy1, dx2, dy2, col1, row1, col2, row2); }
}
/** /**
* Constructs a textbox under the drawing. * Constructs a textbox under the drawing.
* *
* @param anchor the client anchor describes how this group is attached * @param anchor
* to the sheet. * the client anchor describes how this group is attached to the
* @return the newly created textbox. * sheet.
* @return the newly created textbox.
*/ */
public XSSFTextBox createTextbox(XSSFClientAnchor anchor){ public XSSFTextBox createTextbox(XSSFClientAnchor anchor) {
long shapeId = newShapeId(); long shapeId = newShapeId();
CTTwoCellAnchor ctAnchor = createTwoCellAnchor(anchor); CTTwoCellAnchor ctAnchor = createTwoCellAnchor(anchor);
CTShape ctShape = ctAnchor.addNewSp(); CTShape ctShape = ctAnchor.addNewSp();
@ -186,14 +189,18 @@ public final class XSSFDrawing extends POIXMLDocumentPart implements Drawing<XSS
/** /**
* Creates a picture. * Creates a picture.
* *
* @param anchor the client anchor describes how this picture is attached to the sheet. * @param anchor
* @param pictureIndex the index of the picture in the workbook collection of pictures, * the client anchor describes how this picture is attached to
* {@link org.apache.poi.xssf.usermodel.XSSFWorkbook#getAllPictures()} . * the sheet.
* @param pictureIndex
* the index of the picture in the workbook collection of
* pictures,
* {@link org.apache.poi.xssf.usermodel.XSSFWorkbook#getAllPictures()}
* .
* *
* @return the newly created picture shape. * @return the newly created picture shape.
*/ */
public XSSFPicture createPicture(XSSFClientAnchor anchor, int pictureIndex) public XSSFPicture createPicture(XSSFClientAnchor anchor, int pictureIndex) {
{
PackageRelationship rel = addPictureReference(pictureIndex); PackageRelationship rel = addPictureReference(pictureIndex);
long shapeId = newShapeId(); long shapeId = newShapeId();
@ -212,23 +219,24 @@ public final class XSSFDrawing extends POIXMLDocumentPart implements Drawing<XSS
} }
@Override @Override
public XSSFPicture createPicture(ClientAnchor anchor, int pictureIndex){ public XSSFPicture createPicture(ClientAnchor anchor, int pictureIndex) {
return createPicture((XSSFClientAnchor)anchor, pictureIndex); return createPicture((XSSFClientAnchor) anchor, pictureIndex);
} }
/** /**
* Creates a chart. * Creates a chart.
* @param anchor the client anchor describes how this chart is attached to *
* the sheet. * @param anchor
* @return the newly created chart * the client anchor describes how this chart is attached to the
* @see org.apache.poi.xssf.usermodel.XSSFDrawing#createChart(ClientAnchor) * sheet.
*/ * @return the newly created chart
* @see org.apache.poi.xssf.usermodel.XSSFDrawing#createChart(ClientAnchor)
*/
public XSSFChart createChart(XSSFClientAnchor anchor) { public XSSFChart createChart(XSSFClientAnchor anchor) {
int chartNumber = getPackagePart().getPackage(). int chartNumber = getPackagePart().getPackage().getPartsByContentType(XSSFRelation.CHART.getContentType())
getPartsByContentType(XSSFRelation.CHART.getContentType()).size() + 1; .size() + 1;
RelationPart rp = createRelationship( RelationPart rp = createRelationship(XSSFRelation.CHART, XSSFFactory.getInstance(), chartNumber, false);
XSSFRelation.CHART, XSSFFactory.getInstance(), chartNumber, false);
XSSFChart chart = rp.getDocumentPart(); XSSFChart chart = rp.getDocumentPart();
String chartRelId = rp.getRelationship().getId(); String chartRelId = rp.getRelationship().getId();
@ -239,25 +247,52 @@ public final class XSSFDrawing extends POIXMLDocumentPart implements Drawing<XSS
return chart; return chart;
} }
/** /**
* Creates a chart. * Creates a chart.
* @param anchor the client anchor describes how this chart is attached to *
* the sheet. * @param anchor
* @return the newly created chart * the client anchor describes how this chart is attached to the
*/ * sheet.
* @return the newly created chart
*/
public XSSFChart createChart(ClientAnchor anchor) { public XSSFChart createChart(ClientAnchor anchor) {
return createChart((XSSFClientAnchor)anchor); return createChart((XSSFClientAnchor) anchor);
} }
/**
* Imports the chart from the <code>srcChart</code> into this drawing.
*
* @param srcChart
* the source chart to be cloned into this drawing.
* @return the newly created chart.
* @throws XmlException
* @throws IOException
* @since 4.0.0
*/
public XSSFChart importChart(XSSFChart srcChart) throws IOException, XmlException {
CTTwoCellAnchor anchor = ((XSSFDrawing) srcChart.getParent()).getCTDrawing().getTwoCellAnchorArray(0);
CTMarker from = (CTMarker) anchor.getFrom().copy();
CTMarker to = (CTMarker) anchor.getTo().copy();
XSSFClientAnchor destAnchor = new XSSFClientAnchor(from, to);
destAnchor.setAnchorType(ClientAnchor.AnchorType.MOVE_AND_RESIZE);
XSSFChart destChart = createChart(destAnchor);
destChart.getCTChartSpace().set(srcChart.getCTChartSpace().copy());
destChart.getCTChart().set(srcChart.getCTChart().copy());
return destChart;
}
/** /**
* Add the indexed picture to this drawing relations * Add the indexed picture to this drawing relations
* *
* @param pictureIndex the index of the picture in the workbook collection of pictures, * @param pictureIndex
* {@link org.apache.poi.xssf.usermodel.XSSFWorkbook#getAllPictures()} . * the index of the picture in the workbook collection of
* pictures,
* {@link org.apache.poi.xssf.usermodel.XSSFWorkbook#getAllPictures()}
* .
*/ */
@SuppressWarnings("resource") @SuppressWarnings("resource")
protected PackageRelationship addPictureReference(int pictureIndex){ protected PackageRelationship addPictureReference(int pictureIndex) {
XSSFWorkbook wb = (XSSFWorkbook)getParent().getParent(); XSSFWorkbook wb = (XSSFWorkbook) getParent().getParent();
XSSFPictureData data = wb.getAllPictures().get(pictureIndex); XSSFPictureData data = wb.getAllPictures().get(pictureIndex);
XSSFPictureData pic = new XSSFPictureData(data.getPackagePart()); XSSFPictureData pic = new XSSFPictureData(data.getPackagePart());
RelationPart rp = addRelation(null, XSSFRelation.IMAGES, pic); RelationPart rp = addRelation(null, XSSFRelation.IMAGES, pic);
@ -265,15 +300,15 @@ public final class XSSFDrawing extends POIXMLDocumentPart implements Drawing<XSS
} }
/** /**
* Creates a simple shape. This includes such shapes as lines, rectangles, * Creates a simple shape. This includes such shapes as lines, rectangles,
* and ovals. * and ovals.
* *
* @param anchor the client anchor describes how this group is attached * @param anchor
* to the sheet. * the client anchor describes how this group is attached to the
* @return the newly created shape. * sheet.
* @return the newly created shape.
*/ */
public XSSFSimpleShape createSimpleShape(XSSFClientAnchor anchor) public XSSFSimpleShape createSimpleShape(XSSFClientAnchor anchor) {
{
long shapeId = newShapeId(); long shapeId = newShapeId();
CTTwoCellAnchor ctAnchor = createTwoCellAnchor(anchor); CTTwoCellAnchor ctAnchor = createTwoCellAnchor(anchor);
CTShape ctShape = ctAnchor.addNewSp(); CTShape ctShape = ctAnchor.addNewSp();
@ -286,15 +321,15 @@ public final class XSSFDrawing extends POIXMLDocumentPart implements Drawing<XSS
} }
/** /**
* Creates a simple shape. This includes such shapes as lines, rectangles, * Creates a simple shape. This includes such shapes as lines, rectangles,
* and ovals. * and ovals.
* *
* @param anchor the client anchor describes how this group is attached * @param anchor
* to the sheet. * the client anchor describes how this group is attached to the
* @return the newly created shape. * sheet.
* @return the newly created shape.
*/ */
public XSSFConnector createConnector(XSSFClientAnchor anchor) public XSSFConnector createConnector(XSSFClientAnchor anchor) {
{
CTTwoCellAnchor ctAnchor = createTwoCellAnchor(anchor); CTTwoCellAnchor ctAnchor = createTwoCellAnchor(anchor);
CTConnector ctShape = ctAnchor.addNewCxnSp(); CTConnector ctShape = ctAnchor.addNewCxnSp();
ctShape.set(XSSFConnector.prototype()); ctShape.set(XSSFConnector.prototype());
@ -305,20 +340,20 @@ public final class XSSFDrawing extends POIXMLDocumentPart implements Drawing<XSS
} }
/** /**
* Creates a simple shape. This includes such shapes as lines, rectangles, * Creates a simple shape. This includes such shapes as lines, rectangles,
* and ovals. * and ovals.
* *
* @param anchor the client anchor describes how this group is attached * @param anchor
* to the sheet. * the client anchor describes how this group is attached to the
* @return the newly created shape. * sheet.
* @return the newly created shape.
*/ */
public XSSFShapeGroup createGroup(XSSFClientAnchor anchor) public XSSFShapeGroup createGroup(XSSFClientAnchor anchor) {
{
CTTwoCellAnchor ctAnchor = createTwoCellAnchor(anchor); CTTwoCellAnchor ctAnchor = createTwoCellAnchor(anchor);
CTGroupShape ctGroup = ctAnchor.addNewGrpSp(); CTGroupShape ctGroup = ctAnchor.addNewGrpSp();
ctGroup.set(XSSFShapeGroup.prototype()); ctGroup.set(XSSFShapeGroup.prototype());
CTTransform2D xfrm = createXfrm(anchor); CTTransform2D xfrm = createXfrm(anchor);
CTGroupTransform2D grpXfrm =ctGroup.getGrpSpPr().getXfrm(); CTGroupTransform2D grpXfrm = ctGroup.getGrpSpPr().getXfrm();
grpXfrm.setOff(xfrm.getOff()); grpXfrm.setOff(xfrm.getOff());
grpXfrm.setExt(xfrm.getExt()); grpXfrm.setExt(xfrm.getExt());
grpXfrm.setChExt(xfrm.getExt()); grpXfrm.setChExt(xfrm.getExt());
@ -328,38 +363,38 @@ public final class XSSFDrawing extends POIXMLDocumentPart implements Drawing<XSS
return shape; return shape;
} }
/** /**
* Creates a comment. * Creates a comment.
* @param anchor the client anchor describes how this comment is attached *
* to the sheet. * @param anchor
* @return the newly created comment. * the client anchor describes how this comment is attached to
*/ * the sheet.
* @return the newly created comment.
*/
@Override @Override
public XSSFComment createCellComment(ClientAnchor anchor) { public XSSFComment createCellComment(ClientAnchor anchor) {
XSSFClientAnchor ca = (XSSFClientAnchor)anchor; XSSFClientAnchor ca = (XSSFClientAnchor) anchor;
XSSFSheet sheet = getSheet(); XSSFSheet sheet = getSheet();
//create comments and vmlDrawing parts if they don't exist // create comments and vmlDrawing parts if they don't exist
CommentsTable comments = sheet.getCommentsTable(true); CommentsTable comments = sheet.getCommentsTable(true);
XSSFVMLDrawing vml = sheet.getVMLDrawing(true); XSSFVMLDrawing vml = sheet.getVMLDrawing(true);
com.microsoft.schemas.vml.CTShape vmlShape = vml.newCommentShape(); com.microsoft.schemas.vml.CTShape vmlShape = vml.newCommentShape();
if(ca.isSet()){ if (ca.isSet()) {
// convert offsets from emus to pixels since we get a DrawingML-anchor // convert offsets from emus to pixels since we get a
// DrawingML-anchor
// but create a VML Drawing // but create a VML Drawing
int dx1Pixels = ca.getDx1()/Units.EMU_PER_PIXEL; int dx1Pixels = ca.getDx1() / Units.EMU_PER_PIXEL;
int dy1Pixels = ca.getDy1()/Units.EMU_PER_PIXEL; int dy1Pixels = ca.getDy1() / Units.EMU_PER_PIXEL;
int dx2Pixels = ca.getDx2()/Units.EMU_PER_PIXEL; int dx2Pixels = ca.getDx2() / Units.EMU_PER_PIXEL;
int dy2Pixels = ca.getDy2()/Units.EMU_PER_PIXEL; int dy2Pixels = ca.getDy2() / Units.EMU_PER_PIXEL;
String position = String position = ca.getCol1() + ", " + dx1Pixels + ", " + ca.getRow1() + ", " + dy1Pixels + ", " + ca
ca.getCol1() + ", " + dx1Pixels + ", " + .getCol2() + ", " + dx2Pixels + ", " + ca.getRow2() + ", " + dy2Pixels;
ca.getRow1() + ", " + dy1Pixels + ", " +
ca.getCol2() + ", " + dx2Pixels + ", " +
ca.getRow2() + ", " + dy2Pixels;
vmlShape.getClientDataArray(0).setAnchorArray(0, position); vmlShape.getClientDataArray(0).setAnchorArray(0, position);
} }
CellAddress ref = new CellAddress(ca.getRow1(), ca.getCol1()); CellAddress ref = new CellAddress(ca.getRow1(), ca.getCol1());
if(comments.findCellComment(ref) != null) { if (comments.findCellComment(ref) != null) {
throw new IllegalArgumentException("Multiple cell comments in one cell are not allowed, cell: " + ref); throw new IllegalArgumentException("Multiple cell comments in one cell are not allowed, cell: " + ref);
} }
@ -369,9 +404,10 @@ public final class XSSFDrawing extends POIXMLDocumentPart implements Drawing<XSS
/** /**
* Creates a new graphic frame. * Creates a new graphic frame.
* *
* @param anchor the client anchor describes how this frame is attached * @param anchor
* to the sheet * the client anchor describes how this frame is attached to the
* @return the newly created graphic frame * sheet
* @return the newly created graphic frame
*/ */
private XSSFGraphicFrame createGraphicFrame(XSSFClientAnchor anchor) { private XSSFGraphicFrame createGraphicFrame(XSSFClientAnchor anchor) {
CTTwoCellAnchor ctAnchor = createTwoCellAnchor(anchor); CTTwoCellAnchor ctAnchor = createTwoCellAnchor(anchor);
@ -395,36 +431,40 @@ public final class XSSFDrawing extends POIXMLDocumentPart implements Drawing<XSS
/* /*
* The shape id of the ole object seems to be a legacy shape id. * The shape id of the ole object seems to be a legacy shape id.
* *
* see 5.3.2.1 legacyDrawing (Legacy Drawing Object): * see 5.3.2.1 legacyDrawing (Legacy Drawing Object): Legacy Shape ID
* Legacy Shape ID that is unique throughout the entire document. * that is unique throughout the entire document. Legacy shape IDs
* Legacy shape IDs should be assigned based on which portion of the document the * should be assigned based on which portion of the document the drawing
* drawing resides on. The assignment of these ids is broken down into clusters of * resides on. The assignment of these ids is broken down into clusters
* 1024 values. The first cluster is 1-1024, the second 1025-2048 and so on. * of 1024 values. The first cluster is 1-1024, the second 1025-2048 and
* so on.
* *
* Ole shapes seem to start with 1025 on the first sheet ... * Ole shapes seem to start with 1025 on the first sheet ... and not
* and not sure, if the ids need to be reindexed when sheets are removed * sure, if the ids need to be reindexed when sheets are removed or more
* or more than 1024 shapes are on a given sheet (see #51332 for a similar issue) * than 1024 shapes are on a given sheet (see #51332 for a similar
* issue)
*/ */
XSSFSheet sheet = getSheet(); XSSFSheet sheet = getSheet();
XSSFWorkbook wb = sheet.getWorkbook(); XSSFWorkbook wb = sheet.getWorkbook();
int sheetIndex = wb.getSheetIndex(sheet); int sheetIndex = wb.getSheetIndex(sheet);
long shapeId = (sheetIndex+1)*1024 + newShapeId(); long shapeId = (sheetIndex + 1) * 1024 + newShapeId();
// add reference to OLE part // add reference to OLE part
PackagePartName olePN; PackagePartName olePN;
try { try {
olePN = PackagingURIHelper.createPartName( "/xl/embeddings/oleObject"+storageId+".bin" ); olePN = PackagingURIHelper.createPartName("/xl/embeddings/oleObject" + storageId + ".bin");
} catch (InvalidFormatException e) { } catch (InvalidFormatException e) {
throw new POIXMLException(e); throw new POIXMLException(e);
} }
PackageRelationship olePR = sheetPart.addRelationship( olePN, TargetMode.INTERNAL, POIXMLDocument.OLE_OBJECT_REL_TYPE ); PackageRelationship olePR = sheetPart.addRelationship(olePN, TargetMode.INTERNAL,
POIXMLDocument.OLE_OBJECT_REL_TYPE);
// add reference to image part // add reference to image part
XSSFPictureData imgPD = sh.getWorkbook().getAllPictures().get(pictureIndex); XSSFPictureData imgPD = sh.getWorkbook().getAllPictures().get(pictureIndex);
PackagePartName imgPN = imgPD.getPackagePart().getPartName(); PackagePartName imgPN = imgPD.getPackagePart().getPartName();
PackageRelationship imgSheetPR = sheetPart.addRelationship( imgPN, TargetMode.INTERNAL, PackageRelationshipTypes.IMAGE_PART ); PackageRelationship imgSheetPR = sheetPart.addRelationship(imgPN, TargetMode.INTERNAL,
PackageRelationship imgDrawPR = getPackagePart().addRelationship( imgPN, TargetMode.INTERNAL, PackageRelationshipTypes.IMAGE_PART ); PackageRelationshipTypes.IMAGE_PART);
PackageRelationship imgDrawPR = getPackagePart().addRelationship(imgPN, TargetMode.INTERNAL,
PackageRelationshipTypes.IMAGE_PART);
// add OLE part metadata to sheet // add OLE part metadata to sheet
CTWorksheet cwb = sh.getCTWorksheet(); CTWorksheet cwb = sh.getCTWorksheet();
@ -443,7 +483,7 @@ public final class XSSFDrawing extends POIXMLDocumentPart implements Drawing<XSS
cur1.beginElement("anchor", XSSFRelation.NS_SPREADSHEETML); cur1.beginElement("anchor", XSSFRelation.NS_SPREADSHEETML);
cur1.insertAttributeWithValue("moveWithCells", "1"); cur1.insertAttributeWithValue("moveWithCells", "1");
CTTwoCellAnchor ctAnchor = createTwoCellAnchor((XSSFClientAnchor)anchor); CTTwoCellAnchor ctAnchor = createTwoCellAnchor((XSSFClientAnchor) anchor);
XmlCursor cur2 = ctAnchor.newCursor(); XmlCursor cur2 = ctAnchor.newCursor();
cur2.copyXmlContents(cur1); cur2.copyXmlContents(cur1);
@ -460,7 +500,7 @@ public final class XSSFDrawing extends POIXMLDocumentPart implements Drawing<XSS
// add a new shape and link OLE & image part // add a new shape and link OLE & image part
CTShape ctShape = ctAnchor.addNewSp(); CTShape ctShape = ctAnchor.addNewSp();
ctShape.set(XSSFObjectData.prototype()); ctShape.set(XSSFObjectData.prototype());
ctShape.getSpPr().setXfrm(createXfrm((XSSFClientAnchor)anchor)); ctShape.getSpPr().setXfrm(createXfrm((XSSFClientAnchor) anchor));
// workaround for not having the vmlDrawing filled // workaround for not having the vmlDrawing filled
CTBlipFillProperties blipFill = ctShape.getSpPr().addNewBlipFill(); CTBlipFillProperties blipFill = ctShape.getSpPr().addNewBlipFill();
@ -469,35 +509,35 @@ public final class XSSFDrawing extends POIXMLDocumentPart implements Drawing<XSS
CTNonVisualDrawingProps cNvPr = ctShape.getNvSpPr().getCNvPr(); CTNonVisualDrawingProps cNvPr = ctShape.getNvSpPr().getCNvPr();
cNvPr.setId(shapeId); cNvPr.setId(shapeId);
cNvPr.setName("Object "+shapeId); cNvPr.setName("Object " + shapeId);
XmlCursor extCur = cNvPr.getExtLst().getExtArray(0).newCursor(); XmlCursor extCur = cNvPr.getExtLst().getExtArray(0).newCursor();
extCur.toFirstChild(); extCur.toFirstChild();
extCur.setAttributeText(new QName("spid"), "_x0000_s"+shapeId); extCur.setAttributeText(new QName("spid"), "_x0000_s" + shapeId);
extCur.dispose(); extCur.dispose();
XSSFObjectData shape = new XSSFObjectData(this, ctShape); XSSFObjectData shape = new XSSFObjectData(this, ctShape);
shape.anchor = (XSSFClientAnchor)anchor; shape.anchor = (XSSFClientAnchor) anchor;
return shape; return shape;
} }
/** /**
* Returns all charts in this drawing. * Returns all charts in this drawing.
*/ */
public List<XSSFChart> getCharts() { public List<XSSFChart> getCharts() {
List<XSSFChart> charts = new ArrayList<>(); List<XSSFChart> charts = new ArrayList<>();
for(POIXMLDocumentPart part : getRelations()) { for (POIXMLDocumentPart part : getRelations()) {
if(part instanceof XSSFChart) { if (part instanceof XSSFChart) {
charts.add((XSSFChart)part); charts.add((XSSFChart) part);
} }
} }
return charts; return charts;
} }
/** /**
* Create and initialize a CTTwoCellAnchor that anchors a shape against top-left and bottom-right cells. * Create and initialize a CTTwoCellAnchor that anchors a shape against
* top-left and bottom-right cells.
* *
* @return a new CTTwoCellAnchor * @return a new CTTwoCellAnchor
*/ */
@ -508,14 +548,21 @@ public final class XSSFDrawing extends POIXMLDocumentPart implements Drawing<XSS
ctAnchor.addNewClientData(); ctAnchor.addNewClientData();
anchor.setTo(ctAnchor.getTo()); anchor.setTo(ctAnchor.getTo());
anchor.setFrom(ctAnchor.getFrom()); anchor.setFrom(ctAnchor.getFrom());
STEditAs.Enum aditAs; STEditAs.Enum editAs;
switch(anchor.getAnchorType()) { switch (anchor.getAnchorType()) {
case DONT_MOVE_AND_RESIZE: aditAs = STEditAs.ABSOLUTE; break; case DONT_MOVE_AND_RESIZE:
case MOVE_AND_RESIZE: aditAs = STEditAs.TWO_CELL; break; editAs = STEditAs.ABSOLUTE;
case MOVE_DONT_RESIZE: aditAs = STEditAs.ONE_CELL; break; break;
default: aditAs = STEditAs.ONE_CELL; case MOVE_AND_RESIZE:
editAs = STEditAs.TWO_CELL;
break;
case MOVE_DONT_RESIZE:
editAs = STEditAs.ONE_CELL;
break;
default:
editAs = STEditAs.ONE_CELL;
} }
ctAnchor.setEditAs(aditAs); ctAnchor.setEditAs(editAs);
return ctAnchor; return ctAnchor;
} }
@ -526,15 +573,15 @@ public final class XSSFDrawing extends POIXMLDocumentPart implements Drawing<XSS
off.setY(anchor.getDy1()); off.setY(anchor.getDy1());
XSSFSheet sheet = getSheet(); XSSFSheet sheet = getSheet();
double widthPx = 0; double widthPx = 0;
for (int col=anchor.getCol1(); col<anchor.getCol2(); col++) { for (int col = anchor.getCol1(); col < anchor.getCol2(); col++) {
widthPx += sheet.getColumnWidthInPixels(col); widthPx += sheet.getColumnWidthInPixels(col);
} }
double heightPx = 0; double heightPx = 0;
for (int row=anchor.getRow1(); row<anchor.getRow2(); row++) { for (int row = anchor.getRow1(); row < anchor.getRow2(); row++) {
heightPx += ImageUtils.getRowHeightInPixels(sheet, row); heightPx += ImageUtils.getRowHeightInPixels(sheet, row);
} }
long width = Units.pixelToEMU((int)widthPx); long width = Units.pixelToEMU((int) widthPx);
long height = Units.pixelToEMU((int)heightPx); long height = Units.pixelToEMU((int) heightPx);
CTPositiveSize2D ext = xfrm.addNewExt(); CTPositiveSize2D ext = xfrm.addNewExt();
ext.setCx(width - anchor.getDx1() + anchor.getDx2()); ext.setCx(width - anchor.getDx1() + anchor.getDx2());
ext.setCy(height - anchor.getDy1() + anchor.getDy2()); ext.setCy(height - anchor.getDy1() + anchor.getDy2());
@ -543,17 +590,15 @@ public final class XSSFDrawing extends POIXMLDocumentPart implements Drawing<XSS
return xfrm; return xfrm;
} }
private long newShapeId(){ private long newShapeId() {
return 1+ return 1 + drawing.sizeOfAbsoluteAnchorArray() + drawing.sizeOfOneCellAnchorArray() + drawing
drawing.sizeOfAbsoluteAnchorArray()+ .sizeOfTwoCellAnchorArray();
drawing.sizeOfOneCellAnchorArray()+
drawing.sizeOfTwoCellAnchorArray();
} }
/** /**
* @return list of shapes in this drawing * @return list of shapes in this drawing
*/ */
public List<XSSFShape> getShapes(){ public List<XSSFShape> getShapes() {
List<XSSFShape> lst = new ArrayList<>(); List<XSSFShape> lst = new ArrayList<>();
XmlCursor cur = drawing.newCursor(); XmlCursor cur = drawing.newCursor();
try { try {
@ -569,7 +614,7 @@ public final class XSSFDrawing extends POIXMLDocumentPart implements Drawing<XSS
/** /**
* @return list of shapes in this shape group * @return list of shapes in this shape group
*/ */
public List<XSSFShape> getShapes(XSSFShapeGroup groupshape){ public List<XSSFShape> getShapes(XSSFShapeGroup groupshape) {
List<XSSFShape> lst = new ArrayList<>(); List<XSSFShape> lst = new ArrayList<>();
XmlCursor cur = groupshape.getCTGroupShape().newCursor(); XmlCursor cur = groupshape.getCTGroupShape().newCursor();
try { try {
@ -593,29 +638,28 @@ public final class XSSFDrawing extends POIXMLDocumentPart implements Drawing<XSS
// ignore anchor elements // ignore anchor elements
continue; continue;
} else if (obj instanceof CTPicture) { } else if (obj instanceof CTPicture) {
shape = new XSSFPicture(this, (CTPicture)obj) ; shape = new XSSFPicture(this, (CTPicture) obj);
} else if(obj instanceof CTConnector) { } else if (obj instanceof CTConnector) {
shape = new XSSFConnector(this, (CTConnector)obj) ; shape = new XSSFConnector(this, (CTConnector) obj);
} else if(obj instanceof CTShape) { } else if (obj instanceof CTShape) {
shape = hasOleLink(obj) shape = hasOleLink(obj) ? new XSSFObjectData(this, (CTShape) obj)
? new XSSFObjectData(this, (CTShape)obj) : new XSSFSimpleShape(this, (CTShape) obj);
: new XSSFSimpleShape(this, (CTShape)obj) ; } else if (obj instanceof CTGraphicalObjectFrame) {
} else if(obj instanceof CTGraphicalObjectFrame) { shape = new XSSFGraphicFrame(this, (CTGraphicalObjectFrame) obj);
shape = new XSSFGraphicFrame(this, (CTGraphicalObjectFrame)obj) ; } else if (obj instanceof CTGroupShape) {
} else if(obj instanceof CTGroupShape) { shape = new XSSFShapeGroup(this, (CTGroupShape) obj);
shape = new XSSFShapeGroup(this, (CTGroupShape)obj) ; } else if (obj instanceof XmlAnyTypeImpl) {
} else if(obj instanceof XmlAnyTypeImpl) { LOG.log(POILogger.WARN,
LOG.log(POILogger.WARN, "trying to parse AlternateContent, " "trying to parse AlternateContent, " + "this unlinks the returned Shapes from the underlying xml content, " + "so those shapes can't be used to modify the drawing, " + "i.e. modifications will be ignored!");
+ "this unlinks the returned Shapes from the underlying xml content, "
+ "so those shapes can't be used to modify the drawing, "
+ "i.e. modifications will be ignored!");
// XmlAnyTypeImpl is returned for AlternateContent parts, which might contain a CTDrawing // XmlAnyTypeImpl is returned for AlternateContent
// parts, which might contain a CTDrawing
cur.push(); cur.push();
cur.toFirstChild(); cur.toFirstChild();
XmlCursor cur2 = null; XmlCursor cur2 = null;
try { try {
// need to parse AlternateContent again, otherwise the child elements aren't typed, // need to parse AlternateContent again,
// otherwise the child elements aren't typed,
// but also XmlAnyTypes // but also XmlAnyTypes
CTDrawing alterWS = CTDrawing.Factory.parse(cur.newXMLStreamReader()); CTDrawing alterWS = CTDrawing.Factory.parse(cur.newXMLStreamReader());
cur2 = alterWS.newCursor(); cur2 = alterWS.newCursor();
@ -636,7 +680,7 @@ public final class XSSFDrawing extends POIXMLDocumentPart implements Drawing<XSS
continue; continue;
} }
assert(shape != null); assert (shape != null);
shape.anchor = getAnchorFromParent(obj); shape.anchor = getAnchorFromParent(obj);
lst.add(shape); lst.add(shape);
@ -651,7 +695,7 @@ public final class XSSFDrawing extends POIXMLDocumentPart implements Drawing<XSS
private boolean hasOleLink(XmlObject shape) { private boolean hasOleLink(XmlObject shape) {
QName uriName = new QName(null, "uri"); QName uriName = new QName(null, "uri");
String xquery = "declare namespace a='"+XSSFRelation.NS_DRAWINGML+"' .//a:extLst/a:ext"; String xquery = "declare namespace a='" + XSSFRelation.NS_DRAWINGML + "' .//a:extLst/a:ext";
XmlCursor cur = shape.newCursor(); XmlCursor cur = shape.newCursor();
cur.selectPath(xquery); cur.selectPath(xquery);
try { try {
@ -667,21 +711,21 @@ public final class XSSFDrawing extends POIXMLDocumentPart implements Drawing<XSS
return false; return false;
} }
private XSSFAnchor getAnchorFromParent(XmlObject obj){ private XSSFAnchor getAnchorFromParent(XmlObject obj) {
XSSFAnchor anchor = null; XSSFAnchor anchor = null;
XmlObject parentXbean = null; XmlObject parentXbean = null;
XmlCursor cursor = obj.newCursor(); XmlCursor cursor = obj.newCursor();
if(cursor.toParent()) { if (cursor.toParent()) {
parentXbean = cursor.getObject(); parentXbean = cursor.getObject();
} }
cursor.dispose(); cursor.dispose();
if(parentXbean != null){ if (parentXbean != null) {
if (parentXbean instanceof CTTwoCellAnchor) { if (parentXbean instanceof CTTwoCellAnchor) {
CTTwoCellAnchor ct = (CTTwoCellAnchor)parentXbean; CTTwoCellAnchor ct = (CTTwoCellAnchor) parentXbean;
anchor = new XSSFClientAnchor(ct.getFrom(), ct.getTo()); anchor = new XSSFClientAnchor(ct.getFrom(), ct.getTo());
} else if (parentXbean instanceof CTOneCellAnchor) { } else if (parentXbean instanceof CTOneCellAnchor) {
CTOneCellAnchor ct = (CTOneCellAnchor)parentXbean; CTOneCellAnchor ct = (CTOneCellAnchor) parentXbean;
anchor = new XSSFClientAnchor(getSheet(), ct.getFrom(), ct.getExt()); anchor = new XSSFClientAnchor(getSheet(), ct.getFrom(), ct.getExt());
} else if (parentXbean instanceof CTAbsoluteAnchor) { } else if (parentXbean instanceof CTAbsoluteAnchor) {
CTAbsoluteAnchor ct = (CTAbsoluteAnchor) parentXbean; CTAbsoluteAnchor ct = (CTAbsoluteAnchor) parentXbean;
@ -700,7 +744,7 @@ public final class XSSFDrawing extends POIXMLDocumentPart implements Drawing<XSS
* @return the sheet associated with the drawing * @return the sheet associated with the drawing
*/ */
public XSSFSheet getSheet() { public XSSFSheet getSheet() {
return (XSSFSheet)getParent(); return (XSSFSheet) getParent();
} }
} }

View File

@ -84,7 +84,6 @@ import org.openxmlformats.schemas.wordprocessingml.x2006.main.STDocProtect;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STHdrFtr; import org.openxmlformats.schemas.wordprocessingml.x2006.main.STHdrFtr;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STOnOff; import org.openxmlformats.schemas.wordprocessingml.x2006.main.STOnOff;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.StylesDocument; import org.openxmlformats.schemas.wordprocessingml.x2006.main.StylesDocument;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.*;
/** /**
* <p>High(ish) level class for working with .docx files.</p> * <p>High(ish) level class for working with .docx files.</p>