I have to make a simple change to a HTML-Element (add and remove some attributes). The problem is that I have to go through a lot of HTML-files to do that.
How could I automate that? Sure, there are libraries for parsing and modifying HTML, but after looking at a few of them I am getting the feeling that most don't support saving the changes to the HTML-files.
Check out Html Agility Pack. There are plenty of examples out there.
Related
I've made a code which displays an array which shows traffic lights flashing, should I save externally as script files or embed it into the HTML.
I also need to explain why I've done this.
Please I've got until over Christmas to finish this, I've looked everywhere and can't find much, so I'm turning to this where apparently experienced programmers are and who have done all this before.
Please don't close the question, I really need help. Thanks
What is the ultimate goal?
Code maintainability - use external script
Reuseability - use external script
Downloadtime/network i/o - a bit better if embedded.
Want the HTML/CSS redone by designer later - use external script
The more I think of it, the more reasons I see to put it extern.
And tge one I listed pro embed - that's nullified at second load (script from cache)
Revering to the MVC-Pattern I'd put it in an extra file. It's just better structured and better to read.
Another advantage is that you can reuse your code. Like if you'd have a second page which uses this code you would just need the include it there, too.
Good evening, I'm working on a project with a team, we have to make a browser without using JEditorPane or any other class that reads HTML.
How can we do that? Do we need to make a new class that does what JEditorPane does? Can I find somewhere JEditorPane's code? Thanks!
Well, this is an answer:
If you need to display web content without using any pre-existing engine (such JEditorPanel or a ChromeBind), you need to read the HTML as a XML file and construct your native View based on it (without CSS and JS this is a fairly easy task) by constructing the screen based on a one-to-one equivalent of a HTML tag to a Java JComponent.
Modern Web Browsers are pretty complicated, so there are a lot of different pieces that come together to display a web page. In order to build a browser, you need to first understand what a browser is. For that, I recommend reading this tutorial.
Once you have an understanding of how a browser actually works you need to determine which pieces you can reuse and which pieces you have to write from scratch. Do you have to write the entire rendering engine? Good luck! Can you use an existing engine like Gecko or Webkit? Or maybe you can get a little closer to done and use the java port of Webkit?
Once you have a better understanding of the question come back and ask more direct questions when you get stuck at a specific piece. As it is, your first step is to gain an understanding of the problem you are trying to solve.
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
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.
Has anyone got a working solution without some Java/COM-bridge? E.g. process the Email as a file (.msg) rather than locating the data that is referenced in the Clipboard?
Maybe this is a solution for your problem:
http://sourceforge.net/projects/javaoutlookdd/
It allows to handle outlook items like File objects during drag&drop.
I did make some headway on this sort of thing a few years back using Apache POI to extract the contents of an email from .msg files. I'm pretty sure they have a simple swing explorer / viewer that you can use to examine the structure within the compound document format, but I can't find it right now.
I was able to extract most information that I was interested in but was ultimately wanting to create a mime format version of the message and couldn't extract all the information I needed in a format I could use.
I assume that you've already ruled out the tools in "org.eclipse.swt.dnd" for some reason? There are some examples here on how to go about using them, in case you haven't. If what you really want to do is drag&drop, you're going to have to do some work with those tools. At that point, really the question becomes, what format is it in on the clipboard, vs in a file, and which is easier to integrate into your app.