KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > render > mif > MIFFile


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 /* $Id: MIFFile.java 426576 2006-07-28 15:44:37Z jeremias $ */
19  
20 package org.apache.fop.render.mif;
21
22 // Java
23
import java.io.IOException JavaDoc;
24 import java.io.OutputStream JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.List JavaDoc;
27
28 /**
29  * The MIF File.
30  * This organises the MIF File and the corresponding elements.
31  * The catalog elements are used to setup the resources that
32  * are referenced.
33  */

34 public class MIFFile extends MIFElement {
35
36     protected MIFElement colorCatalog = null;
37     protected PGFElement pgfCatalog = null;
38     protected MIFElement fontCatalog = null;
39     protected RulingElement rulingCatalog = null;
40     protected MIFElement tblCatalog = null;
41     protected MIFElement views = null;
42     protected MIFElement variableFormats = null;
43     protected MIFElement xRefFormats = null;
44     protected MIFElement document = null;
45     protected MIFElement bookComponent = null;
46     protected MIFElement initialAutoNums = null;
47     protected MIFElement aFrames = null;
48     protected MIFElement tbls = null;
49     protected List JavaDoc pages = new java.util.ArrayList JavaDoc();
50     protected List JavaDoc textFlows = null;
51
52
53     public MIFFile() {
54         super("");
55         valueElements = new java.util.ArrayList JavaDoc();
56         setup();
57     }
58
59     /**
60      * Do some setup.
61      * Currently adds some dummy values to the resources.
62      */

63     protected void setup() {
64         MIFElement unit = new MIFElement("Units");
65         unit.setValue("Ucm");
66         addElement(unit);
67
68         colorCatalog = new MIFElement("ColorCatalog");
69         MIFElement color = new MIFElement("Color");
70         MIFElement prop = new MIFElement("ColorTag");
71         prop.setValue("`Black'");
72         color.addElement(prop);
73         prop = new MIFElement("ColorCyan");
74         prop.setValue("0.000000");
75         color.addElement(prop);
76
77         prop = new MIFElement("ColorMagenta");
78         prop.setValue("0.000000");
79         color.addElement(prop);
80         prop = new MIFElement("ColorYellow");
81         prop.setValue("0.000000");
82         color.addElement(prop);
83         prop = new MIFElement("ColorBlack");
84         prop.setValue("100.000000");
85         color.addElement(prop);
86         prop = new MIFElement("ColorAttribute");
87         prop.setValue("ColorIsBlack");
88         color.addElement(prop);
89         prop = new MIFElement("ColorAttribute");
90         prop.setValue("ColorIsReserved");
91         color.addElement(prop);
92         color.finish(true);
93
94         colorCatalog.addElement(color);
95         addElement(colorCatalog);
96
97         pgfCatalog = new PGFElement();
98         pgfCatalog.lookupElement(null);
99         addElement(pgfCatalog);
100
101         rulingCatalog = new RulingElement();
102         rulingCatalog.lookupElement(null);
103         addElement(rulingCatalog);
104
105     }
106
107     public void output(OutputStream JavaDoc os) throws IOException JavaDoc {
108         if (finished) {
109             return;
110         }
111
112         if (!started) {
113             os.write(("<MIFFile 5.00> # Generated by FOP\n"/* + getVersion()*/).getBytes());
114             started = true;
115         }
116         boolean done = true;
117
118         for (Iterator JavaDoc iter = valueElements.iterator(); iter.hasNext();) {
119             MIFElement el = (MIFElement)iter.next();
120             boolean d = el.output(os, 0);
121             if (d) {
122                 iter.remove();
123             } else {
124                 done = false;
125                 break;
126             }
127         }
128         if (done && finish) {
129             os.write(("# end of MIFFile").getBytes());
130         }
131     }
132
133     public void addPage(MIFElement p) {
134         pages.add(p);
135         addElement(p);
136     }
137 }
138
139
Popular Tags