You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MIFFile.java 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. /* $Id$ */
  18. package org.apache.fop.render.mif;
  19. // Java
  20. import java.io.IOException;
  21. import java.io.OutputStream;
  22. import java.util.Iterator;
  23. import java.util.List;
  24. /**
  25. * The MIF File.
  26. * This organises the MIF File and the corresponding elements.
  27. * The catalog elements are used to setup the resources that
  28. * are referenced.
  29. */
  30. public class MIFFile extends MIFElement {
  31. /** colorCatalog */
  32. protected MIFElement colorCatalog;
  33. /** pgfCatalog */
  34. protected PGFElement pgfCatalog;
  35. /** fontCatalog */
  36. // protected MIFElement fontCatalog;
  37. /** rulingCatalog */
  38. protected RulingElement rulingCatalog;
  39. /** tblCatalog */
  40. // protected MIFElement tblCatalog;
  41. /** views */
  42. // protected MIFElement views;
  43. /** variableFormats */
  44. // protected MIFElement variableFormats;
  45. /** xRefFormats */
  46. // protected MIFElement xRefFormats;
  47. /** document */
  48. // protected MIFElement document;
  49. /** bookComponent */
  50. // protected MIFElement bookComponent;
  51. /** initialAutoNums */
  52. // protected MIFElement initialAutoNums;
  53. /** aFrames */
  54. // protected MIFElement aFrames;
  55. /** tbls */
  56. // protected MIFElement tbls;
  57. /** pages */
  58. protected List pages = new java.util.ArrayList();
  59. /** textFlows */
  60. // protected List textFlows;
  61. /** default constructor */
  62. public MIFFile() {
  63. super("");
  64. valueElements = new java.util.ArrayList();
  65. setup();
  66. }
  67. /**
  68. * Do some setup.
  69. * Currently adds some dummy values to the resources.
  70. */
  71. protected void setup() {
  72. MIFElement unit = new MIFElement("Units");
  73. unit.setValue("Ucm");
  74. addElement(unit);
  75. colorCatalog = new MIFElement("ColorCatalog");
  76. MIFElement color = new MIFElement("Color");
  77. MIFElement prop = new MIFElement("ColorTag");
  78. prop.setValue("`Black'");
  79. color.addElement(prop);
  80. prop = new MIFElement("ColorCyan");
  81. prop.setValue("0.000000");
  82. color.addElement(prop);
  83. prop = new MIFElement("ColorMagenta");
  84. prop.setValue("0.000000");
  85. color.addElement(prop);
  86. prop = new MIFElement("ColorYellow");
  87. prop.setValue("0.000000");
  88. color.addElement(prop);
  89. prop = new MIFElement("ColorBlack");
  90. prop.setValue("100.000000");
  91. color.addElement(prop);
  92. prop = new MIFElement("ColorAttribute");
  93. prop.setValue("ColorIsBlack");
  94. color.addElement(prop);
  95. prop = new MIFElement("ColorAttribute");
  96. prop.setValue("ColorIsReserved");
  97. color.addElement(prop);
  98. color.finish(true);
  99. colorCatalog.addElement(color);
  100. addElement(colorCatalog);
  101. pgfCatalog = new PGFElement();
  102. pgfCatalog.lookupElement(null);
  103. addElement(pgfCatalog);
  104. rulingCatalog = new RulingElement();
  105. rulingCatalog.lookupElement(null);
  106. addElement(rulingCatalog);
  107. }
  108. /**
  109. * @param os output stream
  110. * @throws IOException if not caught
  111. */
  112. public void output(OutputStream os) throws IOException {
  113. if (finished) {
  114. return;
  115. }
  116. if (!started) {
  117. os.write(("<MIFFile 5.00> # Generated by FOP\n"/* + getVersion()*/).getBytes());
  118. started = true;
  119. }
  120. boolean done = true;
  121. for (Iterator iter = valueElements.iterator(); iter.hasNext();) {
  122. MIFElement el = (MIFElement)iter.next();
  123. boolean d = el.output(os, 0);
  124. if (d) {
  125. iter.remove();
  126. } else {
  127. done = false;
  128. break;
  129. }
  130. }
  131. if (done && finish) {
  132. os.write(("# end of MIFFile").getBytes());
  133. }
  134. }
  135. /** @param p a page element to add */
  136. public void addPage(MIFElement p) {
  137. pages.add(p);
  138. addElement(p);
  139. }
  140. }