Search in sources :

Example 26 with NodeProxy

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();
}
Also used : TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) NodeProxy(org.exist.dom.persistent.NodeProxy) SAXException(org.xml.sax.SAXException)

Example 27 with NodeProxy

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")));
}
Also used : TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) NodeProxy(org.exist.dom.persistent.NodeProxy) SAXException(org.xml.sax.SAXException)

Example 28 with NodeProxy

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;
}
Also used : ReferenceNode(org.exist.dom.memtree.ReferenceNode) NodeList(org.w3c.dom.NodeList) StoredNode(org.exist.dom.persistent.StoredNode) Node(org.w3c.dom.Node) ReferenceNode(org.exist.dom.memtree.ReferenceNode) NodeProxy(org.exist.dom.persistent.NodeProxy) ProcessingInstruction(org.w3c.dom.ProcessingInstruction)

Example 29 with NodeProxy

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();
    }
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) QName(org.exist.dom.QName) NodeProxy(org.exist.dom.persistent.NodeProxy) PermissionDeniedException(org.exist.security.PermissionDeniedException) LockException(org.exist.util.LockException) DatabaseConfigurationException(org.exist.util.DatabaseConfigurationException) LockException(org.exist.util.LockException) NodeId(org.exist.numbering.NodeId) Value(org.exist.storage.btree.Value) NodeList(org.w3c.dom.NodeList)

Example 30 with NodeProxy

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();
    }
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) QName(org.exist.dom.QName) NodeProxy(org.exist.dom.persistent.NodeProxy) PermissionDeniedException(org.exist.security.PermissionDeniedException) LockException(org.exist.util.LockException) DatabaseConfigurationException(org.exist.util.DatabaseConfigurationException) LockException(org.exist.util.LockException) NodeId(org.exist.numbering.NodeId) Value(org.exist.storage.btree.Value) NodeList(org.w3c.dom.NodeList)

Aggregations

NodeProxy (org.exist.dom.persistent.NodeProxy)79 DocumentImpl (org.exist.dom.persistent.DocumentImpl)18 Sequence (org.exist.xquery.value.Sequence)17 NodeSet (org.exist.dom.persistent.NodeSet)16 NodeId (org.exist.numbering.NodeId)16 XPathException (org.exist.xquery.XPathException)16 IOException (java.io.IOException)12 NewArrayNodeSet (org.exist.dom.persistent.NewArrayNodeSet)10 PermissionDeniedException (org.exist.security.PermissionDeniedException)10 LockException (org.exist.util.LockException)10 NodeValue (org.exist.xquery.value.NodeValue)10 Node (org.w3c.dom.Node)9 Document (org.w3c.dom.Document)8 SAXException (org.xml.sax.SAXException)8 NodeImpl (org.exist.dom.memtree.NodeImpl)7 ExtArrayNodeSet (org.exist.dom.persistent.ExtArrayNodeSet)7 SequenceIterator (org.exist.xquery.value.SequenceIterator)7 ReentrantLock (java.util.concurrent.locks.ReentrantLock)6 MemTreeBuilder (org.exist.dom.memtree.MemTreeBuilder)6 Match (org.exist.dom.persistent.Match)6