return result;
} else if (isCalledAs("show-grammar-cache")){
final MemTreeBuilder builder = context.getDocumentBuilder();
final NodeImpl result = writeReport(grammarpool, builder);
return result;
} else if (isCalledAs("pre-parse-grammar")){
if (args[0].isEmpty())
{return Sequence.EMPTY_SEQUENCE;}
// Setup for XML schema support only
final XMLGrammarPreparser parser = new XMLGrammarPreparser();
parser.registerPreparser(TYPE_XSD , null);
final List<Grammar> allGrammars = new ArrayList<Grammar>();
// iterate through the argument sequence and parse url
for (final SequenceIterator i = args[0].iterate(); i.hasNext();) {
String url = i.nextItem().getStringValue();
// Fix database urls
if(url.startsWith("/")){
url="xmldb:exist://"+url;
}
LOG.debug("Parsing "+url);
// parse XSD grammar
try {
if(url.endsWith(".xsd")){
final InputStream is = new URL(url).openStream();
final XMLInputSource xis = new XMLInputSource(null, url, url, is, null);
final Grammar schema = parser.preparseGrammar(TYPE_XSD, xis);
is.close();
allGrammars.add(schema);
} else {
throw new XPathException(this, "Only XMLSchemas can be preparsed.");
}
} catch(final IOException ex) {
LOG.debug(ex);
throw new XPathException(this, ex);
} catch(final Exception ex) {
LOG.debug(ex);
throw new XPathException(this, ex);
}
}
LOG.debug("Successfully parsed "+allGrammars.size()+" grammars.");
// Send all XSD grammars to grammarpool
Grammar grammars[] = new Grammar[allGrammars.size()];
grammars = allGrammars.toArray(grammars);
grammarpool.cacheGrammars(TYPE_XSD, grammars);
// Construct result to end user
final ValueSequence result = new ValueSequence();
for(final Grammar one : grammars){
result.add( new StringValue(one.getGrammarDescription().getNamespace()) );
}
return result;