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


Java View类代码示例

本文整理汇总了Java中io.dropwizard.views.View的典型用法代码示例。如果您正苦于以下问题:Java View类的具体用法?Java View怎么用?Java View使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: render

import io.dropwizard.views.View; //导入依赖的package包/类
/**
 * Render method will write the rendered output utilizing the
 * properties on the views class and the template specified by the
 * views to the provided outputstream
 * @param view
 * @param locale
 * @param outputStream
 * @throws IOException
 */
public void render(View view, Locale locale, OutputStream outputStream) throws IOException {

    logger.debug("rendering jade views {}", view);

    final Map<String, Object> model = Try.of(() -> convert(view))
        .recover(this::recoverFromObjectMapping)
        .orElseThrow(Throwables::propagate);

    logger.debug("views class converted into the following model {}", model);

    Try.of(() -> cache.get(view.getClass()))
        .andThen((config) -> {
            logger.debug("rendering template with name {} and model {}", view.getTemplateName(), model);
            final String rendered = config.renderTemplate(config.getTemplate(view.getTemplateName()), model);
            outputStream.write(
                    rendered.getBytes(view.getCharset().or(Charset.defaultCharset())));
        })
        .onFailure(Throwables::propagate);
}
 
开发者ID:gethalfpintoss,项目名称:dropwizard-views-jade,代码行数:29,代码来源:JadeViewRenderer.java

示例2: getActiveView

import io.dropwizard.views.View; //导入依赖的package包/类
/**
 * Show the functions defined for the collection.
 */
@GET
@Path("/{collection}/functions")
public View getActiveView(
    @PathParam("collection") String collection,
    @DefaultValue("false") @QueryParam("hideInactive") boolean hideInactive) throws Exception {
  ThirdEyeAnomalyDetectionConfiguration config = collectionToConfigMap.get(collection);
  switch (config.getMode()) {
    case GENERIC:
      return getActiveGenericView(config, hideInactive);
    case RULEBASED:
      return getActiveRuleBasedView(config, hideInactive);
    default:
      throw new IllegalStateException();
  }
}
 
开发者ID:Hanmourang,项目名称:Pinot,代码行数:19,代码来源:FunctionTableResource.java

示例3: getAddView

import io.dropwizard.views.View; //导入依赖的package包/类
/**
 * Add function view for the collection.
 */
@GET
@Path("/{collection}/functions/add")
public View getAddView(@PathParam("collection") String collection) throws Exception {
  ThirdEyeAnomalyDetectionConfiguration config = collectionToConfigMap.get(collection);
  switch (config.getMode()) {
    case GENERIC:
      return new AddGenericView(config.getAnomalyDatabaseConfig().getUrl(),
          config.getAnomalyDatabaseConfig().getFunctionTableName(),
          config.getCollectionName(),
          SLASH.join("", collection, "functions", "add"));
    case RULEBASED:
      return new AddRuleBasedView(config.getAnomalyDatabaseConfig().getUrl(),
          config.getAnomalyDatabaseConfig().getFunctionTableName(),
          config.getCollectionName(),
          SLASH.join("", collection, "functions", "add"));
    default:
      throw new IllegalStateException();
  }
}
 
开发者ID:Hanmourang,项目名称:Pinot,代码行数:23,代码来源:FunctionTableResource.java

示例4: JadeViewRenderer

import io.dropwizard.views.View; //导入依赖的package包/类
/**
 * JadeViewRenderer constructor that allows you to provide an instance
 * of the object mapper.
 * @param objectMapper
 */
private JadeViewRenderer(ObjectMapper objectMapper) {
    this.mapper = objectMapper;
    this.cache = CacheBuilder.newBuilder()
        .build(new CacheLoader<Class<? extends View>, JadeConfiguration>() {
            @Override
            public JadeConfiguration load(Class<? extends View> aClass) throws Exception {
                logger.debug("building new JadeConfiguration for views class {}", aClass);
                JadeConfiguration config = new JadeConfiguration();
                config.setTemplateLoader(new JadeTemplateLoader(aClass));
                return config;
            }
        });
}
 
开发者ID:gethalfpintoss,项目名称:dropwizard-views-jade,代码行数:19,代码来源:JadeViewRenderer.java

示例5: testRender

import io.dropwizard.views.View; //导入依赖的package包/类
@Test
public void testRender() throws IOException {
    View view = new TestView("assertion");
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    renderer.render(view, Locale.US, output);
    assertThat(output.toString(), equalTo(TemplateUtil.renderedRawFileToString(view)));
}
 
开发者ID:gethalfpintoss,项目名称:dropwizard-views-jade,代码行数:8,代码来源:JadeViewRendererTest.java

示例6: testNoProps

import io.dropwizard.views.View; //导入依赖的package包/类
@Test
public void testNoProps() throws IOException {
    View view = new TestNoPropsView();
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    renderer.render(view, Locale.US, output);
    assertThat(output.toString(), equalTo(TemplateUtil.renderedRawFileToString(view)));
}
 
开发者ID:gethalfpintoss,项目名称:dropwizard-views-jade,代码行数:8,代码来源:JadeViewRendererTest.java

示例7: testGetLastModified

import io.dropwizard.views.View; //导入依赖的package包/类
@Test
public void testGetLastModified() throws IOException {
    final View view = view("assertion");
    final long actual = new File(view.getClass().getResource(view.getTemplateName()).getFile())
        .lastModified();
    assertThat(loader.getLastModified(view.getTemplateName()), equalTo(actual));
}
 
开发者ID:gethalfpintoss,项目名称:dropwizard-views-jade,代码行数:8,代码来源:JadeTemplateLoaderTest.java

示例8: jsonPreview

import io.dropwizard.views.View; //导入依赖的package包/类
@GET
@Path("/preview-records/{media-type}")
@Produces(ExtraMediaType.TEXT_HTML)
@Timed
public View jsonPreview(@PathParam("media-type") final String mediaType) {
    final int limit = register.getTotalRecords() > IndexSizePagination.ENTRY_LIMIT
            ? IndexSizePagination.ENTRY_LIMIT
            : register.getTotalRecords();
    final List<Record> records = register.getRecords(limit, DEFAULT_OFFSET);

    return viewFactory.previewRecordsPageView(records, null, ExtraMediaType.transform(mediaType));
}
 
开发者ID:openregister,项目名称:openregister-java,代码行数:13,代码来源:PreviewRecordsResource.java

示例9: jsonByKeyPreview

import io.dropwizard.views.View; //导入依赖的package包/类
@GET
@Path("/preview-records/{media-type}/{record-key}")
@Produces(ExtraMediaType.TEXT_HTML)
@Timed
public View jsonByKeyPreview(@PathParam("media-type") final String mediaType, @PathParam("record-key") final String key) {
    final List<Record> records = Collections.singletonList(register.getRecord(key)
            .orElseThrow(() -> new NotFoundException("No records found with key: " + key)));

    return viewFactory.previewRecordsPageView(records, key, ExtraMediaType.transform(mediaType));
}
 
开发者ID:openregister,项目名称:openregister-java,代码行数:11,代码来源:PreviewRecordsResource.java

示例10: jsonByKeyPreview

import io.dropwizard.views.View; //导入依赖的package包/类
@GET
@Path("/preview-items/{media-type}/sha-256:{item-hash}")
@Produces(ExtraMediaType.TEXT_HTML)
@Timed
public View jsonByKeyPreview(@PathParam("media-type") final String mediaType, @PathParam("item-hash") final String itemHash) {
    final HashValue hash = new HashValue(HashingAlgorithm.SHA256, itemHash);
    final Item item = register.getItemBySha256(hash)
            .orElseThrow(() -> new NotFoundException("No item found with item hash: " + itemHash));

    return viewFactory.previewItemPageView(item, itemHash, ExtraMediaType.transform(mediaType));
}
 
开发者ID:openregister,项目名称:openregister-java,代码行数:12,代码来源:PreviewItemsResource.java

示例11: preview

import io.dropwizard.views.View; //导入依赖的package包/类
@GET
@Path("/preview-entries/{media-type}")
@Produces(ExtraMediaType.TEXT_HTML)
@Timed
public View preview(@PathParam("media-type") final String mediaType) {
    final int limit = register.getTotalEntries() > IndexSizePagination.ENTRY_LIMIT
            ? IndexSizePagination.ENTRY_LIMIT
            : register.getTotalEntries();
    final Collection<Entry> entries = register.getEntries(START, limit);

    return viewFactory.previewEntriesPageView(entries, null, ExtraMediaType.transform(mediaType));
}
 
开发者ID:openregister,项目名称:openregister-java,代码行数:13,代码来源:PreviewEntriesResource.java

示例12: jsonByKeyPreview

import io.dropwizard.views.View; //导入依赖的package包/类
@GET
@Path("/preview-entries/{media-type}/{entry-key}")
@Produces(ExtraMediaType.TEXT_HTML)
@Timed
public View jsonByKeyPreview(@PathParam("media-type") final String mediaType, @PathParam("entry-key") final int key) {
    final Collection<Entry> entries = Collections.singletonList(register.getEntry(key).orElseThrow(NotFoundException::new));

    return viewFactory.previewEntriesPageView(entries, key, ExtraMediaType.transform(mediaType));
}
 
开发者ID:openregister,项目名称:openregister-java,代码行数:10,代码来源:PreviewEntriesResource.java

示例13: home

import io.dropwizard.views.View; //导入依赖的package包/类
@GET
@Produces({ExtraMediaType.TEXT_HTML})
@Timed
public View home() {
    return viewFactory.homePageView(
            register.getTotalRecords(),
            register.getTotalEntries(),
            register.getLastUpdatedTime(),
            register.getCustodianName()
    );
}
 
开发者ID:openregister,项目名称:openregister-java,代码行数:12,代码来源:HomePageResource.java

示例14: download

import io.dropwizard.views.View; //导入依赖的package包/类
@GET
@Path("/download")
@Produces(ExtraMediaType.TEXT_HTML)
@Timed
public View download() {
    return viewFactory.downloadPageView(resourceConfiguration.getEnableDownloadResource());
}
 
开发者ID:openregister,项目名称:openregister-java,代码行数:8,代码来源:DataDownload.java

示例15: render

import io.dropwizard.views.View; //导入依赖的package包/类
@Override
public void render(View view, Locale locale, OutputStream output)
        throws IOException, WebApplicationException {

    ThymeleafContext context = new ThymeleafContext((ThymeleafView) view);
    OutputStreamWriter writer = new OutputStreamWriter(output, StandardCharsets.UTF_8);
    engine.process(view.getTemplateName(), context, writer);
    writer.flush();
}
 
开发者ID:openregister,项目名称:openregister-java,代码行数:10,代码来源:ThymeleafViewRenderer.java


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