<commit_before>package org.intermine.web.logic.query;

/*
 * Copyright (C) 2002-2007 FlyMine
 *
 * This code may be freely distributed and modified under the
 * terms of the GNU Lesser General Public Licence.  This should
 * be distributed with the code.  See the LICENSE file for more
 * information or http://www.gnu.org/copyleft/lesser.html.
 *
 */

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.intermine.objectstore.query.BagConstraint;
import org.intermine.objectstore.query.ConstraintOp;

import org.intermine.metadata.Model;
import org.intermine.util.StringUtil;
import org.intermine.util.TypeUtil;
import org.intermine.web.logic.ClassKeyHelper;
import org.intermine.web.logic.Constants;

import javax.servlet.ServletContext;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

/**
 * Extension of DefaultHandler to handle parsing PathQuery objects
 * @author <NAME>
 * @author <NAME>
 * @author <NAME>
 */
public class PathQueryHandler extends DefaultHandler
{
    private Map<String, PathQuery> queries;
    private String queryName;
    private char gencode;
    private PathNode node;
    protected PathQuery query;
    private Model model = null;
    private Map savedBags;
    private List<String> viewStrings = new ArrayList<String>();
    private String sortOrderString = "";
    private String directionString = ""; // will be asc or desc
    private Map<String, String> pathStringDescriptions = new HashMap<String, String>();
    private final ServletContext servletContext;
    
    /**
     * Constructor
     * @param queries Map from query name to PathQuery
     * @param savedBags Map from bag name to bag
     * @param servletContext global ServletContext object
     */

    public PathQueryHandler(Map<String, PathQuery> queries, Map savedBags,
                            ServletContext servletContext) {
        this.queries = queries;
        this.savedBags = savedBags;
        this.servletContext = servletContext;
    }

    /**
     * {@inheritDoc}
     */
    public void startElement(String uri, String localName, String qName, Attributes attrs)
    throws SAXException {
        if (qName.equals("query")) {
            // reset things
            gencode = 'A';
            queryName = validateName(attrs.getValue("name"));
            try {
                model = Model.getInstanceByName(attrs.getValue("model"));
            } catch (Exception e) {
                throw new SAXException(e);
            }
            query = new PathQuery(model);
            if (attrs.getValue("view") != null) {
                viewStrings = StringUtil.tokenize(attrs.getValue("view"));
                
            }
            if (attrs.getValue("sortOrder") != null) {
               String[] s = (attrs.getValue("sortOrder")).split(" ");
               sortOrderString = s[0];
               directionString = s[1];
            }
            if (attrs.getValue("constraintLogic") != null) {
                query.setConstraintLogic(attrs.getValue("constraintLogic"));
            }
        }
        if (qName.equals("node")) {
            node = query.addNode(attrs.getValue("path"));
            if (attrs.getValue("type") != null) {
                node.setType(attrs.getValue("type"));<commit_msg>Fix reading direction strings.<commit_after>package org.intermine.web.logic.query;

/*
 * Copyright (C) 2002-2007 FlyMine
 *
 * This code may be freely distributed and modified under the
 * terms of the GNU Lesser General Public Licence.  This should
 * be distributed with the code.  See the LICENSE file for more
 * information or http://www.gnu.org/copyleft/lesser.html.
 *
 */

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.intermine.objectstore.query.BagConstraint;
import org.intermine.objectstore.query.ConstraintOp;

import org.intermine.metadata.Model;
import org.intermine.util.StringUtil;
import org.intermine.util.TypeUtil;
import org.intermine.web.logic.ClassKeyHelper;
import org.intermine.web.logic.Constants;

import javax.servlet.ServletContext;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

/**
 * Extension of DefaultHandler to handle parsing PathQuery objects
 * @author <NAME>
 * @author <NAME>
 * @author <NAME>
 */
public class PathQueryHandler extends DefaultHandler
{
    private Map<String, PathQuery> queries;
    private String queryName;
    private char gencode;
    private PathNode node;
    protected PathQuery query;
    private Model model = null;
    private Map savedBags;
    private List<String> viewStrings = new ArrayList<String>();
    private String sortOrderString = "";
    private String directionString = ""; // will be asc or desc
    private Map<String, String> pathStringDescriptions = new HashMap<String, String>();
    private final ServletContext servletContext;
    
    /**
     * Constructor
     * @param queries Map from query name to PathQuery
     * @param savedBags Map from bag name to bag
     * @param servletContext global ServletContext object
     */

    public PathQueryHandler(Map<String, PathQuery> queries, Map savedBags,
                            ServletContext servletContext) {
        this.queries = queries;
        this.savedBags = savedBags;
        this.servletContext = servletContext;
    }

    /**
     * {@inheritDoc}
     */
    public void startElement(String uri, String localName, String qName, Attributes attrs)
    throws SAXException {
        if (qName.equals("query")) {
            // reset things
            gencode = 'A';
            queryName = validateName(attrs.getValue("name"));
            try {
                model = Model.getInstanceByName(attrs.getValue("model"));
            } catch (Exception e) {
                throw new SAXException(e);
            }
            query = new PathQuery(model);
            if (attrs.getValue("view") != null) {
                viewStrings = StringUtil.tokenize(attrs.getValue("view"));
                
            }
            if (attrs.getValue("sortOrder") != null) {
               String[] s = (attrs.getValue("sortOrder")).split(" ");
               sortOrderString = s[0];
               if ((s.length > 1) && (s[1].equalsIgnoreCase("desc"))) { 
                   directionString = "desc";
               } else {
                   directionString = "asc";
               }
            }
            if (attrs.getValue("constraintLogic") != null) {
                query.setConstraintLogic(attrs.getValue("constraintLogic"));
            }
        }
        if (qName.equals("node")) {
            node = query.addNode(attrs.getValue("path"));
            if (attrs.getValue("type") != null) {
                node.setType(attrs.getValue("type"));
{'fraction_non_alphanumeric': 0.10744634884055884, 'fraction_numerical': 0.0030246291228575545, 'mean_word_length': 2.5464759959141983, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 6}, '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': '5630861', 'n_tokens_mistral': 1883, 'n_tokens_neox': 1846, 'n_words': 483}