Java Code Examples for org.restlet.data.MediaType#TEXT_HTML
The following examples show how to use
org.restlet.data.MediaType#TEXT_HTML .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LinksResponseWriter.java From attic-polygene-java with Apache License 2.0 | 6 votes |
private Representation createTextHtmlRepresentation( final Object result, final Response response ) { return new WriterRepresentation( MediaType.TEXT_HTML ) { @Override public void write( Writer writer ) throws IOException { Map<String, Object> context = new HashMap<>(); context.put( "request", response.getRequest() ); context.put( "response", response ); context.put( "result", result ); try { cfg.getTemplate( "links.htm" ).process( context, writer ); } catch( TemplateException e ) { throw new IOException( e ); } } }; }
Example 2
Source File: APIInfoResource.java From ontopia with Apache License 2.0 | 6 votes |
@Get public Representation getAPIInfo() throws IOException { TemplateRepresentation r = new TemplateRepresentation("net/ontopia/topicmaps/rest/resources/info.html", MediaType.TEXT_HTML); r.getEngine().addProperty(VelocityEngine.RESOURCE_LOADER, "classpath"); r.getEngine().addProperty("classpath." + VelocityEngine.RESOURCE_LOADER + ".class", ClasspathResourceLoader.class.getName()); Map<Restlet, String> allRoutes = new HashMap<>(); list(allRoutes, getApplication().getInboundRoot(), ""); Map<String, Object> data = new HashMap<>(); data.put("util", this); data.put("root", getApplication().getInboundRoot()); data.put("routes", allRoutes); data.put("cutil", ClassUtils.class); r.setDataModel(data); return r; }
Example 3
Source File: EntitiesResource.java From attic-polygene-java with Apache License 2.0 | 5 votes |
private Representation representHtml() throws ResourceException { try { Stream<EntityReference> query = entityFinder.findEntities( EntityComposite.class, null, null, null, null, Collections.emptyMap() ); Representation representation = new WriterRepresentation( MediaType.TEXT_HTML ) { @Override public void write( Writer buf ) throws IOException { PrintWriter out = new PrintWriter( buf ); out.println( "<html><head><title>All entities</title></head><body><h1>All entities</h1><ul>" ); query.forEach( entity -> out.println( "<li><a href=\"" + getRequest().getResourceRef().clone().addSegment( entity.identity() + ".html" ) + "\">" + entity.identity() + "</a></li>" ) ); out.println( "</ul></body></html>" ); } }; representation.setCharacterSet( CharacterSet.UTF_8 ); return representation; } catch( EntityFinderException e ) { throw new ResourceException( e ); } }
Example 4
Source File: ResourceResponseWriter.java From attic-polygene-java with Apache License 2.0 | 4 votes |
@Override public boolean writeResponse( final Object result, final Response response ) throws ResourceException { if( result instanceof Resource ) { Resource resourceValue = (Resource) result; // Allowed methods response.getAllowedMethods().add( Method.GET ); if( resourceValue.commands().get().stream().anyMatch( LinksUtil.withRel( "delete" ) ) ) { response.getAllowedMethods().add( Method.DELETE ); } if( resourceValue.commands().get().stream().anyMatch( LinksUtil.withRel( "update" ) ) ) { response.getAllowedMethods().add( Method.PUT ); } // Response according to what client accepts MediaType type = getVariant( response.getRequest(), ENGLISH, supportedMediaTypes ).getMediaType(); if( MediaType.APPLICATION_JSON.equals( type ) ) { String json = jsonSerializer.serialize( resourceValue ); response.setEntity( new StringRepresentation( json, MediaType.APPLICATION_JSON ) ); return true; } else if( MediaType.TEXT_HTML.equals( type ) ) { Representation rep = new WriterRepresentation( MediaType.TEXT_HTML ) { @Override public void write( Writer writer ) throws IOException { Map<String, Object> context = new HashMap<>(); context.put( "request", response.getRequest() ); context.put( "response", response ); context.put( "result", result ); try { cfg.getTemplate( "resource.htm" ).process( context, writer ); } catch( TemplateException e ) { throw new IOException( e ); } } }; response.setEntity( rep ); return true; } } return false; }