Decode Json urls - java

I'm manually parsing Json objects using java and I have a problem with urls.
They currently look like this:
http:\/\/a3.sphotos.ak.fbcdn.net\/hphotos-ak-ash4\/...
and I was wondering how to decode them into a normal form that I can further use, like this:
http://a3.sphotos.ak.fbcdn.net//hphotos-ak-ash4//...
It's not just the slashes that cause this problem, so simply searching for them is not a solution.
I'm searching for a standard method from the jdk that could easily accomplish this.
Unfortunately I have know idea what the encoding is called, so I can't be more specific in what I want to know.

Looks like you should try and use the answer from here:
unEscape JavaScript escaped value in JAVA
There seems to be an unescape function. I have used that before in javascript (unescape) to help with the same issue. Looks like Java has a similar function.
http://commons.apache.org/lang/api-release/org/apache/commons/lang/StringEscapeUtils.html

Related

best way to replace an XML element's value in java 8

I've got a requirement to take an XML file and replace any existing value with one I generate from user input. Needs to only replace the existing value in the document.
I was looking at the simplest library SAX (https://docs.oracle.com/javase/tutorial/jaxp/sax/index.html) that is now in the standard JAVA JDK, but since this is an old project I was wondering if I should use something else like XMLT (https://docs.oracle.com/javase/tutorial/jaxp/xslt/transformingXML.html).
Can someone please advise the best (easiest) approach for this simple case?
The fact that it's old does not change that it's XML. Use the library best suited to your needs. The standard SAX parser should be fine.
Also, if it's just a matter of replacing text content, why can't you just so a simple textual replace?

Html entity decoder java

I have a string like this:
नमस्कार
Now i want to translate the string to html entity decoder. I can translate manually by using
url https://mothereff.in/html-entities
is there any java api to translate it ?
can anyone help me ? thanks in advance
This might prove to be useful unbescape. I found it to be diverse and very quick to implement. I'm using it to convert huge lists of strings with HTML entities in them back to normal strings. It's quick and accurate so far.
It seems, after a quick google search, that a popular solution to this is using StringEscapeUtils.unescapeHtml4(). More information can be found in this Stack Overflow question.

get part with regex

I need to get everything bewteen
onmouseout="this.style.backgroundColor='#fff'">
and the following <
in this case:
onmouseout="this.style.backgroundColor='#fff'">example<
I would like to get the word example.
Here is a more complicated example of where it should work as well:
onmouseout="this.style.backgroundColor='#fff'">going to drink?<br></span><span title="Juist!" onmouseover="this.style.backgroundColor='#ebeff9'" onmouseout="this.style.backgroundColor='#fff'">Exactly!</span></span></div></div>
So here i need 2 of them back (and not joined).
Could someone help? I suck at regex.
Someone edited my tag to javascript.
I need a solution to use in java, i just get a file as plain text. So javascript or html solutions are not really helpfull.
Regex with html? Well, If you have to parse only a few lines then ok. But in general is better to use a html parser (because HTML is not a regular language).
This is pure gold: https://stackoverflow.com/a/1732454/434171

JSON parser for Java online

Is there a Json - parser for java online that can help me to create Java - objects from Json-string? (I found similar one but there I can translate json-string in Java -objects only if I have url for my json-string)?
Thanks for the link, this should be easy:
upload your JSON string to a site like pastebin.com
get the RAW link, i.e. the one without the PasteBin website around)
put that into http://jsongen.byingtondesign.com
Have a look at http://jackson.codehaus.org/
But be sure that you really want to put it into Java objects, because whenever the JSON representation changes, translation will break of course.
QuickType.io is exactly what you're looking for.
For the record, I'm unaffiliated.

Retrieving well formed HTML using Jericho HTML parser in Java

I've looked at jTidy for converting a snipped of malformed/real-world HTML into well-formed HTML/XHTML. However, there's a bug in the latest version due to which I'm not able to use it. I'm looking at Jericho since it has a lot of positive reviews around the net.
However, its not immediately obvious to me how one would go about implementing a method like:
public String getValidHTML(String messedUpHTML)
For instance, if it was passed <div>bar, it would return <div>bar</div>
Any pointers would be helpful.
Thanks in advance!
Jericho's HTMLSanitiser sample might be a good start.
However, keep in mind that jericho's key strength is its ability to parse and manipulate malformed HTML, while keeping the original "bad" formatting. However, it'd be interesting to see how the library performs such a task.

Categories