activate javadoc lint and fix errors

add signing and checksum generation
add slf4j-bridge for tests
add dependencies to ooxml-lite
fix complex enum classes
add override annotations
move gradle logic to root build
generate javadoc in its own dist directory, because JPMS complains about duplicate modules otherwise

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1890089 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andreas Beeker 2021-05-21 21:22:40 +00:00
parent cecab7f573
commit 7eaca60a1a
175 changed files with 1712 additions and 2025 deletions

View File

@ -14,6 +14,7 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
buildscript {
repositories {
maven { url "https://plugins.gradle.org/m2/" }
@ -85,15 +86,15 @@ allprojects {
}
/**
Define things that are only necessary in sub-projects, but not in the master-project itself
*/
subprojects {
//Put instructions for each sub project, but not the master
apply plugin: 'java-library'
apply plugin: 'jacoco'
apply plugin: 'maven-publish'
apply plugin: 'signing'
version = '5.0.1-SNAPSHOT'
ext {
@ -122,12 +123,8 @@ subprojects {
options.deprecation = true
}
tasks.withType(Jar) {
duplicatesStrategy = 'fail'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
repositories {
mavenCentral()
@ -145,7 +142,41 @@ subprojects {
task wrapper(type: Wrapper){
// https://stackoverflow.com/a/65701523/2066598
gradleVersion = '6.8'
gradleVersion = '7.0.1'
}
java {
withJavadocJar()
withSourcesJar()
}
javadoc {
failOnError = true
maxMemory = "1024M"
doFirst {
options {
if (JavaVersion.current().isJava9Compatible()) {
addBooleanOption('html5', true)
}
addBooleanOption('Xdoclint:all,-missing', true)
links 'https://poi.apache.org/apidocs/dev/'
links 'https://docs.oracle.com/javase/8/docs/api/'
links 'https://xmlbeans.apache.org/docs/5.0.0/'
use = true
splitIndex = true
source = "1.8"
}
}
}
tasks.withType(Jar) {
duplicatesStrategy = 'fail'
destinationDirectory = file("../build/dist/maven/${project.archivesBaseName}")
doLast {
ant.checksum(file: it.archivePath, algorithm: 'SHA-256', fileext: '.sha256', format: 'MD5SUM')
ant.checksum(file: it.archivePath, algorithm: 'SHA-512', fileext: '.sha512', format: 'MD5SUM')
}
}
jar {
@ -154,6 +185,17 @@ subprojects {
}
}
javadocJar {
// if javadocs and binaries are in the same directory, JPMS complaints about duplicated modules
// in the module-path
destinationDirectory = file("../build/dist/maven/${project.archivesBaseName}-javadoc")
}
sourcesJar {
destinationDirectory = file("../build/dist/maven/${project.archivesBaseName}")
exclude 'META-INF/services/**'
}
test {
// make XML test-results available for Jenkins CI
useJUnitPlatform()
@ -176,7 +218,21 @@ subprojects {
maxHeapSize = "768m"
// Specifying the local via system properties did not work, so we set them this way
jvmArgs '-Duser.language=en -Duser.country=US'
jvmArgs << [
'-Djava.io.tmpdir=build',
'-DPOI.testdata.path=../test-data',
'-Djava.awt.headless=true',
'-Djava.locale.providers=JRE,CLDR',
'-Duser.language=en',
'-Duser.country=US',
'-Djavax.xml.stream.XMLInputFactory=com.sun.xml.internal.stream.XMLInputFactoryImpl',
"-Dversion.id=${project.version}",
'-ea',
'-Djunit.jupiter.execution.parallel.enabled=true',
'-Djunit.jupiter.execution.parallel.config.strategy=fixed',
'-Djunit.jupiter.execution.parallel.config.fixed.parallelism=3'
// -Xjit:verbose={compileStart|compileEnd},vlog=build/jit.log${no.jit.sherlock} ... if ${isIBMVM}
]
// show standard out and standard error of the test JVM(s) on the console
//testLogging.showStandardStreams = true
@ -190,6 +246,23 @@ subprojects {
systemProperties['java.locale.providers'] = 'JRE,CLDR'
systemProperties['junit.jupiter.execution.parallel.enabled'] = 'false'
doFirst {
if (JavaVersion.current() != JavaVersion.VERSION_1_8) {
jvmArgs += [
'-Dsun.reflect.debugModuleAccessChecks=true',
'-Dcom.sun.xml.bind.v2.bytecode.ClassTailor.noOptimize=true',
'--illegal-access=warn',
// see https://github.com/java9-modularity/gradle-modules-plugin/issues/97
// opposed to the recommendation there, it doesn't work to add ... to the dependencies
// testRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.7.1'
// gradles gradle-worker.jar is still not a JPMS module and thus runs as unnamed module
'--add-exports','org.junit.platform.commons/org.junit.platform.commons.util=ALL-UNNAMED',
'--add-exports','org.junit.platform.commons/org.junit.platform.commons.logging=ALL-UNNAMED',
]
}
}
}
jacoco {
@ -242,10 +315,15 @@ subprojects {
publications {
POI(MavenPublication) {
groupId 'org.apache.poi'
artifactId project.archivesBaseName
from components.java
pom {
packaging = 'jar'
url = 'https://poi.apache.org/'
name = 'Apache POI'
description = 'Apache POI - Java API To Access Microsoft Format Files'
mailingLists {
mailingList {
@ -278,7 +356,9 @@ subprojects {
withXml {
def r = asElement()
def doc = r.getOwnerDocument()
def asl = doc.createComment(new File('../legal/HEADER').text)
def hdr = new File('../legal/HEADER')
if (!hdr.exists()) hdr = new File('legal/HEADER')
def asl = doc.createComment(hdr.text)
// adding ASF header before root node is ignored
// doc.insertBefore(asl, doc.getDocumentElement())
r.insertBefore(asl, r.getFirstChild())
@ -287,17 +367,11 @@ subprojects {
}
}
}
}
// Make JavaDoc behave similar to Ant, i.e. be a bit more lenient
// and define amount of memory
// https://blog.joda.org/2014/02/turning-off-doclint-in-jdk-8-javadoc.html
if (JavaVersion.current().isJava8Compatible()) {
allprojects {
tasks.withType(Javadoc) {
options.addStringOption('Xdoclint:none', '-quiet')
maxMemory="384M"
}
generatePomFileForPOIPublication.destination = "../build/dist/maven/${project.archivesBaseName}/${project.archivesBaseName}-${project.version}.pom"
signing {
sign publishing.publications.POI
}
}
@ -313,6 +387,7 @@ task allJavaDoc(type: Javadoc) {
// for possible options see https://docs.gradle.org/current/javadoc/org/gradle/external/javadoc/StandardJavadocDocletOptions.html
options.use = true
options.splitIndex = true
options.addBooleanOption('Xdoclint:all,-missing', true)
title = 'POI API Documentation'
options.bottom = '<![CDATA[<i>Copyright ' + new Date().format('yyyy') + ' The Apache Software Foundation or\n' +

View File

@ -43,12 +43,6 @@ final String MODULE_NAME = 'org.apache.poi.examples'
final Pattern MODULE_REGEX = ~'\\.jar$'
final List MAIN_MODULE_PATH = sourceSets.main.runtimeClasspath.findAll{ it.path =~ MODULE_REGEX }.collect{ it.parent }.unique()
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
withSourcesJar()
}
task compileJava9(type: JavaCompile) {
dependsOn 'compileJava', ':poi-ooxml:jar', ':poi-scratchpad:jar'
@ -83,7 +77,3 @@ jar {
attributes('Automatic-Module-Name': MODULE_NAME, 'Multi-Release': 'true')
}
}
sourcesJar {
destinationDirectory = file("../build/dist/maven/${project.archivesBaseName}")
}

View File

@ -42,23 +42,23 @@ import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.util.TempFile;
/**
* <p>This class copies a POI file system to a new file and compares the copy
* with the original.</p>
* This class copies a POI file system to a new file and compares the copy
* with the original.
* <p>
* <p>Property set streams are copied logically, i.e. the application
* Property set streams are copied logically, i.e. the application
* establishes a {@link org.apache.poi.hpsf.PropertySet} of an original property
* set, creates a {@link org.apache.poi.hpsf.PropertySet} and writes the
* {@link org.apache.poi.hpsf.PropertySet} to the destination POI file
* system. - Streams which are no property set streams are copied bit by
* bit.</p>
* bit.
* <p>
* <p>The comparison of the POI file systems is done logically. That means that
* The comparison of the POI file systems is done logically. That means that
* the two disk files containing the POI file systems do not need to be
* exactly identical. However, both POI file systems must contain the same
* files, and most of these files must be bitwise identical. Property set
* streams, however, are compared logically: they must have the same sections
* with the same attributes, and the sections must contain the same properties.
* Details like the ordering of the properties do not matter.</p>
* Details like the ordering of the properties do not matter.
*/
@SuppressWarnings({"java:S106","java:S4823"})
public final class CopyCompare {

View File

@ -30,10 +30,10 @@ import org.apache.poi.xssf.eventusermodel.XSSFReader.SheetIterator;
/**
* An example that loads a password protected workbook and counts the sheets.
* The example highlights how to do this in streaming way.
* <p><ul>
* <ul>
* <li>The example demonstrates that all temp files are removed.
* <li><code>AesZipFileZipEntrySource</code> is used to ensure that temp files are encrypted.
* </ul><p>
* <li>{@code AesZipFileZipEntrySource} is used to ensure that temp files are encrypted.
* </ul>
*/
@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public final class LoadPasswordProtectedXlsxStreaming {

View File

@ -41,10 +41,10 @@ import org.apache.poi.xssf.streaming.SXSSFSheet;
/**
* An example that outputs a simple generated workbook that is password protected.
* The example highlights how to do this in streaming way.
* <p><ul>
* <ul>
* <li>The example demonstrates that all temp files are removed.
* <li><code>SXSSFWorkbookWithCustomZipEntrySource</code> extends SXSSFWorkbook to ensure temp files are encrypted.
* </ul><p>
* <li>{@code SXSSFWorkbookWithCustomZipEntrySource} extends SXSSFWorkbook to ensure temp files are encrypted.
* </ul>
*/
@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public final class SavePasswordProtectedXlsx {

View File

@ -32,10 +32,10 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
/**
* An example that loads a password protected workbook and counts the sheets.
* <p><ul>
* <ul>
* <li>The example demonstrates that all temp files are removed.
* <li><code>AesZipFileZipEntrySource</code> is used to ensure that temp files are encrypted.
* </ul></p>
* <li>{@code AesZipFileZipEntrySource} is used to ensure that temp files are encrypted.
* </ul>
*/
@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public final class LoadPasswordProtectedXlsx {

View File

@ -47,6 +47,7 @@ dependencies {
testImplementation project(path: ':poi-ooxml', configuration: 'tests')
testImplementation project(path: ':poi-scratchpad', configuration: 'tests')
testImplementation 'com.google.guava:guava:30.0-jre'
testImplementation 'org.apache.logging.log4j:log4j-slf4j-impl:2.14.1'
}
final String MODULE_NAME = 'org.apache.poi.excelant'
@ -60,13 +61,6 @@ final String OOXML_LITE_REPORT = '../build/ooxml-lite-report'
final String OOXML_LITE_JAR = "../build/dist/maven/poi-ooxml-lite/poi-ooxml-lite-${project.version}.jar"
final String OOXML_LITE_INCLUDES = "^(com/microsoft/schemas|org/(etsi|openxmlformats|w3/)|org/apache/poi/schemas)"
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
withJavadocJar()
withSourcesJar()
}
task compileJava9(type: JavaCompile) {
dependsOn 'compileJava', ':poi-ooxml:jar', ':poi-scratchpad:jar'
@ -146,18 +140,6 @@ task testJar(type: Jar, dependsOn: testClasses) {
}
}
sourcesJar {
destinationDirectory = file("../build/dist/maven/${project.archivesBaseName}")
}
javadoc {
// fails currently, need to fix the sources
failOnError = false
// if(JavaVersion.current().isJava9Compatible()) {
// options.addBooleanOption('html5', true)
// }
}
artifacts {
tests testJar
}
@ -165,40 +147,13 @@ artifacts {
test {
dependsOn { testJar }
useJUnitPlatform()
doFirst {
jvmArgs = [
'-Djava.io.tmpdir=build',
'-DPOI.testdata.path=../test-data',
'-Djava.awt.headless=true',
'-Djava.locale.providers=JRE,CLDR',
'-Duser.language=en',
'-Duser.country=US',
'-Djavax.xml.stream.XMLInputFactory=com.sun.xml.internal.stream.XMLInputFactoryImpl',
"-Dversion.id=${project.version}",
'-ea',
jvmArgs += [
"-javaagent:${OOXML_LITE_AGENT}=${OOXML_LITE_REPORT}|${OOXML_LITE_INCLUDES}",
'-Djunit.jupiter.execution.parallel.enabled=true',
'-Djunit.jupiter.execution.parallel.config.strategy=fixed',
'-Djunit.jupiter.execution.parallel.config.fixed.parallelism=3'
// -Xjit:verbose={compileStart|compileEnd},vlog=build/jit.log${no.jit.sherlock} ... if ${isIBMVM}
]
if (JavaVersion.current() != JavaVersion.VERSION_1_8) {
jvmArgs += [
'-Dsun.reflect.debugModuleAccessChecks=true',
'-Dcom.sun.xml.bind.v2.bytecode.ClassTailor.noOptimize=true',
'--illegal-access=warn',
'--add-modules', MODULE_NAME,
// see https://github.com/java9-modularity/gradle-modules-plugin/issues/97
// opposed to the recommendation there, it doesn't work to add ... to the dependencies
// testRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.7.1'
// gradles gradle-worker.jar is still not a JPMS module and thus runs as unnamed module
'--add-exports','org.junit.platform.commons/org.junit.platform.commons.util=ALL-UNNAMED',
'--add-exports','org.junit.platform.commons/org.junit.platform.commons.logging=ALL-UNNAMED',
'--module-path', '../build/dist/maven/poi-excelant-tests:' + files(TEST_MODULE_PATH).asPath,
]
}
@ -208,16 +163,10 @@ test {
publishing {
publications {
POI(MavenPublication) {
artifactId project.archivesBaseName
from components.java
pom {
name = 'Apache POI - API based on OPC and OOXML schemas'
name = 'Apache POI - ExcelAnt'
description = 'Apache POI - Java API To Access Microsoft Format Files'
}
}
}
}
generatePomFileForPOIPublication.destination = "../build/dist/maven/${project.archivesBaseName}/${project.archivesBaseName}-${project.version}.pom"

View File

@ -23,7 +23,7 @@ import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
/**
* This is the class that backs the <handler> tag in the Ant task.
* This is the class that backs the {@code <handler>} tag in the Ant task.
* <p>
* Its purpose is to provide a way to manipulate a workbook in the course
* of an ExcelAnt task. The idea being to model a way for test writers to
@ -36,7 +36,7 @@ import org.apache.tools.ant.Task;
* class you write to manipulate the workbook.
* <p>
* In order to use this tag you must write a class that implements the
* <code>IExcelAntWorkbookHandler</code> interface. After writing the
* {@code IExcelAntWorkbookHandler} interface. After writing the
* class you should package it and it's dependencies into a jar file to
* add as library in your Ant build file.
*/

View File

@ -187,8 +187,6 @@ public class ExcelAntWorkbookUtil extends Typedef {
/**
* Returns the Workbook instance associated with this WorkbookUtil.
*
* @return
*/
public Workbook getWorkbook() {
return workbook;
@ -197,8 +195,6 @@ public class ExcelAntWorkbookUtil extends Typedef {
/**
* Returns the fileName that was used to initialize this instance. May
* return null if the instance was constructed from a Workbook object.
*
* @return
*/
public String getFileName() {
return excelFileName;
@ -206,8 +202,6 @@ public class ExcelAntWorkbookUtil extends Typedef {
/**
* Returns the list of sheet names.
*
* @return
*/
public List<String> getSheets() {
ArrayList<String> sheets = new ArrayList<>();
@ -224,9 +218,6 @@ public class ExcelAntWorkbookUtil extends Typedef {
/**
* This method uses a String in standard Excel format (SheetName!CellId) to
* locate the cell and set it to the value of the double in value.
*
* @param cellName
* @param value
*/
public void setDoubleValue(String cellName, double value) {
log("starting setCellValue()", Project.MSG_DEBUG);
@ -240,9 +231,6 @@ public class ExcelAntWorkbookUtil extends Typedef {
/**
* Utility method for setting the value of a Cell with a String.
*
* @param cellName
* @param value
*/
public void setStringValue(String cellName, String value) {
Cell cell = getCell(cellName);
@ -251,9 +239,6 @@ public class ExcelAntWorkbookUtil extends Typedef {
/**
* Utility method for setting the value of a Cell with a Formula.
*
* @param cellName
* @param formula
*/
public void setFormulaValue(String cellName, String formula) {
Cell cell = getCell(cellName);
@ -262,8 +247,6 @@ public class ExcelAntWorkbookUtil extends Typedef {
/**
* Utility method for setting the value of a Cell with a Date.
* @param cellName
* @param date
*/
public void setDateValue(String cellName, Date date) {
Cell cell = getCell(cellName);
@ -272,15 +255,11 @@ public class ExcelAntWorkbookUtil extends Typedef {
/**
* Uses a String in standard Excel format (SheetName!CellId) to locate a
* cell and evaluate it.
*
* @param cellName
* @param expectedValue
* @param precision
*/
public ExcelAntEvaluationResult evaluateCell(String cellName, double expectedValue,
double precision) {
ExcelAntEvaluationResult evalResults = null;
ExcelAntEvaluationResult evalResults;
Cell cell = getCell(cellName);
@ -304,12 +283,11 @@ public class ExcelAntWorkbookUtil extends Typedef {
"Evaluation passed without error within in range.", delta, cellName);
}
} else {
String errorMeaning = null;
String errorMeaning;
try {
errorMeaning = FormulaError.forInt(resultOfEval.getErrorValue()).getString();
} catch(IllegalArgumentException iae) {
errorMeaning = "unknown error code: " +
Byte.toString(resultOfEval.getErrorValue());
errorMeaning = "unknown error code: " + resultOfEval.getErrorValue();
}
evalResults = new ExcelAntEvaluationResult(true, false,
@ -325,9 +303,6 @@ public class ExcelAntWorkbookUtil extends Typedef {
/**
* Returns a Cell as a String value.
*
* @param cellName
* @return
*/
public String getCellAsString(String cellName) {
Cell cell = getCell(cellName);
@ -337,9 +312,6 @@ public class ExcelAntWorkbookUtil extends Typedef {
/**
* Returns the value of the Cell as a double.
*
* @param cellName
* @return
*/
public double getCellAsDouble(String cellName) {
Cell cell = getCell(cellName);
@ -349,9 +321,6 @@ public class ExcelAntWorkbookUtil extends Typedef {
* Returns a cell reference based on a String in standard Excel format
* (SheetName!CellId). This method will create a new cell if the
* requested cell isn't initialized yet.
*
* @param cellName
* @return
*/
private Cell getCell(String cellName) {
CellReference cellRef = new CellReference(cellName);

View File

@ -46,6 +46,7 @@ dependencies {
testImplementation project(path:':poi-ooxml', configuration:'tests')
testImplementation project(path:':poi-scratchpad', configuration:'tests')
testImplementation project(path: ':poi-ooxml-lite-agent', configuration: 'archives')
testImplementation 'org.apache.logging.log4j:log4j-slf4j-impl:2.14.1'
}
final String MODULE_NAME = 'org.apache.poi.stress'
@ -125,45 +126,15 @@ test {
dependsOn { testJar }
useJUnitPlatform()
doFirst {
jvmArgs = [
'-Djava.io.tmpdir=build',
'-DPOI.testdata.path=../test-data',
'-Djava.awt.headless=true',
'-Djava.locale.providers=JRE,CLDR',
'-Duser.language=en',
'-Duser.country=US',
'-Djavax.xml.stream.XMLInputFactory=com.sun.xml.internal.stream.XMLInputFactoryImpl',
"-Dversion.id=${project.version}",
'-ea',
jvmArgs += [
"-javaagent:${OOXML_LITE_AGENT}=${OOXML_LITE_REPORT}|${OOXML_LITE_INCLUDES}",
'-Djunit.jupiter.execution.parallel.enabled=true',
'-Djunit.jupiter.execution.parallel.config.strategy=fixed',
'-Djunit.jupiter.execution.parallel.config.fixed.parallelism=3'
// -Xjit:verbose={compileStart|compileEnd},vlog=build/jit.log${no.jit.sherlock} ... if ${isIBMVM}
]
if (JavaVersion.current() != JavaVersion.VERSION_1_8) {
jvmArgs += [
'-Dsun.reflect.debugModuleAccessChecks=true',
'-Dcom.sun.xml.bind.v2.bytecode.ClassTailor.noOptimize=true',
'--illegal-access=warn',
'--add-modules', MODULE_NAME,
// see https://github.com/java9-modularity/gradle-modules-plugin/issues/97
// opposed to the recommendation there, it doesn't work to add ... to the dependencies
// testRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.7.1'
// gradles gradle-worker.jar is still not a JPMS module and thus runs as unnamed module
'--add-exports','org.junit.platform.commons/org.junit.platform.commons.util=ALL-UNNAMED',
'--add-exports','org.junit.platform.commons/org.junit.platform.commons.logging=ALL-UNNAMED',
'--module-path', '../build/dist/maven/poi-integration-tests:' + files(TEST_MODULE_PATH).asPath,
]
}
}
}
generatePomFileForPOIPublication.destination = "../build/dist/maven/${project.archivesBaseName}/${project.archivesBaseName}-${project.version}.pom"

View File

@ -54,8 +54,6 @@ final List MAIN_MODULE_PATH = sourceSets.main.runtimeClasspath.findAll{ it.path
compileJava {
dependsOn 'generate_beans'
sourceCompatibility = 8
targetCompatibility = 8
}
task compileJava9(type: JavaCompile) {
@ -133,26 +131,6 @@ task generate_beans(dependsOn: copy_xsds) {
}
}
tasks.withType(Jar) {
destinationDirectory = file("../build/dist/maven/${project.archivesBaseName}")
}
javadoc {
failOnError = true
maxMemory = "1024M"
doFirst {
options {
if (JavaVersion.current().isJava9Compatible()) {
addBooleanOption('html5', true)
}
links 'https://xmlbeans.apache.org/docs/5.0.0/'
use = true
splitIndex = true
source = "1.8"
}
}
}
task sourceJar(type: Jar) {
classifier 'sources'
from sourceSets.main.allJava
@ -175,11 +153,6 @@ jar {
publishing {
publications {
POI(MavenPublication) {
artifactId "${project.archivesBaseName}"
from components.java
artifact tasks.sourceJar
pom {
name = 'Apache POI - OOXML schemas (full)'
description =
@ -189,5 +162,3 @@ publishing {
}
}
}
generatePomFileForPOIPublication.destination = "../build/dist/maven/${project.archivesBaseName}/${project.archivesBaseName}-${project.version}.pom"

View File

@ -1,6 +1,4 @@
import java.util.function.Function
import java.util.regex.Pattern
import java.util.stream.Collectors
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
@ -89,7 +87,9 @@ java {
targetCompatibility = JavaVersion.VERSION_1_8
}
processResources.dependsOn 'compileOoxmlLite'
compileJava.dependsOn 'compileOoxmlLite'
sourcesJar.dependsOn 'compileOoxmlLite'
task compileJava9(type: JavaCompile, dependsOn: 'compileJava') {
sourceCompatibility = 9

View File

@ -73,6 +73,11 @@ dependencies {
testImplementation 'org.openjdk.jmh:jmh-generator-annprocess:1.26'
testImplementation 'com.google.guava:guava:30.0-jre'
// prevent slf4j warnings coming from xmlsec -> slf4j-api 1.7.30 dependency
// see https://logging.apache.org/log4j/2.x/log4j-slf4j-impl/
testImplementation 'org.apache.logging.log4j:log4j-slf4j-impl:2.14.1'
broken "org.apache.xmlgraphics:batik-script:${batikVersion}"
javadocs project(':poi')
@ -89,14 +94,6 @@ final String OOXML_LITE_AGENT = "../build/dist/maven/poi-ooxml-lite-agent/poi-oo
final String OOXML_LITE_REPORT = '../build/ooxml-lite-report'
final String OOXML_LITE_INCLUDES = "^(com/microsoft/schemas|org/(etsi|openxmlformats|w3/)|org/apache/poi/schemas)"
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
withJavadocJar()
withSourcesJar()
}
compileJava {
dependsOn 'fixBatik'
}
@ -180,11 +177,6 @@ task testJar(type: Jar, dependsOn: testClasses) {
}
}
sourcesJar {
destinationDirectory = file("../build/dist/maven/${project.archivesBaseName}")
exclude 'META-INF/services/**'
}
// based on https://github.com/moditect/moditect-gradle-plugin/issues/12
task fixBatik(type: Zip) {
ant.mkdir(dir: "${buildDir}/brokenJars")
@ -223,41 +215,13 @@ test {
dependsOn { testJar }
useJUnitPlatform()
doFirst {
jvmArgs = [
'-Djava.io.tmpdir=build',
'-DPOI.testdata.path=../test-data',
'-Djava.awt.headless=true',
'-Djava.locale.providers=JRE,CLDR',
'-Duser.language=en',
'-Duser.country=US',
'-Djavax.xml.stream.XMLInputFactory=com.sun.xml.internal.stream.XMLInputFactoryImpl',
"-Dversion.id=${project.version}",
'-ea',
jvmArgs += [
"-javaagent:${OOXML_LITE_AGENT}=${OOXML_LITE_REPORT}|${OOXML_LITE_INCLUDES}",
'-Djunit.jupiter.execution.parallel.enabled=true',
'-Djunit.jupiter.execution.parallel.config.strategy=fixed',
'-Djunit.jupiter.execution.parallel.config.fixed.parallelism=3'
// -Xjit:verbose={compileStart|compileEnd},vlog=build/jit.log${no.jit.sherlock} ... if ${isIBMVM}
]
if (JavaVersion.current() != JavaVersion.VERSION_1_8) {
jvmArgs += [
'-Dsun.reflect.debugModuleAccessChecks=true',
'-Dcom.sun.xml.bind.v2.bytecode.ClassTailor.noOptimize=true',
'--illegal-access=warn',
'--add-modules', MODULE_NAME,
// see https://github.com/java9-modularity/gradle-modules-plugin/issues/97
// opposed to the recommendation there, it doesn't work to add ... to the dependencies
// testRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.7.1'
// gradles gradle-worker.jar is still not a JPMS module and thus runs as unnamed module
'--add-exports','org.junit.platform.commons/org.junit.platform.commons.util=ALL-UNNAMED',
'--add-exports','org.junit.platform.commons/org.junit.platform.commons.logging=ALL-UNNAMED',
'--module-path', '../build/dist/maven/poi-ooxml-tests:' + files(TEST_MODULE_PATH).asPath,
]
}
@ -267,10 +231,6 @@ test {
publishing {
publications {
POI(MavenPublication) {
artifactId project.archivesBaseName
from components.java
pom {
name = 'Apache POI - API based on OPC and OOXML schemas'
description = 'Apache POI - Java API To Access Microsoft Format Files'
@ -278,5 +238,3 @@ publishing {
}
}
}
generatePomFileForPOIPublication.destination = "../build/dist/maven/${project.archivesBaseName}/${project.archivesBaseName}-${project.version}.pom"

View File

@ -196,6 +196,7 @@ public class POIXMLDocumentPart {
* @throws IllegalStateException if there are more than one core document relations
*/
protected final void rebase(OPCPackage pkg) throws InvalidFormatException {
// TODO: check why pkg parameter is not used ???
PackageRelationshipCollection cores =
packagePart.getRelationshipsByType(coreDocumentRel);
if (cores.size() != 1) {
@ -240,10 +241,10 @@ public class POIXMLDocumentPart {
}
/**
* Returns the target {@link POIXMLDocumentPart}, where a
* Returns the target POIXMLDocumentPart, where a
* {@link PackageRelationship} is set from the {@link PackagePart} of this
* {@link POIXMLDocumentPart} to the {@link PackagePart} of the target
* {@link POIXMLDocumentPart} with a {@link PackageRelationship#getId()}
* POIXMLDocumentPart to the {@link PackagePart} of the target
* POIXMLDocumentPart with a {@link PackageRelationship#getId()}
* matching the given parameter value.
*
* @param id The relation id to look for
@ -257,8 +258,8 @@ public class POIXMLDocumentPart {
/**
* Returns the target {@link RelationPart}, where a
* {@link PackageRelationship} is set from the {@link PackagePart} of this
* {@link POIXMLDocumentPart} to the {@link PackagePart} of the target
* {@link POIXMLDocumentPart} with a {@link PackageRelationship#getId()}
* POIXMLDocumentPart to the {@link PackagePart} of the target
* POIXMLDocumentPart with a {@link PackageRelationship#getId()}
* matching the given parameter value.
*
* @param id The relation id to look for
@ -272,13 +273,13 @@ public class POIXMLDocumentPart {
/**
* Returns the first {@link PackageRelationship#getId()} of the
* {@link PackageRelationship}, that sources from the {@link PackagePart} of
* this {@link POIXMLDocumentPart} to the {@link PackagePart} of the given
* parameter value.<p>
* this POIXMLDocumentPart to the {@link PackagePart} of the given
* parameter value.
* <p>
* There can be multiple references to the given {@link POIXMLDocumentPart}
* There can be multiple references to the given POIXMLDocumentPart
* and only the first in the order of creation is returned.
*
* @param part The {@link POIXMLDocumentPart} for which the according
* @param part The POIXMLDocumentPart for which the according
* relation-id shall be found.
* @return The value of the {@link PackageRelationship#getId()} or null, if
* parts are not related.
@ -326,7 +327,7 @@ public class POIXMLDocumentPart {
/**
* Remove the relation to the specified part in this package and remove the
* part, if it is no longer needed.<p>
* part, if it is no longer needed.
* <p>
* If there are multiple relationships to the same part, this will only
* remove the first relationship in the order of creation. The removal
@ -340,7 +341,7 @@ public class POIXMLDocumentPart {
/**
* Remove the relation to the specified part in this package and remove the
* part, if it is no longer needed and flag is set to true.<p>
* part, if it is no longer needed and flag is set to true.
* <p>
* If there are multiple relationships to the same part, this will only
* remove the first relationship in the order of creation. The removal
@ -358,7 +359,7 @@ public class POIXMLDocumentPart {
/**
* Remove the relation to the specified part in this package and remove the
* part, if it is no longer needed.<p>
* part, if it is no longer needed.
* <p>
* If there are multiple relationships to the same part, this will only
* remove the first relationship in the order of creation. The removal
@ -413,7 +414,7 @@ public class POIXMLDocumentPart {
/**
* Returns the parent POIXMLDocumentPart. All parts except root have not-null parent.
*
* @return the parent POIXMLDocumentPart or <code>null</code> for the root element.
* @return the parent POIXMLDocumentPart or {@code null} for the root element.
*/
public final POIXMLDocumentPart getParent() {
return parent;
@ -719,8 +720,8 @@ public class POIXMLDocumentPart {
/**
* Internal method, do not use!
* <p>
* This method only exists to allow access to protected {@link POIXMLDocumentPart#onDocumentRead()}
*
* @deprecated This method only exists to allow access to protected {@link POIXMLDocumentPart#onDocumentRead()}
* from {@link XWPFDocument} without reflection. It should be removed.
*
* @param part the part which is to be read

View File

@ -60,7 +60,6 @@ public interface SignatureFacet {
* @param document the signature document to be used for imports
* @param references list of reference definitions
* @param objects objects to be signed/included in the signature document
* @throws XMLSignatureException
*/
default void preSign(
SignatureInfo signatureInfo
@ -78,7 +77,6 @@ public interface SignatureFacet {
*
* @param signatureInfo the signature info object holding the OPCPackage and other document related data
* @param document the signature document to be modified
* @throws MarshalException
*/
default void postSign(SignatureInfo signatureInfo, Document document) throws MarshalException {

View File

@ -48,8 +48,6 @@ public class RevocationData {
/**
* Adds a CRL to this revocation data set.
*
* @param encodedCrl
*/
public void addCRL(byte[] encodedCrl) {
this.crls.add(encodedCrl);
@ -57,8 +55,6 @@ public class RevocationData {
/**
* Adds a CRL to this revocation data set.
*
* @param crl
*/
public void addCRL(X509CRL crl) {
byte[] encodedCrl;
@ -73,8 +69,6 @@ public class RevocationData {
/**
* Adds an OCSP response to this revocation data set.
*
* @param encodedOcsp
*/
public void addOCSP(byte[] encodedOcsp) {
this.ocsps.add(encodedOcsp);
@ -99,10 +93,10 @@ public class RevocationData {
}
/**
* Returns <code>true</code> if this revocation data set holds OCSP
* Returns {@code true} if this revocation data set holds OCSP
* responses.
*
* @return <code>true</code> if this revocation data set holds OCSP
* @return {@code true} if this revocation data set holds OCSP
* responses.
*/
public boolean hasOCSPs() {
@ -110,18 +104,18 @@ public class RevocationData {
}
/**
* Returns <code>true</code> if this revocation data set holds CRLs.
* Returns {@code true} if this revocation data set holds CRLs.
*
* @return <code>true</code> if this revocation data set holds CRLs.
* @return {@code true} if this revocation data set holds CRLs.
*/
public boolean hasCRLs() {
return !this.crls.isEmpty();
}
/**
* Returns <code>true</code> if this revocation data is not empty.
* Returns {@code true} if this revocation data is not empty.
*
* @return <code>true</code> if this revocation data is not empty.
* @return {@code true} if this revocation data is not empty.
*/
public boolean hasRevocationDataEntries() {
return hasOCSPs() || hasCRLs();

View File

@ -35,7 +35,6 @@ public interface TimeStampServiceValidator {
/**
* Validates the given certificate chain.
*
* @param certificateChain
* @param revocationData
* the optional data container that should be filled with
* revocation data that was used to validate the given

View File

@ -141,7 +141,7 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai
* @param part
* the package part holding the chart data, the content type must
* be
* <code>application/vnd.openxmlformats-officedocument.drawingml.chart+xml</code>
* {@code application/vnd.openxmlformats-officedocument.drawingml.chart+xml}
* @since POI 3.14-Beta1
*/
protected XDDFChart(PackagePart part) throws IOException, XmlException {
@ -411,13 +411,11 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai
series.plot();
XDDFDataSource<?> categoryDS = series.getCategoryData();
XDDFNumericalDataSource<? extends Number> valuesDS = series.getValuesData();
if (categoryDS == null || valuesDS == null
|| categoryDS.isCellRange() || valuesDS.isCellRange()
|| categoryDS.isLiteral() || valuesDS.isLiteral()) {
// let's assume the data is already in the sheet
} else {
if (categoryDS != null && !categoryDS.isCellRange() && !categoryDS.isLiteral() &&
valuesDS != null && !valuesDS.isCellRange() && !valuesDS.isLiteral()) {
fillSheet(sheet, categoryDS, valuesDS);
}
// otherwise let's assume the data is already in the sheet
}
}
@ -774,7 +772,6 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai
* @param chartFactory
* factory object of POIXMLFactory (XWPFFactory/XSLFFactory)
* @return return the new package part
* @throws InvalidFormatException
* @since POI 4.0.0
*/
private PackagePart createWorksheetPart(POIXMLRelation chartWorkbookRelation, POIXMLFactory chartFactory)
@ -787,10 +784,7 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai
/**
* this method write the XSSFWorkbook object data into embedded excel file
*
* @param workbook
* XSSFworkbook object
* @throws IOException
* @throws InvalidFormatException
* @param workbook XSSFworkbook object
* @since POI 4.0.0
*/
public void saveWorkbook(XSSFWorkbook workbook) throws IOException, InvalidFormatException {
@ -953,8 +947,6 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai
}
/**
* @param range
* @return
* @since POI 4.0.0
*/
public String formatRange(CellRangeAddress range) {
@ -969,12 +961,11 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai
* @since POI 4.0.0
*/
private XSSFSheet getSheet() {
XSSFSheet sheet = null;
try {
sheet = getWorkbook().getSheetAt(0);
} catch (InvalidFormatException | IOException ife) {
return getWorkbook().getSheetAt(0);
} catch (InvalidFormatException | IOException ignored) {
return null;
}
return sheet;
}
/**
@ -983,7 +974,6 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai
* writing xssfworkbook object into output stream of embedded part
*
* @return returns the packagepart of embedded file
* @throws InvalidFormatException
* @since POI 4.0.0
*/
private PackagePart getWorksheetPart() throws InvalidFormatException {
@ -1006,8 +996,6 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai
/**
* @return returns the workbook object of embedded excel file
* @throws IOException
* @throws InvalidFormatException
* @since POI 4.0.0
*/
public XSSFWorkbook getWorkbook() throws IOException, InvalidFormatException {
@ -1087,8 +1075,8 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai
public void replaceReferences(XSSFSheet newSheet) {
for (XDDFChartData data : getChartSeries()) {
for (XDDFChartData.Series series : data.series) {
XDDFDataSource newCategory = series.categoryData;
XDDFNumericalDataSource newValues = series.valuesData;
XDDFDataSource<?> newCategory = series.categoryData;
XDDFNumericalDataSource<? extends Number> newValues = series.valuesData;
try {
if (series.categoryData != null && series.categoryData.isReference()) {
String ref = series.categoryData.getDataRangeReference();
@ -1097,7 +1085,7 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai
? XDDFDataSourcesFactory.fromNumericCellRange(newSheet, rangeAddress)
: XDDFDataSourcesFactory.fromStringCellRange(newSheet, rangeAddress);
if (newCategory.isNumeric()) {
((XDDFNumericalDataSource) newCategory).setFormatCode(series.categoryData.getFormatCode());
((XDDFNumericalDataSource<? extends Number>) newCategory).setFormatCode(series.categoryData.getFormatCode());
}
}
if (series.valuesData!= null && series.valuesData.isReference()) {

View File

@ -26,6 +26,7 @@ import java.util.Map;
import org.apache.poi.ss.util.CellReference;
import org.apache.poi.util.Beta;
import org.apache.poi.util.Internal;
import org.apache.poi.util.Removal;
import org.apache.poi.xddf.usermodel.XDDFFillProperties;
import org.apache.poi.xddf.usermodel.XDDFLineProperties;
import org.apache.poi.xddf.usermodel.XDDFShapeProperties;
@ -81,7 +82,7 @@ public abstract class XDDFChartData {
}
/**
* Calls to <code>getSeries().add(series)</code> or to <code>getSeries().remove(series)</code>
* Calls to {@code getSeries().add(series)} or to {@code getSeries().remove(series)}
* may corrupt the workbook.
*
* <p>
@ -94,9 +95,9 @@ public abstract class XDDFChartData {
* </ul>
*
* @deprecated since POI 4.1.1
* @return
*/
@Deprecated
@Removal(version = "5.3")
public List<Series> getSeries() {
return Collections.unmodifiableList(series);
}
@ -119,18 +120,15 @@ public abstract class XDDFChartData {
}
/**
* This method should be implemented in every class that extends <code>XDDFChartData</code>.
* This method should be implemented in every class that extends {@code XDDFChartData}.
* <p>
* A typical implementation would be
*
* <pre><code>
protected void removeCTSeries(int n) {
chart.removeSer(n);
}
* </code></pre>
*
* @param n
* <pre>{@code
* protected void removeCTSeries(int n) {
* chart.removeSer(n);
* }
* }</pre>
*/
@Internal
protected abstract void removeCTSeries(int n);
@ -195,7 +193,7 @@ public abstract class XDDFChartData {
}
if (cache.sizeOfPtArray() < 1) {
cache.addNewPtCount().setVal(1);
cache.addNewPt().setIdx(0);;
cache.addNewPt().setIdx(0);
}
cache.getPtArray(0).setV(title);
}
@ -255,7 +253,7 @@ public abstract class XDDFChartData {
}
/**
* If a data point definition with the given <code>index</code> exists, then remove it.
* If a data point definition with the given {@code index} exists, then remove it.
* Otherwise do nothing.
*
* @param index
@ -267,19 +265,19 @@ public abstract class XDDFChartData {
for (int i = 0; i < points.size(); i++) {
if (points.get(i).getIdx().getVal() == index) {
points.remove(i);
i = points.size();
break;
}
}
}
/**
* If a data point definition with the given <code>index</code> exists, then return it.
* If a data point definition with the given {@code index} exists, then return it.
* Otherwise create a new data point definition and return it.
*
* @param index
* data point index.
* @return
* the data point with the given <code>index</code>.
* the data point with the given {@code index}.
* @since POI 5.0.1
*/
public XDDFDataPoint getDataPoint(long index) {

View File

@ -48,7 +48,7 @@ import org.openxmlformats.schemas.drawingml.x2006.main.STTextUnderlineType;
@Beta
public class XDDFTextRun {
private XDDFTextParagraph _parent;
private final XDDFTextParagraph _parent;
private XDDFRunProperties _properties;
private CTTextLineBreak _tlb;
private CTTextField _tf;
@ -320,9 +320,6 @@ public class XDDFTextRun {
* <p>
* The size is specified using a percentage.
* Positive values indicate superscript, negative values indicate subscript.
* </p>
*
* @param offset
*/
public void setBaseline(Double offset) {
if (offset == null) {
@ -336,9 +333,6 @@ public class XDDFTextRun {
* Set whether the text in this run is formatted as superscript.
* <p>
* The size is specified using a percentage.
* </p>
*
* @param offset
*/
public void setSuperscript(Double offset) {
setBaseline(offset == null ? null : Math.abs(offset));
@ -348,9 +342,6 @@ public class XDDFTextRun {
* Set whether the text in this run is formatted as subscript.
* <p>
* The size is specified using a percentage.
* </p>
*
* @param offset
*/
public void setSubscript(Double offset) {
setBaseline(offset == null ? null : -Math.abs(offset));
@ -407,7 +398,7 @@ public class XDDFTextRun {
/**
* @param size
* font size in points. The value <code>null</code> unsets the
* font size in points. The value {@code null} unsets the
* size for this run.
* <dl>
* <dt>Minimum inclusive =</dt>
@ -432,7 +423,7 @@ public class XDDFTextRun {
/**
* Set the kerning of characters within a text run.
* <p>
* The value <code>null</code> unsets the kerning for this run.
* The value {@code null} unsets the kerning for this run.
* </p>
*
* @param kerning
@ -451,7 +442,7 @@ public class XDDFTextRun {
/**
*
* @return the kerning of characters within a text run,
* If this attribute is omitted then returns <code>null</code>.
* If this attribute is omitted then returns {@code null}.
*/
public Double getCharacterKerning() {
return findDefinedProperty(
@ -468,7 +459,7 @@ public class XDDFTextRun {
* negative values to condense.
* </p>
* <p>
* The value <code>null</code> unsets the spacing for this run.
* The value {@code null} unsets the spacing for this run.
* </p>
*
* @param spacing
@ -487,7 +478,7 @@ public class XDDFTextRun {
/**
*
* @return the spacing between characters within a text run,
* If this attribute is omitted then returns <code>null</code>.
* If this attribute is omitted then returns {@code null}.
*/
public Double getCharacterSpacing() {
return findDefinedProperty(

View File

@ -21,13 +21,10 @@ import java.util.Collections;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.SortedMap;
/**
* An iterator used to iterate over the base and master items
*
* @param <T>
*/
public class CombinedIterable<T> implements Iterable<T> {
@ -43,14 +40,8 @@ public class CombinedIterable<T> implements Iterable<T> {
@Override
public Iterator<T> iterator() {
final Iterator<Entry<Long, T>> vmasterI;
if (_masterItems != null) {
vmasterI = _masterItems.entrySet().iterator();
} else {
final Set<Entry<Long, T>> empty = Collections.emptySet();
vmasterI = empty.iterator();
}
final Iterator<Entry<Long, T>> vmasterI = (_masterItems == null)
? Collections.emptyIterator() : _masterItems.entrySet().iterator();
return new Iterator<T>() {
@ -60,8 +51,8 @@ public class CombinedIterable<T> implements Iterable<T> {
Entry<Long, T> currentMaster;
// grab the iterator for both
Iterator<Entry<Long, T>> baseI = _baseItems.entrySet().iterator();
Iterator<Entry<Long, T>> masterI = vmasterI;
final Iterator<Entry<Long, T>> baseI = _baseItems.entrySet().iterator();
final Iterator<Entry<Long, T>> masterI = vmasterI;
@Override
public boolean hasNext() {

View File

@ -315,7 +315,7 @@ public abstract class XSLFShape implements Shape<XSLFShape,XSLFTextParagraph> {
/**
* Walk up the inheritance tree and fetch shape properties.<p>
*
* The following order of inheritance is assumed:<p>
* The following order of inheritance is assumed:
* <ol>
* <li>slide
* <li>slideLayout

View File

@ -54,7 +54,7 @@ public class ThemesTable extends POIXMLDocumentPart implements Themes {
if (idx >= values().length || idx < 0) return UNKNOWN;
return values()[idx];
}
private ThemeElement(int idx, String name) {
ThemeElement(int idx, String name) {
this.idx = idx; this.name = name;
}
public final int idx;
@ -62,7 +62,7 @@ public class ThemesTable extends POIXMLDocumentPart implements Themes {
}
private IndexedColorMap colorMap;
private ThemeDocument theme;
private final ThemeDocument theme;
/**
* Create a new, empty ThemesTable
@ -99,7 +99,6 @@ public class ThemesTable extends POIXMLDocumentPart implements Themes {
/**
* called from {@link StylesTable} when setting theme, used to adjust colors if a custom indexed mapping is defined
* @param colorMap
*/
protected void setColorMap(IndexedColorMap colorMap) {
this.colorMap = colorMap;
@ -133,7 +132,7 @@ public class ThemesTable extends POIXMLDocumentPart implements Themes {
default: return null;
}
byte[] rgb = null;
byte[] rgb;
if (ctColor.isSetSrgbClr()) {
// Color is a regular one
rgb = ctColor.getSrgbClr().getVal();

View File

@ -49,6 +49,7 @@ final class SXSSFEvaluationSheet implements EvaluationSheet {
* @see org.apache.poi.ss.formula.EvaluationSheet#isRowHidden(int)
* @since POI 4.1.0
*/
@Override
public boolean isRowHidden(int rowIndex) {
SXSSFRow row = _xs.getRow(rowIndex);
if (row == null) return false;

View File

@ -51,6 +51,7 @@ public abstract class BaseXSSFFormulaEvaluator extends BaseFormulaEvaluator {
/**
* Returns a CellValue wrapper around the supplied ValueEval instance.
*/
@Override
protected CellValue evaluateFormulaCellValue(Cell cell) {
EvaluationCell evalCell = toEvaluationCell(cell);
ValueEval eval = _bookEvaluator.evaluate(evalCell);
@ -72,6 +73,7 @@ public abstract class BaseXSSFFormulaEvaluator extends BaseFormulaEvaluator {
throw new RuntimeException("Unexpected eval class (" + eval.getClass().getName() + ")");
}
@Override
protected void setCellType(Cell cell, CellType cellType) {
if (cell instanceof XSSFCell) {
EvaluationWorkbook evaluationWorkbook = getEvaluationWorkbook();

View File

@ -23,15 +23,12 @@ import org.apache.poi.hssf.util.HSSFColor;
*/
public class DefaultIndexedColorMap implements IndexedColorMap {
/**
* @see org.apache.poi.xssf.usermodel.IndexedColorMap#getRGB(int)
*/
@Override
public byte[] getRGB(int index) {
return getDefaultRGB(index);
}
/**
* @param index
* @return RGB bytes from HSSF default color by index
*/
public static byte[] getDefaultRGB(int index) {

View File

@ -18,7 +18,6 @@
package org.apache.poi.xssf.usermodel;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.EnumMap;
@ -343,7 +342,7 @@ public enum XSSFBuiltinTableStyle {
*/
private static final Map<XSSFBuiltinTableStyle, TableStyle> styleMap = new EnumMap<>(XSSFBuiltinTableStyle.class);
private XSSFBuiltinTableStyle() {
XSSFBuiltinTableStyle() {
}
/**
@ -357,7 +356,6 @@ public enum XSSFBuiltinTableStyle {
/**
* NOTE: only checks by name, not definition.
*
* @param style
* @return true if the style represents a built-in style, false if it is null or a custom style
*/
public static boolean isBuiltinStyle(TableStyle style) {
@ -423,22 +421,20 @@ public enum XSSFBuiltinTableStyle {
}
}
private static String styleXML(Node dxfsNode, Node tableStyleNode) throws IOException, TransformerException {
private static String styleXML(Node dxfsNode, Node tableStyleNode) throws TransformerException {
// built-ins doc uses 1-based dxf indexing, Excel uses 0 based.
// add a dummy node to adjust properly.
dxfsNode.insertBefore(dxfsNode.getOwnerDocument().createElement("dxf"), dxfsNode.getFirstChild());
StringBuilder sb = new StringBuilder(1024);
sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n")
.append("<styleSheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" ")
.append("xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" ")
.append("xmlns:x14ac=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac\" ")
.append("xmlns:x16r2=\"http://schemas.microsoft.com/office/spreadsheetml/2015/02/main\" ")
.append("mc:Ignorable=\"x14ac x16r2\">\n");
sb.append(writeToString(dxfsNode));
sb.append(writeToString(tableStyleNode));
sb.append("</styleSheet>");
return sb.toString();
return "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" +
"<styleSheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" " +
"xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" " +
"xmlns:x14ac=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac\" " +
"xmlns:x16r2=\"http://schemas.microsoft.com/office/spreadsheetml/2015/02/main\" " +
"mc:Ignorable=\"x14ac x16r2\">\n" +
writeToString(dxfsNode) +
writeToString(tableStyleNode) +
"</styleSheet>";
}
private static String writeToString(Node node) throws TransformerException {
@ -458,27 +454,27 @@ public enum XSSFBuiltinTableStyle {
private final XSSFBuiltinTableStyle builtIn;
private final TableStyle style;
/**
* @param builtIn
* @param style
*/
protected XSSFBuiltinTypeStyleStyle(XSSFBuiltinTableStyle builtIn, TableStyle style) {
this.builtIn = builtIn;
this.style = style;
}
@Override
public String getName() {
return style.getName();
}
@Override
public int getIndex() {
return builtIn.ordinal();
}
@Override
public boolean isBuiltin() {
return true;
}
@Override
public DifferentialStyleProvider getStyle(TableStyleType type) {
return style.getStyle(type);
}

View File

@ -49,10 +49,9 @@ import org.apache.poi.ss.util.CellReference;
import org.apache.poi.util.Beta;
import org.apache.poi.util.Internal;
import org.apache.poi.util.LocaleUtil;
import org.apache.poi.util.Removal;
import org.apache.poi.xssf.model.CalculationChain;
import org.apache.poi.xssf.model.SharedStringsTable;
import org.apache.poi.xssf.model.StylesTable;
import org.apache.poi.xssf.model.CalculationChain;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCell;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellFormula;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STCellFormulaType;
@ -99,12 +98,12 @@ public final class XSSFCell extends CellBase {
* Table of strings shared across this workbook.
* If two cells contain the same string, then the cell value is the same index into SharedStringsTable
*/
private SharedStringsTable _sharedStringSource;
private final SharedStringsTable _sharedStringSource;
/**
* Table of cell styles shared across all cells in a workbook.
*/
private StylesTable _stylesSource;
private final StylesTable _stylesSource;
/**
* Construct a XSSFCell.
@ -127,9 +126,6 @@ public final class XSSFCell extends CellBase {
_stylesSource = row.getSheet().getWorkbook().getStylesSource();
}
/**
* {@inheritDoc}
*/
@Override
protected SpreadsheetVersion getSpreadsheetVersion() {
return SpreadsheetVersion.EXCEL2007;
@ -290,7 +286,7 @@ public final class XSSFCell extends CellBase {
* </p>
* @return the value of the cell as a number
* @throws IllegalStateException if the cell type returned by {@link #getCellType()} is {@link CellType#STRING}
* @exception NumberFormatException if the cell value isn't a parsable <code>double</code>.
* @exception NumberFormatException if the cell value isn't a parsable {@code double}.
* @see DataFormatter for turning this number into a string similar to that which Excel would render this number as.
*/
@Override
@ -320,9 +316,6 @@ public final class XSSFCell extends CellBase {
}
}
/**
* {@inheritDoc}
*/
@Override
public void setCellValueImpl(double value) {
_cell.setT(STCellType.N);
@ -385,10 +378,14 @@ public final class XSSFCell extends CellBase {
}
}
break;
case FORMULA:
checkFormulaCachedValueType(CellType.STRING, getBaseCellType(false));
case FORMULA: {
CellType cachedValueType = getBaseCellType(false);
if (cachedValueType != CellType.STRING) {
throw typeMismatch(CellType.STRING, cachedValueType, true);
}
rt = new XSSFRichTextString(_cell.isSetV() ? _cell.getV() : "");
break;
}
default:
throw typeMismatch(CellType.STRING, cellType, false);
}
@ -396,23 +393,11 @@ public final class XSSFCell extends CellBase {
return rt;
}
private static void checkFormulaCachedValueType(CellType expectedTypeCode, CellType cachedValueType) {
if (cachedValueType != expectedTypeCode) {
throw typeMismatch(expectedTypeCode, cachedValueType, true);
}
}
/**
* {@inheritDoc}
*/
@Override
protected void setCellValueImpl(String value) {
setCellValueImpl(new XSSFRichTextString(value));
}
/**
* {@inheritDoc}
*/
@Override
protected void setCellValueImpl(RichTextString str) {
CellType cellType = getCellType();
@ -434,7 +419,7 @@ public final class XSSFCell extends CellBase {
}
/**
* Return a formula for the cell, for example, <code>SUM(C4:E4)</code>
* Return a formula for the cell, for example, {@code SUM(C4:E4)}
*
* @return a formula for the cell
* @throws IllegalStateException if the cell type returned by {@link #getCellType()} is not {@link CellType#FORMULA}
@ -517,8 +502,8 @@ public final class XSSFCell extends CellBase {
* {@link FormulaEvaluator} instances based on this workbook.
* </p>
*
* @param formula the formula to set, e.g. <code>"SUM(C4:E4)"</code>.
* If the argument is <code>null</code> then the current formula is removed.
* @param formula the formula to set, e.g. {@code "SUM(C4:E4)"}.
* If the argument is {@code null} then the current formula is removed.
* @throws org.apache.poi.ss.formula.FormulaParseException if the formula has incorrect syntax or is otherwise invalid
* @throws IllegalStateException if the operation is not allowed, for example,
* when the cell is a part of a multi-cell array formula
@ -657,10 +642,8 @@ public final class XSSFCell extends CellBase {
* @return true if the cell is of a formula type POI can handle
*/
private boolean isFormulaCell() {
if ( (_cell.isSetF() && _cell.getF().getT() != STCellFormulaType.DATA_TABLE ) || getSheet().isCellInArrayFormulaContext(this)) {
return true;
}
return false;
return (_cell.isSetF() && _cell.getF().getT() != STCellFormulaType.DATA_TABLE)
|| getSheet().isCellInArrayFormulaContext(this);
}
/**
@ -732,7 +715,7 @@ public final class XSSFCell extends CellBase {
* </p>
* @return the value of the cell as a date
* @throws IllegalStateException if the cell type returned by {@link #getCellType()} is {@link CellType#STRING}
* @exception NumberFormatException if the cell value isn't a parsable <code>double</code>.
* @exception NumberFormatException if the cell value isn't a parsable {@code double}.
* @see DataFormatter for formatting this date into a string similar to how excel does.
*/
@Override
@ -753,7 +736,7 @@ public final class XSSFCell extends CellBase {
* </p>
* @return the value of the cell as a LocalDateTime
* @throws IllegalStateException if the cell type returned by {@link #getCellType()} is {@link CellType#STRING}
* @exception NumberFormatException if the cell value isn't a parsable <code>double</code>.
* @exception NumberFormatException if the cell value isn't a parsable {@code double}.
* @see DataFormatter for formatting this date into a string similar to how excel does.
*/
@Override
@ -767,27 +750,18 @@ public final class XSSFCell extends CellBase {
return DateUtil.getLocalDateTime(value, date1904);
}
/**
* {@inheritDoc}
*/
@Override
protected void setCellValueImpl(Date value) {
boolean date1904 = getSheet().getWorkbook().isDate1904();
setCellValue(DateUtil.getExcelDate(value, date1904));
}
/**
* {@inheritDoc}
*/
@Override
protected void setCellValueImpl(LocalDateTime value) {
boolean date1904 = getSheet().getWorkbook().isDate1904();
setCellValue(DateUtil.getExcelDate(value, date1904));
}
/**
* {@inheritDoc}
*/
@Override
protected void setCellValueImpl(Calendar value) {
boolean date1904 = getSheet().getWorkbook().isDate1904();
@ -861,9 +835,6 @@ public final class XSSFCell extends CellBase {
_cell.setV(error.getString());
}
/**
* {@inheritDoc}
*/
@Override
public void setAsActiveCell() {
getSheet().setActiveCell(getAddress());
@ -902,7 +873,6 @@ public final class XSSFCell extends CellBase {
/**
* Needed by bug #62834, which points out getCellFormula() expects an evaluation context or creates a new one,
* so if there is one in use, it needs to be carried on through.
* @param cellType
* @param evalWb BaseXSSFEvaluationWorkbook already in use, or null if a new implicit one should be used
*/
protected void setCellType(CellType cellType, BaseXSSFEvaluationWorkbook evalWb) {
@ -1003,7 +973,7 @@ public final class XSSFCell extends CellBase {
* </p>
*
* @return the raw cell value as contained in the underlying CTCell bean,
* <code>null</code> for blank cells.
* {@code null} for blank cells.
*/
public String getRawValue() {
return _cell.getV();
@ -1034,7 +1004,7 @@ public final class XSSFCell extends CellBase {
/**
* Returns cell comment associated with this cell
*
* @return the cell comment associated with this cell or <code>null</code>
* @return the cell comment associated with this cell or {@code null}
*/
@Override
public XSSFComment getCellComment() {
@ -1074,7 +1044,7 @@ public final class XSSFCell extends CellBase {
/**
* Returns hyperlink associated with this cell
*
* @return hyperlink associated with this cell or <code>null</code> if not found
* @return hyperlink associated with this cell or {@code null} if not found
*/
@Override
public XSSFHyperlink getHyperlink() {

View File

@ -17,25 +17,31 @@
package org.apache.poi.xssf.usermodel;
import static org.apache.poi.ooxml.POIXMLTypeLoader.DEFAULT_XML_OPTIONS;
import java.io.IOException;
import java.io.OutputStream;
import javax.xml.namespace.QName;
import org.apache.poi.ooxml.POIXMLFactory;
import org.apache.poi.ooxml.POIXMLRelation;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.util.Removal;
import org.apache.poi.xddf.usermodel.chart.XDDFChart;
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlObject;
import org.apache.xmlbeans.XmlOptions;
import org.openxmlformats.schemas.drawingml.x2006.chart.*;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTChartSpace;
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.CTStrRef;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTTitle;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTTx;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.Text;
import javax.xml.namespace.QName;
import java.io.IOException;
import java.io.OutputStream;
import static org.apache.poi.ooxml.POIXMLTypeLoader.DEFAULT_XML_OPTIONS;
/**
* Represents a SpreadsheetML Chart
*/
@ -60,7 +66,7 @@ public final class XSSFChart extends XDDFChart {
* @param part
* the package part holding the chart data, the content type must
* be
* <code>application/vnd.openxmlformats-officedocument.drawingml.chart+xml</code>
* {@code application/vnd.openxmlformats-officedocument.drawingml.chart+xml}
*
* @since POI 3.14-Beta1
*/
@ -204,8 +210,6 @@ public final class XSSFChart extends XDDFChart {
/**
* Set the formula expression to use for the chart title
*
* @param formula
*/
public void setTitleFormula(String formula) {
CTTitle ctTitle;

View File

@ -191,8 +191,6 @@ public class XSSFClientAnchor extends XSSFAnchor implements ClientAnchor {
}
/**
* @param sheet
* @param row
* @return height in twips (1/20th of point) for row or default
*/
private static float getRowHeight(XSSFSheet sheet, int row) {
@ -208,54 +206,59 @@ public class XSSFClientAnchor extends XSSFAnchor implements ClientAnchor {
return cell2 != null ? cell2 : calcCell(getCell1(), size.getCx(), size.getCy());
}
@Override
public short getCol1() {
return (short)getCell1().getCol();
}
/**
* @throws NullPointerException if cell1 is null (fixed position)
* @see org.apache.poi.ss.usermodel.ClientAnchor#setCol1(int)
*/
@Override
public void setCol1(int col1) {
cell1.setCol(col1);
}
@Override
public short getCol2() {
return (short) getCell2().getCol();
}
/**
* @throws NullPointerException if cell2 is null (fixed size)
* @see org.apache.poi.ss.usermodel.ClientAnchor#setCol2(int)
*/
@Override
public void setCol2(int col2) {
cell2.setCol(col2);
}
@Override
public int getRow1() {
return getCell1().getRow();
}
/**
* @throws NullPointerException if cell1 is null (fixed position)
* @see org.apache.poi.ss.usermodel.ClientAnchor#setRow1(int)
*/
@Override
public void setRow1(int row1) {
cell1.setRow(row1);
}
@Override
public int getRow2() {
return getCell2().getRow();
}
/**
* @throws NullPointerException if cell2 is null (fixed size)
* @see org.apache.poi.ss.usermodel.ClientAnchor#setRow2(int)
*/
@Override
public void setRow2(int row2) {
cell2.setRow(row2);
}
@Override
public int getDx1() {
return Math.toIntExact(POIXMLUnits.parseLength(getCell1().xgetColOff()));
}
@ -264,10 +267,12 @@ public class XSSFClientAnchor extends XSSFAnchor implements ClientAnchor {
* @throws NullPointerException if cell1 is null (fixed position)
* @see org.apache.poi.ss.usermodel.ChildAnchor#setDx1(int)
*/
@Override
public void setDx1(int dx1) {
cell1.setColOff(dx1);
}
@Override
public int getDy1() {
return Math.toIntExact(POIXMLUnits.parseLength(getCell1().xgetRowOff()));
}
@ -276,10 +281,12 @@ public class XSSFClientAnchor extends XSSFAnchor implements ClientAnchor {
* @throws NullPointerException if cell1 is null (fixed position)
* @see org.apache.poi.ss.usermodel.ChildAnchor#setDy1(int)
*/
@Override
public void setDy1(int dy1) {
cell1.setRowOff(dy1);
}
@Override
public int getDy2() {
return Math.toIntExact(POIXMLUnits.parseLength(getCell2().xgetRowOff()));
}
@ -288,10 +295,12 @@ public class XSSFClientAnchor extends XSSFAnchor implements ClientAnchor {
* @throws NullPointerException if cell2 is null (fixed size)
* @see org.apache.poi.ss.usermodel.ChildAnchor#setDy2(int)
*/
@Override
public void setDy2(int dy2) {
cell2.setRowOff(dy2);
}
@Override
public int getDx2() {
return Math.toIntExact(POIXMLUnits.parseLength(getCell2().xgetColOff()));
}
@ -300,13 +309,14 @@ public class XSSFClientAnchor extends XSSFAnchor implements ClientAnchor {
* @throws NullPointerException if cell2 is null (fixed size)
* @see org.apache.poi.ss.usermodel.ChildAnchor#setDx2(int)
*/
@Override
public void setDx2(int dx2) {
cell2.setColOff(dx2);
}
@Override
public boolean equals(Object o) {
if (o == null || !(o instanceof XSSFClientAnchor)) return false;
if (!(o instanceof XSSFClientAnchor)) return false;
XSSFClientAnchor anchor = (XSSFClientAnchor) o;
return getDx1() == anchor.getDx1() &&
@ -369,7 +379,6 @@ public class XSSFClientAnchor extends XSSFAnchor implements ClientAnchor {
/**
* Sets the top-left absolute position of the object. To use this, "from" must be set to null.
* @param position
* @since POI 3.17 beta 1
*/
public void setPosition(CTPoint2D position) {
@ -387,7 +396,6 @@ public class XSSFClientAnchor extends XSSFAnchor implements ClientAnchor {
/**
* Sets the size of the object. To use this, "to" must be set to null.
* @param size
* @since POI 3.17 beta 1
*/
public void setSize(CTPositiveSize2D size) {

View File

@ -51,10 +51,10 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.STIconSetType;
*/
public class XSSFConditionalFormattingRule implements ConditionalFormattingRule {
private final CTCfRule _cfRule;
private XSSFSheet _sh;
private final XSSFSheet _sh;
private static Map<STCfType.Enum, ConditionType> typeLookup = new HashMap<>();
private static Map<STCfType.Enum, ConditionFilterType> filterTypeLookup = new HashMap<>();
private static final Map<STCfType.Enum, ConditionType> typeLookup = new HashMap<>();
private static final Map<STCfType.Enum, ConditionFilterType> filterTypeLookup = new HashMap<>();
static {
typeLookup.put(STCfType.CELL_IS, ConditionType.CELL_VALUE_IS);
typeLookup.put(STCfType.EXPRESSION, ConditionType.FORMULA);
@ -95,7 +95,6 @@ public class XSSFConditionalFormattingRule implements ConditionalFormattingRule
/**
* NOTE: does not set priority, so this assumes the rule will not be added to the sheet yet
* @param sh
*/
/*package*/ XSSFConditionalFormattingRule(XSSFSheet sh){
_cfRule = CTCfRule.Factory.newInstance();
@ -126,12 +125,14 @@ public class XSSFConditionalFormattingRule implements ConditionalFormattingRule
return dxf;
}
@Override
public int getPriority() {
final int priority = _cfRule.getPriority();
// priorities start at 1, if it is less, it is undefined, use definition order in caller
return priority >=1 ? priority : 0;
}
@Override
public boolean getStopIfTrue() {
return _cfRule.getStopIfTrue();
}
@ -140,8 +141,9 @@ public class XSSFConditionalFormattingRule implements ConditionalFormattingRule
* Create a new border formatting structure if it does not exist,
* otherwise just return existing object.
*
* @return - border formatting object, never returns <code>null</code>.
* @return - border formatting object, never returns {@code null}.
*/
@Override
public XSSFBorderFormatting createBorderFormatting(){
CTDxf dxf = getDxf(true);
CTBorder border;
@ -155,8 +157,9 @@ public class XSSFConditionalFormattingRule implements ConditionalFormattingRule
}
/**
* @return - border formatting object if defined, <code>null</code> otherwise
* @return - border formatting object if defined, {@code null} otherwise
*/
@Override
public XSSFBorderFormatting getBorderFormatting(){
CTDxf dxf = getDxf(false);
if(dxf == null || !dxf.isSetBorder()) return null;
@ -168,8 +171,9 @@ public class XSSFConditionalFormattingRule implements ConditionalFormattingRule
* Create a new font formatting structure if it does not exist,
* otherwise just return existing object.
*
* @return - font formatting object, never returns <code>null</code>.
* @return - font formatting object, never returns {@code null}.
*/
@Override
public XSSFFontFormatting createFontFormatting(){
CTDxf dxf = getDxf(true);
CTFont font;
@ -183,8 +187,9 @@ public class XSSFConditionalFormattingRule implements ConditionalFormattingRule
}
/**
* @return - font formatting object if defined, <code>null</code> otherwise
* @return - font formatting object if defined, {@code null} otherwise
*/
@Override
public XSSFFontFormatting getFontFormatting(){
CTDxf dxf = getDxf(false);
if(dxf == null || !dxf.isSetFont()) return null;
@ -196,8 +201,9 @@ public class XSSFConditionalFormattingRule implements ConditionalFormattingRule
* Create a new pattern formatting structure if it does not exist,
* otherwise just return existing object.
*
* @return - pattern formatting object, never returns <code>null</code>.
* @return - pattern formatting object, never returns {@code null}.
*/
@Override
public XSSFPatternFormatting createPatternFormatting(){
CTDxf dxf = getDxf(true);
CTFill fill;
@ -211,8 +217,9 @@ public class XSSFConditionalFormattingRule implements ConditionalFormattingRule
}
/**
* @return - pattern formatting object if defined, <code>null</code> otherwise
* @return - pattern formatting object if defined, {@code null} otherwise
*/
@Override
public XSSFPatternFormatting getPatternFormatting(){
CTDxf dxf = getDxf(false);
if(dxf == null || !dxf.isSetFill()) return null;
@ -221,8 +228,6 @@ public class XSSFConditionalFormattingRule implements ConditionalFormattingRule
}
/**
*
* @param color
* @return data bar formatting
*/
public XSSFDataBarFormatting createDataBarFormatting(XSSFColor color) {
@ -234,12 +239,7 @@ public class XSSFConditionalFormattingRule implements ConditionalFormattingRule
_cfRule.setType(STCfType.DATA_BAR);
// Ensure the right element
CTDataBar bar = null;
if (_cfRule.isSetDataBar()) {
bar = _cfRule.getDataBar();
} else {
bar = _cfRule.addNewDataBar();
}
CTDataBar bar = _cfRule.isSetDataBar() ? _cfRule.getDataBar() : _cfRule.addNewDataBar();
// Set the color
bar.setColor(color.getCTColor());
@ -252,6 +252,7 @@ public class XSSFConditionalFormattingRule implements ConditionalFormattingRule
// Wrap and return
return new XSSFDataBarFormatting(bar, _sh.getWorkbook().getStylesSource().getIndexedColors());
}
@Override
public XSSFDataBarFormatting getDataBarFormatting() {
if (_cfRule.isSetDataBar()) {
CTDataBar bar = _cfRule.getDataBar();
@ -270,12 +271,7 @@ public class XSSFConditionalFormattingRule implements ConditionalFormattingRule
_cfRule.setType(STCfType.ICON_SET);
// Ensure the right element
CTIconSet icons = null;
if (_cfRule.isSetIconSet()) {
icons = _cfRule.getIconSet();
} else {
icons = _cfRule.addNewIconSet();
}
CTIconSet icons = _cfRule.isSetIconSet() ? _cfRule.getIconSet() : _cfRule.addNewIconSet();
// Set the type of the icon set
if (iconSet.name != null) {
STIconSetType.Enum xIconSet = STIconSetType.Enum.forString(iconSet.name);
@ -294,6 +290,7 @@ public class XSSFConditionalFormattingRule implements ConditionalFormattingRule
// Wrap and return
return new XSSFIconMultiStateFormatting(icons);
}
@Override
public XSSFIconMultiStateFormatting getMultiStateFormatting() {
if (_cfRule.isSetIconSet()) {
CTIconSet icons = _cfRule.getIconSet();
@ -312,12 +309,7 @@ public class XSSFConditionalFormattingRule implements ConditionalFormattingRule
_cfRule.setType(STCfType.COLOR_SCALE);
// Ensure the right element
CTColorScale scale = null;
if (_cfRule.isSetColorScale()) {
scale = _cfRule.getColorScale();
} else {
scale = _cfRule.addNewColorScale();
}
CTColorScale scale = _cfRule.isSetColorScale() ? _cfRule.getColorScale() : _cfRule.addNewColorScale();
// Add a default set of thresholds and colors
if (scale.sizeOfCfvoArray() == 0) {
@ -338,6 +330,7 @@ public class XSSFConditionalFormattingRule implements ConditionalFormattingRule
// Wrap and return
return new XSSFColorScaleFormatting(scale, _sh.getWorkbook().getStylesSource().getIndexedColors());
}
@Override
public XSSFColorScaleFormatting getColorScaleFormatting() {
if (_cfRule.isSetColorScale()) {
CTColorScale scale = _cfRule.getColorScale();
@ -349,8 +342,8 @@ public class XSSFConditionalFormattingRule implements ConditionalFormattingRule
/**
* Return the number format from the dxf style record if present, null if not
* @see org.apache.poi.ss.usermodel.ConditionalFormattingRule#getNumberFormat()
*/
@Override
public ExcelNumberFormat getNumberFormat() {
CTDxf dxf = getDxf(false);
if(dxf == null || !dxf.isSetNumFmt()) return null;
@ -369,12 +362,13 @@ public class XSSFConditionalFormattingRule implements ConditionalFormattingRule
/**
* Will return null if {@link #getConditionType()} != {@link ConditionType#FILTER}
* @see org.apache.poi.ss.usermodel.ConditionalFormattingRule#getConditionFilterType()
*/
@Override
public ConditionFilterType getConditionFilterType() {
return filterTypeLookup.get(_cfRule.getType());
}
@Override
public ConditionFilterData getFilterConfiguration() {
return new XSSFConditionFilterData(_cfRule);
}
@ -384,7 +378,6 @@ public class XSSFConditionalFormattingRule implements ConditionalFormattingRule
* {@link ConditionType#CELL_VALUE_IS}
* <p>
* MUST be a constant from {@link org.apache.poi.ss.usermodel.ComparisonOperator}
* </p>
*
* @return the conditional format operator
*/
@ -413,13 +406,12 @@ public class XSSFConditionalFormattingRule implements ConditionalFormattingRule
* this field is the first operand of the comparison.
* If type is {@link ConditionType#FORMULA}, this formula is used
* to determine if the conditional formatting is applied.
* </p>
* <p>
* If comparison type is {@link ConditionType#FORMULA} the formula MUST be a Boolean function
* </p>
*
* @return the first formula
*/
@Override
public String getFormula1(){
return _cfRule.sizeOfFormulaArray() > 0 ? _cfRule.getFormulaArray(0) : null;
}
@ -431,10 +423,12 @@ public class XSSFConditionalFormattingRule implements ConditionalFormattingRule
*
* @return the second formula
*/
@Override
public String getFormula2(){
return _cfRule.sizeOfFormulaArray() == 2 ? _cfRule.getFormulaArray(1) : null;
}
@Override
public String getText() {
return _cfRule.getText();
}
@ -443,6 +437,7 @@ public class XSSFConditionalFormattingRule implements ConditionalFormattingRule
* Conditional format rules don't define stripes, so always 0
* @see org.apache.poi.ss.usermodel.DifferentialStyleProvider#getStripeSize()
*/
@Override
public int getStripeSize() {
return 0;
}

View File

@ -42,7 +42,7 @@ public final class XSSFConnector extends XSSFShape {
private static CTConnector prototype;
private CTConnector ctShape;
private final CTConnector ctShape;
/**
* Construct a new XSSFConnector object.
@ -128,6 +128,7 @@ public final class XSSFConnector extends XSSFShape {
ctShape.getSpPr().getPrstGeom().setPrst(STShapeType.Enum.forInt(type));
}
@Override
protected CTShapeProperties getShapeProperties(){
return ctShape.getSpPr();
}

View File

@ -36,7 +36,7 @@ public class XSSFDataValidationConstraint implements DataValidationConstraint {
private String formula1;
private String formula2;
private int validationType = -1;
private final int validationType;
private int operator = -1;
private String[] explicitListOfValues;
@ -73,10 +73,8 @@ public class XSSFDataValidationConstraint implements DataValidationConstraint {
/**
* This is the constructor called using the OOXML raw data. Excel overloads formula1 to also encode explicit value lists,
* so this constructor has to check for and parse that syntax.
* @param validationType
* @param operator
* @param formula1 Overloaded: formula1 or list of explicit values
* @param formula2 (formula1 is a list of explicit values, this is ignored: use <code>null</code>)
* @param formula2 (formula1 is a list of explicit values, this is ignored: use {@code null})
*/
public XSSFDataValidationConstraint(int validationType, int operator, String formula1, String formula2) {
super();
@ -101,6 +99,7 @@ public class XSSFDataValidationConstraint implements DataValidationConstraint {
/* (non-Javadoc)
* @see org.apache.poi.ss.usermodel.DataValidationConstraint#getExplicitListValues()
*/
@Override
public String[] getExplicitListValues() {
return explicitListOfValues;
}
@ -108,6 +107,7 @@ public class XSSFDataValidationConstraint implements DataValidationConstraint {
/* (non-Javadoc)
* @see org.apache.poi.ss.usermodel.DataValidationConstraint#getFormula1()
*/
@Override
public String getFormula1() {
return formula1;
}
@ -115,6 +115,7 @@ public class XSSFDataValidationConstraint implements DataValidationConstraint {
/* (non-Javadoc)
* @see org.apache.poi.ss.usermodel.DataValidationConstraint#getFormula2()
*/
@Override
public String getFormula2() {
return formula2;
}
@ -122,6 +123,7 @@ public class XSSFDataValidationConstraint implements DataValidationConstraint {
/* (non-Javadoc)
* @see org.apache.poi.ss.usermodel.DataValidationConstraint#getOperator()
*/
@Override
public int getOperator() {
return operator;
}
@ -129,6 +131,7 @@ public class XSSFDataValidationConstraint implements DataValidationConstraint {
/* (non-Javadoc)
* @see org.apache.poi.ss.usermodel.DataValidationConstraint#getValidationType()
*/
@Override
public int getValidationType() {
return validationType;
}
@ -136,6 +139,7 @@ public class XSSFDataValidationConstraint implements DataValidationConstraint {
/* (non-Javadoc)
* @see org.apache.poi.ss.usermodel.DataValidationConstraint#setExplicitListValues(java.lang.String[])
*/
@Override
public void setExplicitListValues(String[] explicitListValues) {
this.explicitListOfValues = explicitListValues;
@ -143,8 +147,7 @@ public class XSSFDataValidationConstraint implements DataValidationConstraint {
// further, Excel has no escaping for commas in explicit lists, so we don't need to worry about that.
if ( explicitListOfValues!=null && explicitListOfValues.length > 0 ) {
StringBuilder builder = new StringBuilder(QUOTE);
for (int i = 0; i < explicitListValues.length; i++) {
String string = explicitListValues[i];
for (String string : explicitListValues) {
if (builder.length() > 1) {
builder.append(LIST_SEPARATOR);
}
@ -158,6 +161,7 @@ public class XSSFDataValidationConstraint implements DataValidationConstraint {
/* (non-Javadoc)
* @see org.apache.poi.ss.usermodel.DataValidationConstraint#setFormula1(java.lang.String)
*/
@Override
public void setFormula1(String formula1) {
this.formula1 = removeLeadingEquals(formula1);
}
@ -182,6 +186,7 @@ public class XSSFDataValidationConstraint implements DataValidationConstraint {
/* (non-Javadoc)
* @see org.apache.poi.ss.usermodel.DataValidationConstraint#setFormula2(java.lang.String)
*/
@Override
public void setFormula2(String formula2) {
this.formula2 = removeLeadingEquals(formula2);
}
@ -189,6 +194,7 @@ public class XSSFDataValidationConstraint implements DataValidationConstraint {
/* (non-Javadoc)
* @see org.apache.poi.ss.usermodel.DataValidationConstraint#setOperator(int)
*/
@Override
public void setOperator(int operator) {
this.operator = operator;
}

View File

@ -38,9 +38,7 @@ public class XSSFDxfStyleProvider implements DifferentialStyleProvider {
private final int stripeSize;
/**
* @param dxf
* @param stripeSize 0 for non-stripe styles, &gt; 1 for stripes
* @param colorMap
*/
public XSSFDxfStyleProvider(CTDxf dxf, int stripeSize, IndexedColorMap colorMap) {
this.stripeSize = stripeSize;
@ -63,22 +61,27 @@ public class XSSFDxfStyleProvider implements DifferentialStyleProvider {
}
}
@Override
public BorderFormatting getBorderFormatting() {
return border;
}
@Override
public FontFormatting getFontFormatting() {
return font;
}
@Override
public ExcelNumberFormat getNumberFormat() {
return number;
}
@Override
public PatternFormatting getPatternFormatting() {
return fill;
}
@Override
public int getStripeSize() {
return stripeSize;
}

View File

@ -56,6 +56,7 @@ final class XSSFEvaluationSheet implements EvaluationSheet {
* @see org.apache.poi.ss.formula.EvaluationSheet#isRowHidden(int)
* @since POI 4.1.0
*/
@Override
public boolean isRowHidden(int rowIndex) {
final XSSFRow row = _xs.getRow(rowIndex);
if (row == null) return false;

View File

@ -42,7 +42,6 @@ public class XSSFEvenFooter extends XSSFHeaderFooter implements Footer{
/**
* Create an instance of XSSFEvenFooter from the supplied XML bean
* @see XSSFSheet#getEvenFooter()
* @param headerFooter
*/
protected XSSFEvenFooter(CTHeaderFooter headerFooter) {
super(headerFooter);

View File

@ -44,7 +44,6 @@ public class XSSFEvenHeader extends XSSFHeaderFooter implements Header {
* header is created, The property "DifferentOddEven" is set for this sheet as well.
*
* @see XSSFSheet#getEvenHeader()
* @param headerFooter
*/
protected XSSFEvenHeader(CTHeaderFooter headerFooter) {
super(headerFooter);

View File

@ -41,7 +41,6 @@ public class XSSFFirstFooter extends XSSFHeaderFooter implements Footer{
/**
* Create an instance of XSSFFirstFooter from the supplied XML bean
* @see XSSFSheet#getFirstFooter()
* @param headerFooter
*/
protected XSSFFirstFooter(CTHeaderFooter headerFooter) {
super(headerFooter);

View File

@ -22,26 +22,23 @@ import org.apache.poi.xssf.usermodel.extensions.XSSFHeaderFooter;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHeaderFooter;
/**
* <p>
* First page header content. Corresponds to first printed page.
* The first logical page in the sheet may not be printed, for example, if the print area is specified to
* be a range such that it falls outside the first page's scope.
* </p><p>
* <p>
* The first page header is activated by the "Different First" Header/Footer property for the sheet.
* If this property is not set, the first page header is ignored.
* </p><p>
* <p>
* Creating a first page header or footer sets this property by default, so all you need to do to
* get an first page header or footer to display is to create one. Likewise, if both the first page
* header and footer are usnset, then this property is unset, and the first page header and footer
* are ignored.
* </p>
*/
public class XSSFFirstHeader extends XSSFHeaderFooter implements Header{
/**
* Create an instance of XSSFFirstHeader from the supplied XML bean
* @see XSSFSheet#getFirstHeader()
* @param headerFooter
*/
protected XSSFFirstHeader(CTHeaderFooter headerFooter) {
super(headerFooter);

View File

@ -64,7 +64,7 @@ public class XSSFFont implements Font {
private IndexedColorMap _indexedColorMap;
private ThemesTable _themes;
private CTFont _ctFont;
private final CTFont _ctFont;
private int _index;
/**
@ -113,6 +113,7 @@ public class XSSFFont implements Font {
*
* @return boolean - bold
*/
@Override
public boolean getBold() {
CTBooleanProperty bold = _ctFont.sizeOfBArray() == 0 ? null : _ctFont.getBArray(0);
return (bold != null && bold.getVal());
@ -124,6 +125,7 @@ public class XSSFFont implements Font {
* @return int - character-set (0-255)
* @see FontCharset
*/
@Override
public int getCharSet() {
CTIntProperty charset = _ctFont.sizeOfCharsetArray() == 0 ? null : _ctFont.getCharsetArray(0);
return charset == null ? FontCharset.ANSI.getNativeId() : FontCharset.valueOf(charset.getVal()).getNativeId();
@ -137,6 +139,7 @@ public class XSSFFont implements Font {
* @return short - indexed color to use
* @see IndexedColors
*/
@Override
public short getColor() {
CTColor color = _ctFont.sizeOfColorArray() == 0 ? null : _ctFont.getColorArray(0);
if (color == null) return IndexedColors.BLACK.getIndex();
@ -194,6 +197,7 @@ public class XSSFFont implements Font {
* @return short - height in 1/20ths of a point
* @see #getFontHeightInPoints()
*/
@Override
public short getFontHeight() {
return (short)(getFontHeightRaw()*Font.TWIPS_PER_POINT);
}
@ -206,6 +210,7 @@ public class XSSFFont implements Font {
* @return short - height in the familiar unit of measure - points
* @see #getFontHeight()
*/
@Override
public short getFontHeightInPoints() {
return (short)getFontHeightRaw();
}
@ -227,6 +232,7 @@ public class XSSFFont implements Font {
*
* @return String - a string representing the name of the font to use
*/
@Override
public String getFontName() {
CTFontName name = _ctFont.sizeOfNameArray() == 0 ? null : _ctFont.getNameArray(0);
return name == null ? DEFAULT_FONT_NAME : name.getVal();
@ -237,6 +243,7 @@ public class XSSFFont implements Font {
*
* @return boolean - value for italic
*/
@Override
public boolean getItalic() {
CTBooleanProperty italic = _ctFont.sizeOfIArray() == 0 ? null : _ctFont.getIArray(0);
return italic != null && italic.getVal();
@ -247,6 +254,7 @@ public class XSSFFont implements Font {
*
* @return boolean - value for strikeout
*/
@Override
public boolean getStrikeout() {
CTBooleanProperty strike = _ctFont.sizeOfStrikeArray() == 0 ? null : _ctFont.getStrikeArray(0);
return strike != null && strike.getVal();
@ -260,6 +268,7 @@ public class XSSFFont implements Font {
* @see Font#SS_SUPER
* @see Font#SS_SUB
*/
@Override
public short getTypeOffset() {
CTVerticalAlignFontProperty vAlign = _ctFont.sizeOfVertAlignArray() == 0 ? null : _ctFont.getVertAlignArray(0);
if (vAlign == null) {
@ -284,6 +293,7 @@ public class XSSFFont implements Font {
* @return byte - underlining type
* @see org.apache.poi.ss.usermodel.FontUnderline
*/
@Override
public byte getUnderline() {
CTUnderlineProperty underline = _ctFont.sizeOfUArray() == 0 ? null : _ctFont.getUArray(0);
if (underline != null) {
@ -298,6 +308,7 @@ public class XSSFFont implements Font {
*
* @param bold - boldness to use
*/
@Override
public void setBold(boolean bold) {
if(bold){
CTBooleanProperty ctBold = _ctFont.sizeOfBArray() == 0 ? _ctFont.addNewB() : _ctFont.getBArray(0);
@ -313,6 +324,7 @@ public class XSSFFont implements Font {
* @param charset - charset
* @see FontCharset
*/
@Override
public void setCharSet(byte charset) {
int cs = charset & 0xff;
setCharSet(cs);
@ -324,6 +336,7 @@ public class XSSFFont implements Font {
* @param charset - charset
* @see FontCharset
*/
@Override
public void setCharSet(int charset) {
FontCharset fontCharset = FontCharset.valueOf(charset);
if(fontCharset != null) {
@ -336,7 +349,6 @@ public class XSSFFont implements Font {
/**
* set character-set to use.
*
* @param charSet
* @deprecated use {@link #setCharSet(FontCharset)} instead
*/
@Deprecated
@ -356,7 +368,6 @@ public class XSSFFont implements Font {
/**
* set character-set to use.
*
* @param charSet
* @since 5.0.0
*/
public void setCharSet(FontCharset charSet) {
@ -378,6 +389,7 @@ public class XSSFFont implements Font {
* @see #DEFAULT_FONT_COLOR - Note: default font color
* @see IndexedColors
*/
@Override
public void setColor(short color) {
CTColor ctColor = _ctFont.sizeOfColorArray() == 0 ? _ctFont.addNewColor() : _ctFont.getColorArray(0);
switch (color) {
@ -415,6 +427,7 @@ public class XSSFFont implements Font {
*
* @param height - height in points
*/
@Override
public void setFontHeight(short height) {
setFontHeight((double) height/Font.TWIPS_PER_POINT);
}
@ -434,6 +447,7 @@ public class XSSFFont implements Font {
*
* @see #setFontHeight
*/
@Override
public void setFontHeightInPoints(short height) {
setFontHeight((double)height);
}
@ -459,6 +473,7 @@ public class XSSFFont implements Font {
* @param name - value representing the name of the font to use
* @see #DEFAULT_FONT_NAME
*/
@Override
public void setFontName(String name) {
CTFontName fontName = _ctFont.sizeOfNameArray() == 0 ? _ctFont.addNewName() : _ctFont.getNameArray(0);
fontName.setVal(name == null ? DEFAULT_FONT_NAME : name);
@ -471,6 +486,7 @@ public class XSSFFont implements Font {
*
* @param italic - value for italics or not
*/
@Override
public void setItalic(boolean italic) {
if(italic){
CTBooleanProperty bool = _ctFont.sizeOfIArray() == 0 ? _ctFont.addNewI() : _ctFont.getIArray(0);
@ -487,6 +503,7 @@ public class XSSFFont implements Font {
*
* @param strikeout - value for strikeout or not
*/
@Override
public void setStrikeout(boolean strikeout) {
if(strikeout) {
CTBooleanProperty strike = _ctFont.sizeOfStrikeArray() == 0 ? _ctFont.addNewStrike() : _ctFont.getStrikeArray(0);
@ -506,15 +523,13 @@ public class XSSFFont implements Font {
* @see #SS_SUPER
* @see #SS_SUB
*/
@Override
public void setTypeOffset(short offset) {
if(offset == Font.SS_NONE){
_ctFont.setVertAlignArray(null);
} else {
CTVerticalAlignFontProperty offsetProperty = _ctFont.sizeOfVertAlignArray() == 0 ? _ctFont.addNewVertAlign() : _ctFont.getVertAlignArray(0);
switch (offset) {
case Font.SS_NONE:
offsetProperty.setVal(STVerticalAlignRun.BASELINE);
break;
case Font.SS_SUB:
offsetProperty.setVal(STVerticalAlignRun.SUBSCRIPT);
break;
@ -534,6 +549,7 @@ public class XSSFFont implements Font {
* @param underline - underline type to use
* @see FontUnderline
*/
@Override
public void setUnderline(byte underline) {
setUnderline(FontUnderline.valueOf(underline));
}

View File

@ -103,6 +103,7 @@ public final class XSSFFormulaEvaluator extends BaseXSSFFormulaEvaluator {
/**
* Turns a XSSFCell into a XSSFEvaluationCell
*/
@Override
protected EvaluationCell toEvaluationCell(Cell cell) {
if (!(cell instanceof XSSFCell)){
throw new IllegalArgumentException("Unexpected type of cell: " + cell.getClass() + "." +

View File

@ -43,7 +43,7 @@ public final class XSSFGraphicFrame extends XSSFShape {
private static CTGraphicalObjectFrame prototype;
private CTGraphicalObjectFrame graphicFrame;
private final CTGraphicalObjectFrame graphicFrame;
/**
* Construct a new XSSFGraphicFrame object.
@ -145,6 +145,7 @@ public final class XSSFGraphicFrame extends XSSFShape {
* Returns the frame anchor.
* @return the XSSFClientAnchor anchor this frame is attached to
*/
@Override
public XSSFClientAnchor getAnchor() {
return (XSSFClientAnchor) anchor;
}

View File

@ -29,12 +29,10 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHeaderFooter;
* </p>
*/
public class XSSFHeaderFooterProperties {
private CTHeaderFooter headerFooter;
private final CTHeaderFooter headerFooter;
/**
* Create an instance of XSSFHeaderFooterProperties from the supplied XML bean
*
* @param headerFooter
*/
public XSSFHeaderFooterProperties(CTHeaderFooter headerFooter) {
this.headerFooter = headerFooter;
@ -54,28 +52,28 @@ public class XSSFHeaderFooterProperties {
* returns alignWithMargins attribute
*/
public boolean getAlignWithMargins() {
return getHeaderFooter().isSetAlignWithMargins() ? getHeaderFooter().getAlignWithMargins() : false;
return getHeaderFooter().isSetAlignWithMargins() && getHeaderFooter().getAlignWithMargins();
}
/**
* returns differentFirst attribute
*/
public boolean getDifferentFirst() {
return getHeaderFooter().isSetDifferentFirst() ? getHeaderFooter().getDifferentFirst() : false;
return getHeaderFooter().isSetDifferentFirst() && getHeaderFooter().getDifferentFirst();
}
/**
* returns differentOddEven attribute
*/
public boolean getDifferentOddEven() {
return getHeaderFooter().isSetDifferentOddEven() ? getHeaderFooter().getDifferentOddEven() : false;
return getHeaderFooter().isSetDifferentOddEven() && getHeaderFooter().getDifferentOddEven();
}
/**
* returns scaleWithDoc attribute
*/
public boolean getScaleWithDoc() {
return getHeaderFooter().isSetScaleWithDoc() ? getHeaderFooter().getScaleWithDoc() : false;
return getHeaderFooter().isSetScaleWithDoc() && getHeaderFooter().getScaleWithDoc();
}
/**

View File

@ -38,6 +38,7 @@ class XSSFLineBreak extends XSSFTextRun {
/**
* Always throws IllegalStateException. You cannot change text of a line break.
*/
@Override
public void setText(String text){
throw new IllegalStateException("You cannot change text of a line break, it is always '\\n'");
}

View File

@ -32,7 +32,6 @@ public class XSSFOddFooter extends XSSFHeaderFooter implements Footer{
/**
* Create an instance of XSSFOddFooter from the supplied XML bean
* @see XSSFSheet#getOddFooter()
* @param headerFooter
*/
protected XSSFOddFooter(CTHeaderFooter headerFooter) {
super(headerFooter);

View File

@ -32,7 +32,6 @@ public class XSSFOddHeader extends XSSFHeaderFooter implements Header{
/**
* Create an instance of XSSFOddHeader from the supplied XML bean
* @see XSSFSheet#getOddHeader()
* @param headerFooter
*/
protected XSSFOddHeader(CTHeaderFooter headerFooter) {
super(headerFooter);

View File

@ -46,7 +46,7 @@ import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTPictureNo
public final class XSSFPicture extends XSSFShape implements Picture {
private static final Logger LOG = LogManager.getLogger(XSSFPicture.class);
/**
/*
* Column width measured as the number of characters of the maximum digit width of the
* numbers 0, 1, 2, ..., 9 as rendered in the normal style's font. There are 4 pixels of margin
* padding (two on each side), plus 1 pixel padding for the gridlines.
@ -63,7 +63,7 @@ public final class XSSFPicture extends XSSFShape implements Picture {
/**
* This object specifies a picture object and all its properties
*/
private CTPicture ctPicture;
private final CTPicture ctPicture;
/**
* Construct a new XSSFPicture object. This constructor is called from
@ -140,6 +140,7 @@ public final class XSSFPicture extends XSSFShape implements Picture {
*
* @see #resize(double, double)
*/
@Override
public void resize(){
resize(Double.MAX_VALUE);
}
@ -149,6 +150,7 @@ public final class XSSFPicture extends XSSFShape implements Picture {
*
* @see #resize(double, double)
*/
@Override
public void resize(double scale) {
resize(scale, scale);
}
@ -159,19 +161,18 @@ public final class XSSFPicture extends XSSFShape implements Picture {
* Please note, that this method works correctly only for workbooks
* with the default font size (Calibri 11pt for .xlsx).
* If the default font is changed the resized image can be streched vertically or horizontally.
* </p>
* <p>
* <code>resize(1.0,1.0)</code> keeps the original size,<br>
* <code>resize(0.5,0.5)</code> resize to 50% of the original,<br>
* <code>resize(2.0,2.0)</code> resizes to 200% of the original.<br>
* {@code resize(1.0,1.0)} keeps the original size,<br>
* {@code resize(0.5,0.5)} resize to 50% of the original,<br>
* {@code resize(2.0,2.0)} resizes to 200% of the original.<br>
* <code>resize({@link Double#MAX_VALUE},{@link Double#MAX_VALUE})</code> resizes to the dimension of the embedded image.
* </p>
*
* @param scaleX the amount by which the image width is multiplied relative to the original width,
* when set to {@link Double#MAX_VALUE} the width of the embedded image is used
* @param scaleY the amount by which the image height is multiplied relative to the original height,
* when set to {@link Double#MAX_VALUE} the height of the embedded image is used
*/
@Override
public void resize(double scaleX, double scaleY){
XSSFClientAnchor anchor = getClientAnchor();
XSSFClientAnchor pref = getPreferredSize(scaleX,scaleY);
@ -197,6 +198,7 @@ public final class XSSFPicture extends XSSFShape implements Picture {
*
* @return XSSFClientAnchor with the preferred size for this image
*/
@Override
public XSSFClientAnchor getPreferredSize(){
return getPreferredSize(1);
}
@ -218,6 +220,7 @@ public final class XSSFPicture extends XSSFShape implements Picture {
* @param scaleY the amount by which image height is multiplied relative to the original height.
* @return XSSFClientAnchor with the preferred size for this image
*/
@Override
public XSSFClientAnchor getPreferredSize(double scaleX, double scaleY){
Dimension dim = ImageUtils.setPreferredSize(this, scaleX, scaleY);
CTPositiveSize2D size2d = ctPicture.getSpPr().getXfrm().getExt();
@ -250,6 +253,7 @@ public final class XSSFPicture extends XSSFShape implements Picture {
*
* @return image dimension in pixels
*/
@Override
public Dimension getImageDimension() {
XSSFPictureData picData = getPictureData();
return getImageDimension(picData.getPackagePart(), picData.getPictureType());
@ -260,11 +264,13 @@ public final class XSSFPicture extends XSSFShape implements Picture {
*
* @return picture data for this shape
*/
@Override
public XSSFPictureData getPictureData() {
String blipId = ctPicture.getBlipFill().getBlip().getEmbed();
return (XSSFPictureData)getDrawing().getRelationById(blipId);
}
@Override
protected CTShapeProperties getShapeProperties(){
return ctPicture.getSpPr();
}

View File

@ -125,8 +125,6 @@ public abstract class XSSFShape implements Shape {
/**
* Sets the line style.
*
* @param lineStyle
*/
public void setLineStyle( int lineStyle ) {
CTShapeProperties props = getShapeProperties();

View File

@ -32,14 +32,12 @@ import java.util.Locale;
import org.apache.poi.ooxml.POIXMLDocumentPart;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.DataFormatter;
import org.apache.poi.ss.usermodel.Table;
import org.apache.poi.ss.usermodel.TableStyleInfo;
import org.apache.poi.ss.util.AreaReference;
import org.apache.poi.ss.util.CellReference;
import org.apache.poi.util.Internal;
import org.apache.poi.util.Removal;
import org.apache.poi.util.StringUtil;
import org.apache.poi.xssf.usermodel.helpers.XSSFXmlColumnPr;
import org.apache.xmlbeans.XmlException;
@ -358,6 +356,7 @@ public class XSSFTable extends POIXMLDocumentPart implements Table {
/**
* @return the name of the Table, if set
*/
@Override
public String getName() {
if (name == null && ctTable.getName() != null) {
setName(ctTable.getName());
@ -383,6 +382,7 @@ public class XSSFTable extends POIXMLDocumentPart implements Table {
* @return the table style name, if set
* @since 3.17 beta 1
*/
@Override
public String getStyleName() {
if (styleName == null && ctTable.isSetTableStyleInfo()) {
setStyleName(ctTable.getTableStyleInfo().getName());
@ -628,7 +628,7 @@ public class XSSFTable extends POIXMLDocumentPart implements Table {
* and {@link #getEndCellReference()}.
* The next call to {@link #getStartCellReference()} and
* {@link #getEndCellReference()} will synchronize the
* cell references with the underlying <code>CTTable</code>.
* cell references with the underlying {@code CTTable}.
* Thus this method is inexpensive.
*
* @since POI 3.15 beta 3
@ -645,7 +645,7 @@ public class XSSFTable extends POIXMLDocumentPart implements Table {
* {@linkplain #getTotalsRowCount() totals rows}. (Note: in this version
* autofiltering is ignored)
*
* Returns <code>0</code> if the start or end cell references are not set.
* Returns {@code 0} if the start or end cell references are not set.
*
* Does not track updates to underlying changes to CTTable To synchronize
* with changes to the underlying CTTable, call {@link #updateReferences()}.
@ -667,7 +667,7 @@ public class XSSFTable extends POIXMLDocumentPart implements Table {
* Get the number of data rows in this table. This does not include any
* header rows or totals rows.
*
* Returns <code>0</code> if the start or end cell references are not set.
* Returns {@code 0} if the start or end cell references are not set.
*
* Does not track updates to underlying changes to CTTable To synchronize
* with changes to the underlying CTTable, call {@link #updateReferences()}.
@ -821,9 +821,9 @@ public class XSSFTable extends POIXMLDocumentPart implements Table {
}
/**
* Gets the relative column index of a column in this table having the header name <code>column</code>.
* Gets the relative column index of a column in this table having the header name {@code column}.
* The column index is relative to the left-most column in the table, 0-indexed.
* Returns <code>-1</code> if <code>column</code> is not a header name in table.
* Returns {@code -1} if {@code column} is not a header name in table.
*
* Column Header names are case-insensitive
*
@ -832,6 +832,7 @@ public class XSSFTable extends POIXMLDocumentPart implements Table {
*
* @since 3.15 beta 2
*/
@Override
public int findColumnIndex(String columnHeader) {
if (columnHeader == null) return -1;
if (columnMap == null) {
@ -849,12 +850,13 @@ public class XSSFTable extends POIXMLDocumentPart implements Table {
// Table column names with special characters need a single quote escape
// but the escape is not present in the column definition
Integer idx = columnMap.get(caseInsensitive(columnHeader.replace("'", "")));
return idx == null ? -1 : idx.intValue();
return idx == null ? -1 : idx;
}
/**
* @since 3.15 beta 2
*/
@Override
public String getSheetName() {
return getXSSFSheet().getSheetName();
}
@ -866,6 +868,7 @@ public class XSSFTable extends POIXMLDocumentPart implements Table {
* @since 3.15 beta 2
* @see #getTotalsRowCount()
*/
@Override
public boolean isHasTotalsRow() {
return ctTable.getTotalsRowShown();
}
@ -876,6 +879,7 @@ public class XSSFTable extends POIXMLDocumentPart implements Table {
* doesn't define how they would be implemented.
* @since 3.17 beta 1
*/
@Override
public int getTotalsRowCount() {
return (int) ctTable.getTotalsRowCount();
}
@ -885,6 +889,7 @@ public class XSSFTable extends POIXMLDocumentPart implements Table {
* Values &gt; 1 might be used by Excel for pivot tables?
* @since 3.17 beta 1
*/
@Override
public int getHeaderRowCount() {
return (int) ctTable.getHeaderRowCount();
}
@ -892,6 +897,7 @@ public class XSSFTable extends POIXMLDocumentPart implements Table {
/**
* @since 3.15 beta 2
*/
@Override
public int getStartColIndex() {
return getStartCellReference().getCol();
}
@ -899,6 +905,7 @@ public class XSSFTable extends POIXMLDocumentPart implements Table {
/**
* @since 3.15 beta 2
*/
@Override
public int getStartRowIndex() {
return getStartCellReference().getRow();
}
@ -906,6 +913,7 @@ public class XSSFTable extends POIXMLDocumentPart implements Table {
/**
* @since 3.15 beta 2
*/
@Override
public int getEndColIndex() {
return getEndCellReference().getCol();
}
@ -913,6 +921,7 @@ public class XSSFTable extends POIXMLDocumentPart implements Table {
/**
* @since 3.15 beta 2
*/
@Override
public int getEndRowIndex() {
return getEndCellReference().getRow();
}
@ -920,6 +929,7 @@ public class XSSFTable extends POIXMLDocumentPart implements Table {
/**
* @since 3.17 beta 1
*/
@Override
public TableStyleInfo getStyle() {
if (! ctTable.isSetTableStyleInfo()) return null;
return new XSSFTableStyleInfo(((XSSFSheet) getParent()).getWorkbook().getStylesSource(), ctTable.getTableStyleInfo());
@ -929,18 +939,16 @@ public class XSSFTable extends POIXMLDocumentPart implements Table {
* @see org.apache.poi.ss.usermodel.Table#contains(org.apache.poi.ss.usermodel.Cell)
* @since 3.17 beta 1
*/
@Override
public boolean contains(CellReference cell) {
if (cell == null) return false;
// check if cell is on the same sheet as the table
if ( ! getSheetName().equals(cell.getSheetName())) return false;
// check if the cell is inside the table
if (cell.getRow() >= getStartRowIndex()
return cell.getRow() >= getStartRowIndex()
&& cell.getRow() <= getEndRowIndex()
&& cell.getCol() >= getStartColIndex()
&& cell.getCol() <= getEndColIndex()) {
return true;
}
return false;
&& cell.getCol() <= getEndColIndex();
}
/**

View File

@ -49,8 +49,6 @@ public class XSSFTableStyle implements TableStyle {
/**
* @param index style definition index or built-in ordinal depending on use
* @param dxfs
* @param tableStyle
* @param colorMap indexed color map - default or custom
* @see TableStyle#getIndex()
*/
@ -99,10 +97,12 @@ public class XSSFTableStyle implements TableStyle {
}
}
@Override
public String getName() {
return name;
}
@Override
public int getIndex() {
return index;
}
@ -110,10 +110,12 @@ public class XSSFTableStyle implements TableStyle {
/**
* Always false for these, these are user defined styles
*/
@Override
public boolean isBuiltin() {
return false;
}
@Override
public DifferentialStyleProvider getStyle(TableStyleType type) {
return elementMap.get(type);
}

View File

@ -34,10 +34,6 @@ public class XSSFTableStyleInfo implements TableStyleInfo {
private boolean firstColumn;
private boolean lastColumn;
/**
* @param stylesTable
* @param tableStyleInfo
*/
public XSSFTableStyleInfo(StylesTable stylesTable, CTTableStyleInfo tableStyleInfo) {
this.columnStripes = tableStyleInfo.getShowColumnStripes();
this.rowStripes = tableStyleInfo.getShowRowStripes();
@ -48,6 +44,7 @@ public class XSSFTableStyleInfo implements TableStyleInfo {
this.styleInfo = tableStyleInfo;
}
@Override
public boolean isShowColumnStripes() {
return columnStripes;
}
@ -56,6 +53,7 @@ public class XSSFTableStyleInfo implements TableStyleInfo {
styleInfo.setShowColumnStripes(show);
}
@Override
public boolean isShowRowStripes() {
return rowStripes;
}
@ -64,6 +62,7 @@ public class XSSFTableStyleInfo implements TableStyleInfo {
styleInfo.setShowRowStripes(show);
}
@Override
public boolean isShowFirstColumn() {
return firstColumn;
}
@ -72,6 +71,7 @@ public class XSSFTableStyleInfo implements TableStyleInfo {
styleInfo.setShowFirstColumn(showFirstColumn);
}
@Override
public boolean isShowLastColumn() {
return lastColumn;
}
@ -80,6 +80,7 @@ public class XSSFTableStyleInfo implements TableStyleInfo {
styleInfo.setShowLastColumn(showLastColumn);
}
@Override
public String getName() {
return style.getName();
}
@ -88,6 +89,7 @@ public class XSSFTableStyleInfo implements TableStyleInfo {
style = stylesTable.getTableStyle(name);
}
@Override
public TableStyle getStyle() {
return style;
}

View File

@ -91,7 +91,7 @@ public class XSSFTextRun {
/**
*
* @param fontSize font size in points.
* The value of <code>-1</code> unsets the Sz attribute from the underlying xml bean
* The value of {@code -1} unsets the Sz attribute from the underlying xml bean
*/
public void setFontSize(double fontSize){
CTTextCharacterProperties rPr = getRPr();
@ -158,7 +158,7 @@ public class XSSFTextRun {
* Specifies the typeface, or name of the font that is to be used for this text run.
*
* @param typeface the font to apply to this text run.
* The value of <code>null</code> unsets the Typeface attribute from the underlying xml.
* The value of {@code null} unsets the Typeface attribute from the underlying xml.
*/
public void setFont(String typeface){
setFontFamily(typeface, (byte)-1, (byte)-1, false);
@ -241,9 +241,6 @@ public class XSSFTextRun {
* <p>
* The size is specified using a percentage.
* Positive values indicate superscript, negative values indicate subscript.
* </p>
*
* @param baselineOffset
*/
public void setBaselineOffset(double baselineOffset){
getRPr().setBaseline((int) baselineOffset * 1000);

View File

@ -45,6 +45,7 @@ public class XSSFVBAPart extends POIXMLDocumentPart {
* directly without keeping a copy like all others therefore we need to
* handle them differently.
*/
@Override
protected void prepareForCommit() {
// do not clear the part here
}

View File

@ -121,15 +121,13 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHeaderFooter;
*
*/
public abstract class XSSFHeaderFooter implements HeaderFooter {
private HeaderFooterHelper helper;
private CTHeaderFooter headerFooter;
private final HeaderFooterHelper helper;
private final CTHeaderFooter headerFooter;
private boolean stripFields;
/**
* Create an instance of XSSFAbstractHeaderFooter from the supplied XML bean
*
* @param headerFooter
*/
public XSSFHeaderFooter(CTHeaderFooter headerFooter) {
this.headerFooter = headerFooter;
@ -160,7 +158,7 @@ public abstract class XSSFHeaderFooter implements HeaderFooter {
/**
* Are fields currently being stripped from the text that this
* {@link XSSFHeaderFooter} returns? Default is false, but can be changed
* XSSFHeaderFooter returns? Default is false, but can be changed
*/
public boolean areFieldsStripped() {
return stripFields;
@ -169,8 +167,6 @@ public abstract class XSSFHeaderFooter implements HeaderFooter {
/**
* Should fields (eg macros) be stripped from the text that this class
* returns? Default is not to strip.
*
* @param stripFields
*/
public void setAreFieldsStripped(boolean stripFields) {
this.stripFields = stripFields;

View File

@ -19,7 +19,6 @@
package org.apache.poi.xssf.usermodel.helpers;
import java.util.Iterator;
import java.util.List;
import org.apache.poi.ooxml.POIXMLDocumentPart;
@ -59,11 +58,9 @@ public final class XSSFFormulaUtils {
* Update sheet name in all charts, formulas and named ranges.
* Called from {@link XSSFWorkbook#setSheetName(int, String)}
* <p>
* <p>
* The idea is to parse every formula and render it back to string
* with the updated sheet name. This is done by parsing into Ptgs,
* looking for ones with sheet references in them, and changing those
* </p>
*
* @param sheetIndex the 0-based index of the sheet being changed
* @param oldName the old sheet name
@ -93,9 +90,7 @@ public final class XSSFFormulaUtils {
for (POIXMLDocumentPart r : rels) {
if (r instanceof XSSFDrawing) {
XSSFDrawing dg = (XSSFDrawing) r;
Iterator<XSSFChart> it = dg.getCharts().iterator();
while (it.hasNext()) {
XSSFChart chart = it.next();
for (XSSFChart chart : dg.getCharts()) {
Node dom = chart.getCTChartSpace().getDomNode();
updateDomSheetReference(dom, oldName, newName);
}

View File

@ -41,7 +41,7 @@ public interface IBody {
*
* @return the Part, to which the body belongs
*/
public POIXMLDocumentPart getPart();
POIXMLDocumentPart getPart();
/**
* get the PartType of the body, for example
@ -49,26 +49,26 @@ public interface IBody {
*
* @return the PartType of the body
*/
public BodyType getPartType();
BodyType getPartType();
/**
* Returns an Iterator with paragraphs and tables,
* in the order that they occur in the text.
*/
public List<IBodyElement> getBodyElements();
List<IBodyElement> getBodyElements();
/**
* Returns the paragraph(s) that holds
* the text of the header or footer.
*/
public List<XWPFParagraph> getParagraphs();
List<XWPFParagraph> getParagraphs();
/**
* Return the table(s) that holds the text
* of the IBodyPart, for complex cases
* where a paragraph isn't used.
*/
public List<XWPFTable> getTables();
List<XWPFTable> getTables();
/**
* Returns the paragraph corresponding to the provided {@link CTP}.
@ -77,58 +77,47 @@ public interface IBody {
* @return The paragraph corresponding to the {@link CTP}, or {@code null} if there is no corresponding paragraph in
* this body.
*/
public XWPFParagraph getParagraph(CTP p);
XWPFParagraph getParagraph(CTP p);
/**
* if there is a corresponding {@link XWPFTable} of the parameter ctTable in the tableList of this header
* the method will return this table
* if there is no corresponding {@link XWPFTable} the method will return null
*
* @param ctTable
*/
public XWPFTable getTable(CTTbl ctTable);
XWPFTable getTable(CTTbl ctTable);
/**
* Returns the paragraph that of position pos
*/
public XWPFParagraph getParagraphArray(int pos);
XWPFParagraph getParagraphArray(int pos);
/**
* Returns the table at position pos
*/
public XWPFTable getTableArray(int pos);
XWPFTable getTableArray(int pos);
/**
* inserts a new paragraph at position of the cursor
*
* @param cursor
*/
public XWPFParagraph insertNewParagraph(XmlCursor cursor);
XWPFParagraph insertNewParagraph(XmlCursor cursor);
/**
* inserts a new Table at the cursor position.
*
* @param cursor
*/
public XWPFTable insertNewTbl(XmlCursor cursor);
XWPFTable insertNewTbl(XmlCursor cursor);
/**
* inserts a new Table at position pos
*
* @param pos
* @param table
*/
void insertTable(int pos, XWPFTable table);
/**
* returns the TableCell to which the Table belongs
*
* @param cell
*/
public XWPFTableCell getTableCell(CTTc cell);
XWPFTableCell getTableCell(CTTc cell);
/**
* Return XWPFDocument
*/
public XWPFDocument getXWPFDocument();
XWPFDocument getXWPFDocument();
}

View File

@ -17,18 +17,17 @@
package org.apache.poi.xwpf.usermodel;
import org.apache.poi.util.Beta;
/**
* Experimental interface to offer rudimentary read-only processing of
* of the contentblock of an SDT/ContentControl.
* <p>
* <p>
* <p>
* WARNING - APIs expected to change rapidly
*/
@Beta
public interface ISDTContent {
public String getText();
String getText();
public String toString();
String toString();
}

View File

@ -68,7 +68,7 @@ public class XWPFChart extends XDDFChart {
* Construct a chart from a package part.
*
* @param part the package part holding the chart data,
* the content type must be <code>application/vnd.openxmlformats-officedocument.drawingml.chart+xml</code>
* the content type must be {@code application/vnd.openxmlformats-officedocument.drawingml.chart+xml}
* @since POI 4.0.0
*/
protected XWPFChart(PackagePart part) throws IOException, XmlException {
@ -105,30 +105,7 @@ public class XWPFChart extends XDDFChart {
@Override
public boolean equals(Object obj) {
/**
* In case two objects ARE equal, but its not the same instance, this
* implementation will always run through the whole
* byte-array-comparison before returning true. If this will turn into a
* performance issue, two possible approaches are available:<br>
* a) Use the checksum only and take the risk that two images might have
* the same CRC32 sum, although they are not the same.<br>
* b) Use a second (or third) checksum algorithm to minimise the chance
* that two images have the same checksums but are not equal (e.g.
* CRC32, MD5 and SHA-1 checksums, additionally compare the
* data-byte-array lengths).
*/
if (obj == this) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof XWPFChart)) {
return false;
}
return false;
return obj == this;
}
@Override
@ -141,8 +118,6 @@ public class XWPFChart extends XDDFChart {
*
* @param chartRelId the relation id of this chart in its parent document.
* @param run the text run to which this chart will be inlined.
* @throws InvalidFormatException
* @throws IOException
* @since POI 4.0.0
*/
protected void attach(String chartRelId, XWPFRun run)
@ -215,7 +190,6 @@ public class XWPFChart extends XDDFChart {
/**
* get margin from Top
*
* @param margin
* @since POI 4.0.0
*/
public long getChartTopMargin(long margin) {
@ -235,7 +209,6 @@ public class XWPFChart extends XDDFChart {
/**
* get margin from Bottom
*
* @param margin
* @since POI 4.0.0
*/
public long getChartBottomMargin(long margin) {
@ -255,7 +228,6 @@ public class XWPFChart extends XDDFChart {
/**
* get margin from left
*
* @param margin
* @since POI 4.0.0
*/
public long getChartLeftMargin(long margin) {
@ -275,7 +247,6 @@ public class XWPFChart extends XDDFChart {
/**
* get margin from Right
*
* @param margin
* @since POI 4.0.0
*/
public long getChartRightMargin(long margin) {

View File

@ -47,8 +47,8 @@ import static org.apache.poi.ooxml.POIXMLTypeLoader.DEFAULT_XML_OPTIONS;
public class XWPFComments extends POIXMLDocumentPart {
XWPFDocument document;
private List<XWPFComment> comments = new ArrayList<>();
private List<XWPFPictureData> pictures = new ArrayList<>();
private final List<XWPFComment> comments = new ArrayList<>();
private final List<XWPFPictureData> pictures = new ArrayList<>();
private CTComments ctComments;
/**
@ -192,8 +192,6 @@ public class XWPFComments extends POIXMLDocumentPart {
/**
* Get the list of {@link XWPFComment} in the Comments part.
*
* @return
*/
public List<XWPFComment> getComments() {
return comments;
@ -203,7 +201,6 @@ public class XWPFComments extends POIXMLDocumentPart {
* Get the specified comment by position
*
* @param pos Array position of the comment
* @return
*/
public XWPFComment getComment(int pos) {
if (pos >= 0 && pos < ctComments.sizeOfCommentArray()) {
@ -229,14 +226,11 @@ public class XWPFComments extends POIXMLDocumentPart {
/**
* Get the specified comment by ctComment
*
* @param ctComment
* @return
*/
public XWPFComment getComment(CTComment ctComment) {
for (int i = 0; i < comments.size(); i++) {
if (comments.get(i).getCtComment() == ctComment) {
return comments.get(i);
for (XWPFComment comment : comments) {
if (comment.getCtComment() == ctComment) {
return comment;
}
}
return null;
@ -246,7 +240,6 @@ public class XWPFComments extends POIXMLDocumentPart {
* Create a new comment and add it to the document.
*
* @param cid comment Id
* @return
*/
public XWPFComment createComment(BigInteger cid) {
CTComment ctComment = ctComments.addNewComment();

View File

@ -89,7 +89,7 @@ public class XWPFFooter extends XWPFHeaderFooter {
@Override
protected void onDocumentRead() throws IOException {
super.onDocumentRead();
FtrDocument ftrDocument = null;
FtrDocument ftrDocument;
try (InputStream is = getPackagePart().getInputStream()) {
ftrDocument = FtrDocument.Factory.parse(is, DEFAULT_XML_OPTIONS);
headerFooter = ftrDocument.getFtr();
@ -125,6 +125,7 @@ public class XWPFFooter extends XWPFHeaderFooter {
*
* @see org.apache.poi.xwpf.usermodel.IBody#getPartType()
*/
@Override
public BodyType getPartType() {
return BodyType.FOOTER;
}

View File

@ -86,13 +86,11 @@ public class XWPFHeader extends XWPFHeaderFooter {
/**
* reads the document
*
* @throws IOException
*/
@Override
protected void onDocumentRead() throws IOException {
super.onDocumentRead();
HdrDocument hdrDocument = null;
HdrDocument hdrDocument;
try (InputStream is = getPackagePart().getInputStream()) {
hdrDocument = HdrDocument.Factory.parse(is, DEFAULT_XML_OPTIONS);
headerFooter = hdrDocument.getHdr();
@ -128,6 +126,7 @@ public class XWPFHeader extends XWPFHeaderFooter {
*
* @see org.apache.poi.xwpf.usermodel.IBody#getPartType()
*/
@Override
public BodyType getPartType() {
return BodyType.HEADER;
}

View File

@ -68,7 +68,7 @@ public class XWPFNumbering extends POIXMLDocumentPart {
*/
@Override
protected void onDocumentRead() throws IOException {
NumberingDocument numberingDoc = null;
NumberingDocument numberingDoc;
InputStream is;
is = getPackagePart().getInputStream();
try {
@ -105,8 +105,6 @@ public class XWPFNumbering extends POIXMLDocumentPart {
/**
* Sets the ctNumbering
*
* @param numbering
*/
public void setNumbering(CTNumbering numbering) {
ctNumbering = numbering;
@ -116,7 +114,6 @@ public class XWPFNumbering extends POIXMLDocumentPart {
/**
* Checks whether number with numID exists
*
* @param numID
* @return boolean true if num exist, false if num not exist
*/
public boolean numExist(BigInteger numID) {
@ -129,8 +126,6 @@ public class XWPFNumbering extends POIXMLDocumentPart {
/**
* add a new number to the numbering document
*
* @param num
*/
public BigInteger addNum(XWPFNum num) {
ctNumbering.addNewNum();
@ -157,9 +152,6 @@ public class XWPFNumbering extends POIXMLDocumentPart {
/**
* Add a new num with an abstractNumID and a numID
*
* @param abstractNumID
* @param numID
*/
public void addNum(BigInteger abstractNumID, BigInteger numID) {
CTNum ctNum = this.ctNumbering.addNewNum();
@ -173,7 +165,6 @@ public class XWPFNumbering extends POIXMLDocumentPart {
/**
* get Num by NumID
*
* @param numID
* @return abstractNum with NumId if no Num exists with that NumID
* null will be returned
*/
@ -188,7 +179,6 @@ public class XWPFNumbering extends POIXMLDocumentPart {
/**
* get AbstractNum by abstractNumID
*
* @param abstractNumID
* @return abstractNum with abstractNumId if no abstractNum exists with that abstractNumID
* null will be returned
*/
@ -207,7 +197,6 @@ public class XWPFNumbering extends POIXMLDocumentPart {
* the BigInteger Value of it will be returned.
* If no equal abstractNum is existing null will be returned
*
* @param abstractNum
* @return BigInteger
*/
public BigInteger getIdOfAbstractNum(XWPFAbstractNum abstractNum) {
@ -227,8 +216,6 @@ public class XWPFNumbering extends POIXMLDocumentPart {
/**
* add a new AbstractNum and return its AbstractNumID
*
* @param abstractNum
*/
public BigInteger addAbstractNum(XWPFAbstractNum abstractNum) {
int pos = abstractNums.size();
@ -246,7 +233,6 @@ public class XWPFNumbering extends POIXMLDocumentPart {
/**
* remove an existing abstractNum
*
* @param abstractNumID
* @return true if abstractNum with abstractNumID exists in NumberingArray,
* false if abstractNum with abstractNumID not exists
*/
@ -268,7 +254,6 @@ public class XWPFNumbering extends POIXMLDocumentPart {
* If the AbstractNumID not exists
* return null
*
* @param numID
* @return abstractNumID
*/
public BigInteger getAbstractNumID(BigInteger numID) {

View File

@ -25,9 +25,9 @@ import org.openxmlformats.schemas.drawingml.x2006.picture.CTPicture;
public class XWPFPicture {
private CTPicture ctPic;
private String description;
private XWPFRun run;
private final CTPicture ctPic;
private final String description;
private final XWPFRun run;
public XWPFPicture(CTPicture ctPic, XWPFRun run) {
this.run = run;
@ -37,8 +37,6 @@ public class XWPFPicture {
/**
* Link Picture with PictureData
*
* @param rel
*/
public void setPictureReference(PackageRelationship rel) {
ctPic.getBlipFill().getBlip().setEmbed(rel.getId());

View File

@ -19,6 +19,7 @@ package org.apache.poi.xwpf.usermodel;
import java.util.ArrayList;
import java.util.List;
import org.apache.poi.util.Beta;
import org.apache.xmlbeans.XmlCursor;
import org.apache.xmlbeans.XmlObject;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.*;
@ -26,11 +27,8 @@ import org.openxmlformats.schemas.wordprocessingml.x2006.main.*;
/**
* Experimental class to offer rudimentary read-only processing of
* of the contentblock of an SDT/ContentControl.
* <p>
* <p>
* <p>
* WARNING - APIs expected to change rapidly
*/
@Beta
public class XWPFSDTContent implements ISDTContent {
// private final IBody part;
@ -39,7 +37,7 @@ public class XWPFSDTContent implements ISDTContent {
// private List<XWPFTable> tables = new ArrayList<>();
// private List<XWPFRun> runs = new ArrayList<>();
// private List<XWPFSDT> contentControls = new ArrayList<>();
private List<ISDTContents> bodyElements = new ArrayList<>();
private final List<ISDTContents> bodyElements = new ArrayList<>();
public XWPFSDTContent(CTSdtContentRun sdtRun, IBody part, IRunBody parent) {
if (sdtRun == null) {

View File

@ -25,21 +25,10 @@ public class XWPFStyle {
protected XWPFStyles styles;
private CTStyle ctStyle;
/**
* constructor
*
* @param style
*/
public XWPFStyle(CTStyle style) {
this(style, null);
}
/**
* constructor
*
* @param style
* @param styles
*/
public XWPFStyle(CTStyle style, XWPFStyles styles) {
this.ctStyle = style;
this.styles = styles;
@ -56,8 +45,6 @@ public class XWPFStyle {
/**
* set styleID
*
* @param styleId
*/
public void setStyleId(String styleId) {
ctStyle.setStyleId(styleId);
@ -74,8 +61,6 @@ public class XWPFStyle {
/**
* set styleType
*
* @param type
*/
public void setType(STStyleType.Enum type) {
ctStyle.setType(type);
@ -83,8 +68,6 @@ public class XWPFStyle {
/**
* set style
*
* @param style
*/
public void setStyle(CTStyle style) {
this.ctStyle = style;
@ -144,8 +127,6 @@ public class XWPFStyle {
/**
* compares the names of the Styles
*
* @param compStyle
*/
public boolean hasSameName(XWPFStyle compStyle) {
CTStyle ctCompStyle = compStyle.getCTStyle();
@ -153,4 +134,4 @@ public class XWPFStyle {
return name.equals(ctStyle.getName().getVal());
}
}//end class
}

View File

@ -141,7 +141,7 @@ public class XWPFTable implements IBodyElement, ISDTContents {
// Unused: UUF_UNUSED_PUBLIC_OR_PROTECTED_FIELD
//protected List<String> styleIDs;
protected IBody part;
private CTTbl ctTbl;
private final CTTbl ctTbl;
public XWPFTable(CTTbl table, IBody part, int row, int col) {
this(table, part);
@ -243,8 +243,8 @@ public class XWPFTable implements IBodyElement, ISDTContents {
if (tableRows.size() == 0) {
createRow();
}
for (int i = 0; i < tableRows.size(); i++) {
tableRows.get(i).createCell();
for (XWPFTableRow tableRow : tableRows) {
tableRow.createCell();
}
}
@ -1046,7 +1046,6 @@ public class XWPFTable implements IBodyElement, ISDTContents {
/**
* inserts a new tablerow
*
* @param pos
* @return the inserted row
*/
public XWPFTableRow insertNewTableRow(int pos) {
@ -1081,8 +1080,6 @@ public class XWPFTable implements IBodyElement, ISDTContents {
/**
* returns the type of the BodyElement Table
*
* @see org.apache.poi.xwpf.usermodel.IBodyElement#getElementType()
*/
@Override
public BodyElementType getElementType() {
@ -1195,14 +1192,12 @@ public class XWPFTable implements IBodyElement, ISDTContents {
switch (typeValue.intValue()) {
case STTblWidth.INT_NIL:
return TableWidthType.NIL;
case STTblWidth.INT_AUTO:
return TableWidthType.AUTO;
case STTblWidth.INT_DXA:
return TableWidthType.DXA;
case STTblWidth.INT_PCT:
return TableWidthType.PCT;
default:
// Should never get here
case STTblWidth.INT_AUTO:
return TableWidthType.AUTO;
}
}
@ -1284,11 +1279,9 @@ public class XWPFTable implements IBodyElement, ISDTContents {
if (!currentType.equals(widthType)) {
STTblWidth.Enum stWidthType = widthType.getStWidthType();
ctWidth.setType(stWidthType);
switch (stWidthType.intValue()) {
case STTblWidth.INT_PCT:
if (stWidthType.intValue() == STTblWidth.INT_PCT) {
setWidthPercentage(ctWidth, DEFAULT_PERCENTAGE_WIDTH);
break;
default:
} else {
ctWidth.setW(BigInteger.ZERO);
}
}

View File

@ -119,9 +119,8 @@ public class XWPFTableCell implements IBody, ICell {
/**
* returns an Iterator with paragraphs and tables
*
* @see org.apache.poi.xwpf.usermodel.IBody#getBodyElements()
*/
@Override
public List<IBodyElement> getBodyElements() {
return Collections.unmodifiableList(bodyElements);
}
@ -136,6 +135,7 @@ public class XWPFTableCell implements IBody, ICell {
/**
* returns a list of paragraphs
*/
@Override
public List<XWPFParagraph> getParagraphs() {
return Collections.unmodifiableList(paragraphs);
}
@ -221,7 +221,7 @@ public class XWPFTableCell implements IBody, ICell {
/**
* Get the vertical alignment of the cell.
*
* @return the cell alignment enum value or <code>null</code>
* @return the cell alignment enum value or {@code null}
* if no vertical alignment is set.
*/
public XWPFVertAlign getVerticalAlignment() {
@ -253,6 +253,7 @@ public class XWPFTableCell implements IBody, ICell {
* @param cursor The XmlCursor structure created with XmlBeans
* @return the inserted paragraph
*/
@Override
public XWPFParagraph insertNewParagraph(final XmlCursor cursor) {
if (!isCursorInTableCell(cursor)) {
return null;
@ -291,6 +292,7 @@ public class XWPFTableCell implements IBody, ICell {
return newP;
}
@Override
public XWPFTable insertNewTbl(final XmlCursor cursor) {
if (isCursorInTableCell(cursor)) {
String uri = CTTbl.type.getName().getNamespaceURI();
@ -339,9 +341,7 @@ public class XWPFTableCell implements IBody, ICell {
return result;
}
/**
* @see org.apache.poi.xwpf.usermodel.IBody#getParagraphArray(int)
*/
@Override
public XWPFParagraph getParagraphArray(int pos) {
if (pos >= 0 && pos < paragraphs.size()) {
return paragraphs.get(pos);
@ -351,25 +351,21 @@ public class XWPFTableCell implements IBody, ICell {
/**
* get the to which the TableCell belongs
*
* @see org.apache.poi.xwpf.usermodel.IBody#getPart()
*/
@Override
public POIXMLDocumentPart getPart() {
return tableRow.getTable().getPart();
}
/**
* @see org.apache.poi.xwpf.usermodel.IBody#getPartType()
*/
@Override
public BodyType getPartType() {
return BodyType.TABLECELL;
}
/**
* get a table by its CTTbl-Object
*
* @see org.apache.poi.xwpf.usermodel.IBody#getTable(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl)
*/
@Override
public XWPFTable getTable(CTTbl ctTable) {
for (int i = 0; i < tables.size(); i++) {
if (getTables().get(i).getCTTbl() == ctTable) return getTables().get(i);
@ -377,9 +373,7 @@ public class XWPFTableCell implements IBody, ICell {
return null;
}
/**
* @see org.apache.poi.xwpf.usermodel.IBody#getTableArray(int)
*/
@Override
public XWPFTable getTableArray(int pos) {
if(pos >= 0 && pos < tables.size()) {
return tables.get(pos);
@ -387,18 +381,15 @@ public class XWPFTableCell implements IBody, ICell {
return null;
}
/**
* @see org.apache.poi.xwpf.usermodel.IBody#getTables()
*/
@Override
public List<XWPFTable> getTables() {
return Collections.unmodifiableList(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)
*/
@Override
public void insertTable(int pos, XWPFTable table) {
bodyElements.add(pos, table);
int i = 0;
@ -482,6 +473,7 @@ public class XWPFTableCell implements IBody, ICell {
/**
* get the TableCell which belongs to the TableCell
*/
@Override
public XWPFTableCell getTableCell(CTTc cell) {
XmlCursor cursor = cell.newCursor();
cursor.toParent();
@ -508,6 +500,7 @@ public class XWPFTableCell implements IBody, ICell {
return tr.getTableCell(cell);
}
@Override
public XWPFDocument getXWPFDocument() {
return part.getXWPFDocument();
}

View File

@ -41,8 +41,8 @@ import org.openxmlformats.schemas.wordprocessingml.x2006.main.STHeightRule;
* the child {@link XWPFTableCell}s
*/
public class XWPFTableRow {
private CTRow ctRow;
private XWPFTable table;
private final CTRow ctRow;
private final XWPFTable table;
private List<XWPFTableCell> tableCells;
public XWPFTableRow(CTRow row, XWPFTable table) {
@ -123,8 +123,6 @@ public class XWPFTableRow {
* its attribute values). If omitted, then the table row shall automatically
* resize its height to the height required by its contents (the equivalent
* of an hRule value of auto).
*
* @param height
*/
public void setHeight(int height) {
CTTrPr properties = getTrPr();
@ -221,9 +219,9 @@ public class XWPFTableRow {
* if there is no XWPFTableCell which belongs to the parameter CTTc cell null will be returned
*/
public XWPFTableCell getTableCell(CTTc cell) {
for (int i = 0; i < tableCells.size(); i++) {
if (tableCells.get(i).getCTTc() == cell)
return tableCells.get(i);
for (XWPFTableCell tableCell : tableCells) {
if (tableCell.getCTTc() == cell)
return tableCell;
}
return null;
}

View File

@ -29,7 +29,7 @@ import org.junit.jupiter.api.Test;
class TestCombinedIterator {
void testIteration(CombinedIterable<String> iterable, String... expected) {
void testIteration(Iterable<String> iterable, String... expected) {
Iterator<String> iter = iterable.iterator();
@ -49,8 +49,7 @@ class TestCombinedIterator {
base.put(2L, "B2");
base.put(3L, "B3");
testIteration(new CombinedIterable<>(base, null), "B1", "B2",
"B3");
testIteration(createIter(base, null), "B1", "B2", "B3");
}
@Test
@ -66,8 +65,7 @@ class TestCombinedIterator {
master.put(5L, "M5");
master.put(6L, "M6");
testIteration(new CombinedIterable<>(base, master), "B1", "B2",
"B3", "M4", "M5", "M6");
testIteration(createIter(base, master), "B1", "B2", "B3", "M4", "M5", "M6");
}
@Test
@ -83,8 +81,7 @@ class TestCombinedIterator {
master.put(2L, "M2");
master.put(3L, "M3");
testIteration(new CombinedIterable<>(base, master), "M1", "M2",
"M3", "B4", "B5", "B6");
testIteration(createIter(base, master), "M1", "M2", "M3", "B4", "B5", "B6");
}
@Test
@ -100,8 +97,7 @@ class TestCombinedIterator {
master.put(4L, "M4");
master.put(6L, "M6");
testIteration(new CombinedIterable<>(base, master), "B1", "M2",
"B3", "M4", "B5", "M6");
testIteration(createIter(base, master), "B1", "M2", "B3", "M4", "B5", "M6");
}
@Test
@ -119,8 +115,7 @@ class TestCombinedIterator {
master.put(7L, "M7");
master.put(8L, "M8");
testIteration(new CombinedIterable<>(base, master), "B1", "B2",
"M3", "M4", "B5", "B6", "M7", "M8");
testIteration(createIter(base, master), "B1", "B2", "M3", "M4", "B5", "B6", "M7", "M8");
}
@Test
@ -136,8 +131,7 @@ class TestCombinedIterator {
master.put(2L, "M2");
master.put(3L, "M3");
testIteration(new CombinedIterable<>(base, master), "B1", "B2",
"B3");
testIteration(createIter(base, master), "B1", "B2", "B3");
}
@Test
@ -154,7 +148,12 @@ class TestCombinedIterator {
master.put(3L, "M3");
master.put(4L, "M4");
testIteration(new CombinedIterable<>(base, master), "B1", "B2",
"B3", "M4");
testIteration(createIter(base, master), "B1", "B2", "B3", "M4");
}
private static <T> Iterable<T> createIter(SortedMap<Long, T> map1, SortedMap<Long, T> map2) {
// TODO: try to use commons collection and remove CombinedIterable
return new CombinedIterable<>(map1, map2);
}
}

View File

@ -56,13 +56,6 @@ final Pattern MODULE_REGEX = ~'\\.jar$'
final List MAIN_MODULE_PATH = sourceSets.main.runtimeClasspath.findAll{ it.path =~ MODULE_REGEX }.collect{ it.parent }.unique()
final List TEST_MODULE_PATH = sourceSets.test.runtimeClasspath.findAll{ it.path =~ MODULE_REGEX && !(it.path =~ MODULE_NOT_REGEX) }.collect{ it.parent }.unique()
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
withJavadocJar()
withSourcesJar()
}
task compileJava9(type: JavaCompile) {
dependsOn 'compileJava', ':poi:jar'
@ -142,23 +135,9 @@ task testJar(type: Jar, dependsOn: testClasses) {
}
}
sourcesJar {
destinationDirectory = file("../build/dist/maven/${project.archivesBaseName}")
exclude 'META-INF/services/**'
}
javadoc {
failOnError = true
doFirst {
options {
if (JavaVersion.current().isJava9Compatible()) {
addBooleanOption('html5', true)
}
links 'https://poi.apache.org/apidocs/dev/'
links 'https://docs.oracle.com/javase/8/docs/api/'
use = true
splitIndex = true
source = "1.8"
classpath += configurations.javadocs.files
}
}
@ -171,39 +150,10 @@ artifacts {
test {
dependsOn { testJar }
useJUnitPlatform()
doFirst {
jvmArgs = [
'-Djava.io.tmpdir=build',
'-DPOI.testdata.path=../test-data',
'-Djava.awt.headless=true',
'-Djava.locale.providers=JRE,CLDR',
'-Duser.language=en',
'-Duser.country=US',
'-Djavax.xml.stream.XMLInputFactory=com.sun.xml.internal.stream.XMLInputFactoryImpl',
"-Dversion.id=${project.version}",
'-ea',
'-Djunit.jupiter.execution.parallel.enabled=true',
'-Djunit.jupiter.execution.parallel.config.strategy=fixed',
'-Djunit.jupiter.execution.parallel.config.fixed.parallelism=3'
// -Xjit:verbose={compileStart|compileEnd},vlog=build/jit.log${no.jit.sherlock} ... if ${isIBMVM}
]
if (JavaVersion.current() != JavaVersion.VERSION_1_8) {
jvmArgs += [
'-Dsun.reflect.debugModuleAccessChecks=true',
'-Dcom.sun.xml.bind.v2.bytecode.ClassTailor.noOptimize=true',
'--illegal-access=warn',
'--add-modules', MODULE_NAME,
// see https://github.com/java9-modularity/gradle-modules-plugin/issues/97
// opposed to the recommendation there, it doesn't work to add ... to the dependencies
// testRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.7.1'
// gradles gradle-worker.jar is still not a JPMS module and thus runs as unnamed module
'--add-exports','org.junit.platform.commons/org.junit.platform.commons.util=ALL-UNNAMED',
'--add-exports','org.junit.platform.commons/org.junit.platform.commons.logging=ALL-UNNAMED',
'--module-path', '../build/dist/maven/poi-scratchpad-tests:' + files(TEST_MODULE_PATH).asPath,
]
}
@ -213,10 +163,6 @@ test {
publishing {
publications {
POI(MavenPublication) {
artifactId project.archivesBaseName
from components.java
pom {
name = 'Apache POI'
description = 'Apache POI - Java API To Access Microsoft Format Files (Scratchpad)'
@ -224,5 +170,3 @@ publishing {
}
}
}
generatePomFileForPOIPublication.destination = "../build/dist/maven/${project.archivesBaseName}/${project.archivesBaseName}-${project.version}.pom"

View File

@ -55,7 +55,7 @@ import org.apache.poi.util.LittleEndian;
public final class QuickButCruddyTextExtractor {
private POIFSFileSystem fs;
private InputStream is;
private byte[] pptContents;
private final byte[] pptContents;
/**
* Really basic text extractor, that will also return lots of crud text.
@ -78,7 +78,6 @@ public final class QuickButCruddyTextExtractor {
/**
* Creates an extractor from a given file name
* @param fileName
*/
@SuppressWarnings("resource")
public QuickButCruddyTextExtractor(String fileName) throws IOException {
@ -87,7 +86,6 @@ public final class QuickButCruddyTextExtractor {
/**
* Creates an extractor from a given input stream
* @param iStream
*/
@SuppressWarnings("resource")
public QuickButCruddyTextExtractor(InputStream iStream) throws IOException {
@ -97,7 +95,6 @@ public final class QuickButCruddyTextExtractor {
/**
* Creates an extractor from a POIFS Filesystem
* @param poifs
*/
public QuickButCruddyTextExtractor(POIFSFileSystem poifs) throws IOException {
fs = poifs;
@ -192,9 +189,7 @@ public final class QuickButCruddyTextExtractor {
String text = cs.getText();
// Ignore the ones we know to be rubbish
if(text.equals("___PPT10")) {
} else if(text.equals("Default Design")) {
} else {
if (!"___PPT10".equals(text) && !"Default Design".equals(text)) {
textV.add(text);
}
}

View File

@ -46,7 +46,7 @@ public final class ActiveXShape extends HSLFPictureShape {
public static final int DEFAULT_ACTIVEX_THUMBNAIL = -1;
/**
* Create a new <code>Picture</code>
* Create a new {@code Picture}
*
* @param pictureData the picture data
*/
@ -56,10 +56,10 @@ public final class ActiveXShape extends HSLFPictureShape {
}
/**
* Create a <code>Picture</code> object
* Create a {@code Picture} object
*
* @param escherRecord the <code>EscherSpContainer</code> record which holds information about
* this picture in the <code>Slide</code>
* @param escherRecord the {@code EscherSpContainer} record which holds information about
* this picture in the {@code Slide}
* @param parent the parent shape of this picture
*/
protected ActiveXShape(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
@ -69,13 +69,14 @@ public final class ActiveXShape extends HSLFPictureShape {
/**
* Create a new Placeholder and initialize internal structures
*
* @return the created <code>EscherContainerRecord</code> which holds shape data
* @return the created {@code EscherContainerRecord} which holds shape data
*/
@Override
protected EscherContainerRecord createSpContainer(int idx, boolean isChild) {
EscherContainerRecord ecr = super.createSpContainer(idx, isChild);
EscherSpRecord spRecord = ecr.getChildById(EscherSpRecord.RECORD_ID);
assert(spRecord != null);
spRecord.setFlags(EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HASSHAPETYPE | EscherSpRecord.FLAG_OLESHAPE);
setShapeType(ShapeType.HOST_CONTROL);
@ -114,8 +115,6 @@ public final class ActiveXShape extends HSLFPictureShape {
/**
* Set a property of this ActiveX control
* @param key
* @param value
*/
public void setProperty(String key, String value){

View File

@ -40,7 +40,7 @@ public final class Polygon extends HSLFAutoShape {
/**
* Create a Polygon object and initialize it from the supplied Record container.
*
* @param escherRecord <code>EscherSpContainer</code> container which holds information about this shape
* @param escherRecord {@code EscherSpContainer} container which holds information about this shape
* @param parent the parent of the shape
*/
protected Polygon(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
@ -69,9 +69,6 @@ public final class Polygon extends HSLFAutoShape {
/**
* Set the polygon vertices
*
* @param xPoints
* @param yPoints
*/
public void setPoints(float[] xPoints, float[] yPoints)
{
@ -147,10 +144,9 @@ public final class Polygon extends HSLFAutoShape {
private float findBiggest( float[] values )
{
float result = Float.MIN_VALUE;
for ( int i = 0; i < values.length; i++ )
{
if (values[i] > result)
result = values[i];
for (float value : values) {
if (value > result)
result = value;
}
return result;
}
@ -158,10 +154,9 @@ public final class Polygon extends HSLFAutoShape {
private float findSmallest( float[] values )
{
float result = Float.MAX_VALUE;
for ( int i = 0; i < values.length; i++ )
{
if (values[i] < result)
result = values[i];
for (float value : values) {
if (value < result)
result = value;
}
return result;
}

View File

@ -37,9 +37,9 @@ import org.apache.poi.util.GenericRecordUtil;
public abstract class BitMaskTextProp extends TextProp {
protected static final Logger LOG = LogManager.getLogger(BitMaskTextProp.class);
private String[] subPropNames;
private int[] subPropMasks;
private boolean[] subPropMatches;
private final String[] subPropNames;
private final int[] subPropMasks;
private final boolean[] subPropMatches;
/** Fetch the list of the names of the sub properties */
public String[] getSubPropNames() { return subPropNames; }
@ -141,9 +141,6 @@ public abstract class BitMaskTextProp extends TextProp {
/**
* Convenience method to set a value with mask, without splitting it into the subvalues
*
* @param val
* @param writeMask
*/
public void setValueWithMask(int val, int writeMask) {
setWriteMask(writeMask);

View File

@ -64,7 +64,7 @@ public final class SlideListWithText extends RecordContainer {
*/
public static final int NOTES = 2;
private byte[] _header;
private final byte[] _header;
private SlideAtomsSet[] slideAtomsSets;
@ -124,7 +124,6 @@ public final class SlideListWithText extends RecordContainer {
/**
* Add a new SlidePersistAtom, to the end of the current list,
* and update the internal list of SlidePersistAtoms
* @param spa
*/
public void addSlidePersistAtom(SlidePersistAtom spa) {
// Add the new SlidePersistAtom at the end
@ -164,12 +163,14 @@ public final class SlideListWithText extends RecordContainer {
/**
* Return the value we were given at creation
*/
@Override
public long getRecordType() { return _type; }
/**
* Write the contents of the record back, so it can be written
* to disk
*/
@Override
public void writeOut(OutputStream out) throws IOException {
writeOut(_header[0],_header[1],_type,_children,out);
}
@ -182,8 +183,8 @@ public final class SlideListWithText extends RecordContainer {
* along with some others.
*/
public static class SlideAtomsSet {
private SlidePersistAtom slidePersistAtom;
private org.apache.poi.hslf.record.Record[] slideRecords;
private final SlidePersistAtom slidePersistAtom;
private final org.apache.poi.hslf.record.Record[] slideRecords;
/** Get the SlidePersistAtom, which gives details on the Slide this text is associated with */
public SlidePersistAtom getSlidePersistAtom() { return slidePersistAtom; }

View File

@ -30,6 +30,7 @@ public final class HSLFBackground extends HSLFShape implements Background<HSLFSh
super(escherRecord, parent);
}
@Override
protected EscherContainerRecord createSpContainer(boolean isChild) {
return null;
}

View File

@ -25,7 +25,7 @@ import java.awt.geom.Point2D;
import java.util.Date;
public final class HSLFComment implements Comment {
private Comment2000 _comment2000;
private final Comment2000 _comment2000;
public HSLFComment(Comment2000 comment2000) {
_comment2000 = comment2000;
@ -38,6 +38,7 @@ public final class HSLFComment implements Comment {
/**
* Get the Author of this comment
*/
@Override
public String getAuthor() {
return _comment2000.getAuthor();
}
@ -45,6 +46,7 @@ public final class HSLFComment implements Comment {
/**
* Set the Author of this comment
*/
@Override
public void setAuthor(String author) {
_comment2000.setAuthor(author);
}
@ -52,6 +54,7 @@ public final class HSLFComment implements Comment {
/**
* Get the Author's Initials of this comment
*/
@Override
public String getAuthorInitials() {
return _comment2000.getAuthorInitials();
}
@ -59,6 +62,7 @@ public final class HSLFComment implements Comment {
/**
* Set the Author's Initials of this comment
*/
@Override
public void setAuthorInitials(String initials) {
_comment2000.setAuthorInitials(initials);
}
@ -66,6 +70,7 @@ public final class HSLFComment implements Comment {
/**
* Get the text of this comment
*/
@Override
public String getText() {
return _comment2000.getText();
}
@ -73,6 +78,7 @@ public final class HSLFComment implements Comment {
/**
* Set the text of this comment
*/
@Override
public void setText(String text) {
_comment2000.setText(text);
}

View File

@ -55,18 +55,14 @@ import org.apache.poi.util.StringUtil;
import org.apache.poi.util.Units;
/**
* <p>
* Represents a Shape which is the elemental object that composes a drawing.
* This class is a wrapper around EscherSpContainer which holds all information
* about a shape in PowerPoint document.
* </p>
* <p>
* When you add a shape, you usually specify the dimensions of the shape and the position
* of the upper'left corner of the bounding box for the shape relative to the upper'left
* corner of the page, worksheet, or slide. Distances in the drawing layer are measured
* in points (72 points = 1 inch).
* </p>
* <p>
*/
public abstract class HSLFShape implements Shape<HSLFShape,HSLFTextParagraph> {
private static final Logger LOG = LogManager.getLogger(HSLFShape.class);
@ -79,12 +75,12 @@ public abstract class HSLFShape implements Shape<HSLFShape,HSLFTextParagraph> {
/**
* Parent of this shape.
* <code>null</code> for the topmost shapes.
* {@code null} for the topmost shapes.
*/
private ShapeContainer<HSLFShape,HSLFTextParagraph> _parent;
private final ShapeContainer<HSLFShape,HSLFTextParagraph> _parent;
/**
* The <code>Sheet</code> this shape belongs to
* The {@code Sheet} this shape belongs to
*/
private HSLFSheet _sheet;
@ -96,7 +92,7 @@ public abstract class HSLFShape implements Shape<HSLFShape,HSLFTextParagraph> {
/**
* Create a Shape object. This constructor is used when an existing Shape is read from from a PowerPoint document.
*
* @param escherRecord <code>EscherSpContainer</code> container which holds information about this shape
* @param escherRecord {@code EscherSpContainer} container which holds information about this shape
* @param parent the parent of this Shape
*/
protected HSLFShape(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
@ -233,7 +229,7 @@ public abstract class HSLFShape implements Shape<HSLFShape,HSLFTextParagraph> {
/**
* Helper method to return escher child by record ID
*
* @return escher record or <code>null</code> if not found.
* @return escher record or {@code null} if not found.
*/
public static <T extends EscherRecord> T getEscherChild(EscherContainerRecord owner, int recordId){
return owner.getChildById((short)recordId);
@ -260,7 +256,7 @@ public abstract class HSLFShape implements Shape<HSLFShape,HSLFTextParagraph> {
/**
* Returns escher property by id.
*
* @return escher property or <code>null</code> if not found.
* @return escher property or {@code null} if not found.
*
* @deprecated use {@link #getEscherProperty(EscherPropertyTypes)} instead
*/
@ -273,7 +269,7 @@ public abstract class HSLFShape implements Shape<HSLFShape,HSLFTextParagraph> {
/**
* Returns escher property by type.
*
* @return escher property or <code>null</code> if not found.
* @return escher property or {@code null} if not found.
*/
public static <T extends EscherProperty> T getEscherProperty(AbstractEscherOptRecord opt, EscherPropertyTypes type){
return (opt == null) ? null : opt.lookup(type);
@ -428,7 +424,7 @@ public abstract class HSLFShape implements Shape<HSLFShape,HSLFTextParagraph> {
}
/**
* @return the <code>SlideShow</code> this shape belongs to
* @return the {@code SlideShow} this shape belongs to
*/
@Override
public HSLFSheet getSheet(){
@ -436,7 +432,7 @@ public abstract class HSLFShape implements Shape<HSLFShape,HSLFTextParagraph> {
}
/**
* Assign the <code>SlideShow</code> this shape belongs to
* Assign the {@code SlideShow} this shape belongs to
*
* @param sheet owner of this shape
*/
@ -726,7 +722,7 @@ public abstract class HSLFShape implements Shape<HSLFShape,HSLFTextParagraph> {
/**
* Search for EscherClientDataRecord, if found, convert its contents into an array of HSLF records
*
* @return an array of HSLF records contained in the shape's EscherClientDataRecord or <code>null</code>
* @return an array of HSLF records contained in the shape's EscherClientDataRecord or {@code null}
*/
protected List<? extends Record> getClientRecords() {
HSLFEscherClientDataRecord clientData = getClientData(false);

View File

@ -86,14 +86,6 @@ import org.apache.poi.util.Units;
public final class HSLFTextParagraph implements TextParagraph<HSLFShape,HSLFTextParagraph,HSLFTextRun> {
private static final Logger LOG = LogManager.getLogger(HSLFTextParagraph.class);
/**
* How to align the text
*/
/* package */static final int AlignLeft = 0;
/* package */static final int AlignCenter = 1;
/* package */static final int AlignRight = 2;
/* package */static final int AlignJustify = 3;
// Note: These fields are protected to help with unit testing
// Other classes shouldn't really go playing with them!
private final TextHeaderAtom _headerAtom;
@ -120,19 +112,23 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFShape,HSLFText
this.tabStop = tabStop;
}
@Override
public double getPositionInPoints() {
return tabStop.getPositionInPoints();
}
@Override
public void setPositionInPoints(double position) {
tabStop.setPositionInPoints(position);
setDirty();
}
@Override
public TabStopType getType() {
return tabStop.getType();
}
@Override
public void setType(TabStopType type) {
tabStop.setType(type);
setDirty();
@ -165,18 +161,6 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFShape,HSLFText
setParagraphStyle(new TextPropCollection(1, TextPropType.paragraph));
}
/* package */HSLFTextParagraph(HSLFTextParagraph other) {
_headerAtom = other._headerAtom;
_byteAtom = other._byteAtom;
_charAtom = other._charAtom;
_parentShape = other._parentShape;
_sheet = other._sheet;
_ruler = other._ruler;
shapeId = other.shapeId;
parentList = other.parentList;
setParagraphStyle(other._paragraphStyle);
}
public void addTextRun(HSLFTextRun run) {
_runs.add(run);
}
@ -248,8 +232,6 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFShape,HSLFText
/**
* Sets the index of the paragraph in the SLWT container
*
* @param index
*/
protected void setIndex(int index) {
if (_headerAtom != null) {
@ -636,7 +618,7 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFShape,HSLFText
* Sets the bullet character
*/
public void setBulletChar(Character c) {
Integer val = (c == null) ? null : (int)c.charValue();
Integer val = (c == null) ? null : (int) c;
setParagraphTextPropVal("bullet.char", val);
}
@ -765,23 +747,21 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFShape,HSLFText
@Override
public List<? extends TabStop> getTabStops() {
final List<HSLFTabStop> tabStops;
final TextRulerAtom textRuler;
if (getSheet() instanceof HSLFSlideMaster) {
final HSLFTabStopPropCollection tpc = getMasterPropVal(_paragraphStyle, HSLFTabStopPropCollection.NAME);
if (tpc == null) {
return null;
}
tabStops = tpc.getTabStops();
textRuler = null;
} else {
textRuler = (TextRulerAtom)_headerAtom.getParentRecord().findFirstOfType(RecordTypes.TextRulerAtom.typeID);
final TextRulerAtom textRuler = (TextRulerAtom) _headerAtom.getParentRecord().findFirstOfType(RecordTypes.TextRulerAtom.typeID);
if (textRuler == null) {
return null;
}
tabStops = textRuler.getTabStops();
}
return tabStops.stream().map((tabStop) -> new HSLFTabStopDecorator(tabStop)).collect(Collectors.toList());
return tabStops.stream().map(HSLFTabStopDecorator::new).collect(Collectors.toList());
}
@Override
@ -836,11 +816,11 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFShape,HSLFText
private boolean getFlag(int index) {
BitMaskTextProp tp = getPropVal(_paragraphStyle, ParagraphFlagsTextProp.NAME);
return (tp == null) ? false : tp.getSubValue(index);
return tp != null && tp.getSubValue(index);
}
private void setFlag(int index, boolean value) {
BitMaskTextProp tp = (BitMaskTextProp)_paragraphStyle.addWithName(ParagraphFlagsTextProp.NAME);
BitMaskTextProp tp = _paragraphStyle.addWithName(ParagraphFlagsTextProp.NAME);
tp.setSubValue(value, index);
setDirty();
}
@ -1047,7 +1027,6 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFShape,HSLFText
StringUtil.putCompressedUnicode(rawText, byteText, 0);
byteAtom.setText(byteText);
}
assert (newRecord != null);
RecordContainer _txtbox = headerAtom.getParentRecord();
Record[] cr = _txtbox.getChildRecords();
@ -1528,7 +1507,7 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFShape,HSLFText
break;
}
List<HSLFTextRun> runs = p.getTextRuns();
for (int rlen=0,rIdx=0; rIdx < runs.size(); csIdx+=rlen, rIdx++) {
for (int rlen,rIdx=0; rIdx < runs.size(); csIdx+=rlen, rIdx++) {
HSLFTextRun run = runs.get(rIdx);
rlen = run.getLength();
if (csIdx < h.getEndIndex() && h.getStartIndex() < csIdx+rlen) {
@ -1722,8 +1701,6 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFShape,HSLFText
}
/**
* {@inheritDoc}
*
* @see RoundTripHFPlaceholder12
*/
@Override

View File

@ -322,8 +322,6 @@ public class HwmfDrawProperties {
/**
* Sets the current palette.
* It's the callers duty to set a modifiable copy of the palette.
*
* @param palette
*/
public void setPalette(List<PaletteEntry> palette) {
this.palette = palette;

View File

@ -223,6 +223,7 @@ public class HwmfEscape implements HwmfRecord {
return escapeFunction;
}
@SuppressWarnings("unchecked")
public <T extends HwmfEscapeData> T getEscapeData() {
return (T)escapeData;
}

View File

@ -171,10 +171,12 @@ public class HwmfFill {
*/
int regionIndex;
@Override
public HwmfRecordType getWmfRecordType() {
return HwmfRecordType.paintRegion;
}
@Override
public int init(LittleEndianInputStream leis, long recordSize, int recordFunction) throws IOException {
regionIndex = leis.readUShort();
return LittleEndianConsts.SHORT_SIZE;

View File

@ -31,7 +31,6 @@ public interface HwmfRecord extends GenericRecord {
*
* @param leis the little endian input stream
* @return count of processed bytes
* @throws IOException
*/
int init(LittleEndianInputStream leis, long recordSize, int recordFunction) throws IOException;
@ -43,7 +42,7 @@ public interface HwmfRecord extends GenericRecord {
void draw(HwmfGraphics ctx);
@Override
default Enum getGenericRecordType() {
default Enum<?> getGenericRecordType() {
return getWmfRecordType();
}
}

View File

@ -44,7 +44,6 @@ public interface CharIndexTranslator {
/**
* Check if index is in table
*
* @param bytePos
* @return true if index in table, false if not
*/
boolean isIndexInTable(int bytePos);
@ -52,7 +51,6 @@ public interface CharIndexTranslator {
/**
* Return first index &gt;= bytePos that is in table
*
* @param bytePos
* @return first index greater or equal to bytePos that is in table
*/
int lookIndexForward(int bytePos);
@ -60,7 +58,6 @@ public interface CharIndexTranslator {
/**
* Return last index &lt;= bytePos that is in table
*
* @param bytePos
* @return last index less of equal to bytePos that is in table
*/
int lookIndexBackward(int bytePos);

View File

@ -38,7 +38,7 @@ import static org.apache.logging.log4j.util.Unbox.box;
/**
* <p>The File Information Block (FIB). Holds pointers
* to various bits of the file, and lots of flags which
* specify properties of the document.<p>
* specify properties of the document.
* <ul>
* <li>The {@link FibBase} class, holds the first 32 bytes.</li>
* <li>The next part, the fibRgW / FibRgW97, is handled by the {@link FibRgW97}.</li>
@ -244,12 +244,12 @@ public final class FileInformationBlock {
// field info
for ( FieldsDocumentPart part : FieldsDocumentPart.values() )
knownFieldSet.add( Integer.valueOf( part.getFibFieldsField() ) );
knownFieldSet.add(part.getFibFieldsField());
// bookmarks
knownFieldSet.add( Integer.valueOf( FIBFieldHandler.PLCFBKF ) );
knownFieldSet.add( Integer.valueOf( FIBFieldHandler.PLCFBKL ) );
knownFieldSet.add( Integer.valueOf( FIBFieldHandler.STTBFBKMK ) );
knownFieldSet.add(FIBFieldHandler.PLCFBKF);
knownFieldSet.add(FIBFieldHandler.PLCFBKL);
knownFieldSet.add(FIBFieldHandler.STTBFBKMK);
// notes
for ( NoteType noteType : NoteType.values() ) {

View File

@ -33,13 +33,7 @@ import org.apache.poi.util.LittleEndian;
public final class OldCHPBinTable extends CHPBinTable
{
/**
* Constructor used to read an old-style binTable
* in from a Word document.
*
* @param documentStream
* @param offset
* @param size
* @param fcMin
* Constructor used to read an old-style binTable in from a Word document.
*/
public OldCHPBinTable(byte[] documentStream, int offset,
int size, int fcMin, OldTextPieceTable tpt)

View File

@ -52,7 +52,6 @@ public class OldTextPiece extends TextPiece {
/**
* @return nothing, ever. Always throws an UnsupportedOperationException
* @throws UnsupportedOperationException
*/
@NotImplemented
@Override
@ -77,8 +76,8 @@ public class OldTextPiece extends TextPiece {
*
* @param start Local start position, in characters
* @param end Local end position, in characters
* @throws UnsupportedOperationException
*/
@Override
@Deprecated
@NotImplemented
public String substring(int start, int end) {
@ -89,6 +88,7 @@ public class OldTextPiece extends TextPiece {
* Not implemented for OldTextPiece.
* Always throws UnsupportedOperationException
*/
@Override
@Deprecated
@NotImplemented
public void adjustForDelete(int start, int length) {
@ -98,6 +98,7 @@ public class OldTextPiece extends TextPiece {
/**
* Returns the length, in bytes
*/
@Override
public int bytesLength() {
return rawBytes.length;
}

View File

@ -94,7 +94,7 @@ public class OldTextPieceTable extends TextPieceTable {
// into order, if they're not already
Collections.sort(_textPieces);
_textPiecesFCOrder = new ArrayList<>(_textPieces);
_textPiecesFCOrder.sort(new FCComparator());
_textPiecesFCOrder.sort(byFilePosition());
}

View File

@ -39,8 +39,8 @@ public final class PlexOfCps {
private static final int MAX_RECORD_LENGTH = 10_485_760;
private int _iMac;
private int _cbStruct;
private List<GenericPropertyNode> _props;
private final int _cbStruct;
private final List<GenericPropertyNode> _props;
public PlexOfCps(int sizeOfStruct) {
_props = new ArrayList<>();
@ -69,18 +69,10 @@ public final class PlexOfCps {
void adjust(int startCp, int shift) {
for (GenericPropertyNode node : _props) {
if (node.getStart() > startCp) {
if (node.getStart() + shift < startCp) {
node.setStart(startCp);
} else {
node.setStart(node.getStart() + shift);
}
node.setStart(Math.max(node.getStart() + shift, startCp));
}
if (node.getEnd() >= startCp) {
if (node.getEnd() + shift < startCp) {
node.setEnd(startCp);
} else {
node.setEnd(node.getEnd() + shift);
}
node.setEnd(Math.max(node.getEnd() + shift, startCp));
}
}
}

View File

@ -162,7 +162,6 @@ public class PlfLfo
/**
* @param ilfo 1-based index
* @return The {@link LFO} stored at the given index
* @throws NoSuchElementException
*/
public LFO getLfo( int ilfo ) throws NoSuchElementException
{
@ -177,7 +176,6 @@ public class PlfLfo
/**
* @param ilfo 1-based index
* @return The {@link LFOData} stored at the given index
* @throws NoSuchElementException
*/
public LFOData getLfoData( int ilfo ) throws NoSuchElementException
{

View File

@ -32,9 +32,9 @@ import org.apache.poi.util.StringUtil;
*/
@Internal
public class TextPiece extends PropertyNode<TextPiece> {
private boolean _usesUnicode;
private final boolean _usesUnicode;
private PieceDescriptor _pd;
private final PieceDescriptor _pd;
public TextPiece(TextPiece other) {
super(other);
@ -142,6 +142,7 @@ public class TextPiece extends PropertyNode<TextPiece> {
* @param start The start position for the delete, in characters
* @param length The number of characters to delete
*/
@Override
@Deprecated
public void adjustForDelete(int start, int length) {
int myStart = getStart();

View File

@ -18,7 +18,6 @@ package org.apache.poi.hwpf.model;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
@ -114,7 +113,7 @@ public class TextPieceTable implements CharIndexTranslator {
// into order, if they're not already
Collections.sort(_textPieces);
_textPiecesFCOrder = new ArrayList<>(_textPieces);
_textPiecesFCOrder.sort(new FCComparator());
_textPiecesFCOrder.sort(byFilePosition());
}
protected TextPiece newTextPiece(int nodeStartChars, int nodeEndChars, byte[] buf, PieceDescriptor pd) {
@ -125,7 +124,7 @@ public class TextPieceTable implements CharIndexTranslator {
_textPieces.add(piece);
_textPiecesFCOrder.add(piece);
Collections.sort(_textPieces);
_textPiecesFCOrder.sort(new FCComparator());
_textPiecesFCOrder.sort(byFilePosition());
}
/**
@ -169,6 +168,7 @@ public class TextPieceTable implements CharIndexTranslator {
return false;
}
@Override
public int getByteIndex(int charPos) {
int byteCount = 0;
for (TextPiece tp : _textPieces) {
@ -308,6 +308,7 @@ public class TextPieceTable implements CharIndexTranslator {
return _textPieces.hashCode();
}
@Override
public boolean isIndexInTable(int bytePos) {
for (TextPiece tp : _textPiecesFCOrder) {
int pieceStart = tp.getPieceDescriptor().getFilePosition();
@ -339,6 +340,7 @@ public class TextPieceTable implements CharIndexTranslator {
return false;
}
@Override
public int lookIndexBackward(final int startBytePos) {
int bytePos = startBytePos;
int lastEnd = 0;
@ -361,6 +363,7 @@ public class TextPieceTable implements CharIndexTranslator {
return bytePos;
}
@Override
public int lookIndexForward(final int startBytePos) {
if (_textPiecesFCOrder.isEmpty())
throw new IllegalStateException("Text pieces table is empty");
@ -433,10 +436,7 @@ public class TextPieceTable implements CharIndexTranslator {
return textPlex.toByteArray();
}
protected static class FCComparator implements Comparator<TextPiece>, Serializable {
public int compare(TextPiece textPiece, TextPiece textPiece1) {
return Integer.compare(textPiece.getPieceDescriptor().fc, textPiece1
.getPieceDescriptor().fc);
}
static Comparator<TextPiece> byFilePosition() {
return Comparator.comparing(t -> t.getPieceDescriptor().getFilePosition());
}
}

View File

@ -34,7 +34,7 @@ import org.apache.poi.hwpf.model.SubdocumentType;
* as offsets are not yet updated!
*/
public final class HeaderStories {
private Range headerStories;
private final Range headerStories;
private PlexOfCps plcfHdd;
private boolean stripFields;
@ -370,7 +370,7 @@ public final class HeaderStories {
/**
* Are fields currently being stripped from
* the text that this {@link HeaderStories} returns?
* the text that this HeaderStories returns?
* Default is false, but can be changed
*/
public boolean areFieldsStripped() {
@ -380,7 +380,6 @@ public final class HeaderStories {
* Should fields (eg macros) be stripped from
* the text that this class returns?
* Default is not to strip.
* @param stripFields
*/
public void setAreFieldsStripped(boolean stripFields) {
this.stripFields = stripFields;

View File

@ -30,15 +30,19 @@ import org.apache.logging.log4j.Logger;
import org.apache.poi.ddf.EscherBSERecord;
import org.apache.poi.ddf.EscherBlipRecord;
import org.apache.poi.ddf.EscherComplexProperty;
import org.apache.poi.ddf.EscherContainerRecord;
import org.apache.poi.ddf.EscherOptRecord;
import org.apache.poi.ddf.EscherProperty;
import org.apache.poi.ddf.EscherPropertyTypes;
import org.apache.poi.ddf.EscherRecord;
import org.apache.poi.ddf.EscherRecordTypes;
import org.apache.poi.ddf.EscherSimpleProperty;
import org.apache.poi.hwpf.model.PICF;
import org.apache.poi.hwpf.model.PICFAndOfficeArtData;
import org.apache.poi.sl.image.ImageHeaderPNG;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.StringUtil;
import org.apache.poi.util.Units;
/**
* Represents embedded picture extracted from Word Document
@ -264,42 +268,42 @@ public final class Picture {
/**
* @return The amount the picture has been cropped on the left in twips
* @deprecated POI 3.8 beta 4.
*/
@Deprecated
public int getDxaCropLeft()
{
// TODO: use new properties
// if (_picfAndOfficeArtData == null || _picfAndOfficeArtData.getShape()
// == null)
// return 0;
//
// final EscherContainerRecord shape = _picfAndOfficeArtData.getShape();
// EscherOptRecord optRecord = shape.getChildById( (short) 0xF00B );
// if (optRecord == null)
// return 0;
//
// EscherProperty property = optRecord.lookup( 0x0102 );
// if (property == null || !(property instanceof EscherSimpleProperty))
// return 0;
//
// EscherSimpleProperty simpleProperty = (EscherSimpleProperty)
// property;
// return simpleProperty.getPropertyValue();
public int getDxaCropLeft() {
return _picf.getDxaReserved1();
}
/**
* @return The amount the picture has been cropped on the right in twips
* @deprecated POI 3.8 beta 4.
* The location, expressed as a fraction of the image width, of the left side of
* the crop rectangle. A value of 0 specifies that the left side of the image is uncropped.
* Positive values specify cropping into the image. Negative values specify cropping out from the
* image. The default value for this property is 0.
*
* @return the left crop percent
*/
@Deprecated
public int getDxaCropRight()
{
public double getCropLeft() {
return getCrop(EscherPropertyTypes.BLIP__CROPFROMLEFT);
}
/**
* @return The amount the picture has been cropped on the right in twips
*/
public int getDxaCropRight() {
return _picf.getDxaReserved2();
}
/**
* the location of the right side, expressed as a fraction of the image width, of
* the crop rectangle. A value of 0 specifies that the right side of the image is uncropped.
* Positive values specify cropping into the image. Negative values specify cropping out from the
* image. The default value for this property is 0.
*
* @return the right crop percent
*/
public double getCropRight() {
return getCrop(EscherPropertyTypes.BLIP__CROPFROMRIGHT);
}
/**
* Gets the initial width of the picture, in twips, prior to cropping or
* scaling.
@ -313,24 +317,57 @@ public final class Picture {
/**
* @return The amount the picture has been cropped on the bottom in twips
* @deprecated POI 3.8 beta 5.
*/
@Deprecated
public int getDyaCropBottom()
{
public int getDyaCropBottom() {
return _picf.getDyaReserved2();
}
/**
* @return The amount the picture has been cropped on the top in twips
* @deprecated POI 3.8 beta 5.
* the location, expressed as a fraction of the image height, of the bottom of
* the crop rectangle. A value of 0 specifies that the bottom of the image is uncropped.
* Positive values specify cropping into the image. Negative values specify cropping out from the
* image. The default value for this property is 0
*
* @return the bottom crop percent
*/
@Deprecated
public int getDyaCropTop()
{
public double getCropBottom() {
return getCrop(EscherPropertyTypes.BLIP__CROPFROMBOTTOM);
}
/**
* @return The amount the picture has been cropped on the top in twips
*/
public int getDyaCropTop() {
return _picf.getDyaReserved1();
}
/**
* the location, expressed as a fraction of the image height, of the top of the crop
* rectangle. A value of 0 specifies that the top of the image is uncropped. Positive values
* specify cropping into the image. Negative values specify cropping out from the image. The default
* value for this property is 0.
*
* @return the top crop percent
*/
public double getCropTop() {
return getCrop(EscherPropertyTypes.BLIP__CROPFROMTOP);
}
private double getCrop(EscherPropertyTypes propType) {
EscherContainerRecord shape;
if (_picfAndOfficeArtData != null && (shape = _picfAndOfficeArtData.getShape()) != null) {
EscherOptRecord optRecord = shape.getChildById(EscherRecordTypes.OPT.typeID);
if (optRecord != null) {
EscherProperty property = optRecord.lookup(propType);
if (property instanceof EscherSimpleProperty) {
EscherSimpleProperty simpleProperty = (EscherSimpleProperty) property;
return Units.fixedPointToDouble(simpleProperty.getPropertyValue());
}
}
}
return 0;
}
/**
* Gets the initial height of the picture, in twips, prior to cropping or
* scaling.
@ -490,20 +527,15 @@ public final class Picture {
+ ( fileExt.length() > 0 ? "." + fileExt : "" );
}
public PictureType suggestPictureType()
{
public PictureType suggestPictureType() {
if (_blipRecords.size() != 1 ) {
return PictureType.UNKNOWN;
}
EscherRecord escherRecord = _blipRecords.get( 0 );
switch ( escherRecord.getRecordId() )
{
case (short) 0xF007:
{
if (escherRecord instanceof EscherBSERecord) {
EscherBSERecord bseRecord = (EscherBSERecord) escherRecord;
switch ( bseRecord.getBlipTypeWin32() )
{
switch ( bseRecord.getBlipTypeWin32() ) {
case 0x00:
return PictureType.UNKNOWN;
case 0x01:
@ -528,22 +560,24 @@ public final class Picture {
return PictureType.UNKNOWN;
}
}
case (short) 0xF01A:
Enum<?> recordType = escherRecord.getGenericRecordType();
assert (recordType instanceof EscherRecordTypes);
switch ((EscherRecordTypes)recordType) {
case BLIP_EMF:
return PictureType.EMF;
case (short) 0xF01B:
case BLIP_WMF:
return PictureType.WMF;
case (short) 0xF01C:
case BLIP_PICT:
return PictureType.PICT;
case (short) 0xF01D:
case BLIP_JPEG:
return PictureType.JPEG;
case (short) 0xF01E:
case BLIP_PNG:
return PictureType.PNG;
case (short) 0xF01F:
case BLIP_DIB:
return PictureType.BMP;
case (short) 0xF029:
case BLIP_TIFF:
return PictureType.TIFF;
case (short) 0xF02A:
return PictureType.JPEG;
default:
return PictureType.UNKNOWN;
}

View File

@ -40,9 +40,6 @@ public class DoubleByteUtil
* We know MS zero-padded ascii, and we drop those.
* There may be areas for improvement in this.
*
* @param data
* @param offset
* @param lengthInBytes
* @return Decoded String
*/
public static String cp950ToString(byte[] data, int offset, int lengthInBytes) {

View File

@ -100,7 +100,7 @@ public class TestWordToHtmlConverter {
})
void testFile(String file, String contains) throws Exception {
boolean emulatePictureStorage = file.contains("picture");
boolean emulatePictureStorage = !file.contains("equation");
String result = getHtmlText(file, emulatePictureStorage);
assertNotNull(result);

View File

@ -50,6 +50,7 @@ dependencies {
testImplementation "org.junit.jupiter:junit-jupiter-api:${junitVersion}"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${junitVersion}"
// needed for locating the external references
javadocs project(':poi-ooxml')
javadocs project(':poi-scratchpad')
}
@ -59,13 +60,6 @@ final Pattern MODULE_NOT_REGEX = ~'(poi[/\\\\][^/\\\\]+$|batik-script)'
final Pattern MODULE_REGEX = ~'\\.jar$'
final List MODULE_PATH = sourceSets.test.runtimeClasspath.findAll{ it.path =~ MODULE_REGEX && !(it.path =~ MODULE_NOT_REGEX) }.collect{ it.parent }.unique()
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
withJavadocJar()
withSourcesJar()
}
task compileJava9(type: JavaCompile) {
dependsOn 'compileJava'
@ -110,8 +104,6 @@ task cacheTest9(type: Copy) {
}
jar {
destinationDirectory = file("../build/dist/maven/${project.archivesBaseName}")
if (JavaVersion.current() == JavaVersion.VERSION_1_8) {
into('META-INF/versions/9') {
from JAVA9_SRC include '*.class'
@ -145,24 +137,12 @@ task testJar(type: Jar, dependsOn: testClasses) {
}
}
sourcesJar {
destinationDirectory = file("../build/dist/maven/${project.archivesBaseName}")
exclude 'META-INF/services/**'
}
javadoc {
failOnError = true
dependsOn configurations.javadocs.dependencies.collect{ ':' + it.dependencyProject.name + ':compileJava' }
doFirst {
options {
if (JavaVersion.current().isJava9Compatible()) {
addBooleanOption('html5', true)
}
links 'https://poi.apache.org/apidocs/dev/'
links 'https://docs.oracle.com/javase/8/docs/api/'
use = true
splitIndex = true
source = "1.8"
classpath += configurations.javadocs.files
classpath += files(configurations.javadocs.dependencies.collect{ it.dependencyProject.sourceSets.main.output.classesDirs })
}
}
}
@ -174,39 +154,10 @@ artifacts {
test {
dependsOn { testJar }
useJUnitPlatform()
doFirst {
jvmArgs = [
'-Djava.io.tmpdir=build',
'-DPOI.testdata.path=../test-data',
'-Djava.awt.headless=true',
'-Djava.locale.providers=JRE,CLDR',
'-Duser.language=en',
'-Duser.country=US',
'-Djavax.xml.stream.XMLInputFactory=com.sun.xml.internal.stream.XMLInputFactoryImpl',
"-Dversion.id=${project.version}",
'-ea',
'-Djunit.jupiter.execution.parallel.enabled=true',
'-Djunit.jupiter.execution.parallel.config.strategy=fixed',
'-Djunit.jupiter.execution.parallel.config.fixed.parallelism=3'
// -Xjit:verbose={compileStart|compileEnd},vlog=build/jit.log${no.jit.sherlock} ... if ${isIBMVM}
]
if (JavaVersion.current() != JavaVersion.VERSION_1_8) {
jvmArgs += [
'-Dsun.reflect.debugModuleAccessChecks=true',
'-Dcom.sun.xml.bind.v2.bytecode.ClassTailor.noOptimize=true',
'--illegal-access=warn',
jvmArgs << [
'--add-modules', MODULE_NAME,
// see https://github.com/java9-modularity/gradle-modules-plugin/issues/97
// opposed to the recommendation there, it doesn't work to add ... to the dependencies
// testRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.7.1'
// gradles gradle-worker.jar is still not a JPMS module and thus runs as unnamed module
'--add-exports','org.junit.platform.commons/org.junit.platform.commons.util=ALL-UNNAMED',
'--add-exports','org.junit.platform.commons/org.junit.platform.commons.logging=ALL-UNNAMED',
'--module-path', '../build/dist/maven/poi-tests:' + files(MODULE_PATH).asPath,
]
}
@ -216,16 +167,10 @@ test {
publishing {
publications {
POI(MavenPublication) {
artifactId project.archivesBaseName
from components.java
pom {
name = 'Apache POI'
name = 'Apache POI - Common'
description = 'Apache POI - Java API To Access Microsoft Format Files'
}
}
}
}
generatePomFileForPOIPublication.destination = "../build/dist/maven/${project.archivesBaseName}/${project.archivesBaseName}-${project.version}.pom"

View File

@ -79,6 +79,7 @@ public enum EscherRecordTypes {
BLIP_JPEG(0xf018 + 5 /* 0xf01d */, "BlipJpeg", null, EscherBitmapBlip::new),
BLIP_PNG(0xf018 + 6 /* 0xf01e */, "BlipPng", null, EscherBitmapBlip::new),
BLIP_DIB(0xf018 + 7 /* 0xf01f */, "BlipDib", null, EscherBitmapBlip::new),
BLIP_TIFF(0xf018 + 17 /* 0xf029 */, "BlipTiff", null, EscherBitmapBlip::new),
BLIP_END(0xf117, "Blip", "msofbtBlip", null),
REGROUP_ITEMS(0xf118, null, null, null),
SELECTION(0xf119, null, null, null),
@ -111,6 +112,11 @@ public enum EscherRecordTypes {
Stream.of(values()).collect(Collectors.toMap(EscherRecordTypes::getTypeId, Function.identity()));
public static EscherRecordTypes forTypeID(int typeID) {
// Section 2.2.23: 0xF02A is treated as 0xF01D
if (typeID == 0xF02A) {
return EscherRecordTypes.BLIP_JPEG;
}
EscherRecordTypes rt = LOOKUP.get((short)typeID);
return (rt != null) ? rt : EscherRecordTypes.UNKNOWN;
}

View File

@ -30,9 +30,6 @@ public class EscherShapePathProperty extends EscherSimpleProperty {
/**
* Create an instance of an escher shape path property.
*
* @param propertyNumber
* @param shapePath
*/
public EscherShapePathProperty( short propertyNumber, int shapePath ) {
super( propertyNumber, false, false, shapePath );

View File

@ -30,6 +30,7 @@ import java.util.stream.StreamSupport;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.poi.EmptyFileException;
import org.apache.poi.OldFileFormatException;
import org.apache.poi.hssf.extractor.ExcelExtractor;
import org.apache.poi.poifs.crypt.Decryptor;
import org.apache.poi.poifs.filesystem.DirectoryEntry;

Some files were not shown because too many files have changed in this diff Show More