DatabaseRepresentation { public StreamingOutput getResource(final String resourceName, final Map<QueryParameter, String> queryParams) throws JaxRxException { final StreamingOutput streamingOutput = new StreamingOutput() { @Override public void write(final OutputStream output) throws IOException, JaxRxException { final String revision = queryParams.get(QueryParameter.REVISION); final String wrap = queryParams.get(QueryParameter.WRAP); final String nodeId = queryParams.get(QueryParameter.OUTPUT); final boolean wrapResult = (wrap == null) ? false : wrap .equalsIgnoreCase(YESSTRING); final boolean nodeid = (nodeId == null) ? false : nodeId .equalsIgnoreCase(YESSTRING); try { if (revision == null) { serialize(resourceName, null, nodeid, output, wrapResult); } else { final Pattern pattern = Pattern.compile("[0-9]+[-]{1}[1-9]+"); final Matcher matcher = pattern.matcher(revision); if (matcher.matches()) { getModificHistory(resourceName, revision, nodeid, output, wrapResult); } else { serialize(resourceName, Integer.valueOf(revision), nodeid, output, wrapResult); } } } catch (final NumberFormatException exce) { throw new JaxRxException(400, exce.getMessage()); } catch (final SirixException exce) { throw new JaxRxException(exce); } } }; return streamingOutput; } DatabaseRepresentation(final File storagePath); void createResource(final InputStream inputStream,
			final String resourceName); StreamingOutput getResource(final String resourceName,
			final Map<QueryParameter, String> queryParams); StreamingOutput performQueryOnResource(final String resource,
			final String query, final Map<QueryParameter, String> otherParams); StreamingOutput getResourcesNames(); boolean add(final InputStream input, final String resource); void deleteResource(final String resourceName); final boolean shred(final InputStream xmlInput, final String resource); long getLastRevision(final String resourceName); OutputStream getModificHistory(
			final String resourceName, // NOPMD this method needs alls these
			// functions
			final String revisionRange, final boolean nodeid,
			final OutputStream output, final boolean wrap); void revertToRevision(final String resourceName,
			final int backToRevision);  }
@Test public void getResource() throws SirixException, WebApplicationException, IOException, ParserConfigurationException, SAXException { final Map<QueryParameter, String> queryParams = new HashMap<QueryParameter, String>(); Document doc; Node node; Node resultNode; Attr attribute; StreamingOutput sOutput = sirix.getResource(RESOURCENAME, queryParams); ByteArrayOutputStream output = new ByteArrayOutputStream(); sOutput.write(output); doc = DOMHelper.buildDocument(output); node = doc.getElementsByTagName("mondial").item(0); attribute = (Attr) node.getAttributes().getNamedItem(IDNAME); resultNode = doc.getElementsByTagName(RESULTNAME).item(0); assertNotNull("mondial does exist", node); assertNull("test if result node exists - null", resultNode); assertNull("test if id element exists - null", attribute); output.close(); queryParams.put(QueryParameter.WRAP, LITERALTRUE); sOutput = sirix.getResource(RESOURCENAME, queryParams); output = new ByteArrayOutputStream(); sOutput.write(output); doc = DOMHelper.buildDocument(output); node = doc.getElementsByTagName("country").item(0); attribute = (Attr) node.getAttributes().getNamedItem(IDNAME); resultNode = doc.getElementsByTagName(RESULTNAME).item(0); assertNotNull("test if country exists", node); assertNotNull("test if result node exists", resultNode); assertNull("test if id element exists", attribute); output.close(); queryParams.put(QueryParameter.OUTPUT, LITERALTRUE); sOutput = sirix.getResource(RESOURCENAME, queryParams); output = new ByteArrayOutputStream(); sOutput.write(output); doc = DOMHelper.buildDocument(output); node = doc.getElementsByTagName(NAME).item(0); attribute = (Attr) node.getAttributes().getNamedItem(IDNAME); resultNode = doc.getElementsByTagName(RESULTNAME).item(0); assertNotNull("test if country exists2", node); assertNotNull("test if result node exists2", resultNode); assertNotNull("test if id element exists2", attribute); output.close(); sOutput = sirix.getResource(RESOURCENAME, queryParams); output = new ByteArrayOutputStream(); sOutput.write(output); doc = DOMHelper.buildDocument(output); node = doc.getElementsByTagName("city").item(0); attribute = (Attr) node.getAttributes().getNamedItem(IDNAME); resultNode = doc.getElementsByTagName(RESULTNAME).item(0); assertNotNull("test if city exists2", node); assertNotNull("test if result node exists2", resultNode); assertNotNull("test if id element exists2", attribute); output.close(); }