Add author's line in license
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / adapter / SslCertificateViewAdapter.java
1 /* ownCloud Android client application
2 *
3 * @author masensio
4 * @author David A. Velasco
5 * Copyright (C) 2012-2014 ownCloud Inc.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2,
9 * as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20 package com.owncloud.android.ui.adapter;
21
22 import java.text.DateFormat;
23 import java.util.Date;
24
25 import com.owncloud.android.R;
26 import com.owncloud.android.ui.dialog.SslUntrustedCertDialog;
27 import android.net.http.SslCertificate;
28 import android.view.View;
29 import android.widget.TextView;
30
31 /**
32 * TODO
33 */
34 public class SslCertificateViewAdapter implements SslUntrustedCertDialog.CertificateViewAdapter {
35
36 //private final static String TAG = SslCertificateViewAdapter.class.getSimpleName();
37
38 private SslCertificate mCertificate;
39
40
41 /**
42 * Constructor
43 *
44 * @param
45 */
46 public SslCertificateViewAdapter(SslCertificate certificate) {
47 mCertificate = certificate;
48 }
49
50 @Override
51 public void updateCertificateView(View dialogView) {
52 TextView nullCerView = (TextView) dialogView.findViewById(R.id.null_cert);
53 if (mCertificate != null) {
54 nullCerView.setVisibility(View.GONE);
55 showSubject(mCertificate.getIssuedTo(), dialogView);
56 showIssuer(mCertificate.getIssuedBy(), dialogView);
57 showValidity(mCertificate.getValidNotBeforeDate(), mCertificate.getValidNotAfterDate(), dialogView);
58 hideSignature(dialogView);
59
60 } else {
61 nullCerView.setVisibility(View.VISIBLE);
62 }
63 }
64
65 private void showValidity(Date notBefore, Date notAfter, View dialogView) {
66 TextView fromView = ((TextView)dialogView.findViewById(R.id.value_validity_from));
67 TextView toView = ((TextView)dialogView.findViewById(R.id.value_validity_to));
68 DateFormat dateFormat = DateFormat.getDateInstance();
69 fromView.setText(dateFormat.format(notBefore));
70 toView.setText(dateFormat.format(notAfter));
71 }
72
73
74 private void showSubject(SslCertificate.DName subject, View dialogView) {
75 TextView cnView = ((TextView)dialogView.findViewById(R.id.value_subject_CN));
76 cnView.setText(subject.getCName());
77 cnView.setVisibility(View.VISIBLE);
78
79 TextView oView = ((TextView)dialogView.findViewById(R.id.value_subject_O));
80 oView.setText(subject.getOName());
81 oView.setVisibility(View.VISIBLE);
82
83 TextView ouView = ((TextView)dialogView.findViewById(R.id.value_subject_OU));
84 ouView.setText(subject.getUName());
85 ouView.setVisibility(View.VISIBLE);
86
87 // SslCertificates don't offer this information
88 ((TextView)dialogView.findViewById(R.id.value_subject_C)).setVisibility(View.GONE);
89 ((TextView)dialogView.findViewById(R.id.value_subject_ST)).setVisibility(View.GONE);
90 ((TextView)dialogView.findViewById(R.id.value_subject_L)).setVisibility(View.GONE);
91 ((TextView)dialogView.findViewById(R.id.label_subject_C)).setVisibility(View.GONE);
92 ((TextView)dialogView.findViewById(R.id.label_subject_ST)).setVisibility(View.GONE);
93 ((TextView)dialogView.findViewById(R.id.label_subject_L)).setVisibility(View.GONE);
94 }
95
96
97 private void showIssuer(SslCertificate.DName issuer, View dialogView) {
98 TextView cnView = ((TextView)dialogView.findViewById(R.id.value_issuer_CN));
99 cnView.setText(issuer.getCName());
100 cnView.setVisibility(View.VISIBLE);
101
102 TextView oView = ((TextView)dialogView.findViewById(R.id.value_issuer_O));
103 oView.setText(issuer.getOName());
104 oView.setVisibility(View.VISIBLE);
105
106 TextView ouView = ((TextView)dialogView.findViewById(R.id.value_issuer_OU));
107 ouView.setText(issuer.getUName());
108 ouView.setVisibility(View.VISIBLE);
109
110 // SslCertificates don't offer this information
111 ((TextView)dialogView.findViewById(R.id.value_issuer_C)).setVisibility(View.GONE);
112 ((TextView)dialogView.findViewById(R.id.value_issuer_ST)).setVisibility(View.GONE);
113 ((TextView)dialogView.findViewById(R.id.value_issuer_L)).setVisibility(View.GONE);
114 ((TextView)dialogView.findViewById(R.id.label_issuer_C)).setVisibility(View.GONE);
115 ((TextView)dialogView.findViewById(R.id.label_issuer_ST)).setVisibility(View.GONE);
116 ((TextView)dialogView.findViewById(R.id.label_issuer_L)).setVisibility(View.GONE);
117 }
118
119 private void hideSignature(View dialogView) {
120 ((TextView)dialogView.findViewById(R.id.label_signature)).setVisibility(View.GONE);
121 ((TextView)dialogView.findViewById(R.id.label_signature_algorithm)).setVisibility(View.GONE);
122 ((TextView)dialogView.findViewById(R.id.value_signature_algorithm)).setVisibility(View.GONE);
123 ((TextView)dialogView.findViewById(R.id.value_signature)).setVisibility(View.GONE);
124 }
125
126 }