1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 // $Id: SAXResult.java 446598 2006-09-15 12:55:40Z jeremias $ 19 20 package javax.xml.transform.sax; 21 22 import javax.xml.transform.Result; 23 24 import org.xml.sax.ContentHandler; 25 import org.xml.sax.ext.LexicalHandler; 26 27 /** 28 * <p>Acts as an holder for a transformation Result.</p> 29 * 30 * @author <a href="Jeff.Suttor@Sun.com">Jeff Suttor</a> 31 */ 32 public class SAXResult implements Result { 33 34 /** 35 * If {@link javax.xml.transform.TransformerFactory#getFeature} 36 * returns true when passed this value as an argument, 37 * the Transformer supports Result output of this type. 38 */ 39 public static final String FEATURE = 40 "http://javax.xml.transform.sax.SAXResult/feature"; 41 42 /** 43 * Zero-argument default constructor. 44 */ 45 public SAXResult() { 46 } 47 48 /** 49 * Create a SAXResult that targets a SAX2 {@link org.xml.sax.ContentHandler}. 50 * 51 * @param handler Must be a non-null ContentHandler reference. 52 */ 53 public SAXResult(ContentHandler handler) { 54 setHandler(handler); 55 } 56 57 /** 58 * Set the target to be a SAX2 {@link org.xml.sax.ContentHandler}. 59 * 60 * @param handler Must be a non-null ContentHandler reference. 61 */ 62 public void setHandler(ContentHandler handler) { 63 this.handler = handler; 64 } 65 66 /** 67 * Get the {@link org.xml.sax.ContentHandler} that is the Result. 68 * 69 * @return The ContentHandler that is to be transformation output. 70 */ 71 public ContentHandler getHandler() { 72 return handler; 73 } 74 75 /** 76 * Set the SAX2 {@link org.xml.sax.ext.LexicalHandler} for the output. 77 * 78 * <p>This is needed to handle XML comments and the like. If the 79 * lexical handler is not set, an attempt should be made by the 80 * transformer to cast the {@link org.xml.sax.ContentHandler} to a 81 * <code>LexicalHandler</code>.</p> 82 * 83 * @param handler A non-null <code>LexicalHandler</code> for 84 * handling lexical parse events. 85 */ 86 public void setLexicalHandler(LexicalHandler handler) { 87 this.lexhandler = handler; 88 } 89 90 /** 91 * Get a SAX2 {@link org.xml.sax.ext.LexicalHandler} for the output. 92 * 93 * @return A <code>LexicalHandler</code>, or null. 94 */ 95 public LexicalHandler getLexicalHandler() { 96 return lexhandler; 97 } 98 99 /** 100 * Method setSystemId Set the systemID that may be used in association 101 * with the {@link org.xml.sax.ContentHandler}. 102 * 103 * @param systemId The system identifier as a URI string. 104 */ 105 public void setSystemId(String systemId) { 106 this.systemId = systemId; 107 } 108 109 /** 110 * Get the system identifier that was set with setSystemId. 111 * 112 * @return The system identifier that was set with setSystemId, or null 113 * if setSystemId was not called. 114 */ 115 public String getSystemId() { 116 return systemId; 117 } 118 119 ////////////////////////////////////////////////////////////////////// 120 // Internal state. 121 ////////////////////////////////////////////////////////////////////// 122 123 /** 124 * The handler for parse events. 125 */ 126 private ContentHandler handler; 127 128 /** 129 * The handler for lexical events. 130 */ 131 private LexicalHandler lexhandler; 132 133 /** 134 * The systemID that may be used in association 135 * with the node. 136 */ 137 private String systemId; 138 }