Source Code Cross Referenced for AdminSitesAction.java in  » ERP-CRM-Financial » sakai » org » sakaiproject » site » tool » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ERP CRM Financial » sakai » org.sakaiproject.site.tool 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /**********************************************************************************
0002:         * $URL: https://source.sakaiproject.org/svn/site/tags/sakai_2-4-1/site-tool/tool/src/java/org/sakaiproject/site/tool/AdminSitesAction.java $
0003:         * $Id: AdminSitesAction.java 19627 2006-12-16 02:38:02Z ggolden@umich.edu $
0004:         ***********************************************************************************
0005:         *
0006:         * Copyright (c) 2003, 2004, 2005, 2006 The Sakai Foundation.
0007:         * 
0008:         * Licensed under the Educational Community License, Version 1.0 (the "License"); 
0009:         * you may not use this file except in compliance with the License. 
0010:         * You may obtain a copy of the License at
0011:         * 
0012:         *      http://www.opensource.org/licenses/ecl1.php
0013:         * 
0014:         * Unless required by applicable law or agreed to in writing, software 
0015:         * distributed under the License is distributed on an "AS IS" BASIS, 
0016:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
0017:         * See the License for the specific language governing permissions and 
0018:         * limitations under the License.
0019:         *
0020:         **********************************************************************************/package org.sakaiproject.site.tool;
0021:
0022:        import java.util.Collection;
0023:        import java.util.Collections;
0024:        import java.util.Enumeration;
0025:        import java.util.HashSet;
0026:        import java.util.Iterator;
0027:        import java.util.List;
0028:        import java.util.Set;
0029:        import java.util.Vector;
0030:
0031:        import org.sakaiproject.authz.api.AuthzGroup;
0032:        import org.sakaiproject.authz.api.GroupNotDefinedException;
0033:        import org.sakaiproject.authz.api.Role;
0034:        import org.sakaiproject.authz.cover.AuthzGroupService;
0035:        import org.sakaiproject.authz.cover.SecurityService;
0036:        import org.sakaiproject.cheftool.Context;
0037:        import org.sakaiproject.cheftool.JetspeedRunData;
0038:        import org.sakaiproject.cheftool.PagedResourceActionII;
0039:        import org.sakaiproject.cheftool.RunData;
0040:        import org.sakaiproject.cheftool.VelocityPortlet;
0041:        import org.sakaiproject.cheftool.api.Menu;
0042:        import org.sakaiproject.cheftool.api.MenuItem;
0043:        import org.sakaiproject.cheftool.menu.MenuDivider;
0044:        import org.sakaiproject.cheftool.menu.MenuEntry;
0045:        import org.sakaiproject.cheftool.menu.MenuField;
0046:        import org.sakaiproject.cheftool.menu.MenuImpl;
0047:        import org.sakaiproject.courier.api.ObservingCourier;
0048:        import org.sakaiproject.entity.api.ResourcePropertiesEdit;
0049:        import org.sakaiproject.event.api.SessionState;
0050:        import org.sakaiproject.exception.IdInvalidException;
0051:        import org.sakaiproject.exception.IdUnusedException;
0052:        import org.sakaiproject.exception.IdUsedException;
0053:        import org.sakaiproject.exception.PermissionException;
0054:        import org.sakaiproject.javax.PagingPosition;
0055:        import org.sakaiproject.site.api.Group;
0056:        import org.sakaiproject.site.api.Site;
0057:        import org.sakaiproject.site.api.SitePage;
0058:        import org.sakaiproject.site.api.ToolConfiguration;
0059:        import org.sakaiproject.site.cover.SiteService;
0060:        import org.sakaiproject.tool.api.Session;
0061:        import org.sakaiproject.tool.api.Tool;
0062:        import org.sakaiproject.tool.api.ToolSession;
0063:        import org.sakaiproject.tool.cover.SessionManager;
0064:        import org.sakaiproject.tool.cover.ToolManager;
0065:        import org.sakaiproject.util.ResourceLoader;
0066:        import org.sakaiproject.util.StringUtil;
0067:
0068:        /**
0069:         * <p>
0070:         * SitesAction is the Sakai admin sites editor.
0071:         * </p>
0072:         */
0073:        public class AdminSitesAction extends PagedResourceActionII {
0074:            /** State holding the site id for site id search. */
0075:            protected static final String STATE_SEARCH_SITE_ID = "search_site";
0076:
0077:            /** State holding the user id for user id search. */
0078:            protected static final String STATE_SEARCH_USER_ID = "search_user";
0079:
0080:            protected static final String FORM_SEARCH_SITEID = "search_site";
0081:
0082:            protected static final String FORM_SEARCH_USERID = "search_user";
0083:
0084:            private static ResourceLoader rb = new ResourceLoader("admin");
0085:
0086:            /**
0087:             * {@inheritDoc}
0088:             */
0089:            protected List readResourcesPage(SessionState state, int first,
0090:                    int last) {
0091:                // search?
0092:                String search = StringUtil.trimToNull((String) state
0093:                        .getAttribute(STATE_SEARCH));
0094:                String siteId = StringUtil.trimToNull((String) state
0095:                        .getAttribute(STATE_SEARCH_SITE_ID));
0096:                String userId = StringUtil.trimToNull((String) state
0097:                        .getAttribute(STATE_SEARCH_USER_ID));
0098:
0099:                // Boolean userOnly = (Boolean) state.getAttribute(STATE_SEARCH_USER);
0100:
0101:                // if site id specified, use that
0102:                if (siteId != null) {
0103:                    List rv = new Vector();
0104:                    try {
0105:                        Site site = SiteService.getSite(siteId);
0106:                        rv.add(site);
0107:                    } catch (IdUnusedException e) {
0108:                    }
0109:
0110:                    return rv;
0111:                }
0112:
0113:                // if userId specified, use that
0114:                else if (userId != null) {
0115:                    List rv = new Vector();
0116:                    try {
0117:                        Site userSite = SiteService.getSite(SiteService
0118:                                .getUserSiteId(userId));
0119:                        rv.add(userSite);
0120:                    } catch (IdUnusedException e) {
0121:                    }
0122:
0123:                    return rv;
0124:                }
0125:
0126:                // search for non-user sites, using the criteria
0127:                else if (search != null) {
0128:                    return SiteService
0129:                            .getSites(
0130:                                    org.sakaiproject.site.api.SiteService.SelectionType.NON_USER,
0131:                                    null,
0132:                                    search,
0133:                                    null,
0134:                                    org.sakaiproject.site.api.SiteService.SortType.TITLE_ASC,
0135:                                    new PagingPosition(first, last));
0136:                }
0137:
0138:                // otherwise just show a page of all
0139:                else {
0140:                    return SiteService
0141:                            .getSites(
0142:                                    org.sakaiproject.site.api.SiteService.SelectionType.ANY,
0143:                                    null,
0144:                                    search,
0145:                                    null,
0146:                                    org.sakaiproject.site.api.SiteService.SortType.TITLE_ASC,
0147:                                    new PagingPosition(first, last));
0148:                }
0149:            }
0150:
0151:            /**
0152:             * {@inheritDoc}
0153:             */
0154:            protected int sizeResources(SessionState state) {
0155:                // search?
0156:                String search = StringUtil.trimToNull((String) state
0157:                        .getAttribute(STATE_SEARCH));
0158:                String siteId = StringUtil.trimToNull((String) state
0159:                        .getAttribute(STATE_SEARCH_SITE_ID));
0160:                String userId = StringUtil.trimToNull((String) state
0161:                        .getAttribute(STATE_SEARCH_USER_ID));
0162:
0163:                // search for non-user sites, using the criteria
0164:                if (siteId != null) {
0165:                    try {
0166:                        Site site = SiteService.getSite(siteId);
0167:                        return 1;
0168:                    } catch (IdUnusedException e) {
0169:                    }
0170:
0171:                    return 0;
0172:                }
0173:
0174:                else if (userId != null) {
0175:                    try {
0176:                        Site userSite = SiteService.getSite(SiteService
0177:                                .getUserSiteId(userId));
0178:                        return 1;
0179:                    } catch (IdUnusedException e) {
0180:                    }
0181:
0182:                    return 0;
0183:                }
0184:
0185:                else if (search != null) {
0186:                    return SiteService
0187:                            .countSites(
0188:                                    org.sakaiproject.site.api.SiteService.SelectionType.NON_USER,
0189:                                    null, search, null);
0190:                }
0191:
0192:                else {
0193:                    return SiteService
0194:                            .countSites(
0195:                                    org.sakaiproject.site.api.SiteService.SelectionType.ANY,
0196:                                    null, search, null);
0197:                }
0198:            }
0199:
0200:            /**
0201:             * Populate the state object, if needed.
0202:             */
0203:            protected void initState(SessionState state,
0204:                    VelocityPortlet portlet, JetspeedRunData rundata) {
0205:                super .initState(state, portlet, rundata);
0206:
0207:                // // setup the observer to notify our main panel
0208:                // if (state.getAttribute(STATE_OBSERVER) == null)
0209:                // {
0210:                // // the delivery location for this tool
0211:                // String deliveryId = clientWindowId(state, portlet.getID());
0212:                //			
0213:                // // the html element to update on delivery
0214:                // String elementId = mainPanelUpdateId(portlet.getID());
0215:                //			
0216:                // // the event resource reference pattern to watch for
0217:                // String pattern = SiteService.siteReference("");
0218:                //
0219:                // state.setAttribute(STATE_OBSERVER, new EventObservingCourier(deliveryId, elementId, pattern));
0220:                // }
0221:            }
0222:
0223:            /**
0224:             * build the context
0225:             */
0226:            public String buildMainPanelContext(VelocityPortlet portlet,
0227:                    Context context, RunData rundata, SessionState state) {
0228:                context.put("tlang", rb);
0229:
0230:                // if not logged in as the super user, we won't do anything
0231:                if (!SecurityService.isSuperUser()) {
0232:                    context.put("tlang", rb);
0233:                    return (String) getContext(rundata).get("template")
0234:                            + "_noaccess";
0235:                }
0236:
0237:                String template = null;
0238:
0239:                // get the Sakai session
0240:                Session session = SessionManager.getCurrentSession();
0241:
0242:                // get the Tool session
0243:                ToolSession toolSession = SessionManager
0244:                        .getCurrentToolSession();
0245:
0246:                // check mode and dispatch
0247:                String mode = (String) state.getAttribute("mode");
0248:                if (mode == null) {
0249:                    template = buildListContext(state, context);
0250:                } else if (mode.equals("new")) {
0251:                    template = buildNewContext(state, context);
0252:                } else if (mode.equals("edit")) {
0253:                    template = buildEditContext(state, context);
0254:                } else if (mode.equals("confirm")) {
0255:                    template = buildConfirmRemoveContext(state, context);
0256:                } else if (mode.equals("saveas")) {
0257:                    template = buildSaveasContext(state, context);
0258:                }
0259:
0260:                else if (mode.equals("pages")) {
0261:                    template = buildPagesContext(state, context);
0262:                } else if (mode.equals("newPage")) {
0263:                    template = buildNewPageContext(state, context);
0264:                } else if (mode.equals("editPage")) {
0265:                    template = buildEditPageContext(state, context);
0266:                }
0267:
0268:                else if (mode.equals("properties")) {
0269:                    template = buildPropertiesContext(state, context);
0270:                }
0271:
0272:                else if (mode.equals("groups")) {
0273:                    template = buildGroupsContext(state, context);
0274:                } else if (mode.equals("newGroup")) {
0275:                    template = buildNewGroupContext(state, context);
0276:                } else if (mode.equals("editGroup")) {
0277:                    template = buildEditGroupContext(state, context);
0278:                }
0279:
0280:                else if (mode.equals("tools")) {
0281:                    template = buildToolsContext(state, context);
0282:                } else if (mode.equals("newTool")) {
0283:                    template = buildNewToolContext(state, context);
0284:                } else if (mode.equals("editTool")) {
0285:                    template = buildEditToolContext(state, context);
0286:                }
0287:
0288:                // else if (mode.equals("newMember"))
0289:                // {
0290:                // template = buildNewMemberContext(state, context);
0291:                // }
0292:                else {
0293:                    Log.warn("chef", "SitesAction: mode: " + mode);
0294:                    template = buildListContext(state, context);
0295:                }
0296:
0297:                String prefix = (String) getContext(rundata).get("template");
0298:                return prefix + template;
0299:
0300:            } // buildMainPanelContext
0301:
0302:            /**
0303:             * Build the context for the main list mode.
0304:             */
0305:            private String buildListContext(SessionState state, Context context) {
0306:                // put the service in the context (used for allow update calls on each site)
0307:                context.put("service", SiteService.getInstance());
0308:
0309:                // prepare the paging of realms
0310:                List sites = prepPage(state);
0311:                context.put("sites", sites);
0312:
0313:                // we need the Realms, too!
0314:                context.put("realms", AuthzGroupService.getInstance());
0315:
0316:                // build the menu
0317:                Menu bar = new MenuImpl();
0318:                if (SiteService.allowAddSite("")) {
0319:                    bar.add(new MenuEntry(rb.getString("sitact.newsit"),
0320:                            "doNew"));
0321:                }
0322:
0323:                // add the paging commands
0324:                addListPagingMenus(bar, state);
0325:
0326:                // add the search commands
0327:                addSearchMenus(bar, state);
0328:
0329:                // more search
0330:                bar.add(new MenuDivider());
0331:                bar.add(new MenuField(FORM_SEARCH_SITEID, "toolbar2",
0332:                        "doSearch_site_id", (String) state
0333:                                .getAttribute(STATE_SEARCH_SITE_ID)));
0334:                bar.add(new MenuEntry(rb.getString("sitlis.sid"), null, true,
0335:                        MenuItem.CHECKED_NA, "doSearch_site_id", "toolbar2"));
0336:                if (state.getAttribute(STATE_SEARCH_SITE_ID) != null) {
0337:                    bar.add(new MenuEntry(rb_praII.getString("sea.cleasea"),
0338:                            "doSearch_clear"));
0339:                }
0340:                bar.add(new MenuDivider());
0341:                bar.add(new MenuField(FORM_SEARCH_USERID, "toolbar3",
0342:                        "doSearch_user_id", (String) state
0343:                                .getAttribute(STATE_SEARCH_USER_ID)));
0344:                bar.add(new MenuEntry(rb.getString("sitlis.uid"), null, true,
0345:                        MenuItem.CHECKED_NA, "doSearch_user_id", "toolbar3"));
0346:                if (state.getAttribute(STATE_SEARCH_USER_ID) != null) {
0347:                    bar.add(new MenuEntry(rb_praII.getString("sea.cleasea"),
0348:                            "doSearch_clear"));
0349:                }
0350:
0351:                // add the refresh commands
0352:                addRefreshMenus(bar, state);
0353:
0354:                if (bar.size() > 0) {
0355:                    context.put(Menu.CONTEXT_MENU, bar);
0356:                }
0357:
0358:                // inform the observing courier that we just updated the page...
0359:                // if there are pending requests to do so they can be cleared
0360:                justDelivered(state);
0361:
0362:                return "_list";
0363:
0364:            } // buildListContext
0365:
0366:            /**
0367:             * Build the context for the new site mode.
0368:             */
0369:            private String buildNewContext(SessionState state, Context context) {
0370:                // name the html form for user edit fields
0371:                context.put("tlang", rb);
0372:                context.put("form-name", "site-form");
0373:
0374:                return "_edit";
0375:
0376:            } // buildNewContext
0377:
0378:            /**
0379:             * Build the context for the edit site mode.
0380:             */
0381:            private String buildEditContext(SessionState state, Context context) {
0382:                // get the site to edit
0383:                context.put("tlang", rb);
0384:                Site site = (Site) state.getAttribute("site");
0385:                context.put("site", site);
0386:
0387:                // name the html form for user edit fields
0388:                context.put("form-name", "site-form");
0389:
0390:                // build the menu
0391:                // we need the form fields for the remove...
0392:                Menu bar = new MenuImpl();
0393:                if (SiteService.allowRemoveSite(site.getId())) {
0394:                    bar
0395:                            .add(new MenuEntry(rb.getString("sitact.remsit"),
0396:                                    null, true, MenuItem.CHECKED_NA,
0397:                                    "doRemove", "site-form"));
0398:                }
0399:
0400:                bar.add(new MenuEntry(rb.getString("sitact.savas"), null, true,
0401:                        MenuItem.CHECKED_NA, "doSaveas_request", "site-form"));
0402:
0403:                context.put(Menu.CONTEXT_MENU, bar);
0404:
0405:                return "_edit";
0406:
0407:            } // buildEditContext
0408:
0409:            /**
0410:             * Build the context for the new site mode.
0411:             */
0412:            private String buildConfirmRemoveContext(SessionState state,
0413:                    Context context) {
0414:                context.put("tlang", rb);
0415:                // get the site to edit
0416:                Site site = (Site) state.getAttribute("site");
0417:                context.put("site", site);
0418:
0419:                return "_confirm_remove";
0420:
0421:            } // buildConfirmRemoveContext
0422:
0423:            /**
0424:             * Build the context for the new site mode.
0425:             */
0426:            private String buildSaveasContext(SessionState state,
0427:                    Context context) {
0428:                context.put("tlang", rb);
0429:                // get the site to edit
0430:                Site site = (Site) state.getAttribute("site");
0431:                context.put("site", site);
0432:
0433:                return "_saveas";
0434:
0435:            } // buildSaveasContext
0436:
0437:            /**
0438:             * Build the context for the new member mode
0439:             */
0440:            /*
0441:             * private String buildNewMemberContext(SessionState state, Context context) { return "_add_member"; } // buildNewMemberContext
0442:             */
0443:
0444:            /**
0445:             * Build the context for the pages display in edit mode.
0446:             */
0447:            private String buildPagesContext(SessionState state, Context context) {
0448:                context.put("tlang", rb);
0449:                // get the site to edit
0450:                Site site = (Site) state.getAttribute("site");
0451:                context.put("site", site);
0452:
0453:                // put all site's pages into the context
0454:                List pages = site.getPages();
0455:                context.put("pages", pages);
0456:
0457:                // build the menu
0458:                Menu bar = new MenuImpl();
0459:                bar.add(new MenuEntry(rb.getString("sitact.newpag"),
0460:                        "doNew_page"));
0461:                context.put(Menu.CONTEXT_MENU, bar);
0462:
0463:                return "_pages";
0464:
0465:            } // buildPagesContext
0466:
0467:            /**
0468:             * Build the context for the new page mode.
0469:             */
0470:            private String buildNewPageContext(SessionState state,
0471:                    Context context) {
0472:                context.put("tlang", rb);
0473:                // name the html form for user edit fields
0474:                context.put("form-name", "page-form");
0475:
0476:                Site site = (Site) state.getAttribute("site");
0477:                SitePage page = (SitePage) state.getAttribute("page");
0478:
0479:                context.put("site", site);
0480:                context.put("page", page);
0481:
0482:                context.put("layouts", layoutsList());
0483:
0484:                return "_edit_page";
0485:
0486:            } // buildNewPageContext
0487:
0488:            /**
0489:             * Build the context for the edit page mode.
0490:             */
0491:            private String buildEditPageContext(SessionState state,
0492:                    Context context) {
0493:                context.put("tlang", rb);
0494:                // name the html form for user edit fields
0495:                context.put("form-name", "page-form");
0496:
0497:                Site site = (Site) state.getAttribute("site");
0498:                SitePage page = (SitePage) state.getAttribute("page");
0499:
0500:                context.put("site", site);
0501:                context.put("page", page);
0502:
0503:                // build the menu
0504:                Menu bar = new MenuImpl();
0505:                bar.add(new MenuEntry(rb.getString("sitact.rempag"), null,
0506:                        true, MenuItem.CHECKED_NA, "doRemove_page"));
0507:                context.put(Menu.CONTEXT_MENU, bar);
0508:
0509:                context.put("layouts", layoutsList());
0510:
0511:                return "_edit_page";
0512:
0513:            } // buildEditPageContext
0514:
0515:            /**
0516:             * Build the context for the properties edit in edit mode.
0517:             */
0518:            private String buildPropertiesContext(SessionState state,
0519:                    Context context) {
0520:                context.put("tlang", rb);
0521:                // get the site to edit
0522:                Site site = (Site) state.getAttribute("site");
0523:                context.put("site", site);
0524:
0525:                return "_properties";
0526:            }
0527:
0528:            /**
0529:             * Build the context for the groups display in edit mode.
0530:             */
0531:            private String buildGroupsContext(SessionState state,
0532:                    Context context) {
0533:                context.put("tlang", rb);
0534:                // get the site to edit
0535:                Site site = (Site) state.getAttribute("site");
0536:                context.put("site", site);
0537:
0538:                // put all site's groups into the context
0539:                Collection groups = site.getGroups();
0540:                context.put("groups", groups);
0541:
0542:                // build the menu
0543:                Menu bar = new MenuImpl();
0544:                bar.add(new MenuEntry(rb.getString("sitact.newgrp"),
0545:                        "doNew_group"));
0546:                context.put(Menu.CONTEXT_MENU, bar);
0547:
0548:                return "_groups";
0549:
0550:            } // buildGroupsContext
0551:
0552:            /**
0553:             * Build the context for the new group mode.
0554:             */
0555:            private String buildNewGroupContext(SessionState state,
0556:                    Context context) {
0557:                context.put("tlang", rb);
0558:                // name the html form for user edit fields
0559:                context.put("form-name", "page-form");
0560:
0561:                Site site = (Site) state.getAttribute("site");
0562:                Group group = (Group) state.getAttribute("group");
0563:
0564:                context.put("site", site);
0565:                context.put("group", group);
0566:
0567:                return "_edit_group";
0568:
0569:            } // buildNewGroupContext
0570:
0571:            /**
0572:             * Build the context for the edit group mode.
0573:             */
0574:            private String buildEditGroupContext(SessionState state,
0575:                    Context context) {
0576:                context.put("tlang", rb);
0577:                // name the html form for user edit fields
0578:                context.put("form-name", "group-form");
0579:
0580:                Site site = (Site) state.getAttribute("site");
0581:                Group group = (Group) state.getAttribute("group");
0582:
0583:                context.put("site", site);
0584:                context.put("group", group);
0585:
0586:                // build the menu
0587:                Menu bar = new MenuImpl();
0588:                bar.add(new MenuEntry(rb.getString("sitact.remgrp"), null,
0589:                        true, MenuItem.CHECKED_NA, "doRemove_group"));
0590:                context.put(Menu.CONTEXT_MENU, bar);
0591:
0592:                return "_edit_group";
0593:
0594:            } // buildEditGroupContext
0595:
0596:            /**
0597:             * Build the context for the tools display in edit mode.
0598:             */
0599:            private String buildToolsContext(SessionState state, Context context) {
0600:                context.put("tlang", rb);
0601:                // get the site to edit
0602:                Site site = (Site) state.getAttribute("site");
0603:                context.put("site", site);
0604:
0605:                // get the page being edited
0606:                SitePage page = (SitePage) state.getAttribute("page");
0607:                context.put("page", page);
0608:
0609:                // put all page's tools into the context
0610:                List tools = page.getTools();
0611:                context.put("tools", tools);
0612:
0613:                // build the menu
0614:                Menu bar = new MenuImpl();
0615:                bar.add(new MenuEntry(rb.getString("sitact.newtoo"),
0616:                        "doNew_tool"));
0617:                context.put(Menu.CONTEXT_MENU, bar);
0618:
0619:                return "_tools";
0620:
0621:            } // buildToolsContext
0622:
0623:            /**
0624:             * Build the context for the new tool mode.
0625:             */
0626:            private String buildNewToolContext(SessionState state,
0627:                    Context context) {
0628:                context.put("tlang", rb);
0629:                // name the html form for user edit fields
0630:                context.put("form-name", "tool-form");
0631:
0632:                Site site = (Site) state.getAttribute("site");
0633:                SitePage page = (SitePage) state.getAttribute("page");
0634:                ToolConfiguration tool = (ToolConfiguration) state
0635:                        .getAttribute("tool");
0636:
0637:                context.put("site", site);
0638:                context.put("page", page);
0639:                context.put("tool", tool);
0640:
0641:                List features = findNonHelperTools();
0642:                context.put("features", features);
0643:
0644:                return "_edit_tool";
0645:
0646:            } // buildNewToolContext
0647:
0648:            /**
0649:             * Get the list of all tools that are not helper tools.
0650:             * 
0651:             * @return The list of all tools that are not helper to.
0652:             */
0653:            private List findNonHelperTools() {
0654:                // get all tools
0655:                Set all = ToolManager.findTools(null, null);
0656:
0657:                // get the helpers
0658:                Set categories = new HashSet();
0659:                categories.add("sakai.helper");
0660:                Set helpers = ToolManager.findTools(categories, null);
0661:
0662:                // remove the helpers from all
0663:                all.removeAll(helpers);
0664:
0665:                // make a list for sorting
0666:                List features = new Vector();
0667:                features.addAll(all);
0668:                Collections.sort(features);
0669:
0670:                return features;
0671:            }
0672:
0673:            /**
0674:             * Build the context for the edit tool mode.
0675:             */
0676:            private String buildEditToolContext(SessionState state,
0677:                    Context context) {
0678:                context.put("tlang", rb);
0679:                // name the html form for user edit fields
0680:                context.put("form-name", "tool-form");
0681:
0682:                Site site = (Site) state.getAttribute("site");
0683:                SitePage page = (SitePage) state.getAttribute("page");
0684:                ToolConfiguration tool = (ToolConfiguration) state
0685:                        .getAttribute("tool");
0686:
0687:                context.put("site", site);
0688:                context.put("page", page);
0689:                context.put("tool", tool);
0690:
0691:                List features = findNonHelperTools();
0692:                context.put("features", features);
0693:
0694:                context.put("toolReg", tool.getTool());
0695:
0696:                // build the menu
0697:                Menu bar = new MenuImpl();
0698:                bar.add(new MenuEntry(rb.getString("sitact.remtoo"), null,
0699:                        true, MenuItem.CHECKED_NA, "doRemove_tool"));
0700:                context.put(Menu.CONTEXT_MENU, bar);
0701:
0702:                return "_edit_tool";
0703:
0704:            } // buildEditToolContext
0705:
0706:            /**
0707:             * Handle a request for a new site.
0708:             */
0709:            public void doNew(RunData data, Context context) {
0710:                SessionState state = ((JetspeedRunData) data)
0711:                        .getPortletSessionState(((JetspeedRunData) data)
0712:                                .getJs_peid());
0713:                state.setAttribute("mode", "new");
0714:
0715:                // mark the site as new, so on cancel it can be deleted
0716:                state.setAttribute("new", "true");
0717:
0718:                // disable auto-updates while in view mode
0719:                ObservingCourier courier = (ObservingCourier) state
0720:                        .getAttribute(STATE_OBSERVER);
0721:                if (courier != null)
0722:                    courier.disable();
0723:
0724:            } // doNew
0725:
0726:            /**
0727:             * Handle a request to edit a site.
0728:             */
0729:            public void doEdit(RunData data, Context context) {
0730:                SessionState state = ((JetspeedRunData) data)
0731:                        .getPortletSessionState(((JetspeedRunData) data)
0732:                                .getJs_peid());
0733:                String id = data.getParameters().getString("id");
0734:
0735:                if (SiteService.allowUpdateSite(id)) {
0736:                    // get the site
0737:                    try {
0738:                        Site site = SiteService.getSite(id);
0739:                        state.setAttribute("site", site);
0740:
0741:                        // RealmEdit realm = AuthzGroupService.editRealm("/site/" + id); // %%% use a site service call -ggolden
0742:                        // state.setAttribute("realm", realm);
0743:
0744:                        state.setAttribute("mode", "edit");
0745:
0746:                        // disable auto-updates while in view mode
0747:                        ObservingCourier courier = (ObservingCourier) state
0748:                                .getAttribute(STATE_OBSERVER);
0749:                        if (courier != null)
0750:                            courier.disable();
0751:                    } catch (IdUnusedException e) {
0752:                        Log.warn("chef", "SitesAction.doEdit: site not found: "
0753:                                + id);
0754:
0755:                        addAlert(state, rb.getString("siteact.site") + " " + id
0756:                                + " " + rb.getString("siteact.notfou"));
0757:                        state.removeAttribute("mode");
0758:
0759:                        // make sure auto-updates are enabled
0760:                        enableObserver(state);
0761:                    }
0762:                }
0763:
0764:                else {
0765:                    addAlert(state, rb.getString("youdonot1") + " " + id);
0766:                    state.removeAttribute("mode");
0767:
0768:                    // make sure auto-updates are enabled
0769:                    enableObserver(state);
0770:                }
0771:
0772:            } // doEdit
0773:
0774:            /**
0775:             * Handle a request to save the site edit (from the site edit form).
0776:             */
0777:            public void doSave(RunData data, Context context) {
0778:                SessionState state = ((JetspeedRunData) data)
0779:                        .getPortletSessionState(((JetspeedRunData) data)
0780:                                .getJs_peid());
0781:
0782:                // read the form - if rejected, leave things as they are
0783:                if (!readSiteForm(data, state))
0784:                    return;
0785:
0786:                doSave_edit(data, context);
0787:
0788:            } // doSave
0789:
0790:            /**
0791:             * Handle a request to save the edit from either page or tools list mode - no form to read in.
0792:             */
0793:            public void doSave_props_edit(RunData data, Context context) {
0794:                SessionState state = ((JetspeedRunData) data)
0795:                        .getPortletSessionState(((JetspeedRunData) data)
0796:                                .getJs_peid());
0797:
0798:                // read the properties form
0799:                readPropertiesForm(data, state);
0800:
0801:                doSave_edit(data, context);
0802:            }
0803:
0804:            /**
0805:             * Handle a request to save the edit from either page or tools list mode - no form to read in.
0806:             */
0807:            public void doSave_edit(RunData data, Context context) {
0808:                SessionState state = ((JetspeedRunData) data)
0809:                        .getPortletSessionState(((JetspeedRunData) data)
0810:                                .getJs_peid());
0811:
0812:                // commit the change
0813:                Site site = (Site) state.getAttribute("site");
0814:                if (site != null) {
0815:                    // bring the mail archive service's channel for this site in sync with the site's setting
0816:                    // syncWithMailArchive(site);
0817:
0818:                    try {
0819:                        SiteService.save(site);
0820:                    } catch (PermissionException e) {
0821:                        Log.warn("chef", "SitesAction.doSave_edit: " + e);
0822:                    } catch (IdUnusedException e) {
0823:                        Log.warn("chef", "SitesAction.doSave_edit: " + e);
0824:                    }
0825:
0826:                    // save the realm, too
0827:                    // RealmEdit realm = (RealmEdit) state.getAttribute("realm");
0828:                    // AuthzGroupService.commitEdit(realm);
0829:                }
0830:
0831:                // cleanup
0832:                cleanState(state);
0833:
0834:                // return to main mode
0835:                state.removeAttribute("mode");
0836:
0837:                // make sure auto-updates are enabled
0838:                enableObserver(state);
0839:
0840:                // TODO: hard coding this frame id is fragile, portal dependent, and needs to be fixed -ggolden
0841:                schedulePeerFrameRefresh("sitenav");
0842:
0843:            } // doSave_edit
0844:
0845:            /**
0846:             * Go into saveas mode
0847:             */
0848:            public void doSaveas_request(RunData data, Context context) {
0849:                SessionState state = ((JetspeedRunData) data)
0850:                        .getPortletSessionState(((JetspeedRunData) data)
0851:                                .getJs_peid());
0852:
0853:                // read the form - if rejected, leave things as they are
0854:                if (!readSiteForm(data, state))
0855:                    return;
0856:
0857:                // go to saveas mode
0858:                state.setAttribute("mode", "saveas");
0859:
0860:            } // doSaveas_request
0861:
0862:            /**
0863:             * Handle a request to save-as the site as a new site.
0864:             */
0865:            public void doSaveas(RunData data, Context context) {
0866:                SessionState state = ((JetspeedRunData) data)
0867:                        .getPortletSessionState(((JetspeedRunData) data)
0868:                                .getJs_peid());
0869:
0870:                // read the form
0871:                String id = data.getParameters().getString("id");
0872:
0873:                // get the site to copy from
0874:                Site site = (Site) state.getAttribute("site");
0875:
0876:                try {
0877:                    // make a new site with this id and as a structural copy of site
0878:                    Site newSite = SiteService.addSite(id, site);
0879:                } catch (IdUsedException e) {
0880:                    addAlert(state, rb.getString("sitact.thesitid"));
0881:                    return;
0882:                } catch (IdInvalidException e) {
0883:                    addAlert(state, rb.getString("sitact.thesitid2"));
0884:                    return;
0885:                } catch (PermissionException e) {
0886:                    addAlert(state, rb.getString("sitact.youdonot2"));
0887:                    return;
0888:                }
0889:
0890:                cleanState(state);
0891:
0892:                // return to main mode
0893:                state.removeAttribute("mode");
0894:
0895:                // make sure auto-updates are enabled
0896:                enableObserver(state);
0897:
0898:                // TODO: hard coding this frame id is fragile, portal dependent, and needs to be fixed -ggolden
0899:                schedulePeerFrameRefresh("sitenav");
0900:
0901:            } // doSaveas
0902:
0903:            /**
0904:             * cancel the saveas request, return to edit
0905:             */
0906:            public void doCancel_saveas(RunData data, Context context) {
0907:                SessionState state = ((JetspeedRunData) data)
0908:                        .getPortletSessionState(((JetspeedRunData) data)
0909:                                .getJs_peid());
0910:
0911:                // return to main mode
0912:                state.setAttribute("mode", "edit");
0913:
0914:            } // doCancel_saveas
0915:
0916:            /**
0917:             * doCancel called when "eventSubmit_doCancel" is in the request parameters to cancel site edits
0918:             */
0919:            public void doCancel(RunData data, Context context) {
0920:                SessionState state = ((JetspeedRunData) data)
0921:                        .getPortletSessionState(((JetspeedRunData) data)
0922:                                .getJs_peid());
0923:
0924:                // cancel the realm edit - it will be removed if the site is removed
0925:                // RealmEdit realm = (RealmEdit) state.getAttribute("realm");
0926:                // if (realm != null)
0927:                // {
0928:                // AuthzGroupService.cancelEdit(realm);
0929:                // }
0930:
0931:                // get the site
0932:                Site site = (Site) state.getAttribute("site");
0933:                if (site != null) {
0934:                    // if this was a new, delete the site
0935:                    if ("true".equals(state.getAttribute("new"))) {
0936:                        // remove the site
0937:                        try {
0938:                            SiteService.removeSite(site);
0939:                        } catch (PermissionException e) {
0940:                            addAlert(state, rb.getString("sitact.youdonot3")
0941:                                    + " " + site.getId());
0942:                        }
0943:                    }
0944:                }
0945:
0946:                // cleanup
0947:                cleanState(state);
0948:
0949:                // return to main mode
0950:                state.removeAttribute("mode");
0951:
0952:                // make sure auto-updates are enabled
0953:                enableObserver(state);
0954:
0955:            } // doCancel
0956:
0957:            /**
0958:             * doRemove called when "eventSubmit_doRemove" is in the request parameters to confirm removal of the site
0959:             */
0960:            public void doRemove(RunData data, Context context) {
0961:                SessionState state = ((JetspeedRunData) data)
0962:                        .getPortletSessionState(((JetspeedRunData) data)
0963:                                .getJs_peid());
0964:
0965:                // read the form - if rejected, leave things as they are
0966:                if (!readSiteForm(data, state))
0967:                    return;
0968:
0969:                // go to remove confirm mode
0970:                state.setAttribute("mode", "confirm");
0971:
0972:            } // doRemove
0973:
0974:            /**
0975:             * doRemove_confirmed called when "eventSubmit_doRemove_confirmed" is in the request parameters to remove the site
0976:             */
0977:            public void doRemove_confirmed(RunData data, Context context) {
0978:                SessionState state = ((JetspeedRunData) data)
0979:                        .getPortletSessionState(((JetspeedRunData) data)
0980:                                .getJs_peid());
0981:
0982:                // get the site
0983:                Site site = (Site) state.getAttribute("site");
0984:
0985:                // cancel the realm edit - the site remove will remove the realm
0986:                // RealmEdit realm = (RealmEdit) state.getAttribute("realm");
0987:                // AuthzGroupService.cancelEdit(realm);
0988:
0989:                // remove the site
0990:                try {
0991:                    SiteService.removeSite(site);
0992:                } catch (PermissionException e) {
0993:                    addAlert(state, rb.getString("sitact.youdonot3") + " "
0994:                            + site.getId());
0995:                }
0996:
0997:                // cleanup
0998:                cleanState(state);
0999:
1000:                // go to main mode
1001:                state.removeAttribute("mode");
1002:
1003:                // make sure auto-updates are enabled
1004:                enableObserver(state);
1005:
1006:                // TODO: hard coding this frame id is fragile, portal dependent, and needs to be fixed -ggolden
1007:                schedulePeerFrameRefresh("sitenav");
1008:
1009:            } // doRemove_confirmed
1010:
1011:            /**
1012:             * doCancel_remove called when "eventSubmit_doCancel_remove" is in the request parameters to cancel site removal
1013:             */
1014:            public void doCancel_remove(RunData data, Context context) {
1015:                SessionState state = ((JetspeedRunData) data)
1016:                        .getPortletSessionState(((JetspeedRunData) data)
1017:                                .getJs_peid());
1018:
1019:                // return to edit mode
1020:                state.setAttribute("mode", "edit");
1021:
1022:            } // doCancel_remove
1023:
1024:            /**
1025:             * Read the site form and update the site in state.
1026:             * 
1027:             * @return true if the form is accepted, false if there's a validation error (an alertMessage will be set)
1028:             */
1029:            private boolean readSiteForm(RunData data, SessionState state) {
1030:                // read the form
1031:                String id = StringUtil.trimToNull(data.getParameters()
1032:                        .getString("id"));
1033:                String title = StringUtil.trimToNull(data.getParameters()
1034:                        .getString("title"));
1035:                String type = StringUtil.trimToNull(data.getParameters()
1036:                        .getString("type"));
1037:                String shortDescription = StringUtil.trimToNull(data
1038:                        .getParameters().getString("shortDescription"));
1039:                String description = StringUtil.trimToNull(data.getParameters()
1040:                        .getString("description"));
1041:                boolean joinable = data.getParameters().getBoolean("joinable");
1042:                String joinerRole = StringUtil.trimToNull(data.getParameters()
1043:                        .getString("joinerRole"));
1044:                String icon = StringUtil.trimToNull(data.getParameters()
1045:                        .getString("icon"));
1046:                String info = StringUtil.trimToNull(data.getParameters()
1047:                        .getString("info"));
1048:                boolean published = data.getParameters()
1049:                        .getBoolean("published");
1050:                String skin = StringUtil.trimToNull(data.getParameters()
1051:                        .getString("skin"));
1052:                boolean pubView = data.getParameters().getBoolean("pubView");
1053:                boolean customOrder = data.getParameters().getBoolean(
1054:                        "customOrder");
1055:
1056:                // get the site
1057:                Site site = (Site) state.getAttribute("site");
1058:
1059:                // add if needed
1060:                if (site == null) {
1061:                    try {
1062:                        site = SiteService.addSite(id, type);
1063:
1064:                        // put the site in the state
1065:                        state.setAttribute("site", site);
1066:                    } catch (IdUsedException e) {
1067:                        addAlert(state, rb.getString("sitact.thesitid"));
1068:                        return false;
1069:                    } catch (IdInvalidException e) {
1070:                        addAlert(state, rb.getString("sitact.thesitid2"));
1071:                        return false;
1072:                    } catch (PermissionException e) {
1073:                        addAlert(state, rb.getString("sitact.youdonot2"));
1074:                        return false;
1075:                    }
1076:                }
1077:
1078:                // update
1079:                if (site != null) {
1080:                    if (joinable) {
1081:                        // check if there is a qualifed role in the role field
1082:                        if ((joinerRole == null) || (joinerRole.equals(""))) {
1083:                            addAlert(state, rb.getString("sitact.sperol"));
1084:                            return false;
1085:                        }
1086:                        Vector roles = new Vector();
1087:                        Vector roleIds = new Vector();
1088:                        AuthzGroup realm = null;
1089:                        try {
1090:                            realm = AuthzGroupService.getAuthzGroup(site
1091:                                    .getReference());
1092:                            roles.addAll(realm.getRoles());
1093:                        } catch (GroupNotDefinedException e) {
1094:                            // use the type's template, if defined
1095:                            String realmTemplate = "!site.template";
1096:                            if (type != null) {
1097:                                realmTemplate = realmTemplate + "." + type;
1098:                            }
1099:                            try {
1100:                                AuthzGroup r = AuthzGroupService
1101:                                        .getAuthzGroup(realmTemplate);
1102:                                roles.addAll(r.getRoles());
1103:                            } catch (GroupNotDefinedException err) {
1104:                                try {
1105:                                    AuthzGroup rr = AuthzGroupService
1106:                                            .getAuthzGroup("!site.template");
1107:                                    roles.addAll(rr.getRoles());
1108:                                } catch (GroupNotDefinedException ee) {
1109:                                }
1110:                            }
1111:                        }
1112:
1113:                        for (int i = 0; i < roles.size(); i++) {
1114:                            roleIds.add(((Role) roles.elementAt(i)).getId());
1115:                        }
1116:
1117:                        if (!roleIds.contains(joinerRole)) {
1118:                            addAlert(state, rb.getString("sitact.sperol"));
1119:                            return false;
1120:                        }
1121:                    }
1122:
1123:                    site.setTitle(title);
1124:                    site.setShortDescription(shortDescription);
1125:                    site.setDescription(description);
1126:                    site.setJoinable(joinable);
1127:                    site.setJoinerRole(joinerRole);
1128:                    site.setIconUrl(icon);
1129:                    site.setInfoUrl(info);
1130:                    site.setSkin(skin);
1131:                    site.setType(type);
1132:                    site.setPubView(pubView);
1133:                    site.setPublished(published);
1134:                    site.setCustomPageOrdered(customOrder);
1135:                }
1136:
1137:                return true;
1138:
1139:            } // readSiteForm
1140:
1141:            /**
1142:             * Switch to page display mode within a site edit.
1143:             */
1144:            public void doPages(RunData data, Context context) {
1145:                SessionState state = ((JetspeedRunData) data)
1146:                        .getPortletSessionState(((JetspeedRunData) data)
1147:                                .getJs_peid());
1148:
1149:                // read the form - if rejected, leave things as they are
1150:                if (!readSiteForm(data, state))
1151:                    return;
1152:
1153:                state.setAttribute("mode", "pages");
1154:
1155:            } // doPages
1156:
1157:            /**
1158:             * Switch to property edit mode within a site edit.
1159:             */
1160:            public void doProperties(RunData data, Context context) {
1161:                SessionState state = ((JetspeedRunData) data)
1162:                        .getPortletSessionState(((JetspeedRunData) data)
1163:                                .getJs_peid());
1164:
1165:                // read the form - if rejected, leave things as they are
1166:                if (!readSiteForm(data, state))
1167:                    return;
1168:
1169:                state.setAttribute("mode", "properties");
1170:            }
1171:
1172:            /**
1173:             * Handle a request to create a new page in the site edit.
1174:             */
1175:            public void doNew_page(RunData data, Context context) {
1176:                SessionState state = ((JetspeedRunData) data)
1177:                        .getPortletSessionState(((JetspeedRunData) data)
1178:                                .getJs_peid());
1179:                state.setAttribute("mode", "newPage");
1180:
1181:                // make the page so we have the id
1182:                Site site = (Site) state.getAttribute("site");
1183:                SitePage page = site.addPage();
1184:                state.setAttribute("page", page);
1185:
1186:                // mark the site as new, so on cancel it can be deleted
1187:                state.setAttribute("newPage", "true");
1188:
1189:            } // doNew_page
1190:
1191:            /**
1192:             * Handle a request to create a new property in the site edit.
1193:             */
1194:            public void doNew_property(RunData data, Context context) {
1195:                SessionState state = ((JetspeedRunData) data)
1196:                        .getPortletSessionState(((JetspeedRunData) data)
1197:                                .getJs_peid());
1198:
1199:                // read the properties form
1200:                readPropertiesForm(data, state);
1201:            }
1202:
1203:            /**
1204:             * Edit an existing page.
1205:             */
1206:            public void doEdit_page(RunData data, Context context) {
1207:                SessionState state = ((JetspeedRunData) data)
1208:                        .getPortletSessionState(((JetspeedRunData) data)
1209:                                .getJs_peid());
1210:                state.setAttribute("mode", "editPage");
1211:
1212:                String id = data.getParameters().getString("id");
1213:
1214:                // get the page
1215:                Site site = (Site) state.getAttribute("site");
1216:                SitePage page = site.getPage(id);
1217:                state.setAttribute("page", page);
1218:
1219:            } // doEdit_page
1220:
1221:            /**
1222:             * Move the page up in the order.
1223:             */
1224:            public void doEdit_page_up(RunData data, Context context) {
1225:                SessionState state = ((JetspeedRunData) data)
1226:                        .getPortletSessionState(((JetspeedRunData) data)
1227:                                .getJs_peid());
1228:
1229:                String id = data.getParameters().getString("id");
1230:
1231:                // get the page
1232:                Site site = (Site) state.getAttribute("site");
1233:                SitePage page = site.getPage(id);
1234:                state.setAttribute("page", page);
1235:
1236:                // move it
1237:                page.moveUp();
1238:
1239:            } // doEdit_page_up
1240:
1241:            /**
1242:             * Move the page down in the order.
1243:             */
1244:            public void doEdit_page_down(RunData data, Context context) {
1245:                SessionState state = ((JetspeedRunData) data)
1246:                        .getPortletSessionState(((JetspeedRunData) data)
1247:                                .getJs_peid());
1248:
1249:                String id = data.getParameters().getString("id");
1250:
1251:                // get the page
1252:                Site site = (Site) state.getAttribute("site");
1253:                SitePage page = site.getPage(id);
1254:                state.setAttribute("page", page);
1255:
1256:                // move it
1257:                page.moveDown();
1258:
1259:            } // doEdit_page_down
1260:
1261:            /**
1262:             * save the page edited, and save the site edit
1263:             */
1264:            public void doSave_page(RunData data, Context context) {
1265:                SessionState state = ((JetspeedRunData) data)
1266:                        .getPortletSessionState(((JetspeedRunData) data)
1267:                                .getJs_peid());
1268:
1269:                // read the form - if rejected, leave things as they are
1270:                if (!readPageForm(data, state))
1271:                    return;
1272:
1273:                // done with the page
1274:                state.removeAttribute("page");
1275:
1276:                // commit the entire site edit
1277:                doSave_edit(data, context);
1278:
1279:            } // doSave_page
1280:
1281:            /**
1282:             * save the page edited, and return to the pages mode
1283:             */
1284:            public void doDone_page(RunData data, Context context) {
1285:                SessionState state = ((JetspeedRunData) data)
1286:                        .getPortletSessionState(((JetspeedRunData) data)
1287:                                .getJs_peid());
1288:
1289:                // read the form - if rejected, leave things as they are
1290:                if (!readPageForm(data, state))
1291:                    return;
1292:
1293:                // done with the page
1294:                state.removeAttribute("page");
1295:
1296:                // return to main mode
1297:                state.setAttribute("mode", "pages");
1298:
1299:            } // doDone_page
1300:
1301:            /**
1302:             * cancel a page edit, return to the pages list
1303:             */
1304:            public void doCancel_page(RunData data, Context context) {
1305:                SessionState state = ((JetspeedRunData) data)
1306:                        .getPortletSessionState(((JetspeedRunData) data)
1307:                                .getJs_peid());
1308:
1309:                Site site = (Site) state.getAttribute("site");
1310:                SitePage page = (SitePage) state.getAttribute("page");
1311:
1312:                // if the page was new, remove it
1313:                if ("true".equals(state.getAttribute("newPage"))) {
1314:                    site.removePage(page);
1315:                }
1316:
1317:                // %%% do we need the old page around for a restore; did we already modify it? - ggolden
1318:
1319:                // done with the page
1320:                state.removeAttribute("page");
1321:
1322:                // return to main mode
1323:                state.setAttribute("mode", "pages");
1324:
1325:            } // doCancel_page
1326:
1327:            /**
1328:             * Handle a request to remove the page being edited.
1329:             */
1330:            public void doRemove_page(RunData data, Context context) {
1331:                SessionState state = ((JetspeedRunData) data)
1332:                        .getPortletSessionState(((JetspeedRunData) data)
1333:                                .getJs_peid());
1334:
1335:                Site site = (Site) state.getAttribute("site");
1336:                SitePage page = (SitePage) state.getAttribute("page");
1337:
1338:                // remove the page (no confirm)
1339:                site.removePage(page);
1340:
1341:                // done with the page
1342:                state.removeAttribute("page");
1343:
1344:                // return to pages mode
1345:                state.setAttribute("mode", "pages");
1346:
1347:            } // doRemove_page
1348:
1349:            /**
1350:             * Switch to group display mode within a site edit.
1351:             */
1352:            public void doGroups(RunData data, Context context) {
1353:                SessionState state = ((JetspeedRunData) data)
1354:                        .getPortletSessionState(((JetspeedRunData) data)
1355:                                .getJs_peid());
1356:
1357:                // read the form - if rejected, leave things as they are
1358:                if (!readSiteForm(data, state))
1359:                    return;
1360:
1361:                state.setAttribute("mode", "groups");
1362:
1363:            } // doGroups
1364:
1365:            /**
1366:             * Edit an existing group.
1367:             */
1368:            public void doEdit_group(RunData data, Context context) {
1369:                SessionState state = ((JetspeedRunData) data)
1370:                        .getPortletSessionState(((JetspeedRunData) data)
1371:                                .getJs_peid());
1372:                state.setAttribute("mode", "editGroup");
1373:
1374:                String id = data.getParameters().getString("id");
1375:
1376:                // get the group
1377:                Site site = (Site) state.getAttribute("site");
1378:                Group group = site.getGroup(id);
1379:                state.setAttribute("group", group);
1380:
1381:            } // doEdit_group
1382:
1383:            /**
1384:             * save the group edited, and save the site edit
1385:             */
1386:            public void doSave_group(RunData data, Context context) {
1387:                SessionState state = ((JetspeedRunData) data)
1388:                        .getPortletSessionState(((JetspeedRunData) data)
1389:                                .getJs_peid());
1390:
1391:                // read the form - if rejected, leave things as they are
1392:                if (!readGroupForm(data, state))
1393:                    return;
1394:
1395:                // done with the group
1396:                state.removeAttribute("group");
1397:
1398:                // commit the entire site edit
1399:                doSave_edit(data, context);
1400:
1401:            } // doSave_group
1402:
1403:            /**
1404:             * save the group edited, and return to the groups mode
1405:             */
1406:            public void doDone_group(RunData data, Context context) {
1407:                SessionState state = ((JetspeedRunData) data)
1408:                        .getPortletSessionState(((JetspeedRunData) data)
1409:                                .getJs_peid());
1410:
1411:                // read the form - if rejected, leave things as they are
1412:                if (!readGroupForm(data, state))
1413:                    return;
1414:
1415:                // done with the group
1416:                state.removeAttribute("group");
1417:
1418:                // return to main mode
1419:                state.setAttribute("mode", "groups");
1420:
1421:            } // doDone_group
1422:
1423:            /**
1424:             * cancel a group edit, return to the groups list
1425:             */
1426:            public void doCancel_group(RunData data, Context context) {
1427:                SessionState state = ((JetspeedRunData) data)
1428:                        .getPortletSessionState(((JetspeedRunData) data)
1429:                                .getJs_peid());
1430:
1431:                Site site = (Site) state.getAttribute("site");
1432:                Group group = (Group) state.getAttribute("group");
1433:
1434:                // if the page was new, remove it
1435:                if ("true".equals(state.getAttribute("newGroup"))) {
1436:                    site.removeGroup(group);
1437:                }
1438:
1439:                // %%% do we need the old group around for a restore; did we already modify it? - ggolden
1440:
1441:                // done with the group
1442:                state.removeAttribute("group");
1443:
1444:                // return to main mode
1445:                state.setAttribute("mode", "groups");
1446:
1447:            } // doCancel_group
1448:
1449:            /**
1450:             * Handle a request to remove the group being edited.
1451:             */
1452:            public void doRemove_group(RunData data, Context context) {
1453:                SessionState state = ((JetspeedRunData) data)
1454:                        .getPortletSessionState(((JetspeedRunData) data)
1455:                                .getJs_peid());
1456:
1457:                Site site = (Site) state.getAttribute("site");
1458:                Group group = (Group) state.getAttribute("group");
1459:
1460:                // remove the page (no confirm)
1461:                site.removeGroup(group);
1462:
1463:                // done with the page
1464:                state.removeAttribute("group");
1465:
1466:                // return to pages mode
1467:                state.setAttribute("mode", "groups");
1468:
1469:            } // doRemove_group
1470:
1471:            /**
1472:             * Handle a request to create a new group in the site edit.
1473:             */
1474:            public void doNew_group(RunData data, Context context) {
1475:                SessionState state = ((JetspeedRunData) data)
1476:                        .getPortletSessionState(((JetspeedRunData) data)
1477:                                .getJs_peid());
1478:                state.setAttribute("mode", "newGroup");
1479:
1480:                // make the page so we have the id
1481:                Site site = (Site) state.getAttribute("site");
1482:                Group group = site.addGroup();
1483:                state.setAttribute("group", group);
1484:
1485:                // mark the site as new, so on cancel it can be deleted
1486:                state.setAttribute("newGroup", "true");
1487:
1488:            } // doRemove_group
1489:
1490:            /**
1491:             * Switch back to edit main info mode from another edit mode (like pages).
1492:             */
1493:            public void doEdit_to_main(RunData data, Context context) {
1494:                SessionState state = ((JetspeedRunData) data)
1495:                        .getPortletSessionState(((JetspeedRunData) data)
1496:                                .getJs_peid());
1497:
1498:                state.setAttribute("mode", "edit");
1499:
1500:            } // doEdit_to_main
1501:
1502:            /**
1503:             * Switch back to edit main info mode properties edit mode
1504:             */
1505:            public void doEdit_props_to_main(RunData data, Context context) {
1506:                SessionState state = ((JetspeedRunData) data)
1507:                        .getPortletSessionState(((JetspeedRunData) data)
1508:                                .getJs_peid());
1509:
1510:                // read the properties form
1511:                readPropertiesForm(data, state);
1512:
1513:                state.setAttribute("mode", "edit");
1514:            }
1515:
1516:            /**
1517:             * Read the page form and update the site in state.
1518:             * 
1519:             * @return true if the form is accepted, false if there's a validation error (an alertMessage will be set)
1520:             */
1521:            private boolean readPageForm(RunData data, SessionState state) {
1522:                // get the page - it's there
1523:                SitePage page = (SitePage) state.getAttribute("page");
1524:
1525:                // read the form
1526:                String title = StringUtil.trimToNull(data.getParameters()
1527:                        .getString("title"));
1528:                page.setTitle(title);
1529:
1530:                try {
1531:                    // this comes in 1 based, convert to 0 based
1532:                    int layout = Integer.parseInt(data.getParameters()
1533:                            .getString("layout")) - 1;
1534:                    page.setLayout(layout);
1535:                } catch (Exception e) {
1536:                    Log.warn("chef", this  + ".readPageForm(): reading layout: "
1537:                            + e);
1538:                }
1539:
1540:                boolean popup = data.getParameters().getBoolean("popup");
1541:                page.setPopup(popup);
1542:
1543:                if (title == null) {
1544:                    addAlert(state, rb.getString("sitact.plespe"));
1545:                    return false;
1546:                } else {
1547:                    return true;
1548:                }
1549:
1550:            } // readPageForm
1551:
1552:            /**
1553:             * Read the properties form and update the site in state.
1554:             * 
1555:             * @return true if the form is accepted, false if there's a validation error (an alertMessage will be set)
1556:             */
1557:            private boolean readPropertiesForm(RunData data, SessionState state) {
1558:                // get the site
1559:                Site site = (Site) state.getAttribute("site");
1560:
1561:                ResourcePropertiesEdit props = site.getPropertiesEdit();
1562:
1563:                // check each property for possible update
1564:                for (Iterator i = props.getPropertyNames(); i.hasNext();) {
1565:                    String name = (String) i.next();
1566:                    String formValue = StringUtil.trimToNull(data
1567:                            .getParameters().getString("param_" + name));
1568:
1569:                    // update the properties or remove
1570:                    if (formValue != null) {
1571:                        props.addProperty(name, formValue);
1572:                    } else {
1573:                        props.removeProperty(name);
1574:                    }
1575:                }
1576:
1577:                // see if there's a new one
1578:                String formName = StringUtil.trimToNull(data.getParameters()
1579:                        .getString("new_name"));
1580:                if (formName != null) {
1581:                    String formValue = StringUtil.trimToNull(data
1582:                            .getParameters().getString("new_value"));
1583:                    if (formValue != null) {
1584:                        props.addProperty(formName, formValue);
1585:                    }
1586:                }
1587:
1588:                return true;
1589:            }
1590:
1591:            /**
1592:             * Read the group form and update the site in state.
1593:             * 
1594:             * @return true if the form is accepted, false if there's a validation error (an alertMessage will be set)
1595:             */
1596:            private boolean readGroupForm(RunData data, SessionState state) {
1597:                // get the group - it's there
1598:                Group group = (Group) state.getAttribute("group");
1599:
1600:                // read the form
1601:                String title = StringUtil.trimToNull(data.getParameters()
1602:                        .getString("title"));
1603:                group.setTitle(title);
1604:
1605:                String description = StringUtil.trimToNull(data.getParameters()
1606:                        .getString("description"));
1607:                group.setDescription(description);
1608:
1609:                if (title == null) {
1610:                    addAlert(state, rb.getString("sitgrp.plespe"));
1611:                    return false;
1612:                } else {
1613:                    return true;
1614:                }
1615:
1616:            } // readGroupForm
1617:
1618:            /**
1619:             * Switch to tools display mode within a site edit.
1620:             */
1621:            public void doTools(RunData data, Context context) {
1622:                SessionState state = ((JetspeedRunData) data)
1623:                        .getPortletSessionState(((JetspeedRunData) data)
1624:                                .getJs_peid());
1625:
1626:                // read the form - if rejected, leave things as they are
1627:                if (!readPageForm(data, state))
1628:                    return;
1629:
1630:                state.setAttribute("mode", "tools");
1631:
1632:            } // doTools
1633:
1634:            /**
1635:             * create a new tool in the page edit.
1636:             */
1637:            public void doNew_tool(RunData data, Context context) {
1638:                SessionState state = ((JetspeedRunData) data)
1639:                        .getPortletSessionState(((JetspeedRunData) data)
1640:                                .getJs_peid());
1641:                state.setAttribute("mode", "newTool");
1642:
1643:                // make the tool so we have the id
1644:                SitePage page = (SitePage) state.getAttribute("page");
1645:                ToolConfiguration tool = page.addTool();
1646:                state.setAttribute("tool", tool);
1647:
1648:                // mark the site as new, so on cancel it can be deleted
1649:                state.setAttribute("newTool", "true");
1650:
1651:            } // doNew_tool
1652:
1653:            /**
1654:             * Edit an existing tool.
1655:             */
1656:            public void doEdit_tool(RunData data, Context context) {
1657:                SessionState state = ((JetspeedRunData) data)
1658:                        .getPortletSessionState(((JetspeedRunData) data)
1659:                                .getJs_peid());
1660:                state.setAttribute("mode", "editTool");
1661:
1662:                String id = data.getParameters().getString("id");
1663:
1664:                // get the tool
1665:                Site site = (Site) state.getAttribute("site");
1666:                SitePage page = (SitePage) state.getAttribute("page");
1667:                ToolConfiguration tool = page.getTool(id);
1668:                state.setAttribute("tool", tool);
1669:
1670:            } // doEdit_tool
1671:
1672:            /**
1673:             * Move the tool up in the order.
1674:             */
1675:            public void doEdit_tool_up(RunData data, Context context) {
1676:                SessionState state = ((JetspeedRunData) data)
1677:                        .getPortletSessionState(((JetspeedRunData) data)
1678:                                .getJs_peid());
1679:
1680:                String id = data.getParameters().getString("id");
1681:
1682:                // get the tool
1683:                Site site = (Site) state.getAttribute("site");
1684:                SitePage page = (SitePage) state.getAttribute("page");
1685:                ToolConfiguration tool = page.getTool(id);
1686:
1687:                // move it
1688:                tool.moveUp();
1689:
1690:            } // doEdit_tool_up
1691:
1692:            /**
1693:             * Move the tool down in the order.
1694:             */
1695:            public void doEdit_tool_down(RunData data, Context context) {
1696:                SessionState state = ((JetspeedRunData) data)
1697:                        .getPortletSessionState(((JetspeedRunData) data)
1698:                                .getJs_peid());
1699:
1700:                String id = data.getParameters().getString("id");
1701:
1702:                // get the tool
1703:                Site site = (Site) state.getAttribute("site");
1704:                SitePage page = (SitePage) state.getAttribute("page");
1705:                ToolConfiguration tool = page.getTool(id);
1706:
1707:                // move it
1708:                tool.moveDown();
1709:
1710:            } // doEdit_tool_down
1711:
1712:            /**
1713:             * save the tool edited, and save the site edit.
1714:             */
1715:            public void doSave_tool(RunData data, Context context) {
1716:                SessionState state = ((JetspeedRunData) data)
1717:                        .getPortletSessionState(((JetspeedRunData) data)
1718:                                .getJs_peid());
1719:
1720:                // read the form - if rejected, leave things as they are
1721:                if (!readToolForm(data, state))
1722:                    return;
1723:
1724:                // done with the tool
1725:                state.removeAttribute("tool");
1726:
1727:                // commit the entire site edit
1728:                doSave_edit(data, context);
1729:
1730:            } // doSave_tool
1731:
1732:            /**
1733:             * save the tool edited, and return to the tools mode
1734:             */
1735:            public void doDone_tool(RunData data, Context context) {
1736:                SessionState state = ((JetspeedRunData) data)
1737:                        .getPortletSessionState(((JetspeedRunData) data)
1738:                                .getJs_peid());
1739:
1740:                // read the form - if rejected, leave things as they are
1741:                if (!readToolForm(data, state))
1742:                    return;
1743:
1744:                // done with the tool
1745:                state.removeAttribute("tool");
1746:
1747:                // return to main mode
1748:                state.setAttribute("mode", "tools");
1749:
1750:            } // doDone_tool
1751:
1752:            /**
1753:             * save the tool's selected feature, continue editing the tool
1754:             */
1755:            public void doDone_feature(RunData data, Context context) {
1756:                SessionState state = ((JetspeedRunData) data)
1757:                        .getPortletSessionState(((JetspeedRunData) data)
1758:                                .getJs_peid());
1759:
1760:                // read the form - if rejected, leave things as they are
1761:                if (!readToolFeatureForm(data, state))
1762:                    return;
1763:
1764:                // go into edit mode
1765:                state.setAttribute("mode", "editTool");
1766:
1767:            } // doDone_feature
1768:
1769:            /**
1770:             * cancel a tool edit, return to the tools list
1771:             */
1772:            public void doCancel_tool(RunData data, Context context) {
1773:                SessionState state = ((JetspeedRunData) data)
1774:                        .getPortletSessionState(((JetspeedRunData) data)
1775:                                .getJs_peid());
1776:
1777:                Site site = (Site) state.getAttribute("site");
1778:                SitePage page = (SitePage) state.getAttribute("page");
1779:                ToolConfiguration tool = (ToolConfiguration) state
1780:                        .getAttribute("tool");
1781:
1782:                // if the tool was new, remove it
1783:                if ("true".equals(state.getAttribute("newTool"))) {
1784:                    page.removeTool(tool);
1785:                }
1786:
1787:                // %%% do we need the old tool around for a restore; did we already modify it? - ggolden
1788:
1789:                // done with the tool
1790:                state.removeAttribute("tool");
1791:
1792:                // return to tools mode
1793:                state.setAttribute("mode", "tools");
1794:
1795:            } // doCancel_tool
1796:
1797:            /**
1798:             * Handle a request to remove the tool being edited.
1799:             */
1800:            public void doRemove_tool(RunData data, Context context) {
1801:                SessionState state = ((JetspeedRunData) data)
1802:                        .getPortletSessionState(((JetspeedRunData) data)
1803:                                .getJs_peid());
1804:
1805:                SitePage page = (SitePage) state.getAttribute("page");
1806:                ToolConfiguration tool = (ToolConfiguration) state
1807:                        .getAttribute("tool");
1808:
1809:                // remove the tool (no confirm)
1810:                page.removeTool(tool);
1811:
1812:                // done with the tool
1813:                state.removeAttribute("tool");
1814:
1815:                // return to tools mode
1816:                state.setAttribute("mode", "tools");
1817:
1818:            } // doRemove_tool
1819:
1820:            /**
1821:             * Switch back to edit page info mode from another edit mode (like tools).
1822:             */
1823:            public void doEdit_to_page(RunData data, Context context) {
1824:                SessionState state = ((JetspeedRunData) data)
1825:                        .getPortletSessionState(((JetspeedRunData) data)
1826:                                .getJs_peid());
1827:
1828:                state.setAttribute("mode", "editPage");
1829:
1830:            } // doEdit_to_page
1831:
1832:            /**
1833:             * Handle a request to regenerate the ids in the site under edit.
1834:             */
1835:            public void doIds(RunData data, Context context) {
1836:                SessionState state = ((JetspeedRunData) data)
1837:                        .getPortletSessionState(((JetspeedRunData) data)
1838:                                .getJs_peid());
1839:
1840:                // get the site
1841:                Site site = (Site) state.getAttribute("site");
1842:
1843:                site.regenerateIds();
1844:                addAlert(state, rb.getString("sitact.thesit"));
1845:            }
1846:
1847:            /**
1848:             * Handle a Search request.
1849:             */
1850:            public void doSearch(RunData runData, Context context) {
1851:                // access the portlet element id to find our state
1852:                String peid = ((JetspeedRunData) runData).getJs_peid();
1853:                SessionState state = ((JetspeedRunData) runData)
1854:                        .getPortletSessionState(peid);
1855:
1856:                // clear the search(s)
1857:                state.removeAttribute(STATE_SEARCH);
1858:                state.removeAttribute(STATE_SEARCH_SITE_ID);
1859:                state.removeAttribute(STATE_SEARCH_USER_ID);
1860:
1861:                super .doSearch(runData, context);
1862:
1863:            } // doSearch
1864:
1865:            /**
1866:             * Handle a Search request - for site id
1867:             */
1868:            public void doSearch_site_id(RunData runData, Context context) {
1869:                // access the portlet element id to find our state
1870:                String peid = ((JetspeedRunData) runData).getJs_peid();
1871:                SessionState state = ((JetspeedRunData) runData)
1872:                        .getPortletSessionState(peid);
1873:
1874:                // clear the search(s)
1875:                state.removeAttribute(STATE_SEARCH);
1876:                state.removeAttribute(STATE_SEARCH_SITE_ID);
1877:                state.removeAttribute(STATE_SEARCH_USER_ID);
1878:
1879:                // read the search form field into the state object
1880:                String search = StringUtil.trimToNull(runData.getParameters()
1881:                        .getString(FORM_SEARCH_SITEID));
1882:
1883:                // set the flag to go to the prev page on the next list
1884:                if (search != null) {
1885:                    state.setAttribute(STATE_SEARCH_SITE_ID, search);
1886:                }
1887:
1888:            } // doSearch_site_id
1889:
1890:            /**
1891:             * Handle a Search request - for user my workspace
1892:             */
1893:            public void doSearch_user_id(RunData runData, Context context) {
1894:                // access the portlet element id to find our state
1895:                String peid = ((JetspeedRunData) runData).getJs_peid();
1896:                SessionState state = ((JetspeedRunData) runData)
1897:                        .getPortletSessionState(peid);
1898:
1899:                // clear the search(s)
1900:                state.removeAttribute(STATE_SEARCH);
1901:                state.removeAttribute(STATE_SEARCH_SITE_ID);
1902:                state.removeAttribute(STATE_SEARCH_USER_ID);
1903:
1904:                // read the search form field into the state object
1905:                String search = StringUtil.trimToNull(runData.getParameters()
1906:                        .getString(FORM_SEARCH_USERID));
1907:
1908:                // set the flag to go to the prev page on the next list
1909:                if (search != null) {
1910:                    state.setAttribute(STATE_SEARCH_USER_ID, search);
1911:                }
1912:
1913:                // start paging again from the top of the list
1914:                resetPaging(state);
1915:
1916:            } // doSearch_user_id
1917:
1918:            /**
1919:             * Handle a Search Clear request.
1920:             */
1921:            public void doSearch_clear(RunData runData, Context context) {
1922:                // access the portlet element id to find our state
1923:                String peid = ((JetspeedRunData) runData).getJs_peid();
1924:                SessionState state = ((JetspeedRunData) runData)
1925:                        .getPortletSessionState(peid);
1926:
1927:                // clear the search(s)
1928:                state.removeAttribute(STATE_SEARCH);
1929:                state.removeAttribute(STATE_SEARCH_SITE_ID);
1930:                state.removeAttribute(STATE_SEARCH_USER_ID);
1931:
1932:                // start paging again from the top of the list
1933:                resetPaging(state);
1934:
1935:                // turn on auto refresh
1936:                enableObserver(state);
1937:
1938:            } // doSearch_clear
1939:
1940:            /**
1941:             * Read the tool form and update the site in state.
1942:             * 
1943:             * @return true if the form is accepted, false if there's a validation error (an alertMessage will be set)
1944:             */
1945:            private boolean readToolForm(RunData data, SessionState state) {
1946:                // get the tool - it's there
1947:                ToolConfiguration tool = (ToolConfiguration) state
1948:                        .getAttribute("tool");
1949:
1950:                // read the form
1951:                String title = StringUtil.trimToNull(data.getParameters()
1952:                        .getString("title"));
1953:                tool.setTitle(title);
1954:
1955:                // read the layout hints
1956:                String hints = StringUtil.trimToNull(data.getParameters()
1957:                        .getString("layoutHints"));
1958:                if (hints != null) {
1959:                    // strip all whitespace
1960:                    hints = hints.replaceAll("\\s", ""); // strip all whitespace
1961:                }
1962:                tool.setLayoutHints(hints);
1963:
1964:                Tool t = tool.getTool();
1965:                if (t != null) {
1966:                    // read in any params
1967:                    for (Enumeration iParams = t.getRegisteredConfig()
1968:                            .propertyNames(); iParams.hasMoreElements();) {
1969:                        String paramName = (String) iParams.nextElement();
1970:                        String formName = "param_" + paramName;
1971:                        String value = data.getParameters().getString(formName);
1972:                        if (value != null) {
1973:                            value = StringUtil.trimToNull(value);
1974:
1975:                            // if we have a value
1976:                            if (value != null) {
1977:                                // if this value is not the same as the tool's registered, set it in the placement
1978:                                if (!value.equals(t.getRegisteredConfig()
1979:                                        .getProperty(paramName))) {
1980:                                    tool.getPlacementConfig().setProperty(
1981:                                            paramName, value);
1982:                                }
1983:
1984:                                // otherwise clear it
1985:                                else {
1986:                                    tool.getPlacementConfig().remove(paramName);
1987:                                }
1988:                            }
1989:
1990:                            // if no value
1991:                            else {
1992:                                tool.getPlacementConfig().remove(paramName);
1993:                            }
1994:                        }
1995:                    }
1996:                } else {
1997:                    addAlert(state, rb.getString("sitact.plesel"));
1998:                    return false;
1999:                }
2000:
2001:                return true;
2002:
2003:            } // readToolForm
2004:
2005:            /**
2006:             * Read the tool feature form and update the site in state.
2007:             * 
2008:             * @return true if the form is accepted, false if there's a validation error (an alertMessage will be set)
2009:             */
2010:            private boolean readToolFeatureForm(RunData data, SessionState state) {
2011:                // get the tool - it's there
2012:                ToolConfiguration tool = (ToolConfiguration) state
2013:                        .getAttribute("tool");
2014:
2015:                // read the form
2016:                String feature = data.getParameters().getString("feature");
2017:
2018:                // get this feature
2019:                Tool t = tool.getTool();
2020:
2021:                // if the feature has changed, update the default configuration
2022:                if ((t == null) || (!feature.equals(t.getId()))) {
2023:                    tool.setTool(feature, ToolManager.getTool(feature));
2024:                    tool.setTitle(null);
2025:                    tool.getPlacementConfig().clear();
2026:                }
2027:
2028:                return true;
2029:
2030:            } // readToolFeatureForm
2031:
2032:            /**
2033:             * Clean up all possible state value when done an edit.
2034:             */
2035:            private void cleanState(SessionState state) {
2036:                state.removeAttribute("site");
2037:                state.removeAttribute("page");
2038:                state.removeAttribute("tool");
2039:                state.removeAttribute("new");
2040:                state.removeAttribute("newPage");
2041:                state.removeAttribute("newTool");
2042:
2043:                // clear the search, so after an edit or delete, the search is not automatically re-run
2044:                state.removeAttribute(STATE_SEARCH);
2045:                state.removeAttribute(STATE_SEARCH_SITE_ID);
2046:                state.removeAttribute(STATE_SEARCH_USER_ID);
2047:
2048:            } // cleanState
2049:
2050:            /**
2051:             * Create a list of the valid layout names.
2052:             * 
2053:             * @return A List (String) of the value layout names.
2054:             */
2055:            private List layoutsList() {
2056:                List rv = new Vector();
2057:                String[] layoutNames = SiteService.getLayoutNames();
2058:                for (int i = 0; i < layoutNames.length; i++) {
2059:                    rv.add(layoutNames[i]);
2060:                }
2061:                return rv;
2062:
2063:            } // layoutsList
2064:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.