How To Paginate A Long Text Post - java

I'm Creating a website for online reading stories using grails and i'm facing a business problem that if i post a story say 30 pages A4 in the Fckeditor and it had saved will .. the question is how can i display this in a 30 pages with a pagination or something like that.. do anyone have idea cause i'm out of simple ideas and i think making many lists of the story is a rough idea.. so is there any java/grails/groovy or even jQuery idea that can save my day?

You're probably going to have to write some custom code here.
If you want to auto-paginate, then you'll have to index into the string and grab a fixed number of characters, words, paragraphs, or whatever makes sense. If you don't need to auto-paginate, then you can embed pagination information in the text string. Either way you'll have to expose a page number field in the view, then use that to page into the text based on what the user provided.
Sorry I don't have a more elegant solution.

If you are willing to do it client-side then there are jQuery options, such as SimplePager plugin or jQuery Paginate. You will probably need your HTML to be divided into "segments" such as DIVs or LIs or something divisible, though.

Related

parsing web page which is changing real time in JAVA

Heres what i want to do. Im quite a beginner with this so maybe a lame question, But, I want to implement gui application in java wich gets data from sports livescore pages
e.g
http://www.futbol24.com/Live/
http://livescore.com/
and parse it (somehow) in my app...and then i will be able to store it in for example jtable ,save full time results in database,playing sounds after goal is scored and so on
What is the best way to do this ?
It would be almost impossible to parse an HTML document from a live web page and get specific information from it. If you did manage to work out exactly where in the document the data is, the page structure could change at any time. The scores might not even be in the HTML - they could be fetched by Javascript in the page.
I suggest you find an RSS feed of the information you want. Then you'll only have a nice, small piece of XML to parse. That's what it's for.

Does JSoup achieve this?

I want to collect domain names (crawling). I have wrote a simple Java application that reads HTML page and save the code in text file. Now, I want to parse this text in order to collect all domain names without douplicates. But I need the domain names without "http://www.", just domainname.topleveldmian or the possibilities of dmianname.subdomain.topleveldomain or whatever number of subdomains (then, the collected links need to be extracted the same way and collect the links inside them till I reach certain number of links, say 100).
I have asked about this in previous posts https://stackoverflow.com/questions/11113568/simple-efficient-java-web-crawler-to-extract-hostnames , and searched. JSoup seems good solution but I have not worked with JSoup before, so before going deeply on it. I just want to ask: Does it achieve what I want to do ?? Any other suggestions for achieving my simple crawling in a simple way are welcome.
jsoup is a Java library for working with real-world HTML. It provides
a very convenient API for extracting and manipulating data, using the
best of DOM, CSS, and jquery-like methods
So yes, you can connect to a website extract its html and parse it with jsoup.
The logic of extracting the top level domain is "your part" you will need to write the code logic yourself.
Take a look at the docs for more options...
Use selector-syntax to find elements
Use DOM methods to navigate a document

How to programmatically submit a filled form and scrape the resulting page?

I want to retrieve a set of results, which consist of all results produced by (looping) all the options of one of the request-form fields.
I'm using Java language, and HtmlUnit API.
I have managed to do this looping form-fill using the URL to 'fill' the field's variables (I don't know if its the best method, and actually am quite worried it's one of the worst...But it's the one i could do with the knowledge i have).
But i'm having problems figuring out how to make the program submit the form in order to reach the result page, and on how to download (scrape) that page before moving to the next.
NOTES:
-If you have a better way of filling the 'request-form', that is welcome as well.
UPDATE:
This solves the issues when using HtmlUnit API (thank you, touti):
HtmlPage resultado = pageNow.getElementByName("buscar").click();
System.out.println(resultado.asText());
A better way than loading both the request and response pages is still hugely welcome tough!
you can simulate using Jquery the click on your submit input like this
$("#submit_id").trigger("click");

How can I highlight text - strictly timed - a la Karaoke without Flash on a web page. What technology choice?

I would like to display the whole text of a poem, then have text highlighted according to a pre-established time sequence. Something like Karaoke, but without any sound track. A user would then be able to read it at exactly the "right" tempo.
I figure I can generate a subtitle track (for example, with something like Aegisum - although this keeps crashing on my Mac) with the timing data. Something line by line, such as:
1
00:00:18,067 --> 00:00:20,067
Twinkle twinkle little star
2
00:00:20,467 --> 00:00:22,467
How I wonder what you are
... or better still, a word or sylable at a time.
I don't want to use Flash for iPad/iPhone reasons.
My exact question is this as I'm somewhat naive: What would be the best technology to use? I don't need an exact solution, just some pointers on where I should concentrate my efforts. Does Timed Text in HTML5 (TTML) have anything I could use on this? Or SMIL?
Someone posted a karaoke display engine build in js: https://github.com/sk89q/ricekaraoke
You can use Javascript and CSS to accomplish what you want. You can wrap each word in a span, then apply styles to the span elements at the proper timing intervals. If you can store timing information about when you want corresponding words highlighted, you can use setInterval to add styles at the appropriate times. If you want to use HTML5 features, you might look into using Canvas or SVG to enable more advanced animations.
You can achieve a karaoke effect using a javascript library from Mozilla called popcorn.js You can download it from http://mozillapopcorn.org/
Here is a tutorial http://net.tutsplus.com/articles/news/a-look-at-popcorn/
Here is a demo http://danharper.me/demo/a-look-at-popcorn/
Lots of links to related info at the bottom of the second link.

list option in html from text files

I want to list options in drop down menu in HTML form but i need to make some options to be multiline .and the options i need to read them from text file.any ideas how to do that?
In order to have your HTML display values from a text file, you're going to need to use some kind of server-side generation (ASP.NET, JSP, CGI, whatever). The exact solution will depend on what server-side technology you use/choose, but in all cases it should be fairly straightforward as this is a common requirement for all of these technologies.
As for your first part, what exactly do you mean by "some options to be multiline"? Do you mean that some values are quite long and have spaces, so you want them to wrap? Do you want to have some kind of drop-down box that shows multiple values at once? Do you want them not to be a dropdown at all? How will you decide between the values that should be multiline and those that should not? If you can express your intention more clearly (which may involve some additional thinking on your end), it will be possible to help, and you may even end up working out the solution yourself.

Categories