1 17 18 19 20 package org.apache.fop.render.mif; 21 22 import java.io.IOException ; 24 import java.io.OutputStream ; 25 26 import org.apache.commons.logging.Log; 27 import org.apache.commons.logging.LogFactory; 28 import org.apache.fop.apps.FOUserAgent; 29 import org.apache.fop.fo.FOEventHandler; 30 import org.apache.fop.fo.flow.BasicLink; 31 import org.apache.fop.fo.flow.Block; 32 import org.apache.fop.fo.flow.ExternalGraphic; 33 import org.apache.fop.fo.flow.Footnote; 34 import org.apache.fop.fo.flow.FootnoteBody; 35 import org.apache.fop.fo.flow.InstreamForeignObject; 36 import org.apache.fop.fo.flow.Inline; 37 import org.apache.fop.fo.flow.Leader; 38 import org.apache.fop.fo.flow.ListBlock; 39 import org.apache.fop.fo.flow.ListItem; 40 import org.apache.fop.fo.flow.PageNumber; 41 import org.apache.fop.fo.flow.Table; 42 import org.apache.fop.fo.flow.TableBody; 43 import org.apache.fop.fo.flow.TableCell; 44 import org.apache.fop.fo.flow.TableColumn; 45 import org.apache.fop.fo.flow.TableRow; 46 import org.apache.fop.fo.pagination.Flow; 47 import org.apache.fop.fo.pagination.PageSequence; 48 import org.apache.fop.fo.pagination.PageSequenceMaster; 49 import org.apache.fop.fo.pagination.SimplePageMaster; 50 import org.apache.fop.fonts.FontSetup; 51 import org.apache.fop.render.DefaultFontResolver; 52 import org.xml.sax.SAXException ; 53 54 56 62 public class MIFHandler extends FOEventHandler { 63 64 65 private static Log log = LogFactory.getLog(MIFHandler.class); 66 67 68 protected MIFFile mifFile; 69 70 71 protected OutputStream outStream; 72 73 private MIFElement textFlow; 75 private MIFElement para; 76 77 82 public MIFHandler(FOUserAgent ua, OutputStream os) { 83 super(ua); 84 outStream = os; 85 FontSetup.setup(fontInfo, null, new DefaultFontResolver(ua)); 86 } 87 88 91 public void startDocument() throws SAXException { 92 log.fatal("The MIF Handler is non-functional at this time. Please help resurrect it!"); 93 mifFile = new MIFFile(); 94 try { 95 mifFile.output(outStream); 96 } catch (IOException ioe) { 97 throw new SAXException (ioe); 98 } 99 } 100 101 104 public void endDocument() throws SAXException { 105 mifFile.finish(true); 107 try { 108 mifFile.output(outStream); 109 outStream.flush(); 110 } catch (IOException ioe) { 111 throw new SAXException (ioe); 112 } 113 } 114 115 121 public void startPageSequence(PageSequence pageSeq) { 122 String name = pageSeq.getMasterReference(); 125 SimplePageMaster spm = pageSeq.getRoot().getLayoutMasterSet().getSimplePageMaster(name); 126 if (spm == null) { 127 PageSequenceMaster psm = pageSeq.getRoot().getLayoutMasterSet().getPageSequenceMaster(name); 128 } else { 129 MIFElement prop = new MIFElement("PageType"); 131 prop.setValue("BodyPage"); 132 133 MIFElement page = new MIFElement("Page"); 134 page.addElement(prop); 135 136 prop = new MIFElement("PageBackground"); 137 prop.setValue("'Default'"); 138 page.addElement(prop); 139 140 MIFElement textRect = new MIFElement("TextRect"); 142 prop = new MIFElement("ID"); 143 prop.setValue("1"); 144 textRect.addElement(prop); 145 prop = new MIFElement("ShapeRect"); 146 prop.setValue("0.0 841.889 453.543 0.0"); 147 textRect.addElement(prop); 148 page.addElement(textRect); 149 150 textRect = new MIFElement("TextRect"); 151 prop = new MIFElement("ID"); 152 prop.setValue("2"); 153 textRect.addElement(prop); 154 prop = new MIFElement("ShapeRect"); 155 prop.setValue("0.0 841.889 453.543 187.65"); 156 textRect.addElement(prop); 157 page.addElement(textRect); 158 159 mifFile.addPage(page); 160 } 161 } 162 163 166 public void endPageSequence(PageSequence pageSeq) { 167 } 168 169 172 public void startFlow(Flow fl) { 173 textFlow = new MIFElement("TextFlow"); 175 } 176 177 180 public void endFlow(Flow fl) { 181 textFlow.finish(true); 182 mifFile.addElement(textFlow); 183 textFlow = null; 184 } 185 186 189 public void startBlock(Block bl) { 190 para = new MIFElement("Para"); 191 textFlow.addElement(para); 193 } 194 195 198 public void endBlock(Block bl) { 199 para.finish(true); 200 para = null; 201 } 202 203 207 public void startInline(Inline inl){ 208 } 209 210 214 public void endInline(Inline inl){ 215 } 216 217 220 public void startTable(Table tbl) { 221 } 222 223 226 public void endTable(Table tbl) { 227 } 228 229 233 public void startColumn(TableColumn tc) { 234 } 235 236 240 public void endColumn(TableColumn tc) { 241 } 242 243 246 public void startHeader(TableBody th) { 247 } 248 249 252 public void endHeader(TableBody th) { 253 } 254 255 258 public void startFooter(TableBody tf) { 259 } 260 261 264 public void endFooter(TableBody tf) { 265 } 266 267 270 public void startBody(TableBody tb) { 271 } 272 273 276 public void endBody(TableBody tb) { 277 } 278 279 282 public void startRow(TableRow tr) { 283 } 284 285 288 public void endRow(TableRow tr) { 289 } 290 291 294 public void startCell(TableCell tc) { 295 } 296 297 300 public void endCell(TableCell tc) { 301 } 302 303 307 public void startList(ListBlock lb) { 308 } 309 310 313 public void endList(ListBlock lb) { 314 } 315 316 319 public void startListItem(ListItem li) { 320 } 321 322 325 public void endListItem(ListItem li) { 326 } 327 328 331 public void startListLabel() { 332 } 333 334 337 public void endListLabel() { 338 } 339 340 343 public void startListBody() { 344 } 345 346 349 public void endListBody() { 350 } 351 352 356 public void startStatic() { 357 } 358 359 362 public void endStatic() { 363 } 364 365 368 public void startMarkup() { 369 } 370 371 374 public void endMarkup() { 375 } 376 377 380 public void startLink(BasicLink basicLink) { 381 } 382 383 386 public void endLink() { 387 } 388 389 392 public void image(ExternalGraphic eg) { 393 } 394 395 398 public void pageRef() { 399 } 400 401 404 public void foreignObject(InstreamForeignObject ifo) { 405 } 406 407 410 public void startFootnote(Footnote footnote) { 411 } 412 413 416 public void endFootnote(Footnote footnote) { 417 } 418 419 422 public void startFootnoteBody(FootnoteBody body) { 423 } 424 425 428 public void endFootnoteBody(FootnoteBody body) { 429 } 430 431 434 public void leader(Leader l) { 435 } 436 437 440 public void characters(char data[], int start, int length) { 441 if (para != null) { 442 String str = new String (data, start, length); 443 str = str.trim(); 444 if (str.length() == 0) { 446 return; 447 } 448 449 MIFElement line = new MIFElement("ParaLine"); 450 MIFElement prop = new MIFElement("TextRectID"); 451 prop.setValue("2"); 452 line.addElement(prop); 453 prop = new MIFElement("String"); 454 prop.setValue("\"" + str + "\""); 455 line.addElement(prop); 456 457 para.addElement(line); 458 } 459 } 460 461 465 public void startPageNumber(PageNumber pagenum) { 466 } 467 468 472 public void endPageNumber(PageNumber pagenum) { 473 } 474 } 475 476 | Popular Tags |