public boolean isCorrect(String word, String... uris) { try { RequestParameters params = new RequestParameters(); params.add("service", "is-correct"); params.add("word", word); params.add("uris", uris); XMLStreamReaderHandle readHandle = new XMLStreamReaderHandle(); // call the service getServices().get(params, readHandle); QName correctName = new QName(XMLConstants.DEFAULT_NS_PREFIX, "correct"); XMLStreamReader streamReader = readHandle.get(); while (streamReader.hasNext()) { int current = streamReader.next(); if (current == XMLStreamReader.START_ELEMENT) { if (correctName.equals(streamReader.getName())) { return "true".equals(streamReader.getElementText()); } } } return false; } catch (XMLStreamException ex) { throw new RuntimeException(ex); } }
public Document[] checkDictionaries(String... uris) { RequestParameters params = new RequestParameters(); params.add("service", "check-dictionary"); params.add("uris", uris); // specify the mime type for each expected document returned String[] mimetypes = new String[uris.length]; for (int i = 0; i < uris.length; i++) { mimetypes[i] = "application/xml"; } // call the service ServiceResultIterator resultItr = getServices().get(params, mimetypes); // iterate over the results List<Document> documents = new ArrayList<Document>(); DOMHandle readHandle = new DOMHandle(); while (resultItr.hasNext()) { ServiceResult result = resultItr.next(); // get the result content result.getContent(readHandle); documents.add(readHandle.get()); } // release the iterator resources resultItr.close(); return documents.toArray(new Document[documents.size()]); }
protected RequestParameters getWriteParams() { if (metadataExtraction == null || metadataExtraction == MetadataExtraction.NONE) return null; RequestParameters params = new RequestParameters(); if (metadataExtraction == MetadataExtraction.PROPERTIES) params.put("extract", "properties"); else if (metadataExtraction == MetadataExtraction.DOCUMENT) params.put("extract", "document"); else throw new MarkLogicInternalException( "Internal error - unknown metadata extraction policy: " + metadataExtraction.name()); return params; }
@Override public <T extends BinaryReadHandle> T read( DocumentDescriptor desc, DocumentMetadataReadHandle metadataHandle, T contentHandle, ServerTransform transform, long start, long length, Transaction transaction) { if (logger.isInfoEnabled()) logger.info("Reading range of binary content for {}", desc.getUri()); RequestParameters extraParams = new RequestParameters(); if (length > 0) extraParams.put("range", "bytes=" + start + "-" + (start + length - 1)); else extraParams.put("range", "bytes=" + String.valueOf(start)); return read(desc, metadataHandle, contentHandle, transform, transaction, null, extraParams); }
public String[] suggest( String word, Integer maximum, Integer distanceThreshold, String... uris) { try { RequestParameters params = new RequestParameters(); params.add("service", "suggest-detailed"); params.add("word", word); params.add("uris", uris); if (maximum != null) params.add("maximum", String.valueOf(maximum)); if (distanceThreshold != null) params.add("distance-threshold", String.valueOf(distanceThreshold)); XMLStreamReaderHandle readHandle = new XMLStreamReaderHandle(); // call the service getServices().get(params, readHandle); XMLStreamReader streamReader = readHandle.get(); QName wordName = new QName("http://marklogic.com/xdmp/spell", "word"); ArrayList<String> words = new ArrayList<String>(); while (streamReader.hasNext()) { int current = streamReader.next(); if (current == XMLStreamReader.START_ELEMENT) { if (wordName.equals(streamReader.getName())) { words.add(streamReader.getElementText()); } } } return words.toArray(new String[words.size()]); } catch (XMLStreamException ex) { throw new RuntimeException(ex); } }