Can Jodd provide functionality like apache tiles framework? - java

I am using jodd in my project. I am using lots of functionality jodd like madvoc , petite. I am looking functionality like apache tiles framework I have seen and read the post http://jodd.org/doc/decora/ but I don't get to much. Can any one provide working example of decora.

Ok, this is not short question - so please be a bit more concrete here on StackOverflow :)
Decora is quite simple and somewhat different then Apache Tiles. It reminds on old, good SiteMesh. Now, let me explain how it works:
with your business logic, create an design-free html page. Generate the content right in the <body>.
Now, create a template with design, colors, images... Choose where you want your content to be injected; like inside certain div.
After you apply Decora, the body content from the page will be decorated with the template, by inserting it into this div.
This is how it works in a nutshell. You have working example in Uphea but just note that is a bit older version of Jodd used. Also, there is quickstart project, that has Decora configured.
Decora is more powerful then above - you may have more regions on one page, set the header tags like title and so on. You may use html tags for marking the regions, or JSP tags, etc.

Related

Is it advisable to use 'include' tag of jsp for setting the general structure of the website?

I am making a website with around 20 pages in it. Now almost all the pages have same general layout like the menu bar, header, footer etc. I've made a jsp page which contains this common contents and then with the help of 'include' tag I'm using it for the other pages. So is it advisable to follow this technique? Kindly inform me about the pros and cons of using this technique.
Thanks in advance.
Remember that with each #include tag,the whole jsp thing will be converted to a servlet and then it will work as required HTML format as compiled by the browser. So there is no doubt that for a large application it will create unnecessary performance issue.
Instead of doing this you may use iframe tag which is now widely used in web development.
You may modify the iframe source code as u want........
So it's totally depends on which way you want to proceed and your application context.there is no fixed rule that you must have to use this or that technoque

How to render plain html in Play 2.0

I'm working on learning JSP and the Play framework, and I understand that it runs on Scala and renders views based on templates, but what if I just want to use plain HTML rather than scala templates?
The situation I'm in is that I'm designing the site to match a visual template, so I'm using Dreamweaver to build the html files. I really like Play framework though, so I'd like to continue using it. So, what are my options here?
I don't get. Play's views are not just nice html files, of course you can (or even should) use your favorite tools for design part, anyway you have to also learn how to include a dynamic parts in it.
Of course you can use DreamWeaver for that task as it has feature for editing source code. But I can ensure you from my own experience, that there are better tools for every-day work with Play's views than DW.
You can also use plain HTML in your /public folder however in this scenario you won't be able to make it dynamic, so it has no sense, as you can create the pages without any framework - just using static files created with DW.
In general words: you need to verify your needs, cause from your question I read: "I like Play framework, anyway I don't want to use it for its job..."
After-comments edit:
You don't have to make views dynamic. If you won't pass any arguments into the view and will put there pure HTML it will be 'relatively cheap' way for displaying static pages as well. Just you need to remeber to leave first line of the file empty. So you don't need to use File index = new File... instead just put your bare HTML code into ie: app/views/staticContact.scala.html and then use an action:
public static Result staticContact(){
return ok(views.html.staticContact.render());
}
On the quite other hand, last time I was wondering if it wasn't better to put HTML code of the static pages into the DB, in such case you could create an editing page, where you could change HTML without redeploying the application. All what you will need it was just fetching HTML from DB and displaying it in one generic view. For better performance you can use included Cache implementation.
GET / controllers.Assets.at(path="/public/html", file="index.html")
This is working for play 2.0.1 for /public/html/index.html file

How do I translate a page in java with lot of text,without using resource bundle?

I have a web page with lots of text.Is there any means through which I can translate it,without using resource bundle(which involves using properties files,requiring key value pairs for all words.)?
Thanks for your precious time.
An alternative is to create separate views for each language. So a "mypage_en_US.html" for the US-english version and a "mypage_en_GB.html" for the british-english version. This gives you total control over the text and layout but has the drawback of possible code duplication if there is any logic in your view.
Wicket uses pretty clean views which should hardly contain any logic so this works pretty well there.
Just be innovative here. If you are getting shitty copy pase work. Write a program to convert the properties file and then use that properties file using google translate api, but yeah end of the day you will have to go with properties file.
I belive there would be other way too using google translate api again, would love to hear that myself too
Depends on your web framework.
For example, Wicket can apply I18N on webpages in two ways :
- using I18N files and resourcesbundles, with placeholders where required in the page
- by having totally separate pages, one for each language. The page template itself is postfixed with the locale, much like property files : HomePage_en.html, HomePage_fr.html, etc.
Other web frameworks may have similar features. If you're using raw JSP/Servlets, I'm afraid you're pretty much on your own.
But it's totally possible to implement your own templating system. For example, you could use a set of Freemarker templates, and load the one that matches the desired locale.

mediawiki syntax parser for android

I need some help fetching the content of a mediawiki page and displaying it in my android app. I've found that mediawiki has a api which can export the markup text, but I need someway to parse it.
Other solutions are also welcome, but I don't just want to include the whole page (with menus and everything) as a webview.
You can get the HTML for just the content section (i.e. not including the menus and everything) by specifying action=render when fetching the page normally. You can get about the same result using the API's action=parse. In either case, you could then supply your own framing HTML, stylesheets, and the like for proper display to the user.
If you are in control of the wiki you may be best served by using the mobile format that wikipedia uses. Otherwise it will depend on what the markup text it returns looks like. If the markup is what you would see in the wiki editor you may have issues. Wikipedia for example make extensive use of templates (or whatever they call them). I'm not sure if you can do much if you don't have the actual temple code behind that.
You also might want to look at http://www.mediawiki.org/wiki/Markup_spec if you are headed down this path.

Is there a way to change or reskin an incoming website on the fly?

I have a project where they want me to embed a website into a java application and they want the website to have a similar color scheme as the rest of the application. I know a lot about CSS and building websites but I am not aware of a way to change the look of a website as it comes in on the fly. Is there someone who can help?
Update:
I don't have access to the header because it is not my website. To give more info about the project is we have a browser embedded in a java client application. The user needs to access a website that displays the contents of a database. I have no access to the original html or css from the site.
What i need is to change the background color and font sizes of the incoming webpage to match the look and feel of the java application.
One approach would be to replace their CSS with your own.
You could also take the approach used by the Stylish plugin, which involves a lot !important decelerations to override the site's CSS. Since this is a Java app, I assume the user will not have opportunity to supply their own CSS, so using !important here doesn't precisely go against the standard.
In your particular situation, I'd look into data scraping, all you need to do is scrape the website for the data, and then re-style it to present it how you want.
Good luck
The Greasemonkey add-on for Firefox does just this. You can write a bit of Javascript code and have it run when certain web pages load. One common thing to use it for is to make changes to the DOM to move page elements around, hide or resize elements, change colors, etc. There are a bunch of examples at userscripts.org if you want to get an idea of what I am talking about.
Your code would simply need to do something similar. Load the page (including the normal style sheets) and then use the DOM to make changes to style elements as desired. Browse through the source of the page to get the names/ids of important elements, and your code can key off of those. Loading an additional CSS file containing your changes is an option, but doing it programmatically will likely give you more flexibility in the event that the target website changes.
Depends on what do you use to show the pages in Java. Most browser implementations support dynamic changes to the DOM, so you can simply add a CSS file to header as a last element, and it will be applied.
you need to know the markup of the html / css so you can make the best skin.
you could theoretically do it by styling just the basic tags: h1...h6, p, etc... but it would not be as good and would probably fail to produce the best results at times and even produce horrible things at times.
if you KNOW the site markup then you can make a skin and simply use CSS/images to skin it as you wanted it.
just include your CSS markup LAST so that it overrides the one already present on the site that you want to skin differently.
should not be a difficult thing per se. the skin itself is probably the better (more effort required) part of the job.
On the fly, should mean changing the html fetched. So parsing and replacing tokens seems to be a/the way.
You could change the locations of the style sheet files by replacing the href value in a link that points to a css file, and set the value to your style sheet (a different URI).
<link type="text/css" href="mylocalURI" rel="stylesheet />
(this should be the result of a process/replacement)
I think you understand what should happend for inline styles.
I would use JTidy to normalize the original site HTML to XHTML, then use XSLT to filter only the interesting/relevant information, obtaining XML format; and finally (since I wouln't want to convert XML to objects), XSLT again to transform the "pure" XML into the HTML look & feel I need/want.
All of this can be assembled as streams, using more or less 4 Kb of buffer per filter (12 Kb total) per thread. Also meaning that it will run fast enough. And all built on standard, open-source available components.
Cheers.

Categories

Resources