private Object readDocContent(String docId) { Object docContent = null; if (docContentType == byte[].class){ docContent = ((BytesHandle)docManager.read(docId, new BytesHandle())).get(); } else if (docContentType == File.class) { try { docContent = new SAXReader().read((File) docManager.readAs(docId, docContentType)); } catch (DocumentException e) { throw new MarkLogicException(new MarkLogicErrorCode("Can't read document"), e); } } else { docContent = docManager.readAs(docId, docContentType); } return docContent; }
public XMLStreamReaderHandle readDocumentUsingXMLStreamReaderHandle(DatabaseClient client, String uri, String type) { // create doc manager DocumentManager docMgr = null; docMgr = documentManagerSelector(client, docMgr, type); // create handle XMLStreamReaderHandle readerHandle = new XMLStreamReaderHandle(); // create doc id String readDocId = uri; System.out.println("Read " + readDocId + " from database"); docMgr.read(readDocId, readerHandle); return readerHandle; }
@Test // https://github.com/marklogic/java-client-api/issues/759 public void test_issue_759() throws Exception { DocumentManager docMgr = Common.client.newDocumentManager(); String[] uris = new String[150]; for ( int i=0; i < 102; i++ ) { String mapDocId = "/" + Integer.toString(i); uris[i] = mapDocId; } docMgr.read(uris); }
private Object readDocContent(String docId) { Object docContent = null; if (docContentType == byte[].class){ docContent = ((BytesHandle)docManager.read(docId, new BytesHandle())).get(); } else if (docContentType == File.class) { try { docContent = new SAXReader().read((File) docManager.readAs(docId, docContentType)); } catch (DocumentException e) { throw new MarkLogicException(new MarkLogicErrorCode("Can't read document"), e); } } else { docContent = docManager.readAs(docId, docContentType); } return docContent; }
private void verifyDeleted(DocumentManager docMgr, String uri) { try { docMgr.read(uri, new StringHandle()); } catch(ResourceNotFoundException e) { // success! return; } fail("Read of document with uri=[" + uri + "] should have thrown ResourceNotFoundException"); }
/** * Read document using JAXBHandle * * @param client * @param uri * @param type * @return * @throws JAXBException */ public JAXBHandle readDocumentUsingJAXBHandle(DatabaseClient client, String uri, String type) throws JAXBException { // create doc manager DocumentManager docMgr = null; docMgr = documentManagerSelector(client, docMgr, type); // create handle JAXBContext con = JAXBContext.newInstance(Product.class); JAXBHandle contentHandle = new JAXBHandle(con); // create doc id String readDocId = uri; System.out.println("Read " + readDocId + " from database"); docMgr.read(readDocId, contentHandle); return contentHandle; }
/** * Reading document using SourceHandle * * @param client * @param uri * @param type * @return */ public SourceHandle readDocumentUsingSourceHandle(DatabaseClient client, String uri, String type) { // create doc manager DocumentManager docMgr = null; docMgr = documentManagerSelector(client, docMgr, type); // create handle SourceHandle contentHandle = new SourceHandle(); // create doc id String readDocId = uri; System.out.println("Read " + readDocId + " from database"); docMgr.read(readDocId, contentHandle); return contentHandle; }
/** * Read document using StringHandle * * @param client * @param uri * @param type * @return */ public StringHandle readDocumentUsingStringHandle(DatabaseClient client, String uri, String type) { // create doc manager DocumentManager docMgr = null; docMgr = documentManagerSelector(client, docMgr, type); // create handle StringHandle contentHandle = new StringHandle(); // contentHandle.set(readContent); // create doc id String readDocId = uri; System.out.println("Read " + readDocId + " from database"); docMgr.read(readDocId, contentHandle); return contentHandle; }
/** * Reading document using InputStreamHandle * * @param client * @param uri * @param type * @return */ public InputStreamHandle readDocumentUsingInputStreamHandle(DatabaseClient client, String uri, String type) { // create doc manager DocumentManager docMgr = null; docMgr = documentManagerSelector(client, docMgr, type); // create handle InputStreamHandle contentHandle = new InputStreamHandle(); // create doc id String readDocId = uri; System.out.println("Read " + readDocId + " from database"); docMgr.read(readDocId, contentHandle); return contentHandle; }
/** * Reading document using InputSourceHandle * * @param client * @param uri * @param type * @return */ public InputSourceHandle readDocumentUsingInputSourceHandle(DatabaseClient client, String uri, String type) { // create doc manager DocumentManager docMgr = null; docMgr = documentManagerSelector(client, docMgr, type); // create handle InputSourceHandle contentHandle = new InputSourceHandle(); // create doc id String readDocId = uri; System.out.println("Read " + readDocId + " from database"); docMgr.read(readDocId, contentHandle); return contentHandle; }
/** * Read document using FileHandle * * @param client * @param uri * @param type * @return */ public FileHandle readDocumentUsingFileHandle(DatabaseClient client, String uri, String type) { // create doc manager DocumentManager docMgr = null; docMgr = documentManagerSelector(client, docMgr, type); // create handle FileHandle contentHandle = new FileHandle(); // create doc id String readDocId = uri; System.out.println("Read " + readDocId + " from database"); docMgr.read(readDocId, contentHandle); return contentHandle; }
/** * Read document using BytesHandle * * @param client * @param uri * @param type * @throws IOException */ public BytesHandle readDocumentUsingBytesHandle(DatabaseClient client, String uri, String type) throws IOException, NullPointerException { // create doc manager DocumentManager docMgr = null; docMgr = documentManagerSelector(client, docMgr, type); // create handle BytesHandle contentHandle = new BytesHandle(); // create doc id String readDocId = uri; System.out.println("Read " + readDocId + " from database"); docMgr.read(readDocId, contentHandle); return contentHandle; }
/** * Read document using ReaderHandle * * @param client * @param uri * @param type * @return */ public ReaderHandle readDocumentReaderHandle(DatabaseClient client, String uri, String type) { // create doc manager DocumentManager docMgr = null; docMgr = documentManagerSelector(client, docMgr, type); // create handle ReaderHandle readerHandle = new ReaderHandle(); // create doc id String readDocId = uri; System.out.println("Read " + readDocId + " from database"); docMgr.read(readDocId, readerHandle); return readerHandle; }
/** * Read document using XMLEventReaderHandle * * @param client * @param uri * @param type * @return */ public XMLEventReaderHandle readDocumentUsingXMLEventReaderHandle(DatabaseClient client, String uri, String type) { // create doc manager DocumentManager docMgr = null; docMgr = documentManagerSelector(client, docMgr, type); // create handle XMLEventReaderHandle readerHandle = new XMLEventReaderHandle(); // create doc id String readDocId = uri; System.out.println("Read " + readDocId + " from database"); docMgr.read(readDocId, readerHandle); return readerHandle; }
/** * Read document using DOMHandle * * @param client * @param uri * @param type * @return */ public DOMHandle readDocumentUsingDOMHandle(DatabaseClient client, String uri, String type) { // create doc manager DocumentManager docMgr = null; docMgr = documentManagerSelector(client, docMgr, type); // create handle DOMHandle contentHandle = new DOMHandle(); // create doc id String readDocId = uri; System.out.println("Read " + readDocId + " from database"); docMgr.read(readDocId, contentHandle); return contentHandle; }
@Test public void testUnmatchedMimetypeOnXML() throws KeyManagementException, NoSuchAlgorithmException, IOException, ParserConfigurationException, SAXException, XpathException { System.out.println("Running testUnmatchedMimetypeOnXML"); String filename = "flipper.xml"; String uri = "/xml-mimetype/"; // connect the client DatabaseClient client = getDatabaseClient("rest-writer", "x", getConnType()); // create doc manager DocumentManager docMgr = client.newDocumentManager(); File file = new File("src/test/java/com/marklogic/client/functionaltest/data/" + filename); // create a handle on the content FileHandle handle = new FileHandle(file); handle.set(file); handle.setMimetype("image/svg+xml"); // create docId String docId = uri + filename; docMgr.write(docId, handle); String expectedUri = uri + filename; String docUri = docMgr.exists(expectedUri).getUri(); assertEquals("URI is not found", expectedUri, docUri); // read document mimetype docMgr.read(docId, handle); String format = handle.getFormat().name(); String expectedFormat = "XML"; assertEquals("Format does not match", expectedFormat, format); // release the client client.release(); }
@Test public void testUnknownMimetypeOnText() throws KeyManagementException, NoSuchAlgorithmException, IOException, ParserConfigurationException, SAXException, XpathException { System.out.println("Running testUnknownMimetypeOnText"); String filename = "text-original.txt"; String uri = "/txt-mimetype/"; // connect the client DatabaseClient client = getDatabaseClient("rest-writer", "x", getConnType()); // create doc manager DocumentManager docMgr = client.newDocumentManager(); File file = new File("src/test/java/com/marklogic/client/functionaltest/data/" + filename); // create a handle on the content FileHandle handle = new FileHandle(file); handle.set(file); handle.setMimetype("application/rtf"); // create docId String docId = uri + filename; docMgr.write(docId, handle); String expectedUri = uri + filename; String docUri = docMgr.exists(expectedUri).getUri(); assertEquals("URI is not found", expectedUri, docUri); // read document mimetype docMgr.read(docId, handle); String format = handle.getFormat().name(); String expectedFormat = "TEXT"; assertEquals("Format does not match", expectedFormat, format); // release the client client.release(); }
@Test public void testUnsupportedMimetypeOnText() throws KeyManagementException, NoSuchAlgorithmException, IOException, ParserConfigurationException, SAXException, XpathException { System.out.println("Running testUnsupportedMimetypeOnText"); String filename = "text-original.txt"; String uri = "/txt-mimetype/"; // connect the client DatabaseClient client = getDatabaseClient("rest-writer", "x", getConnType()); // create doc manager DocumentManager docMgr = client.newDocumentManager(); File file = new File("src/test/java/com/marklogic/client/functionaltest/data/" + filename); // create a handle on the content FileHandle handle = new FileHandle(file); handle.set(file); handle.setMimetype("application/vnd.nokia.configuration-message"); // create docId String docId = uri + filename; docMgr.write(docId, handle); String expectedUri = uri + filename; String docUri = docMgr.exists(expectedUri).getUri(); assertEquals("URI is not found", expectedUri, docUri); // read document mimetype docMgr.read(docId, handle); String format = handle.getFormat().name(); String expectedFormat = "TEXT"; assertEquals("Format does not match", expectedFormat, format); // release the client client.release(); }
@Test public void testMatchedMimetypeOnJSON() throws KeyManagementException, NoSuchAlgorithmException, IOException, ParserConfigurationException, SAXException, XpathException { System.out.println("Running testMatchedMimetypeOnJSON"); String filename = "json-original.json"; String uri = "/json-mimetype/"; // connect the client DatabaseClient client = getDatabaseClient("rest-writer", "x", getConnType()); // create doc manager DocumentManager docMgr = client.newDocumentManager(); File file = new File("src/test/java/com/marklogic/client/functionaltest/data/" + filename); // create a handle on the content FileHandle handle = new FileHandle(file); handle.set(file); handle.setMimetype("application/json"); // create docId String docId = uri + filename; docMgr.write(docId, handle); String expectedUri = uri + filename; String docUri = docMgr.exists(expectedUri).getUri(); assertEquals("URI is not found", expectedUri, docUri); // read document format docMgr.read(docId, handle); String format = handle.getFormat().name(); String expectedFormat = "JSON"; assertEquals("Format does not match", expectedFormat, format); // release the client client.release(); }
@Test public void testMatchedMimetypeOnBinary() throws KeyManagementException, NoSuchAlgorithmException, IOException, ParserConfigurationException, SAXException, XpathException { System.out.println("Running testMatchedMimetypeOnBinary"); String filename = "Pandakarlino.jpg"; String uri = "/bin-mimetype/"; // connect the client DatabaseClient client = getDatabaseClient("rest-writer", "x", getConnType()); // create doc manager DocumentManager docMgr = client.newDocumentManager(); File file = new File("src/test/java/com/marklogic/client/functionaltest/data/" + filename); // create a handle on the content FileHandle handle = new FileHandle(file); handle.set(file); handle.setMimetype("image/jpeg"); // create docId String docId = uri + filename; docMgr.write(docId, handle); String expectedUri = uri + filename; String docUri = docMgr.exists(expectedUri).getUri(); assertEquals("URI is not found", expectedUri, docUri); // read document format docMgr.read(docId, handle); String format = handle.getFormat().name(); String expectedFormat = "BINARY"; assertEquals("Format does not match", expectedFormat, format); // release the client client.release(); }