WYSIWYG XML Editor java - java

I need to write a swing based editor that can open specified xml files, which contains the text i have to use between a <p> and </p> tag, but there are other tags in the file too. There are other useless informations in the file.I don't need to display them, but it needs to be preserved. I need to dispay only the text inside the mentioned tags in a JTextComponent and let the user modifying it and somehow write back the changes to the underlying xml source. The positions of the tags in the xml file will vary from file to file and there are more than one <p> tags in a file, and i should display and make editable the content from all of them at once. What do you think? Which is the best way to accomplish the above task?

If you want a quick'n'dirty programmatic solution, just read your XML DOM into a JTree. Here's one of many, many examples you can find on the web:
http://www.developer.com/xml/article.php/3731356/Displaying-XML-in-a-Swing-JTree.htm
If you're looking for an open source XML editor, you might want to consider Amaya:
http://www.w3.org/Amaya/
PS:
As you're probably aware, Swing's "JTree" implementation is MVC to the max - you can easily adapt any example to filter the contents of the tree model (i.e. to filter/modify your DOM content source), or to change the appearance (i.e. modify your JTree's appearance and/or behavior).

http://java-sl.com/xml_editor_kit.html
You can use the kit as the basis for your project. Add a DocumentFilter to allow editing only the plain text.

Load the XML into a DOM tree
Present the required text to the user in your UI
When the user commits changes, update the DOM tree with the new text
Serialize the DOM tree back to XML

Related

How to create a Word doc from a template using Content Control Data Binding with OpenDoPE

I have a Word template, complete with fonts, colors, etc. I am querying a database and retrieving information into a POJO. I want to extract the relevant info from said POJO and create a Word document as per my template's directives.
The doc will have tables and graphs so I need to use Content Control Data Binding. As I understand it, I'll have to do the following to achieve this
Modify the Word template to add content controls
Transform the POJO into an XML object (template?)
Use ContentControlMergeXML to bind the XML data to the Word template
Unfortunately, I can't find a good step-by-step example of this anywhere. Nearly all of the links in the docx4j forum lead to broken GitHub pages
My questions
How can I use OpenDoPE to add tags to my Word template? I'll need to preserve style, so I want the correct OpenDoPE version
Should the POJO be converted into an XML object or document?
Is there an end to end example of this entire process so I can follow along? (preferably with source code)
Content control data binding essentially injects an XPath value into a content control in the Word document.
That XPath is evaluated against an XML document, so yes, you need to convert your POJO into XML.
Authoring
Now, there are 3 different OpenDoPE Word AddIns which you can use to add content controls to your Word document. See the links at https://opendope.org/implementations.html
The most recent one assumes a fixed XML format. So to use that, you'd need to transform your POJO to match that format. (ie use the AddIn to author your docx, then inspect the resulting XML (embedded in the docx), then figure out how to transform your POJO to that).
The older AddIns support arbitrary XML, but are cruder. To use one of these, first convert your POJO to XML (eg using JAXB), then feed the AddIn your sample XML.
Runtime
To bind your XML to a docx "template" to create an instance docx, see https://github.com/plutext/docx4j/blob/master/docx4j-samples-docx4j/src/main/java/org/docx4j/samples/ContentControlBindingExtensions.java
You can run that sample code against the sample docx + data; you can take a look at the docx to see what the content controls look like (they bind a custom xml part in the docx, so unzip it to see that)
ps the GitHub links broke as a result of a recent code re-org. GitHub isn't smart enough to dynamically maintain them :-( See https://www.docx4java.org/downloads.html for downloadable sample code.

How to manipulate a Check box in Word with Java and save as PDF?

I need to edit some Check-Boxes in a big Wordfile (docx) and save this then as PDF. This file contains many images and is about 19MB big.
Maybe there will be the need of adding some Checkbox and text.
My idea was to use docx4j, but before to learn the ropes I want to ask if this is possible and which is the best way.
May it be better to save the document as a PDF and then use this as base for processing?
Yes, you can manipulate checkboxes using docx4j.
Be aware that there are several different kinds of checkboxes:
legacy checkbox
content control checkbox
checkbox character
and the details depend on which type are present.
For more, you should post a snippet of the relevant OpenXML (and as they say here on SO, code showing what you've tried).
Is it necessary to use only docx4j?
Recently i tried a solution that helps me manage a Word document with checkboxes and save it as a PDF file. I used Plumsail Documents. The case is about how to populate a Word template using a form with checkboxes. You can connect your app via Zapier or Power Automate to activate checkboxes depending on value from your app. You can set the resulting file as a PDF and deliver it by email and across any system using Zapier and Power Automate.
The great is that Plumsail Documents has a templating engine that allows it to operate pictures.
Your case may be like this:
Create a form in Plumsail Form. It will allow you to activate checkboxes depending on your needs, or your users' needs.
Create a process in Plumsail Documents, upload your Word document and set it as a template. Just put placeholders where you want to change or fill a document with some values or data. Set the resulting document in PDF format.
Set the delivery method. Save across apps or deliver by email.
I recommend you to read the article. That solution is not free, but there is a free 30-day trial, so you will have enough time to try it.

Creating word document from a template using java

I want to create a word document which has a text part, checkboxes and tables in it. I want to create a template of this document and use the template to create a word document using java.
Can anyone please suggest me an easiest way to do the same. I tried doing xml mapping but it only works fine with text and tables. I am more concerned about the checkboxes in the word document.
Please help!
I had a play with a bound checkbox content control.
I found that Word updates the custom xml part when you check/uncheck the checkbox on the document surface, but that the checkbox doesn't automatically update when you change the value in the custom xml part outside word. Nor is it enough to update the checked state (w14:checkbox/w14:checked) outside Word 2010: it seems to be ignored.
In other words, unlike for bound text content controls, the update isn't bi-directional.
So to make this work, you'd need to apply the binding yourself (ie alter the sdtContent to be a checked or unchecked box).
In terms of Java implementations, docx4j 2.7.1 can apply bindings for text content controls, but would need a minor patch to insert the checked or unchecked box.
JDReports and Docmosis might help you. I think both can do what you require given the template requirement and output format.

Jericho-html: is it possible to extract text with reference to positions in source file?

I use Jericho HTML Parser 3.1.
I need to extract text from html, handle it and according to this, I need to insert tags to original html.
But for this I need matching between extracted text and source html.
net.htmlparser.jericho.TextExtractor extracts text pretty good, but I was not able to find how to find the location in original file.
Is it possible to do so with Jericho-html?
You cann't do this with the TextExtractor as is, but I've needed to do similar things in the past and the simplest solution is to copy Jericho's TextExtractor implementation and edit it to add your own custom behaviour. It's a pretty simple class so you'll be able to easily see where to add your own hooks.

Building an XML editor in java and RichFaces

I'm building an XML editor using the above technologies. In essence, I want to read in a whole XML file to a java object, and refer using this object to each element in the XML node tree (grouped into entries) to display the content locked, have separate padlocks for the user to click to 'unlock' an entry allow overwriting of the data, and to submit this entry. 'Add entry', 'Duplicate entry', 'Delete entry' are also functions I'd like to add.
I already use dom4j and XPath to access areas of the XML file so some of the work in theory is already done. Given the above, I was going to use these two together with inplaceInputs to allow the user to edit the XML and JSF validators to check the data coming in.
Is this the best way to approach this problem, or is there a more straightforward route than XPathing a whole record? I started looking at jaxb but I'm new at java and jsf but I've got the feeling I won't be by the end..
Thanks
You can try using SIMPLE FRAMEWORK API in java.It is dedicated for XML in java and will certainly suit your needs.You can access the entire xml BASED ON NODE,TRESS,CHILD.Morever writing and reading an XML is equally easy by using serializer and persister which will store the values in repsective setters and gettters.

Categories

Resources