001: /*
002: * This file or a portion of this file is licensed under the terms of
003: * the Globus Toolkit Public License, found in file ../GTPL, or at
004: * http://www.globus.org/toolkit/download/license.html. This notice must
005: * appear in redistributions of this file, with or without modification.
006: *
007: * Redistributions of this Software, with or without modification, must
008: * reproduce the GTPL in: (1) the Software, or (2) the Documentation or
009: * some other similar material which is provided with the Software (if
010: * any).
011: *
012: * Copyright 1999-2004 University of Chicago and The University of
013: * Southern California. All rights reserved.
014: */
015:
016: package org.griphyn.vdl.classes;
017:
018: import org.griphyn.vdl.classes.*;
019: import java.util.*;
020: import java.io.IOException;
021: import java.io.Writer;
022: import java.io.Serializable;
023:
024: /**
025: * This class implements nothing for meta data.
026: *
027: * @author Jens-S. Vöckler
028: * @author Yong Zhao
029: * @version $Revision: 50 $
030: */
031: public class Meta extends VDL implements Serializable {
032: /**
033: * Stores the content of whatever.
034: */
035: private String m_content;
036:
037: /**
038: * Default ctor. Calls the parent initialization.
039: */
040: public Meta() {
041: super ();
042: this .m_content = new String();
043: }
044:
045: /**
046: * Ctor to initialize the content while constructing the class.
047: * This is a convenience ctor.
048: */
049: public Meta(String content) {
050: super ();
051: this .m_content = content;
052: }
053:
054: /**
055: * Appends text to the current internal state. The text may contain
056: * other elements which are not quoted or changed in any way.
057: *
058: * @param content is the new text to append to the current content.
059: * @see #getContent()
060: */
061: public void addContent(String content) {
062: this .m_content += content;
063: }
064:
065: /**
066: * Gets the content state of this object. The text may contain
067: * other elements which are not quoted or changed in any way.
068: *
069: * @return The current state of content. The text may be null.
070: * @see #setContent(String)
071: */
072: public String getContent() {
073: return this .m_content;
074: }
075:
076: /**
077: * Overwrites the internal state with new content. The supplied content
078: * will become effectively the active state of the object. Usually, this
079: * method will be called during SAX assembly of the instance structure.
080: *
081: * @param content is the new state to register.
082: * @see #getContent()
083: **/
084: public void setContent(String content) {
085: this .m_content = content;
086: }
087:
088: /**
089: * Converts the active state into something meant for human consumption.
090: * This method overwrites the base class default as it can be more
091: * efficiently implemented.
092: *
093: * @return There is not textual representation of metadata in VDLt.
094: */
095: public String toString() {
096: return new String();
097: }
098:
099: /**
100: * Prints the current content onto the stream. This is a no-op, because
101: * there is not textual representation of metadata in VDLt.
102: *
103: * @param stream is a stream opened and ready for writing. This can also
104: * be a string stream for efficient output.
105: * @throws IOException if something happens to the stream.
106: */
107: public void toString(Writer stream) throws IOException {
108: // do nothing
109: }
110:
111: /**
112: * Dump the state of the current element as XML output. The stream
113: * interface should be able to handle large output efficiently, if you
114: * use a buffered writer.
115: *
116: * @param stream is a stream opened and ready for writing. This can also
117: * be a string stream for efficient output.
118: * @param indent is a <code>String</code> of spaces used for pretty
119: * printing. The initial amount of spaces should be an empty string.
120: * The parameter is used internally for the recursive traversal.
121: * @param namespace is the XML schema namespace prefix. If neither
122: * empty nor null, each element will be prefixed with this prefix,
123: * and the root element will map the XML namespace.
124: * @exception IOException if something fishy happens to the stream.
125: */
126: public void toXML(Writer stream, String indent, String namespace)
127: throws IOException {
128: String tag = (namespace != null && namespace.length() > 0) ? namespace
129: + ":meta"
130: : "meta";
131:
132: // just one tag
133: if (indent != null && indent.length() > 0)
134: stream.write(indent);
135: stream.write('<');
136: stream.write(tag);
137: if (this .m_content.length() > 0) {
138: stream.write('>');
139: stream.write(quote(this .m_content, false));
140: stream.write("</");
141: stream.write(tag);
142: stream.write('>');
143: } else {
144: stream.write("/>");
145: }
146: if (indent != null)
147: stream.write(System.getProperty("line.separator", "\r\n"));
148: }
149: }
|