Author: jeremias
Date: Thu Dec 11 08:02:23 2008
New Revision: 725722
URL: http://svn.apache.org/viewvc?rev=725722&view=rev
Log:
Fixed parsing of document navigation namespace (its elements are no longer
simple extension elements but get sent to a specific interface).
Added:
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/extensions/DocumentNavigationHandler.java
- copied, changed from r725704,
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/extensions/DocumentNavigationExtensionHandlerFactory.java
Removed:
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/extensions/DocumentNavigationExtensionHandlerFactory.java
Modified:
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/META-INF/services/org.apache.fop.util.ContentHandlerFactory
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFParser.java
Modified:
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/META-INF/services/org.apache.fop.util.ContentHandlerFactory
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/META-INF/services/org.apache.fop.util.ContentHandlerFactory?rev=725722&r1=725721&r2=725722&view=diff
==============================================================================
---
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/META-INF/services/org.apache.fop.util.ContentHandlerFactory
(original)
+++
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/META-INF/services/org.apache.fop.util.ContentHandlerFactory
Thu Dec 11 08:02:23 2008
@@ -1,4 +1,3 @@
org.apache.fop.render.afp.extensions.AFPExtensionHandlerFactory
org.apache.fop.render.ps.extensions.PSExtensionHandlerFactory
org.apache.fop.fo.extensions.xmp.XMPContentHandlerFactory
-org.apache.fop.render.intermediate.extensions.DocumentNavigationExtensionHandlerFactory
Modified:
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFParser.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFParser.java?rev=725722&r1=725721&r2=725722&view=diff
==============================================================================
---
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFParser.java
(original)
+++
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/IFParser.java
Thu Dec 11 08:02:23 2008
@@ -50,6 +50,8 @@
import org.apache.fop.fo.ElementMapping;
import org.apache.fop.fo.ElementMappingRegistry;
import org.apache.fop.fo.expr.PropertyException;
+import
org.apache.fop.render.intermediate.extensions.DocumentNavigationExtensionConstants;
+import org.apache.fop.render.intermediate.extensions.DocumentNavigationHandler;
import org.apache.fop.traits.BorderProps;
import org.apache.fop.traits.RuleStyle;
import org.apache.fop.util.ColorUtil;
@@ -122,6 +124,8 @@
private boolean inForeignObject;
private Document foreignObject;
+ private ContentHandler navParser;
+
public Handler(IFDocumentHandler documentHandler, FOUserAgent
userAgent,
ElementMappingRegistry elementMappingRegistry) {
this.documentHandler = documentHandler;
@@ -174,6 +178,15 @@
} else {
handled = false;
}
+ } else if
(DocumentNavigationExtensionConstants.NAMESPACE.equals(uri)) {
+ if (this.navParser == null) {
+ this.navParser = new DocumentNavigationHandler(
+
this.documentHandler.getDocumentNavigationHandler());
+ }
+ delegate = this.navParser;
+ delegateDepth++;
+ delegate.startDocument();
+ delegate.startElement(uri, localName, qName, attributes);
} else {
ContentHandlerFactoryRegistry registry
=
userAgent.getFactory().getContentHandlerFactoryRegistry();
Copied:
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/extensions/DocumentNavigationHandler.java
(from r725704,
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/extensions/DocumentNavigationExtensionHandlerFactory.java)
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/extensions/DocumentNavigationHandler.java?p2=xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/extensions/DocumentNavigationHandler.java&p1=xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/extensions/DocumentNavigationExtensionHandlerFactory.java&r1=725704&r2=725722&rev=725722&view=diff
==============================================================================
---
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/extensions/DocumentNavigationExtensionHandlerFactory.java
(original)
+++
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/intermediate/extensions/DocumentNavigationHandler.java
Thu Dec 11 08:02:23 2008
@@ -20,117 +20,122 @@
package org.apache.fop.render.intermediate.extensions;
import java.awt.Point;
+import java.awt.Rectangle;
import java.util.Stack;
import org.xml.sax.Attributes;
-import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.fop.render.ps.extensions.PSExtensionAttachment;
-import org.apache.fop.util.ContentHandlerFactory;
+import org.apache.fop.render.intermediate.IFDocumentNavigationHandler;
+import org.apache.fop.render.intermediate.IFException;
import org.apache.fop.util.XMLUtil;
/**
- * Factory for the ContentHandler that handles the IF document navigation
namespace.
+ * ContentHandler that handles the IF document navigation namespace.
*/
-public class DocumentNavigationExtensionHandlerFactory
- implements ContentHandlerFactory, DocumentNavigationExtensionConstants
{
+public class DocumentNavigationHandler extends DefaultHandler
+ implements DocumentNavigationExtensionConstants {
/** Logger instance */
- protected static Log log =
LogFactory.getLog(DocumentNavigationExtensionHandlerFactory.class);
+ protected static Log log =
LogFactory.getLog(DocumentNavigationHandler.class);
- /** [EMAIL PROTECTED] */
- public String[] getSupportedNamespaces() {
- return new String[] {NAMESPACE};
- }
-
- /** [EMAIL PROTECTED] */
- public ContentHandler createContentHandler() {
- return new Handler();
- }
-
- private static class Handler extends DefaultHandler
- implements ContentHandlerFactory.ObjectSource {
+ private StringBuffer content = new StringBuffer();
+ private Stack objectStack = new Stack();
- private StringBuffer content = new StringBuffer();
- private Stack objectStack = new Stack();
+ private IFDocumentNavigationHandler navHandler;
- private Object objectBuilt;
- private ObjectBuiltListener listener;
+ /**
+ * Main constructor.
+ * @param navHandler the navigation handler that will receive the events
+ */
+ public DocumentNavigationHandler(IFDocumentNavigationHandler navHandler) {
+ this.navHandler = navHandler;
+ }
- /** [EMAIL PROTECTED] */
- public void startElement(String uri, String localName, String qName,
Attributes attributes)
- throws SAXException {
- boolean handled = false;
- if (NAMESPACE.equals(uri)) {
- if (BOOKMARK_TREE.getLocalName().equals(localName)) {
- if (!objectStack.isEmpty()) {
- throw new SAXException(localName + " must be the root
element!");
- }
- BookmarkTree bookmarkTree = new BookmarkTree();
- objectStack.push(bookmarkTree);
- } else if (BOOKMARK.getLocalName().equals(localName)) {
- String title = attributes.getValue("title");
- String s = attributes.getValue("starting-state");
- boolean show = !"hide".equals(s);
- Bookmark b = new Bookmark(title, show, null);
- Object o = objectStack.peek();
- if (o instanceof AbstractAction) {
- AbstractAction action =
(AbstractAction)objectStack.pop();
- o = objectStack.peek();
- ((Bookmark)o).setAction(action);
- }
- if (o instanceof BookmarkTree) {
- ((BookmarkTree)o).addBookmark(b);
- } else {
- ((Bookmark)o).addChildBookmark(b);
- }
- objectStack.push(b);
- } else if (NAMED_DESTINATION.getLocalName().equals(localName))
{
- if (!objectStack.isEmpty()) {
- throw new SAXException(localName + " must be the root
element!");
- }
- String name = attributes.getValue("name");
- NamedDestination dest = new NamedDestination(name, null);
- objectStack.push(dest);
- } else if (GOTO_XY.getLocalName().equals(localName)) {
- String id = attributes.getValue("id");
- int pageIndex = XMLUtil.getAttributeAsInt(attributes,
"page-index");
- int x = XMLUtil.getAttributeAsInt(attributes, "x");
- int y = XMLUtil.getAttributeAsInt(attributes, "y");
- GoToXYAction action = new GoToXYAction(id, pageIndex, new
Point(x, y));
- objectStack.push(action);
- } else if (GOTO_URI.getLocalName().equals(localName)) {
- String gotoURI = attributes.getValue("uri");
- String showDestination =
attributes.getValue("show-destination");
- boolean newWindow = "new".equals(showDestination);
- URIAction action = new URIAction(gotoURI, newWindow);
- objectStack.push(action);
- } else {
- throw new SAXException(
- "Invalid element " + localName + " in namespace: "
+ uri);
+ /** [EMAIL PROTECTED] */
+ public void startElement(String uri, String localName, String qName,
Attributes attributes)
+ throws SAXException {
+ boolean handled = false;
+ if (NAMESPACE.equals(uri)) {
+ if (BOOKMARK_TREE.getLocalName().equals(localName)) {
+ if (!objectStack.isEmpty()) {
+ throw new SAXException(localName + " must be the root
element!");
}
- handled = true;
- }
- if (!handled) {
- if (PSExtensionAttachment.CATEGORY.equals(uri)) {
- throw new SAXException("Unhandled element " + localName +
" in namespace: "
- + uri);
+ BookmarkTree bookmarkTree = new BookmarkTree();
+ objectStack.push(bookmarkTree);
+ } else if (BOOKMARK.getLocalName().equals(localName)) {
+ String title = attributes.getValue("title");
+ String s = attributes.getValue("starting-state");
+ boolean show = !"hide".equals(s);
+ Bookmark b = new Bookmark(title, show, null);
+ Object o = objectStack.peek();
+ if (o instanceof AbstractAction) {
+ AbstractAction action = (AbstractAction)objectStack.pop();
+ o = objectStack.peek();
+ ((Bookmark)o).setAction(action);
+ }
+ if (o instanceof BookmarkTree) {
+ ((BookmarkTree)o).addBookmark(b);
} else {
- log.warn("Unhandled element " + localName + " in
namespace: " + uri);
+ ((Bookmark)o).addChildBookmark(b);
+ }
+ objectStack.push(b);
+ } else if (NAMED_DESTINATION.getLocalName().equals(localName)) {
+ if (!objectStack.isEmpty()) {
+ throw new SAXException(localName + " must be the root
element!");
+ }
+ String name = attributes.getValue("name");
+ NamedDestination dest = new NamedDestination(name, null);
+ objectStack.push(dest);
+ } else if (LINK.getLocalName().equals(localName)) {
+ if (!objectStack.isEmpty()) {
+ throw new SAXException(localName + " must be the root
element!");
}
+ Rectangle targetRect =
XMLUtil.getAttributeAsRectangle(attributes, "rect");
+ Link link = new Link(null, targetRect);
+ objectStack.push(link);
+ } else if (GOTO_XY.getLocalName().equals(localName)) {
+ String id = attributes.getValue("id");
+ int pageIndex = XMLUtil.getAttributeAsInt(attributes,
"page-index");
+ int x = XMLUtil.getAttributeAsInt(attributes, "x");
+ int y = XMLUtil.getAttributeAsInt(attributes, "y");
+ GoToXYAction action = new GoToXYAction(id, pageIndex, new
Point(x, y));
+ objectStack.push(action);
+ } else if (GOTO_URI.getLocalName().equals(localName)) {
+ String gotoURI = attributes.getValue("uri");
+ String showDestination =
attributes.getValue("show-destination");
+ boolean newWindow = "new".equals(showDestination);
+ URIAction action = new URIAction(gotoURI, newWindow);
+ objectStack.push(action);
+ } else {
+ throw new SAXException(
+ "Invalid element '" + localName + "' in namespace: " +
uri);
}
+ handled = true;
}
-
- /** [EMAIL PROTECTED] */
- public void endElement(String uri, String localName, String qName)
throws SAXException {
+ if (!handled) {
if (NAMESPACE.equals(uri)) {
+ throw new SAXException("Unhandled element '" + localName + "'
in namespace: "
+ + uri);
+ } else {
+ log.warn("Unhandled element '" + localName + "' in namespace:
" + uri);
+ }
+ }
+ }
+
+ /** [EMAIL PROTECTED] */
+ public void endElement(String uri, String localName, String qName) throws
SAXException {
+ if (NAMESPACE.equals(uri)) {
+ try {
if (BOOKMARK_TREE.getLocalName().equals(localName)) {
- //nop
+ BookmarkTree tree = (BookmarkTree)objectStack.pop();
+ if (hasNavigation()) {
+ this.navHandler.renderBookmarkTree(tree);
+ }
} else if (BOOKMARK.getLocalName().equals(localName)) {
if (objectStack.peek() instanceof AbstractAction) {
AbstractAction action =
(AbstractAction)objectStack.pop();
@@ -141,36 +146,46 @@
}
} else if (NAMED_DESTINATION.getLocalName().equals(localName))
{
AbstractAction action = (AbstractAction)objectStack.pop();
- NamedDestination dest =
(NamedDestination)objectStack.peek();
+ NamedDestination dest =
(NamedDestination)objectStack.pop();
dest.setAction(action);
+ if (hasNavigation()) {
+ this.navHandler.renderNamedDestination(dest);
+ }
+ } else if (LINK.getLocalName().equals(localName)) {
+ AbstractAction action = (AbstractAction)objectStack.pop();
+ Link link = (Link)objectStack.pop();
+ link.setAction(action);
+ if (hasNavigation()) {
+ this.navHandler.renderLink(link);
+ }
+ } else if (localName.startsWith("goto-")) {
+ if (objectStack.size() == 1) {
+ //Stand-alone action
+ AbstractAction action =
(AbstractAction)objectStack.pop();
+ if (hasNavigation()) {
+ this.navHandler.addResolvedAction(action);
+ }
+ }
}
+ } catch (IFException ife) {
+ throw new SAXException(ife);
}
- content.setLength(0); // Reset text buffer (see characters())
- }
-
- /** [EMAIL PROTECTED] */
- public void characters(char[] ch, int start, int length) throws
SAXException {
- content.append(ch, start, length);
}
+ content.setLength(0); // Reset text buffer (see characters())
+ }
- /** [EMAIL PROTECTED] */
- public void endDocument() throws SAXException {
- this.objectBuilt = objectStack.pop();
- assert objectStack.isEmpty();
- if (listener != null) {
- listener.notifyObjectBuilt(this.objectBuilt);
- }
- }
+ private boolean hasNavigation() {
+ return this.navHandler != null;
+ }
- /** [EMAIL PROTECTED] */
- public Object getObject() {
- return objectBuilt;
- }
+ /** [EMAIL PROTECTED] */
+ public void characters(char[] ch, int start, int length) throws
SAXException {
+ content.append(ch, start, length);
+ }
- /** [EMAIL PROTECTED] */
- public void setObjectBuiltListener(ObjectBuiltListener listener) {
- this.listener = listener;
- }
+ /** [EMAIL PROTECTED] */
+ public void endDocument() throws SAXException {
+ assert objectStack.isEmpty();
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]