// Path: src/main/java/org/bbreak/excella/reports/tag/BreakParamParser.java
// public class BreakParamParser extends ReportsTagParser<Object> {
// 
//     /** デフォルトタグ */
//     public static final String DEFAULT_TAG = "$BREAK";
// 
//     /**
//      * コンストラクタ
//      */
//     public BreakParamParser() {
//         this( DEFAULT_TAG);
//     }
// 
//     /**
//      * コンストラクタ
//      * 
//      * @param tag
//      */
//     public BreakParamParser( String tag) {
//         super( tag);
//     }
// 
//     /**
//      * @see org.bbreak.excella.reports.tag.ReportsTagParser#parse(org.apache.poi.ss.usermodel.Sheet, org.apache.poi.ss.usermodel.Cell, java.lang.Object)
//      */
//     @Override
//     public ParsedReportInfo parse( Sheet sheet, Cell tagCell, Object data) throws ParseException {
//         // このタグは何も出力しない
//         ParsedReportInfo parsedReportInfo = new ParsedReportInfo();
//         parsedReportInfo.setRowIndex( tagCell.getRowIndex());
//         parsedReportInfo.setColumnIndex( tagCell.getColumnIndex());
//         parsedReportInfo.setDefaultRowIndex( tagCell.getRowIndex());
//         parsedReportInfo.setDefaultColumnIndex( tagCell.getColumnIndex());
//         return parsedReportInfo;
//     }
// 
//     /**
//      * @see org.bbreak.excella.reports.tag.ReportsTagParser#useControlRow()
//      */
//     @Override
//     public boolean useControlRow() {
//         return false;
//     }
// 
// }


import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.util.CellRangeAddress;
import org.bbreak.excella.core.SheetData;
import org.bbreak.excella.core.SheetParser;
import org.bbreak.excella.core.exception.ParseException;
import org.bbreak.excella.core.util.PoiUtil;
import org.bbreak.excella.reports.tag.BreakParamParser;

/*-
 * #%L
 * excella-reports
 * %%
 * Copyright (C) 2009 - 2019 bBreak Systems and contributors
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */

package org.bbreak.excella.reports.listener;


/**
 * 改ページの挿入
 * 
 * @author T.Maruyama
 * @version 1.8
 */
public class BreakAdapter extends ReportProcessAdaptor {

    /**
     * @see org.bbreak.excella.reports.listener.ReportProcessAdaptor#postParse(org.apache.poi.ss.usermodel.Sheet, org.bbreak.excella.core.SheetParser, org.bbreak.excella.core.SheetData)
     */
    @Override
    public void postParse( Sheet sheet, SheetParser sheetParser, SheetData sheetData) throws ParseException {
        int firstRowNum = sheet.getFirstRowNum();
        int lastRowNum = sheet.getLastRowNum();

        for ( int rowIndex = firstRowNum; rowIndex <= lastRowNum; rowIndex++) {
            Row row = sheet.getRow( rowIndex);
            if ( row != null) {
                parseRow( sheet, sheetParser, sheetData, row, rowIndex);
            }
        }
    }

    /**
     * 行単位で解析し、必要なら改ページを挿入する
     */
    protected void parseRow( Sheet sheet, SheetParser sheetParser, SheetData sheetData, Row row, int rowIndex) {
        int firstColNum = row.getFirstCellNum();
        int lastColNum = row.getLastCellNum() - 1;

        for ( int colIndex = firstColNum; colIndex <= lastColNum; colIndex++) {
            Cell cell = row.getCell( colIndex);
            if ( cell != null) {

// Path: src/main/java/org/bbreak/excella/reports/tag/BreakParamParser.java
// public class BreakParamParser extends ReportsTagParser<Object> {
// 
//     /** デフォルトタグ */
//     public static final String DEFAULT_TAG = "$BREAK";
// 
//     /**
//      * コンストラクタ
//      */
//     public BreakParamParser() {
//         this( DEFAULT_TAG);
//     }
// 
//     /**
//      * コンストラクタ
//      * 
//      * @param tag
//      */
//     public BreakParamParser( String tag) {
//         super( tag);
//     }
// 
//     /**
//      * @see org.bbreak.excella.reports.tag.ReportsTagParser#parse(org.apache.poi.ss.usermodel.Sheet, org.apache.poi.ss.usermodel.Cell, java.lang.Object)
//      */
//     @Override
//     public ParsedReportInfo parse( Sheet sheet, Cell tagCell, Object data) throws ParseException {
//         // このタグは何も出力しない
//         ParsedReportInfo parsedReportInfo = new ParsedReportInfo();
//         parsedReportInfo.setRowIndex( tagCell.getRowIndex());
//         parsedReportInfo.setColumnIndex( tagCell.getColumnIndex());
//         parsedReportInfo.setDefaultRowIndex( tagCell.getRowIndex());
//         parsedReportInfo.setDefaultColumnIndex( tagCell.getColumnIndex());
//         return parsedReportInfo;
//     }
// 
//     /**
//      * @see org.bbreak.excella.reports.tag.ReportsTagParser#useControlRow()
//      */
//     @Override
//     public boolean useControlRow() {
//         return false;
//     }
// 
// }


// Path: src/main/java/org/bbreak/excella/reports/listener/BreakAdapter.java
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.util.CellRangeAddress;
import org.bbreak.excella.core.SheetData;
import org.bbreak.excella.core.SheetParser;
import org.bbreak.excella.core.exception.ParseException;
import org.bbreak.excella.core.util.PoiUtil;
import org.bbreak.excella.reports.tag.BreakParamParser;

/*-
 * #%L
 * excella-reports
 * %%
 * Copyright (C) 2009 - 2019 bBreak Systems and contributors
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */

package org.bbreak.excella.reports.listener;


/**
 * 改ページの挿入
 * 
 * @author T.Maruyama
 * @version 1.8
 */
public class BreakAdapter extends ReportProcessAdaptor {

    /**
     * @see org.bbreak.excella.reports.listener.ReportProcessAdaptor#postParse(org.apache.poi.ss.usermodel.Sheet, org.bbreak.excella.core.SheetParser, org.bbreak.excella.core.SheetData)
     */
    @Override
    public void postParse( Sheet sheet, SheetParser sheetParser, SheetData sheetData) throws ParseException {
        int firstRowNum = sheet.getFirstRowNum();
        int lastRowNum = sheet.getLastRowNum();

        for ( int rowIndex = firstRowNum; rowIndex <= lastRowNum; rowIndex++) {
            Row row = sheet.getRow( rowIndex);
            if ( row != null) {
                parseRow( sheet, sheetParser, sheetData, row, rowIndex);
            }
        }
    }

    /**
     * 行単位で解析し、必要なら改ページを挿入する
     */
    protected void parseRow( Sheet sheet, SheetParser sheetParser, SheetData sheetData, Row row, int rowIndex) {
        int firstColNum = row.getFirstCellNum();
        int lastColNum = row.getLastCellNum() - 1;

        for ( int colIndex = firstColNum; colIndex <= lastColNum; colIndex++) {
            Cell cell = row.getCell( colIndex);
            if ( cell != null) {

                if ( cell.getCellType() == CellType.STRING && cell.getStringCellValue().contains( BreakParamParser.DEFAULT_TAG)) {
