git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1875979 13f79535-47bb-0310-9956-ffa450edef68tags/before_ooxml_3rd_edition
@@ -31,6 +31,7 @@ import java.util.List; | |||
import java.util.Map; | |||
import java.util.Optional; | |||
import java.util.function.Function; | |||
import java.util.function.Predicate; | |||
import javax.xml.namespace.QName; | |||
@@ -115,8 +116,6 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai | |||
private int chartIndex = 0; | |||
private POIXMLDocumentPart documentPart = null; | |||
protected List<XDDFChartAxis> axes = new ArrayList<>(); | |||
/** | |||
@@ -362,14 +361,14 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai | |||
} | |||
@Override | |||
public <R> Optional<R> findDefinedParagraphProperty(Function<CTTextParagraphProperties, Boolean> isSet, | |||
public <R> Optional<R> findDefinedParagraphProperty(Predicate<CTTextParagraphProperties> isSet, | |||
Function<CTTextParagraphProperties, R> getter) { | |||
// TODO Auto-generated method stub | |||
return Optional.empty(); | |||
} | |||
@Override | |||
public <R> Optional<R> findDefinedRunProperty(Function<CTTextCharacterProperties, Boolean> isSet, | |||
public <R> Optional<R> findDefinedRunProperty(Predicate<CTTextCharacterProperties> isSet, | |||
Function<CTTextCharacterProperties, R> getter) { | |||
// TODO Auto-generated method stub | |||
return Optional.empty(); | |||
@@ -578,23 +577,23 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai | |||
private Map<Long, XDDFChartAxis> getCategoryAxes() { | |||
CTPlotArea plotArea = getCTPlotArea(); | |||
int sizeOfArray = plotArea.sizeOfCatAxArray(); | |||
Map<Long, XDDFChartAxis> axes = new HashMap<>(sizeOfArray); | |||
Map<Long, XDDFChartAxis> axesMap = new HashMap<>(sizeOfArray); | |||
for (int i = 0; i < sizeOfArray; i++) { | |||
CTCatAx category = plotArea.getCatAxArray(i); | |||
axes.put(category.getAxId().getVal(), new XDDFCategoryAxis(category)); | |||
axesMap.put(category.getAxId().getVal(), new XDDFCategoryAxis(category)); | |||
} | |||
return axes; | |||
return axesMap; | |||
} | |||
private Map<Long, XDDFValueAxis> getValueAxes() { | |||
CTPlotArea plotArea = getCTPlotArea(); | |||
int sizeOfArray = plotArea.sizeOfValAxArray(); | |||
Map<Long, XDDFValueAxis> axes = new HashMap<>(sizeOfArray); | |||
Map<Long, XDDFValueAxis> axesMap = new HashMap<>(sizeOfArray); | |||
for (int i = 0; i < sizeOfArray; i++) { | |||
CTValAx values = plotArea.getValAxArray(i); | |||
axes.put(values.getAxId().getVal(), new XDDFValueAxis(values)); | |||
axesMap.put(values.getAxId().getVal(), new XDDFValueAxis(values)); | |||
} | |||
return axes; | |||
return axesMap; | |||
} | |||
public XDDFValueAxis createValueAxis(AxisPosition pos) { | |||
@@ -767,15 +766,14 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai | |||
*/ | |||
public PackageRelationship createRelationshipInChart(POIXMLRelation chartRelation, POIXMLFactory chartFactory, | |||
int chartIndex) { | |||
documentPart = createRelationship(chartRelation, chartFactory, chartIndex, true).getDocumentPart(); | |||
POIXMLDocumentPart documentPart = | |||
createRelationship(chartRelation, chartFactory, chartIndex, true).getDocumentPart(); | |||
return addRelation(null, chartRelation, documentPart).getRelationship(); | |||
} | |||
/** | |||
* if embedded part was null then create new part | |||
* | |||
* @param chartRelation | |||
* chart relation object | |||
* @param chartWorkbookRelation | |||
* chart workbook relation object | |||
* @param chartFactory | |||
@@ -784,8 +782,8 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai | |||
* @throws InvalidFormatException | |||
* @since POI 4.0.0 | |||
*/ | |||
private PackagePart createWorksheetPart(POIXMLRelation chartRelation, POIXMLRelation chartWorkbookRelation, | |||
POIXMLFactory chartFactory) throws InvalidFormatException { | |||
private PackagePart createWorksheetPart(POIXMLRelation chartWorkbookRelation, POIXMLFactory chartFactory) | |||
throws InvalidFormatException { | |||
PackageRelationship xlsx = createRelationshipInChart(chartWorkbookRelation, chartFactory, chartIndex); | |||
setExternalId(xlsx.getId()); | |||
return getTargetPart(xlsx); | |||
@@ -803,11 +801,10 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai | |||
public void saveWorkbook(XSSFWorkbook workbook) throws IOException, InvalidFormatException { | |||
PackagePart worksheetPart = getWorksheetPart(); | |||
if (worksheetPart == null) { | |||
POIXMLRelation chartRelation = getChartRelation(); | |||
POIXMLRelation chartWorkbookRelation = getChartWorkbookRelation(); | |||
POIXMLFactory chartFactory = getChartFactory(); | |||
if (chartRelation != null && chartWorkbookRelation != null && chartFactory != null) { | |||
worksheetPart = createWorksheetPart(chartRelation, chartWorkbookRelation, chartFactory); | |||
if (chartWorkbookRelation != null && chartFactory != null) { | |||
worksheetPart = createWorksheetPart(chartWorkbookRelation, chartFactory); | |||
} else { | |||
throw new InvalidFormatException("unable to determine chart relations"); | |||
} | |||
@@ -950,6 +947,9 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai | |||
*/ | |||
public CellReference setSheetTitle(String title, int column) { | |||
XSSFSheet sheet = getSheet(); | |||
if (sheet == null) { | |||
return null; | |||
} | |||
XSSFRow row = getRow(sheet, 0); | |||
XSSFCell cell = getCell(row, column); | |||
cell.setCellValue(title); | |||
@@ -1000,7 +1000,7 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai | |||
return null; | |||
} | |||
private void setWorksheetPartCommitted() throws InvalidFormatException { | |||
private void setWorksheetPartCommitted() { | |||
for (RelationPart part : getRelationParts()) { | |||
if (POIXMLDocument.PACK_OBJECT_REL_TYPE.equals(part.getRelationship().getRelationshipType())) { | |||
part.getDocumentPart().setCommitted(true); |
@@ -408,7 +408,10 @@ public abstract class XDDFChartAxis implements HasShapeProperties { | |||
} | |||
protected long getNextAxId(CTPlotArea plotArea) { | |||
long totalAxisCount = plotArea.sizeOfValAxArray() + plotArea.sizeOfCatAxArray() + plotArea.sizeOfDateAxArray() | |||
long totalAxisCount = 0L | |||
+ plotArea.sizeOfValAxArray() | |||
+ plotArea.sizeOfCatAxArray() | |||
+ plotArea.sizeOfDateAxArray() | |||
+ plotArea.sizeOfSerAxArray(); | |||
return totalAxisCount; | |||
} |
@@ -20,6 +20,7 @@ package org.apache.poi.xddf.usermodel.chart; | |||
import java.util.List; | |||
import java.util.Optional; | |||
import java.util.function.Function; | |||
import java.util.function.Predicate; | |||
import java.util.stream.Collectors; | |||
import org.apache.poi.util.Beta; | |||
@@ -195,14 +196,16 @@ public final class XDDFChartLegend implements TextContainer { | |||
legend.getOverlay().setVal(value); | |||
} | |||
@Override | |||
public <R> Optional<R> findDefinedParagraphProperty( | |||
Function<CTTextParagraphProperties, Boolean> isSet, | |||
Predicate<CTTextParagraphProperties> isSet, | |||
Function<CTTextParagraphProperties, R> getter) { | |||
return Optional.empty(); // chart legend has no (indirect) paragraph properties | |||
} | |||
@Override | |||
public <R> Optional<R> findDefinedRunProperty( | |||
Function<CTTextCharacterProperties, Boolean> isSet, | |||
Predicate<CTTextCharacterProperties> isSet, | |||
Function<CTTextCharacterProperties, R> getter) { | |||
return Optional.empty(); // chart legend has no (indirect) paragraph properties | |||
} |
@@ -19,6 +19,7 @@ package org.apache.poi.xddf.usermodel.chart; | |||
import java.util.Optional; | |||
import java.util.function.Function; | |||
import java.util.function.Predicate; | |||
import org.apache.poi.util.Beta; | |||
import org.apache.poi.util.Internal; | |||
@@ -113,14 +114,14 @@ public class XDDFLegendEntry implements TextContainer { | |||
@Override | |||
public <R> Optional<R> findDefinedParagraphProperty( | |||
Function<CTTextParagraphProperties, Boolean> isSet, | |||
Predicate<CTTextParagraphProperties> isSet, | |||
Function<CTTextParagraphProperties, R> getter) { | |||
return Optional.empty(); // legend entry has no (indirect) paragraph properties | |||
} | |||
@Override | |||
public <R> Optional<R> findDefinedRunProperty( | |||
Function<CTTextCharacterProperties, Boolean> isSet, | |||
Predicate<CTTextCharacterProperties> isSet, | |||
Function<CTTextCharacterProperties, R> getter) { | |||
return Optional.empty(); // legend entry has no (indirect) paragraph properties | |||
} |
@@ -19,6 +19,7 @@ package org.apache.poi.xddf.usermodel.text; | |||
import java.util.Optional; | |||
import java.util.function.Function; | |||
import java.util.function.Predicate; | |||
import org.apache.poi.util.Beta; | |||
import org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties; | |||
@@ -27,10 +28,10 @@ import org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraphProperties | |||
@Beta | |||
public interface TextContainer { | |||
<R> Optional<R> findDefinedParagraphProperty(Function<CTTextParagraphProperties, Boolean> isSet, | |||
<R> Optional<R> findDefinedParagraphProperty(Predicate<CTTextParagraphProperties> isSet, | |||
Function<CTTextParagraphProperties, R> getter); | |||
<R> Optional<R> findDefinedRunProperty(Function<CTTextCharacterProperties, Boolean> isSet, | |||
<R> Optional<R> findDefinedRunProperty(Predicate<CTTextCharacterProperties> isSet, | |||
Function<CTTextCharacterProperties, R> getter); | |||
} |
@@ -22,6 +22,7 @@ import java.util.List; | |||
import java.util.Locale; | |||
import java.util.Optional; | |||
import java.util.function.Function; | |||
import java.util.function.Predicate; | |||
import java.util.stream.Collectors; | |||
import org.apache.poi.util.Beta; | |||
@@ -337,12 +338,12 @@ public class XDDFTextBody { | |||
} | |||
@Internal | |||
protected <R> Optional<R> findDefinedParagraphProperty(Function<CTTextParagraphProperties, Boolean> isSet, | |||
protected <R> Optional<R> findDefinedParagraphProperty(Predicate<CTTextParagraphProperties> isSet, | |||
Function<CTTextParagraphProperties, R> getter, int level) { | |||
if (_body.isSetLstStyle() && level >= 0) { | |||
CTTextListStyle list = _body.getLstStyle(); | |||
CTTextParagraphProperties props = level == 0 ? list.getDefPPr() : retrieveProperties(list, level); | |||
if (props != null && isSet.apply(props)) { | |||
if (props != null && isSet.test(props)) { | |||
return Optional.of(getter.apply(props)); | |||
} else { | |||
return findDefinedParagraphProperty(isSet, getter, level - 1); | |||
@@ -355,12 +356,12 @@ public class XDDFTextBody { | |||
} | |||
@Internal | |||
protected <R> Optional<R> findDefinedRunProperty(Function<CTTextCharacterProperties, Boolean> isSet, | |||
protected <R> Optional<R> findDefinedRunProperty(Predicate<CTTextCharacterProperties> isSet, | |||
Function<CTTextCharacterProperties, R> getter, int level) { | |||
if (_body.isSetLstStyle() && level >= 0) { | |||
CTTextListStyle list = _body.getLstStyle(); | |||
CTTextParagraphProperties props = level == 0 ? list.getDefPPr() : retrieveProperties(list, level); | |||
if (props != null && props.isSetDefRPr() && isSet.apply(props.getDefRPr())) { | |||
if (props != null && props.isSetDefRPr() && isSet.test(props.getDefRPr())) { | |||
return Optional.of(getter.apply(props.getDefRPr())); | |||
} else { | |||
return findDefinedRunProperty(isSet, getter, level - 1); |
@@ -23,6 +23,7 @@ import java.util.Iterator; | |||
import java.util.List; | |||
import java.util.Optional; | |||
import java.util.function.Function; | |||
import java.util.function.Predicate; | |||
import org.apache.commons.collections4.iterators.IteratorIterable; | |||
import org.apache.commons.collections4.iterators.ReverseListIterator; | |||
@@ -178,8 +179,10 @@ public class XDDFTextParagraph { | |||
* @return alignment that is applied to the paragraph | |||
*/ | |||
public TextAlignment getTextAlignment() { | |||
return findDefinedParagraphProperty(props -> props.isSetAlgn(), props -> props.getAlgn()) | |||
.map(align -> TextAlignment.valueOf(align)).orElse(null); | |||
return findDefinedParagraphProperty( | |||
CTTextParagraphProperties::isSetAlgn, | |||
CTTextParagraphProperties::getAlgn) | |||
.map(TextAlignment::valueOf).orElse(null); | |||
} | |||
/** | |||
@@ -205,8 +208,10 @@ public class XDDFTextParagraph { | |||
* @return alignment that is applied to the paragraph | |||
*/ | |||
public FontAlignment getFontAlignment() { | |||
return findDefinedParagraphProperty(props -> props.isSetFontAlgn(), props -> props.getFontAlgn()) | |||
.map(align -> FontAlignment.valueOf(align)).orElse(null); | |||
return findDefinedParagraphProperty( | |||
CTTextParagraphProperties::isSetFontAlgn, | |||
CTTextParagraphProperties::getFontAlgn) | |||
.map(FontAlignment::valueOf).orElse(null); | |||
} | |||
/** | |||
@@ -230,8 +235,10 @@ public class XDDFTextParagraph { | |||
* the paragraph. | |||
*/ | |||
public Double getIndentation() { | |||
return findDefinedParagraphProperty(props -> props.isSetIndent(), props -> props.getIndent()) | |||
.map(emu -> Units.toPoints(emu)).orElse(null); | |||
return findDefinedParagraphProperty( | |||
CTTextParagraphProperties::isSetIndent, | |||
CTTextParagraphProperties::getIndent) | |||
.map(Units::toPoints).orElse(null); | |||
} | |||
/** | |||
@@ -259,8 +266,10 @@ public class XDDFTextParagraph { | |||
* @return the left margin, in points, of the paragraph. | |||
*/ | |||
public Double getMarginLeft() { | |||
return findDefinedParagraphProperty(props -> props.isSetMarL(), props -> props.getMarL()) | |||
.map(emu -> Units.toPoints(emu)).orElse(null); | |||
return findDefinedParagraphProperty( | |||
CTTextParagraphProperties::isSetMarL, | |||
CTTextParagraphProperties::getMarL) | |||
.map(Units::toPoints).orElse(null); | |||
} | |||
/** | |||
@@ -290,8 +299,10 @@ public class XDDFTextParagraph { | |||
* @return the right margin, in points, of the paragraph. | |||
*/ | |||
public Double getMarginRight() { | |||
return findDefinedParagraphProperty(props -> props.isSetMarR(), props -> props.getMarR()) | |||
.map(emu -> Units.toPoints(emu)).orElse(null); | |||
return findDefinedParagraphProperty( | |||
CTTextParagraphProperties::isSetMarR, | |||
CTTextParagraphProperties::getMarR) | |||
.map(Units::toPoints).orElse(null); | |||
} | |||
/** | |||
@@ -322,8 +333,10 @@ public class XDDFTextParagraph { | |||
* points. | |||
*/ | |||
public Double getDefaultTabSize() { | |||
return findDefinedParagraphProperty(props -> props.isSetDefTabSz(), props -> props.getDefTabSz()) | |||
.map(emu -> Units.toPoints(emu)).orElse(null); | |||
return findDefinedParagraphProperty( | |||
CTTextParagraphProperties::isSetDefTabSz, | |||
CTTextParagraphProperties::getDefTabSz) | |||
.map(Units::toPoints).orElse(null); | |||
} | |||
/** | |||
@@ -352,8 +365,10 @@ public class XDDFTextParagraph { | |||
* @return the vertical line spacing. | |||
*/ | |||
public XDDFSpacing getLineSpacing() { | |||
return findDefinedParagraphProperty(props -> props.isSetLnSpc(), props -> props.getLnSpc()) | |||
.map(spacing -> extractSpacing(spacing)).orElse(null); | |||
return findDefinedParagraphProperty( | |||
CTTextParagraphProperties::isSetLnSpc, | |||
CTTextParagraphProperties::getLnSpc) | |||
.map(this::extractSpacing).orElse(null); | |||
} | |||
@@ -403,8 +418,10 @@ public class XDDFTextParagraph { | |||
* @return the vertical white space before the paragraph. | |||
*/ | |||
public XDDFSpacing getSpaceBefore() { | |||
return findDefinedParagraphProperty(props -> props.isSetSpcBef(), props -> props.getSpcBef()) | |||
.map(spacing -> extractSpacing(spacing)).orElse(null); | |||
return findDefinedParagraphProperty( | |||
CTTextParagraphProperties::isSetSpcBef, | |||
CTTextParagraphProperties::getSpcBef) | |||
.map(this::extractSpacing).orElse(null); | |||
} | |||
/** | |||
@@ -451,8 +468,10 @@ public class XDDFTextParagraph { | |||
* @return the vertical white space after the paragraph. | |||
*/ | |||
public XDDFSpacing getSpaceAfter() { | |||
return findDefinedParagraphProperty(props -> props.isSetSpcAft(), props -> props.getSpcAft()) | |||
.map(spacing -> extractSpacing(spacing)).orElse(null); | |||
return findDefinedParagraphProperty( | |||
CTTextParagraphProperties::isSetSpcAft, | |||
CTTextParagraphProperties::getSpcAft) | |||
.map(this::extractSpacing).orElse(null); | |||
} | |||
/** | |||
@@ -599,7 +618,10 @@ public class XDDFTextParagraph { | |||
} | |||
public boolean hasEastAsianLineBreak() { | |||
return findDefinedParagraphProperty(props -> props.isSetEaLnBrk(), props -> props.getEaLnBrk()).orElse(false); | |||
return findDefinedParagraphProperty( | |||
CTTextParagraphProperties::isSetEaLnBrk, | |||
CTTextParagraphProperties::getEaLnBrk) | |||
.orElse(false); | |||
} | |||
public void setEastAsianLineBreak(Boolean value) { | |||
@@ -609,7 +631,9 @@ public class XDDFTextParagraph { | |||
} | |||
public boolean hasLatinLineBreak() { | |||
return findDefinedParagraphProperty(props -> props.isSetLatinLnBrk(), props -> props.getLatinLnBrk()) | |||
return findDefinedParagraphProperty( | |||
CTTextParagraphProperties::isSetLatinLnBrk, | |||
CTTextParagraphProperties::getLatinLnBrk) | |||
.orElse(false); | |||
} | |||
@@ -620,7 +644,9 @@ public class XDDFTextParagraph { | |||
} | |||
public boolean hasHangingPunctuation() { | |||
return findDefinedParagraphProperty(props -> props.isSetHangingPunct(), props -> props.getHangingPunct()) | |||
return findDefinedParagraphProperty( | |||
CTTextParagraphProperties::isSetHangingPunct, | |||
CTTextParagraphProperties::getHangingPunct) | |||
.orElse(false); | |||
} | |||
@@ -631,7 +657,10 @@ public class XDDFTextParagraph { | |||
} | |||
public boolean isRightToLeft() { | |||
return findDefinedParagraphProperty(props -> props.isSetRtl(), props -> props.getRtl()).orElse(false); | |||
return findDefinedParagraphProperty( | |||
CTTextParagraphProperties::isSetRtl, | |||
CTTextParagraphProperties::getRtl) | |||
.orElse(false); | |||
} | |||
public void setRightToLeft(Boolean value) { | |||
@@ -760,7 +789,7 @@ public class XDDFTextParagraph { | |||
return getProperties(); | |||
} | |||
protected <R> Optional<R> findDefinedParagraphProperty(Function<CTTextParagraphProperties, Boolean> isSet, | |||
protected <R> Optional<R> findDefinedParagraphProperty(Predicate<CTTextParagraphProperties> isSet, | |||
Function<CTTextParagraphProperties, R> getter) { | |||
if (_p.isSetPPr()) { | |||
int level = _p.getPPr().isSetLvl() ? 1 + _p.getPPr().getLvl() : 0; | |||
@@ -770,17 +799,17 @@ public class XDDFTextParagraph { | |||
} | |||
} | |||
private <R> Optional<R> findDefinedParagraphProperty(Function<CTTextParagraphProperties, Boolean> isSet, | |||
private <R> Optional<R> findDefinedParagraphProperty(Predicate<CTTextParagraphProperties> isSet, | |||
Function<CTTextParagraphProperties, R> getter, int level) { | |||
final CTTextParagraphProperties props = _p.getPPr(); | |||
if (props != null && isSet.apply(props)) { | |||
if (props != null && isSet.test(props)) { | |||
return Optional.ofNullable(getter.apply(props)); | |||
} else { | |||
return _parent.findDefinedParagraphProperty(isSet, getter, level); | |||
} | |||
} | |||
protected <R> Optional<R> findDefinedRunProperty(Function<CTTextCharacterProperties, Boolean> isSet, | |||
protected <R> Optional<R> findDefinedRunProperty(Predicate<CTTextCharacterProperties> isSet, | |||
Function<CTTextCharacterProperties, R> getter) { | |||
if (_p.isSetPPr()) { | |||
int level = _p.getPPr().isSetLvl() ? 1 + _p.getPPr().getLvl() : 0; | |||
@@ -790,10 +819,10 @@ public class XDDFTextParagraph { | |||
} | |||
} | |||
private <R> Optional<R> findDefinedRunProperty(Function<CTTextCharacterProperties, Boolean> isSet, | |||
private <R> Optional<R> findDefinedRunProperty(Predicate<CTTextCharacterProperties> isSet, | |||
Function<CTTextCharacterProperties, R> getter, int level) { | |||
final CTTextCharacterProperties props = _p.getPPr().isSetDefRPr() ? _p.getPPr().getDefRPr() : null; | |||
if (props != null && isSet.apply(props)) { | |||
if (props != null && isSet.test(props)) { | |||
return Optional.ofNullable(getter.apply(props)); | |||
} else { | |||
return _parent.findDefinedRunProperty(isSet, getter, level); |
@@ -21,6 +21,7 @@ import java.util.LinkedList; | |||
import java.util.Locale; | |||
import java.util.Optional; | |||
import java.util.function.Function; | |||
import java.util.function.Predicate; | |||
import org.apache.poi.common.usermodel.fonts.FontGroup; | |||
import org.apache.poi.ooxml.POIXMLRelation; | |||
@@ -108,7 +109,9 @@ public class XDDFTextRun { | |||
} | |||
public Boolean getDirty() { | |||
return findDefinedProperty(props -> props.isSetDirty(), props -> props.getDirty()) | |||
return findDefinedProperty( | |||
CTTextCharacterProperties::isSetDirty, | |||
CTTextCharacterProperties::getDirty) | |||
.orElse(null); | |||
} | |||
@@ -117,7 +120,9 @@ public class XDDFTextRun { | |||
} | |||
public Boolean getSpellError() { | |||
return findDefinedProperty(props -> props.isSetErr(), props -> props.getErr()) | |||
return findDefinedProperty( | |||
CTTextCharacterProperties::isSetErr, | |||
CTTextCharacterProperties::getErr) | |||
.orElse(null); | |||
} | |||
@@ -126,7 +131,9 @@ public class XDDFTextRun { | |||
} | |||
public Boolean getNoProof() { | |||
return findDefinedProperty(props -> props.isSetNoProof(), props -> props.getNoProof()) | |||
return findDefinedProperty( | |||
CTTextCharacterProperties::isSetNoProof, | |||
CTTextCharacterProperties::getNoProof) | |||
.orElse(null); | |||
} | |||
@@ -135,7 +142,9 @@ public class XDDFTextRun { | |||
} | |||
public Boolean getNormalizeHeights() { | |||
return findDefinedProperty(props -> props.isSetNormalizeH(), props -> props.getNormalizeH()) | |||
return findDefinedProperty( | |||
CTTextCharacterProperties::isSetNormalizeH, | |||
CTTextCharacterProperties::getNormalizeH) | |||
.orElse(null); | |||
} | |||
@@ -144,7 +153,9 @@ public class XDDFTextRun { | |||
} | |||
public boolean isKumimoji() { | |||
return findDefinedProperty(props -> props.isSetKumimoji(), props -> props.getKumimoji()) | |||
return findDefinedProperty( | |||
CTTextCharacterProperties::isSetKumimoji, | |||
CTTextCharacterProperties::getKumimoji) | |||
.orElse(false); | |||
} | |||
@@ -162,7 +173,9 @@ public class XDDFTextRun { | |||
* @return whether this run of text is formatted as bold text. | |||
*/ | |||
public boolean isBold() { | |||
return findDefinedProperty(props -> props.isSetB(), props -> props.getB()) | |||
return findDefinedProperty( | |||
CTTextCharacterProperties::isSetB, | |||
CTTextCharacterProperties::getB) | |||
.orElse(false); | |||
} | |||
@@ -178,7 +191,9 @@ public class XDDFTextRun { | |||
* @return whether this run of text is formatted as italic text. | |||
*/ | |||
public boolean isItalic() { | |||
return findDefinedProperty(props -> props.isSetI(), props -> props.getI()) | |||
return findDefinedProperty( | |||
CTTextCharacterProperties::isSetI, | |||
CTTextCharacterProperties::getI) | |||
.orElse(false); | |||
} | |||
@@ -194,7 +209,9 @@ public class XDDFTextRun { | |||
* @return whether this run of text is formatted as striked text. | |||
*/ | |||
public boolean isStrikeThrough() { | |||
return findDefinedProperty(props -> props.isSetStrike(), props -> props.getStrike()) | |||
return findDefinedProperty( | |||
CTTextCharacterProperties::isSetStrike, | |||
CTTextCharacterProperties::getStrike) | |||
.map(strike -> strike != STTextStrikeType.NO_STRIKE) | |||
.orElse(false); | |||
} | |||
@@ -203,8 +220,10 @@ public class XDDFTextRun { | |||
* @return which strike style this run of text is formatted with. | |||
*/ | |||
public StrikeType getStrikeThrough() { | |||
return findDefinedProperty(props -> props.isSetStrike(), props -> props.getStrike()) | |||
.map(strike -> StrikeType.valueOf(strike)) | |||
return findDefinedProperty( | |||
CTTextCharacterProperties::isSetStrike, | |||
CTTextCharacterProperties::getStrike) | |||
.map(StrikeType::valueOf) | |||
.orElse(null); | |||
} | |||
@@ -220,7 +239,9 @@ public class XDDFTextRun { | |||
* @return whether this run of text is formatted as underlined text. | |||
*/ | |||
public boolean isUnderline() { | |||
return findDefinedProperty(props -> props.isSetU(), props -> props.getU()) | |||
return findDefinedProperty( | |||
CTTextCharacterProperties::isSetU, | |||
CTTextCharacterProperties::getU) | |||
.map(underline -> underline != STTextUnderlineType.NONE) | |||
.orElse(false); | |||
} | |||
@@ -229,8 +250,10 @@ public class XDDFTextRun { | |||
* @return which underline style this run of text is formatted with. | |||
*/ | |||
public UnderlineType getUnderline() { | |||
return findDefinedProperty(props -> props.isSetU(), props -> props.getU()) | |||
.map(underline -> UnderlineType.valueOf(underline)) | |||
return findDefinedProperty( | |||
CTTextCharacterProperties::isSetU, | |||
CTTextCharacterProperties::getU) | |||
.map(UnderlineType::valueOf) | |||
.orElse(null); | |||
} | |||
@@ -246,7 +269,9 @@ public class XDDFTextRun { | |||
* @return whether this run of text is formatted as capitalized text. | |||
*/ | |||
public boolean isCapitals() { | |||
return findDefinedProperty(props -> props.isSetCap(), props -> props.getCap()) | |||
return findDefinedProperty( | |||
CTTextCharacterProperties::isSetCap, | |||
CTTextCharacterProperties::getCap) | |||
.map(caps -> caps != STTextCapsType.NONE) | |||
.orElse(false); | |||
} | |||
@@ -255,8 +280,10 @@ public class XDDFTextRun { | |||
* @return which caps style this run of text is formatted with. | |||
*/ | |||
public CapsType getCapitals() { | |||
return findDefinedProperty(props -> props.isSetCap(), props -> props.getCap()) | |||
.map(caps -> CapsType.valueOf(caps)) | |||
return findDefinedProperty( | |||
CTTextCharacterProperties::isSetCap, | |||
CTTextCharacterProperties::getCap) | |||
.map(CapsType::valueOf) | |||
.orElse(null); | |||
} | |||
@@ -265,7 +292,9 @@ public class XDDFTextRun { | |||
* Default is false. | |||
*/ | |||
public boolean isSubscript() { | |||
return findDefinedProperty(props -> props.isSetBaseline(), props -> props.getBaseline()) | |||
return findDefinedProperty( | |||
CTTextCharacterProperties::isSetBaseline, | |||
CTTextCharacterProperties::getBaseline) | |||
.map(baseline -> baseline < 0) | |||
.orElse(false); | |||
} | |||
@@ -275,7 +304,9 @@ public class XDDFTextRun { | |||
* Default is false. | |||
*/ | |||
public boolean isSuperscript() { | |||
return findDefinedProperty(props -> props.isSetBaseline(), props -> props.getBaseline()) | |||
return findDefinedProperty( | |||
CTTextCharacterProperties::isSetBaseline, | |||
CTTextCharacterProperties::getBaseline) | |||
.map(baseline -> baseline > 0) | |||
.orElse(false); | |||
} | |||
@@ -332,8 +363,10 @@ public class XDDFTextRun { | |||
} | |||
public XDDFColor getFontColor() { | |||
XDDFSolidFillProperties solid = findDefinedProperty(props -> props.isSetSolidFill(), props -> props.getSolidFill()) | |||
.map(props -> new XDDFSolidFillProperties(props)) | |||
XDDFSolidFillProperties solid = findDefinedProperty( | |||
CTTextCharacterProperties::isSetSolidFill, | |||
CTTextCharacterProperties::getSolidFill) | |||
.map(XDDFSolidFillProperties::new) | |||
.orElse(new XDDFSolidFillProperties()); | |||
return solid.getColor(); | |||
} | |||
@@ -352,18 +385,18 @@ public class XDDFTextRun { | |||
public XDDFFont[] getFonts() { | |||
LinkedList<XDDFFont> list = new LinkedList<>(); | |||
findDefinedProperty(props -> props.isSetCs(), props -> props.getCs()) | |||
findDefinedProperty(CTTextCharacterProperties::isSetCs, CTTextCharacterProperties::getCs) | |||
.map(font -> new XDDFFont(FontGroup.COMPLEX_SCRIPT, font)) | |||
.ifPresent(font -> list.add(font)); | |||
findDefinedProperty(props -> props.isSetEa(), props -> props.getEa()) | |||
.ifPresent(list::add); | |||
findDefinedProperty(CTTextCharacterProperties::isSetEa, CTTextCharacterProperties::getEa) | |||
.map(font -> new XDDFFont(FontGroup.EAST_ASIAN, font)) | |||
.ifPresent(font -> list.add(font)); | |||
findDefinedProperty(props -> props.isSetLatin(), props -> props.getLatin()) | |||
.ifPresent(list::add); | |||
findDefinedProperty(CTTextCharacterProperties::isSetLatin, CTTextCharacterProperties::getLatin) | |||
.map(font -> new XDDFFont(FontGroup.LATIN, font)) | |||
.ifPresent(font -> list.add(font)); | |||
findDefinedProperty(props -> props.isSetSym(), props -> props.getSym()) | |||
.ifPresent(list::add); | |||
findDefinedProperty(CTTextCharacterProperties::isSetSym, CTTextCharacterProperties::getSym) | |||
.map(font -> new XDDFFont(FontGroup.SYMBOL, font)) | |||
.ifPresent(font -> list.add(font)); | |||
.ifPresent(list::add); | |||
return list.toArray(new XDDFFont[0]); | |||
} | |||
@@ -384,7 +417,9 @@ public class XDDFTextRun { | |||
} | |||
public Double getFontSize() { | |||
Integer size = findDefinedProperty(props -> props.isSetSz(), props -> props.getSz()) | |||
Integer size = findDefinedProperty( | |||
CTTextCharacterProperties::isSetSz, | |||
CTTextCharacterProperties::getSz) | |||
.orElse(100 * XSSFFont.DEFAULT_FONT_SIZE); // default font size | |||
double scale = _parent.getParentBody().getBodyProperties().getAutoFit().getFontScale() / 10_000_000.0; | |||
return size * scale; | |||
@@ -415,7 +450,9 @@ public class XDDFTextRun { | |||
* If this attribute is omitted then returns <code>null</code>. | |||
*/ | |||
public Double getCharacterKerning() { | |||
return findDefinedProperty(props -> props.isSetKern(), props -> props.getKern()) | |||
return findDefinedProperty( | |||
CTTextCharacterProperties::isSetKern, | |||
CTTextCharacterProperties::getKern) | |||
.map(kerning -> 0.01 * kerning) | |||
.orElse(null); | |||
} | |||
@@ -449,7 +486,9 @@ public class XDDFTextRun { | |||
* If this attribute is omitted then returns <code>null</code>. | |||
*/ | |||
public Double getCharacterSpacing() { | |||
return findDefinedProperty(props -> props.isSetSpc(), props -> props.getSpc()) | |||
return findDefinedProperty( | |||
CTTextCharacterProperties::isSetSpc, | |||
CTTextCharacterProperties::getSpc) | |||
.map(spacing -> 0.01 * spacing) | |||
.orElse(null); | |||
} | |||
@@ -459,7 +498,9 @@ public class XDDFTextRun { | |||
} | |||
public String getBookmark() { | |||
return findDefinedProperty(props -> props.isSetBmk(), props -> props.getBmk()) | |||
return findDefinedProperty( | |||
CTTextCharacterProperties::isSetBmk, | |||
CTTextCharacterProperties::getBmk) | |||
.orElse(null); | |||
} | |||
@@ -484,8 +525,10 @@ public class XDDFTextRun { | |||
} | |||
public XDDFHyperlink getHyperlink() { | |||
return findDefinedProperty(props -> props.isSetHlinkClick(), props -> props.getHlinkClick()) | |||
.map(link -> new XDDFHyperlink(link)) | |||
return findDefinedProperty( | |||
CTTextCharacterProperties::isSetHlinkClick, | |||
CTTextCharacterProperties::getHlinkClick) | |||
.map(XDDFHyperlink::new) | |||
.orElse(null); | |||
} | |||
@@ -496,8 +539,10 @@ public class XDDFTextRun { | |||
} | |||
public XDDFHyperlink getMouseOver() { | |||
return findDefinedProperty(props -> props.isSetHlinkMouseOver(), props -> props.getHlinkMouseOver()) | |||
.map(link -> new XDDFHyperlink(link)) | |||
return findDefinedProperty( | |||
CTTextCharacterProperties::isSetHlinkMouseOver, | |||
CTTextCharacterProperties::getHlinkMouseOver) | |||
.map(XDDFHyperlink::new) | |||
.orElse(null); | |||
} | |||
@@ -506,8 +551,10 @@ public class XDDFTextRun { | |||
} | |||
public Locale getLanguage() { | |||
return findDefinedProperty(props -> props.isSetLang(), props -> props.getLang()) | |||
.map(lang -> Locale.forLanguageTag(lang)) | |||
return findDefinedProperty( | |||
CTTextCharacterProperties::isSetLang, | |||
CTTextCharacterProperties::getLang) | |||
.map(Locale::forLanguageTag) | |||
.orElse(null); | |||
} | |||
@@ -516,8 +563,10 @@ public class XDDFTextRun { | |||
} | |||
public Locale getAlternativeLanguage() { | |||
return findDefinedProperty(props -> props.isSetAltLang(), props -> props.getAltLang()) | |||
.map(lang -> Locale.forLanguageTag(lang)) | |||
return findDefinedProperty( | |||
CTTextCharacterProperties::isSetAltLang, | |||
CTTextCharacterProperties::getAltLang) | |||
.map(Locale::forLanguageTag) | |||
.orElse(null); | |||
} | |||
@@ -526,8 +575,10 @@ public class XDDFTextRun { | |||
} | |||
public XDDFColor getHighlight() { | |||
return findDefinedProperty(props -> props.isSetHighlight(), props -> props.getHighlight()) | |||
.map(color -> XDDFColor.forColorContainer(color)) | |||
return findDefinedProperty( | |||
CTTextCharacterProperties::isSetHighlight, | |||
CTTextCharacterProperties::getHighlight) | |||
.map(XDDFColor::forColorContainer) | |||
.orElse(null); | |||
} | |||
@@ -536,14 +587,16 @@ public class XDDFTextRun { | |||
} | |||
public XDDFLineProperties getLineProperties() { | |||
return findDefinedProperty(props -> props.isSetLn(), props -> props.getLn()) | |||
.map(props -> new XDDFLineProperties(props)) | |||
return findDefinedProperty( | |||
CTTextCharacterProperties::isSetLn, | |||
CTTextCharacterProperties::getLn) | |||
.map(XDDFLineProperties::new) | |||
.orElse(null); | |||
} | |||
private <R> Optional<R> findDefinedProperty(Function<CTTextCharacterProperties, Boolean> isSet, Function<CTTextCharacterProperties, R> getter) { | |||
private <R> Optional<R> findDefinedProperty(Predicate<CTTextCharacterProperties> isSet, Function<CTTextCharacterProperties, R> getter) { | |||
CTTextCharacterProperties props = getProperties(); | |||
if (props != null && isSet.apply(props)) { | |||
if (props != null && isSet.test(props)) { | |||
return Optional.ofNullable(getter.apply(props)); | |||
} else { | |||
return _parent.findDefinedRunProperty(isSet, getter); |
@@ -26,6 +26,7 @@ import java.util.Iterator; | |||
import java.util.List; | |||
import java.util.Optional; | |||
import java.util.function.Function; | |||
import java.util.function.Predicate; | |||
import org.apache.poi.ooxml.POIXMLException; | |||
import org.apache.poi.sl.draw.DrawFactory; | |||
@@ -773,14 +774,14 @@ public abstract class XSLFTextShape extends XSLFSimpleShape | |||
} | |||
@Override | |||
public <R> Optional<R> findDefinedParagraphProperty(Function<CTTextParagraphProperties, Boolean> isSet, | |||
public <R> Optional<R> findDefinedParagraphProperty(Predicate<CTTextParagraphProperties> isSet, | |||
Function<CTTextParagraphProperties, R> getter) { | |||
// TODO Auto-generated method stub | |||
return Optional.empty(); | |||
} | |||
@Override | |||
public <R> Optional<R> findDefinedRunProperty(Function<CTTextCharacterProperties, Boolean> isSet, | |||
public <R> Optional<R> findDefinedRunProperty(Predicate<CTTextCharacterProperties> isSet, | |||
Function<CTTextCharacterProperties, R> getter) { | |||
// TODO Auto-generated method stub | |||
return Optional.empty(); |
@@ -23,6 +23,7 @@ import java.util.List; | |||
import java.util.Locale; | |||
import java.util.Optional; | |||
import java.util.function.Function; | |||
import java.util.function.Predicate; | |||
import org.apache.poi.hssf.util.HSSFColor; | |||
import org.apache.poi.ss.usermodel.SimpleShape; | |||
@@ -1005,14 +1006,14 @@ public class XSSFSimpleShape extends XSSFShape implements Iterable<XSSFTextParag | |||
} | |||
@Override | |||
public <R> Optional<R> findDefinedParagraphProperty(Function<CTTextParagraphProperties, Boolean> isSet, | |||
public <R> Optional<R> findDefinedParagraphProperty(Predicate<CTTextParagraphProperties> isSet, | |||
Function<CTTextParagraphProperties, R> getter) { | |||
// TODO Auto-generated method stub | |||
return Optional.empty(); | |||
} | |||
@Override | |||
public <R> Optional<R> findDefinedRunProperty(Function<CTTextCharacterProperties, Boolean> isSet, | |||
public <R> Optional<R> findDefinedRunProperty(Predicate<CTTextCharacterProperties> isSet, | |||
Function<CTTextCharacterProperties, R> getter) { | |||
// TODO Auto-generated method stub | |||
return Optional.empty(); |