com.kazurayam.materialstore.mapper.RSS2ExcelMapper Maven / Gradle / Ivy
package com.kazurayam.materialstore.mapper;
import com.kazurayam.materialstore.core.FileType;
import com.kazurayam.materialstore.core.Material;
import com.kazurayam.materialstore.core.MaterialstoreException;
import com.kazurayam.materialstore.core.Metadata;
import com.kazurayam.materialstore.core.Store;
import com.kazurayam.materialstore.core.StoreImpl;
import com.kazurayam.materialstore.map.MappedResultSerializer;
import com.kazurayam.materialstore.map.Mapper;
import com.kazurayam.materialstore.map.MappingListener;
import com.rometools.rome.feed.synd.SyndFeed;
import com.rometools.rome.io.FeedException;
import com.rometools.rome.io.SyndFeedInput;
import com.rometools.rome.io.XmlReader;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.URL;
import java.util.List;
import java.util.Map;
import java.util.Objects;
public abstract class RSS2ExcelMapper implements Mapper {
private static final Logger logger =
LoggerFactory.getLogger(RSS2ExcelMapper.class);
protected Store store;
protected MappingListener listener;
public RSS2ExcelMapper() {
store = StoreImpl.NULL_OBJECT;
listener = MappedResultSerializer.NULL_OBJECT;
}
@Override
public void setStore(Store store) {
Objects.requireNonNull(store);
this.store = store;
}
@Override
public void setMappingListener(MappingListener listener) {
Objects.requireNonNull(listener);
this.listener = listener;
}
@Override
public void map(Material material) throws MaterialstoreException {
Objects.requireNonNull(material);
SyndFeed feed = getFeed(material);
logger.debug(feed.toString());
//
Workbook workbook = new XSSFWorkbook();
Sheet sheet = createSheet(workbook, getSheetName(), getColumns());
// create Header row, place it into the sheet
//Row header = createHeaderRow(sheet, getColumnsOfDemo());
Row header = createHeaderRow(sheet, getColumns());
logger.debug("header: " + header);
// write the data rows with different style
//List