Source Code Cross Referenced for ResourcesAction.java in  » ERP-CRM-Financial » sakai » org » sakaiproject » content » 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.content.tool 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /**********************************************************************************
0002:         * $URL: https://source.sakaiproject.org/svn/content/tags/sakai_2-4-1/content-tool/tool/src/java/org/sakaiproject/content/tool/ResourcesAction.java $
0003:         * $Id: ResourcesAction.java 33703 2007-08-08 20:42:40Z ajpoland@iupui.edu $
0004:         ***********************************************************************************
0005:         *
0006:         * Copyright (c) 2003, 2004, 2005, 2006, 2007 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.content.tool;
0021:
0022:        import java.io.InputStream;
0023:        import java.net.MalformedURLException;
0024:        import java.net.URL;
0025:        import java.text.NumberFormat;
0026:        import java.util.ArrayList;
0027:        import java.util.Arrays;
0028:        import java.util.Collection;
0029:        import java.util.Collections;
0030:        import java.util.Comparator;
0031:        import java.util.Enumeration;
0032:        import java.util.HashMap;
0033:        import java.util.Hashtable;
0034:        import java.util.Iterator;
0035:        import java.util.LinkedList;
0036:        import java.util.List;
0037:        import java.util.Map;
0038:        import java.util.Set;
0039:        import java.util.SortedSet;
0040:        import java.util.Stack;
0041:        import java.util.TreeSet;
0042:        import java.util.Vector;
0043:        import java.util.regex.Matcher;
0044:        import java.util.regex.Pattern;
0045:
0046:        import org.apache.commons.logging.Log;
0047:        import org.apache.commons.logging.LogFactory;
0048:        import org.sakaiproject.authz.api.PermissionsHelper;
0049:        import org.sakaiproject.authz.cover.AuthzGroupService;
0050:        import org.sakaiproject.authz.cover.SecurityService;
0051:        import org.sakaiproject.cheftool.Context;
0052:        import org.sakaiproject.cheftool.JetspeedRunData;
0053:        import org.sakaiproject.cheftool.PagedResourceHelperAction;
0054:        import org.sakaiproject.cheftool.PortletConfig;
0055:        import org.sakaiproject.cheftool.RunData;
0056:        import org.sakaiproject.cheftool.VelocityPortlet;
0057:        import org.sakaiproject.component.cover.ComponentManager;
0058:        import org.sakaiproject.component.cover.ServerConfigurationService;
0059:        import org.sakaiproject.content.api.ContentCollection;
0060:        import org.sakaiproject.content.api.ContentCollectionEdit;
0061:        import org.sakaiproject.content.api.ContentEntity;
0062:        import org.sakaiproject.content.api.ContentResource;
0063:        import org.sakaiproject.content.api.ContentResourceEdit;
0064:        import org.sakaiproject.content.api.GroupAwareEntity;
0065:        import org.sakaiproject.content.api.InteractionAction;
0066:        import org.sakaiproject.content.api.MultiFileUploadPipe;
0067:        import org.sakaiproject.content.api.ResourceToolAction;
0068:        import org.sakaiproject.content.api.ResourceToolActionPipe;
0069:        import org.sakaiproject.content.api.ResourceType;
0070:        import org.sakaiproject.content.api.ResourceTypeRegistry;
0071:        import org.sakaiproject.content.api.ServiceLevelAction;
0072:        import org.sakaiproject.content.api.SiteSpecificResourceType;
0073:        import org.sakaiproject.content.api.GroupAwareEntity.AccessMode;
0074:        import org.sakaiproject.content.api.ResourceToolAction.ActionType;
0075:        import org.sakaiproject.content.cover.ContentHostingService;
0076:        import org.sakaiproject.content.cover.ContentTypeImageService;
0077:        import org.sakaiproject.coursemanagement.api.AcademicSession;
0078:        import org.sakaiproject.coursemanagement.api.CourseManagementService;
0079:        import org.sakaiproject.entity.api.Entity;
0080:        import org.sakaiproject.entity.api.EntityPropertyNotDefinedException;
0081:        import org.sakaiproject.entity.api.EntityPropertyTypeException;
0082:        import org.sakaiproject.entity.api.Reference;
0083:        import org.sakaiproject.entity.api.ResourceProperties;
0084:        import org.sakaiproject.entity.api.ResourcePropertiesEdit;
0085:        import org.sakaiproject.entity.cover.EntityManager;
0086:        import org.sakaiproject.event.api.SessionState;
0087:        import org.sakaiproject.event.api.UsageSession;
0088:        import org.sakaiproject.event.cover.NotificationService;
0089:        import org.sakaiproject.event.cover.UsageSessionService;
0090:        import org.sakaiproject.exception.IdInvalidException;
0091:        import org.sakaiproject.exception.IdLengthException;
0092:        import org.sakaiproject.exception.IdUniquenessException;
0093:        import org.sakaiproject.exception.IdUnusedException;
0094:        import org.sakaiproject.exception.IdUsedException;
0095:        import org.sakaiproject.exception.InUseException;
0096:        import org.sakaiproject.exception.InconsistentException;
0097:        import org.sakaiproject.exception.OverQuotaException;
0098:        import org.sakaiproject.exception.PermissionException;
0099:        import org.sakaiproject.exception.ServerOverloadException;
0100:        import org.sakaiproject.exception.TypeException;
0101:        import org.sakaiproject.site.api.Site;
0102:        import org.sakaiproject.site.cover.SiteService;
0103:        import org.sakaiproject.time.api.Time;
0104:        import org.sakaiproject.time.api.TimeBreakdown;
0105:        import org.sakaiproject.time.cover.TimeService;
0106:        import org.sakaiproject.tool.api.ToolSession;
0107:        import org.sakaiproject.tool.cover.SessionManager;
0108:        import org.sakaiproject.tool.cover.ToolManager;
0109:        import org.sakaiproject.user.api.User;
0110:        import org.sakaiproject.user.api.UserNotDefinedException;
0111:        import org.sakaiproject.user.cover.UserDirectoryService;
0112:        import org.sakaiproject.util.FormattedText;
0113:        import org.sakaiproject.util.ParameterParser;
0114:        import org.sakaiproject.util.ResourceLoader;
0115:        import org.sakaiproject.util.StringUtil;
0116:        import org.sakaiproject.util.Validator;
0117:        import org.w3c.dom.Element;
0118:
0119:        /**
0120:         * <p>ResourceAction is a ContentHosting application</p>
0121:         *
0122:         * @author University of Michigan, CHEF Software Development Team
0123:         * @version $Revision: 33703 $
0124:         */
0125:        public class ResourcesAction extends PagedResourceHelperAction // VelocityPortletPaneledAction
0126:        {
0127:            /**
0128:             * Action
0129:             *
0130:             */
0131:            public class Action {
0132:                protected String actionId;
0133:                protected String label;
0134:
0135:                /**
0136:                 * @return the actionId
0137:                 */
0138:                public String getActionId() {
0139:                    return this .actionId;
0140:                }
0141:
0142:                /**
0143:                 * @return the label
0144:                 */
0145:                public String getLabel() {
0146:                    return this .label;
0147:                }
0148:
0149:                /**
0150:                 * @param actionId the actionId to set
0151:                 */
0152:
0153:                public void setActionId(String actionId) {
0154:                    this .actionId = actionId;
0155:                }
0156:
0157:                /**
0158:                 * @param label the label to set
0159:                 */
0160:                public void setLabel(String label) {
0161:                    this .label = label;
0162:                }
0163:
0164:            }
0165:
0166:            /**
0167:             * Inner class encapsulates information about folders (and final item?) in a collection path (a.k.a. breadcrumb)
0168:             * This is being phased out as we switch to the resources type registry.
0169:             */
0170:            public static class ChefPathItem {
0171:                protected boolean m_canRead;
0172:                protected String m_id;
0173:                protected boolean m_isFolder;
0174:                protected boolean m_isLast;
0175:                protected boolean m_isLocal;
0176:                protected String m_name;
0177:                protected String m_root;
0178:                protected String m_url;
0179:
0180:                public ChefPathItem(String id, String name) {
0181:                    m_id = id;
0182:                    m_name = name;
0183:                    m_canRead = false;
0184:                    m_isFolder = false;
0185:                    m_isLast = false;
0186:                    m_url = "";
0187:                    m_isLocal = true;
0188:                }
0189:
0190:                /**
0191:                 * @return
0192:                 */
0193:                public boolean canRead() {
0194:                    return m_canRead;
0195:                }
0196:
0197:                /**
0198:                 * @return
0199:                 */
0200:                public String getId() {
0201:                    return m_id;
0202:                }
0203:
0204:                /**
0205:                 * @return
0206:                 */
0207:                public String getName() {
0208:                    return m_name;
0209:                }
0210:
0211:                /**
0212:                 * @return
0213:                 */
0214:                public String getRoot() {
0215:                    return m_root;
0216:                }
0217:
0218:                /**
0219:                 * @return
0220:                 */
0221:                public String getUrl() {
0222:                    return m_url;
0223:                }
0224:
0225:                /**
0226:                 * @return
0227:                 */
0228:                public boolean isFolder() {
0229:                    return m_isFolder;
0230:                }
0231:
0232:                /**
0233:                 * @return
0234:                 */
0235:                public boolean isLast() {
0236:                    return m_isLast;
0237:                }
0238:
0239:                public boolean isLocal() {
0240:                    return m_isLocal;
0241:                }
0242:
0243:                /**
0244:                 * @param canRead
0245:                 */
0246:                public void setCanRead(boolean canRead) {
0247:                    m_canRead = canRead;
0248:                }
0249:
0250:                /**
0251:                 * @param id
0252:                 */
0253:                public void setId(String id) {
0254:                    m_id = id;
0255:                }
0256:
0257:                /**
0258:                 * @param isFolder
0259:                 */
0260:                public void setIsFolder(boolean isFolder) {
0261:                    m_isFolder = isFolder;
0262:                }
0263:
0264:                public void setIsLocal(boolean isLocal) {
0265:                    m_isLocal = isLocal;
0266:                }
0267:
0268:                /**
0269:                 * @param isLast
0270:                 */
0271:                public void setLast(boolean isLast) {
0272:                    m_isLast = isLast;
0273:                }
0274:
0275:                /**
0276:                 * @param name
0277:                 */
0278:                public void setName(String name) {
0279:                    m_name = name;
0280:                }
0281:
0282:                /**
0283:                 * @param root
0284:                 */
0285:                public void setRoot(String root) {
0286:                    m_root = root;
0287:                }
0288:
0289:                /**
0290:                 * @param url
0291:                 */
0292:                public void setUrl(String url) {
0293:                    m_url = url;
0294:                }
0295:
0296:            } // inner class ChefPathItem
0297:
0298:            public enum ContentPermissions {
0299:                CREATE, DELETE, READ, REVISE, SITE_UPDATE
0300:            }
0301:
0302:            public static class ElementCarrier {
0303:                protected Element element;
0304:                protected String parent;
0305:
0306:                public ElementCarrier(Element element, String parent) {
0307:                    this .element = element;
0308:                    this .parent = parent;
0309:
0310:                }
0311:
0312:                public Element getElement() {
0313:                    return element;
0314:                }
0315:
0316:                public String getParent() {
0317:                    return parent;
0318:                }
0319:
0320:                public void setElement(Element element) {
0321:                    this .element = element;
0322:                }
0323:
0324:                public void setParent(String parent) {
0325:                    this .parent = parent;
0326:                }
0327:
0328:            }
0329:
0330:            /**
0331:             *
0332:             * inner class encapsulates information about groups of metadata tags (such as DC, LOM, etc.)
0333:             *
0334:             */
0335:            public static class MetadataGroup extends Vector {
0336:                /**
0337:                 *
0338:                 */
0339:                private static final long serialVersionUID = -821054142728929236L;
0340:                protected boolean m_isShowing;
0341:                protected String m_name;
0342:
0343:                /**
0344:                 * @param name
0345:                 */
0346:                public MetadataGroup(String name) {
0347:                    super ();
0348:                    m_name = name;
0349:                    m_isShowing = false;
0350:                }
0351:
0352:                /* (non-Javadoc)
0353:                 * @see java.lang.Object#equals(java.lang.Object)
0354:                 * needed to determine List.contains()
0355:                 */
0356:                public boolean equals(Object obj) {
0357:                    MetadataGroup mg = (MetadataGroup) obj;
0358:                    boolean rv = (obj != null) && (m_name.equals(mg));
0359:                    return rv;
0360:                }
0361:
0362:                /**
0363:                 * @return
0364:                 */
0365:                public String getName() {
0366:                    return m_name;
0367:                }
0368:
0369:                /**
0370:                 * @return
0371:                 */
0372:                public boolean isShowing() {
0373:                    return m_isShowing;
0374:                }
0375:
0376:                /**
0377:                 * @param name
0378:                 */
0379:                public void setName(String name) {
0380:                    m_name = name;
0381:                }
0382:
0383:                /**
0384:                 * @param isShowing
0385:                 */
0386:                public void setShowing(boolean isShowing) {
0387:                    m_isShowing = isShowing;
0388:                }
0389:
0390:            }
0391:
0392:            /** Resource bundle using current language locale */
0393:            private static ResourceLoader rb = new ResourceLoader("content");
0394:            /** Resource bundle using current language locale */
0395:            public static ResourceLoader trb = new ResourceLoader("types");
0396:            static final Log logger = LogFactory.getLog(ResourcesAction.class);
0397:
0398:            public static final String PREFIX = "resources.";
0399:
0400:            public static final List<ActionType> ACTIONS_ON_FOLDERS = new Vector<ActionType>();
0401:            public static final List<ActionType> ACTIONS_ON_MULTIPLE_ITEMS = new Vector<ActionType>();
0402:            public static final List<ActionType> ACTIONS_ON_RESOURCES = new Vector<ActionType>();
0403:
0404:            public static final List<ActionType> CONTENT_DELETE_ACTIONS = new Vector<ActionType>();
0405:            public static final List<ActionType> CONTENT_MODIFY_ACTIONS = new Vector<ActionType>();
0406:            public static final List<ActionType> CONTENT_NEW_ACTIONS = new Vector<ActionType>();
0407:            public static final List<ActionType> CONTENT_NEW_FOR_PARENT_ACTIONS = new Vector<ActionType>();
0408:            public static final List<ActionType> CONTENT_READ_ACTIONS = new Vector<ActionType>();
0409:
0410:            public static final List<ActionType> CREATION_ACTIONS = new Vector<ActionType>();
0411:
0412:            public static final List<ActionType> PASTE_COPIED_ACTIONS = new Vector<ActionType>();
0413:            public static final List<ActionType> PASTE_MOVED_ACTIONS = new Vector<ActionType>();
0414:
0415:            public static final List<ActionType> SITE_UPDATE_ACTIONS = new Vector<ActionType>();
0416:
0417:            /** copyright path -- MUST have same value as AccessServlet.COPYRIGHT_PATH */
0418:            public static final String COPYRIGHT_PATH = Entity.SEPARATOR
0419:                    + "copyright";
0420:
0421:            private static final String STATE_DEFAULT_COPYRIGHT = PREFIX
0422:                    + "default_copyright";
0423:
0424:            private static final String STATE_DEFAULT_COPYRIGHT_ALERT = PREFIX
0425:                    + "default_copyright_alert";
0426:
0427:            private static final String COPYRIGHT_ALERT_URL = ServerConfigurationService
0428:                    .getAccessUrl()
0429:                    + COPYRIGHT_PATH;
0430:
0431:            private static final String STATE_COPYRIGHT_FAIRUSE_URL = PREFIX
0432:                    + "copyright_fairuse_url";
0433:
0434:            private static final String STATE_COPYRIGHT_NEW_COPYRIGHT = PREFIX
0435:                    + "new_copyright";
0436:
0437:            /** copyright related info */
0438:            private static final String STATE_COPYRIGHT_TYPES = PREFIX
0439:                    + "copyright_types";
0440:
0441:            private static final int CREATE_MAX_ITEMS = 10;
0442:
0443:            /** The default number of site collections per page. */
0444:            protected static final int DEFAULT_PAGE_SIZE = 50;
0445:
0446:            public static final String DELIM = "@";
0447:
0448:            /** The default number of members for a collection at which this tool should refuse to expand the collection. Used only if value can't be read from config service. */
0449:            protected static final int EXPANDABLE_FOLDER_SIZE_LIMIT = 256;
0450:
0451:            private static final String LIST_COLUMNS = "columns";
0452:
0453:            private static final String LIST_HIERARCHY = "hierarchy";
0454:
0455:            public static final int MAXIMUM_ATTEMPTS_FOR_UNIQUENESS = 100;
0456:
0457:            /** The maximum number of suspended operations that can be on the stack. */
0458:            private static final int MAXIMUM_SUSPENDED_OPERATIONS_STACK_DEPTH = 10;
0459:
0460:            public static final String MIME_TYPE_DOCUMENT_HTML = "text/html";
0461:
0462:            public static final String MIME_TYPE_DOCUMENT_PLAINTEXT = "text/plain";
0463:
0464:            public static final String MIME_TYPE_STRUCTOBJ = "application/x-osp";
0465:
0466:            public static final String MODE_ATTACHMENT_CONFIRM = "resources.attachment_confirm";
0467:
0468:            public static final String MODE_ATTACHMENT_CONFIRM_INIT = "resources.attachment_confirm_initialized";
0469:
0470:            public static final String MODE_ATTACHMENT_CREATE = "resources.attachment_create";
0471:
0472:            public static final String MODE_ATTACHMENT_CREATE_INIT = "resources.attachment_create_initialized";
0473:
0474:            public static final String MODE_ATTACHMENT_DONE = "resources.attachment_done";
0475:
0476:            public static final String MODE_ATTACHMENT_EDIT_ITEM = "resources.attachment_edit_item";
0477:
0478:            public static final String MODE_ATTACHMENT_EDIT_ITEM_INIT = "resources.attachment_edit_item_initialized";
0479:
0480:            public static final String MODE_ATTACHMENT_NEW_ITEM = "resources.attachment_new_item";
0481:
0482:            public static final String MODE_ATTACHMENT_NEW_ITEM_INIT = "resources.attachment_new_item_initialized";
0483:
0484:            /** modes for attachment helper */
0485:            public static final String MODE_ATTACHMENT_SELECT = "resources.attachment_select";
0486:
0487:            public static final String MODE_ATTACHMENT_SELECT_INIT = "resources.attachment_select_initialized";
0488:
0489:            //private static final String MODE_CREATE = "create";
0490:            private static final String MODE_CREATE_WIZARD = "createWizard";
0491:
0492:            /************** the more context *****************************************/
0493:
0494:            private static final String MODE_DAV = "webdav";
0495:
0496:            private static final String MODE_DELETE_CONFIRM = "deleteConfirm";
0497:
0498:            /************** the edit context *****************************************/
0499:
0500:            private static final String MODE_DELETE_FINISH = "deleteFinish";
0501:
0502:            public static final String MODE_HELPER = "helper";
0503:
0504:            /** Modes. */
0505:            private static final String MODE_LIST = "list";
0506:            private static final String MODE_MORE = "more";
0507:
0508:            private static final String MODE_PROPERTIES = "properties";
0509:
0510:            private static final String MODE_REORDER = "reorder";
0511:
0512:            static final String MODE_REVISE_METADATA = "revise_metadata";
0513:
0514:            private static final String STATE_NEW_COPYRIGHT_INPUT = PREFIX
0515:                    + "new_copyright_input";
0516:
0517:            /** The null/empty string */
0518:            private static final String NULL_STRING = "";
0519:
0520:            /** A long representing the number of milliseconds in one week.  Used for date calculations */
0521:            protected static final long ONE_WEEK = 1000L * 60L * 60L * 24L * 7L;
0522:
0523:            protected static final String PARAM_PAGESIZE = "collections_per_page";
0524:
0525:            /** string used to represent "public" access mode in UI elements */
0526:            protected static final String PUBLIC_ACCESS = "public";
0527:
0528:            public static final String RESOURCES_MODE_DROPBOX = "dropbox";
0529:
0530:            public static final String RESOURCES_MODE_HELPER = "helper";
0531:
0532:            public static final String RESOURCES_MODE_RESOURCES = "resources";
0533:
0534:            /** The default value for whether to show all sites in dropbox (used if global value can't be read from server config service) */
0535:            private static final boolean SHOW_ALL_SITES_IN_DROPBOX = false;
0536:
0537:            /** The default value for whether to show all sites in file-picker (used if global value can't be read from server config service) */
0538:            public static final boolean SHOW_ALL_SITES_IN_FILE_PICKER = false;
0539:            /** The default value for whether to show all sites in resources tool (used if global value can't be read from server config service) */
0540:            private static final boolean SHOW_ALL_SITES_IN_RESOURCES = false;
0541:            /** The collection id being browsed. */
0542:            private static final String STATE_COLLECTION_ID = PREFIX
0543:                    + "collection_id";
0544:
0545:            /** The collection id path */
0546:            private static final String STATE_COLLECTION_PATH = PREFIX
0547:                    + "collection_path";
0548:
0549:            /** The name of the state attribute containing BrowseItems for all content collections the user has access to */
0550:            private static final String STATE_COLLECTION_ROOTS = PREFIX
0551:                    + "collection_rootie_tooties";
0552:
0553:            public static final String STATE_COLUMN_ITEM_ID = PREFIX
0554:                    + "state_column_item_id";
0555:
0556:            /** The content hosting service in the State. */
0557:            private static final String STATE_CONTENT_SERVICE = PREFIX
0558:                    + "content_service";
0559:
0560:            /** The content type image lookup service in the State. */
0561:            private static final String STATE_CONTENT_TYPE_IMAGE_SERVICE = PREFIX
0562:                    + "content_type_image_service";
0563:
0564:            /** The copied item ids */
0565:            private static final String STATE_COPIED_IDS = PREFIX
0566:                    + "revise_copied_ids";
0567:
0568:            /** The copy flag */
0569:            private static final String STATE_COPY_FLAG = PREFIX + "copy_flag";
0570:
0571:            //	public static final String STATE_CREATE_TYPE = PREFIX + "create_type";
0572:            public static final String STATE_CREATE_COLLECTION_ID = PREFIX
0573:                    + "create_collection_id";
0574:
0575:            protected static final String STATE_CREATE_MESSAGE = PREFIX
0576:                    + "create_message";
0577:
0578:            public static final String STATE_CREATE_NUMBER = PREFIX
0579:                    + "create_number";
0580:
0581:            protected static final String STATE_CREATE_WIZARD_ACTION = PREFIX
0582:                    + "create_wizard_action";
0583:
0584:            protected static final String STATE_CREATE_WIZARD_COLLECTION_ID = PREFIX
0585:                    + "create_wizard_collection_id";
0586:
0587:            protected static final String STATE_CREATE_WIZARD_ITEM = PREFIX
0588:                    + "create_wizard_item";
0589:
0590:            /** name of state attribute for the default retract time */
0591:            protected static final String STATE_DEFAULT_RETRACT_TIME = PREFIX
0592:                    + "default_retract_time";
0593:
0594:            /** The name of the state attribute containing a list of ListItem objects corresponding to resources selected for deletion */
0595:            private static final String STATE_DELETE_ITEMS = PREFIX
0596:                    + "delete_items";
0597:
0598:            /** The name of the state attribute containing a list of ListItem objects corresponding to nonempty folders selected for deletion */
0599:            private static final String STATE_DELETE_ITEMS_NOT_EMPTY = PREFIX
0600:                    + "delete_items_not_empty";
0601:
0602:            protected static final String STATE_DELETE_SET = PREFIX
0603:                    + "delete_set";
0604:
0605:            /** The name of the state attribute indicating whether the hierarchical list is expanded */
0606:            private static final String STATE_EXPAND_ALL_FLAG = PREFIX
0607:                    + "expand_all_flag";
0608:
0609:            /** Name of state attribute indicating number of members for a collection at which this tool should refuse to expand the collection. */
0610:            private static final String STATE_EXPANDABLE_FOLDER_SIZE_LIMIT = PREFIX
0611:                    + "expandable_folder_size_limit";
0612:
0613:            /** Name of state attribute containing a list of opened/expanded collections */
0614:            private static final String STATE_EXPANDED_COLLECTIONS = PREFIX
0615:                    + "expanded_collections";
0616:
0617:            protected static final String STATE_EXPANDED_FOLDER_SORT_MAP = PREFIX
0618:                    + "expanded_folder_sort_map";
0619:
0620:            /** state attribute for the maximum size for file upload */
0621:            static final String STATE_FILE_UPLOAD_MAX_SIZE = PREFIX
0622:                    + "file_upload_max_size";
0623:
0624:            /** The from state name */
0625:            private static final String STATE_FROM = PREFIX + "from";
0626:
0627:            /** State attribute for where there is at least one attachment before invoking attachment tool */
0628:            public static final String STATE_HAS_ATTACHMENT_BEFORE = PREFIX
0629:                    + "has_attachment_before";
0630:
0631:            /**
0632:             *  the name of the state attribute indicating that the user canceled out of the helper.  Is set only if the user canceled out of the helper. 
0633:             */
0634:            public static final String STATE_HELPER_CANCELED_BY_USER = PREFIX
0635:                    + "state_attach_canceled_by_user";
0636:
0637:            protected static final String STATE_HIGHLIGHTED_ITEMS = PREFIX
0638:                    + "highlighted_items";
0639:
0640:            /** The display name of the "home" collection (can't go up from here.) */
0641:            private static final String STATE_HOME_COLLECTION_DISPLAY_NAME = PREFIX
0642:                    + "collection_home_display_name";
0643:
0644:            /** The id of the "home" collection (can't go up from here.) */
0645:            private static final String STATE_HOME_COLLECTION_ID = PREFIX
0646:                    + "collection_home";
0647:
0648:            /** Name of state attribute for status of initialization.  */
0649:            private static final String STATE_INITIALIZED = PREFIX
0650:                    + "initialized";
0651:
0652:            protected static final String STATE_ITEMS_TO_BE_COPIED = PREFIX
0653:                    + "items_to_be_copied";
0654:
0655:            protected static final String STATE_ITEMS_TO_BE_MOVED = PREFIX
0656:                    + "items_to_be_moved";
0657:
0658:            private static final String STATE_LIST_PREFERENCE = PREFIX
0659:                    + "state_list_preference";
0660:
0661:            /** The name of the state attribute containing a java.util.Set with the id's of selected items */
0662:            private static final String STATE_LIST_SELECTIONS = PREFIX
0663:                    + "ignore_delete_selections";
0664:
0665:            protected static final String STATE_LIST_VIEW_SORT = PREFIX
0666:                    + "list_view_sort";
0667:
0668:            private static final String STATE_METADATA_GROUPS = PREFIX
0669:                    + "metadata.types";
0670:
0671:            /** The resources, helper or dropbox mode. */
0672:            public static final String STATE_MODE_RESOURCES = PREFIX
0673:                    + "resources_mode";
0674:
0675:            /** The more collection id */
0676:            private static final String STATE_MORE_COLLECTION_ID = PREFIX
0677:                    + "more_collection_id";
0678:
0679:            /** The more id */
0680:            private static final String STATE_MORE_ID = PREFIX + "more_id";
0681:
0682:            /** The move flag */
0683:            private static final String STATE_MOVE_FLAG = PREFIX + "move_flag";
0684:
0685:            /** The copied item ids */
0686:            private static final String STATE_MOVED_IDS = PREFIX
0687:                    + "revise_moved_ids";
0688:
0689:            /** The user copyright string */
0690:            private static final String STATE_MY_COPYRIGHT = PREFIX
0691:                    + "mycopyright";
0692:
0693:            /** The root of the navigation breadcrumbs for a folder, either the home or another site the user belongs to */
0694:            private static final String STATE_NAVIGATION_ROOT = PREFIX
0695:                    + "navigation_root";
0696:
0697:            /** The name of the state attribute indicating whether the hierarchical list needs to be expanded */
0698:            private static final String STATE_NEED_TO_EXPAND_ALL = PREFIX
0699:                    + "need_to_expand_all";
0700:
0701:            protected static final String STATE_NON_EMPTY_DELETE_SET = PREFIX
0702:                    + "non-empty_delete_set";
0703:
0704:            /** The can-paste flag */
0705:            private static final String STATE_PASTE_ALLOWED_FLAG = PREFIX
0706:                    + "can_paste_flag";
0707:
0708:            /** state attribute indicating whether users in current site should be denied option of making resources public */
0709:            private static final String STATE_PREVENT_PUBLIC_DISPLAY = PREFIX
0710:                    + "prevent_public_display";
0711:
0712:            protected static final String STATE_REMOVED_ATTACHMENTS = PREFIX
0713:                    + "removed_attachments";
0714:
0715:            protected static final String STATE_REORDER_FOLDER = PREFIX
0716:                    + "reorder_folder_id";
0717:
0718:            protected static final String STATE_REORDER_SORT = PREFIX
0719:                    + "reorder_sort";
0720:
0721:            /** The sort ascending or decending for the reorder context */
0722:            protected static final String STATE_REORDER_SORT_ASC = PREFIX
0723:                    + "sort_asc";
0724:
0725:            /** The property (column) to sort by in the reorder context */
0726:            protected static final String STATE_REORDER_SORT_BY = PREFIX
0727:                    + "reorder_sort_by";
0728:
0729:            /** The resources, helper or dropbox mode. */
0730:            public static final String STATE_RESOURCES_HELPER_MODE = PREFIX
0731:                    + "resources_helper_mode";
0732:
0733:            private static final String STATE_RESOURCES_TYPE_REGISTRY = PREFIX
0734:                    + "type_registry";
0735:
0736:            protected static final String STATE_REVISE_PROPERTIES_ACTION = PREFIX
0737:                    + "revise_properties_action";
0738:
0739:            protected static final String STATE_REVISE_PROPERTIES_ENTITY_ID = PREFIX
0740:                    + "revise_properties_entity_id";
0741:
0742:            protected static final String STATE_REVISE_PROPERTIES_ITEM = PREFIX
0743:                    + "revise_properties_item";
0744:
0745:            /** The select all flag */
0746:            private static final String STATE_SELECT_ALL_FLAG = PREFIX
0747:                    + "select_all_flag";
0748:
0749:            /** The name of a state attribute indicating whether the resources tool/helper is allowed to show all sites the user has access to */
0750:            public static final String STATE_SHOW_ALL_SITES = PREFIX
0751:                    + "allow_user_to_see_all_sites";
0752:
0753:            protected static final String STATE_SHOW_COPY_ACTION = PREFIX
0754:                    + "show_copy_action";
0755:
0756:            private static final String STATE_SHOW_FORM_ITEMS = PREFIX
0757:                    + "show_form_items";
0758:
0759:            protected static final String STATE_SHOW_MOVE_ACTION = PREFIX
0760:                    + "show_move_action";
0761:
0762:            /** The name of a state attribute indicating whether the wants to see other sites if that is enabled */
0763:            public static final String STATE_SHOW_OTHER_SITES = PREFIX
0764:                    + "user_chooses_to_see_other_sites";
0765:
0766:            protected static final String STATE_SHOW_REMOVE_ACTION = PREFIX
0767:                    + "show_remove_action";
0768:
0769:            /** the site title */
0770:            private static final String STATE_SITE_TITLE = PREFIX
0771:                    + "site_title";
0772:
0773:            /** The sort ascending or decending */
0774:            private static final String STATE_SORT_ASC = PREFIX + "sort_asc";
0775:
0776:            /** The sort by */
0777:            private static final String STATE_SORT_BY = PREFIX + "sort_by";
0778:
0779:            public static final String STATE_STACK_CREATE_COLLECTION_ID = PREFIX
0780:                    + "stack_create_collection_id";
0781:
0782:            public static final String STATE_STACK_CREATE_NUMBER = PREFIX
0783:                    + "stack_create_number";
0784:
0785:            public static final String STATE_STACK_CREATE_TYPE = PREFIX
0786:                    + "stack_create_type";
0787:
0788:            public static final String STATE_STACK_EDIT_COLLECTION_ID = PREFIX
0789:                    + "stack_edit_collection_id";
0790:
0791:            public static final String STATE_STACK_EDIT_ID = PREFIX
0792:                    + "stack_edit_id";
0793:
0794:            public static final String STATE_STACK_STRUCTOBJ_TYPE = PREFIX
0795:                    + "stack_create_structured_object_type";
0796:
0797:            public static final String STATE_SUSPENDED_OPERATIONS_STACK = PREFIX
0798:                    + "suspended_operations_stack";
0799:
0800:            public static final String STATE_SUSPENDED_OPERATIONS_STACK_DEPTH = PREFIX
0801:                    + "suspended_operations_stack_depth";
0802:
0803:            protected static final String STATE_TOP_MESSAGE_INDEX = PREFIX
0804:                    + "top_message_index";
0805:
0806:            /** state attribute indicating whether we're using the Creative Commons dialog instead of the "old" copyright dialog */
0807:            protected static final String STATE_USING_CREATIVE_COMMONS = PREFIX
0808:                    + "usingCreativeCommons";
0809:
0810:            /** vm files for each mode. */
0811:            //private static final String TEMPLATE_LIST = "content/chef_resources_list";
0812:            //private static final String TEMPLATE_EDIT = "content/chef_resources_edit";
0813:            //private static final String TEMPLATE_CREATE = "content/chef_resources_create";
0814:            private static final String TEMPLATE_DAV = "content/chef_resources_webdav";
0815:            //private static final String TEMPLATE_ITEMTYPE = "content/chef_resources_itemtype";
0816:            //private static final String TEMPLATE_SELECT = "content/chef_resources_select";
0817:            //private static final String TEMPLATE_ATTACH = "content/chef_resources_attach";
0818:
0819:            private static final String TEMPLATE_DELETE_CONFIRM = "content/chef_resources_deleteConfirm";
0820:
0821:            private static final String TEMPLATE_DELETE_FINISH = "content/sakai_resources_deleteFinish";
0822:
0823:            private static final String TEMPLATE_MORE = "content/chef_resources_more";
0824:
0825:            private static final String TEMPLATE_NEW_LIST = "content/sakai_resources_list";
0826:
0827:            private static final String TEMPLATE_OPTIONS = "content/sakai_resources_options";
0828:
0829:            private static final String TEMPLATE_PROPERTIES = "content/chef_resources_properties";
0830:
0831:            // private static final String TEMPLATE_REPLACE = "_replace";
0832:            private static final String TEMPLATE_REORDER = "content/chef_resources_reorder";
0833:
0834:            private static final String TEMPLATE_REVISE_METADATA = "content/sakai_resources_properties";
0835:
0836:            public static final String TYPE_HTML = MIME_TYPE_DOCUMENT_HTML;
0837:
0838:            public static final String TYPE_TEXT = MIME_TYPE_DOCUMENT_PLAINTEXT;
0839:
0840:            public static final String TYPE_UPLOAD = "file";
0841:
0842:            public static final String TYPE_URL = "Url";
0843:
0844:            public static final String UTF_8_ENCODING = "UTF-8";
0845:
0846:            // may need to distinguish permission on entity vs permission on its containing collection
0847:            static {
0848:                CONTENT_NEW_ACTIONS.add(ActionType.NEW_UPLOAD);
0849:                CONTENT_NEW_ACTIONS.add(ActionType.NEW_FOLDER);
0850:                CONTENT_NEW_ACTIONS.add(ActionType.NEW_URLS);
0851:                CONTENT_NEW_ACTIONS.add(ActionType.CREATE);
0852:
0853:                PASTE_COPIED_ACTIONS.add(ActionType.PASTE_COPIED);
0854:                PASTE_MOVED_ACTIONS.add(ActionType.PASTE_MOVED);
0855:
0856:                CONTENT_NEW_FOR_PARENT_ACTIONS.add(ActionType.DUPLICATE);
0857:
0858:                CONTENT_READ_ACTIONS.add(ActionType.VIEW_CONTENT);
0859:                CONTENT_READ_ACTIONS.add(ActionType.VIEW_METADATA);
0860:                CONTENT_READ_ACTIONS.add(ActionType.COPY);
0861:
0862:                CONTENT_MODIFY_ACTIONS.add(ActionType.REVISE_METADATA);
0863:                CONTENT_MODIFY_ACTIONS.add(ActionType.REVISE_CONTENT);
0864:                CONTENT_MODIFY_ACTIONS.add(ActionType.REPLACE_CONTENT);
0865:                CONTENT_MODIFY_ACTIONS.add(ActionType.REVISE_ORDER);
0866:
0867:                CONTENT_DELETE_ACTIONS.add(ActionType.MOVE);
0868:                CONTENT_DELETE_ACTIONS.add(ActionType.DELETE);
0869:
0870:                SITE_UPDATE_ACTIONS.add(ActionType.REVISE_PERMISSIONS);
0871:
0872:                ACTIONS_ON_FOLDERS.add(ActionType.VIEW_METADATA);
0873:                ACTIONS_ON_FOLDERS.add(ActionType.REVISE_METADATA);
0874:                ACTIONS_ON_FOLDERS.add(ActionType.DUPLICATE);
0875:                ACTIONS_ON_FOLDERS.add(ActionType.COPY);
0876:                ACTIONS_ON_FOLDERS.add(ActionType.MOVE);
0877:                ACTIONS_ON_FOLDERS.add(ActionType.DELETE);
0878:                ACTIONS_ON_FOLDERS.add(ActionType.REVISE_ORDER);
0879:                ACTIONS_ON_FOLDERS.add(ActionType.REVISE_PERMISSIONS);
0880:                // ACTIONS_ON_FOLDERS.add(ActionType.PASTE_MOVED);
0881:
0882:                ACTIONS_ON_RESOURCES.add(ActionType.VIEW_CONTENT);
0883:                ACTIONS_ON_RESOURCES.add(ActionType.VIEW_METADATA);
0884:                ACTIONS_ON_RESOURCES.add(ActionType.REVISE_METADATA);
0885:                ACTIONS_ON_RESOURCES.add(ActionType.REVISE_CONTENT);
0886:                ACTIONS_ON_RESOURCES.add(ActionType.REPLACE_CONTENT);
0887:                ACTIONS_ON_RESOURCES.add(ActionType.DUPLICATE);
0888:                ACTIONS_ON_RESOURCES.add(ActionType.COPY);
0889:                ACTIONS_ON_RESOURCES.add(ActionType.MOVE);
0890:                ACTIONS_ON_RESOURCES.add(ActionType.DELETE);
0891:
0892:                ACTIONS_ON_MULTIPLE_ITEMS.add(ActionType.COPY);
0893:                ACTIONS_ON_MULTIPLE_ITEMS.add(ActionType.MOVE);
0894:                ACTIONS_ON_MULTIPLE_ITEMS.add(ActionType.DELETE);
0895:
0896:                CREATION_ACTIONS.add(ActionType.NEW_UPLOAD);
0897:                CREATION_ACTIONS.add(ActionType.NEW_FOLDER);
0898:                CREATION_ACTIONS.add(ActionType.NEW_URLS);
0899:                CREATION_ACTIONS.add(ActionType.CREATE);
0900:                CREATION_ACTIONS.add(ActionType.PASTE_MOVED);
0901:                CREATION_ACTIONS.add(ActionType.PASTE_COPIED);
0902:            }
0903:
0904:            /**
0905:             * Add additional resource pattern to the observer
0906:             *@param pattern The pattern value to be added
0907:             *@param state The state object
0908:             */
0909:            private static void addObservingPattern(String pattern,
0910:                    SessionState state) {
0911:                //		// get the observer and add the pattern
0912:                //		ContentObservingCourier o = (ContentObservingCourier) state.getAttribute(STATE_OBSERVER);
0913:                //		o.addResourcePattern(ContentHostingService.getReference(pattern));
0914:                //
0915:                //		// add it back to state
0916:                //		state.setAttribute(STATE_OBSERVER, o);
0917:
0918:            } // addObservingPattern
0919:
0920:            /**
0921:             * Build the context to show the list of resource properties
0922:             */
0923:            public static String buildMoreContext(VelocityPortlet portlet,
0924:                    Context context, RunData data, SessionState state) {
0925:                context.put("tlang", rb);
0926:                // find the ContentTypeImage service
0927:                context.put("contentTypeImageService", state
0928:                        .getAttribute(STATE_CONTENT_TYPE_IMAGE_SERVICE));
0929:                // find the ContentHosting service
0930:                org.sakaiproject.content.api.ContentHostingService service = (org.sakaiproject.content.api.ContentHostingService) state
0931:                        .getAttribute(STATE_CONTENT_SERVICE);
0932:                context.put("service", service);
0933:
0934:                Map current_stack_frame = peekAtStack(state);
0935:
0936:                String id = (String) current_stack_frame.get(STATE_MORE_ID);
0937:                context.put("id", id);
0938:                String collectionId = (String) current_stack_frame
0939:                        .get(STATE_MORE_COLLECTION_ID);
0940:                context.put("collectionId", collectionId);
0941:                String homeCollectionId = (String) (String) state
0942:                        .getAttribute(STATE_HOME_COLLECTION_ID);
0943:                context.put("homeCollectionId", homeCollectionId);
0944:                //List cPath = getCollectionPath(state);
0945:                //context.put ("collectionPath", cPath);
0946:                String navRoot = (String) state
0947:                        .getAttribute(STATE_NAVIGATION_ROOT);
0948:                context.put("navRoot", navRoot);
0949:
0950:                ResourcesEditItem item = getEditItem(id, collectionId, data);
0951:                context.put("item", item);
0952:
0953:                // for the resources of type URL or plain text, show the content also
0954:                try {
0955:                    ResourceProperties properties = service.getProperties(id);
0956:                    context.put("properties", properties);
0957:
0958:                    String isCollection = properties
0959:                            .getProperty(ResourceProperties.PROP_IS_COLLECTION);
0960:                    if ((isCollection != null)
0961:                            && isCollection.equals(Boolean.FALSE.toString())) {
0962:                        String copyrightAlert = properties
0963:                                .getProperty(properties
0964:                                        .getNamePropCopyrightAlert());
0965:                        context.put("hasCopyrightAlert", copyrightAlert);
0966:
0967:                        String type = properties
0968:                                .getProperty(ResourceProperties.PROP_CONTENT_TYPE);
0969:                        if (type.equalsIgnoreCase(MIME_TYPE_DOCUMENT_PLAINTEXT)
0970:                                || type
0971:                                        .equalsIgnoreCase(MIME_TYPE_DOCUMENT_HTML)
0972:                                || type
0973:                                        .equalsIgnoreCase(ResourceProperties.TYPE_URL)) {
0974:                            ContentResource moreResource = service
0975:                                    .getResource(id);
0976:                            // read the body
0977:                            String body = "";
0978:                            byte[] content = null;
0979:                            try {
0980:                                content = moreResource.getContent();
0981:                                if (content != null) {
0982:                                    body = new String(content);
0983:                                }
0984:                            } catch (ServerOverloadException e) {
0985:                                // this represents server's file system is temporarily unavailable
0986:                                // report problem to user? log problem?
0987:                            }
0988:                            context.put("content", body);
0989:                        } // if
0990:                    } // if
0991:
0992:                    else {
0993:                        // setup for quota - ADMIN only, collection only
0994:                        if (SecurityService.isSuperUser()) {
0995:                            try {
0996:                                // Getting the quota as a long validates the property
0997:                                long quota = properties
0998:                                        .getLongProperty(ResourceProperties.PROP_COLLECTION_BODY_QUOTA);
0999:                                context.put("hasQuota", Boolean.TRUE);
1000:                                context
1001:                                        .put(
1002:                                                "quota",
1003:                                                properties
1004:                                                        .getProperty(ResourceProperties.PROP_COLLECTION_BODY_QUOTA));
1005:                            } catch (Exception any) {
1006:                            }
1007:                        }
1008:                    }
1009:                } catch (IdUnusedException e) {
1010:                    addAlert(state, rb.getString("notexist1"));
1011:                    context.put("notExistFlag", new Boolean(true));
1012:                } catch (TypeException e) {
1013:                    addAlert(state, rb.getString("typeex") + " ");
1014:                } catch (PermissionException e) {
1015:                    addAlert(state, " " + rb.getString("notpermis2") + " " + id
1016:                            + ". ");
1017:                } // try-catch
1018:
1019:                if (state.getAttribute(STATE_MESSAGE) == null) {
1020:                    context.put("notExistFlag", new Boolean(false));
1021:                }
1022:
1023:                if (RESOURCES_MODE_DROPBOX.equalsIgnoreCase((String) state
1024:                        .getAttribute(STATE_MODE_RESOURCES))) {
1025:                    // notshow the public option or notification when in dropbox mode
1026:                    context.put("dropboxMode", Boolean.TRUE);
1027:                } else {
1028:                    context.put("dropboxMode", Boolean.FALSE);
1029:
1030:                    Boolean preventPublicDisplay = (Boolean) state
1031:                            .getAttribute(STATE_PREVENT_PUBLIC_DISPLAY);
1032:                    if (preventPublicDisplay == null) {
1033:                        preventPublicDisplay = Boolean.FALSE;
1034:                        state.setAttribute(STATE_PREVENT_PUBLIC_DISPLAY,
1035:                                preventPublicDisplay);
1036:                    }
1037:                    context.put("preventPublicDisplay", preventPublicDisplay);
1038:                    if (preventPublicDisplay.equals(Boolean.FALSE)) {
1039:                        // find out about pubview
1040:                        boolean pubview = ContentHostingService
1041:                                .isInheritingPubView(id);
1042:                        if (!pubview)
1043:                            pubview = ContentHostingService.isPubView(id);
1044:                        context.put("pubview", new Boolean(pubview));
1045:                    }
1046:
1047:                }
1048:
1049:                context.put("siteTitle", state.getAttribute(STATE_SITE_TITLE));
1050:
1051:                if (state.getAttribute(STATE_COPYRIGHT_TYPES) != null) {
1052:                    List copyrightTypes = (List) state
1053:                            .getAttribute(STATE_COPYRIGHT_TYPES);
1054:                    context.put("copyrightTypes", copyrightTypes);
1055:                }
1056:
1057:                metadataGroupsIntoContext(state, context);
1058:
1059:                // String template = (String) getContext(data).get("template");
1060:                return TEMPLATE_MORE;
1061:
1062:            } // buildMoreContext
1063:
1064:            //	/**
1065:            //	 * Retrieve values for one or more items from create context.  Create context contains up to ten items at a time
1066:            //	 * all of the same type (folder, file, text document, structured-artifact, etc).  This method retrieves the data
1067:            //	 * apppropriate to the type and updates the values of the ResourcesEditItem objects stored as the STATE_STACK_CREATE_ITEMS
1068:            //	 * attribute in state. If the third parameter is "true", missing/incorrect user inputs will generate error messages
1069:            //	 * and attach flags to the input elements.
1070:            //	 * @param state
1071:            //	 * @param params
1072:            //	 * @param markMissing Should this method generate error messages and add flags for missing/incorrect user inputs?
1073:            //	 */
1074:            //	protected static void captureMultipleValues(SessionState state, ParameterParser params, boolean markMissing)
1075:            //	{
1076:            //		Map current_stack_frame = peekAtStack(state);
1077:            //		Integer number = (Integer) current_stack_frame.get(STATE_STACK_CREATE_NUMBER);
1078:            //		if(number == null)
1079:            //		{
1080:            //			number = (Integer) state.getAttribute(STATE_CREATE_NUMBER);
1081:            //			current_stack_frame.put(STATE_STACK_CREATE_NUMBER, number);
1082:            //		}
1083:            //		if(number == null)
1084:            //		{
1085:            //			number = new Integer(1);
1086:            //			current_stack_frame.put(STATE_STACK_CREATE_NUMBER, number);
1087:            //		}
1088:            //
1089:            //		List new_items = (List) current_stack_frame.get(STATE_STACK_CREATE_ITEMS);
1090:            //		if(new_items == null)
1091:            //		{
1092:            //			String collectionId = params.getString("collectionId");
1093:            //			String defaultCopyrightStatus = (String) state.getAttribute(DEFAULT_COPYRIGHT);
1094:            //			if(defaultCopyrightStatus == null || defaultCopyrightStatus.trim().equals(""))
1095:            //			{
1096:            //				defaultCopyrightStatus = ServerConfigurationService.getString("default.copyright");
1097:            //				state.setAttribute(DEFAULT_COPYRIGHT, defaultCopyrightStatus);
1098:            //			}
1099:            //
1100:            //			
1101:            //			String encoding = (String) state.getAttribute(STATE_ENCODING);
1102:            //
1103:            //			Boolean preventPublicDisplay = (Boolean) state.getAttribute(STATE_PREVENT_PUBLIC_DISPLAY);
1104:            //
1105:            //			Time defaultRetractDate = (Time) state.getAttribute(STATE_DEFAULT_RETRACT_TIME);
1106:            //			if(defaultRetractDate == null)
1107:            //			{
1108:            //				defaultRetractDate = TimeService.newTime();
1109:            //				state.setAttribute(STATE_DEFAULT_RETRACT_TIME, defaultRetractDate);
1110:            //			}
1111:            //
1112:            //		}
1113:            //
1114:            //		Set alerts = (Set) state.getAttribute(STATE_CREATE_ALERTS);
1115:            //		if(alerts == null)
1116:            //		{
1117:            //			alerts = new HashSet();
1118:            //			state.setAttribute(STATE_CREATE_ALERTS, alerts);
1119:            //		}
1120:            //		int actualCount = 0;
1121:            //		Set first_item_alerts = null;
1122:            //
1123:            //		String max_file_size_mb = (String) state.getAttribute(STATE_FILE_UPLOAD_MAX_SIZE);
1124:            //		int max_bytes = 1024 * 1024;
1125:            //		try
1126:            //		{
1127:            //			max_bytes = Integer.parseInt(max_file_size_mb) * 1024 * 1024;
1128:            //		}
1129:            //		catch(Exception e)
1130:            //		{
1131:            //			// if unable to parse an integer from the value
1132:            //			// in the properties file, use 1 MB as a default
1133:            //			max_file_size_mb = "1";
1134:            //			max_bytes = 1024 * 1024;
1135:            //		}
1136:            //
1137:            //		/*
1138:            //		// params.getContentLength() returns m_req.getContentLength()
1139:            //		if(params.getContentLength() > max_bytes)
1140:            //		{
1141:            //			alerts.add(rb.getString("size") + " " + max_file_size_mb + "MB " + rb.getString("exceeded2"));
1142:            //			state.setAttribute(STATE_CREATE_ALERTS, alerts);
1143:            //
1144:            //			return;
1145:            //		}
1146:            //		*/
1147:            //		for(int i = 0; i < number.intValue(); i++)
1148:            //		{
1149:            //			ResourcesEditItem item = (ResourcesEditItem) new_items.get(i);
1150:            //			Set item_alerts = captureValues(item, i, state, params, markMissing);
1151:            //			if(i == 0)
1152:            //			{
1153:            //				first_item_alerts = item_alerts;
1154:            //			}
1155:            //			else if(item.isBlank())
1156:            //			{
1157:            //				item.clearMissing();
1158:            //			}
1159:            //			if(! item.isBlank())
1160:            //			{
1161:            //				alerts.addAll(item_alerts);
1162:            //				actualCount ++;
1163:            //			}
1164:            //		}
1165:            //		if(actualCount > 0)
1166:            //		{
1167:            //			ResourcesEditItem item = (ResourcesEditItem) new_items.get(0);
1168:            //			if(item.isBlank())
1169:            //			{
1170:            //				item.clearMissing();
1171:            //			}
1172:            //		}
1173:            //		else if(markMissing)
1174:            //		{
1175:            //			alerts.addAll(first_item_alerts);
1176:            //		}
1177:            //		state.setAttribute(STATE_CREATE_ALERTS, alerts);
1178:            //		current_stack_frame.put(STATE_STACK_CREATE_ACTUAL_COUNT, Integer.toString(actualCount));
1179:            //
1180:            //	}	// captureMultipleValues
1181:            //
1182:            protected static void capturePropertyValues(ParameterParser params,
1183:                    ResourcesEditItem item, List properties) {
1184:                // use the item's properties if they're not supplied
1185:                if (properties == null) {
1186:                    properties = item.getProperties();
1187:                }
1188:                // if max cardinality > 1, value is a list (Iterate over members of list)
1189:                // else value is an object, not a list
1190:
1191:                // if type is nested, object is a Map (iterate over name-value pairs for the properties of the nested object)
1192:                // else object is type to store value, usually a string or a date/time
1193:
1194:                Iterator it = properties.iterator();
1195:                while (it.hasNext()) {
1196:                    ResourcesMetadata prop = (ResourcesMetadata) it.next();
1197:                    String propname = prop.getDottedname();
1198:
1199:                    if (ResourcesMetadata.WIDGET_NESTED
1200:                            .equals(prop.getWidget())) {
1201:                        // do nothing
1202:                    } else if (ResourcesMetadata.WIDGET_BOOLEAN.equals(prop
1203:                            .getWidget())) {
1204:                        String value = params.getString(propname);
1205:                        if (value == null
1206:                                || Boolean.FALSE.toString().equals(value)) {
1207:                            prop.setValue(0, Boolean.FALSE.toString());
1208:                        } else {
1209:                            prop.setValue(0, Boolean.TRUE.toString());
1210:                        }
1211:                    } else if (ResourcesMetadata.WIDGET_DATE.equals(prop
1212:                            .getWidget())
1213:                            || ResourcesMetadata.WIDGET_DATETIME.equals(prop
1214:                                    .getWidget())
1215:                            || ResourcesMetadata.WIDGET_TIME.equals(prop
1216:                                    .getWidget())) {
1217:                        int year = 0;
1218:                        int month = 0;
1219:                        int day = 0;
1220:                        int hour = 0;
1221:                        int minute = 0;
1222:                        int second = 0;
1223:                        int millisecond = 0;
1224:                        String ampm = "";
1225:
1226:                        if (prop.getWidget().equals(
1227:                                ResourcesMetadata.WIDGET_DATE)
1228:                                || prop.getWidget().equals(
1229:                                        ResourcesMetadata.WIDGET_DATETIME)) {
1230:                            year = params.getInt(propname + "_year", year);
1231:                            month = params.getInt(propname + "_month", month);
1232:                            day = params.getInt(propname + "_day", day);
1233:                        }
1234:                        if (prop.getWidget().equals(
1235:                                ResourcesMetadata.WIDGET_TIME)
1236:                                || prop.getWidget().equals(
1237:                                        ResourcesMetadata.WIDGET_DATETIME)) {
1238:                            hour = params.getInt(propname + "_hour", hour);
1239:                            minute = params
1240:                                    .getInt(propname + "_minute", minute);
1241:                            second = params
1242:                                    .getInt(propname + "_second", second);
1243:                            millisecond = params.getInt(propname
1244:                                    + "_millisecond", millisecond);
1245:                            ampm = params.getString(propname + "_ampm");
1246:
1247:                            if ("pm".equalsIgnoreCase(ampm)) {
1248:                                if (hour < 12) {
1249:                                    hour += 12;
1250:                                }
1251:                            } else if (hour == 12) {
1252:                                hour = 0;
1253:                            }
1254:                        }
1255:                        if (hour > 23) {
1256:                            hour = hour % 24;
1257:                            day++;
1258:                        }
1259:
1260:                        Time value = TimeService.newTimeLocal(year, month, day,
1261:                                hour, minute, second, millisecond);
1262:                        prop.setValue(0, value);
1263:                    } else if (ResourcesMetadata.WIDGET_ANYURI.equals(prop
1264:                            .getWidget())) {
1265:                        String value = params.getString(propname);
1266:                        if (value != null && !value.trim().equals("")) {
1267:                            Reference ref = EntityManager
1268:                                    .newReference(ContentHostingService
1269:                                            .getReference(value));
1270:                            prop.setValue(0, ref);
1271:                        }
1272:                    } else {
1273:                        String value = params.getString(propname);
1274:                        if (value != null) {
1275:                            prop.setValue(0, value);
1276:                        }
1277:                    }
1278:                }
1279:
1280:            } // capturePropertyValues
1281:
1282:            /**
1283:             *
1284:             * put copyright info into context
1285:             */
1286:            public static void copyrightChoicesIntoContext(SessionState state,
1287:                    Context context) {
1288:                boolean usingCreativeCommons = state
1289:                        .getAttribute(STATE_USING_CREATIVE_COMMONS) != null
1290:                        && state.getAttribute(STATE_USING_CREATIVE_COMMONS)
1291:                                .equals(Boolean.TRUE.toString());
1292:
1293:                if (usingCreativeCommons) {
1294:
1295:                    String ccOwnershipLabel = "Who created this resource?";
1296:                    List ccOwnershipList = new Vector();
1297:                    ccOwnershipList.add("-- Select --");
1298:                    ccOwnershipList.add("I created this resource");
1299:                    ccOwnershipList.add("Someone else created this resource");
1300:
1301:                    String ccMyGrantLabel = "Terms of use";
1302:                    List ccMyGrantOptions = new Vector();
1303:                    ccMyGrantOptions.add("-- Select --");
1304:                    ccMyGrantOptions.add("Use my copyright");
1305:                    ccMyGrantOptions.add("Use Creative Commons License");
1306:                    ccMyGrantOptions.add("Use Public Domain Dedication");
1307:
1308:                    String ccCommercialLabel = "Allow commercial use?";
1309:                    List ccCommercialList = new Vector();
1310:                    ccCommercialList.add("Yes");
1311:                    ccCommercialList.add("No");
1312:
1313:                    String ccModificationLabel = "Allow Modifications?";
1314:                    List ccModificationList = new Vector();
1315:                    ccModificationList.add("Yes");
1316:                    ccModificationList.add("Yes, share alike");
1317:                    ccModificationList.add("No");
1318:
1319:                    String ccOtherGrantLabel = "Terms of use";
1320:                    List ccOtherGrantList = new Vector();
1321:                    ccOtherGrantList.add("Subject to fair-use exception");
1322:                    ccOtherGrantList
1323:                            .add("Public domain (created before copyright law applied)");
1324:                    ccOtherGrantList
1325:                            .add("Public domain (copyright has expired)");
1326:                    ccOtherGrantList
1327:                            .add("Public domain (government document not subject to copyright)");
1328:
1329:                    String ccRightsYear = "Year";
1330:                    String ccRightsOwner = "Copyright owner";
1331:
1332:                    String ccAcknowledgeLabel = "Require users to acknowledge author's rights before access?";
1333:                    List ccAcknowledgeList = new Vector();
1334:                    ccAcknowledgeList.add("Yes");
1335:                    ccAcknowledgeList.add("No");
1336:
1337:                    String ccInfoUrl = "";
1338:
1339:                    int year = TimeService.newTime().breakdownLocal().getYear();
1340:                    String username = UserDirectoryService.getCurrentUser()
1341:                            .getDisplayName();
1342:
1343:                    context.put("usingCreativeCommons", Boolean.TRUE);
1344:                    context.put("ccOwnershipLabel", ccOwnershipLabel);
1345:                    context.put("ccOwnershipList", ccOwnershipList);
1346:                    context.put("ccMyGrantLabel", ccMyGrantLabel);
1347:                    context.put("ccMyGrantOptions", ccMyGrantOptions);
1348:                    context.put("ccCommercialLabel", ccCommercialLabel);
1349:                    context.put("ccCommercialList", ccCommercialList);
1350:                    context.put("ccModificationLabel", ccModificationLabel);
1351:                    context.put("ccModificationList", ccModificationList);
1352:                    context.put("ccOtherGrantLabel", ccOtherGrantLabel);
1353:                    context.put("ccOtherGrantList", ccOtherGrantList);
1354:                    context.put("ccRightsYear", ccRightsYear);
1355:                    context.put("ccRightsOwner", ccRightsOwner);
1356:                    context.put("ccAcknowledgeLabel", ccAcknowledgeLabel);
1357:                    context.put("ccAcknowledgeList", ccAcknowledgeList);
1358:                    context.put("ccInfoUrl", ccInfoUrl);
1359:                    context.put("ccThisYear", Integer.toString(year));
1360:                    context.put("ccThisUser", username);
1361:                } else {
1362:                    //copyright
1363:                    if (state.getAttribute(STATE_COPYRIGHT_FAIRUSE_URL) != null) {
1364:                        context.put("fairuseurl", state
1365:                                .getAttribute(STATE_COPYRIGHT_FAIRUSE_URL));
1366:                    }
1367:                    if (state.getAttribute(STATE_NEW_COPYRIGHT_INPUT) != null) {
1368:                        context.put("newcopyrightinput", state
1369:                                .getAttribute(STATE_NEW_COPYRIGHT_INPUT));
1370:                    }
1371:
1372:                    if (state.getAttribute(STATE_COPYRIGHT_TYPES) != null) {
1373:                        List copyrightTypes = (List) state
1374:                                .getAttribute(STATE_COPYRIGHT_TYPES);
1375:                        context.put("copyrightTypes", copyrightTypes);
1376:                        context.put("copyrightTypesSize", new Integer(
1377:                                copyrightTypes.size() - 1));
1378:                        context.put("USE_THIS_COPYRIGHT", copyrightTypes
1379:                                .get(copyrightTypes.size() - 1));
1380:                    }
1381:                }
1382:
1383:            } // copyrightChoicesIntoContext
1384:
1385:            public static void publicDisplayChoicesIntoContext(
1386:                    SessionState state, Context context) {
1387:                Boolean preventPublicDisplay = (Boolean) state
1388:                        .getAttribute(STATE_PREVENT_PUBLIC_DISPLAY);
1389:                if (preventPublicDisplay == null) {
1390:                    preventPublicDisplay = Boolean.FALSE;
1391:                    state.setAttribute(STATE_PREVENT_PUBLIC_DISPLAY,
1392:                            preventPublicDisplay);
1393:                }
1394:                context.put("preventPublicDisplay", preventPublicDisplay);
1395:            }
1396:
1397:            /**
1398:             * @param pipe
1399:             * @param state 
1400:             */
1401:            protected static List<ContentCollection> createFolders(
1402:                    SessionState state, ResourceToolActionPipe pipe) {
1403:                List<ContentCollection> new_collections = new Vector<ContentCollection>();
1404:                String collectionId = pipe.getContentEntity().getId();
1405:                MultiFileUploadPipe mfp = (MultiFileUploadPipe) pipe;
1406:                Iterator<ResourceToolActionPipe> pipeIt = mfp.getPipes()
1407:                        .iterator();
1408:                while (pipeIt.hasNext()) {
1409:                    ResourceToolActionPipe fp = pipeIt.next();
1410:                    String name = fp.getFileName();
1411:                    if (name == null || name.trim().equals("")) {
1412:                        continue;
1413:                    }
1414:                    try {
1415:                        ContentCollectionEdit edit = ContentHostingService
1416:                                .addCollection(collectionId, Validator
1417:                                        .escapeResourceName(name));
1418:                        ResourcePropertiesEdit props = edit.getPropertiesEdit();
1419:                        props.addProperty(ResourceProperties.PROP_DISPLAY_NAME,
1420:                                name);
1421:                        Object obj = fp.getRevisedListItem();
1422:                        if (obj != null && obj instanceof  ListItem) {
1423:                            ((ListItem) obj).updateContentCollectionEdit(edit);
1424:                        }
1425:                        ContentHostingService.commitCollection(edit);
1426:                        new_collections.add(edit);
1427:                    } catch (PermissionException e) {
1428:                        addAlert(state, trb.getString("alert.perm"));
1429:                        break;
1430:                    } catch (IdInvalidException e) {
1431:                        // TODO Auto-generated catch block
1432:                        logger.warn(
1433:                                "IdInvalidException " + collectionId + name, e);
1434:                    } catch (IdUsedException e) {
1435:                        String[] args = { name };
1436:                        addAlert(state, trb.getFormattedMessage("alert.exists",
1437:                                args));
1438:                        // logger.warn("IdUsedException ", e);
1439:                    } catch (IdUnusedException e) {
1440:                        // TODO Auto-generated catch block
1441:                        logger.warn("IdUnusedException " + collectionId + name,
1442:                                e);
1443:                        break;
1444:                    } catch (IdLengthException e) {
1445:                        String[] args = { name };
1446:                        addAlert(state, trb.getFormattedMessage(
1447:                                "alert.toolong", args));
1448:                        logger.warn("IdLengthException " + collectionId + name,
1449:                                e);
1450:                    } catch (TypeException e) {
1451:                        // TODO Auto-generated catch block
1452:                        logger.warn(
1453:                                "TypeException id = " + collectionId + name, e);
1454:                    }
1455:                }
1456:                return (new_collections.isEmpty() ? null : new_collections);
1457:            }
1458:
1459:            /**
1460:             * @param pipe
1461:             */
1462:            public static List<ContentResource> createResources(
1463:                    ResourceToolActionPipe pipe) {
1464:                boolean item_added = false;
1465:                String collectionId = null;
1466:                List<ContentResource> new_resources = new Vector<ContentResource>();
1467:                MultiFileUploadPipe mfp = (MultiFileUploadPipe) pipe;
1468:                Iterator<ResourceToolActionPipe> pipeIt = mfp.getPipes()
1469:                        .iterator();
1470:                while (pipeIt.hasNext()) {
1471:                    ResourceToolActionPipe fp = pipeIt.next();
1472:                    collectionId = pipe.getContentEntity().getId();
1473:                    String name = fp.getFileName();
1474:                    if (name == null || name.trim().equals("")) {
1475:                        continue;
1476:                    }
1477:                    String basename = name.trim();
1478:                    String extension = "";
1479:                    if (name.contains(".")) {
1480:                        String[] parts = name.split("\\.");
1481:                        basename = parts[0];
1482:                        if (parts.length > 1) {
1483:                            extension = parts[parts.length - 1];
1484:                        }
1485:
1486:                        for (int i = 1; i < parts.length - 1; i++) {
1487:                            basename += "." + parts[i];
1488:                            // extension = parts[i + 1];
1489:                        }
1490:                    }
1491:                    try {
1492:                        ContentResourceEdit resource = ContentHostingService
1493:                                .addResource(
1494:                                        collectionId,
1495:                                        Validator.escapeResourceName(basename),
1496:                                        Validator.escapeResourceName(extension),
1497:                                        MAXIMUM_ATTEMPTS_FOR_UNIQUENESS);
1498:
1499:                        byte[] content = fp.getRevisedContent();
1500:                        if (content == null) {
1501:                            InputStream stream = fp.getRevisedContentStream();
1502:                            if (stream == null) {
1503:                                logger
1504:                                        .warn("pipe with null content and null stream: "
1505:                                                + pipe.getFileName());
1506:                            } else {
1507:                                resource.setContent(stream);
1508:                            }
1509:                        } else {
1510:                            resource.setContent(content);
1511:                        }
1512:
1513:                        resource.setContentType(fp.getRevisedMimeType());
1514:                        resource.setResourceType(pipe.getAction().getTypeId());
1515:                        Object obj = fp.getRevisedListItem();
1516:                        if (obj != null && obj instanceof  ListItem) {
1517:                            ((ListItem) obj)
1518:                                    .updateContentResourceEdit(resource);
1519:                        }
1520:
1521:                        ResourcePropertiesEdit resourceProperties = resource
1522:                                .getPropertiesEdit();
1523:                        Map values = pipe.getRevisedResourceProperties();
1524:                        Iterator valueIt = values.keySet().iterator();
1525:                        while (valueIt.hasNext()) {
1526:                            String pname = (String) valueIt.next();
1527:                            String pvalue = (String) values.get(pname);
1528:                            resourceProperties.addProperty(pname, pvalue);
1529:                        }
1530:
1531:                        //				if(MIME_TYPE_DOCUMENT_HTML.equals(fp.getRevisedMimeType()) || MIME_TYPE_DOCUMENT_PLAINTEXT.equals(fp.getRevisedMimeType()))
1532:                        //				{
1533:                        //					resourceProperties.addProperty(ResourceProperties.PROP_CONTENT_ENCODING, UTF_8_ENCODING);
1534:                        //				}
1535:
1536:                        ContentHostingService.commitResource(resource,
1537:                                NotificationService.NOTI_NONE);
1538:                        item_added = true;
1539:                        new_resources.add(resource);
1540:                    } catch (PermissionException e) {
1541:                        // TODO Auto-generated catch block
1542:                        logger.warn("PermissionException ", e);
1543:                    } catch (IdUnusedException e) {
1544:                        // TODO Auto-generated catch block
1545:                        logger.warn("IdUsedException ", e);
1546:                    } catch (IdInvalidException e) {
1547:                        // TODO Auto-generated catch block
1548:                        logger.warn("IdInvalidException ", e);
1549:                    } catch (IdUniquenessException e) {
1550:                        // TODO Auto-generated catch block
1551:                        logger.warn("IdUniquenessException ", e);
1552:                    } catch (IdLengthException e) {
1553:                        // TODO Auto-generated catch block
1554:                        logger.warn("IdLengthException ", e);
1555:                    } catch (OverQuotaException e) {
1556:                        // TODO Auto-generated catch block
1557:                        logger.warn("OverQuotaException ", e);
1558:                    } catch (ServerOverloadException e) {
1559:                        // TODO Auto-generated catch block
1560:                        logger.warn("ServerOverloadException ", e);
1561:                    }
1562:                }
1563:
1564:                return (item_added ? new_resources : null);
1565:            }
1566:
1567:            /**
1568:             * Paste the item(s) selected to be moved
1569:             */
1570:            public static void doMoveitems(RunData data) {
1571:                ParameterParser params = data.getParameters();
1572:
1573:                SessionState state = ((JetspeedRunData) data)
1574:                        .getPortletSessionState(((JetspeedRunData) data)
1575:                                .getJs_peid());
1576:
1577:                // cancel copy if there is one in progress
1578:                if (!Boolean.FALSE.toString().equals(
1579:                        state.getAttribute(STATE_COPY_FLAG))) {
1580:                    initCopyContext(state);
1581:                }
1582:
1583:                List items = (List) state.getAttribute(STATE_MOVED_IDS);
1584:
1585:                String collectionId = params.getString("collectionId");
1586:
1587:                Iterator itemIter = items.iterator();
1588:                while (itemIter.hasNext()) {
1589:                    // get the copied item to be pasted
1590:                    String itemId = (String) itemIter.next();
1591:
1592:                    String originalDisplayName = NULL_STRING;
1593:
1594:                    try {
1595:                        /*
1596:                        ResourceProperties properties = ContentHostingService.getProperties (itemId);
1597:                        originalDisplayName = properties.getPropertyFormatted (ResourceProperties.PROP_DISPLAY_NAME);
1598:
1599:                        // copy, cut and paste not operated on collections
1600:                        if (properties.getProperty (ResourceProperties.PROP_IS_COLLECTION).equals (Boolean.TRUE.toString()))
1601:                        {
1602:                        	String alert = (String) state.getAttribute(STATE_MESSAGE);
1603:                        	if (alert == null || ((alert != null) && (alert.indexOf(rb.getString("notsupported")) == -1)))
1604:                        	{
1605:                        		addAlert(state, rb.getString("notsupported"));
1606:                        	}
1607:                        }
1608:                        else
1609:                         */
1610:                        {
1611:                            ContentHostingService.moveIntoFolder(itemId,
1612:                                    collectionId);
1613:                        } // if-else
1614:                    } catch (PermissionException e) {
1615:                        addAlert(state, rb.getString("notpermis8") + " "
1616:                                + originalDisplayName + ". ");
1617:                    } catch (IdUnusedException e) {
1618:                        addAlert(state, rb.getString("notexist1"));
1619:                    } catch (InUseException e) {
1620:                        addAlert(state, rb.getString("someone") + " "
1621:                                + originalDisplayName);
1622:                    } catch (TypeException e) {
1623:                        addAlert(state, rb.getString("pasteitem") + " "
1624:                                + originalDisplayName + " "
1625:                                + rb.getString("mismatch"));
1626:                    } catch (InconsistentException e) {
1627:                        addAlert(state, rb.getString("recursive") + " "
1628:                                + itemId);
1629:                    } catch (IdUsedException e) {
1630:                        addAlert(state, rb.getString("toomany"));
1631:                    } catch (ServerOverloadException e) {
1632:                        addAlert(state, rb.getString("failed"));
1633:                    } catch (OverQuotaException e) {
1634:                        addAlert(state, rb.getString("overquota"));
1635:                    } // try-catch
1636:                    catch (RuntimeException e) {
1637:                        logger
1638:                                .debug("ResourcesAction.doMoveitems ***** Unknown Exception ***** "
1639:                                        + e.getMessage());
1640:                        addAlert(state, rb.getString("failed"));
1641:                    }
1642:
1643:                    if (state.getAttribute(STATE_MESSAGE) == null) {
1644:                        // delete sucessful
1645:                        String mode = (String) state.getAttribute(STATE_MODE);
1646:                        if (MODE_HELPER.equals(mode)) {
1647:                            state.setAttribute(STATE_RESOURCES_HELPER_MODE,
1648:                                    MODE_ATTACHMENT_SELECT);
1649:                        } else {
1650:                            state.setAttribute(STATE_MODE, MODE_LIST);
1651:                        }
1652:
1653:                        // try to expand the collection
1654:                        SortedSet expandedCollections = (SortedSet) state
1655:                                .getAttribute(STATE_EXPANDED_COLLECTIONS);
1656:                        if (!expandedCollections.contains(collectionId)) {
1657:                            expandedCollections.add(collectionId);
1658:                        }
1659:
1660:                        // reset the copy flag
1661:                        if (((String) state.getAttribute(STATE_MOVE_FLAG))
1662:                                .equals(Boolean.TRUE.toString())) {
1663:                            state.setAttribute(STATE_MOVE_FLAG, Boolean.FALSE
1664:                                    .toString());
1665:                        }
1666:                    }
1667:
1668:                }
1669:
1670:            } // doMoveitems
1671:
1672:            /**
1673:             * Paste the previously copied item(s)
1674:             */
1675:            public static void doPasteitem(RunData data) {
1676:                ParameterParser params = data.getParameters();
1677:
1678:                SessionState state = ((JetspeedRunData) data)
1679:                        .getPortletSessionState(((JetspeedRunData) data)
1680:                                .getJs_peid());
1681:
1682:                // get the copied item to be pasted
1683:                String itemId = params.getString("itemId");
1684:
1685:                String collectionId = params.getString("collectionId");
1686:
1687:                duplicateItem(state, itemId, collectionId);
1688:
1689:            } // doPasteitem
1690:
1691:            /**
1692:             * Paste the previously copied item(s)
1693:             */
1694:            public static void doPasteitems(RunData data) {
1695:                ParameterParser params = data.getParameters();
1696:
1697:                SessionState state = ((JetspeedRunData) data)
1698:                        .getPortletSessionState(((JetspeedRunData) data)
1699:                                .getJs_peid());
1700:
1701:                List items = (List) state.getAttribute(STATE_COPIED_IDS);
1702:
1703:                String collectionId = params.getString("collectionId");
1704:
1705:                Iterator itemIter = items.iterator();
1706:                while (itemIter.hasNext()) {
1707:                    // get the copied item to be pasted
1708:                    String itemId = (String) itemIter.next();
1709:
1710:                    String originalDisplayName = NULL_STRING;
1711:
1712:                    try {
1713:                        String id = ContentHostingService.copyIntoFolder(
1714:                                itemId, collectionId);
1715:                        String mode = (String) state.getAttribute(STATE_MODE);
1716:                        if (MODE_HELPER.equals(mode)) {
1717:                        }
1718:                    } catch (PermissionException e) {
1719:                        addAlert(state, rb.getString("notpermis8") + " "
1720:                                + originalDisplayName + ". ");
1721:                    } catch (IdUnusedException e) {
1722:                        addAlert(state, rb.getString("notexist1"));
1723:                    } catch (InUseException e) {
1724:                        addAlert(state, rb.getString("someone") + " "
1725:                                + originalDisplayName);
1726:                    } catch (TypeException e) {
1727:                        addAlert(state, rb.getString("pasteitem") + " "
1728:                                + originalDisplayName + " "
1729:                                + rb.getString("mismatch"));
1730:                    } catch (IdUsedException e) {
1731:                        addAlert(state, rb.getString("toomany"));
1732:                    } catch (IdLengthException e) {
1733:                        addAlert(state, rb.getString("toolong") + " "
1734:                                + e.getMessage());
1735:                    } catch (IdUniquenessException e) {
1736:                        addAlert(state, trb.getFormattedMessage("paste.error",
1737:                                new Object[] { itemId }));
1738:                    } catch (ServerOverloadException e) {
1739:                        addAlert(state, rb.getString("failed"));
1740:                    } catch (InconsistentException e) {
1741:                        addAlert(state, rb.getString("recursive") + " "
1742:                                + itemId);
1743:                    } catch (OverQuotaException e) {
1744:                        addAlert(state, rb.getString("overquota"));
1745:                    } // try-catch
1746:                    catch (RuntimeException e) {
1747:                        logger
1748:                                .debug("ResourcesAction.doPasteitems ***** Unknown Exception ***** "
1749:                                        + e.getMessage());
1750:                        addAlert(state, rb.getString("failed"));
1751:                    }
1752:
1753:                    if (state.getAttribute(STATE_MESSAGE) == null) {
1754:                        // delete sucessful
1755:                        String mode = (String) state.getAttribute(STATE_MODE);
1756:                        if (MODE_HELPER.equals(mode)) {
1757:                            state.setAttribute(STATE_RESOURCES_HELPER_MODE,
1758:                                    MODE_ATTACHMENT_SELECT);
1759:                        } else {
1760:                            state.setAttribute(STATE_MODE, MODE_LIST);
1761:                        }
1762:
1763:                        // try to expand the collection
1764:                        SortedSet expandedCollections = (SortedSet) state
1765:                                .getAttribute(STATE_EXPANDED_COLLECTIONS);
1766:                        if (expandedCollections == null) {
1767:                            expandedCollections = new TreeSet();
1768:                            state.setAttribute(STATE_EXPANDED_COLLECTIONS,
1769:                                    expandedCollections);
1770:                        }
1771:                        if (!expandedCollections.contains(collectionId)) {
1772:                            expandedCollections.add(collectionId);
1773:                        }
1774:
1775:                        // reset the copy flag
1776:                        if (((String) state.getAttribute(STATE_COPY_FLAG))
1777:                                .equals(Boolean.TRUE.toString())) {
1778:                            state.setAttribute(STATE_COPY_FLAG, Boolean.FALSE
1779:                                    .toString());
1780:                        }
1781:                    }
1782:
1783:                }
1784:
1785:            } // doPasteitems
1786:
1787:            /**
1788:             * @param state
1789:             * @param itemId
1790:             * @param collectionId
1791:             */
1792:            protected static String duplicateItem(SessionState state,
1793:                    String itemId, String collectionId) {
1794:                String originalDisplayName = NULL_STRING;
1795:
1796:                String newId = null;
1797:                String displayName = "";
1798:                try {
1799:                    ResourceProperties properties = ContentHostingService
1800:                            .getProperties(itemId);
1801:                    originalDisplayName = properties
1802:                            .getPropertyFormatted(ResourceProperties.PROP_DISPLAY_NAME);
1803:
1804:                    // copy, cut and paste not operated on collections
1805:                    if (properties.getProperty(
1806:                            ResourceProperties.PROP_IS_COLLECTION).equals(
1807:                            Boolean.TRUE.toString())) {
1808:                        String alert = (String) state
1809:                                .getAttribute(STATE_MESSAGE);
1810:                        if (alert == null
1811:                                || ((alert != null) && (alert.indexOf(rb
1812:                                        .getString("notsupported")) == -1))) {
1813:                            addAlert(state, rb.getString("notsupported"));
1814:                        }
1815:                    } else {
1816:                        // paste the resource
1817:                        ContentResource resource = ContentHostingService
1818:                                .getResource(itemId);
1819:                        ResourceProperties p = ContentHostingService
1820:                                .getProperties(itemId);
1821:                        String[] args = { p
1822:                                .getProperty(ResourceProperties.PROP_DISPLAY_NAME) };
1823:                        displayName = rb.getFormattedMessage("copy.name", args);
1824:
1825:                        String newItemId = ContentHostingService
1826:                                .copyIntoFolder(itemId, collectionId);
1827:
1828:                        ContentResourceEdit copy = ContentHostingService
1829:                                .editResource(newItemId);
1830:                        ResourcePropertiesEdit pedit = copy.getPropertiesEdit();
1831:                        pedit.addProperty(ResourceProperties.PROP_DISPLAY_NAME,
1832:                                displayName);
1833:                        ContentHostingService.commitResource(copy,
1834:                                NotificationService.NOTI_NONE);
1835:                        newId = copy.getId();
1836:
1837:                    } // if-else
1838:                } catch (PermissionException e) {
1839:                    addAlert(state, rb.getString("notpermis8") + " "
1840:                            + originalDisplayName + ". ");
1841:                } catch (IdUnusedException e) {
1842:                    addAlert(state, rb.getString("notexist1"));
1843:                } catch (IdUsedException e) {
1844:                    addAlert(state, rb.getString("notaddreso") + " "
1845:                            + originalDisplayName + " " + rb.getString("used2"));
1846:                } catch (IdLengthException e) {
1847:                    addAlert(state, rb.getString("toolong") + " "
1848:                            + e.getMessage());
1849:                } catch (IdUniquenessException e) {
1850:                    addAlert(state, trb.getFormattedMessage("paste.error",
1851:                            new Object[] { originalDisplayName }));
1852:                } catch (InconsistentException ee) {
1853:                    addAlert(state, rb.getString("titlecannot"));
1854:                } catch (InUseException e) {
1855:                    addAlert(state, rb.getString("someone") + " "
1856:                            + originalDisplayName + ". ");
1857:                } catch (OverQuotaException e) {
1858:                    addAlert(state, rb.getString("overquota"));
1859:                } catch (ServerOverloadException e) {
1860:                    // this represents temporary unavailability of server's filesystem
1861:                    // for server configured to save resource body in filesystem
1862:                    addAlert(state, rb.getString("failed"));
1863:                } catch (TypeException e) {
1864:                    addAlert(state, rb.getString("pasteitem") + " "
1865:                            + originalDisplayName + " "
1866:                            + rb.getString("mismatch"));
1867:                } // try-catch
1868:
1869:                if (state.getAttribute(STATE_MESSAGE) == null) {
1870:                    // delete sucessful
1871:                    String mode = (String) state.getAttribute(STATE_MODE);
1872:                    if (MODE_HELPER.equals(mode)) {
1873:                        state.setAttribute(STATE_RESOURCES_HELPER_MODE,
1874:                                MODE_ATTACHMENT_SELECT);
1875:                    } else {
1876:                        state.setAttribute(STATE_MODE, MODE_LIST);
1877:                    }
1878:
1879:                    // try to expand the collection
1880:                    SortedSet expandedCollections = (SortedSet) state
1881:                            .getAttribute(STATE_EXPANDED_COLLECTIONS);
1882:                    if (STATE_EXPANDED_COLLECTIONS == null) {
1883:                        expandedCollections = new TreeSet();
1884:                        state.setAttribute(STATE_EXPANDED_COLLECTIONS,
1885:                                expandedCollections);
1886:                    }
1887:                    if (!expandedCollections.contains(collectionId)) {
1888:                        expandedCollections.add(collectionId);
1889:                    }
1890:
1891:                    // reset the copy flag
1892:                    if (((String) state.getAttribute(STATE_COPY_FLAG))
1893:                            .equals(Boolean.TRUE.toString())) {
1894:                        state.setAttribute(STATE_COPY_FLAG, Boolean.FALSE
1895:                                .toString());
1896:                    }
1897:                }
1898:                return newId;
1899:            }
1900:
1901:            /**
1902:             * @param selectedItem
1903:             * @param permissions TODO
1904:             * @param registry
1905:             * @return
1906:             */
1907:            protected static List<ResourceToolAction> getActions(
1908:                    ContentEntity selectedItem,
1909:                    Set<ContentPermissions> permissions,
1910:                    ResourceTypeRegistry registry) {
1911:                String resourceType = ResourceType.TYPE_UPLOAD;
1912:                Reference ref = EntityManager.newReference(selectedItem
1913:                        .getReference());
1914:                List<ResourceToolAction> actions = new Vector<ResourceToolAction>();
1915:                if (selectedItem.isCollection()) {
1916:                    resourceType = ResourceType.TYPE_FOLDER;
1917:                } else {
1918:                    ContentResource resource = (ContentResource) selectedItem;
1919:                    // String mimetype = resource.getContentType();
1920:                    resourceType = resource.getResourceType();
1921:                }
1922:
1923:                // get the registration for the current item's type 
1924:                ResourceType typeDef = registry.getType(resourceType);
1925:
1926:                // if user has content.read, user can view content, view metadata and/or copy
1927:                if (permissions.contains(ContentPermissions.READ)) {
1928:                    List<ResourceToolAction> contentReadActions = typeDef
1929:                            .getActions(CONTENT_READ_ACTIONS);
1930:                    if (contentReadActions != null) {
1931:                        actions.addAll(contentReadActions);
1932:                    }
1933:                }
1934:
1935:                // if user has content.modify, user can revise metadata, revise content, and/or replace content
1936:                if (permissions.contains(ContentPermissions.REVISE)) {
1937:                    List<ResourceToolAction> contentModifyActions = typeDef
1938:                            .getActions(CONTENT_MODIFY_ACTIONS);
1939:                    if (contentModifyActions != null) {
1940:                        actions.addAll(contentModifyActions);
1941:                    }
1942:                }
1943:
1944:                // if user has content.delete, user can move item or delete item
1945:                if (permissions.contains(ContentPermissions.DELETE)) {
1946:                    List<ResourceToolAction> contentDeleteActions = typeDef
1947:                            .getActions(CONTENT_DELETE_ACTIONS);
1948:                    if (contentDeleteActions != null) {
1949:                        actions.addAll(contentDeleteActions);
1950:                    }
1951:                }
1952:
1953:                // if user has content.new for item's parent and content.read for item, user can duplicate item
1954:                if (permissions.contains(ContentPermissions.CREATE)) {
1955:                    List<ResourceToolAction> contentNewOnParentActions = typeDef
1956:                            .getActions(CONTENT_NEW_FOR_PARENT_ACTIONS);
1957:                    if (contentNewOnParentActions != null) {
1958:                        actions.addAll(contentNewOnParentActions);
1959:                    }
1960:                }
1961:
1962:                // if user has content.new for item's parent and content.read for item, user can duplicate item
1963:                if (permissions.contains(ContentPermissions.SITE_UPDATE)) {
1964:                    List<ResourceToolAction> folderPermissionsActions = typeDef
1965:                            .getActions(SITE_UPDATE_ACTIONS);
1966:                    if (folderPermissionsActions != null) {
1967:                        actions.addAll(folderPermissionsActions);
1968:                    }
1969:                }
1970:
1971:                // filter -- remove actions that are not available to the current user in the context of this item
1972:                Iterator<ResourceToolAction> actionIt = actions.iterator();
1973:                while (actionIt.hasNext()) {
1974:                    ResourceToolAction action = actionIt.next();
1975:                    if (!action.available((ContentEntity) ref.getEntity())) {
1976:                        actionIt.remove();
1977:                    }
1978:                }
1979:                return actions;
1980:            }
1981:
1982:            public static List<ResourceToolAction> getPasteActions(
1983:                    ContentEntity selectedItem,
1984:                    Set<ContentPermissions> permissions,
1985:                    ResourceTypeRegistry registry,
1986:                    List<String> items_to_be_moved,
1987:                    List<String> items_to_be_copied) {
1988:                String resourceType = ResourceType.TYPE_UPLOAD;
1989:                Reference ref = EntityManager.newReference(selectedItem
1990:                        .getReference());
1991:
1992:                List<ResourceToolAction> actions = new Vector<ResourceToolAction>();
1993:
1994:                Set<String> memberIds = new TreeSet<String>();
1995:                if (permissions.contains(ContentPermissions.CREATE)) {
1996:                    if (selectedItem.isCollection()) {
1997:                        resourceType = ResourceType.TYPE_FOLDER;
1998:                        memberIds.addAll(((ContentCollection) selectedItem)
1999:                                .getMembers());
2000:                    } else {
2001:                        ContentResource resource = (ContentResource) selectedItem;
2002:                        // String mimetype = resource.getContentType();
2003:                        resourceType = resource.getResourceType();
2004:                    }
2005:
2006:                    // get the registration for the current item's type 
2007:                    ResourceType typeDef = registry.getType(resourceType);
2008:                    if (items_to_be_moved != null
2009:                            && !items_to_be_moved.isEmpty()) {
2010:                        // check items_to_be_moved to ensure there's at least one item that can be pasted here (SAK-9837)
2011:                        String slash1 = selectedItem.getId().endsWith("/") ? ""
2012:                                : "/";
2013:                        boolean movable = false;
2014:                        for (String itemId : items_to_be_moved) {
2015:                            if (!itemId.equals(selectedItem.getId())) {
2016:                                if (itemId.endsWith("/")) {
2017:                                    String name = isolateName(itemId) + "/";
2018:                                    if (!memberIds.contains(selectedItem
2019:                                            .getId()
2020:                                            + slash1 + name)) {
2021:                                        movable = true;
2022:                                        break;
2023:                                    }
2024:                                } else {
2025:                                    movable = true;
2026:                                    break;
2027:                                }
2028:                            }
2029:                        }
2030:
2031:                        List<ResourceToolAction> conditionalContentNewActions = typeDef
2032:                                .getActions(PASTE_MOVED_ACTIONS);
2033:                        if (movable && conditionalContentNewActions != null) {
2034:                            actions.addAll(conditionalContentNewActions);
2035:                        }
2036:                    }
2037:
2038:                    if (items_to_be_copied != null
2039:                            && !items_to_be_copied.isEmpty()) {
2040:                        // check items_to_be_copied to ensure there's at least one item that can be pasted here (SAK-9837)
2041:                        String slash1 = selectedItem.getId().endsWith("/") ? ""
2042:                                : "/";
2043:                        boolean copyable = false;
2044:                        for (String itemId : items_to_be_copied) {
2045:                            if (!itemId.equals(selectedItem.getId())) {
2046:                                if (itemId.endsWith("/")) {
2047:                                    String name = isolateName(itemId) + "/";
2048:                                    if (!memberIds.contains(selectedItem
2049:                                            .getId()
2050:                                            + slash1 + name)) {
2051:                                        copyable = true;
2052:                                        break;
2053:                                    }
2054:                                } else {
2055:                                    copyable = true;
2056:                                    break;
2057:                                }
2058:                            }
2059:                        }
2060:
2061:                        List<ResourceToolAction> conditionalContentNewActions = typeDef
2062:                                .getActions(PASTE_COPIED_ACTIONS);
2063:                        if (copyable && conditionalContentNewActions != null) {
2064:                            actions.addAll(conditionalContentNewActions);
2065:                        }
2066:                    }
2067:                }
2068:
2069:                // filter -- remove actions that are not available to the current user in the context of this item
2070:                Iterator<ResourceToolAction> actionIt = actions.iterator();
2071:                while (actionIt.hasNext()) {
2072:                    ResourceToolAction action = actionIt.next();
2073:                    ContentEntity entity = (ContentEntity) ref.getEntity();
2074:                    if (!action.available(entity)) {
2075:                        actionIt.remove();
2076:                    }
2077:                }
2078:
2079:                return actions;
2080:
2081:            }
2082:
2083:            /**
2084:             * @param selectedItem
2085:             * @param permissions TODO
2086:             * @param registry
2087:             * @return
2088:             */
2089:            protected static List<ResourceToolAction> getAddActions(
2090:                    ContentEntity selectedItem,
2091:                    Set<ContentPermissions> permissions,
2092:                    ResourceTypeRegistry registry) {
2093:                String resourceType = ResourceType.TYPE_UPLOAD;
2094:                Reference ref = EntityManager.newReference(selectedItem
2095:                        .getReference());
2096:
2097:                List<ResourceToolAction> actions = new Vector<ResourceToolAction>();
2098:
2099:                if (permissions.contains(ContentPermissions.CREATE)) {
2100:                    if (selectedItem.isCollection()) {
2101:                        resourceType = ResourceType.TYPE_FOLDER;
2102:                    } else {
2103:                        ContentResource resource = (ContentResource) selectedItem;
2104:                        // String mimetype = resource.getContentType();
2105:                        resourceType = resource.getResourceType();
2106:                    }
2107:
2108:                    // get the registration for the current item's type 
2109:                    ResourceType typeDef = registry.getType(resourceType);
2110:
2111:                    // certain actions are defined elsewhere but pertain only to collections
2112:                    if (selectedItem.isCollection()) {
2113:                        // if item is collection and user has content.new for item, user can create anything 
2114:                        {
2115:                            // iterate over resource-types and get all the registered types and find actions requiring "content.new" permission
2116:                            Collection types = registry.getTypes(ref
2117:                                    .getContext());
2118:                            Iterator<ActionType> actionTypeIt = CONTENT_NEW_ACTIONS
2119:                                    .iterator();
2120:                            while (actionTypeIt.hasNext()) {
2121:                                ActionType actionType = actionTypeIt.next();
2122:                                Iterator typeIt = types.iterator();
2123:                                while (typeIt.hasNext()) {
2124:                                    ResourceType type = (ResourceType) typeIt
2125:                                            .next();
2126:
2127:                                    List<ResourceToolAction> createActions = type
2128:                                            .getActions(actionType);
2129:                                    if (createActions != null) {
2130:                                        actions.addAll(createActions);
2131:                                    }
2132:                                }
2133:                            }
2134:                        }
2135:
2136:                    }
2137:                }
2138:                // filter -- remove actions that are not available to the current user in the context of this item
2139:                Iterator<ResourceToolAction> actionIt = actions.iterator();
2140:                while (actionIt.hasNext()) {
2141:                    ResourceToolAction action = actionIt.next();
2142:                    ContentEntity entity = (ContentEntity) ref.getEntity();
2143:                    if (!action.available(entity)) {
2144:                        actionIt.remove();
2145:                    }
2146:                }
2147:
2148:                return actions;
2149:            }
2150:
2151:            /**
2152:             * @param state
2153:             * @param homeCollectionId
2154:             * @param currentCollectionId
2155:             * @return
2156:             */
2157:            public static List getCollectionPath(SessionState state) {
2158:                org.sakaiproject.content.api.ContentHostingService contentService = (org.sakaiproject.content.api.ContentHostingService) state
2159:                        .getAttribute(STATE_CONTENT_SERVICE);
2160:                // make sure the channedId is set
2161:                String currentCollectionId = (String) state
2162:                        .getAttribute(STATE_COLLECTION_ID);
2163:                String homeCollectionId = (String) state
2164:                        .getAttribute(STATE_HOME_COLLECTION_ID);
2165:                String navRoot = (String) state
2166:                        .getAttribute(STATE_NAVIGATION_ROOT);
2167:
2168:                LinkedList collectionPath = new LinkedList();
2169:
2170:                String previousCollectionId = "";
2171:                Vector pathitems = new Vector();
2172:                while ((currentCollectionId != null)
2173:                        && (!currentCollectionId.equals(navRoot))
2174:                        && (!currentCollectionId.equals(previousCollectionId))
2175:                        && !(contentService.ROOT_COLLECTIONS
2176:                                .contains(currentCollectionId))
2177:                        && (!contentService
2178:                                .isRootCollection(previousCollectionId))) {
2179:                    pathitems.add(currentCollectionId);
2180:                    previousCollectionId = currentCollectionId;
2181:                    currentCollectionId = contentService
2182:                            .getContainingCollectionId(currentCollectionId);
2183:                }
2184:
2185:                if (navRoot != null
2186:                        && (pathitems.isEmpty() || (!navRoot
2187:                                .equals(previousCollectionId) && !navRoot
2188:                                .equals(currentCollectionId)))) {
2189:                    pathitems.add(navRoot);
2190:
2191:                }
2192:                if (homeCollectionId != null
2193:                        && (pathitems.isEmpty() || (!homeCollectionId
2194:                                .equals(navRoot)
2195:                                && !homeCollectionId
2196:                                        .equals(previousCollectionId) && !homeCollectionId
2197:                                .equals(currentCollectionId)))) {
2198:                    pathitems.add(homeCollectionId);
2199:                }
2200:
2201:                Iterator items = pathitems.iterator();
2202:                while (items.hasNext()) {
2203:                    String id = (String) items.next();
2204:                    try {
2205:                        ResourceProperties props = contentService
2206:                                .getProperties(id);
2207:                        String name = props
2208:                                .getPropertyFormatted(ResourceProperties.PROP_DISPLAY_NAME);
2209:                        String containingCollectionId = contentService
2210:                                .getContainingCollectionId(id);
2211:                        if (contentService.COLLECTION_DROPBOX
2212:                                .equals(containingCollectionId)) {
2213:                            Reference ref = EntityManager
2214:                                    .newReference(contentService
2215:                                            .getReference(id));
2216:                            Site site = SiteService.getSite(ref.getContext());
2217:                            String[] args = { site.getTitle() };
2218:                            name = trb.getFormattedMessage("title.dropbox",
2219:                                    args);
2220:                        } else if (contentService.COLLECTION_SITE
2221:                                .equals(containingCollectionId)) {
2222:                            Reference ref = EntityManager
2223:                                    .newReference(contentService
2224:                                            .getReference(id));
2225:                            Site site = SiteService.getSite(ref.getContext());
2226:                            String[] args = { site.getTitle() };
2227:                            name = trb.getFormattedMessage("title.resources",
2228:                                    args);
2229:                        }
2230:
2231:                        ChefPathItem item = new ChefPathItem(id, name);
2232:
2233:                        boolean canRead = contentService.allowGetCollection(id)
2234:                                || contentService.allowGetResource(id);
2235:                        item.setCanRead(canRead);
2236:
2237:                        if (canRead) {
2238:                            String url = contentService.getUrl(id);
2239:                            item.setUrl(url);
2240:                        }
2241:
2242:                        item.setLast(collectionPath.isEmpty());
2243:                        if (id.equals(homeCollectionId)) {
2244:                            item.setRoot(homeCollectionId);
2245:                        } else {
2246:                            item.setRoot(navRoot);
2247:                        }
2248:
2249:                        try {
2250:                            boolean isFolder = props
2251:                                    .getBooleanProperty(ResourceProperties.PROP_IS_COLLECTION);
2252:                            item.setIsFolder(isFolder);
2253:                        } catch (EntityPropertyNotDefinedException e1) {
2254:                        } catch (EntityPropertyTypeException e1) {
2255:                        }
2256:
2257:                        collectionPath.addFirst(item);
2258:
2259:                    } catch (PermissionException e) {
2260:                    } catch (IdUnusedException e) {
2261:                    }
2262:                }
2263:                return collectionPath;
2264:            }
2265:
2266:            public static ResourcesEditItem getEditItem(String id,
2267:                    String collectionId, RunData data) {
2268:                SessionState state = ((JetspeedRunData) data)
2269:                        .getPortletSessionState(((JetspeedRunData) data)
2270:                                .getJs_peid());
2271:
2272:                Stack operations_stack = (Stack) state
2273:                        .getAttribute(STATE_SUSPENDED_OPERATIONS_STACK);
2274:
2275:                Map current_stack_frame = peekAtStack(state);
2276:
2277:                ResourcesEditItem item = null;
2278:
2279:                // populate an ResourcesEditItem object with values from the resource and return the ResourcesEditItem
2280:                try {
2281:                    ResourceProperties properties = ContentHostingService
2282:                            .getProperties(id);
2283:
2284:                    boolean isCollection = false;
2285:                    try {
2286:                        isCollection = properties
2287:                                .getBooleanProperty(ResourceProperties.PROP_IS_COLLECTION);
2288:                    } catch (Exception e) {
2289:                        // assume isCollection is false if property is not set
2290:                    }
2291:
2292:                    ContentEntity entity = null;
2293:                    String itemType = "";
2294:                    byte[] content = null;
2295:                    if (isCollection) {
2296:                        itemType = "folder";
2297:                        entity = ContentHostingService.getCollection(id);
2298:                    } else {
2299:                        entity = ContentHostingService.getResource(id);
2300:                        itemType = ((ContentResource) entity).getContentType();
2301:                        content = ((ContentResource) entity).getContent();
2302:                    }
2303:
2304:                    String itemName = properties
2305:                            .getProperty(ResourceProperties.PROP_DISPLAY_NAME);
2306:
2307:                    item = new ResourcesEditItem(id, itemName, itemType);
2308:
2309:                    item.setInDropbox(ContentHostingService.isInDropbox(id));
2310:                    boolean isUserSite = false;
2311:                    String refstr = entity.getReference();
2312:                    Reference ref = EntityManager.newReference(refstr);
2313:                    String contextId = ref.getContext();
2314:                    if (contextId != null) {
2315:                        isUserSite = SiteService.isUserSite(contextId);
2316:                    }
2317:                    item.setInWorkspace(isUserSite);
2318:
2319:                    BasicRightsAssignment rightsObj = new BasicRightsAssignment(
2320:                            item.getItemNum(), properties);
2321:                    item.setRights(rightsObj);
2322:
2323:                    String encoding = data.getRequest().getCharacterEncoding();
2324:                    if (encoding != null) {
2325:                        item.setEncoding(encoding);
2326:                    }
2327:
2328:                    String defaultCopyrightStatus = (String) state
2329:                            .getAttribute(STATE_DEFAULT_COPYRIGHT);
2330:                    if (defaultCopyrightStatus == null
2331:                            || defaultCopyrightStatus.trim().equals("")) {
2332:                        defaultCopyrightStatus = ServerConfigurationService
2333:                                .getString("default.copyright");
2334:                        state.setAttribute(STATE_DEFAULT_COPYRIGHT,
2335:                                defaultCopyrightStatus);
2336:                    }
2337:                    item.setCopyrightStatus(defaultCopyrightStatus);
2338:
2339:                    if (content != null) {
2340:                        item.setContent(content);
2341:                    }
2342:
2343:                    String dummyId = collectionId.trim();
2344:                    if (dummyId.endsWith(Entity.SEPARATOR)) {
2345:                        dummyId += "dummy";
2346:                    } else {
2347:                        dummyId += Entity.SEPARATOR + "dummy";
2348:                    }
2349:
2350:                    String containerId = ContentHostingService
2351:                            .getContainingCollectionId(id);
2352:                    item.setContainer(containerId);
2353:
2354:                    boolean canRead = ContentHostingService
2355:                            .allowGetCollection(id);
2356:                    boolean canAddFolder = ContentHostingService
2357:                            .allowAddCollection(id);
2358:                    boolean canAddItem = ContentHostingService
2359:                            .allowAddResource(id);
2360:                    boolean canDelete = ContentHostingService
2361:                            .allowRemoveResource(id);
2362:                    boolean canRevise = ContentHostingService
2363:                            .allowUpdateResource(id);
2364:                    item.setCanRead(canRead);
2365:                    item.setCanRevise(canRevise);
2366:                    item.setCanAddItem(canAddItem);
2367:                    item.setCanAddFolder(canAddFolder);
2368:                    item.setCanDelete(canDelete);
2369:                    // item.setIsUrl(isUrl);
2370:
2371:                    AccessMode access = ((GroupAwareEntity) entity).getAccess();
2372:                    if (access == null) {
2373:                        item.setAccess(AccessMode.INHERITED.toString());
2374:                    } else {
2375:                        item.setAccess(access.toString());
2376:                    }
2377:
2378:                    AccessMode inherited_access = ((GroupAwareEntity) entity)
2379:                            .getInheritedAccess();
2380:                    if (inherited_access == null
2381:                            || inherited_access.equals(AccessMode.SITE)) {
2382:                        item
2383:                                .setInheritedAccess(AccessMode.INHERITED
2384:                                        .toString());
2385:                    } else {
2386:                        item.setInheritedAccess(inherited_access.toString());
2387:                    }
2388:
2389:                    Site site = SiteService.getSite(ToolManager
2390:                            .getCurrentPlacement().getContext());
2391:                    Collection site_groups = site.getGroups();
2392:                    item.setAllSiteGroups(site_groups);
2393:
2394:                    List access_groups = new Vector(((GroupAwareEntity) entity)
2395:                            .getGroups());
2396:                    item.setEntityGroupRefs(access_groups);
2397:                    //			if(access_groups != null)
2398:                    //			{
2399:                    //				
2400:                    //				Iterator it = access_groups.iterator();
2401:                    //				while(it.hasNext())
2402:                    //				{
2403:                    //					String groupRef = (String) it.next();
2404:                    //					Group group = site.getGroup(groupRef);
2405:                    //					item.addGroup(group.getId());
2406:                    //				}
2407:                    //			}
2408:
2409:                    List inherited_access_groups = new Vector(
2410:                            ((GroupAwareEntity) entity).getInheritedGroups());
2411:                    item.setInheritedGroupRefs(inherited_access_groups);
2412:                    //			if(inherited_access_groups != null)
2413:                    //			{
2414:                    //				Iterator it = inherited_access_groups.iterator();
2415:                    //				while(it.hasNext())
2416:                    //				{
2417:                    //					String groupRef = (String) it.next();
2418:                    //					Group group = site.getGroup(groupRef);
2419:                    //					item.addInheritedGroup(group.getId());
2420:                    //				}
2421:                    //			}
2422:
2423:                    Collection allowedRemoveGroups = null;
2424:                    if (AccessMode.GROUPED == access) {
2425:                        allowedRemoveGroups = ContentHostingService
2426:                                .getGroupsWithRemovePermission(id);
2427:                        Collection more = ContentHostingService
2428:                                .getGroupsWithRemovePermission(collectionId);
2429:                        if (more != null && !more.isEmpty()) {
2430:                            allowedRemoveGroups.addAll(more);
2431:                        }
2432:                    } else if (AccessMode.GROUPED == inherited_access) {
2433:                        allowedRemoveGroups = ContentHostingService
2434:                                .getGroupsWithRemovePermission(collectionId);
2435:                    } else {
2436:                        allowedRemoveGroups = ContentHostingService
2437:                                .getGroupsWithRemovePermission(ContentHostingService
2438:                                        .getSiteCollection(site.getId()));
2439:                    }
2440:                    item.setAllowedRemoveGroupRefs(allowedRemoveGroups);
2441:
2442:                    Collection allowedAddGroups = null;
2443:                    if (AccessMode.GROUPED == access) {
2444:                        allowedAddGroups = ContentHostingService
2445:                                .getGroupsWithAddPermission(id);
2446:                        Collection more = ContentHostingService
2447:                                .getGroupsWithAddPermission(collectionId);
2448:                        if (more != null && !more.isEmpty()) {
2449:                            allowedAddGroups.addAll(more);
2450:                        }
2451:                    } else if (AccessMode.GROUPED == inherited_access) {
2452:                        allowedAddGroups = ContentHostingService
2453:                                .getGroupsWithAddPermission(collectionId);
2454:                    } else {
2455:                        allowedAddGroups = ContentHostingService
2456:                                .getGroupsWithAddPermission(ContentHostingService
2457:                                        .getSiteCollection(site.getId()));
2458:                    }
2459:                    item.setAllowedAddGroupRefs(allowedAddGroups);
2460:
2461:                    Boolean preventPublicDisplay = (Boolean) state
2462:                            .getAttribute(STATE_PREVENT_PUBLIC_DISPLAY);
2463:                    if (preventPublicDisplay == null) {
2464:                        preventPublicDisplay = Boolean.FALSE;
2465:                        state.setAttribute(STATE_PREVENT_PUBLIC_DISPLAY,
2466:                                preventPublicDisplay);
2467:                    }
2468:                    if (preventPublicDisplay.booleanValue()) {
2469:                        item.setPubviewPossible(false);
2470:                        item.setPubviewInherited(false);
2471:                        item.setPubview(false);
2472:                    } else {
2473:                        item.setPubviewPossible(true);
2474:                        // find out about pubview
2475:                        boolean pubviewset = ContentHostingService
2476:                                .isInheritingPubView(id);
2477:                        item.setPubviewInherited(pubviewset);
2478:                        boolean pubview = pubviewset;
2479:                        if (!pubviewset) {
2480:                            pubview = ContentHostingService.isPubView(id);
2481:                            item.setPubview(pubview);
2482:                        }
2483:                    }
2484:
2485:                    if (entity.isHidden()) {
2486:                        item.setHidden(true);
2487:                        //item.setReleaseDate(null);
2488:                        //item.setRetractDate(null);
2489:                    } else {
2490:                        item.setHidden(false);
2491:                        Time releaseDate = entity.getReleaseDate();
2492:                        if (releaseDate == null) {
2493:                            item.setUseReleaseDate(false);
2494:                            item.setReleaseDate(TimeService.newTime());
2495:                        } else {
2496:                            item.setUseReleaseDate(true);
2497:                            item.setReleaseDate(releaseDate);
2498:                        }
2499:                        Time retractDate = entity.getRetractDate();
2500:                        if (retractDate == null) {
2501:                            item.setUseRetractDate(false);
2502:                            Time defaultRetractDate = (Time) state
2503:                                    .getAttribute(STATE_DEFAULT_RETRACT_TIME);
2504:                            if (defaultRetractDate == null) {
2505:                                defaultRetractDate = TimeService.newTime();
2506:                                state.setAttribute(STATE_DEFAULT_RETRACT_TIME,
2507:                                        defaultRetractDate);
2508:                            }
2509:                            item.setRetractDate(defaultRetractDate);
2510:                        } else {
2511:                            item.setUseRetractDate(true);
2512:                            item.setRetractDate(retractDate);
2513:                        }
2514:                    }
2515:
2516:                    if (item.isUrl()) {
2517:                        String url = new String(content);
2518:                        item.setFilename(url);
2519:                    } else if (item.isHtml() || item.isPlaintext()
2520:                            || item.isFileUpload()) {
2521:                        String filename = properties
2522:                                .getProperty(ResourceProperties.PROP_ORIGINAL_FILENAME);
2523:                        if (filename == null) {
2524:                            // this is a hack to deal with the fact that original filenames were not saved for some time.
2525:                            if (containerId != null
2526:                                    && item.getId().startsWith(containerId)
2527:                                    && containerId.length() < item.getId()
2528:                                            .length()) {
2529:                                filename = item.getId().substring(
2530:                                        containerId.length());
2531:                            }
2532:                        }
2533:
2534:                        if (filename == null) {
2535:                            item.setFilename(itemName);
2536:                        } else {
2537:                            item.setFilename(filename);
2538:                        }
2539:                    }
2540:
2541:                    String description = properties
2542:                            .getProperty(ResourceProperties.PROP_DESCRIPTION);
2543:                    item.setDescription(description);
2544:
2545:                    try {
2546:                        Time creTime = properties
2547:                                .getTimeProperty(ResourceProperties.PROP_CREATION_DATE);
2548:                        String createdTime = creTime.toStringLocalShortDate()
2549:                                + " " + creTime.toStringLocalShort();
2550:                        item.setCreatedTime(createdTime);
2551:                    } catch (Exception e) {
2552:                        String createdTime = properties
2553:                                .getProperty(ResourceProperties.PROP_CREATION_DATE);
2554:                        item.setCreatedTime(createdTime);
2555:                    }
2556:                    try {
2557:                        String createdBy = getUserProperty(properties,
2558:                                ResourceProperties.PROP_CREATOR)
2559:                                .getDisplayName();
2560:                        item.setCreatedBy(createdBy);
2561:                    } catch (Exception e) {
2562:                        String createdBy = properties
2563:                                .getProperty(ResourceProperties.PROP_CREATOR);
2564:                        item.setCreatedBy(createdBy);
2565:                    }
2566:                    try {
2567:                        Time modTime = properties
2568:                                .getTimeProperty(ResourceProperties.PROP_MODIFIED_DATE);
2569:                        String modifiedTime = modTime.toStringLocalShortDate()
2570:                                + " " + modTime.toStringLocalShort();
2571:                        item.setModifiedTime(modifiedTime);
2572:                    } catch (Exception e) {
2573:                        String modifiedTime = properties
2574:                                .getProperty(ResourceProperties.PROP_MODIFIED_DATE);
2575:                        item.setModifiedTime(modifiedTime);
2576:                    }
2577:                    try {
2578:                        String modifiedBy = getUserProperty(properties,
2579:                                ResourceProperties.PROP_MODIFIED_BY)
2580:                                .getDisplayName();
2581:                        item.setModifiedBy(modifiedBy);
2582:                    } catch (Exception e) {
2583:                        String modifiedBy = properties
2584:                                .getProperty(ResourceProperties.PROP_MODIFIED_BY);
2585:                        item.setModifiedBy(modifiedBy);
2586:                    }
2587:
2588:                    String url = ContentHostingService.getUrl(id);
2589:                    item.setUrl(url);
2590:
2591:                    String size = "";
2592:                    if (properties
2593:                            .getProperty(ResourceProperties.PROP_CONTENT_LENGTH) != null) {
2594:                        long size_long = 0;
2595:                        try {
2596:                            size_long = properties
2597:                                    .getLongProperty(ResourceProperties.PROP_CONTENT_LENGTH);
2598:                        } catch (EntityPropertyNotDefinedException e) {
2599:                            // TODO Auto-generated catch block
2600:                            logger
2601:                                    .warn("EntityPropertyNotDefinedException for size of "
2602:                                            + item.getId());
2603:                        } catch (EntityPropertyTypeException e) {
2604:                            // TODO Auto-generated catch block
2605:                            logger
2606:                                    .warn("EntityPropertyTypeException for size of "
2607:                                            + item.getId());
2608:                        }
2609:                        size = getFileSizeString(size_long, rb);
2610:                    }
2611:                    item.setSize(size);
2612:
2613:                    String copyrightStatus = properties.getProperty(properties
2614:                            .getNamePropCopyrightChoice());
2615:                    if (copyrightStatus == null
2616:                            || copyrightStatus.trim().equals("")) {
2617:                        copyrightStatus = (String) state
2618:                                .getAttribute(STATE_DEFAULT_COPYRIGHT);
2619:
2620:                    }
2621:                    item.setCopyrightStatus(copyrightStatus);
2622:                    String copyrightInfo = properties
2623:                            .getPropertyFormatted(properties
2624:                                    .getNamePropCopyright());
2625:                    item.setCopyrightInfo(copyrightInfo);
2626:                    String copyrightAlert = properties.getProperty(properties
2627:                            .getNamePropCopyrightAlert());
2628:
2629:                    if ("true".equalsIgnoreCase(copyrightAlert)) {
2630:                        item.setCopyrightAlert(true);
2631:                    } else {
2632:                        item.setCopyrightAlert(false);
2633:                    }
2634:
2635:                    Map metadata = new Hashtable();
2636:                    List groups = (List) state
2637:                            .getAttribute(STATE_METADATA_GROUPS);
2638:                    if (groups != null && !groups.isEmpty()) {
2639:                        Iterator it = groups.iterator();
2640:                        while (it.hasNext()) {
2641:                            MetadataGroup group = (MetadataGroup) it.next();
2642:                            Iterator propIt = group.iterator();
2643:                            while (propIt.hasNext()) {
2644:                                ResourcesMetadata prop = (ResourcesMetadata) propIt
2645:                                        .next();
2646:                                String name = prop.getFullname();
2647:                                String widget = prop.getWidget();
2648:                                if (widget
2649:                                        .equals(ResourcesMetadata.WIDGET_DATE)
2650:                                        || widget
2651:                                                .equals(ResourcesMetadata.WIDGET_DATETIME)
2652:                                        || widget
2653:                                                .equals(ResourcesMetadata.WIDGET_TIME)) {
2654:                                    Time time = TimeService.newTime();
2655:                                    try {
2656:                                        time = properties.getTimeProperty(name);
2657:                                    } catch (Exception ignore) {
2658:                                        // use "now" as default in that case
2659:                                    }
2660:                                    metadata.put(name, time);
2661:                                } else {
2662:                                    String value = properties
2663:                                            .getPropertyFormatted(name);
2664:                                    metadata.put(name, value);
2665:                                }
2666:                            }
2667:                        }
2668:                        item.setMetadata(metadata);
2669:                    } else {
2670:                        item.setMetadata(new Hashtable());
2671:                    }
2672:                    // for collections only
2673:                    if (item.isFolder()) {
2674:                        // setup for quota - ADMIN only, site-root collection only
2675:                        if (SecurityService.isSuperUser()) {
2676:                            String siteCollectionId = ContentHostingService
2677:                                    .getSiteCollection(contextId);
2678:                            if (siteCollectionId.equals(entity.getId())) {
2679:                                item.setCanSetQuota(true);
2680:                                try {
2681:                                    long quota = properties
2682:                                            .getLongProperty(ResourceProperties.PROP_COLLECTION_BODY_QUOTA);
2683:                                    item.setHasQuota(true);
2684:                                    item.setQuota(Long.toString(quota));
2685:                                } catch (Exception any) {
2686:                                }
2687:                            }
2688:                        }
2689:                    }
2690:
2691:                } catch (IdUnusedException e) {
2692:                    addAlert(state, rb.getString("notexist1"));
2693:                } catch (PermissionException e) {
2694:                    addAlert(state, rb.getString("notpermis2") + " " + id
2695:                            + ". ");
2696:                } catch (TypeException e) {
2697:                    addAlert(state, " " + rb.getString("typeex") + " " + id);
2698:                } catch (ServerOverloadException e) {
2699:                    // this represents temporary unavailability of server's filesystem
2700:                    // for server configured to save resource body in filesystem
2701:                    addAlert(state, rb.getString("failed"));
2702:                } catch (RuntimeException e) {
2703:                    logger
2704:                            .debug("ResourcesAction.getEditItem ***** Unknown Exception ***** "
2705:                                    + e.getMessage());
2706:                    addAlert(state, rb.getString("failed"));
2707:                }
2708:
2709:                return item;
2710:
2711:            }
2712:
2713:            /**
2714:             * @param size_long
2715:             * @param rl 
2716:             * @return
2717:             */
2718:            public static String getFileSizeString(long size_long,
2719:                    ResourceLoader rl) {
2720:                String size;
2721:                NumberFormat formatter = NumberFormat.getInstance(rl
2722:                        .getLocale());
2723:                formatter.setMaximumFractionDigits(1);
2724:                if (size_long > 700000000L) {
2725:                    String[] args = { formatter.format(1.0 * size_long
2726:                            / (1024L * 1024L * 1024L)) };
2727:                    size = rl.getFormattedMessage("size.gb", args);
2728:                } else if (size_long > 700000L) {
2729:                    String[] args = { formatter.format(1.0 * size_long
2730:                            / (1024L * 1024L)) };
2731:                    size = rl.getFormattedMessage("size.mb", args);
2732:                } else if (size_long > 700L) {
2733:                    String[] args = { formatter.format(1.0 * size_long / 1024L) };
2734:                    size = rl.getFormattedMessage("size.kb", args);
2735:                } else {
2736:                    String[] args = { formatter.format(size_long) };
2737:                    size = rl.getFormattedMessage("size.bytes", args);
2738:                }
2739:                return size;
2740:            }
2741:
2742:            /**
2743:             * Get the items in this folder that should be seen.
2744:             * @param collectionId - String version of
2745:             * @param expandedCollections - Hash of collection resources
2746:             * @param sortedBy  - pass through to ContentHostingComparator
2747:             * @param sortedAsc - pass through to ContentHostingComparator
2748:             * @param parent - The folder containing this item
2749:             * @param isLocal - true if navigation root and home collection id of site are the same, false otherwise
2750:             * @param state - The session state
2751:             * @return a List of ResourcesBrowseItem objects
2752:             */
2753:            protected static List getListView(String collectionId,
2754:                    Set highlightedItems, ResourcesBrowseItem parent,
2755:                    boolean isLocal, SessionState state) {
2756:                // find the ContentHosting service
2757:                org.sakaiproject.content.api.ContentHostingService contentService = (org.sakaiproject.content.api.ContentHostingService) state
2758:                        .getAttribute(STATE_CONTENT_SERVICE);
2759:
2760:                boolean need_to_expand_all = Boolean.TRUE.toString().equals(
2761:                        (String) state.getAttribute(STATE_NEED_TO_EXPAND_ALL));
2762:
2763:                Comparator userSelectedSort = (Comparator) state
2764:                        .getAttribute(STATE_LIST_VIEW_SORT);
2765:
2766:                Map expandedFolderSortMap = (Map) state
2767:                        .getAttribute(STATE_EXPANDED_FOLDER_SORT_MAP);
2768:                if (expandedFolderSortMap == null) {
2769:                    expandedFolderSortMap = new Hashtable();
2770:                    state.setAttribute(STATE_EXPANDED_FOLDER_SORT_MAP,
2771:                            expandedFolderSortMap);
2772:                }
2773:
2774:                SortedSet<String> expandedCollections = (SortedSet<String>) state
2775:                        .getAttribute(STATE_EXPANDED_COLLECTIONS);
2776:                if (expandedCollections == null) {
2777:                    expandedCollections = new TreeSet<String>();
2778:                    state.setAttribute(STATE_EXPANDED_COLLECTIONS,
2779:                            expandedCollections);
2780:                }
2781:                String mode = (String) state.getAttribute(STATE_MODE);
2782:
2783:                List newItems = new LinkedList();
2784:                try {
2785:                    // get the collection
2786:                    // try using existing resource first
2787:                    ContentCollection collection = null;
2788:
2789:                    // get the collection
2790:                    collection = contentService.getCollection(collectionId);
2791:                    if (need_to_expand_all
2792:                            || expandedCollections.contains(collectionId)) {
2793:                        Comparator comparator = null;
2794:                        if (userSelectedSort != null) {
2795:                            comparator = userSelectedSort;
2796:                        } else {
2797:                            boolean hasCustomSort = false;
2798:                            try {
2799:                                hasCustomSort = collection
2800:                                        .getProperties()
2801:                                        .getBooleanProperty(
2802:                                                ResourceProperties.PROP_HAS_CUSTOM_SORT);
2803:                            } catch (Exception e) {
2804:                                // ignore -- let value be false
2805:                            }
2806:                            if (hasCustomSort) {
2807:                                comparator = ListItem.PRIORITY_SORT_COMPARATOR;
2808:                            } else {
2809:                                comparator = ListItem.DEFAULT_COMPARATOR;
2810:                            }
2811:                        }
2812:                        expandedFolderSortMap.put(collectionId, comparator);
2813:                        expandedCollections.add(collectionId);
2814:                        // state.setAttribute(STATE_EXPANDED_FOLDER_SORT_MAP, expandedFolderSortMap);
2815:                    }
2816:
2817:                    String dummyId = collectionId.trim();
2818:                    if (dummyId.endsWith(Entity.SEPARATOR)) {
2819:                        dummyId += "dummy";
2820:                    } else {
2821:                        dummyId += Entity.SEPARATOR + "dummy";
2822:                    }
2823:
2824:                    boolean canRead = false;
2825:                    boolean canDelete = false;
2826:                    boolean canRevise = false;
2827:                    boolean canAddFolder = false;
2828:                    boolean canAddItem = false;
2829:                    boolean canUpdate = false;
2830:                    int depth = 0;
2831:
2832:                    if (parent == null || !parent.canRead()) {
2833:                        canRead = contentService
2834:                                .allowGetCollection(collectionId);
2835:                    } else {
2836:                        canRead = parent.canRead();
2837:                    }
2838:                    if (parent == null || !parent.canDelete()) {
2839:                        canDelete = contentService
2840:                                .allowRemoveCollection(collectionId);
2841:                    } else {
2842:                        canDelete = parent.canDelete();
2843:                    }
2844:                    if (parent == null || !parent.canRevise()) {
2845:                        canRevise = contentService
2846:                                .allowUpdateCollection(collectionId);
2847:                    } else {
2848:                        canRevise = parent.canRevise();
2849:                    }
2850:                    if (parent == null || !parent.canAddFolder()) {
2851:                        canAddFolder = contentService
2852:                                .allowAddCollection(dummyId);
2853:                    } else {
2854:                        canAddFolder = parent.canAddFolder();
2855:                    }
2856:                    if (parent == null || !parent.canAddItem()) {
2857:                        canAddItem = contentService.allowAddResource(dummyId);
2858:                    } else {
2859:                        canAddItem = parent.canAddItem();
2860:                    }
2861:                    if (parent == null || !parent.canUpdate()) {
2862:                        canUpdate = AuthzGroupService.allowUpdate(collectionId);
2863:                    } else {
2864:                        canUpdate = parent.canUpdate();
2865:                    }
2866:                    if (parent != null) {
2867:                        depth = parent.getDepth() + 1;
2868:                    }
2869:
2870:                    if (canAddItem) {
2871:                        state.setAttribute(STATE_PASTE_ALLOWED_FLAG,
2872:                                Boolean.TRUE.toString());
2873:                    }
2874:                    // each child will have it's own delete status based on: delete.own or delete.any
2875:                    boolean hasDeletableChildren = true;
2876:
2877:                    // may have perms to copy in another folder, even if no perms in this folder
2878:                    boolean hasCopyableChildren = canRead;
2879:
2880:                    String homeCollectionId = (String) state
2881:                            .getAttribute(STATE_HOME_COLLECTION_ID);
2882:
2883:                    ResourceProperties cProperties = collection.getProperties();
2884:                    String folderName = cProperties
2885:                            .getProperty(ResourceProperties.PROP_DISPLAY_NAME);
2886:                    if (collectionId.equals(homeCollectionId)) {
2887:                        folderName = (String) state
2888:                                .getAttribute(STATE_HOME_COLLECTION_DISPLAY_NAME);
2889:                    }
2890:                    ResourcesBrowseItem folder = new ResourcesBrowseItem(
2891:                            collectionId, folderName, "folder");
2892:                    if (parent == null) {
2893:                        folder.setRoot(collectionId);
2894:                    } else {
2895:                        folder.setRoot(parent.getRoot());
2896:                    }
2897:
2898:                    boolean isInDropbox = contentService
2899:                            .isInDropbox(collectionId);
2900:                    folder.setInDropbox(isInDropbox);
2901:
2902:                    BasicRightsAssignment rightsObj = new BasicRightsAssignment(
2903:                            folder.getItemNum(), cProperties);
2904:                    folder.setRights(rightsObj);
2905:
2906:                    AccessMode access = collection.getAccess();
2907:                    if (access == null || AccessMode.SITE == access) {
2908:                        folder.setAccess(AccessMode.INHERITED.toString());
2909:                    } else {
2910:                        folder.setAccess(access.toString());
2911:                    }
2912:
2913:                    AccessMode inherited_access = collection
2914:                            .getInheritedAccess();
2915:                    if (inherited_access == null
2916:                            || AccessMode.SITE == inherited_access) {
2917:                        folder.setInheritedAccess(AccessMode.INHERITED
2918:                                .toString());
2919:                    } else {
2920:                        folder.setInheritedAccess(inherited_access.toString());
2921:                    }
2922:
2923:                    Collection access_groups = collection.getGroupObjects();
2924:                    if (access_groups == null) {
2925:                        access_groups = new Vector();
2926:                    }
2927:                    folder.setGroups(access_groups);
2928:                    Collection inherited_access_groups = collection
2929:                            .getInheritedGroupObjects();
2930:                    if (inherited_access_groups == null) {
2931:                        inherited_access_groups = new Vector();
2932:                    }
2933:                    folder.setInheritedGroups(inherited_access_groups);
2934:
2935:                    if (parent != null
2936:                            && (parent.isPubview() || parent
2937:                                    .isPubviewInherited())) {
2938:                        folder.setPubviewInherited(true);
2939:                        folder.setPubview(false);
2940:                    } else if (contentService.isPubView(folder.getId())) {
2941:                        folder.setPubview(true);
2942:                    }
2943:
2944:                    if (highlightedItems == null || highlightedItems.isEmpty()) {
2945:                        // do nothing
2946:                    } else if (parent != null && parent.isHighlighted()) {
2947:                        folder.setInheritsHighlight(true);
2948:                        folder.setHighlighted(true);
2949:                    } else if (highlightedItems.contains(collectionId)) {
2950:                        folder.setHighlighted(true);
2951:                        folder.setInheritsHighlight(false);
2952:                    }
2953:
2954:                    String containerId = contentService
2955:                            .getContainingCollectionId(collectionId);
2956:                    folder.setContainer(containerId);
2957:
2958:                    folder.setCanRead(canRead);
2959:                    folder.setCanRevise(canRevise);
2960:                    folder.setCanAddItem(canAddItem);
2961:                    folder.setCanAddFolder(canAddFolder);
2962:                    folder.setCanDelete(canDelete);
2963:                    folder.setCanUpdate(canUpdate);
2964:
2965:                    folder.setAvailable(collection.isAvailable());
2966:
2967:                    try {
2968:                        Time createdTime = cProperties
2969:                                .getTimeProperty(ResourceProperties.PROP_CREATION_DATE);
2970:                        String createdTimeString = createdTime
2971:                                .toStringLocalShortDate();
2972:                        folder.setCreatedTime(createdTimeString);
2973:                    } catch (Exception e) {
2974:                        String createdTimeString = cProperties
2975:                                .getProperty(ResourceProperties.PROP_CREATION_DATE);
2976:                        folder.setCreatedTime(createdTimeString);
2977:                    }
2978:                    try {
2979:                        String createdBy = getUserProperty(cProperties,
2980:                                ResourceProperties.PROP_CREATOR)
2981:                                .getDisplayName();
2982:                        folder.setCreatedBy(createdBy);
2983:                    } catch (Exception e) {
2984:                        String createdBy = cProperties
2985:                                .getProperty(ResourceProperties.PROP_CREATOR);
2986:                        folder.setCreatedBy(createdBy);
2987:                    }
2988:                    try {
2989:                        Time modifiedTime = cProperties
2990:                                .getTimeProperty(ResourceProperties.PROP_MODIFIED_DATE);
2991:                        String modifiedTimeString = modifiedTime
2992:                                .toStringLocalShortDate();
2993:                        folder.setModifiedTime(modifiedTimeString);
2994:                    } catch (Exception e) {
2995:                        String modifiedTimeString = cProperties
2996:                                .getProperty(ResourceProperties.PROP_MODIFIED_DATE);
2997:                        folder.setModifiedTime(modifiedTimeString);
2998:                    }
2999:                    try {
3000:                        String modifiedBy = getUserProperty(cProperties,
3001:                                ResourceProperties.PROP_MODIFIED_BY)
3002:                                .getDisplayName();
3003:                        folder.setModifiedBy(modifiedBy);
3004:                    } catch (Exception e) {
3005:                        String modifiedBy = cProperties
3006:                                .getProperty(ResourceProperties.PROP_MODIFIED_BY);
3007:                        folder.setModifiedBy(modifiedBy);
3008:                    }
3009:
3010:                    String url = contentService.getUrl(collectionId);
3011:                    folder.setUrl(url);
3012:
3013:                    // get the "size' of the collection, meaning the number of members one level down
3014:                    int collection_size = collection.getMemberCount(); // newMembers.size();
3015:                    folder.setIsEmpty(collection_size < 1);
3016:                    folder.setSortable(ContentHostingService
3017:                            .isSortByPriorityEnabled()
3018:                            && collection_size > 1
3019:                            && collection_size < EXPANDABLE_FOLDER_SIZE_LIMIT);
3020:                    Integer expansionLimit = (Integer) state
3021:                            .getAttribute(STATE_EXPANDABLE_FOLDER_SIZE_LIMIT);
3022:                    if (expansionLimit == null) {
3023:                        expansionLimit = new Integer(
3024:                                EXPANDABLE_FOLDER_SIZE_LIMIT);
3025:                    }
3026:                    folder.setIsTooBig(collection_size > expansionLimit
3027:                            .intValue());
3028:
3029:                    folder.setDepth(depth);
3030:                    newItems.add(folder);
3031:
3032:                    if (need_to_expand_all
3033:                            || expandedFolderSortMap.keySet().contains(
3034:                                    collectionId)) {
3035:                        // Get the collection members from the 'new' collection
3036:                        List newMembers = collection.getMemberResources();
3037:
3038:                        Comparator comparator = userSelectedSort;
3039:                        if (comparator == null) {
3040:                            comparator = (Comparator) expandedFolderSortMap
3041:                                    .get(collectionId);
3042:                            if (comparator == null) {
3043:                                comparator = ListItem.DEFAULT_COMPARATOR;
3044:                            }
3045:                        }
3046:
3047:                        Collections.sort(newMembers, comparator);
3048:
3049:                        // loop thru the (possibly) new members and add to the list
3050:                        Iterator it = newMembers.iterator();
3051:                        while (it.hasNext()) {
3052:                            ContentEntity resource = (ContentEntity) it.next();
3053:                            ResourceProperties props = resource.getProperties();
3054:
3055:                            String itemId = resource.getId();
3056:
3057:                            if (contentService.isAvailabilityEnabled()
3058:                                    && !contentService.isAvailable(itemId)) {
3059:                                continue;
3060:                            }
3061:
3062:                            if (resource.isCollection()) {
3063:                                List offspring = getListView(itemId,
3064:                                        highlightedItems, folder, isLocal,
3065:                                        state);
3066:
3067:                                if (!offspring.isEmpty()) {
3068:                                    ResourcesBrowseItem child = (ResourcesBrowseItem) offspring
3069:                                            .get(0);
3070:                                    hasDeletableChildren = hasDeletableChildren
3071:                                            || child.hasDeletableChildren();
3072:                                    hasCopyableChildren = hasCopyableChildren
3073:                                            || child.hasCopyableChildren();
3074:                                }
3075:
3076:                                // add all the items in the subfolder to newItems
3077:                                newItems.addAll(offspring);
3078:                            } else {
3079:                                AccessMode access_mode = ((GroupAwareEntity) resource)
3080:                                        .getAccess();
3081:                                if (access_mode == null) {
3082:                                    access_mode = AccessMode.INHERITED;
3083:                                } else if (access_mode == AccessMode.GROUPED) {
3084:                                    if (!contentService
3085:                                            .allowGetResource(resource.getId())) {
3086:                                        continue;
3087:                                    }
3088:                                }
3089:
3090:                                String itemType = ((ContentResource) resource)
3091:                                        .getContentType();
3092:                                String itemName = props
3093:                                        .getProperty(ResourceProperties.PROP_DISPLAY_NAME);
3094:                                ResourcesBrowseItem newItem = new ResourcesBrowseItem(
3095:                                        itemId, itemName, itemType);
3096:
3097:                                boolean isLocked = contentService
3098:                                        .isLocked(itemId);
3099:                                newItem.setLocked(isLocked);
3100:
3101:                                boolean isAvailable = folder.isAvailable();
3102:                                if (isAvailable) {
3103:                                    isAvailable = resource.isAvailable();
3104:                                }
3105:                                newItem.setAvailable(isAvailable);
3106:
3107:                                newItem.setAccess(access_mode.toString());
3108:                                newItem.setInheritedAccess(folder
3109:                                        .getEffectiveAccess());
3110:
3111:                                newItem.setInDropbox(isInDropbox);
3112:
3113:                                BasicRightsAssignment rightsObj2 = new BasicRightsAssignment(
3114:                                        newItem.getItemNum(), props);
3115:                                newItem.setRights(rightsObj2);
3116:                                Collection groups = ((GroupAwareEntity) resource)
3117:                                        .getGroupObjects();
3118:                                if (groups == null) {
3119:                                    groups = new Vector();
3120:                                }
3121:                                Collection inheritedGroups = folder.getGroups();
3122:                                if (inheritedGroups == null
3123:                                        || inheritedGroups.isEmpty()) {
3124:                                    inheritedGroups = folder
3125:                                            .getInheritedGroups();
3126:                                }
3127:                                newItem.setGroups(groups);
3128:                                newItem.setInheritedGroups(inheritedGroups);
3129:
3130:                                newItem.setContainer(collectionId);
3131:                                newItem.setRoot(folder.getRoot());
3132:
3133:                                // delete and revise permissions based on item (not parent)
3134:                                newItem.setCanDelete(contentService
3135:                                        .allowRemoveResource(itemId)
3136:                                        && !isLocked);
3137:                                newItem.setCanRevise(contentService
3138:                                        .allowUpdateResource(itemId));
3139:                                newItem.setCanRead(canRead);
3140:                                newItem.setCanCopy(canRead); // may have perms to copy in another folder, even if no perms in this folder
3141:                                newItem.setCanAddItem(canAddItem); // true means this user can add an item in the folder containing this item (used for "duplicate")
3142:
3143:                                if (highlightedItems == null
3144:                                        || highlightedItems.isEmpty()) {
3145:                                    // do nothing
3146:                                } else if (folder.isHighlighted()) {
3147:                                    newItem.setInheritsHighlight(true);
3148:                                    newItem.setHighlighted(true);
3149:                                } else if (highlightedItems.contains(itemId)) {
3150:                                    newItem.setHighlighted(true);
3151:                                    newItem.setInheritsHighlight(false);
3152:                                }
3153:
3154:                                try {
3155:                                    Time createdTime = props
3156:                                            .getTimeProperty(ResourceProperties.PROP_CREATION_DATE);
3157:                                    String createdTimeString = createdTime
3158:                                            .toStringLocalShortDate();
3159:                                    newItem.setCreatedTime(createdTimeString);
3160:                                } catch (Exception e) {
3161:                                    String createdTimeString = props
3162:                                            .getProperty(ResourceProperties.PROP_CREATION_DATE);
3163:                                    newItem.setCreatedTime(createdTimeString);
3164:                                }
3165:                                try {
3166:                                    String createdBy = getUserProperty(props,
3167:                                            ResourceProperties.PROP_CREATOR)
3168:                                            .getDisplayName();
3169:                                    newItem.setCreatedBy(createdBy);
3170:                                } catch (Exception e) {
3171:                                    String createdBy = props
3172:                                            .getProperty(ResourceProperties.PROP_CREATOR);
3173:                                    newItem.setCreatedBy(createdBy);
3174:                                }
3175:                                try {
3176:                                    Time modifiedTime = props
3177:                                            .getTimeProperty(ResourceProperties.PROP_MODIFIED_DATE);
3178:                                    String modifiedTimeString = modifiedTime
3179:                                            .toStringLocalShortDate();
3180:                                    newItem.setModifiedTime(modifiedTimeString);
3181:                                } catch (Exception e) {
3182:                                    String modifiedTimeString = props
3183:                                            .getProperty(ResourceProperties.PROP_MODIFIED_DATE);
3184:                                    newItem.setModifiedTime(modifiedTimeString);
3185:                                }
3186:                                try {
3187:                                    String modifiedBy = getUserProperty(props,
3188:                                            ResourceProperties.PROP_MODIFIED_BY)
3189:                                            .getDisplayName();
3190:                                    newItem.setModifiedBy(modifiedBy);
3191:                                } catch (Exception e) {
3192:                                    String modifiedBy = props
3193:                                            .getProperty(ResourceProperties.PROP_MODIFIED_BY);
3194:                                    newItem.setModifiedBy(modifiedBy);
3195:                                }
3196:
3197:                                if (folder.isPubview()
3198:                                        || folder.isPubviewInherited()) {
3199:                                    newItem.setPubviewInherited(true);
3200:                                    newItem.setPubview(false);
3201:                                } else if (contentService.isPubView(resource
3202:                                        .getId())) {
3203:                                    newItem.setPubview(true);
3204:                                }
3205:
3206:                                String size = props
3207:                                        .getPropertyFormatted(ResourceProperties.PROP_CONTENT_LENGTH);
3208:                                newItem.setSize(size);
3209:
3210:                                String target = Validator
3211:                                        .getResourceTarget(props
3212:                                                .getProperty(ResourceProperties.PROP_CONTENT_TYPE));
3213:                                newItem.setTarget(target);
3214:
3215:                                String newUrl = contentService.getUrl(itemId);
3216:                                newItem.setUrl(newUrl);
3217:
3218:                                try {
3219:                                    boolean copyrightAlert = props
3220:                                            .getBooleanProperty(ResourceProperties.PROP_COPYRIGHT_ALERT);
3221:                                    newItem.setCopyrightAlert(copyrightAlert);
3222:                                } catch (Exception e) {
3223:                                }
3224:                                newItem.setDepth(depth + 1);
3225:                                newItems.add(newItem);
3226:
3227:                            }
3228:                        }
3229:
3230:                    }
3231:                    folder.seDeletableChildren(hasDeletableChildren);
3232:                    folder.setCopyableChildren(hasCopyableChildren);
3233:                    // return newItems;
3234:                } catch (IdUnusedException ignore) {
3235:                    // this condition indicates a site that does not have a resources collection (mercury?)
3236:                } catch (TypeException e) {
3237:                    addAlert(state, "TypeException.");
3238:                } catch (PermissionException e) {
3239:                    // ignore -- we'll just skip this collection since user lacks permission to access it.
3240:                    //addAlert(state, "PermissionException");
3241:                }
3242:
3243:                return newItems;
3244:
3245:            } // getListView
3246:
3247:            /**
3248:             * @param inheritedPermissions TODO
3249:             * @param context
3250:             * @return
3251:             */
3252:            protected static Collection<ContentPermissions> getPermissions(
3253:                    String id,
3254:                    Collection<ContentPermissions> inheritedPermissions) {
3255:                Collection<ContentPermissions> permissions = new Vector<ContentPermissions>();
3256:                if (ContentHostingService.isCollection(id)) {
3257:                    if ((inheritedPermissions != null && inheritedPermissions
3258:                            .contains(ContentPermissions.CREATE))
3259:                            || ContentHostingService.allowAddCollection(id)
3260:                            && !ContentHostingService.isRootCollection(id)) {
3261:                        permissions.add(ContentPermissions.CREATE);
3262:                    }
3263:                    if ((inheritedPermissions != null && inheritedPermissions
3264:                            .contains(ContentPermissions.DELETE))
3265:                            || ContentHostingService.allowRemoveCollection(id)) {
3266:                        permissions.add(ContentPermissions.DELETE);
3267:                    }
3268:                    if ((inheritedPermissions != null && inheritedPermissions
3269:                            .contains(ContentPermissions.READ))
3270:                            || ContentHostingService.allowGetCollection(id)) {
3271:                        permissions.add(ContentPermissions.READ);
3272:                    }
3273:                    if ((inheritedPermissions != null && inheritedPermissions
3274:                            .contains(ContentPermissions.REVISE))
3275:                            || ContentHostingService.allowUpdateCollection(id)) {
3276:                        permissions.add(ContentPermissions.REVISE);
3277:                    }
3278:                    if ((inheritedPermissions != null && inheritedPermissions
3279:                            .contains(ContentPermissions.SITE_UPDATE))
3280:                            || SiteService.allowUpdateSite(ToolManager
3281:                                    .getCurrentPlacement().getContext())) {
3282:                        permissions.add(ContentPermissions.SITE_UPDATE);
3283:                    }
3284:                } else {
3285:                    if ((inheritedPermissions != null && inheritedPermissions
3286:                            .contains(ContentPermissions.CREATE))
3287:                            || ContentHostingService.allowAddResource(id)
3288:                            && !ContentHostingService.isRootCollection(id)) {
3289:                        permissions.add(ContentPermissions.CREATE);
3290:                    }
3291:                    if ((inheritedPermissions != null && inheritedPermissions
3292:                            .contains(ContentPermissions.DELETE))
3293:                            || ContentHostingService.allowRemoveResource(id)) {
3294:                        permissions.add(ContentPermissions.DELETE);
3295:                    }
3296:                    if ((inheritedPermissions != null && inheritedPermissions
3297:                            .contains(ContentPermissions.READ))
3298:                            || ContentHostingService.allowGetResource(id)) {
3299:                        permissions.add(ContentPermissions.READ);
3300:                    }
3301:                    if ((inheritedPermissions != null && inheritedPermissions
3302:                            .contains(ContentPermissions.REVISE))
3303:                            || ContentHostingService.allowUpdateResource(id)) {
3304:                        permissions.add(ContentPermissions.REVISE);
3305:                    }
3306:                    if ((inheritedPermissions != null && inheritedPermissions
3307:                            .contains(ContentPermissions.SITE_UPDATE))
3308:                            || SiteService.allowUpdateSite(ToolManager
3309:                                    .getCurrentPlacement().getContext())) {
3310:                        permissions.add(ContentPermissions.SITE_UPDATE);
3311:                    }
3312:                }
3313:
3314:                return permissions;
3315:            }
3316:
3317:            protected static User getUserProperty(ResourceProperties props,
3318:                    String name) {
3319:                String id = props.getProperty(name);
3320:                if (id != null) {
3321:                    try {
3322:                        return UserDirectoryService.getUser(id);
3323:                    } catch (UserNotDefinedException e) {
3324:                    }
3325:                }
3326:
3327:                return null;
3328:            }
3329:
3330:            /**
3331:             * initialize the copy context
3332:             */
3333:            private static void initCopyContext(SessionState state) {
3334:                state.setAttribute(STATE_COPIED_IDS, new Vector());
3335:
3336:                state.setAttribute(STATE_COPY_FLAG, Boolean.FALSE.toString());
3337:
3338:            } // initCopyContent
3339:
3340:            /**
3341:             * initialize the metadata context
3342:             */
3343:            private static void initMetadataContext(SessionState state) {
3344:                // define MetadataSets map
3345:                List metadataGroups = (List) state
3346:                        .getAttribute(STATE_METADATA_GROUPS);
3347:                if (metadataGroups == null) {
3348:                    metadataGroups = new Vector();
3349:                    state.setAttribute(STATE_METADATA_GROUPS, metadataGroups);
3350:                }
3351:                // define DublinCore
3352:                if (!metadataGroups.contains(new MetadataGroup(rb
3353:                        .getString("opt_props")))) {
3354:                    MetadataGroup dc = new MetadataGroup(rb
3355:                            .getString("opt_props"));
3356:                    // dc.add(ResourcesMetadata.PROPERTY_DC_TITLE);
3357:                    // dc.add(ResourcesMetadata.PROPERTY_DC_DESCRIPTION);
3358:                    dc.add(ResourcesMetadata.PROPERTY_DC_ALTERNATIVE);
3359:                    dc.add(ResourcesMetadata.PROPERTY_DC_CREATOR);
3360:                    dc.add(ResourcesMetadata.PROPERTY_DC_PUBLISHER);
3361:                    dc.add(ResourcesMetadata.PROPERTY_DC_SUBJECT);
3362:                    dc.add(ResourcesMetadata.PROPERTY_DC_CREATED);
3363:                    dc.add(ResourcesMetadata.PROPERTY_DC_ISSUED);
3364:                    // dc.add(ResourcesMetadata.PROPERTY_DC_MODIFIED);
3365:                    // dc.add(ResourcesMetadata.PROPERTY_DC_TABLEOFCONTENTS);
3366:                    dc.add(ResourcesMetadata.PROPERTY_DC_ABSTRACT);
3367:                    dc.add(ResourcesMetadata.PROPERTY_DC_CONTRIBUTOR);
3368:                    // dc.add(ResourcesMetadata.PROPERTY_DC_TYPE);
3369:                    // dc.add(ResourcesMetadata.PROPERTY_DC_FORMAT);
3370:                    // dc.add(ResourcesMetadata.PROPERTY_DC_IDENTIFIER);
3371:                    // dc.add(ResourcesMetadata.PROPERTY_DC_SOURCE);
3372:                    // dc.add(ResourcesMetadata.PROPERTY_DC_LANGUAGE);
3373:                    // dc.add(ResourcesMetadata.PROPERTY_DC_COVERAGE);
3374:                    // dc.add(ResourcesMetadata.PROPERTY_DC_RIGHTS);
3375:                    dc.add(ResourcesMetadata.PROPERTY_DC_AUDIENCE);
3376:                    dc.add(ResourcesMetadata.PROPERTY_DC_EDULEVEL);
3377:
3378:                    /* Filesystem and file-like mount points */
3379:                    dc.add(ResourcesMetadata.PROPERTY_FSMOUNT_ACTIVE);
3380:
3381:                    metadataGroups.add(dc);
3382:                    state.setAttribute(STATE_METADATA_GROUPS, metadataGroups);
3383:                }
3384:                /*
3385:                // define DublinCore
3386:                if(!metadataGroups.contains(new MetadataGroup("Test of Datatypes")))
3387:                {
3388:                	MetadataGroup dc = new MetadataGroup("Test of Datatypes");
3389:                	dc.add(ResourcesMetadata.PROPERTY_DC_TITLE);
3390:                	dc.add(ResourcesMetadata.PROPERTY_DC_DESCRIPTION);
3391:                	dc.add(ResourcesMetadata.PROPERTY_DC_ANYURI);
3392:                	dc.add(ResourcesMetadata.PROPERTY_DC_DOUBLE);
3393:                	dc.add(ResourcesMetadata.PROPERTY_DC_DATETIME);
3394:                	dc.add(ResourcesMetadata.PROPERTY_DC_TIME);
3395:                	dc.add(ResourcesMetadata.PROPERTY_DC_DATE);
3396:                	dc.add(ResourcesMetadata.PROPERTY_DC_BOOLEAN);
3397:                	dc.add(ResourcesMetadata.PROPERTY_DC_INTEGER);
3398:                	metadataGroups.add(dc);
3399:                	state.setAttribute(STATE_METADATA_GROUPS, metadataGroups);
3400:                }
3401:                 */
3402:            }
3403:
3404:            /**
3405:             * initialize the copy context
3406:             */
3407:            private static void initMoveContext(SessionState state) {
3408:                state.setAttribute(STATE_MOVED_IDS, new Vector());
3409:
3410:                state.setAttribute(STATE_MOVE_FLAG, Boolean.FALSE.toString());
3411:
3412:            } // initCopyContent
3413:
3414:            /**
3415:             * Find the resource name of a given resource id or filepath.
3416:             * 
3417:             * @param id
3418:             *        The resource id.
3419:             * @return the resource name.
3420:             */
3421:            protected static String isolateName(String id) {
3422:                if (id == null)
3423:                    return null;
3424:                if (id.length() == 0)
3425:                    return null;
3426:
3427:                // take after the last resource path separator, not counting one at the very end if there
3428:                boolean lastIsSeparator = id.charAt(id.length() - 1) == '/';
3429:                return id.substring(id.lastIndexOf('/', id.length() - 2) + 1,
3430:                        (lastIsSeparator ? id.length() - 1 : id.length()));
3431:
3432:            } // isolateName
3433:
3434:            /**
3435:             * Returns true if the suspended operations stack contains no elements.
3436:             * @param state The current session state, including the STATE_SUSPENDED_OPERATIONS_STACK attribute.
3437:             * @return true if the suspended operations stack contains no elements
3438:             */
3439:            private static boolean isStackEmpty(SessionState state) {
3440:                Stack operations_stack = (Stack) state
3441:                        .getAttribute(STATE_SUSPENDED_OPERATIONS_STACK);
3442:                if (operations_stack == null) {
3443:                    operations_stack = new Stack();
3444:                    state.setAttribute(STATE_SUSPENDED_OPERATIONS_STACK,
3445:                            operations_stack);
3446:                }
3447:                return operations_stack.isEmpty();
3448:            }
3449:
3450:            /**
3451:             * Add variables and constants to the velocity context to render an editor
3452:             * for inputing and modifying optional metadata properties about a resource.
3453:             */
3454:            private static void metadataGroupsIntoContext(SessionState state,
3455:                    Context context) {
3456:
3457:                context.put("STRING", ResourcesMetadata.WIDGET_STRING);
3458:                context.put("TEXTAREA", ResourcesMetadata.WIDGET_TEXTAREA);
3459:                context.put("BOOLEAN", ResourcesMetadata.WIDGET_BOOLEAN);
3460:                context.put("INTEGER", ResourcesMetadata.WIDGET_INTEGER);
3461:                context.put("DOUBLE", ResourcesMetadata.WIDGET_DOUBLE);
3462:                context.put("DATE", ResourcesMetadata.WIDGET_DATE);
3463:                context.put("TIME", ResourcesMetadata.WIDGET_TIME);
3464:                context.put("DATETIME", ResourcesMetadata.WIDGET_DATETIME);
3465:                context.put("ANYURI", ResourcesMetadata.WIDGET_ANYURI);
3466:                context.put("WYSIWYG", ResourcesMetadata.WIDGET_WYSIWYG);
3467:
3468:                context.put("today", TimeService.newTime());
3469:
3470:                List metadataGroups = (List) state
3471:                        .getAttribute(STATE_METADATA_GROUPS);
3472:                if (metadataGroups != null && !metadataGroups.isEmpty()) {
3473:                    context.put("metadataGroups", metadataGroups);
3474:                }
3475:
3476:            } // metadataGroupsIntoContext
3477:
3478:            protected static List newEditItems(String collectionId,
3479:                    String itemtype, String encoding,
3480:                    String defaultCopyrightStatus,
3481:                    boolean preventPublicDisplay, Time defaultRetractDate,
3482:                    int number) {
3483:                List new_items = new Vector();
3484:
3485:                ContentCollection collection = null;
3486:                AccessMode inheritedAccess = AccessMode.INHERITED;
3487:                //		Collection inheritedGroups = new Vector();
3488:                try {
3489:                    collection = ContentHostingService
3490:                            .getCollection(collectionId);
3491:
3492:                    inheritedAccess = collection.getAccess();
3493:                    //			inheritedGroups = collection.getGroups();
3494:                    if (AccessMode.INHERITED == inheritedAccess) {
3495:                        inheritedAccess = collection.getInheritedAccess();
3496:                        //				inheritedGroups = collection.getInheritedGroups();
3497:                    }
3498:                } catch (PermissionException e) {
3499:                    //alerts.add(rb.getString("notpermis4"));
3500:                    logger
3501:                            .warn(
3502:                                    "ResourcesAction.newEditItems() PermissionException ",
3503:                                    e);
3504:                } catch (IdUnusedException e) {
3505:                    // TODO Auto-generated catch block
3506:                    logger
3507:                            .warn(
3508:                                    "ResourcesAction.newEditItems() IdUnusedException ",
3509:                                    e);
3510:                } catch (TypeException e) {
3511:                    // TODO Auto-generated catch block
3512:                    logger.warn(
3513:                            "ResourcesAction.newEditItems() TypeException ", e);
3514:                }
3515:
3516:                boolean isUserSite = false;
3517:                String refstr = collection.getReference();
3518:                Reference ref = EntityManager.newReference(refstr);
3519:                String contextId = ref.getContext();
3520:                if (contextId != null) {
3521:                    isUserSite = SiteService.isUserSite(contextId);
3522:                }
3523:
3524:                boolean pubviewset = ContentHostingService
3525:                        .isInheritingPubView(collectionId)
3526:                        || ContentHostingService.isPubView(collectionId);
3527:
3528:                //Collection possibleGroups = ContentHostingService.getGroupsWithReadAccess(collectionId);
3529:                boolean isInDropbox = ContentHostingService
3530:                        .isInDropbox(collectionId);
3531:
3532:                Collection possibleGroups = ContentHostingService
3533:                        .getGroupsWithAddPermission(collectionId);
3534:                Site site = null;
3535:                Collection site_groups = null;
3536:
3537:                try {
3538:                    site = SiteService.getSite(ToolManager
3539:                            .getCurrentPlacement().getContext());
3540:                } catch (IdUnusedException e) {
3541:                    logger
3542:                            .warn(
3543:                                    "resourcesAction.newEditItems() IdUnusedException ",
3544:                                    e);
3545:                }
3546:                if (site != null) {
3547:                    site_groups = site.getGroups();
3548:                } else {
3549:                    site_groups = new Vector();
3550:                }
3551:
3552:                Collection inherited_access_groups = collection.getGroups();
3553:                if (inherited_access_groups == null
3554:                        || inherited_access_groups.isEmpty()) {
3555:                    inherited_access_groups = collection.getInheritedGroups();
3556:                }
3557:                if (inherited_access_groups == null) {
3558:                    inherited_access_groups = new Vector();
3559:                }
3560:
3561:                Collection allowedAddGroups = ContentHostingService
3562:                        .getGroupsWithAddPermission(collectionId); // null;
3563:                //		if(AccessMode.GROUPED == inheritedAccess)
3564:                //		{
3565:                //			allowedAddGroups = ContentHostingService.getGroupsWithAddPermission(collectionId);
3566:                //		}
3567:                //		else
3568:                //		{
3569:                //			allowedAddGroups = ContentHostingService.getGroupsWithAddPermission(ContentHostingService.getSiteCollection(site.getId()));
3570:                //		}
3571:                if (allowedAddGroups == null) {
3572:                    allowedAddGroups = new Vector();
3573:                }
3574:
3575:                for (int i = 0; i < CREATE_MAX_ITEMS; i++) {
3576:                    ResourcesEditItem item = new ResourcesEditItem(itemtype);
3577:                    if (encoding != null) {
3578:                        item.setEncoding(encoding);
3579:                    }
3580:                    item.setInDropbox(isInDropbox);
3581:
3582:                    if (inheritedAccess == null
3583:                            || AccessMode.SITE == inheritedAccess) {
3584:                        item
3585:                                .setInheritedAccess(AccessMode.INHERITED
3586:                                        .toString());
3587:                    } else {
3588:                        item.setInheritedAccess(inheritedAccess.toString());
3589:                    }
3590:                    item.setAllSiteGroups(site_groups);
3591:                    item.setInheritedGroupRefs(inherited_access_groups);
3592:                    item.setAllowedAddGroupRefs(allowedAddGroups);
3593:
3594:                    item.setHidden(false);
3595:                    item.setUseReleaseDate(false);
3596:                    item.setReleaseDate(TimeService.newTime());
3597:                    item.setUseRetractDate(false);
3598:                    item.setRetractDate(defaultRetractDate);
3599:                    item.setInWorkspace(isUserSite);
3600:
3601:                    item.setCopyrightStatus(defaultCopyrightStatus);
3602:                    new_items.add(item);
3603:                    // item.setPossibleGroups(new Vector(possibleGroups));
3604:                    //			if(inheritedGroups != null)
3605:                    //			{
3606:                    //				item.setInheritedGroups(inheritedGroups);
3607:                    //			}
3608:
3609:                    if (preventPublicDisplay) {
3610:                        item.setPubviewPossible(false);
3611:                        item.setPubviewInherited(false);
3612:                        item.setPubview(false);
3613:                    } else {
3614:                        item.setPubviewPossible(true);
3615:                        item.setPubviewInherited(pubviewset);
3616:                        //item.setPubview(pubviewset);
3617:                    }
3618:
3619:                }
3620:
3621:                return new_items;
3622:            }
3623:
3624:            /**
3625:             * Access the top item on the suspended-operations stack
3626:             * @param state The current session state, including the STATE_SUSPENDED_OPERATIONS_STACK attribute.
3627:             * @return The top item on the stack, or null if the stack is empty.
3628:             */
3629:            private static Map peekAtStack(SessionState state) {
3630:                Map current_stack_frame = null;
3631:                Stack operations_stack = (Stack) state
3632:                        .getAttribute(STATE_SUSPENDED_OPERATIONS_STACK);
3633:                if (operations_stack == null) {
3634:                    operations_stack = new Stack();
3635:                    state.setAttribute(STATE_SUSPENDED_OPERATIONS_STACK,
3636:                            operations_stack);
3637:                }
3638:                if (!operations_stack.isEmpty()) {
3639:                    current_stack_frame = (Map) operations_stack.peek();
3640:                }
3641:                return current_stack_frame;
3642:
3643:            }
3644:
3645:            /**
3646:             * Remove and return the top item from the suspended-operations stack.
3647:             * @param state The current session state, including the STATE_SUSPENDED_OPERATIONS_STACK attribute.
3648:             * @return The item that has just been removed from the stack, or null if the stack was empty.
3649:             */
3650:            private static Map popFromStack(SessionState state) {
3651:                Map current_stack_frame = null;
3652:                Stack operations_stack = (Stack) state
3653:                        .getAttribute(STATE_SUSPENDED_OPERATIONS_STACK);
3654:                if (operations_stack == null) {
3655:                    operations_stack = new Stack();
3656:                    state.setAttribute(STATE_SUSPENDED_OPERATIONS_STACK,
3657:                            operations_stack);
3658:                }
3659:                if (!operations_stack.isEmpty()) {
3660:                    current_stack_frame = (Map) operations_stack.pop();
3661:                    if (operations_stack.isEmpty()) {
3662:                        String canceled = (String) current_stack_frame
3663:                                .get(STATE_HELPER_CANCELED_BY_USER);
3664:                        if (canceled != null) {
3665:                            state.setAttribute(STATE_HELPER_CANCELED_BY_USER,
3666:                                    canceled);
3667:                        }
3668:                    }
3669:                }
3670:                return current_stack_frame;
3671:
3672:            }
3673:
3674:            /**
3675:             * Push an item of the suspended-operations stack.
3676:             * @param state The current session state, including the STATE_SUSPENDED_OPERATIONS_STACK attribute.
3677:             * @return The new item that has just been added to the stack, or null if depth limit is exceeded.
3678:             */
3679:            private static Map pushOnStack(SessionState state) {
3680:                Map current_stack_frame = null;
3681:                Stack operations_stack = (Stack) state
3682:                        .getAttribute(STATE_SUSPENDED_OPERATIONS_STACK);
3683:                if (operations_stack == null) {
3684:                    operations_stack = new Stack();
3685:                    state.setAttribute(STATE_SUSPENDED_OPERATIONS_STACK,
3686:                            operations_stack);
3687:                }
3688:                if (operations_stack.size() < MAXIMUM_SUSPENDED_OPERATIONS_STACK_DEPTH) {
3689:                    current_stack_frame = (Map) operations_stack
3690:                            .push(new Hashtable());
3691:                }
3692:                Object helper_mode = state
3693:                        .getAttribute(STATE_RESOURCES_HELPER_MODE);
3694:                if (helper_mode != null) {
3695:                    current_stack_frame.put(STATE_RESOURCES_HELPER_MODE,
3696:                            helper_mode);
3697:                }
3698:                return current_stack_frame;
3699:
3700:            }
3701:
3702:            /**
3703:             * Remove a resource pattern from the observer
3704:             *@param pattern The pattern value to be removed
3705:             *@param state The state object
3706:             */
3707:            private static void removeObservingPattern(String pattern,
3708:                    SessionState state) {
3709:                //		// get the observer and remove the pattern
3710:                //		ContentObservingCourier o = (ContentObservingCourier) state.getAttribute(STATE_OBSERVER);
3711:                //		o.removeResourcePattern(ContentHostingService.getReference(pattern));
3712:                //
3713:                //		// add it back to state
3714:                //		state.setAttribute(STATE_OBSERVER, o);
3715:
3716:            } // removeObservingPattern
3717:
3718:            /**
3719:             *
3720:             * Whether a resource item can be replaced
3721:             * @param p The ResourceProperties object for the resource item
3722:             * @return true If it can be replaced; false otherwise
3723:             */
3724:            private static boolean replaceable(ResourceProperties p) {
3725:                boolean rv = true;
3726:
3727:                if (p.getPropertyFormatted(
3728:                        ResourceProperties.PROP_IS_COLLECTION).equals(
3729:                        Boolean.TRUE.toString())) {
3730:                    rv = false;
3731:                } else if (p.getProperty(ResourceProperties.PROP_CONTENT_TYPE)
3732:                        .equals(ResourceProperties.TYPE_URL)) {
3733:                    rv = false;
3734:                }
3735:                String displayName = p
3736:                        .getPropertyFormatted(ResourceProperties.PROP_DISPLAY_NAME);
3737:                if (displayName.indexOf(rb.getString("shortcut")) != -1) {
3738:                    rv = false;
3739:                }
3740:
3741:                return rv;
3742:
3743:            } // replaceable
3744:
3745:            /**
3746:             * @param pipe
3747:             * @param action
3748:             */
3749:            public static void reviseContent(ResourceToolActionPipe pipe) {
3750:                ResourceToolAction action = pipe.getAction();
3751:                ContentEntity entity = pipe.getContentEntity();
3752:                try {
3753:                    ContentResourceEdit edit = ContentHostingService
3754:                            .editResource(entity.getId());
3755:                    ResourcePropertiesEdit props = edit.getPropertiesEdit();
3756:                    // update content
3757:                    byte[] content = pipe.getRevisedContent();
3758:                    if (content == null) {
3759:                        InputStream stream = pipe.getRevisedContentStream();
3760:                        if (stream == null) {
3761:                            logger
3762:                                    .warn("pipe with null content and null stream: "
3763:                                            + pipe.getFileName());
3764:                        } else {
3765:                            edit.setContent(stream);
3766:                        }
3767:                    } else {
3768:                        edit.setContent(content);
3769:                    }
3770:                    // update properties
3771:                    if (action instanceof  InteractionAction) {
3772:                        InteractionAction iAction = (InteractionAction) action;
3773:                        Map revprops = pipe.getRevisedResourceProperties();
3774:                        List propkeys = iAction.getRequiredPropertyKeys();
3775:                        if (propkeys != null) {
3776:                            Iterator keyIt = propkeys.iterator();
3777:                            while (keyIt.hasNext()) {
3778:                                String key = (String) keyIt.next();
3779:                                String value = (String) revprops.get(key);
3780:                                if (value == null) {
3781:                                    props.removeProperty(key);
3782:                                } else {
3783:                                    // should we support multivalued properties?
3784:                                    props.addProperty(key, value);
3785:                                }
3786:                            }
3787:                        }
3788:                    }
3789:                    // update mimetype
3790:                    edit.setContentType(pipe.getRevisedMimeType());
3791:                    ContentHostingService.commitResource(edit);
3792:                } catch (PermissionException e) {
3793:                    // TODO Auto-generated catch block
3794:                    logger.warn("PermissionException ", e);
3795:                } catch (IdUnusedException e) {
3796:                    // TODO Auto-generated catch block
3797:                    logger.warn("IdUnusedException ", e);
3798:                } catch (TypeException e) {
3799:                    // TODO Auto-generated catch block
3800:                    logger.warn("TypeException ", e);
3801:                } catch (InUseException e) {
3802:                    // TODO Auto-generated catch block
3803:                    logger.warn("InUseException ", e);
3804:                } catch (OverQuotaException e) {
3805:                    // TODO Auto-generated catch block
3806:                    logger.warn("OverQuotaException ", e);
3807:                } catch (ServerOverloadException e) {
3808:                    // TODO Auto-generated catch block
3809:                    logger.warn("ServerOverloadException ", e);
3810:                }
3811:            }
3812:
3813:            //	/**
3814:            //	* Edit the editable collection/resource properties
3815:            //	*/
3816:            //	public static void doEdit ( RunData data )
3817:            //	{
3818:            //		ParameterParser params = data.getParameters ();
3819:            //		SessionState state = ((JetspeedRunData)data).getPortletSessionState (((JetspeedRunData)data).getJs_peid ());
3820:            //
3821:            //		Map current_stack_frame = pushOnStack(state);
3822:            //
3823:            //		state.setAttribute(STATE_LIST_SELECTIONS, new TreeSet());
3824:            //
3825:            //		// cancel copy if there is one in progress
3826:            //		if(! Boolean.FALSE.toString().equals(state.getAttribute (STATE_COPY_FLAG)))
3827:            //		{
3828:            //			initCopyContext(state);
3829:            //		}
3830:            //
3831:            //		// cancel move if there is one in progress
3832:            //		if(! Boolean.FALSE.toString().equals(state.getAttribute (STATE_MOVE_FLAG)))
3833:            //		{
3834:            //			initMoveContext(state);
3835:            //		}
3836:            //
3837:            //		String id = NULL_STRING;
3838:            //		id = params.getString ("id");
3839:            //		if(id == null || id.length() == 0)
3840:            //		{
3841:            //			// there is no resource selected, show the alert message to the user
3842:            //			addAlert(state, rb.getString("choosefile2"));
3843:            //			return;
3844:            //		}
3845:            //
3846:            //		current_stack_frame.put(STATE_STACK_EDIT_ID, id);
3847:            //
3848:            //		String collectionId = (String) params.getString("collectionId");
3849:            //		if(collectionId == null)
3850:            //		{
3851:            //			collectionId = ContentHostingService.getSiteCollection(ToolManager.getCurrentPlacement().getContext());
3852:            //			state.setAttribute(STATE_HOME_COLLECTION_ID, collectionId);
3853:            //		}
3854:            //		current_stack_frame.put(STATE_STACK_EDIT_COLLECTION_ID, collectionId);
3855:            //
3856:            //		ResourcesEditItem item = getEditItem(id, collectionId, data);
3857:            //
3858:            //		if (state.getAttribute(STATE_MESSAGE) == null)
3859:            //		{
3860:            //			// got resource and sucessfully populated item with values
3861:            //			// state.setAttribute (STATE_MODE, MODE_EDIT);
3862:            //			state.setAttribute(ResourcesAction.STATE_RESOURCES_HELPER_MODE, ResourcesAction.MODE_ATTACHMENT_EDIT_ITEM_INIT);
3863:            //			state.setAttribute(STATE_EDIT_ALERTS, new HashSet());
3864:            //			current_stack_frame.put(STATE_STACK_EDIT_ITEM, item);
3865:            //
3866:            //		}
3867:            //		else
3868:            //		{
3869:            //			popFromStack(state);
3870:            //		}
3871:            //
3872:            //	}	// doEdit
3873:
3874:            /**
3875:             * @param pedit
3876:             * @param metadataGroups
3877:             * @param metadata
3878:             */
3879:            private static void saveMetadata(ResourcePropertiesEdit pedit,
3880:                    List metadataGroups, ResourcesEditItem item) {
3881:                if (metadataGroups != null && !metadataGroups.isEmpty()) {
3882:                    MetadataGroup group = null;
3883:                    Iterator it = metadataGroups.iterator();
3884:                    while (it.hasNext()) {
3885:                        group = (MetadataGroup) it.next();
3886:                        Iterator props = group.iterator();
3887:                        while (props.hasNext()) {
3888:                            ResourcesMetadata prop = (ResourcesMetadata) props
3889:                                    .next();
3890:
3891:                            if (ResourcesMetadata.WIDGET_DATETIME.equals(prop
3892:                                    .getWidget())
3893:                                    || ResourcesMetadata.WIDGET_DATE
3894:                                            .equals(prop.getWidget())
3895:                                    || ResourcesMetadata.WIDGET_TIME
3896:                                            .equals(prop.getWidget())) {
3897:                                Time val = (Time) item.getMetadata().get(
3898:                                        prop.getFullname());
3899:                                if (val != null) {
3900:                                    pedit.addProperty(prop.getFullname(), val
3901:                                            .toString());
3902:                                }
3903:                            } else {
3904:                                String val = (String) item.getMetadata().get(
3905:                                        prop.getFullname());
3906:                                pedit.addProperty(prop.getFullname(), val);
3907:                            }
3908:                        }
3909:                    }
3910:                }
3911:
3912:            }
3913:
3914:            /**
3915:             * @param url
3916:             * @return
3917:             * @throws MalformedURLException
3918:             */
3919:            protected static String validateURL(String url)
3920:                    throws MalformedURLException {
3921:                if (url.equals(NULL_STRING)) {
3922:                    // ignore the empty url field
3923:                } else if (url.indexOf("://") == -1) {
3924:                    // if it's missing the transport, add http://
3925:                    url = "http://" + url;
3926:                }
3927:
3928:                if (!url.equals(NULL_STRING)) {
3929:                    // valid protocol?
3930:                    try {
3931:                        // test to see if the input validates as a URL.
3932:                        // Checks string for format only.
3933:                        URL u = new URL(url);
3934:                    } catch (MalformedURLException e1) {
3935:                        try {
3936:                            Pattern pattern = Pattern
3937:                                    .compile("\\s*([a-zA-Z0-9]+)://([^\\n]+)");
3938:                            Matcher matcher = pattern.matcher(url);
3939:                            if (matcher.matches()) {
3940:                                // if URL has "unknown" protocol, check remaider with
3941:                                // "http" protocol and accept input if that validates.
3942:                                URL test = new URL("http://" + matcher.group(2));
3943:                            } else {
3944:                                throw e1;
3945:                            }
3946:                        } catch (MalformedURLException e2) {
3947:                            throw e1;
3948:                        }
3949:                    }
3950:                }
3951:                return url;
3952:            }
3953:
3954:            /**
3955:             * Search a flat list of ResourcesMetadata properties for one whose localname matches "field".
3956:             * If found and the field can have additional instances, increment the count for that item.
3957:             * @param field
3958:             * @param properties
3959:             * @return true if the field is found, false otherwise.
3960:             */
3961:            protected boolean addInstance(String field, List properties) {
3962:                Iterator propIt = properties.iterator();
3963:                boolean found = false;
3964:                while (!found && propIt.hasNext()) {
3965:                    ResourcesMetadata property = (ResourcesMetadata) propIt
3966:                            .next();
3967:                    if (field.equals(property.getDottedname())) {
3968:                        found = true;
3969:                        property.incrementCount();
3970:                    }
3971:                }
3972:                return found;
3973:            }
3974:
3975:            /**
3976:             * Build the context to establish a custom-ordering of resources/folders within a folder.
3977:             */
3978:            public String buildColumnsContext(VelocityPortlet portlet,
3979:                    Context context, RunData data, SessionState state) {
3980:                context.put("tlang", trb);
3981:
3982:                // need to check permissions
3983:
3984:                // get the id of the item currently selected
3985:                String selectedItemId = (String) state
3986:                        .getAttribute(STATE_COLUMN_ITEM_ID);
3987:                if (selectedItemId == null) {
3988:                    selectedItemId = (String) state
3989:                            .getAttribute(STATE_HOME_COLLECTION_ID);
3990:                }
3991:                context.put("selectedItemId", selectedItemId);
3992:                String folderId = null;
3993:
3994:                // need a list of folders (ListItem objects) for one root in context as $folders
3995:                List<List<ListItem>> folders = new Vector<List<ListItem>>();
3996:                ContentCollection collection = null;
3997:                ContentEntity selectedItem = null;
3998:
3999:                // need a list of roots (ListItem objects) in context as $roots
4000:                List<ListItem> roots = new Vector<ListItem>();
4001:                Map othersites = ContentHostingService.getCollectionMap();
4002:                Iterator it = othersites.keySet().iterator();
4003:                while (it.hasNext()) {
4004:                    String rootId = (String) it.next();
4005:                    String rootName = (String) othersites.get(rootId);
4006:                    ListItem root = new ListItem(rootId);
4007:                    root.setName(rootName);
4008:                    root.setHoverText(rootName);
4009:                    root.setAccessUrl(ContentHostingService.getUrl(rootId));
4010:                    root.setIconLocation(ContentTypeImageService
4011:                            .getContentTypeImage("folder"));
4012:
4013:                    if (selectedItemId != null
4014:                            && selectedItemId.startsWith(rootId)) {
4015:                        root.setSelected(true);
4016:                        folderId = rootId;
4017:                        try {
4018:                            selectedItem = ContentHostingService
4019:                                    .getCollection(rootId);
4020:                        } catch (IdUnusedException e) {
4021:                            // TODO Auto-generated catch block
4022:                            logger.warn("IdUnusedException ", e);
4023:                        } catch (TypeException e) {
4024:                            // TODO Auto-generated catch block
4025:                            logger.warn("TypeException ", e);
4026:                        } catch (PermissionException e) {
4027:                            // TODO Auto-generated catch block
4028:                            logger.warn("PermissionException ", e);
4029:                        }
4030:                    }
4031:                    roots.add(root);
4032:                }
4033:                // sort by name?
4034:                context.put("roots", roots);
4035:
4036:                ResourceTypeRegistry registry = (ResourceTypeRegistry) state
4037:                        .getAttribute(STATE_RESOURCES_TYPE_REGISTRY);
4038:                if (registry == null) {
4039:                    registry = (ResourceTypeRegistry) ComponentManager
4040:                            .get("org.sakaiproject.content.api.ResourceTypeRegistry");
4041:                    state.setAttribute(STATE_RESOURCES_TYPE_REGISTRY, registry);
4042:                }
4043:
4044:                while (folderId != null) {
4045:                    String collectionId = folderId;
4046:                    folderId = null;
4047:
4048:                    List<ListItem> folder = new Vector<ListItem>();
4049:                    try {
4050:                        if (collection == null) {
4051:                            collection = ContentHostingService
4052:                                    .getCollection(collectionId);
4053:                        }
4054:                        List members = collection.getMemberResources();
4055:                        collection = null;
4056:                        Iterator memberIt = members.iterator();
4057:                        while (memberIt.hasNext()) {
4058:                            ContentEntity member = (ContentEntity) memberIt
4059:                                    .next();
4060:                            String itemId = member.getId();
4061:                            ListItem item = new ListItem(member);
4062:                            if (selectedItemId != null
4063:                                    && (selectedItemId.equals(itemId) || (member
4064:                                            .isCollection() && selectedItemId
4065:                                            .startsWith(itemId)))) {
4066:                                selectedItem = member;
4067:                                item.setSelected(true);
4068:                                if (member.isCollection()) {
4069:                                    folderId = itemId;
4070:                                }
4071:                            } else {
4072:                                item.setSelected(false);
4073:                            }
4074:                            folder.add(item);
4075:                        }
4076:                        folders.add(folder);
4077:
4078:                    } catch (IdUnusedException e) {
4079:                        // TODO Auto-generated catch block
4080:                        logger.warn("IdUnusedException " + e.getMessage());
4081:                    } catch (TypeException e) {
4082:                        // TODO Auto-generated catch block
4083:                        logger.warn("TypeException " + e.getMessage());
4084:                    } catch (PermissionException e) {
4085:                        // TODO Auto-generated catch block
4086:                        logger.warn("PermissionException " + e.getMessage());
4087:                    }
4088:
4089:                }
4090:                context.put("folders", folders);
4091:
4092:                if (selectedItem != null) {
4093:                    // if copy or move is in progress AND user has content.new for this folder, user can paste in the collection 
4094:                    // (the paste action will only be defined for collections)
4095:                    List<String> items_to_be_copied = (List<String>) state
4096:                            .getAttribute(STATE_ITEMS_TO_BE_COPIED);
4097:
4098:                    List<String> items_to_be_moved = (List<String>) state
4099:                            .getAttribute(STATE_ITEMS_TO_BE_MOVED);
4100:
4101:                    List<ResourceToolAction> actions = getActions(selectedItem,
4102:                            new TreeSet(getPermissions(selectedItem.getId(),
4103:                                    null)), registry);
4104:
4105:                    // TODO: need to deal with paste actions
4106:
4107:                    context.put("actions", actions);
4108:                    context.put("labeler", new ResourceTypeLabeler());
4109:                }
4110:
4111:                return "content/sakai_resources_columns";
4112:            }
4113:
4114:            public String buildCreateWizardContext(VelocityPortlet portlet,
4115:                    Context context, RunData data, SessionState state) {
4116:                context.put("tlang", trb);
4117:
4118:                String template = "content/sakai_resources_cwiz_finish";
4119:                ToolSession toolSession = SessionManager
4120:                        .getCurrentToolSession();
4121:                ResourceToolActionPipe pipe = (ResourceToolActionPipe) toolSession
4122:                        .getAttribute(ResourceToolAction.ACTION_PIPE);
4123:                if (pipe == null) {
4124:                    // go back to list view
4125:                } else if (pipe.isActionCanceled()) {
4126:                    // go back to list view
4127:                } else if (pipe.isErrorEncountered()) {
4128:                    // report the error?
4129:                    // go back to list view
4130:                } else {
4131:                    // complete the create wizard
4132:                    String defaultCopyrightStatus = (String) state
4133:                            .getAttribute(STATE_DEFAULT_COPYRIGHT);
4134:                    if (defaultCopyrightStatus == null
4135:                            || defaultCopyrightStatus.trim().equals("")) {
4136:                        defaultCopyrightStatus = ServerConfigurationService
4137:                                .getString("default.copyright");
4138:                        state.setAttribute(STATE_DEFAULT_COPYRIGHT,
4139:                                defaultCopyrightStatus);
4140:                    }
4141:
4142:                    String encoding = data.getRequest().getCharacterEncoding();
4143:
4144:                    Time defaultRetractDate = (Time) state
4145:                            .getAttribute(STATE_DEFAULT_RETRACT_TIME);
4146:                    if (defaultRetractDate == null) {
4147:                        defaultRetractDate = TimeService.newTime();
4148:                        state.setAttribute(STATE_DEFAULT_RETRACT_TIME,
4149:                                defaultRetractDate);
4150:                    }
4151:
4152:                    Boolean preventPublicDisplay = (Boolean) state
4153:                            .getAttribute(STATE_PREVENT_PUBLIC_DISPLAY);
4154:                    if (preventPublicDisplay == null) {
4155:                        preventPublicDisplay = Boolean.FALSE;
4156:                        state.setAttribute(STATE_PREVENT_PUBLIC_DISPLAY,
4157:                                preventPublicDisplay);
4158:                    }
4159:
4160:                    ContentEntity collection = pipe.getContentEntity();
4161:
4162:                    String typeId = pipe.getAction().getTypeId();
4163:
4164:                    ListItem parent = new ListItem(pipe.getContentEntity());
4165:                    parent.setPubviewPossible(!preventPublicDisplay);
4166:                    ListItem item = new ListItem(pipe, parent,
4167:                            defaultRetractDate);
4168:                    //item.setPubviewPossible(! preventPublicDisplay);
4169:
4170:                    context.put("item", item);
4171:
4172:                    state.setAttribute(STATE_CREATE_WIZARD_ITEM, item);
4173:
4174:                    ResourceTypeRegistry registry = (ResourceTypeRegistry) state
4175:                            .getAttribute(STATE_RESOURCES_TYPE_REGISTRY);
4176:                    if (registry == null) {
4177:                        registry = (ResourceTypeRegistry) ComponentManager
4178:                                .get("org.sakaiproject.content.api.ResourceTypeRegistry");
4179:                        state.setAttribute(STATE_RESOURCES_TYPE_REGISTRY,
4180:                                registry);
4181:                    }
4182:                    ResourceType typeDef = registry.getType(typeId);
4183:                    context.put("type", typeDef);
4184:
4185:                    context.put("title", (new ResourceTypeLabeler())
4186:                            .getLabel(pipe.getAction()));
4187:                    context.put("instruction", trb
4188:                            .getFormattedMessage("instr.create",
4189:                                    new String[] { typeDef.getLabel() }));
4190:                    context
4191:                            .put(
4192:                                    "required",
4193:                                    trb
4194:                                            .getFormattedMessage(
4195:                                                    "instr.require",
4196:                                                    new String[] { "<span class=\"reqStarInline\">*</span>" }));
4197:
4198:                    if (ContentHostingService.isAvailabilityEnabled()) {
4199:                        context.put("availability_is_enabled", Boolean.TRUE);
4200:                    }
4201:
4202:                    copyrightChoicesIntoContext(state, context);
4203:                    publicDisplayChoicesIntoContext(state, context);
4204:
4205:                    context.put("SITE_ACCESS", AccessMode.SITE.toString());
4206:                    context.put("GROUP_ACCESS", AccessMode.GROUPED.toString());
4207:                    context.put("INHERITED_ACCESS", AccessMode.INHERITED
4208:                            .toString());
4209:                    context.put("PUBLIC_ACCESS", PUBLIC_ACCESS);
4210:                }
4211:                return template;
4212:            }
4213:
4214:            /**
4215:             * Build the context for delete confirmation page
4216:             */
4217:            public String buildDeleteConfirmContext(VelocityPortlet portlet,
4218:                    Context context, RunData data, SessionState state) {
4219:                context.put("tlang", rb);
4220:                // find the ContentTypeImage service
4221:                context.put("contentTypeImageService", state
4222:                        .getAttribute(STATE_CONTENT_TYPE_IMAGE_SERVICE));
4223:                context.put("collectionId", state
4224:                        .getAttribute(STATE_COLLECTION_ID));
4225:
4226:                //%%%% FIXME
4227:                context.put("collectionPath", state
4228:                        .getAttribute(STATE_COLLECTION_PATH));
4229:
4230:                List deleteItems = (List) state
4231:                        .getAttribute(STATE_DELETE_ITEMS);
4232:                List nonEmptyFolders = (List) state
4233:                        .getAttribute(STATE_DELETE_ITEMS_NOT_EMPTY);
4234:
4235:                context.put("deleteItems", deleteItems);
4236:
4237:                Iterator it = nonEmptyFolders.iterator();
4238:                while (it.hasNext()) {
4239:                    ListItem folder = (ListItem) it.next();
4240:                    String[] args = { folder.getName() };
4241:                    addAlert(state, rb.getFormattedMessage("folder.notempty",
4242:                            args)
4243:                            + " ");
4244:                }
4245:
4246:                //  %%STATE_MODE_RESOURCES%%
4247:                //not show the public option when in dropbox mode
4248:                if (RESOURCES_MODE_RESOURCES.equalsIgnoreCase((String) state
4249:                        .getAttribute(STATE_MODE_RESOURCES))) {
4250:                    context.put("dropboxMode", Boolean.FALSE);
4251:                } else if (RESOURCES_MODE_DROPBOX
4252:                        .equalsIgnoreCase((String) state
4253:                                .getAttribute(STATE_MODE_RESOURCES))) {
4254:                    // not show the public option or notification when in dropbox mode
4255:                    context.put("dropboxMode", Boolean.TRUE);
4256:                }
4257:                context.put("homeCollection", (String) state
4258:                        .getAttribute(STATE_HOME_COLLECTION_ID));
4259:                context.put("siteTitle", state.getAttribute(STATE_SITE_TITLE));
4260:                context.put("resourceProperties", ContentHostingService
4261:                        .newResourceProperties());
4262:
4263:                // String template = (String) getContext(data).get("template");
4264:                return TEMPLATE_DELETE_CONFIRM;
4265:
4266:            } // buildDeleteConfirmContext
4267:
4268:            /**
4269:             * @param portlet
4270:             * @param context
4271:             * @param data
4272:             * @param state
4273:             * @return
4274:             */
4275:            public String buildDeleteFinishContext(VelocityPortlet portlet,
4276:                    Context context, RunData data, SessionState state) {
4277:                context.put("tlang", trb);
4278:                context.put("collectionId", state
4279:                        .getAttribute(STATE_COLLECTION_ID));
4280:
4281:                //%%%% FIXME
4282:                context.put("collectionPath", state
4283:                        .getAttribute(STATE_COLLECTION_PATH));
4284:
4285:                List deleteItems = (List) state.getAttribute(STATE_DELETE_SET);
4286:                List nonEmptyFolders = (List) state
4287:                        .getAttribute(STATE_NON_EMPTY_DELETE_SET);
4288:
4289:                context.put("deleteItems", deleteItems);
4290:
4291:                Iterator it = nonEmptyFolders.iterator();
4292:                while (it.hasNext()) {
4293:                    ListItem folder = (ListItem) it.next();
4294:                    String[] args = { folder.getName() };
4295:                    String msg = rb
4296:                            .getFormattedMessage("folder.notempty", args)
4297:                            + " ";
4298:                    addAlert(state, msg);
4299:                }
4300:
4301:                //  %%STATE_MODE_RESOURCES%%
4302:                //not show the public option when in dropbox mode
4303:                if (RESOURCES_MODE_RESOURCES.equalsIgnoreCase((String) state
4304:                        .getAttribute(STATE_MODE_RESOURCES))) {
4305:                    context.put("dropboxMode", Boolean.FALSE);
4306:                } else if (RESOURCES_MODE_DROPBOX
4307:                        .equalsIgnoreCase((String) state
4308:                                .getAttribute(STATE_MODE_RESOURCES))) {
4309:                    // not show the public option or notification when in dropbox mode
4310:                    context.put("dropboxMode", Boolean.TRUE);
4311:                }
4312:                context.put("homeCollection", (String) state
4313:                        .getAttribute(STATE_HOME_COLLECTION_ID));
4314:                context.put("siteTitle", state.getAttribute(STATE_SITE_TITLE));
4315:                context.put("resourceProperties", ContentHostingService
4316:                        .newResourceProperties());
4317:
4318:                // String template = (String) getContext(data).get("template");
4319:                return TEMPLATE_DELETE_FINISH;
4320:
4321:            }
4322:
4323:            /**
4324:             * Build the context for the new list view, which uses the resources type registry
4325:             */
4326:            public String buildListContext(VelocityPortlet portlet,
4327:                    Context context, RunData data, SessionState state) {
4328:                context.put("tlang", rb);
4329:
4330:                // find the ContentTypeImage service
4331:                context.put("contentTypeImageService", state
4332:                        .getAttribute(STATE_CONTENT_TYPE_IMAGE_SERVICE));
4333:
4334:                context.put("TYPE_UPLOAD", TYPE_UPLOAD);
4335:
4336:                context.put("listStack", new Stack());
4337:                context.put("tempStack", new Stack());
4338:
4339:                context.put("SITE_ACCESS", AccessMode.SITE);
4340:                context.put("GROUP_ACCESS", AccessMode.GROUPED);
4341:                context.put("INHERITED_ACCESS", AccessMode.INHERITED);
4342:                context.put("PUBLIC_ACCESS", PUBLIC_ACCESS);
4343:
4344:                context.put("ACTION_DELIMITER",
4345:                        ResourceToolAction.ACTION_DELIMITER);
4346:
4347:                Set selectedItems = (Set) state
4348:                        .getAttribute(STATE_LIST_SELECTIONS);
4349:                if (selectedItems == null) {
4350:                    selectedItems = new TreeSet();
4351:                    state.setAttribute(STATE_LIST_SELECTIONS, selectedItems);
4352:                }
4353:                context.put("selectedItems", selectedItems);
4354:
4355:                // find the ContentHosting service
4356:                org.sakaiproject.content.api.ContentHostingService contentService = ContentHostingService
4357:                        .getInstance();
4358:                context.put("service", contentService);
4359:
4360:                ResourceTypeRegistry registry = (ResourceTypeRegistry) state
4361:                        .getAttribute(STATE_RESOURCES_TYPE_REGISTRY);
4362:                if (registry == null) {
4363:                    registry = (ResourceTypeRegistry) ComponentManager
4364:                            .get("org.sakaiproject.content.api.ResourceTypeRegistry");
4365:                    state.setAttribute(STATE_RESOURCES_TYPE_REGISTRY, registry);
4366:                }
4367:
4368:                boolean inMyWorkspace = SiteService.isUserSite(ToolManager
4369:                        .getCurrentPlacement().getContext());
4370:                context.put("inMyWorkspace", Boolean.toString(inMyWorkspace));
4371:
4372:                boolean atHome = false;
4373:
4374:                // %%STATE_MODE_RESOURCES%%
4375:
4376:                boolean dropboxMode = RESOURCES_MODE_DROPBOX
4377:                        .equalsIgnoreCase((String) state
4378:                                .getAttribute(STATE_MODE_RESOURCES));
4379:                if (dropboxMode) {
4380:                    // notshow the public option or notification when in dropbox mode
4381:                    context.put("dropboxMode", Boolean.TRUE);
4382:                } else {
4383:                    //context.put("dropboxMode", Boolean.FALSE);
4384:                }
4385:
4386:                // make sure the channedId is set
4387:                String collectionId = (String) state
4388:                        .getAttribute(STATE_COLLECTION_ID);
4389:                context.put("collectionId", collectionId);
4390:                String navRoot = (String) state
4391:                        .getAttribute(STATE_NAVIGATION_ROOT);
4392:                String homeCollectionId = (String) state
4393:                        .getAttribute(STATE_HOME_COLLECTION_ID);
4394:
4395:                String siteTitle = (String) state
4396:                        .getAttribute(STATE_SITE_TITLE);
4397:                if (collectionId.equals(homeCollectionId)) {
4398:                    atHome = true;
4399:                    context.put("collectionDisplayName", state
4400:                            .getAttribute(STATE_HOME_COLLECTION_DISPLAY_NAME));
4401:                } else {
4402:                    // should be not PermissionException thrown at this time, when the user can successfully navigate to this collection
4403:                    try {
4404:                        context.put("collectionDisplayName", contentService
4405:                                .getCollection(collectionId).getProperties()
4406:                                .getProperty(
4407:                                        ResourceProperties.PROP_DISPLAY_NAME));
4408:                    } catch (IdUnusedException e) {
4409:                    } catch (TypeException e) {
4410:                    } catch (PermissionException e) {
4411:                    }
4412:                }
4413:                if (!inMyWorkspace
4414:                        && !dropboxMode
4415:                        && atHome
4416:                        && SiteService.allowUpdateSite(ToolManager
4417:                                .getCurrentPlacement().getContext())) {
4418:                    context.put("showPermissions", Boolean.TRUE.toString());
4419:                    //buildListMenu(portlet, context, data, state);
4420:
4421:                    String home = (String) state
4422:                            .getAttribute(STATE_HOME_COLLECTION_ID);
4423:                    Reference ref = EntityManager
4424:                            .newReference(ContentHostingService
4425:                                    .getReference(home));
4426:                    String siteId = ref.getContext();
4427:                    Map<String, Boolean> statusMap = registry
4428:                            .getMapOfResourceTypesForContext(siteId);
4429:                    if (statusMap != null && !statusMap.isEmpty()) {
4430:                        context.put("showOptions", Boolean.TRUE.toString());
4431:                    }
4432:
4433:                }
4434:
4435:                context.put("atHome", Boolean.toString(atHome));
4436:
4437:                if (ContentHostingService.isAvailabilityEnabled()) {
4438:                    context.put("availability_is_enabled", Boolean.TRUE);
4439:                }
4440:
4441:                Comparator userSelectedSort = (Comparator) state
4442:                        .getAttribute(STATE_LIST_VIEW_SORT);
4443:
4444:                List cPath = getCollectionPath(state);
4445:                context.put("collectionPath", cPath);
4446:
4447:                // set the sort values
4448:                String sortedBy = (String) state.getAttribute(STATE_SORT_BY);
4449:                String sortedAsc = (String) state.getAttribute(STATE_SORT_ASC);
4450:                context.put("currentSortedBy", sortedBy);
4451:                context.put("currentSortAsc", sortedAsc);
4452:                context.put("TRUE", Boolean.TRUE.toString());
4453:
4454:                boolean showRemoveAction = false;
4455:                boolean showMoveAction = false;
4456:                boolean showCopyAction = false;
4457:
4458:                Set highlightedItems = new TreeSet();
4459:
4460:                try {
4461:                    try {
4462:                        contentService.checkCollection(collectionId);
4463:                        context.put("collectionFlag", Boolean.TRUE.toString());
4464:                    } catch (IdUnusedException ex) {
4465:                        logger
4466:                                .warn(this  + "IdUnusedException: "
4467:                                        + collectionId);
4468:                        try {
4469:                            ContentCollectionEdit coll = contentService
4470:                                    .addCollection(collectionId);
4471:                            contentService.commitCollection(coll);
4472:                        } catch (IdUsedException inner) {
4473:                            // how can this happen??
4474:                            logger.warn(this  + "IdUsedException: "
4475:                                    + collectionId);
4476:                            throw ex;
4477:                        } catch (IdInvalidException inner) {
4478:                            logger.warn(this  + "IdInvalidException: "
4479:                                    + collectionId);
4480:                            // what now?
4481:                            throw ex;
4482:                        } catch (InconsistentException inner) {
4483:                            logger.warn(this  + "InconsistentException: "
4484:                                    + collectionId);
4485:                            // what now?
4486:                            throw ex;
4487:                        }
4488:                    } catch (TypeException ex) {
4489:                        logger.warn(this  + "TypeException.");
4490:                        throw ex;
4491:                    } catch (PermissionException ex) {
4492:                        logger.warn(this  + "PermissionException.");
4493:                        throw ex;
4494:                    }
4495:
4496:                    String copyFlag = (String) state
4497:                            .getAttribute(STATE_COPY_FLAG);
4498:                    if (copyFlag.equals(Boolean.TRUE.toString())) {
4499:                        context.put("copyFlag", copyFlag);
4500:                        List copiedItems = (List) state
4501:                                .getAttribute(STATE_COPIED_IDS);
4502:                        // context.put ("copiedItem", state.getAttribute (STATE_COPIED_ID));
4503:                        highlightedItems.addAll(copiedItems);
4504:                        // context.put("copiedItems", copiedItems);
4505:                    }
4506:
4507:                    String moveFlag = (String) state
4508:                            .getAttribute(STATE_MOVE_FLAG);
4509:                    if (moveFlag.equals(Boolean.TRUE.toString())) {
4510:                        context.put("moveFlag", moveFlag);
4511:                        List movedItems = (List) state
4512:                                .getAttribute(STATE_MOVED_IDS);
4513:                        highlightedItems.addAll(movedItems);
4514:                        // context.put ("copiedItem", state.getAttribute (STATE_COPIED_ID));
4515:                        // context.put("movedItems", movedItems);
4516:                    }
4517:
4518:                    SortedSet<String> expandedCollections = (SortedSet<String>) state
4519:                            .getAttribute(STATE_EXPANDED_COLLECTIONS);
4520:
4521:                    //ContentCollection coll = contentService.getCollection(collectionId);
4522:                    expandedCollections.add(collectionId);
4523:                    context.put("expandedCollections", expandedCollections);
4524:
4525:                    state.removeAttribute(STATE_PASTE_ALLOWED_FLAG);
4526:
4527:                    ContentCollection collection = ContentHostingService
4528:                            .getCollection(collectionId);
4529:
4530:                    List<String> items_to_be_copied = (List<String>) state
4531:                            .getAttribute(STATE_ITEMS_TO_BE_COPIED);
4532:                    List<String> items_to_be_moved = (List<String>) state
4533:                            .getAttribute(STATE_ITEMS_TO_BE_MOVED);
4534:
4535:                    boolean need_to_expand_all = Boolean.TRUE
4536:                            .toString()
4537:                            .equals(
4538:                                    (String) state
4539:                                            .getAttribute(STATE_NEED_TO_EXPAND_ALL));
4540:
4541:                    ListItem item = ListItem.getListItem(collection, null,
4542:                            registry, need_to_expand_all, expandedCollections,
4543:                            items_to_be_moved, items_to_be_copied, 0,
4544:                            userSelectedSort, false);
4545:
4546:                    Map<String, ResourceToolAction> listActions = new HashMap<String, ResourceToolAction>();
4547:
4548:                    List<ListItem> items = item.convert2list();
4549:
4550:                    for (ListItem lItem : items) {
4551:                        if (lItem.hasMultipleItemActions()) {
4552:                            for (String listActionId : lItem
4553:                                    .getMultipleItemActions().keySet()) {
4554:                                ServiceLevelAction listAction = registry
4555:                                        .getMultiItemAction(listActionId);
4556:                                if (listAction != null) {
4557:                                    listActions.put(listActionId, listAction);
4558:                                }
4559:                            }
4560:                        }
4561:                    }
4562:
4563:                    String containingCollectionId = contentService
4564:                            .getContainingCollectionId(item.getId());
4565:                    if (contentService.COLLECTION_DROPBOX
4566:                            .equals(containingCollectionId)) {
4567:                        Reference ref = EntityManager
4568:                                .newReference(contentService.getReference(item
4569:                                        .getId()));
4570:                        Site site = SiteService.getSite(ref.getContext());
4571:                        String[] args = { site.getTitle() };
4572:                        item.setName(trb.getFormattedMessage("title.dropbox",
4573:                                args));
4574:                    } else if (contentService.COLLECTION_SITE
4575:                            .equals(containingCollectionId)) {
4576:                        Reference ref = EntityManager
4577:                                .newReference(contentService.getReference(item
4578:                                        .getId()));
4579:                        Site site = SiteService.getSite(ref.getContext());
4580:                        String[] args = { site.getTitle() };
4581:                        item.setName(trb.getFormattedMessage("title.resources",
4582:                                args));
4583:                    }
4584:
4585:                    //			if(atHome && dropboxMode)
4586:                    //			{
4587:                    //				item.setName(siteTitle + " " + rb.getString("gen.drop"));
4588:                    //			}
4589:                    //			else if(atHome)
4590:                    //			{
4591:                    //				item.setName(siteTitle + " " + rb.getString("gen.reso"));
4592:                    //			}
4593:
4594:                    context.put("site", items);
4595:
4596:                    boolean show_all_sites = false;
4597:
4598:                    String allowed_to_see_other_sites = (String) state
4599:                            .getAttribute(STATE_SHOW_ALL_SITES);
4600:                    String show_other_sites = (String) state
4601:                            .getAttribute(STATE_SHOW_OTHER_SITES);
4602:                    context.put("show_other_sites", show_other_sites);
4603:                    if (Boolean.TRUE.toString().equals(
4604:                            allowed_to_see_other_sites)) {
4605:                        context.put("allowed_to_see_other_sites", Boolean.TRUE
4606:                                .toString());
4607:                        show_all_sites = Boolean.TRUE.toString().equals(
4608:                                show_other_sites);
4609:                    }
4610:
4611:                    if (atHome && show_all_sites) {
4612:                        state.setAttribute(STATE_HIGHLIGHTED_ITEMS,
4613:                                highlightedItems);
4614:                        // TODO: see call to prepPage below.  That also calls readAllResources.  Are both calls necessary?
4615:                        //other_sites.addAll(readAllResources(state));
4616:                        //all_roots.addAll(other_sites);
4617:
4618:                        List<ListItem> siteCollections = prepPage(state);
4619:                        List<ListItem> otherSites = new Vector<ListItem>();
4620:                        for (ListItem siteCollection : siteCollections) {
4621:                            otherSites.addAll(siteCollection.convert2list());
4622:                        }
4623:                        context.put("other_sites", otherSites);
4624:
4625:                        if (state.getAttribute(STATE_NUM_MESSAGES) != null) {
4626:                            context.put("allMsgNumber", state.getAttribute(
4627:                                    STATE_NUM_MESSAGES).toString());
4628:                            context.put("allMsgNumberInt", state
4629:                                    .getAttribute(STATE_NUM_MESSAGES));
4630:                        }
4631:
4632:                        context.put("pagesize", ((Integer) state
4633:                                .getAttribute(STATE_PAGESIZE)).toString());
4634:
4635:                        // find the position of the message that is the top first on the page
4636:                        if ((state.getAttribute(STATE_TOP_MESSAGE_INDEX) != null)
4637:                                && (state.getAttribute(STATE_PAGESIZE) != null)) {
4638:                            int topMsgPos = ((Integer) state
4639:                                    .getAttribute(STATE_TOP_MESSAGE_INDEX))
4640:                                    .intValue() + 1;
4641:                            context.put("topMsgPos", Integer
4642:                                    .toString(topMsgPos));
4643:                            int btmMsgPos = topMsgPos
4644:                                    + ((Integer) state
4645:                                            .getAttribute(STATE_PAGESIZE))
4646:                                            .intValue() - 1;
4647:                            if (state.getAttribute(STATE_NUM_MESSAGES) != null) {
4648:                                int allMsgNumber = ((Integer) state
4649:                                        .getAttribute(STATE_NUM_MESSAGES))
4650:                                        .intValue();
4651:                                if (btmMsgPos > allMsgNumber)
4652:                                    btmMsgPos = allMsgNumber;
4653:                            }
4654:                            context.put("btmMsgPos", Integer
4655:                                    .toString(btmMsgPos));
4656:                        }
4657:
4658:                        boolean goPPButton = state
4659:                                .getAttribute(STATE_PREV_PAGE_EXISTS) != null;
4660:                        context.put("goPPButton", Boolean.toString(goPPButton));
4661:                        boolean goNPButton = state
4662:                                .getAttribute(STATE_NEXT_PAGE_EXISTS) != null;
4663:                        context.put("goNPButton", Boolean.toString(goNPButton));
4664:
4665:                        /*
4666:                        boolean goFPButton = state.getAttribute(STATE_FIRST_PAGE_EXISTS) != null;
4667:                        context.put("goFPButton", Boolean.toString(goFPButton));
4668:                        boolean goLPButton = state.getAttribute(STATE_LAST_PAGE_EXISTS) != null;
4669:                        context.put("goLPButton", Boolean.toString(goLPButton));
4670:                         */
4671:
4672:                        context.put("pagesize", state
4673:                                .getAttribute(STATE_PAGESIZE));
4674:                        // context.put("pagesizes", PAGESIZES);
4675:
4676:                    }
4677:
4678:                    context.put("listActions", listActions);
4679:                    context.put("counter", new EntityCounter());
4680:
4681:                    // context.put ("other_sites", other_sites);
4682:                    //state.setAttribute(STATE_COLLECTION_ROOTS, all_roots);
4683:                    // context.put ("root", root);
4684:
4685:                    if (state.getAttribute(STATE_PASTE_ALLOWED_FLAG) != null) {
4686:                        context.put("paste_place_showing", state
4687:                                .getAttribute(STATE_PASTE_ALLOWED_FLAG));
4688:                    }
4689:
4690:                    if (showRemoveAction) {
4691:                        context
4692:                                .put("showRemoveAction", Boolean.TRUE
4693:                                        .toString());
4694:                    }
4695:
4696:                    if (showMoveAction) {
4697:                        context.put("showMoveAction", Boolean.TRUE.toString());
4698:                    }
4699:
4700:                    if (showCopyAction) {
4701:                        context.put("showCopyAction", Boolean.TRUE.toString());
4702:                    }
4703:
4704:                } catch (IdUnusedException e) {
4705:                    addAlert(state, rb.getString("cannotfind"));
4706:                    context.put("collectionFlag", Boolean.FALSE.toString());
4707:                } catch (TypeException e) {
4708:                    logger.warn(this  + "TypeException.");
4709:                    context.put("collectionFlag", Boolean.FALSE.toString());
4710:                } catch (PermissionException e) {
4711:                    addAlert(state, rb.getString("notpermis1"));
4712:                    context.put("collectionFlag", Boolean.FALSE.toString());
4713:                }
4714:
4715:                context.put("homeCollection", (String) state
4716:                        .getAttribute(STATE_HOME_COLLECTION_ID));
4717:                context.put("siteTitle", state.getAttribute(STATE_SITE_TITLE));
4718:                context.put("resourceProperties", contentService
4719:                        .newResourceProperties());
4720:
4721:                try {
4722:                    // TODO: why 'site' here?
4723:                    Site site = SiteService.getSite(ToolManager
4724:                            .getCurrentPlacement().getContext());
4725:                    context.put("siteTitle", site.getTitle());
4726:                } catch (IdUnusedException e) {
4727:                    logger.debug(this  + e.toString());
4728:                }
4729:
4730:                context.put("expandallflag", state
4731:                        .getAttribute(STATE_EXPAND_ALL_FLAG));
4732:                state.removeAttribute(STATE_NEED_TO_EXPAND_ALL);
4733:
4734:                // inform the observing courier that we just updated the page...
4735:                // if there are pending requests to do so they can be cleared
4736:                justDelivered(state);
4737:
4738:                // pick the "show" template based on the standard template name
4739:                // String template = (String) getContext(data).get("template");
4740:
4741:                context.put("labeler", new ResourceTypeLabeler());
4742:
4743:                return TEMPLATE_NEW_LIST;
4744:
4745:            } // buildListContext
4746:
4747:            /**
4748:             * Build the context for normal display
4749:             */
4750:            public String buildMainPanelContext(VelocityPortlet portlet,
4751:                    Context context, RunData data, SessionState state) {
4752:                //context.put("sysout", System.out);
4753:                //context.put("tlang",rb);
4754:                // find the ContentTypeImage service
4755:                context.put("contentTypeImageService", state
4756:                        .getAttribute(STATE_CONTENT_TYPE_IMAGE_SERVICE));
4757:
4758:                context.put("copyright_alert_url", COPYRIGHT_ALERT_URL);
4759:                context.put("ACTION_DELIMITER",
4760:                        ResourceToolAction.ACTION_DELIMITER);
4761:                context.put("DOT", ListItem.DOT);
4762:
4763:                context.put("TYPE_FOLDER", ResourceType.TYPE_FOLDER);
4764:                context.put("TYPE_HTML", ResourceType.TYPE_HTML);
4765:                context.put("TYPE_TEXT", ResourceType.TYPE_TEXT);
4766:                context.put("TYPE_UPLOAD", ResourceType.TYPE_UPLOAD);
4767:                context.put("TYPE_URL", ResourceType.TYPE_URL);
4768:
4769:                ToolSession toolSession = SessionManager
4770:                        .getCurrentToolSession();
4771:                ResourceToolActionPipe pipe = (ResourceToolActionPipe) toolSession
4772:                        .getAttribute(ResourceToolAction.ACTION_PIPE);
4773:                if (pipe != null) {
4774:                    if (pipe.isActionCanceled()) {
4775:                        state.setAttribute(STATE_MODE, MODE_LIST);
4776:                        toolSession
4777:                                .removeAttribute(ResourceToolAction.ACTION_PIPE);
4778:                    } else if (pipe.isErrorEncountered()) {
4779:                        String msg = pipe.getErrorMessage();
4780:                        if (msg != null && !msg.trim().equals("")) {
4781:                            addAlert(state, msg);
4782:                        }
4783:                        state.setAttribute(STATE_MODE, MODE_LIST);
4784:                        toolSession
4785:                                .removeAttribute(ResourceToolAction.ACTION_PIPE);
4786:                    } else if (pipe.isActionCompleted()) {
4787:                        finishAction(state, toolSession, pipe);
4788:                    }
4789:                    toolSession.removeAttribute(ResourceToolAction.DONE);
4790:                }
4791:
4792:                String template = null;
4793:
4794:                // place if notification is enabled and current site is not of My Workspace type
4795:                boolean isUserSite = SiteService.isUserSite(ToolManager
4796:                        .getCurrentPlacement().getContext());
4797:                context.put("notification", new Boolean(!isUserSite
4798:                        && notificationEnabled(state)));
4799:                // get the mode
4800:                String mode = (String) state.getAttribute(STATE_MODE);
4801:                if (mode.equals(MODE_LIST)) {
4802:                    String list_pref = (String) state
4803:                            .getAttribute(STATE_LIST_PREFERENCE);
4804:                    if (list_pref == null) {
4805:                        list_pref = LIST_HIERARCHY;
4806:                    }
4807:                    if (LIST_COLUMNS.equals(list_pref)) {
4808:                        // build the context for list view
4809:                        template = buildColumnsContext(portlet, context, data,
4810:                                state);
4811:                    } else {
4812:                        // build the context for list view
4813:                        //template = buildChefListContext (portlet, context, data, state);
4814:                        template = buildListContext(portlet, context, data,
4815:                                state);
4816:                    }
4817:                }
4818:                //		else if (mode.equals (MODE_CREATE))
4819:                //		{
4820:                //			// build the context for create item
4821:                //			template = buildCreateContext (portlet, context, data, state);
4822:                //		}
4823:                else if (mode.equals(MODE_CREATE_WIZARD)) {
4824:                    template = buildCreateWizardContext(portlet, context, data,
4825:                            state);
4826:                }
4827:                //		else if (mode.equals (MODE_DELETE_CONFIRM))
4828:                //		{
4829:                //			// build the context for the basic step of delete confirm page
4830:                //			template = buildDeleteConfirmContext (portlet, context, data, state);
4831:                //		}
4832:                else if (mode.equals(MODE_DELETE_FINISH)) {
4833:                    // build the context for the basic step of delete confirm page
4834:                    template = buildDeleteFinishContext(portlet, context, data,
4835:                            state);
4836:                } else if (mode.equals(MODE_MORE)) {
4837:                    // build the context to display the property list
4838:                    template = buildMoreContext(portlet, context, data, state);
4839:                }
4840:                //		else if (mode.equals (MODE_EDIT))
4841:                //		{
4842:                //			// build the context to display the property list
4843:                //			template = buildEditContext (portlet, context, data, state);
4844:                //		}
4845:                else if (mode.equals(MODE_OPTIONS)) {
4846:                    template = buildOptionsPanelContext(portlet, context, data,
4847:                            state);
4848:                } else if (mode.equals(MODE_REORDER)) {
4849:                    template = buildReorderContext(portlet, context, data,
4850:                            state);
4851:                } else if (mode.equals(MODE_DAV)) {
4852:                    template = buildWebdavContext(portlet, context, data, state);
4853:                } else if (mode.equals(MODE_REVISE_METADATA)) {
4854:                    template = buildReviseMetadataContext(portlet, context,
4855:                            data, state);
4856:                }
4857:
4858:                return template;
4859:
4860:            } // buildMainPanelContext
4861:
4862:            /**
4863:             *  Setup for customization
4864:             **/
4865:            public String buildOptionsPanelContext(VelocityPortlet portlet,
4866:                    Context context, RunData data, SessionState state) {
4867:                context.put("tlang", trb);
4868:                String home = (String) state
4869:                        .getAttribute(STATE_HOME_COLLECTION_ID);
4870:                Reference ref = EntityManager
4871:                        .newReference(ContentHostingService.getReference(home));
4872:                String siteId = ref.getContext();
4873:
4874:                context.put("siteId", siteId);
4875:                context.put("form-submit", BUTTON + "doUpdateOptions");
4876:                context.put("form-cancel", BUTTON + "doCancelOptions");
4877:                String[] args = { SiteService.getSiteDisplay(siteId) };
4878:                context.put("title", trb.getFormattedMessage("title.options",
4879:                        args));
4880:
4881:                ResourceTypeRegistry registry = (ResourceTypeRegistry) state
4882:                        .getAttribute(STATE_RESOURCES_TYPE_REGISTRY);
4883:                if (registry == null) {
4884:                    registry = (ResourceTypeRegistry) ComponentManager
4885:                            .get("org.sakaiproject.content.api.ResourceTypeRegistry");
4886:                    state.setAttribute(STATE_RESOURCES_TYPE_REGISTRY, registry);
4887:                }
4888:
4889:                Map<String, Boolean> statusMap = registry
4890:                        .getMapOfResourceTypesForContext(siteId);
4891:                context.put("statusMap", statusMap);
4892:
4893:                List types = new Vector(registry.getTypes());
4894:                Collections.sort(types, new Comparator() {
4895:
4896:                    public int compare(Object arg0, Object arg1) {
4897:                        ResourceType type0 = (ResourceType) arg0;
4898:
4899:                        ResourceType type1 = (ResourceType) arg1;
4900:                        return type0.getLabel().compareToIgnoreCase(
4901:                                type1.getLabel());
4902:                    }
4903:                });
4904:
4905:                context.put("types", types);
4906:
4907:                return TEMPLATE_OPTIONS;
4908:
4909:            } // buildOptionsPanelContext
4910:
4911:            /**
4912:             * Build the context to establish a custom-ordering of resources/folders within a folder.
4913:             */
4914:            public String buildReorderContext(VelocityPortlet portlet,
4915:                    Context context, RunData data, SessionState state) {
4916:                context.put("tlang", rb);
4917:
4918:                String folderId = (String) state
4919:                        .getAttribute(STATE_REORDER_FOLDER);
4920:                context.put("folderId", folderId);
4921:
4922:                // save expanded folder lists
4923:                SortedSet<String> expandedCollections = (SortedSet<String>) state
4924:                        .getAttribute(STATE_EXPANDED_COLLECTIONS);
4925:                Map expandedFolderSortMap = (Map) state
4926:                        .getAttribute(STATE_EXPANDED_FOLDER_SORT_MAP);
4927:                String need_to_expand_all = (String) state
4928:                        .getAttribute(STATE_NEED_TO_EXPAND_ALL);
4929:
4930:                // create temporary expanded folder lists for this invocation of getListView
4931:                Map tempExpandedFolderSortMap = new Hashtable();
4932:                state.setAttribute(STATE_EXPANDED_FOLDER_SORT_MAP,
4933:                        tempExpandedFolderSortMap);
4934:                SortedSet tempExpandedCollections = new TreeSet();
4935:                tempExpandedCollections.add(folderId);
4936:                state.setAttribute(STATE_EXPANDED_COLLECTIONS,
4937:                        tempExpandedCollections);
4938:
4939:                Set highlightedItems = new TreeSet();
4940:                List all_roots = new Vector();
4941:                List this _site = new Vector();
4942:
4943:                List members = getListView(folderId, highlightedItems,
4944:                        (ResourcesBrowseItem) null, true, state);
4945:
4946:                // restore expanded folder lists 
4947:                expandedCollections.addAll(tempExpandedCollections);
4948:                state.setAttribute(STATE_EXPANDED_COLLECTIONS,
4949:                        expandedCollections);
4950:                expandedFolderSortMap.putAll(tempExpandedFolderSortMap);
4951:                state.setAttribute(STATE_EXPANDED_FOLDER_SORT_MAP,
4952:                        expandedFolderSortMap);
4953:
4954:                String navRoot = (String) state
4955:                        .getAttribute(STATE_NAVIGATION_ROOT);
4956:                String homeCollectionId = (String) state
4957:                        .getAttribute(STATE_HOME_COLLECTION_ID);
4958:
4959:                boolean atHome = false;
4960:
4961:                context.put("atHome", Boolean.toString(atHome));
4962:
4963:                List cPath = getCollectionPath(state);
4964:                context.put("collectionPath", cPath);
4965:
4966:                String sortBy = (String) state
4967:                        .getAttribute(STATE_REORDER_SORT_BY);
4968:                context.put("sortBy", sortBy);
4969:                String sortAsc = (String) state
4970:                        .getAttribute(STATE_REORDER_SORT_ASC);
4971:                context.put("sortAsc", sortAsc);
4972:                // Comparator comparator = (Comparator) state.getAttribute(STATE_REORDER_SORT);
4973:
4974:                String rootTitle = (String) state
4975:                        .getAttribute(STATE_SITE_TITLE);
4976:                if (folderId.equals(homeCollectionId)) {
4977:                    atHome = true;
4978:                    String siteTitle = (String) state
4979:                            .getAttribute(STATE_SITE_TITLE);
4980:                    rootTitle = siteTitle + " " + rb.getString("gen.reso");
4981:                } else {
4982:                    // should be not PermissionException thrown at this time, when the user can successfully navigate to this collection
4983:                    try {
4984:                        rootTitle = ContentHostingService.getCollection(
4985:                                folderId).getProperties().getProperty(
4986:                                ResourceProperties.PROP_DISPLAY_NAME);
4987:                    } catch (IdUnusedException e) {
4988:                    } catch (TypeException e) {
4989:                    } catch (PermissionException e) {
4990:                    }
4991:                }
4992:
4993:                if (members != null && members.size() > 0) {
4994:                    ResourcesBrowseItem root = (ResourcesBrowseItem) members
4995:                            .remove(0);
4996:                    root.addMembers(members);
4997:                    root.setName(rootTitle);
4998:                    this _site.add(root);
4999:                    all_roots.add(root);
5000:                }
5001:                context.put("this_site", this _site);
5002:
5003:                return TEMPLATE_REORDER;
5004:            }
5005:
5006:            /**
5007:             * @param portlet
5008:             * @param context
5009:             * @param data
5010:             * @param state
5011:             * @return
5012:             */
5013:            public String buildReviseMetadataContext(VelocityPortlet portlet,
5014:                    Context context, RunData data, SessionState state) {
5015:                context.put("tlang", trb);
5016:
5017:                ResourceToolAction action = (ResourceToolAction) state
5018:                        .getAttribute(STATE_REVISE_PROPERTIES_ACTION);
5019:                context.put("action", action);
5020:
5021:                context.put("showItemSummary", Boolean.TRUE.toString());
5022:
5023:                String typeId = action.getTypeId();
5024:
5025:                ResourceTypeRegistry registry = (ResourceTypeRegistry) state
5026:                        .getAttribute(STATE_RESOURCES_TYPE_REGISTRY);
5027:                if (registry == null) {
5028:                    registry = (ResourceTypeRegistry) ComponentManager
5029:                            .get("org.sakaiproject.content.api.ResourceTypeRegistry");
5030:                    state.setAttribute(STATE_RESOURCES_TYPE_REGISTRY, registry);
5031:                }
5032:
5033:                ResourceType type = registry.getType(typeId);
5034:                context.put("type", type);
5035:
5036:                copyrightChoicesIntoContext(state, context);
5037:                publicDisplayChoicesIntoContext(state, context);
5038:
5039:                context
5040:                        .put(
5041:                                "required",
5042:                                trb
5043:                                        .getFormattedMessage(
5044:                                                "instr.require",
5045:                                                new String[] { "<span class=\"reqStarInline\">*</span>" }));
5046:
5047:                ListItem item = (ListItem) state
5048:                        .getAttribute(STATE_REVISE_PROPERTIES_ITEM);
5049:                if (item == null) {
5050:                    item = getListItem(state);
5051:                    state.setAttribute(STATE_REVISE_PROPERTIES_ITEM, item);
5052:                }
5053:                context.put("item", item);
5054:
5055:                if (ContentHostingService.isAvailabilityEnabled()) {
5056:                    context.put("availability_is_enabled", Boolean.TRUE);
5057:                }
5058:
5059:                context.put("SITE_ACCESS", AccessMode.SITE.toString());
5060:                context.put("GROUP_ACCESS", AccessMode.GROUPED.toString());
5061:                context
5062:                        .put("INHERITED_ACCESS", AccessMode.INHERITED
5063:                                .toString());
5064:                context.put("PUBLIC_ACCESS", PUBLIC_ACCESS);
5065:
5066:                return TEMPLATE_REVISE_METADATA;
5067:            }
5068:
5069:            /**
5070:             * @param state
5071:             * @return
5072:             */
5073:            protected ListItem getListItem(SessionState state) {
5074:                // complete the create wizard
5075:                String defaultCopyrightStatus = (String) state
5076:                        .getAttribute(STATE_DEFAULT_COPYRIGHT);
5077:                if (defaultCopyrightStatus == null
5078:                        || defaultCopyrightStatus.trim().equals("")) {
5079:                    defaultCopyrightStatus = ServerConfigurationService
5080:                            .getString("default.copyright");
5081:                    state.setAttribute(STATE_DEFAULT_COPYRIGHT,
5082:                            defaultCopyrightStatus);
5083:                }
5084:
5085:                Time defaultRetractDate = (Time) state
5086:                        .getAttribute(STATE_DEFAULT_RETRACT_TIME);
5087:                if (defaultRetractDate == null) {
5088:                    defaultRetractDate = TimeService.newTime();
5089:                    state.setAttribute(STATE_DEFAULT_RETRACT_TIME,
5090:                            defaultRetractDate);
5091:                }
5092:
5093:                Boolean preventPublicDisplay = (Boolean) state
5094:                        .getAttribute(STATE_PREVENT_PUBLIC_DISPLAY);
5095:                if (preventPublicDisplay == null) {
5096:                    preventPublicDisplay = Boolean.FALSE;
5097:                    state.setAttribute(STATE_PREVENT_PUBLIC_DISPLAY,
5098:                            preventPublicDisplay);
5099:                }
5100:
5101:                String entityId = (String) state
5102:                        .getAttribute(STATE_REVISE_PROPERTIES_ENTITY_ID);
5103:                String refstr = ContentHostingService.getReference(entityId);
5104:                Reference ref = EntityManager.newReference(refstr);
5105:                ContentEntity entity = (ContentEntity) ref.getEntity();
5106:
5107:                ListItem item = new ListItem(entity);
5108:                if (item.getReleaseDate() == null) {
5109:                    item.setReleaseDate(TimeService.newTime());
5110:                }
5111:                if (item.getRetractDate() == null) {
5112:                    item.setRetractDate(defaultRetractDate);
5113:                }
5114:                item.setPubviewPossible(!preventPublicDisplay);
5115:                return item;
5116:            }
5117:
5118:            /**
5119:             * Build the context for add display
5120:             */
5121:            public String buildWebdavContext(VelocityPortlet portlet,
5122:                    Context context, RunData data, SessionState state) {
5123:                context.put("tlang", rb);
5124:                // find the ContentTypeImage service
5125:                context.put("contentTypeImageService", state
5126:                        .getAttribute(STATE_CONTENT_TYPE_IMAGE_SERVICE));
5127:
5128:                boolean inMyWorkspace = SiteService.isUserSite(ToolManager
5129:                        .getCurrentPlacement().getContext());
5130:                context.put("inMyWorkspace", Boolean.toString(inMyWorkspace));
5131:
5132:                context.put("server_url", ServerConfigurationService
5133:                        .getServerUrl());
5134:                context.put("site_id", ToolManager.getCurrentPlacement()
5135:                        .getContext());
5136:                context.put("site_title", state.getAttribute(STATE_SITE_TITLE));
5137:                context.put("user_id", UserDirectoryService.getCurrentUser()
5138:                        .getEid());
5139:                if (ContentHostingService.isShortRefs()) {
5140:                    // with short refs, this is prettier
5141:                    context.put("dav_group", "/dav/");
5142:                    context.put("dav_user", "/dav/~");
5143:                } else {
5144:                    context.put("dav_group", "/dav/group/");
5145:                    context.put("dav_user", "/dav/user/");
5146:                }
5147:
5148:                String webdav_instructions = ServerConfigurationService
5149:                        .getString("webdav.instructions.url");
5150:                context.put("webdav_instructions", webdav_instructions);
5151:
5152:                String browserID = UsageSessionService.getSession()
5153:                        .getBrowserId();
5154:                if (browserID.equals(UsageSession.WIN_IE)) {
5155:                    context.put("isWinIEBrowser", Boolean.TRUE.toString());
5156:                }
5157:
5158:                return TEMPLATE_DAV;
5159:
5160:            } // buildWebdavContext
5161:
5162:            /**
5163:             * Iterate over attributes in ToolSession and remove all attributes starting with a particular prefix.
5164:             * @param toolSession
5165:             * @param prefix
5166:             */
5167:            protected void cleanup(ToolSession toolSession, String prefix) {
5168:                Enumeration attributeNames = toolSession.getAttributeNames();
5169:                while (attributeNames.hasMoreElements()) {
5170:                    String aName = (String) attributeNames.nextElement();
5171:                    if (aName.startsWith(prefix)) {
5172:                        toolSession.removeAttribute(aName);
5173:                    }
5174:                }
5175:
5176:            }
5177:
5178:            /**
5179:             * @param state
5180:             * @param deleteIdSet
5181:             */
5182:            protected void deleteItem(SessionState state, String itemId) {
5183:                List deleteItems = new Vector();
5184:                List notDeleteItems = new Vector();
5185:                List nonEmptyFolders = new Vector();
5186:
5187:                boolean isFolder = itemId.endsWith(Entity.SEPARATOR);
5188:
5189:                try {
5190:                    ContentEntity entity = null;
5191:                    if (isFolder) {
5192:                        entity = ContentHostingService.getCollection(itemId);
5193:                    } else {
5194:                        entity = ContentHostingService.getResource(itemId);
5195:                    }
5196:
5197:                    ListItem member = new ListItem(entity);
5198:
5199:                    if (isFolder) {
5200:                        ContentCollection collection = (ContentCollection) entity;
5201:                        if (ContentHostingService.allowRemoveCollection(itemId)) {
5202:                            deleteItems.add(member);
5203:                            if (collection.getMemberCount() > 0) {
5204:                                nonEmptyFolders.add(member);
5205:                            }
5206:                        } else {
5207:                            notDeleteItems.add(member);
5208:                        }
5209:                    } else if (ContentHostingService.allowRemoveResource(member
5210:                            .getId())) {
5211:                        deleteItems.add(member);
5212:                    } else {
5213:                        notDeleteItems.add(member);
5214:                    }
5215:                } catch (IdUnusedException e) {
5216:                    // TODO Auto-generated catch block
5217:                    logger.warn("IdUnusedException ", e);
5218:                } catch (TypeException e) {
5219:                    // TODO Auto-generated catch block
5220:                    logger.warn("TypeException ", e);
5221:                } catch (PermissionException e) {
5222:                    // TODO Auto-generated catch block
5223:                    logger.warn("PermissionException ", e);
5224:                }
5225:
5226:                if (!notDeleteItems.isEmpty()) {
5227:                    String notDeleteNames = "";
5228:                    boolean first_item = true;
5229:                    Iterator notIt = notDeleteItems.iterator();
5230:                    while (notIt.hasNext()) {
5231:                        ListItem item = (ListItem) notIt.next();
5232:                        if (first_item) {
5233:                            notDeleteNames = item.getName();
5234:                            first_item = false;
5235:                        } else if (notIt.hasNext()) {
5236:                            notDeleteNames += ", " + item.getName();
5237:                        } else {
5238:                            notDeleteNames += " and " + item.getName();
5239:                        }
5240:                    }
5241:                    addAlert(state, rb.getString("notpermis14")
5242:                            + notDeleteNames);
5243:                }
5244:
5245:                if (state.getAttribute(STATE_MESSAGE) == null) {
5246:                    state.setAttribute(STATE_DELETE_SET, deleteItems);
5247:                    state.setAttribute(STATE_NON_EMPTY_DELETE_SET,
5248:                            nonEmptyFolders);
5249:                }
5250:            }
5251:
5252:            /**
5253:             * @param state
5254:             * @param deleteIdSet
5255:             * @param deleteIds
5256:             */
5257:            protected void deleteItems(SessionState state, Set deleteIdSet) {
5258:                List deleteItems = new Vector();
5259:                List notDeleteItems = new Vector();
5260:                List nonEmptyFolders = new Vector();
5261:
5262:                org.sakaiproject.content.api.ContentHostingService contentService = ContentHostingService
5263:                        .getInstance();
5264:
5265:                for (String deleteId : (Set<String>) deleteIdSet) {
5266:                    ContentEntity entity = null;
5267:                    try {
5268:                        if (contentService.isCollection(deleteId)) {
5269:                            entity = contentService.getCollection(deleteId);
5270:                        } else if (contentService.allowRemoveResource(deleteId)) {
5271:                            entity = contentService.getResource(deleteId);
5272:                        } else {
5273:
5274:                        }
5275:                        ListItem item = new ListItem(entity);
5276:                        if (item.isCollection()
5277:                                && contentService
5278:                                        .allowRemoveCollection(deleteId)) {
5279:                            deleteItems.add(item);
5280:                            if (!item.isEmpty) {
5281:                                nonEmptyFolders.add(item);
5282:                            }
5283:                        } else if (!item.isCollection()
5284:                                && contentService.allowRemoveResource(deleteId)) {
5285:                            deleteItems.add(item);
5286:                        } else {
5287:                            notDeleteItems.add(item);
5288:                        }
5289:
5290:                    } catch (PermissionException e) {
5291:
5292:                    } catch (IdUnusedException e) {
5293:                        // TODO Auto-generated catch block
5294:                        e.printStackTrace();
5295:                    } catch (TypeException e) {
5296:                        // TODO Auto-generated catch block
5297:                        e.printStackTrace();
5298:                    }
5299:                }
5300:
5301:                if (!notDeleteItems.isEmpty()) {
5302:                    String notDeleteNames = "";
5303:                    boolean first_item = true;
5304:                    Iterator notIt = notDeleteItems.iterator();
5305:                    while (notIt.hasNext()) {
5306:                        ListItem item = (ListItem) notIt.next();
5307:                        if (first_item) {
5308:                            notDeleteNames = item.getName();
5309:                            first_item = false;
5310:                        } else if (notIt.hasNext()) {
5311:                            notDeleteNames += ", " + item.getName();
5312:                        } else {
5313:                            notDeleteNames += " and " + item.getName();
5314:                        }
5315:                    }
5316:                    addAlert(state, rb.getString("notpermis14")
5317:                            + notDeleteNames);
5318:                }
5319:
5320:                state.setAttribute(STATE_DELETE_SET, deleteItems);
5321:                state.setAttribute(STATE_NON_EMPTY_DELETE_SET, nonEmptyFolders);
5322:            }
5323:
5324:            /**
5325:             * doCancel to return to the previous state
5326:             */
5327:            public void doCancel(RunData data) {
5328:                SessionState state = ((JetspeedRunData) data)
5329:                        .getPortletSessionState(((JetspeedRunData) data)
5330:                                .getJs_peid());
5331:
5332:                state.setAttribute(STATE_LIST_SELECTIONS, new TreeSet());
5333:
5334:                state.setAttribute(STATE_MODE, MODE_LIST);
5335:
5336:                //		if(!isStackEmpty(state))
5337:                //		{
5338:                //			Map current_stack_frame = peekAtStack(state);
5339:                //			current_stack_frame.put(STATE_HELPER_CANCELED_BY_USER, Boolean.TRUE.toString());
5340:                //
5341:                //			popFromStack(state);
5342:                //		}
5343:                //
5344:                //		resetCurrentMode(state);
5345:
5346:            } // doCancel
5347:
5348:            /**
5349:             * Remove the collection id from the expanded collection list
5350:             */
5351:            public void doCollapse_collection(RunData data) {
5352:                SessionState state = ((JetspeedRunData) data)
5353:                        .getPortletSessionState(((JetspeedRunData) data)
5354:                                .getJs_peid());
5355:                SortedSet expandedItems = (SortedSet) state
5356:                        .getAttribute(STATE_EXPANDED_COLLECTIONS);
5357:                if (expandedItems == null) {
5358:                    expandedItems = new TreeSet();
5359:                }
5360:                Map folderSortMap = (Map) state
5361:                        .getAttribute(STATE_EXPANDED_FOLDER_SORT_MAP);
5362:                if (folderSortMap == null) {
5363:                    folderSortMap = new Hashtable();
5364:                    state.setAttribute(STATE_EXPANDED_FOLDER_SORT_MAP,
5365:                            folderSortMap);
5366:                }
5367:
5368:                //get the ParameterParser from RunData
5369:                ParameterParser params = data.getParameters();
5370:                String collectionId = params.getString("collectionId");
5371:
5372:                // save the current selections
5373:                Set selectedSet = new TreeSet();
5374:                String[] selectedItems = data.getParameters().getStrings(
5375:                        "selectedMembers");
5376:                if (selectedItems != null) {
5377:                    selectedSet.addAll(Arrays.asList(selectedItems));
5378:                }
5379:                state.setAttribute(STATE_LIST_SELECTIONS, selectedSet);
5380:
5381:                SortedSet newSet = new TreeSet();
5382:                Iterator l = expandedItems.iterator();
5383:                while (l.hasNext()) {
5384:                    // remove the collection id and all of the subcollections
5385:                    //		    Resource collection = (Resource) l.next();
5386:                    //			String id = (String) collection.getId();
5387:                    String id = (String) l.next();
5388:
5389:                    if (id.indexOf(collectionId) == -1) {
5390:                        //			newSet.put(id,collection);
5391:                        newSet.add(id);
5392:                    } else {
5393:                        folderSortMap.remove(id);
5394:                    }
5395:                }
5396:
5397:                state.setAttribute(STATE_EXPANDED_COLLECTIONS, newSet);
5398:
5399:                // remove this folder id into the set to be event-observed
5400:                removeObservingPattern(collectionId, state);
5401:
5402:            } // doCollapse_collection
5403:
5404:            public void doColumns(RunData data) {
5405:                SessionState state = ((JetspeedRunData) data)
5406:                        .getPortletSessionState(((JetspeedRunData) data)
5407:                                .getJs_peid());
5408:                state.setAttribute(STATE_LIST_PREFERENCE, LIST_COLUMNS);
5409:            }
5410:
5411:            /**
5412:             * @param data
5413:             */
5414:            public void doCompleteCreateWizard(RunData data) {
5415:                SessionState state = ((JetspeedRunData) data)
5416:                        .getPortletSessionState(((JetspeedRunData) data)
5417:                                .getJs_peid());
5418:
5419:                ListItem item = (ListItem) state
5420:                        .getAttribute(STATE_CREATE_WIZARD_ITEM);
5421:
5422:                // get the parameter-parser
5423:                ParameterParser params = data.getParameters();
5424:
5425:                String user_action = params.getString("user_action");
5426:
5427:                ToolSession toolSession = SessionManager
5428:                        .getCurrentToolSession();
5429:                ResourceToolActionPipe pipe = (ResourceToolActionPipe) toolSession
5430:                        .getAttribute(ResourceToolAction.ACTION_PIPE);
5431:
5432:                if (user_action == null) {
5433:
5434:                } else if (user_action.equals("save")) {
5435:                    item.captureProperties(params, ListItem.DOT + "0");
5436:                    String name = params.getString("name" + ListItem.DOT + "0");
5437:                    if (name == null) {
5438:                        name = item.getName();
5439:                    } else {
5440:                        item.setName(name);
5441:                    }
5442:                    if (name == null) {
5443:                        item.setNameIsMissing(true);
5444:                        addAlert(state, rb.getString("edit.missing"));
5445:                        return;
5446:                    } else {
5447:                        name = name.trim();
5448:                    }
5449:
5450:                    String collectionId = (String) state
5451:                            .getAttribute(STATE_CREATE_WIZARD_COLLECTION_ID);
5452:                    try {
5453:                        // title
5454:                        String basename = name;
5455:                        String extension = "";
5456:                        if (name.contains(".")) {
5457:                            String[] parts = name.split("\\.");
5458:                            basename = parts[0];
5459:                            if (parts.length > 1) {
5460:                                extension = parts[parts.length - 1];
5461:                            }
5462:
5463:                            for (int i = 1; i < parts.length - 1; i++) {
5464:                                basename += "." + parts[i];
5465:                            }
5466:                        }
5467:
5468:                        // create resource
5469:                        ContentResourceEdit resource = ContentHostingService
5470:                                .addResource(
5471:                                        collectionId,
5472:                                        Validator.escapeResourceName(basename),
5473:                                        Validator.escapeResourceName(extension),
5474:                                        MAXIMUM_ATTEMPTS_FOR_UNIQUENESS);
5475:
5476:                        String resourceType = null;
5477:                        if (pipe != null) {
5478:                            ResourceToolAction action = pipe.getAction();
5479:                            if (action == null) {
5480:
5481:                            } else {
5482:                                if (action instanceof  InteractionAction) {
5483:                                    InteractionAction iAction = (InteractionAction) action;
5484:                                    iAction.finalizeAction(EntityManager
5485:                                            .newReference(resource
5486:                                                    .getReference()), pipe
5487:                                            .getInitializationId());
5488:                                }
5489:                                resourceType = action.getTypeId();
5490:                            }
5491:                        }
5492:
5493:                        resource.setResourceType(resourceType);
5494:
5495:                        item.updateContentResourceEdit(resource);
5496:
5497:                        byte[] content = pipe.getRevisedContent();
5498:                        if (content == null) {
5499:                            InputStream stream = pipe.getRevisedContentStream();
5500:                            if (stream == null) {
5501:                                logger
5502:                                        .warn("pipe with null content and null stream: "
5503:                                                + pipe.getFileName());
5504:                            } else {
5505:                                resource.setContent(stream);
5506:                            }
5507:                        } else {
5508:                            resource.setContent(content);
5509:                        }
5510:
5511:                        resource.setContentType(pipe.getRevisedMimeType());
5512:
5513:                        ResourcePropertiesEdit resourceProperties = resource
5514:                                .getPropertiesEdit();
5515:                        Map values = pipe.getRevisedResourceProperties();
5516:                        Iterator valueIt = values.keySet().iterator();
5517:                        while (valueIt.hasNext()) {
5518:                            String pname = (String) valueIt.next();
5519:                            String pvalue = (String) values.get(pname);
5520:                            resourceProperties.addProperty(pname, pvalue);
5521:
5522:                        }
5523:
5524:                        // notification
5525:                        int noti = NotificationService.NOTI_NONE;
5526:                        // %%STATE_MODE_RESOURCES%%
5527:                        if (RESOURCES_MODE_DROPBOX
5528:                                .equalsIgnoreCase((String) state
5529:                                        .getAttribute(STATE_MODE_RESOURCES))) {
5530:                            // set noti to none if in dropbox mode
5531:                            noti = NotificationService.NOTI_NONE;
5532:                        } else {
5533:                            // read the notification options
5534:                            String notification = params.getString("notify");
5535:                            if ("r".equals(notification)) {
5536:                                noti = NotificationService.NOTI_REQUIRED;
5537:                            } else if ("o".equals(notification)) {
5538:                                noti = NotificationService.NOTI_OPTIONAL;
5539:                            }
5540:                        }
5541:
5542:                        List<String> alerts = item.checkRequiredProperties();
5543:
5544:                        if (alerts.isEmpty()) {
5545:
5546:                            ContentHostingService
5547:                                    .commitResource(resource, noti);
5548:
5549:                            toolSession
5550:                                    .removeAttribute(ResourceToolAction.ACTION_PIPE);
5551:
5552:                            // show folder if in hierarchy view
5553:                            SortedSet expandedCollections = (SortedSet) state
5554:                                    .getAttribute(STATE_EXPANDED_COLLECTIONS);
5555:                            expandedCollections.add(collectionId);
5556:
5557:                            state.setAttribute(STATE_MODE, MODE_LIST);
5558:                        } else {
5559:                            for (String alert : alerts) {
5560:                                addAlert(state, alert);
5561:                            }
5562:                        }
5563:                    } catch (IdUnusedException e) {
5564:                        logger.warn("IdUnusedException", e);
5565:                    } catch (PermissionException e) {
5566:                        logger.warn("PermissionException", e);
5567:                    } catch (IdInvalidException e) {
5568:                        logger.warn("IdInvalidException", e);
5569:                    } catch (ServerOverloadException e) {
5570:                        logger.warn("ServerOverloadException", e);
5571:                    } catch (OverQuotaException e) {
5572:                        // TODO Auto-generated catch block
5573:                        logger.warn("OverQuotaException ", e);
5574:                    } catch (IdUniquenessException e) {
5575:                        addAlert(state, trb.getFormattedMessage("paste.error",
5576:                                new Object[] { name }));
5577:                    } catch (IdLengthException e) {
5578:                        // TODO Auto-generated catch block
5579:                        logger.warn("IdLengthException ", e);
5580:                    }
5581:
5582:                } else if (user_action.equals("cancel")) {
5583:                    if (pipe != null) {
5584:                        ResourceToolAction action = pipe.getAction();
5585:                        if (action == null) {
5586:
5587:                        } else {
5588:                            if (action instanceof  InteractionAction) {
5589:                                InteractionAction iAction = (InteractionAction) action;
5590:                                iAction.cancelAction(null, pipe
5591:                                        .getInitializationId());
5592:                            }
5593:                            state
5594:                                    .removeAttribute(ResourceToolAction.ACTION_PIPE);
5595:                        }
5596:                    }
5597:                    state.setAttribute(STATE_MODE, MODE_LIST);
5598:                }
5599:            }
5600:
5601:            /**
5602:             * set the state name to be "copy" if any item has been selected for copying
5603:             */
5604:            public void doCopy(RunData data) {
5605:                // get the state object
5606:                SessionState state = ((JetspeedRunData) data)
5607:                        .getPortletSessionState(((JetspeedRunData) data)
5608:                                .getJs_peid());
5609:
5610:                // cancel copy if there is one in progress
5611:                if (!Boolean.FALSE.toString().equals(
5612:                        state.getAttribute(STATE_COPY_FLAG))) {
5613:                    initCopyContext(state);
5614:                }
5615:
5616:                // cancel move if there is one in progress
5617:                if (!Boolean.FALSE.toString().equals(
5618:                        state.getAttribute(STATE_MOVE_FLAG))) {
5619:                    initMoveContext(state);
5620:                }
5621:
5622:                Vector copyItemsVector = new Vector();
5623:
5624:                String[] copyItems = data.getParameters().getStrings(
5625:                        "selectedMembers");
5626:                if (copyItems == null) {
5627:                    // there is no resource selected, show the alert message to the user
5628:                    addAlert(state, rb.getString("choosefile6"));
5629:                    state.setAttribute(STATE_MODE, MODE_LIST);
5630:                } else {
5631:                    String copyId = NULL_STRING;
5632:                    for (int i = 0; i < copyItems.length; i++) {
5633:                        copyId = copyItems[i];
5634:                        try {
5635:                            ResourceProperties properties = ContentHostingService
5636:                                    .getProperties(copyId);
5637:                            /*
5638:                            if (properties.getProperty (ResourceProperties.PROP_IS_COLLECTION).equals (Boolean.TRUE.toString()))
5639:                            {
5640:                            	String alert = (String) state.getAttribute(STATE_MESSAGE);
5641:                            	if (alert == null || ((alert != null) && (alert.indexOf(rb.getString("notsupported")) == -1)))
5642:                            	{
5643:                            		addAlert(state, rb.getString("notsupported"));
5644:                            	}
5645:                            }
5646:                             */
5647:                        } catch (PermissionException e) {
5648:                            addAlert(state, rb.getString("notpermis15"));
5649:                        } catch (IdUnusedException e) {
5650:                            addAlert(state, rb.getString("notexist1"));
5651:                        } // try-catch
5652:                    }
5653:
5654:                    if (state.getAttribute(STATE_MESSAGE) == null) {
5655:                        state.setAttribute(STATE_COPY_FLAG, Boolean.TRUE
5656:                                .toString());
5657:
5658:                        copyItemsVector.addAll(Arrays.asList(copyItems));
5659:                        ContentHostingService
5660:                                .eliminateDuplicates(copyItemsVector);
5661:                        state.setAttribute(STATE_COPIED_IDS, copyItemsVector);
5662:
5663:                    } // if-else
5664:                } // if-else
5665:
5666:            } // doCopy
5667:
5668:            /**
5669:             * set the state name to be "deletecofirm" if any item has been selected for deleting
5670:             */
5671:            public void doDeleteconfirm(RunData data) {
5672:                SessionState state = ((JetspeedRunData) data)
5673:                        .getPortletSessionState(((JetspeedRunData) data)
5674:                                .getJs_peid());
5675:
5676:                // cancel copy if there is one in progress
5677:                if (!Boolean.FALSE.toString().equals(
5678:                        state.getAttribute(STATE_COPY_FLAG))) {
5679:                    initCopyContext(state);
5680:                }
5681:
5682:                // cancel move if there is one in progress
5683:                if (!Boolean.FALSE.toString().equals(
5684:                        state.getAttribute(STATE_MOVE_FLAG))) {
5685:                    initMoveContext(state);
5686:                }
5687:
5688:                Set deleteIdSet = new TreeSet();
5689:                String[] deleteIds = data.getParameters().getStrings(
5690:                        "selectedMembers");
5691:                if (deleteIds == null) {
5692:                    // there is no resource selected, show the alert message to the user
5693:                    addAlert(state, rb.getString("choosefile3"));
5694:                } else {
5695:                    deleteIdSet.addAll(Arrays.asList(deleteIds));
5696:                    deleteItems(state, deleteIdSet);
5697:                }
5698:
5699:                if (state.getAttribute(STATE_MESSAGE) == null) {
5700:                    state.setAttribute(STATE_MODE, MODE_DELETE_FINISH);
5701:                    state.setAttribute(STATE_LIST_SELECTIONS, deleteIdSet);
5702:                }
5703:
5704:            } // doDeleteconfirm
5705:
5706:            public void doDispatchAction(RunData data) {
5707:                try {
5708:                    SessionState state = ((JetspeedRunData) data)
5709:                            .getPortletSessionState(((JetspeedRunData) data)
5710:                                    .getJs_peid());
5711:
5712:                    // get the parameter-parser
5713:                    ParameterParser params = data.getParameters();
5714:
5715:                    String action_string = params.getString("rt_action");
5716:                    String selectedItemId = params.getString("selectedItemId");
5717:
5718:                    String[] parts = action_string
5719:                            .split(ResourceToolAction.ACTION_DELIMITER);
5720:                    String typeId = parts[0];
5721:                    String actionId = parts[1];
5722:
5723:                    // ResourceType type = getResourceType(selectedItemId, state);
5724:                    ResourceTypeRegistry registry = (ResourceTypeRegistry) state
5725:                            .getAttribute(STATE_RESOURCES_TYPE_REGISTRY);
5726:                    if (registry == null) {
5727:                        registry = (ResourceTypeRegistry) ComponentManager
5728:                                .get("org.sakaiproject.content.api.ResourceTypeRegistry");
5729:                        state.setAttribute(STATE_RESOURCES_TYPE_REGISTRY,
5730:                                registry);
5731:                    }
5732:                    ResourceType type = registry.getType(typeId);
5733:
5734:                    Reference reference = EntityManager
5735:                            .newReference(ContentHostingService
5736:                                    .getReference(selectedItemId));
5737:
5738:                    ResourceToolAction action = type.getAction(actionId);
5739:                    if (action == null) {
5740:
5741:                    } else if (action instanceof  InteractionAction) {
5742:                        ToolSession toolSession = SessionManager
5743:                                .getCurrentToolSession();
5744:                        // toolSession.setAttribute(ResourceToolAction.ACTION_ID, actionId);
5745:                        // toolSession.setAttribute(ResourceToolAction.RESOURCE_TYPE, typeId);
5746:
5747:                        state.setAttribute(STATE_CREATE_WIZARD_COLLECTION_ID,
5748:                                selectedItemId);
5749:
5750:                        ContentEntity entity = (ContentEntity) reference
5751:                                .getEntity();
5752:                        InteractionAction iAction = (InteractionAction) action;
5753:                        String intitializationId = iAction
5754:                                .initializeAction(reference);
5755:
5756:                        ResourceToolActionPipe pipe = registry.newPipe(
5757:                                intitializationId, action);
5758:                        pipe.setContentEntity(entity);
5759:                        pipe.setHelperId(iAction.getHelperId());
5760:
5761:                        toolSession.setAttribute(
5762:                                ResourceToolAction.ACTION_PIPE, pipe);
5763:
5764:                        ResourceProperties props = entity.getProperties();
5765:
5766:                        List propKeys = iAction.getRequiredPropertyKeys();
5767:                        if (propKeys != null) {
5768:                            Iterator it = propKeys.iterator();
5769:                            while (it.hasNext()) {
5770:                                String key = (String) it.next();
5771:                                Object value = props.get(key);
5772:                                if (value == null) {
5773:                                    // do nothing
5774:                                } else if (value instanceof  String) {
5775:                                    pipe.setResourceProperty(key,
5776:                                            (String) value);
5777:                                } else if (value instanceof  List) {
5778:                                    pipe.setResourceProperty(key, (List) value);
5779:                                }
5780:                            }
5781:                        }
5782:
5783:                        if (entity.isResource()) {
5784:                            try {
5785:                                pipe.setMimeType(((ContentResource) entity)
5786:                                        .getContentType());
5787:                                pipe.setContent(((ContentResource) entity)
5788:                                        .getContent());
5789:                            } catch (ServerOverloadException e) {
5790:                                logger
5791:                                        .warn(
5792:                                                this 
5793:                                                        + ".doDispatchAction ServerOverloadException",
5794:                                                e);
5795:                            }
5796:                        }
5797:
5798:                        startHelper(data.getRequest(), iAction.getHelperId());
5799:                    } else if (action instanceof  ServiceLevelAction) {
5800:                        ServiceLevelAction sAction = (ServiceLevelAction) action;
5801:                        switch (sAction.getActionType()) {
5802:                        case COPY:
5803:                            List<String> items_to_be_copied = new Vector<String>();
5804:                            if (selectedItemId != null) {
5805:                                items_to_be_copied.add(selectedItemId);
5806:                            }
5807:                            state.removeAttribute(STATE_ITEMS_TO_BE_MOVED);
5808:                            state.setAttribute(STATE_ITEMS_TO_BE_COPIED,
5809:                                    items_to_be_copied);
5810:                            break;
5811:                        case DUPLICATE:
5812:                            sAction.initializeAction(reference);
5813:                            String newId = duplicateItem(
5814:                                    state,
5815:                                    selectedItemId,
5816:                                    ContentHostingService
5817:                                            .getContainingCollectionId(selectedItemId));
5818:                            if (newId == null) {
5819:                                sAction.cancelAction(reference);
5820:                            } else {
5821:                                reference = EntityManager
5822:                                        .newReference(ContentHostingService
5823:                                                .getReference(newId));
5824:                                sAction.finalizeAction(reference);
5825:                            }
5826:                            state.removeAttribute(STATE_ITEMS_TO_BE_MOVED);
5827:                            break;
5828:                        case DELETE:
5829:                            sAction.initializeAction(reference);
5830:                            deleteItem(state, selectedItemId);
5831:                            if (state.getAttribute(STATE_MESSAGE) == null) {
5832:                                // need new context
5833:                                state.setAttribute(STATE_MODE,
5834:                                        MODE_DELETE_FINISH);
5835:                            }
5836:                            sAction.finalizeAction(reference);
5837:                            break;
5838:                        case MOVE:
5839:                            List<String> items_to_be_moved = new Vector<String>();
5840:                            if (selectedItemId != null) {
5841:                                items_to_be_moved.add(selectedItemId);
5842:                            }
5843:                            state.removeAttribute(STATE_ITEMS_TO_BE_COPIED);
5844:                            state.setAttribute(STATE_ITEMS_TO_BE_MOVED,
5845:                                    items_to_be_moved);
5846:                            break;
5847:                        case VIEW_METADATA:
5848:                            break;
5849:                        case REVISE_METADATA:
5850:                            // sAction.initializeAction(reference);
5851:                            state.setAttribute(
5852:                                    STATE_REVISE_PROPERTIES_ENTITY_ID,
5853:                                    selectedItemId);
5854:                            state.setAttribute(STATE_REVISE_PROPERTIES_ACTION,
5855:                                    action);
5856:                            state
5857:                                    .setAttribute(STATE_MODE,
5858:                                            MODE_REVISE_METADATA);
5859:                            ListItem item = getListItem(state);
5860:                            state.setAttribute(STATE_REVISE_PROPERTIES_ITEM,
5861:                                    item);
5862:                            // sAction.finalizeAction(reference);
5863:                            break;
5864:                        case CUSTOM_TOOL_ACTION:
5865:                            // do nothing
5866:                            break;
5867:                        case NEW_UPLOAD:
5868:                            break;
5869:                        case NEW_FOLDER:
5870:                            break;
5871:                        case NEW_URLS:
5872:                            break;
5873:                        case CREATE:
5874:                            break;
5875:                        case REVISE_CONTENT:
5876:                            break;
5877:                        case REPLACE_CONTENT:
5878:                            break;
5879:                        case PASTE_MOVED:
5880:                            //sAction.initializeAction(reference);
5881:                            pasteItem(state, selectedItemId);
5882:                            //sAction.finalizeAction(reference);
5883:                            break;
5884:                        case PASTE_COPIED:
5885:                            //sAction.initializeAction(reference);
5886:                            pasteItem(state, selectedItemId);
5887:                            //sAction.finalizeAction(reference);
5888:                            break;
5889:                        case REVISE_ORDER:
5890:                            sAction.initializeAction(reference);
5891:                            state.setAttribute(STATE_REORDER_FOLDER,
5892:                                    selectedItemId);
5893:                            state.setAttribute(STATE_MODE, MODE_REORDER);
5894:                            sAction.finalizeAction(reference);
5895:                            break;
5896:                        default:
5897:                            sAction.initializeAction(reference);
5898:                            sAction.finalizeAction(reference);
5899:                            break;
5900:                        }
5901:                        // not quite right for actions involving user interaction in Resources tool.
5902:                        // For example, with delete, this should be after the confirmation and actual deletion
5903:                        // Need mechanism to remember to do it later
5904:
5905:                    }
5906:                } catch (Exception e) {
5907:                    logger.warn("doDispatchAction ", e);
5908:                }
5909:            }
5910:
5911:            /**
5912:             * Add the collection id into the expanded collection list
5913:             * @throws PermissionException
5914:             * @throws TypeException
5915:             * @throws IdUnusedException
5916:             */
5917:            public void doExpand_collection(RunData data)
5918:                    throws IdUnusedException, TypeException,
5919:                    PermissionException {
5920:                SessionState state = ((JetspeedRunData) data)
5921:                        .getPortletSessionState(((JetspeedRunData) data)
5922:                                .getJs_peid());
5923:                SortedSet expandedItems = (SortedSet) state
5924:                        .getAttribute(STATE_EXPANDED_COLLECTIONS);
5925:                if (expandedItems == null) {
5926:                    expandedItems = new TreeSet();
5927:                    state.setAttribute(STATE_EXPANDED_COLLECTIONS,
5928:                            expandedItems);
5929:                }
5930:
5931:                //get the ParameterParser from RunData
5932:                ParameterParser params = data.getParameters();
5933:
5934:                // save the current selections
5935:                Set selectedSet = new TreeSet();
5936:                String[] selectedItems = params.getStrings("selectedMembers");
5937:                if (selectedItems != null) {
5938:                    selectedSet.addAll(Arrays.asList(selectedItems));
5939:                }
5940:                state.setAttribute(STATE_LIST_SELECTIONS, selectedSet);
5941:
5942:                String id = params.getString("collectionId");
5943:                expandedItems.add(id);
5944:
5945:                // add this folder id into the set to be event-observed
5946:                addObservingPattern(id, state);
5947:
5948:            } // doExpand_collection
5949:
5950:            /**
5951:             * Expand all the collection resources.
5952:             */
5953:            public void doExpandall(RunData data) {
5954:                // get the state object
5955:                SessionState state = ((JetspeedRunData) data)
5956:                        .getPortletSessionState(((JetspeedRunData) data)
5957:                                .getJs_peid());
5958:
5959:                //get the ParameterParser from RunData
5960:                ParameterParser params = data.getParameters();
5961:
5962:                // save the current selections
5963:                Set selectedSet = new TreeSet();
5964:                String[] selectedItems = params.getStrings("selectedMembers");
5965:                if (selectedItems != null) {
5966:                    selectedSet.addAll(Arrays.asList(selectedItems));
5967:                }
5968:                state.setAttribute(STATE_LIST_SELECTIONS, selectedSet);
5969:
5970:                // expansion actually occurs in getBrowseItems method.
5971:                state.setAttribute(STATE_EXPAND_ALL_FLAG, Boolean.TRUE
5972:                        .toString());
5973:                state.setAttribute(STATE_NEED_TO_EXPAND_ALL, Boolean.TRUE
5974:                        .toString());
5975:
5976:            } // doExpandall
5977:
5978:            /**
5979:             * doDelete to delete the selected collection or resource items
5980:             */
5981:            public void doFinalizeDelete(RunData data) {
5982:                SessionState state = ((JetspeedRunData) data)
5983:                        .getPortletSessionState(((JetspeedRunData) data)
5984:                                .getJs_peid());
5985:
5986:                // cancel copy if there is one in progress
5987:                if (!Boolean.FALSE.toString().equals(
5988:                        state.getAttribute(STATE_COPY_FLAG))) {
5989:                    initCopyContext(state);
5990:                }
5991:
5992:                // cancel move if there is one in progress
5993:                if (!Boolean.FALSE.toString().equals(
5994:                        state.getAttribute(STATE_MOVE_FLAG))) {
5995:                    initMoveContext(state);
5996:                }
5997:
5998:                ParameterParser params = data.getParameters();
5999:
6000:                List items = (List) state.getAttribute(STATE_DELETE_SET);
6001:
6002:                // Vector deleteIds = (Vector) state.getAttribute (STATE_DELETE_IDS);
6003:
6004:                // delete the lowest item in the hireachy first
6005:                Hashtable deleteItems = new Hashtable();
6006:                // String collectionId = (String) state.getAttribute (STATE_COLLECTION_ID);
6007:                int maxDepth = 0;
6008:                int depth = 0;
6009:
6010:                Iterator it = items.iterator();
6011:                while (it.hasNext()) {
6012:                    ListItem item = (ListItem) it.next();
6013:                    String[] parts = item.getId().split(Entity.SEPARATOR);
6014:                    depth = parts.length;
6015:                    if (depth > maxDepth) {
6016:                        maxDepth = depth;
6017:                    }
6018:                    List v = (List) deleteItems.get(new Integer(depth));
6019:                    if (v == null) {
6020:                        v = new Vector();
6021:                    }
6022:                    v.add(item);
6023:                    deleteItems.put(new Integer(depth), v);
6024:                }
6025:
6026:                boolean isCollection = false;
6027:                for (int j = maxDepth; j > 0; j--) {
6028:                    List v = (List) deleteItems.get(new Integer(j));
6029:                    if (v == null) {
6030:                        v = new Vector();
6031:                    }
6032:                    Iterator itemIt = v.iterator();
6033:                    while (itemIt.hasNext()) {
6034:                        ListItem item = (ListItem) itemIt.next();
6035:                        try {
6036:                            if (item.isCollection()) {
6037:                                ContentHostingService.removeCollection(item
6038:                                        .getId());
6039:                            } else {
6040:                                ContentHostingService.removeResource(item
6041:                                        .getId());
6042:                            }
6043:                        } catch (PermissionException e) {
6044:                            addAlert(state, rb.getString("notpermis6") + " "
6045:                                    + item.getName() + ". ");
6046:                        } catch (IdUnusedException e) {
6047:                            addAlert(state, rb.getString("notexist1"));
6048:                        } catch (TypeException e) {
6049:                            addAlert(state, rb.getString("deleteres") + " "
6050:                                    + item.getName() + " "
6051:                                    + rb.getString("wrongtype"));
6052:                        } catch (ServerOverloadException e) {
6053:                            addAlert(state, rb.getString("failed"));
6054:                        } catch (InUseException e) {
6055:                            addAlert(state, rb.getString("deleteres") + " "
6056:                                    + item.getName() + " "
6057:                                    + rb.getString("locked"));
6058:                        }// try - catch
6059:                        catch (RuntimeException e) {
6060:                            logger
6061:                                    .debug("ResourcesAction.doDelete ***** Unknown Exception ***** "
6062:                                            + e.getMessage());
6063:                            addAlert(state, rb.getString("failed"));
6064:                        }
6065:                    } // for
6066:
6067:                } // for
6068:
6069:                if (state.getAttribute(STATE_MESSAGE) == null) {
6070:                    // delete sucessful
6071:                    state.setAttribute(STATE_MODE, MODE_LIST);
6072:                    state.removeAttribute(STATE_DELETE_SET);
6073:                    state.removeAttribute(STATE_NON_EMPTY_DELETE_SET);
6074:
6075:                    if (((String) state.getAttribute(STATE_SELECT_ALL_FLAG))
6076:                            .equals(Boolean.TRUE.toString())) {
6077:                        state.setAttribute(STATE_SELECT_ALL_FLAG, Boolean.FALSE
6078:                                .toString());
6079:                    }
6080:
6081:                } // if-else
6082:
6083:            } // doDelete
6084:
6085:            /**
6086:             * @param data
6087:             */
6088:            public void doHide_metadata(RunData data) {
6089:                ParameterParser params = data.getParameters();
6090:                String name = params.getString("metadataGroup");
6091:
6092:                SessionState state = ((JetspeedRunData) data)
6093:                        .getPortletSessionState(((JetspeedRunData) data)
6094:                                .getJs_peid());
6095:                List metadataGroups = (List) state
6096:                        .getAttribute(STATE_METADATA_GROUPS);
6097:                if (metadataGroups != null && !metadataGroups.isEmpty()) {
6098:                    boolean found = false;
6099:                    MetadataGroup group = null;
6100:                    Iterator it = metadataGroups.iterator();
6101:                    while (!found && it.hasNext()) {
6102:                        group = (MetadataGroup) it.next();
6103:                        found = (name.equals(Validator.escapeUrl(group
6104:                                .getName())) || name.equals(group.getName()));
6105:                    }
6106:                    if (found) {
6107:                        group.setShowing(false);
6108:                    }
6109:                }
6110:
6111:            } // doHide_metadata
6112:
6113:            /**
6114:             * @param data
6115:             */
6116:            public void doHideOtherSites(RunData data) {
6117:                SessionState state = ((JetspeedRunData) data)
6118:                        .getPortletSessionState(((JetspeedRunData) data)
6119:                                .getJs_peid());
6120:
6121:                state.setAttribute(STATE_SHOW_OTHER_SITES, Boolean.FALSE
6122:                        .toString());
6123:
6124:                //get the ParameterParser from RunData
6125:                ParameterParser params = data.getParameters();
6126:
6127:                // save the current selections
6128:                Set selectedSet = new TreeSet();
6129:                String[] selectedItems = params.getStrings("selectedMembers");
6130:                if (selectedItems != null) {
6131:                    selectedSet.addAll(Arrays.asList(selectedItems));
6132:                }
6133:                state.setAttribute(STATE_LIST_SELECTIONS, selectedSet);
6134:
6135:            }
6136:
6137:            public void doHierarchy(RunData data) {
6138:                SessionState state = ((JetspeedRunData) data)
6139:                        .getPortletSessionState(((JetspeedRunData) data)
6140:                                .getJs_peid());
6141:                state.setAttribute(STATE_LIST_PREFERENCE, LIST_HIERARCHY);
6142:            }
6143:
6144:            //	private static void resetCurrentMode(SessionState state)
6145:            //	{
6146:            //		String mode = (String) state.getAttribute(STATE_MODE);
6147:            //		if(isStackEmpty(state))
6148:            //		{
6149:            //			if(MODE_HELPER.equals(mode))
6150:            //			{
6151:            //				cleanupState(state);
6152:            //				state.setAttribute(STATE_RESOURCES_HELPER_MODE, MODE_ATTACHMENT_DONE);
6153:            //			}
6154:            //			else
6155:            //			{
6156:            //				state.setAttribute(STATE_MODE, MODE_LIST);
6157:            //				state.removeAttribute(STATE_RESOURCES_HELPER_MODE);
6158:            //			}
6159:            //			return;
6160:            //		}
6161:            //		Map current_stack_frame = peekAtStack(state);
6162:            //		String helper_mode = (String) current_stack_frame.get(STATE_RESOURCES_HELPER_MODE);
6163:            //		if(helper_mode != null)
6164:            //		{
6165:            //			state.setAttribute(STATE_RESOURCES_HELPER_MODE, helper_mode);
6166:            //		}
6167:            //
6168:            //	}
6169:            //
6170:            /**
6171:             * Expand all the collection resources and put in EXPANDED_COLLECTIONS attribute.
6172:             */
6173:            public void doList(RunData data) {
6174:                // get the state object
6175:                SessionState state = ((JetspeedRunData) data)
6176:                        .getPortletSessionState(((JetspeedRunData) data)
6177:                                .getJs_peid());
6178:
6179:                state.setAttribute(STATE_MODE, MODE_LIST);
6180:
6181:            } // doList
6182:
6183:            /**
6184:             * Handle user's selection of items to be moved.
6185:             */
6186:            public void doMove(RunData data) {
6187:                // get the state object
6188:                SessionState state = ((JetspeedRunData) data)
6189:                        .getPortletSessionState(((JetspeedRunData) data)
6190:                                .getJs_peid());
6191:
6192:                List moveItemsVector = new Vector();
6193:
6194:                // cancel copy if there is one in progress
6195:                if (!Boolean.FALSE.toString().equals(
6196:                        state.getAttribute(STATE_COPY_FLAG))) {
6197:                    initCopyContext(state);
6198:                }
6199:
6200:                // cancel move if there is one in progress
6201:                if (!Boolean.FALSE.toString().equals(
6202:                        state.getAttribute(STATE_MOVE_FLAG))) {
6203:                    initMoveContext(state);
6204:                }
6205:
6206:                state.setAttribute(STATE_LIST_SELECTIONS, new TreeSet());
6207:
6208:                String[] moveItems = data.getParameters().getStrings(
6209:                        "selectedMembers");
6210:                if (moveItems == null) {
6211:                    // there is no resource selected, show the alert message to the user
6212:                    addAlert(state, rb.getString("choosefile6"));
6213:                    state.setAttribute(STATE_MODE, MODE_LIST);
6214:                } else {
6215:                    String moveId = NULL_STRING;
6216:                    for (int i = 0; i < moveItems.length; i++) {
6217:                        moveId = moveItems[i];
6218:                        try {
6219:                            ResourceProperties properties = ContentHostingService
6220:                                    .getProperties(moveId);
6221:                            /*
6222:                            if (properties.getProperty (ResourceProperties.PROP_IS_COLLECTION).equals (Boolean.TRUE.toString()))
6223:                            {
6224:                            	String alert = (String) state.getAttribute(STATE_MESSAGE);
6225:                            	if (alert == null || ((alert != null) && (alert.indexOf(rb.getString("notsupported")) == -1)))
6226:                            	{
6227:                            		addAlert(state, rb.getString("notsupported"));
6228:                            	}
6229:                            }
6230:                             */
6231:                        } catch (PermissionException e) {
6232:                            addAlert(state, rb.getString("notpermis15"));
6233:                        } catch (IdUnusedException e) {
6234:                            addAlert(state, rb.getString("notexist1"));
6235:                        } // try-catch
6236:                    }
6237:
6238:                    if (state.getAttribute(STATE_MESSAGE) == null) {
6239:                        state.setAttribute(STATE_MOVE_FLAG, Boolean.TRUE
6240:                                .toString());
6241:
6242:                        moveItemsVector.addAll(Arrays.asList(moveItems));
6243:
6244:                        ContentHostingService
6245:                                .eliminateDuplicates(moveItemsVector);
6246:
6247:                        state.setAttribute(STATE_MOVED_IDS, moveItemsVector);
6248:
6249:                    } // if-else
6250:                } // if-else
6251:
6252:            } // doMove
6253:
6254:            public void doMultiItemDispatch(RunData data) {
6255:                SessionState state = ((JetspeedRunData) data)
6256:                        .getPortletSessionState(((JetspeedRunData) data)
6257:                                .getJs_peid());
6258:
6259:                ParameterParser params = data.getParameters();
6260:
6261:                String actionId = params.getString("rt_action");
6262:
6263:                if (actionId == null) {
6264:
6265:                } else if (ResourceToolAction.COPY.equals(actionId)) {
6266:                    List selectedSet = new Vector();
6267:                    String[] selectedItems = params
6268:                            .getStrings("selectedMembers");
6269:                    if (selectedItems != null) {
6270:                        selectedSet.addAll(Arrays.asList(selectedItems));
6271:                    }
6272:
6273:                    state.setAttribute(STATE_ITEMS_TO_BE_COPIED, selectedSet);
6274:                    state.removeAttribute(STATE_ITEMS_TO_BE_MOVED);
6275:                } else if (ResourceToolAction.MOVE.equals(actionId)) {
6276:                    List selectedSet = new Vector();
6277:                    String[] selectedItems = params
6278:                            .getStrings("selectedMembers");
6279:                    if (selectedItems != null) {
6280:                        selectedSet.addAll(Arrays.asList(selectedItems));
6281:                    }
6282:
6283:                    state.setAttribute(STATE_ITEMS_TO_BE_MOVED, selectedSet);
6284:                    state.removeAttribute(STATE_ITEMS_TO_BE_COPIED);
6285:                } else if (ResourceToolAction.DELETE.equals(actionId)) {
6286:                    doDeleteconfirm(data);
6287:                }
6288:
6289:            }
6290:
6291:            /**
6292:             * Navigate in the resource hireachy
6293:             */
6294:            public void doNavigate(RunData data) {
6295:                SessionState state = ((JetspeedRunData) data)
6296:                        .getPortletSessionState(((JetspeedRunData) data)
6297:                                .getJs_peid());
6298:
6299:                if (state.getAttribute(STATE_SELECT_ALL_FLAG) != null
6300:                        && state.getAttribute(STATE_SELECT_ALL_FLAG).equals(
6301:                                Boolean.TRUE.toString())) {
6302:                    state.setAttribute(STATE_SELECT_ALL_FLAG, Boolean.FALSE
6303:                            .toString());
6304:                }
6305:
6306:                if (state.getAttribute(STATE_EXPAND_ALL_FLAG) != null
6307:                        && state.getAttribute(STATE_EXPAND_ALL_FLAG).equals(
6308:                                Boolean.TRUE.toString())) {
6309:                    state.setAttribute(STATE_EXPAND_ALL_FLAG, Boolean.FALSE
6310:                            .toString());
6311:                }
6312:
6313:                // save the current selections
6314:                Set selectedSet = new TreeSet();
6315:                String[] selectedItems = data.getParameters().getStrings(
6316:                        "selectedMembers");
6317:                if (selectedItems != null) {
6318:                    selectedSet.addAll(Arrays.asList(selectedItems));
6319:                }
6320:                state.setAttribute(STATE_LIST_SELECTIONS, selectedSet);
6321:
6322:                String collectionId = data.getParameters().getString(
6323:                        "collectionId");
6324:                String navRoot = data.getParameters().getString("navRoot");
6325:                state.setAttribute(STATE_NAVIGATION_ROOT, navRoot);
6326:
6327:                // the exception message
6328:
6329:                try {
6330:                    ContentHostingService.checkCollection(collectionId);
6331:                } catch (PermissionException e) {
6332:                    addAlert(state, " " + rb.getString("notpermis3") + " ");
6333:                } catch (IdUnusedException e) {
6334:                    addAlert(state, " " + rb.getString("notexist2") + " ");
6335:                } catch (TypeException e) {
6336:                    addAlert(state, " " + rb.getString("notexist2") + " ");
6337:                }
6338:
6339:                if (state.getAttribute(STATE_MESSAGE) == null) {
6340:                    String oldCollectionId = (String) state
6341:                            .getAttribute(STATE_COLLECTION_ID);
6342:                    // update this folder id in the set to be event-observed
6343:                    removeObservingPattern(oldCollectionId, state);
6344:                    addObservingPattern(collectionId, state);
6345:
6346:                    state.setAttribute(STATE_COLLECTION_ID, collectionId);
6347:
6348:                    SortedSet currentMap = (SortedSet) state
6349:                            .getAttribute(STATE_EXPANDED_COLLECTIONS);
6350:                    if (currentMap == null) {
6351:                        currentMap = new TreeSet();
6352:                        state.setAttribute(STATE_EXPANDED_COLLECTIONS,
6353:                                currentMap);
6354:                    }
6355:
6356:                    Map sortMap = (Map) state
6357:                            .getAttribute(STATE_EXPANDED_FOLDER_SORT_MAP);
6358:                    if (sortMap == null) {
6359:                        sortMap = new Hashtable();
6360:                        state.setAttribute(STATE_EXPANDED_FOLDER_SORT_MAP,
6361:                                sortMap);
6362:                    }
6363:
6364:                    Iterator it = currentMap.iterator();
6365:                    while (it.hasNext()) {
6366:                        String id = (String) it.next();
6367:                        if (id.startsWith(collectionId)) {
6368:                            it.remove();
6369:                            sortMap.remove(id);
6370:                            removeObservingPattern(id, state);
6371:                        }
6372:                    }
6373:
6374:                    if (!currentMap.contains(collectionId)) {
6375:                        currentMap.add(collectionId);
6376:
6377:                        // add this folder id into the set to be event-observed
6378:                        addObservingPattern(collectionId, state);
6379:                    }
6380:                    //state.setAttribute(STATE_EXPANDED_FOLDER_SORT_MAP, new Hashtable());
6381:                }
6382:
6383:            } // doNavigate
6384:
6385:            /**
6386:             * Fire up the permissions editor for the tool's permissions
6387:             */
6388:            public void doPermissions(RunData data, Context context) {
6389:                SessionState state = ((JetspeedRunData) data)
6390:                        .getPortletSessionState(((JetspeedRunData) data)
6391:                                .getJs_peid());
6392:
6393:                // cancel copy if there is one in progress
6394:                if (!Boolean.FALSE.toString().equals(
6395:                        state.getAttribute(STATE_COPY_FLAG))) {
6396:                    initCopyContext(state);
6397:                }
6398:
6399:                // cancel move if there is one in progress
6400:                if (!Boolean.FALSE.toString().equals(
6401:                        state.getAttribute(STATE_MOVE_FLAG))) {
6402:                    initMoveContext(state);
6403:                }
6404:
6405:                // should we save here?
6406:                state.setAttribute(STATE_LIST_SELECTIONS, new TreeSet());
6407:
6408:                // get the current home collection id and the related site
6409:                String collectionId = (String) state
6410:                        .getAttribute(STATE_HOME_COLLECTION_ID);
6411:                Reference ref = EntityManager
6412:                        .newReference(ContentHostingService
6413:                                .getReference(collectionId));
6414:                String siteRef = SiteService.siteReference(ref.getContext());
6415:
6416:                // setup for editing the permissions of the site for this tool, using the roles of this site, too
6417:                state.setAttribute(PermissionsHelper.TARGET_REF, siteRef);
6418:
6419:                // ... with this description
6420:                state.setAttribute(PermissionsHelper.DESCRIPTION, rb
6421:                        .getString("setpermis1")
6422:                        + SiteService.getSiteDisplay(ref.getContext()));
6423:
6424:                // ... showing only locks that are prpefixed with this
6425:                state.setAttribute(PermissionsHelper.PREFIX, "content.");
6426:
6427:                // get into helper mode with this helper tool
6428:                startHelper(data.getRequest(), "sakai.permissions.helper");
6429:
6430:            } // doPermissions
6431:
6432:            /**
6433:             * Sort based on the given property
6434:             */
6435:            public void doReorder(RunData data) {
6436:                SessionState state = ((JetspeedRunData) data)
6437:                        .getPortletSessionState(((JetspeedRunData) data)
6438:                                .getJs_peid());
6439:
6440:                //get the ParameterParser from RunData
6441:                ParameterParser params = data.getParameters();
6442:
6443:                boolean isPrioritySortEnabled = ContentHostingService
6444:                        .isSortByPriorityEnabled();
6445:
6446:                String folderId = params.getString("folderId");
6447:                if (folderId == null) {
6448:                    addAlert(state, "error");
6449:                }
6450:
6451:                String sortBy = (String) state
6452:                        .getAttribute(STATE_REORDER_SORT_BY);
6453:                if (sortBy == null) {
6454:                    sortBy = ResourceProperties.PROP_CONTENT_PRIORITY;
6455:                    state.setAttribute(STATE_REORDER_SORT_BY, sortBy);
6456:                }
6457:                String sortedAsc = (String) state
6458:                        .getAttribute(STATE_REORDER_SORT_ASC);
6459:                if (sortedAsc == null) {
6460:                    sortedAsc = Boolean.TRUE.toString();
6461:                    state.setAttribute(STATE_REORDER_SORT_ASC, sortedAsc);
6462:                }
6463:
6464:                Comparator comparator = ContentHostingService
6465:                        .newContentHostingComparator(sortBy, Boolean
6466:                                .getBoolean(sortedAsc));
6467:                state.setAttribute(STATE_REORDER_SORT, comparator);
6468:
6469:                if (state.getAttribute(STATE_MESSAGE) == null) {
6470:                    state.setAttribute(STATE_REORDER_FOLDER, folderId);
6471:                    state.setAttribute(STATE_MODE, MODE_REORDER);
6472:
6473:                } // if-else
6474:
6475:            } // doReorder
6476:
6477:            public void doReviseProperties(RunData data) {
6478:                // get the state object
6479:                SessionState state = ((JetspeedRunData) data)
6480:                        .getPortletSessionState(((JetspeedRunData) data)
6481:                                .getJs_peid());
6482:
6483:                // get the parameter-parser
6484:                ParameterParser params = data.getParameters();
6485:
6486:                String user_action = params.getString("user_action");
6487:
6488:                if (user_action.equals("save")) {
6489:                    String entityId = (String) state
6490:                            .getAttribute(STATE_REVISE_PROPERTIES_ENTITY_ID);
6491:                    ListItem item = (ListItem) state
6492:                            .getAttribute(STATE_REVISE_PROPERTIES_ITEM);
6493:                    ResourceToolAction action = (ResourceToolAction) state
6494:                            .getAttribute(STATE_REVISE_PROPERTIES_ACTION);
6495:
6496:                    if (item == null) {
6497:
6498:                    }
6499:                    item.captureProperties(params, ListItem.DOT + "0");
6500:
6501:                    // notification
6502:                    int noti = NotificationService.NOTI_NONE;
6503:                    // %%STATE_MODE_RESOURCES%%
6504:                    if (RESOURCES_MODE_DROPBOX.equalsIgnoreCase((String) state
6505:                            .getAttribute(STATE_MODE_RESOURCES))) {
6506:                        // set noti to none if in dropbox mode
6507:                        noti = NotificationService.NOTI_NONE;
6508:                    } else {
6509:                        // read the notification options
6510:                        String notification = params.getString("notify");
6511:                        if ("r".equals(notification)) {
6512:                            noti = NotificationService.NOTI_REQUIRED;
6513:                        } else if ("o".equals(notification)) {
6514:                            noti = NotificationService.NOTI_OPTIONAL;
6515:                        }
6516:                    }
6517:
6518:                    List<String> alerts = item.checkRequiredProperties();
6519:
6520:                    if (alerts.isEmpty()) {
6521:                        try {
6522:                            if (item.isCollection()) {
6523:                                ContentCollectionEdit entity = ContentHostingService
6524:                                        .editCollection(entityId);
6525:                                item.updateContentCollectionEdit(entity);
6526:
6527:                                ContentHostingService.commitCollection(entity);
6528:                            } else {
6529:                                ContentResourceEdit entity = ContentHostingService
6530:                                        .editResource(entityId);
6531:                                item.updateContentResourceEdit(entity);
6532:                                ContentHostingService.commitResource(entity,
6533:                                        noti);
6534:                            }
6535:
6536:                            state.setAttribute(STATE_MODE, MODE_LIST);
6537:                        } catch (IdUnusedException e) {
6538:                            logger.warn("IdUnusedException", e);
6539:                        } catch (TypeException e) {
6540:                            logger.warn("TypeException", e);
6541:                        } catch (PermissionException e) {
6542:                            logger.warn("PermissionException", e);
6543:                        } catch (ServerOverloadException e) {
6544:                            logger.warn("ServerOverloadException", e);
6545:                        } catch (OverQuotaException e) {
6546:                            // TODO Auto-generated catch block
6547:                            logger.warn("OverQuotaException ", e);
6548:                        } catch (InUseException e) {
6549:                            // TODO Auto-generated catch block
6550:                            logger.warn("InUseException ", e);
6551:                        }
6552:                    } else {
6553:                        for (String alert : alerts) {
6554:                            addAlert(state, alert);
6555:                        }
6556:                    }
6557:
6558:                } else if (user_action.equals("cancel")) {
6559:                    state.setAttribute(STATE_MODE, MODE_LIST);
6560:                }
6561:            }
6562:
6563:            /**
6564:             * Sort based on the given property
6565:             */
6566:            public void doSaveOrder(RunData data) {
6567:                SessionState state = ((JetspeedRunData) data)
6568:                        .getPortletSessionState(((JetspeedRunData) data)
6569:                                .getJs_peid());
6570:
6571:                //get the ParameterParser from RunData
6572:                ParameterParser params = data.getParameters();
6573:
6574:                String flow = params.getString("flow");
6575:
6576:                if ("save".equalsIgnoreCase(flow)) {
6577:                    String folderId = params.getString("folderId");
6578:                    if (folderId == null) {
6579:                        // TODO: log error
6580:                        // TODO: move strings to rb
6581:                        addAlert(state, "Unable to complete Sort");
6582:                    } else {
6583:                        try {
6584:                            ContentCollectionEdit collection = ContentHostingService
6585:                                    .editCollection(folderId);
6586:                            List memberIds = collection.getMembers();
6587:                            Map priorities = new Hashtable();
6588:                            Iterator it = memberIds.iterator();
6589:                            while (it.hasNext()) {
6590:                                String memberId = (String) it.next();
6591:                                int position = params.getInt("position_"
6592:                                        + Validator.escapeUrl(memberId));
6593:                                priorities.put(memberId, new Integer(position));
6594:                            }
6595:                            collection.setPriorityMap(priorities);
6596:
6597:                            ContentHostingService.commitCollection(collection);
6598:
6599:                            SortedSet expandedCollections = (SortedSet) state
6600:                                    .getAttribute(STATE_EXPANDED_COLLECTIONS);
6601:                            if (expandedCollections == null) {
6602:                                expandedCollections = (SortedSet) new TreeSet();
6603:                                state.setAttribute(STATE_EXPANDED_COLLECTIONS,
6604:                                        expandedCollections);
6605:                            }
6606:                            expandedCollections.add(folderId);
6607:
6608:                            Comparator comparator = ContentHostingService
6609:                                    .newContentHostingComparator(
6610:                                            ResourceProperties.PROP_CONTENT_PRIORITY,
6611:                                            true);
6612:                            Map expandedFolderSortMap = (Map) state
6613:                                    .getAttribute(STATE_EXPANDED_FOLDER_SORT_MAP);
6614:                            if (expandedFolderSortMap == null) {
6615:                                expandedFolderSortMap = new Hashtable();
6616:                                state.setAttribute(
6617:                                        STATE_EXPANDED_FOLDER_SORT_MAP,
6618:                                        expandedFolderSortMap);
6619:                            }
6620:                            expandedFolderSortMap.put(folderId, comparator);
6621:                        } catch (IdUnusedException e) {
6622:                            // TODO: log error
6623:                            // TODO: move strings to rb
6624:                            addAlert(state, "Unable to complete Sort");
6625:                        } catch (TypeException e) {
6626:                            // TODO: log error
6627:                            // TODO: move strings to rb
6628:                            addAlert(state, "Unable to complete Sort");
6629:                        } catch (PermissionException e) {
6630:                            // TODO: log error
6631:                            // TODO: move strings to rb
6632:                            addAlert(state, "Unable to complete Sort");
6633:                        } catch (InUseException e) {
6634:                            // TODO: log error
6635:                            // TODO: move strings to rb
6636:                            addAlert(state, "Unable to complete Sort");
6637:                        }
6638:                    }
6639:                }
6640:
6641:                if (state.getAttribute(STATE_MESSAGE) == null) {
6642:                    state.setAttribute(STATE_MODE, MODE_LIST);
6643:
6644:                } // if-else
6645:
6646:            } // doSaveOrder
6647:
6648:            /**
6649:             * @param data
6650:             */
6651:            public void doShow_metadata(RunData data) {
6652:                ParameterParser params = data.getParameters();
6653:                String name = params.getString("metadataGroup");
6654:
6655:                SessionState state = ((JetspeedRunData) data)
6656:                        .getPortletSessionState(((JetspeedRunData) data)
6657:                                .getJs_peid());
6658:                List metadataGroups = (List) state
6659:                        .getAttribute(STATE_METADATA_GROUPS);
6660:                if (metadataGroups != null && !metadataGroups.isEmpty()) {
6661:                    boolean found = false;
6662:                    MetadataGroup group = null;
6663:                    Iterator it = metadataGroups.iterator();
6664:                    while (!found && it.hasNext()) {
6665:                        group = (MetadataGroup) it.next();
6666:                        found = (name.equals(Validator.escapeUrl(group
6667:                                .getName())) || name.equals(group.getName()));
6668:                    }
6669:                    if (found) {
6670:                        group.setShowing(true);
6671:                    }
6672:                }
6673:
6674:            } // doShow_metadata
6675:
6676:            /**
6677:             * Show information about WebDAV
6678:             */
6679:            public void doShow_webdav(RunData data) {
6680:                SessionState state = ((JetspeedRunData) data)
6681:                        .getPortletSessionState(((JetspeedRunData) data)
6682:                                .getJs_peid());
6683:
6684:                state.setAttribute(STATE_LIST_SELECTIONS, new TreeSet());
6685:
6686:                state.setAttribute(STATE_MODE, MODE_DAV);
6687:
6688:                // cancel copy if there is one in progress
6689:                if (!Boolean.FALSE.toString().equals(
6690:                        state.getAttribute(STATE_COPY_FLAG))) {
6691:                    initCopyContext(state);
6692:                }
6693:
6694:                // cancel move if there is one in progress
6695:                if (!Boolean.FALSE.toString().equals(
6696:                        state.getAttribute(STATE_MOVE_FLAG))) {
6697:                    initMoveContext(state);
6698:                }
6699:
6700:            } // doShow_webdav
6701:
6702:            public void doShowMembers(RunData data) {
6703:                // get the state object
6704:                SessionState state = ((JetspeedRunData) data)
6705:                        .getPortletSessionState(((JetspeedRunData) data)
6706:                                .getJs_peid());
6707:
6708:                // get the parameter-parser
6709:                ParameterParser params = data.getParameters();
6710:
6711:                // get the item to be expanded
6712:                String itemId = params.getString("item");
6713:                if (itemId != null) {
6714:                    // put the itemId into state
6715:                    state.setAttribute(STATE_COLUMN_ITEM_ID, itemId);
6716:                }
6717:            }
6718:
6719:            /**
6720:             * @param data
6721:             */
6722:            public void doShowOtherSites(RunData data) {
6723:                SessionState state = ((JetspeedRunData) data)
6724:                        .getPortletSessionState(((JetspeedRunData) data)
6725:                                .getJs_peid());
6726:
6727:                //get the ParameterParser from RunData
6728:                ParameterParser params = data.getParameters();
6729:
6730:                // save the current selections
6731:                Set selectedSet = new TreeSet();
6732:                String[] selectedItems = params.getStrings("selectedMembers");
6733:                if (selectedItems != null) {
6734:                    selectedSet.addAll(Arrays.asList(selectedItems));
6735:                }
6736:                state.setAttribute(STATE_LIST_SELECTIONS, selectedSet);
6737:
6738:                state.setAttribute(STATE_SHOW_OTHER_SITES, Boolean.TRUE
6739:                        .toString());
6740:            }
6741:
6742:            /**
6743:             * Sort based on the given property
6744:             */
6745:            public void doSort(RunData data) {
6746:                SessionState state = ((JetspeedRunData) data)
6747:                        .getPortletSessionState(((JetspeedRunData) data)
6748:                                .getJs_peid());
6749:
6750:                //get the ParameterParser from RunData
6751:                ParameterParser params = data.getParameters();
6752:
6753:                // save the current selections
6754:                Set selectedSet = new TreeSet();
6755:                String[] selectedItems = data.getParameters().getStrings(
6756:                        "selectedMembers");
6757:                if (selectedItems != null) {
6758:                    selectedSet.addAll(Arrays.asList(selectedItems));
6759:                }
6760:                state.setAttribute(STATE_LIST_SELECTIONS, selectedSet);
6761:
6762:                String criteria = params.getString("criteria");
6763:
6764:                if (criteria.equals("title")) {
6765:                    criteria = ResourceProperties.PROP_DISPLAY_NAME;
6766:                } else if (criteria.equals("size")) {
6767:                    criteria = ResourceProperties.PROP_CONTENT_LENGTH;
6768:                } else if (criteria.equals("created by")) {
6769:                    criteria = ResourceProperties.PROP_CREATOR;
6770:                } else if (criteria.equals("last modified")) {
6771:                    criteria = ResourceProperties.PROP_MODIFIED_DATE;
6772:                } else if (criteria.equals("priority")
6773:                        && ContentHostingService.isSortByPriorityEnabled()) {
6774:                    // if error, use title sort
6775:                    criteria = ResourceProperties.PROP_CONTENT_PRIORITY;
6776:                } else {
6777:                    criteria = ResourceProperties.PROP_DISPLAY_NAME;
6778:                }
6779:
6780:                String sortBy_attribute = STATE_SORT_BY;
6781:                String sortAsc_attribute = STATE_SORT_ASC;
6782:                String comparator_attribute = STATE_LIST_VIEW_SORT;
6783:
6784:                if (state.getAttribute(STATE_MODE).equals(MODE_REORDER)) {
6785:                    sortBy_attribute = STATE_REORDER_SORT_BY;
6786:                    sortAsc_attribute = STATE_REORDER_SORT_ASC;
6787:                    comparator_attribute = STATE_REORDER_SORT;
6788:                }
6789:                // current sorting sequence
6790:                String asc = NULL_STRING;
6791:                boolean bValue = true;
6792:                if (!criteria.equals(state.getAttribute(sortBy_attribute))) {
6793:                    state.setAttribute(sortBy_attribute, criteria);
6794:                    asc = Boolean.TRUE.toString();
6795:                    bValue = true;
6796:                    state.setAttribute(sortAsc_attribute, asc);
6797:                } else {
6798:                    // current sorting sequence
6799:                    asc = (String) state.getAttribute(sortAsc_attribute);
6800:
6801:                    //toggle between the ascending and descending sequence
6802:                    if (asc.equals(Boolean.TRUE.toString())) {
6803:                        bValue = false;
6804:                    } else {
6805:                        bValue = true;
6806:                    }
6807:                    asc = Boolean.toString(bValue);
6808:                    state.setAttribute(sortAsc_attribute, asc);
6809:                }
6810:
6811:                if (state.getAttribute(STATE_MESSAGE) == null) {
6812:                    Comparator comparator = ContentHostingService
6813:                            .newContentHostingComparator(criteria, bValue);
6814:                    state.setAttribute(comparator_attribute, comparator);
6815:
6816:                    // sort sucessful
6817:                    // state.setAttribute (STATE_MODE, MODE_LIST);
6818:
6819:                } // if-else
6820:
6821:            } // doSort
6822:
6823:            /**
6824:             * Unexpand all the collection resources
6825:             */
6826:            public void doUnexpandall(RunData data) {
6827:                // get the state object
6828:                SessionState state = ((JetspeedRunData) data)
6829:                        .getPortletSessionState(((JetspeedRunData) data)
6830:                                .getJs_peid());
6831:
6832:                //get the ParameterParser from RunData
6833:                ParameterParser params = data.getParameters();
6834:
6835:                // save the current selections
6836:                Set selectedSet = new TreeSet();
6837:                String[] selectedItems = params.getStrings("selectedMembers");
6838:                if (selectedItems != null) {
6839:                    selectedSet.addAll(Arrays.asList(selectedItems));
6840:                }
6841:                state.setAttribute(STATE_LIST_SELECTIONS, selectedSet);
6842:
6843:                state.setAttribute(STATE_EXPANDED_COLLECTIONS, new TreeSet());
6844:                state.setAttribute(STATE_EXPANDED_FOLDER_SORT_MAP,
6845:                        new Hashtable());
6846:                state.setAttribute(STATE_EXPAND_ALL_FLAG, Boolean.FALSE
6847:                        .toString());
6848:
6849:            } // doUnexpandall
6850:
6851:            /**
6852:             * Read user inputs from options form and update accordingly
6853:             */
6854:            public void doUpdateOptions(RunData data) {
6855:                // get the state object
6856:                SessionState state = ((JetspeedRunData) data)
6857:                        .getPortletSessionState(((JetspeedRunData) data)
6858:                                .getJs_peid());
6859:
6860:                //get the ParameterParser from RunData
6861:                ParameterParser params = data.getParameters();
6862:
6863:                ResourceTypeRegistry registry = (ResourceTypeRegistry) state
6864:                        .getAttribute(STATE_RESOURCES_TYPE_REGISTRY);
6865:                if (registry == null) {
6866:                    registry = (ResourceTypeRegistry) ComponentManager
6867:                            .get("org.sakaiproject.content.api.ResourceTypeRegistry");
6868:                    state.setAttribute(STATE_RESOURCES_TYPE_REGISTRY, registry);
6869:                }
6870:
6871:                List<ResourceType> typeDefs = new Vector<ResourceType>(registry
6872:                        .getTypes());
6873:
6874:                String siteId = params.getString("siteId");
6875:                if (siteId == null || siteId.trim().equals("")) {
6876:                    String home = (String) state
6877:                            .getAttribute(STATE_HOME_COLLECTION_ID);
6878:                    Reference ref = EntityManager
6879:                            .newReference(ContentHostingService
6880:                                    .getReference(home));
6881:                    siteId = ref.getContext();
6882:                }
6883:
6884:                Map<String, Boolean> statusMap = new HashMap<String, Boolean>();
6885:
6886:                String[] types = params.getStrings("types");
6887:                SortedSet enabledTypes = new TreeSet();
6888:                if (types != null) {
6889:                    enabledTypes.addAll(Arrays.asList(types));
6890:                }
6891:
6892:                for (ResourceType typeDef : typeDefs) {
6893:                    if (typeDef instanceof  SiteSpecificResourceType) {
6894:                        statusMap.put(typeDef.getId(), new Boolean(enabledTypes
6895:                                .contains(typeDef.getId())));
6896:                    }
6897:                }
6898:                registry.setMapOfResourceTypesForContext(siteId, statusMap);
6899:
6900:                state.setAttribute(STATE_MODE, MODE_LIST);
6901:
6902:            }
6903:
6904:            /**
6905:             * cancel out of options mode
6906:             */
6907:            public void doCancelOptions(RunData data) {
6908:                // get the state object
6909:                SessionState state = ((JetspeedRunData) data)
6910:                        .getPortletSessionState(((JetspeedRunData) data)
6911:                                .getJs_peid());
6912:
6913:                state.setAttribute(STATE_MODE, MODE_LIST);
6914:
6915:            }
6916:
6917:            /**
6918:             * Find the resource with this id in the list.
6919:             * @param messages The list of messages.
6920:             * @param id The message id.
6921:             * @return The index position in the list of the message with this id, or -1 if not found.
6922:             */
6923:            protected int findResourceInList(List resources, String id) {
6924:                for (int i = 0; i < resources.size(); i++) {
6925:                    // if this is the one, return this index
6926:                    if (((ListItem) (resources.get(i))).getId().equals(id))
6927:                        return i;
6928:                }
6929:
6930:                // not found
6931:                return -1;
6932:
6933:            } // findResourceInList
6934:
6935:            /**
6936:             * @param state
6937:             * @param toolSession
6938:             * @param pipe
6939:             */
6940:            protected void finishAction(SessionState state,
6941:                    ToolSession toolSession, ResourceToolActionPipe pipe) {
6942:                ResourceToolAction action = pipe.getAction();
6943:                // use ActionType for this 
6944:                switch (action.getActionType()) {
6945:                case CREATE:
6946:                    state.setAttribute(STATE_MODE, MODE_CREATE_WIZARD);
6947:                    break;
6948:                case NEW_UPLOAD:
6949:                    List<ContentResource> resources = createResources(pipe);
6950:                    if (resources != null && !resources.isEmpty()) {
6951:                        // expand folder
6952:                        SortedSet<String> expandedCollections = (SortedSet<String>) state
6953:                                .getAttribute(STATE_EXPANDED_COLLECTIONS);
6954:                        expandedCollections
6955:                                .add(pipe.getContentEntity().getId());
6956:                    }
6957:                    toolSession.removeAttribute(ResourceToolAction.ACTION_PIPE);
6958:                    break;
6959:                case NEW_FOLDER:
6960:                    List<ContentCollection> folders = createFolders(state, pipe);
6961:                    if (folders != null && !folders.isEmpty()) {
6962:                        // expand folder
6963:                        SortedSet<String> expandedCollections = (SortedSet<String>) state
6964:                                .getAttribute(STATE_EXPANDED_COLLECTIONS);
6965:                        expandedCollections
6966:                                .add(pipe.getContentEntity().getId());
6967:                    }
6968:                    toolSession.removeAttribute(ResourceToolAction.ACTION_PIPE);
6969:                    break;
6970:                case NEW_URLS:
6971:                    List<ContentResource> urls = createUrls(state, pipe);
6972:                    if (urls == null || urls.isEmpty()) {
6973:                        // add an alert and return to the addUrl view?
6974:                    } else {
6975:                        // expand folder
6976:                        SortedSet<String> expandedCollections = (SortedSet<String>) state
6977:                                .getAttribute(STATE_EXPANDED_COLLECTIONS);
6978:                        expandedCollections
6979:                                .add(pipe.getContentEntity().getId());
6980:                        toolSession
6981:                                .removeAttribute(ResourceToolAction.ACTION_PIPE);
6982:                    }
6983:                    break;
6984:                case REVISE_CONTENT:
6985:                    reviseContent(pipe);
6986:                    toolSession.removeAttribute(ResourceToolAction.ACTION_PIPE);
6987:                    state.setAttribute(STATE_MODE, MODE_LIST);
6988:                    break;
6989:                case REPLACE_CONTENT:
6990:                    replaceContent(pipe);
6991:                    toolSession.removeAttribute(ResourceToolAction.ACTION_PIPE);
6992:                    state.setAttribute(STATE_MODE, MODE_LIST);
6993:                default:
6994:                    state.setAttribute(STATE_MODE, MODE_LIST);
6995:                }
6996:            }
6997:
6998:            protected void replaceContent(ResourceToolActionPipe pipe) {
6999:                ResourceToolAction action = pipe.getAction();
7000:                ContentEntity entity = pipe.getContentEntity();
7001:                try {
7002:                    ContentResourceEdit edit = ContentHostingService
7003:                            .editResource(entity.getId());
7004:                    ResourcePropertiesEdit props = edit.getPropertiesEdit();
7005:                    // update content
7006:                    byte[] content = pipe.getRevisedContent();
7007:                    if (content == null) {
7008:                        InputStream stream = pipe.getRevisedContentStream();
7009:                        if (stream == null) {
7010:                            logger
7011:                                    .warn("pipe with null content and null stream: "
7012:                                            + pipe.getFileName());
7013:                        } else {
7014:                            edit.setContent(stream);
7015:                        }
7016:                    } else {
7017:                        edit.setContent(content);
7018:                    }
7019:                    // update properties
7020:                    if (action instanceof  InteractionAction) {
7021:                        InteractionAction iAction = (InteractionAction) action;
7022:                        Map revprops = pipe.getRevisedResourceProperties();
7023:                        List propkeys = iAction.getRequiredPropertyKeys();
7024:                        if (propkeys != null) {
7025:                            Iterator keyIt = propkeys.iterator();
7026:                            while (keyIt.hasNext()) {
7027:                                String key = (String) keyIt.next();
7028:                                String value = (String) revprops.get(key);
7029:                                if (value == null) {
7030:                                    props.removeProperty(key);
7031:                                } else {
7032:                                    // should we support multivalued properties?
7033:                                    props.addProperty(key, value);
7034:                                }
7035:                            }
7036:                        }
7037:                    }
7038:                    // update mimetype
7039:                    edit.setContentType(pipe.getRevisedMimeType());
7040:                    ContentHostingService.commitResource(edit);
7041:                } catch (PermissionException e) {
7042:                    // TODO Auto-generated catch block
7043:                    logger.warn("PermissionException ", e);
7044:                } catch (IdUnusedException e) {
7045:                    // TODO Auto-generated catch block
7046:                    logger.warn("IdUnusedException ", e);
7047:                } catch (TypeException e) {
7048:                    // TODO Auto-generated catch block
7049:                    logger.warn("TypeException ", e);
7050:                } catch (InUseException e) {
7051:                    // TODO Auto-generated catch block
7052:                    logger.warn("InUseException ", e);
7053:                } catch (OverQuotaException e) {
7054:                    // TODO Auto-generated catch block
7055:                    logger.warn("OverQuotaException ", e);
7056:                } catch (ServerOverloadException e) {
7057:                    // TODO Auto-generated catch block
7058:                    logger.warn("ServerOverloadException ", e);
7059:                }
7060:            }
7061:
7062:            protected ResourceType getResourceType(String id, SessionState state) {
7063:                ResourceType type = null;
7064:
7065:                boolean isCollection = false;
7066:                String typeId = TYPE_UPLOAD;
7067:                ResourceProperties properties;
7068:                try {
7069:                    properties = ContentHostingService.getProperties(id);
7070:                    isCollection = properties
7071:                            .getBooleanProperty(ResourceProperties.PROP_IS_COLLECTION);
7072:                    if (isCollection) {
7073:                        typeId = "folder";
7074:                    } else {
7075:                        ContentResource resource = ContentHostingService
7076:                                .getResource(id);
7077:                        String mimetype = resource.getContentType();
7078:                        if (TYPE_HTML.equals(mimetype)
7079:                                || TYPE_URL.equals(mimetype)
7080:                                || TYPE_TEXT.equals(mimetype)) {
7081:                            typeId = mimetype;
7082:                        }
7083:                    }
7084:
7085:                    ResourceTypeRegistry registry = (ResourceTypeRegistry) state
7086:                            .getAttribute(STATE_RESOURCES_TYPE_REGISTRY);
7087:                    if (registry == null) {
7088:                        registry = (ResourceTypeRegistry) ComponentManager
7089:                                .get(ResourceTypeRegistry.class);
7090:                        state.setAttribute(STATE_RESOURCES_TYPE_REGISTRY,
7091:                                registry);
7092:                    }
7093:                    type = registry.getType(typeId);
7094:                } catch (PermissionException e1) {
7095:                    // TODO Auto-generated catch block
7096:                    e1.printStackTrace();
7097:                } catch (IdUnusedException e1) {
7098:                    // TODO Auto-generated catch block
7099:                    e1.printStackTrace();
7100:                } catch (EntityPropertyNotDefinedException e) {
7101:                    // TODO Auto-generated catch block
7102:                    e.printStackTrace();
7103:                } catch (EntityPropertyTypeException e) {
7104:                    // TODO Auto-generated catch block
7105:                    e.printStackTrace();
7106:                } catch (TypeException e) {
7107:                    // TODO Auto-generated catch block
7108:                    e.printStackTrace();
7109:                }
7110:
7111:                return type;
7112:
7113:            }
7114:
7115:            /**
7116:             * Populate the state object, if needed - override to do something!
7117:             */
7118:            protected void initState(SessionState state,
7119:                    VelocityPortlet portlet, JetspeedRunData data) {
7120:                super .initState(state, portlet, data);
7121:
7122:                if (state.getAttribute(STATE_INITIALIZED) == null) {
7123:                    initCopyContext(state);
7124:                    initMoveContext(state);
7125:                }
7126:
7127:                initStateAttributes(state, portlet);
7128:
7129:            } // initState
7130:
7131:            public void initStateAttributes(SessionState state,
7132:                    VelocityPortlet portlet) {
7133:                if (state.getAttribute(STATE_INITIALIZED) != null)
7134:                    return;
7135:
7136:                if (state.getAttribute(STATE_FILE_UPLOAD_MAX_SIZE) == null) {
7137:                    state.setAttribute(STATE_FILE_UPLOAD_MAX_SIZE,
7138:                            ServerConfigurationService.getString(
7139:                                    "content.upload.max", "1"));
7140:                }
7141:
7142:                PortletConfig config = portlet.getPortletConfig();
7143:                try {
7144:                    Integer size = new Integer(config
7145:                            .getInitParameter(PARAM_PAGESIZE));
7146:                    if (size == null || size.intValue() < 1) {
7147:                        size = new Integer(DEFAULT_PAGE_SIZE);
7148:                    }
7149:                    state.setAttribute(STATE_PAGESIZE, size);
7150:                } catch (Exception any) {
7151:                    state.setAttribute(STATE_PAGESIZE, new Integer(
7152:                            DEFAULT_PAGE_SIZE));
7153:                }
7154:
7155:                // state.setAttribute(STATE_TOP_PAGE_MESSAGE_ID, "");
7156:
7157:                state.setAttribute(STATE_CONTENT_SERVICE, ContentHostingService
7158:                        .getInstance());
7159:                state.setAttribute(STATE_CONTENT_TYPE_IMAGE_SERVICE,
7160:                        ContentTypeImageService.getInstance());
7161:                state
7162:                        .setAttribute(
7163:                                STATE_RESOURCES_TYPE_REGISTRY,
7164:                                ComponentManager
7165:                                        .get("org.sakaiproject.content.api.ResourceTypeRegistry"));
7166:
7167:                TimeBreakdown timeBreakdown = (TimeService.newTime())
7168:                        .breakdownLocal();
7169:                String mycopyright = rb.getString("cpright1")
7170:                        + " "
7171:                        + timeBreakdown.getYear()
7172:                        + ", "
7173:                        + UserDirectoryService.getCurrentUser()
7174:                                .getDisplayName() + ". All Rights Reserved. ";
7175:                state.setAttribute(STATE_MY_COPYRIGHT, mycopyright);
7176:
7177:                if (state.getAttribute(STATE_MODE) == null) {
7178:                    state.setAttribute(STATE_MODE, MODE_LIST);
7179:                    state.setAttribute(STATE_FROM, NULL_STRING);
7180:                }
7181:                state.setAttribute(STATE_SORT_BY,
7182:                        ResourceProperties.PROP_DISPLAY_NAME);
7183:
7184:                state.setAttribute(STATE_SORT_ASC, Boolean.TRUE.toString());
7185:
7186:                state.setAttribute(STATE_SELECT_ALL_FLAG, Boolean.FALSE
7187:                        .toString());
7188:
7189:                state.setAttribute(STATE_EXPAND_ALL_FLAG, Boolean.FALSE
7190:                        .toString());
7191:
7192:                state.setAttribute(STATE_LIST_SELECTIONS, new TreeSet());
7193:
7194:                state.setAttribute(STATE_COLLECTION_PATH, new Vector());
7195:
7196:                // %%STATE_MODE_RESOURCES%%
7197:                // In helper mode, calling tool should set attribute STATE_MODE_RESOURCES
7198:                String resources_mode = (String) state
7199:                        .getAttribute(STATE_MODE_RESOURCES);
7200:                if (resources_mode == null) {
7201:                    // get resources mode from tool registry
7202:                    resources_mode = portlet.getPortletConfig()
7203:                            .getInitParameter("resources_mode");
7204:                    if (resources_mode != null) {
7205:                        state
7206:                                .setAttribute(STATE_MODE_RESOURCES,
7207:                                        resources_mode);
7208:                    }
7209:                }
7210:
7211:                boolean show_other_sites = false;
7212:                if (RESOURCES_MODE_HELPER.equals(resources_mode)) {
7213:                    show_other_sites = ServerConfigurationService.getBoolean(
7214:                            "resources.show_all_collections.helper",
7215:                            SHOW_ALL_SITES_IN_FILE_PICKER);
7216:                } else if (RESOURCES_MODE_DROPBOX.equals(resources_mode)) {
7217:                    show_other_sites = ServerConfigurationService.getBoolean(
7218:                            "resources.show_all_collections.dropbox",
7219:                            SHOW_ALL_SITES_IN_DROPBOX);
7220:                } else {
7221:                    show_other_sites = ServerConfigurationService.getBoolean(
7222:                            "resources.show_all_collections.tool",
7223:                            SHOW_ALL_SITES_IN_RESOURCES);
7224:                }
7225:
7226:                /** set attribute for the maximum size at which the resources tool will expand a collection. */
7227:                int expandableFolderSizeLimit = ServerConfigurationService
7228:                        .getInt("resources.expanded_folder_size_limit",
7229:                                EXPANDABLE_FOLDER_SIZE_LIMIT);
7230:                state.setAttribute(STATE_EXPANDABLE_FOLDER_SIZE_LIMIT,
7231:                        new Integer(expandableFolderSizeLimit));
7232:
7233:                /** This attribute indicates whether "Other Sites" twiggle should show */
7234:                state.setAttribute(STATE_SHOW_ALL_SITES, Boolean
7235:                        .toString(show_other_sites));
7236:                /** This attribute indicates whether "Other Sites" twiggle should be open */
7237:                state.setAttribute(STATE_SHOW_OTHER_SITES, Boolean.FALSE
7238:                        .toString());
7239:
7240:                // set the home collection to the parameter, if present, or the default if not
7241:                String home = StringUtil.trimToNull(portlet.getPortletConfig()
7242:                        .getInitParameter("home"));
7243:                state.setAttribute(STATE_HOME_COLLECTION_DISPLAY_NAME, home);
7244:                if ((home == null) || (home.length() == 0)) {
7245:                    // no home set, see if we are in dropbox mode
7246:                    if (RESOURCES_MODE_DROPBOX.equalsIgnoreCase(resources_mode)) {
7247:                        home = ContentHostingService.getDropboxCollection();
7248:
7249:                        // if it came back null, we will pretend not to be in dropbox mode
7250:                        if (home != null) {
7251:                            state.setAttribute(
7252:                                    STATE_HOME_COLLECTION_DISPLAY_NAME,
7253:                                    ContentHostingService
7254:                                            .getDropboxDisplayName());
7255:
7256:                            // create/update the collection of folders in the dropbox
7257:                            ContentHostingService.createDropboxCollection();
7258:                        }
7259:                    }
7260:
7261:                    // if we still don't have a home,
7262:                    if ((home == null) || (home.length() == 0)) {
7263:                        home = ContentHostingService
7264:                                .getSiteCollection(ToolManager
7265:                                        .getCurrentPlacement().getContext());
7266:
7267:                        // TODO: what's the 'name' of the context? -ggolden
7268:                        // we'll need this to create the home collection if needed
7269:                        state
7270:                                .setAttribute(
7271:                                        STATE_HOME_COLLECTION_DISPLAY_NAME,
7272:                                        ToolManager.getCurrentPlacement()
7273:                                                .getContext()
7274:                                /*SiteService.getSiteDisplay(ToolManager.getCurrentPlacement().getContext()) */);
7275:                    }
7276:                }
7277:                state.setAttribute(STATE_HOME_COLLECTION_ID, home);
7278:                state.setAttribute(STATE_COLLECTION_ID, home);
7279:                state.setAttribute(STATE_NAVIGATION_ROOT, home);
7280:
7281:                // state.setAttribute (STATE_COLLECTION_ID, state.getAttribute (STATE_HOME_COLLECTION_ID));
7282:
7283:                if (state.getAttribute(STATE_SITE_TITLE) == null) {
7284:                    String title = "";
7285:                    try {
7286:                        title = ((Site) SiteService.getSite(ToolManager
7287:                                .getCurrentPlacement().getContext()))
7288:                                .getTitle();
7289:                    } catch (IdUnusedException e) { // ignore
7290:                    }
7291:                    state.setAttribute(STATE_SITE_TITLE, title);
7292:                }
7293:
7294:                SortedSet expandedCollections = new TreeSet();
7295:                //expandedCollections.add (state.getAttribute (STATE_HOME_COLLECTION_ID));
7296:                state.setAttribute(STATE_EXPANDED_COLLECTIONS,
7297:                        expandedCollections);
7298:                state.setAttribute(STATE_EXPANDED_FOLDER_SORT_MAP,
7299:                        new Hashtable());
7300:
7301:                if (state.getAttribute(STATE_USING_CREATIVE_COMMONS) == null) {
7302:                    String usingCreativeCommons = ServerConfigurationService
7303:                            .getString("copyright.use_creative_commons");
7304:                    if (usingCreativeCommons != null
7305:                            && usingCreativeCommons
7306:                                    .equalsIgnoreCase(Boolean.TRUE.toString())) {
7307:                        state.setAttribute(STATE_USING_CREATIVE_COMMONS,
7308:                                Boolean.TRUE.toString());
7309:                    } else {
7310:                        state.setAttribute(STATE_USING_CREATIVE_COMMONS,
7311:                                Boolean.FALSE.toString());
7312:                    }
7313:                }
7314:
7315:                if (state.getAttribute(STATE_COPYRIGHT_TYPES) == null) {
7316:                    if (ServerConfigurationService.getStrings("copyrighttype") != null) {
7317:                        state.setAttribute(STATE_COPYRIGHT_TYPES,
7318:                                new ArrayList(Arrays
7319:                                        .asList(ServerConfigurationService
7320:                                                .getStrings("copyrighttype"))));
7321:                    }
7322:                }
7323:
7324:                if (state.getAttribute(STATE_DEFAULT_COPYRIGHT) == null) {
7325:                    if (ServerConfigurationService
7326:                            .getString("default.copyright") != null) {
7327:                        state.setAttribute(STATE_DEFAULT_COPYRIGHT,
7328:                                ServerConfigurationService
7329:                                        .getString("default.copyright"));
7330:                    }
7331:                }
7332:
7333:                if (state.getAttribute(STATE_DEFAULT_COPYRIGHT_ALERT) == null) {
7334:                    if (ServerConfigurationService
7335:                            .getString("default.copyright.alert") != null) {
7336:                        state.setAttribute(STATE_DEFAULT_COPYRIGHT_ALERT,
7337:                                ServerConfigurationService
7338:                                        .getString("default.copyright.alert"));
7339:                    }
7340:                }
7341:
7342:                if (state.getAttribute(STATE_NEW_COPYRIGHT_INPUT) == null) {
7343:                    if (ServerConfigurationService
7344:                            .getString("newcopyrightinput") != null) {
7345:                        state.setAttribute(STATE_NEW_COPYRIGHT_INPUT,
7346:                                ServerConfigurationService
7347:                                        .getString("newcopyrightinput"));
7348:                    }
7349:                }
7350:
7351:                if (state.getAttribute(STATE_COPYRIGHT_FAIRUSE_URL) == null) {
7352:                    if (ServerConfigurationService.getString("fairuse.url") != null) {
7353:                        state.setAttribute(STATE_COPYRIGHT_FAIRUSE_URL,
7354:                                ServerConfigurationService
7355:                                        .getString("fairuse.url"));
7356:                    }
7357:                }
7358:
7359:                if (state.getAttribute(STATE_COPYRIGHT_NEW_COPYRIGHT) == null) {
7360:                    if (ServerConfigurationService
7361:                            .getString("copyrighttype.new") != null) {
7362:                        state.setAttribute(STATE_COPYRIGHT_NEW_COPYRIGHT,
7363:                                ServerConfigurationService
7364:                                        .getString("copyrighttype.new"));
7365:                    }
7366:                }
7367:
7368:                // get resources mode from tool registry
7369:                String optional_properties = portlet.getPortletConfig()
7370:                        .getInitParameter("optional_properties");
7371:                if (optional_properties != null
7372:                        && "true".equalsIgnoreCase(optional_properties)) {
7373:                    initMetadataContext(state);
7374:                }
7375:
7376:                state.setAttribute(STATE_PREVENT_PUBLIC_DISPLAY, Boolean.FALSE);
7377:                String[] siteTypes = ServerConfigurationService
7378:                        .getStrings("prevent.public.resources");
7379:                String siteType = null;
7380:                Site site;
7381:                try {
7382:                    site = SiteService.getSite(ToolManager
7383:                            .getCurrentPlacement().getContext());
7384:                    siteType = site.getType();
7385:                    if (siteTypes != null) {
7386:                        for (int i = 0; i < siteTypes.length; i++) {
7387:                            if ((StringUtil.trimToNull(siteTypes[i]))
7388:                                    .equals(siteType)) {
7389:                                state.setAttribute(
7390:                                        STATE_PREVENT_PUBLIC_DISPLAY,
7391:                                        Boolean.TRUE);
7392:                                break;
7393:                            }
7394:                        }
7395:                    }
7396:                } catch (IdUnusedException e) {
7397:                    // allow public display
7398:                } catch (NullPointerException e) {
7399:                    // allow public display
7400:                }
7401:
7402:                CourseManagementService courseManagementService = (CourseManagementService) ComponentManager
7403:                        .get(CourseManagementService.class);
7404:
7405:                Time defaultRetractTime = TimeService.newTime(TimeService
7406:                        .newTime().getTime()
7407:                        + ONE_WEEK);
7408:                Time guess = null;
7409:                Time now = TimeService.newTime();
7410:                if (siteType != null && siteType.equalsIgnoreCase("course")
7411:                        && courseManagementService != null) {
7412:                    List<AcademicSession> terms = courseManagementService
7413:                            .getAcademicSessions();
7414:                    boolean found = false;
7415:                    for (AcademicSession term : terms) {
7416:                        if (term.getEndDate() != null
7417:                                && term.getEndDate().getTime() > now.getTime()) {
7418:                            if (guess == null) {
7419:                                guess = TimeService.newTime(term.getEndDate()
7420:                                        .getTime());
7421:                            } else if (term.getEndDate().getTime() < guess
7422:                                    .getTime()) {
7423:                                guess.setTime(term.getEndDate().getTime());
7424:                            }
7425:                        }
7426:                    }
7427:                    if (guess != null) {
7428:                        defaultRetractTime = guess;
7429:                    }
7430:                }
7431:                state.setAttribute(STATE_DEFAULT_RETRACT_TIME,
7432:                        defaultRetractTime);
7433:
7434:                if (state.getAttribute(STATE_LIST_PREFERENCE) == null) {
7435:                    state.setAttribute(STATE_LIST_PREFERENCE, LIST_HIERARCHY);
7436:                }
7437:
7438:                state.setAttribute(STATE_INITIALIZED, Boolean.TRUE.toString());
7439:
7440:            }
7441:
7442:            /**
7443:             * is notification enabled?
7444:             */
7445:            protected boolean notificationEnabled(SessionState state) {
7446:                return true;
7447:
7448:            } // notificationEnabled
7449:
7450:            /**
7451:             * @param state
7452:             */
7453:            protected void pasteItem(SessionState state, String collectionId) {
7454:                boolean moving = true;
7455:                boolean copying = false;
7456:                List<String> items_to_be_pasted = (List<String>) state
7457:                        .removeAttribute(STATE_ITEMS_TO_BE_MOVED);
7458:                if (items_to_be_pasted == null) {
7459:                    items_to_be_pasted = (List<String>) state
7460:                            .removeAttribute(STATE_ITEMS_TO_BE_COPIED);
7461:                    copying = true;
7462:                    moving = false;
7463:                }
7464:
7465:                if (items_to_be_pasted == null) {
7466:                    return;
7467:                }
7468:
7469:                org.sakaiproject.content.api.ContentHostingService contentService = (org.sakaiproject.content.api.ContentHostingService) state
7470:                        .getAttribute(STATE_CONTENT_SERVICE);
7471:
7472:                ResourceTypeRegistry registry = (ResourceTypeRegistry) state
7473:                        .getAttribute(STATE_RESOURCES_TYPE_REGISTRY);
7474:                if (registry == null) {
7475:                    registry = (ResourceTypeRegistry) ComponentManager
7476:                            .get("org.sakaiproject.content.api.ResourceTypeRegistry");
7477:                    state.setAttribute(STATE_RESOURCES_TYPE_REGISTRY, registry);
7478:                }
7479:
7480:                ServiceLevelAction slAction = null;
7481:                Reference ref = null;
7482:
7483:                for (String entityId : items_to_be_pasted) {
7484:                    try {
7485:                        ContentEntity entity = null;
7486:                        if (contentService.isCollection(entityId)) {
7487:                            entity = contentService.getCollection(entityId);
7488:                        } else {
7489:                            entity = contentService.getResource(entityId);
7490:                        }
7491:
7492:                        String resourceTypeId = entity.getResourceType();
7493:
7494:                        ResourceType typeDef = registry.getType(resourceTypeId);
7495:
7496:                        ResourceToolAction action = null;
7497:                        if (moving) {
7498:                            action = typeDef.getAction(ResourceToolAction.MOVE);
7499:                        } else {
7500:                            action = typeDef.getAction(ResourceToolAction.COPY);
7501:                        }
7502:                        if (action == null) {
7503:                            continue;
7504:                        }
7505:
7506:                        if (action instanceof  ServiceLevelAction) {
7507:                            slAction = (ServiceLevelAction) action;
7508:
7509:                            ref = EntityManager.newReference(entity
7510:                                    .getReference());
7511:
7512:                            slAction.initializeAction(ref);
7513:
7514:                            // paste copied item into collection 
7515:                            String newId = null;
7516:
7517:                            if (moving) {
7518:                                newId = contentService.moveIntoFolder(entityId,
7519:                                        collectionId);
7520:                            } else {
7521:                                newId = contentService.copyIntoFolder(entityId,
7522:                                        collectionId);
7523:                            }
7524:
7525:                            ref = EntityManager.newReference(contentService
7526:                                    .getReference(newId));
7527:
7528:                            slAction.finalizeAction(ref);
7529:                        }
7530:
7531:                        ref = null;
7532:                    } catch (IdUniquenessException e) {
7533:                        String name = isolateName(entityId);
7534:                        if (slAction != null && ref != null) {
7535:                            slAction.cancelAction(ref);
7536:                            name = ref.getProperties().getProperty(
7537:                                    ResourceProperties.PROP_DISPLAY_NAME);
7538:                        }
7539:                        addAlert(state, trb.getFormattedMessage("paste.error",
7540:                                new Object[] { name }));
7541:                    } catch (IdUsedException e) {
7542:                        String name = isolateName(entityId);
7543:                        if (slAction != null && ref != null) {
7544:                            slAction.cancelAction(ref);
7545:                            name = ref.getProperties().getProperty(
7546:                                    ResourceProperties.PROP_DISPLAY_NAME);
7547:                        }
7548:                        addAlert(state, trb.getFormattedMessage("paste.error",
7549:                                new Object[] { name }));
7550:                    } catch (InconsistentException e) {
7551:                        String name = isolateName(entityId);
7552:                        if (slAction != null && ref != null) {
7553:                            slAction.cancelAction(ref);
7554:                            name = ref.getProperties().getProperty(
7555:                                    ResourceProperties.PROP_DISPLAY_NAME);
7556:                        }
7557:                        addAlert(state, trb.getFormattedMessage("paste.error",
7558:                                new Object[] { name }));
7559:                    } catch (Exception e) {
7560:                        if (slAction != null && ref != null) {
7561:                            slAction.cancelAction(ref);
7562:                        }
7563:                        logger.warn(ref.getReference(), e);
7564:                    }
7565:                }
7566:                // if no errors
7567:                // TODO expand collection
7568:
7569:            }
7570:
7571:            /**
7572:             * Prepare the current page of site collections to display.
7573:             * @return List of ListItem objects to display on this page.
7574:             */
7575:            protected List<ListItem> prepPage(SessionState state) {
7576:                List<ListItem> rv = new Vector<ListItem>();
7577:
7578:                // access the page size
7579:                int pageSize = ((Integer) state.getAttribute(STATE_PAGESIZE))
7580:                        .intValue();
7581:
7582:                // cleanup prior prep
7583:                state.removeAttribute(STATE_NUM_MESSAGES);
7584:
7585:                // are we going next or prev, first or last page?
7586:                boolean goNextPage = state.getAttribute(STATE_GO_NEXT_PAGE) != null;
7587:                boolean goPrevPage = state.getAttribute(STATE_GO_PREV_PAGE) != null;
7588:                boolean goFirstPage = state.getAttribute(STATE_GO_FIRST_PAGE) != null;
7589:                boolean goLastPage = state.getAttribute(STATE_GO_LAST_PAGE) != null;
7590:                state.removeAttribute(STATE_GO_NEXT_PAGE);
7591:                state.removeAttribute(STATE_GO_PREV_PAGE);
7592:                state.removeAttribute(STATE_GO_FIRST_PAGE);
7593:                state.removeAttribute(STATE_GO_LAST_PAGE);
7594:
7595:                // are we going next or prev message?
7596:                boolean goNext = state.getAttribute(STATE_GO_NEXT) != null;
7597:                boolean goPrev = state.getAttribute(STATE_GO_PREV) != null;
7598:                state.removeAttribute(STATE_GO_NEXT);
7599:                state.removeAttribute(STATE_GO_PREV);
7600:
7601:                // read all channel messages
7602:                List<ListItem> allMessages = readAllResources(state);
7603:
7604:                if (allMessages == null) {
7605:                    return rv;
7606:                }
7607:
7608:                String messageIdAtTheTopOfThePage = null;
7609:                Object topMsgId = state.getAttribute(STATE_TOP_PAGE_MESSAGE_ID);
7610:                if (topMsgId == null) {
7611:                    // do nothing
7612:                } else if (topMsgId instanceof  Integer) {
7613:                    messageIdAtTheTopOfThePage = ((Integer) topMsgId)
7614:                            .toString();
7615:                } else if (topMsgId instanceof  String) {
7616:                    messageIdAtTheTopOfThePage = (String) topMsgId;
7617:                }
7618:
7619:                // if we have no prev page and do have a top message, then we will stay "pinned" to the top
7620:                boolean pinToTop = ((messageIdAtTheTopOfThePage != null)
7621:                        && (state.getAttribute(STATE_PREV_PAGE_EXISTS) == null)
7622:                        && !goNextPage && !goPrevPage && !goNext && !goPrev
7623:                        && !goFirstPage && !goLastPage);
7624:
7625:                // if we have no next page and do have a top message, then we will stay "pinned" to the bottom
7626:                boolean pinToBottom = ((messageIdAtTheTopOfThePage != null)
7627:                        && (state.getAttribute(STATE_NEXT_PAGE_EXISTS) == null)
7628:                        && !goNextPage && !goPrevPage && !goNext && !goPrev
7629:                        && !goFirstPage && !goLastPage);
7630:
7631:                // how many messages, total
7632:                int numMessages = allMessages.size();
7633:
7634:                if (numMessages == 0) {
7635:                    return rv;
7636:                }
7637:
7638:                // save the number of messges
7639:                state
7640:                        .setAttribute(STATE_NUM_MESSAGES, new Integer(
7641:                                numMessages));
7642:
7643:                // find the position of the message that is the top first on the page
7644:                int posStart = 0;
7645:                if (messageIdAtTheTopOfThePage != null) {
7646:                    // find the next page
7647:                    posStart = findResourceInList(allMessages,
7648:                            messageIdAtTheTopOfThePage);
7649:
7650:                    // if missing, start at the top
7651:                    if (posStart == -1) {
7652:                        posStart = 0;
7653:                    }
7654:                }
7655:
7656:                // if going to the next page, adjust
7657:                if (goNextPage) {
7658:                    posStart += pageSize;
7659:                }
7660:
7661:                // if going to the prev page, adjust
7662:                else if (goPrevPage) {
7663:                    posStart -= pageSize;
7664:                    if (posStart < 0)
7665:                        posStart = 0;
7666:                }
7667:
7668:                // if going to the first page, adjust
7669:                else if (goFirstPage) {
7670:                    posStart = 0;
7671:                }
7672:
7673:                // if going to the last page, adjust
7674:                else if (goLastPage) {
7675:                    posStart = numMessages - pageSize;
7676:                    if (posStart < 0)
7677:                        posStart = 0;
7678:                }
7679:
7680:                // pinning
7681:                if (pinToTop) {
7682:                    posStart = 0;
7683:                } else if (pinToBottom) {
7684:                    posStart = numMessages - pageSize;
7685:                    if (posStart < 0)
7686:                        posStart = 0;
7687:                }
7688:
7689:                // get the last page fully displayed
7690:                if (posStart + pageSize > numMessages) {
7691:                    posStart = numMessages - pageSize;
7692:                    if (posStart < 0)
7693:                        posStart = 0;
7694:                }
7695:
7696:                // compute the end to a page size, adjusted for the number of messages available
7697:                int posEnd = posStart + (pageSize - 1);
7698:                if (posEnd >= numMessages)
7699:                    posEnd = numMessages - 1;
7700:                int numMessagesOnThisPage = (posEnd - posStart) + 1;
7701:
7702:                // select the messages on this page
7703:                for (int i = posStart; i <= posEnd; i++) {
7704:                    rv.add(allMessages.get(i));
7705:                }
7706:
7707:                // save which message is at the top of the page
7708:                ListItem itemAtTheTopOfThePage = (ListItem) allMessages
7709:                        .get(posStart);
7710:                state.setAttribute(STATE_TOP_PAGE_MESSAGE_ID,
7711:                        itemAtTheTopOfThePage.getId());
7712:                state.setAttribute(STATE_TOP_MESSAGE_INDEX, new Integer(
7713:                        posStart));
7714:
7715:                // which message starts the next page (if any)
7716:                int next = posStart + pageSize;
7717:                if (next < numMessages) {
7718:                    state.setAttribute(STATE_NEXT_PAGE_EXISTS, "");
7719:                } else {
7720:                    state.removeAttribute(STATE_NEXT_PAGE_EXISTS);
7721:                }
7722:
7723:                // which message ends the prior page (if any)
7724:                int prev = posStart - 1;
7725:                if (prev >= 0) {
7726:                    state.setAttribute(STATE_PREV_PAGE_EXISTS, "");
7727:                } else {
7728:                    state.removeAttribute(STATE_PREV_PAGE_EXISTS);
7729:                }
7730:
7731:                if (state.getAttribute(STATE_VIEW_ID) != null) {
7732:                    int viewPos = findResourceInList(allMessages,
7733:                            (String) state.getAttribute(STATE_VIEW_ID));
7734:
7735:                    // are we moving to the next message
7736:                    if (goNext) {
7737:                        // advance
7738:                        viewPos++;
7739:                        if (viewPos >= numMessages)
7740:                            viewPos = numMessages - 1;
7741:                    }
7742:
7743:                    // are we moving to the prev message
7744:                    if (goPrev) {
7745:                        // retreat
7746:                        viewPos--;
7747:                        if (viewPos < 0)
7748:                            viewPos = 0;
7749:                    }
7750:
7751:                    // update the view message
7752:                    state.setAttribute(STATE_VIEW_ID, ((ListItem) allMessages
7753:                            .get(viewPos)).getId());
7754:
7755:                    // if the view message is no longer on the current page, adjust the page
7756:                    // Note: next time through this will get processed
7757:                    if (viewPos < posStart) {
7758:                        state.setAttribute(STATE_GO_PREV_PAGE, "");
7759:                    } else if (viewPos > posEnd) {
7760:                        state.setAttribute(STATE_GO_NEXT_PAGE, "");
7761:                    }
7762:
7763:                    if (viewPos > 0) {
7764:                        state.setAttribute(STATE_PREV_EXISTS, "");
7765:                    } else {
7766:                        state.removeAttribute(STATE_PREV_EXISTS);
7767:                    }
7768:
7769:                    if (viewPos < numMessages - 1) {
7770:                        state.setAttribute(STATE_NEXT_EXISTS, "");
7771:                    } else {
7772:                        state.removeAttribute(STATE_NEXT_EXISTS);
7773:                    }
7774:                }
7775:
7776:                return rv;
7777:
7778:            } // prepPage
7779:
7780:            /**
7781:             * Processes the HTML document that is coming back from the browser
7782:             * (from the formatted text editing widget).
7783:             * @param state Used to pass in any user-visible alerts or errors when processing the text
7784:             * @param strFromBrowser The string from the browser
7785:             * @return The formatted text
7786:             */
7787:            private String processHtmlDocumentFromBrowser(SessionState state,
7788:                    String strFromBrowser) {
7789:                StringBuffer alertMsg = new StringBuffer();
7790:                String text = FormattedText.processHtmlDocument(strFromBrowser,
7791:                        alertMsg);
7792:                if (alertMsg.length() > 0)
7793:                    addAlert(state, alertMsg.toString());
7794:                return text;
7795:            }
7796:
7797:            /**
7798:             * Develop a list of all the site collections that there are to page.
7799:             * Sort them as appropriate, and apply search criteria.
7800:             */
7801:            protected List<ListItem> readAllResources(SessionState state) {
7802:                ResourceTypeRegistry registry = (ResourceTypeRegistry) state
7803:                        .getAttribute(STATE_RESOURCES_TYPE_REGISTRY);
7804:                if (registry == null) {
7805:                    registry = (ResourceTypeRegistry) ComponentManager
7806:                            .get("org.sakaiproject.content.api.ResourceTypeRegistry");
7807:                    state.setAttribute(STATE_RESOURCES_TYPE_REGISTRY, registry);
7808:                }
7809:
7810:                List<ListItem> other_sites = new Vector<ListItem>();
7811:
7812:                String collectionId = (String) state
7813:                        .getAttribute(STATE_COLLECTION_ID);
7814:                SortedSet<String> expandedCollections = (SortedSet<String>) state
7815:                        .getAttribute(STATE_EXPANDED_COLLECTIONS);
7816:                if (expandedCollections == null) {
7817:                    expandedCollections = new TreeSet();
7818:                    state.setAttribute(STATE_EXPANDED_COLLECTIONS,
7819:                            expandedCollections);
7820:                }
7821:
7822:                Comparator userSelectedSort = (Comparator) state
7823:                        .getAttribute(STATE_LIST_VIEW_SORT);
7824:
7825:                // set the sort values
7826:                String sortedBy = (String) state.getAttribute(STATE_SORT_BY);
7827:                String sortedAsc = (String) state.getAttribute(STATE_SORT_ASC);
7828:
7829:                Boolean showRemove = (Boolean) state
7830:                        .getAttribute(STATE_SHOW_REMOVE_ACTION);
7831:                boolean showRemoveAction = showRemove != null
7832:                        && showRemove.booleanValue();
7833:
7834:                Boolean showMove = (Boolean) state
7835:                        .getAttribute(STATE_SHOW_MOVE_ACTION);
7836:                boolean showMoveAction = showMove != null
7837:                        && showMove.booleanValue();
7838:
7839:                Boolean showCopy = (Boolean) state
7840:                        .getAttribute(STATE_SHOW_COPY_ACTION);
7841:                boolean showCopyAction = showCopy != null
7842:                        && showCopy.booleanValue();
7843:
7844:                Set highlightedItems = (Set) state
7845:                        .getAttribute(STATE_HIGHLIGHTED_ITEMS);
7846:
7847:                // add user's personal workspace
7848:                User user = UserDirectoryService.getCurrentUser();
7849:                String userId = user.getId();
7850:                String userName = user.getDisplayName();
7851:                String wsId = SiteService.getUserSiteId(userId);
7852:                String wsCollectionId = ContentHostingService
7853:                        .getSiteCollection(wsId);
7854:                List<String> items_to_be_copied = (List<String>) state
7855:                        .getAttribute(STATE_ITEMS_TO_BE_COPIED);
7856:                List<String> items_to_be_moved = (List<String>) state
7857:                        .getAttribute(STATE_ITEMS_TO_BE_MOVED);
7858:
7859:                if (!collectionId.equals(wsCollectionId)) {
7860:                    try {
7861:                        ContentCollection wsCollection = ContentHostingService
7862:                                .getCollection(wsCollectionId);
7863:                        ListItem wsRoot = ListItem.getListItem(wsCollection,
7864:                                null, registry, false, expandedCollections,
7865:                                items_to_be_moved, items_to_be_copied, 0,
7866:                                userSelectedSort, false);
7867:                        other_sites.add(wsRoot);
7868:                    } catch (IdUnusedException e) {
7869:                        // TODO Auto-generated catch block
7870:                        logger.warn("IdUnusedException ", e);
7871:                    } catch (TypeException e) {
7872:                        // TODO Auto-generated catch block
7873:                        logger.warn("TypeException ", e);
7874:                    } catch (PermissionException e) {
7875:                        // TODO Auto-generated catch block
7876:                        logger.warn("PermissionException ", e);
7877:                    }
7878:                }
7879:
7880:                /*
7881:                 * add all other sites user has access to
7882:                 * NOTE: This does not (and should not) get all sites for admin.  
7883:                 *       Getting all sites for admin is too big a request and
7884:                 *       would result in too big a display to render in html.
7885:                 */
7886:                Map othersites = ContentHostingService.getCollectionMap();
7887:                Iterator siteIt = othersites.keySet().iterator();
7888:                SortedSet sort = new TreeSet();
7889:                while (siteIt.hasNext()) {
7890:                    String collId = (String) siteIt.next();
7891:                    String displayName = (String) othersites.get(collId);
7892:                    sort.add(displayName + DELIM + collId);
7893:                }
7894:
7895:                Iterator sortIt = sort.iterator();
7896:                while (sortIt.hasNext()) {
7897:                    String keyvalue = (String) sortIt.next();
7898:                    String displayName = keyvalue.substring(0, keyvalue
7899:                            .lastIndexOf(DELIM));
7900:                    String collId = keyvalue.substring(keyvalue
7901:                            .lastIndexOf(DELIM) + 1);
7902:                    if (!collectionId.equals(collId)
7903:                            && !wsCollectionId.equals(collId)) {
7904:                        ContentCollection collection;
7905:                        try {
7906:                            collection = ContentHostingService
7907:                                    .getCollection(collId);
7908:                            ListItem root = ListItem.getListItem(collection,
7909:                                    null, registry, false, expandedCollections,
7910:                                    items_to_be_moved, items_to_be_copied, 0,
7911:                                    null, false);
7912:                            root.setName(displayName);
7913:                            other_sites.add(root);
7914:                        } catch (IdUnusedException e) {
7915:                            // TODO Auto-generated catch block
7916:                            logger.warn("IdUnusedException " + e);
7917:                        } catch (TypeException e) {
7918:                            // TODO Auto-generated catch block
7919:                            logger.warn("TypeException " + e);
7920:                        } catch (PermissionException e) {
7921:                            // TODO Auto-generated catch block
7922:                            logger.warn("PermissionException " + e);
7923:                        }
7924:                    }
7925:                }
7926:
7927:                return other_sites;
7928:            }
7929:
7930:            /**
7931:             * Setup our observer to be watching for change events for the collection
7932:             */
7933:            private void updateObservation(SessionState state, String peid) {
7934:                // 		ContentObservingCourier observer = (ContentObservingCourier) state.getAttribute(STATE_OBSERVER);
7935:                //
7936:                // 		// the delivery location for this tool
7937:                // 		String deliveryId = clientWindowId(state, peid);
7938:                // 		observer.setDeliveryId(deliveryId);
7939:            }
7940:
7941:            public static List<ContentResource> createUrls(SessionState state,
7942:                    ResourceToolActionPipe pipe) {
7943:                boolean item_added = false;
7944:                String collectionId = null;
7945:                List<ContentResource> new_resources = new Vector<ContentResource>();
7946:                MultiFileUploadPipe mfp = (MultiFileUploadPipe) pipe;
7947:                Iterator<ResourceToolActionPipe> pipeIt = mfp.getPipes()
7948:                        .iterator();
7949:                while (pipeIt.hasNext()) {
7950:                    ResourceToolActionPipe fp = pipeIt.next();
7951:                    collectionId = pipe.getContentEntity().getId();
7952:                    String name = fp.getFileName();
7953:                    if (name == null || name.trim().equals("")) {
7954:                        continue;
7955:                    }
7956:                    String basename = name.trim();
7957:                    String extension = "";
7958:                    if (name.contains(".")) {
7959:                        String[] parts = name.split("\\.");
7960:                        basename = parts[0];
7961:                        if (parts.length > 1) {
7962:                            extension = parts[parts.length - 1];
7963:                        }
7964:
7965:                        for (int i = 1; i < parts.length - 1; i++) {
7966:                            basename += "." + parts[i];
7967:                            // extension = parts[i + 1];
7968:                        }
7969:                    }
7970:                    try {
7971:                        ContentResourceEdit resource = ContentHostingService
7972:                                .addResource(
7973:                                        collectionId,
7974:                                        Validator.escapeResourceName(basename),
7975:                                        Validator.escapeResourceName(extension),
7976:                                        MAXIMUM_ATTEMPTS_FOR_UNIQUENESS);
7977:
7978:                        byte[] content = fp.getRevisedContent();
7979:                        if (content == null) {
7980:                            InputStream stream = fp.getRevisedContentStream();
7981:                            if (stream == null) {
7982:                                logger
7983:                                        .warn("pipe with null content and null stream: "
7984:                                                + pipe.getFileName());
7985:                            } else {
7986:                                resource.setContent(stream);
7987:                            }
7988:                        } else {
7989:                            resource.setContent(content);
7990:                        }
7991:
7992:                        resource.setContentType(fp.getRevisedMimeType());
7993:                        resource.setResourceType(pipe.getAction().getTypeId());
7994:                        Object obj = fp.getRevisedListItem();
7995:                        if (obj != null && obj instanceof  ListItem) {
7996:                            ((ListItem) obj)
7997:                                    .updateContentResourceEdit(resource);
7998:                        }
7999:                        ContentHostingService.commitResource(resource,
8000:                                NotificationService.NOTI_NONE);
8001:                        item_added = true;
8002:                        new_resources.add(resource);
8003:                    } catch (PermissionException e) {
8004:                        // TODO Auto-generated catch block
8005:                        logger.warn("PermissionException ", e);
8006:                    } catch (IdUnusedException e) {
8007:                        // TODO Auto-generated catch block
8008:                        logger.warn("IdUsedException ", e);
8009:                    } catch (IdInvalidException e) {
8010:                        // TODO Auto-generated catch block
8011:                        logger.warn("IdInvalidException ", e);
8012:                    } catch (IdUniquenessException e) {
8013:                        // TODO Auto-generated catch block
8014:                        logger.warn("IdUniquenessException ", e);
8015:                    } catch (IdLengthException e) {
8016:                        // TODO Auto-generated catch block
8017:                        logger.warn("IdLengthException ", e);
8018:                    } catch (OverQuotaException e) {
8019:                        // TODO Auto-generated catch block
8020:                        logger.warn("OverQuotaException ", e);
8021:                    } catch (ServerOverloadException e) {
8022:                        // TODO Auto-generated catch block
8023:                        logger.warn("ServerOverloadException ", e);
8024:                    }
8025:                }
8026:
8027:                return (item_added ? new_resources : null);
8028:            }
8029:
8030:        } // ResourcesAction
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.