1 17 18 19 20 package org.apache.fop.area; 21 22 import java.util.ArrayList ; 23 import java.util.List ; 24 import java.util.HashMap ; 25 26 import org.apache.fop.fo.pagination.bookmarks.BookmarkTree; 27 import org.apache.fop.fo.pagination.bookmarks.Bookmark; 28 29 34 public class BookmarkData extends AbstractOffDocumentItem implements Resolvable { 35 private ArrayList subData = new ArrayList (); 36 37 private String bookmarkTitle = null; 39 40 private boolean bShow = true; 42 43 private String idRef; 45 46 private PageViewport pageRef = null; 48 49 private HashMap unresolvedIDRefs = new HashMap (); 51 52 59 public BookmarkData(BookmarkTree bookmarkTree) { 60 idRef = null; 61 whenToProcess = END_OF_DOC; 62 bShow = true; 64 65 for (int count = 0; count < bookmarkTree.getBookmarks().size(); count++) { 66 Bookmark bkmk = (Bookmark)(bookmarkTree.getBookmarks()).get(count); 67 addSubData(createBookmarkData(bkmk)); 68 } 69 } 70 71 79 public BookmarkData(Bookmark bookmark) { 80 bookmarkTitle = bookmark.getBookmarkTitle(); 81 bShow = bookmark.showChildItems(); 82 this.idRef = bookmark.getInternalDestination(); 83 unresolvedIDRefs.put(idRef, this); 84 } 85 86 91 public String getIDRef() { 92 return idRef; 93 } 94 95 101 public void addSubData(BookmarkData sub) { 102 subData.add(sub); 103 unresolvedIDRefs.put(sub.getIDRef(), sub); 104 String [] ids = sub.getIDRefs(); 105 for (int count = 0; count < ids.length; count++) { 106 unresolvedIDRefs.put(ids[count], sub); 107 } 108 } 109 110 115 public String getBookmarkTitle() { 116 return bookmarkTitle; 117 } 118 119 124 public boolean showChildItems() { 125 return bShow; 126 } 127 128 133 public int getCount() { 134 return subData.size(); 135 } 136 137 143 public BookmarkData getSubData(int count) { 144 return (BookmarkData) subData.get(count); 145 } 146 147 152 public PageViewport getPageViewport() { 153 return pageRef; 154 } 155 156 163 public boolean isResolved() { 164 return unresolvedIDRefs == null || (unresolvedIDRefs.size() == 0); 165 } 166 167 170 public String [] getIDRefs() { 171 return (String [])unresolvedIDRefs.keySet().toArray(new String [] {}); 172 } 173 174 184 public void resolveIDRef(String id, List pages) { 185 if (!id.equals(idRef)) { 186 BookmarkData bd = (BookmarkData) unresolvedIDRefs.get(id); 187 if (bd != null) { 188 bd.resolveIDRef(id, pages); 189 unresolvedIDRefs.remove(id); 190 } 191 } else { 192 pageRef = (PageViewport) pages.get(0); 193 unresolvedIDRefs.remove(idRef); 195 } 196 } 197 198 201 public String getName() { 202 return "Bookmarks"; 203 } 204 205 214 private BookmarkData createBookmarkData(Bookmark bookmark) { 215 BookmarkData data = new BookmarkData(bookmark); 216 for (int count = 0; count < bookmark.getChildBookmarks().size(); count++) { 217 Bookmark bkmk = (Bookmark)(bookmark.getChildBookmarks()).get(count); 218 data.addSubData(createBookmarkData(bkmk)); 219 } 220 return data; 221 } 222 223 } 224 225 | Popular Tags |