Convert javax.mail.Message Email to XML format - java

I am looking for the open source API if there is any available which can convert javax.mail.Message object to XML specific format or some sample code if there is any already exist ?
Please let me know if you know any.
Thanks.

The way I've always done it is by using the DOM parser. Message provides methods to grab every part of the mail (recipients, body, sender...). With that, you can just create your Elements and Attributes and you should be sorted. As far as I'm aware, there is not library that will do that for you.

Related

How get the actual emailbody of email sent as riche text using PidTagRtfCompressed Canonical Property

I am trying to get the emailbody of the email, using ews java 2.0, sent in rich text format.
Though I am getting the text format correctly, but i am not receiving the html format of the same.
All I need is the exact representation of the emailbody in which the email was sent. So that I could reproduce the same in another system which requires html.
Is it possible for me to get it?
I tried using the PidTagRtfCompressed Canonical Property. I defined an extended property using the extended property definition with the corresponding tag(0x1009) and mapitype(binary) for the rtf emailbody. Though i did receive value in it but I am not able decode it to the corresponding readable value.
Would it be possible to get the readable value out of this extended property? Would it be possible to get the html format as well?
I would be grateful for any help.
Thanks
I am trying to get the emailbody of the email, using ews java 2.0, sent in rich text format.
If you just request the body using a GetItem operation EWS will return HTML, if the message has a Native RTF body the Exchange Store will do an on the fly conversion of the RTF message into HTML (the meta information in the HTML returned will tell you if a conversion has been done). You can test this without writing any code using the EWSEditor https://ewseditor.codeplex.com/ . Is there any reason your not using the Strongly typed properties as this would be the normal method of getting the body the rest of your question doesn't make much sense unless you have a problem with the Store conversion ?
Though i did receive value in it but I am not able decode it to the corresponding readable value.
If you want to that then you need to implement your own decompression library to do this eg something like https://github.com/Sicos1977/MSGReader/blob/master/MsgReader/Outlook/RtfDecompressor.cs should work. The protocol spec for this is https://msdn.microsoft.com/en-us/library/cc463890(v=exchg.80).aspx . Exchange has a library to do that but its limited in use to the server only as it mostly for use in Transport agents https://msdn.microsoft.com/en-us/library/microsoft.exchange.data.textconverters(v=exchg.150).aspx

Can i get selected tag from xml and download the value?

I want to download the value of selected tag from some site. The only way i know is is to download whole XML and then get the value.
My Question is:
Can i get the value without downloading whole XML?
For example:
I have this site:
http://api.nbp.pl/api/exchangerates/tables/a/?format=xml
And i only want to download the value of tag "EffectiveDate".
I know i can download whole XML then get it but why should I if I want get only one value.
Is there any way to do it in Java?
If you are looking for converting the data given in some XML format to convert it to Java objects then you can use those values as you need .
There is java marshalling and unmarshalling of XML to Java object would help you to do it.
Please refer to the below link for example..
http://www.javatpoint.com/jaxb-unmarshalling-example
It's not possible to get those values without downloading whole xml. What if at the end of XML there are tags which are matching your needs? On other hand if you need only specific values - maybe it's worth to update backend to return values specified by some selector?

Wikipedia content parsing JSON

I want to get the contents of a Wikipedia page and then do some funny stuff with it.
The idea is that I want to get them in XML/JSON format and at the moment I don't seem to find a way to do it.
For the moment I succeeded in getting this far:
https://en.wikipedia.org/w/api.php?action=query&format=jsonfm&prop=revisions&titles=April_1&rvprop=content&rvcontentformat=text%2Fx-wiki
Bu I receive the content in XWiki and I cannot change it to JSON due to the fact that the page does not support it.
How can I parse the XWiki to a JSON or how can I get the contents of the page.
Thanks!
Yes, you can use the HTML parser inside of XWiki Rendering to parse the HTML generated by wikipedia. This gives you an AST on which you can do whatever you wish.
See http://rendering.xwiki.org/xwiki/bin/view/Main/WebHome for more details.
You just need to find a way to get the wikipedia content in HTML.

Extract feeds list from an OPML file in java

I want to extract a list of feed information from an OPML file in java. I know I have to use some xml-parse technique, but I have no idea what to use.
I am a java beginner, so could you tell me how to do it and give me an example?
Thanks a lot!!
This should fairly straight forward. You can take one of hte following two approaches.
Use java parsing capabilities and parse it as any XML file. Here is an example using DOM parse.
There are lot of the open source code/libraries for doing this. Here is one such example. This class has a method public ArrayList<OpmlElement> readDocument(Reader reader). You can create a Reader object from the OPML file and pass the same to this function. Please note that this library depends on xml Pull parser libraries. So if you do not want to add another dependency use the first approach.
Here is another example on this forum itself.

Twitter saved JSON String to Java Object (POJO) using something like twitter4j..?

I have a large collection of twitter messages from the streaming twitter API saved as JSON strings in text files.
I wanted to know if anyone knew how I could convert these JSON strings into something like the Twitter4J status object for use as a simple object with getters and setters?
I was thinking about debugging the source and writing my own inject class which would mimic the input stream classes, however I wonder if there is a better way..?
Thanks!
Try DataObjectFactory#createStatus(String). It's a simple static method that returns one single twitter4j.Status object.
http://twitter4j.org/en/javadoc/twitter4j/json/DataObjectFactory.html#createStatus(java.lang.String)
You can try using Google's Protobuff or Codehause's XStream or Jackson
This thread might help
https://stackoverflow.com/questions/338586/a-better-java-json-library
Depends on what you want to do with the data. One thought that comes to mind is importing it into a database like MongoDb which already has support for importing JSON http://www.mongodb.org/display/DOCS/Import+Export+Tools . then you can proceed to analyse or convert the data further from there

Categories