View Javadoc

1   /*
2    * Copyright 2013 smartics, Kronseder & Reiner GmbH
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package de.smartics.properties.admin.resources.representation.html;
17  
18  import java.io.OutputStream;
19  import java.util.List;
20  
21  import de.smartics.html5.jatl.HtmlResourceContext;
22  import de.smartics.properties.admin.domain.model.ApiServices;
23  import de.smartics.properties.admin.domain.model.ApiServices.ServiceDescriptor;
24  import de.smartics.properties.admin.resources.representation.html.share.AbstractHtmlRepresentationRenderer;
25  import de.smartics.properties.admin.resources.representation.share.BreadcrumbHelper;
26  import de.smartics.resteasy.hypermedia.renderer.LinkDescriptor;
27  
28  /**
29   * Displays the list of services in an HTML page.
30   */
31  public final class ApiServicesHtmlRepresentationRenderer extends
32      AbstractHtmlRepresentationRenderer<ApiServices>
33  {
34    // ********************************* Fields *********************************
35  
36    // --- constants ------------------------------------------------------------
37  
38    /**
39     * The title to the page.
40     */
41    private static final String TITLE = "Services";
42  
43    // --- members --------------------------------------------------------------
44  
45    /**
46     * The domain object to render.
47     */
48    private final ApiServices domainObject;
49  
50    // ****************************** Initializer *******************************
51  
52    // ****************************** Constructors ******************************
53  
54    /**
55     * Default constructor.
56     *
57     * @param htmlContext the context information to render the representation.
58     * @param domainObject the domain object to render.
59     * @param entityStream the stream to write to.
60     */
61    public ApiServicesHtmlRepresentationRenderer(
62        final HtmlResourceContext htmlContext, final ApiServices domainObject,
63        final OutputStream entityStream)
64    {
65      super(htmlContext, entityStream);
66      this.domainObject = domainObject;
67    }
68  
69    // ****************************** Inner Classes *****************************
70  
71    // ********************************* Methods ********************************
72  
73    // --- init -----------------------------------------------------------------
74  
75    // --- get&set --------------------------------------------------------------
76  
77    // --- business -------------------------------------------------------------
78  
79    @Override
80    protected void bodyContents()
81    {
82      renderPageTitle(">>>");
83      html.p().text("The following list shows services provided by the API.")
84          .end();
85  
86      renderServices();
87    }
88  
89    private void renderServices()
90    {
91      for (final ServiceDescriptor service : domainObject.getServices())
92      {
93        final LinkDescriptor link =
94            linkDescriptorFactory.createDescriptor(service, "getAsHtml");
95        html.dl();
96        html.dt().link(link).end();
97        html.dd().text(link.getHelp()).end();
98        html.end();
99      }
100   }
101 
102   @Override
103   protected String getTitle()
104   {
105     return TITLE;
106   }
107 
108   @Override
109   protected List<LinkDescriptor> breadcrumbLinks()
110   {
111     return BreadcrumbHelper.adjustSelf(breadcrumb.api());
112   }
113 
114   // --- object basics --------------------------------------------------------
115 
116 }