1 17 18 19 20 package org.apache.fop.layoutmgr; 21 22 import java.util.ArrayList ; 23 import java.util.Map ; 24 import java.util.HashMap ; 25 import java.util.List ; 26 import java.util.Iterator ; 27 28 import org.apache.commons.logging.Log; 29 import org.apache.commons.logging.LogFactory; 30 31 import org.apache.fop.fo.FONode; 32 import org.apache.fop.fo.FOText; 33 import org.apache.fop.fo.FObjMixed; 34 import org.apache.fop.fo.flow.BasicLink; 35 import org.apache.fop.fo.flow.BidiOverride; 36 import org.apache.fop.fo.flow.Block; 37 import org.apache.fop.fo.flow.BlockContainer; 38 import org.apache.fop.fo.flow.Character; 39 import org.apache.fop.fo.flow.ExternalGraphic; 40 import org.apache.fop.fo.flow.Footnote; 41 import org.apache.fop.fo.flow.Inline; 42 import org.apache.fop.fo.flow.InlineLevel; 43 import org.apache.fop.fo.flow.InlineContainer; 44 import org.apache.fop.fo.flow.InstreamForeignObject; 45 import org.apache.fop.fo.flow.Leader; 46 import org.apache.fop.fo.flow.ListBlock; 47 import org.apache.fop.fo.flow.ListItem; 48 import org.apache.fop.fo.flow.PageNumber; 49 import org.apache.fop.fo.flow.PageNumberCitation; 50 import org.apache.fop.fo.flow.PageNumberCitationLast; 51 import org.apache.fop.fo.flow.RetrieveMarker; 52 import org.apache.fop.fo.flow.Table; 53 import org.apache.fop.fo.flow.TableBody; 54 import org.apache.fop.fo.flow.TableCell; 55 import org.apache.fop.fo.flow.TableColumn; 56 import org.apache.fop.fo.flow.TableFooter; 57 import org.apache.fop.fo.flow.TableHeader; 58 import org.apache.fop.fo.flow.TableRow; 59 import org.apache.fop.fo.flow.Wrapper; 60 import org.apache.fop.fo.pagination.Flow; 61 import org.apache.fop.fo.pagination.PageSequence; 62 import org.apache.fop.fo.pagination.SideRegion; 63 import org.apache.fop.fo.pagination.StaticContent; 64 import org.apache.fop.fo.pagination.Title; 65 import org.apache.fop.area.AreaTreeHandler; 66 67 import org.apache.fop.layoutmgr.inline.BasicLinkLayoutManager; 68 import org.apache.fop.layoutmgr.inline.BidiLayoutManager; 69 import org.apache.fop.layoutmgr.inline.CharacterLayoutManager; 70 import org.apache.fop.layoutmgr.inline.ContentLayoutManager; 71 import org.apache.fop.layoutmgr.inline.ExternalGraphicLayoutManager; 72 import org.apache.fop.layoutmgr.inline.FootnoteLayoutManager; 73 import org.apache.fop.layoutmgr.inline.ICLayoutManager; 74 import org.apache.fop.layoutmgr.inline.InlineLayoutManager; 75 import org.apache.fop.layoutmgr.inline.InlineLevelLayoutManager; 76 import org.apache.fop.layoutmgr.inline.InstreamForeignObjectLM; 77 import org.apache.fop.layoutmgr.inline.LeaderLayoutManager; 78 import org.apache.fop.layoutmgr.inline.PageNumberCitationLayoutManager; 79 import org.apache.fop.layoutmgr.inline.PageNumberCitationLastLayoutManager; 80 import org.apache.fop.layoutmgr.inline.PageNumberLayoutManager; 81 import org.apache.fop.layoutmgr.inline.TextLayoutManager; 82 import org.apache.fop.layoutmgr.inline.WrapperLayoutManager; 83 import org.apache.fop.layoutmgr.list.ListBlockLayoutManager; 84 import org.apache.fop.layoutmgr.list.ListItemLayoutManager; 85 import org.apache.fop.layoutmgr.table.TableLayoutManager; 86 import org.apache.fop.util.CharUtilities; 87 88 91 public class LayoutManagerMapping implements LayoutManagerMaker { 92 93 94 protected static Log log = LogFactory.getLog(LayoutManagerMapping.class); 95 96 97 private Map makers = new HashMap (); 98 99 public LayoutManagerMapping() { 100 initialize(); 101 } 102 103 106 protected void initialize() { 107 makers.put(FOText.class, new FOTextLayoutManagerMaker()); 108 makers.put(FObjMixed.class, new Maker()); 109 makers.put(BidiOverride.class, new BidiOverrideLayoutManagerMaker()); 110 makers.put(Inline.class, new InlineLayoutManagerMaker()); 111 makers.put(Footnote.class, new FootnodeLayoutManagerMaker()); 112 makers.put(InlineContainer.class, 113 new InlineContainerLayoutManagerMaker()); 114 makers.put(BasicLink.class, new BasicLinkLayoutManagerMaker()); 115 makers.put(Block.class, new BlockLayoutManagerMaker()); 116 makers.put(Leader.class, new LeaderLayoutManagerMaker()); 117 makers.put(RetrieveMarker.class, new RetrieveMarkerLayoutManagerMaker()); 118 makers.put(Character .class, new CharacterLayoutManagerMaker()); 119 makers.put(ExternalGraphic.class, 120 new ExternalGraphicLayoutManagerMaker()); 121 makers.put(BlockContainer.class, 122 new BlockContainerLayoutManagerMaker()); 123 makers.put(ListItem.class, new ListItemLayoutManagerMaker()); 124 makers.put(ListBlock.class, new ListBlockLayoutManagerMaker()); 125 makers.put(InstreamForeignObject.class, 126 new InstreamForeignObjectLayoutManagerMaker()); 127 makers.put(PageNumber.class, new PageNumberLayoutManagerMaker()); 128 makers.put(PageNumberCitation.class, 129 new PageNumberCitationLayoutManagerMaker()); 130 makers.put(PageNumberCitationLast.class, 131 new PageNumberCitationLastLayoutManagerMaker()); 132 makers.put(Table.class, new TableLayoutManagerMaker()); 133 makers.put(TableBody.class, new Maker()); 134 makers.put(TableColumn.class, new Maker()); 135 makers.put(TableRow.class, new Maker()); 136 makers.put(TableCell.class, new Maker()); 137 makers.put(TableFooter.class, new Maker()); 138 makers.put(TableHeader.class, new Maker()); 139 makers.put(Wrapper.class, new WrapperLayoutManagerMaker()); 140 makers.put(Title.class, new InlineLayoutManagerMaker()); 141 } 142 143 146 public void makeLayoutManagers(FONode node, List lms) { 147 Maker maker = (Maker) makers.get(node.getClass()); 148 if (maker == null) { 149 log.error("No LayoutManager maker for class " + node.getClass()); 150 } else { 151 maker.make(node, lms); 152 } 153 } 154 155 158 public LayoutManager makeLayoutManager(FONode node) { 159 List lms = new ArrayList (); 160 makeLayoutManagers(node, lms); 161 if (lms.size() == 0) { 162 throw new IllegalStateException ("LayoutManager for class " 163 + node.getClass() 164 + " is missing."); 165 } else if (lms.size() > 1) { 166 throw new IllegalStateException ("Duplicate LayoutManagers for class " 167 + node.getClass() 168 + " found, only one may be declared."); 169 } 170 return (LayoutManager) lms.get(0); 171 } 172 173 public PageSequenceLayoutManager makePageSequenceLayoutManager( 174 AreaTreeHandler ath, PageSequence ps) { 175 return new PageSequenceLayoutManager(ath, ps); 176 } 177 178 181 public FlowLayoutManager makeFlowLayoutManager( 182 PageSequenceLayoutManager pslm, Flow flow) { 183 return new FlowLayoutManager(pslm, flow); 184 } 185 186 189 public ContentLayoutManager makeContentLayoutManager(PageSequenceLayoutManager pslm, 190 Title title) { 191 return new ContentLayoutManager(pslm, title); 192 } 193 194 197 public StaticContentLayoutManager makeStaticContentLayoutManager( 198 PageSequenceLayoutManager pslm, StaticContent sc, SideRegion reg) { 199 return new StaticContentLayoutManager(pslm, sc, reg); 200 } 201 202 205 public StaticContentLayoutManager makeStaticContentLayoutManager( 206 PageSequenceLayoutManager pslm, StaticContent sc, org.apache.fop.area.Block block) { 207 return new StaticContentLayoutManager(pslm, sc, block); 208 } 209 210 public static class Maker { 211 public void make(FONode node, List lms) { 212 return; 214 } 215 } 216 217 public static class FOTextLayoutManagerMaker extends Maker { 218 public void make(FONode node, List lms) { 219 FOText foText = (FOText) node; 220 if (foText.endIndex - foText.startIndex > 0) { 221 lms.add(new TextLayoutManager(foText)); 222 } 223 } 224 } 225 226 237 238 public static class BidiOverrideLayoutManagerMaker extends Maker { 239 public void make(BidiOverride node, List lms) { 241 if (false) { 242 super.make(node, lms); 245 } else { 246 ArrayList childList = new ArrayList (); 247 super.make(node, childList); 250 for (int count = childList.size() - 1; count >= 0; count--) { 251 LayoutManager lm = (LayoutManager) childList.get(count); 252 if (lm instanceof InlineLevelLayoutManager) { 253 LayoutManager blm = new BidiLayoutManager 254 (node, (InlineLayoutManager) lm); 255 lms.add(blm); 256 } else { 257 lms.add(lm); 258 } 259 } 260 } 261 } 262 } 263 264 public static class InlineLayoutManagerMaker extends Maker { 265 public void make(FONode node, List lms) { 266 if (node.getChildNodes() != null) { 267 lms.add(new InlineLayoutManager((InlineLevel) node)); 268 } 269 } 270 } 271 272 public static class FootnodeLayoutManagerMaker extends Maker { 273 public void make(FONode node, List lms) { 274 lms.add(new FootnoteLayoutManager((Footnote) node)); 275 } 276 } 277 278 public static class InlineContainerLayoutManagerMaker extends Maker { 279 public void make(FONode node, List lms) { 280 ArrayList childList = new ArrayList (); 281 super.make(node, childList); 282 lms.add(new ICLayoutManager((InlineContainer) node, childList)); 283 } 284 } 285 286 public static class BasicLinkLayoutManagerMaker extends Maker { 287 public void make(FONode node, List lms) { 288 lms.add(new BasicLinkLayoutManager((BasicLink) node)); 289 } 290 } 291 292 public static class BlockLayoutManagerMaker extends Maker { 293 public void make(FONode node, List lms) { 294 lms.add(new BlockLayoutManager((Block) node)); 295 } 296 } 297 298 public static class LeaderLayoutManagerMaker extends Maker { 299 public void make(FONode node, List lms) { 300 lms.add(new LeaderLayoutManager((Leader) node)); 301 } 302 } 303 304 public static class CharacterLayoutManagerMaker extends Maker { 305 public void make(FONode node, List lms) { 306 Character foCharacter = (Character ) node; 307 if (foCharacter.getCharacter() != CharUtilities.CODE_EOT) { 308 lms.add(new CharacterLayoutManager(foCharacter)); 309 } 310 } 311 } 312 313 public static class ExternalGraphicLayoutManagerMaker extends Maker { 314 public void make(FONode node, List lms) { 315 ExternalGraphic eg = (ExternalGraphic) node; 316 if (!eg.getSrc().equals("")) { 317 lms.add(new ExternalGraphicLayoutManager(eg)); 318 } 319 } 320 } 321 322 public static class BlockContainerLayoutManagerMaker extends Maker { 323 public void make(FONode node, List lms) { 324 lms.add(new BlockContainerLayoutManager((BlockContainer) node)); 325 } 326 } 327 328 public static class ListItemLayoutManagerMaker extends Maker { 329 public void make(FONode node, List lms) { 330 lms.add(new ListItemLayoutManager((ListItem) node)); 331 } 332 } 333 334 public static class ListBlockLayoutManagerMaker extends Maker { 335 public void make(FONode node, List lms) { 336 lms.add(new ListBlockLayoutManager((ListBlock) node)); 337 } 338 } 339 340 public static class InstreamForeignObjectLayoutManagerMaker extends Maker { 341 public void make(FONode node, List lms) { 342 lms.add(new InstreamForeignObjectLM((InstreamForeignObject) node)); 343 } 344 } 345 346 public static class PageNumberLayoutManagerMaker extends Maker { 347 public void make(FONode node, List lms) { 348 lms.add(new PageNumberLayoutManager((PageNumber) node)); 349 } 350 } 351 352 public static class PageNumberCitationLayoutManagerMaker extends Maker { 353 public void make(FONode node, List lms) { 354 lms.add(new PageNumberCitationLayoutManager((PageNumberCitation) node)); 355 } 356 } 357 358 public static class PageNumberCitationLastLayoutManagerMaker extends Maker { 359 public void make(FONode node, List lms) { 360 lms.add(new PageNumberCitationLastLayoutManager((PageNumberCitationLast) node)); 361 } 362 } 363 364 public static class TableLayoutManagerMaker extends Maker { 365 public void make(FONode node, List lms) { 366 Table table = (Table) node; 367 TableLayoutManager tlm = new TableLayoutManager(table); 368 lms.add(tlm); 369 } 370 } 371 372 public class RetrieveMarkerLayoutManagerMaker extends Maker { 373 public void make(FONode node, List lms) { 374 Iterator baseIter; 375 baseIter = node.getChildNodes(); 376 if (baseIter == null) { 377 return; 378 } 379 while (baseIter.hasNext()) { 380 FONode child = (FONode) baseIter.next(); 381 makeLayoutManagers(child, lms); 382 } 383 } 384 } 385 386 public class WrapperLayoutManagerMaker extends Maker { 387 public void make(FONode node, List lms) { 388 lms.add(new WrapperLayoutManager((Wrapper)node)); 391 Iterator baseIter; 392 baseIter = node.getChildNodes(); 393 if (baseIter == null) { 394 return; 395 } 396 while (baseIter.hasNext()) { 397 FONode child = (FONode) baseIter.next(); 398 makeLayoutManagers(child, lms); 399 } 400 } 401 } 402 403 } 404 | Popular Tags |