diff -r c6e1507c0f1e autoupdate.services/src/org/netbeans/modules/autoupdate/services/UpdateLicenseImpl.java --- a/autoupdate.services/src/org/netbeans/modules/autoupdate/services/UpdateLicenseImpl.java Fri Feb 27 16:10:59 2009 +0300 +++ b/autoupdate.services/src/org/netbeans/modules/autoupdate/services/UpdateLicenseImpl.java Mon Mar 02 15:33:51 2009 +0300 @@ -41,6 +41,8 @@ package org.netbeans.modules.autoupdate.services; +import org.netbeans.modules.autoupdate.updateprovider.AutoupdateCatalogCache; + /** * * @author Jiri Rechtacek @@ -52,19 +54,21 @@ /** Creates a new instance of UpdateLicense */ public UpdateLicenseImpl (String licenseName, String agreement) { this.name = licenseName; - this.agreement = agreement; + setAgreement(agreement); } - + public String getName () { return name; } - public String getAgreement () { - return agreement; + public String getAgreement () { + return AutoupdateCatalogCache.getDefault().getLicense(name); } - - public void setAgreement (String content) { - this.agreement = content; + + public void setAgreement (String content) { + if(content!=null) { + AutoupdateCatalogCache.getDefault().storeLicense(name,content); + } } } diff -r c6e1507c0f1e autoupdate.services/src/org/netbeans/modules/autoupdate/updateprovider/AutoupdateCatalogCache.java --- a/autoupdate.services/src/org/netbeans/modules/autoupdate/updateprovider/AutoupdateCatalogCache.java Fri Feb 27 16:10:59 2009 +0300 +++ b/autoupdate.services/src/org/netbeans/modules/autoupdate/updateprovider/AutoupdateCatalogCache.java Mon Mar 02 15:33:51 2009 +0300 @@ -43,6 +43,7 @@ import java.io.BufferedOutputStream; import java.io.File; +import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; @@ -78,7 +79,62 @@ assert cacheDir != null && cacheDir.exists (); return cacheDir; } - + + private File getLicenseDir() { + return new File(getCatalogCache(), "licenses"); + } + private File getLicenseFile(String name) { + return new File(getLicenseDir(), name); + } + + public String getLicense(String name) { + synchronized (name.intern()) { + File file = getLicenseFile(name); + if(!file.exists()) { + return null; + } + try { + FileInputStream fr = new FileInputStream(file); + byte[] buffer = new byte[8192]; + int n = 0; + StringBuilder sb = new StringBuilder(); + while ((n = fr.read(buffer)) != -1) { + sb.append(new String(buffer, 0, n, "utf-8"));//NOI18N + } + return sb.toString(); + } catch (IOException e) { + err.log(Level.INFO, "Can`t read license from file " + file, e); + return null; + } + } + } + + public void storeLicense(String name, String content) { + synchronized (name.intern()) { + File file = getLicenseFile(name); + if (file.exists() || content==null) { + return; + } + + FileOutputStream fw = null; + try { + fw = new FileOutputStream(file); + fw.write(content.getBytes("utf-8")); //NOI18N + } catch (IOException e) { + err.log(Level.INFO, "Can`t write license " + name + " to " + file, e); + } finally { + if (fw != null) { + try { + fw.flush(); + fw.close(); + } catch (IOException e) { + err.log(Level.INFO, "Can`t output stream for " + file, e); + } + } + } + } + } + private void initCacheDirectory () { assert cacheDir == null : "Do initCacheDirectory only once!"; String userDir = System.getProperty("netbeans.user"); // NOI18N @@ -89,6 +145,7 @@ cacheDir = new File(dir, "catalogcache"); // NOI18N } cacheDir.mkdirs(); + getLicenseDir().mkdirs(); err.log (Level.FINE, "getCacheDirectory: " + cacheDir.getPath ()); return; }