| Method from org.dom4j.io.DispatchHandler Detail: |
public void addHandler(String handlerPath,
ElementHandler handler) {
handlers.put(handlerPath, handler);
}
Adds the ElementHandler to be called when the specified
path is encounted. |
public boolean containsHandler(String handlerPath) {
return handlers.containsKey(handlerPath);
}
|
public int getActiveHandlerCount() {
return handlerStack.size();
}
Returns the number of ElementHandler objects that are waiting for
their elements closing tag. |
public ElementHandler getHandler(String handlerPath) {
return (ElementHandler) handlers.get(handlerPath);
}
|
public String getPath() {
return path;
}
|
public void onEnd(ElementPath elementPath) {
if ((handlers != null) && (handlers.containsKey(path))) {
// This node has a handler associated with it.
// Find the handler and pop it from the handler stack.
ElementHandler handler = (ElementHandler) handlers.get(path);
handlerStack.remove(handlerStack.size() - 1);
// Call the handlers onEnd method
handler.onEnd(elementPath);
} else {
// No handler is associated with this node, so use the
// defaultHandler it it exists.
if (handlerStack.isEmpty() && (defaultHandler != null)) {
defaultHandler.onEnd(elementPath);
}
}
// Set path back to its parent
path = (String) pathStack.remove(pathStack.size() - 1);
if (pathStack.size() == 0) {
atRoot = true;
}
}
|
public void onStart(ElementPath elementPath) {
Element element = elementPath.getCurrent();
// Save the location of the last (i.e. parent) path
pathStack.add(path);
// Calculate the new path
if (atRoot) {
path = path + element.getName();
atRoot = false;
} else {
path = path + "/" + element.getName();
}
if ((handlers != null) && (handlers.containsKey(path))) {
// The current node has a handler associated with it.
// Find the handler and save it on the handler stack.
ElementHandler handler = (ElementHandler) handlers.get(path);
handlerStack.add(handler);
// Call the handlers onStart method.
handler.onStart(elementPath);
} else {
// No handler is associated with this node, so use the
// defaultHandler it it exists.
if (handlerStack.isEmpty() && (defaultHandler != null)) {
defaultHandler.onStart(elementPath);
}
}
}
|
public ElementHandler removeHandler(String handlerPath) {
return (ElementHandler) handlers.remove(handlerPath);
}
Removes the ElementHandler from the event based processor,
for the specified path. |
public void resetHandlers() {
atRoot = true;
path = "/";
pathStack.clear();
handlerStack.clear();
handlers.clear();
defaultHandler = null;
}
Used to remove all the Element Handlers and return things back to the way
they were when object was created. |
public void setDefaultHandler(ElementHandler handler) {
defaultHandler = handler;
}
When multiple ElementHandler instances have been
registered, this will set a default ElementHandler to be
called for any path which does NOT have a handler registered. |