use of org.exist.xmldb.LocalXMLResource in project exist by eXist-db.
the class TestCase method getResource.
public Resource getResource(Object r) throws XMLDBException {
LocalCollection collection = null;
Subject user = null;
LocalXMLResource res = null;
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
if (r instanceof NodeProxy) {
NodeProxy p = (NodeProxy) r;
res = new LocalXMLResource(user, pool, collection, p);
} else if (r instanceof Node) {
res = new LocalXMLResource(user, pool, collection, XmldbURI.EMPTY_URI);
res.setContentAsDOM((Node) r);
} else if (r instanceof AtomicValue) {
res = new LocalXMLResource(user, pool, collection, XmldbURI.EMPTY_URI);
res.setContent(r);
} else if (r instanceof LocalXMLResource)
res = (LocalXMLResource) r;
else
throw new XMLDBException(ErrorCodes.VENDOR_ERROR, "unknown object " + r.getClass());
try {
Field field = res.getClass().getDeclaredField("outputProperties");
field.setAccessible(true);
field.set(res, new Properties(defaultProperties));
} catch (Exception e) {
}
return res;
}
use of org.exist.xmldb.LocalXMLResource in project exist by eXist-db.
the class InternalModuleTest method moduleVariablesQuery.
private void moduleVariablesQuery(final EXistXQueryService queryService, final Source query, final long expectedCount) throws XMLDBException {
// this variation of execute will use the XQueryPool for caching
final ResourceSet result = queryService.execute(query);
assertNotNull(result);
assertEquals(1, result.getSize());
final LocalXMLResource resource = (LocalXMLResource) result.getResource(0);
assertNotNull(resource);
final Node actualDoc = resource.getContentAsDOM();
final javax.xml.transform.Source expected = Input.fromString("<variables><var1>" + expectedCount + "</var1></variables>").build();
final javax.xml.transform.Source actual = Input.fromNode(actualDoc).build();
final Diff diff = DiffBuilder.compare(expected).withTest(actual).checkForSimilar().build();
assertFalse(diff.toString(), diff.hasDifferences());
}
use of org.exist.xmldb.LocalXMLResource in project exist by eXist-db.
the class XPathUtil method getNode.
/**
* Converts an XMLResource into a NodeProxy.
*
* @param broker The DBBroker to use to access the database
* @param xres The XMLResource to convert
* @return A NodeProxy for accessing the content represented by xres
* @throws XPathException if an XMLDBException is encountered
*/
public static final NodeProxy getNode(DBBroker broker, XMLResource xres) throws XPathException {
if (xres instanceof LocalXMLResource) {
final LocalXMLResource lres = (LocalXMLResource) xres;
try {
return lres.getNode();
} catch (final XMLDBException xe) {
throw new XPathException("Failed to convert LocalXMLResource to node: " + xe.getMessage());
}
}
DocumentImpl document;
try {
document = broker.getCollection(XmldbURI.xmldbUriFor(xres.getParentCollection().getName())).getDocument(broker, XmldbURI.xmldbUriFor(xres.getDocumentId()));
} catch (final URISyntaxException xe) {
throw new XPathException(xe);
} catch (final XMLDBException xe) {
throw new XPathException("Failed to get document for RemoteXMLResource: " + xe.getMessage());
} catch (final PermissionDeniedException pde) {
throw new XPathException("Failed to get document: " + pde.getMessage());
}
final NodeId nodeId = broker.getBrokerPool().getNodeFactory().createFromString(((RemoteXMLResource) xres).getNodeId());
return new NodeProxy(document, nodeId);
}
use of org.exist.xmldb.LocalXMLResource in project exist by eXist-db.
the class InternalModuleTest method requestResponseSessionVariablesQuery_4_x_X_Api.
private void requestResponseSessionVariablesQuery_4_x_X_Api(final EXistXQueryService queryService, final Source query) throws XMLDBException {
// this variation of execute will use the XQueryPool for caching
final ResourceSet result = queryService.execute(query);
assertNotNull(result);
assertEquals(1, result.getSize());
final LocalXMLResource resource = (LocalXMLResource) result.getResource(0);
assertNotNull(resource);
final Node actualDoc = resource.getContentAsDOM();
final javax.xml.transform.Source expected = Input.fromString("<vars><request>XPDY0002</request><session>XPDY0002</session><response>XPDY0002</response></vars>").build();
final javax.xml.transform.Source actual = Input.fromNode(actualDoc).build();
final Diff diff = DiffBuilder.compare(expected).withTest(actual).checkForSimilar().build();
assertFalse(diff.toString(), diff.hasDifferences());
}
use of org.exist.xmldb.LocalXMLResource in project exist by eXist-db.
the class DocTest method testURIResolveWithEval.
@Test
public void testURIResolveWithEval() throws XMLDBException {
String query = "util:eval(xs:anyURI('/db/test/test.xq'), false(), ())";
ResourceSet result = existEmbeddedServer.executeQuery(query);
LocalXMLResource res = (LocalXMLResource) result.getResource(0);
assertNotNull(res);
Node n = res.getContentAsDOM();
assertEquals("y", n.getLocalName());
query = "util:eval(xs:anyURI('/db/test/test1.xq'), false(), ())";
result = existEmbeddedServer.executeQuery(query);
res = (LocalXMLResource) result.getResource(0);
assertNotNull(res);
n = res.getContentAsDOM();
assertEquals("x", n.getLocalName());
query = "util:eval(xs:anyURI('/db/test/test2.xq'), false(), ())";
result = existEmbeddedServer.executeQuery(query);
res = (LocalXMLResource) result.getResource(0);
assertNotNull(res);
n = res.getContentAsDOM();
assertEquals("x", n.getLocalName());
}
Aggregations