Highlight and Edit XML in a browser - java

Trying to provide a user with editable XML page in a browser.
For example, the following is part of an XML.
<Employee name="John Doe" type="contract" ID="1000">
<Salary>10000</Salary>
<Email>johndoe#johndoe.com</Email>
</Employee>
When the above is presented to the user in a brower (either IE or FF), the user should be able to highlight an attribute or the value. When highlighted and the second mouse button is pressed, this would pop up a menu for editing. For attributes and tags, it could be something like ID-TEST-PRESENT or ID-TEST-OPTIONAL. Now instead of ID, the attribute should change to ID-TEST-PRESENT when selected.
Likewise, for values, a text box can be presented, where the user can enter a new value. Then this updated XML file needs to be sent to the back end and saved.
Is this doable? If yes, what would be the easiest way.
I have always written embedded applications. This is my first foray on the web browser side. Any help is appreciated.

It is doable of course, but it's not trivial. At least not for someone who is not used to Javascript and manipulating the DOM. You would have to parse the XML and create a HTML document with Javascript event listeners on each element.
You could try and use an existing component and modify it if necessary. I found a similar question here:
https://stackoverflow.com/questions/378205/web-xml-editor-with-xml-syntax-highlighting
Unless you are dealing with generic XML files, you are probably better off just reading the XML and generate a standard HTML form. The simplest way would be to base everything on a database that will export to XML to the backend processes if needed. This makes it much simpler to add/edit multiple rows of data

One way to to create an interface for editing information in a particular XML vocabulary is to use XForms. (I think it is by far the easiest and best, but YMMV.) Given an appropriate infrastructure (see below), using XForms for what you describe would involve:
Write a form, using XHTML + XForms. Specify editing widgets for the parts of the XML you want the user to be able to edit; make other parts of the XML read-only (or don't display them at all). Define how you want the edited data to be submitted. Style using CSS.
When the user opens the form, the XForms processor loads the XML document automatically and provides editing widgets as specified in the XForm you specified in step 1. The user edits.
When the user clicks on the submit button, the browser sends the data back to the server as XML, and software on the server performs the necessary validations (this is user input from the open web, you do want to check it) and processes it appropriately.
As you can see, it's a little simpler than rolling your own using AJAX (at least once you have the infrastructure set up).
What infrastructure is necessary for XForms depends in part on which XForms implementation you are using.
For client-based implementations of XForms (such as XSLTForms from AgenceXML, or Formula from EMC), you need (a) a copy of the software on your server (in the case of XSLTForms, this means one XSLT stylesheet, one Javascript library, and one CSS file), (b) possibly an appropriate link in the form itself (how this needs to be done varies with the implementation), and (c) a server willing to accept PUT requests. In some contexts, it will be (c) that is the hardest to get set up, but any server that provides a WebDAV interface will do, so SVN with auto-versioning, Apache (alone or on top of Subversion), and other tools can all be used.
For server-based implementations (such as Orbeon Forms or BetterForm), you need to install the XForms implementation and run it on your Web server; since they are typically servlets, you will need to put them in a servlet engine. In general, they will ship with some form of WebDAV server included.
Steven Pemberton of W3C and CWI has written a helpful tutorial introduction to XForms; I maintain a list of pointers to that and to other XForms-related materials that may also be helpful.

In order to do this you would need to work a lot. To do generic editing you would need the following
XML parser at back end to parse XML file to 2 formats (A) To convert to the required HTML format for front end. (B) To convert into a required backend format. This is tricky and requires some thought. A brute force method is easy but very inefficient.
Setup an AJAX connection to your script which can take and recognize parts of the XML. For this you will need some mechanism to identify the part... may be an ID passed though HTML.
The interface for AJAX should the update the Database/file and do the needful.
This is a simple layout. It needs a lot of work to be done. Do some research
item

codemirror seems to be the best one
The jquery.xmleditor might be what you are looking for. They offer a graphical UI for editing XML. For the text-based XML editor, they rely on the Cloud9 editor. Be aware that Cloud9 is GPL licensed.
LiveXMLEdit is more an explorer-like editor, but maybe it helps, too
AXEL is a library for creating XML authoring applications based on document templates.

Related

What is best approach for pdf generation front end angular or back end Java?

I would like to here few expert advise to make this decision.
We have web app angular as UI and spring boot as back end.
requirement is to generate PDF of dashboard which we are showing on UI contains few data table with client side pagenation and also need to add extra header footer in pdf which we are not showing currently on UI. font requirement is given by client and must follow.
Considering following two options--
1. Itext pdf generation in java where we will design pdf similar to UI dashboard.
2. use some js library like jspdf and write dashboard inner html to pdf.
Need to understand what is pros and cons of each approach,which is good out of both?
Since you have client and server side options I suggest it's worth prototyping a typical document in both approaches (if you can spare the time). The reason is that there are advantages to each and it depends really how specifically you want your PDF to be like your html.
Generally I prefer server-side generation because:
you have access to data possibly not on the client (eg what is going into your header and footer maybe)
you can store the document server side (if relevant) then deliver to the client
However you said "font requirement is given by client". If the client is subject to change and you need that reflected automatically in the paginated PDF, then Amedee's suggestion of html to pdf might be your best option.
I hope that helps.
Paul.

Struts search application within website of without database

i'm new to java struts.
actly i want to create an application in which i want to search within the website static pages,which has no database. i.e. if user enter the search string then the corresponding results are shown to user.
You should probably start with a Struts tutorial (http://j2ee.masslight.com/Chapter4.html for example) to get the bones of your application up and running, namely your textbox and button.
Struts is an MVC framework with a 'M'. By that I mean the implemention of your model is completely up to you. So when it comes time to write your Action class you can do anything you want. From the sounds of it you want parse an HTML file so you can either load it using java.io if it's stored on the server or load it from where ever.
It depends on your definition of a 'database'. There are some good search engines out there (like Lucene) that can index your html and store this in an index file on your file system. The semantics come in on whether you believe this index is a 'database' or not.
Most of the search engines come with an HTML crawler and parser out-of-the-box so your requirement to have something search through your content (especially when it is not publicly available to be indexed by the likes of Google), should not be insurmountable.

Eclipse Forms Editor for XML

I'd like to program an editor for domain specific XML files which also has a form part (much like the PDE Manifest Editor or the editors of the ADT). Problem is: I don't really understand the code of these 2 examples.
My current approach is following:
Using EMF with an ECore model created from XSD. As Editor a Multipage Editor (one XML editor, one forms part). I don't exactly use databinding between the form and the editor, instead I reload the whole file on page change to the forms page (resp. rebuild the whole file on changing to the editor page).
Currently the XML files are pretty small, so this approach could work, but they can become larger and everytime to reload/rebuild the whole file seems pretty heavy (I'm also planning to use such an editor later for ODX files which can easily become larger than 5MB)
So is there any way to avoid rebuilding/reloading the whole file and just update the changed information in the datamodel?
Also, I'd like to have some kind of content assist (something like lightweight IntelliSense and more important ProblemMarkers)
Can this be achieved directly by using EMF or how can this be done?
Despite the fact that there are some really good resources about Eclipse forms and XML binding to Java, I can't find any resources for these handy Multipage editors.
Can you point me towards some directions. Maybe if EMF also isn't the solution, the project is still in the beginning phase, so I can switch to another library. E.g. for the upper mentioned ODX files I'm already using XMLBeans(in another, pure data mining/converting context), but I assumed EMF would provide some benefits since it is directly bound to the Eclipse project.
I recommend that you take a look at the Sapphire Project. One of they key usecases it covers is bi-directional editing between a form page and an XML source page. There is support for field validation, content assist, etc.
Sapphire Project's Website
Introduction to Sapphire

GWT URL routing and other features

I am thinking about using GWT in my future project. I have few questions:
How can I define the structure of URLs? Does it allow me to recognize the parts of the URL by some information I have in database? How it is defined? Directly in Java or XML?
Does it support HTML5 history tools to change the URL without the necessity of using hashes?
Forms and editation of items in database - does it allow to generate Forms by definition and generate their validation, without the necessity of writing everything hard by hand?
Are there any tools for uploading files (images) in iframes, so that the page does not have to me reloaded? Drag'n'drop uploading? Are there any tools to simply manipulate uploaded images? Resize, crop...
Is it natively possible to create similar hover information like it can be seen on (for inst. when you hover an item on the left, there is an information bubble appearing on the right side):
http://goout.cz/theatre/prague/
Is it natively possible to create similar search dialog like on the page http://goout.cz - for inst. when you type 'a' it starts to suggest items in the database with their pictures.
All the GWT application I've found, run in browser rather as an JS application - but is it possible for javascript disabled browser to use them? Can search engines go through them?
Thanks
1. How can I define the structure of URLs? Does it allow me to recognize the parts of the URL by some information I have in database? How it is defined? Directly in Java or XML?
It's up to you to code it all (or almost all) by hand, in Java.
2. Does it support HTML5 history tools to change the URL without the necessity of using hashes?
It's possible to do it (quite easily actually) but GWT doesn't provide built-in support.
3. Forms and editation of items in database - does it allow to generate Forms by definition and generate their validation, without the necessity of writing everything hard by hand?
No. Editors cut the boilerplate by half, but you still have to build your forms by hand (but that's not a bad things: generated things never look or behave like you'd like to). And UiBinder helps creating UIs.
4. Are there any tools for uploading files (images) in iframes, so that the page does not have to me reloaded?
Yes.
Drag'n'drop uploading?
Not directly. There's support for native drag-and-drop, but not for accessing dropped files and uploading them. It's not hard to add though.
Are there any tools to simply manipulate uploaded images? Resize, crop...
The canvas API is supported but you'd have to do it all "by hand" (including, particularly, getting the image to draw it to the canvas, and then upload the canvas content)
5. Is it natively possible to create similar hover information like it can be seen on (for inst. when you hover an item on the left, there is an information bubble appearing on the right side): http://goout.cz/theatre/prague/
Yes.
6. Is it natively possible to create similar search dialog like on the page http://goout.cz - for inst. when you type 'a' it starts to suggest items in the database with their pictures.
Yes.
7. All the GWT application I've found, run in browser rather as an JS application - but is it possible for javascript disabled browser to use them?
No.
Can search engines go through them?
Google can, with little effort.

Clientside Javascript --> Serverside Java --> user is served a .doc

I am helping someone out with a javascript-based web app (even though I know next to nothing about web development) and we are unsure about the best way to implement a feature we'd like to have.
Basically, the user will be using our tool to view all kinds of boring data in tables, columns, etc. via javascript. We want to implement a feature where the user can click a button or link that then allows the user to download the displayed data in a .doc file.
Our basic idea so far is something like:
call a Java function on the server with the desired data passed in as a String when the link is clicked
generate the .doc file on the server
automatically "open" a link to the file in the client's browser to initiate the download
Is this possible? If so, is it feasible? Or, can you recommend a better solution?
edit: the data does not reside on the server; rather, it is queried from a SQL database
Yep, its possible. Your saviour is the Apache POI library. Its HWPF library will help you generate Microsoft word files using java. The rest is just clever use of HTTP.
Your basic idea sounds a bit Rube-Goldbergesque.
Is the data you want in the document present on the server? If so, then all you need to do is display a plain HTML link with GET parameters that describes the data (i.e. data for customer X from date A to date B). The link will be handled on the server by a Servlet that gets the data and produces the .DOC file as its output to be downloaded by the browser - a very simple one-step process that doesn't even involve any JavaScript.
Passing large amount data as GET/POST around might not be the best idea. You could just pass in the same parameters you used to generate the HTML page earlier. You don't even need to use 3rd party library to generate DOC. You could just generate a plain old HTML file with DOC extension and Word will be happy to open it.
Sounds like Docmosis Java library could help - check out theonline demo since shows it something similar to what you're asking - generating a real doc file from a web site based on selections in the web page. Docmosis can query from databases and run pretty much anywhere.

Categories