use of org.sirix.service.xml.serialize.XMLSerializer.XMLSerializerBuilder in project sirix by sirixdb.
the class XMLSerializerTest method testIDSerializer.
@Test
public void testIDSerializer() throws Exception {
final Database database = TestHelper.getDatabase(PATHS.PATH1.getFile());
final ResourceManager manager = database.getResourceManager(new ResourceManagerConfiguration.Builder(TestHelper.RESOURCE).build());
final XdmNodeWriteTrx wtx = manager.beginNodeWriteTrx();
DocumentCreater.create(wtx);
wtx.commit();
wtx.close();
// Generate from this session.
final ByteArrayOutputStream out = new ByteArrayOutputStream();
final XMLSerializer serializer = new XMLSerializerBuilder(manager, out).emitIDs().emitXMLDeclaration().build();
serializer.call();
assertEquals(DocumentCreater.ID, out.toString());
manager.close();
}
use of org.sirix.service.xml.serialize.XMLSerializer.XMLSerializerBuilder in project sirix by sirixdb.
the class NodeIdRepresentation method serialize.
/**
* This method serializes requested resource
*
* @param resource
* The requested resource
* @param nodeId
* The node id of the requested resource.
* @param revision
* The revision of the requested resource.
* @param doNodeId
* Specifies whether the node id's have to be shown in the result.
* @param output
* The output stream to be written.
* @param wrapResult
* Specifies whether the result has to be wrapped with a result
* element.
*/
private void serialize(final String resource, final long nodeId, final Long revision, final boolean doNodeId, final OutputStream output, final boolean wrapResult) {
if (WorkerHelper.checkExistingResource(mStoragePath, resource)) {
Session session = null;
Database database = null;
try {
database = Databases.openDatabase(mStoragePath);
session = database.getSession(new SessionConfiguration.Builder(resource).build());
if (wrapResult) {
output.write(BEGINRESULT);
final XMLSerializerProperties props = new XMLSerializerProperties();
final XMLSerializerBuilder builder = new XMLSerializerBuilder(session, nodeId, output, props);
if (doNodeId) {
builder.emitRESTful().emitIDs();
}
final XMLSerializer serializer = builder.build();
serializer.call();
output.write(ENDRESULT);
} else {
final XMLSerializerProperties props = new XMLSerializerProperties();
final XMLSerializerBuilder builder = new XMLSerializerBuilder(session, nodeId, output, props);
if (doNodeId) {
builder.emitRESTful().emitIDs();
}
final XMLSerializer serializer = builder.build();
serializer.call();
}
} catch (final SirixException ttExcep) {
throw new JaxRxException(ttExcep);
} catch (final IOException ioExcep) {
throw new JaxRxException(ioExcep);
} catch (final Exception globExcep) {
if (globExcep instanceof JaxRxException) {
// types
throw (JaxRxException) globExcep;
} else {
throw new JaxRxException(globExcep);
}
} finally {
try {
WorkerHelper.closeRTX(null, session, database);
} catch (final SirixException exce) {
throw new JaxRxException(exce);
}
}
} else {
throw new JaxRxException(404, "Resource does not exist");
}
}
Aggregations