Skip to content

Commit

Permalink
Apply some IDE suggestions, JavaDoc and GitHub PR
Browse files Browse the repository at this point in the history
Update assertion-message
Adjust JavaDoc
Add tests
Reformat class DirectoryNode, adjust/move some comments

Closes #730

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1921980 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
centic9 committed Nov 20, 2024
1 parent 83384cc commit c1f018f
Show file tree
Hide file tree
Showing 10 changed files with 147 additions and 174 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ Licensed to the Apache Software Foundation (ASF) under one or more
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.PrivateKey;
import java.security.Provider;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
Expand All @@ -52,14 +51,11 @@ Licensed to the Apache Software Foundation (ASF) under one or more
import javax.xml.crypto.dsig.CanonicalizationMethod;
import javax.xml.crypto.dsig.DigestMethod;
import javax.xml.crypto.dsig.Transform;
import javax.xml.crypto.dsig.XMLSignatureFactory;
import javax.xml.crypto.dsig.keyinfo.KeyInfoFactory;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.poi.EncryptedDocumentException;
import org.apache.poi.hpsf.ClassID;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.poifs.crypt.HashAlgorithm;
import org.apache.poi.poifs.crypt.dsig.facets.KeyInfoSignatureFacet;
import org.apache.poi.poifs.crypt.dsig.facets.OOXMLSignatureFacet;
Expand All @@ -73,7 +69,6 @@ Licensed to the Apache Software Foundation (ASF) under one or more
import org.apache.poi.poifs.crypt.dsig.services.TimeStampService;
import org.apache.poi.poifs.crypt.dsig.services.TimeStampServiceValidator;
import org.apache.poi.poifs.crypt.dsig.services.TimeStampSimpleHttpClient;
import org.apache.poi.util.Internal;
import org.apache.poi.util.LocaleUtil;
import org.apache.poi.util.Removal;
import org.apache.xml.security.signature.XMLSignature;
Expand Down Expand Up @@ -382,7 +377,7 @@ public String formatExecutionTime() {
* @since POI 4.0.0
*/
public void setExecutionTime(String executionTime) {
if (executionTime != null && !"".equals(executionTime)){
if (executionTime != null && !executionTime.isEmpty()){
final DateFormat fmt = new SimpleDateFormat(SIGNATURE_TIME_FORMAT, Locale.ROOT);
fmt.setTimeZone(LocaleUtil.TIMEZONE_UTC);
try {
Expand Down Expand Up @@ -992,12 +987,12 @@ public void setSignatureMethodFromUri(final String signatureMethodUri) {
* <li>the JDK xmlsec provider</li>
* </ol>
*
* @return a list of possible XMLSEC provider class names
* @return an array of possible XMLSEC provider class names
*/
public static String[] getProviderNames() {
// need to check every time, as the system property might have been changed in the meantime
String sysProp = System.getProperty("jsr105Provider");
return (sysProp == null || "".equals(sysProp))
return (sysProp == null || sysProp.isEmpty())
? new String[]{XMLSEC_SANTUARIO, XMLSEC_JDK}
: new String[]{sysProp, XMLSEC_SANTUARIO, XMLSEC_JDK};
}
Expand Down Expand Up @@ -1031,7 +1026,7 @@ public boolean isUpdateConfigOnValidate() {

/**
* The signature config can be updated if a document is succesful validated.
* This flag is used for activating this modifications.
* This flag is used for activating these modifications.
* Defaults to {@code false}
*
* @param updateConfigOnValidate if true, update config on validate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Licensed to the Apache Software Foundation (ASF) under one or more
import static org.apache.poi.sl.usermodel.BaseTestSlideShow.getColor;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
Expand Down Expand Up @@ -467,21 +468,21 @@ public void drawString(AttributedCharacterIterator iterator, float x, float y) {
attributes = iterator.getAttributes();
}

if ("This is a".equals(sb.toString())) {
if ("This is a".contentEquals(sb)) {
// Should be no background.
assertNotNull(attributes);
Object background = attributes.get(TextAttribute.BACKGROUND);
assertNull(background);
}
if ("highlight".equals(sb.toString())) {
if ("highlight".contentEquals(sb)) {
// Should be yellow background.
assertNotNull(attributes);
Object background = attributes.get(TextAttribute.BACKGROUND);
assertNotNull(background);
assertTrue(background instanceof Color);
assertInstanceOf(Color.class, background);
assertEquals(Color.yellow, background);
}
if (" test".equals(sb.toString())) {
if (" test".contentEquals(sb)) {
// Should be no background.
assertNotNull(attributes);
Object background = attributes.get(TextAttribute.BACKGROUND);
Expand All @@ -494,5 +495,4 @@ public void drawString(AttributedCharacterIterator iterator, float x, float y) {
ppt.getSlides().get(0).draw(dgfx);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3331,7 +3331,7 @@ void test58896WithFile() throws IOException {
LOG.atInfo().log(between(start, now()));

assertTrue(between(start, now()).getSeconds() < 25,
"Had start: " + start + ", now: " + now() +
"Expected to have less than 25s duration for test, but had start: " + start + ", now: " + now() +
", diff: " + Duration.between(start, now()).getSeconds());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,9 @@ private void writeFixedLengthValueHeader(OutputStream out, MAPIProperty property
/**
* Writes out pre-calculated raw values which assume any variable length property `data`
* field to already have size, reserved and manually written header
* @param out
* @throws IOException
*
* @param out The OutputStream to write the data to
* @throws IOException If an I/O error occurs while writing data
*/
private void writeVariableLengthPreCalculatedValue(OutputStream out, PropertyValue value) throws IOException {
// variable length header
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ public HWPFDocument(DirectoryNode directory) throws IOException {
_text = _tpt.getText();

/*
* in this mode we preserving PAPX/CHPX structure from file, so text may
* in this mode we are preserving PAPX/CHPX structure from file, so text may
* miss from output, and text order may be corrupted
*/
boolean preserveBinTables = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public static short[] getAllKnownRecordSIDs() {
*
* @param in the InputStream from which the records will be obtained
*
* @return an array of Records created from the InputStream
* @return a list of Records created from the InputStream
*
* @throws org.apache.poi.util.RecordFormatException on error processing the InputStream
*/
Expand Down
Loading

0 comments on commit c1f018f

Please sign in to comment.