Skip to content

Commit 5c6acf9

Browse files
ars18wrwiText-CI
authored andcommitted
Log a message in case getNextRenderer is not overridden in an extended class. Improve its javadoc
DEVSIX-5277
1 parent 30c58cc commit 5c6acf9

23 files changed

+549
-6
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ public final class LogMessageConstant {
122122
public static final String FONT_SUBSET_ISSUE = "Font subset issue. Full font will be embedded.";
123123
public static final String FORBID_RELEASE_IS_SET = "ForbidRelease flag is set and release is called. Releasing will not be performed.";
124124
public static final String FORM_FIELD_WAS_FLUSHED = "A form field was flushed. There's no way to create this field in the AcroForm dictionary.";
125+
public static final String GET_NEXT_RENDERER_SHOULD_BE_OVERRIDDEN = "If a renderer overflows, "
126+
+ "iText uses this method to create another renderer for the overflow part. So if one wants "
127+
+ "to extend the renderer, one should override this method: otherwise the default method "
128+
+ "will be used and thus the default rather than the custom renderer will be created.";
125129
public static final String GPOS_LOOKUP_SUBTABLE_FORMAT_NOT_SUPPORTED =
126130
"Subtable format {0} of GPOS Lookup Type {1} is not supported yet";
127131
public static final String GRAPHICS_STATE_WAS_DELETED = "Graphics state is always deleted after event dispatching. If you want to preserve it in renderer info, use preserveGraphicsState method after receiving renderer info.";

layout/src/main/java/com/itextpdf/layout/renderer/AbstractRenderer.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2735,6 +2735,16 @@ void setThisAsParent(Collection<IRenderer> children) {
27352735
}
27362736
}
27372737

2738+
boolean logWarningIfGetNextRendererNotOverridden(Class<?> baseClass, Class<?> rendererClass) {
2739+
if (baseClass != rendererClass) {
2740+
final Logger logger = LoggerFactory.getLogger(baseClass);
2741+
logger.warn(MessageFormatUtil.format(LogMessageConstant.GET_NEXT_RENDERER_SHOULD_BE_OVERRIDDEN));
2742+
return false;
2743+
} else {
2744+
return true;
2745+
}
2746+
}
2747+
27382748
private void removeThisFromParent(IRenderer toRemove) {
27392749
// we need to be sure that the removed element has no other entries in child renderers list
27402750
if (toRemove != null && this == toRemove.getParent() && !this.childRenderers.contains(toRemove)) {

layout/src/main/java/com/itextpdf/layout/renderer/CellRenderer.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ This file is part of the iText (R) project.
5252
import com.itextpdf.layout.IPropertyContainer;
5353
import com.itextpdf.layout.borders.Border;
5454
import com.itextpdf.layout.element.Cell;
55+
import com.itextpdf.layout.layout.LayoutContext;
5556
import com.itextpdf.layout.property.BorderCollapsePropertyValue;
5657
import com.itextpdf.layout.property.Property;
5758
import com.itextpdf.layout.property.UnitValue;
@@ -201,10 +202,19 @@ protected Rectangle applySpacings(Rectangle rect, float[] spacings, boolean reve
201202
}
202203

203204
/**
204-
* {@inheritDoc}
205+
* Gets a new instance of this class to be used as a next renderer, after this renderer is used, if
206+
* {@link #layout(LayoutContext)} is called more than once.
207+
*
208+
* <p>
209+
* If a renderer overflows to the next area, iText uses this method to create a renderer
210+
* for the overflow part. So if one wants to extend {@link CellRenderer}, one should override
211+
* this method: otherwise the default method will be used and thus the default rather than the custom
212+
* renderer will be created.
213+
* @return new renderer instance
205214
*/
206215
@Override
207216
public IRenderer getNextRenderer() {
217+
logWarningIfGetNextRendererNotOverridden(CellRenderer.class, this.getClass());
208218
return new CellRenderer((Cell) getModelElement());
209219
}
210220
}

layout/src/main/java/com/itextpdf/layout/renderer/DivRenderer.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ This file is part of the iText (R) project.
4444
package com.itextpdf.layout.renderer;
4545

4646
import com.itextpdf.layout.element.Div;
47+
import com.itextpdf.layout.layout.LayoutContext;
4748

4849
public class DivRenderer extends BlockRenderer {
4950

@@ -57,10 +58,19 @@ public DivRenderer(Div modelElement) {
5758
}
5859

5960
/**
60-
* {@inheritDoc}
61+
* Gets a new instance of this class to be used as a next renderer, after this renderer is used, if
62+
* {@link #layout(LayoutContext)} is called more than once.
63+
*
64+
* <p>
65+
* If a renderer overflows to the next area, iText uses this method to create a renderer
66+
* for the overflow part. So if one wants to extend {@link DivRenderer}, one should override
67+
* this method: otherwise the default method will be used and thus the default rather than the custom
68+
* renderer will be created.
69+
* @return new renderer instance
6170
*/
6271
@Override
6372
public IRenderer getNextRenderer() {
73+
logWarningIfGetNextRendererNotOverridden(DivRenderer.class, this.getClass());
6474
return new DivRenderer((Div) modelElement);
6575
}
6676
}

layout/src/main/java/com/itextpdf/layout/renderer/FlexContainerRenderer.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,19 @@ public FlexContainerRenderer(Div modelElement) {
7575
}
7676

7777
/**
78-
* {@inheritDoc}
78+
* Gets a new instance of this class to be used as a next renderer, after this renderer is used, if
79+
* {@link #layout(LayoutContext)} is called more than once.
80+
*
81+
* <p>
82+
* If a renderer overflows to the next area, iText uses this method to create a renderer
83+
* for the overflow part. So if one wants to extend {@link FlexContainerRenderer}, one should override
84+
* this method: otherwise the default method will be used and thus the default rather than the custom
85+
* renderer will be created.
86+
* @return new renderer instance
7987
*/
8088
@Override
8189
public IRenderer getNextRenderer() {
90+
logWarningIfGetNextRendererNotOverridden(FlexContainerRenderer.class, this.getClass());
8291
return new FlexContainerRenderer((Div) modelElement);
8392
}
8493

layout/src/main/java/com/itextpdf/layout/renderer/LinkRenderer.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ This file is part of the iText (R) project.
4949
import org.slf4j.LoggerFactory;
5050

5151
import com.itextpdf.io.util.MessageFormatUtil;
52+
import com.itextpdf.layout.layout.LayoutContext;
5253

5354
public class LinkRenderer extends TextRenderer {
5455

@@ -88,8 +89,20 @@ public void draw(DrawContext drawContext) {
8889

8990
}
9091

92+
/**
93+
* Gets a new instance of this class to be used as a next renderer, after this renderer is used, if
94+
* {@link #layout(LayoutContext)} is called more than once.
95+
*
96+
* <p>
97+
* If a renderer overflows to the next area, iText uses this method to create a renderer
98+
* for the overflow part. So if one wants to extend {@link LinkRenderer}, one should override
99+
* this method: otherwise the default method will be used and thus the default rather than the custom
100+
* renderer will be created.
101+
* @return new renderer instance
102+
*/
91103
@Override
92104
public IRenderer getNextRenderer() {
105+
logWarningIfGetNextRendererNotOverridden(LinkRenderer.class, this.getClass());
93106
return new LinkRenderer((Link) modelElement);
94107
}
95108
}

layout/src/main/java/com/itextpdf/layout/renderer/ListRenderer.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,20 @@ public LayoutResult layout(LayoutContext layoutContext) {
103103
return result;
104104
}
105105

106+
/**
107+
* Gets a new instance of this class to be used as a next renderer, after this renderer is used, if
108+
* {@link #layout(LayoutContext)} is called more than once.
109+
*
110+
* <p>
111+
* If a renderer overflows to the next area, iText uses this method to create a renderer
112+
* for the overflow part. So if one wants to extend {@link ListRenderer}, one should override
113+
* this method: otherwise the default method will be used and thus the default rather than the custom
114+
* renderer will be created.
115+
* @return new renderer instance
116+
*/
106117
@Override
107118
public IRenderer getNextRenderer() {
119+
logWarningIfGetNextRendererNotOverridden(ListRenderer.class, this.getClass());
108120
return new ListRenderer((com.itextpdf.layout.element.List) modelElement);
109121
}
110122

layout/src/main/java/com/itextpdf/layout/renderer/ParagraphRenderer.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ This file is part of the iText (R) project.
6767
import com.itextpdf.layout.property.RenderingMode;
6868
import com.itextpdf.layout.property.TextAlignment;
6969
import com.itextpdf.layout.property.UnitValue;
70+
7071
import org.slf4j.LoggerFactory;
7172

7273
import java.util.ArrayList;
@@ -501,10 +502,19 @@ protected LayoutResult directLayout(LayoutContext layoutContext) {
501502
}
502503

503504
/**
504-
* {@inheritDoc}
505+
* Gets a new instance of this class to be used as a next renderer, after this renderer is used, if
506+
* {@link #layout(LayoutContext)} is called more than once.
507+
*
508+
* <p>
509+
* If a renderer overflows to the next area, iText uses this method to create a renderer
510+
* for the overflow part. So if one wants to extend {@link ParagraphRenderer}, one should override
511+
* this method: otherwise the default method will be used and thus the default rather than the custom
512+
* renderer will be created.
513+
* @return new renderer instance
505514
*/
506515
@Override
507516
public IRenderer getNextRenderer() {
517+
logWarningIfGetNextRendererNotOverridden(ParagraphRenderer.class, this.getClass());
508518
return new ParagraphRenderer((Paragraph) modelElement);
509519
}
510520

layout/src/main/java/com/itextpdf/layout/renderer/TabRenderer.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,20 @@ public void draw(DrawContext drawContext) {
106106
}
107107
}
108108

109+
/**
110+
* Gets a new instance of this class to be used as a next renderer, after this renderer is used, if
111+
* {@link #layout(LayoutContext)} is called more than once.
112+
*
113+
* <p>
114+
* If a renderer overflows to the next area, iText uses this method to create a renderer
115+
* for the overflow part. So if one wants to extend {@link TabRenderer}, one should override
116+
* this method: otherwise the default method will be used and thus the default rather than the custom
117+
* renderer will be created.
118+
* @return new renderer instance
119+
*/
109120
@Override
110121
public IRenderer getNextRenderer() {
122+
logWarningIfGetNextRendererNotOverridden(TabRenderer.class, this.getClass());
111123
return new TabRenderer((Tab) modelElement);
112124
}
113125
}

layout/src/main/java/com/itextpdf/layout/renderer/TableRenderer.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1194,10 +1194,19 @@ public void drawBackground(DrawContext drawContext) {
11941194
}
11951195

11961196
/**
1197-
* {@inheritDoc}
1197+
* Gets a new instance of this class to be used as a next renderer, after this renderer is used, if
1198+
* {@link #layout(LayoutContext)} is called more than once.
1199+
*
1200+
* <p>
1201+
* If a renderer overflows to the next area, iText uses this method to create a renderer
1202+
* for the overflow part. So if one wants to extend {@link TableRenderer}, one should override
1203+
* this method: otherwise the default method will be used and thus the default rather than the custom
1204+
* renderer will be created.
1205+
* @return new renderer instance
11981206
*/
11991207
@Override
12001208
public IRenderer getNextRenderer() {
1209+
logWarningIfGetNextRendererNotOverridden(TableRenderer.class, this.getClass());
12011210
TableRenderer nextTable = new TableRenderer();
12021211
nextTable.modelElement = modelElement;
12031212
return nextTable;

0 commit comments

Comments
 (0)