The problem came when we needed to store/retrive this data in the XML file. The HTMLDocument (from the Java Swing) and JiBX don't play together very well.
The HTML code is stored in the application in a javax.swing.text.html.HTMLDocument class. I created a HTMLListMapper.java class to map the HTML to XML to (un)Marshal the code. Here is the Marshaller.
public void marshal(Object obj, IMarshallingContext ictx)
throws JiBXException {
if (!(obj instanceof HTMLDocument))
throw new JiBXException ("Marshalling object not of expected type"); if (!(ictx instanceof MarshallingContext))
throw new JiBXException ("Marshalling context not of expected type");StringWriter w = new StringWriter ();
HTMLWriter hw = new HTMLWriter (w, (HTMLDocument)obj);
try {
hw.write();
} catch (IOException ex) { throw new JiBXException ("Failure writing to StringWriter:", ex); }
catch (BadLocationException ex) { throw new JiBXException ("Failure writing to HTMLWriter:", ex); }
MarshallingContext ctx = (MarshallingContext)ictx;
ctx.startTag(m_index, m_name);
IXMLWriter xw = ctx.getXmlWriter();
try {
xw.writeMarkup(w.toString());
} catch (IOException ex) { throw new JiBXException ("Failure writing to Context markup:", ex); }
ctx.endTag(m_index, m_name);
}
The problem with this code is that the IXMLWriter.writeMarkup() is not a public method. I changed the JiBX code and recompiled it to allow it to work.
The Unmarshaller is a little more complex, but follows the example of the org.jibx.extras.DomListMapper class, except compressed into one class, not several. Because the HTMLDocument contains its own HTML parser, I wanted JiBX to do as little work as possible.
And the mapping int the mapping.xml file:
<mapping class="javax.swing.text.html.HTMLDocument" name="comment"
marshaller="com.softstart.stellar.data.HTMLListMapper"
unmarshaller="com.softstart.stellar.data.HTMLListMapper">
</mapping> <mapping name="system" class="com.softstart.stellar.data.StarSystem">
<!-- Other data here -->
<structure field="comment" usage="optional"/>
</mapping>If you would like the complete class, please let me know and I'll send it along.
Or if you have a better suggestion...
--
Thomas Jones-Low Softstart Services Inc.
[EMAIL PROTECTED] JobScheduler for Oracle
Ph: 802-398-1012 http://www.softstart.com------------------------------------------------------- This SF.net email is sponsored by: IT Product Guide on ITManagersJournal Use IT products in your business? Tell us what you think of them. Give us Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more http://productguide.itmanagersjournal.com/guidepromo.tmpl _______________________________________________ jibx-users mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jibx-users
