1 17 18 19 20 package org.apache.fop.render.mif; 21 22 import java.io.IOException ; 24 import java.io.OutputStream ; 25 import java.util.Iterator ; 26 import java.util.List ; 27 28 33 public class MIFElement { 34 protected String name; 35 protected String valueStr = null; 36 protected List valueElements = null; 37 38 protected boolean started = false; 39 protected boolean finish = false; 40 protected boolean finished = false; 41 42 44 public MIFElement(String n) { 45 name = n; 46 } 47 48 public void setValue(String str) { 49 valueStr = str; 50 } 51 52 public void addElement(MIFElement el) { 53 if (valueElements == null) { 54 valueElements = new java.util.ArrayList (); 55 } 56 valueElements.add(el); 57 } 58 59 66 public boolean output(OutputStream os, int indent) throws IOException { 67 if (finished) { 68 return true; 69 } 70 if (valueElements == null && valueStr == null) { 71 return false; 72 } 73 74 String indentStr = ""; 75 for (int c = 0; c < indent; c++) { 76 indentStr += " "; 77 } 78 if (!started) { 79 os.write((indentStr + "<" + name).getBytes()); 80 if (valueElements != null) { 81 os.write(("\n").getBytes()); 82 } 83 started = true; 84 } 85 if (valueElements != null) { 86 boolean done = true; 87 for (Iterator iter = valueElements.iterator(); iter.hasNext();) { 88 MIFElement el = (MIFElement)iter.next(); 89 boolean d = el.output(os, indent + 1); 90 if (d) { 91 iter.remove(); 92 } else { 93 done = false; 94 break; 95 } 96 } 97 if (!finish || !done) { 98 return false; 99 } 100 os.write((indentStr + "> # end of " + name + "\n").getBytes()); 101 } else { 102 os.write((" " + valueStr + ">\n").getBytes()); 103 } 104 finished = true; 105 return true; 106 } 107 108 public void finish(boolean deep) { 109 finish = true; 110 if (deep && valueElements != null) { 111 for (Iterator iter = valueElements.iterator(); iter.hasNext();) { 112 MIFElement el = (MIFElement)iter.next(); 113 el.finish(deep); 114 } 115 } 116 } 117 } 118 119 | Popular Tags |