net.sf.jasperreports.engine.export.oasis.OasisZip Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jasperreports Show documentation
Show all versions of jasperreports Show documentation
Free Java Reporting Library
/*
* JasperReports - Free Java Reporting Library.
* Copyright (C) 2001 - 2019 TIBCO Software Inc. 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.oasis;
import java.io.IOException;
import java.io.Writer;
import net.sf.jasperreports.engine.export.zip.ExportZipEntry;
import net.sf.jasperreports.engine.export.zip.FileBufferedZip;
/**
* @author Teodor Danciu ([email protected])
*/
public abstract class OasisZip extends FileBufferedZip
{
/**
*
*/
public static final String MIME_TYPE_ODT = "text";
public static final String MIME_TYPE_ODS = "spreadsheet";
public static final String PROLOG = "\n";
/**
*
*/
private ExportZipEntry contentEntry;
private ExportZipEntry stylesEntry;
/**
* @deprecated To be removed.
*/
public OasisZip() throws IOException
{
this(MIME_TYPE_ODT);
}
/**
*
*/
public OasisZip(String mimeType) throws IOException
{
contentEntry = createEntry("content.xml");
createMetaEntry();
createSettingsEntry();
stylesEntry = createEntry("styles.xml");
createMimeEntry(mimeType);
createManifestEntry(mimeType);
}
/**
*
*/
public ExportZipEntry getContentEntry()
{
return contentEntry;
}
/**
*
*/
public ExportZipEntry getStylesEntry()
{
return stylesEntry;
}
/**
*
*/
private void createMimeEntry(String mimetype) throws IOException
{
ExportZipEntry mimeEntry = createEntry("mimetype");
Writer mimeWriter = null;
try
{
mimeWriter = mimeEntry.getWriter();
mimeWriter.write("application/vnd.oasis.opendocument." + mimetype);
mimeWriter.flush();
}
finally
{
if (mimeWriter != null)
{
try
{
mimeWriter.close();
}
catch (IOException e)
{
}
}
}
}
/**
*
*/
private void createManifestEntry(String mimetype) throws IOException
{
ExportZipEntry manifestEntry = createEntry("META-INF/manifest.xml");
Writer manifestWriter = null;
try
{
manifestWriter = manifestEntry.getWriter();
manifestWriter.write(PROLOG);
manifestWriter.write("\n");
manifestWriter.write("\n");
manifestWriter.write(" \n");
manifestWriter.write(" \n");
manifestWriter.write(" \n");
manifestWriter.write(" \n");
manifestWriter.write(" \n");
manifestWriter.write(" \n");
manifestWriter.write(" \n");
manifestWriter.write(" \n");
manifestWriter.write(" \n");
manifestWriter.write(" \n");
manifestWriter.flush();
}
finally
{
if (manifestWriter != null)
{
try
{
manifestWriter.close();
}
catch (IOException e)
{
}
}
}
}
/**
*
*/
private void createMetaEntry() throws IOException
{
ExportZipEntry metaEntry = createEntry("meta.xml");
Writer metaWriter = null;
try
{
metaWriter = metaEntry.getWriter();
metaWriter.write(PROLOG);
metaWriter.write(" ");
metaWriter.flush();
}
finally
{
if (metaWriter != null)
{
try
{
metaWriter.close();
}
catch (IOException e)
{
}
}
}
}
/**
*
*/
private void createSettingsEntry() throws IOException
{
ExportZipEntry settingsEntry = createEntry("settings.xml");
Writer settingsWriter = null;
try
{
settingsWriter = settingsEntry.getWriter();
settingsWriter.write(PROLOG);
settingsWriter.write("\n");
settingsWriter.flush();
}
finally
{
if (settingsWriter != null)
{
try
{
settingsWriter.close();
}
catch (IOException e)
{
}
}
}
}
}