OpenNMS API 1.2.3

org.opennms.web.map
Class DocumentGenerator

java.lang.Object
  extended byorg.opennms.web.map.DocumentGenerator

public class DocumentGenerator
extends java.lang.Object

The core of the SVG generation. We get a Vector of MapNode objects, do all our calculations to figure out how to draw the map, where everything goes, and generate the SVG here.

Author:
Derek Glidden , NKSi

Field Summary
private  javax.servlet.ServletContext ctx
           
private  org.w3c.dom.Document document
           
private  int documentHeight
           
private  int documentWidth
           
private  java.util.Hashtable iconNames
           
private  java.lang.String mapType
           
private  java.lang.String namespace
           
private  java.util.Vector nodes
           
private  java.lang.String urlBase
           
 
Constructor Summary
DocumentGenerator()
          constructor
 
Method Summary
private  void calculateBalancedTreeCoordinates(MapNode parent)
          calculate coordinates for all hosts, doing a balanced-tree drawing thingie.
private  void calculateBoringHostCoordinates()
          do a really stupid and simple "draw hosts left to right, 10 columns by as many rows as necessary
private  void calculateDocumentWidthAndHeight()
          figure out the width and height of the document
 void calculateHostCoordinates()
          calculate the coordinates of each node in the map based on the map type
private  void calculateTreeHostCoordinates()
          start the job of figuring out where on the screen to draw each host by starting to calculate the Balanced Tree coordinates from the root node (node "0")
private  org.w3c.dom.Element createHostElement(MapNode n, boolean loadIcons)
          create an SVG subtree, contained inside elements, for a given node
private  void drawHosts(boolean loadIcons)
          generate SVG for each host
private  void drawLine(MapNode parent, MapNode child)
          draw a line from parent to child
private  void drawLines(MapNode parent)
          draw the lines between parents and children
private  int findMaxChildWidth(MapNode parent)
          figure out the max child width for the map.
 int getDocumentHeight()
          get the height of the SVG created.
 int getDocumentWidth()
          get the width of the SVG created.
 org.w3c.dom.Document getHostDocument(boolean loadIcons)
          create a SVGDOMDocument containing all the elements for each host including icon, hostname, IP address and status.
 java.lang.String getImageMap(java.lang.String mapname, java.lang.String uri)
          generate HTML that will output imagemap information for the map that corresponds to the HostDocument created later.
private  boolean isChildNode(MapNode parent, MapNode child)
          tell me if a given node is child of another node
private  void loadIcons()
          load the SVG icon data so we can embed it directly into the SVG we output instead of loading each icon as an external entity.
private  void log(java.lang.String message)
          log a message.
private  int numberOfImmediateParents(MapNode child)
          find out how many immediate parent hosts for this host.
 void setMapType(java.lang.String type)
          set the type of map we want to draw: "tree" or "boring"
 void setNodes(java.util.Vector nodes)
          set the Vector of nodes that we need to map
 void setServletContext(javax.servlet.ServletContext ctx)
          set the ServletContext so we can find the path to load icons from the filesystem directly and use the log method.
 void setUrlBase(java.lang.String base)
          set the URL base so we can create absolute references to content embedded in our SVG
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

documentWidth

private int documentWidth

documentHeight

private int documentHeight

document

private org.w3c.dom.Document document

namespace

private java.lang.String namespace

nodes

private java.util.Vector nodes

iconNames

private java.util.Hashtable iconNames

ctx

private javax.servlet.ServletContext ctx

mapType

private java.lang.String mapType

urlBase

private java.lang.String urlBase
Constructor Detail

DocumentGenerator

public DocumentGenerator()
constructor

Method Detail

log

private void log(java.lang.String message)
log a message. preferably use the ServletContext' log method, but if we don't have one, just go out to System.err


setNodes

public void setNodes(java.util.Vector nodes)
set the Vector of nodes that we need to map


setServletContext

public void setServletContext(javax.servlet.ServletContext ctx)
set the ServletContext so we can find the path to load icons from the filesystem directly and use the log method.


setUrlBase

public void setUrlBase(java.lang.String base)
set the URL base so we can create absolute references to content embedded in our SVG


setMapType

public void setMapType(java.lang.String type)
set the type of map we want to draw: "tree" or "boring"


loadIcons

private void loadIcons()
load the SVG icon data so we can embed it directly into the SVG we output instead of loading each icon as an external entity. this doesn't work right for some reason. when the SVG is rendered, the icons are all messed up or don't show up. For now, forget trying to load the icons as "symbol" elements inside of the SVG document and just refer to them as external entities... When I have more time, I will try to fix this.


isChildNode

private boolean isChildNode(MapNode parent,
                            MapNode child)
tell me if a given node is child of another node

Parameters:
parent - the parent node you are testing for the parent-child relationship
child - the child node you are testing for the parent-child relationship

numberOfImmediateParents

private int numberOfImmediateParents(MapNode child)
find out how many immediate parent hosts for this host. (adapted from nagios code)

Parameters:
child - the child node for which you wish to find the number of parents

findMaxChildWidth

private int findMaxChildWidth(MapNode parent)
figure out the max child width for the map. (adapted from nagios code)

Parameters:
parent - the parent node for which you wish to find the maximum width of children somewhere down its tree of child nodes

calculateBalancedTreeCoordinates

private void calculateBalancedTreeCoordinates(MapNode parent)
calculate coordinates for all hosts, doing a balanced-tree drawing thingie. (heavily adapted from nagios code. in fact, it would be better to say this is based on the algorithms nagios uses than to say it's in any way based on that code...)

Parameters:
parent - the parent node for which you will start to calculate the rest of the tree coordinates

calculateTreeHostCoordinates

private void calculateTreeHostCoordinates()
start the job of figuring out where on the screen to draw each host by starting to calculate the Balanced Tree coordinates from the root node (node "0")


calculateBoringHostCoordinates

private void calculateBoringHostCoordinates()
do a really stupid and simple "draw hosts left to right, 10 columns by as many rows as necessary


drawLine

private void drawLine(MapNode parent,
                      MapNode child)
draw a line from parent to child

Parameters:
parent - the starting point of the line
child - the ending point of the line

drawLines

private void drawLines(MapNode parent)
draw the lines between parents and children


drawHosts

private void drawHosts(boolean loadIcons)
generate SVG for each host

Parameters:
loadIcons - tell me whether I should generate file:// references to load icons from the filesystem or generate URL references. "true" will generate file:// references for when we are sending the output to the Batik Transcoder, while "false" will generate http:// references for when we are downloading the SVG directly into an external viewer.

calculateDocumentWidthAndHeight

private void calculateDocumentWidthAndHeight()
figure out the width and height of the document


createHostElement

private org.w3c.dom.Element createHostElement(MapNode n,
                                              boolean loadIcons)
create an SVG subtree, contained inside elements, for a given node

Parameters:
loadIcons - tell me whether I should generate file:// references to load icons from the filesystem or generate URL references. "true" will generate file:// references for when we are sending the output to the Batik Transcoder, while "false" will generate http:// references for when we are downloading the SVG directly into an external viewer.

calculateHostCoordinates

public void calculateHostCoordinates()
calculate the coordinates of each node in the map based on the map type


getImageMap

public java.lang.String getImageMap(java.lang.String mapname,
                                    java.lang.String uri)
generate HTML that will output imagemap information for the map that corresponds to the HostDocument created later. This is currently dependent on the NodeFactory generating the same nodes with the same parent/child relationship since the createJavascriptMap and createHostDocument each call it independently. It would be A Good Idea(tm) to call it somewhere externally and, e.g. put it into a Session attribute or something along those lines so we don't run the risk of having the information change between method calls. Will do later...

Parameters:
mapname - the "name" of the HTML element that will have the imagemap attached. e.g.
uri - the page and parameters that will be created for the link for the given node. e.g. "node.jsp?node=" will result in a link to "[urlbase]/node.jsp?node=[nodeid]"

getHostDocument

public org.w3c.dom.Document getHostDocument(boolean loadIcons)
create a SVGDOMDocument containing all the elements for each host including icon, hostname, IP address and status.

Parameters:
loadIcons - tell me whether I should load the icons from the filesystem (true) or generate them as URLs (false)

getDocumentWidth

public int getDocumentWidth()
get the width of the SVG created. this is useful for embedding the SVG in an HTML page. you'll need to call getHostDocument first so that there is a width and height to retrieve.


getDocumentHeight

public int getDocumentHeight()
get the height of the SVG created. this is useful for embedding the SVG in an HTML page. you'll need to call getHostDocument first so that there is a width and height to retrieve.


OpenNMS API 1.2.3

Generated by eevans on May 29 2005 2015.