@Override public boolean equals(Object other) { if (this == other) return true; if (other == null || getClass() != other.getClass()) return false; ConversionPath conversionPath = (ConversionPath) other; return sourceFormat.equals(conversionPath.sourceFormat) && targetFormat.equals(conversionPath.targetFormat); }
public AdaptedDocumentType(DocumentType original) { type = original.getType(); subtype = original.getSubtype(); }
private static Map<ConversionPath, IExternalConverter> resolve(IExternalConverter externalConverter) { boolean viableConversionPresent = externalConverter.getClass().isAnnotationPresent(ViableConversion.class); boolean viableConversionsPresent = externalConverter.getClass().isAnnotationPresent(ViableConversions.class); checkState(viableConversionPresent ^ viableConversionsPresent, externalConverter + " must be annotated with " + "exactly one of @ViableConversion or @ViableConversions"); ViableConversion[] viableConversions = viableConversionPresent ? new ViableConversion[]{externalConverter.getClass().getAnnotation(ViableConversion.class)} : externalConverter.getClass().getAnnotation(ViableConversions.class).value(); Map<ConversionPath, IExternalConverter> conversionMapping = new HashMap<ConversionPath, IExternalConverter>(); for (ViableConversion viableConversion : viableConversions) { for (String sourceFormat : viableConversion.from()) { for (String targetFormat : viableConversion.to()) { conversionMapping.put(new ConversionPath(new DocumentType(sourceFormat), new DocumentType(targetFormat)), externalConverter); } } } return conversionMapping; }
@Override public DocumentType unmarshal(AdaptedDocumentType adapted) throws Exception { return new DocumentType(adapted.getType(), adapted.getSubtype()); }
public static MicrosoftOfficeFormat of(DocumentType documentType) { for (MicrosoftWordFormat enumeration : MicrosoftWordFormat.values()) { if (enumeration.documentType.equals(documentType)) { return enumeration; } } throw new IllegalArgumentException("Unknown document type: " + documentType); }
@Override public void onComplete(InputStream inputStream) { if (asyncResponse.isDone()) { return; } synchronized (answerLock) { if (asyncResponse.isDone()) { return; } LOGGER.info("Sending successful response for {}", asyncResponse); asyncResponse.resume(Response .status(ConverterNetworkProtocol.Status.OK.getStatusCode()) .entity(inputStream) .type(targetType.toString()) .build()); } }
@POST public void convert( InputStream inputStream, @Suspended AsyncResponse asyncResponse, @HeaderParam(HttpHeaders.CONTENT_TYPE) String inputType, @HeaderParam(HttpHeaders.ACCEPT) String responseType, @DefaultValue("" + IConverter.JOB_PRIORITY_NORMAL) @HeaderParam(ConverterNetworkProtocol.HEADER_JOB_PRIORITY) int priority) { DocumentType targetType = new DocumentType(responseType); // The received input stream does not need to be closed since the underlying channel is automatically closed with responding. // If the stream was closed manually, this would in contrast lead to a NullPointerException since the channel was already detached. webConverterConfiguration.getConverter() .convert(inputStream, false).as(new DocumentType(inputType)) .to(AsynchronousConversionResponse.to(asyncResponse, targetType, webConverterConfiguration.getTimeout())).as(targetType) .prioritizeWith(priority) .schedule(); } }
public static MicrosoftExcelFormat of(DocumentType documentType) { for (MicrosoftExcelFormat enumeration : MicrosoftExcelFormat.values()) { if (enumeration.documentType.equals(documentType)) { return enumeration; } } throw new IllegalArgumentException("Unknown document type: " + documentType); }
@Override protected RemoteConversionContext startConversion(InputStream fetchedSource) { return new RemoteConversionContext(webTarget .path(ConverterNetworkProtocol.RESOURCE_PATH) .request(targetFormat.toString()) .header(ConverterNetworkProtocol.HEADER_JOB_PRIORITY, getPriority().getValue()) .async() .post(Entity.entity(new ConsumeOnCloseInputStream(this, fetchedSource), sourceFormat.toString()))); }