/** * Returns the default mime type for the format. * @return the default mime type */ public String getDefaultMimetype() { switch(this) { case UNKNOWN: return null; case BINARY: // TODO: or possibly "application/x-unknown-content-type" return "application/octet-stream"; case JSON: return "application/json"; case TEXT: return "text/plain"; case XML: return "application/xml"; default: throw new MarkLogicInternalException("Unknown format "+this.toString()); } }
@SuppressWarnings("rawtypes") static private void setHandleStructuredFormat(BaseHandle handle, Format format) { if (format != Format.JSON && format != Format.XML) { throw new IllegalArgumentException("Received "+format.name()+" format instead of JSON or XML"); } handle.setFormat(format); } }
DocumentFormat xccFormat = null; if (format != null) { if (Format.BINARY.equals(format)) { xccFormat = DocumentFormat.BINARY; } else if (Format.JSON.equals(format)) { xccFormat = DocumentFormat.JSON; } else if (Format.TEXT.equals(format)) { xccFormat = DocumentFormat.TEXT; } else if (Format.XML.equals(format)) { xccFormat = DocumentFormat.XML; } else if (Format.UNKNOWN.equals(format)) { xccFormat = DocumentFormat.NONE; } else if (logger.isDebugEnabled()) { logger.debug("Unsupported format, can't adapt to an XCC DocumentFormat; " + format.toString());
private Format getHeaderFormat(BodyPart part) { String contentDisposition = getHeader(part, HEADER_CONTENT_DISPOSITION); String formatRegex = ".* format=(text|binary|xml|json).*"; String format = getHeader(part, HEADER_VND_MARKLOGIC_DOCUMENT_FORMAT); String contentType = getHeader(part, HEADER_CONTENT_TYPE); if ( format != null && format.length() > 0 ) { return Format.valueOf(format.toUpperCase()); } else if ( contentDisposition != null && contentDisposition.matches(formatRegex) ) { format = contentDisposition.replaceFirst("^.*" + formatRegex + ".*$", "$1"); return Format.valueOf(format.toUpperCase()); } else if ( contentType != null && contentType.length() > 0 ) { return Format.getFromMimetype(contentType); } return null; }
@Override public String getMimetype() { if (mimetype == null && format != null) return format.getDefaultMimetype(); return mimetype; } @Override
else if (payloadFormat != Format.XML && payloadFormat != Format.JSON) throw new IllegalArgumentException( "Cannot perform raw search for "+payloadFormat.name()); payloadMimetype = payloadFormat.getDefaultMimetype(); params.add("format", payloadFormat.toString().toLowerCase()); } else if (payloadMimetype == null) { payloadMimetype = "application/xml";
@Override public String generateOutput(DocumentRecord documentRecord) { if (Format.XML.equals(documentRecord.getFormat())) { DOMHandle handle = documentRecord.getContent(new DOMHandle()); Document document = handle.get(); OutputFormat format = new OutputFormat(handle.get()); format.setOmitXMLDeclaration(omitXmlDeclaration); StringWriter writer = new StringWriter(); try { new XMLSerializer(writer, format).serialize(document); return writer.toString(); } catch (IOException e) { throw new RuntimeException("Unable to serialize XML document to string: " + e.getMessage(), e); } } else if (logger.isDebugEnabled()) { logger.debug(String.format("Document '%s' has a format of '%s', so will not attempt to remove the XML declaration from it", documentRecord.getUri(), documentRecord.getFormat().name())); } return documentRecord.getContent(new StringHandle()).get(); }
private Format getHeaderFormat(MultivaluedMap<String, String> headers) { if (headers.containsKey("vnd.marklogic.document-format")) { List<String> values = headers.get("vnd.marklogic.document-format"); if (values != null) { return Format.valueOf(values.get(0).toUpperCase()); } } return null; }
@Override public String getMimetype() { if (mimetype == null && format != null) return format.getDefaultMimetype(); return mimetype; } @Override
private Format getHeaderFormat(Headers headers) { String format = headers.get(HEADER_VND_MARKLOGIC_DOCUMENT_FORMAT); if (format != null) { return Format.valueOf(format.toUpperCase()); } return null; }
private Format getStructuredQueryFormat(HandleImplementation baseHandle) { Format payloadFormat = baseHandle.getFormat(); if (payloadFormat == Format.UNKNOWN) { payloadFormat = null; } else if (payloadFormat != Format.XML && payloadFormat != Format.JSON) { throw new IllegalArgumentException( "Cannot perform raw search for format "+payloadFormat.name()); } return payloadFormat; }
Request.Builder forDocumentResponse(Request.Builder requestBldr, Format format) { return requestBldr.addHeader(HEADER_ACCEPT, (format == Format.BINARY) ? "application/x-unknown-content-type" : format.getDefaultMimetype()); }
/** * Returns the default mime type for the format. * @return the default mime type */ public String getDefaultMimetype() { switch(this) { case UNKNOWN: return null; case BINARY: // TODO: or possibly "application/x-unknown-content-type" return "application/octet-stream"; case JSON: return "application/json"; case TEXT: return "text/plain"; case XML: return "application/xml"; default: throw new MarkLogicInternalException("Unknown format "+this.toString()); } } }
for ( DocumentRecord doc : docs ) { Format format = doc.getFormat(); if ( Format.BINARY.equals(format) ) { throw new IllegalStateException("Document " + doc.getUri() + " is binary and cannot be written. Change your query to not select any binary documents.");
reader.getElementText().toUpperCase().replace("-", "_")); } else if ("error-format".equals(localName)) { errorFormat = Format.valueOf(reader.getElementText().toUpperCase());
@SuppressWarnings("rawtypes") static private void setHandleStructuredFormat(BaseHandle handle, Format format) { if (format != Format.JSON && format != Format.XML) { throw new IllegalArgumentException("Received "+format.name()+" format instead of JSON or XML"); } handle.setFormat(format); }
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; }
String metadataMimetype = null; if (metadataBase != null) { metadataFormat = metadataBase.getFormat().toString().toLowerCase(); metadataMimetype = metadataBase.getMimetype();