Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / reportbuilder / java / com / sun / star / report / util / ManifestWriter.java
blobf1b6f7a56ab329e04b9fa885191a03319e3cd3d5
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
27 package com.sun.star.report.util;
29 import com.sun.star.report.OutputRepository;
31 import java.io.IOException;
32 import java.io.OutputStream;
33 import java.io.OutputStreamWriter;
35 import java.util.HashMap;
36 import java.util.Iterator;
37 import java.util.Map;
39 import org.jfree.report.JFreeReportBoot;
41 import org.pentaho.reporting.libraries.xmlns.common.AttributeList;
42 import org.pentaho.reporting.libraries.xmlns.writer.DefaultTagDescription;
43 import org.pentaho.reporting.libraries.xmlns.writer.XmlWriter;
44 import org.pentaho.reporting.libraries.xmlns.writer.XmlWriterSupport;
47 /**
48 * Creation-Date: 24.07.2007, 18:16:52
50 * @author Thomas Morgner
52 public class ManifestWriter
54 // need this two strings other it breaks the ooo build :-(
56 public static final String MANIFEST_NS = "urn:oasis:names:tc:opendocument:xmlns:manifest:1.0";
57 public static final String TAG_DEF_PREFIX = "com.sun.star.report.pentaho.output.";
58 private final Map entries;
60 public ManifestWriter()
62 entries = new HashMap();
65 public void addEntry(final String fullPath, final String mimeType)
67 if (fullPath == null)
69 throw new NullPointerException();
71 if (mimeType == null)
73 throw new NullPointerException();
75 if ("META-INF/manifest.xml".equals(fullPath))
77 return;
79 entries.put(fullPath, mimeType);
82 public boolean isEmpty()
84 return entries.isEmpty();
87 public void write(final OutputRepository outputRepository) throws IOException
89 if (isEmpty())
91 return;
94 final DefaultTagDescription tagDescription = new DefaultTagDescription();
95 tagDescription.configure(JFreeReportBoot.getInstance().getGlobalConfig(),
96 TAG_DEF_PREFIX);
98 final OutputStream manifestOutputStream =
99 outputRepository.createOutputStream("META-INF/manifest.xml", "text/xml");
101 final OutputStreamWriter writer = new OutputStreamWriter(manifestOutputStream, "UTF-8");
102 final XmlWriter xmlWriter = new XmlWriter(writer, tagDescription);
103 xmlWriter.setAlwaysAddNamespace(true);
104 xmlWriter.writeXmlDeclaration("UTF-8");
106 final AttributeList rootAttributes = new AttributeList();
107 rootAttributes.addNamespaceDeclaration("manifest", MANIFEST_NS);
108 xmlWriter.writeTag(MANIFEST_NS, "manifest", rootAttributes, XmlWriterSupport.OPEN);
110 final Iterator iterator = entries.entrySet().iterator();
111 while (iterator.hasNext())
113 final Map.Entry entry = (Map.Entry) iterator.next();
114 final AttributeList entryAttrs = new AttributeList();
115 entryAttrs.setAttribute(MANIFEST_NS, "media-type", (String) entry.getValue());
116 entryAttrs.setAttribute(MANIFEST_NS, "full-path", (String) entry.getKey());
117 xmlWriter.writeTag(MANIFEST_NS, "file-entry", entryAttrs, XmlWriterSupport.CLOSE);
120 xmlWriter.writeCloseTag();
121 xmlWriter.close();