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: FootenoteUtil.java 1603386 2014-06-18 09:59:19Z vhennebert $ */ 19 20 package org.apache.fop.layoutmgr; 21 22 import java.util.ArrayList; 23 import java.util.Collections; 24 import java.util.List; 25 import java.util.ListIterator; 26 27 import org.apache.fop.layoutmgr.inline.KnuthInlineBox; 28 29 public final class FootenoteUtil { 30 FootenoteUtil()31 private FootenoteUtil() { 32 } 33 34 /** 35 * Returns the footnotes contained in the given element list. 36 */ getFootnotes(List<ListElement> elemenList)37 public static List<FootnoteBodyLayoutManager> getFootnotes(List<ListElement> elemenList) { 38 return getFootnotes(elemenList, 0, elemenList.size() - 1); 39 } 40 41 /** 42 * Returns the footnotes contained in the given element list. 43 * 44 * @param startIndex index in the element list from which to start the scan, inclusive 45 * @param endIndex index in the element list at which to stop the scan, inclusive 46 */ getFootnotes( List<ListElement> elemenList, int startIndex, int endIndex)47 public static List<FootnoteBodyLayoutManager> getFootnotes( 48 List<ListElement> elemenList, int startIndex, int endIndex) { 49 ListIterator<ListElement> iter = elemenList.listIterator(startIndex); 50 List<FootnoteBodyLayoutManager> footnotes = null; 51 while (iter.nextIndex() <= endIndex) { 52 ListElement element = iter.next(); 53 if (element instanceof KnuthInlineBox && ((KnuthInlineBox) element).isAnchor()) { 54 footnotes = getFootnoteList(footnotes); 55 footnotes.add(((KnuthInlineBox) element).getFootnoteBodyLM()); 56 } else if (element instanceof KnuthBlockBox && ((KnuthBlockBox) element).hasAnchors()) { 57 footnotes = getFootnoteList(footnotes); 58 footnotes.addAll(((KnuthBlockBox) element).getFootnoteBodyLMs()); 59 } 60 } 61 if (footnotes == null) { 62 return Collections.emptyList(); 63 } else { 64 return footnotes; 65 } 66 } 67 getFootnoteList(List<T> footnotes)68 private static <T> List<T> getFootnoteList(List<T> footnotes) { 69 if (footnotes == null) { 70 return new ArrayList<T>(); 71 } else { 72 return footnotes; 73 } 74 } 75 76 } 77