<commit_before>/**
 * Axelor Business Solutions
 *
 * Copyright (C) 2012-2014 Axelor (<http://axelor.com>).
 *
 * This program is free software: you can redistribute it and/or  modify
 * it under the terms of the GNU Affero General Public License, version 3,
 * as published by the Free Software Foundation.
 *
 * 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 Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.axelor.meta.schema.actions;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.List;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;

import org.joda.time.DateTime;

import com.axelor.app.AppSettings;
import com.axelor.common.ClassUtils;
import com.axelor.common.FileUtils;
import com.axelor.i18n.I18n;
import com.axelor.meta.ActionHandler;
import com.axelor.text.GroovyTemplates;
import com.axelor.text.StringTemplates;
import com.axelor.text.Templates;
import com.google.common.base.Charsets;
import com.google.common.base.Objects;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableMap;
import com.google.common.io.Files;

@XmlType
public class ActionExport extends Action {

	public static final String EXPORT_PATH = AppSettings.get().getPath("data.export.dir", "");

	private static final String DEFAULT_DIR = "${date}/${name}";

	@XmlAttribute(name = "output")
	private String output;

	@XmlAttribute(name = "download")
	private Boolean download;

	@XmlElement(name = "export")
	private List<Export> exports;

	public String getOutput() {
		return output;
	}

	public Boolean getDownload() {
		return download;
	}

	public List<Export> getExports() {
		return exports;
	}

	protected String doExport(String dir, Export export, ActionHandler handler) throws IOException {
		export.template = handler.evaluate(export.template).toString();

		Reader reader = null;
		File template = new File(export.template);
		if (template.isFile()) {
			reader = new FileReader(template);
		}

		if (reader == null) {
			InputStream is = ClassUtils.getResourceStream(export.template);
			if (is == null) {
				throw new FileNotFoundException("No such template: " + export.template);
			}
			reader = new InputStreamReader(is);
		}

		String name = export.getName();
		if (name.indexOf("$") > -1) {
			name = handler.evaluate("eval: \"\"\"" + name + "\"\"\"").toString();
		}

		log.info("export {} as {}", export.getTemplate(), name);<commit_msg>Fixed action-export template path issue<commit_after>/**
 * Axelor Business Solutions
 *
 * Copyright (C) 2012-2014 Axelor (<http://axelor.com>).
 *
 * This program is free software: you can redistribute it and/or  modify
 * it under the terms of the GNU Affero General Public License, version 3,
 * as published by the Free Software Foundation.
 *
 * 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 Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.axelor.meta.schema.actions;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.List;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;

import org.joda.time.DateTime;

import com.axelor.app.AppSettings;
import com.axelor.common.ClassUtils;
import com.axelor.common.FileUtils;
import com.axelor.i18n.I18n;
import com.axelor.meta.ActionHandler;
import com.axelor.text.GroovyTemplates;
import com.axelor.text.StringTemplates;
import com.axelor.text.Templates;
import com.google.common.base.Charsets;
import com.google.common.base.Objects;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableMap;
import com.google.common.io.Files;

@XmlType
public class ActionExport extends Action {

	public static final String EXPORT_PATH = AppSettings.get().getPath("data.export.dir", "");

	private static final String DEFAULT_DIR = "${date}/${name}";

	@XmlAttribute(name = "output")
	private String output;

	@XmlAttribute(name = "download")
	private Boolean download;

	@XmlElement(name = "export")
	private List<Export> exports;

	public String getOutput() {
		return output;
	}

	public Boolean getDownload() {
		return download;
	}

	public List<Export> getExports() {
		return exports;
	}

	protected String doExport(String dir, Export export, ActionHandler handler) throws IOException {
		String templatePath = handler.evaluate(export.template).toString();

		Reader reader = null;
		File template = new File(templatePath);
		if (template.isFile()) {
			reader = new FileReader(template);
		}

		if (reader == null) {
			InputStream is = ClassUtils.getResourceStream(templatePath);
			if (is == null) {
				throw new FileNotFoundException("No such template: " + templatePath);
			}
			reader = new InputStreamReader(is);
		}

		String name = export.getName();
		if (name.indexOf("$") > -1) {
			name = handler.evaluate("eval: \"\"\"" + name + "\"\"\"").toString();
		}

		log.info("export {} as {}", templatePath, name);
{'fraction_non_alphanumeric': 0.11770674784373414, 'fraction_numerical': 0.004735328936242178, 'mean_word_length': 4.486085343228201, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3438507', 'n_tokens_mistral': 1862, 'n_tokens_neox': 1727, 'n_words': 516}