use of org.exist.dom.persistent.NodeProxy in project exist by eXist-db.
the class Serializer method serialize.
public void serialize(NodeValue n, Writer out) throws SAXException {
try {
if (n.getItemType() == Type.DOCUMENT && !(n instanceof NodeProxy)) {
setStylesheetFromProperties((Document) n);
} else {
setStylesheetFromProperties(n.getOwnerDocument());
}
} catch (final TransformerConfigurationException e) {
throw new SAXException(e.getMessage(), e);
}
if (templates != null) {
applyXSLHandler(out);
} else
setPrettyPrinter(out, "no".equals(outputProperties.getProperty(OutputKeys.OMIT_XML_DECLARATION, "yes")), n.getImplementationType() == NodeValue.PERSISTENT_NODE ? (NodeProxy) n : null, // setPrettyPrinter(out, false);
false);
serializeToReceiver(n, true);
releasePrettyPrinter();
}
use of org.exist.dom.persistent.NodeProxy in project exist by eXist-db.
the class Serializer method toSAX.
public void toSAX(NodeValue n) throws SAXException {
try {
if (n.getType() == Type.DOCUMENT && !(n instanceof NodeProxy)) {
setStylesheetFromProperties((Document) n);
} else {
setStylesheetFromProperties(n.getOwnerDocument());
}
} catch (final TransformerConfigurationException e) {
throw new SAXException(e.getMessage(), e);
}
setXSLHandler(n.getImplementationType() == NodeValue.PERSISTENT_NODE ? (NodeProxy) n : null, false);
serializeToReceiver(n, "true".equals(getProperty(GENERATE_DOC_EVENTS, "false")));
}
use of org.exist.dom.persistent.NodeProxy in project exist by eXist-db.
the class Serializer method hasXSLPi.
/**
* Check if the document has an xml-stylesheet processing instruction
* that references an XSLT stylesheet. Return the link to the stylesheet.
*
* @param doc the document
* @return link to the stylesheet
*/
public String hasXSLPi(final Document doc) {
final boolean applyXSLPI = outputProperties.getProperty(EXistOutputKeys.PROCESS_XSL_PI, "no").equalsIgnoreCase("yes");
if (!applyXSLPI) {
return null;
}
NodeList docChildren = doc.getChildNodes();
if (docChildren.getLength() == 1) {
final Node onlyChild = docChildren.item(0);
if (onlyChild.getNodeType() == NodeImpl.REFERENCE_NODE) {
// if this is a reference to a persistent document node then we must expand it
final NodeProxy nodeProxy = ((ReferenceNode) onlyChild).getReference();
if (nodeProxy.getNodeType() == Node.DOCUMENT_NODE) {
// switch docChildren to the children of the dereferencedNode
final Node dereferencedNode = nodeProxy.getNode();
docChildren = dereferencedNode.getChildNodes();
}
}
}
for (int i = 0; i < docChildren.getLength(); i++) {
final Node node = docChildren.item(i);
if (node.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE && "xml-stylesheet".equals(((ProcessingInstruction) node).getTarget())) {
// found <?xml-stylesheet?>
final String xsl = ((ProcessingInstruction) node).getData();
final String type = XMLUtil.parseValue(xsl, "type");
if (type != null && (type.equals(MimeType.XML_TYPE.getName()) || type.equals(MimeType.XSL_TYPE.getName()) || type.equals(MimeType.XSLT_TYPE.getName()))) {
final String href = XMLUtil.parseValue(xsl, "href");
if (href == null) {
continue;
}
return href;
}
}
}
return null;
}
use of org.exist.dom.persistent.NodeProxy in project exist by eXist-db.
the class NativeStructuralIndexWorker method removeSome.
protected void removeSome() {
if (pending.size() == 0) {
return;
}
try {
for (final Map.Entry<QName, List<NodeProxy>> entry : pending.entrySet()) {
final QName qname = entry.getKey();
try (final ManagedLock<ReentrantLock> btreeLock = index.lockManager.acquireBtreeWriteLock(index.btree.getLockName())) {
final List<NodeProxy> nodes = entry.getValue();
for (final NodeProxy proxy : nodes) {
final NodeId nodeId = proxy.getNodeId();
final byte[] key = computeKey(qname.getNameType(), qname, document.getDocId(), nodeId);
index.btree.removeValue(new Value(key));
}
} catch (final LockException e) {
NativeStructuralIndex.LOG.warn("Failed to lock structural index: {}", e.getMessage(), e);
} catch (final Exception e) {
NativeStructuralIndex.LOG.warn("Exception caught while writing to structural index: {}", e.getMessage(), e);
}
}
} finally {
pending.clear();
}
}
use of org.exist.dom.persistent.NodeProxy in project exist by eXist-db.
the class NativeStructuralIndexWorker method processPending.
/**
* Process the map of pending entries and store them into the btree.
*/
private void processPending() {
if (pending.size() == 0 || index.btree == null) {
return;
}
try {
for (final Map.Entry<QName, List<NodeProxy>> entry : pending.entrySet()) {
final QName qname = entry.getKey();
try (final ManagedLock<ReentrantLock> btreeLock = index.lockManager.acquireBtreeWriteLock(index.btree.getLockName())) {
final List<NodeProxy> nodes = entry.getValue();
for (final NodeProxy proxy : nodes) {
final NodeId nodeId = proxy.getNodeId();
final byte[] key = computeKey(qname.getNameType(), qname, document.getDocId(), nodeId);
index.btree.addValue(new Value(key), computeValue(proxy));
}
final Value docKey = new Value(computeDocKey(qname.getNameType(), document.getDocId(), qname));
if (index.btree.findValue(docKey) == -1) {
index.btree.addValue(docKey, 0);
}
} catch (final LockException e) {
NativeStructuralIndex.LOG.warn("Failed to lock structural index: {}", e.getMessage(), e);
// } catch (ReadOnlyException e) {
// NativeStructuralIndex.LOG.warn("Read-only error: " + e.getMessage(), e);
} catch (final Exception e) {
NativeStructuralIndex.LOG.warn("Exception caught while writing to structural index: {}", e.getMessage(), e);
}
}
} finally {
pending.clear();
}
}
Aggregations