static public DOMHandle DocumentToHandle(Document value) { return (value == null) ? null : new DOMHandle(value); } static public Stream<DOMHandle> DocumentToHandle(Stream<? extends Document> values) {
@Override public <C> ContentHandle<C> newHandle(Class<C> type) { @SuppressWarnings("unchecked") ContentHandle<C> handle = isHandled(type) ? (ContentHandle<C>) new DOMHandle() : null; return handle; } };
@Override public <C> ContentHandle<C> newHandle(Class<C> type) { @SuppressWarnings("unchecked") ContentHandle<C> handle = isHandled(type) ? (ContentHandle<C>) new DOMHandle() : null; return handle; } };
@Override public Document getRelevanceInfo() { DOMHandle handle = getRelevanceInfo(new DOMHandle()); return (handle == null) ? null : handle.get(); } @Override
@SuppressWarnings("unchecked") @Override public String[] suggest(SuggestDefinition suggestDef) { DOMHandle handle = new DOMHandle(); @SuppressWarnings("rawtypes") HandleImplementation suggestBase = HandleAccessor.checkHandle(handle, "suggest"); suggestBase.receiveContent(services.suggest(suggestBase.receiveAs(), suggestDef)); Document doc = handle.get(); NodeList nodeList = doc.getDocumentElement().getChildNodes(); List<String> suggestions = new ArrayList<String>(); for (int i=0; i <nodeList.getLength(); i++) { suggestions.add(nodeList.item(i).getTextContent()); } return suggestions.toArray(new String[suggestions.size()]); }
@Override public Document getRelevanceInfo() { DOMHandle handle = getRelevanceInfo(new DOMHandle()); return (handle == null) ? null : handle.get(); } @Override
/** * Returns the query plan associated with this search. * * <p>Query plans are highly variable.</p> * @return the plan as a DOM Document */ @Override public Document getPlan() { DOMHandle handle = getPlan(new DOMHandle()); return (handle == null) ? null : handle.get(); } @Override
@Override public Document getMetadata() { DOMHandle handle = getMetadata(new DOMHandle()); return (handle == null) ? null : handle.get(); } @Override
protected void receiveContent(InputStream content) { rules = new ArrayList<RuleDefinition>(); DOMHandle domHandle = new DOMHandle(); HandleAccessor.receiveContent(domHandle, content); Document document = domHandle.get(); NodeList ruleNodes = document.getElementsByTagNameNS(RequestConstants.RESTAPI_NS, "rule"); for (int i=0; i < ruleNodes.getLength(); i++) { Element ruleElement = (Element) ruleNodes.item(i); RuleDefinition ruleDefinition = new RuleDefinition(); ruleDefinition.receiveElement(ruleElement); rules.add(ruleDefinition); } } }
/** * Returns the query plan associated with this search. * * <p>Query plans are highly variable.</p> * @return the plan as a DOM Document */ @Override public Document getPlan() { DOMHandle handle = getPlan(new DOMHandle()); return (handle == null) ? null : handle.get(); } @Override
@Override public Document getMetadata() { DOMHandle handle = getMetadata(new DOMHandle()); return (handle == null) ? null : handle.get(); } @Override
protected void receiveContent(InputStream content) { DOMHandle handle = new DOMHandle(); HandleAccessor.receiveContent(handle, content); Element ruleElement = handle.get().getDocumentElement(); receiveElement(ruleElement); }
@Override protected void receiveContent(InputStream content) { DOMHandle handle = new DOMHandle(); HandleAccessor.receiveContent(handle, content); Element ruleElement = handle.get().getDocumentElement(); receiveElement(ruleElement); }
@Override public void write(List<? extends Document> items) throws Exception { XMLDocumentManager docMgr = client.newXMLDocumentManager(); for (Document doc : items) { DOMHandle handle = new DOMHandle(doc); docMgr.write(doc.getDocumentURI(), handle); } }
public static void writeDoc() throws Exception { Document domDocument = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); Element root = domDocument.createElement("root"); root.setAttribute("xml:lang", "en"); root.setAttribute("foo", "bar"); root.appendChild(domDocument.createElement("child")); root.appendChild(domDocument.createTextNode("mixed")); domDocument.appendChild(root); @SuppressWarnings("unused") String domString = ((DOMImplementationLS) DocumentBuilderFactory.newInstance().newDocumentBuilder() .getDOMImplementation()).createLSSerializer().writeToString(domDocument); XMLDocumentManager docMgr = client.newXMLDocumentManager(); docMgr.write(docId, new DOMHandle().with(domDocument)); }
public Message process(Message message) throws Exception { String uri = (String) message.getBody().get("uri"); Document xmlBody = (Document) message.getBody().get("content"); // do processing and validation batcher.add(uri, new DOMHandle(xmlBody)); return message; }
@Test public void testPostDocumentWithoutFormat() throws SAXException, IOException { StringHandle stringHandle = new StringHandle("<search xmlns=\"http://marklogic.com/appservices/search\"><qtext>true</qtext></search>"); DOMHandle answer = ruleManager.match(stringHandle, new DOMHandle()); Document doc = answer.get(); NodeList nl = doc.getElementsByTagNameNS( "http://marklogic.com/rest-api", "name"); assertEquals(2, nl.getLength()); }
@Test public void testRuleMatchTransform() { StructuredQueryBuilder qb = new StructuredQueryBuilder(); StructuredQueryDefinition structuredQuery; structuredQuery = qb.rangeConstraint("favorited", Operator.EQ, "true"); ServerTransform transform = new ServerTransform("ruleTransform"); DOMHandle answer = ruleManager.match(structuredQuery, 0L, QueryManager.DEFAULT_PAGE_LENGTH, new String[] {}, new DOMHandle(), transform); Document doc = answer.get(); NodeList nl = doc.getElementsByTagNameNS( "", "transformed-name"); assertEquals(2, nl.getLength()); }
protected Document getModulesDocument(String uri) { return modMgr.read(uri).next().getContent(new DOMHandle()).get(); }
@Test /** Avoid regression on https://github.com/marklogic/java-client-api/issues/761 */ public void test_issue_761() { DatabaseClient client = Common.newClient("Documents"); try { client.newServerConfigManager().newResourceExtensionsManager() .listServices(new DOMHandle()); } finally { client.release(); } }