<commit_before>package com.indexdata.pz2utils4jsf.pazpar2.data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.indexdata.pz2utils4jsf.pazpar2.data.Pazpar2ResponseData;

public class Pazpar2ResponseData implements Serializable {
  
  private static final long serialVersionUID = -3909755656714679959L;
  String type = null;
  HashMap<String,String> attributes = new HashMap<String,String>();
  HashMap<String,List<Pazpar2ResponseData>> elements = new HashMap<String,List<Pazpar2ResponseData>>();
  String textContent = "";
  CommandError error = null;
  String xml = null;
        
  public void setType (String type) {
    this.type = type;
  }
  
  public String getType () {
    return type;
  }
  
  public void setAttribute (String name, String value) {
    attributes.put(name, value);
  }
  
  public String getAttribute (String name) {
    return attributes.get(name);
  }
    
  public void addElement (String name, Pazpar2ResponseData value) {    
    if (elements.containsKey(name)) {
      elements.get(name).add(value);
    } else {
      List<Pazpar2ResponseData> list = new ArrayList<Pazpar2ResponseData>();
      list.add(value);
      elements.put(name,list);
    }
  }
  
  public List<Pazpar2ResponseData> getElements (String name) {
    return elements.get(name);
  }
  
  public Pazpar2ResponseData getOneElement (String name) {
    if (elements.get(name) != null) {
      return elements.get(name).get(0);
    } else {
      return null;
    }
  }
  
  /**
   * Returns the text content of the first element found with the given
   * name
   * @param name of the element 
   * @return text value, empty string if none found
   */
  public String getOneElementValue (String name) {
    if (getOneElement(name)!=null && getOneElement(name).getValue().length()>0) {
      return getOneElement(name).getValue();
    } else {
      return "";
    }
  }
  
  public void appendContent (String content) {
    textContent = textContent + content;
  }
  
  public String getValue () {
    return textContent;
  }
  
  public String getProperty(String name) {
    List<Pazpar2ResponseData> els = elements.get(name);
    if (els != null) {
      return els.get(0).getValue();
    } else {     
      return null;
    }
  }
  
  public int getIntValue(String name) {
    String val = getOneElementValue(name);
    if (val.length()==0) {
      return 0;
    } else {
      return Integer.parseInt(val);
    }
  }
    
  public boolean hasApplicationError () {
    return (getOneElement("applicationerror") != null);   
  }
  
  public CommandError getApplicationError() {
    return (CommandError) getOneElement("applicationerror");
  }
  
  public boolean hasPazpar2Error() {
    return hasApplicationError() && getApplicationError().hasPazpar2Error();
  }
  
  public void setXml(String xml) {
    this.xml = xml; 
  }
  
  public String getXml() {
    return xml;<commit_msg>Adds option to return Pazpar2/SP response XML<commit_after>package com.indexdata.pz2utils4jsf.pazpar2.data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.apache.log4j.Logger;

import com.indexdata.pz2utils4jsf.pazpar2.data.Pazpar2ResponseData;

public class Pazpar2ResponseData implements Serializable {

  Logger logger = Logger.getLogger(Pazpar2ResponseData.class);
  private static final long serialVersionUID = -3909755656714679959L;
  String type = null;
  HashMap<String,String> attributes = new HashMap<String,String>();
  HashMap<String,List<Pazpar2ResponseData>> elements = new HashMap<String,List<Pazpar2ResponseData>>();
  String textContent = "";
  CommandError error = null;
  String xml = null;
        
  public void setType (String type) {
    this.type = type;
  }
  
  public String getType () {
    return type;
  }
  
  public void setAttribute (String name, String value) {
    attributes.put(name, value);
  }
  
  public String getAttribute (String name) {
    return attributes.get(name);
  }
    
  public void addElement (String name, Pazpar2ResponseData value) {    
    if (elements.containsKey(name)) {
      elements.get(name).add(value);
    } else {
      List<Pazpar2ResponseData> list = new ArrayList<Pazpar2ResponseData>();
      list.add(value);
      elements.put(name,list);
    }
  }
  
  public List<Pazpar2ResponseData> getElements (String name) {
    return elements.get(name);
  }
  
  public Pazpar2ResponseData getOneElement (String name) {
    if (elements.get(name) != null) {
      return elements.get(name).get(0);
    } else {
      return null;
    }
  }
  
  /**
   * Returns the text content of the first element found with the given
   * name
   * @param name of the element 
   * @return text value, empty string if none found
   */
  public String getOneElementValue (String name) {
    if (getOneElement(name)!=null && getOneElement(name).getValue().length()>0) {
      return getOneElement(name).getValue();
    } else {
      return "";
    }
  }
  
  public void appendContent (String content) {
    textContent = textContent + content;
  }
  
  public String getValue () {
    return textContent;
  }
  
  public String getProperty(String name) {
    List<Pazpar2ResponseData> els = elements.get(name);
    if (els != null) {
      return els.get(0).getValue();
    } else {     
      return null;
    }
  }
  
  public int getIntValue(String name) {
    String val = getOneElementValue(name);
    if (val.length()==0) {
      return 0;
    } else {
      return Integer.parseInt(val);
    }
  }
    
  public boolean hasApplicationError () {
    return (getOneElement("applicationerror") != null);   
  }
  
  public CommandError getApplicationError() {
    return (CommandError) getOneElement("applicationerror");
  }
  
  public boolean hasPazpar2Error() {
    return hasApplicationError() && getApplicationError().hasPazpar2Error();
  }
  
  public void setXml(String xml) {
    this.xml = xml; 
  }
  
  public String getXml() {
    if (type != null && type.equals("record")) {
      logger.debug("Getting XML for "+type + ": "+xml);
    }      
    return xml == null ? "" : xml;
{'fraction_non_alphanumeric': 0.11136290061508579, 'fraction_numerical': 0.014082227258012302, 'mean_word_length': 3.183480027081923, 'pattern_counts': {'":': 1, '<': 23, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 12}, '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': '3405972', 'n_tokens_mistral': 1958, 'n_tokens_neox': 1940, 'n_words': 453}