Bug 44619 - Generic validation for positive integers
Summary: Generic validation for positive integers
Status: CLOSED FIXED
Alias: None
Product: Fop - Now in Jira
Classification: Unclassified
Component: fo tree (show other bugs)
Version: trunk
Hardware: All All
: P2 enhancement
Target Milestone: ---
Assignee: fop-dev
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-03-17 07:52 UTC by Jeremias Maerki
Modified: 2012-04-01 07:00 UTC (History)
0 users



Attachments
A patch for the problem (3.99 KB, patch)
2008-04-08 06:47 UTC, Simon Pepping
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jeremias Maerki 2008-03-17 07:52:18 UTC
Many properties like column-count and number-columns-repeated are defined as positive integers and: "If a non-positive or non-integer value is provided, the value will be rounded to the nearest integer value greater than or equal to 1."

It would be good to have a possibility to declare that in FOPropertyMapping instead of having to write validation code for each such property. ATM, floating point values are often not rounded and not normalized following the above rule.
Comment 1 Andreas L. Delmelle 2008-03-23 02:13:29 UTC
(In reply to comment #0)
> Many properties like column-count and number-columns-repeated are defined as
> positive integers and: "If a non-positive or non-integer value is provided, the
> value will be rounded to the nearest integer value greater than or equal to 1."
> 
> It would be good to have a possibility to declare that in FOPropertyMapping
> instead of having to write validation code for each such property. ATM,
> floating point values are often not rounded and not normalized following the
> above rule.

FWIW: I've been thinking about this too at some point.

My proposal would lie in the creation of a PropertyMaker subtype: PositiveIntegerMaker (?)

The related properties can then be tied to this Maker in FOPropertyMapping. 
The make(PropertyList, String, FObj) implementation, which parses the specified attribute value, can be made to force this rounding (see also TableFObj.ColumnNumberPropertyMaker for a prototype).

Comment 2 Simon Pepping 2008-04-08 06:47:20 UTC
Created attachment 21794 [details]
A patch for the problem

This patch does as suggested: It introduces a NumberProperty.PositiveIntegerMaker, which inherits from NumberProperty.Maker. Its make method checks whether a numeric value can be extracted, and if so, rounds it to an integer, and replaces values <= 0 with 1. I made this the maker of number-columns-repeated, and made ColumnNumberPropertyMaker inherit from it. It should become the maker of more properties, to be done later.
Comment 3 Simon Pepping 2008-04-18 12:07:18 UTC
Fixed in revision 649657, by creating NumberProperty.PositiveIntegerMaker, which implements convertProperty. Note that it is not a good idea to reimplement make. Rather on reimplements convertProperty, which is called by make.
Comment 4 Glenn Adams 2012-04-01 07:00:18 UTC
batch transition pre-FOP1.0 resolved+fixed bugs to closed+fixed