This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 148324
Collapse All | Expand All

(-)a/autoupdate.services/src/org/netbeans/modules/autoupdate/services/UpdateLicenseImpl.java (-7 / +11 lines)
Lines 41-46 Link Here
41
41
42
package org.netbeans.modules.autoupdate.services;
42
package org.netbeans.modules.autoupdate.services;
43
43
44
import org.netbeans.modules.autoupdate.updateprovider.AutoupdateCatalogCache;
45
44
/**
46
/**
45
 *
47
 *
46
 * @author Jiri Rechtacek
48
 * @author Jiri Rechtacek
Lines 52-70 Link Here
52
    /** Creates a new instance of UpdateLicense */
54
    /** Creates a new instance of UpdateLicense */
53
    public UpdateLicenseImpl (String licenseName, String agreement) {
55
    public UpdateLicenseImpl (String licenseName, String agreement) {
54
        this.name = licenseName;
56
        this.name = licenseName;
55
        this.agreement = agreement;
57
        setAgreement(agreement);
56
    }
58
    }
57
    
59
58
    public String getName () {
60
    public String getName () {
59
        return name;
61
        return name;
60
    }
62
    }
61
    
63
    
62
    public String getAgreement () {
64
    public String getAgreement () {        
63
        return agreement;
65
        return AutoupdateCatalogCache.getDefault().getLicense(name);
64
    }
66
    }
65
    
67
66
    public void setAgreement (String content) {
68
    public void setAgreement (String content) {       
67
        this.agreement = content;
69
       if(content!=null) {
70
           AutoupdateCatalogCache.getDefault().storeLicense(name,content);
71
       }       
68
    }
72
    }
69
    
73
    
70
}
74
}
(-)a/autoupdate.services/src/org/netbeans/modules/autoupdate/updateprovider/AutoupdateCatalogCache.java (-1 / +58 lines)
Lines 43-48 Link Here
43
43
44
import java.io.BufferedOutputStream;
44
import java.io.BufferedOutputStream;
45
import java.io.File;
45
import java.io.File;
46
import java.io.FileInputStream;
46
import java.io.FileOutputStream;
47
import java.io.FileOutputStream;
47
import java.io.IOException;
48
import java.io.IOException;
48
import java.io.InputStream;
49
import java.io.InputStream;
Lines 78-84 Link Here
78
        assert cacheDir != null && cacheDir.exists ();
79
        assert cacheDir != null && cacheDir.exists ();
79
        return cacheDir;
80
        return cacheDir;
80
    }
81
    }
81
    
82
83
    private File getLicenseDir() {
84
        return new File(getCatalogCache(), "licenses");
85
    }
86
    private File getLicenseFile(String name) {
87
        return new File(getLicenseDir(), name);
88
    }
89
90
    public String getLicense(String name) {
91
        synchronized (name.intern()) {
92
            File file = getLicenseFile(name);
93
            if(!file.exists()) {
94
                return null;
95
            }
96
            try {
97
                FileInputStream fr = new FileInputStream(file);
98
                byte[] buffer = new byte[8192];
99
                int n = 0;
100
                StringBuilder sb = new StringBuilder();
101
                while ((n = fr.read(buffer)) != -1) {
102
                    sb.append(new String(buffer, 0, n, "utf-8"));//NOI18N
103
                }
104
                return sb.toString();
105
            } catch (IOException e) {
106
                err.log(Level.INFO, "Can`t read license from file " + file, e);
107
                return null;
108
            }
109
        }
110
    }
111
112
    public void storeLicense(String name, String content) {
113
        synchronized (name.intern()) {
114
            File file = getLicenseFile(name);
115
            if (file.exists() || content==null) {
116
                return;
117
            }
118
119
            FileOutputStream fw = null;
120
            try {
121
                fw = new FileOutputStream(file);
122
                fw.write(content.getBytes("utf-8")); //NOI18N
123
            } catch (IOException e) {
124
                err.log(Level.INFO, "Can`t write license " + name + " to " + file, e);
125
            } finally {
126
                if (fw != null) {
127
                    try {
128
                        fw.flush();
129
                        fw.close();
130
                    } catch (IOException e) {
131
                        err.log(Level.INFO, "Can`t output stream for " + file, e);
132
                    }
133
                }
134
            }
135
        }
136
    }
137
82
    private void initCacheDirectory () {
138
    private void initCacheDirectory () {
83
        assert cacheDir == null : "Do initCacheDirectory only once!";
139
        assert cacheDir == null : "Do initCacheDirectory only once!";
84
        String userDir = System.getProperty("netbeans.user"); // NOI18N
140
        String userDir = System.getProperty("netbeans.user"); // NOI18N
Lines 89-94 Link Here
89
            cacheDir = new File(dir, "catalogcache"); // NOI18N
145
            cacheDir = new File(dir, "catalogcache"); // NOI18N
90
        }
146
        }
91
        cacheDir.mkdirs();
147
        cacheDir.mkdirs();
148
        getLicenseDir().mkdirs();
92
        err.log (Level.FINE, "getCacheDirectory: " + cacheDir.getPath ());
149
        err.log (Level.FINE, "getCacheDirectory: " + cacheDir.getPath ());
93
        return;
150
        return;
94
    }
151
    }

Return to bug 148324