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.serializer.*; 018 019/** 020 * TODO - Work in progress. CSV serializer. 021 */ 022@ConfigurableContext 023public final class CsvSerializer extends WriterSerializer { 024 025 //------------------------------------------------------------------------------------------------------------------- 026 // Configurable properties 027 //------------------------------------------------------------------------------------------------------------------- 028 029 static final String PREFIX = "CsvSerializer"; 030 031 //------------------------------------------------------------------------------------------------------------------- 032 // Predefined instances 033 //------------------------------------------------------------------------------------------------------------------- 034 035 /** Default serializer, all default settings.*/ 036 public static final CsvSerializer DEFAULT = new CsvSerializer(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 CsvSerializer(PropertyStore ps) { 049 super(ps, "text/csv", null); 050 } 051 052 @Override /* Context */ 053 public CsvSerializerBuilder builder() { 054 return new CsvSerializerBuilder(getPropertyStore()); 055 } 056 057 /** 058 * Instantiates a new clean-slate {@link CsvSerializerBuilder} object. 059 * 060 * <p> 061 * This is equivalent to simply calling <code><jk>new</jk> CsvSerializerBuilder()</code>. 062 * 063 * <p> 064 * Note that this method creates a builder initialized to all default settings, whereas {@link #builder()} copies 065 * the settings of the object called on. 066 * 067 * @return A new {@link CsvSerializerBuilder} object. 068 */ 069 public static CsvSerializerBuilder create() { 070 return new CsvSerializerBuilder(); 071 } 072 073 @Override /* Context */ 074 public CsvSerializerSession createSession() { 075 return createSession(createDefaultSessionArgs()); 076 } 077 078 @Override /* Serializer */ 079 public CsvSerializerSession createSession(SerializerSessionArgs args) { 080 return new CsvSerializerSession(this, args); 081 } 082 083 //----------------------------------------------------------------------------------------------------------------- 084 // Other methods 085 //----------------------------------------------------------------------------------------------------------------- 086 087 @Override /* Context */ 088 public ObjectMap toMap() { 089 return super.toMap() 090 .append("CsvSerializer", new DefaultFilteringObjectMap()); 091 } 092}