<commit_before>package org.pentaho.agilebi.pdi.perspective;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.ResourceBundle;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.dom4j.DocumentHelper;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.FileDialog;
import org.pentaho.agilebi.pdi.modeler.ModelerWorkspace;
import org.pentaho.agilebi.pdi.modeler.ModelerWorkspaceUtil;
import org.pentaho.di.core.EngineMetaInterface;
import org.pentaho.di.ui.spoon.FileListener;
import org.pentaho.di.ui.spoon.Spoon;
import org.pentaho.di.ui.spoon.SpoonPerspective;
import org.pentaho.di.ui.spoon.SpoonPerspectiveListener;
import org.pentaho.metadata.model.LogicalModel;
import org.pentaho.metadata.util.MondrianModelExporter;
import org.pentaho.ui.xul.XulComponent;
import org.pentaho.ui.xul.XulDomContainer;
import org.pentaho.ui.xul.XulException;
import org.pentaho.ui.xul.XulOverlay;
import org.pentaho.ui.xul.XulRunner;
import org.pentaho.ui.xul.binding.BindingConvertor;
import org.pentaho.ui.xul.components.XulTab;
import org.pentaho.ui.xul.components.XulTabpanel;
import org.pentaho.ui.xul.containers.XulTabbox;
import org.pentaho.ui.xul.containers.XulTabpanels;
import org.pentaho.ui.xul.containers.XulTabs;
import org.pentaho.ui.xul.dom.Document;
import org.pentaho.ui.xul.impl.AbstractXulEventHandler;
import org.pentaho.ui.xul.impl.XulEventHandler;
import org.pentaho.ui.xul.swt.SwtXulLoader;
import org.pentaho.ui.xul.swt.SwtXulRunner;
import org.pentaho.ui.xul.swt.tags.SwtTab;
import org.pentaho.ui.xul.util.XulDialogCallback;

public abstract class AbstractPerspective extends AbstractXulEventHandler implements SpoonPerspective, FileListener{

  protected XulDomContainer container;
  protected XulRunner runner;
  private Log logger = LogFactory.getLog(AgileBiPerspective.class);
  protected Document document;
  protected XulTabs tabs;
  protected XulTabpanels panels;
  protected XulTabbox tabbox;
  protected List<SpoonPerspectiveListener> listeners = new ArrayList<SpoonPerspectiveListener>();
  private ResourceBundle messages = ResourceBundle.getBundle("org/pentaho/agilebi/pdi/perspective/perspective"); //$NON-NLS-1$
  private String defaultExtension = "";
  protected ModelerWorkspace model;
  
  protected Map<XulTab, EngineMetaInterface> metas = new HashMap<XulTab, EngineMetaInterface>();
  
  protected AbstractPerspective(String perspectiveSrc) {
    try {
      SwtXulLoader loader = new SwtXulLoader();
      container = loader.loadXul(perspectiveSrc); //$NON-NLS-1$
      
      runner = new SwtXulRunner();
      runner.addContainer(container);
      runner.initialize();
      
      document = container.getDocumentRoot();
      container.addEventHandler(this);
      tabs = (XulTabs) document.getElementById("tabs");
      panels = (XulTabpanels) document.getElementById("tabpanels");
      tabbox = (XulTabbox) tabs.getParent();
    } catch(Exception e){
      logger.error(e);
    }
  }
  
	public void exportSchema() {
		try {
			if (this.model.isValid()) {
				ModelerWorkspaceUtil.populateDomain(this.model);
				LogicalModel lModel = this.model.getDomain().getLogicalModels().get(0);

				FileDialog fileDialog = new FileDialog(Spoon.getInstance().getShell(), SWT.SAVE);
				String theFile = fileDialog.open();
				if(theFile != null) {
					MondrianModelExporter exporter = new MondrianModelExporter(lModel, Locale.getDefault().toString());
					String mondrianSchema = exporter.createMondrianModelXML();
					logger.info(mondrianSchema);
	
					org.dom4j.Document schemaDoc = DocumentHelper.parseText(mondrianSchema);
					byte schemaBytes[] = schemaDoc.asXML().getBytes();
	
					File modelFile = new File(theFile);
					OutputStream out = new FileOutputStream(modelFile);
					out.write(schemaBytes);
					out.flush();
					out.close();
				}
			} else {
				StringBuffer validationErrors = new StringBuffer();
				for (String msg : this.model.getValidationMessages()) {<commit_msg>Changed to set xml extension on the schema<commit_after>package org.pentaho.agilebi.pdi.perspective;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.ResourceBundle;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.dom4j.DocumentHelper;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.FileDialog;
import org.pentaho.agilebi.pdi.modeler.ModelerWorkspace;
import org.pentaho.agilebi.pdi.modeler.ModelerWorkspaceUtil;
import org.pentaho.di.core.EngineMetaInterface;
import org.pentaho.di.ui.spoon.FileListener;
import org.pentaho.di.ui.spoon.Spoon;
import org.pentaho.di.ui.spoon.SpoonPerspective;
import org.pentaho.di.ui.spoon.SpoonPerspectiveListener;
import org.pentaho.metadata.model.LogicalModel;
import org.pentaho.metadata.util.MondrianModelExporter;
import org.pentaho.ui.xul.XulComponent;
import org.pentaho.ui.xul.XulDomContainer;
import org.pentaho.ui.xul.XulException;
import org.pentaho.ui.xul.XulOverlay;
import org.pentaho.ui.xul.XulRunner;
import org.pentaho.ui.xul.binding.BindingConvertor;
import org.pentaho.ui.xul.components.XulTab;
import org.pentaho.ui.xul.components.XulTabpanel;
import org.pentaho.ui.xul.containers.XulTabbox;
import org.pentaho.ui.xul.containers.XulTabpanels;
import org.pentaho.ui.xul.containers.XulTabs;
import org.pentaho.ui.xul.dom.Document;
import org.pentaho.ui.xul.impl.AbstractXulEventHandler;
import org.pentaho.ui.xul.impl.XulEventHandler;
import org.pentaho.ui.xul.swt.SwtXulLoader;
import org.pentaho.ui.xul.swt.SwtXulRunner;
import org.pentaho.ui.xul.swt.tags.SwtTab;
import org.pentaho.ui.xul.util.XulDialogCallback;

public abstract class AbstractPerspective extends AbstractXulEventHandler implements SpoonPerspective, FileListener{

  protected XulDomContainer container;
  protected XulRunner runner;
  private Log logger = LogFactory.getLog(AgileBiPerspective.class);
  protected Document document;
  protected XulTabs tabs;
  protected XulTabpanels panels;
  protected XulTabbox tabbox;
  protected List<SpoonPerspectiveListener> listeners = new ArrayList<SpoonPerspectiveListener>();
  private ResourceBundle messages = ResourceBundle.getBundle("org/pentaho/agilebi/pdi/perspective/perspective"); //$NON-NLS-1$
  private String defaultExtension = "";
  protected ModelerWorkspace model;
  
  protected Map<XulTab, EngineMetaInterface> metas = new HashMap<XulTab, EngineMetaInterface>();
  
  protected AbstractPerspective(String perspectiveSrc) {
    try {
      SwtXulLoader loader = new SwtXulLoader();
      container = loader.loadXul(perspectiveSrc); //$NON-NLS-1$
      
      runner = new SwtXulRunner();
      runner.addContainer(container);
      runner.initialize();
      
      document = container.getDocumentRoot();
      container.addEventHandler(this);
      tabs = (XulTabs) document.getElementById("tabs");
      panels = (XulTabpanels) document.getElementById("tabpanels");
      tabbox = (XulTabbox) tabs.getParent();
    } catch(Exception e){
      logger.error(e);
    }
  }
  
	public void exportSchema() {
		try {
			if (this.model.isValid()) {
				ModelerWorkspaceUtil.populateDomain(this.model);
				LogicalModel lModel = this.model.getDomain().getLogicalModels().get(0);

				FileDialog fileDialog = new FileDialog(Spoon.getInstance().getShell(), SWT.SAVE);
				String[] theExtensions = { "*.xml" };
				fileDialog.setFilterExtensions(theExtensions);
				String theFile = fileDialog.open();
				if(theFile != null) {
					MondrianModelExporter exporter = new MondrianModelExporter(lModel, Locale.getDefault().toString());
					String mondrianSchema = exporter.createMondrianModelXML();
					logger.info(mondrianSchema);
	
					org.dom4j.Document schemaDoc = DocumentHelper.parseText(mondrianSchema);
					byte schemaBytes[] = schemaDoc.asXML().getBytes();
	
					File modelFile = new File(theFile);
					OutputStream out = new FileOutputStream(modelFile);
					out.write(schemaBytes);
					out.flush();
					out.close();
				}
			} else {
				StringBuffer validationErrors = new StringBuffer();
				for (String msg : this.model.getValidationMessages()) {
{'fraction_non_alphanumeric': 0.1117009000692361, 'fraction_numerical': 0.0011539349180706207, 'mean_word_length': 4.883910386965376, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '1693424', 'n_tokens_mistral': 2915, 'n_tokens_neox': 2780, 'n_words': 471}