The right place to add a validation hook is to override commit() or
prepareForCommit() in XWPFDocument (or any other sub-class of
POIXMLDocument). You may want to do something like this:
XWPFDocument doc = new XWPFDocument(){
@Override
protected void prepareForCommit() throws IOException {
for(XWPFHeader header : getHeaderList()){
if(header.getListParagraph().isEmpty()){
throw new IOException("header was created without a paragraph");
}
}
super.prepareForCommit();
}
};
this way you can perform custom validations independently of the checks
hardcoded in the POI API.
Yegor
On Sun, Oct 30, 2016 at 3:54 PM, Mark Murphy <[email protected]> wrote:
> That might work. for the validations I was talking about, I can just make
> it right. but for things like Javen was talking about, there might need to
> be a way to break out of the save, maybe a new Exception that inherits from
> IOException would be the best onSave doesn't catch it, but it does pass
> IOExceptions on to the caller.
>
> On Sun, Oct 30, 2016 at 6:37 AM, Nick Burch <[email protected]> wrote:
>
> > On Sun, 30 Oct 2016, Mark Murphy wrote:
> >
> >> Is there a validation hook in POIXMLDocument that will allow a document
> to
> >> validate itself before it writes itself to disk?
> >>
> >
> > Maybe prepareForCommit() ? (Need to call superclass too!)
> >
> > Here is the use case. An XWPFDocument header or footer must contain at
> >> least an empty paragraph. If a header or footer is created without a
> >> paragraph, this hook would let me determine this, and just put one in
> there
> >> rather than generating a corrupt document.
> >>
> >
> > You could do it in prepareForCommit or commit of XWPFHeaderFooter
> >
> > Nick
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [email protected]
> > For additional commands, e-mail: [email protected]
> >
> >
>