<commit_before>/******************************************************************
*
*	CyberXML for Java
*
*	Copyright (C) <NAME> 2004
*
*   Author: <NAME> (http://thoean.com)
*
*	File: JaxpParser.java
*
*	Revision;
*
*	06/15/04
*		- first revision.
*
******************************************************************/

package org.cybergarage.xml.parser;

import java.io.InputStream;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.cybergarage.xml.Node;
import org.cybergarage.xml.Parser;
import org.cybergarage.xml.ParserException;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.xml.sax.InputSource;


public class JaxpParser extends Parser
{

	public JaxpParser()
	{
		super();
	}
	
	////////////////////////////////////////////////
	//	parse (Node)
	////////////////////////////////////////////////

	public org.cybergarage.xml.Node parse(org.cybergarage.xml.Node parentNode, org.w3c.dom.Node domNode, int rank)
	{
		int domNodeType = domNode.getNodeType();
//		if (domNodeType != Node.ELEMENT_NODE)
//			return;
			
		String domNodeName = domNode.getNodeName();
		String domNodeValue = domNode.getNodeValue();
		NamedNodeMap attrs = domNode.getAttributes(); 
		int arrrsLen = (attrs != null) ? attrs.getLength() : 0;

//		Debug.message("[" + rank + "] ELEM : " + domNodeName + ", " + domNodeValue + ", type = " + domNodeType + ", attrs = " + arrrsLen);

		if (domNodeType == org.w3c.dom.Node.TEXT_NODE) {
			parentNode.setValue(domNodeValue);
			return parentNode;
		}

		if (domNodeType != org.w3c.dom.Node.ELEMENT_NODE)
			return parentNode;

		org.cybergarage.xml.Node node = new org.cybergarage.xml.Node();
		node.setName(domNodeName);
		node.setValue(domNodeValue);

		if (parentNode != null)
			parentNode.addNode(node);

		NamedNodeMap attrMap = domNode.getAttributes(); 
		int attrLen = attrMap.getLength();
		//Debug.message("attrLen = " + attrLen);
		for (int n = 0; n<attrLen; n++) {
			org.w3c.dom.Node attr = attrMap.item(n);
			String attrName = attr.getNodeName();
			String attrValue = attr.getNodeValue();
			node.setAttribute(attrName, attrValue);
		}
		
		org.w3c.dom.Node child = domNode.getFirstChild();
		if(child==null){ 
			node.setValue(""); 
			return node; 
		}
		do{
			parse(node, child, rank+1);<commit_msg>* Fixed JaxpParser::parse() not to occur null exception when the NamedNodeMap is null on Android.<commit_after>/******************************************************************
*
*	CyberXML for Java
*
*	Copyright (C) <NAME> 2004
*
*   Author: <NAME> (http://thoean.com)
*
*	File: JaxpParser.java
*
*	Revision;
*
*	06/15/04
*		- first revision.
*	01/08/08
*		- Fixed parse() not to occur null exception when the NamedNodeMap is null on Android.
*
******************************************************************/

package org.cybergarage.xml.parser;

import java.io.InputStream;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.cybergarage.xml.Node;
import org.cybergarage.xml.Parser;
import org.cybergarage.xml.ParserException;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.xml.sax.InputSource;


public class JaxpParser extends Parser
{

	public JaxpParser()
	{
		super();
	}
	
	////////////////////////////////////////////////
	//	parse (Node)
	////////////////////////////////////////////////

	public org.cybergarage.xml.Node parse(org.cybergarage.xml.Node parentNode, org.w3c.dom.Node domNode, int rank)
	{
		int domNodeType = domNode.getNodeType();
//		if (domNodeType != Node.ELEMENT_NODE)
//			return;
			
		String domNodeName = domNode.getNodeName();
		String domNodeValue = domNode.getNodeValue();
		NamedNodeMap attrs = domNode.getAttributes(); 
		int arrrsLen = (attrs != null) ? attrs.getLength() : 0;

//		Debug.message("[" + rank + "] ELEM : " + domNodeName + ", " + domNodeValue + ", type = " + domNodeType + ", attrs = " + arrrsLen);

		if (domNodeType == org.w3c.dom.Node.TEXT_NODE) {
			parentNode.setValue(domNodeValue);
			return parentNode;
		}

		if (domNodeType != org.w3c.dom.Node.ELEMENT_NODE)
			return parentNode;

		org.cybergarage.xml.Node node = new org.cybergarage.xml.Node();
		node.setName(domNodeName);
		node.setValue(domNodeValue);

		if (parentNode != null)
			parentNode.addNode(node);

		NamedNodeMap attrMap = domNode.getAttributes(); 
		if (attrMap != null) {
			int attrLen = attrMap.getLength();
			//Debug.message("attrLen = " + attrLen);
			for (int n = 0; n<attrLen; n++) {
				org.w3c.dom.Node attr = attrMap.item(n);
				String attrName = attr.getNodeName();
				String attrValue = attr.getNodeValue();
				node.setAttribute(attrName, attrValue);
			}
		}
		
		org.w3c.dom.Node child = domNode.getFirstChild();
		if(child==null){ 
			node.setValue(""); 
			return node; 
		}
		do{
			parse(node, child, rank+1);
{'fraction_non_alphanumeric': 0.22459453910901253, 'fraction_numerical': 0.009443646068569083, 'mean_word_length': 3.361683079677708, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 22}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4221778', 'n_tokens_mistral': 1792, 'n_tokens_neox': 1648, 'n_words': 317}