Library to parse String content based on rules [closed] - java

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
I want to add custom logic/class to my custom Jackson JsonSerialize implementation such that it parses out html based on certain rules. For example, if html is inclosed in single quotes '<b>'text'</b>' then the custom logic should accept the string as is. If its not in single quotes, like <b>text</b> then I want the custom logic/class to return just text. Additionally, if I have a block of html enclosed in three single quotes '''<html><head><title>example</title></head></html>''' it should accepted as is but if its not then only the example text should be returned and everything else parsed out. What is the best Java library to accomplish this? I thought about using AnitSamy but that leaves me open to an XSS attack since I need to accept anything inside quotes.
Examples:
input:<b>text</b>
output:text
input:'<b>'text'</b>'
output:'<b>'text'</b>'
input:<html><head><title>text</title></head></html>
output:text
input:'''<html><head><title>text</title></head></html>'''
output:'''<html><head><title>text</title></head></html>'''

You could use the Java Regex engine to look for patterns. Ex:
p = Pattern.compile("'''[\\w*]'''");
m = p.matcher(input);
if(m.find()){
//Do some logic
}
Here's a link to a Java Regex website:
http://www.regular-expressions.info/java.html

Related

Java - How to parse information out of HTML Site? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
I have a StringBuffer with a HTML Site in it and want to have some specific information of this Site.
1 line is f.e.:
img class="a" data-src="http://test.com" src="" /<
and i want a String with "http://test.com".
Is there a function/parser which can help me?
This is a common question and you could've found the answer with a quick Google search.
Look into Regular Expression (regex) as you'll need it probably more than once.
Consider JSoup framework.
There is "Selector" mechanism to find and operate with html elements.
Jsoup will do the trick, just do a little css and you can get whatever element you need.
Document doc = Jsoup.connect("http://test.com").get();
//DOM Selector CSS String see jsoup docs.
//This will select all image elements with the a class similar to css. IE: img.a
//http://jsoup.org/cookbook/extracting-data/selector-syntax
//Get all elements that are images with class of a
Elements images = doc.select("img.a");
for (Element image : images) {
//Get the url of the image
String url = image.attr("data-src");;
}

Converting time domain to frequency domain in Java [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
I have 2 arrays containing time and voltage. I would like to convert time domain to frequency domain in Java. I would like to use FFT. If there is any open source library I could use, please point me to it. I have done a research and found few algorithms but they are asking for real part and imaginary part. If anyone got idea regarding that, please let me know how I could use that in my context.
Code I have found so far
Here is one library:
http://www.fftw.org/download.html
You can also use R with Java. See this link:
Java-R integration?
If you are not familiar with R check their home page r-project dot org (I can't post more links)
While I haven't checked the implementation you link to, you should be able to use that one by suppling 0s for the imaginary part. In that case you are going "forward", i.e. set DIRECT to true transforming from time-domain to the frequency domain. The function will return an array containing real parts of the frequency in even numbered seats, and the imaginary part in odd numbered.

Google Search with Java [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
I am looking into a solution to automate Google Searches using Java. I have looked into the Google Custom Search API but it does not appear to fulfill the requirements. It appears Custom Search requires the domains to be specified ahead of time which does not work for me because I don't know the domains. We want to do a Google Web search, like you would from your browser. Is this possible with the Google Custom Search API? If not does anyone know of any api / library, preferable in Java that would work?
public static void main(String[] args) {
String googleAJAX = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=";
String searchFor = "stuff";
/**
**Edit:** of course you can also get user input as a string
and search for that instead. i.e.:
String searchFor = (new Scanner(System.in)).nextLine();
**/
URL url = new URL(googleAJAX + URLEncoder.encode(searchFor, "UTF-8"));
Reader read = new InputStreamReader(url.openStream(), "UTF-8");
GoogleResults results = new Gson().fromJson(read, GoogleResults.class);
// Return results (title and URL)
System.out.println(results.getResponseData().getResults().get(0).getTitle());
System.out.println(results.getResponseData().getResults().get(0).getUrl());
}
Selenium - It's portable, scalable and very simple and quick to get started with.
It has libraries for Java and JavaScript whichever you prefer. You can quickly automate what a user would do. For example go to www.google.com and pass in a query string. You can then parse the Object of Elements using XPATH etc (many other methods) to retrieve search results.
You can also get googles autocomplete results by using xpath.
This is not using the google search api, but a custom web automation tool.

Format and beautify Java code while typing in textarea of html [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
I have a textarea in my webpage works as a editor.
While typing the java/c/c++ code in the textarea, I want the code to be formatted and auto beautify itself (like coloring keywords, spaces, auto tabs for code inside {} blocks).
Or
I need an editor which can be embedded in my webpage.
You can use CodeMirror (C, C++ and Java example there : http://codemirror.net/mode/clike/index.html)
It's really simple to make it work, just include codemirror.js, codemirror.css and the .js of the languages you want in your page's header, then there is a method to create an editor from a textarea, for instance :
CodeMirror.fromTextArea(document.getElementById("TEXTAREA_ID"), {
mode: "text/x-java",
indentWithTabs: true,
smartIndent: true,
lineNumbers: true,
lineWrapping: true,
matchBrackets : true,
autofocus: true
});
More infos : http://codemirror.net/doc/manual.html
Of course there are others (Ace, EditArea, ...) but I already used that one and I'm happy with it :)
Cheers

Is there a library in Java for SQL like string searches? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
I'm looking for an api/method/framework where I can compare strings. One is a string stored on the server whereas the other is a string given by user input.
For example:
Stored String : "Login"
User input : "login" "log in" "lOG IN" or any such permutation.
I'm using java in spring mvc (making a webapp). the server is getting a string from the user and then looks for a string similar to the given string and returns the found records.
Any help would be appreciated. Thanks
Unless your data size is small (< a few MB), you probably want something like Apache Lucene, which can be used to index and search large document sets, and can do fuzzy searches using Levenshtein distance and other algorithms for similarity matches.

Categories

Resources