@Override public Representation toRepresentation(final Object source, final Variant target, Resource resource) throws IOException { return new OutputRepresentation(target.getMediaType()) { @Override public void write(OutputStream outputStream) throws IOException { CharacterSet characterSet = target.getCharacterSet(); if (characterSet == null) { characterSet = CharacterSet.UTF_8; } writeFragment(outputStream, source, characterSet); } }; }
/** * Constructor with a variant. * * @param variant * The variant to describe. */ public RepresentationInfo(Variant variant) { setMediaType(variant.getMediaType()); }
@Override public Representation toRepresentation(Object source, Variant target, Resource resource) throws IOException { Representation result = null; if (source instanceof Document) { result = new DomRepresentation(target.getMediaType(), (Document) source); } else if (source instanceof Representation) { result = (Representation) source; } return result; }
@Override public Representation toRepresentation(Object source, Variant target, Resource resource) throws IOException { Representation result = null; if (source instanceof Document) { result = new DomRepresentation(target.getMediaType(), (Document) source); } else if (source instanceof Representation) { result = (Representation) source; } return result; }
@Override public <T> float score(Representation source, Class<T> target, Resource resource) { for (Variant v : variants) { if (v.getMediaType().isCompatible(source.getMediaType())) { return .5F; } } return -1F; }
@Override protected Representation get( Variant variant ) throws ResourceException { if ( MediaType.APPLICATION_JSON.equals( variant.getMediaType() ) ) { LOGGER.trace( "Will represent {}", MediaType.APPLICATION_JSON ); return representJson(); } else if ( MediaType.TEXT_HTML.equals( variant.getMediaType() ) ) { LOGGER.trace( "Will represent {}", MediaType.TEXT_HTML ); return representHtml(); } throw new ResourceException( Status.CLIENT_ERROR_NOT_FOUND ); }
@Override protected Representation post(Representation entity, Variant variant) { String id = (String) getRequest().getAttributes().get("id"); if (!getPipelines().containsKey(id)) { return badRequest(Status.CLIENT_ERROR_NOT_FOUND, "no pipeline: " + pipelineUri(id), variant.getMediaType()); } PipelineConfiguration pipeconfig = getPipelines().get(id); XPipeline xpipeline = pipeconfig.pipeline; pipeconfig.reset(); xpipeline.reset(); return okResponse("Pipeline reset", variant.getMediaType()); }
public static Representation getRdfRepresentation(final ResourceCount results, final Variant variant, final Reference resourceRef) throws RepositoryException, RDFHandlerException { return RestletUtils.toRDFSerialisation(variant.getMediaType().getName(), SesameUtils.toRDFRepository(results, null)); }
@Override protected Representation post(Representation entity, Variant variant) { String id = (String) getRequest().getAttributes().get("id"); if (!getPipelines().containsKey(id)) { return badRequest(Status.CLIENT_ERROR_NOT_FOUND, "no pipeline: " + pipelineUri(id), variant.getMediaType()); } PipelineConfiguration pipeconfig = getPipelines().get(id); XPipeline xpipeline = pipeconfig.pipeline; pipeconfig.reset(); xpipeline.reset(); return okResponse("Pipeline reset", variant.getMediaType()); }
@Override protected Representation delete(Variant variant) { String id = (String) getRequest().getAttributes().get("id"); if (!getPipelines().containsKey(id)) { return badRequest(Status.CLIENT_ERROR_NOT_FOUND, "no pipeline: " + pipelineUri(id), variant.getMediaType()); } getPipelines().remove(id); setStatus(Status.SUCCESS_OK); return new EmptyRepresentation(); } }
@Override protected Representation delete(Variant variant) { String id = (String) getRequest().getAttributes().get("id"); if (!getPipelines().containsKey(id)) { return badRequest(Status.CLIENT_ERROR_NOT_FOUND, "no pipeline: " + pipelineUri(id), variant.getMediaType()); } getPipelines().remove(id); setStatus(Status.SUCCESS_OK); return new EmptyRepresentation(); } }
@Override public Representation toRepresentation(Object source, Variant target, Resource resource) throws IOException { if (source instanceof Template) { TemplateRepresentation tr = new TemplateRepresentation( (Template) source, target.getMediaType()); tr.setDataModel(resource.getRequest(), resource.getResponse()); return tr; } return null; }
@Override protected Representation post(Representation entity, Variant variant) { try { ((PiperackApplication) getApplication()).stop(); } catch (Exception e) { throw new XProcException(e); } return okResponse("Stopping", variant.getMediaType()); }
@Override protected Representation post(Representation entity, Variant variant) { try { ((PiperackApplication) getApplication()).stop(); } catch (Exception e) { throw new XProcException(e); } return okResponse("Stopping", variant.getMediaType()); }
@Override protected Representation get(Variant variant) { String id = (String) getRequest().getAttributes().get("id"); if (!getPipelines().containsKey(id)) { return badRequest(Status.CLIENT_ERROR_NOT_FOUND, "no pipeline: " + pipelineUri(id), variant.getMediaType()); } String port = (String) getRequest().getAttributes().get("port"); if (getPipelines().containsKey(id)) { PipelineConfiguration pipeconfig = getPipelines().get(id); return getOutput(pipeconfig, port); } else { return badRequest(Status.CLIENT_ERROR_BAD_REQUEST, "no pipe: " + pipelineUri(id), MediaType.APPLICATION_XML); } } }
@Override public Representation toRepresentation(Object source, Variant target, Resource resource) throws IOException { if (source instanceof Template) { return new TemplateRepresentation((Template) source, new ResolverHashModel(Resolver.createResolver( resource.getRequest(), resource.getResponse())), target.getMediaType()); } return null; }
@Override @Get public Representation get(final Variant entity) { MediaType type = entity.getMediaType(); RDFFormat format = RDFMediaTypes.findRdfFormat(type); selfIRI = this.getRequest().getResourceRef().toString(); try { IRI subject = sail.getValueFactory().createIRI(selfIRI); return getRDFRepresentation(subject, format); } catch (Throwable t) { t.printStackTrace(); return null; } }
@Override @Get public Representation get(final Variant entity) { MediaType type = entity.getMediaType(); RDFFormat format = RDFMediaTypes.findRdfFormat(type); selfIRI = this.getRequest().getResourceRef().toString(); try { IRI subject = sail.getValueFactory().createIRI(selfIRI); return getRDFRepresentation(subject, format); } catch (Throwable t) { t.printStackTrace(); return null; } }
@Override public Representation toRepresentation(Object source, Variant target, Resource resource) throws IOException { if (source instanceof Template) { Locale locale = getLocale(resource); TemplateRepresentation tr = new TemplateRepresentation( ((Template) source).getTemplateName(), locale, target.getMediaType()); tr.setDataModel(resource.getRequest(), resource.getResponse()); return tr; } return null; }
/** * Constructor. * * @param variant * The variant to enrich. * @param annotationInfo * The optional annotation descriptor. */ public VariantInfo(Variant variant, MethodAnnotationInfo annotationInfo) { this(variant.getMediaType(), annotationInfo); setCharacterSet(variant.getCharacterSet()); setEncodings(variant.getEncodings()); setLanguages(variant.getLanguages()); }