You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

FootenoteUtil.java 2.8KB

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