@Override public String readDocument(String uri) throws BagriException { DocumentAccessor doc = xRepo.getDocumentManagement().getDocument(uri, null); if (doc == null) { return null; } return doc.getContent(); }
public String getDocument(String uri) throws BagriException { // get it as Map? DocumentAccessor doc = xRepo.getDocumentManagement().getDocument(uri, null); return doc.getContent(); }
@GET @Path("/{uri}") @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) @ApiOperation(value = "getDocumentContent: return content of the specified Document") public Response getDocumentContent(@PathParam("uri") String uri, @Context HttpHeaders hh) { DocumentManagement docMgr = getDocManager(); try { Properties props = new Properties(); if (MediaType.APPLICATION_JSON_TYPE.equals(hh.getAcceptableMediaTypes().get(0))) { props.setProperty(pn_document_data_format, df_json); } else if (MediaType.APPLICATION_XML_TYPE.equals(hh.getAcceptableMediaTypes().get(0))) { props.setProperty(pn_document_data_format, df_xml); } DocumentAccessor doc = docMgr.getDocument(uri, props); String content = doc.getContent(); return Response.ok(content).build(); } catch (Exception ex) { logger.error("getDocumentContent.error", ex); throw new WebApplicationException(ex, Status.INTERNAL_SERVER_ERROR); //return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(ex.getMessage()).build(); } }
public void afterInsert(Document doc, SchemaRepository repo) { logger.info("afterInsert.enter; doc: {}; repo: {}", doc, repo); try { Properties props = new Properties(); props.setProperty(pn_document_data_format, "XML"); DocumentAccessor da = repo.getDocumentManagement().getDocument(doc.getUri(), props); Security sec = da.getContent(); logger.info("afterInsert.exit; got security: {}/{}/{}", sec.getName(), sec.getSymbol(), sec.getId()); } catch (BagriException ex) { logger.info("afterInsert.error; got exception: {}", ex.getMessage()); } }
@Override public Item getItem(XPathContext context) throws XPathException { if (json == null) { Properties props = new Properties(); props.setProperty(pn_document_data_format, "JSON"); props.setProperty(pn_document_headers, String.valueOf(DocumentAccessor.HDR_CONTENT)); try { DocumentAccessor doc = docMgr.getDocument(docKey, props); if (doc == null) { throw new XPathException("Lost document for key: " + docKey); } json = doc.getContent(); } catch (BagriException ex) { throw new XPathException(ex); } } //MapItem options = new HashTrieMap(context); Map<String, Sequence> options = new HashMap<>(); options.put("liberal", BooleanValue.FALSE); options.put("duplicates", new StringValue("use-first")); options.put("escape", BooleanValue.FALSE); return ParseJsonFn.parse(json, options, context); }
@ManagedOperation(description="Return Document Content") @ManagedOperationParameters({ @ManagedOperationParameter(name = "uri", description = "Document identifier"), @ManagedOperationParameter(name = "properties", description = "A list of properties in key=value form separated by semicolon")}) public String getDocumentContent(String uri, String properties) { try { String result = null; DocumentAccessor doc = docManager.getDocument(uri, propsFromString(properties)); if (doc != null) { result = doc.getContent(); } logger.debug("getDocumentContent; got accessor {} for uri: {}, props: {}; returning: {}", doc, uri, properties, result); return result; } catch (IOException | BagriException ex) { logger.error("getDocumentContent.error: {}", ex.getMessage(), ex); throw new RuntimeException(ex.getMessage()); } catch (Throwable ex) { logger.error("getDocumentContent.error: {}", ex.getMessage(), ex); throw new RuntimeException(ex.getMessage()); } }
@Override public Item getItem(XPathContext context) throws XPathException { if (xml == null) { Properties props = new Properties(); props.setProperty(pn_document_data_format, "XML"); props.setProperty(pn_document_headers, String.valueOf(DocumentAccessor.HDR_CONTENT)); try { DocumentAccessor doc = docMgr.getDocument(docKey, props); if (doc == null) { throw new XPathException("Lost document for key: " + docKey); } xml = doc.getContent(); } catch (BagriException ex) { throw new XPathException(ex); } } StreamSource ss = new StreamSource(new StringReader(xml)); return context.getConfiguration().buildDocumentTree(ss).getRootNode(); }
@Override public Item getItem(XPathContext context) throws XPathException { if (map == null) { Properties props = new Properties(); props.setProperty(pn_document_data_format, "MAP"); props.setProperty(pn_document_headers, String.valueOf(DocumentAccessor.HDR_CONTENT)); try { DocumentAccessor doc = docMgr.getDocument(docKey, props); if (doc == null) { throw new XPathException("Lost document for key: " + docKey); } map = doc.getContent(); } catch (BagriException ex) { throw new XPathException(ex); } } if (map != null) { return new MapItemImpl(map, context.getConfiguration()); } return null; }
props.setProperty(pn_document_data_format, srcFormat); DocumentAccessor doc = docManager.getDocument(key, props); String content = doc.getContent(); if (content == null) { logger.info("storeDocument.exit; got null content for key: {}; uri: {}", key, fullUri);
private String resolveContent(URI uri) throws XPathException { if (content != null) { return content.toString(); } DocumentAccessor doc; try { Object key = resolveUri(uri); Properties props = new Properties(); props.setProperty(pn_document_headers, String.valueOf(DocumentAccessor.HDR_CONTENT)); if (key instanceof Long) { doc = ((DocumentManagement) repo.getDocumentManagement()).getDocument((Long) key, props); } else { doc = repo.getDocumentManagement().getDocument((String) key, props); } // we want to get MAP here, not a String! need access to other parameters in context.. //config.getParseOptions() if (doc == null) { throw new XPathException("cannot resolve document for URI: " + uri); } return doc.getContent(); } catch (UnsupportedEncodingException ex) { throw new XPathException("cannot resolve URI: " + uri, ex); } catch (BagriException ex) { throw new XPathException("cannot resolve document for URI: " + uri, ex); } }
private void runTrigger(Document doc, SchemaRepositoryImpl repo) throws BagriException { XQProcessor xqp = repo.getXQProcessor(); try { Properties props = new Properties(); props.setProperty(pn_document_data_format, df_xml); DocumentAccessor da = repo.getDocumentManagement().getDocument(doc.getUri(), props); org.w3c.dom.Document xDoc = XMLUtils.textToDocument((String) da.getContent()); XQDataFactory xqFactory = xqp.getXQDataFactory(); XQItem item = xqFactory.createItemFromNode(xDoc, xqFactory.createDocumentType()); xqp.bindVariable("doc", item); if (logger.isTraceEnabled()) { Iterator<?> iter = xqp.executeXQuery(query, props); while (iter.hasNext()) { logger.trace("runTrigger; result: {}", iter.next()); } } xqp.unbindVariable("doc"); } catch (IOException ex) { throw new BagriException(ex, BagriException.ecInOut); } catch (XQException ex) { throw new BagriException(ex, BagriException.ecQuery); } }
@Test public void selectSecurityTest() throws Exception { long txId = getTxManagement().beginTransaction(); String fileName = sampleRoot + getFileName("security1500.xml"); String xml = readTextFile(fileName); DocumentAccessor doc = createDocumentTest(fileName); assertNotNull(doc); uris.add(doc.getUri()); assertEquals(txId, doc.getTxStart()); assertEquals(0L, doc.getTxFinish()); getTxManagement().commitTransaction(txId); Properties props = getDocumentProperties(); props.setProperty(pn_document_headers, String.valueOf(DocumentAccessor.HDR_CONTENT)); doc = getDocManagement().getDocument(doc.getUri(), props); assertNotNull(doc); assertNotNull(doc.getContent()); String content = doc.getContent(); assertEquals(xml.length(), content.length()); }
@Override public Sequence call(XPathContext context, Sequence[] arguments) throws XPathException { DocumentAccessor result = null; try { String uri = arguments[0].head().getStringValue(); Properties props = null; if (arguments.length > 1) { props = sequence2Properties(arguments[1]); } result = xdm.getDocument(uri, props); } catch (BagriException ex) { throw new XPathException(ex); } if (result == null) { return EmptySequence.getInstance(); } return new StringValue((String) result.getContent()); } };