Source Code Cross Referenced for ListItem.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/ListItem.java $
0003:         * $Id: ListItem.java 30220 2007-05-09 18:32:57Z ajpoland@iupui.edu $
0004:         ***********************************************************************************
0005:         *
0006:         * Copyright (c) 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.text.NumberFormat;
0023:        import java.util.ArrayList;
0024:        import java.util.Arrays;
0025:        import java.util.Collection;
0026:        import java.util.Collections;
0027:        import java.util.Comparator;
0028:        import java.util.HashMap;
0029:        import java.util.Iterator;
0030:        import java.util.LinkedList;
0031:        import java.util.List;
0032:        import java.util.Map;
0033:        import java.util.Set;
0034:        import java.util.SortedSet;
0035:        import java.util.Stack;
0036:        import java.util.TreeSet;
0037:        import java.util.Vector;
0038:
0039:        import org.apache.commons.logging.Log;
0040:        import org.apache.commons.logging.LogFactory;
0041:        import org.sakaiproject.authz.cover.SecurityService;
0042:        import org.sakaiproject.component.cover.ComponentManager;
0043:        import org.sakaiproject.content.api.ContentCollection;
0044:        import org.sakaiproject.content.api.ContentCollectionEdit;
0045:        import org.sakaiproject.content.api.ContentEntity;
0046:        import org.sakaiproject.content.api.ContentResource;
0047:        import org.sakaiproject.content.api.ContentResourceEdit;
0048:        import org.sakaiproject.content.api.GroupAwareEdit;
0049:        import org.sakaiproject.content.api.GroupAwareEntity;
0050:        import org.sakaiproject.content.api.ResourceToolAction;
0051:        import org.sakaiproject.content.api.ResourceToolActionPipe;
0052:        import org.sakaiproject.content.api.ResourceType;
0053:        import org.sakaiproject.content.api.ResourceTypeRegistry;
0054:        import org.sakaiproject.content.cover.ContentHostingService;
0055:        import org.sakaiproject.content.api.ServiceLevelAction;
0056:        import org.sakaiproject.content.api.GroupAwareEntity.AccessMode;
0057:        import org.sakaiproject.content.cover.ContentTypeImageService;
0058:        import org.sakaiproject.content.tool.ResourcesAction.ContentPermissions;
0059:        import org.sakaiproject.entity.api.EntityPropertyNotDefinedException;
0060:        import org.sakaiproject.entity.api.EntityPropertyTypeException;
0061:        import org.sakaiproject.entity.api.Reference;
0062:        import org.sakaiproject.entity.api.ResourceProperties;
0063:        import org.sakaiproject.entity.api.ResourcePropertiesEdit;
0064:        import org.sakaiproject.entity.cover.EntityManager;
0065:        import org.sakaiproject.exception.IdUnusedException;
0066:        import org.sakaiproject.exception.InconsistentException;
0067:        import org.sakaiproject.exception.PermissionException;
0068:        import org.sakaiproject.exception.TypeException;
0069:        import org.sakaiproject.site.api.Group;
0070:        import org.sakaiproject.site.api.Site;
0071:        import org.sakaiproject.site.cover.SiteService;
0072:        import org.sakaiproject.time.api.Time;
0073:        import org.sakaiproject.time.cover.TimeService;
0074:        import org.sakaiproject.tool.cover.ToolManager;
0075:        import org.sakaiproject.user.api.User;
0076:        import org.sakaiproject.user.cover.UserDirectoryService;
0077:        import org.sakaiproject.util.ParameterParser;
0078:        import org.sakaiproject.util.ResourceLoader;
0079:        import org.sakaiproject.util.Validator;
0080:
0081:        /**
0082:         * ListItem
0083:         *
0084:         */
0085:        public class ListItem {
0086:            /** Resource bundle using current language locale */
0087:            private static ResourceLoader rb = new ResourceLoader("content");
0088:
0089:            /** Resource bundle using current language locale */
0090:            private static ResourceLoader trb = new ResourceLoader("types");
0091:
0092:            private static final Log logger = LogFactory.getLog(ListItem.class);
0093:
0094:            protected static Comparator DEFAULT_COMPARATOR = ContentHostingService
0095:                    .newContentHostingComparator(
0096:                            ResourceProperties.PROP_DISPLAY_NAME, true);
0097:            protected static final Comparator PRIORITY_SORT_COMPARATOR = ContentHostingService
0098:                    .newContentHostingComparator(
0099:                            ResourceProperties.PROP_CONTENT_PRIORITY, true);
0100:
0101:            /** A long representing the number of milliseconds in one week.  Used for date calculations */
0102:            protected static final long ONE_WEEK = 1000L * 60L * 60L * 24L * 7L;
0103:
0104:            public static final String DOT = "_";
0105:
0106:            /**
0107:             * @param entity
0108:             * @param parent
0109:             * @param registry
0110:             * @param expandAll
0111:             * @param expandedFolders
0112:             * @param items_to_be_moved
0113:             * @param items_to_be_copied
0114:             * @param depth
0115:             * @param userSelectedSort
0116:             * @param preventPublicDisplay
0117:             * @return
0118:             */
0119:            public static ListItem getListItem(ContentEntity entity,
0120:                    ListItem parent, ResourceTypeRegistry registry,
0121:                    boolean expandAll, Set<String> expandedFolders,
0122:                    List<String> items_to_be_moved,
0123:                    List<String> items_to_be_copied, int depth,
0124:                    Comparator userSelectedSort, boolean preventPublicDisplay) {
0125:                ListItem item = null;
0126:                boolean isCollection = entity.isCollection();
0127:
0128:                org.sakaiproject.content.api.ContentHostingService contentService = ContentHostingService
0129:                        .getInstance();
0130:
0131:                boolean isAvailabilityEnabled = contentService
0132:                        .isAvailabilityEnabled();
0133:
0134:                Reference ref = EntityManager.newReference(entity
0135:                        .getReference());
0136:
0137:                if (entity == null) {
0138:                    item = new ListItem("");
0139:                } else {
0140:                    item = new ListItem(entity);
0141:                }
0142:                item.setPubviewPossible(!preventPublicDisplay);
0143:                item.setDepth(depth);
0144:
0145:                /*
0146:                 * calculate permissions for this entity.  If its access mode is 
0147:                 * GROUPED, we need to calculate permissions based on current user's 
0148:                 * role in group. Otherwise, we inherit from containing collection
0149:                 * and check to see if additional permissions are set on this entity
0150:                 * that were't set on containing collection...
0151:                 */
0152:                if (GroupAwareEntity.AccessMode.INHERITED == entity.getAccess()) {
0153:                    // permissions are same as parent or site
0154:                    if (parent == null) {
0155:                        // permissions are same as site
0156:                        item.setPermissions(ResourcesAction.getPermissions(
0157:                                entity.getId(), null));
0158:                    } else {
0159:                        // permissions are same as parent
0160:                        item.setPermissions(ResourcesAction.getPermissions(
0161:                                entity.getId(), parent.getPermissions()));
0162:                    }
0163:                } else if (GroupAwareEntity.AccessMode.GROUPED == entity
0164:                        .getAccess()) {
0165:                    // permissions are determined by group(s)
0166:                    item.setPermissions(ResourcesAction.getPermissions(entity
0167:                            .getId(), null));
0168:                }
0169:
0170:                if (isCollection) {
0171:                    ContentCollection collection = (ContentCollection) entity;
0172:
0173:                    if (item.isTooBig) {
0174:                        // do nothing
0175:                    } else if (expandAll) {
0176:                        expandedFolders.add(entity.getId());
0177:                    }
0178:
0179:                    if (expandedFolders.contains(entity.getId())) {
0180:                        item.setExpanded(true);
0181:
0182:                        List<ContentEntity> children = collection
0183:                                .getMemberResources();
0184:
0185:                        Comparator comparator = null;
0186:                        if (userSelectedSort != null) {
0187:                            comparator = userSelectedSort;
0188:                        } else {
0189:                            boolean hasCustomSort = false;
0190:                            try {
0191:                                hasCustomSort = collection
0192:                                        .getProperties()
0193:                                        .getBooleanProperty(
0194:                                                ResourceProperties.PROP_HAS_CUSTOM_SORT);
0195:                            } catch (Exception e) {
0196:                                // ignore -- let value be false
0197:                            }
0198:                            if (hasCustomSort) {
0199:                                comparator = PRIORITY_SORT_COMPARATOR;
0200:                            } else {
0201:                                comparator = DEFAULT_COMPARATOR;
0202:                            }
0203:                        }
0204:
0205:                        Collections.sort(children, comparator);
0206:
0207:                        Iterator<ContentEntity> childIt = children.iterator();
0208:                        while (childIt.hasNext()) {
0209:                            ContentEntity childEntity = childIt.next();
0210:                            if (childEntity.getAccess() == AccessMode.GROUPED) {
0211:                                if (childEntity.isCollection()) {
0212:                                    if (!contentService
0213:                                            .allowGetCollection(childEntity
0214:                                                    .getId())) {
0215:                                        continue;
0216:                                    }
0217:                                } else {
0218:                                    if (!contentService
0219:                                            .allowGetResource(childEntity
0220:                                                    .getId())) {
0221:                                        continue;
0222:                                    }
0223:                                }
0224:                            }
0225:
0226:                            if (isAvailabilityEnabled
0227:                                    && !contentService.isAvailable(childEntity
0228:                                            .getId())) {
0229:                                continue;
0230:                            }
0231:
0232:                            ListItem child = getListItem(childEntity, item,
0233:                                    registry, expandAll, expandedFolders,
0234:                                    items_to_be_moved, items_to_be_copied,
0235:                                    depth + 1, userSelectedSort,
0236:                                    preventPublicDisplay);
0237:                            if (items_to_be_copied != null
0238:                                    && items_to_be_copied.contains(child.id)) {
0239:                                child.setSelectedForCopy(true);
0240:                            }
0241:                            if (items_to_be_moved != null
0242:                                    && items_to_be_moved.contains(child.id)) {
0243:                                child.setSelectedForMove(true);
0244:                            }
0245:                            item.addMember(child);
0246:                        }
0247:                    }
0248:
0249:                    item.setAddActions(ResourcesAction.getAddActions(entity,
0250:                            item.getPermissions(), registry));
0251:                    //this.members = coll.getMembers();
0252:                    item.setIconLocation(ContentTypeImageService
0253:                            .getContentTypeImage("folder"));
0254:                }
0255:
0256:                item.setOtherActions(ResourcesAction.getActions(entity, item
0257:                        .getPermissions(), registry));
0258:
0259:                item.setPasteActions(ResourcesAction.getPasteActions(entity,
0260:                        item.getPermissions(), registry, items_to_be_moved,
0261:                        items_to_be_copied));
0262:
0263:                return item;
0264:            }
0265:
0266:            protected boolean selectedForMove = false;
0267:
0268:            protected boolean selectedForCopy = false;
0269:
0270:            protected String name;
0271:            protected String id;
0272:            protected List<ResourceToolAction> addActions;
0273:            protected List<ResourceToolAction> otherActions;
0274:            protected List<ResourceToolAction> pasteActions;
0275:            protected String otherActionsLabel;
0276:            protected List<ListItem> members;
0277:            protected Set<ContentPermissions> permissions;
0278:            protected boolean selected;
0279:            protected boolean collection;
0280:            protected String hoverText;
0281:            protected String accessUrl;
0282:            protected String iconLocation;
0283:            protected String mimetype;
0284:            protected String resourceType;
0285:            protected ResourceType resourceTypeDef = null;
0286:            protected boolean isEmpty = true;
0287:            protected boolean isExpanded = false;
0288:            protected boolean isSortable = false;
0289:            protected boolean isTooBig = false;
0290:            protected String size = "";
0291:            protected String sizzle = "";
0292:            protected String createdBy;
0293:            protected String createdTime;
0294:            protected String modifiedBy;
0295:            protected String modifiedTime;
0296:            protected int depth;
0297:
0298:            protected Map<String, ResourceToolAction> multipleItemActions = new HashMap<String, ResourceToolAction>();
0299:
0300:            protected boolean canSelect = true;
0301:
0302:            /** 
0303:             * Access settings
0304:             * Access mode can be "grouped" or "inherited". Inherited access mode
0305:             * can be "site" or "grouped". Site access implies that the site's
0306:             * permissions apply, possibly with changes due to custom folder 
0307:             * permissions in the hierarchy.   
0308:             */
0309:            protected ContentEntity entity;
0310:            protected AccessMode accessMode;
0311:            protected AccessMode inheritedAccessMode;
0312:            protected Collection<Group> groups = new Vector<Group>();
0313:            protected Collection<Group> inheritedGroups = new Vector<Group>();
0314:            protected Collection<Group> possibleGroups = new Vector<Group>();
0315:            protected Collection<Group> allowedRemoveGroups = new Vector<Group>();
0316:            protected Collection<Group> allowedAddGroups = new Vector<Group>();
0317:            protected Map<String, Group> siteGroupsMap = new HashMap<String, Group>();
0318:
0319:            protected boolean isPubviewPossible;
0320:            protected boolean isPubviewInherited = false;
0321:            protected boolean isPubview = false;
0322:
0323:            protected boolean hidden;
0324:            protected boolean isAvailable;
0325:            protected boolean useReleaseDate;
0326:            protected Time releaseDate;
0327:            protected boolean useRetractDate;
0328:
0329:            protected Time retractDate;
0330:
0331:            protected String description;
0332:            protected String copyrightInfo;
0333:            protected String copyrightStatus;
0334:            protected boolean copyrightAlert;
0335:
0336:            protected ListItem parent;
0337:
0338:            protected String containingCollectionId;
0339:
0340:            protected boolean isUserSite = false;
0341:            protected boolean isDropbox = false;
0342:
0343:            protected boolean isSiteCollection = false;
0344:            protected boolean hasQuota = false;
0345:            protected boolean canSetQuota = false;
0346:            protected String quota;
0347:
0348:            protected boolean nameIsMissing = false;
0349:
0350:            /**
0351:             * @param entity
0352:             */
0353:            public ListItem(ContentEntity entity) {
0354:                this .entity = entity;
0355:                if (entity == null) {
0356:                    return;
0357:                }
0358:                String refstr = entity.getReference();
0359:                Reference ref = EntityManager.newReference(refstr);
0360:                String contextId = ref.getContext();
0361:                boolean isUserSite = false;
0362:                if (contextId != null) {
0363:                    isUserSite = SiteService.isUserSite(contextId);
0364:                }
0365:                setUserSite(isUserSite);
0366:
0367:                this .isSiteCollection = this .siteCollection(refstr);
0368:
0369:                org.sakaiproject.content.api.ContentHostingService contentService = ContentHostingService
0370:                        .getInstance();
0371:                if (entity.getContainingCollection() == null) {
0372:                    this .containingCollectionId = null;
0373:                } else {
0374:                    this .containingCollectionId = entity
0375:                            .getContainingCollection().getId();
0376:                }
0377:                if (this .id != null) {
0378:                    this .isDropbox = contentService.isInDropbox(id);
0379:                } else if (this .containingCollectionId != null) {
0380:                    this .isDropbox = contentService
0381:                            .isInDropbox(this .containingCollectionId);
0382:                }
0383:                ResourceProperties props = entity.getProperties();
0384:                this .accessUrl = entity.getUrl();
0385:                this .collection = entity.isCollection();
0386:                this .id = entity.getId();
0387:                this .name = props
0388:                        .getProperty(ResourceProperties.PROP_DISPLAY_NAME);
0389:                this .description = props
0390:                        .getProperty(ResourceProperties.PROP_DESCRIPTION);
0391:
0392:                this .permissions = new TreeSet<ContentPermissions>();
0393:                this .selected = false;
0394:
0395:                ResourceTypeRegistry registry = (ResourceTypeRegistry) ComponentManager
0396:                        .get("org.sakaiproject.content.api.ResourceTypeRegistry");
0397:                this .resourceType = entity.getResourceType();
0398:                ResourceType typeDef = registry.getType(resourceType);
0399:                this .hoverText = this .name;
0400:                if (typeDef != null) {
0401:                    this .hoverText = typeDef.getLocalizedHoverText(entity);
0402:                    this .iconLocation = typeDef.getIconLocation(this .entity);
0403:                    String[] args = { typeDef.getLabel() };
0404:                    this .otherActionsLabel = trb.getFormattedMessage(
0405:                            "action.other", args);
0406:                }
0407:
0408:                if (this .collection) {
0409:                    ContentCollection collection = (ContentCollection) entity;
0410:                    int collection_size = collection.getMemberCount();
0411:                    if (collection_size == 1) {
0412:                        setSize(rb.getString("size.item"));
0413:                    } else {
0414:                        String[] args = { Integer.toString(collection_size) };
0415:                        setSize(rb.getFormattedMessage("size.items", args));
0416:                    }
0417:                    setIsEmpty(collection_size < 1);
0418:                    setSortable(contentService.isSortByPriorityEnabled()
0419:                            && collection_size > 1
0420:                            && collection_size < ResourcesAction.EXPANDABLE_FOLDER_SIZE_LIMIT);
0421:                    if (collection_size > ResourcesAction.EXPANDABLE_FOLDER_SIZE_LIMIT) {
0422:                        setIsTooBig(true);
0423:                    }
0424:                    // setup for quota - ADMIN only, site-root collection only
0425:                    if (SecurityService.isSuperUser()) {
0426:                        String siteCollectionId = ContentHostingService
0427:                                .getSiteCollection(contextId);
0428:                        if (siteCollectionId.equals(entity.getId())) {
0429:                            setCanSetQuota(true);
0430:                            try {
0431:                                // Getting the quota as a long validates the property
0432:                                long quota = props
0433:                                        .getLongProperty(ResourceProperties.PROP_COLLECTION_BODY_QUOTA);
0434:                                setHasQuota(true);
0435:                                setQuota(Long.toString(quota));
0436:                            } catch (Exception any) {
0437:                            }
0438:                        }
0439:                    }
0440:                } else {
0441:                    ContentResource resource = (ContentResource) entity;
0442:                    this .mimetype = resource.getContentType();
0443:                    if (this .mimetype == null) {
0444:                        this .mimetype = props
0445:                                .getProperty(ResourceProperties.PROP_CONTENT_TYPE);
0446:                    }
0447:                    if (this .mimetype == null) {
0448:
0449:                    } else if (this .iconLocation == null) {
0450:                        this .iconLocation = ContentTypeImageService
0451:                                .getContentTypeImage(this .mimetype);
0452:                    }
0453:                    String size = "";
0454:                    String sizzle = "";
0455:                    if (props
0456:                            .getProperty(ResourceProperties.PROP_CONTENT_LENGTH) != null) {
0457:                        long size_long = 0;
0458:                        try {
0459:                            size_long = props
0460:                                    .getLongProperty(ResourceProperties.PROP_CONTENT_LENGTH);
0461:                        } catch (EntityPropertyNotDefinedException e) {
0462:                            // TODO Auto-generated catch block
0463:                            logger
0464:                                    .warn("EntityPropertyNotDefinedException for size of "
0465:                                            + this .id);
0466:                        } catch (EntityPropertyTypeException e) {
0467:                            size = props
0468:                                    .getProperty(ResourceProperties.PROP_CONTENT_LENGTH);
0469:                        }
0470:                        NumberFormat formatter = NumberFormat.getInstance(rb
0471:                                .getLocale());
0472:                        formatter.setMaximumFractionDigits(1);
0473:                        if (size_long > 700000000L) {
0474:                            String[] args = { formatter.format(1.0 * size_long
0475:                                    / (1024L * 1024L * 1024L)) };
0476:                            size = rb.getFormattedMessage("size.gb", args);
0477:                            String[] argyles = {
0478:                                    formatter.format(1.0 * size_long
0479:                                            / (1024L * 1024L * 1024L)),
0480:                                    formatter.format(size_long) };
0481:                            sizzle = rb.getFormattedMessage("size.gbytes",
0482:                                    argyles);
0483:                        } else if (size_long > 700000L) {
0484:                            String[] args = { formatter.format(1.0 * size_long
0485:                                    / (1024L * 1024L)) };
0486:                            size = rb.getFormattedMessage("size.mb", args);
0487:                            String[] argyles = {
0488:                                    formatter.format(1.0 * size_long
0489:                                            / (1024L * 1024L)),
0490:                                    formatter.format(size_long) };
0491:                            sizzle = rb.getFormattedMessage("size.mbytes",
0492:                                    argyles);
0493:                        } else if (size_long > 700L) {
0494:                            String[] args = { formatter
0495:                                    .format(1.0 * size_long / 1024L) };
0496:                            size = rb.getFormattedMessage("size.kb", args);
0497:                            String[] argyles = {
0498:                                    formatter.format(1.0 * size_long / 1024L),
0499:                                    formatter.format(size_long) };
0500:                            sizzle = rb.getFormattedMessage("size.kbytes",
0501:                                    argyles);
0502:                        } else {
0503:                            String[] args = { formatter.format(size_long) };
0504:                            size = rb.getFormattedMessage("size.bytes", args);
0505:                            sizzle = rb.getFormattedMessage("size.bytes", args);
0506:                        }
0507:                    }
0508:                    setSize(size);
0509:                    setSizzle(sizzle);
0510:
0511:                    this .copyrightStatus = props
0512:                            .getProperty(ResourceProperties.PROP_COPYRIGHT_CHOICE);
0513:                    this .copyrightInfo = props
0514:                            .getProperty(ResourceProperties.PROP_COPYRIGHT);
0515:                    try {
0516:                        this .copyrightAlert = props
0517:                                .getBooleanProperty(ResourceProperties.PROP_COPYRIGHT_ALERT);
0518:                    } catch (EntityPropertyNotDefinedException e) {
0519:                        this .copyrightAlert = false;
0520:                    } catch (EntityPropertyTypeException e) {
0521:                        this .copyrightAlert = false;
0522:                    }
0523:                }
0524:
0525:                User creator = ResourcesAction.getUserProperty(props,
0526:                        ResourceProperties.PROP_CREATOR);
0527:                if (creator != null) {
0528:                    String createdBy = creator.getDisplayName();
0529:                    setCreatedBy(createdBy);
0530:                }
0531:                User modifier = ResourcesAction.getUserProperty(props,
0532:                        ResourceProperties.PROP_MODIFIED_BY);
0533:                if (modifier != null) {
0534:                    String modifiedBy = modifier.getDisplayName();
0535:                    setModifiedBy(modifiedBy);
0536:                }
0537:                // setCreatedBy(props.getProperty(ResourceProperties.PROP_CREATOR));
0538:                this 
0539:                        .setModifiedTime(props
0540:                                .getPropertyFormatted(ResourceProperties.PROP_MODIFIED_DATE));
0541:                this 
0542:                        .setCreatedTime(props
0543:                                .getPropertyFormatted(ResourceProperties.PROP_CREATION_DATE));
0544:
0545:                Site site = null;
0546:                Collection<Group> site_groups = new Vector<Group>();
0547:
0548:                try {
0549:                    site = SiteService.getSite(ToolManager
0550:                            .getCurrentPlacement().getContext());
0551:                } catch (IdUnusedException e) {
0552:                    logger
0553:                            .warn(
0554:                                    "resourcesAction.newEditItems() IdUnusedException ",
0555:                                    e);
0556:                }
0557:                if (site != null) {
0558:                    for (Group gr : (Collection<Group>) site.getGroups()) {
0559:                        if (gr.getId().equals(site.getId())) {
0560:                            // ignore
0561:                        } else {
0562:                            site_groups.add(gr);
0563:                        }
0564:                    }
0565:                }
0566:
0567:                setSiteGroups(site_groups);
0568:
0569:                this .accessMode = entity.getAccess();
0570:                this .inheritedAccessMode = entity.getInheritedAccess();
0571:                //this.effectiveAccess = entity.getInheritedAccess();
0572:                this .groups.clear();
0573:                this .groups.addAll(entity.getGroupObjects());
0574:                this .inheritedGroups.clear();
0575:                this .inheritedGroups.addAll(entity.getInheritedGroupObjects());
0576:
0577:                if (this .inheritedAccessMode == AccessMode.GROUPED) {
0578:                    setPossibleGroups(this .inheritedGroups);
0579:                } else {
0580:                    setPossibleGroups(site_groups);
0581:                }
0582:
0583:                Collection<Group> groupsWithRemovePermission = null;
0584:                if (AccessMode.GROUPED == this .accessMode) {
0585:                    groupsWithRemovePermission = contentService
0586:                            .getGroupsWithRemovePermission(id);
0587:                    Collection<Group> more = contentService
0588:                            .getGroupsWithRemovePermission(ref.getContainer());
0589:                    if (more != null && !more.isEmpty()) {
0590:                        groupsWithRemovePermission.addAll(more);
0591:                    }
0592:                } else if (AccessMode.GROUPED == this .inheritedAccessMode) {
0593:                    groupsWithRemovePermission = contentService
0594:                            .getGroupsWithRemovePermission(ref.getContainer());
0595:                } else if (contentService.getSiteCollection(ref.getContext()) != null) {
0596:                    groupsWithRemovePermission = contentService
0597:                            .getGroupsWithRemovePermission(contentService
0598:                                    .getSiteCollection(ref.getContext()));
0599:                }
0600:                this .allowedRemoveGroups.clear();
0601:                if (groupsWithRemovePermission != null) {
0602:                    this .allowedRemoveGroups.addAll(groupsWithRemovePermission);
0603:                }
0604:
0605:                Collection<Group> groupsWithAddPermission = null;
0606:                if (AccessMode.GROUPED == this .accessMode) {
0607:                    groupsWithAddPermission = contentService
0608:                            .getGroupsWithAddPermission(id);
0609:                    Collection<Group> more = contentService
0610:                            .getGroupsWithAddPermission(ref.getContainer());
0611:                    if (more != null && !more.isEmpty()) {
0612:                        groupsWithAddPermission.addAll(more);
0613:                    }
0614:                } else if (AccessMode.GROUPED == this .inheritedAccessMode) {
0615:                    groupsWithAddPermission = contentService
0616:                            .getGroupsWithAddPermission(ref.getContainer());
0617:                } else if (contentService.getSiteCollection(ref.getContext()) != null) {
0618:                    groupsWithAddPermission = contentService
0619:                            .getGroupsWithAddPermission(contentService
0620:                                    .getSiteCollection(ref.getContext()));
0621:                }
0622:                this .allowedAddGroups.clear();
0623:                if (groupsWithAddPermission != null) {
0624:                    this .allowedAddGroups.addAll(groupsWithAddPermission);
0625:                }
0626:
0627:                this .isPubviewInherited = contentService
0628:                        .isInheritingPubView(id);
0629:                if (!this .isPubviewInherited) {
0630:                    this .isPubview = contentService.isPubView(id);
0631:                }
0632:
0633:                this .hidden = entity.isHidden();
0634:                Time releaseDate = entity.getReleaseDate();
0635:                if (releaseDate == null) {
0636:                    this .useReleaseDate = false;
0637:                    this .releaseDate = TimeService.newTime();
0638:                } else {
0639:                    this .useReleaseDate = true;
0640:                    this .releaseDate = releaseDate;
0641:                }
0642:                Time retractDate = entity.getRetractDate();
0643:                if (retractDate == null) {
0644:                    this .useRetractDate = false;
0645:                } else {
0646:                    this .useRetractDate = true;
0647:                    this .retractDate = retractDate;
0648:                }
0649:                this .isAvailable = entity.isAvailable();
0650:
0651:            }
0652:
0653:            private void setSizzle(String sizzle) {
0654:                this .sizzle = sizzle;
0655:            }
0656:
0657:            public void setQuota(String quota) {
0658:                this .quota = quota;
0659:
0660:            }
0661:
0662:            public void setHasQuota(boolean hasQuota) {
0663:                this .hasQuota = hasQuota;
0664:            }
0665:
0666:            public void setCanSetQuota(boolean canSetQuota) {
0667:                this .canSetQuota = canSetQuota;
0668:            }
0669:
0670:            public void setUserSite(boolean isUserSite) {
0671:                this .isUserSite = isUserSite;
0672:            }
0673:
0674:            public ListItem(ResourceToolActionPipe pipe, ListItem parent,
0675:                    Time defaultRetractTime) {
0676:                org.sakaiproject.content.api.ContentHostingService contentService = ContentHostingService
0677:                        .getInstance();
0678:                this .entity = null;
0679:                this .containingCollectionId = parent.getId();
0680:                ResourceTypeRegistry registry = (ResourceTypeRegistry) ComponentManager
0681:                        .get("org.sakaiproject.content.api.ResourceTypeRegistry");
0682:                this .resourceType = pipe.getAction().getTypeId();
0683:                this .resourceTypeDef = registry.getType(resourceType);
0684:                this .hoverText = this .name;
0685:                if (resourceTypeDef != null) {
0686:                    this .hoverText = resourceTypeDef
0687:                            .getLocalizedHoverText(null);
0688:                    this .iconLocation = resourceTypeDef
0689:                            .getIconLocation(this .entity);
0690:                    String[] args = { resourceTypeDef.getLabel() };
0691:                    this .otherActionsLabel = trb.getFormattedMessage(
0692:                            "action.other", args);
0693:                    this .name = trb.getFormattedMessage("create.unknown", args);
0694:                }
0695:
0696:                this .collection = ResourceType.TYPE_FOLDER.equals(resourceType);
0697:                this .id = "";
0698:                this .parent = parent;
0699:                this .permissions = parent.getPermissions();
0700:                this .selected = false;
0701:
0702:                if (this .collection) {
0703:                    int collection_size = 0;
0704:                    String[] args = { Integer.toString(0) };
0705:                    setSize(rb.getFormattedMessage("size.items", args));
0706:                    setIsEmpty(true);
0707:                    setSortable(false);
0708:                    setIsTooBig(false);
0709:                } else {
0710:                    this .mimetype = pipe.getMimeType();
0711:                    if (this .mimetype == null) {
0712:
0713:                    } else if (this .iconLocation == null) {
0714:                        this .iconLocation = ContentTypeImageService
0715:                                .getContentTypeImage(this .mimetype);
0716:                    }
0717:                    String size = "";
0718:                    if (pipe.getContent() != null) {
0719:                        long size_long = pipe.getContent().length;
0720:                        NumberFormat formatter = NumberFormat.getInstance(rb
0721:                                .getLocale());
0722:                        formatter.setMaximumFractionDigits(1);
0723:                        if (size_long > 700000000L) {
0724:                            String[] args = { formatter.format(1.0 * size_long
0725:                                    / (1024L * 1024L * 1024L)) };
0726:                            size = rb.getFormattedMessage("size.gb", args);
0727:                        } else if (size_long > 700000L) {
0728:                            String[] args = { formatter.format(1.0 * size_long
0729:                                    / (1024L * 1024L)) };
0730:                            size = rb.getFormattedMessage("size.mb", args);
0731:                        } else if (size_long > 700L) {
0732:                            String[] args = { formatter
0733:                                    .format(1.0 * size_long / 1024L) };
0734:                            size = rb.getFormattedMessage("size.kb", args);
0735:                        } else {
0736:                            String[] args = { formatter.format(size_long) };
0737:                            size = rb.getFormattedMessage("size.bytes", args);
0738:                        }
0739:                    }
0740:                    setSize(size);
0741:
0742:                }
0743:
0744:                if (this .id != null) {
0745:                    this .isDropbox = contentService.isInDropbox(id);
0746:                } else if (this .containingCollectionId != null) {
0747:                    this .isDropbox = contentService
0748:                            .isInDropbox(this .containingCollectionId);
0749:                } else {
0750:                    this .isDropbox = parent.isDropbox;
0751:                }
0752:
0753:                Time now = TimeService.newTime();
0754:                User creator = UserDirectoryService.getCurrentUser();
0755:                if (creator != null) {
0756:                    String createdBy = creator.getDisplayName();
0757:                    setCreatedBy(createdBy);
0758:                    setModifiedBy(createdBy);
0759:                }
0760:                // setCreatedBy(props.getProperty(ResourceProperties.PROP_CREATOR));
0761:                this .setModifiedTime(now.getDisplay());
0762:                this .setCreatedTime(now.getDisplay());
0763:
0764:                this .setSiteGroups(parent.siteGroupsMap.values());
0765:                this .accessMode = AccessMode.INHERITED;
0766:                this .inheritedAccessMode = parent.getEffectiveAccess();
0767:                //this.effectiveAccess = parent.getEffectiveAccess();
0768:                this .groups.clear();
0769:                //this.groups.addAll();
0770:                this .inheritedGroups.clear();
0771:                if (parent.getAccessMode() == AccessMode.GROUPED) {
0772:                    this .inheritedGroups.addAll(parent.getGroups());
0773:                    this .setPossibleGroups(parent.getGroups());
0774:                } else {
0775:                    this .inheritedGroups.addAll(parent.getInheritedGroups());
0776:                    this .setPossibleGroups(parent.getPossibleGroups());
0777:
0778:                }
0779:
0780:                this .allowedRemoveGroups = new Vector(
0781:                        parent.allowedRemoveGroups);
0782:                this .allowedAddGroups = new Vector(parent.allowedAddGroups);
0783:
0784:                this .isPubviewPossible = parent.isPubviewPossible;
0785:                this .isPubviewInherited = parent.isPubviewInherited
0786:                        || parent.isPubview;
0787:                if (this .isPubviewInherited) {
0788:                    this .isPubview = false;
0789:                } else {
0790:                    this .isPubview = contentService.isPubView(id);
0791:                }
0792:
0793:                this .hidden = false;
0794:                this .useReleaseDate = false;
0795:                Time releaseDate = TimeService.newTime();
0796:                this .useRetractDate = false;
0797:                Time retractDate = TimeService.newTime(defaultRetractTime
0798:                        .getTime());
0799:                this .isAvailable = parent.isAvailable();
0800:
0801:            }
0802:
0803:            /**
0804:             * @param entityId
0805:             */
0806:            public ListItem(String entityId) {
0807:                this .id = entityId;
0808:                this .containingCollectionId = ContentHostingService
0809:                        .getContainingCollectionId(entityId);
0810:
0811:                String refstr = ContentHostingService.getReference(id);
0812:                this .isSiteCollection = this .siteCollection(refstr);
0813:
0814:            }
0815:
0816:            /**
0817:             * @param child
0818:             */
0819:            public void addMember(ListItem member) {
0820:                if (this .members == null) {
0821:                    this .members = new Vector<ListItem>();
0822:                }
0823:                this .members.add(member);
0824:            }
0825:
0826:            /**
0827:             * @param action
0828:             */
0829:            public void addMultipleItemAction(ResourceToolAction action) {
0830:                this .multipleItemActions.put(action.getId(), action);
0831:            }
0832:
0833:            /**
0834:             * @param permission
0835:             */
0836:            public void addPermission(ContentPermissions permission) {
0837:                if (this .permissions == null) {
0838:                    this .permissions = new TreeSet<ContentPermissions>();
0839:                }
0840:                this .permissions.add(permission);
0841:            }
0842:
0843:            /**
0844:             * @param group
0845:             * @return
0846:             */
0847:            public boolean allowedRemove(Group group) {
0848:                boolean allowed = false;
0849:
0850:                for (Group gr : this .allowedRemoveGroups) {
0851:                    if (gr.getId().equals(group.getId())) {
0852:                        allowed = true;
0853:                        break;
0854:                    }
0855:                }
0856:
0857:                return allowed;
0858:            }
0859:
0860:            public boolean canRead() {
0861:                return isPermitted(ContentPermissions.READ);
0862:            }
0863:
0864:            /**
0865:             * @return
0866:             */
0867:            public boolean canSelect() {
0868:                return canSelect;
0869:            }
0870:
0871:            protected void captureAccess(ParameterParser params, String index) {
0872:                String access_mode = params.getString("access_mode" + index);
0873:                SortedSet groups = new TreeSet();
0874:
0875:                if (access_mode == null
0876:                        || AccessMode.GROUPED.toString().equals(access_mode)) {
0877:                    // we inherit more than one group and must check whether group access changes at this item
0878:                    String[] access_groups = params.getStrings("access_groups"
0879:                            + index);
0880:
0881:                    SortedSet<String> new_groups = new TreeSet<String>();
0882:                    if (access_groups != null) {
0883:                        new_groups.addAll(Arrays.asList(access_groups));
0884:                    }
0885:                    SortedSet<String> new_group_refs = convertToRefs(new_groups);
0886:
0887:                    Collection inh_grps = getInheritedGroupRefs();
0888:                    boolean groups_are_inherited = (new_group_refs.size() == inh_grps
0889:                            .size())
0890:                            && inh_grps.containsAll(new_group_refs);
0891:
0892:                    if (groups_are_inherited) {
0893:                        new_groups.clear();
0894:                        setGroupsById(new_groups);
0895:                        setAccessMode(AccessMode.INHERITED);
0896:                    } else {
0897:                        setGroupsById(new_groups);
0898:                        setAccessMode(AccessMode.GROUPED);
0899:                    }
0900:
0901:                    setPubview(false);
0902:                } else if (ResourcesAction.PUBLIC_ACCESS.equals(access_mode)) {
0903:                    if (!isPubviewInherited()) {
0904:                        setPubview(true);
0905:                        setAccessMode(AccessMode.INHERITED);
0906:                    }
0907:                } else if (AccessMode.INHERITED.toString().equals(access_mode)) {
0908:                    setAccessMode(AccessMode.INHERITED);
0909:                    this .groups.clear();
0910:                    setPubview(false);
0911:                }
0912:            }
0913:
0914:            protected void captureAvailability(ParameterParser params,
0915:                    String index) {
0916:                // availability
0917:                this .hidden = params.getBoolean("hidden" + index);
0918:                boolean use_start_date = params.getBoolean("use_start_date"
0919:                        + index);
0920:                boolean use_end_date = params
0921:                        .getBoolean("use_end_date" + index);
0922:
0923:                this .useReleaseDate = use_start_date;
0924:                if (use_start_date) {
0925:                    int begin_year = params.getInt("release_year" + index);
0926:                    int begin_month = params.getInt("release_month" + index);
0927:                    int begin_day = params.getInt("release_day" + index);
0928:                    int begin_hour = params.getInt("release_hour" + index);
0929:                    int begin_min = params.getInt("release_min" + index);
0930:                    String release_ampm = params.getString("release_ampm"
0931:                            + index);
0932:                    if ("pm".equals(release_ampm)) {
0933:                        begin_hour += 12;
0934:                    } else if (begin_hour == 12) {
0935:                        begin_hour = 0;
0936:                    }
0937:                    this .releaseDate = TimeService
0938:                            .newTimeLocal(begin_year, begin_month, begin_day,
0939:                                    begin_hour, begin_min, 0, 0);
0940:                }
0941:
0942:                this .useRetractDate = use_end_date;
0943:                if (use_end_date) {
0944:                    int end_year = params.getInt("retract_year" + index);
0945:                    int end_month = params.getInt("retract_month" + index);
0946:                    int end_day = params.getInt("retract_day" + index);
0947:                    int end_hour = params.getInt("retract_hour" + index);
0948:                    int end_min = params.getInt("retract_min" + index);
0949:                    String retract_ampm = params.getString("retract_ampm"
0950:                            + index);
0951:                    if ("pm".equals(retract_ampm)) {
0952:                        end_hour += 12;
0953:                    } else if (end_hour == 12) {
0954:                        end_hour = 0;
0955:                    }
0956:                    this .retractDate = TimeService.newTimeLocal(end_year,
0957:                            end_month, end_day, end_hour, end_min, 0, 0);
0958:                }
0959:
0960:            }
0961:
0962:            protected void captureCopyright(ParameterParser params, String index) {
0963:                // rights
0964:                String copyright = params.getString("copyright" + index);
0965:                if (copyright == null || copyright.trim().length() == 0) {
0966:                    // do nothing -- there must be no copyright dialog
0967:                } else {
0968:                    this .copyrightInfo = copyright;
0969:
0970:                    String newcopyright = params.getString("newcopyright"
0971:                            + index);
0972:
0973:                    if (newcopyright == null
0974:                            || newcopyright.trim().length() == 0) {
0975:                        this .copyrightStatus = null;
0976:                    } else {
0977:                        this .copyrightStatus = newcopyright;
0978:                    }
0979:
0980:                    boolean copyrightAlert = params.getBoolean("copyrightAlert"
0981:                            + index);
0982:                    this .copyrightAlert = copyrightAlert;
0983:                }
0984:            }
0985:
0986:            protected void captureDescription(ParameterParser params,
0987:                    String index) {
0988:                // description
0989:                String description = params.getString("description" + index);
0990:                this .setDescription(description);
0991:            }
0992:
0993:            public void captureProperties(ParameterParser params, String index) {
0994:                captureDisplayName(params, index);
0995:                captureDescription(params, index);
0996:                captureCopyright(params, index);
0997:                captureAccess(params, index);
0998:                captureAvailability(params, index);
0999:                if (this .canSetQuota) {
1000:                    captureQuota(params, index);
1001:                }
1002:                if (!isUrl() && !isCollection() && this .mimetype != null) {
1003:                    captureMimetypeChange(params, index);
1004:                }
1005:            }
1006:
1007:            protected void captureMimetypeChange(ParameterParser params,
1008:                    String index) {
1009:                String mimeCategory = params.getString("mime_category" + index);
1010:                if (mimeCategory != null) {
1011:                    String mimeSubtype = params.getString("mime_subtype"
1012:                            + index);
1013:                    if (mimeSubtype != null) {
1014:                        String mimeType = mimeCategory.trim() + "/"
1015:                                + mimeSubtype.trim();
1016:                        if (mimeType.equals(this .mimetype)) {
1017:
1018:                        } else {
1019:                            this .mimetype = mimeType;
1020:                        }
1021:                    }
1022:                }
1023:
1024:            }
1025:
1026:            protected void captureQuota(ParameterParser params, String index) {
1027:                String setQuota = params.getString("setQuota" + index);
1028:                if (setQuota != null) {
1029:                    this .hasQuota = params.getBoolean("hasQuota" + index);
1030:                    if (this .hasQuota) {
1031:                        String quota = params.getString("quota" + index);
1032:                        if (quota != null && quota.trim().matches("^\\d+$")) {
1033:                            this .quota = quota.trim();
1034:                        }
1035:                    } else {
1036:                        this .quota = null;
1037:                    }
1038:                }
1039:            }
1040:
1041:            protected void captureDisplayName(ParameterParser params,
1042:                    String index) {
1043:                String displayName = params.getString("displayName" + index);
1044:                if (displayName == null || displayName.trim().equals("")) {
1045:                    if (this .name == null || this .name.trim().equals("")) {
1046:                        String[] delimiters = { "/", "\\" };
1047:                        displayName = this .id;
1048:                        if (displayName != null) {
1049:                            for (int i = 0; i < delimiters.length; i++) {
1050:                                if (displayName.lastIndexOf(delimiters[i]) >= 0) {
1051:                                    displayName = displayName
1052:                                            .substring(displayName
1053:                                                    .lastIndexOf(delimiters[i]) + 1);
1054:                                }
1055:                            }
1056:                        }
1057:                        this .setName(displayName);
1058:                    }
1059:                } else {
1060:                    this .setName(displayName);
1061:                }
1062:            }
1063:
1064:            /**
1065:             * @param item
1066:             * @return
1067:             */
1068:            public List<ListItem> convert2list() {
1069:                List<ListItem> list = new Vector<ListItem>();
1070:                Stack<ListItem> processStack = new Stack<ListItem>();
1071:
1072:                processStack.push(this );
1073:                while (!processStack.empty()) {
1074:                    ListItem parent = processStack.pop();
1075:                    list.add(parent);
1076:                    List<ListItem> children = parent.getMembers();
1077:                    if (children != null) {
1078:                        for (int i = children.size() - 1; i >= 0; i--) {
1079:                            ListItem child = children.get(i);
1080:                            processStack.push(child);
1081:                        }
1082:                    }
1083:                }
1084:
1085:                return list;
1086:
1087:            } // convert2list
1088:
1089:            /**
1090:             * @param new_groups
1091:             * @return
1092:             */
1093:            public SortedSet<String> convertToRefs(Collection<String> groupIds) {
1094:                SortedSet<String> groupRefs = new TreeSet<String>();
1095:                for (String groupId : groupIds) {
1096:                    Group group = (Group) this .siteGroupsMap.get(groupId);
1097:                    if (group != null) {
1098:                        groupRefs.add(group.getReference());
1099:                    }
1100:                }
1101:                return groupRefs;
1102:
1103:            }
1104:
1105:            public String getLongAccessLabel() {
1106:                String label = "";
1107:
1108:                if (isSiteOnly()) {
1109:                    checkParent();
1110:                    //Site has *NO* groups and public-view is *NOT* enabled on the server 
1111:                    if (this .parent != null) {
1112:                        label = trb.getFormattedMessage("access.site.nochoice",
1113:                                new String[] { parent.getName() });
1114:                    }
1115:                } else if (isGroupInherited()) {
1116:                    //Grouped access is inherited
1117:                    label = getMultiGroupLabel();
1118:                } else if (isPubviewInherited()) {
1119:                    checkParent();
1120:                    if (parent != null) {
1121:                        label = trb.getFormattedMessage(
1122:                                "access.public.nochoice", new String[] { parent
1123:                                        .getName() });
1124:                    }
1125:                } else if (isCollection()) {
1126:                    label = trb.getString("edit.who.fldr");
1127:                } else {
1128:                    label = trb.getString("edit.who");
1129:                }
1130:
1131:                return label;
1132:            }
1133:
1134:            /**
1135:             * 
1136:             */
1137:            protected void checkParent() {
1138:                // Public access inherited from parent 
1139:                if (parent == null) {
1140:                    if (this .containingCollectionId == null) {
1141:                        this .containingCollectionId = ContentHostingService
1142:                                .getContainingCollectionId(this .id);
1143:                    }
1144:                    try {
1145:                        parent = new ListItem(ContentHostingService
1146:                                .getCollection(this .containingCollectionId));
1147:                    } catch (IdUnusedException e) {
1148:                        // TODO Auto-generated catch block
1149:                        logger.warn("IdUnusedException ", e);
1150:                    } catch (TypeException e) {
1151:                        // TODO Auto-generated catch block
1152:                        logger.warn("TypeException ", e);
1153:                    } catch (PermissionException e) {
1154:                        // TODO Auto-generated catch block
1155:                        logger.warn("PermissionException ", e);
1156:                    }
1157:                }
1158:            }
1159:
1160:            /**
1161:             * @return the accessMode
1162:             */
1163:            public AccessMode getAccessMode() {
1164:                return accessMode;
1165:            }
1166:
1167:            /**
1168:             * @return the accessUrl
1169:             */
1170:            public String getAccessUrl() {
1171:                return this .accessUrl;
1172:            }
1173:
1174:            /**
1175:             * @return the addActions
1176:             */
1177:            public List<ResourceToolAction> getAddActions() {
1178:                return addActions;
1179:            }
1180:
1181:            private Collection<Group> getAllowedRemoveGroupRefs() {
1182:                // TODO Auto-generated method stub
1183:                return new TreeSet<Group>(this .allowedAddGroups);
1184:            }
1185:
1186:            /**
1187:             * @return the createdBy
1188:             */
1189:            public String getCreatedBy() {
1190:                if (createdBy == null) {
1191:                    createdBy = "";
1192:                }
1193:                return createdBy;
1194:            }
1195:
1196:            /**
1197:             * @return
1198:             */
1199:            public List<ListItem> getCollectionPath() {
1200:                LinkedList<ListItem> path = new LinkedList<ListItem>();
1201:                org.sakaiproject.content.api.ContentHostingService contentService = ContentHostingService
1202:                        .getInstance();
1203:
1204:                ContentCollection containingCollection = null;
1205:                ContentEntity entity = this .getEntity();
1206:                if (entity == null) {
1207:                    try {
1208:                        containingCollection = contentService
1209:                                .getCollection(this .containingCollectionId);
1210:
1211:                    } catch (IdUnusedException e) {
1212:                        logger.warn("IdUnusedException " + e);
1213:                    } catch (TypeException e) {
1214:                        logger.warn("TypeException " + e);
1215:                    } catch (PermissionException e) {
1216:                        logger.warn("PermissionException " + e);
1217:                    }
1218:
1219:                } else {
1220:                    containingCollection = entity.getContainingCollection();
1221:                }
1222:
1223:                ListItem previousItem = null;
1224:                while (containingCollection != null
1225:                        && !contentService
1226:                                .isRootCollection(containingCollection.getId())) {
1227:                    if (previousItem != null) {
1228:                        path.addFirst(previousItem);
1229:                    }
1230:                    previousItem = new ListItem(containingCollection);
1231:                    containingCollection = containingCollection
1232:                            .getContainingCollection();
1233:                }
1234:                //		if(containingCollection != null)
1235:                //		{
1236:                //			path.addFirst(new ListItem(containingCollection));
1237:                //		}
1238:
1239:                return path;
1240:            }
1241:
1242:            /**
1243:             * @return the depth
1244:             */
1245:            public int getDepth() {
1246:                return depth;
1247:            }
1248:
1249:            /**
1250:             * @return
1251:             */
1252:            public String getDescription() {
1253:                return description;
1254:            }
1255:
1256:            /**
1257:             * @return the effectiveAccess
1258:             */
1259:            public AccessMode getEffectiveAccess() {
1260:                AccessMode access = this .accessMode;
1261:
1262:                if (AccessMode.INHERITED == access) {
1263:                    access = this .inheritedAccessMode;
1264:                }
1265:
1266:                return access;
1267:            }
1268:
1269:            /**
1270:             * @return
1271:             */
1272:            public Collection<Group> getEffectiveGroups() {
1273:                Collection<Group> groups = new Vector<Group>();
1274:
1275:                return groups;
1276:            }
1277:
1278:            /**
1279:             * @return
1280:             */
1281:            public ContentEntity getEntity() {
1282:                return this .entity;
1283:            }
1284:
1285:            public String[] getGroupNameArray(boolean includeItemName) {
1286:                Collection<Group> groups = this .groups;
1287:                if (AccessMode.INHERITED == this .accessMode) {
1288:                    groups = this .inheritedGroups;
1289:                }
1290:
1291:                int size = groups.size();
1292:                if (includeItemName) {
1293:                    size += 1;
1294:                }
1295:                String[] names = new String[size];
1296:
1297:                int index = 0;
1298:                if (includeItemName) {
1299:                    names[index] = this .name;
1300:                    index++;
1301:                }
1302:                for (Group group : groups) {
1303:                    names[index] = group.getTitle();
1304:                    index++;
1305:                }
1306:
1307:                return names;
1308:            }
1309:
1310:            public String getEffectiveAccessLabel() {
1311:                String label = rb.getString("access.site");
1312:
1313:                if (this .isPubviewInherited || this .isPubview) {
1314:                    label = rb.getString("access.public");
1315:                } else if (AccessMode.GROUPED == this .getEffectiveAccess()) {
1316:                    label = rb.getString("access.group");
1317:                }
1318:
1319:                return label;
1320:
1321:            }
1322:
1323:            public String getGroupNamesAsString() {
1324:                String names = "";
1325:                String[] groups = getGroupNameArray(false);
1326:                for (int i = 0; i < groups.length; i++) {
1327:                    if (i > 0 && i < groups.length) {
1328:                        names += ", ";
1329:                    }
1330:                    names += groups[i];
1331:                }
1332:                return names;
1333:            }
1334:
1335:            public String getEffectiveGroupsLabel() {
1336:                String label = rb.getString("access.site1");
1337:
1338:                if (this .isPubviewInherited()) {
1339:                    label = rb.getString("access.public1");
1340:                } else if (this .isPubview()) {
1341:                    label = rb.getString("access.public1");
1342:                } else if (this .isDropbox) {
1343:                    label = rb.getString("access.dropbox1");
1344:                } else if (AccessMode.GROUPED == getEffectiveAccess()) {
1345:                    int size = getNumberOfGroups();
1346:                    label = (String) rb.getFormattedMessage("access.group1",
1347:                            new Object[] { getGroupNamesAsString() });
1348:                }
1349:
1350:                return label;
1351:            }
1352:
1353:            private int getNumberOfGroups() {
1354:                int size = 0;
1355:
1356:                if (AccessMode.INHERITED == this .accessMode) {
1357:                    size = this .inheritedGroups.size();
1358:                } else {
1359:                    size = this .groups.size();
1360:                }
1361:
1362:                return size;
1363:            }
1364:
1365:            public String getMultiGroupLabel() {
1366:                int size = getNumberOfGroups();
1367:                String label = "";
1368:                if (size > 9) {
1369:                    label = trb.getFormattedMessage("access.groupsX",
1370:                            getGroupNameArray(true));
1371:                } else {
1372:                    label = trb.getFormattedMessage("access.groups" + size,
1373:                            getGroupNameArray(true));
1374:                }
1375:                return label;
1376:            }
1377:
1378:            /**
1379:             * @return
1380:             */
1381:            public Collection<String> getGroupRefs() {
1382:                SortedSet<String> refs = new TreeSet<String>();
1383:                for (Group group : this .groups) {
1384:                    refs.add(group.getReference());
1385:                }
1386:                return refs;
1387:            }
1388:
1389:            /**
1390:             * @return the groups
1391:             */
1392:            public Collection<Group> getGroups() {
1393:                return new Vector<Group>(groups);
1394:            }
1395:
1396:            /**
1397:             * @return the hoverText
1398:             */
1399:            public String getHoverText() {
1400:                return this .hoverText;
1401:            }
1402:
1403:            /**
1404:             * @return the iconLocation
1405:             */
1406:            public String getIconLocation() {
1407:                return this .iconLocation;
1408:            }
1409:
1410:            /**
1411:             * @return
1412:             */
1413:            public String getId() {
1414:                return id;
1415:            }
1416:
1417:            /**
1418:             * @return
1419:             */
1420:            public Collection<String> getInheritedGroupRefs() {
1421:                SortedSet<String> refs = new TreeSet<String>();
1422:                for (Group group : this .inheritedGroups) {
1423:                    refs.add(group.getReference());
1424:                }
1425:                return refs;
1426:            }
1427:
1428:            /**
1429:             * @return the inheritedGroups
1430:             */
1431:            public Collection<Group> getInheritedGroups() {
1432:                return new Vector<Group>(inheritedGroups);
1433:            }
1434:
1435:            public List<ListItem> getMembers() {
1436:                return members;
1437:            }
1438:
1439:            /**
1440:             * @return the mimetype
1441:             */
1442:            public String getMimetype() {
1443:                return this .mimetype;
1444:            }
1445:
1446:            /**
1447:             * @return the modifiedTime
1448:             */
1449:            public String getModifiedTime() {
1450:                return modifiedTime;
1451:            }
1452:
1453:            public ResourceToolAction getMultipleItemAction(String key) {
1454:                return this .multipleItemActions.get(key);
1455:            }
1456:
1457:            /**
1458:             * @return
1459:             */
1460:            public Map<String, ResourceToolAction> getMultipleItemActions() {
1461:                return this .multipleItemActions;
1462:            }
1463:
1464:            public String getName() {
1465:                return name;
1466:            }
1467:
1468:            /**
1469:             * @return the otherActions
1470:             */
1471:            public List<ResourceToolAction> getOtherActions() {
1472:                return otherActions;
1473:            }
1474:
1475:            /**
1476:             * @return the otherActionsLabel
1477:             */
1478:            public String getOtherActionsLabel() {
1479:                return otherActionsLabel;
1480:            }
1481:
1482:            /**
1483:             * @return the permissions
1484:             */
1485:            public Set<ContentPermissions> getPermissions() {
1486:                return this .permissions;
1487:            }
1488:
1489:            /**
1490:             * @return
1491:             */
1492:            public Collection<String> getPossibleGroupRefs() {
1493:                SortedSet<String> refs = new TreeSet<String>();
1494:                for (Group group : this .possibleGroups) {
1495:                    refs.add(group.getReference());
1496:                }
1497:                return refs;
1498:            }
1499:
1500:            /**
1501:             * @return the possibleGroups
1502:             */
1503:            public Collection<Group> getPossibleGroups() {
1504:                return new Vector<Group>(possibleGroups);
1505:            }
1506:
1507:            /**
1508:             * @return the releaseDate
1509:             */
1510:            public Time getReleaseDate() {
1511:                if (this .releaseDate == null) {
1512:                    this .releaseDate = TimeService.newTime();
1513:                }
1514:                return releaseDate;
1515:            }
1516:
1517:            /**
1518:             * @return
1519:             */
1520:            public ResourceType getResourceTypeDef() {
1521:                if (resourceTypeDef == null) {
1522:                    if (resourceType == null) {
1523:                        resourceType = ResourceType.TYPE_UPLOAD;
1524:                    }
1525:                    ResourceTypeRegistry registry = (ResourceTypeRegistry) ComponentManager
1526:                            .get("org.sakaiproject.content.api.ResourceTypeRegistry");
1527:                    resourceTypeDef = registry.getType(this .resourceType);
1528:                }
1529:                return resourceTypeDef;
1530:            }
1531:
1532:            /**
1533:             * @return the retractDate
1534:             */
1535:            public Time getRetractDate() {
1536:                if (this .retractDate == null) {
1537:                    this .retractDate = TimeService.newTime(TimeService
1538:                            .newTime().getTime()
1539:                            + ONE_WEEK);
1540:                }
1541:                return retractDate;
1542:            }
1543:
1544:            /**
1545:             * @return the size
1546:             */
1547:            public String getSize() {
1548:                return size;
1549:            }
1550:
1551:            public String getTarget() {
1552:                return Validator.getResourceTarget(this .mimetype);
1553:            }
1554:
1555:            public boolean hasMultipleItemAction(String key) {
1556:                return this .multipleItemActions.containsKey(key);
1557:            }
1558:
1559:            public boolean hasMultipleItemActions() {
1560:                return !this .multipleItemActions.isEmpty();
1561:            }
1562:
1563:            /**
1564:             * @return the isAvailable
1565:             */
1566:            public boolean isAvailable() {
1567:                return isAvailable;
1568:            }
1569:
1570:            /**
1571:             * @return the collection
1572:             */
1573:            public boolean isCollection() {
1574:                return this .collection;
1575:            }
1576:
1577:            public boolean isEmpty() {
1578:                return this .isEmpty;
1579:            }
1580:
1581:            /**
1582:             * @return the isExpanded
1583:             */
1584:            public boolean isExpanded() {
1585:                return isExpanded;
1586:            }
1587:
1588:            public boolean isGroupInherited() {
1589:                return AccessMode.GROUPED == this .inheritedAccessMode;
1590:            }
1591:
1592:            /**
1593:             * @return
1594:             */
1595:            public boolean isGroupPossible() {
1596:                return this .allowedAddGroups != null
1597:                        && !this .allowedAddGroups.isEmpty();
1598:            }
1599:
1600:            /**
1601:             * @return the hidden
1602:             */
1603:            public boolean isHidden() {
1604:                return hidden;
1605:            }
1606:
1607:            /**
1608:             * @param group
1609:             * @return
1610:             */
1611:            public boolean isLocal(Group group) {
1612:                boolean isLocal = false;
1613:
1614:                for (Group gr : this .groups) {
1615:                    if (gr.getId().equals(group.getId())) {
1616:                        isLocal = true;
1617:                        break;
1618:                    }
1619:                }
1620:
1621:                return isLocal;
1622:            }
1623:
1624:            /**
1625:             * @param permission
1626:             * @return
1627:             */
1628:            public boolean isPermitted(ContentPermissions permission) {
1629:                if (this .permissions == null) {
1630:                    this .permissions = new TreeSet<ContentPermissions>();
1631:                }
1632:                return this .permissions.contains(permission);
1633:            }
1634:
1635:            /**
1636:             * @param group
1637:             * @return
1638:             */
1639:            public boolean isPossible(Group group) {
1640:                boolean isPossible = false;
1641:
1642:                Collection<Group> groupsToCheck = this .possibleGroups;
1643:                if (AccessMode.GROUPED == this .inheritedAccessMode) {
1644:                    groupsToCheck = this .inheritedGroups;
1645:                }
1646:
1647:                for (Group gr : groupsToCheck) {
1648:                    if (gr.getId().equals(group.getId())) {
1649:                        isPossible = true;
1650:                        break;
1651:                    }
1652:                }
1653:
1654:                return isPossible;
1655:            }
1656:
1657:            /**
1658:             * @return the isPubview
1659:             */
1660:            public boolean isPubview() {
1661:                return isPubview;
1662:            }
1663:
1664:            /**
1665:             * @return the isPubviewInherited
1666:             */
1667:            public boolean isPubviewInherited() {
1668:                return isPubviewInherited;
1669:            }
1670:
1671:            /**
1672:             * @return
1673:             */
1674:            public boolean isPubviewPossible() {
1675:                return isPubviewPossible;
1676:            }
1677:
1678:            public boolean isSelected() {
1679:                return selected;
1680:            }
1681:
1682:            /**
1683:             * Does this entity inherit grouped access mode with a single group that has access?
1684:             * @return true if this entity inherits grouped access mode with a single group that has access, and false otherwise.
1685:             */
1686:            public boolean isSingleGroupInherited() {
1687:                //Collection groups = getInheritedGroups();
1688:                return // AccessMode.INHERITED.toString().equals(this.m_access) && 
1689:                AccessMode.GROUPED == this .inheritedAccessMode
1690:                        && this .inheritedGroups != null
1691:                        && this .inheritedGroups.size() == 1;
1692:                // && this.m_oldInheritedGroups != null 
1693:                // && this.m_oldInheritedGroups.size() == 1;
1694:            }
1695:
1696:            /**
1697:             * Is this entity's access restricted to the site (not pubview) and are there no groups defined for the site?
1698:             * @return
1699:             */
1700:            public boolean isSiteOnly() {
1701:                boolean isSiteOnly = false;
1702:                isSiteOnly = !isGroupPossible() && !isPubviewPossible();
1703:                return isSiteOnly;
1704:            }
1705:
1706:            /**
1707:             * @return
1708:             */
1709:            public boolean isSitePossible() {
1710:                return !this .isPubviewInherited && !isGroupInherited()
1711:                        && !isSingleGroupInherited();
1712:            }
1713:
1714:            public boolean isTooBig() {
1715:                return this .isTooBig;
1716:            }
1717:
1718:            public boolean isUrl() {
1719:                return this .resourceType != null
1720:                        && this .resourceType.equals(ResourceType.TYPE_URL);
1721:            }
1722:
1723:            /**
1724:             * @param accessMode the accessMode to set
1725:             */
1726:            public void setAccessMode(AccessMode accessMode) {
1727:                this .accessMode = accessMode;
1728:            }
1729:
1730:            /**
1731:             * @param accessUrl the accessUrl to set
1732:             */
1733:            public void setAccessUrl(String accessUrl) {
1734:                this .accessUrl = accessUrl;
1735:            }
1736:
1737:            /**
1738:             * @param addActions the addActions to set
1739:             */
1740:            public void setAddActions(List<ResourceToolAction> addActions) {
1741:                for (ResourceToolAction action : addActions) {
1742:                    if (action instanceof  ServiceLevelAction
1743:                            && ((ServiceLevelAction) action)
1744:                                    .isMultipleItemAction()) {
1745:                        this .multipleItemActions.put(action.getId(), action);
1746:                    }
1747:                }
1748:                this .addActions = addActions;
1749:            }
1750:
1751:            /**
1752:             * @param isAvailable the isAvailable to set
1753:             */
1754:            public void setAvailable(boolean isAvailable) {
1755:                this .isAvailable = isAvailable;
1756:            }
1757:
1758:            /**
1759:             * @param canSelect
1760:             */
1761:            public void setCanSelect(boolean canSelect) {
1762:                this .canSelect = canSelect;
1763:            }
1764:
1765:            /**
1766:             * @param collection the collection to set
1767:             */
1768:            public void setCollection(boolean collection) {
1769:                this .collection = collection;
1770:            }
1771:
1772:            /**
1773:             * @param createdBy the createdBy to set
1774:             */
1775:            public void setCreatedBy(String createdBy) {
1776:                this .createdBy = createdBy;
1777:            }
1778:
1779:            private void setCreatedTime(String createdTime) {
1780:                this .createdTime = createdTime;
1781:            }
1782:
1783:            /**
1784:             * @param depth the depth to set
1785:             */
1786:            public void setDepth(int depth) {
1787:                this .depth = depth;
1788:            }
1789:
1790:            /**
1791:             * @param description
1792:             */
1793:            public void setDescription(String description) {
1794:                this .description = description;
1795:            }
1796:
1797:            /**
1798:             * @param isExpanded the isExpanded to set
1799:             */
1800:            public void setExpanded(boolean isExpanded) {
1801:                this .isExpanded = isExpanded;
1802:            }
1803:
1804:            /**
1805:             * @param groups the groups to set
1806:             */
1807:            public void setGroups(Collection<Group> groups) {
1808:                this .groups.clear();
1809:                this .groups.addAll(groups);
1810:            }
1811:
1812:            /**
1813:             * @param new_groups
1814:             */
1815:            public void setGroupsById(Collection<String> groupIds) {
1816:                this .groups.clear();
1817:                if (groupIds != null && !groupIds.isEmpty()) {
1818:                    for (String groupId : groupIds) {
1819:                        Group group = this .siteGroupsMap.get(groupId);
1820:                        this .groups.add(group);
1821:                    }
1822:                }
1823:            }
1824:
1825:            /**
1826:             * @param hidden the hidden to set
1827:             */
1828:            public void setHidden(boolean hidden) {
1829:                this .hidden = hidden;
1830:            }
1831:
1832:            /**
1833:             * @param hover
1834:             */
1835:            public void setHoverText(String hover) {
1836:                this .hoverText = hover;
1837:            }
1838:
1839:            /**
1840:             * @param iconLocation the iconLocation to set
1841:             */
1842:            public void setIconLocation(String iconLocation) {
1843:                this .iconLocation = iconLocation;
1844:            }
1845:
1846:            /**
1847:             * @param id
1848:             */
1849:            public void setId(String id) {
1850:                this .id = id;
1851:            }
1852:
1853:            /**
1854:             * @param inheritedGroups the inheritedGroups to set
1855:             */
1856:            public void setInheritedGroups(Collection<Group> inheritedGroups) {
1857:                this .inheritedGroups.clear();
1858:                this .inheritedGroups.addAll(inheritedGroups);
1859:            }
1860:
1861:            /**
1862:             * @param isEmpty
1863:             */
1864:            public void setIsEmpty(boolean isEmpty) {
1865:                this .isEmpty = isEmpty;
1866:            }
1867:
1868:            /**
1869:             * @param b
1870:             */
1871:            public void setIsTooBig(boolean isTooBig) {
1872:                this .isTooBig = isTooBig;
1873:            }
1874:
1875:            public void setMembers(List<ListItem> members) {
1876:                if (this .members == null) {
1877:                    this .members = new Vector<ListItem>();
1878:                }
1879:                this .members.clear();
1880:                this .members.addAll(members);
1881:            }
1882:
1883:            /**
1884:             * @param mimetype the mimetype to set
1885:             */
1886:            public void setMimetype(String mimetype) {
1887:                this .mimetype = mimetype;
1888:            }
1889:
1890:            private void setModifiedBy(String modifiedBy) {
1891:                this .modifiedBy = modifiedBy;
1892:            }
1893:
1894:            /**
1895:             * @param modifiedTime the modifiedTime to set
1896:             */
1897:            public void setModifiedTime(String modifiedTime) {
1898:                this .modifiedTime = modifiedTime;
1899:            }
1900:
1901:            public void setName(String name) {
1902:                this .name = name;
1903:            }
1904:
1905:            /**
1906:             * @param otherActions the otherActions to set
1907:             */
1908:            public void setOtherActions(List<ResourceToolAction> otherActions) {
1909:                for (ResourceToolAction action : otherActions) {
1910:                    if (action instanceof  ServiceLevelAction
1911:                            && ((ServiceLevelAction) action)
1912:                                    .isMultipleItemAction()) {
1913:                        this .multipleItemActions.put(action.getId(), action);
1914:                    }
1915:                }
1916:                if (this .otherActions == null) {
1917:                    this .otherActions = new ArrayList<ResourceToolAction>();
1918:                }
1919:                this .otherActions.clear();
1920:                if (otherActions != null) {
1921:                    this .otherActions.addAll(otherActions);
1922:                }
1923:            }
1924:
1925:            /**
1926:             * @param otherActionsLabel the otherActionsLabel to set
1927:             */
1928:            public void setOtherActionsLabel(String otherActionsLabel) {
1929:                this .otherActionsLabel = otherActionsLabel;
1930:            }
1931:
1932:            protected void setPasteActions(List<ResourceToolAction> pasteActions) {
1933:                if (this .pasteActions == null) {
1934:                    this .pasteActions = new ArrayList<ResourceToolAction>();
1935:                }
1936:                this .pasteActions.clear();
1937:                if (pasteActions != null) {
1938:                    this .pasteActions.addAll(pasteActions);
1939:                }
1940:            }
1941:
1942:            /**
1943:             * @param permissions the permissions to set
1944:             */
1945:            public void setPermissions(
1946:                    Collection<ContentPermissions> permissions) {
1947:                if (this .permissions == null) {
1948:                    this .permissions = new TreeSet<ContentPermissions>();
1949:                }
1950:
1951:                this .permissions.clear();
1952:                this .permissions.addAll(permissions);
1953:            }
1954:
1955:            /**
1956:             * @param possibleGroups the possibleGroups to set
1957:             */
1958:            public void setPossibleGroups(Collection<Group> possibleGroups) {
1959:                this .possibleGroups.clear();
1960:                this .possibleGroups.addAll(possibleGroups);
1961:                // TODO remove site itself?
1962:            }
1963:
1964:            public void setSiteGroups(Collection<Group> siteGroups) {
1965:                this .siteGroupsMap.clear();
1966:                for (Group group : siteGroups) {
1967:                    this .siteGroupsMap.put(group.getId(), group);
1968:                }
1969:            }
1970:
1971:            /**
1972:             * @param isPubview the isPubview to set
1973:             */
1974:            public void setPubview(boolean isPubview) {
1975:                this .isPubview = isPubview;
1976:            }
1977:
1978:            /**
1979:             * @param isPubviewInherited the isPubviewInherited to set
1980:             */
1981:            public void setPubviewInherited(boolean isPubviewInherited) {
1982:                this .isPubviewInherited = isPubviewInherited;
1983:            }
1984:
1985:            /**
1986:             * @param isPubviewPossible the isPubviewPossible to set
1987:             */
1988:            public void setPubviewPossible(boolean isPubviewPossible) {
1989:                this .isPubviewPossible = isPubviewPossible;
1990:            }
1991:
1992:            /**
1993:             * @param releaseDate the releaseDate to set
1994:             */
1995:            public void setReleaseDate(Time releaseDate) {
1996:                this .releaseDate = releaseDate;
1997:            }
1998:
1999:            /**
2000:             * @param resourceTypeDef
2001:             */
2002:            public void setResourceTypeDef(ResourceType resourceTypeDef) {
2003:                this .resourceTypeDef = resourceTypeDef;
2004:
2005:                // make sure typeDef and typeId are consistent
2006:                if (resourceTypeDef != null) {
2007:                    this .resourceType = resourceTypeDef.getId();
2008:                }
2009:            }
2010:
2011:            /**
2012:             * @param retractDate the retractDate to set
2013:             */
2014:            public void setRetractDate(Time retractDate) {
2015:                this .retractDate = retractDate;
2016:            }
2017:
2018:            public void setSelected(boolean selected) {
2019:                this .selected = selected;
2020:            }
2021:
2022:            public void setSelectedForCopy(boolean selectedForCopy) {
2023:                this .selectedForCopy = selectedForCopy;
2024:            }
2025:
2026:            public void setSelectedForMove(boolean selectedForMove) {
2027:                this .selectedForMove = selectedForMove;
2028:            }
2029:
2030:            /**
2031:             * @param string
2032:             */
2033:            public void setSize(String size) {
2034:                this .size = size;
2035:            }
2036:
2037:            /**
2038:             * @param isSortable
2039:             */
2040:            public void setSortable(boolean isSortable) {
2041:                this .isSortable = isSortable;
2042:            }
2043:
2044:            /**
2045:             * @param useReleaseDate the useReleaseDate to set
2046:             */
2047:            public void setUseReleaseDate(boolean useReleaseDate) {
2048:                this .useReleaseDate = useReleaseDate;
2049:            }
2050:
2051:            /**
2052:             * @param useRetractDate the useRetractDate to set
2053:             */
2054:            public void setUseRetractDate(boolean useRetractDate) {
2055:                this .useRetractDate = useRetractDate;
2056:            }
2057:
2058:            /**
2059:             * @return the useReleaseDate
2060:             */
2061:            public boolean useReleaseDate() {
2062:                return useReleaseDate;
2063:            }
2064:
2065:            /**
2066:             * @return the useRetractDate
2067:             */
2068:            public boolean useRetractDate() {
2069:                return useRetractDate;
2070:            }
2071:
2072:            public String getCopyrightInfo() {
2073:                return copyrightInfo;
2074:            }
2075:
2076:            public void setCopyrightInfo(String copyright) {
2077:                this .copyrightInfo = copyright;
2078:            }
2079:
2080:            public boolean hasCopyrightAlert() {
2081:                return copyrightAlert;
2082:            }
2083:
2084:            public void setCopyrightAlert(boolean copyrightAlert) {
2085:                this .copyrightAlert = copyrightAlert;
2086:            }
2087:
2088:            public void updateContentCollectionEdit(ContentCollectionEdit edit) {
2089:                ResourcePropertiesEdit props = edit.getPropertiesEdit();
2090:                setDisplayNameOnEntity(props);
2091:                setDescriptionOnEntity(props);
2092:                //setCopyrightOnEntity(props);
2093:                setAccessOnEntity(edit);
2094:                setAvailabilityOnEntity(edit);
2095:                setQuotaOnEntity(props);
2096:            }
2097:
2098:            protected void setQuotaOnEntity(ResourcePropertiesEdit props) {
2099:                if (this .canSetQuota) {
2100:                    if (SecurityService.isSuperUser()) {
2101:                        if (this .hasQuota) {
2102:                            if (this .quota != null
2103:                                    && this .quota.trim().matches("^\\d+$")) {
2104:                                props
2105:                                        .addProperty(
2106:                                                ResourceProperties.PROP_COLLECTION_BODY_QUOTA,
2107:                                                this .quota.trim());
2108:                            }
2109:                        } else {
2110:                            props
2111:                                    .removeProperty(ResourceProperties.PROP_COLLECTION_BODY_QUOTA);
2112:                        }
2113:                    }
2114:                }
2115:            }
2116:
2117:            protected void setAvailabilityOnEntity(GroupAwareEdit edit) {
2118:                edit.setAvailability(hidden, releaseDate, retractDate);
2119:            }
2120:
2121:            protected void setCopyrightOnEntity(ResourcePropertiesEdit props) {
2122:                if (copyrightInfo == null || copyrightInfo.trim().length() == 0) {
2123:                    props
2124:                            .removeProperty(ResourceProperties.PROP_COPYRIGHT_CHOICE);
2125:                } else {
2126:                    props.addProperty(ResourceProperties.PROP_COPYRIGHT_CHOICE,
2127:                            copyrightInfo);
2128:                }
2129:                if (copyrightStatus == null
2130:                        || copyrightStatus.trim().length() == 0) {
2131:                    props.removeProperty(ResourceProperties.PROP_COPYRIGHT);
2132:                } else {
2133:                    props.addProperty(ResourceProperties.PROP_COPYRIGHT,
2134:                            copyrightStatus);
2135:                }
2136:                if (copyrightAlert) {
2137:                    props.addProperty(ResourceProperties.PROP_COPYRIGHT_ALERT,
2138:                            Boolean.TRUE.toString());
2139:                } else {
2140:                    props
2141:                            .removeProperty(ResourceProperties.PROP_COPYRIGHT_ALERT);
2142:                }
2143:
2144:            }
2145:
2146:            protected void setAccessOnEntity(GroupAwareEdit edit) {
2147:                try {
2148:                    if (this .accessMode == AccessMode.GROUPED
2149:                            && this .groups != null && !this .groups.isEmpty()) {
2150:                        edit.setGroupAccess(groups);
2151:                    } else if (this .isPubview && !this .isPubviewInherited) {
2152:                        edit.setPublicAccess();
2153:                    } else if (edit.getAccess() == AccessMode.GROUPED) {
2154:                        edit.clearGroupAccess();
2155:                    }
2156:                } catch (InconsistentException e) {
2157:                    logger.warn("InconsistentException " + e);
2158:                } catch (PermissionException e) {
2159:                    logger.warn("PermissionException " + e);
2160:                }
2161:            }
2162:
2163:            protected void setDescriptionOnEntity(ResourcePropertiesEdit props) {
2164:                if (this .description != null) {
2165:                    props.addProperty(ResourceProperties.PROP_DESCRIPTION,
2166:                            this .description);
2167:                }
2168:            }
2169:
2170:            public void updateContentResourceEdit(ContentResourceEdit edit) {
2171:                ResourcePropertiesEdit props = edit.getPropertiesEdit();
2172:                setDisplayNameOnEntity(props);
2173:                setDescriptionOnEntity(props);
2174:                setCopyrightOnEntity(props);
2175:                setAccessOnEntity(edit);
2176:                setAvailabilityOnEntity(edit);
2177:                if (!isUrl() && !isCollection() && this .mimetype != null) {
2178:                    setMimetypeOnEntity(edit, props);
2179:                }
2180:            }
2181:
2182:            protected void setMimetypeOnEntity(ContentResourceEdit edit,
2183:                    ResourcePropertiesEdit props) {
2184:                if (this .mimetype != null) {
2185:                    props.addProperty(ResourceProperties.PROP_CONTENT_TYPE,
2186:                            this .mimetype);
2187:                    edit.setContentType(this .mimetype);
2188:                }
2189:            }
2190:
2191:            protected void setDisplayNameOnEntity(ResourcePropertiesEdit props) {
2192:                if (this .name != null) {
2193:                    props.addProperty(ResourceProperties.PROP_DISPLAY_NAME,
2194:                            this .name);
2195:                }
2196:            }
2197:
2198:            public String getCopyrightStatus() {
2199:                return copyrightStatus;
2200:            }
2201:
2202:            public void setCopyrightStatus(String copyrightStatus) {
2203:                this .copyrightStatus = copyrightStatus;
2204:            }
2205:
2206:            public boolean isUserSite() {
2207:                return isUserSite;
2208:            }
2209:
2210:            public boolean canSetQuota() {
2211:                return canSetQuota;
2212:            }
2213:
2214:            public boolean hasQuota() {
2215:                return hasQuota;
2216:            }
2217:
2218:            public String getQuota() {
2219:                return quota;
2220:            }
2221:
2222:            public boolean isSiteCollection() {
2223:                return isSiteCollection;
2224:            }
2225:
2226:            public void setSiteCollection(boolean isSiteCollection) {
2227:                this .isSiteCollection = isSiteCollection;
2228:            }
2229:
2230:            public String getResourceType() {
2231:                return resourceType;
2232:            }
2233:
2234:            public void setResourceType(String resourceType) {
2235:                this .resourceType = resourceType;
2236:            }
2237:
2238:            public String getCreatedTime() {
2239:                return createdTime;
2240:            }
2241:
2242:            public String getModifiedBy() {
2243:                return modifiedBy;
2244:            }
2245:
2246:            public String getMimeCategory() {
2247:                if (this .mimetype == null || this .mimetype.equals("")) {
2248:                    return "";
2249:                }
2250:                int index = this .mimetype.indexOf("/");
2251:                if (index < 0) {
2252:                    return this .mimetype;
2253:                }
2254:                return this .mimetype.substring(0, index);
2255:            }
2256:
2257:            public String getMimeSubtype() {
2258:                if (this .mimetype == null || this .mimetype.equals("")) {
2259:                    return "";
2260:                }
2261:                int index = this .mimetype.indexOf("/");
2262:                if (index < 0 || index + 1 == this .mimetype.length()) {
2263:                    return "";
2264:                }
2265:                return this .mimetype.substring(index + 1);
2266:            }
2267:
2268:            public String getSizzle() {
2269:                return sizzle;
2270:            }
2271:
2272:            public boolean isDropbox() {
2273:                return isDropbox;
2274:            }
2275:
2276:            public void setDropbox(boolean isDropbox) {
2277:                this .isDropbox = isDropbox;
2278:            }
2279:
2280:            public List<ResourceToolAction> getPasteActions() {
2281:                return pasteActions;
2282:            }
2283:
2284:            public AccessMode getInheritedAccessMode() {
2285:                return inheritedAccessMode;
2286:            }
2287:
2288:            public void setInheritedAccessMode(AccessMode inheritedAccessMode) {
2289:                this .inheritedAccessMode = inheritedAccessMode;
2290:            }
2291:
2292:            protected boolean siteCollection(String refStr) {
2293:                boolean site = false;
2294:
2295:                Reference ref = EntityManager.newReference(refStr);
2296:                String context = ref.getContext();
2297:                String siteCollection = ContentHostingService
2298:                        .getSiteCollection(context);
2299:                if (ref.getId().equals(siteCollection)) {
2300:                    site = true;
2301:                }
2302:
2303:                return site;
2304:            }
2305:
2306:            public ListItem getParent() {
2307:                checkParent();
2308:                return this .parent;
2309:            }
2310:
2311:            public void setNameIsMissing(boolean nameIsMissing) {
2312:                this .nameIsMissing = nameIsMissing;
2313:            }
2314:
2315:            public boolean isNameMissing() {
2316:                return nameIsMissing;
2317:            }
2318:
2319:            public boolean isSelectedForCopy() {
2320:                return selectedForCopy;
2321:            }
2322:
2323:            public boolean isSelectedForMove() {
2324:                return selectedForMove;
2325:            }
2326:
2327:            public List<String> checkRequiredProperties() {
2328:                List<String> alerts = new Vector<String>();
2329:                String name = getName();
2330:                if (name == null || name.trim().equals("")) {
2331:                    setNameIsMissing(true);
2332:                    alerts.add(rb.getString("edit.missing"));
2333:                }
2334:                return alerts;
2335:            }
2336:
2337:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.