house keeping - fixes for sonarqube blockers

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1634255 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andreas Beeker 2014-10-25 21:32:03 +00:00
parent e409054f89
commit f818d1fdb7
15 changed files with 147 additions and 77 deletions

View File

@ -17,17 +17,26 @@
package org.apache.poi.hwpf;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.usermodel.*;
import org.apache.poi.hwpf.model.*;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.io.*;
import org.apache.poi.hwpf.model.StyleDescription;
import org.apache.poi.hwpf.model.StyleSheet;
import org.apache.poi.hwpf.usermodel.CharacterRun;
import org.apache.poi.hwpf.usermodel.Paragraph;
import org.apache.poi.hwpf.usermodel.Range;
public final class Word2Forrest
{
Writer _out;
HWPFDocument _doc;
@SuppressWarnings("unused")
public Word2Forrest(HWPFDocument doc, OutputStream stream)
throws IOException, UnsupportedEncodingException
{
@ -216,7 +225,7 @@ public final class Word2Forrest
new Word2Forrest(new HWPFDocument(new FileInputStream(args[0])), out);
out.close();
}
catch (Throwable t)
catch (Exception t)
{
t.printStackTrace();
}

View File

@ -41,6 +41,7 @@ import org.apache.poi.poifs.eventfilesystem.POIFSReader;
* @author Rainer Klute <a
* href="mailto:klute@rainer-klute.de">&lt;klute@rainer-klute.de&gt;</a>
*/
@SuppressWarnings("serial")
public class POIBrowser extends JFrame
{
@ -99,7 +100,7 @@ public class POIBrowser extends JFrame
{
System.err.println(filename + ": " + ex);
}
catch (Throwable t)
catch (Exception t)
{
System.err.println("Unexpected exception while reading \"" +
filename + "\":");

View File

@ -70,7 +70,7 @@ public class TreeReaderListener implements POIFSReaderListener
* <p>Maps filenames and POI document paths to their associated
* tree nodes.</p>
*/
protected Map pathToNode;
protected Map<Object,MutableTreeNode> pathToNode;
/**
* <p>The name of the file this {@link TreeReaderListener}
@ -99,7 +99,7 @@ public class TreeReaderListener implements POIFSReaderListener
{
this.filename = filename;
this.rootNode = rootNode;
pathToNode = new HashMap(15); // Should be a reasonable guess.
pathToNode = new HashMap<Object,MutableTreeNode>(15); // Should be a reasonable guess.
}
@ -146,7 +146,7 @@ public class TreeReaderListener implements POIFSReaderListener
d = new DocumentDescriptor(event.getName(), event.getPath(),
is, nrOfBytes);
}
catch (Throwable t)
catch (Exception t)
{
System.err.println
("Unexpected exception while processing " +

View File

@ -175,7 +175,7 @@ public class ExcelAntTask extends Task {
try {
Class.forName("org.apache.poi.hssf.usermodel.HSSFWorkbook");
Class.forName("org.apache.poi.ss.usermodel.WorkbookFactory");
} catch (Throwable e) {
} catch (Exception e) {
throw new BuildException(
"The <classpath> for <excelant> must include poi.jar and poi-ooxml.jar " +
"if not in Ant's own classpath. Processing .xlsx spreadsheets requires " +

View File

@ -120,4 +120,8 @@ public class CustomProperty extends MutableProperty
return (int) this.getID();
}
@Override
public boolean equals(Object o) {
return (o instanceof CustomProperty) ? equalsContents(o) : false;
}
}

View File

@ -72,9 +72,21 @@ public final class WorkbookRecordList implements Iterable<Record> {
return records.iterator();
}
/**
* Find the given record in the record list by identity and removes it
*
* @param record the identical record to be searched for
*/
public void remove( Object record ) {
int i = records.indexOf(record);
this.remove(i);
// can't use List.indexOf here because it checks the records for equality and not identity
int i = 0;
for (Record r : records) {
if (r == record) {
remove(i);
break;
}
i++;
}
}
public void remove( int pos )

View File

@ -475,7 +475,15 @@ public final class FontRecord extends StandardRecord {
field_7_family == other.field_7_family &&
field_8_charset == other.field_8_charset &&
field_9_zero == other.field_9_zero &&
field_11_font_name.equals(other.field_11_font_name)
stringEquals(this.field_11_font_name, other.field_11_font_name)
;
}
public boolean equals(Object o) {
return (o instanceof FontRecord) ? sameProperties((FontRecord)o) : false;
}
private static boolean stringEquals(String s1, String s2) {
return (s1 == s2 || (s1 != null && s1.equals(s2)));
}
}

View File

@ -18,7 +18,13 @@
package org.apache.poi.poifs.property;
import java.io.IOException;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
/**
* Directory property
@ -117,18 +123,6 @@ public class DirectoryProperty extends Property implements Parent { // TODO - fi
public static class PropertyComparator implements Comparator<Property> {
/**
* Object equality, implemented as object identity
*
* @param o Object we're being compared to
*
* @return true if identical, else false
*/
public boolean equals(Object o)
{
return this == o;
}
/**
* compare method. Assumes both parameters are non-null
* instances of Property. One property is less than another if

View File

@ -52,7 +52,7 @@ public final class OOXMLLite {
try {
_classes = ClassLoader.class.getDeclaredField("classes");
_classes.setAccessible(true);
} catch (Throwable e) {
} catch (Exception e) {
throw new RuntimeException(e);
}
}

View File

@ -17,8 +17,13 @@
package org.apache.poi.hdf.extractor;
import java.io.*;
import java.util.*;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Comment me
@ -38,8 +43,8 @@ public final class NewOleFile extends RandomAccessFile
private int[] _bbd_list;
protected int[] _big_block_depot;
protected int[] _small_block_depot;
Hashtable _propertySetsHT = new Hashtable();
Vector _propertySetsV = new Vector();
Map<String,PropertySet> _propertySetsHT = new HashMap<String,PropertySet>();
List<PropertySet> _propertySetsV = new ArrayList<PropertySet>();
public NewOleFile(String fileName, String mode) throws FileNotFoundException
{
@ -48,12 +53,13 @@ public final class NewOleFile extends RandomAccessFile
{
init();
}
catch(Throwable e)
catch(Exception e)
{
e.printStackTrace();
}
}
@SuppressWarnings("unused")
private void init() throws IOException
{
@ -101,6 +107,7 @@ public final class NewOleFile extends RandomAccessFile
initializePropertySets(rootChain);
}
@SuppressWarnings("unused")
public static void main(String args[])
{
try

View File

@ -17,7 +17,7 @@
package org.apache.poi.hdf.extractor;
import java.util.*;
import java.util.ArrayList;
/**
* Comment me
@ -28,9 +28,9 @@ import java.util.*;
public final class TableRow
{
TAP _descriptor;
ArrayList _cells;
ArrayList<String> _cells;
public TableRow(ArrayList cells, TAP descriptor)
public TableRow(ArrayList<String> cells, TAP descriptor)
{
_cells = cells;
_descriptor = descriptor;
@ -39,7 +39,7 @@ public final class TableRow
{
return _descriptor;
}
public ArrayList getCells()
public ArrayList<String> getCells()
{
return _cells;
}

View File

@ -18,14 +18,25 @@
package org.apache.poi.hdf.extractor;
import org.apache.poi.hdf.extractor.util.*;
import org.apache.poi.hdf.extractor.data.*;
import java.util.*;
import java.io.*;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.ArrayList;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.hdf.extractor.data.DOP;
import org.apache.poi.hdf.extractor.data.LVL;
import org.apache.poi.hdf.extractor.data.ListTables;
import org.apache.poi.hdf.extractor.util.BTreeSet;
import org.apache.poi.hdf.extractor.util.ChpxNode;
import org.apache.poi.hdf.extractor.util.NumberFormatter;
import org.apache.poi.hdf.extractor.util.PapxNode;
import org.apache.poi.hdf.extractor.util.PropertyNode;
import org.apache.poi.hdf.extractor.util.SepxNode;
import org.apache.poi.poifs.filesystem.DocumentEntry;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.util.LittleEndian;
/**
@ -70,9 +81,9 @@ public final class WordDocument {
/** used for XSL-FO table conversion*/
StringBuffer _cellBuffer;
/** used for XSL-FO table conversion*/
ArrayList _cells;
ArrayList<String> _cells;
/** used for XSL-FO table conversion*/
ArrayList _table;
ArrayList<TableRow> _table;
/** document's header and footer information*/
byte[] _plcfHdd;
@ -141,7 +152,7 @@ public final class WordDocument {
{
int textStart = Utils.convertBytesToInt(_header, 0x18);
int textEnd = Utils.convertBytesToInt(_header, 0x1c);
ArrayList textPieces = findProperties(textStart, textEnd, _text.root);
ArrayList<PropertyNode> textPieces = findProperties(textStart, textEnd, _text.root);
int size = textPieces.size();
for(int x = 0; x < size; x++)
@ -192,7 +203,7 @@ public final class WordDocument {
readFIB();
//get the SEPS for the main document text
ArrayList sections = findProperties(_fcMin, _fcMin + _ccpText, _sectionTable.root);
ArrayList<PropertyNode> sections = findProperties(_fcMin, _fcMin + _ccpText, _sectionTable.root);
//iterate through sections, paragraphs, and character runs doing what
//you will with the data.
@ -674,11 +685,12 @@ public final class WordDocument {
_sectionCounter++;
}
@SuppressWarnings("unused")
private int calculateHeaderHeight(int start, int end, int pageWidth)
{
ArrayList paragraphs = findProperties(start, end, _paragraphTable.root);
ArrayList<PropertyNode> paragraphs = findProperties(start, end, _paragraphTable.root);
int size = paragraphs.size();
ArrayList lineHeights = new ArrayList();
ArrayList<Integer> lineHeights = new ArrayList<Integer>();
//StyleContext context = StyleContext.getDefaultStyleContext();
for(int x = 0; x < size; x++)
@ -690,7 +702,7 @@ public final class WordDocument {
int lineWidth = 0;
int maxHeight = 0;
ArrayList textRuns = findProperties(parStart, parEnd, _characterTable.root);
ArrayList<PropertyNode> textRuns = findProperties(parStart, parEnd, _characterTable.root);
int charSize = textRuns.size();
//StringBuffer lineBuffer = new StringBuffer();
@ -710,7 +722,7 @@ public final class WordDocument {
int charStart = Math.max(parStart, charNode.getStart());
int charEnd = Math.min(parEnd, charNode.getEnd());
ArrayList text = findProperties(charStart, charEnd, _text.root);
ArrayList<PropertyNode> text = findProperties(charStart, charEnd, _text.root);
int textSize = text.size();
StringBuffer buf = new StringBuffer();
@ -770,6 +782,7 @@ public final class WordDocument {
return context.getFontMetrics(font);
}*/
@SuppressWarnings("unused")
private String createRegion(boolean before, HeaderFooter header, SEP sep, String name)
{
if(header.isEmpty())
@ -818,6 +831,7 @@ public final class WordDocument {
// marginBottom + "pt\" " + region + "/>";
}
@SuppressWarnings("unused")
private String createRegion(String where, String name)
{
return "<fo:region-" + where + " overflow=\"scroll\" region-name=\"" + name + "\"/>";
@ -859,7 +873,7 @@ public final class WordDocument {
{
BTreeSet.BTreeNode root = paragraphTable.root;
ArrayList pars = findProperties(start, end, root);
ArrayList<PropertyNode> pars = findProperties(start, end, root);
//root = characterTable.root;
int size = pars.size();
@ -910,7 +924,7 @@ public final class WordDocument {
{
if(_table == null)
{
_table = new ArrayList();
_table = new ArrayList<TableRow>();
}
TAP tap = (TAP)StyleSheet.uncompressProperty(papx, new TAP(), _styleSheet);
TableRow nextRow = new TableRow(_cells, tap);
@ -937,6 +951,7 @@ public final class WordDocument {
}
@SuppressWarnings("unused")
private void addListParagraphContent(LVL lvl, StringBuffer blockBuffer, PAP pap,
PapxNode currentNode, int start, int end,
StyleDescription std)
@ -945,7 +960,7 @@ public final class WordDocument {
addParagraphProperties(pap, blockBuffer);
ArrayList charRuns = findProperties(Math.max(currentNode.getStart(), start),
ArrayList<PropertyNode> charRuns = findProperties(Math.max(currentNode.getStart(), start),
Math.min(currentNode.getEnd(), end),
_characterTable.root);
int len = charRuns.size();
@ -1003,7 +1018,7 @@ public final class WordDocument {
int charStart = Math.max(charNode.getStart(), currentNode.getStart());
int charEnd = Math.min(charNode.getEnd(), currentNode.getEnd());
ArrayList textRuns = findProperties(charStart, charEnd, _text.root);
ArrayList<PropertyNode> textRuns = findProperties(charStart, charEnd, _text.root);
int textRunLen = textRuns.size();
for(int y = 0; y < textRunLen; y++)
{
@ -1031,7 +1046,7 @@ public final class WordDocument {
{
addParagraphProperties(pap, blockBuffer);
ArrayList charRuns = findProperties(Math.max(currentNode.getStart(), start),
ArrayList<PropertyNode> charRuns = findProperties(Math.max(currentNode.getStart(), start),
Math.min(currentNode.getEnd(), end),
_characterTable.root);
int len = charRuns.size();
@ -1046,7 +1061,7 @@ public final class WordDocument {
int charStart = Math.max(charNode.getStart(), currentNode.getStart());
int charEnd = Math.min(charNode.getEnd(), currentNode.getEnd());
ArrayList textRuns = findProperties(charStart, charEnd, _text.root);
ArrayList<PropertyNode> textRuns = findProperties(charStart, charEnd, _text.root);
int textRunLen = textRuns.size();
for(int y = 0; y < textRunLen; y++)
{
@ -1092,7 +1107,7 @@ public final class WordDocument {
if(_cells == null)
{
_cells = new ArrayList();
_cells = new ArrayList<String>();
}
closeLine(_cellBuffer);
closeBlock(_cellBuffer);
@ -1279,9 +1294,9 @@ public final class WordDocument {
/**
* finds all chpx's that are between start and end
*/
private ArrayList findProperties(int start, int end, BTreeSet.BTreeNode root)
private ArrayList<PropertyNode> findProperties(int start, int end, BTreeSet.BTreeNode root)
{
ArrayList results = new ArrayList();
ArrayList<PropertyNode> results = new ArrayList<PropertyNode>();
BTreeSet.Entry[] entries = root._entries;
for(int x = 0; x < entries.length; x++)
@ -1300,7 +1315,7 @@ public final class WordDocument {
{
if(child != null)
{
ArrayList beforeItems = findProperties(start, end, child);
ArrayList<PropertyNode> beforeItems = findProperties(start, end, child);
results.addAll(beforeItems);
}
results.add(xNode);
@ -1315,7 +1330,7 @@ public final class WordDocument {
{
if(child != null)
{
ArrayList beforeItems = findProperties(start, end, child);
ArrayList<PropertyNode> beforeItems = findProperties(start, end, child);
results.addAll(beforeItems);
}
break;
@ -1323,7 +1338,7 @@ public final class WordDocument {
}
else if(child != null)
{
ArrayList afterItems = findProperties(start, end, child);
ArrayList<PropertyNode> afterItems = findProperties(start, end, child);
results.addAll(afterItems);
}
}
@ -1358,9 +1373,10 @@ public final class WordDocument {
{
buf.append("</fo:block>\r\n");
}
private ArrayList findPAPProperties(int start, int end, BTreeSet.BTreeNode root)
@SuppressWarnings("unused")
private ArrayList<PropertyNode> findPAPProperties(int start, int end, BTreeSet.BTreeNode root)
{
ArrayList results = new ArrayList();
ArrayList<PropertyNode> results = new ArrayList<PropertyNode>();
BTreeSet.Entry[] entries = root._entries;
for(int x = 0; x < entries.length; x++)
@ -1378,7 +1394,7 @@ public final class WordDocument {
{
if(child != null)
{
ArrayList beforeItems = findPAPProperties(start, end, child);
ArrayList<PropertyNode> beforeItems = findPAPProperties(start, end, child);
results.addAll(beforeItems);
}
results.add(papxNode);
@ -1388,7 +1404,7 @@ public final class WordDocument {
{
if(child != null)
{
ArrayList beforeItems = findPAPProperties(start, end, child);
ArrayList<PropertyNode> beforeItems = findPAPProperties(start, end, child);
results.addAll(beforeItems);
}
break;
@ -1396,7 +1412,7 @@ public final class WordDocument {
}
else if(child != null)
{
ArrayList afterItems = findPAPProperties(start, end, child);
ArrayList<PropertyNode> afterItems = findPAPProperties(start, end, child);
results.addAll(afterItems);
}
}
@ -1468,6 +1484,7 @@ public final class WordDocument {
_headerBuffer.append("</fo:simple-page-master>\r\n");
return thisPage;
}
@SuppressWarnings("unused")
private void addBorder(StringBuffer buf, short[] brc, String where)
{
if((brc[0] & 0xff00) != 0 && brc[0] != -1)
@ -1497,7 +1514,7 @@ public final class WordDocument {
test.flush();
test.close();
}
catch(Throwable t)
catch(Exception t)
{
t.printStackTrace();
}
@ -1750,7 +1767,7 @@ public final class WordDocument {
StringBuffer rowBuffer = tableBodyBuffer;
TableRow row = (TableRow)_table.get(x);
TAP tap = row.getTAP();
ArrayList cells = row.getCells();
ArrayList<String> cells = row.getCells();
if(tap._fTableHeader)
{

View File

@ -24,7 +24,19 @@ import java.util.ArrayList;
import java.util.List;
import org.apache.poi.hdf.event.HDFLowLevelParsingListener;
import org.apache.poi.hdf.model.hdftypes.*;
import org.apache.poi.hdf.model.hdftypes.CHPFormattedDiskPage;
import org.apache.poi.hdf.model.hdftypes.ChpxNode;
import org.apache.poi.hdf.model.hdftypes.DocumentProperties;
import org.apache.poi.hdf.model.hdftypes.FileInformationBlock;
import org.apache.poi.hdf.model.hdftypes.FontTable;
import org.apache.poi.hdf.model.hdftypes.FormattedDiskPage;
import org.apache.poi.hdf.model.hdftypes.ListTables;
import org.apache.poi.hdf.model.hdftypes.PAPFormattedDiskPage;
import org.apache.poi.hdf.model.hdftypes.PapxNode;
import org.apache.poi.hdf.model.hdftypes.PlexOfCps;
import org.apache.poi.hdf.model.hdftypes.SepxNode;
import org.apache.poi.hdf.model.hdftypes.StyleSheet;
import org.apache.poi.hdf.model.hdftypes.TextPiece;
import org.apache.poi.hdf.model.util.ParsingState;
import org.apache.poi.poifs.filesystem.DocumentEntry;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
@ -56,6 +68,7 @@ public final class HDFObjectFactory {
byte[] _tableBuffer;
@SuppressWarnings("unused")
public static void main(String args[])
{
try
@ -63,7 +76,7 @@ public final class HDFObjectFactory {
HDFObjectFactory f = new HDFObjectFactory(new FileInputStream("c:\\test.doc"));
int k = 0;
}
catch(Throwable t)
catch(Exception t)
{
t.printStackTrace();
}
@ -115,9 +128,9 @@ public final class HDFObjectFactory {
this(istream, null);
}
public static List getTypes(InputStream istream) throws IOException
public static List<FileInformationBlock> getTypes(InputStream istream) throws IOException
{
List results = new ArrayList(1);
List<FileInformationBlock> results = new ArrayList<FileInformationBlock>(1);
//do Ole stuff
POIFSFileSystem filesystem = new POIFSFileSystem(istream);
@ -355,6 +368,7 @@ public final class HDFObjectFactory {
/**
* intializes the Paragraph Properties BTree
*/
@SuppressWarnings("unused")
private void initParagraphProperties()
{
//paragraphs
@ -458,6 +472,7 @@ public final class HDFObjectFactory {
/**
* initializes the SectionProperties BTree
*/
@SuppressWarnings("unused")
private void initSectionProperties()
{

View File

@ -17,9 +17,12 @@
package org.apache.poi.hwpf;
import java.io.*;
import java.io.FileInputStream;
import org.apache.poi.hwpf.usermodel.*;
import org.apache.poi.hwpf.usermodel.CharacterRun;
import org.apache.poi.hwpf.usermodel.Paragraph;
import org.apache.poi.hwpf.usermodel.Range;
import org.apache.poi.hwpf.usermodel.Section;
public final class QuickTest
{
@ -80,7 +83,7 @@ public final class QuickTest
// }
}
catch (Throwable t)
catch (Exception t)
{
t.printStackTrace();
}

View File

@ -368,7 +368,7 @@ public class WordToTextConverter extends AbstractWordConverter
DirectoryNode.class );
extractor = createExtractor.invoke( null, directoryNode );
}
catch ( Error exc )
catch ( Exception exc )
{
// no extractor in classpath
logger.log( POILogger.WARN, "There is an OLE object entry '",