Tools to retrieve static content from JSP and JS files - ANTLR? - javascript

I am trying to find out if there are any tools that exist that will get all the static content (for localization) from JSP and JS files. We want to automate the process of finding the static content from JSP and create resource bundles with them.
After some analysis it seems like some form of this can be achieved using ANTLR and XML grammar for ANTLR - http://www.antlr.org/wiki/display/ANTLR3/1.+Lexer
That is use ANTLR with XML grammar to parse JSP and use StringTemplate to output in to property bundle.
Kindly let me know if somebody has attempted same succesfully.Any help or pointer is greatly appreciated. Thanks

What you always end up discovering is that a half-baked solution is half-baked. Trying to parse JSP or JS (for the latter you really mean HTML with embedded JS?) you need parsers that will handle JSP and HTML. XML looking like HTML won't cut it; you'll just end up with parsing errors.
So, you can try to bend ANTLR's XML parser and with sufficient effort you might succeed. But then this project turns in to one of bending parsers, rather than doing localization.
Our DMS Software Reengineering Toolkit has full parsers for JSP and for JavaScript embedded in HTML, and for HTML. These parsers build full ASTs automatically and make their content available for custom output purposes.

Related

Skeleton website that will parse external file and display in HTML

I am creating a website that is meant to be a sort of user start guide with an introduction page, an overview page, and a page featuring the actual guide which will feature step-by-step instructions for the user to follow. Since I don't have the specific content for the page, I'm " hard coding" the HTML with placeholder text. Going forward, I want to create a skeleton HTML framework that will parse the start guide files JavaScript and display the information on the page in its expected place. I'm strongly considering using XML (or JSON) files and parsing it with JavaScript and using browser DOM methods because that's what I know. However, I'm working on a team of people who most likely won't know how to convert the start guides (which are PDFs) into well-formed XML so I'm wondering, are there any alternative ways to do this? I know Word has the ability to save documents as HTML and XML but they don't create the proper attributes/tags to be parsed with the JavaScript I'd write.
TLDR: Are there files or alternative methods other than JSON and XML (something that non-tech savvy people will understand) that can be parsed and processed with JavaScript to display in a skeleton website?

Server-side template parsing

I'm currently exploring how to use HandlebarsJS via a server-side parser.
Unfortunately we are limited to using RhinoJS server.
I've searched high and low to find out how to use HandlebarsJS via the server side. I can see how to register a helper and various other things, but I'm curious to know if it's possible to parse a JS or HTML file and have the various portions of the file replaced with the server generated content?
I'm hoping this is possible without using something like node and optimistic that it's possible to parse the file just like you would do using PHP or CFML but using JS under RhinoJS instead.
Any suggestions greatly appreciated.

How to use Javascript to analyze arbitrary html files

I want to use javascript to analyze an html file (I want to find the sum of a column in a table). I have the code that I think will do this, but I am unsure of how to tell the javascript where to find the html file.
Most of the things I've done with javascript have involved linking the html file to the javascript by including a tag in the html file. However, in this case I want to be able to run this analysis on arbitrary html files. Is there an argument I can pass in to the javascript somewhere?
Edit: to those asking to see my code, I am using something a lot like the script in the top answer of this stack overflow question: Sum total for column in jQuery
I am trying to make a tool that can be used on various different html files with tables, although all of them should be hosted in the same directory. It is looking like I would need to use AJAX to do this. Can the script be run without being attached to an html file?
Edit 2: I was originally intending to call this javascript from inside a perl script. However, I am now discovering that Perl might already have some support for analyzing html documents with the HTML::TreeBuilder module. Depending on how hard it is to use, I might just implement the same function with that in a perl script instead of messing around with javascript.

Use Javascript To Print Page As PDF (With Django)

I need to convert a web page to a PDF because it won't print/look correct if it isn't converted. This is because the web page is so big, that as an HTML document the browser will try and split it into multiple pages (not just vertically, which is fine, but horizontally, which is bad). Though I originally planned to do this on the server side with Django, I realized that virtually all of the available libraries were written for python2, when I was using python 3.
So my only other option is client side. The only thing I could find on stackoverflow was this: convert HTML ( having Javascript ) to PDF using JavaScript, but all of the answers were in Java, not javascript.
I think the most ideal solution would be to change the style so that it was more printer friendly rather than making it into a pdf.
If it really does have to be a pdf created with Javascript, there's a library jsPDF http://parall.ax/products/jspdf out there for creating pdfs with Javascript. You would have to write something on your own to parse the page to create a matching pdf.
If you can use php, I recommend using dompdf, which was written specifically to translate webpages into pdfs, so there would be much less work involved there. https://github.com/dompdf/dompdf I've actually used this library, and it seems decent, though it doesn't support all css styling.

Loading data into static html form page or XML and using javascript

I have a text data (CSV) file that needs to be converted into a static HTML page for user viewing. In the HTML page, the user needs to be able to filter the data into views. Each HTML file will be archived.
I plan to use JavaScript for the user filtering functions. I plan to use a Perl script to convert the CSV file into an HTML file and include a form on the top of it for the user filter options. The HTML file will reference the JavaScript file.
My questions are:
I'm considering converting the data into an XML instead. Is this better practice?
If so, is it possible to have web forms in XML and run javascript functions?
I have a CSS for the HTML file. Do I have to use XSLT for XML?
Is there a way of combining XML and HTML into single file? Any benefit in this?
You can use XML as SOURCE instead of CSV, since XML defines cleaner handling of data (commas, semicolons, ' and " in the values).
If the content is static, and you will store it, then I suggest you use a format that is most close to the end result. That would be HTML+JS+CSS files. (JS and CSS help you keep some repetitive info out of the HTML).
Now a little background. XML is not viewable by default, you should use it with an XSLT file. What happens is that the browser "opens" the XML by transforming it with the XSLT into HTML. In this case you need the extra XSLT file, and a client capable of running it (most browsers are quite good at that nowadays). But you would only use this solution for three reasons. 1) If you have so many XML files (already at hand) that you do not want to process them with XSLT and save the resulting HTML instead of them, and leave this (wastly repetitive) computation burden to the clients. 2) You have other uses for the XML files. 3) The generated HTML is so much bigger than the source XML that it poses storage problems (although CSS and JS files should be enough to avoid that).

Categories

Resources