<commit_before>/**
 * JLibs: Common Utilities for Java
 * Copyright (C) 2009  <NAME>
 * <p/>
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * <p/>
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 */

package jlibs.xml.sax.sniff;

import jlibs.xml.Namespaces;
import jlibs.xml.dom.DOMNavigator;
import jlibs.xml.sax.sniff.events.Event;
import org.w3c.dom.Attr;
import org.w3c.dom.Node;

import javax.xml.namespace.NamespaceContext;

/**
 * @author <NAME>
 */
public class NodeItem implements NodeTypes, Comparable<NodeItem>{
    private final long order;
    public final int type;
    public final String location;
    public final String value;
    public final String localName;
    public final String namespaceURI;
    public final String name;

    public NodeItem(Event event){
        order = event.order();
        type = event.type();
        location = event.location();
        value = event.getValue();

        localName = event.localName();
        namespaceURI = event.namespaceURI();
        name = event.qualifiedName();
    }

    // used only for testing purposes
    public NodeItem(Node node, NamespaceContext nsContext){
        order = -1;
        if(node instanceof Attr && Namespaces.URI_XMLNS.equals(node.getNamespaceURI()))
            type = NAMESPACE;
        else
            type = node.getNodeType();
        location = new DOMNavigator().getXPath(node, nsContext);
        value = node.getNodeValue();

        localName = node.getLocalName();
        namespaceURI = node.getNamespaceURI();
        name = node.getNodeName();<commit_msg>added special constructor so that testing can be done with saxon<commit_after>/**
 * JLibs: Common Utilities for Java
 * Copyright (C) 2009  <NAME>
 * <p/>
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * <p/>
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 */

package jlibs.xml.sax.sniff;

import jlibs.xml.Namespaces;
import jlibs.xml.dom.DOMNavigator;
import jlibs.xml.sax.sniff.events.Event;
import org.jaxen.dom.NamespaceNode;
import org.w3c.dom.Attr;
import org.w3c.dom.Node;

import javax.xml.namespace.NamespaceContext;

/**
 * @author <NAME>
 */
public class NodeItem implements NodeTypes, Comparable<NodeItem>{
    private final long order;
    public final int type;
    public final String location;
    public final String value;
    public final String localName;
    public final String namespaceURI;
    public final String name;

    public NodeItem(Event event){
        order = event.order();
        type = event.type();
        location = event.location();
        value = event.getValue();

        localName = event.localName();
        namespaceURI = event.namespaceURI();
        name = event.qualifiedName();
    }

    // used only for testing purposes
    public NodeItem(Node node, NamespaceContext nsContext){
        order = -1;
        if(node instanceof Attr && Namespaces.URI_XMLNS.equals(node.getNamespaceURI()))
            type = NAMESPACE;
        else if(node.getNodeType()==NamespaceNode.NAMESPACE_NODE)
            type = NAMESPACE;
        else
            type = node.getNodeType();
        location = new DOMNavigator().getXPath(node, nsContext);
        value = node.getNodeValue();

        localName = node.getLocalName();
        namespaceURI = node.getNamespaceURI();
        name = node.getNodeName();
    }

    // used only for testing purposes
    public NodeItem(Node node, String prefix, String uri, NamespaceContext nsContext){
        order = -1;
        type = NAMESPACE;

        location = new DOMNavigator().getXPath(node, nsContext)+"/namespace::"+prefix;
        value = uri;

        localName = prefix;
        namespaceURI = Namespaces.URI_XMLNS;
        name = "xmlns:"+prefix;
{'fraction_non_alphanumeric': 0.09394205443371378, 'fraction_numerical': 0.004170324846356453, 'mean_word_length': 2.9938650306748467, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 11}, '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': '3094479', 'n_tokens_mistral': 1252, 'n_tokens_neox': 1230, 'n_words': 431}