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 import org.xml.sax.ContentHandler; 24 import org.xml.sax.ext.LexicalHandler; 25 26 /** 27 * <p>Acts as an holder for a transformation Result.</p> 28 * 29 * @author <a href="Jeff.Suttor@Sun.com">Jeff Suttor</a> 30 */ 31 public class SAXResult implements Result { 32 33 /** 34 * If {@link javax.xml.transform.TransformerFactory#getFeature} 35 * returns true when passed this value as an argument, 36 * the Transformer supports Result output of this type. 37 */ 38 public static final String FEATURE = 39 "http://javax.xml.transform.sax.SAXResult/feature"; 40 41 /** 42 * Zero-argument default constructor. 43 */ SAXResult()44 public SAXResult() { 45 } 46 47 /** 48 * Create a SAXResult that targets a SAX2 {@link org.xml.sax.ContentHandler}. 49 * 50 * @param handler Must be a non-null ContentHandler reference. 51 */ SAXResult(ContentHandler handler)52 public SAXResult(ContentHandler handler) { 53 setHandler(handler); 54 } 55 56 /** 57 * Set the target to be a SAX2 {@link org.xml.sax.ContentHandler}. 58 * 59 * @param handler Must be a non-null ContentHandler reference. 60 */ setHandler(ContentHandler handler)61 public void setHandler(ContentHandler handler) { 62 this.handler = handler; 63 } 64 65 /** 66 * Get the {@link org.xml.sax.ContentHandler} that is the Result. 67 * 68 * @return The ContentHandler that is to be transformation output. 69 */ getHandler()70 public ContentHandler getHandler() { 71 return handler; 72 } 73 74 /** 75 * Set the SAX2 {@link org.xml.sax.ext.LexicalHandler} for the output. 76 * 77 * <p>This is needed to handle XML comments and the like. If the 78 * lexical handler is not set, an attempt should be made by the 79 * transformer to cast the {@link org.xml.sax.ContentHandler} to a 80 * <code>LexicalHandler</code>.</p> 81 * 82 * @param handler A non-null <code>LexicalHandler</code> for 83 * handling lexical parse events. 84 */ setLexicalHandler(LexicalHandler handler)85 public void setLexicalHandler(LexicalHandler handler) { 86 this.lexhandler = handler; 87 } 88 89 /** 90 * Get a SAX2 {@link org.xml.sax.ext.LexicalHandler} for the output. 91 * 92 * @return A <code>LexicalHandler</code>, or null. 93 */ getLexicalHandler()94 public LexicalHandler getLexicalHandler() { 95 return lexhandler; 96 } 97 98 /** 99 * Method setSystemId Set the systemID that may be used in association 100 * with the {@link org.xml.sax.ContentHandler}. 101 * 102 * @param systemId The system identifier as a URI string. 103 */ setSystemId(String systemId)104 public void setSystemId(String systemId) { 105 this.systemId = systemId; 106 } 107 108 /** 109 * Get the system identifier that was set with setSystemId. 110 * 111 * @return The system identifier that was set with setSystemId, or null 112 * if setSystemId was not called. 113 */ getSystemId()114 public String getSystemId() { 115 return systemId; 116 } 117 118 ////////////////////////////////////////////////////////////////////// 119 // Internal state. 120 ////////////////////////////////////////////////////////////////////// 121 122 /** 123 * The handler for parse events. 124 */ 125 private ContentHandler handler; 126 127 /** 128 * The handler for lexical events. 129 */ 130 private LexicalHandler lexhandler; 131 132 /** 133 * The systemID that may be used in association 134 * with the node. 135 */ 136 private String systemId; 137 } 138