merge with trunk
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/xml_signature@1625828 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
11e384f0ec
commit
b410e72196
43
KEYS
43
KEYS
@ -1753,3 +1753,46 @@ W45jdvBkYoPdQtS+8Vy+q0997zobctz8i5hfXzxg51/IuSU4uNtgr26XapsoLDur
|
|||||||
7PoqJGZ6UdBVwyb0qZqs6KLGQkEyJ8358ivjJsjxUR8diK027wWnW/s=
|
7PoqJGZ6UdBVwyb0qZqs6KLGQkEyJ8358ivjJsjxUR8diK027wWnW/s=
|
||||||
=/Vu1
|
=/Vu1
|
||||||
-----END PGP PUBLIC KEY BLOCK-----
|
-----END PGP PUBLIC KEY BLOCK-----
|
||||||
|
pub 2048R/26062CE3 2014-08-17 [expires: 2016-08-16]
|
||||||
|
uid Andreas Beeker <kiwiwings@apache.org>
|
||||||
|
uid Andreas Beeker (kiwiwings) <andreas.beeker@gmx.de>
|
||||||
|
sub 2048R/EE864ED6 2014-08-17 [expires: 2016-08-16]
|
||||||
|
|
||||||
|
-----BEGIN PGP PUBLIC KEY BLOCK-----
|
||||||
|
Version: GnuPG v1
|
||||||
|
|
||||||
|
mQENBFPwtjQBCADWg7jYCGq+QFGfB8nLLQs/WEw4XJiAY9q65qWX1clNuVgTF9Nn
|
||||||
|
ABBOy4KiSDR9XWmARZlC2trKfdoFEnNJ6EnFkLhOjzZKiy4jkyxCctKfbV+sMzCm
|
||||||
|
ODjjNQtn+nYmOu7a8Xg3g3vTnikkuHZqWvK0O0VYouW/p1NHelUejQbOPuUKukD1
|
||||||
|
omzskuYgteTZ9Jn8efJMIymg9dGubuvN4HvUdEO0/u6K2MCZjIqNEPeqWIuZXeMb
|
||||||
|
+4nGv2r0jSQAU94g3hueooqbUf+Mk2+H5O1d/h2Cii9qVvi6gELdVw9H+5Ir9AFc
|
||||||
|
ynsmvxrPIxraBMPgrXmvPFOTlqlizyFv2O7pABEBAAG0MkFuZHJlYXMgQmVla2Vy
|
||||||
|
IChraXdpd2luZ3MpIDxhbmRyZWFzLmJlZWtlckBnbXguZGU+iQE+BBMBAgAoBQJT
|
||||||
|
8LY0AhsDBQkDwmcABgsJCAcDAgYVCAIJCgsEFgIDAQIeAQIXgAAKCRCpPhxLJgYs
|
||||||
|
4wvFB/9hEV8LzHUpD0X/vM9pfW1ZbTl2GNiZfuMh6/KlqB3C4gL3SLLRlk4mEPM3
|
||||||
|
qlZWCqZiWVp5zz1C/j/+BLJW3c+j3rCUEAsobsR6HkxBr7N0LUnurbMXyiOvdg4l
|
||||||
|
AS42Vi1JrydFdih1HCI3NiGMHAV/8NEdtmLt7Ue8Opx01R6rwXBomX5BHJXnzbZR
|
||||||
|
bCbdor/UnO8ff5K4jwd6yhY0BV+bI2uD+vGq9nMld0JGj7W7qB+HzOAxpINtHksQ
|
||||||
|
htTV/PBWjHTCNhOdGh1zyoyvJSshm1NkvwBVZYMs/0ujApcqxAXytGXonLiMmZME
|
||||||
|
COjxAigph8T4PCEKdIqdsVxkC2ybtCVBbmRyZWFzIEJlZWtlciA8a2l3aXdpbmdz
|
||||||
|
QGFwYWNoZS5vcmc+iQE+BBMBAgAoBQJT8RApAhsDBQkDwmcABgsJCAcDAgYVCAIJ
|
||||||
|
CgsEFgIDAQIeAQIXgAAKCRCpPhxLJgYs4732CAC0tb5Wqjf3+/2M6ZzsJR9lqOI6
|
||||||
|
SIwaxu0qnHVUJNzRrF01886uae7k086RCVvEXmSxnmGk86odbx/e7gD0esC9xoxz
|
||||||
|
GRdo5AtMEh18b4fRsq3cdywPDUjvgQBvWXw+jhpJbJe7RRRKZS6X0dRLACn24tGw
|
||||||
|
GPOkn1cE5gkHxUraEk84PKi69znCULasPOV1X46xU2j42N+v0XC3F1ZgFTesvBPh
|
||||||
|
O9Nfaj99GnxpL8PmWyKvKm8SSLTmzLoZ+cXSNGGjJtsrnQn5tmhmEgp5K4DX7lsx
|
||||||
|
+lmfJ9X7+OUxgVHdkesz69d3h+9wBtVl6WqaA+Ocn/0xWr0X55J1OsW+1N2SuQEN
|
||||||
|
BFPwtjQBCACln6mHC8Js3T3KJgNydimOCAFhLmS4e0ur03Y1nckB9zB/pMTLulDg
|
||||||
|
tZwWSin3Kd40VZDyKi6mqOp5ldz6AsZ2CSx1GfI9iVhfuFqOaiBLqpNpdvf9nGL9
|
||||||
|
OVoy1SdwTXgnboiIFtbTG3sVwD4x4qTRbmT22Ln/mIAICR2wxFBkzpbIQ7MfR/zE
|
||||||
|
gRh2VlRUUrWUsnYdOh0xfxuYgsnPCjpTY8hvEno3H6kzXKmj2GQJtawMVs5bRo/G
|
||||||
|
CM9lBBR/PAhB65ACzLmUUSsxjlmjZw0tCcOufg1RyAF/l6YVw1UOJaqXBfSPeZkL
|
||||||
|
QBj9p8VNpasX/acIfpEaZLE8QhoO11ajABEBAAGJASUEGAECAA8FAlPwtjQCGwwF
|
||||||
|
CQPCZwAACgkQqT4cSyYGLOPzLggAjHrdpMjZrHM5WqnxkJ1Eib1g14aScMGdOIw9
|
||||||
|
NOSQ2AGvJjbSy4xyMEUg3S14I73JGYtJu8g9YvCHbuWiyzySBIuGNinMI/ZjET/w
|
||||||
|
1noqoNaSlIY4UfFh30g+OikEzP9WXmo0Scg0XH/fJhX1wCpM/TVlphX0yNGmmkNB
|
||||||
|
BqerRXC7Md4XOy001vvXZGM7vy+xOotyBOy/D4WNERSz3GVS3juCQGMWvMdqKQa+
|
||||||
|
qoiVaXWfFHwg8u4bSHunrzNja17GyaZHdCEmM9vFzlaqBkoLWCMwIcaKnX9stQJp
|
||||||
|
FZwpzgut7DanaPcCDk7LMBbntaJwRC72M0qcj16SUAdAuGt1yQ==
|
||||||
|
=0DjT
|
||||||
|
-----END PGP PUBLIC KEY BLOCK-----
|
||||||
|
16
build.xml
16
build.xml
@ -164,13 +164,17 @@ under the License.
|
|||||||
<property name="ooxml.xmlbeans26.jar" location="${ooxml.lib}/xmlbeans-2.6.0.jar"/>
|
<property name="ooxml.xmlbeans26.jar" location="${ooxml.lib}/xmlbeans-2.6.0.jar"/>
|
||||||
<property name="ooxml.xmlbeans26.url"
|
<property name="ooxml.xmlbeans26.url"
|
||||||
value="${repository.m2}/maven2/org/apache/xmlbeans/xmlbeans/2.6.0/xmlbeans-2.6.0.jar"/>
|
value="${repository.m2}/maven2/org/apache/xmlbeans/xmlbeans/2.6.0/xmlbeans-2.6.0.jar"/>
|
||||||
|
|
||||||
<!-- coverage libs -->
|
<!-- coverage libs -->
|
||||||
<property name="jacoco.zip" location="${main.lib}/jacoco-0.7.1.201405082137.zip"/>
|
<property name="jacoco.zip" location="${main.lib}/jacoco-0.7.1.201405082137.zip"/>
|
||||||
<property name="jacoco.url" value="${repository.m2}/maven2/org/jacoco/jacoco/0.7.1.201405082137/jacoco-0.7.1.201405082137.zip"/>
|
<property name="jacoco.url" value="${repository.m2}/maven2/org/jacoco/jacoco/0.7.1.201405082137/jacoco-0.7.1.201405082137.zip"/>
|
||||||
<property name="asm.jar" location="${main.lib}/asm-all-5.0.3.jar"/>
|
<property name="asm.jar" location="${main.lib}/asm-all-5.0.3.jar"/>
|
||||||
<property name="asm.url" value="${repository.m2}/maven2/org/ow2/asm/asm-all/5.0.3/asm-all-5.0.3.jar"/>
|
<property name="asm.url" value="${repository.m2}/maven2/org/ow2/asm/asm-all/5.0.3/asm-all-5.0.3.jar"/>
|
||||||
|
|
||||||
|
<!-- for testing with older Xerces implementation -->
|
||||||
|
<property name="xerces.jar" location="${main.lib}/xercesImpl-2.6.1.jar"/>
|
||||||
|
<property name="xerces.url" value="${repository.m2}/maven2/xerces/xercesImpl/2.6.1//xercesImpl-2.6.1.jar"/>
|
||||||
|
|
||||||
<!-- license checks -->
|
<!-- license checks -->
|
||||||
<property name="rat.jar" location="${main.lib}/apache-rat-0.10.jar"/>
|
<property name="rat.jar" location="${main.lib}/apache-rat-0.10.jar"/>
|
||||||
<property name="rat.url" value="${repository.m2}/maven2/org/apache/rat/apache-rat/0.10/apache-rat-0.10.jar"/>
|
<property name="rat.url" value="${repository.m2}/maven2/org/apache/rat/apache-rat/0.10/apache-rat-0.10.jar"/>
|
||||||
@ -254,6 +258,7 @@ under the License.
|
|||||||
<path refid="main.classpath"/>
|
<path refid="main.classpath"/>
|
||||||
<pathelement location="${main.output.dir}"/>
|
<pathelement location="${main.output.dir}"/>
|
||||||
<pathelement location="${main.output.test.dir}"/>
|
<pathelement location="${main.output.test.dir}"/>
|
||||||
|
<pathelement location="${additionaljar}"/>
|
||||||
</path>
|
</path>
|
||||||
|
|
||||||
<path id="test.scratchpad.classpath">
|
<path id="test.scratchpad.classpath">
|
||||||
@ -261,6 +266,7 @@ under the License.
|
|||||||
<pathelement location="${main.output.test.dir}"/>
|
<pathelement location="${main.output.test.dir}"/>
|
||||||
<pathelement location="${scratchpad.output.dir}"/>
|
<pathelement location="${scratchpad.output.dir}"/>
|
||||||
<pathelement location="${scratchpad.output.test.dir}"/>
|
<pathelement location="${scratchpad.output.test.dir}"/>
|
||||||
|
<pathelement location="${additionaljar}"/>
|
||||||
</path>
|
</path>
|
||||||
|
|
||||||
<path id="test.ooxml.classpath">
|
<path id="test.ooxml.classpath">
|
||||||
@ -268,6 +274,7 @@ under the License.
|
|||||||
<pathelement location="${ooxml.output.dir}"/>
|
<pathelement location="${ooxml.output.dir}"/>
|
||||||
<pathelement location="${ooxml.output.test.dir}"/>
|
<pathelement location="${ooxml.output.test.dir}"/>
|
||||||
<pathelement location="${main.output.test.dir}"/>
|
<pathelement location="${main.output.test.dir}"/>
|
||||||
|
<pathelement location="${additionaljar}"/>
|
||||||
</path>
|
</path>
|
||||||
|
|
||||||
<path id="ooxml-lite.classpath">
|
<path id="ooxml-lite.classpath">
|
||||||
@ -300,6 +307,7 @@ under the License.
|
|||||||
<pathelement location="${excelant.output.dir}"/>
|
<pathelement location="${excelant.output.dir}"/>
|
||||||
<pathelement location="${excelant.output.test.dir}"/>
|
<pathelement location="${excelant.output.test.dir}"/>
|
||||||
<pathelement location="${main.output.test.dir}"/>
|
<pathelement location="${main.output.test.dir}"/>
|
||||||
|
<pathelement location="${additionaljar}"/>
|
||||||
</path>
|
</path>
|
||||||
|
|
||||||
<path id="lib.jacoco">
|
<path id="lib.jacoco">
|
||||||
@ -372,6 +380,7 @@ under the License.
|
|||||||
<include name="jacoco-0.6*"/>
|
<include name="jacoco-0.6*"/>
|
||||||
<include name="log4j-1.2.13*"/>
|
<include name="log4j-1.2.13*"/>
|
||||||
<include name="org.jacoco.*-0.6.*"/>
|
<include name="org.jacoco.*-0.6.*"/>
|
||||||
|
<include name="dom4j*"/>
|
||||||
</fileset>
|
</fileset>
|
||||||
</delete>
|
</delete>
|
||||||
|
|
||||||
@ -388,6 +397,7 @@ under the License.
|
|||||||
<available file="${asm.jar}"/>
|
<available file="${asm.jar}"/>
|
||||||
<available file="${jacoco.zip}"/>
|
<available file="${jacoco.zip}"/>
|
||||||
<available file="${rat.jar}"/>
|
<available file="${rat.jar}"/>
|
||||||
|
<available file="${xerces.jar}"/>
|
||||||
</and>
|
</and>
|
||||||
<isset property="disconnected"/>
|
<isset property="disconnected"/>
|
||||||
</or>
|
</or>
|
||||||
@ -438,6 +448,10 @@ under the License.
|
|||||||
<include name="lib/*.jar"/>
|
<include name="lib/*.jar"/>
|
||||||
</patternset>
|
</patternset>
|
||||||
</unzip>
|
</unzip>
|
||||||
|
<antcall target="downloadfile">
|
||||||
|
<param name="sourcefile" value="${xerces.url}"/>
|
||||||
|
<param name="destfile" value="${xerces.jar}"/>
|
||||||
|
</antcall>
|
||||||
<antcall target="downloadfile">
|
<antcall target="downloadfile">
|
||||||
<param name="sourcefile" value="${rat.url}"/>
|
<param name="sourcefile" value="${rat.url}"/>
|
||||||
<param name="destfile" value="${rat.jar}"/>
|
<param name="destfile" value="${rat.jar}"/>
|
||||||
|
@ -115,6 +115,7 @@ public class FromHowTo {
|
|||||||
if(nextIsString) {
|
if(nextIsString) {
|
||||||
int idx = Integer.parseInt(lastContents);
|
int idx = Integer.parseInt(lastContents);
|
||||||
lastContents = new XSSFRichTextString(sst.getEntryAt(idx)).toString();
|
lastContents = new XSSFRichTextString(sst.getEntryAt(idx)).toString();
|
||||||
|
nextIsString = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// v => contents of a cell
|
// v => contents of a cell
|
||||||
|
@ -145,7 +145,7 @@ public final class BiffViewer {
|
|||||||
case DatRecord.sid: return new DatRecord(in);
|
case DatRecord.sid: return new DatRecord(in);
|
||||||
case DataFormatRecord.sid: return new DataFormatRecord(in);
|
case DataFormatRecord.sid: return new DataFormatRecord(in);
|
||||||
case DateWindow1904Record.sid: return new DateWindow1904Record(in);
|
case DateWindow1904Record.sid: return new DateWindow1904Record(in);
|
||||||
case DConRefRecord.sid: return new DConRefRecord(in);
|
case DConRefRecord.sid: return new DConRefRecord(in);
|
||||||
case DefaultColWidthRecord.sid:return new DefaultColWidthRecord(in);
|
case DefaultColWidthRecord.sid:return new DefaultColWidthRecord(in);
|
||||||
case DefaultDataLabelTextPropertiesRecord.sid: return new DefaultDataLabelTextPropertiesRecord(in);
|
case DefaultDataLabelTextPropertiesRecord.sid: return new DefaultDataLabelTextPropertiesRecord(in);
|
||||||
case DefaultRowHeightRecord.sid: return new DefaultRowHeightRecord(in);
|
case DefaultRowHeightRecord.sid: return new DefaultRowHeightRecord(in);
|
||||||
|
@ -57,20 +57,19 @@ public abstract class AbstractEscherHolderRecord extends Record {
|
|||||||
public AbstractEscherHolderRecord(RecordInputStream in)
|
public AbstractEscherHolderRecord(RecordInputStream in)
|
||||||
{
|
{
|
||||||
escherRecords = new ArrayList<EscherRecord>();
|
escherRecords = new ArrayList<EscherRecord>();
|
||||||
if (! DESERIALISE )
|
if (! DESERIALISE ) {
|
||||||
{
|
|
||||||
rawDataContainer.concatenate(in.readRemainder());
|
rawDataContainer.concatenate(in.readRemainder());
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
byte[] data = in.readAllContinuedRemainder();
|
byte[] data = in.readAllContinuedRemainder();
|
||||||
convertToEscherRecords( 0, data.length, data );
|
convertToEscherRecords( 0, data.length, data );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void convertRawBytesToEscherRecords() {
|
protected void convertRawBytesToEscherRecords() {
|
||||||
byte[] rawData = getRawData();
|
if (! DESERIALISE ) {
|
||||||
convertToEscherRecords(0, rawData.length, rawData);
|
byte[] rawData = getRawData();
|
||||||
|
convertToEscherRecords(0, rawData.length, rawData);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
private void convertToEscherRecords( int offset, int size, byte[] data )
|
private void convertToEscherRecords( int offset, int size, byte[] data )
|
||||||
{
|
{
|
||||||
@ -224,7 +223,7 @@ public abstract class AbstractEscherHolderRecord extends Record {
|
|||||||
|
|
||||||
public EscherRecord getEscherRecord(int index)
|
public EscherRecord getEscherRecord(int index)
|
||||||
{
|
{
|
||||||
return (EscherRecord) escherRecords.get(index);
|
return escherRecords.get(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -18,10 +18,11 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.poi.hssf.record;
|
package org.apache.poi.hssf.record;
|
||||||
|
|
||||||
import org.apache.poi.util.ArrayUtil;
|
|
||||||
import org.apache.poi.util.LittleEndian;
|
import org.apache.poi.util.LittleEndian;
|
||||||
import org.apache.poi.util.LittleEndianOutput;
|
import org.apache.poi.util.LittleEndianOutput;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DConRef records specify a range in a workbook (internal or external) that serves as a data source
|
* DConRef records specify a range in a workbook (internal or external) that serves as a data source
|
||||||
* for pivot tables or data consolidation.
|
* for pivot tables or data consolidation.
|
||||||
@ -273,7 +274,7 @@ public class DConRefRecord extends StandardRecord
|
|||||||
*/
|
*/
|
||||||
public byte[] getPath()
|
public byte[] getPath()
|
||||||
{
|
{
|
||||||
return ArrayUtil.copyOf(path, path.length);
|
return Arrays.copyOf(path, path.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -291,7 +292,7 @@ public class DConRefRecord extends StandardRecord
|
|||||||
{
|
{
|
||||||
offset++;
|
offset++;
|
||||||
}
|
}
|
||||||
String out = new String(ArrayUtil.copyOfRange(path, offset, path.length));
|
String out = new String(Arrays.copyOfRange(path, offset, path.length));
|
||||||
//UNC paths have \u0003 chars as path separators.
|
//UNC paths have \u0003 chars as path separators.
|
||||||
out = out.replaceAll("\u0003", "/");
|
out = out.replaceAll("\u0003", "/");
|
||||||
return out;
|
return out;
|
||||||
|
@ -118,7 +118,7 @@ public final class DrawingGroupRecord extends AbstractEscherHolderRecord {
|
|||||||
writeHeader( data, offset, segmentLength );
|
writeHeader( data, offset, segmentLength );
|
||||||
writtenActualData += 4;
|
writtenActualData += 4;
|
||||||
offset += 4;
|
offset += 4;
|
||||||
ArrayUtil.arraycopy( rawData, writtenRawData, data, offset, segmentLength );
|
System.arraycopy( rawData, writtenRawData, data, offset, segmentLength );
|
||||||
offset += segmentLength;
|
offset += segmentLength;
|
||||||
writtenRawData += segmentLength;
|
writtenRawData += segmentLength;
|
||||||
writtenActualData += segmentLength;
|
writtenActualData += segmentLength;
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
package org.apache.poi.hssf.record;
|
package org.apache.poi.hssf.record;
|
||||||
|
|
||||||
|
import org.apache.poi.poifs.crypt.CryptoFunctions;
|
||||||
import org.apache.poi.util.HexDump;
|
import org.apache.poi.util.HexDump;
|
||||||
import org.apache.poi.util.LittleEndianOutput;
|
import org.apache.poi.util.LittleEndianOutput;
|
||||||
|
|
||||||
@ -39,23 +40,13 @@ public final class PasswordRecord extends StandardRecord {
|
|||||||
field_1_password = in.readShort();
|
field_1_password = in.readShort();
|
||||||
}
|
}
|
||||||
|
|
||||||
//this is the world's lamest "security". thanks to Wouter van Vugt for making me
|
/**
|
||||||
//not have to try real hard. -ACO
|
* Return the password hash
|
||||||
|
*
|
||||||
|
* @deprecated use {@link CryptoFunctions#createXorVerifier1(String)}
|
||||||
|
*/
|
||||||
public static short hashPassword(String password) {
|
public static short hashPassword(String password) {
|
||||||
byte[] passwordCharacters = password.getBytes();
|
return (short)CryptoFunctions.createXorVerifier1(password);
|
||||||
int hash = 0;
|
|
||||||
if (passwordCharacters.length > 0) {
|
|
||||||
int charIndex = passwordCharacters.length;
|
|
||||||
while (charIndex-- > 0) {
|
|
||||||
hash = ((hash >> 14) & 0x01) | ((hash << 1) & 0x7fff);
|
|
||||||
hash ^= passwordCharacters[charIndex];
|
|
||||||
}
|
|
||||||
// also hash with charcount
|
|
||||||
hash = ((hash >> 14) & 0x01) | ((hash << 1) & 0x7fff);
|
|
||||||
hash ^= passwordCharacters.length;
|
|
||||||
hash ^= (0x8000 | ('N' << 8) | 'K');
|
|
||||||
}
|
|
||||||
return (short)hash;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -24,6 +24,7 @@ import org.apache.poi.hssf.record.ProtectRecord;
|
|||||||
import org.apache.poi.hssf.record.Record;
|
import org.apache.poi.hssf.record.Record;
|
||||||
import org.apache.poi.hssf.record.RecordFormatException;
|
import org.apache.poi.hssf.record.RecordFormatException;
|
||||||
import org.apache.poi.hssf.record.ScenarioProtectRecord;
|
import org.apache.poi.hssf.record.ScenarioProtectRecord;
|
||||||
|
import org.apache.poi.poifs.crypt.CryptoFunctions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Groups the sheet protection records for a worksheet.
|
* Groups the sheet protection records for a worksheet.
|
||||||
@ -186,7 +187,7 @@ public final class WorksheetProtectionBlock extends RecordAggregate {
|
|||||||
ProtectRecord prec = getProtect();
|
ProtectRecord prec = getProtect();
|
||||||
PasswordRecord pass = getPassword();
|
PasswordRecord pass = getPassword();
|
||||||
prec.setProtect(true);
|
prec.setProtect(true);
|
||||||
pass.setPassword(PasswordRecord.hashPassword(password));
|
pass.setPassword((short)CryptoFunctions.createXorVerifier1(password));
|
||||||
if (_objectProtectRecord == null && shouldProtectObjects) {
|
if (_objectProtectRecord == null && shouldProtectObjects) {
|
||||||
ObjectProtectRecord rec = createObjectProtect();
|
ObjectProtectRecord rec = createObjectProtect();
|
||||||
rec.setProtect(true);
|
rec.setProtect(true);
|
||||||
|
@ -827,6 +827,29 @@ public final class HSSFCellStyle implements CellStyle {
|
|||||||
return _format.getShrinkToFit();
|
return _format.getShrinkToFit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the reading order, for RTL/LTR ordering of
|
||||||
|
* the text.
|
||||||
|
* <p>0 means Context (Default), 1 means Left To Right,
|
||||||
|
* and 2 means Right to Left</p>
|
||||||
|
*
|
||||||
|
* @return order - the reading order (0,1,2)
|
||||||
|
*/
|
||||||
|
public short getReadingOrder() {
|
||||||
|
return _format.getReadingOrder();
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Sets the reading order, for RTL/LTR ordering of
|
||||||
|
* the text.
|
||||||
|
* <p>0 means Context (Default), 1 means Left To Right,
|
||||||
|
* and 2 means Right to Left</p>
|
||||||
|
*
|
||||||
|
* @param order - the reading order (0,1,2)
|
||||||
|
*/
|
||||||
|
public void setReadingOrder(short order) {
|
||||||
|
_format.setReadingOrder(order);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verifies that this style belongs to the supplied Workbook.
|
* Verifies that this style belongs to the supplied Workbook.
|
||||||
* Will throw an exception if it belongs to a different one.
|
* Will throw an exception if it belongs to a different one.
|
||||||
|
@ -42,6 +42,10 @@ public final class HSSFClientAnchor extends HSSFAnchor implements ClientAnchor {
|
|||||||
/**
|
/**
|
||||||
* Creates a new client anchor and sets the top-left and bottom-right
|
* Creates a new client anchor and sets the top-left and bottom-right
|
||||||
* coordinates of the anchor.
|
* coordinates of the anchor.
|
||||||
|
*
|
||||||
|
* Note: Microsoft Excel seems to sometimes disallow
|
||||||
|
* higher y1 than y2 or higher x1 than x2, you might need to
|
||||||
|
* reverse them and draw shapes vertically or horizontally flipped!
|
||||||
*
|
*
|
||||||
* @param dx1 the x coordinate within the first cell.
|
* @param dx1 the x coordinate within the first cell.
|
||||||
* @param dy1 the y coordinate within the first cell.
|
* @param dy1 the y coordinate within the first cell.
|
||||||
@ -186,8 +190,12 @@ public final class HSSFClientAnchor extends HSSFAnchor implements ClientAnchor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dets the top-left and bottom-right
|
* Sets the top-left and bottom-right coordinates of
|
||||||
* coordinates of the anchor.
|
* the anchor.
|
||||||
|
*
|
||||||
|
* Note: Microsoft Excel seems to sometimes disallow
|
||||||
|
* higher y1 than y2 or higher x1 than x2, you might need to
|
||||||
|
* reverse them and draw shapes vertically or horizontally flipped!
|
||||||
*
|
*
|
||||||
* @param x1 the x coordinate within the first cell.
|
* @param x1 the x coordinate within the first cell.
|
||||||
* @param y1 the y coordinate within the first cell.
|
* @param y1 the y coordinate within the first cell.
|
||||||
|
@ -171,6 +171,10 @@ public final class HSSFPatriarch implements HSSFShapeContainer, Drawing {
|
|||||||
/**
|
/**
|
||||||
* 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.
|
||||||
|
*
|
||||||
|
* Note: Microsoft Excel seems to sometimes disallow
|
||||||
|
* higher y1 than y2 or higher x1 than x2 in the anchor, you might need to
|
||||||
|
* reverse them and draw shapes vertically or horizontally flipped!
|
||||||
*
|
*
|
||||||
* @param anchor the client anchor describes how this group is attached
|
* @param anchor the client anchor describes how this group is attached
|
||||||
* to the sheet.
|
* to the sheet.
|
||||||
|
@ -27,6 +27,11 @@ import java.io.IOException;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* An abstract shape.
|
* An abstract shape.
|
||||||
|
*
|
||||||
|
* Note: Microsoft Excel seems to sometimes disallow
|
||||||
|
* higher y1 than y2 or higher x1 than x2 in the anchor, you might need to
|
||||||
|
* reverse them and draw shapes vertically or horizontally flipped via
|
||||||
|
* setFlipVertical() or setFlipHorizontally().
|
||||||
*/
|
*/
|
||||||
public abstract class HSSFShape {
|
public abstract class HSSFShape {
|
||||||
public static final int LINEWIDTH_ONE_PT = 12700;
|
public static final int LINEWIDTH_ONE_PT = 12700;
|
||||||
|
@ -181,14 +181,20 @@ public class CryptoFunctions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Initialize a new cipher object with the given cipher properties
|
||||||
|
* If the given algorithm is not implemented in the JCE, it will try to load it from the bouncy castle
|
||||||
|
* provider.
|
||||||
*
|
*
|
||||||
* @param key
|
* @param key the secrect key
|
||||||
* @param chain
|
* @param cipherAlgorithm the cipher algorithm
|
||||||
* @param vec
|
* @param chain the chaining mode
|
||||||
|
* @param vec the initialization vector (IV), can be null
|
||||||
* @param cipherMode Cipher.DECRYPT_MODE or Cipher.ENCRYPT_MODE
|
* @param cipherMode Cipher.DECRYPT_MODE or Cipher.ENCRYPT_MODE
|
||||||
|
* @param padding
|
||||||
* @return the requested cipher
|
* @return the requested cipher
|
||||||
* @throws GeneralSecurityException
|
* @throws GeneralSecurityException
|
||||||
|
* @throws EncryptedDocumentException if the initialization failed or if an algorithm was specified,
|
||||||
|
* which depends on a missing bouncy castle provider
|
||||||
*/
|
*/
|
||||||
public static Cipher getCipher(Key key, CipherAlgorithm cipherAlgorithm, ChainingMode chain, byte[] vec, int cipherMode, String padding) {
|
public static Cipher getCipher(Key key, CipherAlgorithm cipherAlgorithm, ChainingMode chain, byte[] vec, int cipherMode, String padding) {
|
||||||
int keySizeInBytes = key.getEncoded().length;
|
int keySizeInBytes = key.getEncoded().length;
|
||||||
@ -227,10 +233,26 @@ public class CryptoFunctions {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a new byte array with a truncated to the given size.
|
||||||
|
* If the hash has less then size bytes, it will be filled with 0x36-bytes
|
||||||
|
*
|
||||||
|
* @param hash the to be truncated/filled hash byte array
|
||||||
|
* @param size the size of the returned byte array
|
||||||
|
* @return the padded hash
|
||||||
|
*/
|
||||||
public static byte[] getBlock36(byte[] hash, int size) {
|
public static byte[] getBlock36(byte[] hash, int size) {
|
||||||
return getBlockX(hash, size, (byte)0x36);
|
return getBlockX(hash, size, (byte)0x36);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a new byte array with a truncated to the given size.
|
||||||
|
* If the hash has less then size bytes, it will be filled with 0-bytes
|
||||||
|
*
|
||||||
|
* @param hash the to be truncated/filled hash byte array
|
||||||
|
* @param size the size of the returned byte array
|
||||||
|
* @return the padded hash
|
||||||
|
*/
|
||||||
public static byte[] getBlock0(byte[] hash, int size) {
|
public static byte[] getBlock0(byte[] hash, int size) {
|
||||||
return getBlockX(hash, size, (byte)0);
|
return getBlockX(hash, size, (byte)0);
|
||||||
}
|
}
|
||||||
@ -334,11 +356,11 @@ public class CryptoFunctions {
|
|||||||
byte[] generatedKey = new byte[4];
|
byte[] generatedKey = new byte[4];
|
||||||
|
|
||||||
//Maximum length of the password is 15 chars.
|
//Maximum length of the password is 15 chars.
|
||||||
final int intMaxPasswordLength = 15;
|
final int maxPasswordLength = 15;
|
||||||
|
|
||||||
if (!"".equals(password)) {
|
if (!"".equals(password)) {
|
||||||
// Truncate the password to 15 characters
|
// Truncate the password to 15 characters
|
||||||
password = password.substring(0, Math.min(password.length(), intMaxPasswordLength));
|
password = password.substring(0, Math.min(password.length(), maxPasswordLength));
|
||||||
|
|
||||||
// Construct a new NULL-terminated string consisting of single-byte characters:
|
// Construct a new NULL-terminated string consisting of single-byte characters:
|
||||||
// -- > Get the single-byte values by iterating through the Unicode characters of the truncated Password.
|
// -- > Get the single-byte values by iterating through the Unicode characters of the truncated Password.
|
||||||
@ -362,7 +384,7 @@ public class CryptoFunctions {
|
|||||||
// the most significant, if the bit is set, XOR the keys high-order word with the corresponding word from
|
// the most significant, if the bit is set, XOR the keys high-order word with the corresponding word from
|
||||||
// the Encryption Matrix
|
// the Encryption Matrix
|
||||||
for (int i = 0; i < arrByteChars.length; i++) {
|
for (int i = 0; i < arrByteChars.length; i++) {
|
||||||
int tmp = intMaxPasswordLength - arrByteChars.length + i;
|
int tmp = maxPasswordLength - arrByteChars.length + i;
|
||||||
for (int intBit = 0; intBit < 7; intBit++) {
|
for (int intBit = 0; intBit < 7; intBit++) {
|
||||||
if ((arrByteChars[i] & (0x0001 << intBit)) != 0) {
|
if ((arrByteChars[i] & (0x0001 << intBit)) != 0) {
|
||||||
highOrderWord ^= EncryptionMatrix[tmp][intBit];
|
highOrderWord ^= EncryptionMatrix[tmp][intBit];
|
||||||
@ -372,22 +394,28 @@ public class CryptoFunctions {
|
|||||||
|
|
||||||
// Compute the low-order word of the new key:
|
// Compute the low-order word of the new key:
|
||||||
|
|
||||||
// Initialize with 0
|
// SET Verifier TO 0x0000
|
||||||
int lowOrderWord = 0;
|
short verifier = 0;
|
||||||
|
|
||||||
// For each character in the password, going backwards
|
// FOR EACH PasswordByte IN PasswordArray IN REVERSE ORDER
|
||||||
for (int i = arrByteChars.length - 1; i >= 0; i--) {
|
for (int i = arrByteChars.length-1; i >= 0; i--) {
|
||||||
// low-order word = (((low-order word SHR 14) AND 0x0001) OR (low-order word SHL 1) AND 0x7FFF)) XOR character
|
// SET Verifier TO Intermediate3 BITWISE XOR PasswordByte
|
||||||
lowOrderWord = (((lowOrderWord >> 14) & 0x0001) | ((lowOrderWord << 1) & 0x7FFF)) ^ arrByteChars[i];
|
verifier = rotateLeftBase15Bit(verifier);
|
||||||
|
verifier ^= arrByteChars[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lastly,low-order word = (((low-order word SHR 14) AND 0x0001) OR (low-order word SHL 1) AND 0x7FFF)) XOR password length XOR 0xCE4B.
|
// as we haven't prepended the password length into the input array
|
||||||
lowOrderWord = (((lowOrderWord >> 14) & 0x0001) | ((lowOrderWord << 1) & 0x7FFF)) ^ arrByteChars.length ^ 0xCE4B;
|
// we need to do it now separately ...
|
||||||
|
verifier = rotateLeftBase15Bit(verifier);
|
||||||
|
verifier ^= arrByteChars.length;
|
||||||
|
|
||||||
|
// RETURN Verifier BITWISE XOR 0xCE4B
|
||||||
|
verifier ^= 0xCE4B; // (0x8000 | ('N' << 8) | 'K')
|
||||||
|
|
||||||
// The byte order of the result shall be reversed [password "Example": 0x64CEED7E becomes 7EEDCE64],
|
// The byte order of the result shall be reversed [password "Example": 0x64CEED7E becomes 7EEDCE64],
|
||||||
// and that value shall be hashed as defined by the attribute values.
|
// and that value shall be hashed as defined by the attribute values.
|
||||||
|
|
||||||
LittleEndian.putShort(generatedKey, 0, (short)lowOrderWord);
|
LittleEndian.putShort(generatedKey, 0, verifier);
|
||||||
LittleEndian.putShort(generatedKey, 2, (short)highOrderWord);
|
LittleEndian.putShort(generatedKey, 2, (short)highOrderWord);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -424,7 +452,7 @@ public class CryptoFunctions {
|
|||||||
* @see <a href="http://msdn.microsoft.com/en-us/library/dd905229.aspx">2.3.7.4 Binary Document Password Verifier Derivation Method 2</a>
|
* @see <a href="http://msdn.microsoft.com/en-us/library/dd905229.aspx">2.3.7.4 Binary Document Password Verifier Derivation Method 2</a>
|
||||||
*
|
*
|
||||||
* @param password the password
|
* @param password the password
|
||||||
* @return the verifier
|
* @return the verifier (actually a short value)
|
||||||
*/
|
*/
|
||||||
public static int createXorVerifier1(String password) {
|
public static int createXorVerifier1(String password) {
|
||||||
// the verifier for method 1 is part of the verifier for method 2
|
// the verifier for method 1 is part of the verifier for method 2
|
||||||
@ -483,4 +511,25 @@ public class CryptoFunctions {
|
|||||||
private static byte rotateLeft(byte bits, int shift) {
|
private static byte rotateLeft(byte bits, int shift) {
|
||||||
return (byte)(((bits & 0xff) << shift) | ((bits & 0xff) >>> (8 - shift)));
|
return (byte)(((bits & 0xff) << shift) | ((bits & 0xff) >>> (8 - shift)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static short rotateLeftBase15Bit(short verifier) {
|
||||||
|
/*
|
||||||
|
* IF (Verifier BITWISE AND 0x4000) is 0x0000
|
||||||
|
* SET Intermediate1 TO 0
|
||||||
|
* ELSE
|
||||||
|
* SET Intermediate1 TO 1
|
||||||
|
* ENDIF
|
||||||
|
*/
|
||||||
|
short intermediate1 = (short)(((verifier & 0x4000) == 0) ? 0 : 1);
|
||||||
|
/*
|
||||||
|
* SET Intermediate2 TO Verifier MULTIPLED BY 2
|
||||||
|
* SET most significant bit of Intermediate2 TO 0
|
||||||
|
*/
|
||||||
|
short intermediate2 = (short)((verifier<<1) & 0x7FFF);
|
||||||
|
/*
|
||||||
|
* SET Intermediate3 TO Intermediate1 BITWISE OR Intermediate2
|
||||||
|
*/
|
||||||
|
short intermediate3 = (short)(intermediate1 | intermediate2);
|
||||||
|
return intermediate3;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,4 +68,11 @@ public enum HashAlgorithm {
|
|||||||
}
|
}
|
||||||
throw new EncryptedDocumentException("hash algorithm not found");
|
throw new EncryptedDocumentException("hash algorithm not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static HashAlgorithm fromString(String string) {
|
||||||
|
for (HashAlgorithm ha : values()) {
|
||||||
|
if (ha.ecmaString.equalsIgnoreCase(string) || ha.jceId.equalsIgnoreCase(string)) return ha;
|
||||||
|
}
|
||||||
|
throw new EncryptedDocumentException("hash algorithm not found");
|
||||||
|
}
|
||||||
}
|
}
|
@ -153,7 +153,8 @@ public class NPOIFSFileSystem extends BlockStore
|
|||||||
* when you're done to have the underlying file closed, as the file is
|
* when you're done to have the underlying file closed, as the file is
|
||||||
* kept open during normal operation to read the data out.</p>
|
* kept open during normal operation to read the data out.</p>
|
||||||
*
|
*
|
||||||
* @param file the File from which to read the data
|
* @param file the File from which to read or read/write the data
|
||||||
|
* @param readOnly whether the POIFileSystem will only be used in read-only mode
|
||||||
*
|
*
|
||||||
* @exception IOException on errors reading, or on invalid data
|
* @exception IOException on errors reading, or on invalid data
|
||||||
*/
|
*/
|
||||||
@ -165,20 +166,40 @@ public class NPOIFSFileSystem extends BlockStore
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Creates a POIFSFileSystem from an open <tt>FileChannel</tt>. This uses
|
* <p>Creates a POIFSFileSystem from an open <tt>FileChannel</tt>. This uses
|
||||||
* less memory than creating from an <tt>InputStream</tt>.</p>
|
* less memory than creating from an <tt>InputStream</tt>. The stream will
|
||||||
|
* be used in read-only mode.</p>
|
||||||
*
|
*
|
||||||
* <p>Note that with this constructor, you will need to call {@link #close()}
|
* <p>Note that with this constructor, you will need to call {@link #close()}
|
||||||
* when you're done to have the underlying Channel closed, as the channel is
|
* when you're done to have the underlying Channel closed, as the channel is
|
||||||
* kept open during normal operation to read the data out.</p>
|
* kept open during normal operation to read the data out.</p>
|
||||||
*
|
*
|
||||||
* @param channel the FileChannel from which to read and write the data
|
* @param channel the FileChannel from which to read the data
|
||||||
*
|
*
|
||||||
* @exception IOException on errors reading, or on invalid data
|
* @exception IOException on errors reading, or on invalid data
|
||||||
*/
|
*/
|
||||||
public NPOIFSFileSystem(FileChannel channel)
|
public NPOIFSFileSystem(FileChannel channel)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
this(channel, null, false, false);
|
this(channel, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Creates a POIFSFileSystem from an open <tt>FileChannel</tt>. This uses
|
||||||
|
* less memory than creating from an <tt>InputStream</tt>.</p>
|
||||||
|
*
|
||||||
|
* <p>Note that with this constructor, you will need to call {@link #close()}
|
||||||
|
* when you're done to have the underlying Channel closed, as the channel is
|
||||||
|
* kept open during normal operation to read the data out.</p>
|
||||||
|
*
|
||||||
|
* @param channel the FileChannel from which to read or read/write the data
|
||||||
|
* @param readOnly whether the POIFileSystem will only be used in read-only mode
|
||||||
|
*
|
||||||
|
* @exception IOException on errors reading, or on invalid data
|
||||||
|
*/
|
||||||
|
public NPOIFSFileSystem(FileChannel channel, boolean readOnly)
|
||||||
|
throws IOException
|
||||||
|
{
|
||||||
|
this(channel, null, readOnly, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private NPOIFSFileSystem(FileChannel channel, File srcFile, boolean readOnly, boolean closeChannelOnError)
|
private NPOIFSFileSystem(FileChannel channel, File srcFile, boolean readOnly, boolean closeChannelOnError)
|
||||||
|
@ -21,105 +21,111 @@ import org.apache.poi.ss.util.CellReference;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This enum allows spreadsheets from multiple Excel versions to be handled by the common code.
|
* This enum allows spreadsheets from multiple Excel versions to be handled by the common code.
|
||||||
* Properties of this enum correspond to attributes of the <i>spreadsheet</i> that are easily
|
* <p>Properties of this enum correspond to attributes of the <i>spreadsheet</i> that are easily
|
||||||
* discernable to the user. It is not intended to deal with low-level issues like file formats.
|
* discernable to the user. It is not intended to deal with low-level issues like file formats.
|
||||||
* <p/>
|
|
||||||
*
|
|
||||||
* @author Josh Micich
|
|
||||||
* @author Yegor Kozlov
|
|
||||||
*/
|
*/
|
||||||
public enum SpreadsheetVersion {
|
public enum SpreadsheetVersion {
|
||||||
/**
|
/**
|
||||||
* Excel97 format aka BIFF8
|
* Excel97 format aka BIFF8
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>The total number of available columns is 256 (2^8)</li>
|
* <li>The total number of available columns is 256 (2^8)</li>
|
||||||
* <li>The total number of available rows is 64k (2^16)</li>
|
* <li>The total number of available rows is 64k (2^16)</li>
|
||||||
* <li>The maximum number of arguments to a function is 30</li>
|
* <li>The maximum number of arguments to a function is 30</li>
|
||||||
* <li>Number of conditional format conditions on a cell is 3</li>
|
* <li>Number of conditional format conditions on a cell is 3</li>
|
||||||
|
* <li>Number of cell styles is 4000</li>
|
||||||
* <li>Length of text cell contents is 32767</li>
|
* <li>Length of text cell contents is 32767</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
*/
|
*/
|
||||||
EXCEL97(0x10000, 0x0100, 30, 3, 32767),
|
EXCEL97(0x10000, 0x0100, 30, 3, 4000, 32767),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Excel2007
|
* Excel2007
|
||||||
*
|
*
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>The total number of available columns is 16K (2^14)</li>
|
* <li>The total number of available columns is 16K (2^14)</li>
|
||||||
* <li>The total number of available rows is 1M (2^20)</li>
|
* <li>The total number of available rows is 1M (2^20)</li>
|
||||||
* <li>The maximum number of arguments to a function is 255</li>
|
* <li>The maximum number of arguments to a function is 255</li>
|
||||||
* <li>Number of conditional format conditions on a cell is unlimited
|
* <li>Number of conditional format conditions on a cell is unlimited
|
||||||
* (actually limited by available memory in Excel)</li>
|
* (actually limited by available memory in Excel)</li>
|
||||||
|
* <li>Number of cell styles is 64000</li>
|
||||||
* <li>Length of text cell contents is 32767</li>
|
* <li>Length of text cell contents is 32767</li>
|
||||||
* <ul>
|
* <ul>
|
||||||
*/
|
*/
|
||||||
EXCEL2007(0x100000, 0x4000, 255, Integer.MAX_VALUE, 32767);
|
EXCEL2007(0x100000, 0x4000, 255, Integer.MAX_VALUE, 64000, 32767);
|
||||||
|
|
||||||
private final int _maxRows;
|
private final int _maxRows;
|
||||||
private final int _maxColumns;
|
private final int _maxColumns;
|
||||||
private final int _maxFunctionArgs;
|
private final int _maxFunctionArgs;
|
||||||
private final int _maxCondFormats;
|
private final int _maxCondFormats;
|
||||||
|
private final int _maxCellStyles;
|
||||||
private final int _maxTextLength;
|
private final int _maxTextLength;
|
||||||
|
|
||||||
private SpreadsheetVersion(int maxRows, int maxColumns, int maxFunctionArgs, int maxCondFormats, int maxText) {
|
private SpreadsheetVersion(int maxRows, int maxColumns, int maxFunctionArgs, int maxCondFormats, int maxCellStyles, int maxText) {
|
||||||
_maxRows = maxRows;
|
_maxRows = maxRows;
|
||||||
_maxColumns = maxColumns;
|
_maxColumns = maxColumns;
|
||||||
_maxFunctionArgs = maxFunctionArgs;
|
_maxFunctionArgs = maxFunctionArgs;
|
||||||
_maxCondFormats = maxCondFormats;
|
_maxCondFormats = maxCondFormats;
|
||||||
|
_maxCellStyles = maxCellStyles;
|
||||||
_maxTextLength = maxText;
|
_maxTextLength = maxText;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the maximum number of usable rows in each spreadsheet
|
* @return the maximum number of usable rows in each spreadsheet
|
||||||
*/
|
*/
|
||||||
public int getMaxRows() {
|
public int getMaxRows() {
|
||||||
return _maxRows;
|
return _maxRows;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the last (maximum) valid row index, equals to <code> getMaxRows() - 1 </code>
|
* @return the last (maximum) valid row index, equals to <code> getMaxRows() - 1 </code>
|
||||||
*/
|
*/
|
||||||
public int getLastRowIndex() {
|
public int getLastRowIndex() {
|
||||||
return _maxRows - 1;
|
return _maxRows - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the maximum number of usable columns in each spreadsheet
|
* @return the maximum number of usable columns in each spreadsheet
|
||||||
*/
|
*/
|
||||||
public int getMaxColumns() {
|
public int getMaxColumns() {
|
||||||
return _maxColumns;
|
return _maxColumns;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the last (maximum) valid column index, equals to <code> getMaxColumns() - 1 </code>
|
* @return the last (maximum) valid column index, equals to <code> getMaxColumns() - 1 </code>
|
||||||
*/
|
*/
|
||||||
public int getLastColumnIndex() {
|
public int getLastColumnIndex() {
|
||||||
return _maxColumns - 1;
|
return _maxColumns - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the maximum number arguments that can be passed to a multi-arg function (e.g. COUNTIF)
|
* @return the maximum number arguments that can be passed to a multi-arg function (e.g. COUNTIF)
|
||||||
*/
|
*/
|
||||||
public int getMaxFunctionArgs() {
|
public int getMaxFunctionArgs() {
|
||||||
return _maxFunctionArgs;
|
return _maxFunctionArgs;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* @return the maximum number of conditional format conditions on a cell
|
||||||
* @return the maximum number of conditional format conditions on a cell
|
*/
|
||||||
*/
|
public int getMaxConditionalFormats() {
|
||||||
public int getMaxConditionalFormats() {
|
return _maxCondFormats;
|
||||||
return _maxCondFormats;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* @return the maximum number of cell styles per spreadsheet
|
||||||
* @return the last valid column index in a ALPHA-26 representation
|
*/
|
||||||
* (<code>IV</code> or <code>XFD</code>).
|
public int getMaxCellStyles() {
|
||||||
*/
|
return _maxCellStyles;
|
||||||
public String getLastColumnName() {
|
}
|
||||||
return CellReference.convertNumToColString(getLastColumnIndex());
|
|
||||||
}
|
/**
|
||||||
|
*
|
||||||
|
* @return the last valid column index in a ALPHA-26 representation
|
||||||
|
* (<code>IV</code> or <code>XFD</code>).
|
||||||
|
*/
|
||||||
|
public String getLastColumnName() {
|
||||||
|
return CellReference.convertNumToColString(getLastColumnIndex());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the maximum length of a text cell
|
* @return the maximum length of a text cell
|
||||||
@ -127,5 +133,4 @@ public enum SpreadsheetVersion {
|
|||||||
public int getMaxTextLength() {
|
public int getMaxTextLength() {
|
||||||
return _maxTextLength;
|
return _maxTextLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,7 @@ import org.apache.poi.ss.formula.eval.NumberEval;
|
|||||||
import org.apache.poi.ss.formula.eval.OperandResolver;
|
import org.apache.poi.ss.formula.eval.OperandResolver;
|
||||||
import org.apache.poi.ss.formula.eval.StringEval;
|
import org.apache.poi.ss.formula.eval.StringEval;
|
||||||
import org.apache.poi.ss.formula.eval.ValueEval;
|
import org.apache.poi.ss.formula.eval.ValueEval;
|
||||||
|
import org.apache.poi.ss.formula.function.FunctionMetadataRegistry;
|
||||||
import org.apache.poi.ss.formula.functions.Choose;
|
import org.apache.poi.ss.formula.functions.Choose;
|
||||||
import org.apache.poi.ss.formula.functions.FreeRefFunction;
|
import org.apache.poi.ss.formula.functions.FreeRefFunction;
|
||||||
import org.apache.poi.ss.formula.functions.Function;
|
import org.apache.poi.ss.formula.functions.Function;
|
||||||
@ -486,12 +487,15 @@ public final class WorkbookEvaluator {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (evaluatedPredicate) {
|
if (evaluatedPredicate) {
|
||||||
// nothing to skip - true param folows
|
// nothing to skip - true param follows
|
||||||
} else {
|
} else {
|
||||||
int dist = attrPtg.getData();
|
int dist = attrPtg.getData();
|
||||||
i+= countTokensToBeSkipped(ptgs, i, dist);
|
i+= countTokensToBeSkipped(ptgs, i, dist);
|
||||||
Ptg nextPtg = ptgs[i+1];
|
Ptg nextPtg = ptgs[i+1];
|
||||||
if (ptgs[i] instanceof AttrPtg && nextPtg instanceof FuncVarPtg) {
|
if (ptgs[i] instanceof AttrPtg && nextPtg instanceof FuncVarPtg &&
|
||||||
|
// in order to verify that there is no third param, we need to check
|
||||||
|
// if we really have the IF next or some other FuncVarPtg as third param, e.g. ROW()/COLUMN()!
|
||||||
|
((FuncVarPtg)nextPtg).getFunctionIndex() == FunctionMetadataRegistry.FUNCTION_INDEX_IF) {
|
||||||
// this is an if statement without a false param (as opposed to MissingArgPtg as the false param)
|
// this is an if statement without a false param (as opposed to MissingArgPtg as the false param)
|
||||||
i++;
|
i++;
|
||||||
stack.push(BoolEval.FALSE);
|
stack.push(BoolEval.FALSE);
|
||||||
|
@ -106,89 +106,4 @@ public class ArrayUtil
|
|||||||
// We're done - array will now have everything moved as required
|
// We're done - array will now have everything moved as required
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Copies the specified array, truncating or padding with zeros (if
|
|
||||||
* necessary) so the copy has the specified length. This method is temporary
|
|
||||||
* replace for Arrays.copyOf() until we start to require JDK 1.6.
|
|
||||||
*
|
|
||||||
* @param source
|
|
||||||
* the array to be copied
|
|
||||||
* @param newLength
|
|
||||||
* the length of the copy to be returned
|
|
||||||
* @return a copy of the original array, truncated or padded with zeros to
|
|
||||||
* obtain the specified length
|
|
||||||
* @throws NegativeArraySizeException
|
|
||||||
* if <tt>newLength</tt> is negative
|
|
||||||
* @throws NullPointerException
|
|
||||||
* if <tt>original</tt> is null
|
|
||||||
*/
|
|
||||||
public static byte[] copyOf( byte[] source, int newLength )
|
|
||||||
{
|
|
||||||
byte[] result = new byte[newLength];
|
|
||||||
System.arraycopy( source, 0, result, 0,
|
|
||||||
Math.min( source.length, newLength ) );
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Copies the specified array into specified result array, truncating or
|
|
||||||
* padding with zeros (if necessary) so the copy has the specified length.
|
|
||||||
* This method is temporary replace for Arrays.copyOf() until we start to
|
|
||||||
* require JDK 1.6.
|
|
||||||
*
|
|
||||||
* @param source
|
|
||||||
* the array to be copied
|
|
||||||
* @param result
|
|
||||||
* the array to be filled and returned
|
|
||||||
* @throws NegativeArraySizeException
|
|
||||||
* if <tt>newLength</tt> is negative
|
|
||||||
* @throws NullPointerException
|
|
||||||
* if <tt>original</tt> is null
|
|
||||||
*/
|
|
||||||
public static <T> T[] copyOf( T[] source, T[] result )
|
|
||||||
{
|
|
||||||
System.arraycopy( source, 0, result, 0,
|
|
||||||
Math.min( source.length, result.length ) );
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Copies the specified range of the specified array into a new array.
|
|
||||||
* The initial index of the range (<tt>from</tt>) must lie between zero
|
|
||||||
* and <tt>original.length</tt>, inclusive. The value at
|
|
||||||
* <tt>original[from]</tt> is placed into the initial element of the copy
|
|
||||||
* (unless <tt>from == original.length</tt> or <tt>from == to</tt>).
|
|
||||||
* Values from subsequent elements in the original array are placed into
|
|
||||||
* subsequent elements in the copy. The final index of the range
|
|
||||||
* (<tt>to</tt>), which must be greater than or equal to <tt>from</tt>,
|
|
||||||
* may be greater than <tt>original.length</tt>, in which case
|
|
||||||
* <tt>(byte)0</tt> is placed in all elements of the copy whose index is
|
|
||||||
* greater than or equal to <tt>original.length - from</tt>. The length
|
|
||||||
* of the returned array will be <tt>to - from</tt>.
|
|
||||||
*
|
|
||||||
* This method is temporary
|
|
||||||
* replace for Arrays.copyOfRange() until we start to require JDK 1.6.
|
|
||||||
*
|
|
||||||
* @param original the array from which a range is to be copied
|
|
||||||
* @param from the initial index of the range to be copied, inclusive
|
|
||||||
* @param to the final index of the range to be copied, exclusive.
|
|
||||||
* (This index may lie outside the array.)
|
|
||||||
* @return a new array containing the specified range from the original array,
|
|
||||||
* truncated or padded with zeros to obtain the required length
|
|
||||||
* @throws ArrayIndexOutOfBoundsException if <tt>from < 0</tt>
|
|
||||||
* or <tt>from > original.length()</tt>
|
|
||||||
* @throws IllegalArgumentException if <tt>from > to</tt>
|
|
||||||
* @throws NullPointerException if <tt>original</tt> is null
|
|
||||||
* @since 1.6
|
|
||||||
*/
|
|
||||||
public static byte[] copyOfRange(byte[] original, int from, int to) {
|
|
||||||
int newLength = to - from;
|
|
||||||
if (newLength < 0)
|
|
||||||
throw new IllegalArgumentException(from + " > " + to);
|
|
||||||
byte[] copy = new byte[newLength];
|
|
||||||
System.arraycopy(original, from, copy, 0,
|
|
||||||
Math.min(original.length - from, newLength));
|
|
||||||
return copy;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,6 @@ package org.apache.poi.util;
|
|||||||
|
|
||||||
import javax.xml.XMLConstants;
|
import javax.xml.XMLConstants;
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper methods for working with javax.xml classes.
|
* Helper methods for working with javax.xml classes.
|
||||||
@ -27,22 +26,31 @@ import javax.xml.parsers.ParserConfigurationException;
|
|||||||
*/
|
*/
|
||||||
public final class XMLHelper
|
public final class XMLHelper
|
||||||
{
|
{
|
||||||
|
private static POILogger logger = POILogFactory.getLogger(XMLHelper.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new DocumentBuilderFactory, with sensible defaults
|
* Creates a new DocumentBuilderFactory, with sensible defaults
|
||||||
*/
|
*/
|
||||||
public static DocumentBuilderFactory getDocumentBuilderFactory() {
|
public static DocumentBuilderFactory getDocumentBuilderFactory() {
|
||||||
|
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||||
|
factory.setExpandEntityReferences(false);
|
||||||
|
trySetSAXFeature(factory, XMLConstants.FEATURE_SECURE_PROCESSING, true);
|
||||||
|
trySetSAXFeature(factory, "http://xml.org/sax/features/external-general-entities", false);
|
||||||
|
trySetSAXFeature(factory, "http://xml.org/sax/features/external-parameter-entities", false);
|
||||||
|
trySetSAXFeature(factory, "http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
|
||||||
|
trySetSAXFeature(factory, "http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false);
|
||||||
|
return factory;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void trySetSAXFeature(DocumentBuilderFactory documentBuilderFactory, String feature, boolean enabled) {
|
||||||
try {
|
try {
|
||||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
documentBuilderFactory.setFeature(feature, enabled);
|
||||||
factory.setXIncludeAware(false);
|
} catch (Exception e) {
|
||||||
factory.setExpandEntityReferences(false);
|
logger.log(POILogger.WARN, "SAX Feature unsupported", feature, e);
|
||||||
factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
|
} catch (AbstractMethodError ame) {
|
||||||
factory.setFeature("http://xml.org/sax/features/external-general-entities", false);
|
logger.log(POILogger.WARN, "Cannot set SAX feature because outdated XML parser in classpath", feature, ame);
|
||||||
factory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
|
|
||||||
factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
|
|
||||||
factory.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false);
|
|
||||||
return factory;
|
|
||||||
} catch (ParserConfigurationException e) {
|
|
||||||
throw new RuntimeException("Broken XML Setup", e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -285,6 +285,117 @@ public class POIXMLProperties {
|
|||||||
public org.openxmlformats.schemas.officeDocument.x2006.extendedProperties.CTProperties getUnderlyingProperties() {
|
public org.openxmlformats.schemas.officeDocument.x2006.extendedProperties.CTProperties getUnderlyingProperties() {
|
||||||
return props.getProperties();
|
return props.getProperties();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getTemplate() {
|
||||||
|
if (props.getProperties().isSetTemplate()) {
|
||||||
|
return props.getProperties().getTemplate();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public String getManager() {
|
||||||
|
if (props.getProperties().isSetManager()) {
|
||||||
|
return props.getProperties().getManager();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public String getCompany() {
|
||||||
|
if (props.getProperties().isSetCompany()) {
|
||||||
|
return props.getProperties().getCompany();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public String getPresentationFormat() {
|
||||||
|
if (props.getProperties().isSetPresentationFormat()) {
|
||||||
|
return props.getProperties().getPresentationFormat();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public String getApplication() {
|
||||||
|
if (props.getProperties().isSetApplication()) {
|
||||||
|
return props.getProperties().getApplication();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public String getAppVersion() {
|
||||||
|
if (props.getProperties().isSetAppVersion()) {
|
||||||
|
return props.getProperties().getAppVersion();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPages() {
|
||||||
|
if (props.getProperties().isSetPages()) {
|
||||||
|
return props.getProperties().getPages();
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
public int getWords() {
|
||||||
|
if (props.getProperties().isSetWords()) {
|
||||||
|
return props.getProperties().getWords();
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
public int getCharacters() {
|
||||||
|
if (props.getProperties().isSetCharacters()) {
|
||||||
|
return props.getProperties().getCharacters();
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
public int getCharactersWithSpaces() {
|
||||||
|
if (props.getProperties().isSetCharactersWithSpaces()) {
|
||||||
|
return props.getProperties().getCharactersWithSpaces();
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
public int getLines() {
|
||||||
|
if (props.getProperties().isSetLines()) {
|
||||||
|
return props.getProperties().getLines();
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
public int getParagraphs() {
|
||||||
|
if (props.getProperties().isSetParagraphs()) {
|
||||||
|
return props.getProperties().getParagraphs();
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
public int getSlides() {
|
||||||
|
if (props.getProperties().isSetSlides()) {
|
||||||
|
return props.getProperties().getSlides();
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
public int getNotes() {
|
||||||
|
if (props.getProperties().isSetNotes()) {
|
||||||
|
return props.getProperties().getNotes();
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
public int getTotalTime() {
|
||||||
|
if (props.getProperties().isSetTotalTime()) {
|
||||||
|
return props.getProperties().getTotalTime();
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
public int getHiddenSlides() {
|
||||||
|
if (props.getProperties().isSetHiddenSlides()) {
|
||||||
|
return props.getProperties().getHiddenSlides();
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
public int getMMClips() {
|
||||||
|
if (props.getProperties().isSetMMClips()) {
|
||||||
|
return props.getProperties().getMMClips();
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getHyperlinkBase() {
|
||||||
|
if (props.getProperties().isSetHyperlinkBase()) {
|
||||||
|
return props.getProperties().getHyperlinkBase();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -371,25 +482,46 @@ public class POIXMLProperties {
|
|||||||
*
|
*
|
||||||
* @return next property id starting with 2
|
* @return next property id starting with 2
|
||||||
*/
|
*/
|
||||||
protected int nextPid(){
|
@SuppressWarnings("deprecation")
|
||||||
|
protected int nextPid(){
|
||||||
int propid = 1;
|
int propid = 1;
|
||||||
for(CTProperty p : props.getProperties().getPropertyList()){
|
for(CTProperty p : props.getProperties().getPropertyArray()){
|
||||||
if(p.getPid() > propid) propid = p.getPid();
|
if(p.getPid() > propid) propid = p.getPid();
|
||||||
}
|
}
|
||||||
return propid + 1;
|
return propid + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if a property with this name already exists in the collection of custom properties
|
* Check if a property with this name already exists in the collection of custom properties
|
||||||
*
|
*
|
||||||
* @param name the name to check
|
* @param name the name to check
|
||||||
* @return whether a property with the given name exists in the custom properties
|
* @return whether a property with the given name exists in the custom properties
|
||||||
*/
|
*/
|
||||||
public boolean contains(String name){
|
@SuppressWarnings("deprecation")
|
||||||
for(CTProperty p : props.getProperties().getPropertyList()){
|
public boolean contains(String name) {
|
||||||
if(p.getName().equals(name)) return true;
|
for(CTProperty p : props.getProperties().getPropertyArray()){
|
||||||
}
|
if(p.getName().equals(name)) return true;
|
||||||
return false;
|
}
|
||||||
}
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the custom property with this name, or null if none exists.
|
||||||
|
*
|
||||||
|
* You will need to test the various isSetX methods to work out
|
||||||
|
* what the type of the property is, before fetching the
|
||||||
|
* appropriate value for it.
|
||||||
|
*
|
||||||
|
* @param name the name of the property to fetch
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public CTProperty getProperty(String name) {
|
||||||
|
for(CTProperty p : props.getProperties().getPropertyArray()){
|
||||||
|
if(p.getName().equals(name)) {
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,6 @@ package org.apache.poi;
|
|||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.apache.poi.openxml4j.opc.internal.PackagePropertiesPart;
|
import org.apache.poi.openxml4j.opc.internal.PackagePropertiesPart;
|
||||||
import org.openxmlformats.schemas.officeDocument.x2006.customProperties.CTProperty;
|
import org.openxmlformats.schemas.officeDocument.x2006.customProperties.CTProperty;
|
||||||
@ -126,13 +125,13 @@ public class POIXMLPropertiesTextExtractor extends POIXMLTextExtractor {
|
|||||||
* Returns the custom document properties, if
|
* Returns the custom document properties, if
|
||||||
* there are any
|
* there are any
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public String getCustomPropertiesText() {
|
public String getCustomPropertiesText() {
|
||||||
StringBuffer text = new StringBuffer();
|
StringBuilder text = new StringBuilder();
|
||||||
org.openxmlformats.schemas.officeDocument.x2006.customProperties.CTProperties
|
org.openxmlformats.schemas.officeDocument.x2006.customProperties.CTProperties
|
||||||
props = getDocument().getProperties().getCustomProperties().getUnderlyingProperties();
|
props = getDocument().getProperties().getCustomProperties().getUnderlyingProperties();
|
||||||
|
|
||||||
List<CTProperty> properties = props.getPropertyList();
|
for(CTProperty property : props.getPropertyArray()) {
|
||||||
for(CTProperty property : properties) {
|
|
||||||
String val = "(not implemented!)";
|
String val = "(not implemented!)";
|
||||||
|
|
||||||
if (property.isSetLpwstr()) {
|
if (property.isSetLpwstr()) {
|
||||||
|
@ -24,9 +24,9 @@ import java.util.TreeMap;
|
|||||||
|
|
||||||
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
||||||
import org.apache.poi.openxml4j.exceptions.InvalidOperationException;
|
import org.apache.poi.openxml4j.exceptions.InvalidOperationException;
|
||||||
|
import org.apache.poi.util.DocumentHelper;
|
||||||
import org.apache.poi.util.POILogFactory;
|
import org.apache.poi.util.POILogFactory;
|
||||||
import org.apache.poi.util.POILogger;
|
import org.apache.poi.util.POILogger;
|
||||||
import org.apache.poi.util.SAXHelper;
|
|
||||||
import org.w3c.dom.Attr;
|
import org.w3c.dom.Attr;
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
@ -311,7 +311,7 @@ public final class PackageRelationshipCollection implements
|
|||||||
throws InvalidFormatException {
|
throws InvalidFormatException {
|
||||||
try {
|
try {
|
||||||
logger.log(POILogger.DEBUG, "Parsing relationship: " + relPart.getPartName());
|
logger.log(POILogger.DEBUG, "Parsing relationship: " + relPart.getPartName());
|
||||||
Document xmlRelationshipsDoc = SAXHelper.readSAXDocument(relPart.getInputStream());
|
Document xmlRelationshipsDoc = DocumentHelper.readDocument(relPart.getInputStream());
|
||||||
|
|
||||||
// Browse default types
|
// Browse default types
|
||||||
Element root = xmlRelationshipsDoc.getDocumentElement();
|
Element root = xmlRelationshipsDoc.getDocumentElement();
|
||||||
|
@ -33,7 +33,6 @@ import org.apache.poi.openxml4j.opc.PackagePart;
|
|||||||
import org.apache.poi.openxml4j.opc.PackagePartName;
|
import org.apache.poi.openxml4j.opc.PackagePartName;
|
||||||
import org.apache.poi.openxml4j.opc.PackagingURIHelper;
|
import org.apache.poi.openxml4j.opc.PackagingURIHelper;
|
||||||
import org.apache.poi.util.DocumentHelper;
|
import org.apache.poi.util.DocumentHelper;
|
||||||
import org.apache.poi.util.SAXHelper;
|
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
import org.w3c.dom.NodeList;
|
import org.w3c.dom.NodeList;
|
||||||
@ -370,7 +369,7 @@ public abstract class ContentTypeManager {
|
|||||||
private void parseContentTypesFile(InputStream in)
|
private void parseContentTypesFile(InputStream in)
|
||||||
throws InvalidFormatException {
|
throws InvalidFormatException {
|
||||||
try {
|
try {
|
||||||
Document xmlContentTypetDoc = SAXHelper.readSAXDocument(in);
|
Document xmlContentTypetDoc = DocumentHelper.readDocument(in);
|
||||||
|
|
||||||
// Default content types
|
// Default content types
|
||||||
NodeList defaultTypes = xmlContentTypetDoc.getDocumentElement().getElementsByTagName(DEFAULT_TAG_NAME);
|
NodeList defaultTypes = xmlContentTypetDoc.getDocumentElement().getElementsByTagName(DEFAULT_TAG_NAME);
|
||||||
|
@ -31,7 +31,7 @@ import org.apache.poi.openxml4j.opc.ZipPackage;
|
|||||||
import org.apache.poi.openxml4j.opc.internal.PackagePropertiesPart;
|
import org.apache.poi.openxml4j.opc.internal.PackagePropertiesPart;
|
||||||
import org.apache.poi.openxml4j.opc.internal.PartUnmarshaller;
|
import org.apache.poi.openxml4j.opc.internal.PartUnmarshaller;
|
||||||
import org.apache.poi.openxml4j.opc.internal.ZipHelper;
|
import org.apache.poi.openxml4j.opc.internal.ZipHelper;
|
||||||
import org.apache.poi.util.SAXHelper;
|
import org.apache.poi.util.DocumentHelper;
|
||||||
import org.w3c.dom.Attr;
|
import org.w3c.dom.Attr;
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
@ -105,7 +105,7 @@ public final class PackagePropertiesUnmarshaller implements PartUnmarshaller {
|
|||||||
|
|
||||||
Document xmlDoc;
|
Document xmlDoc;
|
||||||
try {
|
try {
|
||||||
xmlDoc = SAXHelper.readSAXDocument(in);
|
xmlDoc = DocumentHelper.readDocument(in);
|
||||||
|
|
||||||
/* Check OPC compliance */
|
/* Check OPC compliance */
|
||||||
|
|
||||||
|
@ -57,9 +57,9 @@ import org.apache.poi.poifs.crypt.HashAlgorithm;
|
|||||||
import org.apache.poi.poifs.crypt.dsig.services.RelationshipTransformService;
|
import org.apache.poi.poifs.crypt.dsig.services.RelationshipTransformService;
|
||||||
import org.apache.poi.poifs.crypt.dsig.services.XmlSignatureService;
|
import org.apache.poi.poifs.crypt.dsig.services.XmlSignatureService;
|
||||||
import org.apache.poi.poifs.crypt.dsig.spi.DigestInfo;
|
import org.apache.poi.poifs.crypt.dsig.spi.DigestInfo;
|
||||||
|
import org.apache.poi.util.DocumentHelper;
|
||||||
import org.apache.poi.util.POILogFactory;
|
import org.apache.poi.util.POILogFactory;
|
||||||
import org.apache.poi.util.POILogger;
|
import org.apache.poi.util.POILogger;
|
||||||
import org.apache.poi.util.SAXHelper;
|
|
||||||
import org.apache.xml.security.Init;
|
import org.apache.xml.security.Init;
|
||||||
import org.apache.xmlbeans.XmlCursor;
|
import org.apache.xmlbeans.XmlCursor;
|
||||||
import org.apache.xmlbeans.XmlException;
|
import org.apache.xmlbeans.XmlException;
|
||||||
@ -127,7 +127,7 @@ public class SignatureInfo {
|
|||||||
throws NoSuchAlgorithmException, IOException, MarshalException, ParserConfigurationException, XmlException {
|
throws NoSuchAlgorithmException, IOException, MarshalException, ParserConfigurationException, XmlException {
|
||||||
XmlSignatureService signatureService = createSignatureService(hashAlgo, pkg);
|
XmlSignatureService signatureService = createSignatureService(hashAlgo, pkg);
|
||||||
|
|
||||||
Document document = SAXHelper.getDocumentBuilder().newDocument();
|
Document document = DocumentHelper.createDocument();
|
||||||
|
|
||||||
// operate
|
// operate
|
||||||
List<X509Certificate> x509Chain = Collections.singletonList(x509);
|
List<X509Certificate> x509Chain = Collections.singletonList(x509);
|
||||||
@ -181,7 +181,7 @@ public class SignatureInfo {
|
|||||||
KeyInfoKeySelector keySelector = new KeyInfoKeySelector();
|
KeyInfoKeySelector keySelector = new KeyInfoKeySelector();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Document doc = SAXHelper.readSAXDocument(signaturePart.getInputStream());
|
Document doc = DocumentHelper.readDocument(signaturePart.getInputStream());
|
||||||
// dummy call to createSignatureService to tweak document afterwards
|
// dummy call to createSignatureService to tweak document afterwards
|
||||||
createSignatureService(HashAlgorithm.sha1, pkg).registerIds(doc);
|
createSignatureService(HashAlgorithm.sha1, pkg).registerIds(doc);
|
||||||
|
|
||||||
|
@ -17,6 +17,10 @@
|
|||||||
|
|
||||||
package org.apache.poi.util;
|
package org.apache.poi.util;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
import javax.xml.XMLConstants;
|
import javax.xml.XMLConstants;
|
||||||
import javax.xml.parsers.DocumentBuilder;
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
@ -25,20 +29,81 @@ import javax.xml.stream.events.Namespace;
|
|||||||
|
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
public class DocumentHelper {
|
public final class DocumentHelper {
|
||||||
|
private static POILogger logger = POILogFactory.getLogger(DocumentHelper.class);
|
||||||
|
|
||||||
|
private DocumentHelper() {}
|
||||||
|
|
||||||
private static final DocumentBuilder newDocumentBuilder;
|
/**
|
||||||
static {
|
* Creates a new document builder, with sensible defaults
|
||||||
|
*/
|
||||||
|
public static synchronized DocumentBuilder newDocumentBuilder() {
|
||||||
try {
|
try {
|
||||||
newDocumentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||||
|
documentBuilder.setEntityResolver(SAXHelper.IGNORING_ENTITY_RESOLVER);
|
||||||
|
return documentBuilder;
|
||||||
} catch (ParserConfigurationException e) {
|
} catch (ParserConfigurationException e) {
|
||||||
throw new IllegalStateException("cannot create a DocumentBuilder", e);
|
throw new IllegalStateException("cannot create a DocumentBuilder", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||||
|
static {
|
||||||
|
documentBuilderFactory.setNamespaceAware(true);
|
||||||
|
documentBuilderFactory.setValidating(false);
|
||||||
|
trySetSAXFeature(documentBuilderFactory, XMLConstants.FEATURE_SECURE_PROCESSING, true);
|
||||||
|
trySetXercesSecurityManager(documentBuilderFactory);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void trySetSAXFeature(DocumentBuilderFactory documentBuilderFactory, String feature, boolean enabled) {
|
||||||
|
try {
|
||||||
|
documentBuilderFactory.setFeature(feature, enabled);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.log(POILogger.WARN, "SAX Feature unsupported", feature, e);
|
||||||
|
} catch (AbstractMethodError ame) {
|
||||||
|
logger.log(POILogger.WARN, "Cannot set SAX feature because outdated XML parser in classpath", feature, ame);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void trySetXercesSecurityManager(DocumentBuilderFactory documentBuilderFactory) {
|
||||||
|
// Try built-in JVM one first, standalone if not
|
||||||
|
for (String securityManagerClassName : new String[] {
|
||||||
|
"com.sun.org.apache.xerces.internal.util.SecurityManager",
|
||||||
|
"org.apache.xerces.util.SecurityManager"
|
||||||
|
}) {
|
||||||
|
try {
|
||||||
|
Object mgr = Class.forName(securityManagerClassName).newInstance();
|
||||||
|
Method setLimit = mgr.getClass().getMethod("setEntityExpansionLimit", Integer.TYPE);
|
||||||
|
setLimit.invoke(mgr, 4096);
|
||||||
|
documentBuilderFactory.setAttribute("http://apache.org/xml/properties/security-manager", mgr);
|
||||||
|
// Stop once one can be setup without error
|
||||||
|
return;
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.log(POILogger.WARN, "SAX Security Manager could not be setup", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses the given stream via the default (sensible)
|
||||||
|
* DocumentBuilder
|
||||||
|
* @param inp Stream to read the XML data from
|
||||||
|
* @return the parsed Document
|
||||||
|
*/
|
||||||
|
public static Document readDocument(InputStream inp) throws IOException, SAXException {
|
||||||
|
return newDocumentBuilder().parse(inp);
|
||||||
|
}
|
||||||
|
|
||||||
|
// must only be used to create empty documents, do not use it for parsing!
|
||||||
|
private static final DocumentBuilder documentBuilderSingleton = newDocumentBuilder();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new DOM Document
|
||||||
|
*/
|
||||||
public static synchronized Document createDocument() {
|
public static synchronized Document createDocument() {
|
||||||
return newDocumentBuilder.newDocument();
|
return documentBuilderSingleton.newDocument();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -18,19 +18,17 @@
|
|||||||
package org.apache.poi.util;
|
package org.apache.poi.util;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
import javax.xml.XMLConstants;
|
import javax.xml.XMLConstants;
|
||||||
import javax.xml.parsers.DocumentBuilder;
|
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
import javax.xml.parsers.SAXParserFactory;
|
||||||
|
|
||||||
import org.w3c.dom.Document;
|
|
||||||
import org.xml.sax.EntityResolver;
|
import org.xml.sax.EntityResolver;
|
||||||
import org.xml.sax.InputSource;
|
import org.xml.sax.InputSource;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
import org.xml.sax.XMLReader;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -39,43 +37,45 @@ import org.xml.sax.SAXException;
|
|||||||
public final class SAXHelper {
|
public final class SAXHelper {
|
||||||
private static POILogger logger = POILogFactory.getLogger(SAXHelper.class);
|
private static POILogger logger = POILogFactory.getLogger(SAXHelper.class);
|
||||||
|
|
||||||
private static final EntityResolver IGNORING_ENTITY_RESOLVER = new EntityResolver() {
|
private SAXHelper() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new SAX XMLReader, with sensible defaults
|
||||||
|
*/
|
||||||
|
public static synchronized XMLReader newXMLReader() throws SAXException, ParserConfigurationException {
|
||||||
|
XMLReader xmlReader = saxFactory.newSAXParser().getXMLReader();
|
||||||
|
xmlReader.setEntityResolver(IGNORING_ENTITY_RESOLVER);
|
||||||
|
trySetSAXFeature(xmlReader, XMLConstants.FEATURE_SECURE_PROCESSING, true);
|
||||||
|
trySetXercesSecurityManager(xmlReader);
|
||||||
|
return xmlReader;
|
||||||
|
}
|
||||||
|
|
||||||
|
static final EntityResolver IGNORING_ENTITY_RESOLVER = new EntityResolver() {
|
||||||
@Override
|
@Override
|
||||||
public InputSource resolveEntity(String publicId, String systemId)
|
public InputSource resolveEntity(String publicId, String systemId)
|
||||||
throws SAXException, IOException {
|
throws SAXException, IOException {
|
||||||
return new InputSource(new StringReader(""));
|
return new InputSource(new StringReader(""));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private static final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
private static final SAXParserFactory saxFactory;
|
||||||
static {
|
static {
|
||||||
documentBuilderFactory.setNamespaceAware(true);
|
saxFactory = SAXParserFactory.newInstance();
|
||||||
documentBuilderFactory.setValidating(false);
|
saxFactory.setValidating(false);
|
||||||
trySetSAXFeature(documentBuilderFactory, XMLConstants.FEATURE_SECURE_PROCESSING, true);
|
saxFactory.setNamespaceAware(true);
|
||||||
trySetXercesSecurityManager(documentBuilderFactory);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private static void trySetSAXFeature(XMLReader xmlReader, String feature, boolean enabled) {
|
||||||
* Creates a new document builder, with sensible defaults
|
|
||||||
*/
|
|
||||||
public static synchronized DocumentBuilder getDocumentBuilder() {
|
|
||||||
try {
|
try {
|
||||||
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
xmlReader.setFeature(feature, enabled);
|
||||||
documentBuilder.setEntityResolver(IGNORING_ENTITY_RESOLVER);
|
|
||||||
return documentBuilder;
|
|
||||||
} catch (ParserConfigurationException e) {
|
|
||||||
throw new IllegalStateException("cannot create a DocumentBuilder", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void trySetSAXFeature(DocumentBuilderFactory documentBuilderFactory, String feature, boolean enabled) {
|
|
||||||
try {
|
|
||||||
documentBuilderFactory.setFeature(feature, enabled);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.log(POILogger.INFO, "SAX Feature unsupported", feature, e);
|
logger.log(POILogger.WARN, "SAX Feature unsupported", feature, e);
|
||||||
|
} catch (AbstractMethodError ame) {
|
||||||
|
logger.log(POILogger.WARN, "Cannot set SAX feature because outdated XML parser in classpath", feature, ame);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private static void trySetXercesSecurityManager(DocumentBuilderFactory documentBuilderFactory) {
|
|
||||||
|
private static void trySetXercesSecurityManager(XMLReader xmlReader) {
|
||||||
// Try built-in JVM one first, standalone if not
|
// Try built-in JVM one first, standalone if not
|
||||||
for (String securityManagerClassName : new String[] {
|
for (String securityManagerClassName : new String[] {
|
||||||
"com.sun.org.apache.xerces.internal.util.SecurityManager",
|
"com.sun.org.apache.xerces.internal.util.SecurityManager",
|
||||||
@ -85,22 +85,12 @@ public final class SAXHelper {
|
|||||||
Object mgr = Class.forName(securityManagerClassName).newInstance();
|
Object mgr = Class.forName(securityManagerClassName).newInstance();
|
||||||
Method setLimit = mgr.getClass().getMethod("setEntityExpansionLimit", Integer.TYPE);
|
Method setLimit = mgr.getClass().getMethod("setEntityExpansionLimit", Integer.TYPE);
|
||||||
setLimit.invoke(mgr, 4096);
|
setLimit.invoke(mgr, 4096);
|
||||||
documentBuilderFactory.setAttribute("http://apache.org/xml/properties/security-manager", mgr);
|
xmlReader.setProperty("http://apache.org/xml/properties/security-manager", mgr);
|
||||||
// Stop once one can be setup without error
|
// Stop once one can be setup without error
|
||||||
return;
|
return;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.log(POILogger.INFO, "SAX Security Manager could not be setup", e);
|
logger.log(POILogger.WARN, "SAX Security Manager could not be setup", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Parses the given stream via the default (sensible)
|
|
||||||
* SAX Reader
|
|
||||||
* @param inp Stream to read the XML data from
|
|
||||||
* @return the SAX processed Document
|
|
||||||
*/
|
|
||||||
public static Document readSAXDocument(InputStream inp) throws IOException, SAXException {
|
|
||||||
return getDocumentBuilder().parse(inp);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,20 @@ import org.apache.poi.util.Internal;
|
|||||||
import org.apache.poi.xslf.usermodel.XMLSlideShow;
|
import org.apache.poi.xslf.usermodel.XMLSlideShow;
|
||||||
import org.apache.poi.xslf.usermodel.XSLFRelation;
|
import org.apache.poi.xslf.usermodel.XSLFRelation;
|
||||||
import org.apache.xmlbeans.XmlException;
|
import org.apache.xmlbeans.XmlException;
|
||||||
import org.openxmlformats.schemas.presentationml.x2006.main.*;
|
import org.openxmlformats.schemas.presentationml.x2006.main.CTCommentList;
|
||||||
|
import org.openxmlformats.schemas.presentationml.x2006.main.CTNotesSlide;
|
||||||
|
import org.openxmlformats.schemas.presentationml.x2006.main.CTPresentation;
|
||||||
|
import org.openxmlformats.schemas.presentationml.x2006.main.CTSlide;
|
||||||
|
import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdList;
|
||||||
|
import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdListEntry;
|
||||||
|
import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideMaster;
|
||||||
|
import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideMasterIdList;
|
||||||
|
import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideMasterIdListEntry;
|
||||||
|
import org.openxmlformats.schemas.presentationml.x2006.main.CmLstDocument;
|
||||||
|
import org.openxmlformats.schemas.presentationml.x2006.main.NotesDocument;
|
||||||
|
import org.openxmlformats.schemas.presentationml.x2006.main.PresentationDocument;
|
||||||
|
import org.openxmlformats.schemas.presentationml.x2006.main.SldDocument;
|
||||||
|
import org.openxmlformats.schemas.presentationml.x2006.main.SldMasterDocument;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Experimental class to do low level processing of pptx files.
|
* Experimental class to do low level processing of pptx files.
|
||||||
@ -53,6 +66,7 @@ public class XSLFSlideShow extends POIXMLDocument {
|
|||||||
*/
|
*/
|
||||||
private List<PackagePart> embedds;
|
private List<PackagePart> embedds;
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public XSLFSlideShow(OPCPackage container) throws OpenXML4JException, IOException, XmlException {
|
public XSLFSlideShow(OPCPackage container) throws OpenXML4JException, IOException, XmlException {
|
||||||
super(container);
|
super(container);
|
||||||
|
|
||||||
@ -64,7 +78,7 @@ public class XSLFSlideShow extends POIXMLDocument {
|
|||||||
PresentationDocument.Factory.parse(getCorePart().getInputStream());
|
PresentationDocument.Factory.parse(getCorePart().getInputStream());
|
||||||
|
|
||||||
embedds = new LinkedList<PackagePart>();
|
embedds = new LinkedList<PackagePart>();
|
||||||
for (CTSlideIdListEntry ctSlide : getSlideReferences().getSldIdList()) {
|
for (CTSlideIdListEntry ctSlide : getSlideReferences().getSldIdArray()) {
|
||||||
PackagePart corePart = getCorePart();
|
PackagePart corePart = getCorePart();
|
||||||
PackagePart slidePart = corePart.getRelatedPart(
|
PackagePart slidePart = corePart.getRelatedPart(
|
||||||
corePart.getRelationship(ctSlide.getId2()));
|
corePart.getRelationship(ctSlide.getId2()));
|
||||||
|
@ -118,6 +118,7 @@ public class XSLFPowerPointExtractor extends POIXMLTextExtractor {
|
|||||||
* @param notesText Should we retrieve text from notes?
|
* @param notesText Should we retrieve text from notes?
|
||||||
* @param masterText Should we retrieve text from master slides?
|
* @param masterText Should we retrieve text from master slides?
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public String getText(boolean slideText, boolean notesText, boolean masterText) {
|
public String getText(boolean slideText, boolean notesText, boolean masterText) {
|
||||||
StringBuffer text = new StringBuffer();
|
StringBuffer text = new StringBuffer();
|
||||||
|
|
||||||
@ -150,7 +151,7 @@ public class XSLFPowerPointExtractor extends POIXMLTextExtractor {
|
|||||||
|
|
||||||
// If the slide has comments, do those too
|
// If the slide has comments, do those too
|
||||||
if (comments != null) {
|
if (comments != null) {
|
||||||
for (CTComment comment : comments.getCTCommentsList().getCmList()) {
|
for (CTComment comment : comments.getCTCommentsList().getCmArray()) {
|
||||||
// Do the author if we can
|
// Do the author if we can
|
||||||
if (commentAuthors != null) {
|
if (commentAuthors != null) {
|
||||||
CTCommentAuthor author = commentAuthors.getAuthorById(comment.getAuthorId());
|
CTCommentAuthor author = commentAuthors.getAuthorById(comment.getAuthorId());
|
||||||
|
@ -19,12 +19,17 @@
|
|||||||
|
|
||||||
package org.apache.poi.xslf.model.geom;
|
package org.apache.poi.xslf.model.geom;
|
||||||
|
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.*;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.main.CTCustomGeometry2D;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.main.CTGeomGuide;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.main.CTGeomGuideList;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.main.CTGeomRect;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.main.CTPath2D;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.main.CTPath2DList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Definition of a custom geometric shape
|
* Definition of a custom geometric shape
|
||||||
*
|
*
|
||||||
@ -36,19 +41,20 @@ public class CustomGeometry implements Iterable<Path>{
|
|||||||
List<Path> paths = new ArrayList<Path>();
|
List<Path> paths = new ArrayList<Path>();
|
||||||
Path textBounds;
|
Path textBounds;
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public CustomGeometry(CTCustomGeometry2D geom) {
|
public CustomGeometry(CTCustomGeometry2D geom) {
|
||||||
CTGeomGuideList avLst = geom.getAvLst();
|
CTGeomGuideList avLst = geom.getAvLst();
|
||||||
if(avLst != null) for(CTGeomGuide gd : avLst.getGdList()){
|
if(avLst != null) for(CTGeomGuide gd : avLst.getGdArray()){
|
||||||
adjusts.add(new AdjustValue(gd));
|
adjusts.add(new AdjustValue(gd));
|
||||||
}
|
}
|
||||||
|
|
||||||
CTGeomGuideList gdLst = geom.getGdLst();
|
CTGeomGuideList gdLst = geom.getGdLst();
|
||||||
if(gdLst != null) for(CTGeomGuide gd : gdLst.getGdList()){
|
if(gdLst != null) for(CTGeomGuide gd : gdLst.getGdArray()){
|
||||||
guides.add(new Guide(gd));
|
guides.add(new Guide(gd));
|
||||||
}
|
}
|
||||||
|
|
||||||
CTPath2DList pathLst = geom.getPathLst();
|
CTPath2DList pathLst = geom.getPathLst();
|
||||||
if(pathLst != null) for(CTPath2D spPath : pathLst.getPathList()){
|
if(pathLst != null) for(CTPath2D spPath : pathLst.getPathArray()){
|
||||||
paths.add(new Path(spPath));
|
paths.add(new Path(spPath));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,8 +20,6 @@ package org.apache.poi.xslf.usermodel;
|
|||||||
import org.openxmlformats.schemas.drawingml.x2006.main.CTTable;
|
import org.openxmlformats.schemas.drawingml.x2006.main.CTTable;
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.CTTableRow;
|
import org.openxmlformats.schemas.drawingml.x2006.main.CTTableRow;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class DrawingTable {
|
public class DrawingTable {
|
||||||
private final CTTable table;
|
private final CTTable table;
|
||||||
|
|
||||||
@ -29,12 +27,13 @@ public class DrawingTable {
|
|||||||
this.table = table;
|
this.table = table;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public DrawingTableRow[] getRows() {
|
public DrawingTableRow[] getRows() {
|
||||||
List<CTTableRow> ctTableRows = table.getTrList();
|
CTTableRow[] ctTableRows = table.getTrArray();
|
||||||
DrawingTableRow[] o = new DrawingTableRow[ctTableRows.size()];
|
DrawingTableRow[] o = new DrawingTableRow[ctTableRows.length];
|
||||||
|
|
||||||
for (int i=0; i<o.length; i++) {
|
for (int i=0; i<o.length; i++) {
|
||||||
o[i] = new DrawingTableRow(ctTableRows.get(i));
|
o[i] = new DrawingTableRow(ctTableRows[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return o;
|
return o;
|
||||||
|
@ -20,8 +20,6 @@ package org.apache.poi.xslf.usermodel;
|
|||||||
import org.openxmlformats.schemas.drawingml.x2006.main.CTTableCell;
|
import org.openxmlformats.schemas.drawingml.x2006.main.CTTableCell;
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.CTTableRow;
|
import org.openxmlformats.schemas.drawingml.x2006.main.CTTableRow;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class DrawingTableRow {
|
public class DrawingTableRow {
|
||||||
private final CTTableRow row;
|
private final CTTableRow row;
|
||||||
|
|
||||||
@ -29,12 +27,13 @@ public class DrawingTableRow {
|
|||||||
this.row = row;
|
this.row = row;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public DrawingTableCell[] getCells() {
|
public DrawingTableCell[] getCells() {
|
||||||
List<CTTableCell> ctTableCells = row.getTcList();
|
CTTableCell[] ctTableCells = row.getTcArray();
|
||||||
DrawingTableCell[] o = new DrawingTableCell[ctTableCells.size()];
|
DrawingTableCell[] o = new DrawingTableCell[ctTableCells.length];
|
||||||
|
|
||||||
for (int i=0; i<o.length; i++) {
|
for (int i=0; i<o.length; i++) {
|
||||||
o[i] = new DrawingTableCell(ctTableCells.get(i));
|
o[i] = new DrawingTableCell(ctTableCells[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return o;
|
return o;
|
||||||
|
@ -20,8 +20,6 @@ package org.apache.poi.xslf.usermodel;
|
|||||||
import org.openxmlformats.schemas.drawingml.x2006.main.CTTextBody;
|
import org.openxmlformats.schemas.drawingml.x2006.main.CTTextBody;
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraph;
|
import org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraph;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class DrawingTextBody {
|
public class DrawingTextBody {
|
||||||
private final CTTextBody textBody;
|
private final CTTextBody textBody;
|
||||||
|
|
||||||
@ -29,12 +27,13 @@ public class DrawingTextBody {
|
|||||||
this.textBody = textBody;
|
this.textBody = textBody;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public DrawingParagraph[] getParagraphs() {
|
public DrawingParagraph[] getParagraphs() {
|
||||||
List<CTTextParagraph> paragraphs = textBody.getPList();
|
CTTextParagraph[] paragraphs = textBody.getPArray();
|
||||||
DrawingParagraph[] o = new DrawingParagraph[paragraphs.size()];
|
DrawingParagraph[] o = new DrawingParagraph[paragraphs.length];
|
||||||
|
|
||||||
for (int i=0; i<o.length; i++) {
|
for (int i=0; i<o.length; i++) {
|
||||||
o[i] = new DrawingParagraph(paragraphs.get(i));
|
o[i] = new DrawingParagraph(paragraphs[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return o;
|
return o;
|
||||||
|
@ -19,6 +19,25 @@
|
|||||||
|
|
||||||
package org.apache.poi.xslf.usermodel;
|
package org.apache.poi.xslf.usermodel;
|
||||||
|
|
||||||
|
import java.awt.AlphaComposite;
|
||||||
|
import java.awt.BasicStroke;
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.GradientPaint;
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.Paint;
|
||||||
|
import java.awt.Shape;
|
||||||
|
import java.awt.Stroke;
|
||||||
|
import java.awt.TexturePaint;
|
||||||
|
import java.awt.geom.AffineTransform;
|
||||||
|
import java.awt.geom.Point2D;
|
||||||
|
import java.awt.geom.Rectangle2D;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Comparator;
|
||||||
|
|
||||||
import org.apache.poi.openxml4j.opc.PackagePart;
|
import org.apache.poi.openxml4j.opc.PackagePart;
|
||||||
import org.apache.poi.openxml4j.opc.PackageRelationship;
|
import org.apache.poi.openxml4j.opc.PackageRelationship;
|
||||||
import org.apache.poi.util.Internal;
|
import org.apache.poi.util.Internal;
|
||||||
@ -47,25 +66,6 @@ import org.openxmlformats.schemas.drawingml.x2006.main.CTSolidColorFillPropertie
|
|||||||
import org.openxmlformats.schemas.drawingml.x2006.main.CTStyleMatrixReference;
|
import org.openxmlformats.schemas.drawingml.x2006.main.CTStyleMatrixReference;
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.STPathShadeType;
|
import org.openxmlformats.schemas.drawingml.x2006.main.STPathShadeType;
|
||||||
|
|
||||||
import java.awt.AlphaComposite;
|
|
||||||
import java.awt.BasicStroke;
|
|
||||||
import java.awt.Color;
|
|
||||||
import java.awt.GradientPaint;
|
|
||||||
import java.awt.Graphics2D;
|
|
||||||
import java.awt.Paint;
|
|
||||||
import java.awt.Shape;
|
|
||||||
import java.awt.Stroke;
|
|
||||||
import java.awt.TexturePaint;
|
|
||||||
import java.awt.geom.AffineTransform;
|
|
||||||
import java.awt.geom.Point2D;
|
|
||||||
import java.awt.geom.Rectangle2D;
|
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
import java.lang.reflect.Constructor;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Comparator;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encapsulates logic to translate DrawingML objects to Java2D
|
* Encapsulates logic to translate DrawingML objects to Java2D
|
||||||
*/
|
*/
|
||||||
@ -548,6 +548,7 @@ class RenderableShape {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
private Collection<Outline> computeOutlines(Graphics2D graphics) {
|
private Collection<Outline> computeOutlines(Graphics2D graphics) {
|
||||||
|
|
||||||
Collection<Outline> lst = new ArrayList<Outline>();
|
Collection<Outline> lst = new ArrayList<Outline>();
|
||||||
@ -576,7 +577,7 @@ class RenderableShape {
|
|||||||
public Guide getAdjustValue(String name) {
|
public Guide getAdjustValue(String name) {
|
||||||
CTPresetGeometry2D prst = _shape.getSpPr().getPrstGeom();
|
CTPresetGeometry2D prst = _shape.getSpPr().getPrstGeom();
|
||||||
if (prst.isSetAvLst()) {
|
if (prst.isSetAvLst()) {
|
||||||
for (CTGeomGuide g : prst.getAvLst().getGdList()) {
|
for (CTGeomGuide g : prst.getAvLst().getGdArray()) {
|
||||||
if (g.getName().equals(name)) {
|
if (g.getName().equals(name)) {
|
||||||
return new Guide(g);
|
return new Guide(g);
|
||||||
}
|
}
|
||||||
|
@ -115,6 +115,7 @@ public class XMLSlideShow extends POIXMLDocument {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
protected void onDocumentRead() throws IOException {
|
protected void onDocumentRead() throws IOException {
|
||||||
try {
|
try {
|
||||||
PresentationDocument doc =
|
PresentationDocument doc =
|
||||||
@ -140,8 +141,7 @@ public class XMLSlideShow extends POIXMLDocument {
|
|||||||
|
|
||||||
_slides = new ArrayList<XSLFSlide>();
|
_slides = new ArrayList<XSLFSlide>();
|
||||||
if (_presentation.isSetSldIdLst()) {
|
if (_presentation.isSetSldIdLst()) {
|
||||||
List<CTSlideIdListEntry> slideIds = _presentation.getSldIdLst().getSldIdList();
|
for (CTSlideIdListEntry slId : _presentation.getSldIdLst().getSldIdArray()) {
|
||||||
for (CTSlideIdListEntry slId : slideIds) {
|
|
||||||
XSLFSlide sh = shIdMap.get(slId.getId2());
|
XSLFSlide sh = shIdMap.get(slId.getId2());
|
||||||
if (sh == null) {
|
if (sh == null) {
|
||||||
_logger.log(POILogger.WARN, "Slide with r:id " + slId.getId() + " was defined, but didn't exist in package, skipping");
|
_logger.log(POILogger.WARN, "Slide with r:id " + slId.getId() + " was defined, but didn't exist in package, skipping");
|
||||||
@ -201,13 +201,14 @@ public class XMLSlideShow extends POIXMLDocument {
|
|||||||
* @param layout
|
* @param layout
|
||||||
* @return created slide
|
* @return created slide
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public XSLFSlide createSlide(XSLFSlideLayout layout) {
|
public XSLFSlide createSlide(XSLFSlideLayout layout) {
|
||||||
int slideNumber = 256, cnt = 1;
|
int slideNumber = 256, cnt = 1;
|
||||||
CTSlideIdList slideList;
|
CTSlideIdList slideList;
|
||||||
if (!_presentation.isSetSldIdLst()) slideList = _presentation.addNewSldIdLst();
|
if (!_presentation.isSetSldIdLst()) slideList = _presentation.addNewSldIdLst();
|
||||||
else {
|
else {
|
||||||
slideList = _presentation.getSldIdLst();
|
slideList = _presentation.getSldIdLst();
|
||||||
for(CTSlideIdListEntry slideId : slideList.getSldIdList()){
|
for(CTSlideIdListEntry slideId : slideList.getSldIdArray()){
|
||||||
slideNumber = (int)Math.max(slideId.getId() + 1, slideNumber);
|
slideNumber = (int)Math.max(slideId.getId() + 1, slideNumber);
|
||||||
cnt++;
|
cnt++;
|
||||||
}
|
}
|
||||||
@ -283,16 +284,16 @@ public class XMLSlideShow extends POIXMLDocument {
|
|||||||
_slides.add(newIndex, _slides.remove(oldIndex));
|
_slides.add(newIndex, _slides.remove(oldIndex));
|
||||||
|
|
||||||
// fix ordering in the low-level xml
|
// fix ordering in the low-level xml
|
||||||
List<CTSlideIdListEntry> slideIds = _presentation.getSldIdLst().getSldIdList();
|
CTSlideIdList sldIdLst = _presentation.getSldIdLst();
|
||||||
CTSlideIdListEntry oldEntry = slideIds.get(oldIndex);
|
CTSlideIdListEntry oldEntry = sldIdLst.getSldIdArray(oldIndex);
|
||||||
slideIds.add(newIndex, oldEntry);
|
sldIdLst.insertNewSldId(newIndex).set(oldEntry);
|
||||||
slideIds.remove(oldEntry);
|
sldIdLst.removeSldId(oldIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
public XSLFSlide removeSlide(int index){
|
public XSLFSlide removeSlide(int index){
|
||||||
XSLFSlide slide = _slides.remove(index);
|
XSLFSlide slide = _slides.remove(index);
|
||||||
removeRelation(slide);
|
removeRelation(slide);
|
||||||
_presentation.getSldIdLst().getSldIdList().remove(index);
|
_presentation.getSldIdLst().removeSldId(index);
|
||||||
return slide;
|
return slide;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,6 +17,8 @@
|
|||||||
|
|
||||||
package org.apache.poi.xslf.usermodel;
|
package org.apache.poi.xslf.usermodel;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.apache.poi.POIXMLDocumentPart;
|
import org.apache.poi.POIXMLDocumentPart;
|
||||||
import org.apache.poi.openxml4j.opc.PackagePart;
|
import org.apache.poi.openxml4j.opc.PackagePart;
|
||||||
import org.apache.poi.openxml4j.opc.PackageRelationship;
|
import org.apache.poi.openxml4j.opc.PackageRelationship;
|
||||||
@ -26,8 +28,6 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTCommentAuthor;
|
|||||||
import org.openxmlformats.schemas.presentationml.x2006.main.CTCommentAuthorList;
|
import org.openxmlformats.schemas.presentationml.x2006.main.CTCommentAuthorList;
|
||||||
import org.openxmlformats.schemas.presentationml.x2006.main.CmAuthorLstDocument;
|
import org.openxmlformats.schemas.presentationml.x2006.main.CmAuthorLstDocument;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
@Beta
|
@Beta
|
||||||
public class XSLFCommentAuthors extends POIXMLDocumentPart {
|
public class XSLFCommentAuthors extends POIXMLDocumentPart {
|
||||||
private final CTCommentAuthorList _authors;
|
private final CTCommentAuthorList _authors;
|
||||||
@ -61,9 +61,10 @@ public class XSLFCommentAuthors extends POIXMLDocumentPart {
|
|||||||
return _authors;
|
return _authors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public CTCommentAuthor getAuthorById(long id) {
|
public CTCommentAuthor getAuthorById(long id) {
|
||||||
// TODO Have a map
|
// TODO Have a map
|
||||||
for (CTCommentAuthor author : _authors.getCmAuthorList()) {
|
for (CTCommentAuthor author : _authors.getCmAuthorArray()) {
|
||||||
if (author.getId() == id) {
|
if (author.getId() == id) {
|
||||||
return author;
|
return author;
|
||||||
}
|
}
|
||||||
|
@ -66,6 +66,6 @@ public class XSLFComments extends POIXMLDocumentPart {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public CTComment getCommentAt(int pos) {
|
public CTComment getCommentAt(int pos) {
|
||||||
return _comments.getCmList().get(pos);
|
return _comments.getCmArray(pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,10 @@
|
|||||||
|
|
||||||
package org.apache.poi.xslf.usermodel;
|
package org.apache.poi.xslf.usermodel;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.poi.POIXMLException;
|
import org.apache.poi.POIXMLException;
|
||||||
import org.apache.poi.util.Beta;
|
import org.apache.poi.util.Beta;
|
||||||
import org.apache.xmlbeans.XmlCursor;
|
import org.apache.xmlbeans.XmlCursor;
|
||||||
@ -32,10 +36,6 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFra
|
|||||||
import org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShape;
|
import org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShape;
|
||||||
import org.openxmlformats.schemas.presentationml.x2006.main.CTShape;
|
import org.openxmlformats.schemas.presentationml.x2006.main.CTShape;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Beta
|
@Beta
|
||||||
public class XSLFCommonSlideData {
|
public class XSLFCommonSlideData {
|
||||||
private final CTCommonSlideData data;
|
private final CTCommonSlideData data;
|
||||||
@ -44,6 +44,7 @@ public class XSLFCommonSlideData {
|
|||||||
this.data = data;
|
this.data = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public List<DrawingTextBody> getDrawingText() {
|
public List<DrawingTextBody> getDrawingText() {
|
||||||
CTGroupShape gs = data.getSpTree();
|
CTGroupShape gs = data.getSpTree();
|
||||||
|
|
||||||
@ -51,11 +52,11 @@ public class XSLFCommonSlideData {
|
|||||||
|
|
||||||
processShape(gs, out);
|
processShape(gs, out);
|
||||||
|
|
||||||
for (CTGroupShape shape : gs.getGrpSpList()) {
|
for (CTGroupShape shape : gs.getGrpSpArray()) {
|
||||||
processShape(shape, out);
|
processShape(shape, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (CTGraphicalObjectFrame frame: gs.getGraphicFrameList()) {
|
for (CTGraphicalObjectFrame frame: gs.getGraphicFrameArray()) {
|
||||||
CTGraphicalObjectData data = frame.getGraphic().getGraphicData();
|
CTGraphicalObjectData data = frame.getGraphic().getGraphicData();
|
||||||
XmlCursor c = data.newCursor();
|
XmlCursor c = data.newCursor();
|
||||||
c.selectPath("declare namespace pic='"+CTTable.type.getName().getNamespaceURI()+"' .//pic:tbl");
|
c.selectPath("declare namespace pic='"+CTTable.type.getName().getNamespaceURI()+"' .//pic:tbl");
|
||||||
@ -97,9 +98,9 @@ public class XSLFCommonSlideData {
|
|||||||
return paragraphs;
|
return paragraphs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
private void processShape(CTGroupShape gs, List<DrawingTextBody> out) {
|
private void processShape(CTGroupShape gs, List<DrawingTextBody> out) {
|
||||||
List<CTShape> shapes = gs.getSpList();
|
for (CTShape shape : gs.getSpArray()) {
|
||||||
for (CTShape shape : shapes) {
|
|
||||||
CTTextBody ctTextBody = shape.getTxBody();
|
CTTextBody ctTextBody = shape.getTxBody();
|
||||||
if (ctTextBody==null) {
|
if (ctTextBody==null) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -19,6 +19,11 @@
|
|||||||
|
|
||||||
package org.apache.poi.xslf.usermodel;
|
package org.apache.poi.xslf.usermodel;
|
||||||
|
|
||||||
|
import java.awt.geom.AffineTransform;
|
||||||
|
import java.awt.geom.GeneralPath;
|
||||||
|
import java.awt.geom.PathIterator;
|
||||||
|
import java.awt.geom.Rectangle2D;
|
||||||
|
|
||||||
import org.apache.poi.util.Beta;
|
import org.apache.poi.util.Beta;
|
||||||
import org.apache.poi.util.Units;
|
import org.apache.poi.util.Units;
|
||||||
import org.apache.xmlbeans.XmlObject;
|
import org.apache.xmlbeans.XmlObject;
|
||||||
@ -35,11 +40,6 @@ import org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties;
|
|||||||
import org.openxmlformats.schemas.presentationml.x2006.main.CTShape;
|
import org.openxmlformats.schemas.presentationml.x2006.main.CTShape;
|
||||||
import org.openxmlformats.schemas.presentationml.x2006.main.CTShapeNonVisual;
|
import org.openxmlformats.schemas.presentationml.x2006.main.CTShapeNonVisual;
|
||||||
|
|
||||||
import java.awt.geom.AffineTransform;
|
|
||||||
import java.awt.geom.GeneralPath;
|
|
||||||
import java.awt.geom.PathIterator;
|
|
||||||
import java.awt.geom.Rectangle2D;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a custom geometric shape.
|
* Represents a custom geometric shape.
|
||||||
* This shape will consist of a series of lines and curves described within a creation path.
|
* This shape will consist of a series of lines and curves described within a creation path.
|
||||||
@ -120,12 +120,13 @@ public class XSLFFreeformShape extends XSLFAutoShape {
|
|||||||
*
|
*
|
||||||
* @return the path
|
* @return the path
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public GeneralPath getPath() {
|
public GeneralPath getPath() {
|
||||||
GeneralPath path = new GeneralPath();
|
GeneralPath path = new GeneralPath();
|
||||||
Rectangle2D bounds = getAnchor();
|
Rectangle2D bounds = getAnchor();
|
||||||
|
|
||||||
CTCustomGeometry2D geom = getSpPr().getCustGeom();
|
CTCustomGeometry2D geom = getSpPr().getCustGeom();
|
||||||
for(CTPath2D spPath : geom.getPathLst().getPathList()){
|
for(CTPath2D spPath : geom.getPathLst().getPathArray()){
|
||||||
double scaleW = bounds.getWidth() / Units.toPoints(spPath.getW());
|
double scaleW = bounds.getWidth() / Units.toPoints(spPath.getW());
|
||||||
double scaleH = bounds.getHeight() / Units.toPoints(spPath.getH());
|
double scaleH = bounds.getHeight() / Units.toPoints(spPath.getH());
|
||||||
for(XmlObject ch : spPath.selectPath("*")){
|
for(XmlObject ch : spPath.selectPath("*")){
|
||||||
|
@ -213,7 +213,7 @@ public class XSLFPictureShape extends XSLFSimpleShape {
|
|||||||
if(blip.isSetExtLst()) {
|
if(blip.isSetExtLst()) {
|
||||||
|
|
||||||
CTOfficeArtExtensionList extLst = blip.getExtLst();
|
CTOfficeArtExtensionList extLst = blip.getExtLst();
|
||||||
for(CTOfficeArtExtension ext : extLst.getExtList()){
|
for(CTOfficeArtExtension ext : extLst.getExtArray()){
|
||||||
String xpath = "declare namespace a14='http://schemas.microsoft.com/office/drawing/2010/main' $this//a14:imgProps/a14:imgLayer";
|
String xpath = "declare namespace a14='http://schemas.microsoft.com/office/drawing/2010/main' $this//a14:imgProps/a14:imgLayer";
|
||||||
XmlObject[] obj = ext.selectPath(xpath);
|
XmlObject[] obj = ext.selectPath(xpath);
|
||||||
if(obj != null && obj.length == 1){
|
if(obj != null && obj.length == 1){
|
||||||
|
@ -51,6 +51,7 @@ public class XSLFTable extends XSLFGraphicFrame implements Iterable<XSLFTableRow
|
|||||||
private CTTable _table;
|
private CTTable _table;
|
||||||
private List<XSLFTableRow> _rows;
|
private List<XSLFTableRow> _rows;
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
/*package*/ XSLFTable(CTGraphicalObjectFrame shape, XSLFSheet sheet){
|
/*package*/ XSLFTable(CTGraphicalObjectFrame shape, XSLFSheet sheet){
|
||||||
super(shape, sheet);
|
super(shape, sheet);
|
||||||
|
|
||||||
@ -71,8 +72,9 @@ public class XSLFTable extends XSLFGraphicFrame implements Iterable<XSLFTableRow
|
|||||||
}
|
}
|
||||||
|
|
||||||
_table = (CTTable) rs[0];
|
_table = (CTTable) rs[0];
|
||||||
_rows = new ArrayList<XSLFTableRow>(_table.sizeOfTrArray());
|
CTTableRow[] trArray = _table.getTrArray();
|
||||||
for(CTTableRow row : _table.getTrList()) _rows.add(new XSLFTableRow(row, this));
|
_rows = new ArrayList<XSLFTableRow>(trArray.length);
|
||||||
|
for(CTTableRow row : trArray) _rows.add(new XSLFTableRow(row, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Internal
|
@Internal
|
||||||
|
@ -19,15 +19,15 @@
|
|||||||
|
|
||||||
package org.apache.poi.xslf.usermodel;
|
package org.apache.poi.xslf.usermodel;
|
||||||
|
|
||||||
import org.apache.poi.util.Units;
|
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.CTTableCell;
|
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.CTTableRow;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.poi.util.Units;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.main.CTTableCell;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.main.CTTableRow;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a table in a .pptx presentation
|
* Represents a table in a .pptx presentation
|
||||||
*
|
*
|
||||||
@ -38,11 +38,13 @@ public class XSLFTableRow implements Iterable<XSLFTableCell> {
|
|||||||
private List<XSLFTableCell> _cells;
|
private List<XSLFTableCell> _cells;
|
||||||
private XSLFTable _table;
|
private XSLFTable _table;
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
/*package*/ XSLFTableRow(CTTableRow row, XSLFTable table){
|
/*package*/ XSLFTableRow(CTTableRow row, XSLFTable table){
|
||||||
_row = row;
|
_row = row;
|
||||||
_table = table;
|
_table = table;
|
||||||
_cells = new ArrayList<XSLFTableCell>(_row.sizeOfTcArray());
|
CTTableCell[] tcArray = _row.getTcArray();
|
||||||
for(CTTableCell cell : _row.getTcList()) {
|
_cells = new ArrayList<XSLFTableCell>(tcArray.length);
|
||||||
|
for(CTTableCell cell : tcArray) {
|
||||||
_cells.add(new XSLFTableCell(cell, table.getSheet()));
|
_cells.add(new XSLFTableCell(cell, table.getSheet()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,12 @@
|
|||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.xslf.usermodel;
|
package org.apache.poi.xslf.usermodel;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.poi.POIXMLDocumentPart;
|
import org.apache.poi.POIXMLDocumentPart;
|
||||||
import org.apache.poi.openxml4j.opc.PackagePart;
|
import org.apache.poi.openxml4j.opc.PackagePart;
|
||||||
import org.apache.poi.openxml4j.opc.PackageRelationship;
|
import org.apache.poi.openxml4j.opc.PackageRelationship;
|
||||||
@ -24,12 +30,6 @@ import org.apache.xmlbeans.XmlException;
|
|||||||
import org.openxmlformats.schemas.drawingml.x2006.main.CTTableStyle;
|
import org.openxmlformats.schemas.drawingml.x2006.main.CTTableStyle;
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.CTTableStyleList;
|
import org.openxmlformats.schemas.drawingml.x2006.main.CTTableStyleList;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Beta
|
@Beta
|
||||||
public class XSLFTableStyles extends POIXMLDocumentPart implements Iterable<XSLFTableStyle>{
|
public class XSLFTableStyles extends POIXMLDocumentPart implements Iterable<XSLFTableStyle>{
|
||||||
private CTTableStyleList _tblStyleLst;
|
private CTTableStyleList _tblStyleLst;
|
||||||
@ -39,12 +39,14 @@ public class XSLFTableStyles extends POIXMLDocumentPart implements Iterable<XSLF
|
|||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public XSLFTableStyles(PackagePart part, PackageRelationship rel) throws IOException, XmlException {
|
public XSLFTableStyles(PackagePart part, PackageRelationship rel) throws IOException, XmlException {
|
||||||
super(part, rel);
|
super(part, rel);
|
||||||
|
|
||||||
_tblStyleLst = CTTableStyleList.Factory.parse(getPackagePart().getInputStream());
|
_tblStyleLst = CTTableStyleList.Factory.parse(getPackagePart().getInputStream());
|
||||||
_styles = new ArrayList<XSLFTableStyle>(_tblStyleLst.sizeOfTblStyleArray());
|
CTTableStyle[] tblStyleArray = _tblStyleLst.getTblStyleArray();
|
||||||
for(CTTableStyle c : _tblStyleLst.getTblStyleList()){
|
_styles = new ArrayList<XSLFTableStyle>(tblStyleArray.length);
|
||||||
|
for(CTTableStyle c : tblStyleArray){
|
||||||
_styles.add(new XSLFTableStyle(c));
|
_styles.add(new XSLFTableStyle(c));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,14 @@
|
|||||||
|
|
||||||
package org.apache.poi.xslf.usermodel;
|
package org.apache.poi.xslf.usermodel;
|
||||||
|
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.geom.AffineTransform;
|
||||||
|
import java.awt.geom.Rectangle2D;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.poi.POIXMLException;
|
import org.apache.poi.POIXMLException;
|
||||||
import org.apache.poi.util.Beta;
|
import org.apache.poi.util.Beta;
|
||||||
import org.apache.poi.util.Units;
|
import org.apache.poi.util.Units;
|
||||||
@ -36,14 +44,6 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTPlaceholder;
|
|||||||
import org.openxmlformats.schemas.presentationml.x2006.main.CTShape;
|
import org.openxmlformats.schemas.presentationml.x2006.main.CTShape;
|
||||||
import org.openxmlformats.schemas.presentationml.x2006.main.STPlaceholderType;
|
import org.openxmlformats.schemas.presentationml.x2006.main.STPlaceholderType;
|
||||||
|
|
||||||
import java.awt.Graphics2D;
|
|
||||||
import java.awt.geom.AffineTransform;
|
|
||||||
import java.awt.geom.Rectangle2D;
|
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a shape that can hold text.
|
* Represents a shape that can hold text.
|
||||||
*
|
*
|
||||||
@ -58,13 +58,14 @@ public abstract class XSLFTextShape extends XSLFSimpleShape implements Iterable<
|
|||||||
*/
|
*/
|
||||||
private boolean _isTextBroken;
|
private boolean _isTextBroken;
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
/*package*/ XSLFTextShape(XmlObject shape, XSLFSheet sheet) {
|
/*package*/ XSLFTextShape(XmlObject shape, XSLFSheet sheet) {
|
||||||
super(shape, sheet);
|
super(shape, sheet);
|
||||||
|
|
||||||
_paragraphs = new ArrayList<XSLFTextParagraph>();
|
_paragraphs = new ArrayList<XSLFTextParagraph>();
|
||||||
CTTextBody txBody = getTextBody(false);
|
CTTextBody txBody = getTextBody(false);
|
||||||
if (txBody != null) {
|
if (txBody != null) {
|
||||||
for (CTTextParagraph p : txBody.getPList()) {
|
for (CTTextParagraph p : txBody.getPArray()) {
|
||||||
_paragraphs.add(new XSLFTextParagraph(p, this));
|
_paragraphs.add(new XSLFTextParagraph(p, this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,12 +22,11 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
import javax.xml.parsers.SAXParser;
|
|
||||||
import javax.xml.parsers.SAXParserFactory;
|
|
||||||
|
|
||||||
import org.apache.poi.openxml4j.opc.OPCPackage;
|
import org.apache.poi.openxml4j.opc.OPCPackage;
|
||||||
import org.apache.poi.openxml4j.opc.PackagePart;
|
import org.apache.poi.openxml4j.opc.PackagePart;
|
||||||
import org.apache.poi.openxml4j.opc.PackageRelationship;
|
import org.apache.poi.openxml4j.opc.PackageRelationship;
|
||||||
|
import org.apache.poi.util.SAXHelper;
|
||||||
import org.apache.poi.xssf.usermodel.XSSFRelation;
|
import org.apache.poi.xssf.usermodel.XSSFRelation;
|
||||||
import org.xml.sax.Attributes;
|
import org.xml.sax.Attributes;
|
||||||
import org.xml.sax.InputSource;
|
import org.xml.sax.InputSource;
|
||||||
@ -134,10 +133,8 @@ public class ReadOnlySharedStringsTable extends DefaultHandler {
|
|||||||
*/
|
*/
|
||||||
public void readFrom(InputStream is) throws IOException, SAXException {
|
public void readFrom(InputStream is) throws IOException, SAXException {
|
||||||
InputSource sheetSource = new InputSource(is);
|
InputSource sheetSource = new InputSource(is);
|
||||||
SAXParserFactory saxFactory = SAXParserFactory.newInstance();
|
|
||||||
try {
|
try {
|
||||||
SAXParser saxParser = saxFactory.newSAXParser();
|
XMLReader sheetParser = SAXHelper.newXMLReader();
|
||||||
XMLReader sheetParser = saxParser.getXMLReader();
|
|
||||||
sheetParser.setContentHandler(this);
|
sheetParser.setContentHandler(this);
|
||||||
sheetParser.parse(sheetSource);
|
sheetParser.parse(sheetSource);
|
||||||
} catch(ParserConfigurationException e) {
|
} catch(ParserConfigurationException e) {
|
||||||
|
@ -18,7 +18,6 @@ package org.apache.poi.xssf.eventusermodel;
|
|||||||
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
|
|
||||||
import org.apache.poi.ss.usermodel.BuiltinFormats;
|
import org.apache.poi.ss.usermodel.BuiltinFormats;
|
||||||
@ -159,11 +158,11 @@ public class XSSFSheetXMLHandler extends DefaultHandler {
|
|||||||
this(styles, strings, sheetContentsHandler, new DataFormatter(), formulasNotResults);
|
this(styles, strings, sheetContentsHandler, new DataFormatter(), formulasNotResults);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
private void init() {
|
private void init() {
|
||||||
if (commentsTable != null) {
|
if (commentsTable != null) {
|
||||||
commentCellRefs = new LinkedList<CellReference>();
|
commentCellRefs = new LinkedList<CellReference>();
|
||||||
List<CTComment> commentList = commentsTable.getCTComments().getCommentList().getCommentList();
|
for (CTComment comment : commentsTable.getCTComments().getCommentList().getCommentArray()) {
|
||||||
for (CTComment comment : commentList) {
|
|
||||||
commentCellRefs.add(new CellReference(comment.getRef()));
|
commentCellRefs.add(new CellReference(comment.getRef()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -187,6 +186,7 @@ public class XSSFSheetXMLHandler extends DefaultHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public void startElement(String uri, String localName, String name,
|
public void startElement(String uri, String localName, String name,
|
||||||
Attributes attributes) throws SAXException {
|
Attributes attributes) throws SAXException {
|
||||||
|
|
||||||
|
@ -24,8 +24,6 @@ import java.util.Locale;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
import javax.xml.parsers.SAXParser;
|
|
||||||
import javax.xml.parsers.SAXParserFactory;
|
|
||||||
|
|
||||||
import org.apache.poi.POIXMLProperties;
|
import org.apache.poi.POIXMLProperties;
|
||||||
import org.apache.poi.POIXMLProperties.CoreProperties;
|
import org.apache.poi.POIXMLProperties.CoreProperties;
|
||||||
@ -35,6 +33,7 @@ import org.apache.poi.POIXMLTextExtractor;
|
|||||||
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
|
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
|
||||||
import org.apache.poi.openxml4j.opc.OPCPackage;
|
import org.apache.poi.openxml4j.opc.OPCPackage;
|
||||||
import org.apache.poi.ss.usermodel.DataFormatter;
|
import org.apache.poi.ss.usermodel.DataFormatter;
|
||||||
|
import org.apache.poi.util.SAXHelper;
|
||||||
import org.apache.poi.xssf.eventusermodel.ReadOnlySharedStringsTable;
|
import org.apache.poi.xssf.eventusermodel.ReadOnlySharedStringsTable;
|
||||||
import org.apache.poi.xssf.eventusermodel.XSSFReader;
|
import org.apache.poi.xssf.eventusermodel.XSSFReader;
|
||||||
import org.apache.poi.xssf.eventusermodel.XSSFSheetXMLHandler;
|
import org.apache.poi.xssf.eventusermodel.XSSFSheetXMLHandler;
|
||||||
@ -174,10 +173,8 @@ public class XSSFEventBasedExcelExtractor extends POIXMLTextExtractor
|
|||||||
}
|
}
|
||||||
|
|
||||||
InputSource sheetSource = new InputSource(sheetInputStream);
|
InputSource sheetSource = new InputSource(sheetInputStream);
|
||||||
SAXParserFactory saxFactory = SAXParserFactory.newInstance();
|
|
||||||
try {
|
try {
|
||||||
SAXParser saxParser = saxFactory.newSAXParser();
|
XMLReader sheetParser = SAXHelper.newXMLReader();
|
||||||
XMLReader sheetParser = saxParser.getXMLReader();
|
|
||||||
ContentHandler handler = new XSSFSheetXMLHandler(
|
ContentHandler handler = new XSSFSheetXMLHandler(
|
||||||
styles, comments, strings, sheetContentsExtractor, formatter, formulasNotResults);
|
styles, comments, strings, sheetContentsExtractor, formatter, formulasNotResults);
|
||||||
sheetParser.setContentHandler(handler);
|
sheetParser.setContentHandler(handler);
|
||||||
|
@ -28,8 +28,6 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
import javax.xml.parsers.DocumentBuilder;
|
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
import javax.xml.transform.OutputKeys;
|
import javax.xml.transform.OutputKeys;
|
||||||
import javax.xml.transform.Source;
|
import javax.xml.transform.Source;
|
||||||
@ -45,7 +43,7 @@ import javax.xml.validation.Validator;
|
|||||||
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
||||||
import org.apache.poi.ss.usermodel.Cell;
|
import org.apache.poi.ss.usermodel.Cell;
|
||||||
import org.apache.poi.ss.usermodel.DateUtil;
|
import org.apache.poi.ss.usermodel.DateUtil;
|
||||||
import org.apache.poi.util.XMLHelper;
|
import org.apache.poi.util.DocumentHelper;
|
||||||
import org.apache.poi.xssf.usermodel.XSSFCell;
|
import org.apache.poi.xssf.usermodel.XSSFCell;
|
||||||
import org.apache.poi.xssf.usermodel.XSSFMap;
|
import org.apache.poi.xssf.usermodel.XSSFMap;
|
||||||
import org.apache.poi.xssf.usermodel.XSSFRow;
|
import org.apache.poi.xssf.usermodel.XSSFRow;
|
||||||
@ -106,15 +104,6 @@ public class XSSFExportToXml implements Comparator<String>{
|
|||||||
exportToXML(os, "UTF-8", validate);
|
exportToXML(os, "UTF-8", validate);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Document getEmptyDocument() throws ParserConfigurationException{
|
|
||||||
|
|
||||||
DocumentBuilderFactory dbfac = XMLHelper.getDocumentBuilderFactory();
|
|
||||||
DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
|
|
||||||
Document doc = docBuilder.newDocument();
|
|
||||||
|
|
||||||
return doc;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exports the data in an XML stream
|
* Exports the data in an XML stream
|
||||||
*
|
*
|
||||||
@ -132,7 +121,7 @@ public class XSSFExportToXml implements Comparator<String>{
|
|||||||
|
|
||||||
String rootElement = map.getCtMap().getRootElement();
|
String rootElement = map.getCtMap().getRootElement();
|
||||||
|
|
||||||
Document doc = getEmptyDocument();
|
Document doc = DocumentHelper.createDocument();
|
||||||
|
|
||||||
Element root = null;
|
Element root = null;
|
||||||
|
|
||||||
@ -459,8 +448,8 @@ public class XSSFExportToXml implements Comparator<String>{
|
|||||||
Node node = list.item(i);
|
Node node = list.item(i);
|
||||||
if (node instanceof Element) {
|
if (node instanceof Element) {
|
||||||
if (node.getLocalName().equals("element")) {
|
if (node.getLocalName().equals("element")) {
|
||||||
Node nameAttribute = node.getAttributes().getNamedItem("name");
|
Node element = getNameOrRefElement(node);
|
||||||
if (nameAttribute.getNodeValue().equals(removeNamespace(elementName))) {
|
if (element.getNodeValue().equals(removeNamespace(elementName))) {
|
||||||
indexOf = i;
|
indexOf = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -471,6 +460,15 @@ public class XSSFExportToXml implements Comparator<String>{
|
|||||||
return indexOf;
|
return indexOf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Node getNameOrRefElement(Node node) {
|
||||||
|
Node returnNode = node.getAttributes().getNamedItem("name");
|
||||||
|
if(returnNode != null) {
|
||||||
|
return returnNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
return node.getAttributes().getNamedItem("ref");
|
||||||
|
}
|
||||||
|
|
||||||
private Node getComplexTypeForElement(String elementName,Node xmlSchema,Node localComplexTypeRootNode) {
|
private Node getComplexTypeForElement(String elementName,Node xmlSchema,Node localComplexTypeRootNode) {
|
||||||
String elementNameWithoutNamespace = removeNamespace(elementName);
|
String elementNameWithoutNamespace = removeNamespace(elementName);
|
||||||
|
|
||||||
@ -494,7 +492,7 @@ public class XSSFExportToXml implements Comparator<String>{
|
|||||||
Node node = list.item(i);
|
Node node = list.item(i);
|
||||||
if ( node instanceof Element) {
|
if ( node instanceof Element) {
|
||||||
if (node.getLocalName().equals("element")) {
|
if (node.getLocalName().equals("element")) {
|
||||||
Node nameAttribute = node.getAttributes().getNamedItem("name");
|
Node nameAttribute = getNameOrRefElement(node);
|
||||||
if (nameAttribute.getNodeValue().equals(elementNameWithoutNamespace)) {
|
if (nameAttribute.getNodeValue().equals(elementNameWithoutNamespace)) {
|
||||||
Node complexTypeAttribute = node.getAttributes().getNamedItem("type");
|
Node complexTypeAttribute = node.getAttributes().getNamedItem("type");
|
||||||
if (complexTypeAttribute!=null) {
|
if (complexTypeAttribute!=null) {
|
||||||
@ -515,7 +513,7 @@ public class XSSFExportToXml implements Comparator<String>{
|
|||||||
Node node = complexTypeList.item(i);
|
Node node = complexTypeList.item(i);
|
||||||
if ( node instanceof Element) {
|
if ( node instanceof Element) {
|
||||||
if (node.getLocalName().equals("complexType")) {
|
if (node.getLocalName().equals("complexType")) {
|
||||||
Node nameAttribute = node.getAttributes().getNamedItem("name");
|
Node nameAttribute = getNameOrRefElement(node);
|
||||||
if (nameAttribute.getNodeValue().equals(complexTypeName)) {
|
if (nameAttribute.getNodeValue().equals(complexTypeName)) {
|
||||||
|
|
||||||
NodeList complexTypeChildList =node.getChildNodes();
|
NodeList complexTypeChildList =node.getChildNodes();
|
||||||
|
@ -24,16 +24,15 @@ import java.util.List;
|
|||||||
|
|
||||||
import javax.xml.namespace.NamespaceContext;
|
import javax.xml.namespace.NamespaceContext;
|
||||||
import javax.xml.parsers.DocumentBuilder;
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
import javax.xml.xpath.XPath;
|
import javax.xml.xpath.XPath;
|
||||||
import javax.xml.xpath.XPathConstants;
|
import javax.xml.xpath.XPathConstants;
|
||||||
import javax.xml.xpath.XPathExpressionException;
|
import javax.xml.xpath.XPathExpressionException;
|
||||||
import javax.xml.xpath.XPathFactory;
|
import javax.xml.xpath.XPathFactory;
|
||||||
|
|
||||||
|
import org.apache.poi.util.DocumentHelper;
|
||||||
import org.apache.poi.util.POILogFactory;
|
import org.apache.poi.util.POILogFactory;
|
||||||
import org.apache.poi.util.POILogger;
|
import org.apache.poi.util.POILogger;
|
||||||
import org.apache.poi.util.XMLHelper;
|
|
||||||
import org.apache.poi.xssf.usermodel.XSSFCell;
|
import org.apache.poi.xssf.usermodel.XSSFCell;
|
||||||
import org.apache.poi.xssf.usermodel.XSSFMap;
|
import org.apache.poi.xssf.usermodel.XSSFMap;
|
||||||
import org.apache.poi.xssf.usermodel.XSSFRow;
|
import org.apache.poi.xssf.usermodel.XSSFRow;
|
||||||
@ -76,11 +75,9 @@ public class XSSFImportFromXML {
|
|||||||
* @throws ParserConfigurationException if there are problems with XML parser configuration
|
* @throws ParserConfigurationException if there are problems with XML parser configuration
|
||||||
* @throws IOException if there are problems reading the input string
|
* @throws IOException if there are problems reading the input string
|
||||||
*/
|
*/
|
||||||
public void importFromXML(String xmlInputString) throws SAXException, XPathExpressionException, ParserConfigurationException, IOException {
|
public void importFromXML(String xmlInputString) throws SAXException, XPathExpressionException, IOException {
|
||||||
|
|
||||||
DocumentBuilderFactory factory = XMLHelper.getDocumentBuilderFactory();
|
DocumentBuilder builder = DocumentHelper.newDocumentBuilder();
|
||||||
factory.setNamespaceAware(true);
|
|
||||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
|
||||||
|
|
||||||
Document doc = builder.parse(new InputSource(new StringReader(xmlInputString.trim())));
|
Document doc = builder.parse(new InputSource(new StringReader(xmlInputString.trim())));
|
||||||
|
|
||||||
|
@ -98,9 +98,11 @@ public class CommentsTable extends POIXMLDocumentPart {
|
|||||||
return comments.getAuthors().getAuthorArray((int)authorId);
|
return comments.getAuthors().getAuthorArray((int)authorId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public int findAuthor(String author) {
|
public int findAuthor(String author) {
|
||||||
for (int i = 0 ; i < comments.getAuthors().sizeOfAuthorArray() ; i++) {
|
String[] authorArray = comments.getAuthors().getAuthorArray();
|
||||||
if (comments.getAuthors().getAuthorArray(i).equals(author)) {
|
for (int i = 0 ; i < authorArray.length; i++) {
|
||||||
|
if (authorArray[i].equals(author)) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -149,15 +151,18 @@ public class CommentsTable extends POIXMLDocumentPart {
|
|||||||
|
|
||||||
public boolean removeComment(String cellRef) {
|
public boolean removeComment(String cellRef) {
|
||||||
CTCommentList lst = comments.getCommentList();
|
CTCommentList lst = comments.getCommentList();
|
||||||
if(lst != null) for(int i=0; i < lst.sizeOfCommentArray(); i++) {
|
if(lst != null) {
|
||||||
CTComment comment = lst.getCommentArray(i);
|
CTComment[] commentArray = lst.getCommentArray();
|
||||||
if (cellRef.equals(comment.getRef())) {
|
for (int i = 0; i < commentArray.length; i++) {
|
||||||
lst.removeComment(i);
|
CTComment comment = commentArray[i];
|
||||||
|
if (cellRef.equals(comment.getRef())) {
|
||||||
if(commentRefs != null) {
|
lst.removeComment(i);
|
||||||
commentRefs.remove(cellRef);
|
|
||||||
|
if(commentRefs != null) {
|
||||||
|
commentRefs.remove(cellRef);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -24,7 +24,6 @@ import java.util.Collection;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
||||||
import org.apache.poi.POIXMLDocumentPart;
|
import org.apache.poi.POIXMLDocumentPart;
|
||||||
import org.apache.poi.openxml4j.opc.PackagePart;
|
import org.apache.poi.openxml4j.opc.PackagePart;
|
||||||
import org.apache.poi.openxml4j.opc.PackageRelationship;
|
import org.apache.poi.openxml4j.opc.PackageRelationship;
|
||||||
@ -66,13 +65,14 @@ public class MapInfo extends POIXMLDocumentPart {
|
|||||||
readFrom(part.getInputStream());
|
readFrom(part.getInputStream());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public void readFrom(InputStream is) throws IOException {
|
public void readFrom(InputStream is) throws IOException {
|
||||||
try {
|
try {
|
||||||
MapInfoDocument doc = MapInfoDocument.Factory.parse(is);
|
MapInfoDocument doc = MapInfoDocument.Factory.parse(is);
|
||||||
mapInfo = doc.getMapInfo();
|
mapInfo = doc.getMapInfo();
|
||||||
|
|
||||||
maps= new HashMap<Integer, XSSFMap>();
|
maps= new HashMap<Integer, XSSFMap>();
|
||||||
for(CTMap map :mapInfo.getMapList()){
|
for(CTMap map :mapInfo.getMapArray()){
|
||||||
maps.put((int)map.getID(), new XSSFMap(map,this));
|
maps.put((int)map.getID(), new XSSFMap(map,this));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,10 +104,11 @@ public class MapInfo extends POIXMLDocumentPart {
|
|||||||
* @param schemaId the schema ID
|
* @param schemaId the schema ID
|
||||||
* @return CTSchema by it's ID
|
* @return CTSchema by it's ID
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public CTSchema getCTSchemaById(String schemaId){
|
public CTSchema getCTSchemaById(String schemaId){
|
||||||
CTSchema xmlSchema = null;
|
CTSchema xmlSchema = null;
|
||||||
|
|
||||||
for(CTSchema schema: mapInfo.getSchemaList()){
|
for(CTSchema schema: mapInfo.getSchemaArray()){
|
||||||
if(schema.getID().equals(schemaId)){
|
if(schema.getID().equals(schemaId)){
|
||||||
xmlSchema = schema;
|
xmlSchema = schema;
|
||||||
break;
|
break;
|
||||||
|
@ -94,10 +94,11 @@ public class SingleXmlCells extends POIXMLDocumentPart {
|
|||||||
*
|
*
|
||||||
* @return all the SimpleXmlCell contained in this SingleXmlCells element
|
* @return all the SimpleXmlCell contained in this SingleXmlCells element
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public List<XSSFSingleXmlCell> getAllSimpleXmlCell(){
|
public List<XSSFSingleXmlCell> getAllSimpleXmlCell(){
|
||||||
List<XSSFSingleXmlCell> list = new Vector<XSSFSingleXmlCell>();
|
List<XSSFSingleXmlCell> list = new Vector<XSSFSingleXmlCell>();
|
||||||
|
|
||||||
for(CTSingleXmlCell singleXmlCell: singleXMLCells.getSingleXmlCellList()){
|
for(CTSingleXmlCell singleXmlCell: singleXMLCells.getSingleXmlCellArray()){
|
||||||
list.add(new XSSFSingleXmlCell(singleXmlCell,this));
|
list.add(new XSSFSingleXmlCell(singleXmlCell,this));
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
|
@ -23,20 +23,22 @@ import org.apache.poi.openxml4j.opc.PackagePart;
|
|||||||
import org.apache.poi.openxml4j.opc.PackageRelationship;
|
import org.apache.poi.openxml4j.opc.PackageRelationship;
|
||||||
import org.apache.poi.xssf.usermodel.XSSFColor;
|
import org.apache.poi.xssf.usermodel.XSSFColor;
|
||||||
import org.apache.xmlbeans.XmlException;
|
import org.apache.xmlbeans.XmlException;
|
||||||
import org.apache.xmlbeans.XmlObject;
|
import org.openxmlformats.schemas.drawingml.x2006.main.CTColor;
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.CTColorScheme;
|
import org.openxmlformats.schemas.drawingml.x2006.main.CTColorScheme;
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.ThemeDocument;
|
import org.openxmlformats.schemas.drawingml.x2006.main.ThemeDocument;
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.CTColor;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class that represents theme of XLSX document. The theme includes specific
|
* Class that represents theme of XLSX document. The theme includes specific
|
||||||
* colors and fonts.
|
* colors and fonts.
|
||||||
*
|
|
||||||
* @author Petr Udalau(Petr.Udalau at exigenservices.com) - theme colors
|
|
||||||
*/
|
*/
|
||||||
public class ThemesTable extends POIXMLDocumentPart {
|
public class ThemesTable extends POIXMLDocumentPart {
|
||||||
private ThemeDocument theme;
|
private ThemeDocument theme;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct a ThemesTable.
|
||||||
|
* @param part A PackagePart.
|
||||||
|
* @param rel A PackageRelationship.
|
||||||
|
*/
|
||||||
public ThemesTable(PackagePart part, PackageRelationship rel) throws IOException {
|
public ThemesTable(PackagePart part, PackageRelationship rel) throws IOException {
|
||||||
super(part, rel);
|
super(part, rel);
|
||||||
|
|
||||||
@ -47,38 +49,56 @@ public class ThemesTable extends POIXMLDocumentPart {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct a ThemesTable from an existing ThemeDocument.
|
||||||
|
* @param theme A ThemeDocument.
|
||||||
|
*/
|
||||||
public ThemesTable(ThemeDocument theme) {
|
public ThemesTable(ThemeDocument theme) {
|
||||||
this.theme = theme;
|
this.theme = theme;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert a theme "index" into a color.
|
||||||
|
* @param idx A theme "index"
|
||||||
|
* @return The mapped XSSFColor, or null if not mapped.
|
||||||
|
*/
|
||||||
public XSSFColor getThemeColor(int idx) {
|
public XSSFColor getThemeColor(int idx) {
|
||||||
|
// Theme color references are NOT positional indices into the color scheme,
|
||||||
|
// i.e. these keys are NOT the same as the order in which theme colors appear
|
||||||
|
// in theme1.xml. They are keys to a mapped color.
|
||||||
CTColorScheme colorScheme = theme.getTheme().getThemeElements().getClrScheme();
|
CTColorScheme colorScheme = theme.getTheme().getThemeElements().getClrScheme();
|
||||||
CTColor ctColor = null;
|
CTColor ctColor;
|
||||||
int cnt = 0;
|
switch (idx) {
|
||||||
for (XmlObject obj : colorScheme.selectPath("./*")) {
|
case 0: ctColor = colorScheme.getLt1(); break;
|
||||||
if (obj instanceof org.openxmlformats.schemas.drawingml.x2006.main.CTColor) {
|
case 1: ctColor = colorScheme.getDk1(); break;
|
||||||
if (cnt == idx) {
|
case 2: ctColor = colorScheme.getLt2(); break;
|
||||||
ctColor = (org.openxmlformats.schemas.drawingml.x2006.main.CTColor) obj;
|
case 3: ctColor = colorScheme.getDk2(); break;
|
||||||
|
case 4: ctColor = colorScheme.getAccent1(); break;
|
||||||
byte[] rgb = null;
|
case 5: ctColor = colorScheme.getAccent2(); break;
|
||||||
if (ctColor.getSrgbClr() != null) {
|
case 6: ctColor = colorScheme.getAccent3(); break;
|
||||||
// Colour is a regular one
|
case 7: ctColor = colorScheme.getAccent4(); break;
|
||||||
rgb = ctColor.getSrgbClr().getVal();
|
case 8: ctColor = colorScheme.getAccent5(); break;
|
||||||
} else if (ctColor.getSysClr() != null) {
|
case 9: ctColor = colorScheme.getAccent6(); break;
|
||||||
// Colour is a tint of white or black
|
case 10: ctColor = colorScheme.getHlink(); break;
|
||||||
rgb = ctColor.getSysClr().getLastClr();
|
case 11: ctColor = colorScheme.getFolHlink(); break;
|
||||||
}
|
default: return null;
|
||||||
|
|
||||||
return new XSSFColor(rgb);
|
|
||||||
}
|
|
||||||
cnt++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
|
byte[] rgb = null;
|
||||||
|
if (ctColor.isSetSrgbClr()) {
|
||||||
|
// Color is a regular one
|
||||||
|
rgb = ctColor.getSrgbClr().getVal();
|
||||||
|
} else if (ctColor.isSetSysClr()) {
|
||||||
|
// Color is a tint of white or black
|
||||||
|
rgb = ctColor.getSysClr().getLastClr();
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new XSSFColor(rgb);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If the colour is based on a theme, then inherit
|
* If the colour is based on a theme, then inherit
|
||||||
* information (currently just colours) from it as
|
* information (currently just colours) from it as
|
||||||
* required.
|
* required.
|
||||||
*/
|
*/
|
||||||
@ -91,13 +111,13 @@ public class ThemesTable extends POIXMLDocumentPart {
|
|||||||
// No theme set, nothing to do
|
// No theme set, nothing to do
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the theme colour
|
// Get the theme colour
|
||||||
XSSFColor themeColor = getThemeColor(color.getTheme());
|
XSSFColor themeColor = getThemeColor(color.getTheme());
|
||||||
// Set the raw colour, not the adjusted one
|
// Set the raw colour, not the adjusted one
|
||||||
// Do a raw set, no adjusting at the XSSFColor layer either
|
// Do a raw set, no adjusting at the XSSFColor layer either
|
||||||
color.getCTColor().setRgb(themeColor.getCTColor().getRgb());
|
color.getCTColor().setRgb(themeColor.getCTColor().getRgb());
|
||||||
|
|
||||||
// All done
|
// All done
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,40 +19,40 @@ package org.apache.poi.xssf.usermodel;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.xml.namespace.QName;
|
import javax.xml.namespace.QName;
|
||||||
|
|
||||||
import org.apache.poi.POIXMLDocumentPart;
|
import org.apache.poi.POIXMLDocumentPart;
|
||||||
import org.apache.poi.openxml4j.opc.PackagePart;
|
import org.apache.poi.openxml4j.opc.PackagePart;
|
||||||
import org.apache.poi.openxml4j.opc.PackageRelationship;
|
import org.apache.poi.openxml4j.opc.PackageRelationship;
|
||||||
import org.apache.poi.util.Internal;
|
|
||||||
import org.apache.poi.ss.usermodel.Chart;
|
import org.apache.poi.ss.usermodel.Chart;
|
||||||
|
import org.apache.poi.ss.usermodel.charts.AxisPosition;
|
||||||
import org.apache.poi.ss.usermodel.charts.ChartAxis;
|
import org.apache.poi.ss.usermodel.charts.ChartAxis;
|
||||||
import org.apache.poi.ss.usermodel.charts.ChartAxisFactory;
|
import org.apache.poi.ss.usermodel.charts.ChartAxisFactory;
|
||||||
import org.apache.poi.xssf.usermodel.charts.XSSFCategoryAxis;
|
|
||||||
import org.apache.poi.xssf.usermodel.charts.XSSFChartDataFactory;
|
|
||||||
import org.apache.poi.xssf.usermodel.charts.XSSFChartAxis;
|
|
||||||
import org.apache.poi.xssf.usermodel.charts.XSSFValueAxis;
|
|
||||||
import org.apache.poi.xssf.usermodel.charts.XSSFManualLayout;
|
|
||||||
import org.apache.poi.xssf.usermodel.charts.XSSFChartLegend;
|
|
||||||
import org.apache.poi.ss.usermodel.charts.ChartData;
|
import org.apache.poi.ss.usermodel.charts.ChartData;
|
||||||
import org.apache.poi.ss.usermodel.charts.AxisPosition;
|
import org.apache.poi.util.Internal;
|
||||||
|
import org.apache.poi.xssf.usermodel.charts.XSSFCategoryAxis;
|
||||||
|
import org.apache.poi.xssf.usermodel.charts.XSSFChartAxis;
|
||||||
|
import org.apache.poi.xssf.usermodel.charts.XSSFChartDataFactory;
|
||||||
|
import org.apache.poi.xssf.usermodel.charts.XSSFChartLegend;
|
||||||
|
import org.apache.poi.xssf.usermodel.charts.XSSFManualLayout;
|
||||||
|
import org.apache.poi.xssf.usermodel.charts.XSSFValueAxis;
|
||||||
import org.apache.xmlbeans.XmlException;
|
import org.apache.xmlbeans.XmlException;
|
||||||
import org.apache.xmlbeans.XmlObject;
|
import org.apache.xmlbeans.XmlObject;
|
||||||
import org.apache.xmlbeans.XmlOptions;
|
import org.apache.xmlbeans.XmlOptions;
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.chart.CTCatAx;
|
import org.openxmlformats.schemas.drawingml.x2006.chart.CTCatAx;
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.chart.CTChart;
|
import org.openxmlformats.schemas.drawingml.x2006.chart.CTChart;
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.chart.CTChartSpace;
|
import org.openxmlformats.schemas.drawingml.x2006.chart.CTChartSpace;
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.chart.CTTitle;
|
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.chart.ChartSpaceDocument;
|
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.chart.CTPlotArea;
|
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.chart.CTValAx;
|
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.chart.CTPrintSettings;
|
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.chart.CTPageMargins;
|
import org.openxmlformats.schemas.drawingml.x2006.chart.CTPageMargins;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.chart.CTPlotArea;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.chart.CTPrintSettings;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.chart.CTTitle;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.chart.CTValAx;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.chart.ChartSpaceDocument;
|
||||||
import org.openxmlformats.schemas.officeDocument.x2006.relationships.STRelationshipId;
|
import org.openxmlformats.schemas.officeDocument.x2006.relationships.STRelationshipId;
|
||||||
import org.w3c.dom.NodeList;
|
import org.w3c.dom.NodeList;
|
||||||
import org.w3c.dom.Text;
|
import org.w3c.dom.Text;
|
||||||
@ -306,14 +306,16 @@ public final class XSSFChart extends POIXMLDocumentPart implements Chart, ChartA
|
|||||||
parseValueAxis();
|
parseValueAxis();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
private void parseCategoryAxis() {
|
private void parseCategoryAxis() {
|
||||||
for (CTCatAx catAx : chart.getPlotArea().getCatAxList()) {
|
for (CTCatAx catAx : chart.getPlotArea().getCatAxArray()) {
|
||||||
axis.add(new XSSFCategoryAxis(this, catAx));
|
axis.add(new XSSFCategoryAxis(this, catAx));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
private void parseValueAxis() {
|
private void parseValueAxis() {
|
||||||
for (CTValAx valAx : chart.getPlotArea().getValAxList()) {
|
for (CTValAx valAx : chart.getPlotArea().getValAxArray()) {
|
||||||
axis.add(new XSSFValueAxis(this, valAx));
|
axis.add(new XSSFValueAxis(this, valAx));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,16 +25,16 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor;
|
|||||||
* Represents a color in SpreadsheetML
|
* Represents a color in SpreadsheetML
|
||||||
*/
|
*/
|
||||||
public class XSSFColor implements Color {
|
public class XSSFColor implements Color {
|
||||||
|
|
||||||
private CTColor ctColor;
|
private CTColor ctColor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create an instance of XSSFColor from the supplied XML bean
|
* Create an instance of XSSFColor from the supplied XML bean
|
||||||
*/
|
*/
|
||||||
public XSSFColor(CTColor color) {
|
public XSSFColor(CTColor color) {
|
||||||
this.ctColor = color;
|
this.ctColor = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create an new instance of XSSFColor
|
* Create an new instance of XSSFColor
|
||||||
*/
|
*/
|
||||||
@ -56,50 +56,29 @@ public class XSSFColor implements Color {
|
|||||||
* A boolean value indicating the ctColor is automatic and system ctColor dependent.
|
* A boolean value indicating the ctColor is automatic and system ctColor dependent.
|
||||||
*/
|
*/
|
||||||
public boolean isAuto() {
|
public boolean isAuto() {
|
||||||
return ctColor.getAuto();
|
return ctColor.getAuto();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A boolean value indicating the ctColor is automatic and system ctColor dependent.
|
* A boolean value indicating the ctColor is automatic and system ctColor dependent.
|
||||||
*/
|
*/
|
||||||
public void setAuto(boolean auto) {
|
public void setAuto(boolean auto) {
|
||||||
ctColor.setAuto(auto);
|
ctColor.setAuto(auto);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indexed ctColor value. Only used for backwards compatibility. References a ctColor in indexedColors.
|
* Indexed ctColor value. Only used for backwards compatibility. References a ctColor in indexedColors.
|
||||||
*/
|
*/
|
||||||
public short getIndexed() {
|
public short getIndexed() {
|
||||||
return (short)ctColor.getIndexed();
|
return (short)ctColor.getIndexed();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indexed ctColor value. Only used for backwards compatibility. References a ctColor in indexedColors.
|
* Indexed ctColor value. Only used for backwards compatibility. References a ctColor in indexedColors.
|
||||||
*/
|
*/
|
||||||
public void setIndexed(int indexed) {
|
public void setIndexed(int indexed) {
|
||||||
ctColor.setIndexed(indexed);
|
ctColor.setIndexed(indexed);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* For RGB colours, but not ARGB (we think...)
|
|
||||||
* Excel gets black and white the wrong way around, so switch them
|
|
||||||
*/
|
|
||||||
private byte[] correctRGB(byte[] rgb) {
|
|
||||||
if(rgb.length == 4) {
|
|
||||||
// Excel doesn't appear to get these wrong
|
|
||||||
// Nothing to change
|
|
||||||
return rgb;
|
|
||||||
} else {
|
|
||||||
// Excel gets black and white the wrong way around, so switch them
|
|
||||||
if (rgb[0] == 0 && rgb[1] == 0 && rgb[2] == 0) {
|
|
||||||
rgb = new byte[] {-1, -1, -1};
|
|
||||||
}
|
|
||||||
else if (rgb[0] == -1 && rgb[1] == -1 && rgb[2] == -1) {
|
|
||||||
rgb = new byte[] {0, 0, 0};
|
|
||||||
}
|
|
||||||
return rgb;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Standard Red Green Blue ctColor value (RGB).
|
* Standard Red Green Blue ctColor value (RGB).
|
||||||
@ -108,7 +87,7 @@ public class XSSFColor implements Color {
|
|||||||
public byte[] getRgb() {
|
public byte[] getRgb() {
|
||||||
byte[] rgb = getRGBOrARGB();
|
byte[] rgb = getRGBOrARGB();
|
||||||
if(rgb == null) return null;
|
if(rgb == null) return null;
|
||||||
|
|
||||||
if(rgb.length == 4) {
|
if(rgb.length == 4) {
|
||||||
// Need to trim off the alpha
|
// Need to trim off the alpha
|
||||||
byte[] tmp = new byte[3];
|
byte[] tmp = new byte[3];
|
||||||
@ -125,7 +104,7 @@ public class XSSFColor implements Color {
|
|||||||
public byte[] getARgb() {
|
public byte[] getARgb() {
|
||||||
byte[] rgb = getRGBOrARGB();
|
byte[] rgb = getRGBOrARGB();
|
||||||
if(rgb == null) return null;
|
if(rgb == null) return null;
|
||||||
|
|
||||||
if(rgb.length == 3) {
|
if(rgb.length == 3) {
|
||||||
// Pad with the default Alpha
|
// Pad with the default Alpha
|
||||||
byte[] tmp = new byte[4];
|
byte[] tmp = new byte[4];
|
||||||
@ -136,7 +115,7 @@ public class XSSFColor implements Color {
|
|||||||
return rgb;
|
return rgb;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private byte[] getRGBOrARGB() {
|
private byte[] getRGBOrARGB() {
|
||||||
byte[] rgb = null;
|
byte[] rgb = null;
|
||||||
|
|
||||||
@ -150,7 +129,7 @@ public class XSSFColor implements Color {
|
|||||||
return rgb;
|
return rgb;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ctColor.isSetRgb()) {
|
if (!ctColor.isSetRgb()) {
|
||||||
// No colour is available, sorry
|
// No colour is available, sorry
|
||||||
return null;
|
return null;
|
||||||
@ -158,9 +137,7 @@ public class XSSFColor implements Color {
|
|||||||
|
|
||||||
// Grab the colour
|
// Grab the colour
|
||||||
rgb = ctColor.getRgb();
|
rgb = ctColor.getRgb();
|
||||||
|
return rgb;
|
||||||
// Correct it as needed, and return
|
|
||||||
return correctRGB(rgb);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -181,64 +158,63 @@ public class XSSFColor implements Color {
|
|||||||
}
|
}
|
||||||
return rgb;
|
return rgb;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the ARGB value in hex format, eg FF00FF00.
|
* Return the ARGB value in hex format, eg FF00FF00.
|
||||||
* Works for both regular and indexed colours.
|
* Works for both regular and indexed colours.
|
||||||
*/
|
*/
|
||||||
public String getARGBHex() {
|
public String getARGBHex() {
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuffer sb = new StringBuffer();
|
||||||
byte[] rgb = getARgb();
|
byte[] rgb = getARgb();
|
||||||
if(rgb == null) {
|
if(rgb == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
for(byte c : rgb) {
|
for(byte c : rgb) {
|
||||||
int i = (int)c;
|
int i = (int)c;
|
||||||
if(i < 0) {
|
if(i < 0) {
|
||||||
i += 256;
|
i += 256;
|
||||||
}
|
}
|
||||||
String cs = Integer.toHexString(i);
|
String cs = Integer.toHexString(i);
|
||||||
if(cs.length() == 1) {
|
if(cs.length() == 1) {
|
||||||
sb.append('0');
|
sb.append('0');
|
||||||
}
|
}
|
||||||
sb.append(cs);
|
sb.append(cs);
|
||||||
}
|
}
|
||||||
return sb.toString().toUpperCase();
|
return sb.toString().toUpperCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static byte applyTint(int lum, double tint){
|
private static byte applyTint(int lum, double tint){
|
||||||
if(tint > 0){
|
if(tint > 0){
|
||||||
return (byte)(lum * (1.0-tint) + (255 - 255 * (1.0-tint)));
|
return (byte)(lum * (1.0-tint) + (255 - 255 * (1.0-tint)));
|
||||||
} else if (tint < 0){
|
} else if (tint < 0){
|
||||||
return (byte)(lum*(1+tint));
|
return (byte)(lum*(1+tint));
|
||||||
} else {
|
} else {
|
||||||
return (byte)lum;
|
return (byte)lum;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Standard Alpha Red Green Blue ctColor value (ARGB).
|
* Standard Alpha Red Green Blue ctColor value (ARGB).
|
||||||
*/
|
*/
|
||||||
public void setRgb(byte[] rgb) {
|
public void setRgb(byte[] rgb) {
|
||||||
// Correct it and save
|
ctColor.setRgb(rgb);
|
||||||
ctColor.setRgb(correctRGB(rgb));
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Index into the <clrScheme> collection, referencing a particular <sysClr> or
|
* Index into the <clrScheme> collection, referencing a particular <sysClr> or
|
||||||
* <srgbClr> value expressed in the Theme part.
|
* <srgbClr> value expressed in the Theme part.
|
||||||
*/
|
*/
|
||||||
public int getTheme() {
|
public int getTheme() {
|
||||||
return (int)ctColor.getTheme();
|
return (int)ctColor.getTheme();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Index into the <clrScheme> collection, referencing a particular <sysClr> or
|
* Index into the <clrScheme> collection, referencing a particular <sysClr> or
|
||||||
* <srgbClr> value expressed in the Theme part.
|
* <srgbClr> value expressed in the Theme part.
|
||||||
*/
|
*/
|
||||||
public void setTheme(int theme) {
|
public void setTheme(int theme) {
|
||||||
ctColor.setTheme(theme);
|
ctColor.setTheme(theme);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies the tint value applied to the ctColor.
|
* Specifies the tint value applied to the ctColor.
|
||||||
@ -282,9 +258,9 @@ public class XSSFColor implements Color {
|
|||||||
* @return the tint value
|
* @return the tint value
|
||||||
*/
|
*/
|
||||||
public double getTint() {
|
public double getTint() {
|
||||||
return ctColor.getTint();
|
return ctColor.getTint();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies the tint value applied to the ctColor.
|
* Specifies the tint value applied to the ctColor.
|
||||||
*
|
*
|
||||||
@ -326,9 +302,9 @@ public class XSSFColor implements Color {
|
|||||||
*
|
*
|
||||||
* @param tint the tint value
|
* @param tint the tint value
|
||||||
*/
|
*/
|
||||||
public void setTint(double tint) {
|
public void setTint(double tint) {
|
||||||
ctColor.setTint(tint);
|
ctColor.setTint(tint);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the underlying XML bean
|
* Returns the underlying XML bean
|
||||||
@ -339,7 +315,7 @@ public class XSSFColor implements Color {
|
|||||||
public CTColor getCTColor(){
|
public CTColor getCTColor(){
|
||||||
return ctColor;
|
return ctColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int hashCode(){
|
public int hashCode(){
|
||||||
return ctColor.toString().hashCode();
|
return ctColor.toString().hashCode();
|
||||||
}
|
}
|
||||||
|
@ -127,7 +127,7 @@ public class XSSFPivotCacheDefinition extends POIXMLDocumentPart{
|
|||||||
for(int i=columnStart; i<=columnEnd; i++) {
|
for(int i=columnStart; i<=columnEnd; i++) {
|
||||||
CTCacheField cf = cFields.addNewCacheField();
|
CTCacheField cf = cFields.addNewCacheField();
|
||||||
if(i==columnEnd){
|
if(i==columnEnd){
|
||||||
cFields.setCount(cFields.getCacheFieldList().size());
|
cFields.setCount(cFields.sizeOfCacheFieldArray());
|
||||||
}
|
}
|
||||||
//General number format
|
//General number format
|
||||||
cf.setNumFmtId(0);
|
cf.setNumFmtId(0);
|
||||||
|
@ -240,7 +240,6 @@ public class XSSFPivotTable extends POIXMLDocumentPart {
|
|||||||
}
|
}
|
||||||
CTPivotFields pivotFields = pivotTableDefinition.getPivotFields();
|
CTPivotFields pivotFields = pivotTableDefinition.getPivotFields();
|
||||||
|
|
||||||
List<CTPivotField> pivotFieldList = pivotTableDefinition.getPivotFields().getPivotFieldList();
|
|
||||||
CTPivotField pivotField = CTPivotField.Factory.newInstance();
|
CTPivotField pivotField = CTPivotField.Factory.newInstance();
|
||||||
CTItems items = pivotField.addNewItems();
|
CTItems items = pivotField.addNewItems();
|
||||||
|
|
||||||
@ -249,10 +248,8 @@ public class XSSFPivotTable extends POIXMLDocumentPart {
|
|||||||
for(int i = 0; i <= lastRowIndex; i++) {
|
for(int i = 0; i <= lastRowIndex; i++) {
|
||||||
items.addNewItem().setT(STItemType.DEFAULT);
|
items.addNewItem().setT(STItemType.DEFAULT);
|
||||||
}
|
}
|
||||||
items.setCount(items.getItemList().size());
|
items.setCount(items.sizeOfItemArray());
|
||||||
pivotFieldList.set(columnIndex, pivotField);
|
pivotFields.setPivotFieldArray(columnIndex, pivotField);
|
||||||
|
|
||||||
pivotFields.setPivotFieldArray(pivotFieldList.toArray(new CTPivotField[pivotFieldList.size()]));
|
|
||||||
|
|
||||||
CTRowFields rowFields;
|
CTRowFields rowFields;
|
||||||
if(pivotTableDefinition.getRowFields() != null) {
|
if(pivotTableDefinition.getRowFields() != null) {
|
||||||
@ -262,7 +259,7 @@ public class XSSFPivotTable extends POIXMLDocumentPart {
|
|||||||
}
|
}
|
||||||
|
|
||||||
rowFields.addNewField().setX(columnIndex);
|
rowFields.addNewField().setX(columnIndex);
|
||||||
rowFields.setCount(rowFields.getFieldList().size());
|
rowFields.setCount(rowFields.sizeOfFieldArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Beta
|
@Beta
|
||||||
@ -307,7 +304,7 @@ public class XSSFPivotTable extends POIXMLDocumentPart {
|
|||||||
colFields = pivotTableDefinition.addNewColFields();
|
colFields = pivotTableDefinition.addNewColFields();
|
||||||
}
|
}
|
||||||
colFields.addNewField().setX(-2);
|
colFields.addNewField().setX(-2);
|
||||||
colFields.setCount(colFields.getFieldList().size());
|
colFields.setCount(colFields.sizeOfFieldArray());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -338,7 +335,7 @@ public class XSSFPivotTable extends POIXMLDocumentPart {
|
|||||||
cell.setCellType(Cell.CELL_TYPE_STRING);
|
cell.setCellType(Cell.CELL_TYPE_STRING);
|
||||||
dataField.setName(function.getName());
|
dataField.setName(function.getName());
|
||||||
dataField.setFld(columnIndex);
|
dataField.setFld(columnIndex);
|
||||||
dataFields.setCount(dataFields.getDataFieldList().size());
|
dataFields.setCount(dataFields.sizeOfDataFieldArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -354,13 +351,11 @@ public class XSSFPivotTable extends POIXMLDocumentPart {
|
|||||||
throw new IndexOutOfBoundsException();
|
throw new IndexOutOfBoundsException();
|
||||||
}
|
}
|
||||||
CTPivotFields pivotFields = pivotTableDefinition.getPivotFields();
|
CTPivotFields pivotFields = pivotTableDefinition.getPivotFields();
|
||||||
List<CTPivotField> pivotFieldList = pivotFields.getPivotFieldList();
|
|
||||||
CTPivotField pivotField = CTPivotField.Factory.newInstance();
|
CTPivotField pivotField = CTPivotField.Factory.newInstance();
|
||||||
|
|
||||||
pivotField.setDataField(isDataField);
|
pivotField.setDataField(isDataField);
|
||||||
pivotField.setShowAll(false);
|
pivotField.setShowAll(false);
|
||||||
pivotFieldList.set(columnIndex, pivotField);
|
pivotFields.setPivotFieldArray(columnIndex, pivotField);
|
||||||
pivotFields.setPivotFieldArray(pivotFieldList.toArray(new CTPivotField[pivotFieldList.size()]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -378,7 +373,6 @@ public class XSSFPivotTable extends POIXMLDocumentPart {
|
|||||||
}
|
}
|
||||||
CTPivotFields pivotFields = pivotTableDefinition.getPivotFields();
|
CTPivotFields pivotFields = pivotTableDefinition.getPivotFields();
|
||||||
|
|
||||||
List<CTPivotField> pivotFieldList = pivotTableDefinition.getPivotFields().getPivotFieldList();
|
|
||||||
CTPivotField pivotField = CTPivotField.Factory.newInstance();
|
CTPivotField pivotField = CTPivotField.Factory.newInstance();
|
||||||
CTItems items = pivotField.addNewItems();
|
CTItems items = pivotField.addNewItems();
|
||||||
|
|
||||||
@ -387,8 +381,8 @@ public class XSSFPivotTable extends POIXMLDocumentPart {
|
|||||||
for(int i = 0; i <= lastRowIndex; i++) {
|
for(int i = 0; i <= lastRowIndex; i++) {
|
||||||
items.addNewItem().setT(STItemType.DEFAULT);
|
items.addNewItem().setT(STItemType.DEFAULT);
|
||||||
}
|
}
|
||||||
items.setCount(items.getItemList().size());
|
items.setCount(items.sizeOfItemArray());
|
||||||
pivotFieldList.set(columnIndex, pivotField);
|
pivotFields.setPivotFieldArray(columnIndex, pivotField);
|
||||||
|
|
||||||
CTPageFields pageFields;
|
CTPageFields pageFields;
|
||||||
if (pivotTableDefinition.getPageFields()!= null) {
|
if (pivotTableDefinition.getPageFields()!= null) {
|
||||||
@ -402,7 +396,7 @@ public class XSSFPivotTable extends POIXMLDocumentPart {
|
|||||||
pageField.setHier(-1);
|
pageField.setHier(-1);
|
||||||
pageField.setFld(columnIndex);
|
pageField.setFld(columnIndex);
|
||||||
|
|
||||||
pageFields.setCount(pageFields.getPageFieldList().size());
|
pageFields.setCount(pageFields.sizeOfPageFieldArray());
|
||||||
pivotTableDefinition.getLocation().setColPageCount(pageFields.getCount());
|
pivotTableDefinition.getLocation().setColPageCount(pageFields.getCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -459,6 +453,6 @@ public class XSSFPivotTable extends POIXMLDocumentPart {
|
|||||||
pivotField.setDataField(false);
|
pivotField.setDataField(false);
|
||||||
pivotField.setShowAll(false);
|
pivotField.setShowAll(false);
|
||||||
}
|
}
|
||||||
pivotFields.setCount(pivotFields.getPivotFieldList().size());
|
pivotFields.setCount(pivotFields.sizeOfPivotFieldArray());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -439,16 +439,18 @@ public class XSSFRow implements Row, Comparable<XSSFRow> {
|
|||||||
*
|
*
|
||||||
* @see org.apache.poi.xssf.usermodel.XSSFSheet#write(java.io.OutputStream) ()
|
* @see org.apache.poi.xssf.usermodel.XSSFSheet#write(java.io.OutputStream) ()
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
protected void onDocumentWrite(){
|
protected void onDocumentWrite(){
|
||||||
// check if cells in the CTRow are ordered
|
// check if cells in the CTRow are ordered
|
||||||
boolean isOrdered = true;
|
boolean isOrdered = true;
|
||||||
if(_row.sizeOfCArray() != _cells.size()) {
|
CTCell[] cArray = _row.getCArray();
|
||||||
|
if (cArray.length != _cells.size()) {
|
||||||
isOrdered = false;
|
isOrdered = false;
|
||||||
} else {
|
} else {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (XSSFCell cell : _cells.values()) {
|
for (XSSFCell cell : _cells.values()) {
|
||||||
CTCell c1 = cell.getCTCell();
|
CTCell c1 = cell.getCTCell();
|
||||||
CTCell c2 = _row.getCArray(i++);
|
CTCell c2 = cArray[i++];
|
||||||
|
|
||||||
String r1 = c1.getR();
|
String r1 = c1.getR();
|
||||||
String r2 = c2.getR();
|
String r2 = c2.getR();
|
||||||
@ -460,17 +462,17 @@ public class XSSFRow implements Row, Comparable<XSSFRow> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(!isOrdered){
|
if(!isOrdered){
|
||||||
CTCell[] cArray = new CTCell[_cells.size()];
|
cArray = new CTCell[_cells.size()];
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (Map.Entry<Integer, XSSFCell> entry : _cells.entrySet()) {
|
for (XSSFCell xssfCell : _cells.values()) {
|
||||||
cArray[i] = (CTCell) entry.getValue().getCTCell().copy();
|
cArray[i] = (CTCell) xssfCell.getCTCell().copy();
|
||||||
|
|
||||||
// we have to copy and re-create the XSSFCell here because the
|
// we have to copy and re-create the XSSFCell here because the
|
||||||
// elements as otherwise setCArray below invalidates all the columns!
|
// elements as otherwise setCArray below invalidates all the columns!
|
||||||
// see Bug 56170, XMLBeans seems to always release previous objects
|
// see Bug 56170, XMLBeans seems to always release previous objects
|
||||||
// in the CArray, so we need to provide completely new ones here!
|
// in the CArray, so we need to provide completely new ones here!
|
||||||
//_cells.put(entry.getKey(), new XSSFCell(this, cArray[i]));
|
//_cells.put(entry.getKey(), new XSSFCell(this, cArray[i]));
|
||||||
entry.getValue().setCTCell(cArray[i]);
|
xssfCell.setCTCell(cArray[i]);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -19,21 +19,21 @@
|
|||||||
|
|
||||||
package org.apache.poi.xssf.usermodel;
|
package org.apache.poi.xssf.usermodel;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.poi.hssf.record.cf.CellRangeUtil;
|
||||||
|
import org.apache.poi.ss.SpreadsheetVersion;
|
||||||
|
import org.apache.poi.ss.usermodel.ComparisonOperator;
|
||||||
import org.apache.poi.ss.usermodel.ConditionalFormatting;
|
import org.apache.poi.ss.usermodel.ConditionalFormatting;
|
||||||
import org.apache.poi.ss.usermodel.ConditionalFormattingRule;
|
import org.apache.poi.ss.usermodel.ConditionalFormattingRule;
|
||||||
import org.apache.poi.ss.usermodel.SheetConditionalFormatting;
|
import org.apache.poi.ss.usermodel.SheetConditionalFormatting;
|
||||||
import org.apache.poi.ss.usermodel.ComparisonOperator;
|
|
||||||
import org.apache.poi.ss.util.CellRangeAddress;
|
import org.apache.poi.ss.util.CellRangeAddress;
|
||||||
import org.apache.poi.ss.SpreadsheetVersion;
|
|
||||||
import org.apache.poi.hssf.record.cf.CellRangeUtil;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCfRule;
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCfRule;
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STCfType;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTConditionalFormatting;
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTConditionalFormatting;
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STConditionalFormattingOperator;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
|
||||||
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STCfType;
|
||||||
import java.util.List;
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STConditionalFormattingOperator;
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Yegor Kozlov
|
* @author Yegor Kozlov
|
||||||
@ -115,6 +115,7 @@ public class XSSFSheetConditionalFormatting implements SheetConditionalFormattin
|
|||||||
return rule;
|
return rule;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public int addConditionalFormatting(CellRangeAddress[] regions, ConditionalFormattingRule[] cfRules) {
|
public int addConditionalFormatting(CellRangeAddress[] regions, ConditionalFormattingRule[] cfRules) {
|
||||||
if (regions == null) {
|
if (regions == null) {
|
||||||
throw new IllegalArgumentException("regions must not be null");
|
throw new IllegalArgumentException("regions must not be null");
|
||||||
@ -130,21 +131,15 @@ public class XSSFSheetConditionalFormatting implements SheetConditionalFormattin
|
|||||||
if (cfRules.length > 3) {
|
if (cfRules.length > 3) {
|
||||||
throw new IllegalArgumentException("Number of rules must not exceed 3");
|
throw new IllegalArgumentException("Number of rules must not exceed 3");
|
||||||
}
|
}
|
||||||
XSSFConditionalFormattingRule[] hfRules;
|
|
||||||
if(cfRules instanceof XSSFConditionalFormattingRule[]) hfRules = (XSSFConditionalFormattingRule[])cfRules;
|
|
||||||
else {
|
|
||||||
hfRules = new XSSFConditionalFormattingRule[cfRules.length];
|
|
||||||
System.arraycopy(cfRules, 0, hfRules, 0, hfRules.length);
|
|
||||||
}
|
|
||||||
CellRangeAddress[] mergeCellRanges = CellRangeUtil.mergeCellRanges(regions);
|
CellRangeAddress[] mergeCellRanges = CellRangeUtil.mergeCellRanges(regions);
|
||||||
CTConditionalFormatting cf = _sheet.getCTWorksheet().addNewConditionalFormatting();
|
CTConditionalFormatting cf = _sheet.getCTWorksheet().addNewConditionalFormatting();
|
||||||
List<String> refs = new ArrayList<String>();
|
List<String> refs = new ArrayList<String>();
|
||||||
for(CellRangeAddress a : mergeCellRanges) refs.add(a.formatAsString());
|
for(CellRangeAddress a : mergeCellRanges) refs.add(a.formatAsString());
|
||||||
cf.setSqref(refs);
|
cf.setSqref(refs);
|
||||||
|
|
||||||
|
|
||||||
int priority = 1;
|
int priority = 1;
|
||||||
for(CTConditionalFormatting c : _sheet.getCTWorksheet().getConditionalFormattingList()){
|
for(CTConditionalFormatting c : _sheet.getCTWorksheet().getConditionalFormattingArray()){
|
||||||
priority += c.sizeOfCfRuleArray();
|
priority += c.sizeOfCfRuleArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -220,7 +215,7 @@ public class XSSFSheetConditionalFormatting implements SheetConditionalFormattin
|
|||||||
*/
|
*/
|
||||||
public void removeConditionalFormatting(int index) {
|
public void removeConditionalFormatting(int index) {
|
||||||
checkIndex(index);
|
checkIndex(index);
|
||||||
_sheet.getCTWorksheet().getConditionalFormattingList().remove(index);
|
_sheet.getCTWorksheet().removeConditionalFormatting(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkIndex(int index) {
|
private void checkIndex(int index) {
|
||||||
|
@ -128,13 +128,14 @@ public class XSSFTable extends POIXMLDocumentPart {
|
|||||||
*
|
*
|
||||||
* @return the xpath of the table's root element
|
* @return the xpath of the table's root element
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public String getCommonXpath() {
|
public String getCommonXpath() {
|
||||||
|
|
||||||
if(commonXPath == null){
|
if(commonXPath == null){
|
||||||
|
|
||||||
String[] commonTokens ={};
|
String[] commonTokens ={};
|
||||||
|
|
||||||
for(CTTableColumn column :ctTable.getTableColumns().getTableColumnList()){
|
for(CTTableColumn column :ctTable.getTableColumns().getTableColumnArray()){
|
||||||
if(column.getXmlColumnPr()!=null){
|
if(column.getXmlColumnPr()!=null){
|
||||||
String xpath = column.getXmlColumnPr().getXpath();
|
String xpath = column.getXmlColumnPr().getXpath();
|
||||||
String[] tokens = xpath.split("/");
|
String[] tokens = xpath.split("/");
|
||||||
@ -173,11 +174,12 @@ public class XSSFTable extends POIXMLDocumentPart {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public List<XSSFXmlColumnPr> getXmlColumnPrs() {
|
public List<XSSFXmlColumnPr> getXmlColumnPrs() {
|
||||||
|
|
||||||
if(xmlColumnPr==null){
|
if(xmlColumnPr==null){
|
||||||
xmlColumnPr = new ArrayList<XSSFXmlColumnPr>();
|
xmlColumnPr = new ArrayList<XSSFXmlColumnPr>();
|
||||||
for (CTTableColumn column:ctTable.getTableColumns().getTableColumnList()){
|
for (CTTableColumn column:ctTable.getTableColumns().getTableColumnArray()){
|
||||||
if (column.getXmlColumnPr()!=null){
|
if (column.getXmlColumnPr()!=null){
|
||||||
XSSFXmlColumnPr columnPr = new XSSFXmlColumnPr(this,column,column.getXmlColumnPr());
|
XSSFXmlColumnPr columnPr = new XSSFXmlColumnPr(this,column,column.getXmlColumnPr());
|
||||||
xmlColumnPr.add(columnPr);
|
xmlColumnPr.add(columnPr);
|
||||||
@ -285,6 +287,7 @@ public class XSSFTable extends POIXMLDocumentPart {
|
|||||||
* Headers <em>must</em> be in sync, otherwise Excel will display a
|
* Headers <em>must</em> be in sync, otherwise Excel will display a
|
||||||
* "Found unreadable content" message on startup.
|
* "Found unreadable content" message on startup.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public void updateHeaders(){
|
public void updateHeaders(){
|
||||||
XSSFSheet sheet = (XSSFSheet)getParent();
|
XSSFSheet sheet = (XSSFSheet)getParent();
|
||||||
CellReference ref = getStartCellReference();
|
CellReference ref = getStartCellReference();
|
||||||
@ -296,7 +299,7 @@ public class XSSFTable extends POIXMLDocumentPart {
|
|||||||
|
|
||||||
if (row != null && row.getCTRow().validate()) {
|
if (row != null && row.getCTRow().validate()) {
|
||||||
int cellnum = firstHeaderColumn;
|
int cellnum = firstHeaderColumn;
|
||||||
for (CTTableColumn col : getCTTable().getTableColumns().getTableColumnList()) {
|
for (CTTableColumn col : getCTTable().getTableColumns().getTableColumnArray()) {
|
||||||
XSSFCell cell = row.getCell(cellnum);
|
XSSFCell cell = row.getCell(cellnum);
|
||||||
if (cell != null) {
|
if (cell != null) {
|
||||||
col.setName(cell.getStringCellValue());
|
col.setName(cell.getStringCellValue());
|
||||||
|
@ -17,6 +17,9 @@
|
|||||||
|
|
||||||
package org.apache.poi.xssf.usermodel;
|
package org.apache.poi.xssf.usermodel;
|
||||||
|
|
||||||
|
import static org.apache.poi.xssf.usermodel.helpers.XSSFPaswordHelper.setPassword;
|
||||||
|
import static org.apache.poi.xssf.usermodel.helpers.XSSFPaswordHelper.validatePassword;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -47,6 +50,7 @@ import org.apache.poi.openxml4j.opc.PackageRelationship;
|
|||||||
import org.apache.poi.openxml4j.opc.PackageRelationshipTypes;
|
import org.apache.poi.openxml4j.opc.PackageRelationshipTypes;
|
||||||
import org.apache.poi.openxml4j.opc.PackagingURIHelper;
|
import org.apache.poi.openxml4j.opc.PackagingURIHelper;
|
||||||
import org.apache.poi.openxml4j.opc.TargetMode;
|
import org.apache.poi.openxml4j.opc.TargetMode;
|
||||||
|
import org.apache.poi.poifs.crypt.HashAlgorithm;
|
||||||
import org.apache.poi.ss.formula.SheetNameFormatter;
|
import org.apache.poi.ss.formula.SheetNameFormatter;
|
||||||
import org.apache.poi.ss.formula.udf.IndexedUDFFinder;
|
import org.apache.poi.ss.formula.udf.IndexedUDFFinder;
|
||||||
import org.apache.poi.ss.formula.udf.UDFFinder;
|
import org.apache.poi.ss.formula.udf.UDFFinder;
|
||||||
@ -1366,6 +1370,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
|
|||||||
* @param pos the position that we want to insert the sheet into (0 based)
|
* @param pos the position that we want to insert the sheet into (0 based)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public void setSheetOrder(String sheetname, int pos) {
|
public void setSheetOrder(String sheetname, int pos) {
|
||||||
int idx = getSheetIndex(sheetname);
|
int idx = getSheetIndex(sheetname);
|
||||||
sheets.add(pos, sheets.remove(idx));
|
sheets.add(pos, sheets.remove(idx));
|
||||||
@ -1377,8 +1382,9 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
|
|||||||
newcts.set(cts);
|
newcts.set(cts);
|
||||||
|
|
||||||
//notify sheets
|
//notify sheets
|
||||||
for(int i=0; i < sheets.size(); i++) {
|
CTSheet[] sheetArray = ct.getSheetArray();
|
||||||
sheets.get(i).sheet = ct.getSheetArray(i);
|
for(int i=0; i < sheetArray.length; i++) {
|
||||||
|
sheets.get(i).sheet = sheetArray[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1410,10 +1416,11 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
private void reprocessNamedRanges() {
|
private void reprocessNamedRanges() {
|
||||||
namedRanges = new ArrayList<XSSFName>();
|
namedRanges = new ArrayList<XSSFName>();
|
||||||
if(workbook.isSetDefinedNames()) {
|
if(workbook.isSetDefinedNames()) {
|
||||||
for(CTDefinedName ctName : workbook.getDefinedNames().getDefinedNameList()) {
|
for(CTDefinedName ctName : workbook.getDefinedNames().getDefinedNameArray()) {
|
||||||
namedRanges.add(new XSSFName(ctName, this));
|
namedRanges.add(new XSSFName(ctName, this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1735,60 +1742,108 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
|
|||||||
* Locks the structure of workbook.
|
* Locks the structure of workbook.
|
||||||
*/
|
*/
|
||||||
public void lockStructure() {
|
public void lockStructure() {
|
||||||
createProtectionFieldIfNotPresent();
|
safeGetWorkbookProtection().setLockStructure(true);
|
||||||
workbook.getWorkbookProtection().setLockStructure(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unlocks the structure of workbook.
|
* Unlocks the structure of workbook.
|
||||||
*/
|
*/
|
||||||
public void unLockStructure() {
|
public void unLockStructure() {
|
||||||
createProtectionFieldIfNotPresent();
|
safeGetWorkbookProtection().setLockStructure(false);
|
||||||
workbook.getWorkbookProtection().setLockStructure(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Locks the windows that comprise the workbook.
|
* Locks the windows that comprise the workbook.
|
||||||
*/
|
*/
|
||||||
public void lockWindows() {
|
public void lockWindows() {
|
||||||
createProtectionFieldIfNotPresent();
|
safeGetWorkbookProtection().setLockWindows(true);
|
||||||
workbook.getWorkbookProtection().setLockWindows(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unlocks the windows that comprise the workbook.
|
* Unlocks the windows that comprise the workbook.
|
||||||
*/
|
*/
|
||||||
public void unLockWindows() {
|
public void unLockWindows() {
|
||||||
createProtectionFieldIfNotPresent();
|
safeGetWorkbookProtection().setLockWindows(false);
|
||||||
workbook.getWorkbookProtection().setLockWindows(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Locks the workbook for revisions.
|
* Locks the workbook for revisions.
|
||||||
*/
|
*/
|
||||||
public void lockRevision() {
|
public void lockRevision() {
|
||||||
createProtectionFieldIfNotPresent();
|
safeGetWorkbookProtection().setLockRevision(true);
|
||||||
workbook.getWorkbookProtection().setLockRevision(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unlocks the workbook for revisions.
|
* Unlocks the workbook for revisions.
|
||||||
*/
|
*/
|
||||||
public void unLockRevision() {
|
public void unLockRevision() {
|
||||||
createProtectionFieldIfNotPresent();
|
safeGetWorkbookProtection().setLockRevision(false);
|
||||||
workbook.getWorkbookProtection().setLockRevision(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the workbook password.
|
||||||
|
*
|
||||||
|
* @param password if null, the password will be removed
|
||||||
|
* @param hashAlgo if null, the password will be set as XOR password (Excel 2010 and earlier)
|
||||||
|
* otherwise the given algorithm is used for calculating the hash password (Excel 2013)
|
||||||
|
*/
|
||||||
|
public void setWorkbookPassword(String password, HashAlgorithm hashAlgo) {
|
||||||
|
if (password == null && !workbookProtectionPresent()) return;
|
||||||
|
setPassword(safeGetWorkbookProtection(), password, hashAlgo, "workbook");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate the password against the stored hash, the hashing method will be determined
|
||||||
|
* by the existing password attributes
|
||||||
|
* @return true, if the hashes match (... though original password may differ ...)
|
||||||
|
*/
|
||||||
|
public boolean validateWorkbookPassword(String password) {
|
||||||
|
if (!workbookProtectionPresent()) return (password == null);
|
||||||
|
return validatePassword(safeGetWorkbookProtection(), password, "workbook");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the revisions password.
|
||||||
|
*
|
||||||
|
* @param password if null, the password will be removed
|
||||||
|
* @param hashAlgo if null, the password will be set as XOR password (Excel 2010 and earlier)
|
||||||
|
* otherwise the given algorithm is used for calculating the hash password (Excel 2013)
|
||||||
|
*/
|
||||||
|
public void setRevisionsPassword(String password, HashAlgorithm hashAlgo) {
|
||||||
|
if (password == null && !workbookProtectionPresent()) return;
|
||||||
|
setPassword(safeGetWorkbookProtection(), password, hashAlgo, "revisions");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate the password against the stored hash, the hashing method will be determined
|
||||||
|
* by the existing password attributes
|
||||||
|
* @return true if the hashes match (... though original password may differ ...)
|
||||||
|
*/
|
||||||
|
public boolean validateRevisionsPassword(String password) {
|
||||||
|
if (!workbookProtectionPresent()) return (password == null);
|
||||||
|
return validatePassword(safeGetWorkbookProtection(), password, "revisions");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes the workbook protection settings
|
||||||
|
*/
|
||||||
|
public void unLock() {
|
||||||
|
if (workbookProtectionPresent()) {
|
||||||
|
workbook.unsetWorkbookProtection();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private boolean workbookProtectionPresent() {
|
private boolean workbookProtectionPresent() {
|
||||||
return workbook.getWorkbookProtection() != null;
|
return workbook.isSetWorkbookProtection();
|
||||||
}
|
|
||||||
|
|
||||||
private void createProtectionFieldIfNotPresent() {
|
|
||||||
if (workbook.getWorkbookProtection() == null){
|
|
||||||
workbook.setWorkbookProtection(CTWorkbookProtection.Factory.newInstance());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private CTWorkbookProtection safeGetWorkbookProtection() {
|
||||||
|
if (!workbookProtectionPresent()){
|
||||||
|
return workbook.addNewWorkbookProtection();
|
||||||
|
}
|
||||||
|
return workbook.getWorkbookProtection();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Returns the locator of user-defined functions.
|
* Returns the locator of user-defined functions.
|
||||||
|
@ -19,7 +19,6 @@ package org.apache.poi.xssf.usermodel.helpers;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -50,52 +49,39 @@ public class ColumnHelper {
|
|||||||
cleanColumns();
|
cleanColumns();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public void cleanColumns() {
|
public void cleanColumns() {
|
||||||
this.newCols = CTCols.Factory.newInstance();
|
this.newCols = CTCols.Factory.newInstance();
|
||||||
|
|
||||||
CTCols aggregateCols = CTCols.Factory.newInstance();
|
CTCols aggregateCols = CTCols.Factory.newInstance();
|
||||||
List<CTCols> colsList = worksheet.getColsList();
|
CTCols[] colsArray = worksheet.getColsArray();
|
||||||
assert(colsList != null);
|
assert(colsArray != null);
|
||||||
|
|
||||||
for (CTCols cols : colsList) {
|
for (CTCols cols : colsArray) {
|
||||||
for (CTCol col : cols.getColList()) {
|
for (CTCol col : cols.getColArray()) {
|
||||||
cloneCol(aggregateCols, col);
|
cloneCol(aggregateCols, col);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sortColumns(aggregateCols);
|
sortColumns(aggregateCols);
|
||||||
|
|
||||||
CTCol[] colArray = new CTCol[aggregateCols.getColList().size()];
|
CTCol[] colArray = aggregateCols.getColArray();
|
||||||
aggregateCols.getColList().toArray(colArray);
|
|
||||||
sweepCleanColumns(newCols, colArray, null);
|
sweepCleanColumns(newCols, colArray, null);
|
||||||
|
|
||||||
int i = colsList.size();
|
int i = colsArray.length;
|
||||||
for (int y = i - 1; y >= 0; y--) {
|
for (int y = i - 1; y >= 0; y--) {
|
||||||
worksheet.removeCols(y);
|
worksheet.removeCols(y);
|
||||||
}
|
}
|
||||||
worksheet.addNewCols();
|
worksheet.addNewCols();
|
||||||
worksheet.setColsArray(0, newCols);
|
worksheet.setColsArray(0, newCols);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class CTColByMaxComparator implements Comparator<CTCol> {
|
|
||||||
|
|
||||||
public int compare(CTCol arg0, CTCol arg1) {
|
|
||||||
if (arg0.getMax() < arg1.getMax()) {
|
|
||||||
return -1;
|
|
||||||
} else {
|
|
||||||
if (arg0.getMax() > arg1.getMax()) return 1;
|
|
||||||
else return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see <a href="http://en.wikipedia.org/wiki/Sweep_line_algorithm">Sweep line algorithm</a>
|
* @see <a href="http://en.wikipedia.org/wiki/Sweep_line_algorithm">Sweep line algorithm</a>
|
||||||
*/
|
*/
|
||||||
private void sweepCleanColumns(CTCols cols, CTCol[] flattenedColsArray, CTCol overrideColumn) {
|
private void sweepCleanColumns(CTCols cols, CTCol[] flattenedColsArray, CTCol overrideColumn) {
|
||||||
List<CTCol> flattenedCols = new ArrayList<CTCol>(Arrays.asList(flattenedColsArray));
|
List<CTCol> flattenedCols = new ArrayList<CTCol>(Arrays.asList(flattenedColsArray));
|
||||||
TreeSet<CTCol> currentElements = new TreeSet<CTCol>(new CTColByMaxComparator());
|
TreeSet<CTCol> currentElements = new TreeSet<CTCol>(CTColComparator.BY_MAX);
|
||||||
ListIterator<CTCol> flIter = flattenedCols.listIterator();
|
ListIterator<CTCol> flIter = flattenedCols.listIterator();
|
||||||
CTCol haveOverrideColumn = null;
|
CTCol haveOverrideColumn = null;
|
||||||
long lastMaxIndex = 0;
|
long lastMaxIndex = 0;
|
||||||
@ -103,7 +89,8 @@ public class ColumnHelper {
|
|||||||
while (flIter.hasNext()) {
|
while (flIter.hasNext()) {
|
||||||
CTCol col = flIter.next();
|
CTCol col = flIter.next();
|
||||||
long currentIndex = col.getMin();
|
long currentIndex = col.getMin();
|
||||||
long nextIndex = (col.getMax() > currentMax) ? col.getMax() : currentMax;
|
long colMax = col.getMax();
|
||||||
|
long nextIndex = (colMax > currentMax) ? colMax : currentMax;
|
||||||
if (flIter.hasNext()) {
|
if (flIter.hasNext()) {
|
||||||
nextIndex = flIter.next().getMin();
|
nextIndex = flIter.next().getMin();
|
||||||
flIter.previous();
|
flIter.previous();
|
||||||
@ -116,10 +103,10 @@ public class ColumnHelper {
|
|||||||
}
|
}
|
||||||
if (!currentElements.isEmpty() && lastMaxIndex < currentIndex) {
|
if (!currentElements.isEmpty() && lastMaxIndex < currentIndex) {
|
||||||
// we need to process previous elements first
|
// we need to process previous elements first
|
||||||
insertCol(cols, lastMaxIndex, currentIndex - 1, currentElements.toArray(new CTCol[]{}), true, haveOverrideColumn);
|
insertCol(cols, lastMaxIndex, currentIndex - 1, currentElements.toArray(new CTCol[currentElements.size()]), true, haveOverrideColumn);
|
||||||
}
|
}
|
||||||
currentElements.add(col);
|
currentElements.add(col);
|
||||||
if (col.getMax() > currentMax) currentMax = col.getMax();
|
if (colMax > currentMax) currentMax = colMax;
|
||||||
if (col.equals(overrideColumn)) haveOverrideColumn = overrideColumn;
|
if (col.equals(overrideColumn)) haveOverrideColumn = overrideColumn;
|
||||||
while (currentIndex <= nextIndex && !currentElements.isEmpty()) {
|
while (currentIndex <= nextIndex && !currentElements.isEmpty()) {
|
||||||
Set<CTCol> currentIndexElements = new HashSet<CTCol>();
|
Set<CTCol> currentIndexElements = new HashSet<CTCol>();
|
||||||
@ -130,26 +117,21 @@ public class ColumnHelper {
|
|||||||
CTCol currentElem = currentElements.first();
|
CTCol currentElem = currentElements.first();
|
||||||
currentElemIndex = currentElem.getMax();
|
currentElemIndex = currentElem.getMax();
|
||||||
currentIndexElements.add(currentElem);
|
currentIndexElements.add(currentElem);
|
||||||
|
|
||||||
for (CTCol cc : currentElements.tailSet(currentElem)) {
|
while (true) {
|
||||||
if (cc == null || cc.getMax() == currentElemIndex) break;
|
CTCol higherElem = currentElements.higher(currentElem);
|
||||||
currentIndexElements.add(cc);
|
if (higherElem == null || higherElem.getMax() != currentElemIndex)
|
||||||
if (col.getMax() > currentMax) currentMax = col.getMax();
|
break;
|
||||||
|
currentElem = higherElem;
|
||||||
|
currentIndexElements.add(currentElem);
|
||||||
|
if (colMax > currentMax) currentMax = colMax;
|
||||||
if (col.equals(overrideColumn)) haveOverrideColumn = overrideColumn;
|
if (col.equals(overrideColumn)) haveOverrideColumn = overrideColumn;
|
||||||
}
|
}
|
||||||
|
|
||||||
// JDK 6 code
|
|
||||||
// while (currentElements.higher(currentElem) != null && currentElements.higher(currentElem).getMax() == currentElemIndex) {
|
|
||||||
// currentElem = currentElements.higher(currentElem);
|
|
||||||
// currentIndexElements.add(currentElem);
|
|
||||||
// if (col.getMax() > currentMax) currentMax = col.getMax();
|
|
||||||
// if (col.equals(overrideColumn)) haveOverrideColumn = overrideColumn;
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (currentElemIndex < nextIndex || !flIter.hasNext()) {
|
if (currentElemIndex < nextIndex || !flIter.hasNext()) {
|
||||||
insertCol(cols, currentIndex, currentElemIndex, currentElements.toArray(new CTCol[]{}), true, haveOverrideColumn);
|
insertCol(cols, currentIndex, currentElemIndex, currentElements.toArray(new CTCol[currentElements.size()]), true, haveOverrideColumn);
|
||||||
if (flIter.hasNext()) {
|
if (flIter.hasNext()) {
|
||||||
if (nextIndex > currentElemIndex) {
|
if (nextIndex > currentElemIndex) {
|
||||||
currentElements.removeAll(currentIndexElements);
|
currentElements.removeAll(currentIndexElements);
|
||||||
@ -170,10 +152,10 @@ public class ColumnHelper {
|
|||||||
sortColumns(cols);
|
sortColumns(cols);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public static void sortColumns(CTCols newCols) {
|
public static void sortColumns(CTCols newCols) {
|
||||||
CTCol[] colArray = new CTCol[newCols.getColList().size()];
|
CTCol[] colArray = newCols.getColArray();
|
||||||
newCols.getColList().toArray(colArray);
|
Arrays.sort(colArray, CTColComparator.BY_MIN_MAX);
|
||||||
Arrays.sort(colArray, new CTColComparator());
|
|
||||||
newCols.setColArray(colArray);
|
newCols.setColArray(colArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -198,46 +180,46 @@ public class ColumnHelper {
|
|||||||
* as 1 based.
|
* as 1 based.
|
||||||
*/
|
*/
|
||||||
public CTCol getColumn1Based(long index1, boolean splitColumns) {
|
public CTCol getColumn1Based(long index1, boolean splitColumns) {
|
||||||
CTCols colsArray = worksheet.getColsArray(0);
|
CTCols cols = worksheet.getColsArray(0);
|
||||||
|
|
||||||
// Fetching the array is quicker than working on the new style
|
// Fetching the array is quicker than working on the new style
|
||||||
// list, assuming we need to read many of them (which we often do),
|
// list, assuming we need to read many of them (which we often do),
|
||||||
// and assuming we're not making many changes (which we're not)
|
// and assuming we're not making many changes (which we're not)
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
CTCol[] cols = colsArray.getColArray();
|
CTCol[] colArray = cols.getColArray();
|
||||||
|
|
||||||
for (int i = 0; i < cols.length; i++) {
|
for (CTCol col : colArray) {
|
||||||
CTCol colArray = cols[i];
|
long colMin = col.getMin();
|
||||||
if (colArray.getMin() <= index1 && colArray.getMax() >= index1) {
|
long colMax = col.getMax();
|
||||||
|
if (colMin <= index1 && colMax >= index1) {
|
||||||
if (splitColumns) {
|
if (splitColumns) {
|
||||||
if (colArray.getMin() < index1) {
|
if (colMin < index1) {
|
||||||
insertCol(colsArray, colArray.getMin(), (index1 - 1), new CTCol[]{colArray});
|
insertCol(cols, colMin, (index1 - 1), new CTCol[]{col});
|
||||||
}
|
}
|
||||||
if (colArray.getMax() > index1) {
|
if (colMax > index1) {
|
||||||
insertCol(colsArray, (index1 + 1), colArray.getMax(), new CTCol[]{colArray});
|
insertCol(cols, (index1 + 1), colMax, new CTCol[]{col});
|
||||||
}
|
}
|
||||||
colArray.setMin(index1);
|
col.setMin(index1);
|
||||||
colArray.setMax(index1);
|
col.setMax(index1);
|
||||||
}
|
}
|
||||||
return colArray;
|
return col;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public CTCols addCleanColIntoCols(CTCols cols, CTCol col) {
|
public CTCols addCleanColIntoCols(CTCols cols, CTCol col) {
|
||||||
CTCols newCols = CTCols.Factory.newInstance();
|
CTCols newCols = CTCols.Factory.newInstance();
|
||||||
for (CTCol c : cols.getColList()) {
|
for (CTCol c : cols.getColArray()) {
|
||||||
cloneCol(newCols, c);
|
cloneCol(newCols, c);
|
||||||
}
|
}
|
||||||
cloneCol(newCols, col);
|
cloneCol(newCols, col);
|
||||||
sortColumns(newCols);
|
sortColumns(newCols);
|
||||||
CTCol[] colArray = new CTCol[newCols.getColList().size()];
|
CTCol[] colArray = newCols.getColArray();
|
||||||
newCols.getColList().toArray(colArray);
|
|
||||||
CTCols returnCols = CTCols.Factory.newInstance();
|
CTCols returnCols = CTCols.Factory.newInstance();
|
||||||
sweepCleanColumns(returnCols, colArray, col);
|
sweepCleanColumns(returnCols, colArray, col);
|
||||||
colArray = new CTCol[returnCols.getColList().size()];
|
colArray = returnCols.getColArray();
|
||||||
returnCols.getColList().toArray(colArray);
|
|
||||||
cols.setColArray(colArray);
|
cols.setColArray(colArray);
|
||||||
return returnCols;
|
return returnCols;
|
||||||
}
|
}
|
||||||
@ -272,9 +254,11 @@ public class ColumnHelper {
|
|||||||
public boolean columnExists(CTCols cols, long index) {
|
public boolean columnExists(CTCols cols, long index) {
|
||||||
return columnExists1Based(cols, index+1);
|
return columnExists1Based(cols, index+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
private boolean columnExists1Based(CTCols cols, long index1) {
|
private boolean columnExists1Based(CTCols cols, long index1) {
|
||||||
for (int i = 0; i < cols.sizeOfColArray(); i++) {
|
for (CTCol col : cols.getColArray()) {
|
||||||
if (cols.getColArray(i).getMin() == index1) {
|
if (col.getMin() == index1) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -343,20 +327,24 @@ public class ColumnHelper {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
private boolean columnExists(CTCols cols, long min, long max) {
|
private boolean columnExists(CTCols cols, long min, long max) {
|
||||||
for (int i = 0; i < cols.sizeOfColArray(); i++) {
|
for (CTCol col : cols.getColArray()) {
|
||||||
if (cols.getColArray(i).getMin() == min && cols.getColArray(i).getMax() == max) {
|
if (col.getMin() == min && col.getMax() == max) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getIndexOfColumn(CTCols cols, CTCol col) {
|
@SuppressWarnings("deprecation")
|
||||||
for (int i = 0; i < cols.sizeOfColArray(); i++) {
|
public int getIndexOfColumn(CTCols cols, CTCol searchCol) {
|
||||||
if (cols.getColArray(i).getMin() == col.getMin() && cols.getColArray(i).getMax() == col.getMax()) {
|
int i = 0;
|
||||||
|
for (CTCol col : cols.getColArray()) {
|
||||||
|
if (col.getMin() == searchCol.getMin() && col.getMax() == searchCol.getMax()) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,128 @@
|
|||||||
|
/*
|
||||||
|
* ====================================================================
|
||||||
|
* 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.xssf.usermodel.helpers;
|
||||||
|
|
||||||
|
import java.security.SecureRandom;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import javax.xml.bind.DatatypeConverter;
|
||||||
|
import javax.xml.namespace.QName;
|
||||||
|
|
||||||
|
import org.apache.poi.poifs.crypt.CryptoFunctions;
|
||||||
|
import org.apache.poi.poifs.crypt.HashAlgorithm;
|
||||||
|
import org.apache.xmlbeans.XmlCursor;
|
||||||
|
import org.apache.xmlbeans.XmlObject;
|
||||||
|
|
||||||
|
public class XSSFPaswordHelper {
|
||||||
|
/**
|
||||||
|
* Sets the XORed or hashed password
|
||||||
|
*
|
||||||
|
* @param xobj the xmlbeans object which contains the password attributes
|
||||||
|
* @param password the password, if null, the password attributes will be removed
|
||||||
|
* @param hashAlgo the hash algorithm, if null the password will be XORed
|
||||||
|
* @param prefix the prefix of the password attributes, may be null
|
||||||
|
*/
|
||||||
|
public static void setPassword(XmlObject xobj, String password, HashAlgorithm hashAlgo, String prefix) {
|
||||||
|
XmlCursor cur = xobj.newCursor();
|
||||||
|
|
||||||
|
if (password == null) {
|
||||||
|
cur.removeAttribute(getAttrName(prefix, "password"));
|
||||||
|
cur.removeAttribute(getAttrName(prefix, "algorithmName"));
|
||||||
|
cur.removeAttribute(getAttrName(prefix, "hashValue"));
|
||||||
|
cur.removeAttribute(getAttrName(prefix, "saltValue"));
|
||||||
|
cur.removeAttribute(getAttrName(prefix, "spinCount"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
cur.toFirstContentToken();
|
||||||
|
if (hashAlgo == null) {
|
||||||
|
int hash = CryptoFunctions.createXorVerifier1(password);
|
||||||
|
cur.insertAttributeWithValue(getAttrName(prefix, "password"), Integer.toHexString(hash).toUpperCase());
|
||||||
|
} else {
|
||||||
|
SecureRandom random = new SecureRandom();
|
||||||
|
byte salt[] = random.generateSeed(16);
|
||||||
|
|
||||||
|
// Iterations specifies the number of times the hashing function shall be iteratively run (using each
|
||||||
|
// iteration's result as the input for the next iteration).
|
||||||
|
int spinCount = 100000;
|
||||||
|
|
||||||
|
// Implementation Notes List:
|
||||||
|
// --> In this third stage, the reversed byte order legacy hash from the second stage shall
|
||||||
|
// be converted to Unicode hex string representation
|
||||||
|
byte hash[] = CryptoFunctions.hashPassword(password, hashAlgo, salt, spinCount, false);
|
||||||
|
|
||||||
|
cur.insertAttributeWithValue(getAttrName(prefix, "algorithmName"), hashAlgo.jceId);
|
||||||
|
cur.insertAttributeWithValue(getAttrName(prefix, "hashValue"), DatatypeConverter.printBase64Binary(hash));
|
||||||
|
cur.insertAttributeWithValue(getAttrName(prefix, "saltValue"), DatatypeConverter.printBase64Binary(salt));
|
||||||
|
cur.insertAttributeWithValue(getAttrName(prefix, "spinCount"), ""+spinCount);
|
||||||
|
}
|
||||||
|
cur.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validates the password, i.e.
|
||||||
|
* calculates the hash of the given password and compares it against the stored hash
|
||||||
|
*
|
||||||
|
* @param xobj the xmlbeans object which contains the password attributes
|
||||||
|
* @param password the password, if null the method will always return false,
|
||||||
|
* even if there's no password set
|
||||||
|
* @param prefix the prefix of the password attributes, may be null
|
||||||
|
*
|
||||||
|
* @return true, if the hashes match
|
||||||
|
*/
|
||||||
|
public static boolean validatePassword(XmlObject xobj, String password, String prefix) {
|
||||||
|
// TODO: is "velvetSweatshop" the default password?
|
||||||
|
if (password == null) return false;
|
||||||
|
|
||||||
|
XmlCursor cur = xobj.newCursor();
|
||||||
|
String xorHashVal = cur.getAttributeText(getAttrName(prefix, "password"));
|
||||||
|
String algoName = cur.getAttributeText(getAttrName(prefix, "algorithmName"));
|
||||||
|
String hashVal = cur.getAttributeText(getAttrName(prefix, "hashValue"));
|
||||||
|
String saltVal = cur.getAttributeText(getAttrName(prefix, "saltValue"));
|
||||||
|
String spinCount = cur.getAttributeText(getAttrName(prefix, "spinCount"));
|
||||||
|
cur.dispose();
|
||||||
|
|
||||||
|
if (xorHashVal != null) {
|
||||||
|
int hash1 = Integer.parseInt(xorHashVal, 16);
|
||||||
|
int hash2 = CryptoFunctions.createXorVerifier1(password);
|
||||||
|
return hash1 == hash2;
|
||||||
|
} else {
|
||||||
|
if (hashVal == null || algoName == null || saltVal == null || spinCount == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
byte hash1[] = DatatypeConverter.parseBase64Binary(hashVal);
|
||||||
|
HashAlgorithm hashAlgo = HashAlgorithm.fromString(algoName);
|
||||||
|
byte salt[] = DatatypeConverter.parseBase64Binary(saltVal);
|
||||||
|
int spinCnt = Integer.parseInt(spinCount);
|
||||||
|
byte hash2[] = CryptoFunctions.hashPassword(password, hashAlgo, salt, spinCnt, false);
|
||||||
|
return Arrays.equals(hash1, hash2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static QName getAttrName(String prefix, String name) {
|
||||||
|
if (prefix == null || "".equals(prefix)) {
|
||||||
|
return new QName(name);
|
||||||
|
} else {
|
||||||
|
return new QName(prefix+Character.toUpperCase(name.charAt(0))+name.substring(1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -18,7 +18,9 @@
|
|||||||
package org.apache.poi.xssf.usermodel.helpers;
|
package org.apache.poi.xssf.usermodel.helpers;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.poi.ss.formula.FormulaParseException;
|
import org.apache.poi.ss.formula.FormulaParseException;
|
||||||
import org.apache.poi.ss.formula.FormulaParser;
|
import org.apache.poi.ss.formula.FormulaParser;
|
||||||
@ -43,6 +45,7 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCell;
|
|||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellFormula;
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellFormula;
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCfRule;
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCfRule;
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTConditionalFormatting;
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTConditionalFormatting;
|
||||||
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STCellFormulaType;
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STCellFormulaType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -66,8 +69,10 @@ public final class XSSFRowShifter {
|
|||||||
*/
|
*/
|
||||||
public List<CellRangeAddress> shiftMerged(int startRow, int endRow, int n) {
|
public List<CellRangeAddress> shiftMerged(int startRow, int endRow, int n) {
|
||||||
List<CellRangeAddress> shiftedRegions = new ArrayList<CellRangeAddress>();
|
List<CellRangeAddress> shiftedRegions = new ArrayList<CellRangeAddress>();
|
||||||
|
Set<Integer> removedIndices = new HashSet<Integer>();
|
||||||
//move merged regions completely if they fall within the new region boundaries when they are shifted
|
//move merged regions completely if they fall within the new region boundaries when they are shifted
|
||||||
for (int i = 0; i < sheet.getNumMergedRegions(); i++) {
|
int size = sheet.getNumMergedRegions();
|
||||||
|
for (int i = 0; i < size; i++) {
|
||||||
CellRangeAddress merged = sheet.getMergedRegion(i);
|
CellRangeAddress merged = sheet.getMergedRegion(i);
|
||||||
|
|
||||||
boolean inStart = (merged.getFirstRow() >= startRow || merged.getLastRow() >= startRow);
|
boolean inStart = (merged.getFirstRow() >= startRow || merged.getLastRow() >= startRow);
|
||||||
@ -84,10 +89,13 @@ public final class XSSFRowShifter {
|
|||||||
merged.setLastRow(merged.getLastRow() + n);
|
merged.setLastRow(merged.getLastRow() + n);
|
||||||
//have to remove/add it back
|
//have to remove/add it back
|
||||||
shiftedRegions.add(merged);
|
shiftedRegions.add(merged);
|
||||||
sheet.removeMergedRegion(i);
|
removedIndices.add(i);
|
||||||
i = i - 1; // we have to back up now since we removed one
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!removedIndices.isEmpty()) {
|
||||||
|
sheet.removeMergedRegions(removedIndices);
|
||||||
|
}
|
||||||
|
|
||||||
//read so it doesn't get shifted again
|
//read so it doesn't get shifted again
|
||||||
for (CellRangeAddress region : shiftedRegions) {
|
for (CellRangeAddress region : shiftedRegions) {
|
||||||
@ -213,28 +221,29 @@ public final class XSSFRowShifter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public void updateConditionalFormatting(FormulaShifter shifter) {
|
public void updateConditionalFormatting(FormulaShifter shifter) {
|
||||||
XSSFWorkbook wb = sheet.getWorkbook();
|
XSSFWorkbook wb = sheet.getWorkbook();
|
||||||
int sheetIndex = wb.getSheetIndex(sheet);
|
int sheetIndex = wb.getSheetIndex(sheet);
|
||||||
|
|
||||||
|
|
||||||
XSSFEvaluationWorkbook fpb = XSSFEvaluationWorkbook.create(wb);
|
XSSFEvaluationWorkbook fpb = XSSFEvaluationWorkbook.create(wb);
|
||||||
List<CTConditionalFormatting> cfList = sheet.getCTWorksheet().getConditionalFormattingList();
|
CTWorksheet ctWorksheet = sheet.getCTWorksheet();
|
||||||
for(int j = 0; j< cfList.size(); j++){
|
CTConditionalFormatting[] conditionalFormattingArray = ctWorksheet.getConditionalFormattingArray();
|
||||||
CTConditionalFormatting cf = cfList.get(j);
|
// iterate backwards due to possible calls to ctWorksheet.removeConditionalFormatting(j)
|
||||||
|
for (int j = conditionalFormattingArray.length - 1; j >= 0; j--) {
|
||||||
|
CTConditionalFormatting cf = conditionalFormattingArray[j];
|
||||||
|
|
||||||
ArrayList<CellRangeAddress> cellRanges = new ArrayList<CellRangeAddress>();
|
ArrayList<CellRangeAddress> cellRanges = new ArrayList<CellRangeAddress>();
|
||||||
for (Object stRef : cf.getSqref()) {
|
for (Object stRef : cf.getSqref()) {
|
||||||
String[] regions = stRef.toString().split(" ");
|
String[] regions = stRef.toString().split(" ");
|
||||||
for (int i = 0; i < regions.length; i++) {
|
for (String region : regions) {
|
||||||
cellRanges.add(CellRangeAddress.valueOf(regions[i]));
|
cellRanges.add(CellRangeAddress.valueOf(region));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean changed = false;
|
boolean changed = false;
|
||||||
List<CellRangeAddress> temp = new ArrayList<CellRangeAddress>();
|
List<CellRangeAddress> temp = new ArrayList<CellRangeAddress>();
|
||||||
for (int i = 0; i < cellRanges.size(); i++) {
|
for (CellRangeAddress craOld : cellRanges) {
|
||||||
CellRangeAddress craOld = cellRanges.get(i);
|
|
||||||
CellRangeAddress craNew = shiftRange(shifter, craOld, sheetIndex);
|
CellRangeAddress craNew = shiftRange(shifter, craOld, sheetIndex);
|
||||||
if (craNew == null) {
|
if (craNew == null) {
|
||||||
changed = true;
|
changed = true;
|
||||||
@ -249,7 +258,7 @@ public final class XSSFRowShifter {
|
|||||||
if (changed) {
|
if (changed) {
|
||||||
int nRanges = temp.size();
|
int nRanges = temp.size();
|
||||||
if (nRanges == 0) {
|
if (nRanges == 0) {
|
||||||
cfList.remove(j);
|
ctWorksheet.removeConditionalFormatting(j);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
List<String> refs = new ArrayList<String>();
|
List<String> refs = new ArrayList<String>();
|
||||||
@ -257,14 +266,14 @@ public final class XSSFRowShifter {
|
|||||||
cf.setSqref(refs);
|
cf.setSqref(refs);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(CTCfRule cfRule : cf.getCfRuleList()){
|
for(CTCfRule cfRule : cf.getCfRuleArray()){
|
||||||
List<String> formulas = cfRule.getFormulaList();
|
String[] formulaArray = cfRule.getFormulaArray();
|
||||||
for (int i = 0; i < formulas.size(); i++) {
|
for (int i = 0; i < formulaArray.length; i++) {
|
||||||
String formula = formulas.get(i);
|
String formula = formulaArray[i];
|
||||||
Ptg[] ptgs = FormulaParser.parse(formula, fpb, FormulaType.CELL, sheetIndex);
|
Ptg[] ptgs = FormulaParser.parse(formula, fpb, FormulaType.CELL, sheetIndex);
|
||||||
if (shifter.adjustFormula(ptgs, sheetIndex)) {
|
if (shifter.adjustFormula(ptgs, sheetIndex)) {
|
||||||
String shiftedFmla = FormulaRenderer.toFormulaString(fpb, ptgs);
|
String shiftedFmla = FormulaRenderer.toFormulaString(fpb, ptgs);
|
||||||
formulas.set(i, shiftedFmla);
|
cfRule.setFormulaArray(i, shiftedFmla);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,26 +21,26 @@ import java.util.Comparator;
|
|||||||
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol;
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol;
|
||||||
|
|
||||||
public class CTColComparator implements Comparator<CTCol>{
|
public class CTColComparator {
|
||||||
|
|
||||||
public int compare(CTCol o1, CTCol o2) {
|
private CTColComparator() {}
|
||||||
if (o1.getMin() < o2.getMin()) {
|
|
||||||
return -1;
|
public static final Comparator<CTCol> BY_MAX = new Comparator<CTCol>() {
|
||||||
|
@Override
|
||||||
|
public int compare(CTCol col1, CTCol col2) {
|
||||||
|
long col1max = col1.getMax();
|
||||||
|
long col2max = col2.getMax();
|
||||||
|
return col1max < col2max ? -1 : col1max > col2max ? 1 : 0;
|
||||||
}
|
}
|
||||||
else if (o1.getMin() > o2.getMin()) {
|
};
|
||||||
return 1;
|
|
||||||
|
public static final Comparator<CTCol> BY_MIN_MAX = new Comparator<CTCol>() {
|
||||||
|
@Override
|
||||||
|
public int compare(CTCol col1, CTCol col2) {
|
||||||
|
long col11min = col1.getMin();
|
||||||
|
long col2min = col2.getMin();
|
||||||
|
return col11min < col2min ? -1 : col11min > col2min ? 1 : BY_MAX.compare(col1, col2);
|
||||||
}
|
}
|
||||||
else {
|
};
|
||||||
if (o1.getMax() < o2.getMax()) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (o1.getMax() > o2.getMax()) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -33,13 +33,15 @@ public class XWPFCommentsDecorator extends XWPFParagraphDecorator {
|
|||||||
public XWPFCommentsDecorator(XWPFParagraphDecorator nextDecorator) {
|
public XWPFCommentsDecorator(XWPFParagraphDecorator nextDecorator) {
|
||||||
this(nextDecorator.paragraph, nextDecorator);
|
this(nextDecorator.paragraph, nextDecorator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public XWPFCommentsDecorator(XWPFParagraph paragraph, XWPFParagraphDecorator nextDecorator) {
|
public XWPFCommentsDecorator(XWPFParagraph paragraph, XWPFParagraphDecorator nextDecorator) {
|
||||||
super(paragraph, nextDecorator);
|
super(paragraph, nextDecorator);
|
||||||
|
|
||||||
XWPFComment comment;
|
XWPFComment comment;
|
||||||
commentText = new StringBuffer();
|
commentText = new StringBuffer();
|
||||||
|
|
||||||
for(CTMarkupRange anchor : paragraph.getCTP().getCommentRangeStartList())
|
for(CTMarkupRange anchor : paragraph.getCTP().getCommentRangeStartArray())
|
||||||
{
|
{
|
||||||
if((comment = paragraph.getDocument().getCommentByID(anchor.getId().toString())) != null)
|
if((comment = paragraph.getDocument().getCommentByID(anchor.getId().toString())) != null)
|
||||||
commentText.append("\tComment by " + comment.getAuthor()+": "+comment.getText());
|
commentText.append("\tComment by " + comment.getAuthor()+": "+comment.getText());
|
||||||
|
@ -52,10 +52,10 @@ public class XWPFHyperlinkDecorator extends XWPFParagraphDecorator {
|
|||||||
hyperlinkText = new StringBuffer();
|
hyperlinkText = new StringBuffer();
|
||||||
|
|
||||||
// loop over hyperlink anchors
|
// loop over hyperlink anchors
|
||||||
for(CTHyperlink link : paragraph.getCTP().getHyperlinkList()){
|
for(CTHyperlink link : paragraph.getCTP().getHyperlinkArray()){
|
||||||
for (CTR r : link.getRList()) {
|
for (CTR r : link.getRArray()) {
|
||||||
// Loop over text runs
|
// Loop over text runs
|
||||||
for (CTText text : r.getTList()){
|
for (CTText text : r.getTArray()){
|
||||||
hyperlinkText.append(text.getStringValue());
|
hyperlinkText.append(text.getStringValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,17 +35,18 @@ public abstract class AbstractXWPFSDT implements ISDTContents {
|
|||||||
private final String tag;
|
private final String tag;
|
||||||
private final IBody part;
|
private final IBody part;
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public AbstractXWPFSDT(CTSdtPr pr, IBody part){
|
public AbstractXWPFSDT(CTSdtPr pr, IBody part){
|
||||||
|
|
||||||
List<CTString> aliases = pr.getAliasList();
|
CTString[] aliases = pr.getAliasArray();
|
||||||
if (aliases != null && aliases.size() > 0){
|
if (aliases != null && aliases.length > 0){
|
||||||
title = aliases.get(0).getVal();
|
title = aliases[0].getVal();
|
||||||
} else {
|
} else {
|
||||||
title = "";
|
title = "";
|
||||||
}
|
}
|
||||||
List<CTString> tags = pr.getTagList();
|
CTString[] tags = pr.getTagArray();
|
||||||
if (tags != null && tags.size() > 0){
|
if (tags != null && tags.length > 0){
|
||||||
tag = tags.get(0).getVal();
|
tag = tags[0].getVal();
|
||||||
} else {
|
} else {
|
||||||
tag = "";
|
tag = "";
|
||||||
}
|
}
|
||||||
|
@ -31,13 +31,14 @@ public class XWPFComment
|
|||||||
protected String author;
|
protected String author;
|
||||||
protected StringBuffer text;
|
protected StringBuffer text;
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public XWPFComment(CTComment comment, XWPFDocument document)
|
public XWPFComment(CTComment comment, XWPFDocument document)
|
||||||
{
|
{
|
||||||
text = new StringBuffer();
|
text = new StringBuffer();
|
||||||
id = comment.getId().toString();
|
id = comment.getId().toString();
|
||||||
author = comment.getAuthor();
|
author = comment.getAuthor();
|
||||||
|
|
||||||
for(CTP ctp : comment.getPList())
|
for(CTP ctp : comment.getPArray())
|
||||||
{
|
{
|
||||||
XWPFParagraph p = new XWPFParagraph(ctp, document);
|
XWPFParagraph p = new XWPFParagraph(ctp, document);
|
||||||
text.append(p.getText());
|
text.append(p.getText());
|
||||||
|
@ -184,7 +184,7 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
|
|||||||
} else if (relation.equals(XWPFRelation.COMMENT.getRelation())) {
|
} else if (relation.equals(XWPFRelation.COMMENT.getRelation())) {
|
||||||
// TODO Create according XWPFComment class, extending POIXMLDocumentPart
|
// TODO Create according XWPFComment class, extending POIXMLDocumentPart
|
||||||
CommentsDocument cmntdoc = CommentsDocument.Factory.parse(p.getPackagePart().getInputStream());
|
CommentsDocument cmntdoc = CommentsDocument.Factory.parse(p.getPackagePart().getInputStream());
|
||||||
for (CTComment ctcomment : cmntdoc.getComments().getCommentList()) {
|
for (CTComment ctcomment : cmntdoc.getComments().getCommentArray()) {
|
||||||
comments.add(new XWPFComment(ctcomment, this));
|
comments.add(new XWPFComment(ctcomment, this));
|
||||||
}
|
}
|
||||||
} else if (relation.equals(XWPFRelation.SETTINGS.getRelation())) {
|
} else if (relation.equals(XWPFRelation.SETTINGS.getRelation())) {
|
||||||
@ -232,6 +232,7 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
private void initFootnotes() throws XmlException, IOException {
|
private void initFootnotes() throws XmlException, IOException {
|
||||||
for(POIXMLDocumentPart p : getRelations()){
|
for(POIXMLDocumentPart p : getRelations()){
|
||||||
String relation = p.getPackageRelationship().getRelationshipType();
|
String relation = p.getPackageRelationship().getRelationshipType();
|
||||||
@ -241,7 +242,7 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
|
|||||||
} else if (relation.equals(XWPFRelation.ENDNOTE.getRelation())){
|
} else if (relation.equals(XWPFRelation.ENDNOTE.getRelation())){
|
||||||
EndnotesDocument endnotesDocument = EndnotesDocument.Factory.parse(p.getPackagePart().getInputStream());
|
EndnotesDocument endnotesDocument = EndnotesDocument.Factory.parse(p.getPackagePart().getInputStream());
|
||||||
|
|
||||||
for(CTFtnEdn ctFtnEdn : endnotesDocument.getEndnotes().getEndnoteList()) {
|
for(CTFtnEdn ctFtnEdn : endnotesDocument.getEndnotes().getEndnoteArray()) {
|
||||||
endnotes.put(ctFtnEdn.getId().intValue(), new XWPFFootnote(this, ctFtnEdn));
|
endnotes.put(ctFtnEdn.getId().intValue(), new XWPFFootnote(this, ctFtnEdn));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -364,10 +365,8 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public XWPFHyperlink getHyperlinkByID(String id) {
|
public XWPFHyperlink getHyperlinkByID(String id) {
|
||||||
Iterator<XWPFHyperlink> iter = hyperlinks.iterator();
|
for (XWPFHyperlink link : hyperlinks) {
|
||||||
while (iter.hasNext()) {
|
if (link.getId().equals(id))
|
||||||
XWPFHyperlink link = iter.next();
|
|
||||||
if(link.getId().equals(id))
|
|
||||||
return link;
|
return link;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -396,10 +395,8 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public XWPFComment getCommentByID(String id) {
|
public XWPFComment getCommentByID(String id) {
|
||||||
Iterator<XWPFComment> iter = comments.iterator();
|
for (XWPFComment comment : comments) {
|
||||||
while (iter.hasNext()) {
|
if (comment.getId().equals(id))
|
||||||
XWPFComment comment = iter.next();
|
|
||||||
if(comment.getId().equals(id))
|
|
||||||
return comment;
|
return comment;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1187,14 +1184,15 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
|
|||||||
* @param table
|
* @param table
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public void insertTable(int pos, XWPFTable table) {
|
public void insertTable(int pos, XWPFTable table) {
|
||||||
bodyElements.add(pos, table);
|
bodyElements.add(pos, table);
|
||||||
int i;
|
int i = 0;
|
||||||
for (i = 0; i < ctDocument.getBody().getTblList().size(); i++) {
|
for (CTTbl tbl : ctDocument.getBody().getTblArray()) {
|
||||||
CTTbl tbl = ctDocument.getBody().getTblArray(i);
|
|
||||||
if (tbl == table.getCTTbl()) {
|
if (tbl == table.getCTTbl()) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
tables.add(i, table);
|
tables.add(i, table);
|
||||||
}
|
}
|
||||||
|
@ -123,14 +123,15 @@ public class XWPFFootnote implements Iterable<XWPFParagraph>,IBody {
|
|||||||
* @param table
|
* @param table
|
||||||
* @see org.apache.poi.xwpf.usermodel.IBody#insertTable(int pos, XWPFTable table)
|
* @see org.apache.poi.xwpf.usermodel.IBody#insertTable(int pos, XWPFTable table)
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public void insertTable(int pos, XWPFTable table) {
|
public void insertTable(int pos, XWPFTable table) {
|
||||||
bodyElements.add(pos, table);
|
bodyElements.add(pos, table);
|
||||||
int i;
|
int i = 0;
|
||||||
for (i = 0; i < ctFtnEdn.getTblList().size(); i++) {
|
for (CTTbl tbl : ctFtnEdn.getTblArray()) {
|
||||||
CTTbl tbl = ctFtnEdn.getTblArray(i);
|
|
||||||
if(tbl == table.getCTTbl()){
|
if(tbl == table.getCTTbl()){
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
tables.add(i, table);
|
tables.add(i, table);
|
||||||
|
|
||||||
|
@ -34,7 +34,6 @@ import org.apache.poi.openxml4j.opc.PackagePart;
|
|||||||
import org.apache.poi.openxml4j.opc.PackageRelationship;
|
import org.apache.poi.openxml4j.opc.PackageRelationship;
|
||||||
import org.apache.xmlbeans.XmlException;
|
import org.apache.xmlbeans.XmlException;
|
||||||
import org.apache.xmlbeans.XmlOptions;
|
import org.apache.xmlbeans.XmlOptions;
|
||||||
|
|
||||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFtnEdn;
|
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFtnEdn;
|
||||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFootnotes;
|
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFootnotes;
|
||||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.FootnotesDocument;
|
import org.openxmlformats.schemas.wordprocessingml.x2006.main.FootnotesDocument;
|
||||||
@ -68,6 +67,7 @@ public class XWPFFootnotes extends POIXMLDocumentPart {
|
|||||||
* Read document
|
* Read document
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
protected void onDocumentRead () throws IOException {
|
protected void onDocumentRead () throws IOException {
|
||||||
FootnotesDocument notesDoc;
|
FootnotesDocument notesDoc;
|
||||||
try {
|
try {
|
||||||
@ -79,7 +79,7 @@ public class XWPFFootnotes extends POIXMLDocumentPart {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Find our footnotes
|
// Find our footnotes
|
||||||
for(CTFtnEdn note : ctFootnotes.getFootnoteList()) {
|
for(CTFtnEdn note : ctFootnotes.getFootnoteArray()) {
|
||||||
listFootnote.add(new XWPFFootnote(note, this));
|
listFootnote.add(new XWPFFootnote(note, this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -436,14 +436,15 @@ public abstract class XWPFHeaderFooter extends POIXMLDocumentPart implements IBo
|
|||||||
* @param pos
|
* @param pos
|
||||||
* @param table
|
* @param table
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public void insertTable(int pos, XWPFTable table) {
|
public void insertTable(int pos, XWPFTable table) {
|
||||||
bodyElements.add(pos, table);
|
bodyElements.add(pos, table);
|
||||||
int i;
|
int i = 0;
|
||||||
for (i = 0; i < headerFooter.getTblList().size(); i++) {
|
for (CTTbl tbl : headerFooter.getTblArray()) {
|
||||||
CTTbl tbl = headerFooter.getTblArray(i);
|
|
||||||
if(tbl == table.getCTTbl()){
|
if(tbl == table.getCTTbl()){
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
tables.add(i, table);
|
tables.add(i, table);
|
||||||
|
|
||||||
|
@ -38,10 +38,12 @@ public class XWPFLatentStyles {
|
|||||||
/**
|
/**
|
||||||
* checks wheter specific LatentStyleID is a latentStyle
|
* checks wheter specific LatentStyleID is a latentStyle
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
protected boolean isLatentStyle(String latentStyleID){
|
protected boolean isLatentStyle(String latentStyleID){
|
||||||
for ( CTLsdException lsd: latentStyles.getLsdExceptionList()) {
|
for ( CTLsdException lsd: latentStyles.getLsdExceptionArray()) {
|
||||||
if(lsd.getName().equals(latentStyleID));
|
if(lsd.getName().equals(latentStyleID)) {
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -71,6 +71,7 @@ public class XWPFNumbering extends POIXMLDocumentPart {
|
|||||||
* read numbering form an existing package
|
* read numbering form an existing package
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
protected void onDocumentRead() throws IOException{
|
protected void onDocumentRead() throws IOException{
|
||||||
NumberingDocument numberingDoc = null;
|
NumberingDocument numberingDoc = null;
|
||||||
InputStream is;
|
InputStream is;
|
||||||
@ -79,10 +80,10 @@ public class XWPFNumbering extends POIXMLDocumentPart {
|
|||||||
numberingDoc = NumberingDocument.Factory.parse(is);
|
numberingDoc = NumberingDocument.Factory.parse(is);
|
||||||
ctNumbering = numberingDoc.getNumbering();
|
ctNumbering = numberingDoc.getNumbering();
|
||||||
//get any Nums
|
//get any Nums
|
||||||
for(CTNum ctNum : ctNumbering.getNumList()) {
|
for(CTNum ctNum : ctNumbering.getNumArray()) {
|
||||||
nums.add(new XWPFNum(ctNum, this));
|
nums.add(new XWPFNum(ctNum, this));
|
||||||
}
|
}
|
||||||
for(CTAbstractNum ctAbstractNum : ctNumbering.getAbstractNumList()){
|
for(CTAbstractNum ctAbstractNum : ctNumbering.getAbstractNumArray()){
|
||||||
abstractNums.add(new XWPFAbstractNum(ctAbstractNum, this));
|
abstractNums.add(new XWPFAbstractNum(ctAbstractNum, this));
|
||||||
}
|
}
|
||||||
isNew = false;
|
isNew = false;
|
||||||
@ -144,7 +145,7 @@ public class XWPFNumbering extends POIXMLDocumentPart {
|
|||||||
*/
|
*/
|
||||||
public BigInteger addNum(XWPFNum num){
|
public BigInteger addNum(XWPFNum num){
|
||||||
ctNumbering.addNewNum();
|
ctNumbering.addNewNum();
|
||||||
int pos = (ctNumbering.getNumList().size()) - 1;
|
int pos = ctNumbering.sizeOfNumArray() - 1;
|
||||||
ctNumbering.setNumArray(pos, num.getCTNum());
|
ctNumbering.setNumArray(pos, num.getCTNum());
|
||||||
nums.add(num);
|
nums.add(num);
|
||||||
return num.getCTNum().getNumId();
|
return num.getCTNum().getNumId();
|
||||||
|
@ -137,7 +137,7 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents {
|
|||||||
}
|
}
|
||||||
if (o instanceof CTHyperlink) {
|
if (o instanceof CTHyperlink) {
|
||||||
CTHyperlink link = (CTHyperlink) o;
|
CTHyperlink link = (CTHyperlink) o;
|
||||||
for (CTR r : link.getRList()) {
|
for (CTR r : link.getRArray()) {
|
||||||
XWPFHyperlinkRun hr = new XWPFHyperlinkRun(link, r, this);
|
XWPFHyperlinkRun hr = new XWPFHyperlinkRun(link, r, this);
|
||||||
runs.add(hr);
|
runs.add(hr);
|
||||||
iruns.add(hr);
|
iruns.add(hr);
|
||||||
@ -152,14 +152,14 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents {
|
|||||||
iruns.add(cc);
|
iruns.add(cc);
|
||||||
}
|
}
|
||||||
if (o instanceof CTRunTrackChange) {
|
if (o instanceof CTRunTrackChange) {
|
||||||
for (CTR r : ((CTRunTrackChange) o).getRList()) {
|
for (CTR r : ((CTRunTrackChange) o).getRArray()) {
|
||||||
XWPFRun cr = new XWPFRun(r, this);
|
XWPFRun cr = new XWPFRun(r, this);
|
||||||
runs.add(cr);
|
runs.add(cr);
|
||||||
iruns.add(cr);
|
iruns.add(cr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (o instanceof CTSimpleField) {
|
if (o instanceof CTSimpleField) {
|
||||||
for (CTR r : ((CTSimpleField) o).getRList()) {
|
for (CTR r : ((CTSimpleField) o).getRArray()) {
|
||||||
XWPFRun cr = new XWPFRun(r, this);
|
XWPFRun cr = new XWPFRun(r, this);
|
||||||
runs.add(cr);
|
runs.add(cr);
|
||||||
iruns.add(cr);
|
iruns.add(cr);
|
||||||
@ -1170,7 +1170,7 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents {
|
|||||||
*/
|
*/
|
||||||
protected void addRun(CTR run){
|
protected void addRun(CTR run){
|
||||||
int pos;
|
int pos;
|
||||||
pos = paragraph.getRList().size();
|
pos = paragraph.sizeOfRArray();
|
||||||
paragraph.addNewR();
|
paragraph.addNewR();
|
||||||
paragraph.setRArray(pos, run);
|
paragraph.setRArray(pos, run);
|
||||||
}
|
}
|
||||||
@ -1230,9 +1230,10 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents {
|
|||||||
startChar = startPos.getChar();
|
startChar = startPos.getChar();
|
||||||
int beginRunPos = 0, candCharPos = 0;
|
int beginRunPos = 0, candCharPos = 0;
|
||||||
boolean newList = false;
|
boolean newList = false;
|
||||||
for (int runPos=startRun; runPos<paragraph.getRList().size(); runPos++) {
|
CTR[] rArray = paragraph.getRArray();
|
||||||
|
for (int runPos=startRun; runPos<rArray.length; runPos++) {
|
||||||
int beginTextPos = 0,beginCharPos = 0, textPos = 0, charPos = 0;
|
int beginTextPos = 0,beginCharPos = 0, textPos = 0, charPos = 0;
|
||||||
CTR ctRun = paragraph.getRArray(runPos);
|
CTR ctRun = rArray[runPos];
|
||||||
XmlCursor c = ctRun.newCursor();
|
XmlCursor c = ctRun.newCursor();
|
||||||
c.selectPath("./*");
|
c.selectPath("./*");
|
||||||
while(c.toNextSelection()){
|
while(c.toNextSelection()){
|
||||||
@ -1298,15 +1299,17 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents {
|
|||||||
int runEnd = segment.getEndRun();
|
int runEnd = segment.getEndRun();
|
||||||
int textEnd = segment.getEndText();
|
int textEnd = segment.getEndText();
|
||||||
int charEnd = segment.getEndChar();
|
int charEnd = segment.getEndChar();
|
||||||
StringBuffer out = new StringBuffer();
|
StringBuilder out = new StringBuilder();
|
||||||
|
CTR[] rArray = paragraph.getRArray();
|
||||||
for(int i=runBegin; i<=runEnd;i++){
|
for(int i=runBegin; i<=runEnd;i++){
|
||||||
int startText=0, endText = paragraph.getRArray(i).getTList().size()-1;
|
CTText[] tArray = rArray[i].getTArray();
|
||||||
|
int startText=0, endText = tArray.length-1;
|
||||||
if(i==runBegin)
|
if(i==runBegin)
|
||||||
startText=textBegin;
|
startText=textBegin;
|
||||||
if(i==runEnd)
|
if(i==runEnd)
|
||||||
endText = textEnd;
|
endText = textEnd;
|
||||||
for(int j=startText;j<=endText;j++){
|
for(int j=startText;j<=endText;j++){
|
||||||
String tmpText = paragraph.getRArray(i).getTArray(j).getStringValue();
|
String tmpText = tArray[j].getStringValue();
|
||||||
int startChar=0, endChar = tmpText.length()-1;
|
int startChar=0, endChar = tmpText.length()-1;
|
||||||
if((j==textBegin)&&(i==runBegin))
|
if((j==textBegin)&&(i==runBegin))
|
||||||
startChar=charBegin;
|
startChar=charBegin;
|
||||||
@ -1314,7 +1317,6 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents {
|
|||||||
endChar = charEnd;
|
endChar = charEnd;
|
||||||
}
|
}
|
||||||
out.append(tmpText.substring(startChar, endChar+1));
|
out.append(tmpText.substring(startChar, endChar+1));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return out.toString();
|
return out.toString();
|
||||||
|
@ -20,6 +20,7 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.xml.namespace.QName;
|
import javax.xml.namespace.QName;
|
||||||
@ -95,6 +96,7 @@ public class XWPFRun implements ISDTContents, IRunElement{
|
|||||||
* @param r the CTR bean which holds the run attributes
|
* @param r the CTR bean which holds the run attributes
|
||||||
* @param p the parent paragraph
|
* @param p the parent paragraph
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public XWPFRun(CTR r, IRunBody p) {
|
public XWPFRun(CTR r, IRunBody p) {
|
||||||
this.run = r;
|
this.run = r;
|
||||||
this.parent = p;
|
this.parent = p;
|
||||||
@ -103,16 +105,13 @@ public class XWPFRun implements ISDTContents, IRunElement{
|
|||||||
* reserve already occupied drawing ids, so reserving new ids later will
|
* reserve already occupied drawing ids, so reserving new ids later will
|
||||||
* not corrupt the document
|
* not corrupt the document
|
||||||
*/
|
*/
|
||||||
List<CTDrawing> drawingList = r.getDrawingList();
|
for (CTDrawing ctDrawing : r.getDrawingArray()) {
|
||||||
for (CTDrawing ctDrawing : drawingList) {
|
for (CTAnchor anchor : ctDrawing.getAnchorArray()) {
|
||||||
List<CTAnchor> anchorList = ctDrawing.getAnchorList();
|
|
||||||
for (CTAnchor anchor : anchorList) {
|
|
||||||
if (anchor.getDocPr() != null) {
|
if (anchor.getDocPr() != null) {
|
||||||
getDocument().getDrawingIdManager().reserve(anchor.getDocPr().getId());
|
getDocument().getDrawingIdManager().reserve(anchor.getDocPr().getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
List<CTInline> inlineList = ctDrawing.getInlineList();
|
for (CTInline inline : ctDrawing.getInlineArray()) {
|
||||||
for (CTInline inline : inlineList) {
|
|
||||||
if (inline.getDocPr() != null) {
|
if (inline.getDocPr() != null) {
|
||||||
getDocument().getDrawingIdManager().reserve(inline.getDocPr().getId());
|
getDocument().getDrawingIdManager().reserve(inline.getDocPr().getId());
|
||||||
}
|
}
|
||||||
@ -120,17 +119,17 @@ public class XWPFRun implements ISDTContents, IRunElement{
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Look for any text in any of our pictures or drawings
|
// Look for any text in any of our pictures or drawings
|
||||||
StringBuffer text = new StringBuffer();
|
StringBuilder text = new StringBuilder();
|
||||||
List<XmlObject> pictTextObjs = new ArrayList<XmlObject>();
|
List<XmlObject> pictTextObjs = new ArrayList<XmlObject>();
|
||||||
pictTextObjs.addAll(r.getPictList());
|
pictTextObjs.addAll(Arrays.asList(r.getPictArray()));
|
||||||
pictTextObjs.addAll(drawingList);
|
pictTextObjs.addAll(Arrays.asList(r.getDrawingArray()));
|
||||||
for(XmlObject o : pictTextObjs) {
|
for(XmlObject o : pictTextObjs) {
|
||||||
XmlObject[] t = o.selectPath("declare namespace w='http://schemas.openxmlformats.org/wordprocessingml/2006/main' .//w:t");
|
XmlObject[] ts = o.selectPath("declare namespace w='http://schemas.openxmlformats.org/wordprocessingml/2006/main' .//w:t");
|
||||||
for (int m = 0; m < t.length; m++) {
|
for (XmlObject t : ts) {
|
||||||
NodeList kids = t[m].getDomNode().getChildNodes();
|
NodeList kids = t.getDomNode().getChildNodes();
|
||||||
for (int n = 0; n < kids.getLength(); n++) {
|
for (int n = 0; n < kids.getLength(); n++) {
|
||||||
if (kids.item(n) instanceof Text) {
|
if (kids.item(n) instanceof Text) {
|
||||||
if(text.length() > 0)
|
if (text.length() > 0)
|
||||||
text.append("\n");
|
text.append("\n");
|
||||||
text.append(kids.item(n).getNodeValue());
|
text.append(kids.item(n).getNodeValue());
|
||||||
}
|
}
|
||||||
@ -317,7 +316,7 @@ public class XWPFRun implements ISDTContents, IRunElement{
|
|||||||
* @param value the literal text which shall be displayed in the document
|
* @param value the literal text which shall be displayed in the document
|
||||||
*/
|
*/
|
||||||
public void setText(String value) {
|
public void setText(String value) {
|
||||||
setText(value,run.getTList().size());
|
setText(value,run.sizeOfTArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -50,8 +50,8 @@ public class XWPFSDTContent implements ISDTContent {
|
|||||||
private List<ISDTContents> bodyElements = new ArrayList<ISDTContents>();
|
private List<ISDTContents> bodyElements = new ArrayList<ISDTContents>();
|
||||||
|
|
||||||
public XWPFSDTContent(CTSdtContentRun sdtRun, IBody part, IRunBody parent){
|
public XWPFSDTContent(CTSdtContentRun sdtRun, IBody part, IRunBody parent){
|
||||||
for (CTR ctr : sdtRun.getRList()){
|
for (CTR ctr : sdtRun.getRArray()){
|
||||||
XWPFRun run = new XWPFRun((CTR) ctr, parent);
|
XWPFRun run = new XWPFRun(ctr, parent);
|
||||||
runs.add(run);
|
runs.add(run);
|
||||||
bodyElements.add(run);
|
bodyElements.add(run);
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,6 @@ import org.apache.xmlbeans.XmlOptions;
|
|||||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTStyle;
|
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTStyle;
|
||||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTStyles;
|
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTStyles;
|
||||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.StylesDocument;
|
import org.openxmlformats.schemas.wordprocessingml.x2006.main.StylesDocument;
|
||||||
|
|
||||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRPr;
|
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRPr;
|
||||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRPrDefault;
|
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRPrDefault;
|
||||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTLanguage;
|
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTLanguage;
|
||||||
@ -74,6 +73,7 @@ public class XWPFStyles extends POIXMLDocumentPart{
|
|||||||
* Read document
|
* Read document
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
protected void onDocumentRead() throws IOException{
|
protected void onDocumentRead() throws IOException{
|
||||||
StylesDocument stylesDoc;
|
StylesDocument stylesDoc;
|
||||||
try {
|
try {
|
||||||
@ -86,7 +86,7 @@ public class XWPFStyles extends POIXMLDocumentPart{
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Build up all the style objects
|
// Build up all the style objects
|
||||||
for(CTStyle style : ctStyles.getStyleList()) {
|
for(CTStyle style : ctStyles.getStyleArray()) {
|
||||||
listStyle.add(new XWPFStyle(style, this));
|
listStyle.add(new XWPFStyle(style, this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -137,7 +137,7 @@ public class XWPFStyles extends POIXMLDocumentPart{
|
|||||||
public void addStyle(XWPFStyle style){
|
public void addStyle(XWPFStyle style){
|
||||||
listStyle.add(style);
|
listStyle.add(style);
|
||||||
ctStyles.addNewStyle();
|
ctStyles.addNewStyle();
|
||||||
int pos = (ctStyles.getStyleList().size()) - 1;
|
int pos = ctStyles.sizeOfStyleArray() - 1;
|
||||||
ctStyles.setStyleArray(pos, style.getCTStyle());
|
ctStyles.setStyleArray(pos, style.getCTStyle());
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -93,6 +93,7 @@ public class XWPFTable implements IBodyElement, ISDTContents {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public XWPFTable(CTTbl table, IBody part){
|
public XWPFTable(CTTbl table, IBody part){
|
||||||
this.part = part;
|
this.part = part;
|
||||||
this.ctTbl = table;
|
this.ctTbl = table;
|
||||||
@ -103,12 +104,12 @@ public class XWPFTable implements IBodyElement, ISDTContents {
|
|||||||
if (table.sizeOfTrArray() == 0)
|
if (table.sizeOfTrArray() == 0)
|
||||||
createEmptyTable(table);
|
createEmptyTable(table);
|
||||||
|
|
||||||
for (CTRow row : table.getTrList()) {
|
for (CTRow row : table.getTrArray()) {
|
||||||
StringBuffer rowText = new StringBuffer();
|
StringBuilder rowText = new StringBuilder();
|
||||||
XWPFTableRow tabRow = new XWPFTableRow(row, this);
|
XWPFTableRow tabRow = new XWPFTableRow(row, this);
|
||||||
tableRows.add(tabRow);
|
tableRows.add(tabRow);
|
||||||
for (CTTc cell : row.getTcList()) {
|
for (CTTc cell : row.getTcArray()) {
|
||||||
for (CTP ctp : cell.getPList()) {
|
for (CTP ctp : cell.getPArray()) {
|
||||||
XWPFParagraph p = new XWPFParagraph(ctp, part);
|
XWPFParagraph p = new XWPFParagraph(ctp, part);
|
||||||
if (rowText.length() > 0) {
|
if (rowText.length() > 0) {
|
||||||
rowText.append('\t');
|
rowText.append('\t');
|
||||||
|
@ -79,7 +79,7 @@ public class XWPFTableCell implements IBody, ICell {
|
|||||||
this.part = part;
|
this.part = part;
|
||||||
this.tableRow = tableRow;
|
this.tableRow = tableRow;
|
||||||
// NB: If a table cell does not include at least one block-level element, then this document shall be considered corrupt.
|
// NB: If a table cell does not include at least one block-level element, then this document shall be considered corrupt.
|
||||||
if(cell.getPList().size()<1)
|
if(cell.sizeOfPArray()<1)
|
||||||
cell.addNewP();
|
cell.addNewP();
|
||||||
bodyElements = new ArrayList<IBodyElement>();
|
bodyElements = new ArrayList<IBodyElement>();
|
||||||
paragraphs = new ArrayList<XWPFParagraph>();
|
paragraphs = new ArrayList<XWPFParagraph>();
|
||||||
@ -398,16 +398,17 @@ public class XWPFTableCell implements IBody, ICell {
|
|||||||
* inserts an existing XWPFTable to the arrays bodyElements and tables
|
* inserts an existing XWPFTable to the arrays bodyElements and tables
|
||||||
* @see org.apache.poi.xwpf.usermodel.IBody#insertTable(int, org.apache.poi.xwpf.usermodel.XWPFTable)
|
* @see org.apache.poi.xwpf.usermodel.IBody#insertTable(int, org.apache.poi.xwpf.usermodel.XWPFTable)
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public void insertTable(int pos, XWPFTable table) {
|
public void insertTable(int pos, XWPFTable table) {
|
||||||
bodyElements.add(pos, table);
|
bodyElements.add(pos, table);
|
||||||
int i;
|
int i = 0;
|
||||||
for (i = 0; i < ctTc.getTblList().size(); i++) {
|
for (CTTbl tbl : ctTc.getTblArray()) {
|
||||||
CTTbl tbl = ctTc.getTblArray(i);
|
if (tbl == table.getCTTbl()) {
|
||||||
if(tbl == table.getCTTbl()){
|
break;
|
||||||
break;
|
}
|
||||||
}
|
i++;
|
||||||
}
|
}
|
||||||
tables.add(i, table);
|
tables.add(i, table);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getText(){
|
public String getText(){
|
||||||
|
@ -152,10 +152,11 @@ public class XWPFTableRow {
|
|||||||
* who belongs to this row
|
* who belongs to this row
|
||||||
* @return a list of {@link XWPFTableCell}
|
* @return a list of {@link XWPFTableCell}
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public List<XWPFTableCell> getTableCells(){
|
public List<XWPFTableCell> getTableCells(){
|
||||||
if(tableCells == null){
|
if(tableCells == null){
|
||||||
List<XWPFTableCell> cells = new ArrayList<XWPFTableCell>();
|
List<XWPFTableCell> cells = new ArrayList<XWPFTableCell>();
|
||||||
for (CTTc tableCell : ctRow.getTcList()) {
|
for (CTTc tableCell : ctRow.getTcArray()) {
|
||||||
cells.add(new XWPFTableCell(tableCell, this, table.getBody()));
|
cells.add(new XWPFTableCell(tableCell, this, table.getBody()));
|
||||||
}
|
}
|
||||||
//TODO: it is possible to have an SDT that contains a cell in within a row
|
//TODO: it is possible to have an SDT that contains a cell in within a row
|
||||||
@ -201,7 +202,7 @@ public class XWPFTableRow {
|
|||||||
boolean isCant = false;
|
boolean isCant = false;
|
||||||
CTTrPr trpr = getTrPr();
|
CTTrPr trpr = getTrPr();
|
||||||
if (trpr.sizeOfCantSplitArray() > 0) {
|
if (trpr.sizeOfCantSplitArray() > 0) {
|
||||||
CTOnOff onoff = trpr.getCantSplitList().get(0);
|
CTOnOff onoff = trpr.getCantSplitArray(0);
|
||||||
isCant = onoff.getVal().equals(STOnOff.ON);
|
isCant = onoff.getVal().equals(STOnOff.ON);
|
||||||
}
|
}
|
||||||
return isCant;
|
return isCant;
|
||||||
@ -229,7 +230,7 @@ public class XWPFTableRow {
|
|||||||
boolean repeat = false;
|
boolean repeat = false;
|
||||||
CTTrPr trpr = getTrPr();
|
CTTrPr trpr = getTrPr();
|
||||||
if (trpr.sizeOfTblHeaderArray() > 0) {
|
if (trpr.sizeOfTblHeaderArray() > 0) {
|
||||||
CTOnOff rpt = trpr.getTblHeaderList().get(0);
|
CTOnOff rpt = trpr.getTblHeaderArray(0);
|
||||||
repeat = rpt.getVal().equals(STOnOff.ON);
|
repeat = rpt.getVal().equals(STOnOff.ON);
|
||||||
}
|
}
|
||||||
return repeat;
|
return repeat;
|
||||||
|
@ -80,13 +80,14 @@ public final class TestPOIXMLProperties extends TestCase {
|
|||||||
org.apache.poi.POIXMLProperties.ExtendedProperties newProperties =
|
org.apache.poi.POIXMLProperties.ExtendedProperties newProperties =
|
||||||
newProps.getExtendedProperties();
|
newProps.getExtendedProperties();
|
||||||
|
|
||||||
|
assertEquals(application, newProperties.getApplication());
|
||||||
|
assertEquals(appVersion, newProperties.getAppVersion());
|
||||||
|
|
||||||
org.openxmlformats.schemas.officeDocument.x2006.extendedProperties.CTProperties
|
org.openxmlformats.schemas.officeDocument.x2006.extendedProperties.CTProperties
|
||||||
newCtProps = newProperties.getUnderlyingProperties();
|
newCtProps = newProperties.getUnderlyingProperties();
|
||||||
|
|
||||||
assertEquals(application, newCtProps.getApplication());
|
assertEquals(application, newCtProps.getApplication());
|
||||||
assertEquals(appVersion, newCtProps.getAppVersion());
|
assertEquals(appVersion, newCtProps.getAppVersion());
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -42,7 +42,6 @@ import org.apache.poi.openxml4j.opc.internal.PackagePropertiesPart;
|
|||||||
import org.apache.poi.util.DocumentHelper;
|
import org.apache.poi.util.DocumentHelper;
|
||||||
import org.apache.poi.util.POILogFactory;
|
import org.apache.poi.util.POILogFactory;
|
||||||
import org.apache.poi.util.POILogger;
|
import org.apache.poi.util.POILogger;
|
||||||
import org.apache.poi.util.SAXHelper;
|
|
||||||
import org.apache.poi.util.TempFile;
|
import org.apache.poi.util.TempFile;
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
@ -218,7 +217,7 @@ public final class TestPackage extends TestCase {
|
|||||||
PackagePartName relName = PackagingURIHelper.createPartName(PackageRelationship.getContainerPartRelationship());
|
PackagePartName relName = PackagingURIHelper.createPartName(PackageRelationship.getContainerPartRelationship());
|
||||||
PackagePart relPart = pkg.getPart(relName);
|
PackagePart relPart = pkg.getPart(relName);
|
||||||
|
|
||||||
Document xmlRelationshipsDoc = SAXHelper.readSAXDocument(relPart.getInputStream());
|
Document xmlRelationshipsDoc = DocumentHelper.readDocument(relPart.getInputStream());
|
||||||
|
|
||||||
Element root = xmlRelationshipsDoc.getDocumentElement();
|
Element root = xmlRelationshipsDoc.getDocumentElement();
|
||||||
NodeList nodeList = root.getElementsByTagName(PackageRelationship.RELATIONSHIP_TAG_NAME);
|
NodeList nodeList = root.getElementsByTagName(PackageRelationship.RELATIONSHIP_TAG_NAME);
|
||||||
|
@ -30,6 +30,7 @@ import java.security.cert.CertificateEncodingException;
|
|||||||
import java.security.cert.CertificateException;
|
import java.security.cert.CertificateException;
|
||||||
import java.security.cert.X509CRL;
|
import java.security.cert.X509CRL;
|
||||||
import java.security.cert.X509Certificate;
|
import java.security.cert.X509Certificate;
|
||||||
|
import java.security.interfaces.RSAPublicKey;
|
||||||
import java.security.spec.RSAKeyGenParameterSpec;
|
import java.security.spec.RSAKeyGenParameterSpec;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
@ -45,8 +46,6 @@ import javax.xml.transform.TransformerFactory;
|
|||||||
import javax.xml.transform.dom.DOMSource;
|
import javax.xml.transform.dom.DOMSource;
|
||||||
import javax.xml.transform.stream.StreamResult;
|
import javax.xml.transform.stream.StreamResult;
|
||||||
|
|
||||||
import org.bouncycastle.asn1.ASN1InputStream;
|
|
||||||
import org.bouncycastle.asn1.ASN1Sequence;
|
|
||||||
import org.bouncycastle.asn1.DERIA5String;
|
import org.bouncycastle.asn1.DERIA5String;
|
||||||
import org.bouncycastle.asn1.DEROctetString;
|
import org.bouncycastle.asn1.DEROctetString;
|
||||||
import org.bouncycastle.asn1.DERSequence;
|
import org.bouncycastle.asn1.DERSequence;
|
||||||
@ -69,6 +68,7 @@ import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;
|
|||||||
import org.bouncycastle.asn1.x509.X509ObjectIdentifiers;
|
import org.bouncycastle.asn1.x509.X509ObjectIdentifiers;
|
||||||
import org.bouncycastle.cert.X509CRLHolder;
|
import org.bouncycastle.cert.X509CRLHolder;
|
||||||
import org.bouncycastle.cert.X509CertificateHolder;
|
import org.bouncycastle.cert.X509CertificateHolder;
|
||||||
|
import org.bouncycastle.cert.X509ExtensionUtils;
|
||||||
import org.bouncycastle.cert.X509v2CRLBuilder;
|
import org.bouncycastle.cert.X509v2CRLBuilder;
|
||||||
import org.bouncycastle.cert.X509v3CertificateBuilder;
|
import org.bouncycastle.cert.X509v3CertificateBuilder;
|
||||||
import org.bouncycastle.cert.jcajce.JcaX509CRLConverter;
|
import org.bouncycastle.cert.jcajce.JcaX509CRLConverter;
|
||||||
@ -83,6 +83,8 @@ import org.bouncycastle.cert.ocsp.OCSPResp;
|
|||||||
import org.bouncycastle.cert.ocsp.OCSPRespBuilder;
|
import org.bouncycastle.cert.ocsp.OCSPRespBuilder;
|
||||||
import org.bouncycastle.cert.ocsp.Req;
|
import org.bouncycastle.cert.ocsp.Req;
|
||||||
import org.bouncycastle.cert.ocsp.RevokedStatus;
|
import org.bouncycastle.cert.ocsp.RevokedStatus;
|
||||||
|
import org.bouncycastle.crypto.params.RSAKeyParameters;
|
||||||
|
import org.bouncycastle.crypto.util.SubjectPublicKeyInfoFactory;
|
||||||
import org.bouncycastle.operator.ContentSigner;
|
import org.bouncycastle.operator.ContentSigner;
|
||||||
import org.bouncycastle.operator.DigestCalculator;
|
import org.bouncycastle.operator.DigestCalculator;
|
||||||
import org.bouncycastle.operator.OperatorCreationException;
|
import org.bouncycastle.operator.OperatorCreationException;
|
||||||
@ -108,24 +110,6 @@ public class PkiTestUtils {
|
|||||||
return keyPair;
|
return keyPair;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("resource")
|
|
||||||
private static SubjectKeyIdentifier createSubjectKeyId(PublicKey publicKey)
|
|
||||||
throws IOException {
|
|
||||||
ASN1InputStream asnObj = new ASN1InputStream(publicKey.getEncoded());
|
|
||||||
SubjectPublicKeyInfo info = SubjectPublicKeyInfo.getInstance(asnObj.readObject());
|
|
||||||
SubjectKeyIdentifier keyId = SubjectKeyIdentifier.getInstance(info.getEncoded());
|
|
||||||
return keyId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("resource")
|
|
||||||
private static AuthorityKeyIdentifier createAuthorityKeyId(PublicKey publicKey)
|
|
||||||
throws IOException {
|
|
||||||
ASN1InputStream asnObj = new ASN1InputStream(publicKey.getEncoded());
|
|
||||||
SubjectPublicKeyInfo info = SubjectPublicKeyInfo.getInstance(asnObj.readObject());
|
|
||||||
AuthorityKeyIdentifier keyId = AuthorityKeyIdentifier.getInstance(info);
|
|
||||||
return keyId;
|
|
||||||
}
|
|
||||||
|
|
||||||
static X509Certificate generateCertificate(PublicKey subjectPublicKey,
|
static X509Certificate generateCertificate(PublicKey subjectPublicKey,
|
||||||
String subjectDn, Date notBefore, Date notAfter,
|
String subjectDn, Date notBefore, Date notAfter,
|
||||||
X509Certificate issuerCertificate, PrivateKey issuerPrivateKey,
|
X509Certificate issuerCertificate, PrivateKey issuerPrivateKey,
|
||||||
@ -140,9 +124,15 @@ public class PkiTestUtils {
|
|||||||
} else {
|
} else {
|
||||||
issuerName = new X500Name(subjectDn);
|
issuerName = new X500Name(subjectDn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RSAPublicKey rsaPubKey = (RSAPublicKey)subjectPublicKey;
|
||||||
|
RSAKeyParameters rsaSpec = new RSAKeyParameters(false, rsaPubKey.getModulus(), rsaPubKey.getPublicExponent());
|
||||||
|
|
||||||
SubjectPublicKeyInfo subjectPublicKeyInfo = new SubjectPublicKeyInfo(
|
SubjectPublicKeyInfo subjectPublicKeyInfo =
|
||||||
ASN1Sequence.getInstance(subjectPublicKey.getEncoded()));
|
SubjectPublicKeyInfoFactory.createSubjectPublicKeyInfo(rsaSpec);
|
||||||
|
|
||||||
|
DigestCalculator digestCalc = new JcaDigestCalculatorProviderBuilder()
|
||||||
|
.setProvider("BC").build().get(CertificateID.HASH_SHA1);
|
||||||
|
|
||||||
X509v3CertificateBuilder certificateGenerator = new X509v3CertificateBuilder(
|
X509v3CertificateBuilder certificateGenerator = new X509v3CertificateBuilder(
|
||||||
issuerName
|
issuerName
|
||||||
@ -153,8 +143,14 @@ public class PkiTestUtils {
|
|||||||
, subjectPublicKeyInfo
|
, subjectPublicKeyInfo
|
||||||
);
|
);
|
||||||
|
|
||||||
certificateGenerator.addExtension(Extension.subjectKeyIdentifier, false, createSubjectKeyId(subjectPublicKey));
|
X509ExtensionUtils exUtils = new X509ExtensionUtils(digestCalc);
|
||||||
certificateGenerator.addExtension(Extension.authorityKeyIdentifier, false, createAuthorityKeyId(subjectPublicKey));
|
SubjectKeyIdentifier subKeyId = exUtils.createSubjectKeyIdentifier(subjectPublicKeyInfo);
|
||||||
|
AuthorityKeyIdentifier autKeyId = (issuerCertificate != null)
|
||||||
|
? exUtils.createAuthorityKeyIdentifier(new X509CertificateHolder(issuerCertificate.getEncoded()))
|
||||||
|
: exUtils.createAuthorityKeyIdentifier(subjectPublicKeyInfo);
|
||||||
|
|
||||||
|
certificateGenerator.addExtension(Extension.subjectKeyIdentifier, false, subKeyId);
|
||||||
|
certificateGenerator.addExtension(Extension.authorityKeyIdentifier, false, autKeyId);
|
||||||
|
|
||||||
if (caFlag) {
|
if (caFlag) {
|
||||||
BasicConstraints bc;
|
BasicConstraints bc;
|
||||||
|
@ -70,10 +70,10 @@ import org.apache.poi.poifs.crypt.dsig.services.TimeStampService;
|
|||||||
import org.apache.poi.poifs.crypt.dsig.services.TimeStampServiceValidator;
|
import org.apache.poi.poifs.crypt.dsig.services.TimeStampServiceValidator;
|
||||||
import org.apache.poi.poifs.crypt.dsig.services.XmlSignatureService;
|
import org.apache.poi.poifs.crypt.dsig.services.XmlSignatureService;
|
||||||
import org.apache.poi.poifs.crypt.dsig.spi.DigestInfo;
|
import org.apache.poi.poifs.crypt.dsig.spi.DigestInfo;
|
||||||
|
import org.apache.poi.util.DocumentHelper;
|
||||||
import org.apache.poi.util.IOUtils;
|
import org.apache.poi.util.IOUtils;
|
||||||
import org.apache.poi.util.POILogFactory;
|
import org.apache.poi.util.POILogFactory;
|
||||||
import org.apache.poi.util.POILogger;
|
import org.apache.poi.util.POILogger;
|
||||||
import org.apache.poi.util.SAXHelper;
|
|
||||||
import org.apache.xmlbeans.XmlObject;
|
import org.apache.xmlbeans.XmlObject;
|
||||||
import org.bouncycastle.asn1.x509.KeyUsage;
|
import org.bouncycastle.asn1.x509.KeyUsage;
|
||||||
import org.bouncycastle.cert.ocsp.OCSPResp;
|
import org.bouncycastle.cert.ocsp.OCSPResp;
|
||||||
@ -336,7 +336,7 @@ public class TestSignatureInfo {
|
|||||||
signatureService.initFacets(cal.getTime());
|
signatureService.initFacets(cal.getTime());
|
||||||
initKeyPair(alias, signerDn);
|
initKeyPair(alias, signerDn);
|
||||||
|
|
||||||
Document document = SAXHelper.getDocumentBuilder().newDocument();
|
Document document = DocumentHelper.createDocument();
|
||||||
|
|
||||||
// operate
|
// operate
|
||||||
List<X509Certificate> x509Chain = Collections.singletonList(x509);
|
List<X509Certificate> x509Chain = Collections.singletonList(x509);
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
package org.apache.poi.xslf;
|
package org.apache.poi.xslf;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
import org.apache.poi.POIDataSamples;
|
import org.apache.poi.POIDataSamples;
|
||||||
import org.apache.poi.openxml4j.opc.OPCPackage;
|
import org.apache.poi.openxml4j.opc.OPCPackage;
|
||||||
import org.apache.poi.openxml4j.opc.PackagePart;
|
import org.apache.poi.openxml4j.opc.PackagePart;
|
||||||
@ -61,22 +62,19 @@ public class TestXSLFSlideShow extends TestCase {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public void testSlideBasics() throws Exception {
|
public void testSlideBasics() throws Exception {
|
||||||
XSLFSlideShow xml = new XSLFSlideShow(pack);
|
XSLFSlideShow xml = new XSLFSlideShow(pack);
|
||||||
|
|
||||||
// Should have 1 master
|
// Should have 1 master
|
||||||
assertEquals(1, xml.getSlideMasterReferences().sizeOfSldMasterIdArray());
|
assertEquals(1, xml.getSlideMasterReferences().sizeOfSldMasterIdArray());
|
||||||
assertEquals(1, xml.getSlideMasterReferences().getSldMasterIdList().size());
|
|
||||||
|
|
||||||
// Should have three sheets
|
// Should have three sheets
|
||||||
assertEquals(2, xml.getSlideReferences().sizeOfSldIdArray());
|
assertEquals(2, xml.getSlideReferences().sizeOfSldIdArray());
|
||||||
assertEquals(2, xml.getSlideReferences().getSldIdList().size());
|
|
||||||
|
|
||||||
// Check they're as expected
|
// Check they're as expected
|
||||||
CTSlideIdListEntry[] slides = new CTSlideIdListEntry[
|
CTSlideIdListEntry[] slides = xml.getSlideReferences().getSldIdArray();
|
||||||
xml.getSlideReferences().getSldIdList().size()];
|
|
||||||
xml.getSlideReferences().getSldIdList().toArray(slides);
|
|
||||||
|
|
||||||
assertEquals(256, slides[0].getId());
|
assertEquals(256, slides[0].getId());
|
||||||
assertEquals(257, slides[1].getId());
|
assertEquals(257, slides[1].getId());
|
||||||
assertEquals("rId2", slides[0].getId2());
|
assertEquals("rId2", slides[0].getId2());
|
||||||
@ -91,9 +89,7 @@ public class TestXSLFSlideShow extends TestCase {
|
|||||||
assertNotNull(xml.getNotes(slides[1]));
|
assertNotNull(xml.getNotes(slides[1]));
|
||||||
|
|
||||||
// And again for the master
|
// And again for the master
|
||||||
CTSlideMasterIdListEntry[] masters = new CTSlideMasterIdListEntry[
|
CTSlideMasterIdListEntry[] masters = xml.getSlideMasterReferences().getSldMasterIdArray();
|
||||||
xml.getSlideMasterReferences().getSldMasterIdList().size()];
|
|
||||||
xml.getSlideMasterReferences().getSldMasterIdList().toArray(masters);
|
|
||||||
|
|
||||||
assertEquals(2147483648l, masters[0].getId());
|
assertEquals(2147483648l, masters[0].getId());
|
||||||
assertEquals("rId1", masters[0].getId2());
|
assertEquals("rId1", masters[0].getId2());
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
package org.apache.poi.xslf.usermodel;
|
package org.apache.poi.xslf.usermodel;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
import org.apache.poi.POIDataSamples;
|
import org.apache.poi.POIDataSamples;
|
||||||
import org.apache.poi.openxml4j.opc.OPCPackage;
|
import org.apache.poi.openxml4j.opc.OPCPackage;
|
||||||
import org.apache.poi.openxml4j.opc.PackagePart;
|
import org.apache.poi.openxml4j.opc.PackagePart;
|
||||||
@ -58,6 +59,7 @@ public class TestXMLSlideShow extends TestCase {
|
|||||||
assertTrue(xml.getSlideMasters().length > 0);
|
assertTrue(xml.getSlideMasters().length > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public void testSlideBasics() throws Exception {
|
public void testSlideBasics() throws Exception {
|
||||||
XMLSlideShow xml = new XMLSlideShow(pack);
|
XMLSlideShow xml = new XMLSlideShow(pack);
|
||||||
|
|
||||||
@ -68,9 +70,7 @@ public class TestXMLSlideShow extends TestCase {
|
|||||||
assertEquals(2, xml.getSlides().length);
|
assertEquals(2, xml.getSlides().length);
|
||||||
|
|
||||||
// Check they're as expected
|
// Check they're as expected
|
||||||
CTSlideIdListEntry[] slides = new CTSlideIdListEntry[
|
CTSlideIdListEntry[] slides = xml.getCTPresentation().getSldIdLst().getSldIdArray();
|
||||||
xml.getCTPresentation().getSldIdLst().getSldIdList().size()];
|
|
||||||
xml.getCTPresentation().getSldIdLst().getSldIdList().toArray(slides);
|
|
||||||
|
|
||||||
assertEquals(256, slides[0].getId());
|
assertEquals(256, slides[0].getId());
|
||||||
assertEquals(257, slides[1].getId());
|
assertEquals(257, slides[1].getId());
|
||||||
@ -86,9 +86,7 @@ public class TestXMLSlideShow extends TestCase {
|
|||||||
assertNotNull(xml.getSlides()[1].getNotes());
|
assertNotNull(xml.getSlides()[1].getNotes());
|
||||||
|
|
||||||
// Next up look for the slide master
|
// Next up look for the slide master
|
||||||
CTSlideMasterIdListEntry[] masters = new CTSlideMasterIdListEntry[
|
CTSlideMasterIdListEntry[] masters = xml.getCTPresentation().getSldMasterIdLst().getSldMasterIdArray();
|
||||||
xml.getCTPresentation().getSldMasterIdLst().getSldMasterIdList().size()];
|
|
||||||
xml.getCTPresentation().getSldMasterIdLst().getSldMasterIdList().toArray(masters);
|
|
||||||
|
|
||||||
assertEquals(2147483648l, masters[0].getId());
|
assertEquals(2147483648l, masters[0].getId());
|
||||||
assertEquals("rId1", masters[0].getId2());
|
assertEquals("rId1", masters[0].getId2());
|
||||||
|
@ -16,12 +16,19 @@
|
|||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.xslf.usermodel;
|
package org.apache.poi.xslf.usermodel;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
import org.apache.poi.util.Units;
|
import org.apache.poi.util.Units;
|
||||||
import org.apache.poi.xslf.XSLFTestDataSamples;
|
import org.apache.poi.xslf.XSLFTestDataSamples;
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.*;
|
import org.openxmlformats.schemas.drawingml.x2006.main.CTEffectStyleItem;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.main.CTEffectStyleList;
|
||||||
import java.awt.Color;
|
import org.openxmlformats.schemas.drawingml.x2006.main.CTOuterShadowEffect;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.main.CTStyleMatrix;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.main.STLineCap;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.main.STPresetLineDashVal;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Yegor Kozlov
|
* @author Yegor Kozlov
|
||||||
@ -243,13 +250,14 @@ public class TestXSLFSimpleShape extends TestCase {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings({ "deprecation", "unused" })
|
||||||
public void testShadowEffects(){
|
public void testShadowEffects(){
|
||||||
XMLSlideShow ppt = new XMLSlideShow();
|
XMLSlideShow ppt = new XMLSlideShow();
|
||||||
XSLFSlide slide = ppt.createSlide();
|
XSLFSlide slide = ppt.createSlide();
|
||||||
CTStyleMatrix styleMatrix = slide.getTheme().getXmlObject().getThemeElements().getFmtScheme();
|
CTStyleMatrix styleMatrix = slide.getTheme().getXmlObject().getThemeElements().getFmtScheme();
|
||||||
CTEffectStyleList lst = styleMatrix.getEffectStyleLst();
|
CTEffectStyleList lst = styleMatrix.getEffectStyleLst();
|
||||||
assertNotNull(lst);
|
assertNotNull(lst);
|
||||||
for(CTEffectStyleItem ef : lst.getEffectStyleList()){
|
for(CTEffectStyleItem ef : lst.getEffectStyleArray()){
|
||||||
CTOuterShadowEffect obj = ef.getEffectLst().getOuterShdw();
|
CTOuterShadowEffect obj = ef.getEffectLst().getOuterShdw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,12 +16,11 @@
|
|||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.xssf;
|
package org.apache.poi.xssf;
|
||||||
|
|
||||||
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
|
||||||
|
|
||||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
||||||
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||||
|
|
||||||
public class TestSheetProtection extends TestCase {
|
public class TestSheetProtection extends TestCase {
|
||||||
private XSSFSheet sheet;
|
private XSSFSheet sheet;
|
||||||
|
|
||||||
@ -75,6 +74,8 @@ public class TestSheetProtection extends TestCase {
|
|||||||
assertFalse(sheet.isAutoFilterLocked());
|
assertFalse(sheet.isAutoFilterLocked());
|
||||||
sheet.enableLocking();
|
sheet.enableLocking();
|
||||||
assertTrue(sheet.isAutoFilterLocked());
|
assertTrue(sheet.isAutoFilterLocked());
|
||||||
|
sheet.lockAutoFilter(false);
|
||||||
|
assertFalse(sheet.isAutoFilterLocked());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWriteDeleteColumns() throws Exception {
|
public void testWriteDeleteColumns() throws Exception {
|
||||||
@ -83,6 +84,8 @@ public class TestSheetProtection extends TestCase {
|
|||||||
assertFalse(sheet.isDeleteColumnsLocked());
|
assertFalse(sheet.isDeleteColumnsLocked());
|
||||||
sheet.enableLocking();
|
sheet.enableLocking();
|
||||||
assertTrue(sheet.isDeleteColumnsLocked());
|
assertTrue(sheet.isDeleteColumnsLocked());
|
||||||
|
sheet.lockDeleteColumns(false);
|
||||||
|
assertFalse(sheet.isDeleteColumnsLocked());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWriteDeleteRows() throws Exception {
|
public void testWriteDeleteRows() throws Exception {
|
||||||
@ -91,6 +94,8 @@ public class TestSheetProtection extends TestCase {
|
|||||||
assertFalse(sheet.isDeleteRowsLocked());
|
assertFalse(sheet.isDeleteRowsLocked());
|
||||||
sheet.enableLocking();
|
sheet.enableLocking();
|
||||||
assertTrue(sheet.isDeleteRowsLocked());
|
assertTrue(sheet.isDeleteRowsLocked());
|
||||||
|
sheet.lockDeleteRows(false);
|
||||||
|
assertFalse(sheet.isDeleteRowsLocked());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWriteFormatCells() throws Exception {
|
public void testWriteFormatCells() throws Exception {
|
||||||
@ -99,6 +104,8 @@ public class TestSheetProtection extends TestCase {
|
|||||||
assertFalse(sheet.isFormatCellsLocked());
|
assertFalse(sheet.isFormatCellsLocked());
|
||||||
sheet.enableLocking();
|
sheet.enableLocking();
|
||||||
assertTrue(sheet.isFormatCellsLocked());
|
assertTrue(sheet.isFormatCellsLocked());
|
||||||
|
sheet.lockFormatCells(false);
|
||||||
|
assertFalse(sheet.isFormatCellsLocked());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWriteFormatColumns() throws Exception {
|
public void testWriteFormatColumns() throws Exception {
|
||||||
@ -107,6 +114,8 @@ public class TestSheetProtection extends TestCase {
|
|||||||
assertFalse(sheet.isFormatColumnsLocked());
|
assertFalse(sheet.isFormatColumnsLocked());
|
||||||
sheet.enableLocking();
|
sheet.enableLocking();
|
||||||
assertTrue(sheet.isFormatColumnsLocked());
|
assertTrue(sheet.isFormatColumnsLocked());
|
||||||
|
sheet.lockFormatColumns(false);
|
||||||
|
assertFalse(sheet.isFormatColumnsLocked());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWriteFormatRows() throws Exception {
|
public void testWriteFormatRows() throws Exception {
|
||||||
@ -115,6 +124,8 @@ public class TestSheetProtection extends TestCase {
|
|||||||
assertFalse(sheet.isFormatRowsLocked());
|
assertFalse(sheet.isFormatRowsLocked());
|
||||||
sheet.enableLocking();
|
sheet.enableLocking();
|
||||||
assertTrue(sheet.isFormatRowsLocked());
|
assertTrue(sheet.isFormatRowsLocked());
|
||||||
|
sheet.lockFormatRows(false);
|
||||||
|
assertFalse(sheet.isFormatRowsLocked());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWriteInsertColumns() throws Exception {
|
public void testWriteInsertColumns() throws Exception {
|
||||||
@ -123,6 +134,8 @@ public class TestSheetProtection extends TestCase {
|
|||||||
assertFalse(sheet.isInsertColumnsLocked());
|
assertFalse(sheet.isInsertColumnsLocked());
|
||||||
sheet.enableLocking();
|
sheet.enableLocking();
|
||||||
assertTrue(sheet.isInsertColumnsLocked());
|
assertTrue(sheet.isInsertColumnsLocked());
|
||||||
|
sheet.lockInsertColumns(false);
|
||||||
|
assertFalse(sheet.isInsertColumnsLocked());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWriteInsertHyperlinks() throws Exception {
|
public void testWriteInsertHyperlinks() throws Exception {
|
||||||
@ -131,6 +144,8 @@ public class TestSheetProtection extends TestCase {
|
|||||||
assertFalse(sheet.isInsertHyperlinksLocked());
|
assertFalse(sheet.isInsertHyperlinksLocked());
|
||||||
sheet.enableLocking();
|
sheet.enableLocking();
|
||||||
assertTrue(sheet.isInsertHyperlinksLocked());
|
assertTrue(sheet.isInsertHyperlinksLocked());
|
||||||
|
sheet.lockInsertHyperlinks(false);
|
||||||
|
assertFalse(sheet.isInsertHyperlinksLocked());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWriteInsertRows() throws Exception {
|
public void testWriteInsertRows() throws Exception {
|
||||||
@ -139,6 +154,8 @@ public class TestSheetProtection extends TestCase {
|
|||||||
assertFalse(sheet.isInsertRowsLocked());
|
assertFalse(sheet.isInsertRowsLocked());
|
||||||
sheet.enableLocking();
|
sheet.enableLocking();
|
||||||
assertTrue(sheet.isInsertRowsLocked());
|
assertTrue(sheet.isInsertRowsLocked());
|
||||||
|
sheet.lockInsertRows(false);
|
||||||
|
assertFalse(sheet.isInsertRowsLocked());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWritePivotTables() throws Exception {
|
public void testWritePivotTables() throws Exception {
|
||||||
@ -147,6 +164,8 @@ public class TestSheetProtection extends TestCase {
|
|||||||
assertFalse(sheet.isPivotTablesLocked());
|
assertFalse(sheet.isPivotTablesLocked());
|
||||||
sheet.enableLocking();
|
sheet.enableLocking();
|
||||||
assertTrue(sheet.isPivotTablesLocked());
|
assertTrue(sheet.isPivotTablesLocked());
|
||||||
|
sheet.lockPivotTables(false);
|
||||||
|
assertFalse(sheet.isPivotTablesLocked());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWriteSort() throws Exception {
|
public void testWriteSort() throws Exception {
|
||||||
@ -155,6 +174,8 @@ public class TestSheetProtection extends TestCase {
|
|||||||
assertFalse(sheet.isSortLocked());
|
assertFalse(sheet.isSortLocked());
|
||||||
sheet.enableLocking();
|
sheet.enableLocking();
|
||||||
assertTrue(sheet.isSortLocked());
|
assertTrue(sheet.isSortLocked());
|
||||||
|
sheet.lockSort(false);
|
||||||
|
assertFalse(sheet.isSortLocked());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWriteObjects() throws Exception {
|
public void testWriteObjects() throws Exception {
|
||||||
@ -163,6 +184,8 @@ public class TestSheetProtection extends TestCase {
|
|||||||
assertFalse(sheet.isObjectsLocked());
|
assertFalse(sheet.isObjectsLocked());
|
||||||
sheet.enableLocking();
|
sheet.enableLocking();
|
||||||
assertTrue(sheet.isObjectsLocked());
|
assertTrue(sheet.isObjectsLocked());
|
||||||
|
sheet.lockObjects(false);
|
||||||
|
assertFalse(sheet.isObjectsLocked());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWriteScenarios() throws Exception {
|
public void testWriteScenarios() throws Exception {
|
||||||
@ -171,6 +194,8 @@ public class TestSheetProtection extends TestCase {
|
|||||||
assertFalse(sheet.isScenariosLocked());
|
assertFalse(sheet.isScenariosLocked());
|
||||||
sheet.enableLocking();
|
sheet.enableLocking();
|
||||||
assertTrue(sheet.isScenariosLocked());
|
assertTrue(sheet.isScenariosLocked());
|
||||||
|
sheet.lockScenarios(false);
|
||||||
|
assertFalse(sheet.isScenariosLocked());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWriteSelectLockedCells() throws Exception {
|
public void testWriteSelectLockedCells() throws Exception {
|
||||||
@ -179,6 +204,8 @@ public class TestSheetProtection extends TestCase {
|
|||||||
assertFalse(sheet.isSelectLockedCellsLocked());
|
assertFalse(sheet.isSelectLockedCellsLocked());
|
||||||
sheet.enableLocking();
|
sheet.enableLocking();
|
||||||
assertTrue(sheet.isSelectLockedCellsLocked());
|
assertTrue(sheet.isSelectLockedCellsLocked());
|
||||||
|
sheet.lockSelectLockedCells(false);
|
||||||
|
assertFalse(sheet.isSelectLockedCellsLocked());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWriteSelectUnlockedCells() throws Exception {
|
public void testWriteSelectUnlockedCells() throws Exception {
|
||||||
@ -187,6 +214,8 @@ public class TestSheetProtection extends TestCase {
|
|||||||
assertFalse(sheet.isSelectUnlockedCellsLocked());
|
assertFalse(sheet.isSelectUnlockedCellsLocked());
|
||||||
sheet.enableLocking();
|
sheet.enableLocking();
|
||||||
assertTrue(sheet.isSelectUnlockedCellsLocked());
|
assertTrue(sheet.isSelectUnlockedCellsLocked());
|
||||||
|
sheet.lockSelectUnlockedCells(false);
|
||||||
|
assertFalse(sheet.isSelectUnlockedCellsLocked());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWriteSelectEnableLocking() throws Exception {
|
public void testWriteSelectEnableLocking() throws Exception {
|
||||||
|
@ -16,42 +16,94 @@
|
|||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.xssf;
|
package org.apache.poi.xssf;
|
||||||
|
|
||||||
import java.io.File;
|
import static org.apache.poi.xssf.XSSFTestDataSamples.openSampleWorkbook;
|
||||||
|
import static org.apache.poi.xssf.XSSFTestDataSamples.writeOutAndReadBack;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.io.FileInputStream;
|
import org.apache.poi.poifs.crypt.CryptoFunctions;
|
||||||
import java.io.FileOutputStream;
|
import org.apache.poi.poifs.crypt.HashAlgorithm;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
import org.apache.poi.util.TempFile;
|
|
||||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
public class TestWorkbookProtection extends TestCase {
|
public class TestWorkbookProtection {
|
||||||
|
|
||||||
public void testShouldReadWorkbookProtection() throws Exception {
|
@Test
|
||||||
XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("workbookProtection_not_protected.xlsx");
|
public void workbookAndRevisionPassword() throws Exception {
|
||||||
|
XSSFWorkbook workbook;
|
||||||
|
String password = "test";
|
||||||
|
|
||||||
|
// validate password with an actual office file (Excel 2010)
|
||||||
|
workbook = openSampleWorkbook("workbookProtection-workbook_password_user_range-2010.xlsx");
|
||||||
|
assertTrue(workbook.validateWorkbookPassword(password));
|
||||||
|
|
||||||
|
// validate with another office file (Excel 2013)
|
||||||
|
workbook = openSampleWorkbook("workbookProtection-workbook_password-2013.xlsx");
|
||||||
|
assertTrue(workbook.validateWorkbookPassword(password));
|
||||||
|
|
||||||
|
|
||||||
|
workbook = openSampleWorkbook("workbookProtection_not_protected.xlsx");
|
||||||
|
|
||||||
|
// setting a null password shouldn't introduce the protection element
|
||||||
|
workbook.setWorkbookPassword(null, null);
|
||||||
|
assertNull(workbook.getCTWorkbook().getWorkbookProtection());
|
||||||
|
|
||||||
|
// compare the hashes
|
||||||
|
workbook.setWorkbookPassword(password, null);
|
||||||
|
int hashVal = CryptoFunctions.createXorVerifier1(password);
|
||||||
|
int actualVal = Integer.parseInt(workbook.getCTWorkbook().getWorkbookProtection().xgetWorkbookPassword().getStringValue(),16);
|
||||||
|
assertEquals(hashVal, actualVal);
|
||||||
|
assertTrue(workbook.validateWorkbookPassword(password));
|
||||||
|
|
||||||
|
// removing the password again
|
||||||
|
workbook.setWorkbookPassword(null, null);
|
||||||
|
assertFalse(workbook.getCTWorkbook().getWorkbookProtection().isSetWorkbookPassword());
|
||||||
|
|
||||||
|
// removing the whole protection structure
|
||||||
|
workbook.unLock();
|
||||||
|
assertNull(workbook.getCTWorkbook().getWorkbookProtection());
|
||||||
|
|
||||||
|
// setting a null password shouldn't introduce the protection element
|
||||||
|
workbook.setRevisionsPassword(null, null);
|
||||||
|
assertNull(workbook.getCTWorkbook().getWorkbookProtection());
|
||||||
|
|
||||||
|
// compare the hashes
|
||||||
|
password = "T\u0400ST\u0100passwordWhichIsLongerThan15Chars";
|
||||||
|
workbook.setRevisionsPassword(password, null);
|
||||||
|
hashVal = CryptoFunctions.createXorVerifier1(password);
|
||||||
|
actualVal = Integer.parseInt(workbook.getCTWorkbook().getWorkbookProtection().xgetRevisionsPassword().getStringValue(),16);
|
||||||
|
assertEquals(hashVal, actualVal);
|
||||||
|
assertTrue(workbook.validateRevisionsPassword(password));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldReadWorkbookProtection() throws Exception {
|
||||||
|
XSSFWorkbook workbook = openSampleWorkbook("workbookProtection_not_protected.xlsx");
|
||||||
assertFalse(workbook.isStructureLocked());
|
assertFalse(workbook.isStructureLocked());
|
||||||
assertFalse(workbook.isWindowsLocked());
|
assertFalse(workbook.isWindowsLocked());
|
||||||
assertFalse(workbook.isRevisionLocked());
|
assertFalse(workbook.isRevisionLocked());
|
||||||
|
|
||||||
workbook = XSSFTestDataSamples.openSampleWorkbook("workbookProtection_workbook_structure_protected.xlsx");
|
workbook = openSampleWorkbook("workbookProtection_workbook_structure_protected.xlsx");
|
||||||
assertTrue(workbook.isStructureLocked());
|
assertTrue(workbook.isStructureLocked());
|
||||||
assertFalse(workbook.isWindowsLocked());
|
assertFalse(workbook.isWindowsLocked());
|
||||||
assertFalse(workbook.isRevisionLocked());
|
assertFalse(workbook.isRevisionLocked());
|
||||||
|
|
||||||
workbook = XSSFTestDataSamples.openSampleWorkbook("workbookProtection_workbook_windows_protected.xlsx");
|
workbook = openSampleWorkbook("workbookProtection_workbook_windows_protected.xlsx");
|
||||||
assertTrue(workbook.isWindowsLocked());
|
assertTrue(workbook.isWindowsLocked());
|
||||||
assertFalse(workbook.isStructureLocked());
|
assertFalse(workbook.isStructureLocked());
|
||||||
assertFalse(workbook.isRevisionLocked());
|
assertFalse(workbook.isRevisionLocked());
|
||||||
|
|
||||||
workbook = XSSFTestDataSamples.openSampleWorkbook("workbookProtection_workbook_revision_protected.xlsx");
|
workbook = openSampleWorkbook("workbookProtection_workbook_revision_protected.xlsx");
|
||||||
assertTrue(workbook.isRevisionLocked());
|
assertTrue(workbook.isRevisionLocked());
|
||||||
assertFalse(workbook.isWindowsLocked());
|
assertFalse(workbook.isWindowsLocked());
|
||||||
assertFalse(workbook.isStructureLocked());
|
assertFalse(workbook.isStructureLocked());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testShouldWriteStructureLock() throws Exception {
|
@Test
|
||||||
XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("workbookProtection_not_protected.xlsx");
|
public void shouldWriteStructureLock() throws Exception {
|
||||||
|
XSSFWorkbook workbook = openSampleWorkbook("workbookProtection_not_protected.xlsx");
|
||||||
assertFalse(workbook.isStructureLocked());
|
assertFalse(workbook.isStructureLocked());
|
||||||
|
|
||||||
workbook.lockStructure();
|
workbook.lockStructure();
|
||||||
@ -63,8 +115,9 @@ public class TestWorkbookProtection extends TestCase {
|
|||||||
assertFalse(workbook.isStructureLocked());
|
assertFalse(workbook.isStructureLocked());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testShouldWriteWindowsLock() throws Exception {
|
@Test
|
||||||
XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("workbookProtection_not_protected.xlsx");
|
public void shouldWriteWindowsLock() throws Exception {
|
||||||
|
XSSFWorkbook workbook = openSampleWorkbook("workbookProtection_not_protected.xlsx");
|
||||||
assertFalse(workbook.isWindowsLocked());
|
assertFalse(workbook.isWindowsLocked());
|
||||||
|
|
||||||
workbook.lockWindows();
|
workbook.lockWindows();
|
||||||
@ -76,8 +129,9 @@ public class TestWorkbookProtection extends TestCase {
|
|||||||
assertFalse(workbook.isWindowsLocked());
|
assertFalse(workbook.isWindowsLocked());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testShouldWriteRevisionLock() throws Exception {
|
@Test
|
||||||
XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("workbookProtection_not_protected.xlsx");
|
public void shouldWriteRevisionLock() throws Exception {
|
||||||
|
XSSFWorkbook workbook = openSampleWorkbook("workbookProtection_not_protected.xlsx");
|
||||||
assertFalse(workbook.isRevisionLocked());
|
assertFalse(workbook.isRevisionLocked());
|
||||||
|
|
||||||
workbook.lockRevision();
|
workbook.lockRevision();
|
||||||
@ -89,22 +143,32 @@ public class TestWorkbookProtection extends TestCase {
|
|||||||
assertFalse(workbook.isRevisionLocked());
|
assertFalse(workbook.isRevisionLocked());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("resource")
|
||||||
|
@Test
|
||||||
|
public void testHashPassword() throws Exception {
|
||||||
|
XSSFWorkbook wb = new XSSFWorkbook();
|
||||||
|
wb.lockRevision();
|
||||||
|
wb.setRevisionsPassword("test", HashAlgorithm.sha1);
|
||||||
|
|
||||||
|
wb = writeOutAndReadBack(wb);
|
||||||
|
|
||||||
|
assertTrue(wb.isRevisionLocked());
|
||||||
|
assertTrue(wb.validateRevisionsPassword("test"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("resource")
|
||||||
|
@Test
|
||||||
public void testIntegration() throws Exception {
|
public void testIntegration() throws Exception {
|
||||||
XSSFWorkbook wb = new XSSFWorkbook();
|
XSSFWorkbook wb = new XSSFWorkbook();
|
||||||
wb.createSheet("Testing purpose sheet");
|
wb.createSheet("Testing purpose sheet");
|
||||||
assertFalse(wb.isRevisionLocked());
|
assertFalse(wb.isRevisionLocked());
|
||||||
|
|
||||||
wb.lockRevision();
|
wb.lockRevision();
|
||||||
|
wb.setRevisionsPassword("test", null);
|
||||||
|
|
||||||
File tempFile = TempFile.createTempFile("workbookProtection", ".xlsx");
|
wb = writeOutAndReadBack(wb);
|
||||||
FileOutputStream out = new FileOutputStream(tempFile);
|
|
||||||
wb.write(out);
|
assertTrue(wb.isRevisionLocked());
|
||||||
out.close();
|
assertTrue(wb.validateRevisionsPassword("test"));
|
||||||
|
|
||||||
FileInputStream inputStream = new FileInputStream(tempFile);
|
|
||||||
XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
|
|
||||||
inputStream.close();
|
|
||||||
|
|
||||||
assertTrue(workbook.isRevisionLocked());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,8 @@ import org.xml.sax.SAXException;
|
|||||||
* @author Roberto Manicardi
|
* @author Roberto Manicardi
|
||||||
*/
|
*/
|
||||||
public final class TestXSSFExportToXML extends TestCase {
|
public final class TestXSSFExportToXML extends TestCase {
|
||||||
public void testExportToXML() throws Exception {
|
|
||||||
|
public void testExportToXML() throws Exception {
|
||||||
|
|
||||||
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("CustomXMLMappings.xlsx");
|
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("CustomXMLMappings.xlsx");
|
||||||
|
|
||||||
@ -580,4 +581,37 @@ public final class TestXSSFExportToXML extends TestCase {
|
|||||||
}
|
}
|
||||||
assertTrue(found);
|
assertTrue(found);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testRefElementsInXmlSchema_Bugzilla_56730() throws Exception {
|
||||||
|
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("56730.xlsx");
|
||||||
|
|
||||||
|
boolean found = false;
|
||||||
|
for (POIXMLDocumentPart p : wb.getRelations()) {
|
||||||
|
|
||||||
|
if (!(p instanceof MapInfo)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
MapInfo mapInfo = (MapInfo) p;
|
||||||
|
|
||||||
|
XSSFMap map = mapInfo.getXSSFMapById(1);
|
||||||
|
|
||||||
|
assertNotNull("XSSFMap is null", map);
|
||||||
|
|
||||||
|
XSSFExportToXml exporter = new XSSFExportToXml(map);
|
||||||
|
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||||
|
exporter.exportToXML(os, true);
|
||||||
|
String xmlData = os.toString("UTF-8");
|
||||||
|
|
||||||
|
assertNotNull(xmlData);
|
||||||
|
assertFalse(xmlData.equals(""));
|
||||||
|
|
||||||
|
assertEquals("2014-12-31", xmlData.split("<DATE>")[1].split("</DATE>")[0].trim());
|
||||||
|
assertEquals("12.5", xmlData.split("<REFELEMENT>")[1].split("</REFELEMENT>")[0].trim());
|
||||||
|
|
||||||
|
parseXML(xmlData);
|
||||||
|
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
assertTrue(found);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ public final class TestCalculationChain extends TestCase {
|
|||||||
CalculationChain chain = wb.getCalculationChain();
|
CalculationChain chain = wb.getCalculationChain();
|
||||||
//the bean holding the reference to the formula to be deleted
|
//the bean holding the reference to the formula to be deleted
|
||||||
CTCalcCell c = chain.getCTCalcChain().getCArray(0);
|
CTCalcCell c = chain.getCTCalcChain().getCArray(0);
|
||||||
int cnt = chain.getCTCalcChain().getCList().size();
|
int cnt = chain.getCTCalcChain().sizeOfCArray();
|
||||||
assertEquals(10, c.getI());
|
assertEquals(10, c.getI());
|
||||||
assertEquals("E1", c.getR());
|
assertEquals("E1", c.getR());
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ public final class TestCalculationChain extends TestCase {
|
|||||||
|
|
||||||
//the count of items is less by one
|
//the count of items is less by one
|
||||||
c = chain.getCTCalcChain().getCArray(0);
|
c = chain.getCTCalcChain().getCArray(0);
|
||||||
int cnt2 = chain.getCTCalcChain().getCList().size();
|
int cnt2 = chain.getCTCalcChain().sizeOfCArray();
|
||||||
assertEquals(cnt - 1, cnt2);
|
assertEquals(cnt - 1, cnt2);
|
||||||
//the first item in the calculation chain is the former second one
|
//the first item in the calculation chain is the former second one
|
||||||
assertEquals(10, c.getI());
|
assertEquals(10, c.getI());
|
||||||
|
@ -50,7 +50,7 @@ public final class TestMapInfo extends TestCase {
|
|||||||
|
|
||||||
assertNotNull(ctMapInfo);
|
assertNotNull(ctMapInfo);
|
||||||
|
|
||||||
assertEquals(1, ctMapInfo.getSchemaList().size());
|
assertEquals(1, ctMapInfo.sizeOfSchemaArray());
|
||||||
|
|
||||||
for (XSSFMap map : mapInfo.getAllXSSFMaps()) {
|
for (XSSFMap map : mapInfo.getAllXSSFMaps()) {
|
||||||
Node xmlSchema = map.getSchema();
|
Node xmlSchema = map.getSchema();
|
||||||
|
@ -0,0 +1,78 @@
|
|||||||
|
/* ====================================================================
|
||||||
|
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.xssf.model;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
|
||||||
|
import org.apache.commons.codec.binary.Hex;
|
||||||
|
import org.apache.poi.ss.usermodel.CellStyle;
|
||||||
|
import org.apache.poi.ss.usermodel.Row;
|
||||||
|
import org.apache.poi.xssf.XSSFTestDataSamples;
|
||||||
|
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
|
||||||
|
import org.apache.poi.xssf.usermodel.XSSFColor;
|
||||||
|
import org.apache.poi.xssf.usermodel.XSSFFont;
|
||||||
|
import org.apache.poi.xssf.usermodel.XSSFRow;
|
||||||
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class TestThemesTable {
|
||||||
|
private String testFile = "Themes.xlsx";
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testThemesTableColors() throws Exception {
|
||||||
|
XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook(testFile);
|
||||||
|
String rgbExpected[] = {
|
||||||
|
"ffffff", // Lt1
|
||||||
|
"000000", // Dk1
|
||||||
|
"eeece1", // Lt2
|
||||||
|
"1f497d", // DK2
|
||||||
|
"4f81bd", // Accent1
|
||||||
|
"c0504d", // Accent2
|
||||||
|
"9bbb59", // Accent3
|
||||||
|
"8064a2", // Accent4
|
||||||
|
"4bacc6", // Accent5
|
||||||
|
"f79646", // Accent6
|
||||||
|
"0000ff", // Hlink
|
||||||
|
"800080" // FolHlink
|
||||||
|
};
|
||||||
|
boolean createFile = false;
|
||||||
|
int i=0;
|
||||||
|
for (Row row : workbook.getSheetAt(0)) {
|
||||||
|
XSSFFont font = ((XSSFRow)row).getCell(0).getCellStyle().getFont();
|
||||||
|
XSSFColor color = font.getXSSFColor();
|
||||||
|
assertEquals("Failed color theme "+i, rgbExpected[i], Hex.encodeHexString(color.getRgb()));
|
||||||
|
long themeIdx = font.getCTFont().getColorArray(0).getTheme();
|
||||||
|
assertEquals("Failed color theme "+i, i, themeIdx);
|
||||||
|
if (createFile) {
|
||||||
|
XSSFCellStyle cs = (XSSFCellStyle)row.getSheet().getWorkbook().createCellStyle();
|
||||||
|
cs.setFillForegroundColor(color);
|
||||||
|
cs.setFillPattern(CellStyle.SOLID_FOREGROUND);
|
||||||
|
row.createCell(1).setCellStyle(cs);
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (createFile) {
|
||||||
|
FileOutputStream fos = new FileOutputStream("foobaa.xlsx");
|
||||||
|
workbook.write(fos);
|
||||||
|
fos.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -964,9 +964,9 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
assertEquals(text, cell.getStringCellValue());
|
assertEquals(text, cell.getStringCellValue());
|
||||||
|
|
||||||
assertEquals(4, cell.getRichStringCellValue().numFormattingRuns());
|
assertEquals(4, cell.getRichStringCellValue().numFormattingRuns());
|
||||||
assertEquals("Use", cell.getRichStringCellValue().getCTRst().getRList().get(0).getT());
|
assertEquals("Use", cell.getRichStringCellValue().getCTRst().getRArray(0).getT());
|
||||||
|
|
||||||
String r3 = cell.getRichStringCellValue().getCTRst().getRList().get(2).getT();
|
String r3 = cell.getRichStringCellValue().getCTRst().getRArray(2).getT();
|
||||||
assertEquals("line.\n", r3.substring(r3.length()-6));
|
assertEquals("line.\n", r3.substring(r3.length()-6));
|
||||||
|
|
||||||
// Save and re-check
|
// Save and re-check
|
||||||
|
@ -45,6 +45,7 @@ public class TestXSSFColGrouping extends TestCase {
|
|||||||
* Tests that POI doesn't produce "col" elements without "width" attribute.
|
* Tests that POI doesn't produce "col" elements without "width" attribute.
|
||||||
* POI-52186
|
* POI-52186
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public void testNoColsWithoutWidthWhenGrouping() {
|
public void testNoColsWithoutWidthWhenGrouping() {
|
||||||
XSSFWorkbook wb = new XSSFWorkbook();
|
XSSFWorkbook wb = new XSSFWorkbook();
|
||||||
XSSFSheet sheet = wb.createSheet("test");
|
XSSFSheet sheet = wb.createSheet("test");
|
||||||
@ -60,7 +61,7 @@ public class TestXSSFColGrouping extends TestCase {
|
|||||||
|
|
||||||
CTCols cols = sheet.getCTWorksheet().getColsArray(0);
|
CTCols cols = sheet.getCTWorksheet().getColsArray(0);
|
||||||
logger.log(POILogger.DEBUG, "test52186/cols:" + cols);
|
logger.log(POILogger.DEBUG, "test52186/cols:" + cols);
|
||||||
for (CTCol col : cols.getColList()) {
|
for (CTCol col : cols.getColArray()) {
|
||||||
assertTrue("Col width attribute is unset: " + col.toString(), col.isSetWidth());
|
assertTrue("Col width attribute is unset: " + col.toString(), col.isSetWidth());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -69,6 +70,7 @@ public class TestXSSFColGrouping extends TestCase {
|
|||||||
* Tests that POI doesn't produce "col" elements without "width" attribute.
|
* Tests that POI doesn't produce "col" elements without "width" attribute.
|
||||||
* POI-52186
|
* POI-52186
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public void testNoColsWithoutWidthWhenGroupingAndCollapsing() {
|
public void testNoColsWithoutWidthWhenGroupingAndCollapsing() {
|
||||||
XSSFWorkbook wb = new XSSFWorkbook();
|
XSSFWorkbook wb = new XSSFWorkbook();
|
||||||
XSSFSheet sheet = wb.createSheet("test");
|
XSSFSheet sheet = wb.createSheet("test");
|
||||||
@ -90,7 +92,7 @@ public class TestXSSFColGrouping extends TestCase {
|
|||||||
assertEquals("Unexpected width of column "+ i, 5000, sheet.getColumnWidth(i));
|
assertEquals("Unexpected width of column "+ i, 5000, sheet.getColumnWidth(i));
|
||||||
}
|
}
|
||||||
cols = sheet.getCTWorksheet().getColsArray(0);
|
cols = sheet.getCTWorksheet().getColsArray(0);
|
||||||
for (CTCol col : cols.getColList()) {
|
for (CTCol col : cols.getColArray()) {
|
||||||
assertTrue("Col width attribute is unset: " + col.toString(), col.isSetWidth());
|
assertTrue("Col width attribute is unset: " + col.toString(), col.isSetWidth());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,49 +24,49 @@ import org.apache.poi.xssf.XSSFTestDataSamples;
|
|||||||
public final class TestXSSFColor extends TestCase {
|
public final class TestXSSFColor extends TestCase {
|
||||||
public void testIndexedColour() throws Exception {
|
public void testIndexedColour() throws Exception {
|
||||||
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("48779.xlsx");
|
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("48779.xlsx");
|
||||||
|
|
||||||
// Check the CTColor is as expected
|
// Check the CTColor is as expected
|
||||||
XSSFColor indexed = wb.getCellStyleAt((short)1).getFillBackgroundXSSFColor();
|
XSSFColor indexed = wb.getCellStyleAt((short)1).getFillBackgroundXSSFColor();
|
||||||
assertEquals(true, indexed.getCTColor().isSetIndexed());
|
assertEquals(true, indexed.getCTColor().isSetIndexed());
|
||||||
assertEquals(64, indexed.getCTColor().getIndexed());
|
assertEquals(64, indexed.getCTColor().getIndexed());
|
||||||
assertEquals(false, indexed.getCTColor().isSetRgb());
|
assertEquals(false, indexed.getCTColor().isSetRgb());
|
||||||
assertEquals(null, indexed.getCTColor().getRgb());
|
assertEquals(null, indexed.getCTColor().getRgb());
|
||||||
|
|
||||||
// Now check the XSSFColor
|
// Now check the XSSFColor
|
||||||
// Note - 64 is a special "auto" one with no rgb equiv
|
// Note - 64 is a special "auto" one with no rgb equiv
|
||||||
assertEquals(64, indexed.getIndexed());
|
assertEquals(64, indexed.getIndexed());
|
||||||
assertEquals(null, indexed.getRgb());
|
assertEquals(null, indexed.getRgb());
|
||||||
assertEquals(null, indexed.getRgbWithTint());
|
assertEquals(null, indexed.getRgbWithTint());
|
||||||
assertEquals(null, indexed.getARGBHex());
|
assertEquals(null, indexed.getARGBHex());
|
||||||
|
|
||||||
// Now move to one with indexed rgb values
|
// Now move to one with indexed rgb values
|
||||||
indexed.setIndexed(59);
|
indexed.setIndexed(59);
|
||||||
assertEquals(true, indexed.getCTColor().isSetIndexed());
|
assertEquals(true, indexed.getCTColor().isSetIndexed());
|
||||||
assertEquals(59, indexed.getCTColor().getIndexed());
|
assertEquals(59, indexed.getCTColor().getIndexed());
|
||||||
assertEquals(false, indexed.getCTColor().isSetRgb());
|
assertEquals(false, indexed.getCTColor().isSetRgb());
|
||||||
assertEquals(null, indexed.getCTColor().getRgb());
|
assertEquals(null, indexed.getCTColor().getRgb());
|
||||||
|
|
||||||
assertEquals(59, indexed.getIndexed());
|
assertEquals(59, indexed.getIndexed());
|
||||||
assertEquals("FF333300", indexed.getARGBHex());
|
assertEquals("FF333300", indexed.getARGBHex());
|
||||||
|
|
||||||
assertEquals(3, indexed.getRgb().length);
|
assertEquals(3, indexed.getRgb().length);
|
||||||
assertEquals(0x33, indexed.getRgb()[0]);
|
assertEquals(0x33, indexed.getRgb()[0]);
|
||||||
assertEquals(0x33, indexed.getRgb()[1]);
|
assertEquals(0x33, indexed.getRgb()[1]);
|
||||||
assertEquals(0x00, indexed.getRgb()[2]);
|
assertEquals(0x00, indexed.getRgb()[2]);
|
||||||
|
|
||||||
assertEquals(4, indexed.getARgb().length);
|
assertEquals(4, indexed.getARgb().length);
|
||||||
assertEquals(-1, indexed.getARgb()[0]);
|
assertEquals(-1, indexed.getARgb()[0]);
|
||||||
assertEquals(0x33, indexed.getARgb()[1]);
|
assertEquals(0x33, indexed.getARgb()[1]);
|
||||||
assertEquals(0x33, indexed.getARgb()[2]);
|
assertEquals(0x33, indexed.getARgb()[2]);
|
||||||
assertEquals(0x00, indexed.getARgb()[3]);
|
assertEquals(0x00, indexed.getARgb()[3]);
|
||||||
|
|
||||||
// You don't get tinted indexed colours, sorry...
|
// You don't get tinted indexed colours, sorry...
|
||||||
assertEquals(null, indexed.getRgbWithTint());
|
assertEquals(null, indexed.getRgbWithTint());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRGBColour() throws Exception {
|
public void testRGBColour() throws Exception {
|
||||||
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("50299.xlsx");
|
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("50299.xlsx");
|
||||||
|
|
||||||
// Check the CTColor is as expected
|
// Check the CTColor is as expected
|
||||||
XSSFColor rgb3 = wb.getCellStyleAt((short)25).getFillForegroundXSSFColor();
|
XSSFColor rgb3 = wb.getCellStyleAt((short)25).getFillForegroundXSSFColor();
|
||||||
assertEquals(false, rgb3.getCTColor().isSetIndexed());
|
assertEquals(false, rgb3.getCTColor().isSetIndexed());
|
||||||
@ -75,37 +75,39 @@ public final class TestXSSFColor extends TestCase {
|
|||||||
assertEquals(-0.34999, rgb3.getCTColor().getTint(), 0.00001);
|
assertEquals(-0.34999, rgb3.getCTColor().getTint(), 0.00001);
|
||||||
assertEquals(true, rgb3.getCTColor().isSetRgb());
|
assertEquals(true, rgb3.getCTColor().isSetRgb());
|
||||||
assertEquals(3, rgb3.getCTColor().getRgb().length);
|
assertEquals(3, rgb3.getCTColor().getRgb().length);
|
||||||
|
|
||||||
// Now check the XSSFColor
|
// Now check the XSSFColor
|
||||||
assertEquals(0, rgb3.getIndexed());
|
assertEquals(0, rgb3.getIndexed());
|
||||||
assertEquals(-0.34999, rgb3.getTint(), 0.00001);
|
assertEquals(-0.34999, rgb3.getTint(), 0.00001);
|
||||||
|
|
||||||
assertEquals("FFFFFFFF", rgb3.getARGBHex());
|
assertEquals("FFFFFFFF", rgb3.getARGBHex());
|
||||||
assertEquals(3, rgb3.getRgb().length);
|
assertEquals(3, rgb3.getRgb().length);
|
||||||
assertEquals(-1, rgb3.getRgb()[0]);
|
assertEquals(-1, rgb3.getRgb()[0]);
|
||||||
assertEquals(-1, rgb3.getRgb()[1]);
|
assertEquals(-1, rgb3.getRgb()[1]);
|
||||||
assertEquals(-1, rgb3.getRgb()[2]);
|
assertEquals(-1, rgb3.getRgb()[2]);
|
||||||
|
|
||||||
assertEquals(4, rgb3.getARgb().length);
|
assertEquals(4, rgb3.getARgb().length);
|
||||||
assertEquals(-1, rgb3.getARgb()[0]);
|
assertEquals(-1, rgb3.getARgb()[0]);
|
||||||
assertEquals(-1, rgb3.getARgb()[1]);
|
assertEquals(-1, rgb3.getARgb()[1]);
|
||||||
assertEquals(-1, rgb3.getARgb()[2]);
|
assertEquals(-1, rgb3.getARgb()[2]);
|
||||||
assertEquals(-1, rgb3.getARgb()[3]);
|
assertEquals(-1, rgb3.getARgb()[3]);
|
||||||
|
|
||||||
// Tint doesn't have the alpha
|
// Tint doesn't have the alpha
|
||||||
|
// tint = -0.34999
|
||||||
|
// 255 * (1 + tint) = 165 truncated
|
||||||
|
// or (byte) -91 (which is 165 - 256)
|
||||||
assertEquals(3, rgb3.getRgbWithTint().length);
|
assertEquals(3, rgb3.getRgbWithTint().length);
|
||||||
assertEquals(0, rgb3.getRgbWithTint()[0]);
|
assertEquals(-91, rgb3.getRgbWithTint()[0]);
|
||||||
assertEquals(0, rgb3.getRgbWithTint()[1]);
|
assertEquals(-91, rgb3.getRgbWithTint()[1]);
|
||||||
assertEquals(0, rgb3.getRgbWithTint()[2]);
|
assertEquals(-91, rgb3.getRgbWithTint()[2]);
|
||||||
|
|
||||||
// Set the colour to black, will get translated internally
|
// Set the color to black (no theme).
|
||||||
// (Excel stores 3 colour white and black wrong!)
|
rgb3.setRgb(new byte[] {0, 0, 0});
|
||||||
rgb3.setRgb(new byte[] {-1,-1,-1});
|
assertEquals("FF000000", rgb3.getARGBHex());
|
||||||
assertEquals("FFFFFFFF", rgb3.getARGBHex());
|
|
||||||
assertEquals(0, rgb3.getCTColor().getRgb()[0]);
|
assertEquals(0, rgb3.getCTColor().getRgb()[0]);
|
||||||
assertEquals(0, rgb3.getCTColor().getRgb()[1]);
|
assertEquals(0, rgb3.getCTColor().getRgb()[1]);
|
||||||
assertEquals(0, rgb3.getCTColor().getRgb()[2]);
|
assertEquals(0, rgb3.getCTColor().getRgb()[2]);
|
||||||
|
|
||||||
// Set another, is fine
|
// Set another, is fine
|
||||||
rgb3.setRgb(new byte[] {16,17,18});
|
rgb3.setRgb(new byte[] {16,17,18});
|
||||||
assertEquals("FF101112", rgb3.getARGBHex());
|
assertEquals("FF101112", rgb3.getARGBHex());
|
||||||
@ -113,45 +115,45 @@ public final class TestXSSFColor extends TestCase {
|
|||||||
assertEquals(0x11, rgb3.getCTColor().getRgb()[1]);
|
assertEquals(0x11, rgb3.getCTColor().getRgb()[1]);
|
||||||
assertEquals(0x12, rgb3.getCTColor().getRgb()[2]);
|
assertEquals(0x12, rgb3.getCTColor().getRgb()[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testARGBColour() throws Exception {
|
public void testARGBColour() throws Exception {
|
||||||
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("48779.xlsx");
|
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("48779.xlsx");
|
||||||
|
|
||||||
// Check the CTColor is as expected
|
// Check the CTColor is as expected
|
||||||
XSSFColor rgb4 = wb.getCellStyleAt((short)1).getFillForegroundXSSFColor();
|
XSSFColor rgb4 = wb.getCellStyleAt((short)1).getFillForegroundXSSFColor();
|
||||||
assertEquals(false, rgb4.getCTColor().isSetIndexed());
|
assertEquals(false, rgb4.getCTColor().isSetIndexed());
|
||||||
assertEquals(0, rgb4.getCTColor().getIndexed());
|
assertEquals(0, rgb4.getCTColor().getIndexed());
|
||||||
assertEquals(true, rgb4.getCTColor().isSetRgb());
|
assertEquals(true, rgb4.getCTColor().isSetRgb());
|
||||||
assertEquals(4, rgb4.getCTColor().getRgb().length);
|
assertEquals(4, rgb4.getCTColor().getRgb().length);
|
||||||
|
|
||||||
// Now check the XSSFColor
|
// Now check the XSSFColor
|
||||||
assertEquals(0, rgb4.getIndexed());
|
assertEquals(0, rgb4.getIndexed());
|
||||||
assertEquals(0.0, rgb4.getTint());
|
assertEquals(0.0, rgb4.getTint());
|
||||||
|
|
||||||
assertEquals("FFFF0000", rgb4.getARGBHex());
|
assertEquals("FFFF0000", rgb4.getARGBHex());
|
||||||
assertEquals(3, rgb4.getRgb().length);
|
assertEquals(3, rgb4.getRgb().length);
|
||||||
assertEquals(-1, rgb4.getRgb()[0]);
|
assertEquals(-1, rgb4.getRgb()[0]);
|
||||||
assertEquals(0, rgb4.getRgb()[1]);
|
assertEquals(0, rgb4.getRgb()[1]);
|
||||||
assertEquals(0, rgb4.getRgb()[2]);
|
assertEquals(0, rgb4.getRgb()[2]);
|
||||||
|
|
||||||
assertEquals(4, rgb4.getARgb().length);
|
assertEquals(4, rgb4.getARgb().length);
|
||||||
assertEquals(-1, rgb4.getARgb()[0]);
|
assertEquals(-1, rgb4.getARgb()[0]);
|
||||||
assertEquals(-1, rgb4.getARgb()[1]);
|
assertEquals(-1, rgb4.getARgb()[1]);
|
||||||
assertEquals(0, rgb4.getARgb()[2]);
|
assertEquals(0, rgb4.getARgb()[2]);
|
||||||
assertEquals(0, rgb4.getARgb()[3]);
|
assertEquals(0, rgb4.getARgb()[3]);
|
||||||
|
|
||||||
// Tint doesn't have the alpha
|
// Tint doesn't have the alpha
|
||||||
assertEquals(3, rgb4.getRgbWithTint().length);
|
assertEquals(3, rgb4.getRgbWithTint().length);
|
||||||
assertEquals(-1, rgb4.getRgbWithTint()[0]);
|
assertEquals(-1, rgb4.getRgbWithTint()[0]);
|
||||||
assertEquals(0, rgb4.getRgbWithTint()[1]);
|
assertEquals(0, rgb4.getRgbWithTint()[1]);
|
||||||
assertEquals(0, rgb4.getRgbWithTint()[2]);
|
assertEquals(0, rgb4.getRgbWithTint()[2]);
|
||||||
|
|
||||||
|
|
||||||
// Turn on tinting, and check it behaves
|
// Turn on tinting, and check it behaves
|
||||||
// TODO These values are suspected to be wrong...
|
// TODO These values are suspected to be wrong...
|
||||||
rgb4.setTint(0.4);
|
rgb4.setTint(0.4);
|
||||||
assertEquals(0.4, rgb4.getTint());
|
assertEquals(0.4, rgb4.getTint());
|
||||||
|
|
||||||
assertEquals(3, rgb4.getRgbWithTint().length);
|
assertEquals(3, rgb4.getRgbWithTint().length);
|
||||||
assertEquals(-1, rgb4.getRgbWithTint()[0]);
|
assertEquals(-1, rgb4.getRgbWithTint()[0]);
|
||||||
assertEquals(102, rgb4.getRgbWithTint()[1]);
|
assertEquals(102, rgb4.getRgbWithTint()[1]);
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user