本文将为您提供关于使用MarshallerExtraLine写入xml文件的详细介绍,我们还将为您解释incompatiblemarshalfile的相关知识,同时,我们还将为您提供关于asp.net
本文将为您提供关于使用 Marshaller Extra Line 写入 xml 文件的详细介绍,我们还将为您解释incompatible marshal file的相关知识,同时,我们还将为您提供关于asp.net-mvc-4 – 无法从程序集’itextsharp,Version = 5.5.3.0,Culture = neutral,PublicKeyToken = 8354ae6d2174ddca’加载类型’iTextSharp.text.html.HtmlParser’、com.amazonaws.transform.JsonUnmarshallerContextImpl的实例源码、com.amazonaws.transform.JsonUnmarshallerContext的实例源码、com.amazonaws.transform.StaxUnmarshallerContext的实例源码的实用信息。
本文目录一览:- 使用 Marshaller Extra Line 写入 xml 文件(incompatible marshal file)
- asp.net-mvc-4 – 无法从程序集’itextsharp,Version = 5.5.3.0,Culture = neutral,PublicKeyToken = 8354ae6d2174ddca’加载类型’iTextSharp.text.html.HtmlParser’
- com.amazonaws.transform.JsonUnmarshallerContextImpl的实例源码
- com.amazonaws.transform.JsonUnmarshallerContext的实例源码
- com.amazonaws.transform.StaxUnmarshallerContext的实例源码
使用 Marshaller Extra Line 写入 xml 文件(incompatible marshal file)
如何解决使用 Marshaller Extra Line 写入 xml 文件?
不知道以前有没有问过这个问题。我找不到类似的问题。
我收到了一个 xml 文件,我需要根据数据库中存储的数据修改某些值。
提供的 XML 文件打印得不是很漂亮,因此在编组要读取的文件之前,我使用了在各种论坛中找到的 Transformer 方法(下面的代码片段)
private static void formatXMLFile(String file) throws Exception {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(new InputSource(new InputStreamReader(new FileInputStream(
file))));
Transformer xformer = TransformerFactory.newInstance().newTransformer();
xformer.setoutputProperty(OutputKeys.METHOD,"xml");
xformer.setoutputProperty(OutputKeys.INDENT,"yes");
xformer.setoutputProperty("{http://xml.apache.org/xslt}indent-amount","2");
xformer.setoutputProperty(OutputKeys.OMIT_XML_DECLaraTION,"yes");
Source source = new DOMSource(document);
Result result = new StreamResult(new File(file));
xformer.transform(source,result);
}
然后我按照下面的代码片段读取格式化文件
private static void read() {
out = new FileOutputStream(outputFile,false);
XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
xmlStreamWriter = outputFactory.createXMLStreamWriter(out,"UTF-8");
XMLInputFactory xmlif = XMLInputFactory.newInstance();
FileReader fr = new FileReader(filePath);
xmlr = xmlif.createXMLStreamReader(fr);
xmlStreamWriter.writeStartDocument("UTF-8","");
xmlStreamWriter.writeStartElement("Header");
xmlStreamWriter.writeCharacters("");
moveto("Header");
xmlStreamWriter.writeStartElement("List");
xmlStreamWriter.writeCharacters("");
xmlStreamWriter.flush();
movetoBefore("Data","Trailer");
//This is where it gets interesting
while (xmlr.getEventType() != XMLStreamReader.END_ELEMENT) {
if (xmlr.getLocalName().equals("Data")) {
if (xmlr.getEventType() == XMLStreamReader.CHaraCTERS) {
xmlr.next();
}
// read a doc element
if (xmlr.getLocalName().equals("Data")) {
JAXBElement<Data> root = umrx.unmarshal(xmlr,Data.class);
docElement = root.getValue();
}
xmlr.nextTag();
// Extra line being printed
mrx.marshal(docElement,out);
}
if (xmlr.getLocalName().equals("Trailer")) {
break;
}
}
}
private void moveto(final String tagName) throws XMLStreamException {
boolean foundTag = false;
if (!(xmlr.getEventType() == XMLStreamReader.START_ELEMENT && xmlr.getLocalName().equals(tagName))) {
while (xmlr.hasNext() && !foundTag) {
int next = xmlr.next();
if (next == XMLStreamReader.START_ELEMENT) {
foundTag = xmlr.getLocalName().equals(tagName);
}
}
}
}
// this method is used to search for a particular xml tag before the ''beforeTagName''
private void movetoBefore(final String tagName,final String beforeTagName) throws XMLStreamException {
boolean stopSearch = false;
if (!(xmlr.getEventType() == XMLStreamReader.START_ELEMENT && xmlr.getLocalName().equals(tagName))) {
while (xmlr.hasNext() && !stopSearch) {
int next = xmlr.next();
if (next == XMLStreamReader.START_ELEMENT) {
// move to a particular tag until,xml tag is found or beforeTagName is found
stopSearch = xmlr.getLocalName().equals(tagName)
|| xmlr.getLocalName().equals(beforeTagName);
}
}
}
}
程序完成后,我打开文件我注意到一个额外的 LF 字段,因此在 </Data>
和 <Data>
之间有一个额外的空间,如下所示。
我不知道问题是否与我读/写文件的方式有关。不幸的是,我对 JAXB 不是 100% 有信心。你能告诉我我做错了什么吗?
<?xml version="1.0" encoding="UTF-8"?>
<File>
<Header>
<Date>2021-05-11+02:00</Date>
</Header>
<List>
<Data>
<value>b</value>
</Data>
<Data>
<value>a</value>
</Data>
</List>
<Trailer>
<RecsCnt>2</RecsCnt>
</Trailer>
</File>
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
asp.net-mvc-4 – 无法从程序集’itextsharp,Version = 5.5.3.0,Culture = neutral,PublicKeyToken = 8354ae6d2174ddca’加载类型’iTextSharp.text.html.HtmlParser’
我使用RazorPDF完成了一个简单的应用程序.
应用程序是以PDF格式显示普通页面.
我已经创建了一个新的应用程序,它运行正常.但是,当我在我的项目中实现时它不起作用并且给出错误,因为无法从程序集’itextsharp中加载类型’iTextSharp.text.html.HtmlParser’,Version = 5.5.3.0,Culture = neutral,PublicKeyToken = 8354ae6d2174ddca’.
我研究了这个,发现了为什么它显示这个错误的概念,因为bcoz在安装RazorPDF时没有在iTextSharp中安装HtmlParser.
我没有得到的一点是,如果我在新应用程序中做同样的事情,它正在安装一切,并且代码工作正常,如果我在我的项目中做同样的事情,它不是通过我安装所有的东西得到这个错误.
代码工作正常,毫无疑问.问题是在安装RazorPDF时
在我的项目中,它没有在iTextSharp(HtmlEncoder,HtmlTags,HtmlUtilities,WebColors,HtmlParser,Markup,ITextmyHtmlHandler,HtmlWriter,HtmlTagMap)中安装所有9个子包,它只安装了4个子包(HtmlEncoder,WebColors).
由于HtmlParser尚未安装,它是否显示此问题?
有没有人知道这个(RazorPDF).可以帮我解决这个问题吗?
编码
调节器
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using pdf.Models; namespace pdf.Controllers { public class StudentsController : Controller { public ActionResult Index() { var studentMarks = new List<MarksCard>() { new MarksCard(){ RollNo = 101,Subject = "C#",FullMarks = 100,Obtained = 90},new MarksCard() {RollNo = 101,Subject = "asp.net",Obtained = 80},Subject = "MVC",Obtained = 100},Subject = "sql Server",Obtained = 75},}; return new RazorPDF.PdfResult(studentMarks,"Index"); } } }
模型
using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace pdf.Models { public class MarksCard { public int RollNo { get; set; } public string Subject { get; set; } public int FullMarks { get; set; } public int Obtained { get; set; } } }
视图
@model IEnumerable<pdf.Models.MarksCard> @{ Layout = null; } <!DOCTYPE html> <html> <body> <table border="1" width='500' bordercolor="RED"><tr><td colspan="3" bgcolor="LightGreen" align="center" valign="top"> SSLC Marks Sheet 2013</td></tr><tr><td> @{ var rollNumber = Model.Select(z => z.RollNo).Take(1).ToArray();} Riyaz Akhter<br />RollNo:@rollNumber[0]</td></tr> <tr> <td bgcolor="lightblue">@Html.displayNameFor(moel => moel.Subject)</td> <td bgcolor="lightblue">@Html.displayNameFor(model => model.FullMarks)</td> <td bgcolor="lightblue">@Html.displayNameFor(model => model.Obtained)</td></tr> @{ int total = 0; } @foreach (var item in Model) { <tr><td>@Html.displayFor(modelItem => item.Subject)</td> <td>@Html.displayFor(modelItem => item.FullMarks)</td> <td>@Html.displayFor(modelItem => item.Obtained)</td> </tr>total += item.Obtained; } <tr><td> </td> <td> <strong><font color="GREEN">Total</font></strong> </td> <td>@total</td></tr> </table> </body> </html>
解决方法
http://forums.asp.net/t/1925729.aspx?how+to+create+pdf+file+using+razor+pdf
我相信这正是你要找的.
com.amazonaws.transform.JsonUnmarshallerContextImpl的实例源码
private JsonUnmarshallerContext setupUnmarshaller(String body,Map<String,String> headers) throws Exception { HttpResponse httpResponse = new HttpResponse(null,null); for (Map.Entry<String,String> header : headers.entrySet()) { httpresponse.addheader(header.getKey(),header.getValue()); } JsonParser jsonParser = jsonFactory.createParser(new ByteArrayInputStream(body.getBytes())); return new JsonUnmarshallerContextImpl(jsonParser,SdkStructuredplainjsonFactory.JSON_SCALAR_UNMARSHALLERS,SdkStructuredplainjsonFactory.JSON_CUSTOM_TYPE_UNMARSHALLERS,httpResponse); }
/** * Use SWF API to unmarshal a json document into a {@link DecisionTask}. * Note: json is expected to be in the native format used by SWF */ public static DecisionTask unmarshalDecisionTask(String json) { try { Unmarshaller<DecisionTask,JsonUnmarshallerContext> unmarshaller = new DecisionTaskJsonUnmarshaller(); JsonParser parser = new JsonFactory().createParser(json); return unmarshaller.unmarshall(new JsonUnmarshallerContextImpl(parser)); } catch (Exception e) { throw new IllegalStateException(e); } }
private HalResource parseHalResourceFromClasspath(String classpathFile) throws Exception { InputStream inputStream = this.getClass().getClassLoader().getResourceAsstream(classpathFile); JsonParser jsonParser = new JsonFactory().createJsonParser(inputStream); JsonUnmarshallerContext jsonUnmarshallerContext = new JsonUnmarshallerContextImpl(jsonParser); return HalJsonResourceUnmarshaller.getInstance().unmarshall(jsonUnmarshallerContext); }
/** * @see HttpResponseHandler#handle(HttpResponse) */ public AmazonWebServiceResponse<T> handle(HttpResponse response) throws Exception { log.trace("Parsing service response JSON"); String CRC32Checksum = response.getHeaders().get("x-amz-crc32"); JsonParser jsonParser = null; if (shouldParsePayloadAsJson()) { jsonParser = jsonFactory.createParser(response.getContent()); } try { AmazonWebServiceResponse<T> awsResponse = new AmazonWebServiceResponse<T>(); JsonUnmarshallerContext unmarshallerContext = new JsonUnmarshallerContextImpl( jsonParser,simpleTypeUnmarshallers,customTypeMarshallers,response); registeradditionalMetadataExpressions(unmarshallerContext); T result = responseUnmarshaller.unmarshall(unmarshallerContext); // Make sure we read all the data to get an accurate CRC32 calculation. // See https://github.com/aws/aws-sdk-java/issues/1018 if (shouldParsePayloadAsJson() && response.getContent() != null) { IoUtils.drainInputStream(response.getContent()); } if (CRC32Checksum != null) { long serverSideCRC = Long.parseLong(CRC32Checksum); long clientSideCRC = response.getCRC32Checksum(); if (clientSideCRC != serverSideCRC) { throw new CRC32MismatchException( "Client calculated crc32 checksum didn't match that calculated by server side"); } } awsResponse.setResult(result); Map<String,String> Metadata = unmarshallerContext.getMetadata(); Metadata.put(ResponseMetadata.AWS_REQUEST_ID,response.getHeaders().get(X_AMZN_REQUEST_ID_HEADER)); awsResponse.setResponseMetadata(new ResponseMetadata(Metadata)); log.trace("Done parsing service response"); return awsResponse; } finally { if (shouldParsePayloadAsJson()) { try { jsonParser.close(); } catch (IOException e) { log.warn("Error closing json parser",e); } } } }
com.amazonaws.transform.JsonUnmarshallerContext的实例源码
/** * Constructs a new response handler that will use the specified JSON unmarshaller to unmarshall * the service response and uses the specified response element path to find the root of the * business data in the service's response. * @param responseUnmarshaller The JSON unmarshaller to use on the response. * @param simpleTypeUnmarshallers List of unmarshallers to be used for scalar types. * @param customTypeMarshallers List of custom unmarshallers to be used for special types. * @param jsonFactory the json factory to be used for parsing the response. */ public JsonResponseHandler(Unmarshaller<T,JsonUnmarshallerContext> responseUnmarshaller,Map<Class<?>,Unmarshaller<?,JsonUnmarshallerContext>> simpleTypeUnmarshallers,Map<UnmarshallerType,JsonUnmarshallerContext>> customTypeMarshallers,JsonFactory jsonFactory,boolean needsConnectionLeftOpen,boolean isPayloadJson) { /* * Even if the invoked operation just returns null,we still need an * unmarshaller to run so we can pull out response Metadata. * * We might want to pass this in through the client class so that we * don't have to do this check here. */ this.responseUnmarshaller = responseUnmarshaller != null ? responseUnmarshaller : new VoidJsonUnmarshaller<T>(); this.needsConnectionLeftOpen = needsConnectionLeftOpen; this.isPayloadJson = isPayloadJson; this.simpleTypeUnmarshallers = ValidationUtils.assertNotNull(simpleTypeUnmarshallers,"simple type unmarshallers"); this.customTypeMarshallers = ValidationUtils.assertNotNull(customTypeMarshallers,"custom type marshallers"); this.jsonFactory = ValidationUtils.assertNotNull(jsonFactory,"JSONFactory"); }
static Object getobjectForToken(JsonToken token,JsonUnmarshallerContext context) throws IOException { switch (token) { case VALUE_STRING: return context.getJsonParser().getText(); case VALUE_NUMBER_FLOAT: case VALUE_NUMBER_INT: return context.getJsonParser().getNumberValue(); case VALUE_FALSE: return Boolean.FALSE; case VALUE_TRUE: return Boolean.TRUE; case VALUE_NULL: return null; default: throw new RuntimeException("We expected a VALUE token but got: " + token); } }
@Override public List<Object> unmarshall(JsonUnmarshallerContext context) throws Exception { List<Object> list = new ArrayList<>(); JsonToken token = context.getCurrentToken(); while (token != null && token != JsonToken.END_ARRAY) { if (token.isScalarValue()) { list.add(JsonUnmarshallerUtil.getobjectForToken(token,context)); } else if (token == JsonToken.START_OBJECT) { context.nextToken(); list.add(HalJsonMapUnmarshaller.getInstance().unmarshall(context)); } else if (token == JsonToken.START_ARRAY) { context.nextToken(); list.add(HalJsonListUnmarshaller.getInstance().unmarshall(context)); } token = context.nextToken(); } return list; }
@Override public List<T> unmarshall(JsonUnmarshallerContext context) throws Exception { List<T> list = new ArrayList<>(); JsonToken token = context.getCurrentToken(); while (token != null && token != END_ARRAY) { if (token == JsonToken.START_OBJECT) { list.add(itemUnmarshaller.unmarshall(context)); } token = context.nextToken(); } return list; }
GenericApiGatewayClient(ClientConfiguration clientConfiguration,String endpoint,Region region,AWSCredentialsProvider credentials,String apiKey,AmazonHttpClient httpClient) { super(clientConfiguration); setRegion(region); setEndpoint(endpoint); this.credentials = credentials; this.apiKey = apiKey; this.signer = new AWS4Signer(); this.signer.setServiceName(API_GATEWAY_SERVICE_NAME); this.signer.setRegionName(region.getName()); final JsonoperationMetadata Metadata = new JsonoperationMetadata().withHasstreamingSuccessResponse(false).withPayloadJson(false); final Unmarshaller<GenericApiGatewayResponse,JsonUnmarshallerContext> responseUnmarshaller = in -> new GenericApiGatewayResponse(in.getHttpResponse()); this.responseHandler = SdkStructuredplainjsonFactory.SDK_JSON_FACTORY.createResponseHandler(Metadata,responseUnmarshaller); JsonErrorUnmarshaller defaultErrorUnmarshaller = new JsonErrorUnmarshaller(GenericApiGatewayException.class,null) { @Override public AmazonServiceException unmarshall(JsonNode jsonContent) throws Exception { return new GenericApiGatewayException(jsonContent.toString()); } }; this.errorResponseHandler = SdkStructuredplainjsonFactory.SDK_JSON_FACTORY.createErrorResponseHandler( Collections.singletonList(defaultErrorUnmarshaller),null); if (httpClient != null) { super.client = httpClient; } }
public SdkStructuredJsonFactoryImpl(JsonFactory jsonFactory,JsonUnmarshallerContext>> unmarshallers,JsonUnmarshallerContext>> customTypeMarshallers) { this.jsonFactory = jsonFactory; this.unmarshallers = unmarshallers; this.customTypeMarshallers = customTypeMarshallers; }
@Override public <T> JsonResponseHandler<T> createResponseHandler(JsonoperationMetadata operationMetadata,Unmarshaller<T,JsonUnmarshallerContext> responseUnmarshaller) { return new JsonResponseHandler(responseUnmarshaller,unmarshallers,customTypeMarshallers,jsonFactory,operationMetadata.isHasstreamingSuccessResponse(),operationMetadata.isPayloadJson()); }
@Test public void testSimpleMap() throws Exception { JsonUnmarshallerContext unmarshallerContext = setupUnmarshaller(SIMPLE_MAP,EMPTY_HEADERS); MapUnmarshaller<String,String> unmarshaller = new MapUnmarshaller<String,String>( SimpleTypeJsonUnmarshallers.StringJsonUnmarshaller.getInstance(),SimpleTypeJsonUnmarshallers.StringJsonUnmarshaller.getInstance()); Map<String,String> map = unmarshaller.unmarshall(unmarshallerContext); assertTrue(map.size() == 2); assertEquals("value1",map.get("key1")); assertEquals("value2",map.get("key2")); }
@Test public void testMapToList() throws Exception { JsonUnmarshallerContext unmarshallerContext = setupUnmarshaller(MAP_TO_LIST,List<String>> unmarshaller = new MapUnmarshaller<String,List<String>>( SimpleTypeJsonUnmarshallers.StringJsonUnmarshaller.getInstance(),new ListUnmarshaller<String>(SimpleTypeJsonUnmarshallers.StringJsonUnmarshaller.getInstance())); Map<String,List<String>> map = unmarshaller.unmarshall(unmarshallerContext); assertTrue(map.size() == 2); assertEquals(Arrays.asList(null,"value1"),map.get("key1")); assertEquals(Arrays.asList("value2"),map.get("key2")); }
@Test public void testJsonValueStringInBody() throws Exception { JsonUnmarshallerContext unmarshallerContext = setupUnmarshaller(BASE_64_STRING_VALUE,SimpleTypeJsonUnmarshallers.JsonValueStringUnmarshaller.getInstance()); Map<String,String> map = unmarshaller.unmarshall(unmarshallerContext); assertEquals("value1",map.get("key1")); }
@Test public void testJsonValueStringInHeader() throws Exception { Map<String,String> headers = new HashMap<String,String>(); headers.put("Header","dG9EZWNvZGU="); JsonUnmarshallerContext context = setupUnmarshaller(BASE_64_STRING_VALUE,headers); context.setCurrentHeader("Header"); String value = SimpleTypeJsonUnmarshallers.JsonValueStringUnmarshaller.getInstance().unmarshall(context); assertEquals("toDecode",value); }
private JsonUnmarshallerContext setupUnmarshaller(String body,Map<String,String> headers) throws Exception { HttpResponse httpResponse = new HttpResponse(null,null); for (Map.Entry<String,String> header : headers.entrySet()) { httpresponse.addheader(header.getKey(),header.getValue()); } JsonParser jsonParser = jsonFactory.createParser(new ByteArrayInputStream(body.getBytes())); return new JsonUnmarshallerContextImpl(jsonParser,SdkStructuredplainjsonFactory.JSON_SCALAR_UNMARSHALLERS,SdkStructuredplainjsonFactory.JSON_CUSTOM_TYPE_UNMARSHALLERS,httpResponse); }
/** * Use SWF API to unmarshal a json document into a {@link DecisionTask}. * Note: json is expected to be in the native format used by SWF */ public static DecisionTask unmarshalDecisionTask(String json) { try { Unmarshaller<DecisionTask,JsonUnmarshallerContext> unmarshaller = new DecisionTaskJsonUnmarshaller(); JsonParser parser = new JsonFactory().createParser(json); return unmarshaller.unmarshall(new JsonUnmarshallerContextImpl(parser)); } catch (Exception e) { throw new IllegalStateException(e); } }
@Override public ListVoicesResult listVoices(ListVoicesRequest listVoicesRequest) throws AmazonServiceException,AmazonClientException { ExecutionContext executionContext = createExecutionContext(listVoicesRequest); Request<ListVoicesRequest> request = ListVoicesRequestMarshallerFactory.getMarshaller( listVoicesRequest.getmethodType()).marshall(listVoicesRequest); Unmarshaller<ListVoicesResult,JsonUnmarshallerContext> unmarshaller = new ListVoicesResultJsonUnmarshaller(); JsonResponseHandler<ListVoicesResult> responseHandler = new JsonResponseHandler<ListVoicesResult>(unmarshaller); Response<ListVoicesResult> response = invoke(request,responseHandler,executionContext); return response.getAwsResponse(); }
@Override public GetLexiconResult getLexicon(GetLexiconRequest getLexiconRequest) throws AmazonServiceException,AmazonClientException { ExecutionContext executionContext = createExecutionContext(getLexiconRequest); GetLexiconRequestMarshaller marshaller = new GetLexiconPostRequestMarshaller(); Request<GetLexiconRequest> request = marshaller.marshall(getLexiconRequest); Unmarshaller<GetLexiconResult,JsonUnmarshallerContext> unmarshaller = new GetLexiconResultJsonUnmarshaller(); JsonResponseHandler<GetLexiconResult> responseHandler = new JsonResponseHandler<GetLexiconResult>(unmarshaller); Response<GetLexiconResult> response = invoke(request,executionContext); return response.getAwsResponse(); }
@Override public ListLexiconsResult listLexicons() { ListLexiconsRequest listLexiconsRequest = new ListLexiconsRequest(); ExecutionContext executionContext = createExecutionContext(listLexiconsRequest); ListLexiconsRequestMarshaller marshaller = new ListLexiconsPostRequestMarshaller(); Request<ListLexiconsRequest> request = marshaller.marshall(listLexiconsRequest); Unmarshaller<ListLexiconsResult,JsonUnmarshallerContext> unmarshaller = new ListLexiconsResultJsonUnmarshaller(); JsonResponseHandler<ListLexiconsResult> responseHandler = new JsonResponseHandler<ListLexiconsResult>(unmarshaller); Response<ListLexiconsResult> response = invoke(request,executionContext); return response.getAwsResponse(); }
public ListLexiconsResult unmarshall(JsonUnmarshallerContext context) throws Exception { ListLexiconsResult listLexiconsResult = new ListLexiconsResult(); int originalDepth = context.getCurrentDepth(); String currentParentElement = context.getCurrentParentElement(); int targetDepth = originalDepth + 1; JsonToken token = context.getCurrentToken(); if (token == null) { token = context.nextToken(); } if (token == VALUE_NULL) { return null; } while (true) { if (token == null) { break; } if (token == FIELD_NAME || token == START_OBJECT) { if (context.testExpression(JSON_KEY_LEXICONS,targetDepth)) { listLexiconsResult.setLexiconNames(new ListUnmarshaller<String>( SimpleTypeJsonUnmarshallers.StringJsonUnmarshaller.getInstance()).unmarshall(context)); } } else if (token == END_ARRAY || token == END_OBJECT) { if (context.getLastParsedParentElement() == null || context.getLastParsedParentElement().equals(currentParentElement)) { if (context.getCurrentDepth() <= originalDepth) { break; } } } token = context.nextToken(); } return listLexiconsResult; }
public GetLexiconResult unmarshall(JsonUnmarshallerContext context) throws Exception { GetLexiconResult getLexiconResult = new GetLexiconResult(); int originalDepth = context.getCurrentDepth(); String currentParentElement = context.getCurrentParentElement(); int targetDepth = originalDepth + 1; JsonToken token = context.getCurrentToken(); if (token == null) { token = context.nextToken(); } if (token == VALUE_NULL) { return null; } while (true) { if (token == null) { break; } if (token == FIELD_NAME || token == START_OBJECT) { if (context.testExpression(JSON_KEY_LEXICON,targetDepth)) { context.nextToken(); getLexiconResult.setLexicon(LexiconjsonUnmarshaller.getInstance().unmarshall(context)); } } else if (token == END_ARRAY || token == END_OBJECT) { if (context.getLastParsedParentElement() == null || context.getLastParsedParentElement().equals(currentParentElement)) { if (context.getCurrentDepth() <= originalDepth) { break; } } } token = context.nextToken(); } return getLexiconResult; }
public ListVoicesResult unmarshall(JsonUnmarshallerContext context) throws Exception { ListVoicesResult listVoicesResult = new ListVoicesResult(); int originalDepth = context.getCurrentDepth(); String currentParentElement = context.getCurrentParentElement(); int targetDepth = originalDepth + 1; JsonToken token = context.getCurrentToken(); if (token == null) { token = context.nextToken(); } if (token == VALUE_NULL) { return null; } while (true) { if (token == null) { break; } if (token == FIELD_NAME || token == START_OBJECT) { if (context.testExpression(JSON_KEY_VOICES,targetDepth)) { listVoicesResult.setVoices(new ListUnmarshaller<Voice>(VoiceJsonUnmarshaller.getInstance()) .unmarshall(context)); } } else if (token == END_ARRAY || token == END_OBJECT) { if (context.getLastParsedParentElement() == null || context.getLastParsedParentElement().equals(currentParentElement)) { if (context.getCurrentDepth() <= originalDepth) { break; } } } token = context.nextToken(); } return listVoicesResult; }
@Override public Map<String,Object> unmarshall(JsonUnmarshallerContext context) throws Exception { Map<String,Object> map = new HashMap<>(); JsonToken token = context.getCurrentToken(); while (token != null && token != JsonToken.END_OBJECT) { if (token == JsonToken.FIELD_NAME) { String property = context.readText(); token = context.nextToken(); if (token == JsonToken.START_OBJECT) { context.nextToken(); map.put(property,HalJsonMapUnmarshaller.getInstance().unmarshall(context)); } else if (token == JsonToken.START_ARRAY) { context.nextToken(); map.put(property,HalJsonListUnmarshaller.getInstance().unmarshall(context)); } else { map.put(property,JsonUnmarshallerUtil.getobjectForToken(token,context)); } } token = context.nextToken(); } return map; }
@Override public HalLink unmarshall(JsonUnmarshallerContext context) throws Exception { HalLink halLink = new HalLink(); JsonToken token = context.getCurrentToken(); while (token != null && token != JsonToken.END_OBJECT) { if (token == JsonToken.FIELD_NAME) { if (context.testExpression("href")) { context.nextToken(); halLink.setHref(context.readText()); } else if (context.testExpression("name")) { context.nextToken(); halLink.setName(context.readText()); } else if (context.testExpression("title")) { context.nextToken(); halLink.setTitle(context.readText()); } else if (context.testExpression("templated")) { context.nextToken(); halLink.setTemplated(Boolean.valueOf(context.readText())); } else if (context.testExpression("deprecation")) { context.nextToken(); halLink.setDeprecation(context.readText()); } else { // Ignore this. Likely one of hreflang,profile,type context.nextToken(); } } token = context.nextToken(); } return halLink; }
@Override public HalLink unmarshall(JsonUnmarshallerContext context) throws Exception { HalLink halLink = new HalLink(); JsonToken token = context.getCurrentToken(); // Ignore curies for Now. while (token != null && token != JsonToken.END_OBJECT) { token = context.nextToken(); } return halLink; }
@Override protected void registeradditionalMetadataExpressions(JsonUnmarshallerContext unmarshallerContext) { Map<String,String> headers = unmarshallerContext.getHttpResponse().getHeaders(); if (headers.containsKey("Location")) { location = headers.get("Location"); } else if (headers.containsKey("location")) { location = headers.get("location"); } }
@Override public Map<String,HalLink> unmarshall(JsonUnmarshallerContext context) throws Exception { Map<String,HalLink> links = new LinkedHashMap<>(); JsonToken token = context.getCurrentToken(); while (token != null && token != JsonToken.END_OBJECT) { if (token == JsonToken.FIELD_NAME) { if (context.testExpression("curie")) { context.nextToken(); HalJsonCurieUnmarshaller.getInstance().unmarshall(context); } else { String relation = context.readText(); token = context.nextToken(); if (token == JsonToken.START_ARRAY) { List<HalLink> halLinks = new HalJsonArrayUnmarshaller<>(HalJsonLinkUnmarshaller.getInstance()).unmarshall(context); int i = 0; for (HalLink halLink : halLinks) { links.put(relation + "_" + i++,halLink); } } else { links.put(relation,HalJsonLinkUnmarshaller.getInstance().unmarshall(context)); } } } token = context.nextToken(); } return links; }
@Override public HalResource unmarshall(JsonUnmarshallerContext context) throws Exception { HalResource halResource = new HalResource(); JsonToken token = context.getCurrentToken(); if (token == null) { token = context.nextToken(); } while (token != null && token != JsonToken.END_OBJECT) { if (token == JsonToken.FIELD_NAME) { if (context.testExpression("_links")) { context.nextToken(); halResource.setLinks(HalJsonLinksUnmarshaller.getInstance().unmarshall(context)); } else if (context.testExpression("_embedded")) { context.nextToken(); halResource.setEmbedded(HalJsonEmbeddedUnmarshaller.getInstance().unmarshall(context)); } else { String property = context.readText(); token = context.nextToken(); if (token == JsonToken.START_OBJECT) { context.nextToken(); halResource.addProperty(property,HalJsonMapUnmarshaller.getInstance().unmarshall(context)); } else if (token == JsonToken.START_ARRAY) { context.nextToken(); halResource.addProperty(property,HalJsonListUnmarshaller.getInstance().unmarshall(context)); } else { halResource.addProperty(property,context)); } } } token = context.nextToken(); } return halResource; }
private HalResource parseHalResourceFromClasspath(String classpathFile) throws Exception { InputStream inputStream = this.getClass().getClassLoader().getResourceAsstream(classpathFile); JsonParser jsonParser = new JsonFactory().createJsonParser(inputStream); JsonUnmarshallerContext jsonUnmarshallerContext = new JsonUnmarshallerContextImpl(jsonParser); return HalJsonResourceUnmarshaller.getInstance().unmarshall(jsonUnmarshallerContext); }
/** * Returns the response handler to be used for handling a successful response. * * @param operationMetadata Additional context information about an operation to create the appropriate response handler. */ public <T> HttpResponseHandler<AmazonWebServiceResponse<T>> createResponseHandler( JsonoperationMetadata operationMetadata,JsonUnmarshallerContext> responseUnmarshaller) { return getSdkFactory().createResponseHandler(operationMetadata,responseUnmarshaller); }
private SdkStructuredionFactory(IonWriterBuilder builder) { super(JSON_FACTORY,UNMARSHALLERS,Collections.<JsonUnmarshallerContext.UnmarshallerType,JsonUnmarshallerContext>>emptyMap()); this.builder = builder; }
/** * @see HttpResponseHandler#handle(HttpResponse) */ public AmazonWebServiceResponse<T> handle(HttpResponse response) throws Exception { log.trace("Parsing service response JSON"); String CRC32Checksum = response.getHeaders().get("x-amz-crc32"); JsonParser jsonParser = null; if (shouldParsePayloadAsJson()) { jsonParser = jsonFactory.createParser(response.getContent()); } try { AmazonWebServiceResponse<T> awsResponse = new AmazonWebServiceResponse<T>(); JsonUnmarshallerContext unmarshallerContext = new JsonUnmarshallerContextImpl( jsonParser,simpleTypeUnmarshallers,response); registeradditionalMetadataExpressions(unmarshallerContext); T result = responseUnmarshaller.unmarshall(unmarshallerContext); // Make sure we read all the data to get an accurate CRC32 calculation. // See https://github.com/aws/aws-sdk-java/issues/1018 if (shouldParsePayloadAsJson() && response.getContent() != null) { IoUtils.drainInputStream(response.getContent()); } if (CRC32Checksum != null) { long serverSideCRC = Long.parseLong(CRC32Checksum); long clientSideCRC = response.getCRC32Checksum(); if (clientSideCRC != serverSideCRC) { throw new CRC32MismatchException( "Client calculated crc32 checksum didn't match that calculated by server side"); } } awsResponse.setResult(result); Map<String,String> Metadata = unmarshallerContext.getMetadata(); Metadata.put(ResponseMetadata.AWS_REQUEST_ID,response.getHeaders().get(X_AMZN_REQUEST_ID_HEADER)); awsResponse.setResponseMetadata(new ResponseMetadata(Metadata)); log.trace("Done parsing service response"); return awsResponse; } finally { if (shouldParsePayloadAsJson()) { try { jsonParser.close(); } catch (IOException e) { log.warn("Error closing json parser",e); } } } }
public Lexicon unmarshall(JsonUnmarshallerContext context) throws Exception { Lexicon lexicon = new Lexicon(); int originalDepth = context.getCurrentDepth(); String currentParentElement = context.getCurrentParentElement(); int targetDepth = originalDepth + 1; JsonToken token = context.getCurrentToken(); if (token == null) { token = context.nextToken(); } if (token == VALUE_NULL) { return null; } while (true) { if (token == null) { break; } if (token == FIELD_NAME || token == START_OBJECT) { if (context.testExpression(JSON_KEY_NAME,targetDepth)) { context.nextToken(); lexicon.setName( SimpleTypeJsonUnmarshallers.StringJsonUnmarshaller.getInstance().unmarshall(context)); } if (context.testExpression(JSON_KEY_CONTENTS,targetDepth)) { context.nextToken(); lexicon.setContents( SimpleTypeJsonUnmarshallers.StringJsonUnmarshaller.getInstance().unmarshall(context)); } } else if (token == END_ARRAY || token == END_OBJECT) { if (context.getLastParsedParentElement() == null || context.getLastParsedParentElement().equals(currentParentElement)) { if (context.getCurrentDepth() <= originalDepth) { break; } } } token = context.nextToken(); } return lexicon; }
public Voice unmarshall(JsonUnmarshallerContext context) throws Exception { Voice voice = new Voice(); int originalDepth = context.getCurrentDepth(); String currentParentElement = context.getCurrentParentElement(); int targetDepth = originalDepth + 1; JsonToken token = context.getCurrentToken(); if (token == null) { token = context.nextToken(); } if (token == VALUE_NULL) { return null; } while (true) { if (token == null) { break; } if (token == FIELD_NAME || token == START_OBJECT) { if (context.testExpression(JSON_KEY_NAME,targetDepth)) { context.nextToken(); voice.setName( SimpleTypeJsonUnmarshallers.StringJsonUnmarshaller.getInstance().unmarshall(context)); } if (context.testExpression(JSON_KEY_LANGUAGE,targetDepth)) { context.nextToken(); voice.setLanguage( SimpleTypeJsonUnmarshallers.StringJsonUnmarshaller.getInstance().unmarshall(context)); } if (context.testExpression(JSON_KEY_GENDER,targetDepth)) { context.nextToken(); voice.setGender( SimpleTypeJsonUnmarshallers.StringJsonUnmarshaller.getInstance().unmarshall(context)); } } else if (token == END_ARRAY || token == END_OBJECT) { if (context.getLastParsedParentElement() == null || context.getLastParsedParentElement().equals(currentParentElement)) { if (context.getCurrentDepth() <= originalDepth) { break; } } } token = context.nextToken(); } return voice; }
OptionalJsonResponseHandler(Unmarshaller<T,JsonUnmarshallerContext> responseUnmarshaller) { super(responseUnmarshaller); }
public HalJsonArrayUnmarshaller(Unmarshaller<T,JsonUnmarshallerContext> itemUnmarshaller) { this.itemUnmarshaller = itemUnmarshaller; }
/** * Returns the response handler to be used for handling a successfull response. * * @param operationMetadata Additional context information about an operation to create the * appropriate response handler. */ <T> JsonResponseHandler<T> createResponseHandler(JsonoperationMetadata operationMetadata,JsonUnmarshallerContext> responseUnmarshaller);
/** * Hook for subclasses to override in order to collect additional Metadata from service * responses. * * @param unmarshallerContext * The unmarshaller context used to configure a service's response * data. */ protected void registeradditionalMetadataExpressions( JsonUnmarshallerContext unmarshallerContext) { }
com.amazonaws.transform.StaxUnmarshallerContext的实例源码
private final S unmarshall(final HttpSuccess success) throws Exception { XMLEventReader reader = null; try { final XMLInputFactory xmlInputFactory = newInstance(); reader = xmlInputFactory.createXMLEventReader(success.getContent()); final StaxUnmarshallerContext stax = new StaxUnmarshallerContext(reader); stax.registerMetadataExpression("ResponseMetadata/RequestId",2,AWS_REQUEST_ID); stax.registerMetadataExpression("requestId",AWS_REQUEST_ID); return unmarshaller_.unmarshall(stax); } finally { if(reader != null) { reader.close(); } } } @H_301_9@
private final S unmarshall(final HttpSuccess success) throws Exception { XMLEventReader reader = null; try { final XMLInputFactory xmlInputFactory = newInstance(); reader = xmlInputFactory.createXMLEventReader(success.getContent()); final StaxUnmarshallerContext stax = new StaxUnmarshallerContext(reader); stax.registerMetadataExpression("ResponseMetadata/RequestId",AWS_REQUEST_ID); return unmarshaller_.unmarshall(stax); } finally { if(reader != null) { reader.close(); } } } @H_301_9@
public SqsAwsSdkAction(RequestT request,String requestUrl,Marshaller<com.amazonaws.Request<RequestT>,RequestT> marshaller,Unmarshaller<ResponseT,StaxUnmarshallerContext> unmarshaller) { this.requestUrl = requestUrl; this.request = request; this.marshaller = marshaller; this.staxResponseHandler = new StaxResponseHandler<>(unmarshaller); } @H_301_9@
/** * Constructs a new response handler that will use the specified StAX * unmarshaller to unmarshall the service response and uses the specified * response element path to find the root of the business data in the * service's response. * * @param responseUnmarshaller * The StAX unmarshaller to use on the response. */ public StaxResponseHandler(Unmarshaller<T,StaxUnmarshallerContext> responseUnmarshaller) { this.responseUnmarshaller = responseUnmarshaller; /* * Even if the invoked operation just returns null,we still need an * unmarshaller to run so we can pull out response Metadata. * * We might want to pass this in through the client class so that we * don't have to do this check here. */ if (this.responseUnmarshaller == null) { this.responseUnmarshaller = new VoidStaxUnmarshaller<T>(); } } @H_301_9@
/** * Id (aka configuration name) isn't modeled on the actual {@link NotificationConfiguration} * class but as the key name in the map of configurations in * {@link BucketNotificationConfiguration} */ @Override public Entry<String,NotificationConfiguration> unmarshall(StaxUnmarshallerContext context) throws Exception { int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; if (context.isstartOfDocument()) { targetDepth += 1; } T topicConfig = createConfiguration(); String id = null; while (true) { XMLEvent xmlEvent = context.nextEvent(); if (xmlEvent.isEndDocument()) { return new SimpleEntry<String,NotificationConfiguration>(id,topicConfig); } if (xmlEvent.isAttribute() || xmlEvent.isstartElement()) { if (handleXmlEvent(topicConfig,context,targetDepth)) { // Do nothing,subclass has handled it } else if (context.testExpression("Id",targetDepth)) { id = StringStaxUnmarshaller.getInstance().unmarshall(context); } else if (context.testExpression("Event",targetDepth)) { topicConfig.addEvent(StringStaxUnmarshaller.getInstance().unmarshall(context)); } else if (context.testExpression("Filter",targetDepth)) { topicConfig.setFilter(FilterStaxUnmarshaller.getInstance().unmarshall(context)); } } else if (xmlEvent.isEndElement()) { if (context.getCurrentDepth() < originalDepth) { return new SimpleEntry<String,topicConfig); } } } } @H_301_9@
@Override public S3KeyFilter unmarshall(StaxUnmarshallerContext context) throws Exception { int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; if (context.isstartOfDocument()) { targetDepth += 1; } S3KeyFilter filter = new S3KeyFilter(); while (true) { XMLEvent xmlEvent = context.nextEvent(); if (xmlEvent.isEndDocument()) { return filter; } if (xmlEvent.isAttribute() || xmlEvent.isstartElement()) { if (context.testExpression("FilterRule",targetDepth)) { filter.addFilterRule(FilterRuleStaxUnmarshaller.getInstance().unmarshall(context)); } } else if (xmlEvent.isEndElement()) { if (context.getCurrentDepth() < originalDepth) { return filter; } } } } @H_301_9@
@Override public Filter unmarshall(StaxUnmarshallerContext context) throws Exception { int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; if (context.isstartOfDocument()) { targetDepth += 1; } Filter filter = new Filter(); while (true) { XMLEvent xmlEvent = context.nextEvent(); if (xmlEvent.isEndDocument()) { return filter; } if (xmlEvent.isAttribute() || xmlEvent.isstartElement()) { if (context.testExpression("S3Key",targetDepth)) { filter.withS3KeyFilter(S3KeyFilterStaxUnmarshaller.getInstance().unmarshall(context)); } } else if (xmlEvent.isEndElement()) { if (context.getCurrentDepth() < originalDepth) { return filter; } } } } @H_301_9@
@Override public FilterRule unmarshall(StaxUnmarshallerContext context) throws Exception { int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; if (context.isstartOfDocument()) { targetDepth += 1; } FilterRule filter = new FilterRule(); while (true) { XMLEvent xmlEvent = context.nextEvent(); if (xmlEvent.isEndDocument()) { return filter; } if (xmlEvent.isAttribute() || xmlEvent.isstartElement()) { if (context.testExpression("Name",targetDepth)) { filter.setName(StringStaxUnmarshaller.getInstance().unmarshall(context)); } else if (context.testExpression("Value",targetDepth)) { filter.setValue(StringStaxUnmarshaller.getInstance().unmarshall(context)); } } else if (xmlEvent.isEndElement()) { if (context.getCurrentDepth() < originalDepth) { return filter; } } } } @H_301_9@
@Override public Entry<String,NotificationConfiguration> unmarshall(StaxUnmarshallerContext context) throws Exception { int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; if (context.isstartOfDocument()) { targetDepth += 1; } String id = null; List<String> events = new ArrayList<String>(); Filter filter = null; String functionArn = null; String invocationRole = null; while (true) { XMLEvent xmlEvent = context.nextEvent(); if (xmlEvent.isEndDocument()) { return createLambdaConfig(id,events,functionArn,invocationRole,filter); } if (xmlEvent.isAttribute() || xmlEvent.isstartElement()) { if (context.testExpression("Id",targetDepth)) { events.add(StringStaxUnmarshaller.getInstance().unmarshall(context)); } else if (context.testExpression("Filter",targetDepth)) { filter = FilterStaxUnmarshaller.getInstance().unmarshall(context); } else if (context.testExpression("CloudFunction",targetDepth)) { functionArn = StringStaxUnmarshaller.getInstance().unmarshall(context); } else if (context.testExpression("InvocationRole",targetDepth)) { invocationRole = StringStaxUnmarshaller.getInstance().unmarshall(context); } } else if (xmlEvent.isEndElement()) { if (context.getCurrentDepth() < originalDepth) { return createLambdaConfig(id,filter); } } } } @H_301_9@
protected boolean handleXmlEvent(TopicConfiguration topicConfig,StaxUnmarshallerContext context,int targetDepth) throws Exception { if (context.testExpression("Topic",targetDepth)) { topicConfig.setTopicARN(StringStaxUnmarshaller.getInstance().unmarshall(context)); return true; } return false; } @H_301_9@
protected boolean handleXmlEvent(QueueConfiguration queueConfig,int targetDepth) throws Exception { if (context.testExpression("Queue",targetDepth)) { queueConfig.setQueueARN(StringStaxUnmarshaller.getInstance().unmarshall(context)); return true; } return false; } @H_301_9@
public SqsAwsSdkBatchAction(RequestT request,Marshaller<Request<RequestT>,StaxUnmarshallerContext> unmarshaller) { super(request,requestUrl,marshaller,unmarshaller); } @H_301_9@
public AwsSESHttpClosure(final HttpClient client,final int expectStatus,final Unmarshaller<S,StaxUnmarshallerContext> unmarshaller) { super(client,expectStatus); unmarshaller_ = unmarshaller; } @H_301_9@
public AwsSQSHttpClosure(final HttpClient client,expectStatus); unmarshaller_ = unmarshaller; } @H_301_9@
/** * Hook for subclasses to override in order to collect additional Metadata * from service responses. * * @param unmarshallerContext * The unmarshaller context used to configure a service's response * data. */ protected void registeradditionalMetadataExpressions(StaxUnmarshallerContext unmarshallerContext) {} @H_301_9@
/** * Callback to allow subclass first shot at handling an XML event. Only attribute and start * element events are forwarded to subclasses * * @param config * {@link NotificationConfiguration} object we are unmarshalling into * @param context * Context of XML unmarshalling * @param targetDepth * expected depth for this level of unmarshalling * @return True if event has been handled and super class should move on to the next event,* false otherwise * @throws Exception */ protected abstract boolean handleXmlEvent(T config,int targetDepth) throws Exception; @H_301_9@
关于使用 Marshaller Extra Line 写入 xml 文件和incompatible marshal file的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于asp.net-mvc-4 – 无法从程序集’itextsharp,Version = 5.5.3.0,Culture = neutral,PublicKeyToken = 8354ae6d2174ddca’加载类型’iTextSharp.text.html.HtmlParser’、com.amazonaws.transform.JsonUnmarshallerContextImpl的实例源码、com.amazonaws.transform.JsonUnmarshallerContext的实例源码、com.amazonaws.transform.StaxUnmarshallerContext的实例源码等相关知识的信息别忘了在本站进行查找喔。
本文标签: