org.glassfish.jersey.server.mvc.Template Java Examples
The following examples show how to use
org.glassfish.jersey.server.mvc.Template.
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: NamespaceAction.java From emissary with Apache License 2.0 | 6 votes |
@GET @Path("/Namespace.action") @Produces(MediaType.TEXT_HTML) @Template(name = "/namespace") public Map<String, Object> getNamespace(@Context HttpServletRequest request) { Map<String, Object> model = new HashMap<String, Object>(); Set<NamespaceInfo> namespaces = new LinkedHashSet<>(); int rowCount = 0; for (Iterator<String> i = Namespace.keySet().iterator(); i.hasNext();) { String key = i.next(); String clz = rowCount++ % 2 == 0 ? "even" : "odd"; String context = request.getContextPath(); namespaces.add(new NamespaceInfo(key, clz, context)); } model.put("namespaces", namespaces); return model; }
Example #2
Source File: TemplateModelProcessor.java From ameba with MIT License | 6 votes |
/** * Creates enhancing methods for given resource. * * @param resourceClass resource class for which enhancing methods should be created. * @param resourceInstance resource instance for which enhancing methods should be created. May be {@code null}. * @param newMethods list to store new methods into. */ private void createEnhancingMethods(final Class<?> resourceClass, final Object resourceInstance, final List<ModelProcessorUtil.Method> newMethods) { final Template template = resourceClass.getAnnotation(Template.class); if (template != null) { final Class<?> annotatedResourceClass = ModelHelper.getAnnotatedResourceClass(resourceClass); final List<MediaType> produces = MediaTypes .createQualitySourceMediaTypes(annotatedResourceClass.getAnnotation(Produces.class)); final List<MediaType> consumes = MediaTypes.createFrom(annotatedResourceClass.getAnnotation(Consumes.class)); final TemplateInflectorImpl inflector = new TemplateInflectorImpl(template.name(), resourceClass, resourceInstance); newMethods.add(new ModelProcessorUtil.Method(HttpMethod.GET, consumes, produces, inflector)); newMethods.add(new ModelProcessorUtil.Method(IMPLICIT_VIEW_PATH_PARAMETER_TEMPLATE, HttpMethod.GET, consumes, produces, inflector)); } }
Example #3
Source File: ConsoleAction.java From emissary with Apache License 2.0 | 5 votes |
@GET @Path("/Console.action") @Produces(MediaType.TEXT_HTML) @Template(name = "/console") public Map<String, Object> rubyConsole() { Map<String, Object> map = new HashMap<>(); map.put("emissary", ImmutableMap.of("version", new emissary.util.Version().toString())); return map; }
Example #4
Source File: DocumentAction.java From emissary with Apache License 2.0 | 5 votes |
@GET @Path("/Document.action") @Produces(MediaType.TEXT_HTML) @Template(name = "/document_form") public Map<String, Object> documentForm() { Map<String, Object> map = new HashMap<>(); return map; }
Example #5
Source File: EnvironmentAction.java From emissary with Apache License 2.0 | 5 votes |
@GET @Path("/Environment.action") @Produces(MediaType.TEXT_HTML) @Template(name = "/environment") public Map<String, Object> getEnvironment() { Map<String, Object> model = new HashMap<String, Object>(); Set<JustAString> systemProperties = new TreeSet<>(); Enumeration<?> e = System.getProperties().propertyNames(); Set<String> keys = new TreeSet<String>(); while (e.hasMoreElements()) { keys.add((String) e.nextElement()); } for (String prop : keys) { systemProperties.add(new JustAString(prop + ": " + System.getProperty(prop))); } Set<JustAString> environmentVariables = new TreeSet<>(); Map<String, String> m = System.getenv(); for (String s : new TreeSet<String>(m.keySet())) { environmentVariables.add(new JustAString(s + ": " + m.get(s))); } model.put("systemproperties", systemProperties); model.put("environmentvariables", environmentVariables); return model; }
Example #6
Source File: TemplateMethodInterceptor.java From ameba with MIT License | 5 votes |
/** * {@inheritDoc} */ @Override public void aroundWriteTo(final WriterInterceptorContext context) throws IOException, WebApplicationException { final Object entity = context.getEntity(); if (!(entity instanceof Viewable) && resourceInfoProvider.get().getResourceMethod() != null) { final Template template = TemplateHelper.getTemplateAnnotation(context.getAnnotations()); if (template != null) { context.setType(Viewable.class); context.setEntity(new Viewable(template.name(), entity)); } } context.proceed(); }
Example #7
Source File: TemplateHelper.java From ameba with MIT License | 5 votes |
/** * Extract {@link org.glassfish.jersey.server.mvc.Template template} annotation from given list. * * @param annotations list of annotations. * @return {@link org.glassfish.jersey.server.mvc.Template template} annotation or {@code null} if this annotation is not present. */ public static Template getTemplateAnnotation(final Annotation[] annotations) { if (annotations != null && annotations.length > 0) { for (Annotation annotation : annotations) { if (annotation instanceof Template) { return (Template) annotation; } } } return null; }
Example #8
Source File: FruitResource.java From tutorials with MIT License | 5 votes |
@GET @Template(name = "/all.ftl") @Path("/all") @Produces(MediaType.TEXT_HTML) public Map<String, Object> getAllFruit() { final List<Fruit> fruits = new ArrayList<>(); fruits.add(new Fruit("banana", "yellow")); fruits.add(new Fruit("apple", "red")); fruits.add(new Fruit("kiwi", "green")); final Map<String, Object> model = new HashMap<String, Object>(); model.put("items", fruits); return model; }
Example #9
Source File: FrontHandler.java From gluon-samples with BSD 3-Clause "New" or "Revised" License | 4 votes |
@GET @Produces(MediaType.TEXT_HTML + "; charset=UTF-8") @Template(name = "/index.ftl") public String get() { return service.getMotd(); }