 |
As the new Java.net infrastructure contains project-level wikis, this main wiki will be shut down in the near future. For wiki page export and general wiki questions please contact the site admin at communitymanager@java.net. Home | Changes | Index | Search | Go
This is a placeholder for frequently-asked-questions before they are merged into our main FAQ web page.
How do I render custom components in Flying Saucer?
Posted as a question to our mailing list, https://xhtmlrenderer.dev.java.net/servlets/ReadMsg?list=dev&msgNo=2728
From the email:
If you just need a custom tag, styled by css, nothing needs to be done, Flying Saucer can render any XML document styled by CSS.
If you need to add custom components, or some other special handling, extend one of the NamespaceHandler classes (e.g. org.xhtmlrenderer.simple.extend.XhtmlNamespaceHandler).
Do I need to register my custom element somewhere? No, getCustomComponent() is only called for block formatted content. Try adding
mycustomelement {
display: block;
}
or use display: inline-block if you don't want a line break--if you want your component to act like an image tag in XHTML.
How can I get the text between the tags? I want this text he DOM element in question is passed to getCustomComponent().
Any text content in the Element will be contained there. At that
point, it's regular old W3C DOM programming. Something like this
should work (not tested, might not even compile, but hopefully the
idea is clear):
StringBuffer text = new StringBuffer();
NodeList children = e.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
Node n = (Node)children.item(i);
if (n.getNodeType() == Node.TEXT_NODE) {
text.append(((Text)n).getData());
}
}
|