parser the xml and build a ui for user - java

Now I have to handle some xml in my java swing application.
I have to build a swing ui according to the special schema ,then user can fill some values.After user completed,I will collect the information,validate the value and then build a xml file.
For building xml file I can use the xmlbeans,however how to parse the schema and build a swing ui? Since the schema is rather complex.
A schema can be found here:
example schema
I have to parser this schema,for the LiteralInputType ,a JTextArea should be built.
However there are other types "complexType" and etc..
These types may not occur at the sametime. Some times only the LiteralInputType is needed,somethimes the ComplexType is needed,also maybe all of them are needed.
So, how to implement it? Anyone can help me?

Interesting to see someone else busy with WPS. :)
I believe WPS is quite special so that no existing tool would be able to build user interfaces for WPS processes. When we were solving this task, we just took a JAXB-based parser for WPS and simply built the UI programmaticaly using factories. We've implemented Swing-based as well as Javascript/OpenLayers based generic WPS clients this way.

Related

Saving running applications

I have a program where I need to save a running application to be able to go back to it later
I know that I can write/read from a text file to achieve this but the program is pretty prodigious so it's not really a good way to do it because I have 10+ classes and thousands of JTextFields, JComboBoxs, etc. Does anyone know of a way I can achieve this without writing/reading from text files?
An example of what I need to be able to do is this:
In Microsoft Excel you can load files (.exl) into it and be able to edit them.
The Swing Application Framework provides a way to save session state when your application exits and restore the state when you restart. Session state is the graphical window configuration of your application. This state includes window size, internal frame locations, selected tabs, column widths, and other graphical properties.
How do you think Excel does this? It stores the type and value of each cell, along with metadata describing the worksheet in its own proprietary binary format in a file. If you have a custom application with complex internal state, you will have to design a storage format and serialize the state yourself. You may be able to use Java Serialization, but not without some effort.
A good way to do this is to save the data from your controls into a canonical form and then make that class serializable. You can then persist that data to a file. Here's a link about serialization in Java.
UPDATE
I just noticed that you said you have thousands of form controls. So you probably don't want to do all of this in one class, but you probably want to maintain a hierarchy of classes and split out the data into separate classes. This will also help you separate your concerns. Hopefully you have POJOs or domain classes that represents your data. If that is the case, your task will be much easier. This is also why separating concerns is good :).
To save the state of an application, i can think of two popular way:
1) save the state of the application in a Database
2) save the state of the application in a binary file or XML,json or any format you want.
Maybe giving more details about the app. would help.
is it a Web app, fat client app, client/server app... !^
Solution may vary with the type of application.
Hope it help.

Android XML based UI in Java

I would just like to have an Android XML UI file in Java. I have the XML file and I believe I need a parser that would actually generate the Java UI class file. Any ideas how to go about approaching this ?
EDIT: Well, let me explain this a little better. I am trying to track Google finance data for which I use gdata client library. However its authentication does not work in the Android environment, and so I am switching to Java SE. However, is there any library or something by which I can have the Android UI, without having to write my own parser. Need not necessarily be XML based.
You need to write your own parser and instantiate the Swing classes that are synonymous with the controls described in the XML.

Highlight and Edit XML in a browser

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.

Does it exist: context aware, autocompleting, XML editor with API for including into my app

I need an API-addressable, Java-based XML editor that is context aware. For instance, if you give the editor a schema for the XML document that is supposed to be generated, then, as the user is editing the XML, they will have access to recommendations and autocomplete for XML elements and attributes.
You haven't said what environment this should run in...
Assuming Java, the netbeans editor is very solid and it should be possible to embed it in external Java applications. Obviously, that would involve brining a large portion of netbean's code along with it though.
I haven't used it, but it looks like Jaxe might be provide a solution as well.
Something else to look at would be oXygen. The Author component can be integrated into a web application as a Java Applet.
http://www.oxygenxml.com/xml_author.html
Example:
http://www.oxygenxml.com/demo/AuthorDemoApplet/author-component-dita.html

Executing Constantly Changing Logic

I writing a dynamic HTML parsers functionality.
I will want to modify existing parsers and also would want to add more parsers (I expect parsers will be modified as sites a remodified and new parsers will be needed for new sites).
I started writing a generic functionality which use a XML with conditions and rules for each site but as this works fine for now, I'm pretty sure it will need constant modifications...
The parsers will parse and write the data to a DB.
My application runs on JBOSS 4.
Any known best practice for that?
Thanks,
Rod
Thanks for your answer. Maybe I was unclear. I realized that imm. from the rate my question got. What I am writing feature that manage parsers execution. Each parser will parse a different text document structure. Documents structure might change from time to time and more new structured document will be added to be parsed. I dont want to recompile build deploy my application for each arser change.
I want to manage the execution of each parser as theymight be executed in parralel or according to execution rules.
Does Using Java ScriptingEngine might be a good option?
There are lots of ways to have some code that can be modified without redeploying. Using groovy scripts to do the parsing is one. Is is a rather simple matter to check to see if the script has been modified and automatically reload it.
The design sounds convoluted to me, but IFF you prove to yourself there's not a much simpler way to accomplish the same task, you may want a rules engine like Drools...

Categories