protected int resolveInclude ( ) throws XMLStreamException { // we are no more in fallback mode this . fallback = false ; this . depth ++ ; int eventType = - 1 ; // read attributes... String href = getAttributeValue ( null , "href" ) ; LOGGER . trace ( "Resolving xi:include to href {}" , href ) ; String xpointer = getAttributeValue ( null , "xpointer" ) ; // get the included resource... DataResource includeResource = this . resource . navigate ( href ) ; // and try to include it... boolean success = false ; if ( includeResource . isAvailable ( ) ) { // determine inclusion format type... String parse = getAttributeValue ( null , "parse" ) ; if ( ( parse == null ) || ( "xml" . equals ( parse ) ) ) { this . includeReader = new XIncludeStreamReader ( this . factory , includeResource , this ) ; if ( xpointer != null ) { // shorthand form: id // scheme-based form: e.g. element(/1/*) this . includeReader = new XPointerStreamReader ( this . includeReader , xpointer ) ; } eventType = this . includeReader . nextTag ( ) ; setParent ( this . includeReader ) ; // we ascend the XML until the initial include is closed. closeInitialInclude ( ) ; success = true ; } else if ( "text" . equals ( parse ) ) { String encoding = getAttributeValue ( null , "encoding" ) ; Charset charset ; if ( encoding == null ) { charset = Charset . defaultCharset ( ) ; } else { charset = Charset . forName ( encoding ) ; } InputStream textInputStream = includeResource . openStream ( ) ; Reader reader = new InputStreamReader ( textInputStream , charset ) ; this . includeText = read ( reader ) ; // we ascend the XML until the initial include is closed. closeInitialInclude ( ) ; return XMLStreamConstants . CHARACTERS ; } else { throw new XMLStreamException ( "Unsupported XInclude parse type:" + parse ) ; } } if ( ! success ) { // search for fallback do { eventType = super . next ( ) ; } while ( ( eventType != XMLStreamConstants . START_ELEMENT ) && ( eventType != XMLStreamConstants . END_ELEMENT ) ) ; if ( eventType == XMLStreamConstants . START_ELEMENT ) { if ( ( XmlUtil . NAMESPACE_URI_XINCLUDE . equals ( getNamespaceURI ( ) ) ) && ( "fallback" . equals ( getLocalName ( ) ) ) ) { // found fallback this . fallback = true ; return next ( ) ; } } // no fallback available, ignore include... closeInitialInclude ( ) ; return next ( ) ; } return eventType ; }
This method is called when an include tag of the XInclude namespace was started . It resolves the include and finds a fallback on failure .