/*
* This program is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software
* Foundation.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
* or from the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* This program 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.
*
* Copyright (c) 2001 - 2009 Object Refinery Ltd, Pentaho Corporation and Contributors.. All rights reserved.
*/
package org.pentaho.reporting.engine.classic.core.modules.parser.bundle.writer;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import org.pentaho.reporting.engine.classic.core.ClassicEngineBoot;
import org.pentaho.reporting.engine.classic.core.modules.parser.bundle.BundleNamespaces;
import org.pentaho.reporting.engine.classic.core.modules.parser.bundle.BundleXmlModule;
import org.pentaho.reporting.libraries.base.config.Configuration;
import org.pentaho.reporting.libraries.docbundle.WriteableDocumentBundle;
import org.pentaho.reporting.libraries.xmlns.common.AttributeList;
import org.pentaho.reporting.libraries.xmlns.writer.DefaultTagDescription;
import org.pentaho.reporting.libraries.xmlns.writer.XmlWriter;
import org.pentaho.reporting.libraries.xmlns.writer.XmlWriterSupport;
/**
* The content file is included exactly once in each bundle. This file orchestates the parsing process.
*
* @author Thomas Morgner
*/
public class ContentFileWriter implements BundleWriterHandler
{
public ContentFileWriter()
{
}
/**
* Returns a relatively high processing order indicating this BundleWriterHandler should be one of the last processed
* @return the relative processing order for this BundleWriterHandler
*/
public int getProcessingOrder()
{
return 100000;
}
public String writeReport(final WriteableDocumentBundle bundle,
final BundleWriterState state)
throws IOException, BundleWriterException
{
if (bundle == null)
{
throw new NullPointerException();
}
if (state == null)
{
throw new NullPointerException();
}
final BundleWriterState contentFileState = new BundleWriterState(state, "content.xml");
final OutputStream outputStream = new BufferedOutputStream(bundle.createEntry(contentFileState.getFileName(),
"text/xml"));
final Configuration globalConfig = ClassicEngineBoot.getInstance().getGlobalConfig();
final DefaultTagDescription tagDescription = new DefaultTagDescription(globalConfig,
BundleXmlModule.TAG_DEF_PREFIX);
final XmlWriter writer = new XmlWriter
(new OutputStreamWriter(outputStream, "UTF-8"), tagDescription, " ", "\n");
writer.writeXmlDeclaration("UTF-8");
final AttributeList rootAttributes = new AttributeList();
rootAttributes.addNamespaceDeclaration("", BundleNamespaces.CONTENT);
writer.writeTag(BundleNamespaces.CONTENT, "content", rootAttributes, XmlWriterSupport.OPEN);
writer.writeComment(" The content.xml file remains intentionally empty. This file can be used to ");
writer.writeComment(" inject global templates later. ");
writer.writeCloseTag();
writer.close();
return contentFileState.getFileName();
}
}