本文整理匯總了Java中org.apache.xmlbeans.XmlOptions.setErrorListener方法的典型用法代碼示例。如果您正苦於以下問題:Java XmlOptions.setErrorListener方法的具體用法?Java XmlOptions.setErrorListener怎麽用?Java XmlOptions.setErrorListener使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.xmlbeans.XmlOptions
的用法示例。
在下文中一共展示了XmlOptions.setErrorListener方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: addXmlToStream
import org.apache.xmlbeans.XmlOptions; //導入方法依賴的package包/類
public boolean addXmlToStream(LoggedInInfo loggedInInfo, Writer os, XmlOptions opts, Integer rourkeFdid, Integer nddsFdid, Integer report18mFdid, boolean useClinicInfoForOrganizationId) throws IOException {
if (rourkeFdid==null && nddsFdid==null && report18mFdid==null) return false;
BORN18MEWBVBatchDocument bornBatchDocument = ca.bornontario.x18MEWBV.BORN18MEWBVBatchDocument.Factory.newInstance();
BORN18MEWBVBatch bornBatch = bornBatchDocument.addNewBORN18MEWBVBatch();
PatientInfo patientInfo = bornBatch.addNewPatientInfo();
propulatePatientInfo(patientInfo, rourkeFdid, useClinicInfoForOrganizationId);
if (nddsFdid!=null) propulateNdds(patientInfo.addNewNDDS(), nddsFdid);
if (rourkeFdid!=null) propulateRourke(loggedInInfo, patientInfo.addNewRBR(), rourkeFdid);
if (report18mFdid!=null) propulateM18Markers(patientInfo.addNewM18MARKERS(), report18mFdid);
//xml validation
XmlOptions m_validationOptions = new XmlOptions();
ArrayList<Object> validationErrors = new ArrayList<Object>();
m_validationOptions.setErrorListener(validationErrors);
if(!bornBatchDocument.validate(m_validationOptions)) {
MiscUtils.getLogger().warn("forms failed validation");
for(Object o:validationErrors) {
MiscUtils.getLogger().warn(o);
}
}
bornBatchDocument.save(os,opts);
return true;
}
示例2: validateDoc
import org.apache.xmlbeans.XmlOptions; //導入方法依賴的package包/類
public ArrayList validateDoc(HsfoHbpsDataDocument doc) throws IOException,
XmlException
{
if (logger.isDebugEnabled())
logger.debug("<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "\n"
+ PrettyPrinter.indent(doc.xmlText()));
ArrayList messageArray = new ArrayList();
XmlOptions option = new XmlOptions();
ArrayList validationErrors = new ArrayList();
option.setErrorListener(validationErrors);
if (doc.validate(option) == false)
{
String sb = printErrors(validationErrors);
messageArray.add(sb);
return messageArray;
} else
return messageArray;
}
示例3: generateXMLAndValidate
import org.apache.xmlbeans.XmlOptions; //導入方法依賴的package包/類
@Test
public void generateXMLAndValidate() throws Exception {
ARRecordSetDocument recordSetD = ARRecordSetDocument.Factory.newInstance();
ARRecordSet recordSet = recordSetD.addNewARRecordSet();
ARRecord arRecord = recordSet.addNewARRecord();
AR1 ar1 = arRecord.addNewAR1();
populateAr1(ar1);
AR2 ar2 = arRecord.addNewAR2();
populateAr2(ar2);
HashMap<String,String> suggestedPrefixes = new HashMap<String,String>();
suggestedPrefixes.put("http://www.oscarmcmaster.org/AR2005", "");
suggestedPrefixes.put("http://www.w3.org/2001/XMLSchema-instance","xsi");
XmlOptions opts = new XmlOptions();
opts.setSaveSuggestedPrefixes(suggestedPrefixes);
opts.setSavePrettyPrint();
ArrayList validationErrors = new ArrayList();
XmlOptions m_validationOptions = new XmlOptions();
m_validationOptions.setErrorListener(validationErrors);
recordSetD.validate(m_validationOptions);
for(Object o:validationErrors) {
System.out.println(o);
}
recordSetD.save(new FileOutputStream("ar2005.xml"),opts);
}
示例4: checkForErrors
import org.apache.xmlbeans.XmlOptions; //導入方法依賴的package包/類
private void checkForErrors(WctDataExtractor wctData, MetsWriter metsWriter) {
List<XmlError> errors = new ArrayList<XmlError>();
XmlOptions opts = new XmlOptions();
opts.setErrorListener(errors);
if (!metsWriter.validate(opts)) {
StringBuilder errorMessage = new StringBuilder();
for (XmlError error : errors)
// ignore error relating to missing structure map as we are not adding one.
if(!error.getMessage().matches("(Expected element).*(structMap).*")){
errorMessage.append(error.toString());
}
if(errorMessage.length() > 0){
String msg = String.format("WCT Harvest Instance %s: The METs writer failed to produce a valid document, error message: %s",
wctData.getWctTargetInstanceID(), errorMessage);
log.error(msg);
throw new RuntimeException(msg);
}
}
}
示例5: validate
import org.apache.xmlbeans.XmlOptions; //導入方法依賴的package包/類
/**
* Validates a specified XmlObject along with logging errors if any.
*
* @param xmlObject
*/
public static void validate(XmlObject xmlObject) throws AiravataException {
XmlOptions validateOptions = new XmlOptions();
ArrayList errorList = new ArrayList();
validateOptions.setErrorListener(errorList);
boolean isValid = xmlObject.validate(validateOptions);
if (isValid) {
// Valid
return;
}
// Error
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < errorList.size(); i++) {
XmlError error = (XmlError) errorList.get(i);
logger.warn("Message: " + error.getMessage());
logger.warn("Location of invalid XML: " + error.getCursorLocation().xmlText());
stringBuilder.append("Message:" + error.getMessage());
stringBuilder.append("Location of invalid XML: " + error.getCursorLocation().xmlText());
}
throw new AiravataException(stringBuilder.toString());
}
示例6: addXmlToStream
import org.apache.xmlbeans.XmlOptions; //導入方法依賴的package包/類
public boolean addXmlToStream(Writer os, XmlOptions opts, Integer rourkeFdid, Integer nddsFdid, Integer report18mFdid) throws IOException {
if (rourkeFdid==null && nddsFdid==null && report18mFdid==null) return false;
BORN18MEWBVBatchDocument bornBatchDocument = ca.bornontario.x18MEWBV.BORN18MEWBVBatchDocument.Factory.newInstance();
BORN18MEWBVBatch bornBatch = bornBatchDocument.addNewBORN18MEWBVBatch();
PatientInfo patientInfo = bornBatch.addNewPatientInfo();
propulatePatientInfo(patientInfo, rourkeFdid);
if (nddsFdid!=null) propulateNdds(patientInfo.addNewNDDS(), nddsFdid);
if (rourkeFdid!=null) propulateRourke(patientInfo.addNewRBR(), rourkeFdid);
if (report18mFdid!=null) propulateM18Markers(patientInfo.addNewM18MARKERS(), report18mFdid);
//xml validation
XmlOptions m_validationOptions = new XmlOptions();
ArrayList<Object> validationErrors = new ArrayList<Object>();
m_validationOptions.setErrorListener(validationErrors);
if(!bornBatchDocument.validate(m_validationOptions)) {
MiscUtils.getLogger().warn("forms failed validation");
for(Object o:validationErrors) {
MiscUtils.getLogger().warn(o);
}
}
bornBatchDocument.save(os,opts);
return true;
}
示例7: validateDoc
import org.apache.xmlbeans.XmlOptions; //導入方法依賴的package包/類
public ArrayList validateDoc(HsfoHbpsDataDocument doc) throws IOException,
XmlException
{
if (logger.isInfoEnabled())
logger.info("<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "\n"
+ PrettyPrinter.indent(doc.xmlText()));
ArrayList messageArray = new ArrayList();
XmlOptions option = new XmlOptions();
ArrayList validationErrors = new ArrayList();
option.setErrorListener(validationErrors);
if (doc.validate(option) == false)
{
String sb = printErrors(validationErrors);
messageArray.add(sb);
return messageArray;
} else
return messageArray;
}
示例8: generateXMLAndValidate
import org.apache.xmlbeans.XmlOptions; //導入方法依賴的package包/類
public void generateXMLAndValidate(LoggedInInfo loggedInInfo, OutputStream os, String providerNo,String demographicNo, int formId, int episodeId) throws Exception {
this.demographicNo = demographicNo;
this.providerNo = providerNo;
this.formId = formId;
this.episodeId = episodeId;
FrmRecord rec = (new FrmRecordFactory()).factory("ONAREnhanced");
props = rec.getFormRecord(loggedInInfo, Integer.parseInt(demographicNo), formId);
ARRecordSetDocument recordSetD = ARRecordSetDocument.Factory.newInstance();
ARRecordSet recordSet = recordSetD.addNewARRecordSet();
ARRecord arRecord = recordSet.addNewARRecord();
AR1 ar1 = arRecord.addNewAR1();
populateAr1(ar1,providerNo);
AR2 ar2 = arRecord.addNewAR2();
populateAr2(ar2);
HashMap<String,String> suggestedPrefixes = new HashMap<String,String>();
suggestedPrefixes.put("http://www.oscarmcmaster.org/AR2005", "");
suggestedPrefixes.put("http://www.w3.org/2001/XMLSchema-instance","xsi");
XmlOptions opts = new XmlOptions();
opts.setSaveSuggestedPrefixes(suggestedPrefixes);
opts.setSavePrettyPrint();
ArrayList validationErrors = new ArrayList();
XmlOptions m_validationOptions = new XmlOptions();
m_validationOptions.setErrorListener(validationErrors);
recordSetD.validate(m_validationOptions);
for(Object o:validationErrors) {
MiscUtils.getLogger().warn(o);
}
recordSetD.save(os,opts);
}
示例9: addXmlToStream
import org.apache.xmlbeans.XmlOptions; //導入方法依賴的package包/類
public boolean addXmlToStream(LoggedInInfo loggedInInfo, Writer os, XmlOptions opts, String providerNo,String demographicNo, int formId, int episodeId) throws Exception {
this.demographicNo = demographicNo;
this.providerNo = providerNo;
this.formId = formId;
this.episodeId = episodeId;
FrmRecord rec = (new FrmRecordFactory()).factory("ONAREnhanced");
props = rec.getFormRecord(loggedInInfo, Integer.parseInt(demographicNo), formId);
if(StringUtils.isEmpty(props.getProperty("pg1_formDate")) || StringUtils.isEmpty(props.getProperty("pg2_formDate"))) {
MiscUtils.getLogger().warn("skipping form since the signature dates are not both set");
return false;
}
//ARRecord arRecord = ARRecord.Factory.newInstance();
ARRecordDocument arRecordDoc = ARRecordDocument.Factory.newInstance();
ARRecord arRecord = arRecordDoc.addNewARRecord();
AR1 ar1 = arRecord.addNewAR1();
populateAr1(ar1,providerNo);
AR2 ar2 = arRecord.addNewAR2();
populateAr2(ar2);
XmlOptions m_validationOptions = new XmlOptions();
ArrayList validationErrors = new ArrayList();
m_validationOptions.setErrorListener(validationErrors);
if(arRecordDoc.validate(m_validationOptions)) {
arRecordDoc.save(os,opts);
return true;
} else {
MiscUtils.getLogger().warn("form failed validation:"+formId);
for(Object o:validationErrors) {
MiscUtils.getLogger().warn(o);
}
}
return false;
}
示例10: addXmlToStream2
import org.apache.xmlbeans.XmlOptions; //導入方法依賴的package包/類
public FrmRecord addXmlToStream2(LoggedInInfo loggedInInfo, Writer os, XmlOptions opts, String providerNo,String demographicNo, int formId, int episodeId) throws Exception {
this.demographicNo = demographicNo;
this.providerNo = providerNo;
this.formId = formId;
this.episodeId = episodeId;
FrmRecord rec = (new FrmRecordFactory()).factory("ONAREnhanced");
props = rec.getFormRecord(loggedInInfo, Integer.parseInt(demographicNo), formId);
//ARRecord arRecord = ARRecord.Factory.newInstance();
ARRecordDocument arRecordDoc = ARRecordDocument.Factory.newInstance();
ARRecord arRecord = arRecordDoc.addNewARRecord();
AR1 ar1 = arRecord.addNewAR1();
populateAr1(ar1,providerNo);
AR2 ar2 = arRecord.addNewAR2();
populateAr2(ar2);
XmlOptions m_validationOptions = new XmlOptions();
ArrayList validationErrors = new ArrayList();
m_validationOptions.setErrorListener(validationErrors);
if(arRecordDoc.validate(m_validationOptions)) {
arRecordDoc.save(os,opts);
return rec;
} else {
MiscUtils.getLogger().warn("form failed validation:"+formId);
for(Object o:validationErrors) {
MiscUtils.getLogger().warn(o);
}
}
return null;
}
示例11: addToStream
import org.apache.xmlbeans.XmlOptions; //導入方法依賴的package包/類
public boolean addToStream(Writer os, XmlOptions opts, Integer demographicNo, boolean useClinicInfoForOrganizationId) throws IOException {
BORNWBCSDBatchDocument bornBatchDocument = BORNWBCSDBatchDocument.Factory.newInstance();
BORNWBCSDBatch bornBatch = bornBatchDocument.addNewBORNWBCSDBatch();
PatientInfo patientInfo = bornBatch.addNewPatientInfo();
//populate patient info
populatePatientInfo(patientInfo, demographicNo, useClinicInfoForOrganizationId);
populateVisitData(patientInfo, demographicNo);
populateImmunizationData(patientInfo, demographicNo);
populateReferralData(patientInfo, demographicNo);
////business validation
//business validation
if (!isAgeLessThan7y(patientInfo)) {
MiscUtils.getLogger().warn("Child is over 6.5 years old..skipping");
return false;
}
//TODO: xml validation - how can we report the problem better??
XmlOptions m_validationOptions = new XmlOptions();
ArrayList<Object> validationErrors = new ArrayList<Object>();
m_validationOptions.setErrorListener(validationErrors);
if (!bornBatchDocument.validate(m_validationOptions)) {
MiscUtils.getLogger().warn("BORN WBCSD XML failed validation");
for (Object o : validationErrors) {
XmlValidationError xve = (XmlValidationError) o;
MiscUtils.getLogger().warn(o);
}
}
//write to stream provided
bornBatchDocument.save(os, opts);
MiscUtils.getLogger().debug("Wrote out batch document for patient " + demographicNo);
return true;
}
示例12: validateDoc
import org.apache.xmlbeans.XmlOptions; //導入方法依賴的package包/類
public ArrayList validateDoc( HsfHmpDataDocument doc ) throws IOException, XmlException
{
logger.debug( "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "\n" + PrettyPrinter.indent( doc.xmlText() ) );
ArrayList<StringBuilder> messageArray = new ArrayList<StringBuilder>();
XmlOptions option = new XmlOptions();
ArrayList<XmlError> validationErrors = new ArrayList<XmlError>();
option.setErrorListener( validationErrors );
StringBuilder sb = new StringBuilder();
if ( doc.validate( option ) == false )
{
Iterator iter = validationErrors.iterator();
while ( iter.hasNext() ) {
XmlError error = (XmlError)iter.next();
String errorMessage = error.getMessage();
XmlCursor cursor = error.getCursorLocation();
cursor.toParent();
String loc = cursor.xmlText();
String name = getPatientName(doc.xmlText(), loc);
sb.append("\n Patient Name: "+name + " \n ** Error Message: " + errorMessage + " ");
sb.append( loc.substring(loc.indexOf("signedWhen"), loc.indexOf("/")) + " --- ");
messageArray.add( sb );
}
//String sb = printErrors( validationErrors );
messageArray.add( sb );
return messageArray;
}
else
return messageArray;
}
示例13: setUp
import org.apache.xmlbeans.XmlOptions; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception {
xmlErrors = new ArrayList<XmlError>();
xmlOptions = new XmlOptions();
/// xmlOptions.setValidateOnSet();
xmlOptions.setErrorListener(xmlErrors);
}
示例14: getEventParameters
import org.apache.xmlbeans.XmlOptions; //導入方法依賴的package包/類
public EventParameters getEventParameters() {
if (eventParameters == null && file != null) {
try {
XmlOptions xmlOptions = new XmlOptions();
List<XmlError> xmlErrors = null;
if (LOG.isEnabled(Level.DEBUG)) {
xmlErrors = new ArrayList();
xmlOptions.setErrorListener(xmlErrors);
xmlOptions.setLoadLineNumbers();
}
QuakemlDocument qmlDoc = QuakemlDocument.Factory.parse(file, xmlOptions);
if (qmlDoc.validate(xmlOptions)) {
eventParameters = qmlDoc.getQuakeml().getEventParameters();
} else {
LOG.warn("the document is not valid");
if (xmlErrors != null) {
LOG.debug(String.format("number of validation errors: %s",
xmlErrors.size()));
StringBuilder errStr = new StringBuilder();
errStr.append("validation errors: \n ");
for (XmlError xmlError : xmlErrors) {
errStr.append(String.format("line %s: %s\n",
xmlError.getLine(), xmlError));
}
LOG.debug(errStr.toString());
}
}
} catch (XmlException | IOException ex) {
LOG.error(ex);
}
}
return eventParameters;
}
示例15: parseConfig
import org.apache.xmlbeans.XmlOptions; //導入方法依賴的package包/類
public static DhcpServerConfig parseConfig(String filename)
throws DhcpServerConfigException, XmlException, IOException
{
DhcpServerConfig config = null;
FileInputStream fis = null;
try {
fis = new FileInputStream(filename);
config = DhcpServerConfigDocument.Factory.parse(fis).getDhcpServerConfig();
ArrayList<XmlValidationError> validationErrors = new ArrayList<XmlValidationError>();
XmlOptions validationOptions = new XmlOptions();
validationOptions.setErrorListener(validationErrors);
// During validation, errors are added to the ArrayList
boolean isValid = config.validate(validationOptions);
if (!isValid) {
StringBuilder sb = new StringBuilder();
Iterator<XmlValidationError> iter = validationErrors.iterator();
while (iter.hasNext())
{
sb.append(iter.next());
sb.append('\n');
}
throw new DhcpServerConfigException(sb.toString());
}
}
finally {
if (fis != null) {
fis.close();
}
}
return config;
}