<commit_before>/*! ******************************************************************************
 *
 * Pentaho Data Integration
 *
 * Copyright (C) 2002-2013 by Pentaho : http://www.pentaho.com
 *
 *******************************************************************************
 *
 * 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.pentaho.di.ui.repository;

import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.List;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Shell;
import org.pentaho.di.core.exception.KettleException;
import org.pentaho.di.core.exception.KettleSecurityException;
import org.pentaho.di.core.logging.LogChannel;
import org.pentaho.di.core.plugins.PluginInterface;
import org.pentaho.di.core.plugins.PluginRegistry;
import org.pentaho.di.core.plugins.PluginTypeInterface;
import org.pentaho.di.core.plugins.RepositoryPluginType;
import org.pentaho.di.i18n.BaseMessages;
import org.pentaho.di.repository.RepositoriesMeta;
import org.pentaho.di.repository.Repository;
import org.pentaho.di.repository.RepositoryMeta;
import org.pentaho.di.ui.core.PropsUI;
import org.pentaho.di.ui.core.dialog.EnterSelectionDialog;
import org.pentaho.di.ui.core.dialog.ErrorDialog;
import org.pentaho.di.ui.repository.dialog.RepositoryDialogInterface;
import org.pentaho.di.ui.repository.dialog.RepositoryDialogInterface.MODE;
import org.pentaho.di.ui.repository.model.RepositoriesModel;
import org.pentaho.ui.xul.XulComponent;
import org.pentaho.ui.xul.components.XulConfirmBox;
import org.pentaho.ui.xul.dom.Document;
import org.pentaho.ui.xul.util.XulDialogCallback;

public class RepositoriesHelper {
  private static Class<?> PKG = RepositoriesHelper.class; // for i18n purposes, needed by Translator2!!
  private Shell shell;
  private PropsUI props;
  private RepositoriesMeta input;
  private Repository repository;
  private String prefRepositoryName;
  private RepositoriesModel model;
  private Document document;
  private LogChannel log;

  public RepositoriesHelper( RepositoriesModel model, Document document, Shell shell ) {
    this.props = PropsUI.getInstance();
    this.input = new RepositoriesMeta();
    this.repository = null;
    this.model = model;
    this.document = document;
    this.shell = shell;
    log = new LogChannel( "RepositoriesHelper" );
    try {
      try {
        this.input.readData();
        if ( input.getErrorMessage() != null && input.getErrorMessage().length() > 0 ) {
          throw new KettleException( input.getErrorMessage() );
        }
      } catch ( KettleException e ) {
        log.logDetailed( BaseMessages.getString( PKG, "RepositoryLogin.ErrorReadingRepositoryDefinitions", e
          .getLocalizedMessage() ) );
        new ErrorDialog( shell, BaseMessages.getString( PKG, "Dialog.Error" ), BaseMessages.getString(
          PKG, "RepositoryLogin.ErrorReadingRepositoryDefinitions", e.getLocalizedMessage() ), e );
      }
      List<RepositoryMeta> repositoryList = new ArrayList<RepositoryMeta>();
      for ( int i = 0; i < this.input.nrRepositories(); i++ ) {
        repositoryList.add( this.input.getRepository( i ) );
      }
      model.setAvailableRepositories( repositoryList );
    } catch ( Exception e ) {
      log.logDetailed( BaseMessages.getString( PKG, "RepositoryLogin.ErrorReadingRepositoryDefinitions" ) );
      new ErrorDialog( shell, BaseMessages.getString( PKG, "Dialog.Error" ), BaseMessages.getString(
        PKG, "RepositoryLogin.ErrorReadingRepositoryDefinitions" ), e );
    }
  }

  public void newRepository() {
    PluginRegistry registry = PluginRegistry.getInstance();
    Class<? extends PluginTypeInterface> pluginType = RepositoryPluginType.class;
    List<PluginInterface> plugins = registry.getPlugins( pluginType );

    String[] names = new String[plugins.size()];
    for ( int i = 0; i < names.length; i++ ) {
      PluginInterface plugin = plugins.get( i );
      names[i] = plugin.getName() + " : " + plugin.getDescription();
    }

    // TODO: make this a bit fancier!
    EnterSelectionDialog selectRepositoryType = new EnterSelectionDialog( this.shell, names,
      BaseMessages.getString( PKG, "RepositoryLogin.SelectRepositoryType" ),
      BaseMessages.getString( PKG, "RepositoryLogin.SelectRepositoryTypeCreate" ) );
    String choice = selectRepositoryType.openRepoDialog();
    if ( choice != null ) {
      int index = selectRepositoryType.getSelectionNr();
      PluginInterface plugin = plugins.get( index );
      String id = plugin.getIds()[0];

      try {
        // With this ID we can create a new Repository object...
        //
        RepositoryMeta repositoryMeta =
          PluginRegistry.getInstance().loadClass( RepositoryPluginType.class, id, RepositoryMeta.class );<commit_msg>[BACKLOG-6464] changed ':' to '-'<commit_after>/*! ******************************************************************************
 *
 * Pentaho Data Integration
 *
 * Copyright (C) 2002-2013 by Pentaho : http://www.pentaho.com
 *
 *******************************************************************************
 *
 * 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.pentaho.di.ui.repository;

import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.List;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Shell;
import org.pentaho.di.core.exception.KettleException;
import org.pentaho.di.core.exception.KettleSecurityException;
import org.pentaho.di.core.logging.LogChannel;
import org.pentaho.di.core.plugins.PluginInterface;
import org.pentaho.di.core.plugins.PluginRegistry;
import org.pentaho.di.core.plugins.PluginTypeInterface;
import org.pentaho.di.core.plugins.RepositoryPluginType;
import org.pentaho.di.i18n.BaseMessages;
import org.pentaho.di.repository.RepositoriesMeta;
import org.pentaho.di.repository.Repository;
import org.pentaho.di.repository.RepositoryMeta;
import org.pentaho.di.ui.core.PropsUI;
import org.pentaho.di.ui.core.dialog.EnterSelectionDialog;
import org.pentaho.di.ui.core.dialog.ErrorDialog;
import org.pentaho.di.ui.repository.dialog.RepositoryDialogInterface;
import org.pentaho.di.ui.repository.dialog.RepositoryDialogInterface.MODE;
import org.pentaho.di.ui.repository.model.RepositoriesModel;
import org.pentaho.ui.xul.XulComponent;
import org.pentaho.ui.xul.components.XulConfirmBox;
import org.pentaho.ui.xul.dom.Document;
import org.pentaho.ui.xul.util.XulDialogCallback;

public class RepositoriesHelper {
  private static Class<?> PKG = RepositoriesHelper.class; // for i18n purposes, needed by Translator2!!
  private Shell shell;
  private PropsUI props;
  private RepositoriesMeta input;
  private Repository repository;
  private String prefRepositoryName;
  private RepositoriesModel model;
  private Document document;
  private LogChannel log;

  public RepositoriesHelper( RepositoriesModel model, Document document, Shell shell ) {
    this.props = PropsUI.getInstance();
    this.input = new RepositoriesMeta();
    this.repository = null;
    this.model = model;
    this.document = document;
    this.shell = shell;
    log = new LogChannel( "RepositoriesHelper" );
    try {
      try {
        this.input.readData();
        if ( input.getErrorMessage() != null && input.getErrorMessage().length() > 0 ) {
          throw new KettleException( input.getErrorMessage() );
        }
      } catch ( KettleException e ) {
        log.logDetailed( BaseMessages.getString( PKG, "RepositoryLogin.ErrorReadingRepositoryDefinitions", e
          .getLocalizedMessage() ) );
        new ErrorDialog( shell, BaseMessages.getString( PKG, "Dialog.Error" ), BaseMessages.getString(
          PKG, "RepositoryLogin.ErrorReadingRepositoryDefinitions", e.getLocalizedMessage() ), e );
      }
      List<RepositoryMeta> repositoryList = new ArrayList<RepositoryMeta>();
      for ( int i = 0; i < this.input.nrRepositories(); i++ ) {
        repositoryList.add( this.input.getRepository( i ) );
      }
      model.setAvailableRepositories( repositoryList );
    } catch ( Exception e ) {
      log.logDetailed( BaseMessages.getString( PKG, "RepositoryLogin.ErrorReadingRepositoryDefinitions" ) );
      new ErrorDialog( shell, BaseMessages.getString( PKG, "Dialog.Error" ), BaseMessages.getString(
        PKG, "RepositoryLogin.ErrorReadingRepositoryDefinitions" ), e );
    }
  }

  public void newRepository() {
    PluginRegistry registry = PluginRegistry.getInstance();
    Class<? extends PluginTypeInterface> pluginType = RepositoryPluginType.class;
    List<PluginInterface> plugins = registry.getPlugins( pluginType );

    String[] names = new String[plugins.size()];
    for ( int i = 0; i < names.length; i++ ) {
      PluginInterface plugin = plugins.get( i );
      names[i] = plugin.getName() + " - " + plugin.getDescription();
    }

    // TODO: make this a bit fancier!
    EnterSelectionDialog selectRepositoryType = new EnterSelectionDialog( this.shell, names,
      BaseMessages.getString( PKG, "RepositoryLogin.SelectRepositoryType" ),
      BaseMessages.getString( PKG, "RepositoryLogin.SelectRepositoryTypeCreate" ) );
    String choice = selectRepositoryType.openRepoDialog();
    if ( choice != null ) {
      int index = selectRepositoryType.getSelectionNr();
      PluginInterface plugin = plugins.get( index );
      String id = plugin.getIds()[0];

      try {
        // With this ID we can create a new Repository object...
        //
        RepositoryMeta repositoryMeta =
          PluginRegistry.getInstance().loadClass( RepositoryPluginType.class, id, RepositoryMeta.class );
{'fraction_non_alphanumeric': 0.14550018594272965, 'fraction_numerical': 0.0042766827817032355, 'mean_word_length': 4.166666666666667, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, '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': '6741733', 'n_tokens_mistral': 2985, 'n_tokens_neox': 2885, 'n_words': 711}