KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > security > license > LicensePackage


1 /*
2  * Created on Sep 14, 2003
3  *
4  * To change the template for this generated file go to
5  * Window>Preferences>Java>Code Generation>Code and Comments
6  */

7 package org.jahia.security.license;
8
9 import java.io.BufferedInputStream JavaDoc;
10 import java.io.IOException JavaDoc;
11 import java.io.InputStream JavaDoc;
12 import java.util.ArrayList JavaDoc;
13 import java.util.Iterator JavaDoc;
14
15 import org.jahia.utils.xml.XmlWriter;
16
17 /**
18  * @author loom
19  *
20  * To change the template for this generated type comment go to
21  * Window>Preferences>Java>Code Generation>Code and Comments
22  */

23 public class LicensePackage {
24     private String JavaDoc formatVersion = null;
25     private String JavaDoc productName = null;
26     private String JavaDoc releaseVersion = null;
27     private ArrayList JavaDoc licenses = null;
28
29     /**
30      * @param formatVersion
31      * @param productName
32      * @param releaseVersion
33      * @param licenses
34      */

35     public LicensePackage(
36         String JavaDoc formatVersion,
37         String JavaDoc productName,
38         String JavaDoc releaseVersion,
39         ArrayList JavaDoc licenses) {
40         this.formatVersion = formatVersion;
41         this.productName = productName;
42         this.releaseVersion = releaseVersion;
43         this.licenses = licenses;
44     }
45
46     /**
47      * @return
48      */

49     public String JavaDoc getFormatVersion() {
50         return formatVersion;
51     }
52
53     /**
54      * @return
55      */

56     public ArrayList JavaDoc getLicenses() {
57         return licenses;
58     }
59
60     /**
61      * @return
62      */

63     public String JavaDoc getProductName() {
64         return productName;
65     }
66
67     /**
68      * @return
69      */

70     public String JavaDoc getReleaseVersion() {
71         return releaseVersion;
72     }
73
74     public void toXML(XmlWriter xmlWriter) throws IOException JavaDoc {
75         xmlWriter.writeEntity("license-package");
76         xmlWriter.writeAttribute("format", formatVersion);
77         xmlWriter.writeAttribute("product", productName);
78         xmlWriter.writeAttribute("release", releaseVersion);
79         Iterator JavaDoc licenseIter = licenses.iterator();
80         while (licenseIter.hasNext()) {
81             License curLicense = (License) licenseIter.next();
82             curLicense.toXML(xmlWriter);
83         }
84         xmlWriter.endEntity();
85     }
86
87     public boolean verifyAllSignatures(
88         InputStream JavaDoc keystoreIn,
89         String JavaDoc keystorePassword)
90         throws IOException JavaDoc {
91         BufferedInputStream JavaDoc bufIn = new BufferedInputStream JavaDoc(keystoreIn);
92         bufIn.mark(100000);
93         Iterator JavaDoc licenseIter = licenses.iterator();
94         while (licenseIter.hasNext()) {
95             License curLicense = (License) licenseIter.next();
96             if (!curLicense.verifySignature(bufIn, keystorePassword)) {
97                 return false;
98             }
99             bufIn.reset();
100         }
101         return true;
102     }
103
104     public boolean updateAllSignatures(
105         InputStream JavaDoc keystoreIn,
106         String JavaDoc keystorePassword,
107         String JavaDoc privateKeyAlias,
108         String JavaDoc privateKeyPassword,
109         String JavaDoc certAlias)
110         throws IOException JavaDoc {
111         BufferedInputStream JavaDoc bufIn = new BufferedInputStream JavaDoc(keystoreIn);
112         bufIn.mark(100000);
113         Iterator JavaDoc licenseIter = licenses.iterator();
114         while (licenseIter.hasNext()) {
115             License curLicense = (License) licenseIter.next();
116             curLicense.updateSignature(
117                 bufIn,
118                 keystorePassword,
119                 privateKeyAlias,
120                 privateKeyPassword,
121                 certAlias);
122             bufIn.reset();
123         }
124         return true;
125     }
126
127     public License getLicense(String JavaDoc componentName) {
128         Iterator JavaDoc licenseIter = licenses.iterator();
129         while (licenseIter.hasNext()) {
130             License curLicense = (License) licenseIter.next();
131             if (curLicense.getComponentName().equals(componentName)) {
132                 return curLicense;
133             }
134         }
135         return null;
136     }
137
138 }
139
Popular Tags