@Test(expected = IOException.class) public void testBadInputFormat() throws IOException { HTTPHeaders h = new HTTPHeaders(); h.putValue(HTTPHeader.CONTENT_TYPE, MimeType.PNG); h.putValue(HTTPHeader.ACCEPT, MimeType.PNG); new Ditaa().generate(new Request( URI.create("/ditaa"), h, DITAA_INPUT.getBytes(Charset.forName("UTF-8")) )); }
@Override public ResponseData generate(Request request) throws IOException { MimeType format = request.headers.getValue(HTTPHeader.ACCEPT); if (format == null) { format = DEFAULT_OUTPUT_FORMAT; } if (!format.equals(MimeType.PNG) && !format.equals(MimeType.SVG)) { throw new IOException("Unsupported output format: " + format); } MimeType contentType = request.headers.getValue(HTTPHeader.CONTENT_TYPE); if (contentType == null) { contentType = DEFAULT_CONTENT_TYPE; } String charset = contentType.parameters.get("charset"); if (charset == null) { charset = DEFAULT_CHARSET; } java.util.List<String> options = new ArrayList(); options.add("--encoding"); options.add(charset); if (format.equals(MimeType.SVG)) { options.add("--svg"); } String optionString = request.headers.getValue(HTTPHeader.OPTIONS); if (optionString != null) { options.addAll(Arrays.asList(optionString.split(" "))); } ConversionOptions conversionOptions = ConversionOptions.parseCommandLineOptions(options.toArray(new String[0])); ByteArrayInputStream input = new ByteArrayInputStream(request.data); ByteArrayOutputStream output = new ByteArrayOutputStream(); doConvert(input, output, conversionOptions); output.close(); return new ResponseData( format, output.toByteArray() ); }
Ditaa implements DiagramGenerator { @Override public ResponseData generate(Request request) throws IOException { MimeType format = request.headers.getValue(HTTPHeader.ACCEPT); if (format == null) { format = DEFAULT_OUTPUT_FORMAT; } if (!format.equals(MimeType.PNG) && !format.equals(MimeType.SVG)) { throw new IOException("Unsupported output format: " + format); } MimeType contentType = request.headers.getValue(HTTPHeader.CONTENT_TYPE); if (contentType == null) { contentType = DEFAULT_CONTENT_TYPE; } String charset = contentType.parameters.get("charset"); if (charset == null) { charset = DEFAULT_CHARSET; } java.util.List<String> options = new ArrayList(); options.add("--encoding"); options.add(charset); if (format.equals(MimeType.SVG)) { options.add("--svg"); } String optionString = request.headers.getValue(HTTPHeader.OPTIONS); if (optionString != null) { options.addAll(Arrays.asList(optionString.split(" "))); } ConversionOptions conversionOptions = ConversionOptions.parseCommandLineOptions(options.toArray(new String[0])); ByteArrayInputStream input = new ByteArrayInputStream(request.data); ByteArrayOutputStream output = new ByteArrayOutputStream(); doConvert(input, output, conversionOptions); output.close(); return new ResponseData( format, output.toByteArray() ); } }
Ditaa implements DiagramGenerator { @Override public ResponseData generate(Request request) throws IOException { MimeType format = request.headers.getValue(HTTPHeader.ACCEPT); if (format == null) { format = DEFAULT_OUTPUT_FORMAT; } if (!format.equals(MimeType.PNG) && !format.equals(MimeType.SVG)) { throw new IOException("Unsupported output format: " + format); } MimeType contentType = request.headers.getValue(HTTPHeader.CONTENT_TYPE); if (contentType == null) { contentType = DEFAULT_CONTENT_TYPE; } String charset = contentType.parameters.get("charset"); if (charset == null) { charset = DEFAULT_CHARSET; } java.util.List<String> options = new ArrayList(); options.add("--encoding"); options.add(charset); if (format.equals(MimeType.SVG)) { options.add("--svg"); } String optionString = request.headers.getValue(HTTPHeader.OPTIONS); if (optionString != null) { options.addAll(Arrays.asList(optionString.split(" "))); } ConversionOptions conversionOptions = ConversionOptions.parseCommandLineOptions(options.toArray(new String[0])); ByteArrayInputStream input = new ByteArrayInputStream(request.data); ByteArrayOutputStream output = new ByteArrayOutputStream(); doConvert(input, output, conversionOptions); output.close(); return new ResponseData( format, output.toByteArray() ); }  }
Ditaa implements DiagramGenerator { @Override public ResponseData generate(Request request) throws IOException { MimeType format = request.headers.getValue(HTTPHeader.ACCEPT); if (format == null) { format = DEFAULT_OUTPUT_FORMAT; } if (!format.equals(MimeType.PNG) && !format.equals(MimeType.SVG)) { throw new IOException("Unsupported output format: " + format); } MimeType contentType = request.headers.getValue(HTTPHeader.CONTENT_TYPE); if (contentType == null) { contentType = DEFAULT_CONTENT_TYPE; } String charset = contentType.parameters.get("charset"); if (charset == null) { charset = DEFAULT_CHARSET; } java.util.List<String> options = new ArrayList(); options.add("--encoding"); options.add(charset); if (format.equals(MimeType.SVG)) { options.add("--svg"); } String optionString = request.headers.getValue(HTTPHeader.OPTIONS); if (optionString != null) { options.addAll(Arrays.asList(optionString.split(" "))); } ConversionOptions conversionOptions = ConversionOptions.parseCommandLineOptions(options.toArray(new String[0])); ByteArrayInputStream input = new ByteArrayInputStream(request.data); ByteArrayOutputStream output = new ByteArrayOutputStream(); doConvert(input, output, conversionOptions); output.close(); return new ResponseData( format, output.toByteArray() ); }  @Override String getName(); @Override ResponseData generate(Request request); }
Ditaa implements DiagramGenerator { @Override public ResponseData generate(Request request) throws IOException { MimeType format = request.headers.getValue(HTTPHeader.ACCEPT); if (format == null) { format = DEFAULT_OUTPUT_FORMAT; } if (!format.equals(MimeType.PNG) && !format.equals(MimeType.SVG)) { throw new IOException("Unsupported output format: " + format); } MimeType contentType = request.headers.getValue(HTTPHeader.CONTENT_TYPE); if (contentType == null) { contentType = DEFAULT_CONTENT_TYPE; } String charset = contentType.parameters.get("charset"); if (charset == null) { charset = DEFAULT_CHARSET; } java.util.List<String> options = new ArrayList(); options.add("--encoding"); options.add(charset); if (format.equals(MimeType.SVG)) { options.add("--svg"); } String optionString = request.headers.getValue(HTTPHeader.OPTIONS); if (optionString != null) { options.addAll(Arrays.asList(optionString.split(" "))); } ConversionOptions conversionOptions = ConversionOptions.parseCommandLineOptions(options.toArray(new String[0])); ByteArrayInputStream input = new ByteArrayInputStream(request.data); ByteArrayOutputStream output = new ByteArrayOutputStream(); doConvert(input, output, conversionOptions); output.close(); return new ResponseData( format, output.toByteArray() ); }  @Override String getName(); @Override ResponseData generate(Request request); static final MimeType DEFAULT_OUTPUT_FORMAT; static final MimeType DEFAULT_CONTENT_TYPE; static final String DEFAULT_CHARSET; }