001 /*
002 * Copyright 2000-2005 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025
026 package javax.xml.transform.sax;
027
028 import javax.xml.transform.Result;
029
030 import org.xml.sax.ContentHandler;
031 import org.xml.sax.ext.LexicalHandler;
032
033 /**
034 * <p>Acts as an holder for a transformation Result.</p>
035 *
036 * @author <a href="Jeff.Suttor@Sun.com">Jeff Suttor</a>
037 */
038 public class SAXResult implements Result {
039
040 /**
041 * If {@link javax.xml.transform.TransformerFactory#getFeature}
042 * returns true when passed this value as an argument,
043 * the Transformer supports Result output of this type.
044 */
045 public static final String FEATURE = "http://javax.xml.transform.sax.SAXResult/feature";
046
047 /**
048 * Zero-argument default constructor.
049 */
050 public SAXResult() {
051 }
052
053 /**
054 * Create a SAXResult that targets a SAX2 {@link org.xml.sax.ContentHandler}.
055 *
056 * @param handler Must be a non-null ContentHandler reference.
057 */
058 public SAXResult(ContentHandler handler) {
059 setHandler(handler);
060 }
061
062 /**
063 * Set the target to be a SAX2 {@link org.xml.sax.ContentHandler}.
064 *
065 * @param handler Must be a non-null ContentHandler reference.
066 */
067 public void setHandler(ContentHandler handler) {
068 this .handler = handler;
069 }
070
071 /**
072 * Get the {@link org.xml.sax.ContentHandler} that is the Result.
073 *
074 * @return The ContentHandler that is to be transformation output.
075 */
076 public ContentHandler getHandler() {
077 return handler;
078 }
079
080 /**
081 * Set the SAX2 {@link org.xml.sax.ext.LexicalHandler} for the output.
082 *
083 * <p>This is needed to handle XML comments and the like. If the
084 * lexical handler is not set, an attempt should be made by the
085 * transformer to cast the {@link org.xml.sax.ContentHandler} to a
086 * <code>LexicalHandler</code>.</p>
087 *
088 * @param handler A non-null <code>LexicalHandler</code> for
089 * handling lexical parse events.
090 */
091 public void setLexicalHandler(LexicalHandler handler) {
092 this .lexhandler = handler;
093 }
094
095 /**
096 * Get a SAX2 {@link org.xml.sax.ext.LexicalHandler} for the output.
097 *
098 * @return A <code>LexicalHandler</code>, or null.
099 */
100 public LexicalHandler getLexicalHandler() {
101 return lexhandler;
102 }
103
104 /**
105 * Method setSystemId Set the systemID that may be used in association
106 * with the {@link org.xml.sax.ContentHandler}.
107 *
108 * @param systemId The system identifier as a URI string.
109 */
110 public void setSystemId(String systemId) {
111 this .systemId = systemId;
112 }
113
114 /**
115 * Get the system identifier that was set with setSystemId.
116 *
117 * @return The system identifier that was set with setSystemId, or null
118 * if setSystemId was not called.
119 */
120 public String getSystemId() {
121 return systemId;
122 }
123
124 //////////////////////////////////////////////////////////////////////
125 // Internal state.
126 //////////////////////////////////////////////////////////////////////
127
128 /**
129 * The handler for parse events.
130 */
131 private ContentHandler handler;
132
133 /**
134 * The handler for lexical events.
135 */
136 private LexicalHandler lexhandler;
137
138 /**
139 * The systemID that may be used in association
140 * with the node.
141 */
142 private String systemId;
143 }
|