Package com.ctc.wstx.io
Class InputBootstrapper
- java.lang.Object
-
- com.ctc.wstx.io.InputBootstrapper
-
- Direct Known Subclasses:
ReaderBootstrapper
,StreamBootstrapper
public abstract class InputBootstrapper extends Object
Abstract base class that defines common API used with both stream and reader-based input sources. Class is responsible for opening the physical input source, figure out encoding (if necessary; only for streams), and then handle (optional) XML declaration.
-
-
Field Summary
Fields Modifier and Type Field Description static byte
BYTE_CR
static byte
BYTE_LF
static byte
BYTE_NULL
static byte
CHAR_CR
static byte
CHAR_LF
static char
CHAR_NEL
static char
CHAR_NULL
static char
CHAR_SPACE
protected static String
ERR_XMLDECL_END_MARKER
protected static String
ERR_XMLDECL_EXP_ATTRVAL
protected static String
ERR_XMLDECL_EXP_EQ
protected static String
ERR_XMLDECL_EXP_SPACE
protected static String
ERR_XMLDECL_KW_ENCODING
protected static String
ERR_XMLDECL_KW_STANDALONE
protected static String
ERR_XMLDECL_KW_VERSION
protected int
mDeclaredXmlVersion
XML declaration from the input (1.0, 1.1 or 'unknown')protected String
mFoundEncoding
Value of encoding pseudo-attribute from xml declaration, if one was found; null otherwise.protected int
mInputProcessed
Current number of characters that were processed in previous blocks, before contents of current input buffer.protected int
mInputRow
Current row location of current point in input buffer, starting from 1protected int
mInputRowStart
Current index of the first character of the current row in input buffer.protected char[]
mKeywordBuffer
Need a short buffer to read in values of pseudo-attributes (version, encoding, standalone).protected String
mPublicId
protected String
mStandalone
protected SystemId
mSystemId
protected boolean
mXml11Handling
Flag that indicates whether input read from this input source needs to be xml 1.1 compliant or not; if not, xml 1.0 is assumed.
-
Constructor Summary
Constructors Modifier Constructor Description protected
InputBootstrapper(String pubId, SystemId sysId)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract Reader
bootstrapInput(ReaderConfig cfg, boolean mainDoc, int xmlVersion)
protected abstract int
checkKeyword(String exp)
boolean
declaredXml11()
String
getDeclaredEncoding()
int
getDeclaredVersion()
abstract int
getInputColumn()
abstract String
getInputEncoding()
Actual character encoding used by the underlying input source; may have been passed by the application, or auto-detected by byte stream boot strapper (can not be determined from a Reader source).int
getInputRow()
abstract int
getInputTotal()
protected abstract Location
getLocation()
protected abstract int
getNext()
protected abstract int
getNextAfterWs(boolean reqWs)
String
getPublicId()
String
getStandalone()
SystemId
getSystemId()
protected void
initFrom(InputBootstrapper src)
protected abstract void
pushback()
protected abstract int
readQuotedValue(char[] kw, int quoteChar)
protected void
readXmlDecl(boolean isMainDoc, int xmlVersion)
protected void
reportNull()
protected void
reportUnexpectedChar(int i, String msg)
protected void
reportXmlProblem(String msg)
-
-
-
Field Detail
-
ERR_XMLDECL_KW_VERSION
protected static final String ERR_XMLDECL_KW_VERSION
- See Also:
- Constant Field Values
-
ERR_XMLDECL_KW_ENCODING
protected static final String ERR_XMLDECL_KW_ENCODING
- See Also:
- Constant Field Values
-
ERR_XMLDECL_KW_STANDALONE
protected static final String ERR_XMLDECL_KW_STANDALONE
- See Also:
- Constant Field Values
-
ERR_XMLDECL_END_MARKER
protected static final String ERR_XMLDECL_END_MARKER
- See Also:
- Constant Field Values
-
ERR_XMLDECL_EXP_SPACE
protected static final String ERR_XMLDECL_EXP_SPACE
- See Also:
- Constant Field Values
-
ERR_XMLDECL_EXP_EQ
protected static final String ERR_XMLDECL_EXP_EQ
- See Also:
- Constant Field Values
-
ERR_XMLDECL_EXP_ATTRVAL
protected static final String ERR_XMLDECL_EXP_ATTRVAL
- See Also:
- Constant Field Values
-
CHAR_NULL
public static final char CHAR_NULL
- See Also:
- Constant Field Values
-
CHAR_SPACE
public static final char CHAR_SPACE
- See Also:
- Constant Field Values
-
CHAR_NEL
public static final char CHAR_NEL
- See Also:
- Constant Field Values
-
CHAR_CR
public static final byte CHAR_CR
- See Also:
- Constant Field Values
-
CHAR_LF
public static final byte CHAR_LF
- See Also:
- Constant Field Values
-
BYTE_NULL
public static final byte BYTE_NULL
- See Also:
- Constant Field Values
-
BYTE_CR
public static final byte BYTE_CR
- See Also:
- Constant Field Values
-
BYTE_LF
public static final byte BYTE_LF
- See Also:
- Constant Field Values
-
mPublicId
protected final String mPublicId
-
mSystemId
protected final SystemId mSystemId
-
mInputProcessed
protected int mInputProcessed
Current number of characters that were processed in previous blocks, before contents of current input buffer.
-
mInputRow
protected int mInputRow
Current row location of current point in input buffer, starting from 1
-
mInputRowStart
protected int mInputRowStart
Current index of the first character of the current row in input buffer. Needed to calculate column position, if necessary; benefit of not having column itself is that this only has to be updated once per line.
-
mDeclaredXmlVersion
protected int mDeclaredXmlVersion
XML declaration from the input (1.0, 1.1 or 'unknown')
-
mFoundEncoding
protected String mFoundEncoding
Value of encoding pseudo-attribute from xml declaration, if one was found; null otherwise.
-
mStandalone
protected String mStandalone
-
mXml11Handling
protected boolean mXml11Handling
Flag that indicates whether input read from this input source needs to be xml 1.1 compliant or not; if not, xml 1.0 is assumed. State of this flag depends on parent context (if one existed), or if not, on xml declaration of this input source.
-
mKeywordBuffer
protected final char[] mKeywordBuffer
Need a short buffer to read in values of pseudo-attributes (version, encoding, standalone). Don't really need tons of space; just enough for the longest anticipated encoding id... and maybe few chars just in case (for additional white space that we ignore)
-
-
Method Detail
-
initFrom
protected void initFrom(InputBootstrapper src)
-
bootstrapInput
public abstract Reader bootstrapInput(ReaderConfig cfg, boolean mainDoc, int xmlVersion) throws IOException, XMLStreamException
- Parameters:
xmlVersion
- Optional xml version identifier of the main parsed document (if not bootstrapping the main document). Currently only relevant for checking that XML 1.0 document does not include XML 1.1 external parsed entities. If null, no checks will be done; when bootstrapping parsing of the main document, null should be passed for this argument.- Throws:
IOException
XMLStreamException
-
getPublicId
public String getPublicId()
-
getSystemId
public SystemId getSystemId()
-
getDeclaredVersion
public int getDeclaredVersion()
-
declaredXml11
public boolean declaredXml11()
- Returns:
- True, if the input bootstrapped declared that it conforms to xml 1.1 (independent of where it was included from)
-
getStandalone
public String getStandalone()
-
getDeclaredEncoding
public String getDeclaredEncoding()
- Returns:
- Encoding declaration found from the xml declaration, if any; null if none.
-
getInputTotal
public abstract int getInputTotal()
- Returns:
- Total number of characters read from bootstrapped input (stream, reader)
-
getInputRow
public int getInputRow()
-
getInputColumn
public abstract int getInputColumn()
-
getInputEncoding
public abstract String getInputEncoding()
Actual character encoding used by the underlying input source; may have been passed by the application, or auto-detected by byte stream boot strapper (can not be determined from a Reader source).- Returns:
- Input encoding in use, if it could be determined or was passed by the calling application
-
readXmlDecl
protected void readXmlDecl(boolean isMainDoc, int xmlVersion) throws IOException, WstxException
- Parameters:
xmlVersion
- Optional xml version identifier of the main parsed document (if not bootstrapping the main document). Currently only relevant for checking that XML 1.0 document does not include XML 1.1 external parsed entities. If null, no checks will be done; when bootstrapping parsing of the main document, null should be passed for this argument.- Throws:
IOException
WstxException
-
pushback
protected abstract void pushback()
-
getNext
protected abstract int getNext() throws IOException, WstxException
- Throws:
IOException
WstxException
-
getNextAfterWs
protected abstract int getNextAfterWs(boolean reqWs) throws IOException, WstxException
- Throws:
IOException
WstxException
-
checkKeyword
protected abstract int checkKeyword(String exp) throws IOException, WstxException
- Returns:
- First character that does not match expected, if any; CHAR_NULL if match succeeded
- Throws:
IOException
WstxException
-
readQuotedValue
protected abstract int readQuotedValue(char[] kw, int quoteChar) throws IOException, WstxException
- Throws:
IOException
WstxException
-
getLocation
protected abstract Location getLocation()
-
reportNull
protected void reportNull() throws WstxException
- Throws:
WstxException
-
reportXmlProblem
protected void reportXmlProblem(String msg) throws WstxException
- Throws:
WstxException
-
reportUnexpectedChar
protected void reportUnexpectedChar(int i, String msg) throws WstxException
- Throws:
WstxException
-
-