001: /*
002: * Label.java
003: *
004: * Version: $Revision: 1.4 $
005: *
006: * Date: $Date: 2006/03/13 17:19:39 $
007: *
008: * Copyright (c) 2002-2005, Hewlett-Packard Company and Massachusetts
009: * Institute of Technology. All rights reserved.
010: *
011: * Redistribution and use in source and binary forms, with or without
012: * modification, are permitted provided that the following conditions are
013: * met:
014: *
015: * - Redistributions of source code must retain the above copyright
016: * notice, this list of conditions and the following disclaimer.
017: *
018: * - Redistributions in binary form must reproduce the above copyright
019: * notice, this list of conditions and the following disclaimer in the
020: * documentation and/or other materials provided with the distribution.
021: *
022: * - Neither the name of the Hewlett-Packard Company nor the name of the
023: * Massachusetts Institute of Technology nor the names of their
024: * contributors may be used to endorse or promote products derived from
025: * this software without specific prior written permission.
026: *
027: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
028: * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
029: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
030: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
031: * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
032: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
033: * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
034: * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
035: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
036: * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
037: * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
038: * DAMAGE.
039: */
040:
041: package org.dspace.app.xmlui.wing.element;
042:
043: import org.dspace.app.xmlui.wing.AttributeMap;
044: import org.dspace.app.xmlui.wing.WingContext;
045: import org.dspace.app.xmlui.wing.WingException;
046: import org.xml.sax.ContentHandler;
047: import org.xml.sax.SAXException;
048: import org.xml.sax.ext.LexicalHandler;
049: import org.xml.sax.helpers.NamespaceSupport;
050:
051: /**
052: * This class represents a list's label element, they are associated with an
053: * item and annotates that item with a number, a textual description of some
054: * sort, or a simple bullet.
055: *
056: * @author Scott Phillips
057: */
058:
059: public class Label extends TextContainer implements StructuralElement {
060: /** The name of the label element */
061: public static final String E_LABEL = "label";
062:
063: /** The label's name */
064: private String name;
065:
066: /** Special rendering hints */
067: private String rend;
068:
069: /**
070: * Construct a new label.
071: *
072: * @param context
073: * (Required) The context this element is contained in
074: * @param name
075: * (May be null) The label's name
076: * @param rend
077: * (May be null) a rendering hint used to override the default
078: * display of the element.
079: * @throws WingException
080: */
081: protected Label(WingContext context, String name, String rend)
082: throws WingException {
083: super (context);
084: this .name = name;
085: this .rend = rend;
086: }
087:
088: /**
089: * Translate this element and all contained elements into SAX events. The
090: * events should be routed to the contentHandler found in the WingContext.
091: *
092: * @param contentHandler
093: * (Required) The registered contentHandler where SAX events
094: * should be routed too.
095: * @param lexicalHandler
096: * (Required) The registered lexicalHandler where lexical
097: * events (such as CDATA, DTD, etc) should be routed too.
098: * @param namespaces
099: * (Required) SAX Helper class to keep track of namespaces able
100: * to determine the correct prefix for a given namespace URI.
101: */
102: public void toSAX(ContentHandler contentHandler,
103: LexicalHandler lexicalHandler, NamespaceSupport namespaces)
104: throws SAXException {
105: AttributeMap attributes = new AttributeMap();
106: if (this .name != null) {
107: attributes.put(A_NAME, name);
108: attributes.put(A_ID, context.generateID(E_LABEL, name));
109: }
110: if (this .rend != null)
111: attributes.put(A_RENDER, this .rend);
112:
113: startElement(contentHandler, namespaces, E_LABEL, attributes);
114: super .toSAX(contentHandler, lexicalHandler, namespaces);
115: endElement(contentHandler, namespaces, E_LABEL);
116: }
117:
118: /**
119: * dispose()
120: */
121: public void dispose() {
122: super.dispose();
123: }
124: }
|