net.sf.jasperreports.engine.export.ooxml.DocxStyleHelper Maven / Gradle / Ivy
/*
* JasperReports - Free Java Reporting Library.
* Copyright (C) 2001 - 2011 Jaspersoft Corporation. All rights reserved.
* http://www.jaspersoft.com
*
* Unless you have purchased a commercial license agreement from Jaspersoft,
* the following license terms apply:
*
* This program is part of JasperReports.
*
* JasperReports is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* JasperReports is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with JasperReports. If not, see .
*/
package net.sf.jasperreports.engine.export.ooxml;
import java.io.IOException;
import java.io.Writer;
import java.util.List;
import java.util.Map;
import net.sf.jasperreports.engine.JRStyle;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReportsContext;
import net.sf.jasperreports.engine.design.JRDesignStyle;
import net.sf.jasperreports.engine.util.JRDataUtils;
/**
* @author Teodor Danciu ([email protected])
* @version $Id: DocxStyleHelper.java 5521 2012-07-30 13:25:30Z teodord $
*/
public class DocxStyleHelper extends BaseHelper
{
/**
*
*/
private DocxParagraphHelper paragraphHelper;
private DocxRunHelper runHelper;
/**
*
*/
public DocxStyleHelper(JasperReportsContext jasperReportsContext, Writer writer, Map fontMap, String exporterKey)
{
super(jasperReportsContext, writer);
paragraphHelper = new DocxParagraphHelper(jasperReportsContext, writer, false);
runHelper = new DocxRunHelper(jasperReportsContext, writer, fontMap, exporterKey);
}
/**
*
*/
public void export(List jasperPrintList) throws IOException
{
writer.write("\n");
writer.write("\n");
writer.write(" \n");
writer.write(" \n");
writer.write(" \n");
writer.write(" \n");
writer.write(" \n");
writer.write(" \n");
writer.write(" \n");
writer.write(" \n");
writer.write(" \n");
writer.write(" \n");
writer.write(" \n");
writer.write(" \n");
for(int reportIndex = 0; reportIndex < jasperPrintList.size(); reportIndex++)
{
JasperPrint jasperPrint = jasperPrintList.get(reportIndex);
String localeCode = jasperPrint.getLocaleCode();
if (reportIndex == 0)
{
JRDesignStyle style = new JRDesignStyle();
style.setName("EMPTY_CELL_STYLE");
style.setParentStyle(jasperPrint.getDefaultStyle());
style.setFontSize(0);
exportHeader(style);
paragraphHelper.exportProps(style);
runHelper.exportProps(style, (localeCode == null ? null : JRDataUtils.getLocale(localeCode)));//FIXMEDOCX reuse exporter
exportFooter();
}
JRStyle[] styles = jasperPrint.getStyles();
if (styles != null)
{
for(int i = 0; i < styles.length; i++)
{
JRStyle style = styles[i];
exportHeader(style);
paragraphHelper.exportProps(style);
runHelper.exportProps(style, (localeCode == null ? null : JRDataUtils.getLocale(localeCode)));//FIXMEDOCX reuse exporter
exportFooter();
}
}
}
writer.write(" \n");
}
/**
*
*/
private void exportHeader(JRStyle style) throws IOException
{
//writer.write(" \n");
writer.write(" \n");
writer.write(" \n");
writer.write(" \n");
String styleNameReference = style.getStyle() == null ? null : style.getStyle().getName();//FIXMEDOCX why getStyleNameReference is not working?
if (styleNameReference != null)
{
writer.write(" \n");
}
}
/**
*
*/
private void exportFooter() throws IOException
{
writer.write(" \n");
}
}