Reads the source and invokes #parse(TextInput, Options, QueryContext). @param qc query context @return parsed result @throws QueryException query exception
(final QueryContext qc)
| 94 | * @throws QueryException query exception |
| 95 | */ |
| 96 | protected Value doc(final QueryContext qc) throws QueryException { |
| 97 | final String source = toStringOrNull(arg(0), qc); |
| 98 | if(source == null) return Empty.VALUE; |
| 99 | |
| 100 | // input |
| 101 | final String[] testResources = qc.resources.text(source, sc()); |
| 102 | final IO io = testResources != null ? IO.get(testResources[0]) : |
| 103 | input != null ? input : toIO(source, false); |
| 104 | |
| 105 | // encoding |
| 106 | final Options options = options(qc); |
| 107 | final String enc = toEncodingOrNull(options.get(CommonOptions.ENCODING), RESENCODING_X); |
| 108 | final String encoding = enc != null ? enc : testResources != null ? testResources[1] : null; |
| 109 | final boolean fallback = Boolean.TRUE.equals(options.get((Option<?>) CommonOptions.FALLBACK)); |
| 110 | |
| 111 | // newline normalization |
| 112 | Boolean normalize = options.get(CommonOptions.NORMALIZE_NEWLINES); |
| 113 | if(normalize != null) { |
| 114 | if(nl()) throw INVALIDOPTION_X.get(info, Options.unknown(CommonOptions.NORMALIZE_NEWLINES)); |
| 115 | } else { |
| 116 | normalize = nl(); |
| 117 | } |
| 118 | |
| 119 | // parse text |
| 120 | try(InputStream is = io.inputStream(); TextInput ti = |
| 121 | normalize ? new NewlineInput(io, encoding) : new TextInput(io, encoding)) { |
| 122 | return parse(ti.fallback(fallback), options, qc); |
| 123 | } catch(final DecodingException ex) { |
| 124 | throw RECDECODING_X.get(info, ex); |
| 125 | } catch(final InputException ex) { |
| 126 | throw exception(ex); |
| 127 | } catch(final IOException ex) { |
| 128 | throw RESWHICH_X.get(info, io + " (" + Util.info(ex) + ')'); |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * Parses the input and returns a custom result. |
no test coverage detected