001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /* $Id: MIFFile.java 426576 2006-07-28 15:44:37Z jeremias $ */
019:
020: package org.apache.fop.render.mif;
021:
022: // Java
023: import java.io.IOException;
024: import java.io.OutputStream;
025: import java.util.Iterator;
026: import java.util.List;
027:
028: /**
029: * The MIF File.
030: * This organises the MIF File and the corresponding elements.
031: * The catalog elements are used to setup the resources that
032: * are referenced.
033: */
034: public class MIFFile extends MIFElement {
035:
036: protected MIFElement colorCatalog = null;
037: protected PGFElement pgfCatalog = null;
038: protected MIFElement fontCatalog = null;
039: protected RulingElement rulingCatalog = null;
040: protected MIFElement tblCatalog = null;
041: protected MIFElement views = null;
042: protected MIFElement variableFormats = null;
043: protected MIFElement xRefFormats = null;
044: protected MIFElement document = null;
045: protected MIFElement bookComponent = null;
046: protected MIFElement initialAutoNums = null;
047: protected MIFElement aFrames = null;
048: protected MIFElement tbls = null;
049: protected List pages = new java.util.ArrayList();
050: protected List textFlows = null;
051:
052: public MIFFile() {
053: super ("");
054: valueElements = new java.util.ArrayList();
055: setup();
056: }
057:
058: /**
059: * Do some setup.
060: * Currently adds some dummy values to the resources.
061: */
062: protected void setup() {
063: MIFElement unit = new MIFElement("Units");
064: unit.setValue("Ucm");
065: addElement(unit);
066:
067: colorCatalog = new MIFElement("ColorCatalog");
068: MIFElement color = new MIFElement("Color");
069: MIFElement prop = new MIFElement("ColorTag");
070: prop.setValue("`Black'");
071: color.addElement(prop);
072: prop = new MIFElement("ColorCyan");
073: prop.setValue("0.000000");
074: color.addElement(prop);
075:
076: prop = new MIFElement("ColorMagenta");
077: prop.setValue("0.000000");
078: color.addElement(prop);
079: prop = new MIFElement("ColorYellow");
080: prop.setValue("0.000000");
081: color.addElement(prop);
082: prop = new MIFElement("ColorBlack");
083: prop.setValue("100.000000");
084: color.addElement(prop);
085: prop = new MIFElement("ColorAttribute");
086: prop.setValue("ColorIsBlack");
087: color.addElement(prop);
088: prop = new MIFElement("ColorAttribute");
089: prop.setValue("ColorIsReserved");
090: color.addElement(prop);
091: color.finish(true);
092:
093: colorCatalog.addElement(color);
094: addElement(colorCatalog);
095:
096: pgfCatalog = new PGFElement();
097: pgfCatalog.lookupElement(null);
098: addElement(pgfCatalog);
099:
100: rulingCatalog = new RulingElement();
101: rulingCatalog.lookupElement(null);
102: addElement(rulingCatalog);
103:
104: }
105:
106: public void output(OutputStream os) throws IOException {
107: if (finished) {
108: return;
109: }
110:
111: if (!started) {
112: os
113: .write(("<MIFFile 5.00> # Generated by FOP\n"/* + getVersion()*/)
114: .getBytes());
115: started = true;
116: }
117: boolean done = true;
118:
119: for (Iterator iter = valueElements.iterator(); iter.hasNext();) {
120: MIFElement el = (MIFElement) iter.next();
121: boolean d = el.output(os, 0);
122: if (d) {
123: iter.remove();
124: } else {
125: done = false;
126: break;
127: }
128: }
129: if (done && finish) {
130: os.write(("# end of MIFFile").getBytes());
131: }
132: }
133:
134: public void addPage(MIFElement p) {
135: pages.add(p);
136: addElement(p);
137: }
138: }
|