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.Paths;
23  import de.smartics.properties.admin.domain.model.Security;
24  import de.smartics.properties.admin.resources.representation.html.share.AbstractHtmlRepresentationRenderer;
25  import de.smartics.resteasy.hypermedia.renderer.LinkDescriptor;
26  
27  /**
28   * Displays an HTML form to encrypt and decrypt property values.
29   */
30  public final class SecurityHtmlRepresentationRenderer extends
31      AbstractHtmlRepresentationRenderer<Security>
32  {
33    // ********************************* Fields *********************************
34  
35    // --- constants ------------------------------------------------------------
36  
37    /**
38     * The title to the page.
39     */
40    private static final String TITLE = "Security Tool";
41  
42    // --- members --------------------------------------------------------------
43  
44    /**
45     * The domain object to render.
46     */
47    private final Security domainObject;
48  
49    // ****************************** Initializer *******************************
50  
51    // ****************************** Constructors ******************************
52  
53    /**
54     * Default constructor.
55     *
56     * @param htmlContext the context information to render the representation.
57     * @param domainObject the domain object to render.
58     * @param entityStream the stream to write to.
59     */
60    public SecurityHtmlRepresentationRenderer(
61        final HtmlResourceContext htmlContext, final Security domainObject,
62        final OutputStream entityStream)
63    {
64      super(htmlContext, entityStream);
65      this.domainObject = domainObject;
66    }
67  
68    // ****************************** Inner Classes *****************************
69  
70    // ********************************* Methods ********************************
71  
72    // --- init -----------------------------------------------------------------
73  
74    // --- get&set --------------------------------------------------------------
75  
76    // --- business -------------------------------------------------------------
77  
78    @Override
79    protected void bodyContents()
80    {
81      renderPageTitle(">>>");
82      html.p()
83          .text(
84              "This form allows to en- and decrypt property values using the"
85                  + " symmetric key deployed with the application.").end();
86  
87      renderForm();
88    }
89  
90    private void renderForm()
91    {
92      html.form().method("POST").classAttr("form-horizontal");
93  
94      html.fieldset().legend().text("En- and decrypt property values").end();
95      renderInputField(Paths.PARAM_SECURITY_ENCRYPT, "Encrypt",
96          domainObject.getPlainText(), "Enter plain text here ...");
97      renderInputField(Paths.PARAM_SECURITY_DECRYPT, "Decrypt",
98          domainObject.getEncryptedText(), "Enter encrypted text here ...");
99      createSubmitButton();
100     html.end();
101 
102     html.end();
103   }
104 
105   private void renderInputField(final String id, final String label,
106       final String value, final String placeholder)
107   {
108     html.div().classAttr("control-group");
109 
110     html.label().classAttr("control-label")
111         .forAttr(Paths.PARAM_SECURITY_ENCRYPT).text(label).end();
112 
113     html.div().classAttr("controls");
114     html.input().type("text").id(id).name(id).classAttr("input-xlarge")
115         .value(value);
116     html.attr("placeholder", placeholder);
117     html.end(3);
118   }
119 
120   private void createSubmitButton()
121   {
122     html.button().type("submit").id("submit").classAttr("btn btn-default");
123     html.text("Submit").end();
124   }
125 
126   @Override
127   protected String getTitle()
128   {
129     return TITLE;
130   }
131 
132   @Override
133   protected List<LinkDescriptor> breadcrumbLinks()
134   {
135     return breadcrumb.security();
136   }
137 
138   // --- object basics --------------------------------------------------------
139 
140 }