1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.crypto.pkix.params.x509certificate.extension

File X509URI.java

 

Coverage histogram

../../../../../../../img/srcFileCovDistChart9.png
38% of files have more coverage

Code metrics

2
29
7
1
139
74
12
0.41
4.14
7
1.71

Classes

Class Line # Actions
X509URI 37 29 0% 12 7
0.8157894681.6%
 

Contributing tests

This file is covered by 1 test. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.crypto.pkix.params.x509certificate.extension;
21   
22    import java.net.MalformedURLException;
23    import java.net.URI;
24    import java.net.URISyntaxException;
25    import java.net.URL;
26   
27    import org.bouncycastle.asn1.DERIA5String;
28    import org.bouncycastle.asn1.x509.GeneralName;
29    import org.xwiki.crypto.pkix.internal.extension.BcGeneralName;
30   
31    /**
32    * Uniform Resource Identifier general name.
33    *
34    * @version $Id: b6ffe74a22a95353f6bef4765809b41fec7881a5 $
35    * @since 5.4
36    */
 
37    public class X509URI implements X509StringGeneralName, BcGeneralName
38    {
39    private final String str;
40   
41    private final URI uri;
42   
43    private final URL url;
44   
45    /**
46    * Constructs a uniform resource locator general name by parsing the given string.
47    *
48    * @param str the string to be parsed into a URI
49    */
 
50  3 toggle public X509URI(String str)
51    {
52  3 String newStr = null;
53  3 URI newUri = null;
54  3 URL newUrl = null;
55   
56  3 try {
57  3 newUri = new URI(str);
58  3 newUrl = newUri.toURL();
59  3 newStr = newUrl.toString();
60  3 newUri = newUrl.toURI();
61    } catch (URISyntaxException e) {
62  0 try {
63  0 newUrl = new URL(str);
64  0 newStr = newUrl.toString();
65    } catch (MalformedURLException e1) {
66  0 newStr = str;
67    }
68    } catch (MalformedURLException e) {
69  0 newStr = newUri.toASCIIString();
70    }
71   
72  3 this.str = newStr;
73  3 this.uri = newUri;
74  3 this.url = newUrl;
75    }
76   
77    /**
78    * Construct a uniform resource locator general name from an URL.
79    *
80    * @param url the url.
81    */
 
82  1 toggle public X509URI(URL url)
83    {
84  1 this.str = url.toString();
85  1 this.url = url;
86   
87  1 URI newUri = null;
88  1 try {
89  1 newUri = url.toURI();
90    } catch (URISyntaxException e) {
91    // Ignored
92    }
93   
94  1 this.uri = newUri;
95    }
96   
97    /**
98    * Create a new instance from a Bouncy Castle general name.
99    *
100    * @param name the Bouncy Castle general name.
101    */
 
102  2 toggle public X509URI(GeneralName name)
103    {
104  2 this(DERIA5String.getInstance(name.getName()).getString());
105   
106  2 if (name.getTagNo() != GeneralName.uniformResourceIdentifier) {
107  0 throw new IllegalArgumentException("Incompatible general name: " + name.getTagNo());
108    }
109    }
110   
111    /**
112    * @return the URL represented by this general name, or null if this name is malformed URL or the protocol handler
113    * is missing.
114    */
 
115  2 toggle public URL getURL()
116    {
117  2 return this.url;
118    }
119   
120    /**
121    * @return the URI represented by this general name, or null if this name violates RFC 2396.
122    */
 
123  2 toggle public URI getURI()
124    {
125  2 return this.uri;
126    }
127   
 
128  2 toggle @Override
129    public String getName()
130    {
131  2 return this.str;
132    }
133   
 
134  2 toggle @Override
135    public GeneralName getGeneralName()
136    {
137  2 return new GeneralName(GeneralName.uniformResourceIdentifier, this.str);
138    }
139    }