001: /*
002: * Meta.java
003: *
004: * Version: $Revision: 1.6 $
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.WingConstants;
044: import org.dspace.app.xmlui.wing.WingContext;
045: import org.dspace.app.xmlui.wing.WingException;
046: import org.xml.sax.Attributes;
047: import org.xml.sax.ContentHandler;
048: import org.xml.sax.SAXException;
049: import org.xml.sax.ext.LexicalHandler;
050: import org.xml.sax.helpers.NamespaceSupport;
051:
052: /**
053: * A class representing the page division.
054: *
055: * The body contains any number of divisions (div elements) which group content
056: * into interactive and non interactive display blocks.
057: *
058: * @author Scott Phillips
059: */
060: public class Meta extends AbstractWingElement implements
061: WingMergeableElement {
062: /** The name of the meta element */
063: public static final String E_META = "meta";
064:
065: /** The divisions contained within this body */
066: private boolean merged = false;
067:
068: /** User oriented metadata associated with this document */
069: private UserMeta userMeta;
070:
071: /** Page oriented metadata associated with this document */
072: private PageMeta pageMeta;
073:
074: /** Repository oriented metadata associated with this document */
075: private RepositoryMeta repositoryMeta;
076:
077: protected Meta(WingContext context) throws WingException {
078: // FIXME: don't statically assign authenticated status or
079: // repositoryIdentifier.
080: super (context);
081: userMeta = new UserMeta(context);
082: pageMeta = new PageMeta(context);
083: repositoryMeta = new RepositoryMeta(context);
084: }
085:
086: /**
087: * Set a new user oriented metadata set.
088: *
089: * @return The user oriented metadata set.
090: */
091: public UserMeta setUserMeta() throws WingException {
092: return this .userMeta;
093: }
094:
095: /**
096: * Set a new page oriented metadata set.
097: *
098: * @return The page oriented metadata set.
099: */
100: public PageMeta setPageMeta() throws WingException {
101: return this .pageMeta;
102: }
103:
104: /**
105: * Set a new repository oriented metadata set.
106: *
107: * @return The repository oriented metadata set.
108: */
109: public RepositoryMeta setRepositoryMeta() throws WingException {
110: return this .repositoryMeta;
111: }
112:
113: /**
114: * Determine if the given SAX event is a Meta element.
115: *
116: * @param namespace
117: * The element's name space
118: * @param localName
119: * The local, unqualified, name for this element
120: * @param qName
121: * The qualified name for this element
122: * @param attributes
123: * The element's attributes
124: * @return True if this WingElement is equivalent to the given SAX Event.
125: */
126: public boolean mergeEqual(String namespace, String localName,
127: String qName, Attributes attributes) throws SAXException,
128: WingException {
129: if (!WingConstants.DRI.URI.equals(namespace))
130: return false;
131:
132: if (!E_META.equals(localName))
133: return false;
134:
135: return true;
136: }
137:
138: /**
139: * Merge the given sub-domain of metadata elements.
140: *
141: * @param namespace
142: * The element's name space
143: * @param localName
144: * The local, unqualified, name for this element *
145: * @param qName
146: * The qualified name for this element
147: * @param attributes
148: * The element's attributes
149: * @return The child element
150: */
151: public WingMergeableElement mergeChild(String namespace,
152: String localName, String qName, Attributes attributes)
153: throws SAXException, WingException {
154: // User
155: if (this .userMeta != null
156: && this .userMeta.mergeEqual(namespace, localName,
157: qName, attributes)) {
158: UserMeta userMeta = this .userMeta;
159: this .userMeta = null;
160: return userMeta;
161: }
162:
163: // page
164: if (this .pageMeta != null
165: && this .pageMeta.mergeEqual(namespace, localName,
166: qName, attributes)) {
167: PageMeta pageMeta = this .pageMeta;
168: this .pageMeta = null;
169: return pageMeta;
170: }
171:
172: // repository
173: if (this .repositoryMeta != null
174: && this .repositoryMeta.mergeEqual(namespace, localName,
175: qName, attributes)) {
176: RepositoryMeta repositoryMeta = this .repositoryMeta;
177: this .repositoryMeta = null;
178: return repositoryMeta;
179: }
180:
181: return null;
182: }
183:
184: /**
185: * Notify this element that it is being merged.
186: *
187: * @return The attributes for this merged element
188: */
189: public Attributes merge(Attributes attributes) throws SAXException,
190: WingException {
191: this .merged = true;
192: return attributes;
193: }
194:
195: /**
196: * Translate to SAX events
197: *
198: * @param contentHandler
199: * (Required) The registered contentHandler where SAX events
200: * should be routed too.
201: * @param lexicalHandler
202: * (Required) The registered lexicalHandler where lexical
203: * events (such as CDATA, DTD, etc) should be routed too.
204: * @param namespaces
205: * (Required) SAX Helper class to keep track of namespaces able
206: * to determine the correct prefix for a given namespace URI.
207: */
208: public void toSAX(ContentHandler contentHandler,
209: LexicalHandler lexicalHandler, NamespaceSupport namespaces)
210: throws SAXException {
211: if (!merged)
212: startElement(contentHandler, namespaces, E_META, null);
213:
214: if (this .userMeta != null)
215: this .userMeta.toSAX(contentHandler, lexicalHandler,
216: namespaces);
217: if (this .pageMeta != null)
218: this .pageMeta.toSAX(contentHandler, lexicalHandler,
219: namespaces);
220: if (this .repositoryMeta != null)
221: this .repositoryMeta.toSAX(contentHandler, lexicalHandler,
222: namespaces);
223:
224: if (!merged)
225: endElement(contentHandler, namespaces, E_META);
226: }
227:
228: /**
229: * dispose
230: */
231: public void dispose() {
232: if (this.userMeta != null)
233: this.userMeta.dispose();
234: if (this.pageMeta != null)
235: this.pageMeta.dispose();
236: if (this.repositoryMeta != null)
237: this.repositoryMeta.dispose();
238:
239: this.userMeta = null;
240: this.pageMeta = null;
241: this.repositoryMeta = null;
242:
243: super.dispose();
244: }
245: }
|