Convert a table based layout to divs with Java - java

I've recently been charged with creating a Android & iphone app for work. That being said, I'm a css/php designer-developer with a bit of javascript in the mix.
I need to write a bit of Java (not javascript) that will convert a table based layout into a div based layout so that I can then have control over positioning, padding, and what not.
I see many similar post, but these post involve more "designer" oriented goals rather than functional control over positioning, layout and so on.
A good resource would be greatly appreciated as I can't seem to google an appropriate search string. My searches tend to yield more "free javascript code", "Java tutorials about making flashing banners", "How to make fading menus" and countless other rabbit holes that lead to wonderland.
Oh, Currently using eclipse with Android SDK & ADT plugins installed.

It would be much more easier if you have predefinied a set of rules how the conversion should actually be taken place. There is namely fairly a lot which needs to be taken into account. This is really not going to be a bit of Java.
If you're looking for an existing tool, in Adobe Dreamweaver you can do that by Modify > Convert > Tables to AP divs. But still, I question if those kind of tools provides exactly that what you need. As said, there's fairly a lot which needs to be taken into account and it's shooting in the dark without a clear set of rules/requirements.

you may have to write more than a bit of java. you will need parse the html (http://www.benmccann.com/dev-blog/java-html-parsing-library-comparison/) and walk the dom (How to search in a HTML file for some tags?). that's fairly straightforward (assuming that your html is well formed), but i suspect that turning each table element into a div will require a moderate amount of code.
as BalusC pointed out, there may be tools that can get you part of the way, so you might try to do it in two passes.

Related

Can one open another application within a javaFX frame?

I am currently working on a desktop application in which one can generate a responsive website for documentation (java-doc like) by providing nothing more than a simple word document.
I currently have a prototype working in which I select for styles on certain paragraphs to determine its function and how it should be transformed to a correct HTML representation. I also found a way to dynamically link to certain section of the document. Everything is working however I would really like to combine the list of documents to generate, a preview of the to-be generated website and a text editor program in 1.
since this will be relying on word heavily I was wondering if Java FX provides a means to display an application such as word or openoffice within an internal frame. Much like how Java Fx's webview displays websites.
In an ideal situation it would look something like this:
Any help would be greatly appreciated.
Alas, not possible in a plausible way.

How to enlarge eclipse java editor functionality using plugins?

Hope somebody could help me, giving a hint and way out.
Right now I'm involved in a ambitious project trying to create mixed math and programming IDE.
After a huge prestudy we decided to use eclipse as a base, and somehow add Mathematica,maple functionality.
Generally speaking we want to make entering math expressions (a = sin(Pi)+10^2) into java code possible. Also those expressions should be showed in LaTex view, right in the code to make it more readable for engineers, to illustrate the code we want to implement insertion images in comments.
As we need all th java editor functionality, in my opinion it's correct to use standart eclipse java editor, and learn it to behave with other objects, e. g. images.
So my questions are:
- Could somebody share experience developing similar products?
- May be there are something like we are going to develop?
Probably I'll write more questions, especially tighter ones.
That is certainly an interesting sounding project. As Gilbert Le Blanc mentions, the Java Editor is highly optimized to edit Java code and is not meant to be extensible.
That being said, I can recommend two options (one that plays by the rules, and one that goes against them).
Instead of embedding your images directly in the Java editor, you could implement your own hover, through the org.eclipse.jdt.ui.JavaEditorTextHovers extension point (so it would work like JavaDoc hovers), or in a separate view that sits beside the editor (so it would work like the JavaDoc view). (This is playing by the rules.)
A while ago, I implemented a prototype editor that allows you to edit Java code with snippets of CAL (a functional JVM language) embedded inside of it. The snippets were stored in there own little window inside the editor. This was a prototype and not everything worked smoothly and it was also using Eclipse 3.2, but this is exactly the kind of thing that you want to do. It won't be easy to compile and run the code, but you can have a look at it....well, maybe. I have to find an EPL variant of the source code. Until then, just realize that hacking the Java Editor like this requires some specialized knowledge about the JDT and you need to be careful about how you do it so that you do inadvertently break other things.
Edit
Here is a zip of the project I described. It will not compile as it is, but you can look at the source code:
Try this link. It should be viewable by the world.
The essential thing to realize is that swt StyledText widgets can themselves contain other widgets. This project leverages that in Java editors.
In particular, look at the class org.openquark.cal.eclipse.embedded.containing.ContainingEditor, which is a sub-class of CompilaitonUnitEditor. This particular class embeds a second text editor (the contained editor) inside of another editor (the containing editor).
Also, take a look at org.openquark.cal.eclipse.embedded.containing.ControlManager. This class manages the different controls inside of a styled text of the containing CompilationUnitEditor.
What this project does is creates a Java-like editor, and allows users to embed editors for another language inside of the Java editor. These editors are actually backed by text in the containing Java editor, but the text is covered by the contained editor.
The contained editors move up and down as text is entered into containing editor. Also, you can use the keyboard to gain/lose focus in a contained editor.
It's been several years since I looked at this code, but if you have any questions, drop me a line or add to this question.
The Eclipse Java Editor is made up of hundreds of Java classes. There's an implicit assumption in those hundreds of Java classes that the editor view is just for code.
In my opinion, you'll find it much easier to develop a Mathematica-type editor for your math images, and leave the Java editor alone. Your engineers can open two editors in Eclipse.
If my comments haven't dissuaded you, here's the Eclipse documentation for Eclipse Helios, otherwise known as Eclipse 3.6
The section you'd start with is called the JDT Plug-in Developer Guide.
The Eclipse web site is responding slowly as I'm typing this. You can also access the Help from inside of Eclipse Helios.
Help -> Help Contents
I know exactly what you can do. First, you can turn-on the unicode character set. This will allow you to have variables such as greeks, which makes the code much more readable. [General->WorkSpace->Text Encoding = UTF-8].
// Apply spring soft constraint using Erin Catto's method with Semi-Implicit Euler :
// Figure out (ω,ζ) from node sizes, then k=mEff.ω², c=2.mEff.ω.ζ
double ω = 2.0*π*f; // ω (angular frequency)
double k = meff * ω*ω; // spring stiffness
double ζ = (b1.ζ + b2.ζ)/2; // Average out the damping coefficients
double d = 2.0 * meff * ω * ζ; // damping coefficient
double γ=h*(d+h*k); // CFM (Constraint Force Mixing)
Second, your suggestion to have a LaTeX formula visible within the code is also the next best thing. I know it's possible because I wrote one 3 years ago, but I can't find the code anywhere. I had posted it on a forum for eclipse plug-ins but it's gone now.
The good news is that I'm writing it again, because I need it - that's how I found your post . This time I'm using jlatexmath which is better than what I used last time.
The idea was/is that you can embed a formula in a comment as LaTeX, and the plug-in renders the LaTeX in a tooltip when you hover on it.
I'll post a link or code here when I'm done. Most of the work is figuring out how to make eclipse accept the new hover control.
J.D.
Ok, as a follow-up to my post above, here is the Eclipse Plug-In Development Environment (PDE) project I developed for this. The Plug-in is named LaTeXHover and will pop-up a tooltip whenever you hover on top of a comment line that contains LaTeX such as:
// $latex i\hbar\frac{\partial}{\partial t}\left|\Psi(t)\right>=H\left|\Psi(t)\right>$
// $latex x=\frac{-b \pm \sqrt{b^2-4ac}}{2a}$
The LaTeX must be delimited using $latex and $ with no extra spaces.
It uses jlatexmath for rendering.
I'll try to package the plug-in better and add that to the Git repo, and maybe contribute it to one of the Eclipse Plug-In projects. As last time, I don't have time now to do this, but at least it's out there now. Anyone wishing to continue the project from here is welcome to do so.
J.D.
git://github.com/jdbertron/latexhover.git

What is the easiest way (framework/library/call) to prevent Cross Site Scripting using Google App Engine (GAE)?

I'd like to store then later display user-entered content securely with minimal effort (my goal is a web app not writing a bunch of security-related code).
EDIT: Google App Engine for Java
I'm working with the same issue myself; but I haven't had the chance to get it out into the real world yet; so please just keep in mind that MY ANSWER IS NOT BATTLE TESTED. USE AT YOUR OWN RISK.
First, you need to ask yourself if you're going to be allowing the user to use ANY html markup. So, for example, can the user enter a link? What about make bold text?
If the answer is NO, then it is fairly simple. Here is the idea of how to set the filter up:
http://greatwebguy.com/programming/java/simple-cross-site-scripting-xss-servlet-filter/
But personally, I don't like the filter being used in the first example; I just put it there to show you how to set the filter up.
I would recommend using this filter:
http://xss-html-filter.sourceforge.net/
So basically:
Setup the example from first link, get it working
Download the example from the second link, put it in your project in such a way you can access it from your code.
Rewrite the cleanXSS method to use what you downloaded from the second link. So probably something like:
private String cleanXSS(String value) {
return new HTMLInputFilter().filter( input );
}
If you do want to allow HTML (such as an anchor tag/etc) then it looks like the HTMLInputFilter has mechanisms to allow this; but it isn't documented so you'll have to figure it out by looking at the code yourself or provide your own way of filtering.
user-entered content securely with minimal effort (my goal is a web app not writing a bunch of security-related code).
How much security-related code you need to write depends on how much you are at risk (how likely is it someone would want to attack your site, which it self is related to how popular your site is).
For example if your writing a public notepad, which will have a total of 3 users, you can get away with the bare minimum, if however your writing a we hate China, Iran and all hackers/crackers app dealing with $1,000,000 worth of transactions an hour and 3 billion users, you may be a bit more of a target.
Simply put you shouldn't trust any data that comes from outside your app including from the datastore. All this data should be checked that it's what you expect.
I've not validated incoming Java Strings against XSS however removing HTML is normally good enough, and Jsoup looks interesting for this (See Remove HTML tags from a String )
Also to be sure you should ensure your outputting what you expect to be outputting and not the some JavaScript.
Most templating engines, including django's (which is bundled with App Engine), provide facilities to escape output to make it safe to print in HTML. In newer versions of Django, this is done automatically unless you tell it not to; in 0.9.6 (still the default in webapp), you pass your output values to |escape in the template.
Escaping on output is universally the best way to do this, because it means you have the original unmodified text; if you modify your escaping or output formatting later, you can still format text entered before that.
You can also use a service that will proxy all connections and block any XSS attempts. I know only one service like that - CloudFlare (but it doesn't mean there aren't others like that). Unfortunately security features goes in with Pro plan which is paid :(

Is there an API to draw a B-TREE?

That's a simple question: is there an API to draw a B-tree in Java? I just dont want to spend much time reinventing the wheel. I am not having trouble with the algorithm per si, mine works perfectly fine after a lot of reading (specially Lafore's Data Structures & Algorithms in Java), I just dont know how to print a B-tree in a good way.
Thanks in advance.
You've got a couple of options to "render" a graph to screen -
Graphviz has a Java API (Edit: an addon called LJV which gives the API).
I think you ought to be able to use the free version of JGraph to do the same.
I know people have had success with daVinci (now uDraw). I haven't used it since 2003, but from what I remember, you have to generate a bracketed text file for your tree and the program parses it. You should be able to output your text by doing a simple tree traversal.
Have a look at yEd. I'm pretty sure, licensing yFiles just for an API to display tree structures is a bit exaggerated, but the graph editor is free of license costs and you can use it to render your trees. I usually dump my raw graph data in one of the supported file formats, open the output file with yEd and let it do the layout.

Java Swing: Generating dynamic GUI forms from XML

I am writing this application in Java, where I have a JTree on the left of the JFrame, and the item selected in the JTree determines what appears on the right. This is similar to Edit --> Preferences in Thunderbird, and several other applications' preferences.
Anyhow the main difference is that in my app the stuff on the right is dynamic, and needs to be generated at run time using input from a file.
What I am after is various ways in which this can be accomplished, code snippets or existing frameworks / libraries if they exist.
The input file needs to be something higher level than the sort of XML generated during Serialization. No output capability is required.
Thanks
The JEasy Framework looks to do exactly what you're asking for.
But here's a whole list of similar projects: http://java-source.net/open-source/xml-user-interface-toolkits
There's a short description for each one and a link to their project page. You'll want to look at a handful of the ones that sound good to you, and then try one or two for yourself.
As of now i think one of the most actively used is Swixml. better support compared to JEasy.
have been using it for some while now, and is very easy to learn too
Perhaps it - http://www.soyatec.com/eface/ - XAML/WPF for Java.

Categories

Resources