<commit_before>package jp.ac.kyushu.iarch.checkplugin.handler;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import jp.ac.kyushu.iarch.basefunction.reader.ProjectReader;
import jp.ac.kyushu.iarch.checkplugin.view.SelectAllFileDialog;

import org.dom4j.DocumentHelper;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;
import org.dom4j.Document;
import org.dom4j.Element;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.IHandler;
import org.eclipse.core.commands.IHandlerListener;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.ui.handlers.HandlerUtil;

public class ConfigurationXMLHandler implements IHandler{

	public void CreateConfigFile(IProject project, SelectAllFileDialog AllDialog){
		Document codeXmlDocument = DocumentHelper.createDocument();
		Element rootElement = codeXmlDocument.addElement("Project");
		rootElement.addAttribute("name", project.getName());

		final Element ArchCodeElement = rootElement.addElement("Archfile");
		{
			final Element PathElement = ArchCodeElement.addElement("Path");
			PathElement.addAttribute("Attribute", AllDialog.getArchiface().getFullPath().toOSString());
		}


		final Element ClassDiagramElement = rootElement.addElement("ClassDiagram");
		if(AllDialog.getClassDiagram() != null)
		{
			final Element PathElement = ClassDiagramElement.addElement("Path");
			PathElement.addAttribute("Attribute", AllDialog.getClassDiagram().getFullPath().toOSString());
		}

		final Element SequenceDiagramElement = rootElement.addElement("SequenceDiagram");
		if(AllDialog.getSequenceDiagrams() != null)
		{
			for(IResource resource:AllDialog.getSequenceDiagrams()){
				final Element PathElement = SequenceDiagramElement.addElement("Path");
				PathElement.addAttribute("Attribute", resource.getFullPath().toOSString());
			}
		}

		final Element SourceCodeElement = rootElement.addElement("SourceCode");
		{

			for(IResource resource:AllDialog.getSourceCode()){
				final Element PathElement = SourceCodeElement.addElement("Path");
				PathElement.addAttribute("Attribute", resource.getFullPath().toOSString());
			}
		}


		final Element XMLElement = rootElement.addElement("ARXML");
		{
			final Element PathElement = XMLElement.addElement("Path");
			try{
			PathElement.addAttribute("Attribute", AllDialog.getXml().getFullPath().toOSString());
			}catch(Exception e){
				System.out.println(e.getMessage());
			}
		}


		try {
			OutputFormat format = OutputFormat.createPrettyPrint();
			String projectPath = project.getProject().getLocation().toOSString();
			System.out.println(projectPath);
			XMLWriter output = new XMLWriter(new FileWriter(new File(projectPath + File.separator + "Config.xml")), format);
			codeXmlDocument.setXMLEncoding("utf-8");
			output.write(codeXmlDocument);
			output.close();
		} catch (IOException e) {
			System.out.println(e.getMessage());
		}
	}



	public boolean isConfigFileExist(IProject project){
		String ConfigFile=project.getProject().getLocation().toOSString()+ File.separator +"Config.xml";
		File myFilePath = new File(ConfigFile);

		if (myFilePath.exists()) {
			return true;
		}<commit_msg>Bugfix: Avoided the problem that Config.xml created on Windows is invalid for Mac.<commit_after>package jp.ac.kyushu.iarch.checkplugin.handler;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import jp.ac.kyushu.iarch.basefunction.reader.ProjectReader;
import jp.ac.kyushu.iarch.checkplugin.view.SelectAllFileDialog;

import org.dom4j.DocumentHelper;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;
import org.dom4j.Document;
import org.dom4j.Element;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.IHandler;
import org.eclipse.core.commands.IHandlerListener;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.ui.handlers.HandlerUtil;

public class ConfigurationXMLHandler implements IHandler{

	public void CreateConfigFile(IProject project, SelectAllFileDialog AllDialog){
		Document codeXmlDocument = DocumentHelper.createDocument();
		Element rootElement = codeXmlDocument.addElement("Project");
		rootElement.addAttribute("name", project.getName());

		final Element ArchCodeElement = rootElement.addElement("Archfile");
		{
			final Element PathElement = ArchCodeElement.addElement("Path");
			PathElement.addAttribute("Attribute", AllDialog.getArchiface().getFullPath().toString());
		}


		final Element ClassDiagramElement = rootElement.addElement("ClassDiagram");
		if(AllDialog.getClassDiagram() != null)
		{
			final Element PathElement = ClassDiagramElement.addElement("Path");
			PathElement.addAttribute("Attribute", AllDialog.getClassDiagram().getFullPath().toString());
		}

		final Element SequenceDiagramElement = rootElement.addElement("SequenceDiagram");
		if(AllDialog.getSequenceDiagrams() != null)
		{
			for(IResource resource:AllDialog.getSequenceDiagrams()){
				final Element PathElement = SequenceDiagramElement.addElement("Path");
				PathElement.addAttribute("Attribute", resource.getFullPath().toString());
			}
		}

		final Element SourceCodeElement = rootElement.addElement("SourceCode");
		{

			for(IResource resource:AllDialog.getSourceCode()){
				final Element PathElement = SourceCodeElement.addElement("Path");
				PathElement.addAttribute("Attribute", resource.getFullPath().toString());
			}
		}


		final Element XMLElement = rootElement.addElement("ARXML");
		{
			final Element PathElement = XMLElement.addElement("Path");
			try{
			PathElement.addAttribute("Attribute", AllDialog.getXml().getFullPath().toString());
			}catch(Exception e){
				System.out.println(e.getMessage());
			}
		}


		try {
			OutputFormat format = OutputFormat.createPrettyPrint();
			String projectPath = project.getProject().getLocation().toOSString();
			System.out.println(projectPath);
			XMLWriter output = new XMLWriter(new FileWriter(new File(projectPath + File.separator + "Config.xml")), format);
			codeXmlDocument.setXMLEncoding("utf-8");
			output.write(codeXmlDocument);
			output.close();
		} catch (IOException e) {
			System.out.println(e.getMessage());
		}
	}



	public boolean isConfigFileExist(IProject project){
		String ConfigFile=project.getProject().getLocation().toOSString()+ File.separator +"Config.xml";
		File myFilePath = new File(ConfigFile);

		if (myFilePath.exists()) {
			return true;
		}
{'fraction_non_alphanumeric': 0.12312044067291945, 'fraction_numerical': 0.001786511835640911, 'mean_word_length': 5.806484295845998, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 5}, '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': '7493218', 'n_tokens_mistral': 2135, 'n_tokens_neox': 1940, 'n_words': 330}