<commit_before>package org.perfcake.pc4idea.editor;

import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.fileEditor.*;
import com.intellij.openapi.fileTypes.StdFileTypes;
import com.intellij.openapi.module.ModuleUtil;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.testFramework.LightVirtualFile;
import org.jdom.Element;
import org.jetbrains.annotations.NotNull;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;


/**
 * Created with IntelliJ IDEA.
 * User: <NAME>
 * Date: 17.9.2014
 */
public class PerfCakeEditorProvider implements FileEditorProvider, DumbAware {
    private static final Logger LOG = Logger.getInstance("#org.perfcake.pc4idea.editor.PerfCakeEditorProvider");
    private final String EDITOR_TYPE_ID = "PerfCakeDesigner";

    public static PerfCakeEditorProvider getInstance() {
        return ApplicationManager.getApplication().getComponent(PerfCakeEditorProvider.class);
    }

    // accepting perfcake-scenario-3.0
    @Override
    public boolean accept(@NotNull Project project, @NotNull VirtualFile virtualFile) {
        boolean acceptCondition = false;

        if (virtualFile.getFileType() == StdFileTypes.XML && !StdFileTypes.XML.isBinary() &&
           (ModuleUtil.findModuleForFile(virtualFile, project) != null || virtualFile instanceof LightVirtualFile)){
            try {
                DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
                DocumentBuilder builder = factory.newDocumentBuilder();
                Document temp = builder.parse(virtualFile.getPath());

                if (temp.getDocumentElement().getAttribute("xmlns").equals("urn:perfcake:scenario:3.0")) {
                    acceptCondition = true;
                }
            } catch (ParserConfigurationException e) {
                e.printStackTrace();
            } catch (SAXException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        return acceptCondition;
    }

    @NotNull
    @Override
    public FileEditor createEditor(@NotNull Project project, @NotNull VirtualFile virtualFile) {
        LOG.assertTrue(accept(project, virtualFile));
        return new PerfCakeEditor(project, virtualFile);
    }

    @Override
    public void disposeEditor(@NotNull FileEditor fileEditor) {
        Disposer.dispose(fileEditor);<commit_msg>finalized for version 3<commit_after>package org.perfcake.pc4idea.editor;

import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.fileEditor.*;
import com.intellij.openapi.fileTypes.StdFileTypes;
import com.intellij.openapi.module.ModuleUtil;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.testFramework.LightVirtualFile;
import org.jdom.Element;
import org.jetbrains.annotations.NotNull;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;


/**
 * Created with IntelliJ IDEA.
 * User: <NAME>
 * Date: 17.9.2014
 */
public class PerfCakeEditorProvider implements FileEditorProvider, DumbAware {
    private static final Logger LOG = Logger.getInstance("#org.perfcake.pc4idea.editor.PerfCakeEditorProvider");
    private final String EDITOR_TYPE_ID = "PerfCakeDesigner";

    public static PerfCakeEditorProvider getInstance() {
        return ApplicationManager.getApplication().getComponent(PerfCakeEditorProvider.class);
    }

    // accepting perfcake-scenario-3.0 xml
    @Override
    public boolean accept(@NotNull Project project, @NotNull VirtualFile virtualFile) {
        String xmlnsAttr = "";

        if (virtualFile.getFileType() == StdFileTypes.XML && !StdFileTypes.XML.isBinary() &&
           (ModuleUtil.findModuleForFile(virtualFile, project) != null || virtualFile instanceof LightVirtualFile)){
            try {
                DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
                DocumentBuilder builder = factory.newDocumentBuilder();
                Document temp = builder.parse(virtualFile.getPath());

                xmlnsAttr = temp.getDocumentElement().getAttribute("xmlns");
            } catch (ParserConfigurationException ignored) {}
            catch (SAXException ignored) {}
            catch (IOException ignored) {}
        }

        return xmlnsAttr.equals("urn:perfcake:scenario:3.0");
    }

    @NotNull
    @Override
    public FileEditor createEditor(@NotNull Project project, @NotNull VirtualFile virtualFile) {
        LOG.assertTrue(accept(project, virtualFile));
        return new PerfCakeEditor(project, virtualFile);
    }

    @Override
    public void disposeEditor(@NotNull FileEditor fileEditor) {
        Disposer.dispose(fileEditor);
{'fraction_non_alphanumeric': 0.09743589743589744, 'fraction_numerical': 0.005311355311355312, 'mean_word_length': 3.691580756013746, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 14}, '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': '5397037', 'n_tokens_mistral': 1525, 'n_tokens_neox': 1478, 'n_words': 285}