MCPcopy Create free account
hub / github.com/BaseXdb/basex / doc

Method doc

basex-core/src/main/java/org/basex/query/func/fn/ParseFn.java:96–130  ·  view source on GitHub ↗

Reads the source and invokes #parse(TextInput, Options, QueryContext). @param qc query context @return parsed result @throws QueryException query exception

(final QueryContext qc)

Source from the content-addressed store, hash-verified

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.

Callers 14

valueMethod · 0.45
itemMethod · 0.45
itemMethod · 0.45
valueMethod · 0.45
valueMethod · 0.45
itemMethod · 0.45
valueMethod · 0.45
valueMethod · 0.45
valueMethod · 0.45
itemMethod · 0.45
itemMethod · 0.45
testMethod · 0.45

Calls 15

getMethod · 0.95
optionsMethod · 0.95
getMethod · 0.95
nlMethod · 0.95
unknownMethod · 0.95
inputStreamMethod · 0.95
parseMethod · 0.95
exceptionMethod · 0.95
infoMethod · 0.95
toStringOrNullMethod · 0.80
toIOMethod · 0.80
toEncodingOrNullMethod · 0.80

Tested by

no test coverage detected