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$ */ 19 20 package org.apache.fop.layoutmgr; 21 22 import java.util.List; 23 24 import org.apache.commons.logging.Log; 25 import org.apache.commons.logging.LogFactory; 26 27 import org.apache.fop.fo.FONode; 28 import org.apache.fop.fo.flow.RetrieveTableMarker; 29 import org.apache.fop.layoutmgr.inline.InlineLevelLayoutManager; 30 import org.apache.fop.layoutmgr.inline.LeafNodeLayoutManager; 31 import org.apache.fop.layoutmgr.table.TableLayoutManager; 32 33 public class RetrieveTableMarkerLayoutManager extends LeafNodeLayoutManager { 34 35 private static Log log = LogFactory.getLog(RetrieveTableMarkerLayoutManager.class); 36 RetrieveTableMarkerLayoutManager(RetrieveTableMarker node)37 public RetrieveTableMarkerLayoutManager(RetrieveTableMarker node) { 38 super(node); 39 } 40 41 /** {@inheritDoc} */ getNextKnuthElements(LayoutContext context, int alignment)42 public List getNextKnuthElements(LayoutContext context, int alignment) { 43 setFinished(true); 44 FONode foNode = (FONode) getFObj(); 45 foNode = getTableLayoutManager().resolveRetrieveTableMarker((RetrieveTableMarker) foNode); 46 if (foNode != null) { 47 // resolve the RTM and replace current LM by the resolved target LM 48 InlineLevelLayoutManager illm = (InlineLevelLayoutManager) getPSLM().getLayoutManagerMaker() 49 .makeLayoutManager(foNode); 50 if (illm instanceof RetrieveTableMarkerLayoutManager) { 51 // happens if the retrieve-marker was empty 52 return null; 53 } 54 illm.setParent(getParent()); 55 illm.initialize(); 56 return illm.getNextKnuthElements(context, alignment); 57 } else { 58 return null; 59 } 60 } 61 62 /** {@inheritDoc} */ addAreas(PositionIterator posIter, LayoutContext context)63 public void addAreas(PositionIterator posIter, LayoutContext context) { 64 } 65 getTableLayoutManager()66 private TableLayoutManager getTableLayoutManager() { 67 LayoutManager parentLM = getParent(); 68 while (!(parentLM instanceof TableLayoutManager)) { 69 parentLM = parentLM.getParent(); 70 } 71 TableLayoutManager tlm = (TableLayoutManager) parentLM; 72 return tlm; 73 } 74 75 } 76