当前位置: 首页>>代码示例>>Java>>正文


Java MediaType.TEXT_HTML属性代码示例

本文整理汇总了Java中org.restlet.data.MediaType.TEXT_HTML属性的典型用法代码示例。如果您正苦于以下问题:Java MediaType.TEXT_HTML属性的具体用法?Java MediaType.TEXT_HTML怎么用?Java MediaType.TEXT_HTML使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在org.restlet.data.MediaType的用法示例。


在下文中一共展示了MediaType.TEXT_HTML属性的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getTestForm

@Get
public FileRepresentation getTestForm() {
    ExtensionTokenManager tokenManager = this.getTokenManager();
    if (tokenManager.authenticationRequired()) {
        getResponse().setStatus(Status.CLIENT_ERROR_UNAUTHORIZED);
        return null;
    } else {
        try {
            File webDir = getWebDirectory();
            File file = new File(webDir, TEST_FORM_HTML);
            FileRepresentation htmlForm = new FileRepresentation(file, MediaType.TEXT_HTML);
            return htmlForm;
        } catch (Exception ex) {
            getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
            return null;
        }
    }
}
 
开发者ID:blackducksoftware,项目名称:hub-email-extension,代码行数:18,代码来源:EmailTestServerResource.java

示例2: createTextHtmlRepresentation

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 );
                        }
                    }
                };
}
 
开发者ID:apache,项目名称:polygene-java,代码行数:23,代码来源:LinksResponseWriter.java

示例3: getWebIndex

@Get
    public Representation getWebIndex() {

        //get servlet context for getting files
        
        //get servlet context for getting files
//        ServletContext sc = (ServletContext) getContext().getServerDispatcher().getContext().getAttributes().get("org.restlet.ext.servlet.ServletContext");
        ServletContext sc = StorageStartup.servletContext;
        System.out.println(sc.getRealPath("")+"index.html");
        String htmlContent="";
        try {
            htmlContent = FileUtils.readFileToString(new File(sc.getRealPath("/")+"index.html"));
        } catch (IOException ex) {
            Logger.getLogger(indexResource.class.getName()).log(Level.SEVERE, null, ex);
        } 
        
        StringRepresentation result = new StringRepresentation(htmlContent, MediaType.TEXT_HTML);
       

        return result;
    }
 
开发者ID:UniSurreyIoT,项目名称:fiware-iot-discovery-ngsi9,代码行数:21,代码来源:indexResource.java

示例4: getAPIInfo

@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;
}
 
开发者ID:ontopia,项目名称:ontopia,代码行数:18,代码来源:APIInfoResource.java

示例5: getCollectorsHtml

@Get("html")
public Representation getCollectorsHtml() throws ResourceNotFoundException, ParseErrorException, MethodInvocationException, IOException, Exception{
	
	List<Map<String, Object>> agents = getCollectorsJson();
	VelocityContext ctx = new VelocityContext();
	ctx.put("agents",agents);
	StringWriter writer = new StringWriter();
	Velocity.getTemplate("agentsStatusResource.vm").merge(ctx, writer);
	return new  StringRepresentation(writer.toString(), MediaType.TEXT_HTML);
}
 
开发者ID:gerritjvv,项目名称:bigstreams,代码行数:10,代码来源:AgentsStatusResource.java

示例6: getCollectorsHtml

@Get("html")
public Representation getCollectorsHtml() throws ResourceNotFoundException, ParseErrorException, Exception{
	
	List<Map<String, Object>> collectors = getCollectors();
	//TemplateRepresentation rep = new TemplateRepresentation(Velocity.getTemplate("collectorsStatusResource.vm"), model, MediaType.TEXT_HTML);
	VelocityContext ctx = new VelocityContext();
	ctx.put("collectors", collectors);
	StringWriter writer = new StringWriter();
	Velocity.getTemplate("collectorsStatusResource.vm").merge(ctx, writer);
	return new  StringRepresentation(writer.toString(), MediaType.TEXT_HTML);
}
 
开发者ID:gerritjvv,项目名称:bigstreams,代码行数:11,代码来源:CollectorsStatusResource.java

示例7: getCollectorsHtml

@Get("html")
public Representation getCollectorsHtml() throws ResourceNotFoundException, ParseErrorException, Exception{
	
	//this is not the view port
	int port = Integer.valueOf(getQuery().getFirstValue("port", "8220"));
	String collectorHostParam = getQuery().getFirstValue("collector", true);
	String statusObj = null;
	
	if(collectorHostParam != null && collectorHostParam.trim().length() > 0){
		String url = "http://" + collectorHostParam + ":" + viewPort + "/view/collector/status";
		getResponse().redirectPermanent(url);
		return null;
	}else{
		statusObj = objectMapper.writeValueAsString(status);
		collectorHostParam = "localhost";
	}
	
	VelocityContext ctx = new VelocityContext();
	
	ctx.put("collectorPort", port);
	ctx.put("collectorHost", collectorHostParam);
	ctx.put("collectorStatus", statusObj);
	StringWriter writer = new StringWriter();
	Velocity.getTemplate("collectorStatusResource.vm").merge(ctx, writer);
	
	return  new  StringRepresentation(writer.toString(), MediaType.TEXT_HTML);
}
 
开发者ID:gerritjvv,项目名称:bigstreams,代码行数:27,代码来源:CollectorStatusResource.java

示例8: representHtml

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 );
    }
}
 
开发者ID:apache,项目名称:polygene-java,代码行数:29,代码来源:EntitiesResource.java

示例9: doGet

@SuppressWarnings("rawtypes")
@Get
public Representation doGet() throws IOException {
    final String addrStr = "http://hostname:" + RestletServer.SERVER_PORT + RestletServer.ROOT_URI;

    // sorting routes
    Map<String, Class> routesMap = RestletServer.getRoutes();
    String[] routes = new String[routesMap.keySet().size()];
    routesMap.keySet().toArray(routes);
    Arrays.sort(routes);

    /**
     * Bonjour Page Construction
     */
    String htmlTemplate = new String(Files.readAllBytes(java.nio.file.Paths.get(BONJOUR_TMPL_PATH))).trim();
    String imgContent = new String(Files.readAllBytes(java.nio.file.Paths.get(BGROUND_IMG_PATH))).trim();
    final StringBuilder output = new StringBuilder();

    // listing available routes
    int i = 0;
    for (String uri : routes) {
        output.append("<tr><td class='" + (i++ % 2 == 0 ? "even" : "odd")+ "'><a target='_blank' href='");
        output.append(RestletServer.ROOT_URI);
        output.append(uri);
        output.append("'>");
        output.append(addrStr);
        output.append(uri);
        output.append("</a></td></tr>");
    }

    htmlTemplate = htmlTemplate.replace("{#ROUTES#}", output.toString());
    htmlTemplate = htmlTemplate.replace("{#BGROUND_IMG#}", imgContent);
    return new StringRepresentation(htmlTemplate, MediaType.TEXT_HTML);
}
 
开发者ID:jpinho,项目名称:soaba,代码行数:34,代码来源:BonjourService.java

示例10: getAgentStatusHtml

@Get("html")
public Representation getAgentStatusHtml() throws ResourceNotFoundException, ParseErrorException, MethodInvocationException, IOException, Exception{
	
	 
	
	int port = Integer.valueOf(getQuery().getFirstValue("port", "8085"));
	String agentHostParam = getQuery().getFirstValue("agent", true);
	
	if(agentHostParam == null || agentHostParam.trim().length() < 1){
		throw new RuntimeException("Specify the parameters agent and port e.g. ?agent=localhost&post=8085");
	}
	
	
	try{
	//work arround for browsers that do not send local host properly.
	final String agentHost = agentHostParam + ":" + port;
	
	LOG.info("using agetHost: " + agentHost);
		
	final VelocityContext ctx = new VelocityContext();
	
	
	String doneText = getFiles("http://" + agentHost + "/files/list/DONE");
	String readyText = getFiles("http://" + agentHost + "/files/list/READY");
	String parkedText = getFiles("http://" + agentHost + "/files/list/PARKED");
	String readingText = getFiles("http://" + agentHost + "/files/list/READING");
	String readErrorText = getFiles("http://" + agentHost + "/files/list/READ_ERROR");
	String deletedText = getFiles("http://" + agentHost + "/files/list/DELETED");
	
	
	String agentStatus = getFiles("http://" + agentHost + "/agent/status");
	
	ctx.put("DONE", doneText);
	ctx.put("PARKED", parkedText);
	ctx.put("READY", readyText);
	ctx.put("READING", readingText);
	ctx.put("DELETED", deletedText);
	ctx.put("READ_ERROR", readErrorText);
	ctx.put("agentStatus", agentStatus);
	ctx.put("agentHost", agentHost);
	 
	StringWriter writer = new StringWriter();
	Velocity.getTemplate("agentStatusResource.vm").merge(ctx, writer);
	
	return new  StringRepresentation(writer.toString(), MediaType.TEXT_HTML);
	}catch(Throwable t){
		t.printStackTrace();
		System.out.println(getQuery().getFirstValue("agent"));
		return new StringRepresentation("Could not find values for " + getQuery().getFirstValue("agent") + " : " + t.toString() + " Ensure that the agent is reacheable from the collector.");
	}
}
 
开发者ID:gerritjvv,项目名称:bigstreams,代码行数:51,代码来源:AgentStatusResource.java

示例11: writeResponse

@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;
}
 
开发者ID:apache,项目名称:polygene-java,代码行数:56,代码来源:ResourceResponseWriter.java


注:本文中的org.restlet.data.MediaType.TEXT_HTML属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。