1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements.  See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License.  You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 /* $Id: FOValidationEventProducer.java 1835810 2018-07-13 10:29:57Z ssteiner $ */
19 
20 package org.apache.fop.fo;
21 
22 import org.xml.sax.Locator;
23 
24 import org.apache.xmlgraphics.util.QName;
25 
26 import org.apache.fop.apps.FOPException;
27 import org.apache.fop.events.EventBroadcaster;
28 import org.apache.fop.events.EventProducer;
29 import org.apache.fop.fo.expr.PropertyException;
30 
31 /**
32  * Event producer interface for XSL-FO validation messages.
33  */
34 public interface FOValidationEventProducer extends EventProducer {
35 
36     /**
37      * Provider class for the event producer.
38      */
39     final class Provider {
40 
Provider()41         private Provider() { }
42 
43         /**
44          * Returns an event producer.
45          * @param broadcaster the event broadcaster to use
46          * @return the event producer
47          */
get(EventBroadcaster broadcaster)48         public static FOValidationEventProducer get(EventBroadcaster broadcaster) {
49             return broadcaster.getEventProducerFor(FOValidationEventProducer.class);
50         }
51     }
52 
53     /**
54      * Too many child nodes.
55      * @param source the event source
56      * @param elementName the name of the context node
57      * @param offendingNode the offending node
58      * @param loc the location of the error or null
59      * @throws ValidationException the validation error provoked by the method call
60      * @event.severity FATAL
61      */
tooManyNodes(Object source, String elementName, QName offendingNode, Locator loc)62     void tooManyNodes(Object source, String elementName, QName offendingNode,
63             Locator loc) throws ValidationException;
64 
65     /**
66      * The node order is wrong.
67      * @param source the event source
68      * @param elementName the name of the context node
69      * @param tooLateNode string name of node that should be earlier in document
70      * @param tooEarlyNode string name of node that should be later in document
71      * @param canRecover indicates whether FOP can recover from this problem and continue working
72      * @param loc the location of the error or null
73      * @throws ValidationException the validation error provoked by the method call
74      */
nodeOutOfOrder(Object source, String elementName, String tooLateNode, String tooEarlyNode, boolean canRecover, Locator loc)75     void nodeOutOfOrder(Object source, String elementName,
76             String tooLateNode, String tooEarlyNode, boolean canRecover,
77             Locator loc) throws ValidationException;
78 
79     /**
80      * An invalid child was encountered.
81      * @param source the event source
82      * @param elementName the name of the context node
83      * @param offendingNode the offending node
84      * @param ruleViolated the rule that was violated or null
85      * @param loc the location of the error or null
86      * @throws ValidationException the validation error provoked by the method call
87      */
invalidChild(Object source, String elementName, QName offendingNode, String ruleViolated, Locator loc)88     void invalidChild(Object source, String elementName, QName offendingNode, String ruleViolated,
89             Locator loc) throws ValidationException;
90 
91     /**
92      * A valid but not yet supported child was encountered.
93      *
94      * @param source the event source
95      * @param elementName the name of the context node
96      * @param offendingNode the offending node
97      * @param loc the location of the error or null
98      * @throws ValidationException the validation error provoked by the method call
99      */
notSupportedChild(Object source, String elementName, QName offendingNode, Locator loc)100     void notSupportedChild(Object source, String elementName, QName offendingNode, Locator loc)
101             throws ValidationException;
102 
103     /**
104      * A required child element is missing.
105      * @param source the event source
106      * @param elementName the name of the context node
107      * @param contentModel the expected content model
108      * @param canRecover indicates whether FOP can recover from this problem and continue working
109      * @param loc the location of the error or null
110      * @throws ValidationException the validation error provoked by the method call
111      * @event.severity FATAL
112      */
missingChildElement(Object source, String elementName, String contentModel, boolean canRecover, Locator loc)113     void missingChildElement(Object source, String elementName,
114             String contentModel, boolean canRecover,
115             Locator loc) throws ValidationException;
116 
117     /**
118      * An element is missing a required property.
119      * @param source the event source
120      * @param elementName the name of the context node
121      * @param propertyName the name of the missing property
122      * @param loc the location of the error or null
123      * @throws ValidationException the validation error provoked by the method call
124      * @event.severity FATAL
125      */
missingProperty(Object source, String elementName, String propertyName, Locator loc)126     void missingProperty(Object source, String elementName, String propertyName,
127             Locator loc) throws ValidationException;
128 
129     /**
130      * An id was used twice in a document.
131      * @param source the event source
132      * @param elementName the name of the context node
133      * @param id the id that was reused
134      * @param canRecover indicates whether FOP can recover from this problem and continue working
135      * @param loc the location of the error or null
136      * @throws ValidationException the validation error provoked by the method call
137      * @event.severity FATAL
138      */
idNotUnique(Object source, String elementName, String id, boolean canRecover, Locator loc)139     void idNotUnique(Object source, String elementName, String id, boolean canRecover,
140             Locator loc) throws ValidationException;
141 
142     /**
143      * There are multiple color profiles defined with the same name.
144      * @param source the event source
145      * @param elementName the name of the context node
146      * @param name the duplicate color profile name
147      * @param loc the location of the error or null
148      * @event.severity WARN
149      */
colorProfileNameNotUnique(Object source, String elementName, String name, Locator loc)150     void colorProfileNameNotUnique(Object source, String elementName, String name,
151             Locator loc);
152 
153     /**
154      * There are multiple page masters defined with the same name.
155      * @param source the event source
156      * @param elementName the name of the context node
157      * @param name the duplicate page master name
158      * @param loc the location of the error or null
159      * @throws ValidationException the validation error provoked by the method call
160      * @event.severity FATAL
161      */
masterNameNotUnique(Object source, String elementName, String name, Locator loc)162     void masterNameNotUnique(Object source, String elementName, String name,
163             Locator loc) throws ValidationException;
164 
165     /**
166      * An fo:marker appears as initial descendant in an fo:block-container
167      * that generates absolutely positioned areas
168      * @param source    the event source
169      * @param loc       the location of the error (possibly null)
170      * @event.severity ERROR
171      */
markerBlockContainerAbsolutePosition(Object source, Locator loc)172     void markerBlockContainerAbsolutePosition(Object source, Locator loc);
173 
174     /**
175      * A marker is not an initial child on a node.
176      * @param source the event source
177      * @param elementName the name of the context node
178      * @param mcname the marker class name
179      * @param loc the location of the error or null
180      * @event.severity ERROR
181      */
markerNotInitialChild(Object source, String elementName, String mcname, Locator loc)182     void markerNotInitialChild(Object source, String elementName, String mcname, Locator loc);
183 
184     /**
185      * A marker class name is not unique within the same parent.
186      * @param source the event source
187      * @param elementName the name of the context node
188      * @param mcname the marker class name
189      * @param loc the location of the error or null
190      * @event.severity ERROR
191      */
markerNotUniqueForSameParent(Object source, String elementName, String mcname, Locator loc)192     void markerNotUniqueForSameParent(Object source, String elementName,
193             String mcname, Locator loc);
194 
195     /**
196      * An invalid property was found.
197      * @param source the event source
198      * @param elementName the name of the context node
199      * @param attr the invalid attribute
200      * @param canRecover indicates whether FOP can recover from this problem and continue working
201      * @param loc the location of the error or null
202      * @throws ValidationException the validation error provoked by the method call
203      * @event.severity FATAL
204      */
invalidProperty(Object source, String elementName, QName attr, boolean canRecover, Locator loc)205     void invalidProperty(Object source, String elementName, QName attr, boolean canRecover,
206             Locator loc) throws ValidationException;
207 
208     /**
209      * An invalid property value was encountered.
210      * @param source the event source
211      * @param elementName the name of the context node
212      * @param propName the property name
213      * @param propValue the property value
214      * @param e the property exception caused by the invalid value
215      * @param loc the location of the error or null
216      * @event.severity ERROR
217      */
invalidPropertyValue(Object source, String elementName, String propName, String propValue, PropertyException e, Locator loc)218     void invalidPropertyValue(Object source, String elementName,
219             String propName, String propValue, PropertyException e,
220             Locator loc);
221 
222     /**
223      * An invalid property value was encountered.
224      * @param source the event source
225      * @param elementName the name of the context node
226      * @param propName the property name
227      * @param propValue the property value
228      * @param e the property exception caused by the invalid value
229      * @param loc the location of the error or null
230      * @event.severity WARN
231      */
warnOnInvalidPropertyValue(Object source, String elementName, String propName, String propValue, PropertyException e, Locator loc)232     void warnOnInvalidPropertyValue(Object source, String elementName,
233             String propName, String propValue, PropertyException e,
234             Locator loc);
235 
236     /**
237      * A feature is not supported, yet.
238      * @param source the event source
239      * @param elementName the name of the context node
240      * @param feature the unsupported feature
241      * @param loc the location of the error or null
242      * @event.severity WARN
243      */
unimplementedFeature(Object source, String elementName, String feature, Locator loc)244     void unimplementedFeature(Object source, String elementName, String feature,
245             Locator loc);
246 
247     /**
248      * Missing internal-/external-destination on basic-link or bookmark.
249      * @param source the event source
250      * @param elementName the name of the context node
251      * @param loc the location of the error or null
252      * @throws ValidationException the validation error provoked by the method call
253      * @event.severity FATAL
254      */
missingLinkDestination(Object source, String elementName, Locator loc)255     void missingLinkDestination(Object source, String elementName, Locator loc)
256                 throws ValidationException;
257 
258     /**
259      * Indicates a problem while cloning a marker (ex. due to invalid property values).
260      * @param source the event source
261      * @param markerClassName the "marker-class-name" of the marker
262      * @param fe the FOP exception that cause this problem
263      * @param loc the location of the error or null
264      * @event.severity ERROR
265      */
markerCloningFailed(Object source, String markerClassName, FOPException fe, Locator loc)266     void markerCloningFailed(Object source, String markerClassName, FOPException fe, Locator loc);
267 
268     /**
269      * A region name is mapped to multiple region classes.
270      * @param source the event source
271      * @param regionName the region name
272      * @param defaultRegionClass1 the first default region class
273      * @param defaultRegionClass2 the second default region class
274      * @param loc the location of the error or null
275      * @throws ValidationException the validation error provoked by the method call
276      * @event.severity FATAL
277      */
regionNameMappedToMultipleRegionClasses(Object source, String regionName, String defaultRegionClass1, String defaultRegionClass2, Locator loc)278     void regionNameMappedToMultipleRegionClasses(Object source, String regionName,
279             String defaultRegionClass1, String defaultRegionClass2, Locator loc)
280                 throws ValidationException;
281 
282     /**
283      * There are multiple flows with the same name.
284      * @param source the event source
285      * @param elementName the name of the context node
286      * @param flowName the flow name
287      * @param loc the location of the error or null
288      * @throws ValidationException the validation error provoked by the method call
289      * @event.severity FATAL
290      */
duplicateFlowNameInPageSequence(Object source, String elementName, String flowName, Locator loc)291     void duplicateFlowNameInPageSequence(Object source, String elementName, String flowName,
292             Locator loc) throws ValidationException;
293 
294     /**
295      * A flow name could not be mapped to a region.
296      * @param source the event source
297      * @param elementName the name of the context node
298      * @param flowName the flow name
299      * @param loc the location of the error or null
300      * @throws ValidationException the validation error provoked by the method call
301      * @event.severity FATAL
302      */
flowNameNotMapped(Object source, String elementName, String flowName, Locator loc)303     void flowNameNotMapped(Object source, String elementName, String flowName,
304             Locator loc) throws ValidationException;
305 
306     /**
307      * A page master could not be found.
308      * @param source the event source
309      * @param elementName the name of the context node
310      * @param masterReference the page master reference
311      * @param loc the location of the error or null
312      * @throws ValidationException the validation error provoked by the method call
313      * @event.severity FATAL
314      */
masterNotFound(Object source, String elementName, String masterReference, Locator loc)315     void masterNotFound(Object source, String elementName, String masterReference,
316             Locator loc) throws ValidationException;
317 
318     /**
319      * An illegal region name was used.
320      * @param source the event source
321      * @param elementName the name of the context node
322      * @param regionName the region name
323      * @param loc the location of the error or null
324      * @throws ValidationException the validation error provoked by the method call
325      * @event.severity FATAL
326      */
illegalRegionName(Object source, String elementName, String regionName, Locator loc)327     void illegalRegionName(Object source, String elementName, String regionName,
328             Locator loc) throws ValidationException;
329 
330     /**
331      * A non-zero border and/or padding has been encountered on a region.
332      * @param source the event source
333      * @param elementName the name of the context node
334      * @param regionName the region name
335      * @param canRecover indicates whether FOP can recover from this problem and continue working
336      * @param loc the location of the error or null
337      * @throws ValidationException the validation error provoked by the method call
338      * @event.severity FATAL
339      */
nonZeroBorderPaddingOnRegion(Object source, String elementName, String regionName, boolean canRecover, Locator loc)340     void nonZeroBorderPaddingOnRegion(Object source, String elementName, String regionName,
341             boolean canRecover, Locator loc) throws ValidationException;
342 
343     /**
344      * If overflow property is set to "scroll", a column-count other than "1" may not be specified.
345      * @param source the event source
346      * @param elementName the name of the context node
347      * @param loc the location of the error or null
348      * @throws ValidationException the validation error provoked by the method call
349      * @event.severity FATAL
350      */
columnCountErrorOnRegionBodyOverflowScroll(Object source, String elementName, Locator loc)351     void columnCountErrorOnRegionBodyOverflowScroll(Object source, String elementName,
352             Locator loc) throws ValidationException;
353 
354     /**
355      * fo:root must be root.
356      * @param source the event source
357      * @param elementName the name of the context node
358      * @param loc the location of the error or null
359      * @throws ValidationException the validation error provoked by the method call
360      * @event.severity FATAL
361      */
invalidFORoot(Object source, String elementName, Locator loc)362     void invalidFORoot(Object source, String elementName,
363             Locator loc) throws ValidationException;
364 
365     /**
366      * No FO document was found.
367      * @param source the event source
368      * @throws ValidationException the validation error provoked by the method call
369      * @event.severity FATAL
370      */
emptyDocument(Object source)371     void emptyDocument(Object source) throws ValidationException;
372 
373     /**
374      * An unknown/unsupported formatting object has been encountered.
375      * @param source the event source
376      * @param elementName the name of the context node
377      * @param offendingNode the offending node
378      * @param loc the location of the error or null
379      * @event.severity WARN
380      */
unknownFormattingObject(Object source, String elementName, QName offendingNode, Locator loc)381     void unknownFormattingObject(Object source, String elementName,
382             QName offendingNode, Locator loc);
383 
384     /**
385      * A class for change bars is not unique.
386      * @param source the event source
387      * @param elementName the name of the context node
388      * @param name the class name
389      * @param loc the location of the error or null
390      * @event.severity FATAL
391      */
changeBarClassNotUnique(Object source, String elementName, String name, Locator loc)392     void changeBarClassNotUnique(Object source, String elementName, String name,
393             Locator loc);
394 
395     /**
396      * Change bars were not stacked correctly
397      * @param source the event source
398      * @param elementName the name of the context node
399      * @param beginName the class name of the beginning change bar
400      * @param endName the class name of the ending change bar
401      * @param loc the location of the error or null
402      * @event.severity FATAL
403      */
changeBarWrongStacking(Object source, String elementName, String beginName, String endName, Locator loc)404     void changeBarWrongStacking(Object source, String elementName, String beginName,
405             String endName, Locator loc);
406 
407     /**
408      * Change bar ended without a start of bar occurred
409      * @param source the event source
410      * @param elementName the name of the context node
411      * @param loc the location of the error or null
412      * @event.severity FATAL
413      */
changeBarNoBegin(Object source, String elementName, Locator loc)414     void changeBarNoBegin(Object source, String elementName, Locator loc);
415 
416     /**
417      * Change bar not descendant of fo:flow or fo:static-content
418      * @param source the event source
419      * @param elementName the name of the context node
420      * @param loc the location of the error or null
421      * @event.severity FATAL
422      */
changeBarWrongAncestor(Object source, String elementName, Locator loc)423     void changeBarWrongAncestor(Object source, String elementName, Locator loc);
424 
425     /**
426      * Alternate text is missing for a graphic element.
427      *
428      * @param source the event source
429      * @param foElement name of the element (external-graphic or instream-foreign-object)
430      * @param loc the location of the error or null
431      * @event.severity WARN
432      */
altTextMissing(Object source, String foElement, Locator loc)433     void altTextMissing(Object source, String foElement, Locator loc);
434 }
435