diff --git a/core/modules/core/src/com/haulmont/yarg/formatters/impl/AbstractFormatter.java b/core/modules/core/src/com/haulmont/yarg/formatters/impl/AbstractFormatter.java index 516afcda..716f79c7 100644 --- a/core/modules/core/src/com/haulmont/yarg/formatters/impl/AbstractFormatter.java +++ b/core/modules/core/src/com/haulmont/yarg/formatters/impl/AbstractFormatter.java @@ -30,6 +30,7 @@ import com.haulmont.yarg.structure.ReportOutputType; import com.haulmont.yarg.structure.ReportTemplate; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.reflect.ConstructorUtils; import java.io.ByteArrayOutputStream; import java.io.OutputStream; @@ -39,6 +40,8 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +import static com.google.common.base.Preconditions.checkNotNull; + public abstract class AbstractFormatter implements ReportFormatter { public static final String SIMPLE_ALIAS_REGEXP = "\\$\\{([A-z0-9_]+?)\\}"; @@ -57,21 +60,22 @@ public abstract class AbstractFormatter implements ReportFormatter { protected ReportTemplate reportTemplate; protected ReportOutputType outputType; protected OutputStream outputStream; - protected Set supportedOutputTypes = new HashSet(); + protected Set supportedOutputTypes = new HashSet<>(); protected DefaultFormatProvider defaultFormatProvider; /** * Chain of responsibility for content inliners */ - protected List contentInliners = new ArrayList(); + protected List contentInliners = new ArrayList<>(); protected AbstractFormatter(FormatterFactoryInput formatterFactoryInput) { - Preconditions.checkNotNull("\"rootBand\" parameter can not be null", formatterFactoryInput.getRootBand()); - Preconditions.checkNotNull("\"reportTemplate\" parameter can not be null", formatterFactoryInput.getReportTemplate()); + checkNotNull(formatterFactoryInput.getRootBand(), "\"rootBand\" parameter can not be null"); + checkNotNull(formatterFactoryInput.getReportTemplate(), "\"reportTemplate\" parameter can not be null"); this.rootBand = formatterFactoryInput.getRootBand(); this.reportTemplate = formatterFactoryInput.getReportTemplate(); - this.outputType = (formatterFactoryInput.getOutputType() != null) ? formatterFactoryInput.getOutputType() : reportTemplate.getOutputType(); + this.outputType = (formatterFactoryInput.getOutputType() != null) + ? formatterFactoryInput.getOutputType() : reportTemplate.getOutputType(); this.outputStream = formatterFactoryInput.getOutputStream(); this.contentInliners.add(new BitmapContentInliner()); @@ -121,12 +125,14 @@ protected String formatValue(Object value, String parameterName, String fullPara if (formatString != null) { if (formatString.startsWith("class:")) { String className = formatString.replaceFirst("class:", ""); + ValueFormat valueFormat; try { - ValueFormat valueFormat = (ValueFormat) Class.forName(className).newInstance(); - valueString = valueFormat.format(value); - } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) { + Class valueFormatterClass = Class.forName(className); + valueFormat = (ValueFormat) ConstructorUtils.invokeConstructor(valueFormatterClass); + } catch (ReflectiveOperationException e) { throw new ReportingException("An error occurred while applying custom format", e); } + valueString = valueFormat.format(value); } else if (value == null) { valueString = ""; } else if (value instanceof Number) { @@ -185,7 +191,7 @@ protected String defaultFormat(Object value) { } protected String insertBandDataToString(BandData bandData, String resultStr) { - List parametersToInsert = new ArrayList(); + List parametersToInsert = new ArrayList<>(); Matcher matcher = UNIVERSAL_ALIAS_PATTERN.matcher(resultStr); while (matcher.find()) { parametersToInsert.add(unwrapParameterName(matcher.group())); @@ -223,7 +229,7 @@ protected BandData findBandByPath(String path) { } protected BandPathAndParameterName separateBandNameAndParameterName(String alias) { - List bandPathList = new ArrayList(); + List bandPathList = new ArrayList<>(); String[] pathParts = alias.split("\\."); BandData currentBand = rootBand; for (String pathPart : pathParts) { diff --git a/core/modules/core/src/com/haulmont/yarg/formatters/impl/DocxFormatter.java b/core/modules/core/src/com/haulmont/yarg/formatters/impl/DocxFormatter.java index bba05614..f091dbc3 100644 --- a/core/modules/core/src/com/haulmont/yarg/formatters/impl/DocxFormatter.java +++ b/core/modules/core/src/com/haulmont/yarg/formatters/impl/DocxFormatter.java @@ -96,7 +96,12 @@ public void renderDocument() { protected void updateTableOfContents() { try { MainDocumentPart documentPart = wordprocessingMLPackage.getMainDocumentPart(); - Document wmlDocumentEl = documentPart.getJaxbElement(); + Document wmlDocumentEl; + try { + wmlDocumentEl = documentPart.getContents(); + } catch (Docx4JException e) { + throw new RuntimeException("Unable to get document content", e); + } Body body = wmlDocumentEl.getBody(); TocFinder finder = new TocFinder(); diff --git a/core/modules/core/src/com/haulmont/yarg/formatters/impl/XLSFormatter.java b/core/modules/core/src/com/haulmont/yarg/formatters/impl/XLSFormatter.java index 5c0b508b..a91b3f71 100644 --- a/core/modules/core/src/com/haulmont/yarg/formatters/impl/XLSFormatter.java +++ b/core/modules/core/src/com/haulmont/yarg/formatters/impl/XLSFormatter.java @@ -76,18 +76,18 @@ public class XLSFormatter extends AbstractFormatter { protected int rowsAddedByVerticalBand = 0; protected int rowsAddedByHorizontalBand = 0; - protected Map> mergeRegionsForRangeNames = new HashMap>(); - protected Map templateToResultSheetsMapping = new HashMap(); - protected Map templateBounds = new HashMap(); + protected Map> mergeRegionsForRangeNames = new HashMap<>(); + protected Map templateToResultSheetsMapping = new HashMap<>(); + protected Map templateBounds = new HashMap<>(); protected AreaDependencyManager areaDependencyManager = new AreaDependencyManager(); protected Map> areasDependency = areaDependencyManager.getAreasDependency(); - protected List orderedPicturesId = new ArrayList(); - protected Map sheetToEscherAggregate = new HashMap(); + protected List orderedPicturesId = new ArrayList<>(); + protected Map sheetToEscherAggregate = new HashMap<>(); - protected Map drawingPatriarchsMap = new HashMap(); - protected List hints = new ArrayList(); + protected Map drawingPatriarchsMap = new HashMap<>(); + protected List hints = new ArrayList<>(); protected DocumentConverter documentConverter; @@ -304,7 +304,7 @@ protected void writeHorizontalBand(BandData band, HSSFSheet templateSheet, HSSFS if (crefs != null) { addRangeBounds(band, crefs); - ArrayList resultRows = new ArrayList(); + ArrayList resultRows = new ArrayList<>(); int currentRowNum = -1; int currentRowCount = -1; @@ -388,7 +388,7 @@ protected void writeVerticalBand(BandData band, HSSFSheet templateSheet, HSSFShe String rangeName = band.getName(); CellReference[] crefs = getRangeContent(templateWorkbook, rangeName); - Set addedRowNumbers = new HashSet(); + Set addedRowNumbers = new HashSet<>(); if (crefs != null) { addRangeBounds(band, crefs); @@ -501,7 +501,7 @@ protected void initMergeRegions(HSSFSheet currentSheet) { String name = aNamedRange.getNameName(); SheetRange sheetRange = new SheetRange(mergedRegion, currentSheet.getSheetName()); if (mergeRegionsForRangeNames.get(name) == null) { - ArrayList list = new ArrayList(); + ArrayList list = new ArrayList<>(); list.add(sheetRange); mergeRegionsForRangeNames.put(name, list); } else { diff --git a/core/modules/core/src/com/haulmont/yarg/formatters/impl/XlsxFormatter.java b/core/modules/core/src/com/haulmont/yarg/formatters/impl/XlsxFormatter.java index 9f57d627..dcab2ddd 100644 --- a/core/modules/core/src/com/haulmont/yarg/formatters/impl/XlsxFormatter.java +++ b/core/modules/core/src/com/haulmont/yarg/formatters/impl/XlsxFormatter.java @@ -205,7 +205,12 @@ protected void findVerticalDependencies() { protected void updateOutlines() { for (Document.SheetWrapper sheetWrapper : result.getWorksheets()) { - Worksheet resultWorksheet = sheetWrapper.getWorksheet().getJaxbElement(); + Worksheet resultWorksheet; + try { + resultWorksheet = sheetWrapper.getWorksheet().getContents(); + } catch (Docx4JException e) { + throw new RuntimeException("Unable to get worksheet contents"); + } Worksheet templateWorksheet = template.getSheetByName(sheetWrapper.getName()); if (templateWorksheet.getSheetFormatPr() != null) { @@ -312,14 +317,20 @@ protected void updateFormulas() { protected void updateConditionalFormatting() { for (Document.SheetWrapper sheetWrapper : result.getWorksheets()) { - Worksheet worksheet = sheetWrapper.getWorksheet().getJaxbElement(); + Worksheet worksheet; + try { + worksheet = sheetWrapper.getWorksheet().getContents(); + } catch (Docx4JException e) { + throw new RuntimeException("Unable to get worksheet contents"); + } + for (CTConditionalFormatting ctConditionalFormatting : worksheet.getConditionalFormatting()) { - List references = new ArrayList(); + List references = new ArrayList<>(); for (String ref : ctConditionalFormatting.getSqref()) { Range formulaRange = Range.fromRange(sheetWrapper.getName(), ref); for (Range templateRange : rangeDependencies.templates()) { if (templateRange.contains(formulaRange)) { - List resultRanges = new ArrayList(rangeDependencies.resultsForTemplate(templateRange)); + List resultRanges = new ArrayList<>(rangeDependencies.resultsForTemplate(templateRange)); for (Range resultRange : resultRanges) { Offset offset = calculateOffset(templateRange, resultRange); Range shift = formulaRange.copy().shift(offset.downOffset, offset.rightOffset); @@ -360,8 +371,8 @@ protected void processOuterFormulas(int formulaCount, CTCalcChain calculationCha for (Range templateRange : rangeDependencies.templates()) { if (templateRange.containsAny(formulaRanges)) { - List resultRanges = new ArrayList(rangeDependencies.resultsForTemplate(templateRange)); - List newRanges = new ArrayList(); + List resultRanges = new ArrayList<>(rangeDependencies.resultsForTemplate(templateRange)); + List newRanges = new ArrayList<>(); for (Range resultRange : resultRanges) { BandData bandData = bandsForRanges.bandForResultRange(resultRange); boolean hasSameFormulaBand = false; @@ -464,7 +475,11 @@ protected CTCalcChain getCalculationChain() { try { CalcChain part = (CalcChain) result.getPackage().getParts().get(new PartName("/xl/calcChain.xml")); if (part != null) { - calculationChain = part.getJaxbElement(); + try { + calculationChain = part.getContents(); + } catch (Docx4JException e) { + throw new RuntimeException("Unable to get contents of part", e); + } calculationChain.getC().clear(); } } catch (InvalidFormatException e) { @@ -473,7 +488,8 @@ protected CTCalcChain getCalculationChain() { return calculationChain; } - protected void updateFormula(Cell cellWithFormula, Range originalFormulaRange, Range formulaRange, CTCalcChain calculationChain, int formulaCount) { + protected void updateFormula(Cell cellWithFormula, Range originalFormulaRange, Range formulaRange, + CTCalcChain calculationChain, int formulaCount) { CTCellFormula formula = cellWithFormula.getF(); formula.setValue(formula.getValue().replace(originalFormulaRange.toRange(), formulaRange.toRange())); if (originalFormulaRange.isOneCellRange() && formulaRange.isOneCellRange()) { @@ -726,13 +742,13 @@ protected Row ensureNecessaryRowsCreated(Range templateRange, Worksheet resultSh } protected List copyCells(BandData band, Range templateRange, List resultSheetRows, Row firstRow, Worksheet resultSheet) { - List resultCells = new ArrayList(); + List resultCells = new ArrayList<>(); for (int i = 0; i <= templateRange.getLastRow() - templateRange.getFirstRow(); i++) { Range oneRowRange = new Range(templateRange.getSheet(), templateRange.getFirstColumn(), templateRange.getFirstRow() + i, templateRange.getLastColumn(), templateRange.getFirstRow() + i); Map cellsForOneRowRange = template.getCellsByRange(oneRowRange); - List templateCells = new ArrayList(cellsForOneRowRange.values()); + List templateCells = new ArrayList<>(cellsForOneRowRange.values()); Row templateRow = !templateCells.isEmpty() ? (Row) templateCells.get(0).getParent() : resultSheet.getSheetData().getRow().get(oneRowRange.getFirstRow() - 1); @@ -771,13 +787,10 @@ protected void createFakeTemplateCellsForEmptyOnes(Range oneRowRange, } } - Collections.sort(templateCells, new Comparator() { - @Override - public int compare(Cell o1, Cell o2) { - CellReference cellReference1 = referencesToCells.inverse().get(o1); - CellReference cellReference2 = referencesToCells.inverse().get(o2); - return cellReference1.compareTo(cellReference2); - } + templateCells.sort((o1, o2) -> { + CellReference cellReference1 = referencesToCells.inverse().get(o1); + CellReference cellReference2 = referencesToCells.inverse().get(o2); + return cellReference1.compareTo(cellReference2); }); } } @@ -846,7 +859,14 @@ protected List copyCells(Range templateRange, BandData bandData, Row newRo WorksheetPart worksheetPart = null; for (Document.SheetWrapper sheetWrapper : result.getWorksheets()) { - if (sheetWrapper.getWorksheet().getJaxbElement() == resultWorksheet) { + Worksheet contents; + try { + contents = sheetWrapper.getWorksheet().getContents(); + } catch (Docx4JException e) { + throw new RuntimeException("Unable to get worksheet contents", e); + } + + if (contents == resultWorksheet) { worksheetPart = sheetWrapper.getWorksheet(); } } @@ -1012,7 +1032,12 @@ protected void writeToOutputStream(SpreadsheetMLPackage mlPackage, OutputStream protected void updateHeaderAndFooter() { for (Document.SheetWrapper sheetWrapper : result.getWorksheets()) { - Worksheet worksheet = sheetWrapper.getWorksheet().getJaxbElement(); + Worksheet worksheet; + try { + worksheet = sheetWrapper.getWorksheet().getContents(); + } catch (Docx4JException e) { + throw new RuntimeException("Unable to get contents of worksheet", e); + } if (worksheet.getHeaderFooter() != null) { CTHeaderFooter headerFooter = worksheet.getHeaderFooter(); if (headerFooter.getOddHeader() != null) { @@ -1037,7 +1062,7 @@ protected void updateSheetNames() { } protected String insertBandDataToString(String resultStr) { - List parametersToInsert = new ArrayList(); + List parametersToInsert = new ArrayList<>(); Matcher matcher = UNIVERSAL_ALIAS_PATTERN.matcher(resultStr); while (matcher.find()) { parametersToInsert.add(unwrapParameterName(matcher.group())); diff --git a/core/modules/core/src/com/haulmont/yarg/formatters/impl/doc/connector/WinProcessManager.java b/core/modules/core/src/com/haulmont/yarg/formatters/impl/doc/connector/WinProcessManager.java index 17a7ca2d..2f553b23 100644 --- a/core/modules/core/src/com/haulmont/yarg/formatters/impl/doc/connector/WinProcessManager.java +++ b/core/modules/core/src/com/haulmont/yarg/formatters/impl/doc/connector/WinProcessManager.java @@ -18,13 +18,13 @@ import org.apache.commons.io.IOUtils; -import org.apache.commons.lang3.ObjectUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.IOException; import java.util.Collections; import java.util.List; +import java.util.Objects; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -69,7 +69,7 @@ public List findPid(String host, int port) { List r = IOUtils.readLines(process.getInputStream()); for (Object output : r) { NetStatInfo info = new NetStatInfo((String) output); - if (info.localPort == port && ObjectUtils.equals(host, info.localAddress)) + if (info.localPort == port && Objects.equals(host, info.localAddress)) return Collections.singletonList(info.pid); } } catch (IOException e) { diff --git a/core/modules/core/src/com/haulmont/yarg/formatters/impl/inline/AbstractInliner.java b/core/modules/core/src/com/haulmont/yarg/formatters/impl/inline/AbstractInliner.java index 9f723662..6f8370f5 100644 --- a/core/modules/core/src/com/haulmont/yarg/formatters/impl/inline/AbstractInliner.java +++ b/core/modules/core/src/com/haulmont/yarg/formatters/impl/inline/AbstractInliner.java @@ -230,7 +230,8 @@ public void inlineToXls(HSSFPatriarch patriarch, HSSFCell resultCell, Object par } @Override - public void inlineToDoc(OfficeComponent officeComponent, XTextRange textRange, XText destination, Object paramValue, Matcher paramsMatcher) throws Exception { + public void inlineToDoc(OfficeComponent officeComponent, XTextRange textRange, XText destination, Object paramValue, + Matcher paramsMatcher) throws Exception { try { if (paramValue != null) { Image image = new Image(paramValue, paramsMatcher); @@ -322,7 +323,7 @@ protected Part resolveTextPartForDOCX(Text text, WordprocessingMLPackage wordPac java.util.List sectionWrappers = wordPackage.getDocumentModel().getSections(); for (SectionWrapper sw : sectionWrappers) { HeaderFooterPolicy hfp = sw.getHeaderFooterPolicy(); - List parts = Arrays.asList(hfp.getFirstHeader(), hfp.getDefaultHeader(), hfp.getEvenHeader(), + List parts = Arrays.asList(hfp.getFirstHeader(), hfp.getDefaultHeader(), hfp.getEvenHeader(), hfp.getFirstFooter(), hfp.getDefaultFooter(), hfp.getEvenFooter()); for (Part part : parts) { TextMatchCallback callback = new TextMatchCallback(text); diff --git a/core/modules/core/src/com/haulmont/yarg/formatters/impl/xls/hints/CustomCellStyleHint.java b/core/modules/core/src/com/haulmont/yarg/formatters/impl/xls/hints/CustomCellStyleHint.java index f99cc9fe..cfac42d9 100644 --- a/core/modules/core/src/com/haulmont/yarg/formatters/impl/xls/hints/CustomCellStyleHint.java +++ b/core/modules/core/src/com/haulmont/yarg/formatters/impl/xls/hints/CustomCellStyleHint.java @@ -30,9 +30,6 @@ /** * Apply custom style to target cell - * - * @author artamonov - * @version $Id$ */ public class CustomCellStyleHint extends AbstractHint { private XlsFontCache fontCache; @@ -73,13 +70,13 @@ public void apply() { // color newStyle.setFillBackgroundColor(cellStyle.getFillBackgroundColor()); newStyle.setFillForegroundColor(cellStyle.getFillForegroundColor()); - newStyle.setFillPattern(cellStyle.getFillPattern()); + newStyle.setFillPattern(cellStyle.getFillPatternEnum()); // borders - newStyle.setBorderLeft(cellStyle.getBorderLeft()); - newStyle.setBorderRight(cellStyle.getBorderRight()); - newStyle.setBorderTop(cellStyle.getBorderTop()); - newStyle.setBorderBottom(cellStyle.getBorderBottom()); + newStyle.setBorderLeft(cellStyle.getBorderLeftEnum()); + newStyle.setBorderRight(cellStyle.getBorderRightEnum()); + newStyle.setBorderTop(cellStyle.getBorderTopEnum()); + newStyle.setBorderBottom(cellStyle.getBorderBottomEnum()); // border colors newStyle.setLeftBorderColor(cellStyle.getLeftBorderColor()); @@ -88,8 +85,8 @@ public void apply() { newStyle.setTopBorderColor(cellStyle.getTopBorderColor()); // alignment - newStyle.setAlignment(cellStyle.getAlignment()); - newStyle.setVerticalAlignment(cellStyle.getVerticalAlignment()); + newStyle.setAlignment(cellStyle.getAlignmentEnum()); + newStyle.setVerticalAlignment(cellStyle.getVerticalAlignmentEnum()); // misc DataFormat dataFormat = resultWorkbook.getCreationHelper().createDataFormat(); newStyle.setDataFormat(dataFormat.getFormat(cellStyle.getDataFormatString())); @@ -109,7 +106,7 @@ public void apply() { newFont.setItalic(cellFont.getItalic()); newFont.setStrikeout(cellFont.getStrikeout()); newFont.setTypeOffset(cellFont.getTypeOffset()); - newFont.setBoldweight(cellFont.getBoldweight()); + newFont.setBold(cellFont.getBold()); newFont.setCharSet(cellFont.getCharSet()); newFont.setColor(cellFont.getColor()); newFont.setUnderline(cellFont.getUnderline()); @@ -190,11 +187,11 @@ private void fixLeftCell(HSSFSheet sheet, int rowIndex, int columnIndex, HSSFCel HSSFCell leftCell = sheet.getRow(rowIndex).getCell(columnIndex); if (leftCell != null) { HSSFCellStyle leftCellStyle = leftCell.getCellStyle(); - if (leftCellStyle.getBorderRight() != cellStyle.getBorderLeft() || + if (leftCellStyle.getBorderRightEnum() != cellStyle.getBorderLeftEnum() || leftCellStyle.getRightBorderColor() != cellStyle.getLeftBorderColor()) { HSSFCellStyle draftLeftStyle = HSSFWorkbookHelper.createDetachedCellStyle(sheet.getWorkbook()); XslStyleHelper.cloneStyleRelations(leftCellStyle, draftLeftStyle); - draftLeftStyle.setBorderRight(cellStyle.getBorderLeft()); + draftLeftStyle.setBorderRight(cellStyle.getBorderLeftEnum()); draftLeftStyle.setRightBorderColor(cellStyle.getLeftBorderColor()); HSSFCellStyle newLeftStyle = styleCache.getCellStyleByTemplate(draftLeftStyle); if (newLeftStyle == null) { @@ -230,11 +227,11 @@ private void fixRightCell(HSSFSheet sheet, int rowIndex, int columnIndex, HSSFCe if (rightCell != null) { HSSFCellStyle rightCellStyle = rightCell.getCellStyle(); - if (rightCellStyle.getBorderLeft() != cellStyle.getBorderRight() || + if (rightCellStyle.getBorderLeftEnum() != cellStyle.getBorderRightEnum() || rightCellStyle.getLeftBorderColor() != cellStyle.getRightBorderColor()) { HSSFCellStyle draftRightStyle = HSSFWorkbookHelper.createDetachedCellStyle(sheet.getWorkbook()); XslStyleHelper.cloneStyleRelations(rightCellStyle, draftRightStyle); - draftRightStyle.setBorderLeft(cellStyle.getBorderRight()); + draftRightStyle.setBorderLeft(cellStyle.getBorderRightEnum()); draftRightStyle.setLeftBorderColor(cellStyle.getRightBorderColor()); HSSFCellStyle newRightStyle = styleCache.getCellStyleByTemplate(draftRightStyle); @@ -273,11 +270,11 @@ private void fixUpCell(HSSFSheet sheet, int rowIndex, int columnIndex, HSSFCellS if (upCell != null) { HSSFCellStyle upCellStyle = upCell.getCellStyle(); - if (upCellStyle.getBorderBottom() != cellStyle.getBorderTop() || + if (upCellStyle.getBorderBottomEnum() != cellStyle.getBorderTopEnum() || upCellStyle.getBottomBorderColor() != cellStyle.getTopBorderColor()) { HSSFCellStyle draftUpStyle = HSSFWorkbookHelper.createDetachedCellStyle(sheet.getWorkbook()); XslStyleHelper.cloneStyleRelations(upCellStyle, draftUpStyle); - draftUpStyle.setBorderBottom(cellStyle.getBorderTop()); + draftUpStyle.setBorderBottom(cellStyle.getBorderTopEnum()); draftUpStyle.setBottomBorderColor(cellStyle.getTopBorderColor()); HSSFCellStyle newUpStyle = styleCache.getCellStyleByTemplate(draftUpStyle); @@ -318,11 +315,11 @@ private void fixDownCell(HSSFSheet sheet, int rowIndex, int columnIndex, HSSFCel if (downCell != null) { HSSFCellStyle downCellStyle = downCell.getCellStyle(); - if (downCellStyle.getBorderTop() != cellStyle.getBorderBottom() || + if (downCellStyle.getBorderTopEnum() != cellStyle.getBorderBottomEnum() || downCellStyle.getTopBorderColor() != cellStyle.getBottomBorderColor()) { HSSFCellStyle draftDownStyle = HSSFWorkbookHelper.createDetachedCellStyle(sheet.getWorkbook()); XslStyleHelper.cloneStyleRelations(downCellStyle, draftDownStyle); - draftDownStyle.setBorderTop(cellStyle.getBorderBottom()); + draftDownStyle.setBorderTop(cellStyle.getBorderBottomEnum()); draftDownStyle.setTopBorderColor(cellStyle.getBottomBorderColor()); HSSFCellStyle newDownStyle = styleCache.getCellStyleByTemplate(draftDownStyle); diff --git a/core/modules/core/src/com/haulmont/yarg/formatters/impl/xlsx/Document.java b/core/modules/core/src/com/haulmont/yarg/formatters/impl/xlsx/Document.java index 6f957a02..b7c41368 100644 --- a/core/modules/core/src/com/haulmont/yarg/formatters/impl/xlsx/Document.java +++ b/core/modules/core/src/com/haulmont/yarg/formatters/impl/xlsx/Document.java @@ -36,14 +36,14 @@ public class Document { protected SpreadsheetMLPackage thePackage; - protected List worksheets = new ArrayList(); + protected List worksheets = new ArrayList<>(); - protected Map chartSpaces = new HashMap(); + protected Map chartSpaces = new HashMap<>(); protected Workbook workbook; protected SharedStrings sharedStrings; protected StyleSheet styleSheet; protected List pivotCacheDefinitions = new ArrayList<>(); - protected HashSet handled = new HashSet(); + protected HashSet handled = new HashSet<>(); public static Document create(SpreadsheetMLPackage thePackage) { Document document = new Document(); @@ -77,17 +77,24 @@ public List getPivotCacheDefinitions() { public Worksheet getSheetByName(String name) { for (Document.SheetWrapper sheetWrapper : worksheets) { if (sheetWrapper.getName().equals(name)) { - return sheetWrapper.getWorksheet().getJaxbElement(); + return getWorksheetContents(sheetWrapper); } } return null; } + public Worksheet getWorksheetContents(Document.SheetWrapper wrapper) { + try { + return wrapper.getWorksheet().getContents(); + } catch (Docx4JException e) { + throw new RuntimeException("Unable to get worksheet contents", e); + } + } public String getSheetName(Worksheet worksheet) { for (Document.SheetWrapper sheetWrapper : worksheets) { - if (worksheet == sheetWrapper.getWorksheet().getJaxbElement()) { + if (worksheet == getWorksheetContents(sheetWrapper)) { return sheetWrapper.getName(); } } @@ -98,7 +105,14 @@ public String getSheetName(Worksheet worksheet) { public String getCellValue(Cell cell) { if (cell.getV() == null) return null; if (cell.getT().equals(STCellType.S)) { - CTRst ctRst = sharedStrings.getJaxbElement().getSi().get(Integer.parseInt(cell.getV())); + CTSst jaxbElement; + try { + jaxbElement = sharedStrings.getContents(); + } catch (Docx4JException e) { + throw new RuntimeException("Unable to get strings contents", e); + } + + CTRst ctRst = jaxbElement.getSi().get(Integer.parseInt(cell.getV())); String value = null; if (ctRst.getT() != null) { @@ -138,7 +152,7 @@ public Map getCellsByRange(Range range) { Worksheet sheet = getSheetByName(range.getSheet()); SheetData data = sheet.getSheetData(); - Map result = new LinkedHashMap(); + Map result = new LinkedHashMap<>(); for (int i = 1; i <= data.getRow().size(); i++) { Row row = data.getRow().get(i - 1); if (range.getFirstRow() <= row.getR() && row.getR() <= range.getLastRow()) { @@ -182,11 +196,21 @@ private void traverse(Part parent, RelationshipsPart rp) { } if (part instanceof JaxbXmlPart) { - Object o = ((JaxbXmlPart) part).getJaxbElement(); + Object o; + try { + o = ((JaxbXmlPart) part).getContents(); + } catch (Docx4JException e) { + throw new RuntimeException("Unable to get part contents", e); + } if (o instanceof CTChartSpace) { Drawing drawing = (Drawing) parent; - CTDrawing ctDrawing = drawing.getJaxbElement(); + CTDrawing ctDrawing; + try { + ctDrawing = drawing.getContents(); + } catch (Docx4JException e) { + throw new RuntimeException("Unable to get drawing contents", e); + } Object anchorObj = ctDrawing.getEGAnchor().get(chartNum++); Range range = null; @@ -240,8 +264,8 @@ private void traverse(Part parent, RelationshipsPart rp) { public void clearWorkbook() { for (SheetWrapper sheet : worksheets) { - sheet.worksheet.getJaxbElement().getSheetData().getRow().clear(); - CTMergeCells mergeCells = sheet.worksheet.getJaxbElement().getMergeCells(); + getWorksheetContents(sheet).getSheetData().getRow().clear(); + CTMergeCells mergeCells = getWorksheetContents(sheet).getMergeCells(); if (mergeCells != null && mergeCells.getMergeCell() != null) { mergeCells.getMergeCell().clear(); }