<commit_before>/*
 * Autopsy Forensic Browser
 *
 * Copyright 2011 - 2013 Basis Technology Corp.
 * Contact: carrier <at> sleuthkit <dot> org
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.sleuthkit.autopsy.fileextmismatch;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.logging.Level;
import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.autopsy.coreutils.PlatformUtil;
import org.sleuthkit.autopsy.coreutils.XMLUtil;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

/**
 * Storage of file extension mismatch configuration, which maps mimetypes to
 * allowable filename extensions.
 */
public class FileExtMismatchXML {
    private static final Logger logger = Logger.getLogger(FileExtMismatchXML.class.getName());    
    private static final String ENCODING = "UTF-8";
    private static final String XSDFILE = "MismatchConfigSchema.xsd";
    
    private static final String ROOT_EL = "mismatch_config";
    private static final String SIG_EL = "signature";
    private static final String EXT_EL = "ext";    
    private static final String SIG_MIMETYPE_ATTR = "mimetype";
    
    private static final String CUR_CONFIG_FILE_NAME = "mismatch_config.xml";
    private static String CUR_CONFIG_FILE = PlatformUtil.getUserConfigDirectory() + File.separator + CUR_CONFIG_FILE_NAME;    
    
    protected String filePath;
    
    FileExtMismatchXML(String filePath) {
        this.filePath = filePath;
    }

    /**
     * Load and parse XML
     * 
     * @return Loaded hash map or null on error or null if data does not exist
     */
    public HashMap<String, String[]> load() {<commit_msg>Call extractResourceToUserConfigDir() on the file ext mismatch XML file.<commit_after>/*
 * Autopsy Forensic Browser
 *
 * Copyright 2011 - 2013 Basis Technology Corp.
 * Contact: carrier <at> sleuthkit <dot> org
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.sleuthkit.autopsy.fileextmismatch;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.logging.Level;
import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.autopsy.coreutils.PlatformUtil;
import org.sleuthkit.autopsy.coreutils.XMLUtil;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

/**
 * Storage of file extension mismatch configuration, which maps mimetypes to
 * allowable filename extensions.
 */
public class FileExtMismatchXML {
    private static final Logger logger = Logger.getLogger(FileExtMismatchXML.class.getName());    
    private static final String ENCODING = "UTF-8";
    private static final String XSDFILE = "MismatchConfigSchema.xsd";
    
    private static final String ROOT_EL = "mismatch_config";
    private static final String SIG_EL = "signature";
    private static final String EXT_EL = "ext";    
    private static final String SIG_MIMETYPE_ATTR = "mimetype";
    
    private static final String CUR_CONFIG_FILE_NAME = "mismatch_config.xml";
    
    protected String filePath;
    
    FileExtMismatchXML(String filePath) {
        this.filePath = filePath;
        
        try {
            boolean extracted = PlatformUtil.extractResourceToUserConfigDir(FileExtMismatchXML.class, CUR_CONFIG_FILE_NAME);
        } catch (IOException ex) {
            logger.log(Level.SEVERE, "Error copying default mismatch configuration to user dir ", ex);
        }        
    }

    /**
     * Load and parse XML
     * 
     * @return Loaded hash map or null on error or null if data does not exist
     */
    public HashMap<String, String[]> load() {
{'fraction_non_alphanumeric': 0.08124076809453472, 'fraction_numerical': 0.006752479426039249, 'mean_word_length': 3.624390243902439, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, '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': '6650923', 'n_tokens_mistral': 1384, 'n_tokens_neox': 1334, 'n_words': 457}