aboutsummaryrefslogtreecommitdiffstats
path: root/poi-scratchpad
diff options
context:
space:
mode:
authorAndreas Beeker <kiwiwings@apache.org>2021-10-17 20:44:36 +0000
committerAndreas Beeker <kiwiwings@apache.org>2021-10-17 20:44:36 +0000
commit87a764956c280960f6117eee1bfb351d94c3a23b (patch)
treec5518744cfb432bb519882f354fafba4921e38aa /poi-scratchpad
parentb20897a996059e6df7d651ff28361a0c22c7ef1d (diff)
downloadpoi-87a764956c280960f6117eee1bfb351d94c3a23b.tar.gz
poi-87a764956c280960f6117eee1bfb351d94c3a23b.zip
sonar fixes
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1894331 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi-scratchpad')
-rw-r--r--poi-scratchpad/src/main/java/org/apache/poi/extractor/ole2/OLE2ScratchpadExtractorFactory.java32
-rw-r--r--poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSlideShowFactory.java4
-rw-r--r--poi-scratchpad/src/main/java/org/apache/poi/hwpf/dev/HWPFLister.java42
-rw-r--r--poi-scratchpad/src/main/java/org/apache/poi/hwpf/extractor/Word6Extractor.java7
-rw-r--r--poi-scratchpad/src/main/java/org/apache/poi/hwpf/extractor/WordExtractor.java5
-rw-r--r--poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/FileInformationBlock.java19
-rw-r--r--poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/ListLevel.java3
-rw-r--r--poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/StyleDescription.java15
-rw-r--r--poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/types/LFOAbstractType.java39
9 files changed, 64 insertions, 102 deletions
diff --git a/poi-scratchpad/src/main/java/org/apache/poi/extractor/ole2/OLE2ScratchpadExtractorFactory.java b/poi-scratchpad/src/main/java/org/apache/poi/extractor/ole2/OLE2ScratchpadExtractorFactory.java
index 70da34747b..3c4ab886f4 100644
--- a/poi-scratchpad/src/main/java/org/apache/poi/extractor/ole2/OLE2ScratchpadExtractorFactory.java
+++ b/poi-scratchpad/src/main/java/org/apache/poi/extractor/ole2/OLE2ScratchpadExtractorFactory.java
@@ -60,6 +60,21 @@ import org.apache.poi.sl.usermodel.SlideShowFactory;
public class OLE2ScratchpadExtractorFactory implements ExtractorProvider {
private static final Logger LOG = LogManager.getLogger(OLE2ScratchpadExtractorFactory.class);
+ private static final String[] OUTLOOK_ENTRY_NAMES = {
+ // message bodies, saved as plain text (PtypString)
+ // The first short (0x1000, 0x0047, 0x0037) refer to the Property ID (see [MS-OXPROPS].pdf)
+ // the second short (0x001e, 0x001f, 0x0102) refer to the type of data stored in this entry
+ // https://msdn.microsoft.com/endatatypes.Ex-us/library/cc433490(v=exchg.80).aspx
+ // @see org.apache.poi.hsmf.Types.MAPIType
+ "__substg1.0_1000001E", //PidTagBody ASCII
+ "__substg1.0_1000001F", //PidTagBody Unicode
+ "__substg1.0_0047001E", //PidTagMessageSubmissionId ASCII
+ "__substg1.0_0047001F", //PidTagMessageSubmissionId Unicode
+ "__substg1.0_0037001E", //PidTagSubject ASCII
+ "__substg1.0_0037001F", //PidTagSubject Unicode
+ };
+
+
@Override
public boolean accepts(FileMagic fm) {
return FileMagic.OLE2 == fm;
@@ -87,6 +102,8 @@ public class OLE2ScratchpadExtractorFactory implements ExtractorProvider {
*
* @throws IOException when the format specific extraction fails because of invalid entires
*/
+ @SuppressWarnings("java:S2093")
+ @Override
public POITextExtractor create(DirectoryNode poifsDir, String password) throws IOException {
final String oldPW = Biff8EncryptionKey.getCurrentUserPassword();
try {
@@ -112,20 +129,7 @@ public class OLE2ScratchpadExtractorFactory implements ExtractorProvider {
return new PublisherTextExtractor(poifsDir);
}
- final String[] outlookEntryNames = new String[]{
- // message bodies, saved as plain text (PtypString)
- // The first short (0x1000, 0x0047, 0x0037) refer to the Property ID (see [MS-OXPROPS].pdf)
- // the second short (0x001e, 0x001f, 0x0102) refer to the type of data stored in this entry
- // https://msdn.microsoft.com/endatatypes.Ex-us/library/cc433490(v=exchg.80).aspx
- // @see org.apache.poi.hsmf.Types.MAPIType
- "__substg1.0_1000001E", //PidTagBody ASCII
- "__substg1.0_1000001F", //PidTagBody Unicode
- "__substg1.0_0047001E", //PidTagMessageSubmissionId ASCII
- "__substg1.0_0047001F", //PidTagMessageSubmissionId Unicode
- "__substg1.0_0037001E", //PidTagSubject ASCII
- "__substg1.0_0037001F", //PidTagSubject Unicode
- };
- for (String entryName : outlookEntryNames) {
+ for (String entryName : OUTLOOK_ENTRY_NAMES) {
if (poifsDir.hasEntry(entryName)) {
return new OutlookTextExtractor(poifsDir);
}
diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSlideShowFactory.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSlideShowFactory.java
index 936eae064e..47f515b0a7 100644
--- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSlideShowFactory.java
+++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSlideShowFactory.java
@@ -47,6 +47,7 @@ public class HSLFSlideShowFactory implements SlideShowProvider<HSLFShape,HSLFTex
*
* @return The created SlideShow
*/
+ @Override
public HSLFSlideShow create() {
return new HSLFSlideShow();
}
@@ -65,6 +66,8 @@ public class HSLFSlideShowFactory implements SlideShowProvider<HSLFShape,HSLFTex
* Note that in order to properly release resources the
* SlideShow should be closed after use.
*/
+ @Override
+ @SuppressWarnings("java:S2093")
public HSLFSlideShow create(final DirectoryNode root, String password) throws IOException {
boolean passwordSet = false;
if (password != null) {
@@ -91,6 +94,7 @@ public class HSLFSlideShowFactory implements SlideShowProvider<HSLFShape,HSLFTex
return create(fs.getRoot(), password);
}
+ @SuppressWarnings("java:S2093")
@Override
public HSLFSlideShow create(File file, String password, boolean readOnly) throws IOException {
boolean passwordSet = false;
diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/dev/HWPFLister.java b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/dev/HWPFLister.java
index 71079c3b1b..55657f72b3 100644
--- a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/dev/HWPFLister.java
+++ b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/dev/HWPFLister.java
@@ -38,10 +38,6 @@ import org.apache.poi.hwpf.model.CHPX;
import org.apache.poi.hwpf.model.FieldsDocumentPart;
import org.apache.poi.hwpf.model.FileInformationBlock;
import org.apache.poi.hwpf.model.GenericPropertyNode;
-import org.apache.poi.hwpf.model.LFO;
-import org.apache.poi.hwpf.model.LFOData;
-import org.apache.poi.hwpf.model.ListLevel;
-import org.apache.poi.hwpf.model.ListTables;
import org.apache.poi.hwpf.model.PAPFormattedDiskPage;
import org.apache.poi.hwpf.model.PAPX;
import org.apache.poi.hwpf.model.PlexOfCps;
@@ -55,7 +51,6 @@ import org.apache.poi.hwpf.usermodel.Bookmarks;
import org.apache.poi.hwpf.usermodel.Field;
import org.apache.poi.hwpf.usermodel.OfficeDrawing;
import org.apache.poi.hwpf.usermodel.Paragraph;
-import org.apache.poi.hwpf.usermodel.ParagraphProperties;
import org.apache.poi.hwpf.usermodel.Picture;
import org.apache.poi.hwpf.usermodel.Range;
import org.apache.poi.poifs.common.POIFSConstants;
@@ -291,7 +286,7 @@ public final class HWPFLister {
char c = text.charAt( charIndex );
part.append( c );
if ( c == 13 || c == 7 || c == 12 ) {
- paragraphs.put( Integer.valueOf( charIndex ), part.toString() );
+ paragraphs.put(charIndex, part.toString() );
part.setLength( 0 );
}
}
@@ -398,7 +393,7 @@ public final class HWPFLister {
.hasNext(); ) {
Entry entry = iterator.next();
String entryToString = "\n" + dumpFileSystem( entry );
- entryToString = entryToString.replaceAll( "\n", "\n+---" );
+ entryToString = entryToString.replace("\n", "\n+---");
result.append( entryToString );
}
result.append( "\n" );
@@ -530,7 +525,7 @@ public final class HWPFLister {
}
}
- protected void dumpSprms( SprmIterator sprmIt, String linePrefix ) {
+ private void dumpSprms(SprmIterator sprmIt, String linePrefix) {
while ( sprmIt.hasNext() ) {
SprmOperation sprm = sprmIt.next();
System.out.println( linePrefix + sprm);
@@ -588,37 +583,6 @@ public final class HWPFLister {
}
}
- protected void dumpParagraphLevels( ListTables listTables,
- ParagraphProperties paragraph ) {
- if ( paragraph.getIlfo() != 0 ) {
- final LFO lfo = listTables.getLfo( paragraph.getIlfo() );
- System.out.println( "PAP's LFO: " + lfo );
-
- final LFOData lfoData = listTables.getLfoData( paragraph.getIlfo() );
- System.out.println( "PAP's LFOData: " + lfoData );
-
- if ( lfo != null ) {
- final ListLevel listLevel = listTables.getLevel( lfo.getLsid(),
- paragraph.getIlvl() );
-
- System.out.println( "PAP's ListLevel: " + listLevel );
- if ( listLevel.getGrpprlPapx() != null ) {
- System.out.println( "PAP's ListLevel PAPX:" );
- dumpSprms(
- new SprmIterator( listLevel.getGrpprlPapx(), 0 ),
- "* " );
- }
-
- if ( listLevel.getGrpprlPapx() != null ) {
- System.out.println( "PAP's ListLevel CHPX:" );
- dumpSprms(
- new SprmIterator( listLevel.getGrpprlChpx(), 0 ),
- "* " );
- }
- }
- }
- }
-
public void dumpTextPieces( boolean withText ) {
for ( TextPiece textPiece : _doc.getTextTable().getTextPieces() ) {
System.out.println( textPiece );
diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/extractor/Word6Extractor.java b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/extractor/Word6Extractor.java
index 8252d681be..6334855763 100644
--- a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/extractor/Word6Extractor.java
+++ b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/extractor/Word6Extractor.java
@@ -35,7 +35,7 @@ import org.apache.poi.poifs.filesystem.POIFSFileSystem;
* with HWPF.
*/
public final class Word6Extractor implements POIOLE2TextExtractor {
- private HWPFOldDocument doc;
+ private final HWPFOldDocument doc;
private boolean doCloseFilesystem = true;
/**
@@ -97,14 +97,15 @@ public final class Word6Extractor implements POIOLE2TextExtractor {
ret[i] = doc.getTextTable().getTextPieces().get(i).getStringBuilder().toString();
// Fix the line endings
- ret[i] = ret[i].replaceAll("\r", "\ufffe");
- ret[i] = ret[i].replaceAll("\ufffe","\r\n");
+ ret[i] = ret[i].replace("\r", "\ufffe");
+ ret[i] = ret[i].replace("\ufffe","\r\n");
}
}
return ret;
}
+ @Override
public String getText() {
try {
WordToTextConverter wordToTextConverter = new WordToTextConverter();
diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/extractor/WordExtractor.java b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/extractor/WordExtractor.java
index 82f806caaa..9c8dc8b568 100644
--- a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/extractor/WordExtractor.java
+++ b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/extractor/WordExtractor.java
@@ -210,8 +210,8 @@ public final class WordExtractor implements POIOLE2TextExtractor {
String text = doc.getDocumentText();
// Fix line endings (Note - won't get all of them
- text = text.replaceAll( "\r\r\r", "\r\n\r\n\r\n" );
- text = text.replaceAll( "\r\r", "\r\n\r\n" );
+ text = text.replace( "\r\r\r", "\r\n\r\n\r\n" );
+ text = text.replace( "\r\r", "\r\n\r\n" );
if ( text.endsWith( "\r" )) {
text += "\n";
@@ -224,6 +224,7 @@ public final class WordExtractor implements POIOLE2TextExtractor {
* Grab the text, based on the WordToTextConverter. Shouldn't include any
* crud, but slower than getTextFromPieces().
*/
+ @Override
public String getText() {
try {
WordToTextConverter wordToTextConverter = new WordToTextConverter();
diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/FileInformationBlock.java b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/FileInformationBlock.java
index 37ed665ed4..9c29edc297 100644
--- a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/FileInformationBlock.java
+++ b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/FileInformationBlock.java
@@ -27,6 +27,7 @@ import java.util.Locale;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.poi.hwpf.model.types.FibBaseAbstractType;
+import org.apache.poi.hwpf.model.types.FibRgLw97AbstractType;
import org.apache.poi.hwpf.model.types.FibRgW97AbstractType;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.Internal;
@@ -61,7 +62,7 @@ public final class FileInformationBlock {
private final FibRgLw _fibRgLw;
private int _cbRgFcLcb;
private FIBFieldHandler _fieldHandler;
- private int _cswNew;
+ private final int _cswNew;
private final int _nFibNew;
private final byte[] _fibRgCswNew;
@@ -87,7 +88,7 @@ public final class FileInformationBlock {
if ( _fibBase.getNFib() < 105 )
{
_fibRgLw = new FibRgLw95( mainDocument, offset );
- offset += FibRgLw97.getSize();
+ offset += FibRgLw97AbstractType.getSize();
// magic number, run tests after changes
_cbRgFcLcb = 74;
@@ -95,9 +96,7 @@ public final class FileInformationBlock {
// skip fibRgFcLcbBlob (read later at fillVariableFields)
offset += _cbRgFcLcb * LittleEndianConsts.INT_SIZE * 2;
- _cswNew = LittleEndian.getUShort( mainDocument, offset );
- offset += LittleEndianConsts.SHORT_SIZE;
-
+ // _cswNew = LittleEndian.getUShort( mainDocument, offset );
_cswNew = 0;
_nFibNew = -1;
_fibRgCswNew = new byte[0];
@@ -106,7 +105,7 @@ public final class FileInformationBlock {
}
_fibRgLw = new FibRgLw97( mainDocument, offset );
- offset += FibRgLw97.getSize();
+ offset += FibRgLw97AbstractType.getSize();
assert offset == 152;
_cbRgFcLcb = LittleEndian.getUShort( mainDocument, offset );
@@ -1078,7 +1077,7 @@ public final class FileInformationBlock {
offset += LittleEndianConsts.SHORT_SIZE;
( (FibRgLw97) _fibRgLw ).serialize( mainStream, offset );
- offset += FibRgLw97.getSize();
+ offset += FibRgLw97AbstractType.getSize();
LittleEndian.putUShort( mainStream, offset, _cbRgFcLcb );
offset += LittleEndianConsts.SHORT_SIZE;
@@ -1093,16 +1092,14 @@ public final class FileInformationBlock {
LittleEndian.putUShort( mainStream, offset, _nFibNew );
offset += LittleEndianConsts.SHORT_SIZE;
- System.arraycopy( _fibRgCswNew, 0, mainStream, offset,
- _fibRgCswNew.length );
- offset += _fibRgCswNew.length;
+ System.arraycopy( _fibRgCswNew, 0, mainStream, offset, _fibRgCswNew.length );
}
}
public int getSize()
{
return FibBaseAbstractType.getSize() + LittleEndianConsts.SHORT_SIZE + FibRgW97AbstractType.getSize()
- + LittleEndianConsts.SHORT_SIZE + FibRgLw97.getSize()
+ + LittleEndianConsts.SHORT_SIZE + FibRgLw97AbstractType.getSize()
+ LittleEndianConsts.SHORT_SIZE + _fieldHandler.sizeInBytes();
}
diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/ListLevel.java b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/ListLevel.java
index 39c0628487..ca8e1bb9df 100644
--- a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/ListLevel.java
+++ b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/ListLevel.java
@@ -299,7 +299,6 @@ public final class ListLevel
offset += _grpprlChpx.length;
_xst.serialize( buf, offset );
- offset += _xst.getSize();
return buf;
}
@@ -307,7 +306,7 @@ public final class ListLevel
@Override
public String toString()
{
- return "LVL: " + ( "\n" + _lvlf ).replaceAll( "\n", "\n " )
+ return "LVL: " + ( "\n" + _lvlf ).replace( "\n", "\n " )
+ "\n"
+ ( "PAPX's grpprl: " + Arrays.toString( _grpprlPapx ) + "\n" )
+ ( "CHPX's grpprl: " + Arrays.toString( _grpprlChpx ) + "\n" )
diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/StyleDescription.java b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/StyleDescription.java
index 01f927a165..976ab1ed82 100644
--- a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/StyleDescription.java
+++ b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/StyleDescription.java
@@ -37,8 +37,6 @@ import static org.apache.logging.log4j.util.Unbox.box;
public final class StyleDescription {
private static final Logger LOG = LogManager.getLogger(StyleDescription.class);
- //arbitrarily selected; may need to increase
- private static final int MAX_RECORD_LENGTH = 100_000;
private static final int PARAGRAPH_STYLE = 1;
private static final int CHARACTER_STYLE = 2;
@@ -84,13 +82,14 @@ public final class StyleDescription {
//first byte(s) of variable length section of std is the length of the
//style name and aliases string
- int nameLength = 0;
- int multiplier = 1;
+ int nameLength;
+ int multiplier;
if (word9) {
nameLength = LittleEndian.getShort(std, nameStart);
multiplier = 2;
nameStart += LittleEndianConsts.SHORT_SIZE;
} else {
+ multiplier = 1;
nameLength = std[nameStart];
}
@@ -237,12 +236,10 @@ public final class StyleDescription {
result.append("[STD]: '");
result.append(_name);
result.append("'");
- result.append(("\nStdfBase:\t" + _stdfBase).replaceAll("\n",
- "\n "));
- result.append(("\nStdfPost2000:\t" + _stdfPost2000).replaceAll(
- "\n", "\n "));
+ result.append(("\nStdfBase:\t" + _stdfBase).replace("\n", "\n "));
+ result.append(("\nStdfPost2000:\t" + _stdfPost2000).replace("\n", "\n "));
for (UPX upx : _upxs) {
- result.append(("\nUPX:\t" + upx).replaceAll("\n", "\n "));
+ result.append(("\nUPX:\t" + upx).replace("\n", "\n "));
}
return result.toString();
}
diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/types/LFOAbstractType.java b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/types/LFOAbstractType.java
index fe5b723330..a1eac0085a 100644
--- a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/types/LFOAbstractType.java
+++ b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/types/LFOAbstractType.java
@@ -117,28 +117,23 @@ public abstract class LFOAbstractType
field_6_grfhic, field_7_unused3);
}
- public String toString()
- {
- StringBuilder builder = new StringBuilder();
-
- builder.append("[LFO]\n");
- builder.append( " .lsid = " );
- builder.append(" ( ").append( field_1_lsid ).append( " )\n" );
- builder.append( " .unused1 = " );
- builder.append(" ( ").append( field_2_unused1 ).append( " )\n" );
- builder.append( " .unused2 = " );
- builder.append(" ( ").append( field_3_unused2 ).append( " )\n" );
- builder.append( " .clfolvl = " );
- builder.append(" ( ").append( field_4_clfolvl ).append( " )\n" );
- builder.append( " .ibstFltAutoNum = " );
- builder.append(" ( ").append( field_5_ibstFltAutoNum ).append( " )\n" );
- builder.append( " .grfhic = " );
- builder.append(" ( ").append( field_6_grfhic == null ? "null" : field_6_grfhic.toString().replaceAll( "\n", "\n " ) ).append( " )\n" );
- builder.append( " .unused3 = " );
- builder.append(" ( ").append( field_7_unused3 ).append( " )\n" );
-
- builder.append("[/LFO]");
- return builder.toString();
+ public String toString() {
+ return "[LFO]\n" +
+ " .lsid = " +
+ " ( " + field_1_lsid + " )\n" +
+ " .unused1 = " +
+ " ( " + field_2_unused1 + " )\n" +
+ " .unused2 = " +
+ " ( " + field_3_unused2 + " )\n" +
+ " .clfolvl = " +
+ " ( " + field_4_clfolvl + " )\n" +
+ " .ibstFltAutoNum = " +
+ " ( " + field_5_ibstFltAutoNum + " )\n" +
+ " .grfhic = " +
+ " ( " + (field_6_grfhic == null ? "null" : field_6_grfhic.toString().replace("\n", "\n ")) + " )\n" +
+ " .unused3 = " +
+ " ( " + field_7_unused3 + " )\n" +
+ "[/LFO]";
}
/**