sonar fixes

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1832735 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andreas Beeker 2018-06-02 13:01:14 +00:00
parent d879a2d3c8
commit 87f7eac9c5
13 changed files with 118 additions and 1972 deletions

View File

@ -111,18 +111,18 @@ public enum FontGroup {
* @return the FontGroup
*/
public static List<FontGroupRange> getFontGroupRanges(final String runText) {
List<FontGroupRange> ttrList = new ArrayList<>();
final List<FontGroupRange> ttrList = new ArrayList<>();
if (runText == null || runText.isEmpty()) {
return ttrList;
}
FontGroupRange ttrLast = null;
final int rlen = (runText != null) ? runText.length() : 0;
final int rlen = runText.length();
for(int cp, i = 0, charCount; i < rlen; i += charCount) {
cp = runText.codePointAt(i);
charCount = Character.charCount(cp);
// don't switch the font group for a few default characters supposedly available in all fonts
FontGroup tt;
final FontGroup tt;
if (ttrLast != null && " \n\r".indexOf(cp) > -1) {
tt = ttrLast.fontGroup;
} else {

View File

@ -67,12 +67,10 @@ import org.apache.poi.util.SuppressForbidden;
/**
* Translates Graphics2D calls into PowerPoint.
*
* @author Yegor Kozlov
*/
public final class SLGraphics extends Graphics2D implements Cloneable {
public class SLGraphics extends Graphics2D implements Cloneable {
protected POILogger log = POILogFactory.getLogger(this.getClass());
private static final POILogger LOG = POILogFactory.getLogger(SLGraphics.class);
//The ppt object to write into.
private GroupShape<?,?> _group;
@ -303,7 +301,8 @@ public final class SLGraphics extends Graphics2D implements Cloneable {
float ascent = layout.getAscent();
float width = (float) Math.floor(layout.getAdvance());
/**
/*
* Even if top and bottom margins are set to 0 PowerPoint
* always sets extra space between the text and its bounding box.
*
@ -384,8 +383,8 @@ public final class SLGraphics extends Graphics2D implements Cloneable {
*/
@NotImplemented
public void clip(Shape s){
if (log.check(POILogger.WARN)) {
log.log(POILogger.WARN, "Not implemented");
if (LOG.check(POILogger.WARN)) {
LOG.log(POILogger.WARN, "Not implemented");
}
}
@ -407,8 +406,8 @@ public final class SLGraphics extends Graphics2D implements Cloneable {
*/
@NotImplemented
public Shape getClip(){
if (log.check(POILogger.WARN)) {
log.log(POILogger.WARN, "Not implemented");
if (LOG.check(POILogger.WARN)) {
LOG.log(POILogger.WARN, "Not implemented");
}
return null;
}
@ -676,8 +675,8 @@ public final class SLGraphics extends Graphics2D implements Cloneable {
public boolean drawImage(Image img, int x, int y,
Color bgcolor,
ImageObserver observer){
if (log.check(POILogger.WARN)) {
log.log(POILogger.WARN, "Not implemented");
if (LOG.check(POILogger.WARN)) {
LOG.log(POILogger.WARN, "Not implemented");
}
return false;
@ -726,8 +725,8 @@ public final class SLGraphics extends Graphics2D implements Cloneable {
int width, int height,
Color bgcolor,
ImageObserver observer){
if (log.check(POILogger.WARN)) {
log.log(POILogger.WARN, "Not implemented");
if (LOG.check(POILogger.WARN)) {
LOG.log(POILogger.WARN, "Not implemented");
}
return false;
@ -786,8 +785,8 @@ public final class SLGraphics extends Graphics2D implements Cloneable {
int dx1, int dy1, int dx2, int dy2,
int sx1, int sy1, int sx2, int sy2,
ImageObserver observer){
if (log.check(POILogger.WARN)) {
log.log(POILogger.WARN, "Not implemented");
if (LOG.check(POILogger.WARN)) {
LOG.log(POILogger.WARN, "Not implemented");
}
return false;
}
@ -851,8 +850,8 @@ public final class SLGraphics extends Graphics2D implements Cloneable {
int sx1, int sy1, int sx2, int sy2,
Color bgcolor,
ImageObserver observer){
if (log.check(POILogger.WARN)) {
log.log(POILogger.WARN, "Not implemented");
if (LOG.check(POILogger.WARN)) {
LOG.log(POILogger.WARN, "Not implemented");
}
return false;
}
@ -892,8 +891,8 @@ public final class SLGraphics extends Graphics2D implements Cloneable {
@NotImplemented
public boolean drawImage(Image img, int x, int y,
ImageObserver observer) {
if (log.check(POILogger.WARN)) {
log.log(POILogger.WARN, "Not implemented");
if (LOG.check(POILogger.WARN)) {
LOG.log(POILogger.WARN, "Not implemented");
}
return false;
}
@ -1079,8 +1078,8 @@ public final class SLGraphics extends Graphics2D implements Cloneable {
*/
@NotImplemented
public void setClip(Shape clip) {
if (log.check(POILogger.WARN)) {
log.log(POILogger.WARN, "Not implemented");
if (LOG.check(POILogger.WARN)) {
LOG.log(POILogger.WARN, "Not implemented");
}
}
@ -1102,11 +1101,10 @@ public final class SLGraphics extends Graphics2D implements Cloneable {
* @since JDK1.1
*/
public Rectangle getClipBounds(){
Shape c = getClip();
if (c==null) {
return null;
if (LOG.check(POILogger.WARN)) {
LOG.log(POILogger.WARN, "Not implemented");
}
return c.getBounds();
return null;
}
/**
@ -1379,8 +1377,8 @@ public final class SLGraphics extends Graphics2D implements Cloneable {
*/
@NotImplemented
public void setComposite(Composite comp){
if (log.check(POILogger.WARN)) {
log.log(POILogger.WARN, "Not implemented");
if (LOG.check(POILogger.WARN)) {
LOG.log(POILogger.WARN, "Not implemented");
}
}
@ -1393,8 +1391,8 @@ public final class SLGraphics extends Graphics2D implements Cloneable {
*/
@NotImplemented
public Composite getComposite(){
if (log.check(POILogger.WARN)) {
log.log(POILogger.WARN, "Not implemented");
if (LOG.check(POILogger.WARN)) {
LOG.log(POILogger.WARN, "Not implemented");
}
return null;
}
@ -1537,8 +1535,8 @@ public final class SLGraphics extends Graphics2D implements Cloneable {
*/
@NotImplemented
public void drawString(AttributedCharacterIterator iterator, float x, float y) {
if (log.check(POILogger.WARN)) {
log.log(POILogger.WARN, "Not implemented");
if (LOG.check(POILogger.WARN)) {
LOG.log(POILogger.WARN, "Not implemented");
}
}
@ -1644,8 +1642,8 @@ public final class SLGraphics extends Graphics2D implements Cloneable {
*/
@NotImplemented
public boolean drawImage(Image img, AffineTransform xform, ImageObserver obs) {
if (log.check(POILogger.WARN)) {
log.log(POILogger.WARN, "Not implemented");
if (LOG.check(POILogger.WARN)) {
LOG.log(POILogger.WARN, "Not implemented");
}
return false;
}
@ -1690,8 +1688,8 @@ public final class SLGraphics extends Graphics2D implements Cloneable {
public boolean drawImage(Image img, int x, int y,
int width, int height,
ImageObserver observer) {
if (log.check(POILogger.WARN)) {
log.log(POILogger.WARN, "Not implemented");
if (LOG.check(POILogger.WARN)) {
LOG.log(POILogger.WARN, "Not implemented");
}
return false;
}
@ -1741,8 +1739,8 @@ public final class SLGraphics extends Graphics2D implements Cloneable {
*/
@NotImplemented
public void setXORMode(Color c1) {
if (log.check(POILogger.WARN)) {
log.log(POILogger.WARN, "Not implemented");
if (LOG.check(POILogger.WARN)) {
LOG.log(POILogger.WARN, "Not implemented");
}
}
@ -1755,8 +1753,8 @@ public final class SLGraphics extends Graphics2D implements Cloneable {
*/
@NotImplemented
public void setPaintMode() {
if (log.check(POILogger.WARN)) {
log.log(POILogger.WARN, "Not implemented");
if (LOG.check(POILogger.WARN)) {
LOG.log(POILogger.WARN, "Not implemented");
}
}
@ -1793,8 +1791,8 @@ public final class SLGraphics extends Graphics2D implements Cloneable {
*/
@NotImplemented
public void drawRenderedImage(RenderedImage img, AffineTransform xform) {
if (log.check(POILogger.WARN)) {
log.log(POILogger.WARN, "Not implemented");
if (LOG.check(POILogger.WARN)) {
LOG.log(POILogger.WARN, "Not implemented");
}
}
@ -1821,8 +1819,8 @@ public final class SLGraphics extends Graphics2D implements Cloneable {
*/
@NotImplemented
public void drawRenderableImage(RenderableImage img, AffineTransform xform) {
if (log.check(POILogger.WARN)) {
log.log(POILogger.WARN, "Not implemented");
if (LOG.check(POILogger.WARN)) {
LOG.log(POILogger.WARN, "Not implemented");
}
}

View File

@ -632,7 +632,7 @@ public class EvaluationConditionalFormatRule implements Comparable<EvaluationCon
for (int c = region.getFirstColumn(); c <= region.getLastColumn(); c++) {
Cell cell = row.getCell(c);
final ValueAndFormat cv = getCellValue(cell);
if (cv != null && (withText || cv.isNumber()) ) {
if (withText || cv.isNumber()) {
allValues.add(cv);
}
}
@ -646,13 +646,19 @@ public class EvaluationConditionalFormatRule implements Comparable<EvaluationCon
private ValueAndFormat getCellValue(Cell cell) {
if (cell != null) {
final CellType type = cell.getCellType();
if (type == CellType.NUMERIC || (type == CellType.FORMULA && cell.getCachedFormulaResultType() == CellType.NUMERIC) ) {
return new ValueAndFormat(Double.valueOf(cell.getNumericCellValue()), cell.getCellStyle().getDataFormatString(), decimalTextFormat);
} else if (type == CellType.STRING || (type == CellType.FORMULA && cell.getCachedFormulaResultType() == CellType.STRING) ) {
return new ValueAndFormat(cell.getStringCellValue(), cell.getCellStyle().getDataFormatString());
} else if (type == CellType.BOOLEAN || (type == CellType.FORMULA && cell.getCachedFormulaResultType() == CellType.BOOLEAN) ) {
return new ValueAndFormat(cell.getStringCellValue(), cell.getCellStyle().getDataFormatString());
final String format = cell.getCellStyle().getDataFormatString();
CellType type = cell.getCellType();
if (type == CellType.FORMULA) {
type = cell.getCachedFormulaResultType();
}
switch (type) {
case NUMERIC:
return new ValueAndFormat(Double.valueOf(cell.getNumericCellValue()), format, decimalTextFormat);
case STRING:
case BOOLEAN:
return new ValueAndFormat(cell.getStringCellValue(), format);
default:
break;
}
}
return new ValueAndFormat("", "");

View File

@ -59,14 +59,15 @@ public enum TableStyleType {
int firstStart = table.getStartColIndex();
int secondStart = firstStart + c1Stripe;
int c = cell.getCol();
final int c = cell.getCol();
// look for the stripe containing c, accounting for the style element stripe size
// could do fancy math, but tables can't be that wide, a simple loop is fine
// if not in this type of stripe, return null
while (true) {
if (firstStart > c) break;
if (c >= firstStart && c <= secondStart -1) return new CellRangeAddress(table.getStartRowIndex(), table.getEndRowIndex(), firstStart, secondStart - 1);
while (firstStart <= c) {
if (c >= firstStart && c <= secondStart -1) {
return new CellRangeAddress(table.getStartRowIndex(), table.getEndRowIndex(), firstStart, secondStart - 1);
}
firstStart = secondStart + c2Stripe;
secondStart = firstStart + c1Stripe;
}
@ -86,14 +87,15 @@ public enum TableStyleType {
int firstStart = table.getStartColIndex();
int secondStart = firstStart + c1Stripe;
int c = cell.getCol();
final int c = cell.getCol();
// look for the stripe containing c, accounting for the style element stripe size
// could do fancy math, but tables can't be that wide, a simple loop is fine
// if not in this type of stripe, return null
while (true) {
if (firstStart > c) break;
if (c >= secondStart && c <= secondStart + c2Stripe -1) return new CellRangeAddress(table.getStartRowIndex(), table.getEndRowIndex(), secondStart, secondStart + c2Stripe - 1);
while (firstStart <= c) {
if (c >= secondStart && c <= secondStart + c2Stripe -1) {
return new CellRangeAddress(table.getStartRowIndex(), table.getEndRowIndex(), secondStart, secondStart + c2Stripe - 1);
}
firstStart = secondStart + c2Stripe;
secondStart = firstStart + c1Stripe;
}
@ -113,14 +115,15 @@ public enum TableStyleType {
int firstStart = table.getStartRowIndex() + table.getHeaderRowCount();
int secondStart = firstStart + c1Stripe;
int c = cell.getRow();
final int c = cell.getRow();
// look for the stripe containing c, accounting for the style element stripe size
// could do fancy math, but tables can't be that wide, a simple loop is fine
// if not in this type of stripe, return null
while (true) {
if (firstStart > c) break;
if (c >= firstStart && c <= secondStart -1) return new CellRangeAddress(firstStart, secondStart - 1, table.getStartColIndex(), table.getEndColIndex());
while (firstStart <= c) {
if (c >= firstStart && c <= secondStart -1) {
return new CellRangeAddress(firstStart, secondStart - 1, table.getStartColIndex(), table.getEndColIndex());
}
firstStart = secondStart + c2Stripe;
secondStart = firstStart + c1Stripe;
}
@ -140,14 +143,15 @@ public enum TableStyleType {
int firstStart = table.getStartRowIndex() + table.getHeaderRowCount();
int secondStart = firstStart + c1Stripe;
int c = cell.getRow();
final int c = cell.getRow();
// look for the stripe containing c, accounting for the style element stripe size
// could do fancy math, but tables can't be that wide, a simple loop is fine
// if not in this type of stripe, return null
while (true) {
if (firstStart > c) break;
if (c >= secondStart && c <= secondStart +c2Stripe -1) return new CellRangeAddress(secondStart, secondStart + c2Stripe - 1, table.getStartColIndex(), table.getEndColIndex());
while (firstStart <= c) {
if (c >= secondStart && c <= secondStart +c2Stripe -1) {
return new CellRangeAddress(secondStart, secondStart + c2Stripe - 1, table.getStartColIndex(), table.getEndColIndex());
}
firstStart = secondStart + c2Stripe;
secondStart = firstStart + c1Stripe;
}

View File

@ -1,29 +0,0 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.openxml4j.opc;
/**
* Specifies the encryption option for parts in a Package.
*
* @author Julien Chable
* @version 0.1
*/
public enum EncryptionOption {
/** No encryption. */
NONE
}

View File

@ -244,7 +244,6 @@ public final class PackageRelationshipCollection implements
* The relationship ID to remove.
*/
public void removeRelationship(String id) {
if (relationshipsByID != null && relationshipsByType != null) {
PackageRelationship rel = relationshipsByID.get(id);
if (rel != null) {
relationshipsByID.remove(rel.getId());
@ -252,7 +251,6 @@ public final class PackageRelationshipCollection implements
internalRelationshipsByTargetName.values().remove(rel);
}
}
}
/**
* Retrieves a relationship by its index in the collection.
@ -413,28 +411,23 @@ public final class PackageRelationshipCollection implements
@Override
public String toString() {
String str;
if (relationshipsByID == null) {
str = "relationshipsByID=null";
} else {
str = relationshipsByID.size() + " relationship(s) = [";
}
String str = relationshipsByID.size() + " relationship(s) = [";
if ((relationshipPart != null) && (relationshipPart._partName != null)) {
str = str + "," + relationshipPart._partName;
str += relationshipPart._partName;
} else {
str = str + ",relationshipPart=null";
str += "relationshipPart=null";
}
// Source of this relationship
if ((sourcePart != null) && (sourcePart._partName != null)) {
str = str + "," + sourcePart._partName;
str += "," + sourcePart._partName;
} else {
str = str + ",sourcePart=null";
str += ",sourcePart=null";
}
if (partName != null) {
str = str + "," + partName;
str += "," + partName;
} else {
str = str + ",uri=null)";
str += ",uri=null)";
}
return str + "]";
}

View File

@ -316,7 +316,7 @@ public class SignatureInfo implements SignatureConfigurable {
} catch (InvalidFormatException e) {
LOG.log(POILogger.WARN, "Reference to signature is invalid.", e);
}
} while (sigPart == null);
} while (sigRelPart == null);
return new SignaturePart(sigRelPart, signatureConfig);
}

View File

@ -32,12 +32,15 @@ import org.apache.poi.util.IOUtils;
*/
public abstract class HPBFPart {
private byte[] data;
private final String[] path;
/**
* @param path the path to the part, eg Contents or Quill, QuillSub, CONTENTS
*/
public HPBFPart(DirectoryNode baseDir, String[] path) throws IOException {
this.path = path;
DirectoryNode dir = getDir(path, baseDir);
DirectoryNode dir = getDir(baseDir, path);
String name = path[path.length-1];
if (!dir.hasEntry(name)) {
@ -45,11 +48,12 @@ public abstract class HPBFPart {
}
// Grab the data from the part stream
InputStream is = dir.createDocumentInputStream(name);
try (InputStream is = dir.createDocumentInputStream(name)) {
data = IOUtils.toByteArray(is);
is.close();
}
private DirectoryNode getDir(String[] path, DirectoryNode baseDir) {
}
private static DirectoryNode getDir(DirectoryNode baseDir, String[] path) {
DirectoryNode dir = baseDir;
for(int i=0; i<path.length-1; i++) {
try {
@ -64,9 +68,6 @@ public abstract class HPBFPart {
public void writeOut(DirectoryNode baseDir) throws IOException {
String[] path = getPath();
if (path == null) {
return;
}
// Ensure that all parent directories exist
DirectoryNode dir = baseDir;
@ -97,7 +98,9 @@ public abstract class HPBFPart {
* Returns the raw data that makes up
* this document part.
*/
public final byte[] getData() { return data; }
public final byte[] getData() {
return data;
}
protected final void setData(byte data[]) {
this.data = data.clone();
@ -106,5 +109,7 @@ public abstract class HPBFPart {
/**
* Returns
*/
public final String[] getPath() {return null;}
public final String[] getPath() {
return path;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -113,11 +113,7 @@ public class HSLFTabStopPropCollection extends TextProp {
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result
+ ((tabStops == null) ? 0 : tabStops.hashCode());
return result;
return 31 * super.hashCode() + tabStops.hashCode();
}
@Override

View File

@ -338,7 +338,7 @@ public class TextPropCollection {
result = prime * result + charactersCovered;
result = prime * result + maskSpecial;
result = prime * result + indentLevel;
result = prime * result + ((textProps == null) ? 0 : textProps.hashCode());
result = prime * result + textProps.hashCode();
return result;
}
/**

View File

@ -193,9 +193,6 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFShape,HSLFText
private void supplySheet(HSLFSheet sheet) {
this._sheet = sheet;
if (_runs == null) {
return;
}
for (HSLFTextRun rt : _runs) {
rt.updateSheet();
}

View File

@ -27,9 +27,6 @@ import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
/**
* @author Ryan Ackley
*/
@Internal
public final class ListTables
{
@ -169,10 +166,8 @@ public final class ListTables
{
final int prime = 31;
int result = 1;
result = prime * result
+ ( ( _listMap == null ) ? 0 : _listMap.hashCode() );
result = prime * result
+ ( ( _plfLfo == null ) ? 0 : _plfLfo.hashCode() );
result = prime * result + _listMap.hashCode();
result = prime * result + ( ( _plfLfo == null ) ? 0 : _plfLfo.hashCode() );
return result;
}
@ -186,12 +181,7 @@ public final class ListTables
if ( getClass() != obj.getClass() )
return false;
ListTables other = (ListTables) obj;
if ( _listMap == null )
{
if ( other._listMap != null )
return false;
}
else if ( !_listMap.equals( other._listMap ) )
if ( !_listMap.equals( other._listMap ) )
return false;
if ( _plfLfo == null )
{