@Override public String getMimetype() { if (mimetype == null && format != null) return format.getDefaultMimetype(); return mimetype; } @Override
@Override public String getMimetype() { if (mimetype == null && format != null) return format.getDefaultMimetype(); return mimetype; } @Override
Request.Builder forDocumentResponse(Request.Builder requestBldr, Format format) { return requestBldr.addHeader(HEADER_ACCEPT, (format == Format.BINARY) ? "application/x-unknown-content-type" : format.getDefaultMimetype()); }
private String getMimetypeWithDefaultXML(Format payloadFormat, HandleImplementation baseHandle) { String payloadMimetype = baseHandle.getMimetype(); if (payloadFormat != null) { if (payloadMimetype == null) { payloadMimetype = payloadFormat.getDefaultMimetype(); } } else if (payloadMimetype == null) { payloadMimetype = MIMETYPE_APPLICATION_XML; } return payloadMimetype; }
private void setRdfXmlOrJsonMimetype(TriplesReadHandle handle) { HandleImplementation baseHandle = HandleAccessor.as(handle); if ( baseHandle.getFormat() == Format.JSON ) { if ( Format.JSON.getDefaultMimetype().equals(baseHandle.getMimetype()) ) { baseHandle.setMimetype(RDFMimeTypes.RDFJSON); } } else if ( baseHandle.getFormat() == Format.XML ) { if ( Format.XML.getDefaultMimetype().equals(baseHandle.getMimetype())) { baseHandle.setMimetype(RDFMimeTypes.RDFXML); } } }
@SuppressWarnings("rawtypes") private void checkContentFormat(HandleImplementation contentBase) { if (contentBase == null) return; if (contentFormat != null && contentFormat != Format.UNKNOWN) { Format currFormat = contentBase.getFormat(); if (currFormat != contentFormat) { contentBase.setFormat(contentFormat); if (currFormat != Format.UNKNOWN) contentBase.setMimetype(contentFormat.getDefaultMimetype()); } } } protected RequestParameters mergeTransformParameters(ServerTransform transform, RequestParameters extraParams) {
@SuppressWarnings("rawtypes") private void checkContentFormat(HandleImplementation contentBase) { if (contentBase == null) return; if (contentFormat != null && contentFormat != Format.UNKNOWN) { Format currFormat = contentBase.getFormat(); if (currFormat != contentFormat) { contentBase.setFormat(contentFormat); if (currFormat != Format.UNKNOWN) contentBase.setMimetype(contentFormat.getDefaultMimetype()); } } }
@Override public <T extends StructureReadHandle> T listTransforms(T listHandle, boolean refresh) throws ForbiddenUserException, FailedRequestException { if (listHandle == null) throw new IllegalArgumentException("Reading transform list with null handle"); if (logger.isInfoEnabled()) logger.info("Reading transform list"); HandleImplementation listBase = HandleAccessor.checkHandle(listHandle, "transform"); Format listFormat = listBase.getFormat(); if (!(Format.JSON == listFormat || Format.XML == listFormat)) throw new IllegalArgumentException( "list handle for unsupported format: "+listFormat.getClass().getName()); RequestParameters extraParams = null; if (!refresh) { extraParams = new RequestParameters(); extraParams.put("refresh", "false"); } listBase.receiveContent( services.getValues(requestLogger, "config/transforms", extraParams, listFormat.getDefaultMimetype(), listBase.receiveAs()) ); return listHandle; }
static protected boolean checkNull(MimeMultipart multipart, Format format) { if (multipart != null) { try { if (multipart.getCount() != 0) { BodyPart firstPart = multipart.getBodyPart(0); String actualType = (firstPart == null) ? null : firstPart.getContentType(); String defaultType = (format == Format.BINARY) ? "application/x-unknown-content-type" : format.getDefaultMimetype(); if (actualType == null || !actualType.startsWith(defaultType)) { throw new RuntimeException( "Returned document as "+actualType+" instead of "+defaultType ); } return false; } } catch (MessagingException e) { new MarkLogicIOException(e); } } return true; }
@SuppressWarnings("rawtypes") @Override public <T extends RuleListReadHandle> T match(StructureWriteHandle document, String[] candidateRules, T ruleListHandle, ServerTransform transform) { HandleImplementation searchBase = HandleAccessor.checkHandle(document, "match"); Format searchFormat = searchBase.getFormat(); switch(searchFormat) { case UNKNOWN: searchFormat = Format.XML; break; case JSON: case XML: break; default: throw new UnsupportedOperationException("Only XML and JSON queries can filter for rule matches."); } String mimeType = searchFormat.getDefaultMimetype(); HandleAccessor.receiveContent(ruleListHandle, services.match(document, candidateRules, mimeType, transform)); return ruleListHandle; }
@SuppressWarnings({ "unchecked", "rawtypes" }) @Override public <T extends QueryOptionsListReadHandle> T optionsList(T optionsHandle) throws ForbiddenUserException, FailedRequestException { HandleImplementation optionsBase = HandleAccessor.checkHandle(optionsHandle, "optionslist"); Format optionsFormat = optionsBase.getFormat(); switch(optionsFormat) { case UNKNOWN: optionsFormat = Format.XML; break; case JSON: case XML: break; default: throw new UnsupportedOperationException("Only XML and JSON options list results are possible."); } String mimetype = optionsFormat.getDefaultMimetype(); optionsBase.receiveContent(services.optionsList(optionsBase.receiveAs(), mimetype, null)); return optionsHandle; } }
@SuppressWarnings({ "unchecked", "rawtypes" }) @Override public <T extends QueryOptionsListReadHandle> T optionsList(T optionsHandle) throws ForbiddenUserException, FailedRequestException { HandleImplementation optionsBase = HandleAccessor.checkHandle(optionsHandle, "optionslist"); Format optionsFormat = optionsBase.getFormat(); switch(optionsFormat) { case UNKNOWN: optionsFormat = Format.XML; break; case JSON: case XML: break; default: throw new UnsupportedOperationException("Only XML and JSON options list results are possible."); } String mimetype = optionsFormat.getDefaultMimetype(); optionsBase.receiveContent(services.optionsList(optionsBase.receiveAs(), mimetype, null)); return optionsHandle; } }
@SuppressWarnings("unchecked") @Override public <T extends ValuesListReadHandle> T valuesList(ValuesListDefinition valdef, T valuesHandle, Transaction transaction) { @SuppressWarnings("rawtypes") HandleImplementation valuesBase = HandleAccessor.checkHandle(valuesHandle, "valueslist"); Format valuesFormat = valuesBase.getFormat(); switch(valuesFormat) { case UNKNOWN: valuesFormat = Format.XML; break; case JSON: case XML: break; default: throw new UnsupportedOperationException("Only XML and JSON values list results are possible."); } String mimetype = valuesFormat.getDefaultMimetype(); String tid = transaction == null ? null : transaction.getTransactionId(); valuesBase.receiveContent(services.valuesList(valuesBase.receiveAs(), valdef, mimetype, tid)); return valuesHandle; }
@Test public void testExecuteDescribeWithXMLNotMime() { HandleImplementation triplesHandle = executeSetRdfXmlOrJsonMimetype(Format.XML, Format.TEXT.getDefaultMimetype()); assertFalse(triplesHandle.getMimetype().equals(RDFMimeTypes.RDFXML)); assertTrue(triplesHandle.getMimetype().equals(Format.TEXT.getDefaultMimetype())); }
@SuppressWarnings("unchecked") @Override public <T extends ValuesListReadHandle> T valuesList(ValuesListDefinition valdef, T valuesHandle, Transaction transaction) { @SuppressWarnings("rawtypes") HandleImplementation valuesBase = HandleAccessor.checkHandle(valuesHandle, "valueslist"); Format valuesFormat = valuesBase.getFormat(); switch(valuesFormat) { case UNKNOWN: valuesFormat = Format.XML; break; case JSON: case XML: break; default: throw new UnsupportedOperationException("Only XML and JSON values list results are possible."); } String mimetype = valuesFormat.getDefaultMimetype(); String tid = transaction == null ? null : transaction.getTransactionId(); valuesBase.receiveContent(services.valuesList(valuesBase.receiveAs(), valdef, mimetype, transaction)); return valuesHandle; }
@Test public void testExecuteDescribeWithJSONNotMime() { HandleImplementation triplesHandle = executeSetRdfXmlOrJsonMimetype(Format.JSON, Format.TEXT.getDefaultMimetype()); assertFalse(triplesHandle.getMimetype().equals(RDFMimeTypes.RDFJSON)); assertTrue(triplesHandle.getMimetype().equals(Format.TEXT.getDefaultMimetype())); }
@SuppressWarnings("unchecked") @Override public <T extends QueryOptionsListReadHandle> T optionsList(T optionsHandle, Transaction transaction) { @SuppressWarnings("rawtypes") HandleImplementation optionsBase = HandleAccessor.checkHandle(optionsHandle, "optionslist"); Format optionsFormat = optionsBase.getFormat(); switch(optionsFormat) { case UNKNOWN: optionsFormat = Format.XML; break; case JSON: case XML: break; default: throw new UnsupportedOperationException("Only XML and JSON options list results are possible."); } String mimetype = optionsFormat.getDefaultMimetype(); String tid = transaction == null ? null : transaction.getTransactionId(); optionsBase.receiveContent(services.optionsList(optionsBase.receiveAs(), mimetype, tid)); return optionsHandle; }
/** * Test of executeDescribe method, of class SPARQLQueryManagerImpl. */ @Test public void testExecuteDescribeWithJSON() { HandleImplementation triplesHandle = executeSetRdfXmlOrJsonMimetype(Format.JSON, Format.JSON.getDefaultMimetype()); assertTrue(triplesHandle.getMimetype().equals(RDFMimeTypes.RDFJSON)); }
@Test public void testExecuteDescribeWithXML() { HandleImplementation triplesHandle = executeSetRdfXmlOrJsonMimetype(Format.XML, Format.XML.getDefaultMimetype()); assertTrue(triplesHandle.getMimetype().equals(RDFMimeTypes.RDFXML)); }
@Test public void testExecuteDescribeWithUNKNOWNFormat() { HandleImplementation triplesHandle = executeSetRdfXmlOrJsonMimetype(Format.UNKNOWN, Format.JSON.getDefaultMimetype()); assertFalse(triplesHandle.getMimetype().equals(RDFMimeTypes.RDFJSON)); }