001: /*
002: * This file is part of the WfMOpen project.
003: * Copyright (C) 2001-2003 Danet GmbH (www.danet.de), GS-AN.
004: * All rights reserved.
005: *
006: * This program is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU General Public License as published by
008: * the Free Software Foundation; either version 2 of the License, or
009: * (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: * $Id: StackedHandler.java,v 1.2 2006/09/29 12:32:11 drmlipp Exp $
021: *
022: * $Log: StackedHandler.java,v $
023: * Revision 1.2 2006/09/29 12:32:11 drmlipp
024: * Consistently using WfMOpen as projct name now.
025: *
026: * Revision 1.1.1.1 2003/06/30 20:05:12 drmlipp
027: * Initial import
028: *
029: * Revision 1.8 2003/06/27 08:51:46 lipp
030: * Fixed copyright/license information.
031: *
032: * Revision 1.7 2003/04/25 14:50:59 lipp
033: * Fixed javadoc errors and warnings.
034: *
035: * Revision 1.6 2003/04/22 11:13:31 lipp
036: * Various fixes.
037: *
038: * Revision 1.5 2003/04/21 20:25:41 lipp
039: * Major revision of implementation.
040: *
041: * Revision 1.4 2002/01/28 13:43:32 lipp
042: * Added namespace handling in DelegatingHandler.
043: *
044: * Revision 1.3 2002/01/23 09:42:34 lipp
045: * Added default handler and attributes.
046: *
047: * Revision 1.2 2002/01/22 22:28:26 lipp
048: * Getting started with sax support, the second.
049: *
050: * Revision 1.1 2002/01/22 15:51:48 lipp
051: * Getting started with sax support.
052: *
053: */
054: package de.danet.an.util.sax;
055:
056: import org.xml.sax.helpers.DefaultHandler;
057:
058: /**
059: * <code>StackedHandler</code> represents an item on the {@link
060: * HandlerStack <code>HandlerStack</code>}. While any {@link
061: * org.xml.sax.ContentHandler <code>ContentHandler</code>} may be
062: * pushed on the stack, the <code>StackedHandler</code> provides some
063: * convenience methods that may help implementing a stacked handler.
064: */
065: public class StackedHandler extends DefaultHandler {
066:
067: /**
068: * The handler stack.
069: */
070: private HandlerStack stack;
071:
072: /**
073: * Default constructor. The reference to the stack is initialized
074: * when the handler is pushed on the stack.
075: */
076: public StackedHandler() {
077: super ();
078: }
079:
080: /**
081: * Set the stack. Called by the <code>HandlerStack</code> during
082: * <code>push</code>.
083: *
084: * @param theStack the stack.
085: */
086: void setStack(HandlerStack theStack) {
087: stack = theStack;
088: }
089:
090: /**
091: * Return the stack this handler is pushed on.
092: * @return the associated stack.
093: */
094: public HandlerStack getStack() {
095: return stack;
096: }
097:
098: /**
099: * Return the collected character data of the current element.
100: * @return collected characters.
101: */
102: public String text() {
103: return stack.text();
104: }
105:
106: /**
107: * Sets a context data item of the stack. This is a shortcut for
108: * <code>getStack().setContextData (...)</code>.
109: * @param name the name of the item.
110: * @param value the associated value.
111: * @see #getContextData
112: * @see HandlerStack#setContextData
113: */
114: public void setContextData(String name, Object value) {
115: stack.setContextData(name, value);
116: }
117:
118: /**
119: * Retrieves a context data item of the stack. This is a shortcut
120: * for <code>getStack().getContextData (...)</code>.
121: * @param name the name of the data item.
122: * @return the associated value or <code>null</code> if the attribute
123: * has not been set.
124: * @see #setContextData
125: * @see HandlerStack#getContextData
126: */
127: public Object getContextData(String name) {
128: return stack.getContextData(name);
129: }
130:
131: /**
132: * Retrieves and removes a context data item of the stack. This is
133: * a shortcut for <code>getStack().removeContextData (...)</code>.
134: * @param name the name of the data item.
135: * @return the associated value or <code>null</code> if the attribute
136: * has not been set.
137: * @see #setContextData
138: * @see HandlerStack#getContextData
139: */
140: public Object removeContextData(String name) {
141: return stack.removeContextData(name);
142: }
143:
144: /**
145: * Return the current path. This is a shortcut for
146: * <code>getStack().currentPath()</code>.
147: * @return the current path.
148: */
149: public String currentPath() {
150: return stack.currentPath();
151: }
152:
153: }
|