Search in sources :

Example 1 with DeclScanner

use of org.exist.xquery.parser.DeclScanner in project exist by eXist-db.

the class AbstractSource method guessXQueryEncoding.

/**
 * Check if the XQuery file declares a content encoding in the
 * XQuery declaration.
 *
 * @param is the input stream
 * @return The guessed encoding.
 */
protected static String guessXQueryEncoding(final InputStream is) {
    final XQueryLexer lexer = new XQueryLexer(null, new InputStreamReader(is));
    final DeclScanner scanner = new DeclScanner(lexer);
    try {
        scanner.versionDecl();
    } catch (final RecognitionException | XPathException | TokenStreamException e) {
    // Nothing to do
    }
    return scanner.getEncoding();
}
Also used : TokenStreamException(antlr.TokenStreamException) InputStreamReader(java.io.InputStreamReader) XPathException(org.exist.xquery.XPathException) DeclScanner(org.exist.xquery.parser.DeclScanner) XQueryLexer(org.exist.xquery.parser.XQueryLexer) RecognitionException(antlr.RecognitionException)

Example 2 with DeclScanner

use of org.exist.xquery.parser.DeclScanner in project exist by eXist-db.

the class AbstractSource method getModuleDecl.

/**
 * Check if the source is an XQuery module. If yes, return a QName containing
 * the module prefix as local name and the module namespace as namespace URI.
 *
 * @param is the input stream
 * @return QName describing the module namespace or null if the source is not
 * a module.
 */
protected static QName getModuleDecl(final InputStream is) {
    final XQueryLexer lexer = new XQueryLexer(null, new InputStreamReader(is));
    final DeclScanner scanner = new DeclScanner(lexer);
    try {
        scanner.versionDecl();
    } catch (final RecognitionException | XPathException | TokenStreamException e) {
    // Nothing to do
    }
    if (scanner.getNamespace() != null) {
        return new QName(scanner.getPrefix(), scanner.getNamespace());
    }
    return null;
}
Also used : TokenStreamException(antlr.TokenStreamException) InputStreamReader(java.io.InputStreamReader) XPathException(org.exist.xquery.XPathException) QName(org.exist.dom.QName) DeclScanner(org.exist.xquery.parser.DeclScanner) XQueryLexer(org.exist.xquery.parser.XQueryLexer) RecognitionException(antlr.RecognitionException)

Aggregations

RecognitionException (antlr.RecognitionException)2 TokenStreamException (antlr.TokenStreamException)2 InputStreamReader (java.io.InputStreamReader)2 XPathException (org.exist.xquery.XPathException)2 DeclScanner (org.exist.xquery.parser.DeclScanner)2 XQueryLexer (org.exist.xquery.parser.XQueryLexer)2 QName (org.exist.dom.QName)1