sonar fixes - blocker
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1839745 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
14335fd152
commit
3c3f2a3fe3
@ -158,6 +158,11 @@ public final class EntryUtils {
|
|||||||
: new DocumentDelegate((DocumentEntry)entry);
|
: new DocumentDelegate((DocumentEntry)entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return dir.getName().hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object other) {
|
public boolean equals(Object other) {
|
||||||
if (!(other instanceof DirectoryDelegate)) {
|
if (!(other instanceof DirectoryDelegate)) {
|
||||||
@ -191,6 +196,11 @@ public final class EntryUtils {
|
|||||||
this.doc = doc;
|
this.doc = doc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return doc.getName().hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object other) {
|
public boolean equals(Object other) {
|
||||||
if (!(other instanceof DocumentDelegate)) {
|
if (!(other instanceof DocumentDelegate)) {
|
||||||
|
@ -127,10 +127,11 @@ public class FileBackedDataSource extends DataSource {
|
|||||||
@Override
|
@Override
|
||||||
public void copyTo(OutputStream stream) throws IOException {
|
public void copyTo(OutputStream stream) throws IOException {
|
||||||
// Wrap the OutputSteam as a channel
|
// Wrap the OutputSteam as a channel
|
||||||
WritableByteChannel out = Channels.newChannel(stream);
|
try (WritableByteChannel out = Channels.newChannel(stream)) {
|
||||||
// Now do the transfer
|
// Now do the transfer
|
||||||
channel.transferTo(0, channel.size(), out);
|
channel.transferTo(0, channel.size(), out);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long size() throws IOException {
|
public long size() throws IOException {
|
||||||
|
@ -65,7 +65,7 @@ public enum TableStyleType {
|
|||||||
// could do fancy math, but tables can't be that wide, a simple loop is fine
|
// 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
|
// if not in this type of stripe, return null
|
||||||
while (firstStart <= c) {
|
while (firstStart <= c) {
|
||||||
if (c >= firstStart && c <= secondStart -1) {
|
if (c <= secondStart -1) {
|
||||||
return new CellRangeAddress(table.getStartRowIndex(), table.getEndRowIndex(), firstStart, secondStart - 1);
|
return new CellRangeAddress(table.getStartRowIndex(), table.getEndRowIndex(), firstStart, secondStart - 1);
|
||||||
}
|
}
|
||||||
firstStart = secondStart + c2Stripe;
|
firstStart = secondStart + c2Stripe;
|
||||||
@ -121,7 +121,7 @@ public enum TableStyleType {
|
|||||||
// could do fancy math, but tables can't be that wide, a simple loop is fine
|
// 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
|
// if not in this type of stripe, return null
|
||||||
while (firstStart <= c) {
|
while (firstStart <= c) {
|
||||||
if (c >= firstStart && c <= secondStart -1) {
|
if (c <= secondStart -1) {
|
||||||
return new CellRangeAddress(firstStart, secondStart - 1, table.getStartColIndex(), table.getEndColIndex());
|
return new CellRangeAddress(firstStart, secondStart - 1, table.getStartColIndex(), table.getEndColIndex());
|
||||||
}
|
}
|
||||||
firstStart = secondStart + c2Stripe;
|
firstStart = secondStart + c2Stripe;
|
||||||
|
@ -101,7 +101,7 @@ public final class ZipPackage extends OPCPackage {
|
|||||||
*/
|
*/
|
||||||
ZipPackage(InputStream in, PackageAccess access) throws IOException {
|
ZipPackage(InputStream in, PackageAccess access) throws IOException {
|
||||||
super(access);
|
super(access);
|
||||||
ZipArchiveThresholdInputStream zis = ZipHelper.openZipStream(in);
|
ZipArchiveThresholdInputStream zis = ZipHelper.openZipStream(in); // NOSONAR
|
||||||
try {
|
try {
|
||||||
this.zipArchive = new ZipInputStreamZipEntrySource(zis);
|
this.zipArchive = new ZipInputStreamZipEntrySource(zis);
|
||||||
} catch (final IOException e) {
|
} catch (final IOException e) {
|
||||||
|
@ -24,6 +24,8 @@ import java.util.List;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
import org.apache.commons.collections4.iterators.IteratorIterable;
|
||||||
|
import org.apache.commons.collections4.iterators.ReverseListIterator;
|
||||||
import org.apache.poi.util.Beta;
|
import org.apache.poi.util.Beta;
|
||||||
import org.apache.poi.util.Internal;
|
import org.apache.poi.util.Internal;
|
||||||
import org.apache.poi.util.LocaleUtil;
|
import org.apache.poi.util.LocaleUtil;
|
||||||
@ -97,8 +99,8 @@ public class XDDFTextParagraph {
|
|||||||
public XDDFTextRun appendLineBreak() {
|
public XDDFTextRun appendLineBreak() {
|
||||||
CTTextLineBreak br = _p.addNewBr();
|
CTTextLineBreak br = _p.addNewBr();
|
||||||
// by default, line break has the font properties of the last text run
|
// by default, line break has the font properties of the last text run
|
||||||
for (int i = _runs.size() - 1; i <= 0; i--) {
|
for (XDDFTextRun tr : new IteratorIterable<>(new ReverseListIterator<>(_runs))) {
|
||||||
CTTextCharacterProperties prevProps = _runs.get(i).getProperties();
|
CTTextCharacterProperties prevProps = tr.getProperties();
|
||||||
// let's find one that is not undefined
|
// let's find one that is not undefined
|
||||||
if (prevProps != null) {
|
if (prevProps != null) {
|
||||||
br.setRPr((CTTextCharacterProperties) prevProps.copy());
|
br.setRPr((CTTextCharacterProperties) prevProps.copy());
|
||||||
|
@ -931,8 +931,10 @@ public class SXSSFWorkbook implements Workbook {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Substitute the template entries with the generated sheet data files
|
//Substitute the template entries with the generated sheet data files
|
||||||
final ZipEntrySource source = new ZipFileZipEntrySource(new ZipSecureFile(tmplFile));
|
try (ZipSecureFile zf = new ZipSecureFile(tmplFile);
|
||||||
|
ZipFileZipEntrySource source = new ZipFileZipEntrySource(zf)) {
|
||||||
injectData(source, stream);
|
injectData(source, stream);
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
deleted = tmplFile.delete();
|
deleted = tmplFile.delete();
|
||||||
}
|
}
|
||||||
|
@ -292,7 +292,7 @@ public class XWPFRun implements ISDTContents, IRunElement, CharacterRun {
|
|||||||
String color = null;
|
String color = null;
|
||||||
if (run.isSetRPr()) {
|
if (run.isSetRPr()) {
|
||||||
CTRPr pr = getRunProperties(false);
|
CTRPr pr = getRunProperties(false);
|
||||||
if (pr.isSetColor()) {
|
if (pr != null && pr.isSetColor()) {
|
||||||
CTColor clr = pr.getColor();
|
CTColor clr = pr.getColor();
|
||||||
color = clr.xgetVal().getStringValue();
|
color = clr.xgetVal().getStringValue();
|
||||||
}
|
}
|
||||||
|
@ -46,8 +46,8 @@ import org.apache.poi.hslf.model.MovieShape;
|
|||||||
import org.apache.poi.hslf.record.*;
|
import org.apache.poi.hslf.record.*;
|
||||||
import org.apache.poi.hslf.record.SlideListWithText.SlideAtomsSet;
|
import org.apache.poi.hslf.record.SlideListWithText.SlideAtomsSet;
|
||||||
import org.apache.poi.poifs.filesystem.DirectoryNode;
|
import org.apache.poi.poifs.filesystem.DirectoryNode;
|
||||||
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
|
||||||
import org.apache.poi.poifs.filesystem.Ole10Native;
|
import org.apache.poi.poifs.filesystem.Ole10Native;
|
||||||
|
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
||||||
import org.apache.poi.sl.usermodel.MasterSheet;
|
import org.apache.poi.sl.usermodel.MasterSheet;
|
||||||
import org.apache.poi.sl.usermodel.PictureData.PictureType;
|
import org.apache.poi.sl.usermodel.PictureData.PictureType;
|
||||||
import org.apache.poi.sl.usermodel.Resources;
|
import org.apache.poi.sl.usermodel.Resources;
|
||||||
@ -595,6 +595,9 @@ public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagrap
|
|||||||
// The order of slides is defined by the order of slide atom sets in the
|
// The order of slides is defined by the order of slide atom sets in the
|
||||||
// SlideListWithText container.
|
// SlideListWithText container.
|
||||||
SlideListWithText slwt = _documentRecord.getSlideSlideListWithText();
|
SlideListWithText slwt = _documentRecord.getSlideSlideListWithText();
|
||||||
|
if (slwt == null) {
|
||||||
|
throw new IllegalStateException("Slide record not defined.");
|
||||||
|
}
|
||||||
SlideAtomsSet[] sas = slwt.getSlideAtomsSets();
|
SlideAtomsSet[] sas = slwt.getSlideAtomsSets();
|
||||||
|
|
||||||
SlideAtomsSet tmp = sas[oldSlideNumber - 1];
|
SlideAtomsSet tmp = sas[oldSlideNumber - 1];
|
||||||
@ -635,6 +638,9 @@ public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagrap
|
|||||||
}
|
}
|
||||||
|
|
||||||
SlideListWithText slwt = _documentRecord.getSlideSlideListWithText();
|
SlideListWithText slwt = _documentRecord.getSlideSlideListWithText();
|
||||||
|
if (slwt == null) {
|
||||||
|
throw new IllegalStateException("Slide record not defined.");
|
||||||
|
}
|
||||||
SlideAtomsSet[] sas = slwt.getSlideAtomsSets();
|
SlideAtomsSet[] sas = slwt.getSlideAtomsSets();
|
||||||
|
|
||||||
List<Record> records = new ArrayList<>();
|
List<Record> records = new ArrayList<>();
|
||||||
@ -678,12 +684,14 @@ public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagrap
|
|||||||
records.addAll(Arrays.asList(ns.getSlideRecords()));
|
records.addAll(Arrays.asList(ns.getSlideRecords()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!na.isEmpty()) {
|
||||||
|
nslwt.setSlideAtomsSets(na.toArray(new SlideAtomsSet[0]));
|
||||||
|
nslwt.setChildRecord(records.toArray(new Record[0]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (na.isEmpty()) {
|
if (na.isEmpty()) {
|
||||||
_documentRecord.removeSlideListWithText(nslwt);
|
_documentRecord.removeSlideListWithText(nslwt);
|
||||||
} else {
|
|
||||||
nslwt.setSlideAtomsSets(na.toArray(new SlideAtomsSet[0]));
|
|
||||||
nslwt.setChildRecord(records.toArray(new Record[0]));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1113,7 +1121,7 @@ public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagrap
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MasterSheet<HSLFShape,HSLFTextParagraph> createMasterSheet() throws IOException {
|
public MasterSheet<HSLFShape,HSLFTextParagraph> createMasterSheet() {
|
||||||
// TODO implement or throw exception if not supported
|
// TODO implement or throw exception if not supported
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
package org.apache.poi.hwpf.converter;
|
package org.apache.poi.hwpf.converter;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -114,15 +115,14 @@ public class WordToTextConverter extends AbstractWordConverter
|
|||||||
serializer.transform( domSource, streamResult );
|
serializer.transform( domSource, streamResult );
|
||||||
}
|
}
|
||||||
|
|
||||||
static Document process( File docFile ) throws Exception
|
private static Document process( File docFile ) throws IOException, ParserConfigurationException {
|
||||||
{
|
try (final HWPFDocumentCore wordDocument = AbstractWordUtils.loadDoc( docFile )) {
|
||||||
final HWPFDocumentCore wordDocument = AbstractWordUtils
|
|
||||||
.loadDoc( docFile );
|
|
||||||
WordToTextConverter wordToTextConverter = new WordToTextConverter(
|
WordToTextConverter wordToTextConverter = new WordToTextConverter(
|
||||||
XMLHelper.getDocumentBuilderFactory().newDocumentBuilder().newDocument() );
|
XMLHelper.getDocumentBuilderFactory().newDocumentBuilder().newDocument());
|
||||||
wordToTextConverter.processDocument( wordDocument );
|
wordToTextConverter.processDocument(wordDocument);
|
||||||
return wordToTextConverter.getDocument();
|
return wordToTextConverter.getDocument();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private AtomicInteger noteCounters = new AtomicInteger( 1 );
|
private AtomicInteger noteCounters = new AtomicInteger( 1 );
|
||||||
|
|
||||||
@ -153,12 +153,14 @@ public class WordToTextConverter extends AbstractWordConverter
|
|||||||
* @param document
|
* @param document
|
||||||
* XML DOM Document used as storage for text pieces
|
* XML DOM Document used as storage for text pieces
|
||||||
*/
|
*/
|
||||||
public WordToTextConverter( Document document )
|
@SuppressWarnings("WeakerAccess")
|
||||||
|
public WordToTextConverter(Document document )
|
||||||
{
|
{
|
||||||
this.textDocumentFacade = new TextDocumentFacade( document );
|
this.textDocumentFacade = new TextDocumentFacade( document );
|
||||||
}
|
}
|
||||||
|
|
||||||
public WordToTextConverter( TextDocumentFacade textDocumentFacade )
|
@SuppressWarnings("unused")
|
||||||
|
public WordToTextConverter(TextDocumentFacade textDocumentFacade )
|
||||||
{
|
{
|
||||||
this.textDocumentFacade = textDocumentFacade;
|
this.textDocumentFacade = textDocumentFacade;
|
||||||
}
|
}
|
||||||
@ -192,6 +194,7 @@ public class WordToTextConverter extends AbstractWordConverter
|
|||||||
return stringWriter.toString();
|
return stringWriter.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("WeakerAccess")
|
||||||
public boolean isOutputSummaryInformation()
|
public boolean isOutputSummaryInformation()
|
||||||
{
|
{
|
||||||
return outputSummaryInformation;
|
return outputSummaryInformation;
|
||||||
@ -275,7 +278,7 @@ public class WordToTextConverter extends AbstractWordConverter
|
|||||||
|
|
||||||
currentBlock.appendChild( textDocumentFacade.createText( " ("
|
currentBlock.appendChild( textDocumentFacade.createText( " ("
|
||||||
+ UNICODECHAR_ZERO_WIDTH_SPACE
|
+ UNICODECHAR_ZERO_WIDTH_SPACE
|
||||||
+ hyperlink.replaceAll( "\\/", UNICODECHAR_ZERO_WIDTH_SPACE
|
+ hyperlink.replaceAll( "/", UNICODECHAR_ZERO_WIDTH_SPACE
|
||||||
+ "\\/" + UNICODECHAR_ZERO_WIDTH_SPACE )
|
+ "\\/" + UNICODECHAR_ZERO_WIDTH_SPACE )
|
||||||
+ UNICODECHAR_ZERO_WIDTH_SPACE + ")" ) );
|
+ UNICODECHAR_ZERO_WIDTH_SPACE + ")" ) );
|
||||||
}
|
}
|
||||||
@ -307,9 +310,7 @@ public class WordToTextConverter extends AbstractWordConverter
|
|||||||
block.appendChild( textDocumentFacade.createText( "\n" ) );
|
block.appendChild( textDocumentFacade.createText( "\n" ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void processNote( HWPFDocument wordDocument, Element block,
|
private void processNote( HWPFDocument wordDocument, Element block, Range noteTextRange ) {
|
||||||
Range noteTextRange )
|
|
||||||
{
|
|
||||||
final int noteIndex = noteCounters.getAndIncrement();
|
final int noteIndex = noteCounters.getAndIncrement();
|
||||||
block.appendChild( textDocumentFacade
|
block.appendChild( textDocumentFacade
|
||||||
.createText( UNICODECHAR_ZERO_WIDTH_SPACE + "[" + noteIndex
|
.createText( UNICODECHAR_ZERO_WIDTH_SPACE + "[" + noteIndex
|
||||||
@ -457,7 +458,8 @@ public class WordToTextConverter extends AbstractWordConverter
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOutputSummaryInformation( boolean outputDocumentInformation )
|
@SuppressWarnings("unused")
|
||||||
|
public void setOutputSummaryInformation(boolean outputDocumentInformation )
|
||||||
{
|
{
|
||||||
this.outputSummaryInformation = outputDocumentInformation;
|
this.outputSummaryInformation = outputDocumentInformation;
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,8 @@
|
|||||||
package org.apache.poi.hwpf.model;
|
package org.apache.poi.hwpf.model;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
import org.apache.poi.util.Internal;
|
import org.apache.poi.util.Internal;
|
||||||
import org.apache.poi.util.NotImplemented;
|
import org.apache.poi.util.NotImplemented;
|
||||||
|
|
||||||
@ -102,6 +104,12 @@ public class OldTextPiece extends TextPiece {
|
|||||||
return 42; // any arbitrary constant will do
|
return 42; // any arbitrary constant will do
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object other) {
|
||||||
|
return other instanceof OldTextPiece &&
|
||||||
|
Arrays.equals(rawBytes, ((OldTextPiece)other).rawBytes);
|
||||||
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "OldTextPiece from " + getStart() + " to " + getEnd() + " ("
|
return "OldTextPiece from " + getStart() + " to " + getEnd() + " ("
|
||||||
+ getPieceDescriptor() + ")";
|
+ getPieceDescriptor() + ")";
|
||||||
|
Loading…
Reference in New Issue
Block a user