本文整理汇总了Java中org.apache.xmlbeans.XmlError类的典型用法代码示例。如果您正苦于以下问题:Java XmlError类的具体用法?Java XmlError怎么用?Java XmlError使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
XmlError类属于org.apache.xmlbeans包,在下文中一共展示了XmlError类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validate
import org.apache.xmlbeans.XmlError; //导入依赖的package包/类
/**
* Performs validation on the XmlBean, populating the error message if failed.
* @return false if the XmlBean is invalid (error message is available in getValidationError()).
*/
public boolean validate() {
_validationError = null;
List<XmlError> errors = new ArrayList<XmlError>();
boolean valid = _xmlBean.validate(new XmlOptions().setErrorListener(errors));
if (!valid) {
_validationError = "";
for (int i = 0; i < errors.size(); i++) {
_validationError += errors.get(i).toString();
if (i < errors.size() - 1)
_validationError += '\n';
}
}
return valid;
}
示例2: checkForErrors
import org.apache.xmlbeans.XmlError; //导入依赖的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);
}
}
}
示例3: ingestNotification
import org.apache.xmlbeans.XmlError; //导入依赖的package包/类
/**
* Ingests a raw xml by calling ingester
*
* @param xml - XmlObject instance to be inserted
* @param docType - Document type
* @param relationship - Name of the relationship to be ingested, for logging
* @param type - Type of the notification
* @throws IngestException
*/
private void ingestNotification(XmlObject xml, String docType, String relationship,
NotificationTypeEnum type) throws IngestException {
log.debug("Ingesting Raw Notification for " + relationship);
if (log.isDebugEnabled())
log.debug(relationship + "Doc:\n" + xml.xmlText(IngesterConstants.PRETTY_PRINT_OPTS));
// validation errors
List<XmlError> errors = new ArrayList<XmlError>();
// if the xml validates properly, store it
if (xml.validate(new XmlOptions().setErrorListener(errors))) {
Calendar storeTime = Calendar.getInstance();
ingester.storeRawNotification(type, storeTime, xml);
} else {
log.error(IngesterConstants.EXPMSG_INVALID_NOTIFICATION + docType);
for (XmlError err : errors) {
if (err instanceof XmlValidationError) {
XmlValidationError validationError = (XmlValidationError) err;
log.error("Message : " + validationError.getMessage());
}
}
throw new IngestException(IngesterConstants.EXPMSG_INVALID_NOTIFICATION + docType);
}
}
示例4: validateXml
import org.apache.xmlbeans.XmlError; //导入依赖的package包/类
/**
* <p>Validates the XML, printing error messages when the XML is invalid. Note
* that this method will properly validate any instance of a compiled schema
* type because all of these types extend XmlObject.</p>
*
* <p>Note that in actual practice, you'll probably want to use an assertion
* when validating if you want to ensure that your code doesn't pass along
* invalid XML. This sample prints the generated XML whether or not it's
* valid so that you can see the result in both cases.</p>
*
* @param xml The XML to validate.
* @return <code>true</code> if the XML is valid; otherwise, <code>false</code>
*/
public static boolean validateXml(XmlObject xml) {
boolean isXmlValid = false;
// A collection instance to hold validation error messages.
ArrayList<XmlError> validationMessages = new ArrayList<XmlError>();
// Validate the XML, collecting messages.
isXmlValid = xml.validate(
new XmlOptions().setErrorListener(validationMessages));
// If the XML isn't valid, print the messages.
if (!isXmlValid) {
System.out.println("\nInvalid XML: ");
for (int i = 0; i < validationMessages.size(); i++) {
XmlError error = validationMessages.get(i);
System.out.println(error.getMessage());
System.out.println(error.getObjectLocation());
}
}
return isXmlValid;
}
示例5: validate
import org.apache.xmlbeans.XmlError; //导入依赖的package包/类
@Override
public void validate() throws EbicsException {
ArrayList<XmlError> validationMessages;
boolean isValid;
validationMessages = new ArrayList<XmlError>();
isValid = document.validate(new XmlOptions().setErrorListener(validationMessages));
if (!isValid) {
String message;
Iterator<XmlError> iter;
iter = validationMessages.iterator();
message = "";
while (iter.hasNext()) {
if (!message.equals("")) {
message += ";";
}
message += iter.next().getMessage();
}
throw new EbicsException(message);
}
}
示例6: validate
import org.apache.xmlbeans.XmlError; //导入依赖的package包/类
@Override
public void validate() throws AxelorException {
ArrayList<XmlError> validationMessages;
boolean isValid;
validationMessages = new ArrayList<XmlError>();
isValid = document.validate(new XmlOptions().setErrorListener(validationMessages));
if (!isValid) {
String message;
Iterator<XmlError> iter;
iter = validationMessages.iterator();
message = "";
while (iter.hasNext()) {
if (!message.equals("")) {
message += ";";
}
message += iter.next().getMessage();
}
throw new AxelorException(message, IException.CONFIGURATION_ERROR);
}
}
示例7: validate
import org.apache.xmlbeans.XmlError; //导入依赖的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());
}
示例8: testQueryCreation
import org.apache.xmlbeans.XmlError; //导入依赖的package包/类
@Test
public void testQueryCreation() throws Exception {
ConfigurationRegistryMockup.init();
RouteSegmentType route = createRouteSegment();
Collection<XmlError> errors = XMLBeansParser.validate(route);
Assert.assertTrue("RouteSegment is not valid! "+ errors, errors.isEmpty());
SimpleAltitudeQuery query = new SimpleAltitudeQuery("aixm:Airspace", 1, "0003D6AF-8619-4165-9FAA-8299303AA418", route.getTimeSliceArray(0).getRouteSegmentTimeSlice());
Assert.assertTrue("Could not create simple altitude query!", query.createQuery() != null);
query = new SimpleAltitudeQuery("aixm:Airspace", 1, "0003D6AF-8619-4165-9FAA-8299303AA418", createDWithin());
Assert.assertTrue("Could not create simple altitude query!", query.createQuery() != null);
// Map<String,String> user = new HashMap<String, String>();
// user.put(WFSConnector.USER_KEY, "IfGI");
// user.put(WFSConnector.PASSWORD_KEY, "test");
// WFSConnector wfs = new WFSConnector("http://91.221.120.150:13871/cadas-aimdb/wfs", true, user);
// XmlObject[] result = wfs.executeQuery(query);
//
// System.out.println(result);
}
示例9: validateDoc
import org.apache.xmlbeans.XmlError; //导入依赖的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;
}
示例10: setUp
import org.apache.xmlbeans.XmlError; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
xmlErrors = new ArrayList<XmlError>();
xmlOptions = new XmlOptions();
/// xmlOptions.setValidateOnSet();
xmlOptions.setErrorListener(xmlErrors);
}
示例11: validateDocument
import org.apache.xmlbeans.XmlError; //导入依赖的package包/类
public boolean validateDocument (XmlObject xmlObject) {
boolean valid = xmlObject.validate(xmlOptions);
if (!valid) {
logger.error(xmlObject.schemaType() + " failed to validate ");
for (XmlError xmlError : xmlErrors) {
logger.error(xmlError);
}
}
assertTrue(valid);
return valid;
}
示例12: printXMLErrors
import org.apache.xmlbeans.XmlError; //导入依赖的package包/类
private void printXMLErrors(List<XmlError> xmlErrors) {
if (xmlErrors == null) {
return;
}
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());
}
示例13: getEventParameters
import org.apache.xmlbeans.XmlError; //导入依赖的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;
}
示例14: validateDoc
import org.apache.xmlbeans.XmlError; //导入依赖的package包/类
public ArrayList validateDoc( HsfHmpDataDocument doc ) throws IOException, XmlException
{
logger.info( "<?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;
}
示例15: load
import org.apache.xmlbeans.XmlError; //导入依赖的package包/类
@Override
public synchronized void load(InputStream inStream) throws IOException {
EventServiceConfigurationDocument doc = null;
try {
doc = EventServiceConfigurationDocument.Factory.parse(inStream);
XmlOptions opts = new XmlOptions();
ArrayList<XmlError> a = new ArrayList<XmlError>();
opts.setErrorListener(a);
if (!doc.validate(opts)) {
throw new IOException("Configuration is not valid: "+a);
}
} catch (XmlException e) {
throw new IOException(e);
}
for (Parameter param : doc.getEventServiceConfiguration().getParameters().getParameterArray()) {
this.setProperty(param.getName(), param.getValue());
}
for (Parser parser : doc.getEventServiceConfiguration().getRegisteredParsers().getParserArray()) {
if (parser.getEnabled()) {
this.registeredParsers.add(parser.getJavaClass());
} else {
this.disabledRegisteredParsers.add(parser.getJavaClass());
}
}
}