// Apache
import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.FOUserAgent;
-import org.apache.fop.area.extensions.BookmarkData;
import org.apache.fop.fo.FOEventHandler;
import org.apache.fop.fo.extensions.Outline;
import org.apache.fop.fo.extensions.Bookmarks;
}
}
} else {
- model.handleOffDocumentItem(ext, OffDocumentItem.IMMEDIATELY);
+ model.handleOffDocumentItem(ext);
}
}
}
/**
* Handle an OffDocumentItem
* @param ext the extension to handle
- * @param when when the extension should be handled
*/
- public abstract void handleOffDocumentItem(OffDocumentItem ext, int when);
+ public abstract void handleOffDocumentItem(OffDocumentItem ext);
/**
* Signal the end of the document for any processing.
--- /dev/null
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.area;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.HashMap;
+
+/**
+ * This class holds the PDF bookmark OffDocumentItem
+ */
+public class BookmarkData extends OffDocumentItem implements Resolvable {
+ private ArrayList subData = new ArrayList();
+ private HashMap idRefs = new HashMap();
+
+ // area tree model for the top level object to activate when resolved
+ private AreaTreeModel areaTreeModel = null;
+
+ private String idRef;
+ private PageViewport pageRef = null;
+ private String label = null;
+
+ /**
+ * Create a new bookmark data object.
+ * This should only be call by the top level element as the
+ * id reference will be null.
+ */
+ public BookmarkData() {
+ idRef = null;
+ whenToProcess = IMMEDIATELY;
+ }
+
+ /**
+ * Create a new pdf bookmark data object.
+ * This is used by the outlines to create a data object
+ * with a id reference. The id reference is to be resolved.
+ *
+ * @param id the id reference
+ */
+ public BookmarkData(String id) {
+ idRef = id;
+ idRefs.put(idRef, this);
+ }
+
+ /**
+ * Set the area tree model
+ * This should only be called for the top level element.
+ * The area tree model is used once resolving is complete.
+ *
+ * @param atm the area tree model for the current document
+ */
+ public void setAreaTreeModel(AreaTreeModel atm) {
+ areaTreeModel = atm;
+ }
+
+ /**
+ * Get the id reference for this data.
+ *
+ * @return the id reference
+ */
+ public String getID() {
+ return idRef;
+ }
+
+ /**
+ * Add the child bookmark data object.
+ * This adds a child bookmark in the bookmark hierarchy.
+ *
+ * @param sub the child bookmark data
+ */
+ public void addSubData(BookmarkData sub) {
+ subData.add(sub);
+ idRefs.put(sub.getID(), sub);
+ String[] ids = sub.getIDs();
+ for (int count = 0; count < ids.length; count++) {
+ idRefs.put(ids[count], sub);
+ }
+ }
+
+ /**
+ * Set the label for this bookmark.
+ *
+ * @param l the string label
+ */
+ public void setLabel(String l) {
+ label = l;
+ }
+
+ /**
+ * Get the label for this bookmark object.
+ *
+ * @return the label string
+ */
+ public String getLabel() {
+ return label;
+ }
+
+ /**
+ * Get the size of child data objects.
+ *
+ * @return the number of child bookmark data
+ */
+ public int getCount() {
+ return subData.size();
+ }
+
+ /**
+ * Get the child data object.
+ *
+ * @param count the index to get
+ * @return the child bookmark data
+ */
+ public BookmarkData getSubData(int count) {
+ return (BookmarkData)subData.get(count);
+ }
+
+ /**
+ * Get the page that this resolves to.
+ *
+ * @return the PageViewport that this extension resolves to
+ */
+ public PageViewport getPage() {
+ return pageRef;
+ }
+
+ /**
+ * Check if this resolvable object has been resolved.
+ * Once the id reference is null then it has been resolved.
+ *
+ * @return true if this has been resolved
+ */
+ public boolean isResolved() {
+ return idRefs == null;
+ }
+
+ /**
+ * Get the id references held by this object.
+ * Also includes all id references of all children.
+ *
+ * @return the array of id references
+ */
+ public String[] getIDs() {
+ return (String[])idRefs.keySet().toArray(new String[] {});
+ }
+
+ /**
+ * Resolve this resolvable object.
+ * This resolves the id reference and if possible also
+ * resolves id references of child elements that have the same
+ * id reference.
+ *
+ * @param id the id reference being resolved
+ * @param pages the list of pages the the id reference resolves to
+ */
+ public void resolve(String id, List pages) {
+ // this method is buggy
+
+ if (!id.equals(idRef)) {
+ BookmarkData bd = (BookmarkData)idRefs.get(id);
+ idRefs.remove(id);
+ if (bd != null) {
+ bd.resolve(id, pages);
+ if (bd.isResolved()) {
+ checkFinish();
+ }
+ } else if (idRef == null) {
+ checkFinish();
+ }
+ } else {
+ if (pages != null) {
+ pageRef = (PageViewport)pages.get(0);
+ }
+ // TODO get rect area of id on page
+
+ idRefs.remove(idRef);
+ checkFinish();
+ }
+ }
+
+ private void checkFinish() {
+ if (idRefs.size() == 0) {
+ idRefs = null;
+ if (areaTreeModel != null) {
+ areaTreeModel.handleOffDocumentItem(this);
+ }
+ }
+ }
+}
+
package org.apache.fop.area;
/**
- * Interface for objects that are processed by the renderer outside
+ * Abstract base class for objects that are processed by the renderer outside
* of the actual document.
* This object can be handled by the renderer according to three
* possibilities, IMMEDIATELY, AFTER_PAGE, or END_OF_DOC.
*/
-public interface OffDocumentItem {
+public abstract class OffDocumentItem {
+
/**
- * Render this extension immediately when
+ * Process this extension immediately when
* being handled by the area tree.
*/
public static final int IMMEDIATELY = 0;
/**
- * Render this extension after the next page is rendered
+ * Process this extension after the next page is rendered
* or prepared when being handled by the area tree.
*/
public static final int AFTER_PAGE = 1;
/**
- * Render this extension at the end of the document once
+ * Process this extension at the end of the document once
* all pages have been fully rendered.
*/
public static final int END_OF_DOC = 2;
+
+ protected int whenToProcess = IMMEDIATELY;
+
+ /**
+ * Get an indicator of when this item should be processed
+ * @return int constant (IMMEDIATELY, AFTER_PAGE, END_OF_DOC)
+ */
+ public int getWhenToProcess() {
+ return whenToProcess;
+ }
}
* Pages that have been prepared but not rendered yet.
*/
protected List prepared = new java.util.ArrayList();
- private List pendingExt = new java.util.ArrayList();
- private List endDocExt = new java.util.ArrayList();
+ private List pendingODI = new java.util.ArrayList();
+ private List endDocODI = new java.util.ArrayList();
/**
* Create a new render pages model with the given renderer.
boolean cont = checkPreparedPages(page);
if (cont) {
- processOffDocumentItems(pendingExt);
- pendingExt.clear();
+ processOffDocumentItems(pendingODI);
+ pendingODI.clear();
}
}
}
/**
- * @see org.apache.fop.area.AreaTreeModel#handleOffDocumentItem(OffDocumentItem, int)
+ * @see org.apache.fop.area.AreaTreeModel#handleOffDocumentItem(OffDocumentItem)
*/
- public void handleOffDocumentItem(OffDocumentItem ext, int when) {
- switch(when) {
+ public void handleOffDocumentItem(OffDocumentItem oDI) {
+ switch(oDI.getWhenToProcess()) {
case OffDocumentItem.IMMEDIATELY:
- renderer.processOffDocumentItem(ext);
+ renderer.processOffDocumentItem(oDI);
break;
case OffDocumentItem.AFTER_PAGE:
- pendingExt.add(ext);
+ pendingODI.add(oDI);
break;
case OffDocumentItem.END_OF_DOC:
- endDocExt.add(ext);
+ endDocODI.add(oDI);
break;
}
}
private void processOffDocumentItems(List list) {
for (int count = 0; count < list.size(); count++) {
- OffDocumentItem ext = (OffDocumentItem)list.get(count);
- renderer.processOffDocumentItem(ext);
+ OffDocumentItem oDI = (OffDocumentItem)list.get(count);
+ renderer.processOffDocumentItem(oDI);
}
}
/**
- * End the document. Render any end document extensions.
+ * End the document. Render any end document OffDocumentItems
* @see org.apache.fop.area.AreaTreeModel#endDocument()
*/
public void endDocument() throws SAXException {
// render any pages that had unresolved ids
checkPreparedPages(null);
- processOffDocumentItems(pendingExt);
- pendingExt.clear();
-
- processOffDocumentItems(endDocExt);
+ processOffDocumentItems(pendingODI);
+ pendingODI.clear();
+ processOffDocumentItems(endDocODI);
try {
renderer.stopRenderer();
public class StorePagesModel extends AreaTreeModel {
private List pageSequence = null;
private List currSequence;
- private List extensions = new java.util.ArrayList();
+ private List offDocumentItems = new java.util.ArrayList();
/**
* Create a new store pages model
}
/**
- * @see org.apache.fop.area.AreaTreeModel#handleOffDocumentItem(OffDocumentItem, int)
+ * @see org.apache.fop.area.AreaTreeModel#handleOffDocumentItem(OffDocumentItem)
*/
- public void handleOffDocumentItem(OffDocumentItem ext, int when) {
+ public void handleOffDocumentItem(OffDocumentItem ext) {
int seq, page;
- switch(when) {
+ switch(ext.getWhenToProcess()) {
case OffDocumentItem.IMMEDIATELY:
seq = pageSequence == null ? 0 : pageSequence.size();
page = currSequence == null ? 0 : currSequence.size();
case OffDocumentItem.END_OF_DOC:
break;
}
- extensions.add(ext);
+ offDocumentItems.add(ext);
}
/**
- * Get the list of extensions that apply at a particular
+ * Get the list of OffDocumentItems that apply at a particular
* position in the document.
* @param seq the page sequence number
* @param count the page count in the sequence
- * @return the list of extensions
+ * @return the list of OffDocumentItems
*/
- public List getExtensions(int seq, int count) {
+ public List getOffDocumentItems(int seq, int count) {
return null;
}
/**
- * Get the end of document extensions for this stroe pages model.
- * @return the list of end extensions
+ * Get the end of document OffDocumentItems for this store pages model.
+ * @return the list of end OffDocumentItems
*/
- public List getEndExtensions() {
- return extensions;
+ public List getEndOffDocumentItems() {
+ return offDocumentItems;
}
/**
+++ /dev/null
-/*
- * Copyright 1999-2004 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/* $Id$ */
-
-package org.apache.fop.area.extensions;
-
-import org.apache.fop.area.PageViewport;
-import org.apache.fop.area.Resolvable;
-import org.apache.fop.area.OffDocumentItem;
-import org.apache.fop.area.AreaTreeModel;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.HashMap;
-
-/**
- * This class holds the PDF bookmark extension data.
- */
-public class BookmarkData implements Resolvable, OffDocumentItem {
- private ArrayList subData = new ArrayList();
- private HashMap idRefs = new HashMap();
-
- // area tree model for the top level object to activate when resolved
- private AreaTreeModel areaTreeModel = null;
-
- private String idRef;
- private PageViewport pageRef = null;
- private String label = null;
-
- /**
- * Create a new bookmark data object.
- * This should only be call by the top level element as the
- * id reference will be null.
- */
- public BookmarkData() {
- idRef = null;
- }
-
- /**
- * Create a new pdf bookmark data object.
- * This is used by the outlines to create a data object
- * with a id reference. The id reference is to be resolved.
- *
- * @param id the id reference
- */
- public BookmarkData(String id) {
- idRef = id;
- idRefs.put(idRef, this);
- }
-
- /**
- * Set the area tree model
- * This should only be called for the top level element.
- * The area tree model is used once resolving is complete.
- *
- * @param atm the area tree model for the current document
- */
- public void setAreaTreeModel(AreaTreeModel atm) {
- areaTreeModel = atm;
- }
-
- /**
- * Get the id reference for this data.
- *
- * @return the id reference
- */
- public String getID() {
- return idRef;
- }
-
- /**
- * Add the child bookmark data object.
- * This adds a child bookmark in the bookmark hierarchy.
- *
- * @param sub the child bookmark data
- */
- public void addSubData(BookmarkData sub) {
- subData.add(sub);
- idRefs.put(sub.getID(), sub);
- String[] ids = sub.getIDs();
- for (int count = 0; count < ids.length; count++) {
- idRefs.put(ids[count], sub);
- }
- }
-
- /**
- * Set the label for this bookmark.
- *
- * @param l the string label
- */
- public void setLabel(String l) {
- label = l;
- }
-
- /**
- * Get the label for this bookmark object.
- *
- * @return the label string
- */
- public String getLabel() {
- return label;
- }
-
- /**
- * Get the size of child data objects.
- *
- * @return the number of child bookmark data
- */
- public int getCount() {
- return subData.size();
- }
-
- /**
- * Get the child data object.
- *
- * @param count the index to get
- * @return the child bookmark data
- */
- public BookmarkData getSubData(int count) {
- return (BookmarkData)subData.get(count);
- }
-
- /**
- * Get the page that this resolves to.
- *
- * @return the PageViewport that this extension resolves to
- */
- public PageViewport getPage() {
- return pageRef;
- }
-
- /**
- * Check if this resolvable object has been resolved.
- * Once the id reference is null then it has been resolved.
- *
- * @return true if this has been resolved
- */
- public boolean isResolved() {
- return idRefs == null;
- }
-
- /**
- * Get the id references held by this object.
- * Also includes all id references of all children.
- *
- * @return the array of id references
- */
- public String[] getIDs() {
- return (String[])idRefs.keySet().toArray(new String[] {});
- }
-
- /**
- * Resolve this resolvable object.
- * This resolves the id reference and if possible also
- * resolves id references of child elements that have the same
- * id reference.
- *
- * @param id the id reference being resolved
- * @param pages the list of pages the the id reference resolves to
- */
- public void resolve(String id, List pages) {
- // this method is buggy
-
- if (!id.equals(idRef)) {
- BookmarkData bd = (BookmarkData)idRefs.get(id);
- idRefs.remove(id);
- if (bd != null) {
- bd.resolve(id, pages);
- if (bd.isResolved()) {
- checkFinish();
- }
- } else if (idRef == null) {
- checkFinish();
- }
- } else {
- if (pages != null) {
- pageRef = (PageViewport)pages.get(0);
- }
- // TODO get rect area of id on page
-
- idRefs.remove(idRef);
- checkFinish();
- }
- }
-
- private void checkFinish() {
- if (idRefs.size() == 0) {
- idRefs = null;
- if (areaTreeModel != null) {
- areaTreeModel.handleOffDocumentItem(this, OffDocumentItem.AFTER_PAGE);
- }
- }
- }
-}
-
import org.apache.fop.area.RegionViewport;
import org.apache.fop.area.Trait;
import org.apache.fop.area.OffDocumentItem;
-import org.apache.fop.area.extensions.BookmarkData;
+import org.apache.fop.area.BookmarkData;
import org.apache.fop.area.inline.Character;
import org.apache.fop.area.inline.TextArea;
import org.apache.fop.area.inline.Viewport;