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();
}
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;
}
Aggregations