当前位置: 首页>>代码示例>>Java>>正文


Java IParser.setParserErrorHandler方法代码示例

本文整理汇总了Java中ca.uhn.fhir.parser.IParser.setParserErrorHandler方法的典型用法代码示例。如果您正苦于以下问题:Java IParser.setParserErrorHandler方法的具体用法?Java IParser.setParserErrorHandler怎么用?Java IParser.setParserErrorHandler使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ca.uhn.fhir.parser.IParser的用法示例。


在下文中一共展示了IParser.setParserErrorHandler方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import ca.uhn.fhir.parser.IParser; //导入方法依赖的package包/类
public static void main(String[] args) {
	String input = "<Encounter xmlns=\"http://hl7.org/fhir\"><AAAA value=\"foo\"/></Encounter>";

	IParser p = FhirContext.forDstu3().newXmlParser();
	
	// Parse with (default) lenient error handler
	p.setParserErrorHandler(new LenientErrorHandler());
	p.parseResource(input);

	// Parse with strict error handler
	p.setParserErrorHandler(new StrictErrorHandler());
	p.parseResource(input);
}
 
开发者ID:furore-fhir,项目名称:fhirstarters,代码行数:14,代码来源:Example12_ParserErrorHandler.java

示例2: parserValidation

import ca.uhn.fhir.parser.IParser; //导入方法依赖的package包/类
public void parserValidation() {
   // START SNIPPET: parserValidation
   FhirContext ctx = FhirContext.forDstu3();
   
   // Create a parser and configure it to use the strict error handler
   IParser parser = ctx.newXmlParser();
   parser.setParserErrorHandler(new StrictErrorHandler());

   // This example resource is invalid, as Patient.active can not repeat
   String input = "<Patient><active value=\"true\"/><active value=\"false\"/></Patient>";

   // The following will throw a DataFormatException because of the StrictErrorHandler
   parser.parseResource(Patient.class, input);
   // END SNIPPET: parserValidation
}
 
开发者ID:jamesagnew,项目名称:hapi-fhir,代码行数:16,代码来源:ValidatorExamples.java

示例3: testOutOfBoundsDate

import ca.uhn.fhir.parser.IParser; //导入方法依赖的package包/类
/**
 * See issue #50
 */
@Test()
public void testOutOfBoundsDate() {
	Patient p = new Patient();
	p.setBirthDateElement(new DateType("2000-12-31"));

	// Put in an invalid date
	IParser parser = ourCtx.newXmlParser();
	parser.setParserErrorHandler(new StrictErrorHandler());
	
	String encoded = parser.setPrettyPrint(true).encodeResourceToString(p).replace("2000-12-31", "2000-15-31");
	ourLog.info(encoded);

	assertThat(encoded, StringContains.containsString("2000-15-31"));

	ValidationResult result = ourCtx.newValidator().validateWithResult(encoded);
	String resultString = parser.setPrettyPrint(true).encodeResourceToString(result.toOperationOutcome());
	ourLog.info(resultString);

	assertEquals(2, ((OperationOutcome)result.toOperationOutcome()).getIssue().size());
	assertThat(resultString, StringContains.containsString("cvc-pattern-valid"));
	
	try {
		parser.parseResource(encoded);
		fail();
	} catch (DataFormatException e) {
		assertEquals("DataFormatException at [[row,col {unknown-source}]: [2,4]]: Invalid attribute value \"2000-15-31\": Invalid date/time format: \"2000-15-31\"", e.getMessage());
	}
}
 
开发者ID:jamesagnew,项目名称:hapi-fhir,代码行数:32,代码来源:ResourceValidatorDstu2_1Test.java

示例4: forText

import ca.uhn.fhir.parser.IParser; //导入方法依赖的package包/类
public static IValidationContext<IBaseResource> forText(final FhirContext theContext, final String theResourceBody) {
	ObjectUtil.requireNonNull(theContext, "theContext can not be null");
	ObjectUtil.requireNotEmpty(theResourceBody, "theResourceBody can not be null or empty");
	return new BaseValidationContext<IBaseResource>(theContext) {

		private EncodingEnum myEncoding;
		private IBaseResource myParsed;

		@Override
		public IBaseResource getResource() {
			if (myParsed == null) {
				IParser parser = getResourceAsStringEncoding().newParser(getFhirContext());
				LenientErrorHandler errorHandler = new LenientErrorHandler();
				errorHandler.setErrorOnInvalidValue(false);
				parser.setParserErrorHandler(errorHandler);
				myParsed = parser.parseResource(getResourceAsString());
			}
			return myParsed;
		}

		@Override
		public String getResourceAsString() {
			return theResourceBody;
		}

		@Override
		public EncodingEnum getResourceAsStringEncoding() {
			if (myEncoding == null) {
				myEncoding = EncodingEnum.detectEncodingNoDefault(theResourceBody);
				if (myEncoding == null) {
					throw new InvalidRequestException(theContext.getLocalizer().getMessage(ValidationContext.class, "unableToDetermineEncoding"));
				}
			}
			return myEncoding;
		}

	};
}
 
开发者ID:jamesagnew,项目名称:hapi-fhir,代码行数:39,代码来源:ValidationContext.java

示例5: testOutOfBoundsDate

import ca.uhn.fhir.parser.IParser; //导入方法依赖的package包/类
/**
 * See issue #50
 */
@Test()
public void testOutOfBoundsDate() {
	Patient p = new Patient();
	p.setBirthDate(new DateTimeDt("2000-12-31"));

	// Put in an invalid date
	IParser parser = ourCtx.newXmlParser();
	parser.setParserErrorHandler(new StrictErrorHandler());
	
	String encoded = parser.setPrettyPrint(true).encodeResourceToString(p).replace("2000-12-31", "2000-15-31");
	ourLog.info(encoded);

	assertThat(encoded, StringContains.containsString("2000-15-31"));

	FhirValidator validator = ourCtx.newValidator();
	ValidationResult result = validator.validateWithResult(encoded);
	String resultString = parser.setPrettyPrint(true).encodeResourceToString(result.toOperationOutcome());
	ourLog.info(resultString);

	assertEquals(2, ((OperationOutcome)result.toOperationOutcome()).getIssue().size());
	assertThat(resultString, StringContains.containsString("cvc-datatype-valid.1.2.3"));
	
	try {
		parser.parseResource(encoded);
		fail();
	} catch (DataFormatException e) {
		assertEquals("DataFormatException at [[row,col {unknown-source}]: [2,4]]: Invalid attribute value \"2000-15-31\": Invalid date/time format: \"2000-15-31\"", e.getMessage());
	}
}
 
开发者ID:jamesagnew,项目名称:hapi-fhir,代码行数:33,代码来源:ResourceValidatorTest.java

示例6: testJsonLikeSimpleResourceEncode

import ca.uhn.fhir.parser.IParser; //导入方法依赖的package包/类
@Test
public void testJsonLikeSimpleResourceEncode() throws IOException {

	String xmlString = IOUtils.toString(JsonParser.class.getResourceAsStream("/example-patient-general.xml"), Charset.forName("UTF-8"));
	IParser parser = ourCtx.newXmlParser();
	parser.setParserErrorHandler(new StrictErrorHandler());
	Patient obs = parser.parseResource(Patient.class, xmlString);

	IJsonLikeParser jsonLikeParser = (IJsonLikeParser)ourCtx.newJsonParser();
	StringWriter stringWriter = new StringWriter();
	JsonLikeStructure jsonLikeStructure = new GsonStructure();
	JsonLikeWriter jsonLikeWriter = jsonLikeStructure.getJsonLikeWriter(stringWriter);
	jsonLikeParser.encodeResourceToJsonLikeWriter(obs, jsonLikeWriter);
	String encoded = stringWriter.toString();
	ourLog.info(encoded);

	String jsonString = IOUtils.toString(JsonParser.class.getResourceAsStream("/example-patient-general.json"), Charset.forName("UTF-8"));

	JSON expected = JSONSerializer.toJSON(jsonString);
	JSON actual = JSONSerializer.toJSON(encoded.trim());

	// The encoded escapes quote marks using XML escaping instead of JSON escaping, which is probably nicer anyhow...
	String exp = expected.toString().replace("\\\"Jim\\\"", "&quot;Jim&quot;");
	String act = actual.toString();

	ourLog.info("Expected: {}", exp);
	ourLog.info("Actual  : {}", act);
	assertEquals("\nExpected: " + exp + "\nActual  : " + act, exp, act);

}
 
开发者ID:jamesagnew,项目名称:hapi-fhir,代码行数:31,代码来源:JsonLikeParserTest.java

示例7: testOutOfBoundsDate

import ca.uhn.fhir.parser.IParser; //导入方法依赖的package包/类
/**
 * See issue #50
 */
@Test()
public void testOutOfBoundsDate() {
	Patient p = new Patient();
	p.setBirthDateElement(new DateType("2000-12-31"));

	// Put in an invalid date
	IParser parser = ourCtx.newXmlParser();
	parser.setParserErrorHandler(new StrictErrorHandler());

	String encoded = parser.setPrettyPrint(true).encodeResourceToString(p).replace("2000-12-31", "2000-15-31");
	ourLog.info(encoded);

	assertThat(encoded, StringContains.containsString("2000-15-31"));

	ValidationResult result = ourCtx.newValidator().validateWithResult(encoded);
	String resultString = parser.setPrettyPrint(true).encodeResourceToString(result.toOperationOutcome());
	ourLog.info(resultString);

	assertEquals(2, ((OperationOutcome) result.toOperationOutcome()).getIssue().size());
	assertThat(resultString, StringContains.containsString("cvc-pattern-valid"));

	try {
		parser.parseResource(encoded);
		fail();
	} catch (DataFormatException e) {
		assertEquals("DataFormatException at [[row,col {unknown-source}]: [2,4]]: Invalid attribute value \"2000-15-31\": Invalid date/time format: \"2000-15-31\"", e.getMessage());
	}
}
 
开发者ID:jamesagnew,项目名称:hapi-fhir,代码行数:32,代码来源:ResourceValidatorDstu3Test.java


注:本文中的ca.uhn.fhir.parser.IParser.setParserErrorHandler方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。