//
// Create and initialize the document, or parse the given one (with which we'll merge).
//
FormValidationDocument doc;
if ( mergeFile != null && mergeFile.canRead() )
{
doc = FormValidationDocument.Factory.parse( mergeFile );
}
else
{
doc = FormValidationDocument.Factory.newInstance();
}
XmlDocumentProperties dp = doc.documentProperties();
if ( dp.getDoctypeName() == null )
{
dp.setDoctypeName( "form-validation" ); // NOI18N
}
if ( dp.getDoctypePublicId() == null )
{
if ( _validatorVersion.equals( ValidatorVersion.oneZero ) )
{
dp.setDoctypePublicId( "-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.0//EN" );
}
else
{
dp.setDoctypePublicId( "-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.1//EN" );
}
}
if ( dp.getDoctypeSystemId() == null )
{
if ( _validatorVersion.equals( ValidatorVersion.oneZero ) )
{
dp.setDoctypeSystemId( "http://jakarta.apache.org/commons/dtds/validator_1_0.dtd" );
}
else
{
dp.setDoctypeSystemId( "http://jakarta.apache.org/commons/dtds/validator_1_1.dtd" );
}
}
FormValidationDocument.FormValidation formValidationElement = doc.getFormValidation();
if ( formValidationElement == null )
{
formValidationElement = doc.addNewFormValidation();
}
//
// Write the "generated by" comment.
//
XmlCursor curs = formValidationElement.newCursor();
String headerComment = getHeaderComment( mergeFile );
if ( headerComment != null ) curs.insertComment( headerComment );
//
// Now write out all the LocaleSets, which contain the forms/fields/rules.
//
writeLocaleSets( formValidationElement );
writeLocaleSet( _defaultLocaleSet, formValidationElement );
//
// Write the file.
//
XmlOptions options = new XmlOptions();
options.setSavePrettyPrint();
doc.save( outputStream, options );
}