001: /*
002: * ============================================================================
003: * GNU Lesser General Public License
004: * ============================================================================
005: *
006: * JasperReports - Free Java report-generating library.
007: * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com
008: *
009: * This library is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU Lesser General Public
011: * License as published by the Free Software Foundation; either
012: * version 2.1 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: * Lesser General Public License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
022: *
023: * JasperSoft Corporation
024: * 303 Second Street, Suite 450 North
025: * San Francisco, CA 94107
026: * http://www.jaspersoft.com
027: */
028:
029: /*
030: * Special thanks to Google 'Summer of Code 2005' program for supporting this development
031: *
032: * Contributors:
033: * Majid Ali Khan - majidkk@users.sourceforge.net
034: * Frank Schönheit - Frank.Schoenheit@Sun.COM
035: */
036: package net.sf.jasperreports.engine.export.oasis;
037:
038: import java.io.IOException;
039: import java.io.Writer;
040: import java.util.Collection;
041: import java.util.Iterator;
042:
043: import net.sf.jasperreports.engine.export.oasis.zip.OasisZipEntry;
044:
045: /**
046: * @author Teodor Danciu (teodord@users.sourceforge.net)
047: * @version $Id: ContentBuilder.java 1745 2007-06-11 15:13:18Z teodord $
048: */
049: public class ContentBuilder {
050: /**
051: *
052: */
053: public static final String VERSION = "1.0";
054:
055: /**
056: *
057: */
058: private OasisZipEntry contentEntry = null;
059: private OasisZipEntry styleEntry = null;
060: private OasisZipEntry bodyEntry = null;
061:
062: private Collection fontFaces = null;
063:
064: /**
065: *
066: */
067: public ContentBuilder(OasisZipEntry contentEntry,
068: OasisZipEntry styleEntry, OasisZipEntry bodyEntry,
069: Collection fontFaces) {
070: this .contentEntry = contentEntry;
071: this .styleEntry = styleEntry;
072: this .bodyEntry = bodyEntry;
073: this .fontFaces = fontFaces;
074: }
075:
076: public void build() throws IOException {
077: Writer writer = contentEntry.getWriter();
078:
079: writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
080:
081: writer.write("<office:document-content");
082: writer
083: .write(" xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\"");
084: writer
085: .write(" xmlns:style=\"urn:oasis:names:tc:opendocument:xmlns:style:1.0\"");
086: writer
087: .write(" xmlns:text=\"urn:oasis:names:tc:opendocument:xmlns:text:1.0\"");
088: writer
089: .write(" xmlns:table=\"urn:oasis:names:tc:opendocument:xmlns:table:1.0\"");
090: writer
091: .write(" xmlns:draw=\"urn:oasis:names:tc:opendocument:xmlns:drawing:1.0\"");
092: writer
093: .write(" xmlns:fo=\"urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0\"");
094: writer.write(" xmlns:xlink=\"http://www.w3.org/1999/xlink\"");
095: writer.write(" xmlns:dc=\"http://purl.org/dc/elements/1.1/\"");
096: writer
097: .write(" xmlns:meta=\"urn:oasis:names:tc:opendocument:xmlns:meta:1.0\"");
098: writer
099: .write(" xmlns:number=\"urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0\"");
100: writer
101: .write(" xmlns:svg=\"urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0\"");
102: writer
103: .write(" xmlns:chart=\"urn:oasis:names:tc:opendocument:xmlns:chart:1.0\"");
104: writer
105: .write(" xmlns:dr3d=\"urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0\"");
106: writer
107: .write(" xmlns:math=\"http://www.w3.org/1998/Math/MathML\"");
108: writer
109: .write(" xmlns:form=\"urn:oasis:names:tc:opendocument:xmlns:form:1.0\"");
110: writer
111: .write(" xmlns:script=\"urn:oasis:names:tc:opendocument:xmlns:script:1.0\"");
112: writer
113: .write(" xmlns:ooo=\"http://openoffice.org/2004/office\"");
114: writer
115: .write(" xmlns:ooow=\"http://openoffice.org/2004/writer\"");
116: writer.write(" xmlns:oooc=\"http://openoffice.org/2004/calc\"");
117: writer
118: .write(" xmlns:dom=\"http://www.w3.org/2001/xml-events\"");
119: writer.write(" xmlns:xforms=\"http://www.w3.org/2002/xforms\"");
120: writer.write(" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"");
121: writer
122: .write(" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");
123: writer.write(" office:version=\"");
124: writer.write(VERSION);
125: writer.write("\">\n");
126:
127: writer.write(" <office:scripts/>\n");
128:
129: writer.write(" <office:font-face-decls>\n");
130: if (fontFaces != null) {
131: for (Iterator it = fontFaces.iterator(); it.hasNext();) {
132: String fontFace = (String) it.next();
133: writer.write("<style:font-face style:name=\""
134: + fontFace + "\"");
135: writer.write(" svg:font-family=\"" + fontFace + "\"");
136: writer.write("/>\n");
137: }
138: }
139: writer.write(" </office:font-face-decls>\n");
140:
141: writer.write(" <office:automatic-styles>\n");
142:
143: writer.flush();
144: styleEntry.writeData(contentEntry.getOutputStream());
145:
146: writer
147: .write(" <style:style style:name=\"empty-cell\" style:family=\"table-cell\">\n");
148: writer
149: .write(" <style:table-cell-properties fo:wrap-option=\"wrap\" style:shrink-to-fit=\"false\"");
150: writer.write(" fo:border=\"0in solid #000000\"/>\n");
151: writer.write(" </style:style>\n");
152: writer.write(" </office:automatic-styles>\n");
153:
154: writer.write("<office:body><office:text>\n");
155: writer.flush();
156: bodyEntry.writeData(contentEntry.getOutputStream());
157: writer.write("</office:text></office:body>\n");
158:
159: writer.write("</office:document-content>\n");
160:
161: writer.flush();
162: writer.close();
163: }
164:
165: }
|