Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions exist-core/pom.xml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions exist-core/src/main/java/org/exist/Namespaces.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public interface Namespaces {
String EXIST_JAVA_BINDING_NS = "http://exist.sourceforge.net/NS/exist/java-binding";
String EXIST_JAVA_BINDING_NS_PREFIX = "java";

String EXIST_FEATURE_NS = EXIST_NS + "/feature";

String XML_NS = XMLConstants.XML_NS_URI;
String XMLNS_NS = XMLConstants.XMLNS_ATTRIBUTE_NS_URI;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.exist.dom.QName;
import org.exist.dom.memtree.DocumentImpl;
import org.exist.dom.memtree.NodeImpl;
import org.exist.dom.persistent.AttrImpl;
import org.exist.dom.persistent.NodeProxy;
import org.exist.xquery.Expression;
import org.exist.xquery.NodeTest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ public NodeProxy(final DocumentImpl doc, final NodeId nodeId, final short nodeTy
public NodeProxy(final Expression expression, final DocumentImpl doc, final NodeId nodeId, final short nodeType, final long address) {
this.expression = (expression == null && doc != null) ? doc.getExpression() : expression;
this.doc = doc;
this.nodeType = nodeType;
this.nodeType = nodeType == UNKNOWN_NODE_TYPE && NodeId.DOCUMENT_NODE.equals(nodeId) ? Node.DOCUMENT_NODE : nodeType;
this.internalAddress = address;
this.nodeId = nodeId;
}
Expand Down
11 changes: 0 additions & 11 deletions exist-core/src/main/java/org/exist/storage/BrokerPool.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@

import com.evolvedbinary.j8fu.fsm.AtomicFSM;
import com.evolvedbinary.j8fu.fsm.FSM;
import com.evolvedbinary.j8fu.lazy.AtomicLazyVal;
import net.jcip.annotations.ThreadSafe;
import org.apache.commons.io.output.StringBuilderWriter;
import org.apache.logging.log4j.LogManager;
Expand Down Expand Up @@ -142,8 +141,6 @@ public class BrokerPool extends BrokerPools implements BrokerPoolConstants, Data

private final XQuery xqueryService = new XQuery();

private AtomicLazyVal<SaxonConfiguration> saxonConfiguration = new AtomicLazyVal<>(() -> SaxonConfiguration.loadConfiguration(this));

//TODO : make it non-static since every database instance may have its own policy.
//TODO : make a default value that could be overwritten by the configuration
// WM: this is only used by junit tests to test the recovery process.
Expand Down Expand Up @@ -1957,14 +1954,6 @@ public void registerCollectionTrigger(final Class<? extends CollectionTrigger> c
collectionTriggers.add(new CollectionTriggerProxy(clazz));
}

public net.sf.saxon.Configuration getSaxonConfiguration() {
return saxonConfiguration.get().getConfiguration();
}

public net.sf.saxon.s9api.Processor getSaxonProcessor() {
return saxonConfiguration.get().getProcessor();
}

/**
* Represents a change involving {@link BrokerPool#inactiveBrokers}
* or {@link BrokerPool#activeBrokers} or {@link DBBroker#getReferenceCount}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Elemental
* Copyright (C) 2024, Evolved Binary Ltd
*
* admin@evolvedbinary.com
* https://www.evolvedbinary.com | https://www.elemental.xyz
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; version 2.1.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package org.exist.storage.serializers;

/**
* Elemental Feature Keys for {@link Serializer}.
*
* @author <a href="mailto:adam@evolvedbinary.com">Adam Retter</a>
*/
public interface FeatureKeys {

String NS = "http://ns.elemental.xyz/feature";

/**
* Enable or disable XInclude processing in {@link Serializer}.
*/
String EXPAND_XINCLUDES = NS + "/" + EXistOutputKeys.EXPAND_XINCLUDES;

/**
* Set the path for resolving XInclude resources in {@link Serializer}.
*/
String XINCLUDE_PATH = NS + "/" + EXistOutputKeys.XINCLUDE_PATH;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* Elemental
* Copyright (C) 2024, Evolved Binary Ltd
*
* admin@evolvedbinary.com
* https://www.evolvedbinary.com | https://www.elemental.xyz
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; version 2.1.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package org.exist.storage.serializers;

import org.exist.xquery.value.NodeValue;
import org.xml.sax.InputSource;

import java.io.InputStream;
import java.io.Reader;

/**
* Provides a NodeValue to {@link Serializer#parse(InputSource)}.
* This is not a general purpose {@link InputSource} implementation,
* it should only be used with {@link Serializer}.
*
* @author <a href="mailto:adam@evolvedbinary.com">Adam Retter</a>
*/
public class NodeValueInputSource extends InputSource {

private final NodeValue nodeValue;

/**
* Construct a new NodeValueInputSource where the systemId
* will be taken from the Base URI of the node.
*
* @param nodeValue the NodeValue.
*/
public NodeValueInputSource(final NodeValue nodeValue) {
this(nodeValue, nodeValue.getNode().getBaseURI());
}

/**
* Construct a new NodeValueInputSource where the systemId
* is specified.
*
* @param nodeValue the NodeValue.
* @param systemId the systemId.
*/
public NodeValueInputSource(final NodeValue nodeValue, final String systemId) {
super(systemId);
this.nodeValue = nodeValue;
}

@Override
public void setByteStream(final InputStream byteStream) {
throw new UnsupportedOperationException("This implementation does not support byte streams");
}

@Override
public void setEncoding(final String encoding) {
throw new UnsupportedOperationException("This implementation does not support character encodings");
}

@Override
public void setCharacterStream(final Reader characterStream) {
throw new UnsupportedOperationException("This implementation does not support character streams");
}

/**
* Get the NodeValue.
*
* @return the NodeValue.
*/
NodeValue getNodeValue() {
return nodeValue;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
import java.util.*;

import javax.annotation.Nullable;
import javax.xml.XMLConstants;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Source;
import javax.xml.transform.Templates;
Expand Down Expand Up @@ -312,6 +311,7 @@ public void setProperties(@Nullable final HashMap<String, Object> table)
}
}

@Override
public void setProperty(final String prop, final Object value)
throws SAXNotRecognizedException, SAXNotSupportedException {
switch (prop) {
Expand Down Expand Up @@ -378,10 +378,12 @@ protected void applyXSLHandler(final Writer writer) {
*
* @return The entityResolver value
*/
@Override
public @Nullable EntityResolver getEntityResolver() {
return entityResolver;
}

@Override
public @Nullable ErrorHandler getErrorHandler() {
return errorHandler;
}
Expand All @@ -405,6 +407,7 @@ public void setUser(final Subject user) {
return user;
}

@Override
public boolean getFeature(final String name)
throws SAXNotRecognizedException, SAXNotSupportedException {
if (name.equals(Namespaces.SAX_NAMESPACES)
Expand All @@ -414,6 +417,7 @@ public boolean getFeature(final String name)
throw new SAXNotRecognizedException(name);
}

@Override
public Object getProperty(final String name)
throws SAXNotRecognizedException, SAXNotSupportedException {
if (name.equals(Namespaces.SAX_LEXICAL_HANDLER)) {
Expand All @@ -429,13 +433,20 @@ public Object getProperty(final String name)
return null;
}

@Override
public void parse(final InputSource input) throws IOException, SAXException {
// only system-ids are handled
final String doc = input.getSystemId();
if (doc == null) {
throw new SAXException("source is not an eXist document");
if (input instanceof NodeValueInputSource) {
final NodeValue nodeValue = ((NodeValueInputSource) input).getNodeValue();
toSAX(nodeValue);

} else {
// fallback to trying to parse from the systemId
@Nullable final String systemId = input.getSystemId();
if (systemId == null) {
throw new SAXException("Source's systemId is null");
}
parse(systemId);
}
parse(doc);
}

protected void setDocument(final DocumentImpl doc) {
Expand All @@ -448,20 +459,26 @@ protected void setXQueryContext(@Nullable final XQueryContext context) {
}
}

@Override
public void parse(final String systemId) throws IOException, SAXException {
if (systemId == null) {
throw new SAXException("systemId is null");
}

try {
// try to load document from eXist
//TODO: this systemId came from exist, so should be an unchecked create, right?
final DocumentImpl doc = broker.getResource(XmldbURI.create(systemId), Permission.READ);
// assume the systemId is a URI to a document in the database
@Nullable final DocumentImpl doc = broker.getResource(XmldbURI.create(systemId), Permission.READ);
if (doc == null) {
throw new SAXException("document " + systemId + " not found in database");
} else {
LOG.debug("serializing {}", doc.getFileURI());
throw new SAXException("Document " + systemId + " not found in the database");
}

if (LOG.isDebugEnabled()) {
LOG.debug("Serializing {}", doc.getFileURI());
}

toSAX(doc);
} catch (final PermissionDeniedException e) {
throw new SAXException("permission denied");
throw new SAXException("Permission denied to read document + " + systemId + ": " + e.getMessage(), e);
}
}

Expand Down Expand Up @@ -715,9 +732,19 @@ private void prepareStylesheets(final Document doc) throws TransformerConfigurat
* @param contentHandler the content handler
* @param lexicalHandler the lexical handle
*/
public void setSAXHandlers(final ContentHandler contentHandler, final LexicalHandler lexicalHandler) {
public void setSAXHandlers(final ContentHandler contentHandler, @Nullable LexicalHandler lexicalHandler) {
final ReceiverToSAX toSAX = new ReceiverToSAX(contentHandler);
toSAX.setLexicalHandler(lexicalHandler);

if (lexicalHandler != null) {
this.lexicalHandler = lexicalHandler;
}
if (this.lexicalHandler == null && contentHandler instanceof LexicalHandler) {
this.lexicalHandler = (LexicalHandler) contentHandler;
}
if (this.lexicalHandler != null) {
toSAX.setLexicalHandler(this.lexicalHandler);
}

if ("yes".equals(getProperty(EXistOutputKeys.EXPAND_XINCLUDES, "yes"))) {
xinclude.setReceiver(toSAX);
receiver = xinclude;
Expand Down Expand Up @@ -758,6 +785,7 @@ public void setContentHandler(final ContentHandler handler) {
*
* @param entityResolver The new entityResolver value
*/
@Override
public void setEntityResolver(@Nullable final EntityResolver entityResolver) {
this.entityResolver = entityResolver;
}
Expand All @@ -767,6 +795,7 @@ public void setEntityResolver(@Nullable final EntityResolver entityResolver) {
*
* @param errorHandler The new errorHandler value
*/
@Override
public void setErrorHandler(@Nullable final ErrorHandler errorHandler) {
this.errorHandler = errorHandler;
}
Expand All @@ -779,11 +808,17 @@ public void setErrorHandler(@Nullable final ErrorHandler errorHandler) {
* @throws SAXNotRecognizedException Description of the Exception
* @throws SAXNotSupportedException Description of the Exception
*/
public void setFeature(final String name, final boolean value)
throws SAXNotRecognizedException, SAXNotSupportedException {
if (name.equals(Namespaces.SAX_NAMESPACES) || name.equals(Namespaces.SAX_NAMESPACES_PREFIXES)) {
throw new SAXNotSupportedException(name);
@Override
public void setFeature(final String name, final boolean value) throws SAXNotRecognizedException, SAXNotSupportedException {
if (Namespaces.SAX_NAMESPACES.equals(name) || Namespaces.SAX_NAMESPACES_PREFIXES.equals(name)) {
return;
}

if (FeatureKeys.EXPAND_XINCLUDES.equals(name)) {
setProperty(EXistOutputKeys.EXPAND_XINCLUDES, value ? "yes" : "no");
return;
}

throw new SAXNotRecognizedException(name);
}

Expand Down
1 change: 1 addition & 0 deletions exist-core/src/main/java/org/exist/util/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import org.exist.xquery.Expression;
import org.exist.xquery.PerformanceStats;
import org.exist.xquery.XQueryWatchDog;
import org.exist.xslt.SaxonConfiguration;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
Expand Down
Loading