public void save(final OutputStream out, final String encoding)
throws IOException
{
// This print-writer will be flushed, but not closed, as closing the underlying stream is not desired here.
final PrintWriter writer = new PrintWriter(new OutputStreamWriter(out, encoding));
final AttributeList attList = new AttributeList();
attList.addNamespaceDeclaration("", ConfigEditorBoot.NAMESPACE); //$NON-NLS-1$
final DefaultTagDescription tagDescription = new DefaultTagDescription();
tagDescription.configure
(ConfigEditorBoot.getInstance().getGlobalConfig(), "org.pentaho.reporting.tools.configeditor.writer.");
final XmlWriter dwriter = new XmlWriter(writer, tagDescription);
dwriter.writeXmlDeclaration(encoding);
dwriter.writeTag(ConfigEditorBoot.NAMESPACE,
"config-description", attList, XmlWriterSupport.OPEN); //$NON-NLS-1$
final CharacterEntityParser parser = CharacterEntityParser.createXMLEntityParser();
for (int i = 0; i < getSize(); i++)
{
final ConfigDescriptionEntry entry = get(i);
final AttributeList p = new AttributeList();
p.setAttribute(ConfigEditorBoot.NAMESPACE, "name", entry.getKeyName()); //$NON-NLS-1$
p.setAttribute(ConfigEditorBoot.NAMESPACE, "global", String.valueOf(entry.isGlobal())); //$NON-NLS-1$
p.setAttribute(ConfigEditorBoot.NAMESPACE, "hidden", String.valueOf(entry.isHidden())); //$NON-NLS-1$
dwriter.writeTag(ConfigEditorBoot.NAMESPACE, "key", p, XmlWriterSupport.OPEN); //$NON-NLS-1$
if (entry.getDescription() != null)
{
dwriter.writeTag(ConfigEditorBoot.NAMESPACE, "description", XmlWriterSupport.OPEN); //$NON-NLS-1$
writer.write(parser.encodeEntities(entry.getDescription()));
dwriter.writeCloseTag();
}
if (entry instanceof ClassConfigDescriptionEntry)
{
final ClassConfigDescriptionEntry ce = (ClassConfigDescriptionEntry) entry;
if (ce.getBaseClass() != null)
{
dwriter.writeTag(ConfigEditorBoot.NAMESPACE, "class", "instanceof", //$NON-NLS-1$ //$NON-NLS-2$
ce.getBaseClass().getName(), XmlWriterSupport.CLOSE);
}
else
{
dwriter.writeTag(ConfigEditorBoot.NAMESPACE, "class", "instanceof", //$NON-NLS-1$ //$NON-NLS-2$
"java.lang.Object", XmlWriterSupport.CLOSE); //$NON-NLS-1$
}
}
else if (entry instanceof TextConfigDescriptionEntry)
{
dwriter.writeTag(ConfigEditorBoot.NAMESPACE, "text", //$NON-NLS-1$
new AttributeList(), XmlWriterSupport.CLOSE);
}
else if (entry instanceof EnumConfigDescriptionEntry)
{
final EnumConfigDescriptionEntry en = (EnumConfigDescriptionEntry) entry;
dwriter.writeTag(ConfigEditorBoot.NAMESPACE, "enum", XmlWriterSupport.OPEN); //$NON-NLS-1$