KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > applications > packaging > sharehandlers > gui > Controller


1 /*
2  * This software is OSI Certified Open Source Software.
3  * OSI Certified is a certification mark of the Open Source Initiative.
4  * The license (Mozilla version 1.0) can be read at the MMBase site.
5  * See http://www.MMBase.org/license
6  */

7 package org.mmbase.applications.packaging.sharehandlers.gui;
8
9 import java.util.ArrayList JavaDoc;
10 import java.util.Iterator JavaDoc;
11 import java.util.List JavaDoc;
12
13 import org.mmbase.applications.packaging.BundleManager;
14 import org.mmbase.applications.packaging.InstallManager;
15 import org.mmbase.applications.packaging.PackageManager;
16 import org.mmbase.applications.packaging.Person;
17 import org.mmbase.applications.packaging.ShareManager;
18 import org.mmbase.applications.packaging.bundlehandlers.BundleContainer;
19 import org.mmbase.applications.packaging.packagehandlers.PackageContainer;
20 import org.mmbase.applications.packaging.sharehandlers.ShareGroup;
21 import org.mmbase.applications.packaging.sharehandlers.ShareInfo;
22 import org.mmbase.applications.packaging.sharehandlers.ShareUser;
23 import org.mmbase.bridge.Cloud;
24 import org.mmbase.bridge.CloudContext;
25 import org.mmbase.bridge.LocalContext;
26 import org.mmbase.bridge.NodeManager;
27 import org.mmbase.module.core.MMBase;
28 import org.mmbase.module.core.MMObjectNode;
29 import org.mmbase.module.core.VirtualBuilder;
30 import org.mmbase.util.logging.Logger;
31 import org.mmbase.util.logging.Logging;
32
33 /**
34  * @author Daniel Ockeloen
35  * @version $Id: guiController.java
36  */

37 public class Controller {
38
39     private static Logger log = Logging.getLoggerInstance(Controller.class);
40     private static Cloud cloud;
41     NodeManager manager;
42     CloudContext context;
43
44
45     /**
46      *Constructor for the Controller object
47      */

48     public Controller() {
49         cloud = LocalContext.getCloudContext().getCloud("mmbase");
50
51         // hack needs to be solved
52
manager = cloud.getNodeManager("typedef");
53         if (manager == null) {
54             log.error("Can't access builder typedef");
55         }
56         context = LocalContext.getCloudContext();
57         if (!InstallManager.isRunning()) {
58             InstallManager.init();
59         }
60     }
61
62
63     /**
64      * Description of the Method
65      *
66      * @param id Description of the Parameter
67      * @param wv Description of the Parameter
68      * @return Description of the Return Value
69      */

70     public boolean makeShareActive(String JavaDoc id, String JavaDoc wv) {
71         PackageContainer p = null;
72         ShareInfo shareinfo = null;
73         if (wv.equals("best")) {
74             p = (PackageContainer) PackageManager.getPackage(id);
75         } else {
76             // ok lets decode the version and provider we want
77
// p=(PackageContainer)PackageManager.getPackage(id,wv);
78
}
79         if (p != null) {
80             shareinfo = p.getShareInfo();
81         }
82
83         if (shareinfo != null) {
84             shareinfo.setActive(true);
85             ShareManager.writeShareFile();
86             ShareManager.signalRemoteClients();
87         }
88         return true;
89     }
90
91
92     /**
93      * Description of the Method
94      *
95      * @param id Description of the Parameter
96      * @param wv Description of the Parameter
97      * @return Description of the Return Value
98      */

99     public boolean makeShareInactive(String JavaDoc id, String JavaDoc wv) {
100         PackageContainer p = null;
101         ShareInfo shareinfo = null;
102         if (wv.equals("best")) {
103             p = (PackageContainer) PackageManager.getPackage(id);
104         } else {
105             // ok lets decode the version and provider we want
106
// p=(PackageContainer)PackageManager.getPackage(id,wv);
107
}
108         if (p != null) {
109             shareinfo = p.getShareInfo();
110         }
111
112         if (shareinfo != null) {
113             shareinfo.setActive(false);
114             ShareManager.writeShareFile();
115             ShareManager.signalRemoteClients();
116         }
117         return true;
118     }
119
120
121     /**
122      * Gets the sharedPackages attribute of the Controller object
123      *
124      * @return The sharedPackages value
125      */

126     public List JavaDoc getSharedPackages() {
127         // get the current best packages
128
Iterator JavaDoc packages = ShareManager.getSharedPackages();
129
130         List JavaDoc list = new ArrayList JavaDoc();
131         VirtualBuilder builder = new VirtualBuilder(MMBase.getMMBase());
132
133         while (packages.hasNext()) {
134             PackageContainer p = (PackageContainer) packages.next();
135             MMObjectNode virtual = builder.getNewNode("admin");
136             virtual.setValue("id", p.getId());
137             virtual.setValue("name", p.getName());
138             virtual.setValue("type", p.getType());
139             virtual.setValue("maintainer", p.getMaintainer());
140             virtual.setValue("sharedversions", "best");
141
142             ShareInfo shareinfo = p.getShareInfo();
143             if (shareinfo.isActive()) {
144                 virtual.setValue("active", "yes");
145             } else {
146                 virtual.setValue("active", "no");
147             }
148         if (shareinfo.containsUser("guest")) {
149                 virtual.setValue("public", "yes");
150         } else {
151                 virtual.setValue("public", "no");
152         }
153             list.add(virtual);
154         }
155
156         return list;
157     }
158
159
160     /**
161      * Gets the sharedBundles attribute of the Controller object
162      *
163      * @return The sharedBundles value
164      */

165     public List JavaDoc getSharedBundles() {
166         // get the current best packages
167
Iterator JavaDoc bundles = ShareManager.getSharedBundles();
168
169         List JavaDoc list = new ArrayList JavaDoc();
170         VirtualBuilder builder = new VirtualBuilder(MMBase.getMMBase());
171
172         while (bundles.hasNext()) {
173             BundleContainer b = (BundleContainer) bundles.next();
174             MMObjectNode virtual = builder.getNewNode("admin");
175             virtual.setValue("id", b.getId());
176             virtual.setValue("name", b.getName());
177             virtual.setValue("type", b.getType());
178             virtual.setValue("maintainer", b.getMaintainer());
179             virtual.setValue("sharedversions", "best");
180
181             ShareInfo shareinfo = b.getShareInfo();
182             if (shareinfo.isActive()) {
183                 virtual.setValue("active", "yes");
184             } else {
185                 virtual.setValue("active", "no");
186             }
187         if (shareinfo.containsUser("guest")) {
188                 virtual.setValue("public", "yes");
189         } else {
190                 virtual.setValue("public", "no");
191         }
192             list.add(virtual);
193         }
194
195         return list;
196     }
197
198
199     /**
200      * Gets the notSharedPackages attribute of the Controller object
201      *
202      * @return The notSharedPackages value
203      */

204     public List JavaDoc getNotSharedPackages() {
205         // get the current best packages
206
Iterator JavaDoc packages = ShareManager.getNotSharedPackages();
207
208         List JavaDoc list = new ArrayList JavaDoc();
209         VirtualBuilder builder = new VirtualBuilder(MMBase.getMMBase());
210
211         while (packages.hasNext()) {
212             PackageContainer p = (PackageContainer) packages.next();
213             MMObjectNode virtual = builder.getNewNode("admin");
214             virtual.setValue("id", p.getId());
215             virtual.setValue("name", p.getName());
216             virtual.setValue("type", p.getType());
217             virtual.setValue("maintainer", p.getMaintainer());
218             virtual.setValue("sharedversions", "best");
219             list.add(virtual);
220         }
221
222         return list;
223     }
224
225
226     /**
227      * Gets the notSharedBundles attribute of the Controller object
228      *
229      * @return The notSharedBundles value
230      */

231     public List JavaDoc getNotSharedBundles() {
232         // get the current best bundles
233
Iterator JavaDoc bundles = ShareManager.getNotSharedBundles();
234
235         List JavaDoc list = new ArrayList JavaDoc();
236         VirtualBuilder builder = new VirtualBuilder(MMBase.getMMBase());
237
238         while (bundles.hasNext()) {
239             BundleContainer b = (BundleContainer) bundles.next();
240             MMObjectNode virtual = builder.getNewNode("admin");
241             virtual.setValue("id", b.getId());
242             virtual.setValue("name", b.getName());
243             virtual.setValue("type", b.getType());
244             virtual.setValue("maintainer", b.getMaintainer());
245             virtual.setValue("sharedversions", "best");
246             list.add(virtual);
247         }
248         return list;
249     }
250
251
252     /**
253      * Gets the remoteSharedPackages attribute of the Controller object
254      *
255      * @param user Description of the Parameter
256      * @param password Description of the Parameter
257      * @param method Description of the Parameter
258      * @param host Description of the Parameter
259      * @param callbackurl Description of the Parameter
260      * @return The remoteSharedPackages value
261      */

262     public List JavaDoc getRemoteSharedPackages(String JavaDoc user, String JavaDoc password, String JavaDoc method, String JavaDoc host, String JavaDoc callbackurl) {
263         // get the current best packages
264
Iterator JavaDoc packages = ShareManager.getRemoteSharedPackages(user, password, method, host);
265         List JavaDoc list = new ArrayList JavaDoc();
266         VirtualBuilder builder = new VirtualBuilder(MMBase.getMMBase());
267
268         while (packages.hasNext()) {
269             MMObjectNode virtual = builder.getNewNode("admin");
270             Object JavaDoc o = packages.next();
271             if (o instanceof PackageContainer) {
272                 PackageContainer p = (PackageContainer) o;
273                 virtual.setValue("id", p.getId());
274                 virtual.setValue("name", p.getName());
275                 virtual.setValue("type", p.getType());
276                 virtual.setValue("version", p.getVersion());
277                 virtual.setValue("maintainer", p.getMaintainer());
278                 virtual.setValue("creation-date", p.getCreationDate());
279                 virtual.setValue("description", p.getDescription());
280                 virtual.setValue("releasenotes", p.getReleaseNotes());
281                 virtual.setValue("installationnotes", p.getInstallationNotes());
282                 virtual.setValue("licensename", p.getLicenseName());
283                 virtual.setValue("licensetype", p.getLicenseType());
284                 virtual.setValue("licenseversion", p.getLicenseVersion());
285                 virtual.setValue("licensebody", p.getLicenseBody());
286                 String JavaDoc path = ShareManager.getProvidingPath(method) + "/package.mmp?id=" + p.getId() + "&version=" + p.getVersion();
287                 virtual.setValue("path", path);
288                 List JavaDoc l = p.getRelatedPeople("initiators");
289                 if (l != null) {
290                     virtual.setValue("initiators", getRelatedPeopleString(l, "initiators"));
291                 }
292                 l = p.getRelatedPeople("supporters");
293                 if (l != null) {
294                     virtual.setValue("supporters", getRelatedPeopleString(l, "supporters"));
295                 }
296                 l = p.getRelatedPeople("developers");
297                 if (l != null) {
298                     virtual.setValue("developers", getRelatedPeopleString(l, "developers"));
299                 }
300                 l = p.getRelatedPeople("contacts");
301                 if (l != null) {
302                     virtual.setValue("contacts", getRelatedPeopleString(l, "contacts"));
303                 }
304             } else {
305                 BundleContainer p = (BundleContainer) o;
306                 virtual.setValue("id", p.getId());
307                 virtual.setValue("name", p.getName());
308                 virtual.setValue("type", p.getType());
309                 virtual.setValue("version", p.getVersion());
310                 virtual.setValue("creation-date", p.getCreationDate());
311                 virtual.setValue("maintainer", p.getMaintainer());
312                 virtual.setValue("description", p.getDescription());
313                 virtual.setValue("releasenotes", p.getReleaseNotes());
314                 virtual.setValue("installationnotes", p.getInstallationNotes());
315                 virtual.setValue("licensename", p.getLicenseName());
316                 virtual.setValue("licensetype", p.getLicenseType());
317                 virtual.setValue("licenseversion", p.getLicenseVersion());
318                 virtual.setValue("licensebody", p.getLicenseBody());
319                 String JavaDoc path = ShareManager.getProvidingPath(method) + "/package.mmp?id=" + p.getId() + "&version=" + p.getVersion();
320                 virtual.setValue("path", path);
321                 List JavaDoc l = p.getScreenshots();
322                 if (l != null) {
323                     virtual.setValue("screenshots", getRelatedScreenshotsString(l,ShareManager.getProvidingPath(method)));
324                 }
325
326                 l = p.getStarturls();
327                 if (l != null) {
328                     virtual.setValue("starturls", getRelatedStarturlsString(l));
329                 }
330
331                 l = p.getRelatedPeople("initiators");
332                 if (l != null) {
333                     virtual.setValue("initiators", getRelatedPeopleString(l, "initiators"));
334                 }
335                 l = p.getRelatedPeople("supporters");
336                 if (l != null) {
337                     virtual.setValue("supporters", getRelatedPeopleString(l, "supporters"));
338                 }
339                 l = p.getRelatedPeople("developers");
340                 if (l != null) {
341                     virtual.setValue("developers", getRelatedPeopleString(l, "developers"));
342                 }
343                 l = p.getRelatedPeople("contacts");
344                 if (l != null) {
345                     virtual.setValue("contacts", getRelatedPeopleString(l, "contacts"));
346                 }
347             }
348
349             list.add(virtual);
350         }
351
352         // signal we have a client
353
ShareManager.reportClientSession(callbackurl);
354
355         return list;
356     }
357
358
359     /**
360      * Gets the relatedPeopleString attribute of the Controller object
361      *
362      * @param people Description of the Parameter
363      * @param type Description of the Parameter
364      * @return The relatedPeopleString value
365      */

366     public String JavaDoc getRelatedPeopleString(List JavaDoc people, String JavaDoc type) {
367         String JavaDoc body = "";
368         if (people != null) {
369             for (Iterator JavaDoc i = people.iterator(); i.hasNext(); ) {
370                 Person pr = (Person) i.next();
371                 if (type.equals("initiators")) {
372                     body += "\t\t\t<initiator name=\"" + pr.getName() + "\" company=\"" + pr.getCompany() + "\" />\n";
373                 } else if (type.equals("developers")) {
374                     body += "\t\t\t<developer name=\"" + pr.getName() + "\" company=\"" + pr.getCompany() + "\" mailto=\"" + pr.getMailto() + "\" />\n";
375                 } else if (type.equals("contacts")) {
376                     body += "\t\t\t<contact reason=\"" + pr.getReason() + "\" name=\"" + pr.getName() + "\" mailto=\"" + pr.getMailto() + "\" />\n";
377                 } else if (type.equals("supporters")) {
378                     body += "\t\t\t<supporter company=\"" + pr.getCompany() + "\" />\n";
379                 }
380             }
381         }
382         return body;
383     }
384
385     public String JavaDoc getRelatedScreenshotsString(List JavaDoc screenshots,String JavaDoc path) {
386         String JavaDoc body = "";
387     path = path.substring(0,path.length()-31);
388         for (Iterator JavaDoc i = screenshots.iterator(); i.hasNext(); ) {
389                 String JavaDoc name = (String JavaDoc) i.next();
390                 String JavaDoc file = (String JavaDoc) i.next();
391                 String JavaDoc description = (String JavaDoc) i.next();
392                 body += "\t\t\t<screenshot name=\"" + name + "\" file=\"" + path+file + "\">"+description+"</screenshot>\n";
393         }
394         return body;
395     }
396
397
398     public String JavaDoc getRelatedStarturlsString(List JavaDoc starturls) {
399         String JavaDoc body = "";
400         for (Iterator JavaDoc i = starturls.iterator(); i.hasNext(); ) {
401                 String JavaDoc name = (String JavaDoc) i.next();
402                 String JavaDoc link = (String JavaDoc) i.next();
403                 String JavaDoc description = (String JavaDoc) i.next();
404                 body += "\t\t\t<url name=\"" + name + "\" link=\"" + link + "\">"+description+"</url>\n";
405         }
406         return body;
407     }
408
409
410
411     /**
412      * Gets the shareUsers attribute of the Controller object
413      *
414      * @param id Description of the Parameter
415      * @param wv Description of the Parameter
416      * @return The shareUsers value
417      */

418     public List JavaDoc getShareUsers(String JavaDoc id, String JavaDoc wv) {
419         List JavaDoc list = new ArrayList JavaDoc();
420         VirtualBuilder builder = new VirtualBuilder(MMBase.getMMBase());
421
422         ShareInfo shareinfo = null;
423
424         PackageContainer p = null;
425         if (wv.equals("best")) {
426             p = (PackageContainer) PackageManager.getPackage(id);
427         } else {
428             // ok lets decode the version and provider we want
429
// p=(PackageContainer)PackageManager.getPackage(id,wv);
430
}
431
432         if (p != null) {
433             shareinfo = p.getShareInfo();
434         }
435
436         if (shareinfo == null) {
437             BundleContainer b = null;
438             if (wv.equals("best")) {
439                 b = (BundleContainer) BundleManager.getBundle(id);
440             } else {
441                 // ok lets decode the version and provider we want
442
// b=(BundleContainer(BundleManager.getBundle(id,wv);
443
}
444             if (b != null) {
445                 shareinfo = b.getShareInfo();
446             }
447         }
448
449         if (shareinfo != null) {
450             // get the current best packages
451
Iterator JavaDoc users = shareinfo.getShareUsers();
452
453             while (users.hasNext()) {
454                 ShareUser u = (ShareUser) users.next();
455                 MMObjectNode virtual = builder.getNewNode("admin");
456                 virtual.setValue("name", u.getName());
457                 list.add(virtual);
458             }
459         }
460         return list;
461     }
462
463
464     /**
465      * Gets the allUsers attribute of the Controller object
466      *
467      * @return The allUsers value
468      */

469     public List JavaDoc getAllUsers() {
470         List JavaDoc list = new ArrayList JavaDoc();
471         VirtualBuilder builder = new VirtualBuilder(MMBase.getMMBase());
472
473         Iterator JavaDoc users = ShareManager.getShareUsers();
474         while (users.hasNext()) {
475             ShareUser u = (ShareUser) users.next();
476             MMObjectNode virtual = builder.getNewNode("admin");
477             virtual.setValue("name", u.getName());
478             list.add(virtual);
479         }
480         return list;
481     }
482
483
484     /**
485      * Gets the allGroups attribute of the Controller object
486      *
487      * @return The allGroups value
488      */

489     public List JavaDoc getAllGroups() {
490         List JavaDoc list = new ArrayList JavaDoc();
491         VirtualBuilder builder = new VirtualBuilder(MMBase.getMMBase());
492
493         Iterator JavaDoc groups = ShareManager.getShareGroups();
494         while (groups.hasNext()) {
495             ShareGroup g = (ShareGroup) groups.next();
496             MMObjectNode virtual = builder.getNewNode("admin");
497             virtual.setValue("name", g.getName());
498             list.add(virtual);
499         }
500         return list;
501     }
502
503
504     /**
505      * Gets the groupUsers attribute of the Controller object
506      *
507      * @param name Description of the Parameter
508      * @return The groupUsers value
509      */

510     public List JavaDoc getGroupUsers(String JavaDoc name) {
511         List JavaDoc list = new ArrayList JavaDoc();
512         VirtualBuilder builder = new VirtualBuilder(MMBase.getMMBase());
513
514         ShareGroup sg = ShareManager.getShareGroup(name);
515         if (sg != null) {
516             Iterator JavaDoc users = sg.getMembers();
517             while (users.hasNext()) {
518                 ShareUser u = (ShareUser) users.next();
519                 MMObjectNode virtual = builder.getNewNode("admin");
520                 virtual.setValue("name", u.getName());
521                 list.add(virtual);
522             }
523         }
524         return list;
525     }
526
527
528     /**
529      * Adds a feature to the GroupUser attribute of the Controller object
530      *
531      * @param group The feature to be added to the GroupUser attribute
532      * @param user The feature to be added to the GroupUser attribute
533      * @return Description of the Return Value
534      */

535     public boolean addGroupUser(String JavaDoc group, String JavaDoc user) {
536         ShareGroup sg = ShareManager.getShareGroup(group);
537         if (sg != null) {
538             sg.addMember(user);
539             ShareManager.writeShareFile();
540             ShareManager.signalRemoteClients();
541         }
542         return true;
543     }
544
545
546     /**
547      * Description of the Method
548      *
549      * @param group Description of the Parameter
550      * @return Description of the Return Value
551      */

552     public boolean createGroup(String JavaDoc group) {
553         ShareManager.createGroup(group);
554         return true;
555     }
556
557
558     /**
559      * Description of the Method
560      *
561      * @param group Description of the Parameter
562      * @return Description of the Return Value
563      */

564     public boolean removeGroup(String JavaDoc group) {
565         ShareManager.removeGroup(group);
566         return true;
567     }
568
569
570     /**
571      * Description of the Method
572      *
573      * @param group Description of the Parameter
574      * @param user Description of the Parameter
575      * @return Description of the Return Value
576      */

577     public boolean removeGroupUser(String JavaDoc group, String JavaDoc user) {
578         ShareGroup sg = ShareManager.getShareGroup(group);
579         if (sg != null) {
580             sg.removeMember(user);
581             ShareManager.writeShareFile();
582             ShareManager.signalRemoteClients();
583         }
584         return true;
585     }
586
587
588     /**
589      * Gets the shareUsersReverse attribute of the Controller object
590      *
591      * @param id Description of the Parameter
592      * @param wv Description of the Parameter
593      * @return The shareUsersReverse value
594      */

595     public List JavaDoc getShareUsersReverse(String JavaDoc id, String JavaDoc wv) {
596         List JavaDoc list = new ArrayList JavaDoc();
597         VirtualBuilder builder = new VirtualBuilder(MMBase.getMMBase());
598
599         ShareInfo shareinfo = null;
600
601         PackageContainer p = null;
602         if (wv.equals("best")) {
603             p = (PackageContainer) PackageManager.getPackage(id);
604         } else {
605             // ok lets decode the version and provider we want
606
// p=(PackageContainer)PackageManager.getPackage(id,wv);
607
}
608         if (p != null) {
609             shareinfo = p.getShareInfo();
610         }
611
612         if (shareinfo == null) {
613             BundleContainer b = null;
614             if (wv.equals("best")) {
615                 b = (BundleContainer) BundleManager.getBundle(id);
616             } else {
617                 // ok lets decode the version and provider we want
618
// b=(BundleContainer(BundleManager.getBundle(id,wv);
619
}
620             if (b != null) {
621                 shareinfo = b.getShareInfo();
622             }
623         }
624
625         if (shareinfo != null) {
626             // get the current best packages
627
Iterator JavaDoc users = ShareManager.getShareUsers();
628
629             while (users.hasNext()) {
630                 ShareUser u = (ShareUser) users.next();
631                 if (!shareinfo.containsUser(u.getName())) {
632                     MMObjectNode virtual = builder.getNewNode("admin");
633                     virtual.setValue("name", u.getName());
634                     list.add(virtual);
635                 }
636             }
637         }
638         return list;
639     }
640
641
642     /**
643      * Description of the Method
644      *
645      * @param name Description of the Parameter
646      * @return Description of the Return Value
647      */

648     public boolean delUser(String JavaDoc name) {
649         String JavaDoc result = ShareManager.delUser(name);
650         if (result != null) {
651             //virtual.setValue("feedback",result);
652
return false;
653         }
654         ShareManager.writeShareFile();
655         ShareManager.signalRemoteClients();
656         return true;
657     }
658
659
660     /**
661      * Adds a feature to the ShareUser attribute of the Controller object
662      *
663      * @param id The feature to be added to the ShareUser attribute
664      * @param wv The feature to be added to the ShareUser attribute
665      * @param newuser The feature to be added to the ShareUser attribute
666      * @return Description of the Return Value
667      */

668     public boolean addShareUser(String JavaDoc id, String JavaDoc wv, String JavaDoc newuser) {
669
670         ShareInfo shareinfo = null;
671
672         PackageContainer p = null;
673         if (wv.equals("best")) {
674             p = (PackageContainer) PackageManager.getPackage(id);
675         } else {
676             // ok lets decode the version and provider we want
677
// p=(PackageContainer)PackageManager.getPackage(id,wv);
678
}
679         if (p != null) {
680             shareinfo = p.getShareInfo();
681         }
682
683         if (shareinfo == null) {
684             // well maybe its a bundle ?
685
BundleContainer b = (BundleContainer) BundleManager.getBundle(id);
686             if (b != null) {
687                 shareinfo = b.getShareInfo();
688             }
689         }
690
691         if (shareinfo != null) {
692             // get the current best packages
693
shareinfo.addUser(newuser);
694             ShareManager.writeShareFile();
695             ShareManager.signalRemoteClients();
696         }
697         return true;
698     }
699
700
701     /**
702      * Adds a feature to the ShareGroup attribute of the Controller object
703      *
704      * @param id The feature to be added to the ShareGroup attribute
705      * @param wv The feature to be added to the ShareGroup attribute
706      * @param newgroup The feature to be added to the ShareGroup attribute
707      * @return Description of the Return Value
708      */

709     public boolean addShareGroup(String JavaDoc id, String JavaDoc wv, String JavaDoc newgroup) {
710
711         ShareInfo shareinfo = null;
712
713         PackageContainer p = null;
714         if (wv.equals("best")) {
715             p = (PackageContainer) PackageManager.getPackage(id);
716         } else {
717             // ok lets decode the version and provider we want
718
// p=(PackageContainer)PackageManager.getPackage(id,wv);
719
}
720         if (p != null) {
721             shareinfo = p.getShareInfo();
722         }
723
724         if (shareinfo == null) {
725             // well maybe its a bundle ?
726
BundleContainer b = (BundleContainer) BundleManager.getBundle(id);
727             if (b != null) {
728                 shareinfo = b.getShareInfo();
729             }
730         }
731
732         if (shareinfo != null) {
733             // get the current best packages
734
shareinfo.addGroup(newgroup);
735             ShareManager.writeShareFile();
736             ShareManager.signalRemoteClients();
737         }
738         return true;
739     }
740
741
742     /**
743      * Description of the Method
744      *
745      * @param account Description of the Parameter
746      * @param password Description of the Parameter
747      * @param method Description of the Parameter
748      * @param ip Description of the Parameter
749      * @return Description of the Return Value
750      */

751     public boolean createNewUser(String JavaDoc account, String JavaDoc password, String JavaDoc method, String JavaDoc ip) {
752         String JavaDoc result = ShareManager.createNewUser(account, password, method, ip);
753         if (result != null) {
754             //virtual.setStringValue("feedback",result);
755
return false;
756         }
757         ShareManager.writeShareFile();
758         ShareManager.signalRemoteClients();
759         return true;
760     }
761
762
763     /**
764      * Adds a feature to the Share attribute of the Controller object
765      *
766      * @param id The feature to be added to the Share attribute
767      * @return Description of the Return Value
768      */

769     public boolean addShare(String JavaDoc id) {
770         PackageContainer p = (PackageContainer) PackageManager.getPackage(id);
771         if (p != null) {
772             ShareInfo shareinfo = p.getShareInfo();
773             if (shareinfo == null) {
774                 shareinfo = new ShareInfo();
775                 shareinfo.setActive(true);
776                 p.setShareInfo(shareinfo);
777                 ShareManager.writeShareFile();
778                 ShareManager.signalRemoteClients();
779             }
780             //virtual.setStringValue("feedback","Package shared don't forget to add users/groups");
781
} else {
782             //virtual.setStringValue("feedback","Package you want to share is not available anymore");
783
return false;
784         }
785         return true;
786     }
787
788
789     /**
790      * Adds a feature to the BundleShare attribute of the Controller object
791      *
792      * @param id The feature to be added to the BundleShare attribute
793      * @return Description of the Return Value
794      */

795     public boolean addBundleShare(String JavaDoc id) {
796         BundleContainer b = (BundleContainer) BundleManager.getBundle(id);
797         if (b != null) {
798             ShareInfo shareinfo = b.getShareInfo();
799             if (shareinfo == null) {
800                 shareinfo = new ShareInfo();
801                 shareinfo.setActive(true);
802                 b.setShareInfo(shareinfo);
803                 ShareManager.writeShareFile();
804                 ShareManager.signalRemoteClients();
805             }
806             //virtual.setStringValue("feedback","Bundle shared don't forget to add users/groups");
807
} else {
808             //virtual.setStringValue("feedback","Bundle you want to share is not available anymore");
809
return false;
810         }
811         return true;
812     }
813
814
815     /**
816      * Description of the Method
817      *
818      * @param id Description of the Parameter
819      * @return Description of the Return Value
820      */

821     public boolean delShare(String JavaDoc id) {
822         PackageContainer p = (PackageContainer) PackageManager.getPackage(id);
823         if (p != null) {
824             ShareInfo shareinfo = p.getShareInfo();
825             if (shareinfo != null) {
826                 p.removeShare();
827                 ShareManager.writeShareFile();
828                 ShareManager.signalRemoteClients();
829             }
830         } else {
831             return false;
832         }
833         return true;
834     }
835
836
837     /**
838      * Description of the Method
839      *
840      * @param id Description of the Parameter
841      * @return Description of the Return Value
842      */

843     public boolean delBundleShare(String JavaDoc id) {
844
845         BundleContainer b = (BundleContainer) BundleManager.getBundle(id);
846         if (b != null) {
847             ShareInfo shareinfo = b.getShareInfo();
848             if (shareinfo != null) {
849                 b.removeShare();
850                 ShareManager.writeShareFile();
851                 ShareManager.signalRemoteClients();
852             }
853         } else {
854             return false;
855         }
856         return true;
857     }
858
859
860     /**
861      * Description of the Method
862      *
863      * @param id Description of the Parameter
864      * @param wv Description of the Parameter
865      * @param olduser Description of the Parameter
866      * @return Description of the Return Value
867      */

868     public boolean removeShareUser(String JavaDoc id, String JavaDoc wv, String JavaDoc olduser) {
869
870         ShareInfo shareinfo = null;
871
872         PackageContainer p = null;
873         if (wv.equals("best")) {
874             p = (PackageContainer) PackageManager.getPackage(id);
875         } else {
876             // ok lets decode the version and provider we want
877
// p=(PackageContainer)PackageManager.getPackage(id,wv);
878
}
879         if (p != null) {
880             shareinfo = p.getShareInfo();
881         }
882
883         if (shareinfo == null) {
884             // well maybe its a bundle ?
885
BundleContainer b = (BundleContainer) BundleManager.getBundle(id);
886             if (b != null) {
887                 shareinfo = b.getShareInfo();
888             }
889         }
890
891         if (shareinfo != null) {
892             shareinfo.removeUser(olduser);
893             ShareManager.writeShareFile();
894             ShareManager.signalRemoteClients();
895         }
896         return true;
897     }
898
899
900     /**
901      * Description of the Method
902      *
903      * @param id Description of the Parameter
904      * @param wv Description of the Parameter
905      * @param delgroup Description of the Parameter
906      * @return Description of the Return Value
907      */

908     public boolean removeShareGroup(String JavaDoc id, String JavaDoc wv, String JavaDoc delgroup) {
909
910         ShareInfo shareinfo = null;
911
912         PackageContainer p = null;
913         if (wv.equals("best")) {
914             p = (PackageContainer) PackageManager.getPackage(id);
915         } else {
916             // ok lets decode the version and provider we want
917
// p=(PackageContainer)PackageManager.getPackage(id,wv);
918
}
919         if (p != null) {
920             shareinfo = p.getShareInfo();
921         }
922
923         if (shareinfo == null) {
924             // well maybe its a bundle ?
925
BundleContainer b = (BundleContainer) BundleManager.getBundle(id);
926             if (b != null) {
927                 shareinfo = b.getShareInfo();
928             }
929         }
930
931         if (shareinfo != null) {
932             shareinfo.removeGroup(delgroup);
933             ShareManager.writeShareFile();
934             ShareManager.signalRemoteClients();
935         }
936         return true;
937     }
938
939
940     /**
941      * Gets the shareGroups attribute of the Controller object
942      *
943      * @param id Description of the Parameter
944      * @param wv Description of the Parameter
945      * @return The shareGroups value
946      */

947     public List JavaDoc getShareGroups(String JavaDoc id, String JavaDoc wv) {
948         List JavaDoc list = new ArrayList JavaDoc();
949         VirtualBuilder builder = new VirtualBuilder(MMBase.getMMBase());
950
951         ShareInfo shareinfo = null;
952
953         PackageContainer p = null;
954         if (wv.equals("best")) {
955             p = (PackageContainer) PackageManager.getPackage(id);
956         } else {
957             // ok lets decode the version and provider we want
958
// p=(PackageContainer)PackageManager.getPackage(id,wv);
959
}
960         if (p != null) {
961             shareinfo = p.getShareInfo();
962         }
963
964         if (shareinfo == null) {
965             BundleContainer b = null;
966             if (wv.equals("best")) {
967                 b = (BundleContainer) BundleManager.getBundle(id);
968             } else {
969                 // ok lets decode the version and provider we want
970
// b=(BundleContainer(BundleManager.getBundle(id,wv);
971
}
972             if (b != null) {
973                 shareinfo = b.getShareInfo();
974             }
975         }
976
977         if (shareinfo != null) {
978             // get the current best packages
979
Iterator JavaDoc groups = shareinfo.getShareGroups();
980
981             while (groups.hasNext()) {
982                 ShareGroup g = (ShareGroup) groups.next();
983                 MMObjectNode virtual = builder.getNewNode("admin");
984                 virtual.setValue("name", g.getName());
985                 list.add(virtual);
986             }
987         }
988         return list;
989     }
990
991
992     /**
993      * Gets the shareGroupsReverse attribute of the Controller object
994      *
995      * @param id Description of the Parameter
996      * @param wv Description of the Parameter
997      * @return The shareGroupsReverse value
998      */

999     public List JavaDoc getShareGroupsReverse(String JavaDoc id, String JavaDoc wv) {
1000        List JavaDoc list = new ArrayList JavaDoc();
1001        VirtualBuilder builder = new VirtualBuilder(MMBase.getMMBase());
1002
1003        ShareInfo shareinfo = null;
1004
1005        PackageContainer p = null;
1006        if (wv.equals("best")) {
1007            p = (PackageContainer) PackageManager.getPackage(id);
1008        } else {
1009            // ok lets decode the version and provider we want
1010
// p=(PackageContainer)PackageManager.getPackage(id,wv);
1011
}
1012        if (p != null) {
1013            shareinfo = p.getShareInfo();
1014        }
1015
1016        if (shareinfo == null) {
1017            BundleContainer b = null;
1018            if (wv.equals("best")) {
1019                b = (BundleContainer) BundleManager.getBundle(id);
1020            } else {
1021                // ok lets decode the version and provider we want
1022
// b=(BundleContainer(BundleManager.getBundle(id,wv);
1023
}
1024            if (b != null) {
1025                shareinfo = b.getShareInfo();
1026            }
1027        }
1028
1029        if (shareinfo != null) {
1030            // get the current best packages
1031
Iterator JavaDoc groups = ShareManager.getShareGroups();
1032
1033            while (groups.hasNext()) {
1034                ShareGroup g = (ShareGroup) groups.next();
1035                MMObjectNode virtual = builder.getNewNode("admin");
1036                if (!shareinfo.containsGroup(g.getName())) {
1037                    virtual.setValue("name", g.getName());
1038                    list.add(virtual);
1039                }
1040            }
1041        }
1042        return list;
1043    }
1044
1045
1046    /**
1047     * Gets the shareInfo attribute of the Controller object
1048     *
1049     * @param id Description of the Parameter
1050     * @param wv Description of the Parameter
1051     * @return The shareInfo value
1052     */

1053    public MMObjectNode getShareInfo(String JavaDoc id, String JavaDoc wv) {
1054        VirtualBuilder builder = new VirtualBuilder(MMBase.getMMBase());
1055
1056        MMObjectNode virtual = builder.getNewNode("admin");
1057
1058        if (wv.equals("best")) {
1059            PackageContainer p = (PackageContainer) PackageManager.getPackage(id);
1060            if (p != null) {
1061                virtual.setValue("name", p.getName());
1062                virtual.setValue("maintainer", "" + p.getMaintainer());
1063                virtual.setValue("type", p.getType());
1064
1065                ShareInfo scaninfo = p.getShareInfo();
1066                if (scaninfo != null) {
1067                    if (scaninfo.isActive()) {
1068                        virtual.setValue("active", "yes");
1069                    } else {
1070                        virtual.setValue("active", "no");
1071                    }
1072                }
1073            } else {
1074                // well maybe its a bundle ?
1075
BundleContainer b = (BundleContainer) BundleManager.getBundle(id);
1076                if (b != null) {
1077                    virtual.setValue("name", b.getName());
1078                    virtual.setValue("maintainer", "" + b.getMaintainer());
1079                    virtual.setValue("type", b.getType());
1080
1081                    ShareInfo scaninfo = b.getShareInfo();
1082                    if (scaninfo != null) {
1083                        if (scaninfo.isActive()) {
1084                            virtual.setValue("active", "yes");
1085                        } else {
1086                            virtual.setValue("active", "no");
1087                        }
1088                    }
1089                }
1090            }
1091        }
1092        return virtual;
1093    }
1094
1095
1096
1097    /**
1098     * Gets the bundleShareInfo attribute of the Controller object
1099     *
1100     * @param id Description of the Parameter
1101     * @param wv Description of the Parameter
1102     * @return The bundleShareInfo value
1103     */

1104    public List JavaDoc getBundleShareInfo(String JavaDoc id, String JavaDoc wv) {
1105        List JavaDoc list = new ArrayList JavaDoc();
1106        VirtualBuilder builder = new VirtualBuilder(MMBase.getMMBase());
1107        MMObjectNode virtual = builder.getNewNode("admin");
1108
1109        if (wv.equals("best")) {
1110            BundleContainer b = (BundleContainer) BundleManager.getBundle(id);
1111            if (b != null) {
1112                virtual.setValue("name", b.getName());
1113                virtual.setValue("maintainer", "" + b.getMaintainer());
1114                virtual.setValue("type", b.getType());
1115
1116                ShareInfo scaninfo = b.getShareInfo();
1117                if (scaninfo != null) {
1118                    if (scaninfo.isActive()) {
1119                        virtual.setValue("active", "yes");
1120                    } else {
1121                        virtual.setValue("active", "no");
1122                    }
1123                }
1124            }
1125        }
1126        list.add(virtual);
1127        return list;
1128    }
1129
1130
1131    /**
1132     * Gets the userInfo attribute of the Controller object
1133     *
1134     * @param account Description of the Parameter
1135     * @return The userInfo value
1136     */

1137    public List JavaDoc getUserInfo(String JavaDoc account) {
1138        List JavaDoc list = new ArrayList JavaDoc();
1139        VirtualBuilder builder = new VirtualBuilder(MMBase.getMMBase());
1140        MMObjectNode virtual = builder.getNewNode("admin");
1141
1142        ShareUser user = ShareManager.getShareUser(account);
1143        if (user != null) {
1144            virtual.setValue("account", user.getName());
1145            virtual.setValue("password", user.getPassword());
1146            virtual.setValue("method", user.getMethod());
1147            String JavaDoc host = user.getHost();
1148            if (host != null) {
1149                virtual.setValue("host", user.getHost());
1150            } else {
1151                virtual.setValue("host", "none");
1152            }
1153        }
1154        list.add(virtual);
1155        return list;
1156    }
1157
1158
1159}
1160
Popular Tags