<commit_before>/*
 * This program is free software; you can redistribute it and/or modify it under the
 * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software
 * Foundation.
 *
 * You should have received a copy of the GNU Lesser General Public License along with this
 * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
 * or from the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Lesser General Public License for more details.
 *
 * Copyright (c) 2009 Pentaho Corporation..  All rights reserved.
 */
package org.pentaho.agilebi.platform;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.List;
import java.util.Map;

import org.apache.commons.io.IOUtils;
import org.dom4j.Document;
import org.pentaho.platform.api.engine.IActionSequence;
import org.pentaho.platform.api.engine.IFileFilter;
import org.pentaho.platform.api.engine.IPentahoSession;
import org.pentaho.platform.api.engine.IPermissionMask;
import org.pentaho.platform.api.engine.IPermissionRecipient;
import org.pentaho.platform.api.engine.ISolutionFile;
import org.pentaho.platform.api.engine.ISolutionFilter;
import org.pentaho.platform.api.engine.PentahoAccessControlException;
import org.pentaho.platform.api.repository.ISolutionRepository;
import org.pentaho.platform.engine.core.system.PentahoSystem;
import org.pentaho.platform.repository.solution.SolutionRepositoryBase;

import com.google.gwt.http.client.URL;

public class AgileBISolutionRepository extends SolutionRepositoryBase {

  private static final long serialVersionUID = -1174699308144524442L;
  
  private static String cleanUpPath(String path) {
    // TODO: this is a hack until we figure out encoding issues with paths
    path = path.replaceAll("\\+"," ");
    path = path.replaceAll("%3A",":");
    path = path.replaceAll("%5C","\\\\");
    return path;
  }
  
  public int publish(String baseUrl, String path, String fileName, byte[] data, boolean overwrite) throws PentahoAccessControlException {
    
    path = URL.decode(path);
    path = cleanUpPath(path);

    
    // Analyzer puts a "/" at the beginning of the path on windows, remove it.
    if (path.startsWith("/") && path.contains(":")) { //$NON-NLS-1$ //$NON-NLS-2$
      path = path.substring(1);
    }
    
    File f = new File(path, fileName);
    FileOutputStream fos = null;
    try {
      fos = new FileOutputStream(f);
      fos.write(data);
      fos.close();
    } catch (Exception e) {
      e.printStackTrace();
      return ISolutionRepository.FILE_ADD_FAILED;
    }
    return ISolutionRepository.FILE_ADD_SUCCESSFUL;
  }
  
  private File getFile(String solutionPath) {
    
    solutionPath = cleanUpPath(solutionPath);
    
    if (solutionPath.startsWith("system/")) {
      String filePath = PentahoSystem.getApplicationContext().getSolutionPath(solutionPath);
      File file = new File(filePath);
      return file;<commit_msg>AGILEBI-260: Changed AgileBiSolutionRepository to decode the path during save operation so that a file can be created correctly.<commit_after>/*
 * This program is free software; you can redistribute it and/or modify it under the
 * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software
 * Foundation.
 *
 * You should have received a copy of the GNU Lesser General Public License along with this
 * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
 * or from the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Lesser General Public License for more details.
 *
 * Copyright (c) 2009 Pentaho Corporation..  All rights reserved.
 */
package org.pentaho.agilebi.platform;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.List;
import java.util.Map;

import org.apache.commons.io.IOUtils;
import org.dom4j.Document;
import org.pentaho.platform.api.engine.IActionSequence;
import org.pentaho.platform.api.engine.IFileFilter;
import org.pentaho.platform.api.engine.IPentahoSession;
import org.pentaho.platform.api.engine.IPermissionMask;
import org.pentaho.platform.api.engine.IPermissionRecipient;
import org.pentaho.platform.api.engine.ISolutionFile;
import org.pentaho.platform.api.engine.ISolutionFilter;
import org.pentaho.platform.api.engine.PentahoAccessControlException;
import org.pentaho.platform.api.repository.ISolutionRepository;
import org.pentaho.platform.engine.core.system.PentahoSystem;
import org.pentaho.platform.repository.solution.SolutionRepositoryBase;

import com.google.gwt.http.client.URL;

public class AgileBISolutionRepository extends SolutionRepositoryBase {

  private static final long serialVersionUID = -1174699308144524442L;
  
  private static String cleanUpPath(String path) {
    // TODO: this is a hack until we figure out encoding issues with paths
    path = path.replaceAll("\\+"," ");
    path = path.replaceAll("%3A",":");
    path = path.replaceAll("%5C","\\\\");
    path = path.replaceAll("%2F", "\\");
    return path;
  }
  
  public int publish(String baseUrl, String path, String fileName, byte[] data, boolean overwrite) throws PentahoAccessControlException {
    
    path = cleanUpPath(path);
    
    // Analyzer puts a "/" at the beginning of the path on windows, remove it.
    if (path.startsWith("/") && path.contains(":")) { //$NON-NLS-1$ //$NON-NLS-2$
      path = path.substring(1);
    }
    
    File f = new File(path, fileName);
    FileOutputStream fos = null;
    try {
      fos = new FileOutputStream(f);
      fos.write(data);
      fos.close();
    } catch (Exception e) {
      e.printStackTrace();
      return ISolutionRepository.FILE_ADD_FAILED;
    }
    return ISolutionRepository.FILE_ADD_SUCCESSFUL;
  }
  
  private File getFile(String solutionPath) {
    
    solutionPath = cleanUpPath(solutionPath);
    
    if (solutionPath.startsWith("system/")) {
      String filePath = PentahoSystem.getApplicationContext().getSolutionPath(solutionPath);
      File file = new File(filePath);
      return file;
{'fraction_non_alphanumeric': 0.1016873889875666, 'fraction_numerical': 0.013617525162818236, 'mean_word_length': 4.005185185185185, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7249098', 'n_tokens_mistral': 1993, 'n_tokens_neox': 1936, 'n_words': 574}