Java 类org.glassfish.jersey.server.mvc.MvcFeature 实例源码

项目:jersey-mvc-velocity    文件:VelocityMvcFeature.java   
@Override
public boolean configure(final FeatureContext context) {
    final Configuration config = context.getConfiguration();

    if (!config.isRegistered(VelocityViewProcessor.class)) {
        // Template Processor.
        context.register(VelocityViewProcessor.class);

        // MvcFeature.
        if (!config.isRegistered(MvcFeature.class)) {
            context.register(MvcFeature.class);
        }

        return true;
    }
    return false;
}
项目:rabbitframework    文件:FreemarkerMvcFeature.java   
@Override
public boolean configure(final FeatureContext context) {
    final Configuration config = context.getConfiguration();

    if (!config.isRegistered(FreemarkerViewProcessor.class)) {
        // Template Processor.
        context.register(FreemarkerViewProcessor.class);

        // MvcFeature.
        if (!config.isRegistered(MvcFeature.class)) {
            context.register(MvcFeature.class);
        }

        return true;
    }
    return false;
}
项目:game-of-life-modern-java    文件:WebApplicationResourceConfig.java   
public WebApplicationResourceConfig() {
    packages("com.giorgiosironi.gameoflife.web");
    property(MvcFeature.TEMPLATE_BASE_PATH, "templates");
    register(FreemarkerMvcFeature.class);
    register(new AbstractBinder() {
        @Override
        protected void configure() {
            InMemoryGenerationRepository repository = new InMemoryGenerationRepository();
            Generation original = Generation.withAliveCells(
                    Cell.onXAndY(1, 1),
                    Cell.onXAndY(1, 2),
                    Cell.onXAndY(2, 1),
                    Cell.onXAndY(2, 2),
                    Cell.onXAndY(7, 1),
                    Cell.onXAndY(7, 2),
                    Cell.onXAndY(7, 3),
                    Cell.onXAndY(7, 8)
            );
            repository.add("a-block-and-a-bar", 0, original);
            bind(repository).to(GenerationRepository.class);
        }
    });
}
项目:jersey-mvc-jasper    文件:JasperMvcFeature.java   
/**
     * Property defines output encoding produced by
     * {@link org.glassfish.jersey.server.mvc.spi.TemplateProcessor}. The value
     * must be a valid encoding defined that can be passed to the
     * {@link java.nio.charset.Charset#forName(String)} method.
     *
     * <p/>
     * The default value is {@code UTF-8}.
     * <p/>
     * The name of the configuration property is <tt>{@value}</tt>.
     * <p/>
     *
     * @param context
     * @return 
     */
//    public static final String ENCODING = MvcFeature.ENCODING + SUFFIX;
    @Override
    public boolean configure(final FeatureContext context) {
        final Configuration config = context.getConfiguration();

        if (!config.isRegistered(JasperViewProcessor.class)) {
            // Template Processor.
            context.register(JasperViewProcessor.class);

            // MvcFeature.
            if (!config.isRegistered(MvcFeature.class)) {
                context.register(MvcFeature.class);
            }

            return true;
        }
        return false;
    }
项目:ameba    文件:AbstractTemplateProcessor.java   
/**
 * <p>Constructor for AbstractTemplateProcessor.</p>
 *
 * @param config              a {@link javax.ws.rs.core.Configuration} object.
 * @param propertySuffix      a {@link java.lang.String} object.
 * @param supportedExtensions a {@link java.lang.String} object.
 */
public AbstractTemplateProcessor(Configuration config, String propertySuffix, String... supportedExtensions) {
    this.config = config;
    this.suffix = '.' + propertySuffix;
    Map<String, Object> properties = config.getProperties();
    String basePath = TemplateHelper.getBasePath(properties, propertySuffix);

    Collection<String> basePaths = TemplateHelper.getBasePaths(basePath);

    this.basePath = basePaths.toArray(new String[basePaths.size()]);

    Boolean cacheEnabled = PropertiesHelper.getValue(properties,
            MvcFeature.CACHE_TEMPLATES + this.suffix, Boolean.class, null);
    if (cacheEnabled == null) {
        cacheEnabled = PropertiesHelper.getValue(properties, MvcFeature.CACHE_TEMPLATES, false, null);
    }

    this.cache = cacheEnabled ? DataStructures.createConcurrentMap() : null;
    this.encoding = TemplateHelper.getTemplateOutputEncoding(config, this.suffix);

    this.supportedExtensions = Sets.newHashSet(Collections2.transform(
            Arrays.asList(supportedExtensions), input -> {
                input = input.toLowerCase();
                return input.startsWith(".") ? input : "." + input;
            }));

}
项目:ameba    文件:AbstractTemplateProcessor.java   
/**
 * <p>getTemplateObjectFactory.</p>
 *
 * @param serviceLocator a {@link org.glassfish.hk2.api.ServiceLocator} object.
 * @param type           a {@link java.lang.Class} object.
 * @param defaultValue   a {@link org.glassfish.jersey.internal.util.collection.Value} object.
 * @param <F>            a F object.
 * @return a F object.
 */
@SuppressWarnings("unchecked")
protected <F> F getTemplateObjectFactory(ServiceLocator serviceLocator, Class<F> type, Value<F> defaultValue) {
    Object objectFactoryProperty = this.config.getProperty(MvcFeature.TEMPLATE_OBJECT_FACTORY + this.suffix);
    if (objectFactoryProperty != null) {
        if (type.isAssignableFrom(objectFactoryProperty.getClass())) {
            return type.cast(objectFactoryProperty);
        }

        Class<F> factoryClass = null;
        if (objectFactoryProperty instanceof String) {
            factoryClass = ReflectionHelper.<F>classForNamePA((String) objectFactoryProperty).run();
        } else if (objectFactoryProperty instanceof Class) {
            factoryClass = (Class<F>) objectFactoryProperty;
        }

        if (factoryClass != null) {
            if (type.isAssignableFrom(factoryClass)) {
                return serviceLocator.create(factoryClass);
            }

            logger.warn(LocalizationMessages.WRONG_TEMPLATE_OBJECT_FACTORY(factoryClass, type));
        }
    }

    return defaultValue.get();
}
项目:ameba    文件:TemplateHelper.java   
/**
 * Get output encoding from configuration.
 *
 * @param configuration Configuration.
 * @param suffix        Template processor suffix of the
 *                      to configuration property {@link org.glassfish.jersey.server.mvc.MvcFeature#ENCODING}.
 * @return Encoding read from configuration properties or a default encoding if no encoding is configured.
 */
public static Charset getTemplateOutputEncoding(Configuration configuration, String suffix) {
    final String enc = PropertiesHelper.getValue(configuration.getProperties(), MvcFeature.ENCODING + suffix,
            String.class, null);
    if (enc == null) {
        return DEFAULT_ENCODING;
    } else {
        return Charset.forName(enc);
    }
}
项目:ameba    文件:TemplateHelper.java   
/**
 * <p>getBasePath.</p>
 *
 * @param properties a {@link java.util.Map} object.
 * @param cfgSuffix a {@link java.lang.String} object.
 * @return a {@link java.lang.String} object.
 */
public static String getBasePath(Map<String, Object> properties, String cfgSuffix) {
    String basePath = PropertiesHelper.getValue(properties,
            MvcFeature.TEMPLATE_BASE_PATH + "." + cfgSuffix, String.class, null);
    if (basePath == null) {
        basePath = PropertiesHelper.getValue(properties, MvcFeature.TEMPLATE_BASE_PATH, "", null);
    }
    return basePath;
}
项目:PANDA-DEEPLINKING    文件:PandaJerseyConfig.java   
public PandaJerseyConfig() throws JAXBException {
    packages("de.fuberlin.panda.api.jersey");
    setApplicationName("PANDA");

    // Load Resource Map
    JAXBContext jaxbContext = JAXBContext.newInstance(ResourceMap.class);
    Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
    File configFile = new File(pandaSettings.getResourceConfFilePath());
    pandaSettings.setResourceMap((ResourceMap) unmarshaller.unmarshal(configFile));

    // create default settings
    register(new AbstractBinder() {
        @Override
        protected void configure() {
            bind(pandaSettings);
        }
    });

    // register class for JSON support
    this.register(JacksonFeature.class);

    // register JSP support
    this.register(JspMvcFeature.class);
    this.property(MvcFeature.TEMPLATE_BASE_PATH, "/WEB-INF/jsp");

    // Custom JAXB marshaller provider
    this.register(JaxbMarshallerProvider.class);

    // Custom Jackson ObjectMapper provider
    this.register(JacksonObjectMapperProvider.class);

}
项目:jersey-mustache    文件:MustacheMvcFeature.java   
@Override
public boolean configure(final FeatureContext context) {
    if (!context.getConfiguration().isRegistered(MvcFeature.class)) {
        context.register(MvcFeature.class);
    }
    context.register(MustacheViewProcessor.class);
    return true;
}
项目:rallye-server    文件:RallyeApplication.java   
public RallyeApplication() {
    packages("de.rallye.api", "de.rallye.filter.auth", "de.rallye.exceptions.mappers");
    register(JacksonSmileProvider.class);
    register(JacksonXMLProvider.class);
    register(JacksonFeature.class);
    //register(EnsureMimeType.class);
    register(new RallyeBinder());
    register(MultiPartFeature.class);

       property(MvcFeature.TEMPLATE_BASE_PATH, "templates");
    property(MustacheMvcFeature.CACHE_TEMPLATES, false); //TODO enable caching once templates are no longer being modified
       register(MustacheMvcFeature.class);
}