@Test public final void testBuildResponseOfDomLR() throws WebApplicationException, IOException, ParserConfigurationException, SAXException, TTException, InterruptedException { final List<String> availResources = new ArrayList<String>(); availResources.add(FACT); availResources.add(EBAY); availResources.add(BOOK); availResources.add(SHAKE); final DatabaseRepresentation treetank = new DatabaseRepresentation(CoreTestHelper.getStorage(CoreTestHelper.PATHS.PATH1.getFile()), mStorageFac, mRevisioning); InputStream input = NodeIdRepresentationTest.class.getClass().getResourceAsStream(RESPATH); treetank.shred(input, FACT); input.close(); input = NodeIdRepresentationTest.class.getClass().getResourceAsStream(RESPATH); treetank.shred(input, EBAY); input.close(); input.close(); input = NodeIdRepresentationTest.class.getClass().getResourceAsStream(RESPATH); treetank.add(input, BOOK); input = NodeIdRepresentationTest.class.getClass().getResourceAsStream(RESPATH); treetank.shred(input, SHAKE); input.close(); final StreamingOutput result = RESTResponseHelper.buildResponseOfDomLR(CoreTestHelper.getStorage(CoreTestHelper.PATHS.PATH1 .getFile()), mStorageFac, mRevisioning); final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); result.write(outputStream); final Document doc = DOMHelper.buildDocument(outputStream); final NodeList listRes = doc.getElementsByTagName("resource"); assertEquals("Test for the length of resource", 4, listRes.getLength()); Set<String> names = new HashSet<String>(); names.add(listRes.item(0).getAttributes().getNamedItem(NAME).getTextContent()); names.add(listRes.item(1).getAttributes().getNamedItem(NAME).getTextContent()); names.add(listRes.item(2).getAttributes().getNamedItem(NAME).getTextContent()); names.add(listRes.item(3).getAttributes().getNamedItem(NAME).getTextContent()); assertTrue(names.remove(FACT)); assertTrue(names.remove(EBAY)); assertTrue(names.remove(BOOK)); assertTrue(names.remove(SHAKE)); assertEquals("Size of test-structure must be 0", 0, names.size()); outputStream.close(); treetank.deleteResource(EBAY); treetank.deleteResource(FACT); treetank.deleteResource(BOOK); treetank.deleteResource(SHAKE); }
public static StreamingOutput buildResponseOfDomLR(final IStorage pDatabase, final IBackendFactory pStorageFac, final IRevisioning pRevision) { final StreamingOutput sOutput = new StreamingOutput() { @Override public void write(final OutputStream output) throws IOException, WebApplicationException { Document document; try { document = createSurroundingXMLResp(); final Element resElement = RESTResponseHelper.createResultElement(document); List<Element> collections; try { collections = RESTResponseHelper.createCollectionElementDBs(pDatabase, document, pStorageFac, pRevision); } catch (final TTException exce) { throw new WebApplicationException(exce); } for (final Element resource : collections) { resElement.appendChild(resource); } document.appendChild(resElement); final DOMSource domSource = new DOMSource(document); final StreamResult streamResult = new StreamResult(output); final Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.transform(domSource, streamResult); } catch (final ParserConfigurationException exce) { throw new WebApplicationException(exce); } catch (final TransformerConfigurationException exce) { throw new WebApplicationException(exce); } catch (final TransformerFactoryConfigurationError exce) { throw new WebApplicationException(exce); } catch (final TransformerException exce) { throw new WebApplicationException(exce); } } }; return sOutput; }
RESTResponseHelper { public static StreamingOutput buildResponseOfDomLR(final IStorage pDatabase, final IBackendFactory pStorageFac, final IRevisioning pRevision) { final StreamingOutput sOutput = new StreamingOutput() { @Override public void write(final OutputStream output) throws IOException, WebApplicationException { Document document; try { document = createSurroundingXMLResp(); final Element resElement = RESTResponseHelper.createResultElement(document); List<Element> collections; try { collections = RESTResponseHelper.createCollectionElementDBs(pDatabase, document, pStorageFac, pRevision); } catch (final TTException exce) { throw new WebApplicationException(exce); } for (final Element resource : collections) { resElement.appendChild(resource); } document.appendChild(resElement); final DOMSource domSource = new DOMSource(document); final StreamResult streamResult = new StreamResult(output); final Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.transform(domSource, streamResult); } catch (final ParserConfigurationException exce) { throw new WebApplicationException(exce); } catch (final TransformerConfigurationException exce) { throw new WebApplicationException(exce); } catch (final TransformerFactoryConfigurationError exce) { throw new WebApplicationException(exce); } catch (final TransformerException exce) { throw new WebApplicationException(exce); } } }; return sOutput; } }
RESTResponseHelper { public static StreamingOutput buildResponseOfDomLR(final IStorage pDatabase, final IBackendFactory pStorageFac, final IRevisioning pRevision) { final StreamingOutput sOutput = new StreamingOutput() { @Override public void write(final OutputStream output) throws IOException, WebApplicationException { Document document; try { document = createSurroundingXMLResp(); final Element resElement = RESTResponseHelper.createResultElement(document); List<Element> collections; try { collections = RESTResponseHelper.createCollectionElementDBs(pDatabase, document, pStorageFac, pRevision); } catch (final TTException exce) { throw new WebApplicationException(exce); } for (final Element resource : collections) { resElement.appendChild(resource); } document.appendChild(resElement); final DOMSource domSource = new DOMSource(document); final StreamResult streamResult = new StreamResult(output); final Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.transform(domSource, streamResult); } catch (final ParserConfigurationException exce) { throw new WebApplicationException(exce); } catch (final TransformerConfigurationException exce) { throw new WebApplicationException(exce); } catch (final TransformerFactoryConfigurationError exce) { throw new WebApplicationException(exce); } catch (final TransformerException exce) { throw new WebApplicationException(exce); } } }; return sOutput; } private  RESTResponseHelper(); }
RESTResponseHelper { public static StreamingOutput buildResponseOfDomLR(final IStorage pDatabase, final IBackendFactory pStorageFac, final IRevisioning pRevision) { final StreamingOutput sOutput = new StreamingOutput() { @Override public void write(final OutputStream output) throws IOException, WebApplicationException { Document document; try { document = createSurroundingXMLResp(); final Element resElement = RESTResponseHelper.createResultElement(document); List<Element> collections; try { collections = RESTResponseHelper.createCollectionElementDBs(pDatabase, document, pStorageFac, pRevision); } catch (final TTException exce) { throw new WebApplicationException(exce); } for (final Element resource : collections) { resElement.appendChild(resource); } document.appendChild(resElement); final DOMSource domSource = new DOMSource(document); final StreamResult streamResult = new StreamResult(output); final Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.transform(domSource, streamResult); } catch (final ParserConfigurationException exce) { throw new WebApplicationException(exce); } catch (final TransformerConfigurationException exce) { throw new WebApplicationException(exce); } catch (final TransformerFactoryConfigurationError exce) { throw new WebApplicationException(exce); } catch (final TransformerException exce) { throw new WebApplicationException(exce); } } }; return sOutput; } private  RESTResponseHelper(); static StreamingOutput buildResponseOfDomLR(final IStorage pDatabase,
        final IBackendFactory pStorageFac, final IRevisioning pRevision); }
RESTResponseHelper { public static StreamingOutput buildResponseOfDomLR(final IStorage pDatabase, final IBackendFactory pStorageFac, final IRevisioning pRevision) { final StreamingOutput sOutput = new StreamingOutput() { @Override public void write(final OutputStream output) throws IOException, WebApplicationException { Document document; try { document = createSurroundingXMLResp(); final Element resElement = RESTResponseHelper.createResultElement(document); List<Element> collections; try { collections = RESTResponseHelper.createCollectionElementDBs(pDatabase, document, pStorageFac, pRevision); } catch (final TTException exce) { throw new WebApplicationException(exce); } for (final Element resource : collections) { resElement.appendChild(resource); } document.appendChild(resElement); final DOMSource domSource = new DOMSource(document); final StreamResult streamResult = new StreamResult(output); final Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.transform(domSource, streamResult); } catch (final ParserConfigurationException exce) { throw new WebApplicationException(exce); } catch (final TransformerConfigurationException exce) { throw new WebApplicationException(exce); } catch (final TransformerFactoryConfigurationError exce) { throw new WebApplicationException(exce); } catch (final TransformerException exce) { throw new WebApplicationException(exce); } } }; return sOutput; } private  RESTResponseHelper(); static StreamingOutput buildResponseOfDomLR(final IStorage pDatabase,
        final IBackendFactory pStorageFac, final IRevisioning pRevision);  }