<commit_before>/*
 * jETeL/CloverETL - Java based ETL application framework.
 * Copyright (c) Javlin, a.s. (<EMAIL>)
 *  
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */
package org.jetel.component;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jetel.data.DataRecord;
import org.jetel.data.Defaults;
import org.jetel.data.formatter.SpreadsheetFormatter;
import org.jetel.data.formatter.provider.SpreadsheetFormatterProvider;
import org.jetel.data.lookup.LookupTable;
import org.jetel.data.parser.XLSMapping;
import org.jetel.enums.PartitionFileTagType;
import org.jetel.exception.ComponentNotReadyException;
import org.jetel.exception.ConfigurationProblem;
import org.jetel.exception.ConfigurationStatus;
import org.jetel.exception.XMLConfigurationException;
import org.jetel.graph.InputPort;
import org.jetel.graph.Node;
import org.jetel.graph.Result;
import org.jetel.graph.TransformationGraph;
import org.jetel.metadata.DataFieldFormatType;
import org.jetel.metadata.DataFieldMetadata;
import org.jetel.metadata.DataRecordMetadata;
import org.jetel.util.MultiFileWriter;
import org.jetel.util.SpreadsheetUtils.SpreadsheetAttitude;
import org.jetel.util.SpreadsheetUtils.SpreadsheetExistingSheetsActions;
import org.jetel.util.SpreadsheetUtils.SpreadsheetFormat;
import org.jetel.util.SpreadsheetUtils.SpreadsheetWriteMode;
import org.jetel.util.bytes.SystemOutByteChannel;
import org.jetel.util.bytes.WritableByteChannelIterator;
import org.jetel.util.file.FileUtils;
import org.jetel.util.property.ComponentXMLAttributes;
import org.jetel.util.property.RefResFlag;
import org.jetel.util.string.StringUtils;
import org.w3c.dom.Element;

/**
 * @author lkrejci & psimecek (<EMAIL>) (c) Javlin, a.s. (www.cloveretl.com)
 * 
 * @created 5 Sep 2011
 */
public class SpreadsheetWriter extends Node {

	public static final String COMPONENT_TYPE = "SPREADSHEET_WRITER";

	public static final String XML_FILE_URL_ATTRIBUTE = "fileURL";
	public static final String XML_TEMPLATE_FILE_URL_ATTRIBUTE = "templateFileURL";
	public static final String XML_FORMATTER_TYPE_ATTRIBUTE = "formatterType";
	public static final String XML_WRITE_MODE_ATTRIBUTE = "writeMode";
	public static final String XML_MK_DIRS_ATTRIBUTE = "makeDirs";
	public static final String XML_MAPPING_ATTRIBUTE = "mapping";
	public static final String XML_MAPPING_URL_ATTRIBUTE = "mappingURL";
	public static final String XML_SHEET_ATTRIBUTE = "sheet";
	public static final String XML_EXISTING_SHEETS_ACTIONS_ATTRIBUTE = "existingSheetsActions";
	public static final String XML_RECORD_SKIP_ATTRIBUTE = "skipRecords";
	public static final String XML_RECORD_COUNT_ATTRIBUTE = "numRecords";
	public static final String XML_RECORDS_PER_FILE = "numFileRecords";
	public static final String XML_PARTITIONKEY_ATTRIBUTE = "partitionKey";
	public static final String XML_PARTITION_ATTRIBUTE = "partition";
	public static final String XML_PARTITION_OUTFIELDS_ATTRIBUTE = "partitionOutFields";
	public static final String XML_PARTITION_FILETAG_ATTRIBUTE = "partitionFileTag";
	public static final String XML_PARTITION_UNASSIGNED_FILE_NAME_ATTRIBUTE = "partitionUnassignedFileName";

	private static Log LOGGER = LogFactory.getLog(SpreadsheetWriter.class);
	private static final int READ_FROM_PORT = 0;
	private static final int OUTPUT_PORT = 0;
	private static final int OUTPUT_LOG_PORT = 1;
	
	private static final HashSet<Character> supportedTypes;
	
	static {
		supportedTypes = new HashSet<Character>(9);<commit_msg>UDPATE: spreadsheet writer output logging port removed<commit_after>/*
 * jETeL/CloverETL - Java based ETL application framework.
 * Copyright (c) Javlin, a.s. (<EMAIL>)
 *  
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */
package org.jetel.component;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jetel.data.DataRecord;
import org.jetel.data.Defaults;
import org.jetel.data.formatter.SpreadsheetFormatter;
import org.jetel.data.formatter.provider.SpreadsheetFormatterProvider;
import org.jetel.data.lookup.LookupTable;
import org.jetel.data.parser.XLSMapping;
import org.jetel.enums.PartitionFileTagType;
import org.jetel.exception.ComponentNotReadyException;
import org.jetel.exception.ConfigurationProblem;
import org.jetel.exception.ConfigurationStatus;
import org.jetel.exception.XMLConfigurationException;
import org.jetel.graph.InputPort;
import org.jetel.graph.Node;
import org.jetel.graph.Result;
import org.jetel.graph.TransformationGraph;
import org.jetel.metadata.DataFieldFormatType;
import org.jetel.metadata.DataFieldMetadata;
import org.jetel.metadata.DataRecordMetadata;
import org.jetel.util.MultiFileWriter;
import org.jetel.util.SpreadsheetUtils.SpreadsheetAttitude;
import org.jetel.util.SpreadsheetUtils.SpreadsheetExistingSheetsActions;
import org.jetel.util.SpreadsheetUtils.SpreadsheetFormat;
import org.jetel.util.SpreadsheetUtils.SpreadsheetWriteMode;
import org.jetel.util.bytes.SystemOutByteChannel;
import org.jetel.util.bytes.WritableByteChannelIterator;
import org.jetel.util.file.FileUtils;
import org.jetel.util.property.ComponentXMLAttributes;
import org.jetel.util.property.RefResFlag;
import org.jetel.util.string.StringUtils;
import org.w3c.dom.Element;

/**
 * @author lkrejci & psimecek (<EMAIL>) (c) Javlin, a.s. (www.cloveretl.com)
 * 
 * @created 5 Sep 2011
 */
public class SpreadsheetWriter extends Node {

	public static final String COMPONENT_TYPE = "SPREADSHEET_WRITER";

	public static final String XML_FILE_URL_ATTRIBUTE = "fileURL";
	public static final String XML_TEMPLATE_FILE_URL_ATTRIBUTE = "templateFileURL";
	public static final String XML_FORMATTER_TYPE_ATTRIBUTE = "formatterType";
	public static final String XML_WRITE_MODE_ATTRIBUTE = "writeMode";
	public static final String XML_MK_DIRS_ATTRIBUTE = "makeDirs";
	public static final String XML_MAPPING_ATTRIBUTE = "mapping";
	public static final String XML_MAPPING_URL_ATTRIBUTE = "mappingURL";
	public static final String XML_SHEET_ATTRIBUTE = "sheet";
	public static final String XML_EXISTING_SHEETS_ACTIONS_ATTRIBUTE = "existingSheetsActions";
	public static final String XML_RECORD_SKIP_ATTRIBUTE = "skipRecords";
	public static final String XML_RECORD_COUNT_ATTRIBUTE = "numRecords";
	public static final String XML_RECORDS_PER_FILE = "numFileRecords";
	public static final String XML_PARTITIONKEY_ATTRIBUTE = "partitionKey";
	public static final String XML_PARTITION_ATTRIBUTE = "partition";
	public static final String XML_PARTITION_OUTFIELDS_ATTRIBUTE = "partitionOutFields";
	public static final String XML_PARTITION_FILETAG_ATTRIBUTE = "partitionFileTag";
	public static final String XML_PARTITION_UNASSIGNED_FILE_NAME_ATTRIBUTE = "partitionUnassignedFileName";

	private static Log LOGGER = LogFactory.getLog(SpreadsheetWriter.class);
	private static final int READ_FROM_PORT = 0;
	private static final int OUTPUT_PORT = 0;
	
	private static final HashSet<Character> supportedTypes;
	
	static {
		supportedTypes = new HashSet<Character>(9);
{'fraction_non_alphanumeric': 0.07781876873414803, 'fraction_numerical': 0.005879640304357851, 'mean_word_length': 6.035685320356853, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '138602', 'n_tokens_mistral': 2619, 'n_tokens_neox': 2572, 'n_words': 721}