@SuppressWarnings("rawtypes") private String validateGraphsMimetype(HandleImplementation baseHandle) { String mimetype = baseHandle.getMimetype(); if ( mimetype == null ) { if ( defaultMimetype != null ) { baseHandle.setMimetype(defaultMimetype); } else { throw new IllegalArgumentException("You must either call setMimetype on your " + "handle or setDefaultMimetype on your GraphManager instance with a mimetype " + "from RDFMimeTypes"); } } return mimetype; }
@Override public <T extends TriplesReadHandle> T read(String uri, T handle, Transaction transaction) { @SuppressWarnings("rawtypes") HandleImplementation baseHandle = HandleAccessor.as(handle); String mimetype = baseHandle.getMimetype(); if ( mimetype == null ) baseHandle.setMimetype(defaultMimetype); services.readGraph(requestLogger, uri, handle, transaction); baseHandle.setMimetype(mimetype); return handle; }
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); } } }
@Override public void write(String uri, TriplesWriteHandle handle, GraphPermissions permissions, Transaction transaction) { @SuppressWarnings("rawtypes") HandleImplementation baseHandle = HandleAccessor.as(handle); String mimetype = validateGraphsMimetype(baseHandle); services.writeGraph(requestLogger, uri, handle, permissions, transaction); baseHandle.setMimetype(mimetype); }
@Override public void merge(String uri, TriplesWriteHandle handle, GraphPermissions permissions, Transaction transaction) { @SuppressWarnings("rawtypes") HandleImplementation baseHandle = HandleAccessor.as(handle); String mimetype = validateGraphsMimetype(baseHandle); services.mergeGraph(requestLogger, uri, handle, permissions, transaction); baseHandle.setMimetype(mimetype); }
@Override public void mergeGraphs(QuadsWriteHandle handle, Transaction transaction) { @SuppressWarnings("rawtypes") HandleImplementation baseHandle = HandleAccessor.as(handle); String mimetype = validateGraphsMimetype(baseHandle); services.mergeGraphs(requestLogger, handle, transaction); baseHandle.setMimetype(mimetype); }
@Override public void replaceGraphs(QuadsWriteHandle handle, Transaction transaction) { @SuppressWarnings("rawtypes") HandleImplementation baseHandle = HandleAccessor.as(handle); String mimetype = validateGraphsMimetype(baseHandle); services.writeGraphs(requestLogger, handle, transaction); baseHandle.setMimetype(mimetype); }
@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()); } } }
@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) {
private void writeTransform( String transformName, String sourceMimetype, AbstractWriteHandle sourceHandle, ExtensionMetadata metadata) throws ResourceNotFoundException, ResourceNotResendableException, ForbiddenUserException, FailedRequestException { if (transformName == null) throw new IllegalArgumentException("Writing transform with null name"); if (sourceHandle == null) throw new IllegalArgumentException("Writing transform source with null handle"); if (logger.isInfoEnabled()) logger.info("Writing transform source for {}", transformName); HandleImplementation sourceBase = HandleAccessor.checkHandle(sourceHandle, "transform"); Format sourceFormat = sourceBase.getFormat(); if ("application/xquery".equals(sourceMimetype)) { if (Format.TEXT != sourceFormat) sourceBase.setFormat(Format.TEXT); } else if ("application/xslt+xml".equals(sourceMimetype)) { if (Format.XML != sourceFormat) sourceBase.setFormat(Format.XML); } else if ("application/javascript".equals(sourceMimetype)) { if (Format.JSON != sourceFormat) sourceBase.setFormat(Format.JSON); } else { throw new MarkLogicInternalException( "Unsupported mimetype for source: "+sourceMimetype); } if (!sourceMimetype.equals(sourceBase.getMimetype())) sourceBase.setMimetype(sourceMimetype); RequestParameters extraParams = (metadata != null) ? metadata.asParameters() : null; services.putValue(requestLogger, "config/transforms", transformName, extraParams, sourceMimetype, sourceBase); }
sourceBase.setMimetype(sourceMimetype);
private void copyDescriptor(DocumentDescriptor desc, HandleImplementation handleBase) { if (handleBase == null) return; handleBase.setFormat(desc.getFormat()); handleBase.setMimetype(desc.getMimetype()); handleBase.setByteLength(desc.getByteLength()); }
private void copyDescriptor(DocumentDescriptor desc, HandleImplementation handleBase) { if (handleBase == null) return; if (desc.getFormat() != null) handleBase.setFormat(desc.getFormat()); if (desc.getMimetype() != null) handleBase.setMimetype(desc.getMimetype()); handleBase.setByteLength(desc.getByteLength()); }
private HandleImplementation executeSetRdfXmlOrJsonMimetype(Format format, String mimeType) { HandleImplementation triplesHandle = new HandleImplementationTester(); triplesHandle.setFormat(format); triplesHandle.setMimetype(mimeType); RESTServices services = mock(RESTServices.class); SPARQLQueryManagerImpl sparqlQueryManager = new SPARQLQueryManagerImpl(services); SPARQLQueryDefinition qdef = new SPARQLQueryDefinitionImpl(); sparqlQueryManager.executeDescribe(qdef, (TriplesReadHandle) triplesHandle); return triplesHandle; }