org.apache.batik.bridge
Class BridgeContext

java.lang.Object
  |
  +--org.apache.batik.bridge.BridgeContext
All Implemented Interfaces:
CSSContext, ErrorConstants

public class BridgeContext
extends java.lang.Object
implements ErrorConstants, CSSContext

This class represents a context used by the various bridges and the builder. A bridge context is associated to a particular document and cannot be reused. The context encapsulates the dynamic bindings between DOM elements and GVT nodes, graphic contexts such as a GraphicsNodeRenderContext, and the different objects required by the GVT builder to interpret a SVG DOM tree such as the current viewport or the user agent.


Inner Class Summary
protected  class BridgeContext.CSSPropertiesChangedListener
          The CSSEngineListener invoked when CSS properties are modified on a particular element.
protected  class BridgeContext.DOMAttrModifiedEventListener
          The DOM EventListener invoked when an attribute is modified.
protected  class BridgeContext.DOMCharacterDataModifiedListener
          The DOM EventListener invoked when a character data is changed.
protected  class BridgeContext.DOMNodeInsertedEventListener
          The DOM EventListener invoked when a node is added.
protected  class BridgeContext.DOMNodeRemovedEventListener
          The DOM EventListener invoked when a node is removed.
protected static class BridgeContext.EventListenerMememto
          A class used to store an EventListener added to the DOM.
 
Field Summary
protected  CSSEngineListener cssPropertiesChangedListener
          The CSSEngine listener to receive CSSEngineEvent.
protected  Document document
          The document is bridge context is dedicated to.
protected  DocumentLoader documentLoader
          The document loader used to load/create Document.
protected  java.awt.geom.Dimension2D documentSize
          The size of the document.
protected  EventListener domAttrModifiedEventListener
          The DOM EventListener to receive 'DOMAttrModified' event.
protected  EventListener domCharacterDataModifiedListener
          The DOM EventListener to receive 'DOMCharacterDataModified' event.
protected  EventListener domNodeInsertedEventListener
          The DOM EventListener to receive 'DOMNodeInserted' event.
protected  EventListener domNodeRemovedEventListener
          The DOM EventListener to receive 'DOMNodeRemoved' event.
protected  boolean dynamic
          Whether the bridge must support dynamic features.
protected  java.util.HashMap elementNodeMap
          Binding Map: key is an SVG Element - value is a GraphicsNode
protected  java.util.List eventListenerList
          The list of all EventListener attached by bridges that need to be removed on a dispose() call.
protected static java.util.List extensions
           
protected  FocusManager focusManager
          The EventListener that is responsible of managing DOM focus event.
protected  GVTBuilder gvtBuilder
          The GVT builder that might be used to create a GVT subtree.
protected  java.util.Map interpreterMap
          The interpreter cache per document.
protected  InterpreterPool interpreterPool
          The interpreter pool used to handle scripts.
protected  java.util.HashMap namespaceURIMap
          Bridge Map: Keys are namespace URI - values are HashMap (with keys are local name and values are a Bridge instance).
protected  java.util.HashMap nodeElementMap
          Binding Map: key is GraphicsNode - value is a SVG Element.
protected  TextPainter textPainter
          The text painter to use.
protected  UpdateManager updateManager
          The update manager.
protected  UserAgent userAgent
          The user agent.
protected  java.util.Map viewportMap
          The viewports.
protected  java.util.List viewportStack
          The viewport stack.
 
Fields inherited from interface org.apache.batik.bridge.ErrorConstants
ERR_ATTRIBUTE_MISSING, ERR_ATTRIBUTE_VALUE_MALFORMED, ERR_CSS_LENGTH_NEGATIVE, ERR_CSS_URI_BAD_TARGET, ERR_LENGTH_NEGATIVE, ERR_URI_BAD_TARGET, ERR_URI_IMAGE_INVALID, ERR_URI_IO, ERR_URI_MALFORMED, ERR_URI_REFERENCE_A_DOCUMENT, ERR_URI_UNSECURE, ERR_XLINK_HREF_CIRCULAR_DEPENDENCIES, MSG_BROKEN_LINK_TITLE
 
Constructor Summary
protected BridgeContext()
          Constructs a new empty bridge context.
  BridgeContext(UserAgent userAgent)
          Constructs a new bridge context.
  BridgeContext(UserAgent userAgent, DocumentLoader loader)
          Constructs a new bridge context.
  BridgeContext(UserAgent userAgent, InterpreterPool interpreterPool, DocumentLoader documentLoader)
          Constructs a new bridge context.
 
Method Summary
 void addDOMListeners()
          Adds EventListeners to the DOM and CSSEngineListener to the CSSEngine to handle any modifications on the DOM tree or style properties and update the GVT tree in response.
 void bind(Element element, GraphicsNode node)
          Binds the specified GraphicsNode to the specified Element.
 void checkLoadExternalResource(ParsedURL resourceURL, ParsedURL docURL)
          This method throws a SecurityException if the resource found at url and referenced from docURL should not be loaded.
 void closeViewport(Element e)
          Closes the viewport associated to the specified element.
 void dispose()
          Disposes this BridgeContext.
 float getBlockHeight(Element elt)
          Returns the height of the block which directly contains the given element.
 float getBlockWidth(Element elt)
          Returns the width of the block which directly contains the given element.
 float getBolderFontWeight(float f)
          Returns a bolder font-weight.
 Bridge getBridge(Element element)
          Returns the bridge associated with the specified element.
 Bridge getBridge(java.lang.String namespaceURI, java.lang.String localName)
          Returns the bridge associated with the element type
static java.util.List getBridgeExtensions()
          Returns the extensions supported by this bridge context.
protected static BridgeUpdateHandler getBridgeUpdateHandler(Node node)
          Returns the SVGContext associated to the specified Node or null if any.
 Document getDocument()
          Returns the document this bridge context is dedicated to.
 DocumentLoader getDocumentLoader()
          Returns the document loader used to load external documents.
 java.awt.geom.Dimension2D getDocumentSize()
          Returns the actual size of the document or null if the document has not been built yet.
 Element getElement(GraphicsNode node)
          Returns the Element associated to the specified GraphicsNode or null if any.
 FocusManager getFocusManager()
          Returns the focus manager.
 java.util.Map getFontFamilyMap()
          Returns the map of font families
 GraphicsNode getGraphicsNode(Element element)
          Returns the GraphicsNode associated to the specified Element or null if any.
 GVTBuilder getGVTBuilder()
          Returns the GVT builder that is currently used to build the GVT tree.
 Interpreter getInterpreter(java.lang.String language)
          Returns a Interpreter for the specified language.
 InterpreterPool getInterpreterPool()
          Returns the interpreter pool used to handle scripts.
 float getLighterFontWeight(float f)
          Returns a lighter font-weight.
 float getMediumFontSize()
          Returns the medium font size.
 float getPixelToMillimeter()
          Returns the size of a px CSS unit in millimeters.
 float getPixelUnitToMillimeter()
          Returns the size of a px CSS unit in millimeters.
 Element getReferencedElement(Element e, java.lang.String uri)
          Returns the element referenced by the specified element by the specified uri.
protected static SVGContext getSVGContext(Node node)
          Returns the SVGContext associated to the specified Node or null if any.
 Value getSystemColor(java.lang.String ident)
          Returns the Value corresponding to the given system color.
 TextPainter getTextPainter()
          Returns the text painter that will be used be text nodes.
 UpdateManager getUpdateManager()
          Returns the update manager, if the bridge supports dynamic features.
 UserAgent getUserAgent()
          Returns the user agent of this bridge context.
 Viewport getViewport(Element e)
          Returns the viewport of the specified element.
 boolean hasGraphicsNodeBridge(Element element)
          Returns true if the specified element has a GraphicsNodeBridge associated to it, false otherwise.
protected  void initializeDocument(Document document)
          Initializes the given document.
 boolean isDynamic()
          Returns true if the document is dynamic, false otherwise.
 void openViewport(Element e, Viewport viewport)
          Starts a new viewport from the specified element.
 void putBridge(Bridge bridge)
          Associates the specified Bridge object with it's namespace URI and local name.
 void putBridge(java.lang.String namespaceURI, java.lang.String localName, Bridge bridge)
          Associates the specified Bridge object with the specified namespace URI and local name.
static void registerSVGBridges(BridgeContext ctx)
          Registers the bridges to handle SVG 1.0 elements.
 void removeBridge(java.lang.String namespaceURI, java.lang.String localName)
          Removes the Bridge object associated to the specified namespace URI and local name.
protected  void setDocument(Document document)
          Sets the document this bridge context is dedicated to, to the specified document.
protected  void setDocumentLoader(DocumentLoader newDocumentLoader)
          Sets the document loader used to load external documents.
protected  void setDocumentSize(java.awt.geom.Dimension2D d)
          Sets the size of the document to the specified dimension.
 void setDynamic(boolean b)
          Sets the document as a dynamic document.
protected  void setFontFamilyMap(java.util.Map fontFamilyMap)
          Sets the map of font families to the specified value.
protected  void setGVTBuilder(GVTBuilder gvtBuilder)
          Sets the GVT builder that uses this context.
protected  void setInterpreterPool(InterpreterPool interpreterPool)
          Sets the interpreter pool used to handle scripts to the specified interpreter pool.
 void setTextPainter(TextPainter textPainter)
          Sets the text painter that will be used by text nodes.
protected  void setUpdateManager(UpdateManager um)
          Sets the update manager.
protected  void setUserAgent(UserAgent userAgent)
          Sets the user agent to the specified user agent.
protected  void storeEventListener(EventTarget t, java.lang.String s, EventListener l, boolean b)
          Adds to the eventListenerList the specified event listener registration.
 void unbind(Element element)
          Removes the binding of the specified Element.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

document

protected Document document
The document is bridge context is dedicated to.

gvtBuilder

protected GVTBuilder gvtBuilder
The GVT builder that might be used to create a GVT subtree.

interpreterMap

protected java.util.Map interpreterMap
The interpreter cache per document. key is the language - value is a Interpreter

viewportMap

protected java.util.Map viewportMap
The viewports. key is an Element - value is a Viewport

viewportStack

protected java.util.List viewportStack
The viewport stack. Used in building time.

userAgent

protected UserAgent userAgent
The user agent.

elementNodeMap

protected java.util.HashMap elementNodeMap
Binding Map: key is an SVG Element - value is a GraphicsNode

nodeElementMap

protected java.util.HashMap nodeElementMap
Binding Map: key is GraphicsNode - value is a SVG Element.

namespaceURIMap

protected java.util.HashMap namespaceURIMap
Bridge Map: Keys are namespace URI - values are HashMap (with keys are local name and values are a Bridge instance).

interpreterPool

protected InterpreterPool interpreterPool
The interpreter pool used to handle scripts.

documentLoader

protected DocumentLoader documentLoader
The document loader used to load/create Document.

documentSize

protected java.awt.geom.Dimension2D documentSize
The size of the document.

textPainter

protected TextPainter textPainter
The text painter to use. Typically, you can specify the text painter that will be used be text nodes.

dynamic

protected boolean dynamic
Whether the bridge must support dynamic features.

updateManager

protected UpdateManager updateManager
The update manager.

eventListenerList

protected java.util.List eventListenerList
The list of all EventListener attached by bridges that need to be removed on a dispose() call.

domCharacterDataModifiedListener

protected EventListener domCharacterDataModifiedListener
The DOM EventListener to receive 'DOMCharacterDataModified' event.

domAttrModifiedEventListener

protected EventListener domAttrModifiedEventListener
The DOM EventListener to receive 'DOMAttrModified' event.

domNodeInsertedEventListener

protected EventListener domNodeInsertedEventListener
The DOM EventListener to receive 'DOMNodeInserted' event.

domNodeRemovedEventListener

protected EventListener domNodeRemovedEventListener
The DOM EventListener to receive 'DOMNodeRemoved' event.

cssPropertiesChangedListener

protected CSSEngineListener cssPropertiesChangedListener
The CSSEngine listener to receive CSSEngineEvent.

focusManager

protected FocusManager focusManager
The EventListener that is responsible of managing DOM focus event.

extensions

protected static java.util.List extensions
Constructor Detail

BridgeContext

protected BridgeContext()
Constructs a new empty bridge context.

BridgeContext

public BridgeContext(UserAgent userAgent)
Constructs a new bridge context.
Parameters:
userAgent - the user agent

BridgeContext

public BridgeContext(UserAgent userAgent,
                     DocumentLoader loader)
Constructs a new bridge context.
Parameters:
userAgent - the user agent
documentLoader - document loader

BridgeContext

public BridgeContext(UserAgent userAgent,
                     InterpreterPool interpreterPool,
                     DocumentLoader documentLoader)
Constructs a new bridge context.
Parameters:
userAgent - the user agent
interpreterPool - the interpreter pool
documentLoader - document loader
Method Detail

initializeDocument

protected void initializeDocument(Document document)
Initializes the given document.

setTextPainter

public void setTextPainter(TextPainter textPainter)
Sets the text painter that will be used by text nodes. This attributes might be used by bridges (especially SVGTextElementBridge) to set the text painter of each TextNode.
Parameters:
textPainter - the text painter for text nodes

getTextPainter

public TextPainter getTextPainter()
Returns the text painter that will be used be text nodes.

getDocument

public Document getDocument()
Returns the document this bridge context is dedicated to.

setDocument

protected void setDocument(Document document)
Sets the document this bridge context is dedicated to, to the specified document.
Parameters:
document - the document

getFontFamilyMap

public java.util.Map getFontFamilyMap()
Returns the map of font families

setFontFamilyMap

protected void setFontFamilyMap(java.util.Map fontFamilyMap)
Sets the map of font families to the specified value.
Parameters:
fontFamilyMap - the map of font families

getUserAgent

public UserAgent getUserAgent()
Returns the user agent of this bridge context.

setUserAgent

protected void setUserAgent(UserAgent userAgent)
Sets the user agent to the specified user agent.
Parameters:
userAgent - the user agent

getGVTBuilder

public GVTBuilder getGVTBuilder()
Returns the GVT builder that is currently used to build the GVT tree.

setGVTBuilder

protected void setGVTBuilder(GVTBuilder gvtBuilder)
Sets the GVT builder that uses this context.

getInterpreterPool

public InterpreterPool getInterpreterPool()
Returns the interpreter pool used to handle scripts.

getFocusManager

public FocusManager getFocusManager()
Returns the focus manager.

setInterpreterPool

protected void setInterpreterPool(InterpreterPool interpreterPool)
Sets the interpreter pool used to handle scripts to the specified interpreter pool.
Parameters:
interpreterPool - the interpreter pool

getInterpreter

public Interpreter getInterpreter(java.lang.String language)
Returns a Interpreter for the specified language.
Parameters:
language - the scripting language

getDocumentLoader

public DocumentLoader getDocumentLoader()
Returns the document loader used to load external documents.

setDocumentLoader

protected void setDocumentLoader(DocumentLoader newDocumentLoader)
Sets the document loader used to load external documents.
Parameters:
newDocumentLoader - the new document loader

getDocumentSize

public java.awt.geom.Dimension2D getDocumentSize()
Returns the actual size of the document or null if the document has not been built yet.

setDocumentSize

protected void setDocumentSize(java.awt.geom.Dimension2D d)
Sets the size of the document to the specified dimension.
Parameters:
d - the actual size of the SVG document

isDynamic

public boolean isDynamic()
Returns true if the document is dynamic, false otherwise.

setDynamic

public void setDynamic(boolean b)
Sets the document as a dynamic document. Call this method before the build phase (ie. before gvtBuilder.build(...)) otherwise, that will have no effect.
Parameters:
b - the document state

getUpdateManager

public UpdateManager getUpdateManager()
Returns the update manager, if the bridge supports dynamic features.

setUpdateManager

protected void setUpdateManager(UpdateManager um)
Sets the update manager.

getReferencedElement

public Element getReferencedElement(Element e,
                                    java.lang.String uri)
Returns the element referenced by the specified element by the specified uri. The referenced element can not be a Document.
Parameters:
e - the element referencing
uri - the uri of the referenced element

getViewport

public Viewport getViewport(Element e)
Returns the viewport of the specified element.
Parameters:
e - the element interested in its viewport

openViewport

public void openViewport(Element e,
                         Viewport viewport)
Starts a new viewport from the specified element.
Parameters:
e - the element that defines a new viewport
viewport - the viewport of the element

closeViewport

public void closeViewport(Element e)
Closes the viewport associated to the specified element.
Parameters:
e - the element that closes its viewport

bind

public void bind(Element element,
                 GraphicsNode node)
Binds the specified GraphicsNode to the specified Element. This method automatically bind the graphics node to the element and the element to the graphics node.
Parameters:
element - the element to bind to the specified graphics node
node - the graphics node to bind to the specified element

unbind

public void unbind(Element element)
Removes the binding of the specified Element.
Parameters:
element - the element to unbind

getGraphicsNode

public GraphicsNode getGraphicsNode(Element element)
Returns the GraphicsNode associated to the specified Element or null if any.
Parameters:
element - the element associated to the graphics node to return

getElement

public Element getElement(GraphicsNode node)
Returns the Element associated to the specified GraphicsNode or null if any.
Parameters:
node - the graphics node associated to the element to return

getBridge

public Bridge getBridge(Element element)
Returns the bridge associated with the specified element.
Parameters:
element - the element

hasGraphicsNodeBridge

public boolean hasGraphicsNodeBridge(Element element)
Returns true if the specified element has a GraphicsNodeBridge associated to it, false otherwise.
Parameters:
element - the element

getBridge

public Bridge getBridge(java.lang.String namespaceURI,
                        java.lang.String localName)
Returns the bridge associated with the element type
Parameters:
nameSpaceURI - namespace of the requested element
localName - element's local name

putBridge

public void putBridge(java.lang.String namespaceURI,
                      java.lang.String localName,
                      Bridge bridge)
Associates the specified Bridge object with the specified namespace URI and local name.
Parameters:
namespaceURI - the namespace URI
localName - the local name
bridge - the bridge that manages the element

putBridge

public void putBridge(Bridge bridge)
Associates the specified Bridge object with it's namespace URI and local name.
Parameters:
bridge - the bridge that manages the element

removeBridge

public void removeBridge(java.lang.String namespaceURI,
                         java.lang.String localName)
Removes the Bridge object associated to the specified namespace URI and local name.
Parameters:
namespaceURI - the namespace URI
localName - the local name

addDOMListeners

public void addDOMListeners()
Adds EventListeners to the DOM and CSSEngineListener to the CSSEngine to handle any modifications on the DOM tree or style properties and update the GVT tree in response.

storeEventListener

protected void storeEventListener(EventTarget t,
                                  java.lang.String s,
                                  EventListener l,
                                  boolean b)
Adds to the eventListenerList the specified event listener registration.

dispose

public void dispose()
Disposes this BridgeContext.

getSVGContext

protected static SVGContext getSVGContext(Node node)
Returns the SVGContext associated to the specified Node or null if any.

getBridgeUpdateHandler

protected static BridgeUpdateHandler getBridgeUpdateHandler(Node node)
Returns the SVGContext associated to the specified Node or null if any.

getSystemColor

public Value getSystemColor(java.lang.String ident)
Returns the Value corresponding to the given system color.
Specified by:
getSystemColor in interface CSSContext

getLighterFontWeight

public float getLighterFontWeight(float f)
Returns a lighter font-weight.
Specified by:
getLighterFontWeight in interface CSSContext

getBolderFontWeight

public float getBolderFontWeight(float f)
Returns a bolder font-weight.
Specified by:
getBolderFontWeight in interface CSSContext

getPixelUnitToMillimeter

public float getPixelUnitToMillimeter()
Returns the size of a px CSS unit in millimeters.
Specified by:
getPixelUnitToMillimeter in interface CSSContext

getPixelToMillimeter

public float getPixelToMillimeter()
Returns the size of a px CSS unit in millimeters. This will be removed after next release.
Specified by:
getPixelToMillimeter in interface CSSContext
See Also:

getMediumFontSize

public float getMediumFontSize()
Returns the medium font size.
Specified by:
getMediumFontSize in interface CSSContext

getBlockWidth

public float getBlockWidth(Element elt)
Returns the width of the block which directly contains the given element.
Specified by:
getBlockWidth in interface CSSContext

getBlockHeight

public float getBlockHeight(Element elt)
Returns the height of the block which directly contains the given element.
Specified by:
getBlockHeight in interface CSSContext

checkLoadExternalResource

public void checkLoadExternalResource(ParsedURL resourceURL,
                                      ParsedURL docURL)
                               throws java.lang.SecurityException
This method throws a SecurityException if the resource found at url and referenced from docURL should not be loaded. This is a convenience method to call checkLoadExternalResource on the ExternalResourceSecurity strategy returned by getExternalResourceSecurity.
Specified by:
checkLoadExternalResource in interface CSSContext
Parameters:
scriptURL - url for the script, as defined in the script's xlink:href attribute. If that attribute was empty, then this parameter should be null
docURL - url for the document into which the script was found.

registerSVGBridges

public static void registerSVGBridges(BridgeContext ctx)
Registers the bridges to handle SVG 1.0 elements.
Parameters:
ctx - the bridge context to initialize

getBridgeExtensions

public static java.util.List getBridgeExtensions()
Returns the extensions supported by this bridge context.


Copyright © 2002 Apache Software Foundation. All Rights Reserved.