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.share;
17  
18  import de.smartics.html5.jatl.Html;
19  import de.smartics.properties.admin.domain.model.ManagedApplication;
20  import de.smartics.properties.impl.config.ds.DataSourceConfiguration;
21  import de.smartics.properties.resource.domain.ArtifactId;
22  
23  /**
24   * Helps rendering that part of a representation that shows application
25   * information.
26   */
27  public final class ApplicationHtmlRenderingHelper
28  {
29    // ********************************* Fields *********************************
30  
31    // --- constants ------------------------------------------------------------
32  
33    // --- members --------------------------------------------------------------
34  
35    /**
36     * The HTML instance to create HTML documents.
37     */
38    private final Html html;
39  
40    /**
41     * Helper to localize application specific resources.
42     */
43    private final HtmlPathHelper pathHelper;
44  
45    /**
46     * The application to render.
47     *
48     * @serial
49     */
50    private final ManagedApplication application;
51  
52    // ****************************** Initializer *******************************
53  
54    // ****************************** Constructors ******************************
55  
56    // ****************************** Inner Classes *****************************
57  
58    // ********************************* Methods ********************************
59  
60    // --- init -----------------------------------------------------------------
61  
62    // --- get&set --------------------------------------------------------------
63  
64    // --- business -------------------------------------------------------------
65  
66    /**
67     * Default constructor.
68     *
69     * @param html the HTML instance to create HTML documents.
70     * @param pathHelper a helper to localize application specific resources.
71     * @param application the application to render.
72     */
73    public ApplicationHtmlRenderingHelper(final Html html,
74        final HtmlPathHelper pathHelper, final ManagedApplication application)
75    {
76      this.html = html;
77      this.pathHelper = pathHelper;
78      this.application = application;
79    }
80  
81    /**
82     * Adds the HTML representation of the application.
83     */
84    public void addApplication()
85    {
86      html.dl().classAttr("dl-horizontal");
87      addApplicationId();
88      addDataSource();
89      html.end();
90    }
91  
92    private void addApplicationId()
93    {
94      final ArtifactId artifactId = application.getApplicationId();
95      final String url = createArtfactUrl();
96      if (url != null)
97      {
98        html.dt().text("Application").end().dd().a().href(url)
99            .text(artifactId.toString()).end().end();
100     }
101     else
102     {
103       html.dt().text("Application").end().dd()
104           .text(application.getApplicationId().toString()).end();
105     }
106   }
107 
108   private String createArtfactUrl()
109   {
110     final ArtifactId artifactId = application.getApplicationId();
111     final String url =
112         application.getRemoteRepositoryUrl() + '/'
113             + artifactId.getGroupId().replace('.', '/') + '/'
114             + artifactId.getName() + '/' + artifactId.getVersion() + '/'
115             + artifactId.getName() + '-' + artifactId.getVersion() + '.'
116             + artifactId.getArchiveType();
117     return url;
118   }
119 
120   private void addDataSource()
121   {
122     final DataSourceConfiguration config = application.getDataSourceConfig();
123     if (config != null)
124     {
125       final String dsUrl = pathHelper.ds();
126       html.dt().text("Data Source").end().dd().a().href(dsUrl)
127           .text(config.toString()).end().end();
128     }
129   }
130 
131   // --- object basics --------------------------------------------------------
132 
133 }