Login
[x]
Log in using an account from:
Fedora Account System
Red Hat Associate
Red Hat Customer
Or login using a Red Hat Bugzilla account
Forgot Password
Login:
Hide Forgot
Create an Account
Red Hat Bugzilla – Attachment 151047 Details for
Bug 234104
gnu.xml.dom.DomNode.dispatchEvent NullPointerException
[?]
New
Simple Search
Advanced Search
My Links
Browse
Requests
Reports
Current State
Search
Tabular reports
Graphical reports
Duplicates
Other Reports
User Changes
Plotly Reports
Bug Status
Bug Severity
Non-Defaults
|
Product Dashboard
Help
Page Help!
Bug Writing Guidelines
What's new
Browser Support Policy
5.0.4.rh83 Release notes
FAQ
Guides index
User guide
Web Services
Contact
Legal
This site requires JavaScript to be enabled to function correctly, please enable it.
Exemplar code
XMLSetNodeValue.java (text/plain), 7.15 KB, created by
Martin Fong
on 2007-03-27 16:18:29 UTC
(
hide
)
Description:
Exemplar code
Filename:
MIME Type:
Creator:
Martin Fong
Created:
2007-03-27 16:18:29 UTC
Size:
7.15 KB
patch
obsolete
>import java.io.Reader; >import java.io.StringReader; >import java.util.Vector; > >import javax.xml.parsers.DocumentBuilder; >import javax.xml.parsers.DocumentBuilderFactory; > >import org.w3c.dom.Document; >import org.w3c.dom.Element; >import org.w3c.dom.NamedNodeMap; >import org.w3c.dom.Node; >import org.w3c.dom.NodeList; >import org.xml.sax.InputSource; >import org.xml.sax.SAXParseException; > >/** > * This test application returns whether the current JRE's XML > * DOM Node implementation is deficient.<br><br> > * > * @author mwfong > * @version $Revision: 1.1 $ $Date: 2007/03/27 00:12:40 $ > */ > >public class XMLSetNodeValue { > > public static final String version_string = "$Id: XMLSetNodeValue.java,v 1.1 2007/03/27 00:12:40 mwfong Exp $"; > > private static final String _XML_TEST_DOC_STR_ = > "<XMLSetNodeValue>\n" + > " <macrodef>\n" + > " <another />\n" + > " Macro text.\n" + > " </macrodef>\n" + > " Outside text.\n" + > " <macro />\n" + > "</XMLSetNodeValue>\n"; > > /* Expected output: > <XMLSetNodeValue> > > Outside text. > > <another /> > Macro text. > > </XMLSetNodeValue> > */ > > Node macroNode; > > private Document _parse (Reader src) > throws Exception > { > DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance (); > > dbf.setValidating (false); // to improve performance > > try { > DocumentBuilder xmlParser = dbf.newDocumentBuilder (); > InputSource is = new InputSource (src); > > return xmlParser.parse (is); > } > catch (Exception e) { > //*...Report more detailed error information...*/ > if (e.getClass () == SAXParseException.class) { > SAXParseException except = (SAXParseException) e; > String message = e.getMessage (); > > message += "; line: " + except.getLineNumber () + > " column: " + except.getColumnNumber () + > " public ID: " + except.getPublicId () + > " system ID: " + except.getSystemId (); > > e = new Exception (message); > } > > throw e; > } > } > > private int _main (String [] args) > { > //*...Parse the XML file...*/ > > try { > Reader rd = new StringReader (_XML_TEST_DOC_STR_); > Document xmlDoc = _parse (rd); > Element rootNode = xmlDoc.getDocumentElement (); > > return processNode (rootNode, 0); > } > catch (Exception e) { > e.printStackTrace (); > return -1; > } > } > > private int preprocessNode (Node node, int level) > throws Exception > { > //*...Preferentially process macros...*/ > switch (node.getNodeType ()) { > > case Node.TEXT_NODE: > case Node.CDATA_SECTION_NODE: > case Node.COMMENT_NODE: > break; > > default: { > String nodeNameStr = node.getNodeName (); > > if (nodeNameStr.equals ("macro")) > return _processMacro (node); > > break; > } > } > > return 1; // node must be processed > } > > private Node _substNode (Node node, Element callCtxt) > { > Node newNode; > > switch (node.getNodeType ()) { > > case Node.TEXT_NODE: > case Node.CDATA_SECTION_NODE: > newNode = node.cloneNode (false); > newNode.setNodeValue (node.getNodeValue ()); > break; > > case Node.COMMENT_NODE: > newNode = node.cloneNode (false); > break; > > default: { > newNode = callCtxt.getOwnerDocument ().createElement (node.getNodeName ()); > > //*...Process the attributes...*/ > NamedNodeMap nodeMap = node.getAttributes (); > > if (nodeMap != null) { > Element element = (Element) newNode; // for setAttribute () > > for (int i = 0; i < nodeMap.getLength (); i++) { > Node attrNode = nodeMap.item (i); > > element.setAttribute (attrNode.getNodeName (), attrNode.getNodeValue ()); > } > } > > //*...Recursively process the children...*/ > NodeList children = node.getChildNodes (); > > for (int i = 0; i < children.getLength (); i++) > newNode.appendChild (_substNode (children.item (i), callCtxt)); > > break; > } > } > > return newNode; > } > > private int _replaceWithChildren (Node node, Node resultsNode) > { > Node parentNode = node.getParentNode (); > Node nextNode = node.getNextSibling (); > int nChildren = 0; > > NodeList children = resultsNode.getChildNodes (); > > if (children != null) { > while (children.getLength () > 0) { > Node aChild = children.item (0); > > if (nextNode != null) > parentNode.insertBefore (aChild, nextNode); > else > parentNode.appendChild (aChild); > > nChildren++; > } > } > > if (nChildren == 0) > return -1; > else { > parentNode.removeChild (node); > return nChildren; > } > } > > private int _processMacro (Node node) > { > Element element = (Element) node; > Element defNode = (Element) macroNode; > > if (defNode != null) { > Node substNode = defNode.getOwnerDocument ().createDocumentFragment (); > NodeList children = defNode.getChildNodes (); > > for (int i = 0; i < children.getLength (); i++) { > Node child = children.item (i); > > substNode.appendChild (_substNode (child, element)); > } > > _replaceWithChildren (element, substNode); > > return 0; > } > else > return -1; > } > > private int processNode (Node node, int level) > throws Exception > { > int status = preprocessNode (node, level); > > if (status < 1) > return status; > > short nodeType = node.getNodeType (); > boolean fKeepNode = false; > > switch (nodeType) { > > case Node.TEXT_NODE: > case Node.CDATA_SECTION_NODE: > /*...Maintain all strings...*/ > fKeepNode = true; > > String str = node.getNodeValue (); > String valStr = str.replaceAll ("\\\\n", System.getProperty ("line.separator")); > node.setNodeValue (valStr); > > break; > > case Node.COMMENT_NODE: > break; > > default: { > > String nodeNameStr = node.getNodeName (); > > fKeepNode = true; > > if (nodeNameStr.equals ("macrodef")) { > Node parentNode = node.getParentNode (); > > macroNode = parentNode.removeChild (node); > > return 0; > } > > /*...Process children...*/ > _processChildren (node, level); > } > } > > return fKeepNode ? 1 : -1; > } > > private void _processChildren (Node node, int level) > throws Exception > { > /*...Process children...*/ > NodeList children = node.getChildNodes (); > > if (children != null) { > Vector deleteNodes = new Vector (); > int nChildren = children.getLength (); > > for (int i = 0; i < nChildren; /**/) { > Node child = children.item (i); > int nSkip = processNode (child, level + 1); > > if (nSkip < 0) { > deleteNodes.add (child); > nSkip = 1; > } > else > nChildren = children.getLength (); > > i += nSkip; > } > > for (int i = 0; i < deleteNodes.size (); i++) > node.removeChild ((Node) deleteNodes.get (i)); > } > } > > public static void main (String [] args) > { > XMLSetNodeValue anInstance = new XMLSetNodeValue (); > > Runtime.getRuntime().exit (anInstance._main (args)); > } >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 234104
: 151047 |
151048