001/* 002 * (C) Copyright 2012 Nuxeo SA (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * Thomas Roger 016 */ 017 018package org.nuxeo.ecm.csv; 019 020import java.io.Serializable; 021 022/** 023 * @author <a href="mailto:troger@nuxeo.com">Thomas Roger</a> 024 * @since 5.7 025 */ 026public class CSVImporterOptions implements Serializable { 027 028 private static final long serialVersionUID = 1L; 029 030 public static final CSVImporterOptions DEFAULT_OPTIONS = new Builder().build(); 031 032 public static class Builder { 033 034 private CSVImporterDocumentFactory CSVImporterDocumentFactory = new DefaultCSVImporterDocumentFactory(); 035 036 private String dateFormat = "MM/dd/yyyy"; 037 038 private String listSeparatorRegex = "\\|"; 039 040 private Character escapeCharacter = '\\'; 041 042 private boolean updateExisting = true; 043 044 private boolean checkAllowedSubTypes = true; 045 046 private boolean sendEmail = false; 047 048 private int batchSize = 50; 049 050 public Builder documentModelFactory(CSVImporterDocumentFactory factory) { 051 this.CSVImporterDocumentFactory = factory; 052 return this; 053 } 054 055 public Builder dateFormat(String dateFormat) { 056 this.dateFormat = dateFormat; 057 return this; 058 } 059 060 public Builder listSeparatorRegex(String listSeparatorRegex) { 061 this.listSeparatorRegex = listSeparatorRegex; 062 return this; 063 } 064 065 public Builder escapeCharacter(Character escapeCharacter) { 066 this.escapeCharacter = escapeCharacter; 067 return this; 068 } 069 070 public Builder updateExisting(boolean updateExisting) { 071 this.updateExisting = updateExisting; 072 return this; 073 } 074 075 public Builder checkAllowedSubTypes(boolean checkAllowedSubTypes) { 076 this.checkAllowedSubTypes = checkAllowedSubTypes; 077 return this; 078 } 079 080 public Builder sendEmail(boolean sendEmail) { 081 this.sendEmail = sendEmail; 082 return this; 083 } 084 085 public Builder batchSize(int batchSize) { 086 this.batchSize = batchSize; 087 return this; 088 } 089 090 public CSVImporterOptions build() { 091 return new CSVImporterOptions(CSVImporterDocumentFactory, dateFormat, listSeparatorRegex, escapeCharacter, 092 updateExisting, checkAllowedSubTypes, sendEmail, batchSize); 093 } 094 } 095 096 protected final CSVImporterDocumentFactory CSVImporterDocumentFactory; 097 098 protected final String dateFormat; 099 100 protected final String listSeparatorRegex; 101 102 protected final Character escapeCharacter; 103 104 protected final boolean updateExisting; 105 106 protected final boolean checkAllowedSubTypes; 107 108 protected final boolean sendEmail; 109 110 protected final int batchSize; 111 112 protected CSVImporterOptions(CSVImporterDocumentFactory CSVImporterDocumentFactory, String dateFormat, 113 String listSeparatorRegex, boolean updateExisting, boolean checkAllowedSubTypes, boolean sendEmail, 114 int batchSize) { 115 this(CSVImporterDocumentFactory, dateFormat, listSeparatorRegex, '\\', updateExisting, checkAllowedSubTypes, 116 sendEmail, batchSize); 117 } 118 119 /** 120 * @since 7.2 121 */ 122 protected CSVImporterOptions(CSVImporterDocumentFactory CSVImporterDocumentFactory, String dateFormat, 123 String listSeparatorRegex, Character escapeCharacter, boolean updateExisting, boolean checkAllowedSubTypes, 124 boolean sendEmail, int batchSize) { 125 this.CSVImporterDocumentFactory = CSVImporterDocumentFactory; 126 this.dateFormat = dateFormat; 127 this.listSeparatorRegex = listSeparatorRegex; 128 this.escapeCharacter = escapeCharacter; 129 this.updateExisting = updateExisting; 130 this.checkAllowedSubTypes = checkAllowedSubTypes; 131 this.sendEmail = sendEmail; 132 this.batchSize = batchSize; 133 } 134 135 public CSVImporterDocumentFactory getCSVImporterDocumentFactory() { 136 return CSVImporterDocumentFactory; 137 } 138 139 public String getDateFormat() { 140 return dateFormat; 141 } 142 143 public String getListSeparatorRegex() { 144 return listSeparatorRegex; 145 } 146 147 public Character getEscapeCharacter() { 148 return escapeCharacter; 149 } 150 151 public boolean updateExisting() { 152 return updateExisting; 153 } 154 155 public boolean checkAllowedSubTypes() { 156 return checkAllowedSubTypes; 157 } 158 159 public boolean sendEmail() { 160 return sendEmail; 161 } 162 163 public int getBatchSize() { 164 return batchSize; 165 } 166}