1/*
2 * Copyright (c) 2000, 2005, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.  Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26package javax.xml.transform.sax;
27
28import javax.xml.transform.Result;
29
30import org.xml.sax.ContentHandler;
31import org.xml.sax.ext.LexicalHandler;
32
33/**
34 * <p>Acts as an holder for a transformation Result.</p>
35 *
36 * @author <a href="Jeff.Suttor@Sun.com">Jeff Suttor</a>
37 * @since 1.4
38 */
39public class SAXResult implements Result {
40
41    /**
42     * If {@link javax.xml.transform.TransformerFactory#getFeature}
43     * returns true when passed this value as an argument,
44     * the Transformer supports Result output of this type.
45     */
46    public static final String FEATURE =
47        "http://javax.xml.transform.sax.SAXResult/feature";
48
49    /**
50     * Zero-argument default constructor.
51     */
52    public SAXResult() {
53    }
54
55    /**
56     * Create a SAXResult that targets a SAX2 {@link org.xml.sax.ContentHandler}.
57     *
58     * @param handler Must be a non-null ContentHandler reference.
59     */
60    public SAXResult(ContentHandler handler) {
61        setHandler(handler);
62    }
63
64    /**
65     * Set the target to be a SAX2 {@link org.xml.sax.ContentHandler}.
66     *
67     * @param handler Must be a non-null ContentHandler reference.
68     */
69    public void setHandler(ContentHandler handler) {
70        this.handler = handler;
71    }
72
73    /**
74     * Get the {@link org.xml.sax.ContentHandler} that is the Result.
75     *
76     * @return The ContentHandler that is to be transformation output.
77     */
78    public ContentHandler getHandler() {
79        return handler;
80    }
81
82    /**
83     * Set the SAX2 {@link org.xml.sax.ext.LexicalHandler} for the output.
84     *
85     * <p>This is needed to handle XML comments and the like.  If the
86     * lexical handler is not set, an attempt should be made by the
87     * transformer to cast the {@link org.xml.sax.ContentHandler} to a
88     * <code>LexicalHandler</code>.</p>
89     *
90     * @param handler A non-null <code>LexicalHandler</code> for
91     * handling lexical parse events.
92     */
93    public void setLexicalHandler(LexicalHandler handler) {
94        this.lexhandler = handler;
95    }
96
97    /**
98     * Get a SAX2 {@link org.xml.sax.ext.LexicalHandler} for the output.
99     *
100     * @return A <code>LexicalHandler</code>, or null.
101     */
102    public LexicalHandler getLexicalHandler() {
103        return lexhandler;
104    }
105
106    /**
107     * Method setSystemId Set the systemID that may be used in association
108     * with the {@link org.xml.sax.ContentHandler}.
109     *
110     * @param systemId The system identifier as a URI string.
111     */
112    public void setSystemId(String systemId) {
113        this.systemId = systemId;
114    }
115
116    /**
117     * Get the system identifier that was set with setSystemId.
118     *
119     * @return The system identifier that was set with setSystemId, or null
120     * if setSystemId was not called.
121     */
122    public String getSystemId() {
123        return systemId;
124    }
125
126    //////////////////////////////////////////////////////////////////////
127    // Internal state.
128    //////////////////////////////////////////////////////////////////////
129
130    /**
131     * The handler for parse events.
132     */
133    private ContentHandler handler;
134
135    /**
136     * The handler for lexical events.
137     */
138    private LexicalHandler lexhandler;
139
140    /**
141     * The systemID that may be used in association
142     * with the node.
143     */
144    private String systemId;
145}
146