use of org.exist.indexing.MatchListener in project exist by eXist-db.
the class HighlightMatches method eval.
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
if (args[0].isEmpty())
return Sequence.EMPTY_SEQUENCE;
context.pushDocumentContext();
final Serializer serializer = context.getBroker().borrowSerializer();
try (FunctionReference func = (FunctionReference) args[1].itemAt(0)) {
MemTreeBuilder builder = context.getDocumentBuilder();
NGramIndexWorker index = (NGramIndexWorker) context.getBroker().getIndexController().getWorkerByIndexId(NGramIndex.ID);
DocumentBuilderReceiver docBuilder = new DocumentBuilderReceiver(builder);
MatchCallback matchCb = new MatchCallback(func, docBuilder);
ValueSequence result = new ValueSequence();
for (SequenceIterator i = args[0].iterate(); i.hasNext(); ) {
NodeValue v = (NodeValue) i.nextItem();
try {
int nodeNr = builder.getDocument().getLastNode();
if (v.getImplementationType() == NodeValue.IN_MEMORY_NODE) {
((NodeImpl) v).copyTo(context.getBroker(), docBuilder);
} else {
NodeProxy p = (NodeProxy) v;
MatchListener ml = index.getMatchListener(context.getBroker(), p, matchCb);
Receiver receiver;
if (ml == null)
receiver = docBuilder;
else {
ml.setNextInChain(docBuilder);
receiver = ml;
}
serializer.setReceiver(receiver);
serializer.toReceiver((NodeProxy) v, false);
}
result.add(builder.getDocument().getNode(++nodeNr));
} catch (SAXException e) {
LOG.warn(e.getMessage(), e);
throw new XPathException(this, e.getMessage());
}
}
return result;
} finally {
context.getBroker().returnSerializer(serializer);
context.popDocumentContext();
}
}
use of org.exist.indexing.MatchListener in project exist by eXist-db.
the class Serializer method setPrettyPrinter.
protected void setPrettyPrinter(Writer writer, boolean xmlDecl, NodeProxy root, boolean applyFilters) {
outputProperties.setProperty(OutputKeys.OMIT_XML_DECLARATION, xmlDecl ? "no" : "yes");
xmlout = (SAXSerializer) SerializerPool.getInstance().borrowObject(SAXSerializer.class);
xmlout.setOutput(writer, outputProperties);
if ("yes".equals(getProperty(EXistOutputKeys.EXPAND_XINCLUDES, "yes"))) {
xinclude.setReceiver(xmlout);
receiver = xinclude;
} else {
receiver = xmlout;
}
if (root != null && getHighlightingMode() != TAG_NONE) {
final IndexController controller = broker.getIndexController();
MatchListener listener = controller.getMatchListener(root);
if (listener != null) {
final MatchListener last = (MatchListener) listener.getLastInChain();
last.setNextInChain(receiver);
receiver = listener;
}
}
if (root == null && applyFilters && customMatchListeners.getFirst() != null) {
customMatchListeners.getLast().setNextInChain(receiver);
receiver = customMatchListeners.getFirst();
}
}
use of org.exist.indexing.MatchListener in project exist by eXist-db.
the class Serializer method setupMatchListeners.
protected Receiver setupMatchListeners(NodeProxy p) {
final Receiver oldReceiver = receiver;
if (getHighlightingMode() != TAG_NONE) {
final IndexController controller = broker.getIndexController();
MatchListener listener = controller.getMatchListener(p);
if (listener != null) {
final MatchListener last = (MatchListener) listener.getLastInChain();
last.setNextInChain(receiver);
receiver = listener;
}
}
return oldReceiver;
}
use of org.exist.indexing.MatchListener in project exist by eXist-db.
the class Serializer method setXSLHandler.
protected void setXSLHandler(NodeProxy root, boolean applyFilters) {
if (templates != null && xslHandler != null) {
final SAXResult result = new SAXResult();
boolean processXInclude = "yes".equals(getProperty(EXistOutputKeys.EXPAND_XINCLUDES, "yes"));
final ReceiverToSAX filter;
if (processXInclude) {
final Receiver xincludeReceiver = xinclude.getReceiver();
if (xincludeReceiver != null && xincludeReceiver instanceof SAXSerializer) {
filter = new ReceiverToSAX((SAXSerializer) xincludeReceiver);
} else {
filter = (ReceiverToSAX) xincludeReceiver;
}
} else {
filter = (ReceiverToSAX) receiver;
}
result.setHandler(filter.getContentHandler());
result.setLexicalHandler(filter.getLexicalHandler());
filter.setLexicalHandler(xslHandler);
filter.setContentHandler(xslHandler);
xslHandler.setResult(result);
if (processXInclude) {
xinclude.setReceiver(new ReceiverToSAX(xslHandler));
receiver = xinclude;
} else {
receiver = new ReceiverToSAX(xslHandler);
}
}
if (root != null && getHighlightingMode() != TAG_NONE) {
final IndexController controller = broker.getIndexController();
MatchListener listener = controller.getMatchListener(root);
if (listener != null) {
final MatchListener last = (MatchListener) listener.getLastInChain();
last.setNextInChain(receiver);
receiver = listener;
}
}
if (applyFilters && root == null && customMatchListeners.getFirst() != null) {
customMatchListeners.getLast().setNextInChain(receiver);
receiver = customMatchListeners.getFirst();
}
}
Aggregations