286N/A/*
286N/A * reserved comment block
286N/A * DO NOT REMOVE OR ALTER!
286N/A */
286N/A/*
286N/A * Copyright 2001, 2002,2004 The Apache Software Foundation.
286N/A *
286N/A * Licensed under the Apache License, Version 2.0 (the "License");
286N/A * you may not use this file except in compliance with the License.
286N/A * You may obtain a copy of the License at
286N/A *
286N/A * http://www.apache.org/licenses/LICENSE-2.0
286N/A *
286N/A * Unless required by applicable law or agreed to in writing, software
286N/A * distributed under the License is distributed on an "AS IS" BASIS,
286N/A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
286N/A * See the License for the specific language governing permissions and
286N/A * limitations under the License.
286N/A */
286N/A
286N/Apackage com.sun.org.apache.xerces.internal.dom;
286N/A
286N/Aimport org.w3c.dom.ls.LSInput;
286N/A
286N/Aimport java.io.Reader;
286N/Aimport java.io.InputStream;
286N/A
286N/A/**
286N/A * This Class <code>DOMInputImpl</code> represents a single input source for an XML entity.
286N/A * <p> This Class allows an application to encapsulate information about
286N/A * an input source in a single object, which may include a public
286N/A * identifier, a system identifier, a byte stream (possibly with a specified
286N/A * encoding), and/or a character stream.
286N/A * <p> The exact definitions of a byte stream and a character stream are
286N/A * binding dependent.
286N/A * <p> There are two places that the application will deliver this input
286N/A * source to the parser: as the argument to the <code>parse</code> method,
286N/A * or as the return value of the <code>DOMResourceResolver.resolveEntity</code>
286N/A * method.
286N/A * <p> The <code>DOMParser</code> will use the <code>LSInput</code>
286N/A * object to determine how to read XML input. If there is a character stream
286N/A * available, the parser will read that stream directly; if not, the parser
286N/A * will use a byte stream, if available; if neither a character stream nor a
286N/A * byte stream is available, the parser will attempt to open a URI
286N/A * connection to the resource identified by the system identifier.
286N/A * <p> An <code>LSInput</code> object belongs to the application: the
286N/A * parser shall never modify it in any way (it may modify a copy if
286N/A * necessary). Eventhough all attributes in this interface are writable the
286N/A * DOM implementation is expected to never mutate a LSInput.
286N/A * <p>See also the <a href='http://www.w3.org/TR/2001/WD-DOM-Level-3-ASLS-20011025'>Document Object Model (DOM) Level 3 Abstract Schemas and Load
286N/Aand Save Specification</a>.
286N/A *
286N/A * @xerces.internal
286N/A *
286N/A * @author Gopal Sharma, SUN Microsystems Inc.
286N/A */
286N/A
286N/A// REVISIT:
286N/A// 1. it should be possible to do the following
286N/A// DOMInputImpl extends XMLInputSource implements LSInput
286N/A// 2. we probably need only the default constructor. -- el
286N/A
286N/Apublic class DOMInputImpl implements LSInput {
286N/A
286N/A //
286N/A // Data
286N/A //
286N/A
286N/A protected String fPublicId = null;
286N/A protected String fSystemId = null;
286N/A protected String fBaseSystemId = null;
286N/A
286N/A protected InputStream fByteStream = null;
286N/A protected Reader fCharStream = null;
286N/A protected String fData = null;
286N/A
286N/A protected String fEncoding = null;
286N/A
286N/A protected boolean fCertifiedText = false;
286N/A
286N/A /**
286N/A * Default Constructor, constructs an input source
286N/A *
286N/A *
286N/A */
286N/A public DOMInputImpl() {}
286N/A
286N/A /**
286N/A * Constructs an input source from just the public and system
286N/A * identifiers, leaving resolution of the entity and opening of
286N/A * the input stream up to the caller.
286N/A *
286N/A * @param publicId The public identifier, if known.
286N/A * @param systemId The system identifier. This value should
286N/A * always be set, if possible, and can be
286N/A * relative or absolute. If the system identifier
286N/A * is relative, then the base system identifier
286N/A * should be set.
286N/A * @param baseSystemId The base system identifier. This value should
286N/A * always be set to the fully expanded URI of the
286N/A * base system identifier, if possible.
286N/A */
286N/A
286N/A public DOMInputImpl(String publicId, String systemId,
286N/A String baseSystemId) {
286N/A
286N/A fPublicId = publicId;
286N/A fSystemId = systemId;
286N/A fBaseSystemId = baseSystemId;
286N/A
286N/A } // DOMInputImpl(String,String,String)
286N/A
286N/A /**
286N/A * Constructs an input source from a byte stream.
286N/A *
286N/A * @param publicId The public identifier, if known.
286N/A * @param systemId The system identifier. This value should
286N/A * always be set, if possible, and can be
286N/A * relative or absolute. If the system identifier
286N/A * is relative, then the base system identifier
286N/A * should be set.
286N/A * @param baseSystemId The base system identifier. This value should
286N/A * always be set to the fully expanded URI of the
286N/A * base system identifier, if possible.
286N/A * @param byteStream The byte stream.
286N/A * @param encoding The encoding of the byte stream, if known.
286N/A */
286N/A
286N/A public DOMInputImpl(String publicId, String systemId,
286N/A String baseSystemId, InputStream byteStream,
286N/A String encoding) {
286N/A
286N/A fPublicId = publicId;
286N/A fSystemId = systemId;
286N/A fBaseSystemId = baseSystemId;
286N/A fByteStream = byteStream;
286N/A fEncoding = encoding;
286N/A
286N/A } // DOMInputImpl(String,String,String,InputStream,String)
286N/A
286N/A /**
286N/A * Constructs an input source from a character stream.
286N/A *
286N/A * @param publicId The public identifier, if known.
286N/A * @param systemId The system identifier. This value should
286N/A * always be set, if possible, and can be
286N/A * relative or absolute. If the system identifier
286N/A * is relative, then the base system identifier
286N/A * should be set.
286N/A * @param baseSystemId The base system identifier. This value should
286N/A * always be set to the fully expanded URI of the
286N/A * base system identifier, if possible.
286N/A * @param charStream The character stream.
286N/A * @param encoding The original encoding of the byte stream
286N/A * used by the reader, if known.
286N/A */
286N/A
286N/A public DOMInputImpl(String publicId, String systemId,
286N/A String baseSystemId, Reader charStream,
286N/A String encoding) {
286N/A
286N/A fPublicId = publicId;
286N/A fSystemId = systemId;
286N/A fBaseSystemId = baseSystemId;
286N/A fCharStream = charStream;
286N/A fEncoding = encoding;
286N/A
286N/A } // DOMInputImpl(String,String,String,Reader,String)
286N/A
286N/A /**
286N/A * Constructs an input source from a String.
286N/A *
286N/A * @param publicId The public identifier, if known.
286N/A * @param systemId The system identifier. This value should
286N/A * always be set, if possible, and can be
286N/A * relative or absolute. If the system identifier
286N/A * is relative, then the base system identifier
286N/A * should be set.
286N/A * @param baseSystemId The base system identifier. This value should
286N/A * always be set to the fully expanded URI of the
286N/A * base system identifier, if possible.
286N/A * @param data The String Data.
286N/A * @param encoding The original encoding of the byte stream
286N/A * used by the reader, if known.
286N/A */
286N/A
286N/A public DOMInputImpl(String publicId, String systemId,
286N/A String baseSystemId, String data,
286N/A String encoding) {
286N/A fPublicId = publicId;
286N/A fSystemId = systemId;
286N/A fBaseSystemId = baseSystemId;
286N/A fData = data;
286N/A fEncoding = encoding;
286N/A } // DOMInputImpl(String,String,String,String,String)
286N/A
286N/A /**
286N/A * An attribute of a language-binding dependent type that represents a
286N/A * stream of bytes.
286N/A * <br>The parser will ignore this if there is also a character stream
286N/A * specified, but it will use a byte stream in preference to opening a
286N/A * URI connection itself.
286N/A * <br>If the application knows the character encoding of the byte stream,
286N/A * it should set the encoding property. Setting the encoding in this way
286N/A * will override any encoding specified in the XML declaration itself.
286N/A */
286N/A
286N/A public InputStream getByteStream(){
286N/A return fByteStream;
286N/A }
286N/A
286N/A /**
286N/A * An attribute of a language-binding dependent type that represents a
286N/A * stream of bytes.
286N/A * <br>The parser will ignore this if there is also a character stream
286N/A * specified, but it will use a byte stream in preference to opening a
286N/A * URI connection itself.
286N/A * <br>If the application knows the character encoding of the byte stream,
286N/A * it should set the encoding property. Setting the encoding in this way
286N/A * will override any encoding specified in the XML declaration itself.
286N/A */
286N/A
286N/A public void setByteStream(InputStream byteStream){
286N/A fByteStream = byteStream;
286N/A }
286N/A
286N/A /**
286N/A * An attribute of a language-binding dependent type that represents a
286N/A * stream of 16-bit units. Application must encode the stream using
286N/A * UTF-16 (defined in and Amendment 1 of ).
286N/A * <br>If a character stream is specified, the parser will ignore any byte
286N/A * stream and will not attempt to open a URI connection to the system
286N/A * identifier.
286N/A */
286N/A public Reader getCharacterStream(){
286N/A return fCharStream;
286N/A }
286N/A /**
286N/A * An attribute of a language-binding dependent type that represents a
286N/A * stream of 16-bit units. Application must encode the stream using
286N/A * UTF-16 (defined in and Amendment 1 of ).
286N/A * <br>If a character stream is specified, the parser will ignore any byte
286N/A * stream and will not attempt to open a URI connection to the system
286N/A * identifier.
286N/A */
286N/A
286N/A public void setCharacterStream(Reader characterStream){
286N/A fCharStream = characterStream;
286N/A }
286N/A
286N/A /**
286N/A * A string attribute that represents a sequence of 16 bit units (utf-16
286N/A * encoded characters).
286N/A * <br>If string data is available in the input source, the parser will
286N/A * ignore the character stream and the byte stream and will not attempt
286N/A * to open a URI connection to the system identifier.
286N/A */
286N/A public String getStringData(){
286N/A return fData;
286N/A }
286N/A
286N/A /**
286N/A * A string attribute that represents a sequence of 16 bit units (utf-16
286N/A * encoded characters).
286N/A * <br>If string data is available in the input source, the parser will
286N/A * ignore the character stream and the byte stream and will not attempt
286N/A * to open a URI connection to the system identifier.
286N/A */
286N/A
286N/A public void setStringData(String stringData){
286N/A fData = stringData;
286N/A }
286N/A
286N/A /**
286N/A * The character encoding, if known. The encoding must be a string
286N/A * acceptable for an XML encoding declaration ( section 4.3.3 "Character
286N/A * Encoding in Entities").
286N/A * <br>This attribute has no effect when the application provides a
286N/A * character stream. For other sources of input, an encoding specified
286N/A * by means of this attribute will override any encoding specified in
286N/A * the XML claration or the Text Declaration, or an encoding obtained
286N/A * from a higher level protocol, such as HTTP .
286N/A */
286N/A
286N/A public String getEncoding(){
286N/A return fEncoding;
286N/A }
286N/A
286N/A /**
286N/A * The character encoding, if known. The encoding must be a string
286N/A * acceptable for an XML encoding declaration ( section 4.3.3 "Character
286N/A * Encoding in Entities").
286N/A * <br>This attribute has no effect when the application provides a
286N/A * character stream. For other sources of input, an encoding specified
286N/A * by means of this attribute will override any encoding specified in
286N/A * the XML claration or the Text Declaration, or an encoding obtained
286N/A * from a higher level protocol, such as HTTP .
286N/A */
286N/A public void setEncoding(String encoding){
286N/A fEncoding = encoding;
286N/A }
286N/A
286N/A /**
286N/A * The public identifier for this input source. The public identifier is
286N/A * always optional: if the application writer includes one, it will be
286N/A * provided as part of the location information.
286N/A */
286N/A public String getPublicId(){
286N/A return fPublicId;
286N/A }
286N/A /**
286N/A * The public identifier for this input source. The public identifier is
286N/A * always optional: if the application writer includes one, it will be
286N/A * provided as part of the location information.
286N/A */
286N/A public void setPublicId(String publicId){
286N/A fPublicId = publicId;
286N/A }
286N/A
286N/A /**
286N/A * The system identifier, a URI reference , for this input source. The
286N/A * system identifier is optional if there is a byte stream or a
286N/A * character stream, but it is still useful to provide one, since the
286N/A * application can use it to resolve relative URIs and can include it in
286N/A * error messages and warnings (the parser will attempt to fetch the
286N/A * ressource identifier by the URI reference only if there is no byte
286N/A * stream or character stream specified).
286N/A * <br>If the application knows the character encoding of the object
286N/A * pointed to by the system identifier, it can register the encoding by
286N/A * setting the encoding attribute.
286N/A * <br>If the system ID is a relative URI reference (see section 5 in ),
286N/A * the behavior is implementation dependent.
286N/A */
286N/A public String getSystemId(){
286N/A return fSystemId;
286N/A }
286N/A /**
286N/A * The system identifier, a URI reference , for this input source. The
286N/A * system identifier is optional if there is a byte stream or a
286N/A * character stream, but it is still useful to provide one, since the
286N/A * application can use it to resolve relative URIs and can include it in
286N/A * error messages and warnings (the parser will attempt to fetch the
286N/A * ressource identifier by the URI reference only if there is no byte
286N/A * stream or character stream specified).
286N/A * <br>If the application knows the character encoding of the object
286N/A * pointed to by the system identifier, it can register the encoding by
286N/A * setting the encoding attribute.
286N/A * <br>If the system ID is a relative URI reference (see section 5 in ),
286N/A * the behavior is implementation dependent.
286N/A */
286N/A public void setSystemId(String systemId){
286N/A fSystemId = systemId;
286N/A }
286N/A
286N/A /**
286N/A * The base URI to be used (see section 5.1.4 in ) for resolving relative
286N/A * URIs to absolute URIs. If the baseURI is itself a relative URI, the
286N/A * behavior is implementation dependent.
286N/A */
286N/A public String getBaseURI(){
286N/A return fBaseSystemId;
286N/A }
286N/A /**
286N/A * The base URI to be used (see section 5.1.4 in ) for resolving relative
286N/A * URIs to absolute URIs. If the baseURI is itself a relative URI, the
286N/A * behavior is implementation dependent.
286N/A */
286N/A public void setBaseURI(String baseURI){
286N/A fBaseSystemId = baseURI;
286N/A }
286N/A
286N/A /**
286N/A * If set to true, assume that the input is certified (see section 2.13
286N/A * in [<a href='http://www.w3.org/TR/2002/CR-xml11-20021015/'>XML 1.1</a>]) when
286N/A * parsing [<a href='http://www.w3.org/TR/2002/CR-xml11-20021015/'>XML 1.1</a>].
286N/A */
286N/A public boolean getCertifiedText(){
286N/A return fCertifiedText;
286N/A }
286N/A
286N/A /**
286N/A * If set to true, assume that the input is certified (see section 2.13
286N/A * in [<a href='http://www.w3.org/TR/2002/CR-xml11-20021015/'>XML 1.1</a>]) when
286N/A * parsing [<a href='http://www.w3.org/TR/2002/CR-xml11-20021015/'>XML 1.1</a>].
286N/A */
286N/A
286N/A public void setCertifiedText(boolean certifiedText){
286N/A fCertifiedText = certifiedText;
286N/A }
286N/A
286N/A}// class DOMInputImpl