001// *************************************************************************************************************************** 002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * 003// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * 004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * 005// * with the License. You may obtain a copy of the License at * 006// * * 007// * http://www.apache.org/licenses/LICENSE-2.0 * 008// * * 009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * 010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * 011// * specific language governing permissions and limitations under the License. * 012// *************************************************************************************************************************** 013package org.apache.juneau.csv; 014 015import org.apache.juneau.*; 016import org.apache.juneau.annotation.*; 017import org.apache.juneau.parser.*; 018 019/** 020 * TODO - Work in progress. CSV parser. 021 */ 022@ConfigurableContext 023public class CsvParser extends ReaderParser { 024 025 //------------------------------------------------------------------------------------------------------------------- 026 // Configurable properties 027 //------------------------------------------------------------------------------------------------------------------- 028 029 static final String PREFIX = "CsvParser"; 030 031 //------------------------------------------------------------------------------------------------------------------- 032 // Predefined instances 033 //------------------------------------------------------------------------------------------------------------------- 034 035 /** Default parser, all default settings.*/ 036 public static final CsvParser DEFAULT = new CsvParser(PropertyStore.DEFAULT); 037 038 039 //------------------------------------------------------------------------------------------------------------------- 040 // Instance 041 //------------------------------------------------------------------------------------------------------------------- 042 043 /** 044 * Constructor. 045 * 046 * @param ps The property store containing all the settings for this object. 047 */ 048 public CsvParser(PropertyStore ps) { 049 super(ps, "text/csv"); 050 } 051 052 @Override /* Context */ 053 public CsvParserBuilder builder() { 054 return new CsvParserBuilder(getPropertyStore()); 055 } 056 057 /** 058 * Instantiates a new clean-slate {@link CsvParserBuilder} object. 059 * 060 * <p> 061 * Note that this method creates a builder initialized to all default settings, whereas {@link #builder()} copies 062 * the settings of the object called on. 063 * 064 * @return A new {@link CsvParserBuilder} object. 065 */ 066 public static CsvParserBuilder create() { 067 return new CsvParserBuilder(); 068 } 069 070 @Override /* Parser */ 071 public CsvParserSession createSession() { 072 return createSession(createDefaultSessionArgs()); 073 } 074 075 @Override /* Parser */ 076 public CsvParserSession createSession(ParserSessionArgs args) { 077 return new CsvParserSession(this, args); 078 } 079 080 //----------------------------------------------------------------------------------------------------------------- 081 // Other methods 082 //----------------------------------------------------------------------------------------------------------------- 083 084 @Override /* Context */ 085 public ObjectMap toMap() { 086 return super.toMap() 087 .append("CsvParser", new DefaultFilteringObjectMap()); 088 } 089}