Skip to content

Commit 438d81a

Browse files
author
Eugene Bochilo
committed
Add message logging for not supported flex-related properties
DEVSIX-5170
1 parent 917da36 commit 438d81a

File tree

85 files changed

+475
-16
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+475
-16
lines changed

src/main/java/com/itextpdf/html2pdf/LogMessageConstant.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ public final class LogMessageConstant {
7575
public static final String EXCEEDED_THE_MAXIMUM_NUMBER_OF_RELAYOUTS = "Exceeded the maximum number of relayouts. " +
7676
"The resultant document may look not as expected. " +
7777
"Because of the content being dynamic iText performs several relayouts to produce correct document.";
78+
/** The constant FLEX_PROPERTY_IS_NOT_SUPPORTED_YET. */
79+
public static final String FLEX_PROPERTY_IS_NOT_SUPPORTED_YET =
80+
"Flex related property {0}: {1} is not supported yet.";
7881
/** The Constant INPUT_FIELD_DOES_NOT_FIT. */
7982
public static final String INPUT_FIELD_DOES_NOT_FIT = "Input field doesn't fit in outer object. It will be clipped";
8083
/** The Constant INPUT_TYPE_IS_INVALID. */

src/main/java/com/itextpdf/html2pdf/css/apply/util/FlexApplierUtil.java

Lines changed: 86 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,32 @@ This file is part of the iText (R) project.
4242
*/
4343
package com.itextpdf.html2pdf.css.apply.util;
4444

45+
import com.itextpdf.html2pdf.LogMessageConstant;
4546
import com.itextpdf.html2pdf.attach.ProcessorContext;
4647
import com.itextpdf.html2pdf.css.CssConstants;
48+
import com.itextpdf.io.util.MessageFormatUtil;
4749
import com.itextpdf.layout.IPropertyContainer;
4850
import com.itextpdf.layout.property.AlignmentPropertyValue;
4951
import com.itextpdf.layout.property.JustifyContent;
5052
import com.itextpdf.layout.property.Property;
5153
import com.itextpdf.layout.property.UnitValue;
5254
import com.itextpdf.styledxmlparser.css.CommonCssConstants;
5355
import com.itextpdf.styledxmlparser.css.util.CssDimensionParsingUtils;
56+
import org.slf4j.Logger;
57+
import org.slf4j.LoggerFactory;
5458

59+
import java.util.HashMap;
60+
import java.util.HashSet;
5561
import java.util.Map;
62+
import java.util.Set;
5663

5764
/**
5865
* Utilities class to apply flex properties.
5966
*/
6067
final public class FlexApplierUtil {
6168

69+
private static final Logger LOGGER = LoggerFactory.getLogger(FlexApplierUtil.class);
70+
6271
private FlexApplierUtil() {
6372
}
6473

@@ -72,6 +81,9 @@ private FlexApplierUtil() {
7281
public static void applyFlexItemProperties(Map<String, String> cssProps, ProcessorContext context,
7382
IPropertyContainer element) {
7483
element.setProperty(Property.COLLAPSING_MARGINS, null);
84+
85+
logWarningIfThereAreNotSupportedPropertyValues(createSupportedFlexItemPropertiesAndValuesMap(), cssProps);
86+
7587
final String flexGrow = cssProps.get(CommonCssConstants.FLEX_GROW);
7688
if (flexGrow != null) {
7789
final Float flexGrowValue = CssDimensionParsingUtils.parseFloat(flexGrow);
@@ -106,6 +118,8 @@ public static void applyFlexItemProperties(Map<String, String> cssProps, Process
106118
} else {
107119
// The case when we don't set the flex-basis property should be identified
108120
// as flex-basis: content
121+
LOGGER.warn(MessageFormatUtil.format(LogMessageConstant.FLEX_PROPERTY_IS_NOT_SUPPORTED_YET,
122+
CommonCssConstants.FLEX_BASIS, CommonCssConstants.CONTENT));
109123
}
110124
}
111125

@@ -116,6 +130,7 @@ public static void applyFlexItemProperties(Map<String, String> cssProps, Process
116130
* @param element the element
117131
*/
118132
public static void applyFlexContainerProperties(Map<String, String> cssProps, IPropertyContainer element) {
133+
logWarningIfThereAreNotSupportedPropertyValues(createSupportedFlexContainerPropertiesAndValuesMap(), cssProps);
119134
applyAlignItems(cssProps, element);
120135
applyJustifyContent(cssProps, element);
121136
}
@@ -149,11 +164,12 @@ private static void applyAlignItems(Map<String, String> cssProps, IPropertyConta
149164
case CommonCssConstants.SELF_END:
150165
alignItems = AlignmentPropertyValue.SELF_END;
151166
break;
152-
case CommonCssConstants.BASELINE:
153-
alignItems = AlignmentPropertyValue.BASELINE;
154-
break;
155167
case CommonCssConstants.STRETCH:
168+
alignItems = AlignmentPropertyValue.STRETCH;
169+
break;
156170
default:
171+
LOGGER.warn(MessageFormatUtil.format(LogMessageConstant.FLEX_PROPERTY_IS_NOT_SUPPORTED_YET,
172+
CommonCssConstants.ALIGN_ITEMS, alignItemsString));
157173
alignItems = AlignmentPropertyValue.STRETCH;
158174
break;
159175
}
@@ -193,12 +209,79 @@ private static void applyJustifyContent(Map<String, String> cssProps, IPropertyC
193209
case CommonCssConstants.CENTER:
194210
justifyContent = JustifyContent.CENTER;
195211
break;
212+
case CommonCssConstants.STRETCH:
213+
justifyContent = JustifyContent.STRETCH;
214+
break;
196215
case CommonCssConstants.FLEX_START:
216+
justifyContent = JustifyContent.FLEX_START;
217+
break;
197218
default:
219+
LOGGER.warn(MessageFormatUtil.format(LogMessageConstant.FLEX_PROPERTY_IS_NOT_SUPPORTED_YET,
220+
CommonCssConstants.JUSTIFY_CONTENT, justifyContentString));
198221
justifyContent = JustifyContent.FLEX_START;
199222
break;
200223
}
201224
element.setProperty(Property.JUSTIFY_CONTENT, justifyContent);
202225
}
203226
}
227+
228+
private static void logWarningIfThereAreNotSupportedPropertyValues(Map<String, Set<String>> supportedPairs,
229+
Map<String, String> cssProps) {
230+
for (Map.Entry<String, Set<String>> entry : supportedPairs.entrySet()) {
231+
String supportedPair = entry.getKey();
232+
Set<String> supportedValues = entry.getValue();
233+
String propertyValue = cssProps.get(supportedPair);
234+
if (propertyValue != null && !supportedValues.contains(propertyValue)) {
235+
LOGGER.warn(MessageFormatUtil.format(
236+
LogMessageConstant.FLEX_PROPERTY_IS_NOT_SUPPORTED_YET, supportedPair, propertyValue));
237+
}
238+
}
239+
}
240+
241+
private static Map<String, Set<String>> createSupportedFlexItemPropertiesAndValuesMap() {
242+
final Map<String, Set<String>> supportedPairs = new HashMap<>();
243+
244+
final Set<String> supportedAlignSelfValues = new HashSet<>();
245+
supportedAlignSelfValues.add(CommonCssConstants.AUTO);
246+
247+
supportedPairs.put(CommonCssConstants.ALIGN_SELF, supportedAlignSelfValues);
248+
249+
final Set<String> supportedOrderValues = new HashSet<>();
250+
251+
supportedPairs.put(CommonCssConstants.ORDER, supportedOrderValues);
252+
253+
return supportedPairs;
254+
}
255+
256+
private static Map<String, Set<String>> createSupportedFlexContainerPropertiesAndValuesMap() {
257+
final Map<String, Set<String>> supportedPairs = new HashMap<>();
258+
259+
final Set<String> supportedFlexDirectionValues = new HashSet<>();
260+
supportedFlexDirectionValues.add(CommonCssConstants.ROW);
261+
262+
supportedPairs.put(CommonCssConstants.FLEX_DIRECTION, supportedFlexDirectionValues);
263+
264+
final Set<String> supportedFlexWrapValues = new HashSet<>();
265+
supportedFlexWrapValues.add(CommonCssConstants.NOWRAP);
266+
267+
supportedPairs.put(CommonCssConstants.FLEX_WRAP, supportedFlexWrapValues);
268+
269+
final Set<String> supportedAlignContentValues = new HashSet<>();
270+
supportedAlignContentValues.add(CommonCssConstants.STRETCH);
271+
supportedAlignContentValues.add(CommonCssConstants.NORMAL);
272+
273+
supportedPairs.put(CommonCssConstants.ALIGN_CONTENT, supportedAlignContentValues);
274+
275+
final Set<String> supportedRowGapValues = new HashSet<>();
276+
supportedRowGapValues.add(CommonCssConstants.NORMAL);
277+
278+
supportedPairs.put(CommonCssConstants.ROW_GAP, supportedRowGapValues);
279+
280+
final Set<String> supportedColumnGapValues = new HashSet<>();
281+
supportedColumnGapValues.add(CommonCssConstants.NORMAL);
282+
283+
supportedPairs.put(CommonCssConstants.COLUMN_GAP, supportedColumnGapValues);
284+
285+
return supportedPairs;
286+
}
204287
}

src/test/java/com/itextpdf/html2pdf/css/DisplayFlexTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ This file is part of the iText (R) project.
2525
import com.itextpdf.html2pdf.ConverterProperties;
2626
import com.itextpdf.html2pdf.ExtendedHtmlConversionITextTest;
2727
import com.itextpdf.html2pdf.HtmlConverter;
28+
import com.itextpdf.html2pdf.LogMessageConstant;
2829
import com.itextpdf.html2pdf.attach.impl.layout.HtmlPageBreak;
2930
import com.itextpdf.html2pdf.attach.impl.layout.form.element.TextArea;
30-
import com.itextpdf.io.LogMessageConstant;
3131
import com.itextpdf.layout.element.Div;
3232
import com.itextpdf.layout.element.IElement;
3333
import com.itextpdf.layout.element.Image;
@@ -207,6 +207,7 @@ public void brTagTest() throws IOException {
207207
}
208208

209209
@Test
210+
@LogMessages(messages = @LogMessage(messageTemplate = LogMessageConstant.FLEX_PROPERTY_IS_NOT_SUPPORTED_YET))
210211
//TODO DEVSIX-5086 change this test when working on the ticket
211212
public void flexWrapTest() throws IOException {
212213
String name = "flexWrap";
@@ -496,7 +497,7 @@ public void marginsCollapseFlexContainerAndSiblingsTest() throws IOException, In
496497

497498

498499
@Test
499-
@LogMessages(messages = @LogMessage(messageTemplate = LogMessageConstant.CLIP_ELEMENT))
500+
@LogMessages(messages = @LogMessage(messageTemplate = com.itextpdf.io.LogMessageConstant.CLIP_ELEMENT))
500501
public void marginsCollapseFlexContainerAndParentTest() throws IOException, InterruptedException {
501502
convertToPdfAndCompare("marginsCollapseFlexContainerAndParent", SOURCE_FOLDER, DESTINATION_FOLDER);
502503
}

src/test/java/com/itextpdf/html2pdf/css/FlexAlgoTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ This file is part of the iText (R) project.
2323
package com.itextpdf.html2pdf.css;
2424

2525
import com.itextpdf.html2pdf.ExtendedHtmlConversionITextTest;
26+
import com.itextpdf.html2pdf.LogMessageConstant;
27+
import com.itextpdf.test.annotations.LogMessage;
28+
import com.itextpdf.test.annotations.LogMessages;
2629
import com.itextpdf.test.annotations.type.IntegrationTest;
2730

2831
import java.io.IOException;
@@ -146,12 +149,14 @@ public void differentBasisSumLtWidthGrow1Shrink1Item2MBP30Test01() throws IOExce
146149
}
147150

148151
@Test
152+
@LogMessages(messages = @LogMessage(messageTemplate = LogMessageConstant.FLEX_PROPERTY_IS_NOT_SUPPORTED_YET))
149153
//TODO DEVSIX-5086 Support flex-wrap property
150154
public void ltWidthGrow0Shrink1Item2MBP30Test01() throws IOException, InterruptedException {
151155
convertToPdfAndCompare("ltWidthGrow0Shrink1Item2MBP30Test01", SOURCE_FOLDER, DESTINATION_FOLDER);
152156
}
153157

154158
@Test
159+
@LogMessages(messages = @LogMessage(messageTemplate = LogMessageConstant.FLEX_PROPERTY_IS_NOT_SUPPORTED_YET))
155160
//TODO DEVSIX-5086 Support flex-wrap property
156161
public void ltWidthGrow0Shrink1Item2MBP30JustifyContentCenterAlignItemsCenterTest01()
157162
throws IOException, InterruptedException {
@@ -160,6 +165,7 @@ public void ltWidthGrow0Shrink1Item2MBP30JustifyContentCenterAlignItemsCenterTes
160165
}
161166

162167
@Test
168+
@LogMessages(messages = @LogMessage(messageTemplate = LogMessageConstant.FLEX_PROPERTY_IS_NOT_SUPPORTED_YET))
163169
//TODO DEVSIX-5086 Support flex-wrap property
164170
public void ltWidthGrow0Shrink1Item2MBP30JustifyContentFlexEndAlignItemsFlexEndTest01()
165171
throws IOException, InterruptedException {
@@ -168,13 +174,15 @@ public void ltWidthGrow0Shrink1Item2MBP30JustifyContentFlexEndAlignItemsFlexEndT
168174
}
169175

170176
@Test
177+
@LogMessages(messages = @LogMessage(messageTemplate = LogMessageConstant.FLEX_PROPERTY_IS_NOT_SUPPORTED_YET))
171178
//TODO DEVSIX-5086 Support flex-wrap property
172179
public void ltWidthGrow0Shrink1Item2MBP30JustifyContentFlexStartTest() throws IOException, InterruptedException {
173180
convertToPdfAndCompare("ltWidthGrow0Shrink1Item2MBP30JustifyContentFlexStartTest", SOURCE_FOLDER,
174181
DESTINATION_FOLDER);
175182
}
176183

177184
@Test
185+
@LogMessages(messages = @LogMessage(messageTemplate = LogMessageConstant.FLEX_PROPERTY_IS_NOT_SUPPORTED_YET))
178186
//TODO DEVSIX-5086 Support flex-wrap property
179187
public void ltWidthGrow0Shrink1Item2MBP30AlignItemsStretchAndNormalTest() throws IOException, InterruptedException {
180188
convertToPdfAndCompare("ltWidthGrow0Shrink1Item2MBP30AlignItemsStretchAndNormal", SOURCE_FOLDER,
@@ -261,13 +269,15 @@ public void differentBasisSumLtWidthGrow1Shrink1Item2MuchContentSetMinWidthGtBas
261269
}
262270

263271
@Test
272+
@LogMessages(messages = @LogMessage(messageTemplate = LogMessageConstant.FLEX_PROPERTY_IS_NOT_SUPPORTED_YET))
264273
//TODO DEVSIX-5086 Support flex-wrap property
265274
public void differentBasisSumEqWidthGrow1Shrink1Item2Basis0Test01() throws IOException, InterruptedException {
266275
convertToPdfAndCompare("differentBasisSumEqWidthGrow1Shrink1Item2Basis0Test01", SOURCE_FOLDER,
267276
DESTINATION_FOLDER);
268277
}
269278

270279
@Test
280+
@LogMessages(messages = @LogMessage(messageTemplate = LogMessageConstant.FLEX_PROPERTY_IS_NOT_SUPPORTED_YET))
271281
//TODO DEVSIX-5086 Support flex-wrap property
272282
public void differentBasisSumEqWidthGrow1Shrink1Item2Basis0NoContentTest02()
273283
throws IOException, InterruptedException {
@@ -333,62 +343,72 @@ public void differentBasisSumGtWidthGrow1Shrink0Test01() throws IOException, Int
333343
}
334344

335345
@Test
346+
@LogMessages(messages = @LogMessage(messageTemplate = LogMessageConstant.FLEX_PROPERTY_IS_NOT_SUPPORTED_YET))
336347
//TODO DEVSIX-5086 Support flex-wrap property
337348
public void basis250SumGtWidthGrow0Shrink1WrapTest01() throws IOException, InterruptedException {
338349
convertToPdfAndCompare("basis250SumGtWidthGrow0Shrink1WrapTest01", SOURCE_FOLDER, DESTINATION_FOLDER);
339350
}
340351

341352
@Test
353+
@LogMessages(messages = @LogMessage(messageTemplate = LogMessageConstant.FLEX_PROPERTY_IS_NOT_SUPPORTED_YET))
342354
//TODO DEVSIX-5086 Support flex-wrap property
343355
public void differentBasisSumGtWidthGrow0Shrink1WrapTest01() throws IOException, InterruptedException {
344356
convertToPdfAndCompare("differentBasisSumGtWidthGrow0Shrink1WrapTest01", SOURCE_FOLDER, DESTINATION_FOLDER);
345357
}
346358

347359
@Test
360+
@LogMessages(messages = @LogMessage(messageTemplate = LogMessageConstant.FLEX_PROPERTY_IS_NOT_SUPPORTED_YET))
348361
//TODO DEVSIX-5086 Support flex-wrap property
349362
public void differentBasisSumGtWidthGrow0Shrink05WrapTest01() throws IOException, InterruptedException {
350363
convertToPdfAndCompare("differentBasisSumGtWidthGrow0Shrink05WrapTest01", SOURCE_FOLDER, DESTINATION_FOLDER);
351364
}
352365

353366
@Test
367+
@LogMessages(messages = @LogMessage(messageTemplate = LogMessageConstant.FLEX_PROPERTY_IS_NOT_SUPPORTED_YET))
354368
//TODO DEVSIX-5086 Support flex-wrap property
355369
public void differentBasisSumGtWidthGrow0Shrink01WrapTest01() throws IOException, InterruptedException {
356370
convertToPdfAndCompare("differentBasisSumGtWidthGrow0Shrink01WrapTest01", SOURCE_FOLDER, DESTINATION_FOLDER);
357371
}
358372

359373
@Test
374+
@LogMessages(messages = @LogMessage(messageTemplate = LogMessageConstant.FLEX_PROPERTY_IS_NOT_SUPPORTED_YET))
360375
//TODO DEVSIX-5086 Support flex-wrap property
361376
public void differentBasisSumGtWidthGrow0Shrink5WrapTest01() throws IOException, InterruptedException {
362377
convertToPdfAndCompare("differentBasisSumGtWidthGrow0Shrink5WrapTest01", SOURCE_FOLDER, DESTINATION_FOLDER);
363378
}
364379

365380
@Test
381+
@LogMessages(messages = @LogMessage(messageTemplate = LogMessageConstant.FLEX_PROPERTY_IS_NOT_SUPPORTED_YET))
366382
//TODO DEVSIX-5086 Support flex-wrap property
367383
public void differentBasisSumGtWidthGrow1Shrink1WrapTest01() throws IOException, InterruptedException {
368384
convertToPdfAndCompare("differentBasisSumGtWidthGrow1Shrink1WrapTest01", SOURCE_FOLDER, DESTINATION_FOLDER);
369385
}
370386

371387
@Test
388+
@LogMessages(messages = @LogMessage(messageTemplate = LogMessageConstant.FLEX_PROPERTY_IS_NOT_SUPPORTED_YET))
372389
//TODO DEVSIX-5086 Support flex-wrap property
373390
public void differentBasisSumGtWidthGrow1Shrink1Item3Shrink50WrapTest01() throws IOException, InterruptedException {
374391
convertToPdfAndCompare("differentBasisSumGtWidthGrow1Shrink1Item3Shrink50WrapTest01", SOURCE_FOLDER,
375392
DESTINATION_FOLDER);
376393
}
377394

378395
@Test
396+
@LogMessages(messages = @LogMessage(messageTemplate = LogMessageConstant.FLEX_PROPERTY_IS_NOT_SUPPORTED_YET))
379397
//TODO DEVSIX-5086 Support flex-wrap property
380398
public void differentBasisSumGtWidthGrow1Shrink1Item3Shrink5WrapTest01() throws IOException, InterruptedException {
381399
convertToPdfAndCompare("differentBasisSumGtWidthGrow1Shrink1Item3Shrink5WrapTest01", SOURCE_FOLDER,
382400
DESTINATION_FOLDER);
383401
}
384402

385403
@Test
404+
@LogMessages(messages = @LogMessage(messageTemplate = LogMessageConstant.FLEX_PROPERTY_IS_NOT_SUPPORTED_YET))
386405
//TODO DEVSIX-5086 Support flex-wrap property
387406
public void differentBasisSumGtWidthGrow0Shrink0WrapTest01() throws IOException, InterruptedException {
388407
convertToPdfAndCompare("differentBasisSumGtWidthGrow0Shrink0WrapTest01", SOURCE_FOLDER, DESTINATION_FOLDER);
389408
}
390409

391410
@Test
411+
@LogMessages(messages = @LogMessage(messageTemplate = LogMessageConstant.FLEX_PROPERTY_IS_NOT_SUPPORTED_YET))
392412
//TODO DEVSIX-5086 Support flex-wrap property
393413
public void differentBasisSumGtWidthGrow1Shrink0WrapTest01() throws IOException, InterruptedException {
394414
convertToPdfAndCompare("differentBasisSumGtWidthGrow1Shrink0WrapTest01", SOURCE_FOLDER, DESTINATION_FOLDER);

0 commit comments

Comments
 (0)